build.sh 31.8 KB
Newer Older
Oliver Bock's avatar
Oliver Bock committed
1
#!/bin/bash
Oliver Bock's avatar
Oliver Bock committed
2

Oliver Bock's avatar
Oliver Bock committed
3
###########################################################################
4
#   Copyright (C) 2008-2009 by Oliver Bock                                #
Oliver Bock's avatar
Oliver Bock committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#   oliver.bock[AT]aei.mpg.de                                             #
#                                                                         #
#   This file is part of Einstein@Home.                                   #
#                                                                         #
#   Einstein@Home is free software: you can redistribute it and/or modify #
#   it under the terms of the GNU General Public License as published     #
#   by the Free Software Foundation, version 2 of the License.            #
#                                                                         #
#   Einstein@Home is distributed in the hope that it will be useful,      #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with Einstein@Home. If not, see <http://www.gnu.org/licenses/>. #
#                                                                         #
###########################################################################


Oliver Bock's avatar
Oliver Bock committed
24
25
26
### globals ###############################################################

ROOT=`pwd`
27
28
PATH_ORG="$PATH"
PATH_MINGW="$PATH"
29
LOGFILE=$ROOT/build.log
30

Oliver Bock's avatar
Oliver Bock committed
31
32
TAG_GFXAPPS="current_gfx_apps"

Oliver Bock's avatar
Oliver Bock committed
33
TARGET=0
34
TARGET_LINUX=1
35
36
37
TARGET_MAC=2
TARGET_WIN32=3
TARGET_DOC=4
Oliver Bock's avatar
Oliver Bock committed
38

39
40
41
42
43
BUILDSTATE=0
BS_PREREQUISITES=1
BS_PREPARE_TREE=2
BS_BUILD_SDL=3
BS_BUILD_FREETYPE=4
Oliver Bock's avatar
Oliver Bock committed
44
45
BS_BUILD_LIBXML=5
BS_BUILD_OGLFT=6
46
47
48
BS_BUILD_BOINC=7
BS_PREPARE_MINGW=8
BS_BUILD_MINGW=9
Oliver Bock's avatar
Oliver Bock committed
49
50
51
52
53
BS_BUILD_SDL_MINGW=10
BS_BUILD_FREETYPE_MINGW=11
BS_BUILD_LIBXML_MINGW=12
BS_BUILD_OGLFT_MINGW=13
BS_BUILD_BOINC_MINGW=14
54
55

### functions (tools) #############################################################
Oliver Bock's avatar
Oliver Bock committed
56

Oliver Bock's avatar
Oliver Bock committed
57
58
failure()
{
59
60
61
    echo "************************************" | tee -a $LOGFILE
    echo "Error detected! Stopping build!" | tee -a $LOGFILE
    echo "`date`" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
62
63

    if [ -f "$LOGFILE" ]; then
64
65
66
67
68
        echo "------------------------------------"
        echo "Please check logfile: `basename $LOGFILE`"
        echo "These are the final ten lines:"
        echo "------------------------------------"
        tail -n 14 $LOGFILE | head -n 10
Oliver Bock's avatar
Oliver Bock committed
69
70
    fi

71
    echo "************************************" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
72
73
74
75

    exit 1
}

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

