build.sh 24.5 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
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
###########################################################################
#   Copyright (C) 2008 by Oliver Bock                                     #
#   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/>. #
#                                                                         #
###########################################################################

### TODOs #################################################################

# more refactoring (every lib in dedicated function? per traget?)

Oliver Bock's avatar
Oliver Bock committed
27
28
29
### globals ###############################################################

ROOT=`pwd`
30
31
PATH_ORG="$PATH"
PATH_MINGW="$PATH"
32
LOGFILE=$ROOT/build.log
Oliver Bock's avatar
Oliver Bock committed
33
34
TARGET=0

Oliver Bock's avatar
Oliver Bock committed
35
### functions #############################################################
Oliver Bock's avatar
Oliver Bock committed
36

Oliver Bock's avatar
Oliver Bock committed
37
38
failure()
{
39
40
41
	echo "************************************" | tee -a $LOGFILE
	echo "Error detected! Stopping build!" | tee -a $LOGFILE
	echo "`date`" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
42
43
44
45
46
47

    if [ -f "$LOGFILE" ]; then
		echo "------------------------------------"
		echo "Please check logfile: `basename $LOGFILE`"
		echo "These are the final ten lines:"
		echo "------------------------------------"
Oliver Bock's avatar
Oliver Bock committed
48
		tail -n 14 $LOGFILE | head -n 10
Oliver Bock's avatar
Oliver Bock committed
49
50
51
52
53
54
55
    fi

	echo "************************************" | tee -a $LOGFILE

    exit 1
}

Oliver Bock's avatar
Oliver Bock committed
56
57
check_prerequisites()
{
58
	echo "Checking prerequisites..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
59
60
	
	# required toolchain
Oliver Bock's avatar
Oliver Bock committed
61
	TOOLS="automake autoconf m4 cmake wget svn cvs tar patch gcc g++ ld libtool ar lex yacc pkg-config"
Oliver Bock's avatar
Oliver Bock committed
62
63
64

	for tool in $TOOLS; do
		if ! ( type $tool >/dev/null 2>&1 ); then
65
			echo "Missing \"$tool\" which is a required tool!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
66
67
68
69
70
			return 1
		fi
	done

	return 0
Oliver Bock's avatar
Oliver Bock committed
71
72
73
}


74
prepare_source_tree()
Oliver Bock's avatar
Oliver Bock committed
75
{
Oliver Bock's avatar
Oliver Bock committed
76
	echo "Preparing source tree..." | tee -a $LOGFILE
77
78
79
80
81
82
83
84
85
	mkdir -p 3rdparty/oglft >> $LOGFILE || failure
	mkdir -p 3rdparty/boinc >> $LOGFILE || failure

	return 0
}


prepare_build_tree()
{
Oliver Bock's avatar
Oliver Bock committed
86
	echo "Preparing build tree..." | tee -a $LOGFILE
87
88
	mkdir -p build/sdl >> $LOGFILE || failure
	mkdir -p build/freetype2 >> $LOGFILE || failure
89
	mkdir -p build/libxml2 >> $LOGFILE || failure
90
91
92
93
94
95
96
97
98
99
100
101
	mkdir -p build/oglft >> $LOGFILE || failure
	mkdir -p build/boinc >> $LOGFILE || failure
	mkdir -p build/framework >> $LOGFILE || failure
	mkdir -p build/orc >> $LOGFILE || failure
	mkdir -p build/starsphere >> $LOGFILE || failure

	return 0
}


prepare_install_tree()
{
Oliver Bock's avatar
Oliver Bock committed
102
	echo "Preparing install tree..." | tee -a $LOGFILE
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	mkdir -p install/bin >> $LOGFILE || failure
	mkdir -p install/include >> $LOGFILE || failure
	mkdir -p install/lib >> $LOGFILE || failure

	return 0
}


