Subversion Repositories eduke32

Rev

Rev 5762 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2437 hendricks2 1
#!/bin/bash
1907 helixhorne 2
 
2437 hendricks2 3
# build debug/release x86/x86_64/ppc versions of mapster32 and eduke32 on OS X
1907 helixhorne 4
 
3554 hendricks2 5
cd ..
6
 
2437 hendricks2 7
# Variable presets:
8
buildppc=1
9
build86=1
10
build64=1
2541 hendricks2 11
buildmain=1
2476 hendricks2 12
buildtools=0
2852 helixhorne 13
installtools=0
2437 hendricks2 14
builddebug=0
2958 helixhorne 15
buildrelease=1
2541 hendricks2 16
pack=1
2852 helixhorne 17
iamhelix=0
3690 helixhorne 18
dummy=0
3692 helixhorne 19
doclean=0
3235 hendricks2 20
package=package
3690 helixhorne 21
lastrevision=
2437 hendricks2 22
 
23
# Enforce OS:
1907 helixhorne 24
if [ `uname -s` != Darwin ]; then
2437 hendricks2 25
    echo This script is for OS X only.
1907 helixhorne 26
    exit 1
27
fi
28
 
2437 hendricks2 29
# Detect and account for OS X version:
30
darwinversion=`uname -r | cut -d . -f 1`
1907 helixhorne 31
 
2455 hendricks2 32
if [ `expr $darwinversion \< 9` == 1 ]; then
2460 hendricks2 33
    echo OS X 10.5 is the minimum requirement for building.
2437 hendricks2 34
    exit 1
1907 helixhorne 35
fi
2541 hendricks2 36
if [ `expr $darwinversion \< 10` == 1 ]; then
37
    build64=0
38
    # x86_64 is disabled by default on Leopard to avoid the additional hassles of getting libvpx installed into a PowerPC environment.
39
fi
2487 hendricks2 40
if [ `expr $darwinversion \> 9` == 1 ]; then
2437 hendricks2 41
    buildppc=0
2541 hendricks2 42
    # PPC is disabled by default on Snow Leopard for ease of installation.
2437 hendricks2 43
fi
2541 hendricks2 44
# All defaults can be overridden with the command-line parameters.
1907 helixhorne 45
 
2437 hendricks2 46
# Parse arguments:
47
for i in $*; do
48
    case $i in
2852 helixhorne 49
        # onlyzip, helix: For Helixhorned's convenience.
2437 hendricks2 50
        onlyzip)
2541 hendricks2 51
            buildmain=0
52
            buildtools=0
53
            pack=1
2437 hendricks2 54
        ;;
2852 helixhorne 55
        helix)
56
            iamhelix=1
57
            buildppc=0
58
            build86=1
59
            build64=1
60
            buildmain=1
61
            buildtools=1
62
            builddebug=0
63
            pack=1
64
        ;;
2958 helixhorne 65
        debughelix)
66
            iamhelix=1
67
            buildppc=0
68
            build86=0
69
            build64=1
70
            buildmain=1
71
            buildtools=0
72
            builddebug=1
73
            buildrelease=0
74
            pack=1
75
        ;;
3690 helixhorne 76
        dummyhelix)
77
            iamhelix=1
78
            buildppc=0
79
            build86=0
80
            build64=0
81
            buildmain=0
82
            buildtools=0
83
            builddebug=0
84
            buildrelease=0
85
            pack=0
86
            dummy=1
87
        ;;
3692 helixhorne 88
        clean)
89
            buildppc=0
90
            build86=0
91
            build64=0
92
            buildmain=0
93
            buildtools=0
94
            builddebug=0
95
            buildrelease=0
96
            pack=0
97
            doclean=1
98
        ;;
2541 hendricks2 99
        # For the convenience of universal distributors:
100
        dist)
101
            buildppc=1
102
            build86=1
103
            build64=1
104
            buildmain=1
105
            buildtools=0
106
            builddebug=1
107
            pack=1
108
        ;;
109
        disttools)
110
            buildppc=1
111
            build86=1
112
            build64=1
113
            buildmain=0