distclean()
{
    cd $ROOT || failure

    echo "Purging build system..." | tee -a $LOGFILE

    rm -rf 3rdparty || failure
    rm -rf build || failure
    rm -rf install || failure
    rm -rf doc/html || failure
    rm -f doc/*.tag || failure

    rm -f .lastbuild || failure
    rm -f .buildstate || failure
}


check_last_build()
{
    echo "Checking previous build target..." | tee -a $LOGFILE

    LASTBUILD=`cat .lastbuild 2>/dev/null`

    if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
        cd $ROOT || failure
        echo "Build target changed! Purging build and install trees..." | tee -a $LOGFILE
        rm -rf build >> $LOGFILE || failure
        rm -rf install >> $LOGFILE || failure
        prepare_tree || failure
    fi

    echo "$1" > .lastbuild || failure

    return 0
}


check_build_state()
{
    echo "Checking for previous build checkpoints..." | tee -a $LOGFILE

    if [ ! -f .buildstate ]; then
        cd $ROOT || failure
        echo "No previous build checkpoints found! Starting from scratch..." | tee -a $LOGFILE
    else
        BUILDSTATE=`cat $ROOT/.buildstate 2>/dev/null`
        echo "Recovering previous build..."
    fi

    return 0
}


store_build_state()
{
    echo "Saving build checkpoint..." | tee -a $LOGFILE
    echo "$1" > $ROOT/.buildstate || failure

    return 0
}


### functions (features) #############################################################

Oliver Bock's avatar
Oliver Bock committed
141
142
check_prerequisites()
{
143
144
145
    if [ $BUILDSTATE -ge $BS_PREREQUISITES ]; then
        return 0
    fi
Oliver Bock's avatar
Oliver Bock committed
146

147
148
149
    echo "Checking prerequisites..." | tee -a $LOGFILE

    # required toolchain
Oliver Bock's avatar
Oliver Bock committed
150
    TOOLS="automake autoconf m4 cmake wget svn cvs tar patch gcc g++ ld libtool ar lex yacc pkg-config hg"
151
152
153
154
155
156
157
158
159

    for tool in $TOOLS; do
        if ! ( type $tool >/dev/null 2>&1 ); then
            echo "Missing \"$tool\" which is a required tool!" | tee -a $LOGFILE
            return 1
        fi
    done

    return 0
Oliver Bock's avatar
Oliver Bock committed
160
161
162
}


163
prepare_tree()
Oliver Bock's avatar
Oliver Bock committed
164
{
165
166
167
    if [ $BUILDSTATE -ge $BS_PREPARE_TREE ]; then
        return 0
    fi
168

169
170
171
172
173
174
175
176
    echo "Preparing tree..." | tee -a $LOGFILE
    mkdir -p 3rdparty >> $LOGFILE || failure
    mkdir -p install/bin >> $LOGFILE || failure
    mkdir -p install/include >> $LOGFILE || failure
    mkdir -p install/lib >> $LOGFILE || failure

    store_build_state $BS_PREPARE_TREE
    return 0
177
178
179
}


Oliver Bock's avatar
Oliver Bock committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
prepare_version_header()
{
    HEADER_FILE="$ROOT/src/erp_git_version.h"

    cd $ROOT || failure

    echo "Retrieving git version information..." | tee -a $LOGFILE

    if [ -d .git ]; then
        GIT_LOG=`git log -n1 --pretty="format:%H"` || failure
        HOST=`hostname` || failure
    fi

    echo "#ifndef ERP_GIT_VERSION_H" > $HEADER_FILE || failure
    echo "#define ERP_GIT_VERSION_H" >> $HEADER_FILE || failure
    echo "" >> $HEADER_FILE || failure

    if [ "no$GIT_LOG" != "no" ]; then
        echo "#define ERP_GIT_VERSION \"$GIT_LOG ($HOST:$PWD)\"" >> $HEADER_FILE || failure
    else
        echo "#define ERP_GIT_VERSION \"unknown (git repository not found!)\"" >> $HEADER_FILE || failure
    fi

    echo "" >> $HEADER_FILE || failure
    echo "#endif" >> $HEADER_FILE || failure
}


208
prepare_mingw()
209
{
210
211
212
    if [ $BUILDSTATE -ge $BS_PREPARE_MINGW ]; then
        return 0
    fi
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
    cd $ROOT || failure

    echo "Preparing MinGW source tree..." | tee -a $LOGFILE
    mkdir -p 3rdparty/mingw/xscripts >> $LOGFILE || failure
    cd 3rdparty/mingw/xscripts || failure

    if [ -d CVS ]; then
        echo "Updating MinGW build script..." | tee -a $LOGFILE
        cvs update -C >> $LOGFILE 2>&1 || failure
    else
        cd .. || failure
        echo "Retrieving MinGW build script (this may take a while)..." | tee -a $LOGFILE
        cvs -z3 -d:pserver:anonymous@mingw.cvs.sourceforge.net:/cvsroot/mingw checkout -P xscripts >> $LOGFILE 2>&1 || failure
    fi

    echo "Preparing MinGW build script..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/mingw/xscripts || failure
    # note: svn has no force/overwrite switch. the file might not be updated when patched
    patch x86-mingw32-build.sh.conf < $ROOT/patches/x86-mingw32-build.sh.conf.patch >> $LOGFILE || failure
    chmod +x x86-mingw32-build.sh >> $LOGFILE || failure

    store_build_state $BS_PREPARE_MINGW
    return 0
237
238
239
}


240
prepare_sdl()
241
{
242
243
244
245
246
    echo "Preparing SDL..." | tee -a $LOGFILE
    mkdir -p $ROOT/3rdparty/sdl >> $LOGFILE || failure
    mkdir -p $ROOT/build/sdl >> $LOGFILE || failure

    cd $ROOT/3rdparty/sdl || failure
Oliver Bock's avatar
Oliver Bock committed
247
    if [ -d .hg ]; then
248
        echo "Updating SDL..." | tee -a $LOGFIL
Oliver Bock's avatar
Oliver Bock committed
249
250
        # local changes (patches) are reverted, hence also updated
        hg update --clean >> $LOGFILE 2>&1 || failure
251
252
    else
        echo "Retrieving SDL (this may take a while)..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
253
        hg clone -r SDL-1.2 http://hg.libsdl.org/SDL . >> $LOGFILE 2>&1 || failure
254
    fi
255

256
    return 0
257
258
259
}


260
prepare_freetype()
261
{
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    echo "Preparing Freetype2..." | tee -a $LOGFILE
    mkdir -p $ROOT/build/freetype2 >> $LOGFILE || failure

    echo "Retrieving Freetype2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty || failure
    wget http://mesh.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.5.tar.bz2 >> $LOGFILE 2>&1 || failure
    tar -xjf freetype-2.3.5.tar.bz2 >> $LOGFILE 2>&1 || failure
    rm freetype-2.3.5.tar.bz2 >> $LOGFILE 2>&1 || failure
    # substitute old source tree
    rm -rf freetype2 >> $LOGFILE 2>&1 || failure
    mv freetype-2.3.5 freetype2 >> $LOGFILE 2>&1 || failure

    return 0
}
Oliver Bock's avatar
Oliver Bock committed
276

277
278
279
280
281
282
283
284
285

prepare_libxml()
{
    echo "Preparing libxml2..." | tee -a $LOGFILE
    mkdir -p $ROOT/build/libxml2 >> $LOGFILE || failure

    echo "Retrieving libxml2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty || failure
    rm -f libxml2-sources-2.6.32.tar.gz >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
286
    wget --passive-ftp ftp://xmlsoft.org/libxml2/old/libxml2-sources-2.6.32.tar.gz >> $LOGFILE 2>&1 || failure
287
288
289
290
291
292
293
    tar -xzf libxml2-sources-2.6.32.tar.gz >> $LOGFILE 2>&1 || failure
    rm libxml2-sources-2.6.32.tar.gz >> $LOGFILE 2>&1 || failure
    # substitute old source tree
    rm -rf libxml2 >> $LOGFILE 2>&1 || failure
    mv libxml2-2.6.32 libxml2 >> $LOGFILE 2>&1 || failure

    return 0
Oliver Bock's avatar
Oliver Bock committed
294
295
296
}


297
prepare_oglft()
Oliver Bock's avatar
Oliver Bock committed
298
{
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
    echo "Preparing OGLFT..." | tee -a $LOGFILE
    mkdir -p $ROOT/3rdparty/oglft >> $LOGFILE || failure
    mkdir -p $ROOT/build/oglft >> $LOGFILE || failure

    cd $ROOT/3rdparty/oglft || failure
    if [ -d .svn ]; then
        echo "Updating OGLFT..." | tee -a $LOGFILE
        # make sure local changes (patches) are reverted, hence also updated
        svn revert -R . >> $LOGFILE  2>&1 || failure
        svn update >> $LOGFILE  2>&1 || failure
    else
        echo "Retrieving OGLFT (this may take a while)..." | tee -a $LOGFILE
        svn checkout http://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $LOGFILE 2>&1 || failure
    fi
}
Oliver Bock's avatar
Oliver Bock committed
314

Oliver Bock's avatar
Oliver Bock committed
315

316
317
318
319
320
prepare_boinc()
{
    echo "Preparing BOINC..." | tee -a $LOGFILE
    mkdir -p $ROOT/3rdparty/boinc >> $LOGFILE || failure
    mkdir -p $ROOT/build/boinc >> $LOGFILE || failure
Oliver Bock's avatar
Oliver Bock committed
321
 
322
    cd $ROOT/3rdparty/boinc || failure
Oliver Bock's avatar
Oliver Bock committed
323
324
325
326
327
328
329
330
331
    if [ -d .git ]; then
        echo "Updating BOINC (tag: $1)..." | tee -a $LOGFILE
        # make sure local changes (patches) are reverted to ensure fast-forward merge
        git checkout -f $1 >> $LOGFILE  2>&1 || failure
        # update tag info
        git remote update >> $LOGFILE  2>&1 || failure
        git fetch --tags >> $LOGFILE  2>&1 || failure
        # checkout build revision
        git checkout -f $1 >> $LOGFILE  2>&1 || failure
332
    else
Oliver Bock's avatar
Oliver Bock committed
333
334
335
336
337
338
339
340
        # workaround for old git versions
        rm -rf $ROOT/3rdparty/boinc >> $LOGFILE || failure
 
        echo "Retrieving BOINC (tag: $1) (this may take a while)..." | tee -a $LOGFILE
        cd $ROOT/3rdparty || failure
        git clone git://git.aei.uni-hannover.de/shared/einsteinathome/boinc.git boinc >> $LOGFILE 2>&1 || failure
        cd $ROOT/3rdparty/boinc || failure
        git checkout $1 >> $LOGFILE  2>&1 || failure
341
    fi
Oliver Bock's avatar
Oliver Bock committed
342
 
343
    return 0
Oliver Bock's avatar
Oliver Bock committed
344
345
346
}


347
build_sdl()
Oliver Bock's avatar
Oliver Bock committed
348
{
349
350
351
    if [ $BUILDSTATE -ge $BS_BUILD_SDL ]; then
        return 0
    fi
Oliver Bock's avatar
Oliver Bock committed
352

353
354
355
356
357
358
359
360
    prepare_sdl || failure

    echo "Building SDL (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/sdl || failure
    chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
    ./autogen.sh >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/sdl || failure
361
    if [ "$1" == "$TARGET_MAC" ]; then
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
        $ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --enable-screensaver=yes --enable-video-x11=no >> $LOGFILE 2>&1 || failure
    else
        $ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --enable-screensaver=yes >> $LOGFILE 2>&1 || failure 
    fi
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed SDL!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_SDL || failure
    return 0
}


build_freetype()
{
    if [ $BUILDSTATE -ge $BS_BUILD_FREETYPE ]; then
        return 0
    fi

    prepare_freetype || failure

    echo "Building Freetype2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/freetype2 || failure
    chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
    ./autogen.sh >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/freetype2 || failure
    # note: freetype (or sdl?) probably doesn't need *no* configure when static -> ansi build, see readme!
    $ROOT/3rdparty/freetype2/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed Freetype2!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_FREETYPE || failure
    return 0
}


build_libxml()
{
    if [ $BUILDSTATE -ge $BS_BUILD_LIBXML ]; then
        return 0
    fi

    prepare_libxml || failure

    echo "Building libxml2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/libxml2 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/libxml2 || failure
    $ROOT/3rdparty/libxml2/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed libxml2!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_LIBXML || failure
    return 0
}


build_oglft()
{
    if [ $BUILDSTATE -ge $BS_BUILD_OGLFT ]; then
        return 0
    fi

    prepare_oglft || failure

    echo "Patching OGLFT..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/oglft || failure
    # note: svn has no force/overwrite switch. patched files might not be updated
    # patch: use fixed settings for freetype, deactivate FindFreetype
    FREETYPE2_INCLUDE_DIR="$ROOT/install/include"
    FREETYPE2_LIBRARIES="$ROOT/install/lib/libfreetype.a"
    patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.oglft.patch >> $LOGFILE 2>&1 || failure
    echo "Building OGLFT..." | tee -a $LOGFILE
    cd $ROOT/build/oglft || failure
    # TODO: do we wanna create universal binaries on mac? If so, add -DCMAKE_OSX_ARCHITECTURES=ppc;i386
    cmake -DFREETYPE2_INCLUDE_DIR="$FREETYPE2_INCLUDE_DIR" -DFREETYPE2_LIBRARIES="$FREETYPE2_LIBRARIES" $ROOT/3rdparty/oglft >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    mkdir -p $ROOT/install/include/oglft >> $LOGFILE 2>&1 || failure
    cp OGLFT.h $ROOT/install/include/oglft >> $LOGFILE 2>&1 || failure
    cp liboglft/liboglft.a $ROOT/install/lib >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed OGLFT!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_OGLFT || failure
    return 0
}


build_boinc()
{
    if [ $BUILDSTATE -ge $BS_BUILD_BOINC ]; then
        return 0
    fi

Oliver Bock's avatar
Oliver Bock committed
458
    prepare_boinc $TAG_GFXAPPS || failure
459
460
461
462
463
464
465

    echo "Configuring BOINC..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/boinc || failure
    chmod +x _autosetup >> $LOGFILE 2>&1 || failure
    ./_autosetup >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/boinc || failure
466
    if [ "$1" == "$TARGET_MAC" ]; then
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
        export CPPFLAGS=-I/sw/include
        $ROOT/3rdparty/boinc/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --disable-server --disable-client --with-apple-opengl-framework --enable-install-headers --enable-libraries --disable-manager --disable-fcgi >> $LOGFILE 2>&1 || failure
    elif [ -d "/usr/local/ssl" ]; then
        echo "Using local SSL library..." | tee -a $LOGFILE
        $ROOT/3rdparty/boinc/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --disable-server --disable-client --enable-install-headers --enable-libraries --disable-manager --disable-fcgi CPPFLAGS=-I/usr/local/ssl/include LDFLAGS=-L/usr/local/ssl/lib >> $LOGFILE 2>&1 || failure
    else
        $ROOT/3rdparty/boinc/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --disable-server --disable-client --enable-install-headers --enable-libraries --disable-manager --disable-fcgi >> $LOGFILE 2>&1 || failure
    fi
    echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed BOINC!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_BOINC || failure
    return 0
Oliver Bock's avatar
Oliver Bock committed
482
483
}

Oliver Bock's avatar
Oliver Bock committed
484

Oliver Bock's avatar
Oliver Bock committed
485
486
build_mingw()
{
487
488
489
490
    if [ $BUILDSTATE -ge $BS_BUILD_MINGW ]; then
        return 0
    fi
    TARGET_HOST=i586-pc-mingw32
Oliver Bock's avatar
Oliver Bock committed
491

492
493
494
495
    echo "Building MinGW (this will take quite a while)..." | tee -a $LOGFILE
    # note: the script's current config for unattended setup expects it to be run from three levels below root!
    cd $ROOT/3rdparty/mingw/xscripts || failure
    ./x86-mingw32-build.sh --unattended $TARGET_HOST >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
496

497
498
    store_build_state $BS_BUILD_MINGW
    return 0
Oliver Bock's avatar
Oliver Bock committed
499
500
501
}


502
set_mingw()
503
{
504
505
506
507
508
509
510
    # general config
    PREFIX=$ROOT/install
    TARGET_HOST=i586-pc-mingw32
    BUILD_HOST=i386-linux
    PATH_MINGW="$PREFIX/bin:$PREFIX/$TARGET_HOST/bin:$PATH"
    PATH="$PATH_MINGW"
    export PATH
Oliver Bock's avatar
Oliver Bock committed
511
512
}

513

514
build_sdl_mingw()
Oliver Bock's avatar
Oliver Bock committed
515
{
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
    if [ $BUILDSTATE -ge $BS_BUILD_SDL_MINGW ]; then
        return 0
    fi

    prepare_sdl || failure

    echo "Patching SDL..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/sdl/src/video/wincommon || failure
    # patch: amend window class name (required by BOINC v6 screensaver!)
    patch < $ROOT/patches/SDL_sysevents.c.patch >> $LOGFILE 2>&1 || failure
    echo "Building SDL (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/sdl || failure
    chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
    ./autogen.sh >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    if [ -f "$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-sdl-config" ]; then
        SDL_CONFIG="$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-sdl-config"
        export SDL_CONFIG
        echo "Cross-compile SDL_CONFIG: $SDL_CONFIG" >> $LOGFILE
    fi
    cd $ROOT/build/sdl || failure
    $ROOT/3rdparty/sdl/configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX --enable-shared=no --enable-static=yes --enable-screensaver=yes >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed SDL!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_SDL_MINGW || failure
    return 0
}


build_freetype_mingw()
{
    if [ $BUILDSTATE -ge $BS_BUILD_FREETYPE_MINGW ]; then
        return 0
    fi

    prepare_freetype || failure

    echo "Patching Freetype2..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/freetype2/builds || failure
    # patch: deactivating invocation of apinames (would run win32 binary on linux host)
    patch < $ROOT/patches/freetype2.exports.mk.patch >> $LOGFILE 2>&1 || failure
    echo "Building Freetype2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/freetype2 || failure
    chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
    ./autogen.sh >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    if [ -f "$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-freetype-config" ]; then
        FT_CONFIG="$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-freetype-config"
        export FT_CONFIG
        echo "Cross-compile FT_CONFIG: $FT_CONFIG" >> $LOGFILE
    fi
    cd $ROOT/build/freetype2 || failure
    # note: freetype (or sdl?) probably doesn't need *no* configure when static -> ansi build, see readme!
    $ROOT/3rdparty/freetype2/configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX --enable-shared=no --enable-static=yes >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed Freetype2!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_FREETYPE_MINGW || failure
    return 0
}


build_libxml_mingw()
{
    if [ $BUILDSTATE -ge $BS_BUILD_LIBXML_MINGW ]; then
        return 0
    fi

    prepare_libxml || failure

    echo "Building libxml2 (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/libxml2 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    if [ -f "$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-xml2-config" ]; then
        LIBXML2_CONFIG="$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-xml2-config"
        export LIBXML2_CONFIG
        echo "Cross-compile LIBXML2_CONFIG: $LIBXML2_CONFIG" >> $LOGFILE
    fi
    cd $ROOT/build/libxml2 || failure
    $ROOT/3rdparty/libxml2/configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX --enable-shared=no --enable-static=yes >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed libxml2!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_LIBXML_MINGW || failure
    return 0
}


build_oglft_mingw()
{
    if [ $BUILDSTATE -ge $BS_BUILD_OGLFT_MINGW ]; then
        return 0
    fi

    prepare_oglft || failure

    echo "Patching OGLFT..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/oglft || failure
    # note: svn has no force/overwrite switch. patched files might not be updated
    # patch: use fixed settings for freetype, deactivate FindFreetype
    FREETYPE2_INCLUDE_DIR="$ROOT/install/include"
    FREETYPE2_LIBRARIES="$ROOT/install/lib/libfreetype.a"
    patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.oglft.patch >> $LOGFILE 2>&1 || failure
    cp $ROOT/patches/toolchain-linux-mingw.oglft.cmake $ROOT/build/oglft >> $LOGFILE 2>&1 || failure
    export OGLFT_INSTALL=$ROOT/install
    echo "Building OGLFT..." | tee -a $LOGFILE
    cd $ROOT/build/oglft || failure
    cmake -DCMAKE_TOOLCHAIN_FILE="toolchain-linux-mingw.oglft.cmake" -DFREETYPE2_INCLUDE_DIR="$FREETYPE2_INCLUDE_DIR" -DFREETYPE2_LIBRARIES="$FREETYPE2_LIBRARIES" $ROOT/3rdparty/oglft >> $LOGFILE 2>&1 || failure
    make >> $LOGFILE 2>&1 || failure
    mkdir -p $ROOT/install/include/oglft >> $LOGFILE 2>&1 || failure
    cp OGLFT.h $ROOT/install/include/oglft >> $LOGFILE 2>&1 || failure
    cp liboglft/liboglft.a $ROOT/install/lib >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed OGLFT!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_OGLFT_MINGW || failure
    return 0
}

Oliver Bock's avatar
Oliver Bock committed
638
build_boinc_mingw()
639
640
641
642
643
{
    if [ $BUILDSTATE -ge $BS_BUILD_BOINC_MINGW ]; then
        return 0
    fi

Oliver Bock's avatar
Oliver Bock committed
644
    prepare_boinc $TAG_GFXAPPS || failure
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

    echo "Patching BOINC..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/boinc/lib || failure
    # patch: fix a couple of BOINC vs. MinGW issues
    patch boinc_win.h < $ROOT/patches/boinc.boinc_win.h.minggw.patch >> $LOGFILE 2>&1 || failure
    patch filesys.cpp < $ROOT/patches/boinc.filesys.cpp.mingw.patch >> $LOGFILE 2>&1 || failure
    echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
    cd $ROOT/3rdparty/boinc || failure
    chmod +x _autosetup >> $LOGFILE 2>&1 || failure
    ./_autosetup >> $LOGFILE 2>&1 || failure
    chmod +x configure >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/boinc || failure
    # note: configure is still required but we don't use the generated Makefile
    $ROOT/3rdparty/boinc/configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$ROOT/install --includedir=$ROOT/install/include --oldincludedir=$ROOT/install/include --enable-shared=no --enable-static=yes --disable-server --disable-client --enable-install-headers --enable-libraries --disable-manager --disable-fcgi >> $LOGFILE 2>&1 || failure
    cd $ROOT/build/boinc/api || failure
    cp $ROOT/3rdparty/boinc/api/Makefile.mingw . >> $LOGFILE 2>&1 || failure
    # patch: add graphics2 and customize build path (see below)
    patch Makefile.mingw < $ROOT/patches/boinc.Makefile.mingw.patch >> $LOGFILE 2>&1 || failure
    export BOINC_SRC=$ROOT/3rdparty/boinc || failure
    cd $ROOT/build/boinc || failure
    # required for out-of-tree build
    cp config.h $ROOT/3rdparty/boinc >> $LOGFILE 2>&1 || failure
    make -f api/Makefile.mingw >> $LOGFILE 2>&1 || failure
    cp $ROOT/build/boinc/libboinc.a $ROOT/install/lib >> $LOGFILE 2>&1 || failure
    mkdir -p $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/build/boinc/config.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/build/boinc/version.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/api/boinc_api.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/api/graphics2.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/app_ipc.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/boinc_win.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/common_defs.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/diagnostics.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/diagnostics_win.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/filesys.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/hostinfo.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/proxy_info.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/prefs.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/miofile.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/mfile.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/parse.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    cp $ROOT/3rdparty/boinc/lib/util.h $ROOT/install/include/boinc >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed BOINC!" | tee -a $LOGFILE

    store_build_state $BS_BUILD_BOINC_MINGW || failure
    return 0
691
692
693
}


Oliver Bock's avatar
Oliver Bock committed
694
695
build_starsphere()
{
696
697
698
699
700
701
    # make sure ORC is always compiled for host platform (it's exexuted during starsphere build!)
    echo "Preparing Starsphere..." | tee -a $LOGFILE
    mkdir -p $ROOT/build/orc >> $LOGFILE || failure
    mkdir -p $ROOT/build/framework >> $LOGFILE || failure
    mkdir -p $ROOT/build/starsphere >> $LOGFILE || failure
    export PATH=$PATH_ORG
702

Oliver Bock's avatar
Oliver Bock committed
703
704
    prepare_version_header || failure

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
    echo "Building Starsphere [ORC]..." | tee -a $LOGFILE
    export ORC_SRC=$ROOT/src/orc || failure
    export ORC_INSTALL=$ROOT/install || failure
    cd $ROOT/build/orc || failure
    cp $ROOT/src/orc/Makefile . >> $LOGFILE 2>&1 || failure
    make $2 >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed Starsphere [ORC]!" | tee -a $LOGFILE

    # set main include directory
    if [ "$1" == "$TARGET_WIN32" ]; then
        export PATH=$PATH_MINGW
    else
        export PATH=$PATH_ORG
    fi

    echo "Building Starsphere [Framework]..." | tee -a $LOGFILE
    export FRAMEWORK_SRC=$ROOT/src/framework || failure
    export FRAMEWORK_INSTALL=$ROOT/install || failure
    cd $ROOT/build/framework || failure
    if [ "$1" == "$TARGET_WIN32" ]; then
        cp -f $ROOT/src/framework/Makefile.mingw Makefile >> $LOGFILE 2>&1 || failure
    else
        cp -f $ROOT/src/framework/Makefile . >> $LOGFILE 2>&1 || failure
    fi
    make $2 >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed Starsphere [Framework]!" | tee -a $LOGFILE

    echo "Building Starsphere [Application]..." | tee -a $LOGFILE
    export STARSPHERE_SRC=$ROOT/src/starsphere || failure
    export STARSPHERE_INSTALL=$ROOT/install || failure
    cd $ROOT/build/starsphere || failure
    cp $ROOT/src/starsphere/*.res . >> $LOGFILE 2>&1 || failure
739
    if [ "$1" == "$TARGET_MAC" ]; then
740
741
742
743
744
745
746
747
748
749
750
        cp -f $ROOT/src/starsphere/Makefile.macos Makefile >> $LOGFILE 2>&1 || failure
    elif [ "$1" == "$TARGET_WIN32" ]; then
        cp -f $ROOT/src/starsphere/Makefile.mingw Makefile >> $LOGFILE 2>&1 || failure
    else
        cp -f $ROOT/src/starsphere/Makefile . >> $LOGFILE 2>&1 || failure
    fi
    make $2 >> $LOGFILE 2>&1 || failure
    make install >> $LOGFILE 2>&1 || failure
    echo "Successfully built and installed Starsphere [Application]!" | tee -a $LOGFILE

    return 0
Oliver Bock's avatar
Oliver Bock committed
751
}
Oliver Bock's avatar
Oliver Bock committed
752

Oliver Bock's avatar
Oliver Bock committed
753

Oliver Bock's avatar
Oliver Bock committed
754
755
build_linux()
{
756
757
758
759
760
761
762
763
764
    echo "Important for an official build: let CC and CXX point to gcc/g++ 4.0.3!"
    build_sdl || failure
    build_freetype || failure
    build_libxml || failure
    build_oglft || failure
    build_boinc || failure
    build_starsphere $1 $2 || failure

    return 0
Oliver Bock's avatar
Oliver Bock committed
765
766
767
768
769
}


build_mac()
{
770
771
772
773
774
775
776
777
    build_sdl $1 || failure
    build_freetype || failure
    build_libxml || failure
    build_oglft || failure
    build_boinc $1 || failure
    build_starsphere $1 || failure

    return 0
Oliver Bock's avatar
Oliver Bock committed
778
779
780
781
782
}


build_win32()
{
Oliver Bock's avatar
Oliver Bock committed
783
    export CPPFLAGS="-D_WIN32_WINDOWS=0x0410 $CPPFLAGS"
784
785
786
787
788
789
790
791

    prepare_mingw || failure
    build_mingw || failure
    set_mingw || failure
    build_sdl_mingw || failure
    build_freetype_mingw || failure
    build_libxml_mingw || failure
    build_oglft_mingw || failure
Oliver Bock's avatar
Oliver Bock committed
792
    build_boinc_mingw || failure
793
794
795
    build_starsphere $TARGET_WIN32 || failure

    return 0
Oliver Bock's avatar
Oliver Bock committed
796
797
}

Oliver Bock's avatar
Oliver Bock committed
798

Oliver Bock's avatar
Oliver Bock committed
799
800
print_usage()
{
801
802
803
804
805
806
807
    cd $ROOT

    echo "*************************"
    echo "Usage: `basename $0` <target>"
    echo
    echo "Available targets:"
    echo "  --linux"
808
    echo "  --mac"
809
810
811
812
813
814
815
    echo "  --win32"
    echo "  --doc"
    echo "*************************"

    echo "Wrong usage. Stopping!" >> $LOGFILE

    return 0
Oliver Bock's avatar
Oliver Bock committed
816
817
818
}


Oliver Bock's avatar
Oliver Bock committed
819
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
820

821
822
823
824
echo "************************************" | tee -a $LOGFILE
echo "Starting new build!" | tee -a $LOGFILE
echo "`date`" | tee -a $LOGFILE
echo "************************************" | tee -a $LOGFILE
825

Oliver Bock's avatar
Oliver Bock committed
826
# crude command line parsing :-)
827

Oliver Bock's avatar
Oliver Bock committed
828
829
830
if [ $# -ne 1 ]; then
  print_usage
  exit 1
831
832
fi

Oliver Bock's avatar
Oliver Bock committed
833
case "$1" in
834
835
836
837
    "--linux")
        TARGET=$TARGET_LINUX
        check_last_build "$1" || failure
        echo "Building linux version:" | tee -a $LOGFILE
838
        check_build_state || failure
839
        ;;
840
841
    "--mac")
        TARGET=$TARGET_MAC
842
843
        check_last_build "$1" || failure
        echo "Building mac (Intel) version:" | tee -a $LOGFILE
844
        check_build_state || failure
845
846
847
848
849
        ;;
    "--win32")
        TARGET=$TARGET_WIN32
        check_last_build "$1" || failure
        echo "Building win32 version:" | tee -a $LOGFILE
850
        check_build_state || failure
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
        ;;
    "--doc")
        TARGET=$TARGET_DOC
        echo "Building documentation..." | tee -a $LOGFILE
        ;;
    "--distclean")
        distclean || failure
        exit 0
        ;;
    "--starsphere")
        # "hidden" bonus option :-)
        TARGET=$TARGET_LINUX
        build_starsphere $TARGET "debug" || failure
        exit 0
        ;;
    *)
        print_usage
        exit 1
        ;;
Oliver Bock's avatar
Oliver Bock committed
870
esac
871

Oliver Bock's avatar
Oliver Bock committed
872
# here we go...
873

Oliver Bock's avatar
Oliver Bock committed
874
case $TARGET in
875
876
877
878
879
    $TARGET_LINUX)
        check_prerequisites || failure
        prepare_tree || failure
        build_linux || failure
        ;;
880
    $TARGET_MAC)
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
        if [ -d /Developer/SDKs/MacOSX10.4u.sdk ]; then
            echo "Preparing Mac OS X 10.4 SDK build environment..." | tee -a $LOGFILE
            # use 10.4 (Tiger) SDK because of BOINC/10.5 incompatibility (http://boinc.berkeley.edu/doxygen/api/html/QBacktrace_8h.html)
            export LDFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 $LDFLAGS"
            export CPPFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 $CPPFLAGS"
            export CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 $CFLAGS"
            export CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 $CXXFLAGS"
            export SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"
            export MACOSX_DEPLOYMENT_TARGET=10.4
        else
            echo "Mac OS X 10.4 SDK required but missing!" | tee -a $LOGFILE
            failure
        fi
        check_prerequisites || failure
        prepare_tree || failure
896
        build_mac $TARGET_MAC || failure
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
        ;;
    $TARGET_WIN32)
        check_prerequisites || failure
        prepare_tree || failure
        build_win32 || failure
        ;;
    $TARGET_DOC)
        doxygen Doxyfile >> $LOGFILE 2>&1 || failure
        cp -f $ROOT/doc/default/*.png $ROOT/doc/html >> $LOGFILE 2>&1 || failure
        cp -f $ROOT/doc/default/*.gif $ROOT/doc/html >> $LOGFILE 2>&1 || failure
        ;;
    *)
        # should be unreachable
        print_usage
        exit 1
        ;;
Oliver Bock's avatar
Oliver Bock committed
913
914
esac

915
916
917
918
919
echo "************************************" | tee -a $LOGFILE
echo "Build finished successfully!" | tee -a $LOGFILE
echo "`date`" | tee -a $LOGFILE
echo "************************************" | tee -a $LOGFILE

Oliver Bock's avatar
Oliver Bock committed
920
exit 0