prepare_generic()
{
	prepare_source_tree || failure
	prepare_build_tree || failure
	prepare_install_tree || failure

Oliver Bock's avatar
Oliver Bock committed
117
	# prepare additional sources
118
119
120
121

	cd $ROOT || failure
	mkdir -p 3rdparty/sdl >> $LOGFILE 2>&1 || failure
	cd $ROOT/3rdparty/sdl || failure
Oliver Bock's avatar
Oliver Bock committed
122
	if [ -d .svn ]; then
123
124
125
126
		echo "Updating SDL..." | tee -a $LOGFIL
		# make sure local changes (patches) are reverted, hence also updated
		svn revert -R . >> $LOGFILE 2>&1 || failure
		svn update >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
127
	else
Oliver Bock's avatar
Oliver Bock committed
128
		echo "Retrieving SDL (this may take a while)..." | tee -a $LOGFILE
129
		svn checkout http://svn.libsdl.org/branches/SDL-1.2 . >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
130
131
	fi
	
Oliver Bock's avatar
Oliver Bock committed
132
	echo "Retrieving Freetype2 (this may take a while)..." | tee -a $LOGFILE
133
	cd $ROOT/3rdparty || failure
134
135
136
	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
137
138
	# substitute old source tree
	rm -rf freetype2 >> $LOGFILE 2>&1 || failure
139
	mv freetype-2.3.5 freetype2 >> $LOGFILE 2>&1 || failure
140
141
142

	echo "Retrieving libxml2 (this may take a while)..." | tee -a $LOGFILE
	cd $ROOT/3rdparty || failure
Oliver Bock's avatar
Oliver Bock committed
143
	wget --passive-ftp ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.32.tar.gz >> $LOGFILE 2>&1 || failure
144
145
146
147
148
	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
Oliver Bock's avatar
Oliver Bock committed
149
	
150
	cd $ROOT/3rdparty/oglft || failure
Oliver Bock's avatar
Oliver Bock committed
151
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
152
		echo "Updating OGLFT..." | tee -a $LOGFILE
153
154
155
		# make sure local changes (patches) are reverted, hence also updated
		svn revert -R . >> $LOGFILE  2>&1 || failure
		svn update >> $LOGFILE  2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
156
	else
Oliver Bock's avatar
Oliver Bock committed
157
		echo "Retrieving OGLFT (this may take a while)..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
158
		svn checkout http://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
159
160
	fi
	
161
	cd $ROOT/3rdparty/boinc || failure
Oliver Bock's avatar
Oliver Bock committed
162
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
163
		echo "Updating BOINC..." | tee -a $LOGFILE
164
165
166
		# make sure local changes (patches) are reverted, hence also updated
		svn revert -R . >> $LOGFILE  2>&1 || failure
		svn update >> $LOGFILE  2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
167
	else
Oliver Bock's avatar
Oliver Bock committed
168
		echo "Retrieving BOINC (this may take a while)..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
169
		svn checkout http://boinc.berkeley.edu/svn/branches/server_stable . >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
170
	fi
Oliver Bock's avatar
Oliver Bock committed
171
172

	return 0
Oliver Bock's avatar
Oliver Bock committed
173
174
175
176
177
}


prepare_win32()
{
178
	cd $ROOT || failure
Oliver Bock's avatar
Oliver Bock committed
179

Oliver Bock's avatar
Oliver Bock committed
180
	echo "Preparing MinGW source tree..." | tee -a $LOGFILE
181
182
	mkdir -p 3rdparty/mingw/xscripts >> $LOGFILE || failure
	cd 3rdparty/mingw/xscripts || failure
Oliver Bock's avatar
Oliver Bock committed
183
184

	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
185
		echo "Updating MinGW build script..." | tee -a $LOGFILE
186
		cvs update -C >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
187
	else
188
		cd .. || failure
Oliver Bock's avatar
Oliver Bock committed
189
		echo "Retrieving MinGW build script (this may take a while)..." | tee -a $LOGFILE
190
		cvs -z3 -d:pserver:anonymous@mingw.cvs.sourceforge.net:/cvsroot/mingw checkout -P xscripts >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
191
192
	fi
	
Oliver Bock's avatar
Oliver Bock committed
193
	echo "Preparing MinGW build script..." | tee -a $LOGFILE
194
	cd $ROOT/3rdparty/mingw/xscripts || failure
Oliver Bock's avatar
Oliver Bock committed
195
	# note: svn has no force/overwrite switch. the file might not be updated when patched
196
197
	patch x86-mingw32-build.sh.conf < $ROOT/patches/x86-mingw32-build.sh.conf.patch >> $LOGFILE || failure
	chmod +x x86-mingw32-build.sh >> $LOGFILE || failure
Oliver Bock's avatar
Oliver Bock committed
198
199

	return 0
Oliver Bock's avatar
Oliver Bock committed
200
201
202
203
204
}


