setup.sh 10.4 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
55
56
	cd $ROOT

	echo "Preparing source tree..." | tee -a $ROOT/setup.log
	mkdir -p 3rdparty/sdl >> $ROOT/setup.log
	mkdir -p 3rdparty/freetype2 >> $ROOT/setup.log
	mkdir -p 3rdparty/oglft >> $ROOT/setup.log
	mkdir -p 3rdparty/boinc >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
57
	
Oliver Bock's avatar
Oliver Bock committed
58
59
60
61
62
	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
63
64
65
	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
66
	
Oliver Bock's avatar
Oliver Bock committed
67
68
69
70
	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
71
72
73
	
	# prepare additional sources
	
Oliver Bock's avatar
Oliver Bock committed
74
	cd $ROOT/3rdparty/sdl
Oliver Bock's avatar
Oliver Bock committed
75
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
76
77
		echo "Updating SDL..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
78
	else
Oliver Bock's avatar
Oliver Bock committed
79
		echo "Retrieving SDL (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
80
		svn checkout http://svn.libsdl.org/branches/SDL-1.2 . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
81
82
	fi
	
Oliver Bock's avatar
Oliver Bock committed
83
	cd $ROOT/3rdparty/freetype2
Oliver Bock's avatar
Oliver Bock committed
84
	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
85
86
		echo "Updating Freetype2..." | tee -a $ROOT/setup.log
		cvs update -C >> $ROOT/setup.log 2>&1
Oliver Bock's avatar
Oliver Bock committed
87
88
	else
		cd ..
Oliver Bock's avatar
Oliver Bock committed
89
		echo "Retrieving Freetype2 (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
90
		cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/freetype checkout -r VER-2-3-5-REAL freetype2 >> $ROOT/setup.log 2>&1
Oliver Bock's avatar
Oliver Bock committed
91
92
	fi
	
Oliver Bock's avatar
Oliver Bock committed
93
	cd $ROOT/3rdparty/oglft
Oliver Bock's avatar
Oliver Bock committed
94
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
95
		echo "Updating OGLFT..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
96
97
		svn update >> ../../setup.log
	else
Oliver Bock's avatar
Oliver Bock committed
98
		echo "Retrieving OGLFT (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
99
		svn checkout https://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
100
101
	fi
	
Oliver Bock's avatar
Oliver Bock committed
102
	cd $ROOT/3rdparty/boinc
Oliver Bock's avatar
Oliver Bock committed
103
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
104
105
		echo "Updating BOINC..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
106
	else
Oliver Bock's avatar
Oliver Bock committed
107
		echo "Retrieving BOINC (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
108
		svn checkout http://boinc.berkeley.edu/svn/trunk/boinc . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
109
	fi
Oliver Bock's avatar
Oliver Bock committed
110
111

	return 0
Oliver Bock's avatar
Oliver Bock committed
112
113
114
115
116
117
}


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
118
119
120

	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
121
122
123
	cd 3rdparty/mingw/xscripts

	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
124
125
		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
126
127
	else
		cd ..
Oliver Bock's avatar
Oliver Bock committed
128
		echo "Retrieving MinGW build script (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
129
		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
130
131
	fi
	
Oliver Bock's avatar
Oliver Bock committed
132
133
134
135
136
	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
137
138

	return 0
Oliver Bock's avatar
Oliver Bock committed
139
140
141
142
143
}


build_generic()
{
Oliver Bock's avatar
Oliver Bock committed
144
145
146
147
148
149
150
151
152
153
154
155
156
	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
157
	./autogen.sh >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	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
	echo "Building OGLFT (this may take a while)..." | tee -a $ROOT/setup.log
	# 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
	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
185
186

	return 0
Oliver Bock's avatar
Oliver Bock committed
187
188
}

Oliver Bock's avatar
Oliver Bock committed
189

Oliver Bock's avatar
Oliver Bock committed
190
191
192
build_mingw()
{
	echo "Not yet implemented: build_mingw()"
Oliver Bock's avatar
Oliver Bock committed
193
194

	return 0
Oliver Bock's avatar
Oliver Bock committed
195
196
}

Oliver Bock's avatar
Oliver Bock committed
197

