setup.sh 10.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
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
###########################################################################
#   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 #################################################################

# error level checking (break in case of error, always 2>&1 for make logging)
# more refactoring (every lib in dedicated function? per traget?)

### functions #############################################################
Oliver Bock's avatar
Oliver Bock committed
29
30
31

check_prerequisites()
{
Oliver Bock's avatar
Oliver Bock committed
32
33
34
35
36
37
38
39
40
41
42
43
44
	echo "Checking prerequisites..."
	
	# required toolchain
	TOOLS="automake autoconf m4 cmake wget gcc g++ ld libtool ar lex yacc"

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

	return 0
Oliver Bock's avatar
Oliver Bock committed
45
46
47
48
49
}


prepare_generic()
{
Oliver Bock's avatar
Oliver Bock committed
50
51
52
53
54
	cd $ROOT

	echo "Preparing source tree..." | tee -a $ROOT/setup.log
	mkdir -p 3rdparty/oglft >> $ROOT/setup.log
	mkdir -p 3rdparty/boinc >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
55
	
Oliver Bock's avatar
Oliver Bock committed
56
57
58
59
60
	echo "Preparing build tree..." | tee -a $ROOT/setup.log
	mkdir -p build/sdl >> $ROOT/setup.log
	mkdir -p build/freetype2 >> $ROOT/setup.log
	mkdir -p build/oglft >> $ROOT/setup.log
	mkdir -p build/boinc >> $ROOT/setup.log
61
62
63
	mkdir -p build/framework >> $ROOT/setup.log
	mkdir -p build/orc >> $ROOT/setup.log
	mkdir -p build/starsphere >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
64
	
Oliver Bock's avatar
Oliver Bock committed
65
66
67
68
	echo "Preparing install tree..." | tee -a $ROOT/setup.log
	mkdir -p install/bin >> $ROOT/setup.log
	mkdir -p install/include >> $ROOT/setup.log
	mkdir -p install/lib >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
69
70
71
	
	# prepare additional sources
	
Oliver Bock's avatar
Oliver Bock committed
72
	mkdir -p 3rdparty/sdl >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
73
	cd $ROOT/3rdparty/sdl
Oliver Bock's avatar
Oliver Bock committed
74
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
75
76
		echo "Updating SDL..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
77
	else
Oliver Bock's avatar
Oliver Bock committed
78
		echo "Retrieving SDL (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
79
		svn checkout http://svn.libsdl.org/branches/SDL-1.2 . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
80
	fi
Oliver Bock's avatar
Oliver Bock committed
81
82
83
84
85
86
87

# 	cd $ROOT/3rdparty
# 	echo "Retrieving SDL (this may take a while)..." | tee -a $ROOT/setup.log
# 	wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz >> $ROOT/setup.log 2>&1
# 	tar -xzf SDL-1.2.14.tar.gz >> $ROOT/setup.log
# 	rm SDL-1.2.14.tar.gz >> $ROOT/setup.log
# 	mv SDL-1.2.14 sdl >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
88
	
Oliver Bock's avatar
Oliver Bock committed
89
90
91
92
93
94
	cd $ROOT/3rdparty
	echo "Retrieving Freetype2 (this may take a while)..." | tee -a $ROOT/setup.log
	wget http://mesh.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.5.tar.bz2 >> $ROOT/setup.log 2>&1
	tar -xjf freetype-2.3.5.tar.bz2 >> $ROOT/setup.log
	rm freetype-2.3.5.tar.bz2 >> $ROOT/setup.log
	mv freetype-2.3.5 freetype2 >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
95
	
Oliver Bock's avatar
Oliver Bock committed
96
	cd $ROOT/3rdparty/oglft
Oliver Bock's avatar
Oliver Bock committed
97
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
98
		echo "Updating OGLFT..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
99
100
		svn update >> ../../setup.log
	else
Oliver Bock's avatar
Oliver Bock committed
101
		echo "Retrieving OGLFT (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
102
		svn checkout https://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
103
104
	fi
	
Oliver Bock's avatar
Oliver Bock committed
105
	cd $ROOT/3rdparty/boinc
Oliver Bock's avatar
Oliver Bock committed
106
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
107
108
		echo "Updating BOINC..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
109
	else
Oliver Bock's avatar
Oliver Bock committed
110
		echo "Retrieving BOINC (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
111
		svn checkout http://boinc.berkeley.edu/svn/trunk/boinc . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
112
	fi
Oliver Bock's avatar
Oliver Bock committed
113
114

	return 0
Oliver Bock's avatar
Oliver Bock committed
115
116
117
118
119
120
}


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
121
122
123

	echo "Preparing MinGW source tree..." | tee -a $ROOT/setup.log
	mkdir -p 3rdparty/mingw/xscripts >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