114
            buildtools=1
115
            builddebug=1
116
            pack=0
117
        ;;
118
        full)
119
            buildppc=1
120
            build86=1
121
            build64=1
122
            buildmain=1
123
            buildtools=1
124
            builddebug=1
125
            pack=1
126
        ;;
127
 
2852 helixhorne 128
        # misc.
129
        installtools)
130
            buildppc=0
131
            build86=0
132
            build64=0
133
            buildmain=0
134
            buildtools=0
135
            builddebug=0
136
            pack=0
137
            installtools=1
138
        ;;
139
 
2487 hendricks2 140
        --buildppc=*)
141
            buildppc=${i#*=}
2437 hendricks2 142
        ;;
2487 hendricks2 143
        --build86=*)
144
            build86=${i#*=}
2437 hendricks2 145
        ;;
2487 hendricks2 146
        --build64=*)
147
            build64=${i#*=}
2437 hendricks2 148
        ;;
149
 
2541 hendricks2 150
        --main=*)
151
            buildmain=${i#*=}
152
        ;;
2487 hendricks2 153
        --tools=*)
154
            buildtools=${i#*=}
2476 hendricks2 155
        ;;
156
 
2437 hendricks2 157
        --debug=*)
158
        builddebug=${i#*=}
159
        ;;
160
 
2541 hendricks2 161
        --pack=*)
162
            pack=${i#*=}
163
        ;;
164
 
3690 helixhorne 165
        --lastrev=*)
166
            lastrevision=${i#*=}
167
        ;;
168
 
2437 hendricks2 169
        *)
2541 hendricks2 170
            echo "usage: ./osxbuild.sh [options]"
171
            echo "options:"
172
            echo "    [--buildppc=<0|1>] [--build86=<0|1>] [--build64=<0|1>]"
173
            echo "    [--debug=<0|1>]"
174
            echo "    [--main=<0|1>] [--tools=<0|1>]"
175
            echo "    [--pack=<0|1>]"
176
            echo "presets:"
2852 helixhorne 177
            echo "    [onlyzip] [dist] [disttools] [full] [installtools]"
2437 hendricks2 178
            exit 1
179
        ;;
180
    esac
181
done
182
 
2541 hendricks2 183
# Mandatory disabled settings enforced:
184
if [ `expr $darwinversion \< 9` == 1 ]; then
185
    build64=0
186
    # x86_64 support did not exist before Leopard.
187
fi
188
if [ `expr $darwinversion \> 10` == 1 ]; then
189
    buildppc=0
190
    # PPC is disabled on Lion and up because support has been removed from the SDKs.
191
fi
192
 
2437 hendricks2 193
# Detect versioning systems and pull the revision number:
2852 helixhorne 194
rev=$(svn info 2> /dev/null | grep Revision | awk '{ print $2 }')
2402 hendricks2 195
vc=svn
2425 hendricks2 196
if [ -z "$rev" ]; then
2402 hendricks2 197
    vc=git
2852 helixhorne 198
    rev=$(git log | grep 'git-svn-id:' | head -n 1 | sed -E 's/.*\@([0-9]+).*/\1/')
199
    echo "Detected git repository, revision r$rev"
2402 hendricks2 200
fi
201
 
4565 hendricks2 202
if [ -z "$rev" ]; then
2402 hendricks2 203
    rev=unknown
204
    vc=none
205
fi
206
 
2851 helixhorne 207
function dobuildtools ()
208
{
209
    make veryclean
210
    local cmdline="$2"
211
    eval $cmdline
212
    if [ $? ]; then
213
        echo buildtools: "$1" build succeeded.
214
    else
215
        echo buildtools: "$1" build failed.
216
        exit 1
217
    fi
218
}
219
 
220
function dobuildem()  # build EDuke32 and Mapster32
221
{
222
    make veryclean
223
    local cmdline="$2"
224
    eval $cmdline
225
    if [ $? ]; then
226
        echo $1 build succeeded.
227
        cp "Mapster32.app/Contents/MacOS/mapster32" mapster32.$1
228
        cp "EDuke32.app/Contents/MacOS/eduke32" eduke32.$1
229
    else
230
        echo $1 build failed.
231
        exit 1
232
    fi
233
}
234
 
