setup.sh 11 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
###########################################################################
#   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?)

Oliver Bock's avatar
Oliver Bock committed
28
29
30
31
32
33
34
### globals ###############################################################

ROOT=`pwd`
DATE=`date`
LOGFILE=$ROOT/setup.log
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
failure()
{
	echo "************************************" | tee -a 
	echo "Error detected! Stopping setup run!" | tee -a $LOGFILE
	echo "$DATE" | tee -a $LOGFILE

    if [ -f "$LOGFILE" ]; then
		echo "------------------------------------"
		echo "Please check logfile: `basename $LOGFILE`"
		echo "These are the final ten lines:"
		echo "------------------------------------"
		tail -10 $LOGFILE
    fi

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

    exit 1
}

Oliver Bock's avatar
Oliver Bock committed
56
57
check_prerequisites()
{
Oliver Bock's avatar
Oliver Bock committed
58
59
60
61
62
63
64
65
66
67
68
69
70
	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
71
72
73
74
75
}


prepare_generic()
{
Oliver Bock's avatar
Oliver Bock committed
76
77
	cd $ROOT

Oliver Bock's avatar
Oliver Bock committed
78
79
80
	echo "Preparing source tree..." | tee -a $LOGFILE
	mkdir -p 3rdparty/oglft >> $LOGFILE
	mkdir -p 3rdparty/boinc >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
81
	
Oliver Bock's avatar
Oliver Bock committed
82
83
84
85
86
87
88
89
	echo "Preparing build tree..." | tee -a $LOGFILE
	mkdir -p build/sdl >> $LOGFILE
	mkdir -p build/freetype2 >> $LOGFILE
	mkdir -p build/oglft >> $LOGFILE
	mkdir -p build/boinc >> $LOGFILE
	mkdir -p build/framework >> $LOGFILE
	mkdir -p build/orc >> $LOGFILE
	mkdir -p build/starsphere >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
90
	
Oliver Bock's avatar
Oliver Bock committed
91
92
93
94
	echo "Preparing install tree..." | tee -a $LOGFILE
	mkdir -p install/bin >> $LOGFILE
	mkdir -p install/include >> $LOGFILE
	mkdir -p install/lib >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
95
96
97
	
	# prepare additional sources
	
Oliver Bock's avatar
Oliver Bock committed
98
	mkdir -p 3rdparty/sdl >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
99
	cd $ROOT/3rdparty/sdl
Oliver Bock's avatar
Oliver Bock committed
100
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
101
102
		echo "Updating SDL..." | tee -a $LOGFILE
		svn update >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
103
	else
Oliver Bock's avatar
Oliver Bock committed
104
105
		echo "Retrieving SDL (this may take a while)..." | tee -a $LOGFILE
		svn checkout http://svn.libsdl.org/branches/SDL-1.2 . >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
106
	fi
Oliver Bock's avatar
Oliver Bock committed
107
108

# 	cd $ROOT/3rdparty
Oliver Bock's avatar
Oliver Bock committed
109
110
111
112
113
# 	echo "Retrieving SDL (this may take a while)..." | tee -a $LOGFILE
# 	wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz >> $LOGFILE 2>&1
# 	tar -xzf SDL-1.2.14.tar.gz >> $LOGFILE
# 	rm SDL-1.2.14.tar.gz >> $LOGFILE
# 	mv SDL-1.2.14 sdl >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
114
	
Oliver Bock's avatar
Oliver Bock committed
115
	cd $ROOT/3rdparty
Oliver Bock's avatar
Oliver Bock committed
116
117
118
119
120
	echo "Retrieving Freetype2 (this may take a while)..." | tee -a $LOGFILE
	wget http://mesh.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.5.tar.bz2 >> $LOGFILE 2>&1
	tar -xjf freetype-2.3.5.tar.bz2 >> $LOGFILE
	rm freetype-2.3.5.tar.bz2 >> $LOGFILE
	mv freetype-2.3.5 freetype2 >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
121
	
Oliver Bock's avatar
Oliver Bock committed
122
	cd $ROOT/3rdparty/oglft
Oliver Bock's avatar
Oliver Bock committed
123
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
124
		echo "Updating OGLFT..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
125
126
		svn update >> ../../setup.log
	else
Oliver Bock's avatar
Oliver Bock committed
127
128
		echo "Retrieving OGLFT (this may take a while)..." | tee -a $LOGFILE
		svn checkout https://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
129
130
	fi
	
Oliver Bock's avatar
Oliver Bock committed
131
	cd $ROOT/3rdparty/boinc
Oliver Bock's avatar
Oliver Bock committed
132
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
133
134
		echo "Updating BOINC..." | tee -a $LOGFILE
		svn update >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
135
	else
Oliver Bock's avatar
Oliver Bock committed
136
137
		echo "Retrieving BOINC (this may take a while)..." | tee -a $LOGFILE
		svn checkout http://boinc.berkeley.edu/svn/trunk/boinc . >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
138
	fi
Oliver Bock's avatar
Oliver Bock committed
139
140

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


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
147

Oliver Bock's avatar
Oliver Bock committed
148
149
	echo "Preparing MinGW source tree..." | tee -a $LOGFILE
	mkdir -p 3rdparty/mingw/xscripts >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
150
151
152
	cd 3rdparty/mingw/xscripts

	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
153
154
		echo "Updating MinGW build script..." | tee -a $LOGFILE
		cvs update -C >> $LOGFILE 2>&1
Oliver Bock's avatar
Oliver Bock committed
155
156
	else
		cd ..
Oliver Bock's avatar
Oliver Bock committed
157
158
		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
Oliver Bock's avatar
Oliver Bock committed
159
160
	fi
	
Oliver Bock's avatar
Oliver Bock committed
161
	cd $ROOT/3rdparty/mingw/xscripts
Oliver Bock's avatar
Oliver Bock committed
162
	echo "Preparing MinGW build script..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
163
	# note: svn has no force/overwrite switch. the file might not be updated when patched
Oliver Bock's avatar
Oliver Bock committed
164
165
	patch x86-mingw32-build.sh.conf < $ROOT/patches/x86-mingw32-build.sh.conf.patch >> $LOGFILE
	chmod +x x86-mingw32-build.sh >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
166
167

	return 0
Oliver Bock's avatar
Oliver Bock committed
168
169
170
171
172
}