124
125
126
	cd 3rdparty/mingw/xscripts

	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
127
128
		echo "Updating MinGW build script..." | tee -a $ROOT/setup.log
		cvs update -C >> $ROOT/setup.log 2>&1
Oliver Bock's avatar
Oliver Bock committed
129
130
	else
		cd ..
Oliver Bock's avatar
Oliver Bock committed
131
		echo "Retrieving MinGW build script (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
132
		cvs -z3 -d:pserver:anonymous@mingw.cvs.sourceforge.net:/cvsroot/mingw checkout -P xscripts >> $ROOT/setup.log 2>&1
Oliver Bock's avatar
Oliver Bock committed
133
134
	fi
	
Oliver Bock's avatar
Oliver Bock committed
135
136
137
138
139
	cd $ROOT/3rdparty/mingw/xscripts
	echo "Preparing MinGW build script..." | tee -a $ROOT/setup.log
	# 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 >> $ROOT/setup.log
	chmod +x x86-mingw32-build.sh >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
140
141

	return 0
Oliver Bock's avatar
Oliver Bock committed
142
143
144
145
146
}


build_generic()
{
Oliver Bock's avatar
Oliver Bock committed
147
148
149
150
151
152
153
154
155
156
157
158
159
	cd $ROOT/3rdparty/sdl
	echo "Building SDL (this may take a while)..." | tee -a $ROOT/setup.log
	./autogen.sh >> $ROOT/setup.log
	cd $ROOT/build/sdl
	$ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed SDL!" | tee -a $ROOT/setup.log

	cd $ROOT/3rdparty/freetype2
	echo "Building Freetype2 (this may take a while)..." | tee -a $ROOT/setup.log
	chmod +x autogen.sh >> $ROOT/setup.log
	chmod +x configure >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
160
	./autogen.sh >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
161
162
163
164
165
166
167
168
	cd $ROOT/build/freetype2
	# 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 >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed Freetype2!" | tee -a $ROOT/setup.log

	cd $ROOT/3rdparty/oglft/liboglft
Oliver Bock's avatar
Oliver Bock committed
169
	echo "Building OGLFT..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
170
171
	# note: svn has no force/overwrite switch. the file might not be updated when patched
	patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.liboglft.patch >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
172
	# TODO: patch CMakeLists.txt in case FindFreetype.cmake is not available!
Oliver Bock's avatar
Oliver Bock committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	cd $ROOT/build/oglft
	cmake $ROOT/3rdparty/oglft >> $ROOT/setup.log
	make >> $ROOT/setup.log
	mkdir -p $ROOT/install/include/oglft >> $ROOT/setup.log
	cp OGLFT.h $ROOT/install/include/oglft >> $ROOT/setup.log
	cp liboglft/liboglft.a $ROOT/install/lib >> $ROOT/setup.log
	echo "Successfully built and installed OGLFT!" | tee -a $ROOT/setup.log

	cd $ROOT/3rdparty/boinc
	echo "Building BOINC (this may take a while)..." | tee -a $ROOT/setup.log
	./_autosetup >> $ROOT/setup.log
	cd $ROOT/build/boinc
	$ROOT/3rdparty/boinc/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --disable-server --disable-client >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed BOINC!" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
189
190

	return 0
Oliver Bock's avatar
Oliver Bock committed
191
192
}

