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


prepare_win32()
{
	cd $ROOT
Oliver Bock's avatar
Oliver Bock committed
109
110
111

	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
112
113
114
	cd 3rdparty/mingw/xscripts

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


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

Oliver Bock's avatar
Oliver Bock committed
181
182
183
184
build_starsphere()
{
	echo "Not yet implemented: build_starsphere()"
}
Oliver Bock's avatar
Oliver Bock committed
185
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

build_linux()
{
	build_generic
	build_starsphere
}


build_mac()
{
	build_generic
	build_starsphere
}


build_win32()
{
	build_mingw
	build_generic
	build_starsphere
}


check_last_build()
{
	LASTBUILD=`cat .lastbuild`

	if [ "$LASTBUILD" != "$1" ]; then
		# 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
233
	echo "Wrong usage. Stopping!" >> $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
234
235
236
}


Oliver Bock's avatar
Oliver Bock committed
237
### main control ##########################################################
Oliver Bock's avatar
Oliver Bock committed
238

239
240
241
ROOT=`pwd`
DATE=`date`

Oliver Bock's avatar
Oliver Bock committed
242
243
244
245
246
TARGET=0
TARGET_LINUX=1
TARGET_MAC=2
TARGET_WIN32=3

Oliver Bock's avatar
Oliver Bock committed
247
248
249
250
echo "************************************" >> $ROOT/setup.log
echo "Starting new setup run!" >> $ROOT/setup.log
echo "$DATE" >> $ROOT/setup.log
echo "************************************" >> $ROOT/setup.log
251

Oliver Bock's avatar
Oliver Bock committed
252
# crude command line parsing :-)
253

Oliver Bock's avatar
Oliver Bock committed
254
255
256
if [ $# -ne 1 ]; then
  print_usage
  exit 1
257
258
fi

Oliver Bock's avatar
Oliver Bock committed
259
260
261
262
case "$1" in
	"--linux")
		TARGET=$TARGET_LINUX
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
263
		echo "Building linux version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
264
265
266
267
		;;
	"--mac")
		TARGET=$TARGET_MAC
		check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
268
		echo "Building mac version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
269
270
271
272
		;;
	"--win32")
			TARGET=$TARGET_WIN32
			check_last_build "$1"
Oliver Bock's avatar
Oliver Bock committed
273
			echo "Building win32 version:" | tee -a $ROOT/setup.log
Oliver Bock's avatar
Oliver Bock committed
274
275
276
277
278
279
			;;
	*)
			print_usage
			exit 1
			;;
esac
280

Oliver Bock's avatar
Oliver Bock committed
281
# here we go...
282

Oliver Bock's avatar
Oliver Bock committed
283
284
check_prerequisites
prepare_generic
285

Oliver Bock's avatar
Oliver Bock committed
286
287
288
289
if [ TARGET=$TARGET_LINUX ]; then
	build_linux
fi

Oliver Bock's avatar
Oliver Bock committed
290
exit 0