setup.sh 9.78 KB
Newer Older
1
#!/bin/sh
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
32

check_prerequisites()
{
	echo "Not yet implemented: check_prerequisites()"
Oliver Bock's avatar
Oliver Bock committed
33
34
35
	# automake
	# autoconf
	# cmake
Oliver Bock's avatar
Oliver Bock committed
36
37
	# wget
	# C compiler
Oliver Bock's avatar
Oliver Bock committed
38
39
	# libtool
	# ar
Oliver Bock's avatar
Oliver Bock committed
40
41
42
43
44
45
46
47
	# lex or flex
	# yacc or bison or byacc
	# m4
}


prepare_generic()
{
Oliver Bock's avatar
Oliver Bock committed
48
49
50
51
52
53
54
	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
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
	cd $ROOT/3rdparty/sdl
Oliver Bock's avatar
Oliver Bock committed
73
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
74
75
		echo "Updating SDL..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
76
	else
Oliver Bock's avatar
Oliver Bock committed
77
		echo "Retrieving SDL (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
78
		svn checkout http://svn.libsdl.org/branches/SDL-1.2 . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
79
80
	fi
	
Oliver Bock's avatar
Oliver Bock committed
81
	cd $ROOT/3rdparty/freetype2
Oliver Bock's avatar
Oliver Bock committed
82
	if [ -d CVS ]; then
Oliver Bock's avatar
Oliver Bock committed
83
84
		echo "Updating Freetype2..." | tee -a $ROOT/setup.log
		cvs update -C >> $ROOT/setup.log 2>&1
Oliver Bock's avatar
Oliver Bock committed
85
86
	else
		cd ..
Oliver Bock's avatar
Oliver Bock committed
87
		echo "Retrieving Freetype2 (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
88
		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
89
90
	fi
	
Oliver Bock's avatar
Oliver Bock committed
91
	cd $ROOT/3rdparty/oglft
Oliver Bock's avatar
Oliver Bock committed
92
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
93
		echo "Updating OGLFT..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
94
95
		svn update >> ../../setup.log
	else
Oliver Bock's avatar
Oliver Bock committed
96
		echo "Retrieving OGLFT (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
97
		svn checkout https://oglft.svn.sourceforge.net/svnroot/oglft/trunk . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
98
99
	fi
	
Oliver Bock's avatar
Oliver Bock committed
100
	cd $ROOT/3rdparty/boinc
Oliver Bock's avatar
Oliver Bock committed
101
	if [ -d .svn ]; then
Oliver Bock's avatar
Oliver Bock committed
102
103
		echo "Updating BOINC..." | tee -a $ROOT/setup.log
		svn update >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
104
	else
Oliver Bock's avatar
Oliver Bock committed
105
		echo "Retrieving BOINC (this may take a while)..." | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
106
		svn checkout http://boinc.berkeley.edu/svn/trunk/boinc . >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
107
108
109
110
111
112
113
	fi
}


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
114
115
116

	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
117
118
119
	cd 3rdparty/mingw/xscripts

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


build_generic()
{
Oliver Bock's avatar
Oliver Bock committed
138
139
140
141
142
143
144
145
146
147
148
149
150
	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
151
	./autogen.sh >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
152
153
154
155
156
157
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
	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
}

build_mingw()
{
	echo "Not yet implemented: build_mingw()"
Oliver Bock's avatar
Oliver Bock committed
184
185
}

Oliver Bock's avatar
Oliver Bock committed
186
187
build_starsphere()
{
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
	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
215
}
Oliver Bock's avatar
Oliver Bock committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

build_linux()
{
	build_generic
	build_starsphere
}


build_mac()
{
	build_generic
	build_starsphere
}


build_win32()
{
	build_mingw
	build_generic
	build_starsphere
}


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

Oliver Bock's avatar
Oliver Bock committed
243
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
Oliver Bock's avatar
Oliver Bock committed
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
		# TODO: clean build dirs when different target!
		echo "Not yet implemented: cleanup in check_lastbuild()"
	fi

	echo "$1" > .lastbuild
}

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
264
	echo "Wrong usage. Stopping!" >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
265
266
267
}


Oliver Bock's avatar
Oliver Bock committed
268
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
269

270
271
272
ROOT=`pwd`
DATE=`date`

Oliver Bock's avatar
Oliver Bock committed
273
274
275
276
277
TARGET=0
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3

Oliver Bock's avatar
Oliver Bock committed
278
279
280
281
echo "************************************" >> $ROOT/setup.log
echo "Starting new setup run!" >> $ROOT/setup.log
echo "$DATE" >> $ROOT/setup.log
echo "************************************" >> $ROOT/setup.log
282

Oliver Bock's avatar
Oliver Bock committed
283
# crude command line parsing :-)
284

Oliver Bock's avatar
Oliver Bock committed
285
286
287
if [ $# -ne 1 ]; then
  print_usage
  exit 1
288
289
fi

Oliver Bock's avatar
Oliver Bock committed
290
291
292
293
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
294
		echo "Building linux version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
295
296
297
298
		;;
	"--mac")
		TARGET=$TARGET_MAC
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
299
		echo "Building mac version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
300
301
302
303
		;;
	"--win32")
			TARGET=$TARGET_WIN32
			check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
304
			echo "Building win32 version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
305
306
307
308
309
310
			;;
	*)
			print_usage
			exit 1
			;;
esac
311

Oliver Bock's avatar
Oliver Bock committed
312
# here we go...
313

Oliver Bock's avatar
Oliver Bock committed
314
315
check_prerequisites
prepare_generic
316

Oliver Bock's avatar
Oliver Bock committed
317
318
319
320
if [ TARGET=$TARGET_LINUX ]; then
	build_linux
fi

Oliver Bock's avatar
Oliver Bock committed
321
exit 0