build_generic()
{
Oliver Bock's avatar
Oliver Bock committed
205
	echo "Building SDL (this may take a while)..." | tee -a $LOGFILE
206
	cd $ROOT/3rdparty/sdl || failure
207
	chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
208
	./autogen.sh >> $LOGFILE 2>&1 || failure
209
	chmod +x configure >> $LOGFILE 2>&1 || failure
210
	cd $ROOT/build/sdl || failure
211
	if [ "$1" == "$TARGET_MAC_INTEL" -o "$1" == "$TARGET_MAC_PPC" ]; then
212
		$ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --enable-screensaver=yes --enable-video-x11=no >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
213
	else
214
		$ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --enable-screensaver=yes >> $LOGFILE 2>&1 || failure	
Oliver Bock's avatar
Oliver Bock committed
215
	fi
216
217
	make >> $LOGFILE 2>&1 || failure
	make install >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
218
	echo "Successfully built and installed SDL!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
219

Oliver Bock's avatar
Oliver Bock committed
220
	echo "Building Freetype2 (this may take a while)..." | tee -a $LOGFILE
221
	cd $ROOT/3rdparty/freetype2 || failure
222
223
	chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
	./autogen.sh >> $LOGFILE 2>&1 || failure
224
	chmod +x configure >> $LOGFILE 2>&1 || failure
225
	cd $ROOT/build/freetype2 || failure
Oliver Bock's avatar
Oliver Bock committed
226
	# note: freetype (or sdl?) probably doesn't need *no* configure when static -> ansi build, see readme!
227
228
229
	$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
Oliver Bock's avatar
Oliver Bock committed
230
	echo "Successfully built and installed Freetype2!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
231

232
233
234
235
236
237
238
239
240
	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

Oliver Bock's avatar
Oliver Bock committed
241
	echo "Patching OGLFT..." | tee -a $LOGFILE
242
	cd $ROOT/3rdparty/oglft || failure
Oliver Bock's avatar
Oliver Bock committed
243
244
245
	# 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"
246
	FREETYPE2_LIBRARIES="$ROOT/install/lib/libfreetype.a"
247
	patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.oglft.patch >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
248
	echo "Building OGLFT..." | tee -a $LOGFILE
249
	cd $ROOT/build/oglft || failure
250
	# TODO: do we wanna create universal binaries on mac? If so, add -DCMAKE_OSX_ARCHITECTURES=ppc;i386
251
252
253
254
255
	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
Oliver Bock's avatar
Oliver Bock committed
256
	echo "Successfully built and installed OGLFT!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
257

258
	echo "Configuring BOINC..." | tee -a $LOGFILE
259
	cd $ROOT/3rdparty/boinc || failure
260
	chmod +x _autosetup >> $LOGFILE 2>&1 || failure
261
	./_autosetup >> $LOGFILE 2>&1 || failure
262
	chmod +x configure >> $LOGFILE 2>&1 || failure
263
	cd $ROOT/build/boinc || failure
Oliver Bock's avatar
Oliver Bock committed
264
265
	if [ "$1" == "$TARGET_MAC_INTEL" -o "$1" == "$TARGET_MAC_PPC" ]; then
		export CPPFLAGS=-I/sw/include
Oliver Bock's avatar
Oliver Bock committed
266
		$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
267
268
269
	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
Oliver Bock's avatar
Oliver Bock committed
270
	else
Oliver Bock's avatar
Oliver Bock committed
271
		$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
Oliver Bock's avatar
Oliver Bock committed
272
	fi
273
	echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
274
275
	make >> $LOGFILE 2>&1 || failure
	make install >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
276
	echo "Successfully built and installed BOINC!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
277
278

	return 0
Oliver Bock's avatar
Oliver Bock committed
279
280
}

Oliver Bock's avatar
Oliver Bock committed
281

Oliver Bock's avatar
Oliver Bock committed
282
283
284
285
286
287
288
289
290
291
292
293
294
build_mingw()
{
	TARGET_HOST=i586-pc-mingw32

	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

	return 0
}