Oliver Bock's avatar
Oliver Bock committed
193

Oliver Bock's avatar
Oliver Bock committed
194
195
196
build_mingw()
{
	echo "Not yet implemented: build_mingw()"
Oliver Bock's avatar
Oliver Bock committed
197
198

	return 0
Oliver Bock's avatar
Oliver Bock committed
199
200
}

Oliver Bock's avatar
Oliver Bock committed
201

Oliver Bock's avatar
Oliver Bock committed
202
203
build_starsphere()
{
Oliver Bock's avatar
Oliver Bock committed
204
	echo "Building Starsphere [ORC]..." | tee -a $ROOT/setup.log
205
206
207
208
209
210
211
212
	export ORC_SRC=$ROOT/src/orc
	export ORC_INSTALL=$ROOT/install
	cd $ROOT/build/orc
	cp $ROOT/src/orc/Makefile .  >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed Starsphere [ORC]!" | tee -a $ROOT/setup.log

Oliver Bock's avatar
Oliver Bock committed
213
	echo "Building Starsphere [Framework]..." | tee -a $ROOT/setup.log
214
215
216
217
218
219
220
221
	export FRAMEWORK_SRC=$ROOT/src/framework
	export FRAMEWORK_INSTALL=$ROOT/install
	cd $ROOT/build/framework
	cp $ROOT/src/framework/Makefile .  >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed Starsphere [Framework]!" | tee -a $ROOT/setup.log

Oliver Bock's avatar
Oliver Bock committed
222
	echo "Building Starsphere [Application]..." | tee -a $ROOT/setup.log
223
224
225
226
227
228
229
230
	export STARSPHERE_SRC=$ROOT/src/starsphere
	export STARSPHERE_INSTALL=$ROOT/install
	cd $ROOT/build/starsphere
	cp $ROOT/src/starsphere/Makefile .  >> $ROOT/setup.log
	cp $ROOT/src/starsphere/*.res .  >> $ROOT/setup.log
	make >> $ROOT/setup.log
	make install >> $ROOT/setup.log
	echo "Successfully built and installed Starsphere [Application]!" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
231
232

	return 0
Oliver Bock's avatar
Oliver Bock committed
233
}
Oliver Bock's avatar
Oliver Bock committed
234

Oliver Bock's avatar
Oliver Bock committed
235

Oliver Bock's avatar
Oliver Bock committed
236
237
238
239
build_linux()
{
	build_generic
	build_starsphere
Oliver Bock's avatar
Oliver Bock committed
240
241

	return 0
Oliver Bock's avatar
Oliver Bock committed
242
243
244
245
246
}


build_mac()
{
Oliver Bock's avatar
Oliver Bock committed
247
248
249
250
251
252
	echo "Not yet implemented: build_mac()"

# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
253
254
255
256
257
}


build_win32()
{
Oliver Bock's avatar
Oliver Bock committed
258
259
260
261
262
263
264
	echo "Not yet implemented: build_win32()"

# 	build_mingw
# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
265
266
267
}


Oliver Bock's avatar
Oliver Bock committed
268
269
270
271
272
273
274
275
276
277
278
279
distclean()
{
	cd $ROOT

	rm -rf 3rdparty
	rm -rf build
	rm -rf install

	rm -f .lastbuild
}


Oliver Bock's avatar
Oliver Bock committed
280
281
check_last_build()
{
Oliver Bock's avatar
Oliver Bock committed
282
	LASTBUILD=`cat .lastbuild 2>/dev/null`
Oliver Bock's avatar
Oliver Bock committed
283

Oliver Bock's avatar
Oliver Bock committed
284
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
Oliver Bock's avatar
Oliver Bock committed
285
286
287
288
289
		# TODO: clean build dirs when different target!
		echo "Not yet implemented: cleanup in check_lastbuild()"
	fi

	echo "$1" > .lastbuild
Oliver Bock's avatar
Oliver Bock committed
290
291

	return 0
Oliver Bock's avatar
Oliver Bock committed
292
293
}

Oliver Bock's avatar
Oliver Bock committed
294

Oliver Bock's avatar
Oliver Bock committed
295
296
297
298
299
300
301
302
303
304
305
306
307
print_usage()
{
	cd $ROOT

	echo "*************************"
	echo "Usage: `basename $0` <target>"
	echo
	echo "Available targets:"
	echo "  --linux"
	echo "  --mac"
	echo "  --win32"
	echo "*************************"

Oliver Bock's avatar
Oliver Bock committed
308
	echo "Wrong usage. Stopping!" >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
309
310

	return 0
Oliver Bock's avatar
Oliver Bock committed
311
312
313
}


Oliver Bock's avatar
Oliver Bock committed
314
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
315

316
317
318
ROOT=`pwd`
DATE=`date`

Oliver Bock's avatar
Oliver Bock committed
319
320
321
322
323
TARGET=0
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3

Oliver Bock's avatar
Oliver Bock committed
324
325
326
327
echo "************************************" >> $ROOT/setup.log
echo "Starting new setup run!" >> $ROOT/setup.log
echo "$DATE" >> $ROOT/setup.log
echo "************************************" >> $ROOT/setup.log
328

Oliver Bock's avatar
Oliver Bock committed
329
# crude command line parsing :-)
330

Oliver Bock's avatar
Oliver Bock committed
331
332
333
if [ $# -ne 1 ]; then
  print_usage
  exit 1
334
335
fi

Oliver Bock's avatar
Oliver Bock committed
336
337
338
339
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
340
		echo "Building linux version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
341
342
343
344
		;;
	"--mac")
		TARGET=$TARGET_MAC
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
345
		echo "Building mac version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
346
347
		;;
	"--win32")
Oliver Bock's avatar
Oliver Bock committed
348
349
350
351
		TARGET=$TARGET_WIN32
		check_last_build "$1"
		echo "Building win32 version:" | tee -a $ROOT/setup.log
		;;
Oliver Bock's avatar
Oliver Bock committed
352
353
354
355
	"--distclean")
		distclean
		exit 0
		;;
Oliver Bock's avatar
Oliver Bock committed
356
	*)
Oliver Bock's avatar
Oliver Bock committed
357
358
359
		print_usage
		exit 1
		;;
Oliver Bock's avatar
Oliver Bock committed
360
esac
361

Oliver Bock's avatar
Oliver Bock committed
362
# here we go...
363

Oliver Bock's avatar
Oliver Bock committed
364
check_prerequisites
Oliver Bock's avatar
Oliver Bock committed
365
366
367
if [ ! $? -eq 0 ]; then
	exit 1
fi
368

Oliver Bock's avatar
Oliver Bock committed
369
370
371
prepare_generic
if [ ! $? -eq 0 ]; then
	exit 1
Oliver Bock's avatar
Oliver Bock committed
372
373
fi

Oliver Bock's avatar
Oliver Bock committed
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
case $TARGET in
	$TARGET_LINUX)
		build_linux
		if [ ! $? -eq 0 ]; then
			exit 1
		fi
		;;
	$TARGET_MAC)
		build_mac
		if [ ! $? -eq 0 ]; then
			exit 1
		fi
		;;
	$TARGET_WIN32)
		build_win32
		if [ ! $? -eq 0 ]; then
			exit 1
		fi
		;;
	*)
		# should be unreachable
		print_usage
		exit 1
		;;
esac

Oliver Bock's avatar
Oliver Bock committed
400
exit 0