2487 hendricks2 235
# A little factoring:
5941 hendricks2 236
commonargs="WITHOUT_GTK=1"
4548 hendricks2 237
if [ $buildppc == 1 ] || [ `expr $darwinversion = 9` == 1 ]; then
2487 hendricks2 238
    commonargs="$commonargs DARWIN9=1"
239
fi
4548 hendricks2 240
if [ `expr $darwinversion = 10` == 1 ]; then
241
    commonargs="$commonargs DARWIN10=1"
242
fi
2487 hendricks2 243
 
3692 helixhorne 244
if [ $doclean == 1 ]; then
245
    cd build
246
    rm -f *{.x86,.x64,.ppc}
247
    cd ..
248
fi
249
 
2476 hendricks2 250
# Building the buildtools:
2852 helixhorne 251
if [ $buildtools$installtools != 00 ] && [ -d "build" ]; then
2476 hendricks2 252
 
2852 helixhorne 253
    makecmd="make -k"
2476 hendricks2 254
 
2852 helixhorne 255
    if [ $buildtools == 1 ]; then
256
        rm -f *{.x86,.x64,.ppc}
257
        make veryclean
258
        EXESUFFIX_OVERRIDE=.debug make veryclean
2476 hendricks2 259
 
2852 helixhorne 260
        if [ $build64 == 1 ]; then
261
            if [ $builddebug == 1 ]; then
262
                dobuildtools "x86_64 debug" \
5762 hendricks2 263
                    "ARCH=x86_64 EXESUFFIX_OVERRIDE=.debug.x64 $commonargs RELEASE=0 USE_LIBVPX=1 $makecmd utils"
2852 helixhorne 264
            fi
2476 hendricks2 265
 
2852 helixhorne 266
            dobuildtools "x86_64 release" \
5762 hendricks2 267
                "ARCH=x86_64 EXESUFFIX_OVERRIDE=.x64 $commonargs RELEASE=1 USE_LIBVPX=1 $makecmd utils"
2476 hendricks2 268
        fi
269
 
2852 helixhorne 270
        if [ $build86 == 1 ]; then
271
            if [ $builddebug == 1 ]; then
272
                dobuildtools "x86 debug" \
5762 hendricks2 273
                    "ARCH=i386 EXESUFFIX_OVERRIDE=.debug.x86 $commonargs RELEASE=0 USE_LIBVPX=0 $makecmd utils"
2852 helixhorne 274
            fi
2476 hendricks2 275
 
2852 helixhorne 276
            dobuildtools "x86 release" \
5762 hendricks2 277
                "ARCH=i386 EXESUFFIX_OVERRIDE=.x86 $commonargs RELEASE=1 USE_LIBVPX=0 $makecmd utils"
2476 hendricks2 278
        fi
279
 
2852 helixhorne 280
        if [ $buildppc == 1 ]; then
281
            if [ $builddebug == 1 ]; then
282
                dobuildtools "PowerPC debug" \
5762 hendricks2 283
                    "ARCH=ppc EXESUFFIX_OVERRIDE=.debug.ppc $commonargs RELEASE=0 USE_LIBVPX=0 $makecmd utils"
2852 helixhorne 284
            fi
2476 hendricks2 285
 
2852 helixhorne 286
            dobuildtools "PowerPC release" \
5762 hendricks2 287
                "ARCH=ppc EXESUFFIX_OVERRIDE=.ppc $commonargs RELEASE=1 USE_LIBVPX=0 $makecmd utils"
2476 hendricks2 288
        fi
289
 
4548 hendricks2 290
        mkdir -p tools
2852 helixhorne 291
 
292
        echo buildtools: Creating fat binaries.
293
        utils=`make printutils && EXESUFFIX_OVERRIDE=.debug make printutils`
2476 hendricks2 294
        for i in $utils; do
2852 helixhorne 295
            binaries=
296
            for j in ${i}.{x86,x64,ppc}; do
297
                if [ -f "$j" ]; then