295
296
297
298
299
300
301
302
303
304
305
306
build_generic_win32()
{
	# 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

	echo "Building SDL (this may take a while)..." | tee -a $LOGFILE
	cd $ROOT/3rdparty/sdl || failure
307
	chmod +x autogen.sh >> $LOGFILE 2>&1 || failure
308
	./autogen.sh >> $LOGFILE 2>&1 || failure
309
	chmod +x configure >> $LOGFILE 2>&1 || failure
310
311
312
313
314
315
	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
316
	$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
317
318
319
320
321
322
323
324
325
326
327
328
	make >> $LOGFILE 2>&1 || failure
	make install >> $LOGFILE 2>&1 || failure
	echo "Successfully built and installed SDL!" | tee -a $LOGFILE

	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
329
	chmod +x configure >> $LOGFILE 2>&1 || failure
330
331
332
333
334
335
336
337
338
339
340
341
	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

342
343
344
	echo "Building libxml2 (this may take a while)..." | tee -a $LOGFILE
	cd $ROOT/3rdparty/libxml2 || failure
	chmod +x configure >> $LOGFILE 2>&1 || failure
345
346
	if [ -f "$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-xml2-config" ]; then
		LIBXML2_CONFIG="$PREFIX/$TARGET_HOST/bin/$TARGET_HOST-xml2-config"
347
348
349
350
351
352
353
354
355
		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

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
	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

	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
Oliver Bock's avatar
Oliver Bock committed
378
	patch filesys.cpp < $ROOT/patches/boinc.filesys.cpp.mingw.patch >> $LOGFILE 2>&1 || failure
379
380
	echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
	cd $ROOT/3rdparty/boinc || failure
381
	chmod +x _autosetup >> $LOGFILE 2>&1 || failure
382
	./_autosetup >> $LOGFILE 2>&1 || failure
383
	chmod +x configure >> $LOGFILE 2>&1 || failure
384
	cd $ROOT/build/boinc || failure
Oliver Bock's avatar
Oliver Bock committed
385
	# note: configure is still required but we don't use the generated Makefile
Oliver Bock's avatar
Oliver Bock committed
386
	$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
387
388
	cd $ROOT/build/boinc/api || failure
	cp $ROOT/3rdparty/boinc/api/Makefile.mingw . >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
389
	# patch: add graphics2 and customize build path (see below)
390
391
392
	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
Oliver Bock's avatar
Oliver Bock committed
393
394
	# required for out-of-tree build
	cp config.h $ROOT/3rdparty/boinc >> $LOGFILE 2>&1 || failure
395
396
	make -f api/Makefile.mingw >> $LOGFILE 2>&1 || failure
	cp $ROOT/build/boinc/libboinc.a $ROOT/install/lib >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
	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
415
416
417
418
	echo "Successfully built and installed BOINC!" | tee -a $LOGFILE
}


Oliver Bock's avatar
Oliver Bock committed
419
420
build_starsphere()
{
421
422
423
	# make sure ORC is always compiled for host platform (it's exexuted during starsphere build!)
	export PATH=$PATH_ORG

Oliver Bock's avatar
Oliver Bock committed
424
	echo "Building Starsphere [ORC]..." | tee -a $LOGFILE
425
426
427
428
	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
Oliver Bock's avatar
Oliver Bock committed
429
	make $2 >> $LOGFILE 2>&1 || failure
430
	make install >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
431
	echo "Successfully built and installed Starsphere [ORC]!" | tee -a $LOGFILE
432

433
434
435
436
437
438
439
	# set main include directory
	if [ "$1" == "$TARGET_WIN32" ]; then
		export PATH=$PATH_MINGW
	else
		export PATH=$PATH_ORG
	fi

Oliver Bock's avatar
Oliver Bock committed
440
	echo "Building Starsphere [Framework]..." | tee -a $LOGFILE
441
442
443
	export FRAMEWORK_SRC=$ROOT/src/framework || failure
	export FRAMEWORK_INSTALL=$ROOT/install || failure
	cd $ROOT/build/framework || failure
444
445
446
447
448
	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
Oliver Bock's avatar
Oliver Bock committed
449
	make $2 >> $LOGFILE 2>&1 || failure
450
	make install >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
451
	echo "Successfully built and installed Starsphere [Framework]!" | tee -a $LOGFILE
452

Oliver Bock's avatar
Oliver Bock committed
453
	echo "Building Starsphere [Application]..." | tee -a $LOGFILE
454
455
456
457
	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
458
	if [ "$1" == "$TARGET_MAC_INTEL" ] || [ "$1" == "$TARGET_MAC_PPC" ]; then
459
460
461
		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
462
	else
463
		cp -f $ROOT/src/starsphere/Makefile . >> $LOGFILE 2>&1 || failure
464
	fi
Oliver Bock's avatar
Oliver Bock committed
465
	make $2 >> $LOGFILE 2>&1 || failure
466
	make install >> $LOGFILE 2>&1 || failure
Oliver Bock's avatar
Oliver Bock committed
467
	echo "Successfully built and installed Starsphere [Application]!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
468
469

	return 0
Oliver Bock's avatar
Oliver Bock committed
470
}
Oliver Bock's avatar
Oliver Bock committed
471

