setup.sh 9.77 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
38
39
40
41
42
43
44
45
	# wget
	# C compiler
	# lex or flex
	# yacc or bison or byacc
	# m4
}


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


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
112
113
114

	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
115
116
117
	cd 3rdparty/mingw/xscripts

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


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

Oliver Bock's avatar
Oliver Bock committed
184
185
build_starsphere()
{
186
187
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
	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
213
}
Oliver Bock's avatar
Oliver Bock committed
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

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
239
	LASTBUILD=`cat .lastbuild 2>/dev/null`
Oliver Bock's avatar
Oliver Bock committed
240

Oliver Bock's avatar
Oliver Bock committed
241
	if [[ ( -f .lastbuild ) && ( "$LASTBUILD" != "$1" ) ]]; then
Oliver Bock's avatar
Oliver Bock committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
		# 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
262
	echo "Wrong usage. Stopping!" >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
263
264
265
}


Oliver Bock's avatar
Oliver Bock committed
266
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
267

268
269
270
ROOT=`pwd`
DATE=`date`

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

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

Oliver Bock's avatar
Oliver Bock committed
281
# crude command line parsing :-)
282

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

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

Oliver Bock's avatar
Oliver Bock committed
310
# here we go...
311

Oliver Bock's avatar
Oliver Bock committed
312
313
check_prerequisites
prepare_generic
314

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

Oliver Bock's avatar
Oliver Bock committed
319
exit 0