298
                    binaries="$binaries $j"
299
                fi
300
            done
301
            if [ -n "$binaries" ]; then
302
                lipo -create $binaries -output $i || exit 1
4548 hendricks2 303
#                ln -f -s $i tools/$i || exit 1
304
                cp -f $i tools/$i || exit 1
2476 hendricks2 305
            fi
306
        done
307
    fi
308
 
2852 helixhorne 309
    if [ $installtools == 1 ]; then
310
        if [ -d "/opt/local/bin" ]; then
311
            echo buildtools: Installing to MacPorts search path.
312
            for i in $utils; do
313
                if [ -f "$i" ]; then
314
                    cp -f "$i" "/opt/local/bin/" || exit 1
315
                fi
316
            done
317
        fi
318
 
319
        if [ -d "/usr/local/bin" ]; then
320
            echo buildtools: Installing to Homebrew search path.
321
            for i in $utils; do
322
                if [ -f "$i" ]; then
323
                    cp -f "$i" "/usr/local/bin/" || exit 1
324
                fi
325
            done
326
        fi
2476 hendricks2 327
    fi
328
 
329
    cd ..
330
fi
331
 
3692 helixhorne 332
if [ $doclean == 1 ] || [ $buildmain == 1 ]; then
2437 hendricks2 333
    rm -f {eduke32,mapster32}{.debug,}{.x86,.x64,.ppc,}
3235 hendricks2 334
    rm -rf {$package/,}{EDuke32,Mapster32}{.debug,}.app
3692 helixhorne 335
fi
2352 helixhorne 336
 
3692 helixhorne 337
# The build process itself:
338
if [ $buildmain == 1 ]; then
2852 helixhorne 339
    if [ $iamhelix == 1 ]; then
340
        makecmd="make -j 2"
341
    else
342
        makecmd="make"
343
    fi
344
 
2437 hendricks2 345
    if [ $build64 == 1 ]; then
346
        if [ $builddebug == 1 ]; then
5762 hendricks2 347
            dobuildem debug.x64 "ARCH=x86_64 $commonargs RELEASE=0 $makecmd"
2437 hendricks2 348
        fi
1907 helixhorne 349
 
2958 helixhorne 350
        if [ $buildrelease == 1 ]; then
5762 hendricks2 351
            dobuildem x64 "ARCH=x86_64 $commonargs RELEASE=1 $makecmd"
2958 helixhorne 352
        fi
1907 helixhorne 353
    fi
354
 
2437 hendricks2 355
    if [ $build86 == 1 ]; then
356
        if [ $builddebug == 1 ]; then
5762 hendricks2 357
            dobuildem debug.x86 "ARCH=i386 $commonargs RELEASE=0 USE_LIBPNG=0 USE_LIBVPX=0 $makecmd"
2437 hendricks2 358
        fi
1907 helixhorne 359
 
5762 hendricks2 360
        dobuildem x86 "ARCH=i386 $commonargs RELEASE=1 USE_LIBPNG=0 USE_LIBVPX=0 $makecmd"
1907 helixhorne 361
    fi
1935 helixhorne 362
 
2437 hendricks2 363
    if [ $buildppc == 1 ]; then
364
        if [ $builddebug == 1 ]; then
5762 hendricks2 365
            dobuildem debug.ppc "ARCH=ppc $commonargs RELEASE=0 USE_LIBPNG=0 USE_LIBVPX=0 $makecmd"
2437 hendricks2 366
        fi
1935 helixhorne 367
 
5762 hendricks2 368
        dobuildem ppc "ARCH=ppc $commonargs RELEASE=1 USE_LIBPNG=0 USE_LIBVPX=0 $makecmd"
2430 helixhorne 369
    fi
1907 helixhorne 370
fi
371
 
2386 hendricks2 372
# Duplicating .app bundles for debug build:
2852 helixhorne 373
if [ $builddebug == 1 ] || [ $pack == 1 ]; then
2437 hendricks2 374
    for i in Mapster32 EDuke32; do
375
        if [ -d "$i.app" ]; then
376
            cp -RP "$i.app" "$i.debug.app"