build_generic()
{
Oliver Bock's avatar
Oliver Bock committed
173
	cd $ROOT/3rdparty/sdl
Oliver Bock's avatar
Oliver Bock committed
174
175
	echo "Building SDL (this may take a while)..." | tee -a $LOGFILE
	./autogen.sh >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
176
	cd $ROOT/build/sdl
Oliver Bock's avatar
Oliver Bock committed
177
178
179
180
	$ROOT/3rdparty/sdl/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed SDL!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
181
182

	cd $ROOT/3rdparty/freetype2
Oliver Bock's avatar
Oliver Bock committed
183
184
185
186
	echo "Building Freetype2 (this may take a while)..." | tee -a $LOGFILE
	chmod +x autogen.sh >> $LOGFILE
	chmod +x configure >> $LOGFILE
	./autogen.sh >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
187
188
	cd $ROOT/build/freetype2
	# note: freetype (or sdl?) probably doesn't need *no* configure when static -> ansi build, see readme!
Oliver Bock's avatar
Oliver Bock committed
189
190
191
192
	$ROOT/3rdparty/freetype2/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed Freetype2!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
193

Oliver Bock's avatar
Oliver Bock committed
194
195
196
197
198
199
200
201
	cd $ROOT/3rdparty/oglft
	echo "Patching OGLFT..." | tee -a $LOGFILE
	# 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/liboglft.a"
	patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.oglft.patch >> $LOGFILE
	# patch: build static lib instead of shared
Oliver Bock's avatar
Oliver Bock committed
202
	cd $ROOT/3rdparty/oglft/liboglft
Oliver Bock's avatar
Oliver Bock committed
203
204
	patch CMakeLists.txt < $ROOT/patches/CMakeLists.txt.liboglft.patch >> $LOGFILE
	echo "Building OGLFT..." | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
205
	cd $ROOT/build/oglft
Oliver Bock's avatar
Oliver Bock committed
206
207
208
209
210
211
	cmake -DFREETYPE2_INCLUDE_DIR="$FREETYPE2_INCLUDE_DIR" -DFREETYPE2_LIBRARIES="$FREETYPE2_LIBRARIES" $ROOT/3rdparty/oglft >> $LOGFILE
	make >> $LOGFILE
	mkdir -p $ROOT/install/include/oglft >> $LOGFILE
	cp OGLFT.h $ROOT/install/include/oglft >> $LOGFILE
	cp liboglft/liboglft.a $ROOT/install/lib >> $LOGFILE
	echo "Successfully built and installed OGLFT!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
212
213

	cd $ROOT/3rdparty/boinc
Oliver Bock's avatar
Oliver Bock committed
214
215
	echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
	./_autosetup >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
216
	cd $ROOT/build/boinc
Oliver Bock's avatar
Oliver Bock committed
217
218
219
220
	$ROOT/3rdparty/boinc/configure --prefix=$ROOT/install --enable-shared=no --enable-static=yes --disable-server --disable-client >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed BOINC!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
221
222

	return 0
Oliver Bock's avatar
Oliver Bock committed
223
224
}