Oliver Bock's avatar
Oliver Bock committed
472

Oliver Bock's avatar
Oliver Bock committed
473
474
build_linux()
{
475
	echo "Important for an official build: let CC and CXX point to gcc/g++ 4.0.3!"
476
477
	build_generic || failure
	build_starsphere || failure
Oliver Bock's avatar
Oliver Bock committed
478
479

	return 0
Oliver Bock's avatar
Oliver Bock committed
480
481
482
483
484
}


build_mac()
{
485
486
	build_generic $1 || failure
	build_starsphere $1 || failure
Oliver Bock's avatar
Oliver Bock committed
487
488

	return 0
Oliver Bock's avatar
Oliver Bock committed
489
490
491
492
493
}


build_win32()
{
494
495
496
	prepare_win32 || failure
	build_mingw || failure
	build_generic_win32 || failure
Oliver Bock's avatar
Oliver Bock committed
497
	build_starsphere $TARGET_WIN32 || failure
Oliver Bock's avatar
Oliver Bock committed
498
499

	return 0
Oliver Bock's avatar
Oliver Bock committed
500
501
502
}


Oliver Bock's avatar
Oliver Bock committed
503
504
distclean()
{
505
506
507
	cd $ROOT || failure

	echo "Purging build system..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
508

509
510
511
	rm -rf 3rdparty || failure
	rm -rf build || failure
	rm -rf install || failure
512
513
	rm -rf doc/html || failure
	rm -f doc/*.tag || failure
Oliver Bock's avatar
Oliver Bock committed
514

515
	rm -f .lastbuild || failure
Oliver Bock's avatar
Oliver Bock committed
516
517
518
}


Oliver Bock's avatar
Oliver Bock committed
519
520
check_last_build()
{
521
522
	echo "Checking previous build target..." | tee -a $LOGFILE

Oliver Bock's avatar
Oliver Bock committed
523
	LASTBUILD=`cat .lastbuild 2>/dev/null`
Oliver Bock's avatar
Oliver Bock committed
524

Oliver Bock's avatar
Oliver Bock committed
525
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
526
527
528
529
		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
Oliver Bock's avatar
Oliver Bock committed
530
531
	fi

532
	echo "$1" > .lastbuild || failure
Oliver Bock's avatar
Oliver Bock committed
533
534

	return 0
Oliver Bock's avatar
Oliver Bock committed
535
536
}

Oliver Bock's avatar
Oliver Bock committed
537

Oliver Bock's avatar
Oliver Bock committed
538
539
540
541
542
543
544
545
546
print_usage()
{
	cd $ROOT

	echo "*************************"
	echo "Usage: `basename $0` <target>"
	echo
	echo "Available targets:"
	echo "  --linux"
547
548
	echo "  --mac-intel"
	echo "  --mac-ppc"
Oliver Bock's avatar
Oliver Bock committed
549
	echo "  --win32"
Oliver Bock's avatar
Oliver Bock committed
550
	echo "  --doc"
Oliver Bock's avatar
Oliver Bock committed
551
552
	echo "*************************"

Oliver Bock's avatar
Oliver Bock committed
553
	echo "Wrong usage. Stopping!" >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
554
555

	return 0
Oliver Bock's avatar
Oliver Bock committed
556
557
558
}


Oliver Bock's avatar
Oliver Bock committed
559
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
560
561

TARGET_LINUX=1
562
563
564
565
TARGET_MAC_INTEL=2
TARGET_MAC_PPC=4
TARGET_WIN32=8
TARGET_DOC=16
Oliver Bock's avatar
Oliver Bock committed
566

567
568
569
570
echo "************************************" | tee -a $LOGFILE
echo "Starting new build!" | tee -a $LOGFILE
echo "`date`" | tee -a $LOGFILE
echo "************************************" | tee -a $LOGFILE
571

Oliver Bock's avatar
Oliver Bock committed
572
# crude command line parsing :-)
573

Oliver Bock's avatar
Oliver Bock committed
574
575
576
if [ $# -ne 1 ]; then
  print_usage
  exit 1
577
578
fi

Oliver Bock's avatar
Oliver Bock committed
579
580
581
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
582
		check_last_build "$1" || failure
Oliver Bock's avatar
Oliver Bock committed
583
		echo "Building linux version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
584
		;;
585
586
	"--mac-intel")
		TARGET=$TARGET_MAC_INTEL
587
		check_last_build "$1" || failure
588
589
590
591
592
593
		echo "Building mac (Intel) version:" | tee -a $LOGFILE
		;;
	"--mac-ppc")
		TARGET=$TARGET_MAC_PPC
		check_last_build "$1" || failure
		echo "Building mac (PPC) version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
594
595
		;;
	"--win32")
Oliver Bock's avatar
Oliver Bock committed
596
		TARGET=$TARGET_WIN32
597
		check_last_build "$1" || failure
Oliver Bock's avatar
Oliver Bock committed
598
		echo "Building win32 version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
599
		;;
Oliver Bock's avatar
Oliver Bock committed
600
601
602
603
	"--doc")
		TARGET=$TARGET_DOC
		echo "Building documentation..." | tee -a $LOGFILE
		;;
Oliver Bock's avatar
Oliver Bock committed
604
	"--distclean")
605
		distclean || failure
Oliver Bock's avatar
Oliver Bock committed
606
607
		exit 0
		;;
608
609
610
	"--starsphere")
		# "hidden" bonus option :-)
		TARGET=$TARGET_LINUX
Oliver Bock's avatar
Oliver Bock committed
611
		build_starsphere $TARGET "debug" || failure
612
613
		exit 0
		;;
Oliver Bock's avatar
Oliver Bock committed
614
	*)
Oliver Bock's avatar
Oliver Bock committed
615
616
617
		print_usage
		exit 1
		;;
Oliver Bock's avatar
Oliver Bock committed
618
esac
619

Oliver Bock's avatar
Oliver Bock committed
620
# here we go...
621

Oliver Bock's avatar
Oliver Bock committed
622
623
case $TARGET in
	$TARGET_LINUX)
Oliver Bock's avatar
Oliver Bock committed
624
625
		check_prerequisites || failure
		prepare_generic || failure
626
		build_linux || failure
Oliver Bock's avatar
Oliver Bock committed
627
		;;
628
629
630
631
632
633
634
635
	$TARGET_MAC_INTEL)
		check_prerequisites || failure
		prepare_generic || failure
		build_mac $TARGET_MAC_INTEL || failure
		;;
	$TARGET_MAC_PPC)
		export CFLAGS=-mcpu=G3 || failure
		export CXXFLAGS=-mcpu=G3 || failure
Oliver Bock's avatar
Oliver Bock committed
636
637
		check_prerequisites || failure
		prepare_generic || failure
638
		build_mac $TARGET_MAC_PPC || failure
Oliver Bock's avatar
Oliver Bock committed
639
640
		;;
	$TARGET_WIN32)
Oliver Bock's avatar
Oliver Bock committed
641
642
		check_prerequisites || failure
		prepare_generic || failure
643
		build_win32 || failure
Oliver Bock's avatar
Oliver Bock committed
644
		;;
Oliver Bock's avatar
Oliver Bock committed
645
646
647
648
649
	$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
		;;
Oliver Bock's avatar
Oliver Bock committed
650
651
652
653
654
655
656
	*)
		# should be unreachable
		print_usage
		exit 1
		;;
esac

657
658
659
660
661
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
662
exit 0