377
        fi
378
    done
379
fi
2386 hendricks2 380
 
2437 hendricks2 381
# Begin assembling archive contents:
382
echo Creating fat binaries.
3690 helixhorne 383
 
384
success=$dummy
385
if [ $dummy == 0 ]; then
386
    for i in {eduke32,mapster32}{.debug,}; do
387
        binaries=
388
        for j in ${i}.{x86,x64,ppc}; do
389
            if [ -f "$j" ]; then
390
                binaries="$binaries $j"
391
                success=1
392
            fi
393
        done
394
 
395
        if [ -n "$binaries" ]; then
396
            lipo -create $binaries -output $i
397
            app=${i//eduke32/EDuke32}
398
            app=${app//mapster32/Mapster32}.app
399
            cp -f $i "$app/Contents/MacOS/${i%.debug}"
400
            mv -f "$app" "$package/"
2437 hendricks2 401
        fi
402
    done
3690 helixhorne 403
fi
2852 helixhorne 404
 
2437 hendricks2 405
# Almost done...
406
if [ $success == 1 ]; then
3235 hendricks2 407
    cd $package
408
 
2852 helixhorne 409
    echo "Generating README.OSX and Changelog.txt"
2386 hendricks2 410
 
2437 hendricks2 411
    # Output README.OSX:
412
    let "darwinversion -= 4"
1907 helixhorne 413
    echo "This archive was produced from revision $rev by the osxbuild.sh script." > README.OSX
2437 hendricks2 414
    echo "Built on: Mac OS X 10.$darwinversion" >> README.OSX
1935 helixhorne 415
    echo "EDuke32 home: http://www.eduke32.com" >> README.OSX
2437 hendricks2 416
    echo "OS X build discussion on Duke4.net: http://forums.duke4.net/topic/4242-building-eduke-on-mac-os-x/" >> README.OSX
2116 helixhorne 417
    echo "The 64-bit build in this archive has LibVPX (http://www.webmproject.org/code/)" >> README.OSX
2852 helixhorne 418
    echo "from MacPorts (http://www.macports.org/) and" >> README.OSX
419
    echo "LibPNG from Fink (http://www.finkproject.org/) statically linked into it." >> README.OSX
2437 hendricks2 420
 
2455 hendricks2 421
    # Generate Changelog:
3690 helixhorne 422
    if [ -z $lastrevision ]; then
423
        lastrevision=$(ls -A1 eduke32-osx* | tail -n1 | cut -d- -f3 | cut -d. -f1)
2455 hendricks2 424
 
3690 helixhorne 425
        if [ -z $lastrevision ]; then
426
            let lastrevision=rev-1
427
        elif [ $lastrevision -lt $rev ]; then
428
            let lastrevision+=1
429
        else
430
            let lastrevision=rev-1
431
        fi
2455 hendricks2 432
    fi
433
 
3690 helixhorne 434
    echo "Using r$lastrevision as last revision for change log"
435
 
2455 hendricks2 436
    if [ "$vc" == "svn" ]; then
2852 helixhorne 437
        svn log -r $rev:$lastrevision > Changelog.txt
2455 hendricks2 438
    elif [ "$vc" == "git" ]; then
2852 helixhorne 439
        commitid=$(git log --grep="git-svn-id: .*@$lastrevision" -n 1 | grep -E '^commit ' | head -n 1 | awk '{print $2}')
440
        # Get the commit messages and strip the email addresses
441
        git log $commitid..HEAD | sed 's/<.*@.*>//g' > Changelog.txt
2455 hendricks2 442
    fi
443
 
444
    # Package
2541 hendricks2 445
    if [ $pack == 1 ]; then
446
        arfilename="eduke32-osx-$rev.zip"
2852 helixhorne 447
        echo "Packing distribution into $arfilename"
2541 hendricks2 448
        rm -f "$arfilename"
3235 hendricks2 449
        zip -r -y "$arfilename" * -x "*.svn*" "*.git*" "*.dll"
2541 hendricks2 450
    fi
3235 hendricks2 451
    cd ..
1907 helixhorne 452
fi