Oliver Bock's avatar
Oliver Bock committed
225

Oliver Bock's avatar
Oliver Bock committed
226
227
228
build_mingw()
{
	echo "Not yet implemented: build_mingw()"
Oliver Bock's avatar
Oliver Bock committed
229
230

	return 0
Oliver Bock's avatar
Oliver Bock committed
231
232
}

Oliver Bock's avatar
Oliver Bock committed
233

Oliver Bock's avatar
Oliver Bock committed
234
235
build_starsphere()
{
Oliver Bock's avatar
Oliver Bock committed
236
	echo "Building Starsphere [ORC]..." | tee -a $LOGFILE
237
238
239
	export ORC_SRC=$ROOT/src/orc
	export ORC_INSTALL=$ROOT/install
	cd $ROOT/build/orc
Oliver Bock's avatar
Oliver Bock committed
240
241
242
243
	cp $ROOT/src/orc/Makefile .  >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed Starsphere [ORC]!" | tee -a $LOGFILE
244

Oliver Bock's avatar
Oliver Bock committed
245
	echo "Building Starsphere [Framework]..." | tee -a $LOGFILE
246
247
248
	export FRAMEWORK_SRC=$ROOT/src/framework
	export FRAMEWORK_INSTALL=$ROOT/install
	cd $ROOT/build/framework
Oliver Bock's avatar
Oliver Bock committed
249
250
251
252
	cp $ROOT/src/framework/Makefile .  >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed Starsphere [Framework]!" | tee -a $LOGFILE
253

Oliver Bock's avatar
Oliver Bock committed
254
	echo "Building Starsphere [Application]..." | tee -a $LOGFILE
255
256
257
	export STARSPHERE_SRC=$ROOT/src/starsphere
	export STARSPHERE_INSTALL=$ROOT/install
	cd $ROOT/build/starsphere
Oliver Bock's avatar
Oliver Bock committed
258
259
260
261
262
	cp $ROOT/src/starsphere/Makefile .  >> $LOGFILE
	cp $ROOT/src/starsphere/*.res .  >> $LOGFILE
	make >> $LOGFILE
	make install >> $LOGFILE
	echo "Successfully built and installed Starsphere [Application]!" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
263
264

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

Oliver Bock's avatar
Oliver Bock committed
267

Oliver Bock's avatar
Oliver Bock committed
268
269
270
271
build_linux()
{
	build_generic
	build_starsphere
Oliver Bock's avatar
Oliver Bock committed
272
273

	return 0
Oliver Bock's avatar
Oliver Bock committed
274
275
276
277
278
}


build_mac()
{
Oliver Bock's avatar
Oliver Bock committed
279
280
281
282
283
284
	echo "Not yet implemented: build_mac()"

# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
285
286
287
288
289
}


build_win32()
{
Oliver Bock's avatar
Oliver Bock committed
290
291
292
293
294
295
296
	echo "Not yet implemented: build_win32()"

# 	build_mingw
# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
297
298
299
}


Oliver Bock's avatar
Oliver Bock committed
300
301
302
303
304
305
306
307
308
309
310
311
distclean()
{
	cd $ROOT

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

	rm -f .lastbuild
}


Oliver Bock's avatar
Oliver Bock committed
312
313
check_last_build()
{
Oliver Bock's avatar
Oliver Bock committed
314
	LASTBUILD=`cat .lastbuild 2>/dev/null`
Oliver Bock's avatar
Oliver Bock committed
315

Oliver Bock's avatar
Oliver Bock committed
316
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
Oliver Bock's avatar
Oliver Bock committed
317
318
319
		cd $ROOT
		rm -rf build
		rm -rf install
Oliver Bock's avatar
Oliver Bock committed
320
321
322
	fi

	echo "$1" > .lastbuild
Oliver Bock's avatar
Oliver Bock committed
323
324

	return 0
Oliver Bock's avatar
Oliver Bock committed
325
326
}

Oliver Bock's avatar
Oliver Bock committed
327

Oliver Bock's avatar
Oliver Bock committed
328
329
330
331
332
333
334
335
336
337
338
339
340
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
341
	echo "Wrong usage. Stopping!" >> $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
342
343

	return 0
Oliver Bock's avatar
Oliver Bock committed
344
345
346
}


Oliver Bock's avatar
Oliver Bock committed
347
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
348
349
350
351
352

TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3

Oliver Bock's avatar
Oliver Bock committed
353
354
355
356
echo "************************************" >> $LOGFILE
echo "Starting new setup run!" >> $LOGFILE
echo "$DATE" >> $LOGFILE
echo "************************************" >> $LOGFILE
357

Oliver Bock's avatar
Oliver Bock committed
358
# crude command line parsing :-)
359

Oliver Bock's avatar
Oliver Bock committed
360
361
362
if [ $# -ne 1 ]; then
  print_usage
  exit 1
363
364
fi

Oliver Bock's avatar
Oliver Bock committed
365
366
367
368
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
369
		echo "Building linux version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
370
371
372
373
		;;
	"--mac")
		TARGET=$TARGET_MAC
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
374
		echo "Building mac version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
375
376
		;;
	"--win32")
Oliver Bock's avatar
Oliver Bock committed
377
378
		TARGET=$TARGET_WIN32
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
379
		echo "Building win32 version:" | tee -a $LOGFILE
Oliver Bock's avatar
Oliver Bock committed
380
		;;
Oliver Bock's avatar
Oliver Bock committed
381
382
383
384
	"--distclean")
		distclean
		exit 0
		;;
Oliver Bock's avatar
Oliver Bock committed
385
	*)
Oliver Bock's avatar
Oliver Bock committed
386
387
388
		print_usage
		exit 1
		;;
Oliver Bock's avatar
Oliver Bock committed
389
esac
390

Oliver Bock's avatar
Oliver Bock committed
391
# here we go...
392

Oliver Bock's avatar
Oliver Bock committed
393
check_prerequisites
Oliver Bock's avatar
Oliver Bock committed
394
395
396
if [ ! $? -eq 0 ]; then
	exit 1
fi
397

Oliver Bock's avatar
Oliver Bock committed
398
399
400
prepare_generic
if [ ! $? -eq 0 ]; then
	exit 1
Oliver Bock's avatar
Oliver Bock committed
401
402
fi

Oliver Bock's avatar
Oliver Bock committed
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
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
429
exit 0