Oliver Bock's avatar
Oliver Bock committed
198
199
build_starsphere()
{
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
	echo "Building Starsphere [ORC] (this may take a while)..." | tee -a $ROOT/setup.log
	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

	echo "Building Starsphere [Framework] (this may take a while)..." | tee -a $ROOT/setup.log
	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

	echo "Building Starsphere [Application] (this may take a while)..." | tee -a $ROOT/setup.log
	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
227
228

	return 0
Oliver Bock's avatar
Oliver Bock committed
229
}
Oliver Bock's avatar
Oliver Bock committed
230

Oliver Bock's avatar
Oliver Bock committed
231

Oliver Bock's avatar
Oliver Bock committed
232
233
234
235
build_linux()
{
	build_generic
	build_starsphere
Oliver Bock's avatar
Oliver Bock committed
236
237

	return 0
Oliver Bock's avatar
Oliver Bock committed
238
239
240
241
242
}


build_mac()
{
Oliver Bock's avatar
Oliver Bock committed
243
244
245
246
247
248
	echo "Not yet implemented: build_mac()"

# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
249
250
251
252
253
}


build_win32()
{
Oliver Bock's avatar
Oliver Bock committed
254
255
256
257
258
259
260
	echo "Not yet implemented: build_win32()"

# 	build_mingw
# 	build_generic
# 	build_starsphere

	return 0
Oliver Bock's avatar
Oliver Bock committed
261
262
263
264
265
}


check_last_build()
{
Oliver Bock's avatar
Oliver Bock committed
266
	LASTBUILD=`cat .lastbuild 2>/dev/null`
Oliver Bock's avatar
Oliver Bock committed
267

Oliver Bock's avatar
Oliver Bock committed
268
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
Oliver Bock's avatar
Oliver Bock committed
269
270
271
272
273
		# 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
274
275

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

Oliver Bock's avatar
Oliver Bock committed
278

Oliver Bock's avatar
Oliver Bock committed
279
280
281
282
283
284
285
286
287
288
289
290
291
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
292
	echo "Wrong usage. Stopping!" >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
293
294

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


Oliver Bock's avatar
Oliver Bock committed
298
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
299

300
301
302
ROOT=`pwd`
DATE=`date`

Oliver Bock's avatar
Oliver Bock committed
303
304
305
306
307
TARGET=0
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3

Oliver Bock's avatar
Oliver Bock committed
308
309
310
311
echo "************************************" >> $ROOT/setup.log
echo "Starting new setup run!" >> $ROOT/setup.log
echo "$DATE" >> $ROOT/setup.log
echo "************************************" >> $ROOT/setup.log
312

Oliver Bock's avatar
Oliver Bock committed
313
# crude command line parsing :-)
314

Oliver Bock's avatar
Oliver Bock committed
315
316
317
if [ $# -ne 1 ]; then
  print_usage
  exit 1
318
319
fi

Oliver Bock's avatar
Oliver Bock committed
320
321
322
323
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
324
		echo "Building linux version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
325
326
327
328
		;;
	"--mac")
		TARGET=$TARGET_MAC
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
329
		echo "Building mac version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
330
331
		;;
	"--win32")
Oliver Bock's avatar
Oliver Bock committed
332
333
334
335
		TARGET=$TARGET_WIN32
		check_last_build "$1"
		echo "Building win32 version:" | tee -a $ROOT/setup.log
		;;
Oliver Bock's avatar
Oliver Bock committed
336
	*)
Oliver Bock's avatar
Oliver Bock committed
337
338
339
		print_usage
		exit 1
		;;
Oliver Bock's avatar
Oliver Bock committed
340
esac
341

Oliver Bock's avatar
Oliver Bock committed
342
# here we go...
343

Oliver Bock's avatar
Oliver Bock committed
344
check_prerequisites
Oliver Bock's avatar
Oliver Bock committed
345
346
347
if [ ! $? -eq 0 ]; then
	exit 1
fi
348

Oliver Bock's avatar
Oliver Bock committed
349
350
351
prepare_generic
if [ ! $? -eq 0 ]; then
	exit 1
Oliver Bock's avatar
Oliver Bock committed
352
353
fi

Oliver Bock's avatar
Oliver Bock committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
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
380
exit 0