Statistics
| Branch: | Revision:

chunker-player / build_ul.sh @ 962b03bc

History | View | Annotate | Download (27.5 KB)

1
#!/bin/bash
2
SCRIPT=$0
3
BASE_UL_DIR=`pwd`
4
EXTERN_DIR="external_libs"
5
MAKE="make -j 4"
6
cd "$BASE_UL_DIR"
7

    
8
which svn >/dev/null || { echo "CANNOT build UL Applications: svn missing. Please install subversion, then retry!"; exit 1; }
9
#which libtoolize >/dev/null || { echo "CANNOT build UL Applications: libtool missing. Please install libtool, then retry!"; exit 1; }
10
which yasm >/dev/null || { echo "CANNOT build UL Applications: yasm missing. Please install yasm, then retry!"; exit 1; }
11
if [ ! -n "MAC_OS" ]; then
12
  #we don't have git on osx - so we avoid using it
13
  which git >/dev/null || { echo "CANNOT build UL Applications: git missing. Please install git, then retry!"; exit 1; }
14
fi
15
WGET_OR_CURL=`which wget`
16
[ -n "$WGET_OR_CURL" ] || { WGET_OR_CURL=`which curl` ; WGET_OR_CURLOPT="-L -O"; }
17
[ -n "$WGET_OR_CURL" ] || { echo "please install wget or curl!"; exit 1; }
18

    
19
#set some defaults
20
IO=${IO:-"httpevent"}
21
MONL=${MONL:-1}
22
ML=${ML:-1}
23

    
24
if [ "$HOSTARCH" = "mingw32" ]; then
25
	MINGW=1
26
fi
27

    
28
#by default build an check
29
BUILD_ALL=1
30

    
31
LIBTOOLIZE_PATH=`whereis libtoolize`
32
if [ "$LIBTOOLIZE_PATH" = "libtoolize:" ]; then
33
	echo "Can't find libtoolize. Try sudo apt-get install libtool"
34
	exit
35
fi
36

    
37
YASM_PATH=`whereis yasm`
38
if [ "$YASM_PATH" = "yasm:" ]; then
39
	echo "Can't find yasm assembler. Try sudo apt-get install yasm"
40
	exit
41
fi
42

    
43
mkdir $EXTERN_DIR
44

    
45
if [ -n "$MINGW" ]; then
46
	TEMP_BZ2="$BASE_UL_DIR/$EXTERN_DIR/bzip2_mingw"
47
	if [ ! -e "$TEMP_BZ2/lib/libbz2.a" ]; then
48
		#we erase and rebuild since the installation is not there
49
		cd "$BASE_UL_DIR/$EXTERN_DIR"
50
		rm -r -f bzip2_mingw
51
		#get the latest bzip2 library
52
		$WGET_OR_CURL $WGET_OR_CURLOPT http://switch.dl.sourceforge.net/project/gnuwin32/bzip2/1.0.5/bzip2-1.0.5-bin.zip; unzip bzip2-1.0.5-bin.zip -d bzip2_mingw
53
		$WGET_OR_CURL $WGET_OR_CURLOPT http://sunet.dl.sourceforge.net/project/gnuwin32/bzip2/1.0.5/bzip2-1.0.5-lib.zip; unzip -o bzip2-1.0.5-lib.zip -d bzip2_mingw
54
		rm -f bzip2-1.0.5-lib.zip; rm -f bzip2-1.0.5-bin.zip;
55
	fi
56
	LOCAL_BZ2=$TEMP_BZ2
57
else
58
	#try to find libbz2 in your system
59
	LOCAL_BZ2_A=/usr/lib/libbz2.a
60
	if [ ! -e $LOCAL_BZ2_A ]; then
61
		[ X$LOCAL_BZ2_A != X ] && LOCAL_BZ2=`dirname $LOCAL_BZ2_A`/..
62
		if [ ! -e "$LOCAL_BZ2/lib/libbz2.a" ]; then
63
			#wrong location and/or folders structure
64
			echo "you seem not to have file libbz2.a or the location is non-standard.Will be built locally."
65
			LOCAL_BZ2=""
66
			BUILD_BZ2=1
67
		fi
68
	else
69
		echo "You have file libbz2.a in default system"
70
		echo "setting path for it to default /usr/lib/libbz2.a"
71
		LOCAL_BZ2="/usr"
72
	fi
73
fi
74

    
75
if [ -n "$MINGW" ]; then
76
	TEMP_Z="$BASE_UL_DIR/$EXTERN_DIR/zlib_mingw"
77
	if [ ! -e "$TEMP_Z/lib/libz.a" ]; then
78
		cd "$BASE_UL_DIR/$EXTERN_DIR"
79
		rm -r -f zlib_mingw;
80
		#get the latest zlib libraries
81
		$WGET_OR_CURL $WGET_OR_CURLOPT http://sunet.dl.sourceforge.net/project/gnuwin32/zlib/1.2.3/zlib-1.2.3-bin.zip; unzip zlib-1.2.3-bin.zip -d zlib_mingw
82
		$WGET_OR_CURL $WGET_OR_CURLOPT http://kent.dl.sourceforge.net/project/gnuwin32/zlib/1.2.3/zlib-1.2.3-lib.zip; unzip -o zlib-1.2.3-lib.zip -d zlib_mingw
83
		rm -f zlib-1.2.3-bin.zip; rm -f zlib-1.2.3-lib.zip;
84
	fi
85
	LOCAL_Z=$TEMP_Z
86
else
87
	LOCAL_Z="$BASE_UL_DIR/$EXTERN_DIR/zlib/temp_zlib_install_linux"
88
	if [ -f "$LOCAL_Z/lib/libz.a" ]; then
89
		echo "libz.a found in $LOCAL_Z/lib"
90
	else
91
		#force building locally
92
		#does not exist systemwide
93
		cd "$BASE_UL_DIR/$EXTERN_DIR"
94
		rm -r -f zlib
95
		#get and compile latest zlib library
96
		$WGET_OR_CURL $WGET_OR_CURLOPT http://zlib.net/zlib-1.2.5.tar.gz; tar xzf zlib-1.2.5.tar.gz; mv zlib-1.2.5 zlib; rm -f zlib-1.2.5.tar.gz
97
		cd zlib
98
		#make and install in local folder
99
		./configure --prefix="$LOCAL_Z"
100
		$MAKE; $MAKE install
101
	fi
102

    
103
	#clean all external libraries if CLEAN_EXTERNAL_BUILD=1
104
	if [ -n "$CLEAN_EXTERNAL_BUILD" ]; then
105
		#remove previuos versions of external libs builds
106
		rm -r -f $EXTERN_DIR
107
	fi
108
fi
109
LIBSDLIMAGE_FLAGS="$LIBSDLIMAGE_FLAGS -I$LOCAL_Z/include"
110
LIBSDLIMAGE_LDFLAGS="$LIBSDLIMAGE_LDFLAGS -L$LOCAL_Z/lib"
111

    
112
if [ ! -n "$MINGW" ]; then
113
	TEMP_BZ2="$BASE_UL_DIR/$EXTERN_DIR/bzip2/temp_bzip2_install_linux"
114
	if [ -n "$BUILD_BZ2" ]; then
115
		#we have to build it either because of user will or because does not exist system wide
116
		if [ -z "$LOCAL_BZ2" ]; then
117
			#does not exist systemwide
118
			if [ -n "$BUILD_ALL" -a ! -e "$TEMP_BZ2" ]; then
119
				#we erase and rebuild since the installation is not there
120
				cd "$BASE_UL_DIR/$EXTERN_DIR"
121
				rm -r -f bzip2
122
				#get and compile latest bzip2 library
123
				$WGET_OR_CURL $WGET_OR_CURLOPT http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz; tar xzf bzip2-1.0.5.tar.gz; mv bzip2-1.0.5 bzip2; rm -f bzip2-1.0.5.tar.gz
124
				cd bzip2
125
				#make and install in local folder
126
				$MAKE; $MAKE install PREFIX="$TEMP_BZ2"
127
			fi
128
			#previous local install is existing, just set pointer to it
129
			#or override location if it was set as systemwide
130
			LOCAL_BZ2=$TEMP_BZ2
131
		fi
132
	fi
133
fi
134

    
135

    
136
if [ -n "$MINGW" ]; then
137
	# plibc
138
	LOCAL_PLIBC="$BASE_UL_DIR/$EXTERN_DIR/plibc"
139
	if [ -f "$BASE_UL_DIR/$EXTERN_DIR/plibc/lib/libplibc.dll.a" ]; then
140
		echo "You have file libplibc.dll.a in default system: $BASE_UL_DIR/$EXTERN_DIR/plibc/lib/libplibc.dll.a"
141
	else
142
		cd "$BASE_UL_DIR/$EXTERN_DIR"
143
		rm -fR plibc
144
		$WGET_OR_CURL $WGET_OR_CURLOPT http://ovh.dl.sourceforge.net/project/plibc/plibc/0.1.5/plibc-0.1.5.zip
145
		unzip plibc-0.1.5.zip -d plibc;
146
		rm -f plibc/lib/*.la
147
		rm -f plibc-0.1.5.zip
148
	fi
149
	LIBMICROHHTPD_FLAGS="-I$BASE_UL_DIR/$EXTERN_DIR/plibc/include"
150
	LIBMICROHHTPD_LDFLAGS="-L$BASE_UL_DIR/$EXTERN_DIR/plibc/lib"
151

    
152
	# libiconv
153
	LOCAL_LIBICONV="$BASE_UL_DIR/$EXTERN_DIR/libiconv/temp_libiconv_install_mingw"
154
	if [ -f "$LOCAL_LIBICONV/lib/libiconv.a" ]; then
155
		echo "libiconv.a found in $LOCAL_LIBICONV/lib"
156
	else
157
		cd "$BASE_UL_DIR/$EXTERN_DIR"
158
		rm -fR libiconv
159
		
160
		#download binaries
161
		#~ wget http://kent.dl.sourceforge.net/project/gnuwin32/libintl/0.14.4/libintl-0.14.4-dep.zip; unzip libintl-0.14.4-dep.zip -d libiconv
162
		#~ mkdir -p $LOCAL_LIBICONV/lib/
163
		#~ mv libiconv/*.dll $LOCAL_LIBICONV/lib/
164
		#~ rm -f libintl-0.14.4-dep.zip
165
		
166
		#build from sources
167
		$WGET_OR_CURL $WGET_OR_CURLOPT http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
168
		tar zxvf libiconv-1.13.tar.gz; mv libiconv-1.13 libiconv; rm -f libiconv-1.13.tar.gz; cd libiconv
169
		./configure --enable-static ${HOSTARCH:+--host=$HOSTARCH} --prefix=$LOCAL_LIBICONV
170
		make
171
		make install
172
	fi
173
	LIBSDLIMAGE_FLAGS="$LIBSDLIMAGE_FLAGS -I$LOCAL_LIBICONV/include"
174
	#~ LIBSDLIMAGE_LDFLAGS="$LIBSDLIMAGE_LDFLAGS -L$LOCAL_LIBICONV/lib"
175

    
176
	LOCAL_LIBINTL="$BASE_UL_DIR/$EXTERN_DIR/libintl/temp_libintl_install_mingw"
177
	if [ -f "$LOCAL_LIBINTL/lib/libintl.dll.a" ] || [ -f "$LOCAL_LIBINTL/lib/libintl.a" ]; then
178
		echo "libintl libraries found in $LOCAL_LIBINTL/lib"
179
	else
180
		cd "$BASE_UL_DIR/$EXTERN_DIR"
181
		#download binaries
182
		rm -fR libintl
183
		$WGET_OR_CURL $WGET_OR_CURLOPT http://garr.dl.sourceforge.net/project/gnuwin32/libintl/0.14.4/libintl-0.14.4-lib.zip; unzip -o libintl-0.14.4-lib.zip -d libintl
184
		$WGET_OR_CURL $WGET_OR_CURLOPT http://switch.dl.sourceforge.net/project/gnuwin32/libintl/0.14.4/libintl-0.14.4-bin.zip; unzip -o libintl-0.14.4-bin.zip -d libintl
185
		rm -f libintl-0.14.4-bin.zip; rm -f libintl-0.14.4-lib.zip
186
		cd libintl
187
		mkdir -p $LOCAL_LIBINTL;
188
		mv bin $LOCAL_LIBINTL/; mv lib $LOCAL_LIBINTL/; mv include $LOCAL_LIBINTL/
189
		mv man $LOCAL_LIBINTL/; mv share $LOCAL_LIBINTL/
190
		
191
		# build from gettext sources
192
		#~ rm -fR gettext
193
		#~ rm -fR libintl
194
		#~ wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
195
		#~ tar zxvf gettext-0.18.1.1.tar.gz; mv gettext-0.18.1.1 gettext; cd gettext
196
		#~ ./configure ${HOSTARCH:+--host=$HOSTARCH} --with-libiconv-prefix=$LOCAL_LIBICONV
197
		#~ cd gettext-runtime/intl
198
		#~ make
199
		#~ mkdir -p $LOCAL_LIBINTL/bin; mkdir -p $LOCAL_LIBINTL/include; mkdir -p $LOCAL_LIBINTL/lib
200
		#~ cp ./.libs/*a $LOCAL_LIBINTL/lib
201
		#~ cp ./.libs/*.dll $LOCAL_LIBINTL/bin
202
		#~ cp *.h $LOCAL_LIBINTL/include
203
		#~ cd ../../../
204
		#~ rm -f gettext-0.18.1.1.tar.gz
205
		#~ rm -fR gettext
206
	fi
207
	LIBSDLIMAGE_FLAGS="$LIBSDLIMAGE_FLAGS -I$LOCAL_LIBINTL"
208
	LIBSDLIMAGE_LDFLAGS="$LIBSDLIMAGE_LDFLAGS -L$LOCAL_LIBINTL/lib"
209

    
210
	# check for mingw pthread libs
211
	LOCAL_PTHREAD="$BASE_UL_DIR/$EXTERN_DIR/pthreads"
212
	if [ -f "$BASE_UL_DIR/$EXTERN_DIR/pthreads/lib/libpthread.a" ]; then
213
		echo "libpthread.a in $LOCAL_PTHREAD/lib/"
214
	else
215
		cd "$BASE_UL_DIR/$EXTERN_DIR"
216
		rm -fR pthreads
217
		$WGET_OR_CURL $WGET_OR_CURLOPT http://www.mirrorservice.org/sites/sourceware.org/pub/pthreads-win32/pthreads-w32-2-8-0-release.tar.gz
218
		tar zxvf pthreads-w32-2-8-0-release.tar.gz; mv pthreads-w32-2-8-0-release pthreads; rm -f pthreads-w32-2-8-0-release.tar.gz;
219
		cd pthreads
220
		mkdir -p ./{include,lib,bin}
221
		make CROSS=i586-mingw32msvc- GC-inlined
222
		mv libpthreadGC2.a ./lib
223
		mv *.h ./include
224
		mv pthreadGC2.dll ./bin
225
		ln -s "$BASE_UL_DIR/$EXTERN_DIR/pthreads/lib/libpthreadGC2.a" "$BASE_UL_DIR/$EXTERN_DIR/pthreads/lib/libpthread.a"
226
	fi
227
	LIBMICROHHTPD_FLAGS="$LIBMICROHHTPD_FLAGS -I$BASE_UL_DIR/$EXTERN_DIR/pthreads/include"
228
	LIBMICROHHTPD_LDFLAGS="$LIBMICROHHTPD_LDFLAGS -L$BASE_UL_DIR/$EXTERN_DIR/pthreads/lib"
229
fi
230

    
231

    
232
#libpng
233
if [ -n "$MINGW" ]; then
234
	LOCAL_LIBPNG="$BASE_UL_DIR/$EXTERN_DIR/libpng/temp_libpng_install_mingw"
235
else
236
	LOCAL_LIBPNG="$BASE_UL_DIR/$EXTERN_DIR/libpng/temp_libpng_install_linux"
237
fi
238
if [ -f "$LOCAL_LIBPNG/lib/libpng.a" ]; then
239
	echo "libpng.a found in $LOCAL_LIBPNG/lib"
240
else
241
	cd "$BASE_UL_DIR/$EXTERN_DIR"
242
	rm -fR libpng
243
	$WGET_OR_CURL $WGET_OR_CURLOPT http://downloads.sourceforge.net/project/libpng/libpng14/older-releases/1.4.4/libpng-1.4.4.tar.gz
244
	tar zxvf libpng-1.4.4.tar.gz; rm -f libpng-1.4.4.tar.gz
245
	mv libpng-1.4.4 libpng; cd libpng;
246
	CFLAGS=-I$LOCAL_Z/include CPPFLAGS=-I$LOCAL_Z/include LDFLAGS=-L$LOCAL_Z/lib sh configure  ${HOSTARCH:+--host=$HOSTARCH} --prefix=$LOCAL_LIBPNG
247
	make
248
	make install
249
fi
250
LIBSDLIMAGE_FLAGS="$LIBSDLIMAGE_FLAGS -I$LOCAL_LIBPNG/include"
251
LIBSDLIMAGE_LDFLAGS="$LIBSDLIMAGE_LDFLAGS -L$LOCAL_LIBPNG/lib"
252

    
253

    
254
if [ -n "$MINGW" ]; then
255
	TEMP_X264="$BASE_UL_DIR/$EXTERN_DIR/x264/temp_x264_install_mingw"
256
else
257
	TEMP_X264="$BASE_UL_DIR/$EXTERN_DIR/x264/temp_x264_install_linux"
258
fi
259
if [ -n "$BUILD_X264" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_X264" ]; then
260
	cd "$BASE_UL_DIR/$EXTERN_DIR"
261
	if [ -e "x264" ]; then
262
		cd x264
263
		make clean
264
	else
265
		#get and compile latest x264 library
266
		if [ -n "$MAC_OS" ]; then
267
		   $WGET_OR_CURL $WGET_OR_CURLOPT ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20110115-2245.tar.bz2
268
		   tar yvfx x264-snapshot-20110115-2245.tar.bz2
269
		   rm -f x264-snapshot-20110115-2245.tar.bz2
270
		   mv x264-snapshot-20110115-2245/ x264
271
		else
272
		   git clone git://git.videolan.org/x264.git
273
		fi
274
		cd x264
275
	fi	
276

    
277
	#make and install in local folder
278
	./configure --prefix="$TEMP_X264" ${HOSTARCH:+--host=$HOSTARCH}
279
	$MAKE; $MAKE install
280
fi
281

    
282

    
283
if [ -n "$MINGW" ]; then
284
	TEMP_MP3LAME="$BASE_UL_DIR/$EXTERN_DIR/mp3lame/temp_mp3lame_install_mingw"
285
else
286
	TEMP_MP3LAME="$BASE_UL_DIR/$EXTERN_DIR/mp3lame/temp_mp3lame_install_linux"
287
fi
288
if [ -n "$BUILD_MP3LAME" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_MP3LAME" ]; then
289
	cd "$BASE_UL_DIR/$EXTERN_DIR"
290
	
291
	if [ -e "mp3lame" ]; then
292
		cd mp3lame
293
		make clean
294
	else
295
		#get and compile latest mp3lame library
296
		rm -f lame-3.98.4.tar.gz
297
		$WGET_OR_CURL $WGET_OR_CURLOPT http://sourceforge.net/projects/lame/files/lame/3.98.4/lame-3.98.4.tar.gz/download; tar xzf download; rm -f download; mv lame-3.98.4 mp3lame;
298
		cd mp3lame
299
	fi	
300

    
301
	#make and install in local folder
302
	./configure --disable-gtktest --disable-frontend --prefix="$TEMP_MP3LAME" ${HOSTARCH:+--host=$HOSTARCH}
303
	$MAKE; $MAKE install
304
fi
305

    
306

    
307
if [ -n "$MINGW" ]; then
308
	TEMP_FFMPEG="$BASE_UL_DIR/$EXTERN_DIR/ffmpeg/temp_ffmpeg_install_mingw"
309
else
310
	TEMP_FFMPEG="$BASE_UL_DIR/$EXTERN_DIR/ffmpeg/temp_ffmpeg_install_linux"
311
fi
312
if [ ! -e "$TEMP_X264/lib/libx264.a" ] || [ ! -e "$TEMP_MP3LAME/lib/libmp3lame.a" ] || [ ! -e "$LOCAL_Z/lib/libz.a" ] || [ ! -e "$LOCAL_BZ2/lib/libbz2.a" ]; then
313
	echo "Compilation of ffmpeg dependancies failed. Check your internet connection and errors. Exiting."
314
fi
315
if [ -n "$BUILD_FFMPEG" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_FFMPEG" ]; then
316
	cd "$BASE_UL_DIR/$EXTERN_DIR"
317
	
318
	if [ -e "ffmpeg" ]; then
319
		cd ffmpeg
320
		make clean
321
	else
322
		#get and compile ffmpeg with x264 support
323
		#get latest snapshot
324
		#rm -f ffmpeg-checkout-snapshot.tar.bz2
325
		#wget http://ffmpeg.org/releases/ffmpeg-checkout-snapshot.tar.bz2; tar xjf ffmpeg-checkout-snapshot.tar.bz2; mv ffmpeg-checkout-20* ffmpeg
326
		#do not get latest snapshot
327
		#get a release tarball instead
328
		rm -f ffmpeg-0.6.tar.bz2
329
		$WGET_OR_CURL $WGET_OR_CURLOPT http://ffmpeg.org/releases/ffmpeg-0.6.tar.bz2; tar xjf ffmpeg-0.6.tar.bz2; rm -f ffmpeg-0.6.tar.bz2; mv ffmpeg-0.6 ffmpeg
330
		#svn -r 21010 checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
331
		#do not get latest snapshot
332
		#get instead a specific one because allows output video rate resampling
333
		#svn -r 21010 checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
334
		cd ffmpeg
335
	fi	
336

    
337
	if [ -n "$MINGW" ]; then
338
		HOSTARCH_OLDSTYLE=${HOSTARCH:+--arch=i586 --enable-cross-compile --cross-prefix=i586-mingw32msvc- --target-os=$HOSTARCH --disable-sse}
339
	
340
		#configure bugfix
341
		sed -i -e 's/^SDL_CONFIG=/[ -z "$SDL_CONFIG" ] \&\& SDL_CONFIG=/g' ./configure;
342
		sed -i -e 's/check_cflags \+-Werror=missing-prototypes/#\0/g' configure;
343
	
344
		./configure $HOSTARCH_OLDSTYLE --enable-gpl --enable-nonfree --enable-version3 --enable-libmp3lame --enable-libx264 --disable-pthreads --extra-cflags="-I$TEMP_X264/include -I$TEMP_MP3LAME/include -I$LOCAL_BZ2/include  -I$LOCAL_Z/include" --extra-ldflags="-L$TEMP_X264/lib -L$TEMP_MP3LAME/lib -L$LOCAL_BZ2/lib -L$LOCAL_Z/lib" --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --prefix="$TEMP_FFMPEG"
345
	else
346
		./configure --enable-gpl --enable-nonfree --enable-version3 --enable-libmp3lame --enable-libx264 --enable-pthreads --extra-cflags="-I$TEMP_X264/include -I$TEMP_MP3LAME/include -I$LOCAL_BZ2/include  -I$LOCAL_Z/include" --extra-ldflags="-L$TEMP_X264/lib -L$TEMP_MP3LAME/lib -L$LOCAL_BZ2/lib -L$LOCAL_Z/lib" --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --prefix="$TEMP_FFMPEG"
347
	fi
348
	$MAKE; $MAKE install
349
fi
350

    
351

    
352
if [ -n "$MINGW" ]; then
353
	TEMP_MHD="$BASE_UL_DIR/$EXTERN_DIR/libmicrohttpd/temp_mhd_install_mingw"
354
else
355
	TEMP_MHD="$BASE_UL_DIR/$EXTERN_DIR/libmicrohttpd/temp_mhd_install_linux"
356
fi
357
if [ -n "$BUILD_MHD" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_MHD" ]; then
358
	cd "$BASE_UL_DIR/$EXTERN_DIR"
359
	
360
	if [ -e "libmicrohttpd" ]; then
361
		cd libmicrohttpd
362
		make clean
363
	else
364
		#get and compile libmicrohttpd lib
365
		if [ X`svn --version|head -1|cut -c14-16` = X1.6 ]; then
366
			svn --non-interactive --trust-server-cert checkout https://gnunet.org/svn/libmicrohttpd
367
		else
368
			svn --non-interactive checkout https://gnunet.org/svn/libmicrohttpd
369
		fi
370
		cd libmicrohttpd || { echo "CANNOT download libmicrohttpd"; exit 1; }
371
 
372
	fi
373
	
374
	autoreconf -fi
375
	if [ -n "$MINGW" ]; then
376
		CFLAGS="$CFLAGS $LIBMICROHHTPD_FLAGS" CPPFLAGS="$CPPFLAGS $LIBMICROHHTPD_FLAGS" LDFLAGS="$LDFLAGS $LIBMICROHHTPD_LDFLAGS" ./configure ${HOSTARCH:+--host=$HOSTARCH} --disable-curl --disable-https --enable-messages --disable-client-side --prefix="$TEMP_MHD"
377
	else
378
		./configure --disable-curl --disable-https --enable-messages --disable-client-side --prefix="$TEMP_MHD"
379
	fi
380
	$MAKE; $MAKE install
381
fi
382

    
383

    
384
if [ -n "$MINGW" ]; then
385
	TEMP_SDL="$BASE_UL_DIR/$EXTERN_DIR/sdl_mingw/temp_sdl_install"
386
else
387
	TEMP_SDL="$BASE_UL_DIR/$EXTERN_DIR/sdl/temp_sdl_install_linux"
388
fi
389
if [ -n "$BUILD_SDL" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_SDL" ]; then
390
	cd "$BASE_UL_DIR/$EXTERN_DIR"
391

    
392
	if [ -n "$MINGW" ]; then
393
		if [ ! -e "sdl_mingw" ]; then
394
			# use binaries
395
			$WGET_OR_CURL $WGET_OR_CURLOPT http://www.libsdl.org/release/SDL-devel-1.2.14-mingw32.tar.gz; tar zxvf SDL-devel-1.2.14-mingw32.tar.gz; mv SDL-1.2.14 sdl_mingw;
396
			rm -f SDL-devel-1.2.14-mingw32.tar.gz;
397
			cd sdl_mingw
398
			mkdir temp_sdl_install
399
			mv bin $TEMP_SDL/; mv lib $TEMP_SDL/; mv include $TEMP_SDL/; mv share $TEMP_SDL/
400
		fi
401

    
402
		# build from sources
403
		#~ wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz; tar xzf SDL-1.2.14.tar.gz; rm -f SDL-1.2.14.tar.gz; mv SDL-1.2.14 sdl
404
		#make and install in local folder
405
		#~ ./configure ${HOSTARCH:+--host=$HOSTARCH} --disable-video-directfb --prefix="$TEMP_SDL"
406
		#~ $MAKE; $MAKE install
407
	else
408
		if [ -e "sdl" ]; then
409
			cd sdl
410
			make clean
411
		else
412
			#get and compile SDL lib
413
			$WGET_OR_CURL $WGET_OR_CURLOPT http://www.libsdl.org/release/SDL-1.2.14.tar.gz; tar xzf SDL-1.2.14.tar.gz; mv SDL-1.2.14 sdl; rm -f SDL-1.2.14.tar.gz
414
			cd sdl
415
		fi
416
		#make and install in local folder
417
		./configure --disable-video-directfb --prefix="$TEMP_SDL"
418
		$MAKE; $MAKE install
419
	fi
420
fi
421

    
422
if [ -n "$BUILD_SDLIMAGE" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_SDL/lib/libSDL_image.a" ]; then
423
	cd "$BASE_UL_DIR/$EXTERN_DIR"
424
	
425
	if [ -e "sdlimage" ]; then
426
		cd sdlimage
427
		make clean
428
	else
429
		#get and compile SDLIMAGE lib
430
		$WGET_OR_CURL $WGET_OR_CURLOPT http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.10.tar.gz; tar xzf SDL_image-1.2.10.tar.gz; mv SDL_image-1.2.10 sdlimage
431
		rm -f SDL_image-1.2.10.tar.gz
432
		cd sdlimage
433
	fi
434
	
435
	#make and install in local SDL folder
436
        ./autogen.sh
437
	echo "./configure LIBPNG_CFLAGS=\"-I$LOCAL_LIBPNG/include\" LIBPNG_LIBS=\"-L$LOCAL_LIBPNG/lib\" CFLAGS=\"$CFLAGS $LIBSDLIMAGE_FLAGS -static\" CPPFLAGS=\"$CPPFLAGS $LIBSDLIMAGE_FLAGS -static\" LDFLAGS=\"$LDFLAGS $LIBSDLIMAGE_LDFLAGS -static\" ${HOSTARCH:+--host=$HOSTARCH} --prefix=\"$TEMP_SDL\" --with-sdl-prefix=\"$TEMP_SDL\" --disable-png-shared"
438

    
439
	echo "./configure CFLAGS=\"$CFLAGS -I$LOCAL_LIBPNG/include\" CPPFLAGS=\"$CPPFLAGS -I$LOCAL_LIBPNG/include\" LDFLAGS=\"$LDFLAGS -L$LOCAL_LIBPNG/lib\" ${HOSTARCH:+--host=$HOSTARCH} --prefix=\"$TEMP_SDL\" --with-sdl-prefix=\"$TEMP_SDL\" --disable-png-shared"
440

    
441
	./configure CFLAGS="$CFLAGS $LIBSDLIMAGE_FLAGS -I$LOCAL_LIBPNG/include" CPPFLAGS="$CPPFLAGS -I$LOCAL_LIBPNG/include" LDFLAGS="$LDFLAGS $LIBSDLIMAGE_LDFLAGS -L$LOCAL_LIBPNG/lib" ${HOSTARCH:+--host=$HOSTARCH} --prefix="$TEMP_SDL" --with-sdl-prefix="$TEMP_SDL" --disable-png-shared
442

    
443
	$MAKE; $MAKE install
444
fi
445

    
446
# SDL_ttf depends on freetype
447
if [ -n "$MINGW" ]; then
448
	TEMP_FREETYPE="$BASE_UL_DIR/$EXTERN_DIR/freetype/temp_freetype_install_mingw"
449
else
450
	TEMP_FREETYPE="$BASE_UL_DIR/$EXTERN_DIR/freetype/temp_freetype_install_linux"
451
fi
452
if [ -n "$BUILD_FREETYPE" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_FREETYPE" ]; then
453
	cd "$BASE_UL_DIR/$EXTERN_DIR"
454
	if [ -e "freetype" ]; then
455
		cd freetype
456
		make clean
457
	else
458
		#get and compile SDLTTF lib
459
		rm -f freetype-2.1.10.tar.gz
460
		$WGET_OR_CURL $WGET_OR_CURLOPT http://mirror.lihnidos.org/GNU/savannah/freetype/freetype-2.1.10.tar.gz; tar xzf freetype-2.1.10.tar.gz; rm -f freetype-2.1.10.tar.gz; mv freetype-2.1.10 freetype
461
		cd freetype
462
	fi
463

    
464
	#make and install in local folder
465
	./configure ${HOSTARCH:+--host=$HOSTARCH} --prefix="$TEMP_FREETYPE"
466
	$MAKE; $MAKE install
467
fi
468

    
469
if [ -n "$BUILD_SDLTTF" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_SDL/lib/libSDL_ttf.a" ]; then
470
	cd "$BASE_UL_DIR/$EXTERN_DIR"
471
	
472
	if [ -e "sdlttf" ]; then
473
		cd sdlttf
474
		make clean
475
	else
476
		#get and compile SDLTTF lib
477
		rm -f SDL_ttf-2.0.10.tar.gz
478
		$WGET_OR_CURL $WGET_OR_CURLOPT http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.10.tar.gz; tar xzf SDL_ttf-2.0.10.tar.gz; rm -f SDL_ttf-2.0.10.tar.gz; mv SDL_ttf-2.0.10 sdlttf
479
		cd sdlttf
480
	fi
481

    
482
	#make and install in local SDL folder
483
	./configure ${HOSTARCH:+--host=$HOSTARCH} --with-freetype-prefix="$TEMP_FREETYPE" --with-sdl-prefix="$TEMP_SDL" --prefix="$TEMP_SDL"
484
	$MAKE; $MAKE install
485
fi
486

    
487
if [ -n "$MINGW" ]; then
488
	TEMP_CURL="$BASE_UL_DIR/$EXTERN_DIR/curl/temp_curl_install_mingw"
489
else
490
	TEMP_CURL="$BASE_UL_DIR/$EXTERN_DIR/curl/temp_curl_install_linux"
491
fi
492
if [ -n "$BUILD_CURL" ] || [ -n "$BUILD_ALL" -a ! -e "$TEMP_CURL" ]; then
493
	cd "$BASE_UL_DIR/$EXTERN_DIR"
494
	if [ -e "curl" ]; then
495
		cd curl
496
		make clean
497
	else
498
		#get and compile CURL lib
499
		rm -f curl-7.21.0.tar.bz2
500
		$WGET_OR_CURL $WGET_OR_CURLOPT http://curl.haxx.se/download/curl-7.21.0.tar.bz2; tar xjf curl-7.21.0.tar.bz2; rm -f curl-7.21.0.tar.bz2; mv curl-7.21.0 curl
501
		cd curl
502
	fi
503

    
504
	#make and install in local folder
505
	./configure ${HOSTARCH:+--host=$HOSTARCH} --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --without-libssh2 --without-ssl --without-krb4 --enable-static --disable-shared --without-zlib --without-libidn --prefix="$TEMP_CURL"
506
	$MAKE; $MAKE install
507
fi
508

    
509
if [ -d "$BASE_UL_DIR/../../3RDPARTY-LIBS/libevent" ]; then
510
	LOCAL_EVENT="$BASE_UL_DIR/../../3RDPARTY-LIBS/libevent"
511
	echo "found LIBEVENT in $LOCAL_EVENT"
512
else
513
	if [ "$LOCAL_EVENT_A" = "" ]; then
514
		if [ -f "/usr/lib/libevent.a" ]; then
515
			echo "You have file libevent.a in default system"
516
			echo "setting path for it to default /usr/lib/libevent.a"
517
			LOCAL_EVENT="/usr"
518
		else
519
			echo "you seem not to have file libevent.a. EXITING."
520
			exit
521
		fi
522
	else
523
		LOCAL_EVENT=`dirname $LOCAL_EVENT_A`/..
524
	fi
525
fi
526

    
527
if [ -d "$BASE_UL_DIR/../../3RDPARTY-LIBS/libconfuse" ]; then
528
	LOCAL_CONFUSE="$BASE_UL_DIR/../../3RDPARTY-LIBS/libconfuse"
529
	echo "found LIBCONFUSE in $LOCAL_CONFUSE"
530
else
531
	if [ "$LOCAL_CONFUSE_A" = "" ]; then
532
		if [ -f "/usr/lib/libconfuse.a" ]; then
533
			echo "You have file libconfuse.a in default system"
534
			echo "setting path for it to default /usr/lib/libconfuse.a"
535
			LOCAL_CONFUSE="/usr"
536
		else
537
			echo "you seem not to have file libconfuse.a. EXITING."
538
			exit
539
		fi
540
	else
541
		LOCAL_CONFUSE=`dirname $LOCAL_CONFUSE_A`/..
542
	fi
543
fi
544

    
545
#set needed paths to external libraries
546
echo "-----"
547
LOCAL_X264=$TEMP_X264
548
echo "path for X264 dependancy set to $LOCAL_X264"
549
LOCAL_MP3LAME=$TEMP_MP3LAME
550
echo "path for MP3LAME dependancy set to $LOCAL_MP3LAME"
551
LOCAL_FFMPEG=$TEMP_FFMPEG
552
echo "path for FFMPEG dependancy set to $LOCAL_FFMPEG"
553
LOCAL_MHD=$TEMP_MHD
554
echo "path for LIBMICROHTTPD dependancy set to $LOCAL_MHD"
555
LOCAL_ABS_SDL=$TEMP_SDL
556
echo "path for SDL dependancy set to $LOCAL_ABS_SDL"
557
LOCAL_SDLIMAGE=$TEMP_SDL
558
echo "path for SDLIMAGE dependancy set to $LOCAL_SDLIMAGE"
559
LOCAL_SDLTTF=$TEMP_SDL
560
echo "path for SDLTTF dependancy set to $LOCAL_SDLTTF"
561
LOCAL_FREETYPE=$TEMP_FREETYPE
562
echo "path for FREETYPE dependancy set to $LOCAL_FREETYPE"
563
LOCAL_CURL=$TEMP_CURL
564
echo "path for CURL dependancy set to $LOCAL_CURL"
565

    
566
echo "path for BZ2 dependancy is set to $LOCAL_BZ2"
567
echo "path for ZLIB dependancy is set to $LOCAL_Z"
568

    
569
echo "path for LIBEVENT dependancy is set to $LOCAL_EVENT"
570
echo "path for LIBCONFUSE dependancy is set to $LOCAL_CONFUSE"
571
echo "-----"
572

    
573
#compile the UL external applications
574
#chunker_streamer and chunker_player
575

    
576
#CHUNKER_STREAMER
577

    
578
# streamer is not supported yet on windows
579
if [ ! -n "$MINGW" ]; then
580
	echo "----------------COMPILING CHUNKER STREAMER"
581
	cd "$BASE_UL_DIR"
582
	cd chunker_streamer
583
	$MAKE clean
584
	LOCAL_X264=$LOCAL_X264 LOCAL_MP3LAME=$LOCAL_MP3LAME LOCAL_FFMPEG=$LOCAL_FFMPEG LOCAL_BZ2=$LOCAL_BZ2 LOCAL_Z=$LOCAL_Z LOCAL_CONFUSE=$LOCAL_CONFUSE LOCAL_CURL=$LOCAL_CURL IO=$IO MAC_OS=$MAC_OS $MAKE || { echo "Failed to build CHUNKER STREAMER"; exit 1; }
585
	echo "----------------FINISHED COMPILING CHUNKER STREAMER"
586
fi
587

    
588
#CHUNKER_PLAYER
589
echo "----------------COMPILING CHUNKER PLAYER"
590
cd "$BASE_UL_DIR"
591
cd chunker_player
592
$MAKE clean
593
LIBEVENT_DIR=$LOCAL_EVENT LOCAL_PTHREAD=$LOCAL_PTHREAD LOCAL_LIBPNG=$LOCAL_LIBPNG LOCAL_LIBICONV=$LOCAL_LIBICONV LOCAL_LIBINTL=$LOCAL_LIBINTL LOCAL_PLIBC=$LOCAL_PLIBC LOCAL_X264=$LOCAL_X264 LOCAL_MP3LAME=$LOCAL_MP3LAME LOCAL_FFMPEG=$LOCAL_FFMPEG LOCAL_BZ2=$LOCAL_BZ2 LOCAL_Z=$LOCAL_Z LOCAL_CONFUSE=$LOCAL_CONFUSE LOCAL_MHD=$LOCAL_MHD LOCAL_ABS_SDL=$LOCAL_ABS_SDL LOCAL_SDLIMAGE=$LOCAL_SDLIMAGE LOCAL_FREETYPE=$LOCAL_FREETYPE LOCAL_SDLTTF=$LOCAL_SDLTTF IO=$IO MAC_OS=$MAC_OS  $MAKE || { echo "Failed to build CHUNKER PLAYER" ; exit 1; }
594
echo "----------------FINISHED COMPILING CHUNKER PLAYER"
595

    
596
#compile a version of winestreamer with UL enabled
597
#static needs fix??
598
cd "$BASE_UL_DIR/../Streamer"
599

    
600
$MAKE IO=$IO clean
601
#LOCAL_MHD=$LOCAL_MHD LOCAL_CURL=$LOCAL_CURL ULPLAYER=$BASE_UL_DIR ULPLAYER_EXTERNAL_LIBS=$EXTERN_DIR LIBEVENT_DIR=$LOCAL_EVENT ML=$ML STATIC=$STATIC MONL=$MONL IO=$IO DEBUG=$DEBUG THREADS=$THREADS MAC_OS=$MAC_OS SVNVERSION=$SVNVERSION $MAKE || { echo "Failed to build WineStreamer" ; exit 1; }
602
LOCAL_CURL=$LOCAL_CURL LIBEVENT_DIR=$LOCAL_EVENT ML=$ML STATIC=$STATIC MONL=$MONL ALTO=$ALTO IO=$IO DEBUG=$DEBUG THREADS=$THREADS MAC_OS=$MAC_OS SVNVERSION=$SVNVERSION $MAKE || { echo "Failed to build WineStreamer" ; exit 1; }
603

    
604
#check if all is ok
605
echo "============== RESULTS ==================="
606

    
607
if [ ! -n "$MINGW" ]; then
608
	cd "$BASE_UL_DIR/chunker_streamer"
609
	if [ -f "chunker_streamer" ]; then
610
		echo "chunker_streamer OK"
611
		C_STREAMER_EXE=`ls -la chunker_streamer`
612
		echo "$C_STREAMER_EXE"
613
		#now we want the bare name
614
		C_STREAMER_EXE=`ls chunker_streamer`
615
	else
616
		echo "chunker_streamer FAIL"
617
	fi
618
fi
619

    
620
cd "$BASE_UL_DIR/chunker_player"
621
if [ -n "$MINGW" ]; then
622
	SUFFIX=".exe"
623
	SCRIPT_SUFFIX=".bat"
624
else
625
	SUFFIX=""
626
	SCRIPT_SUFFIX=".sh"
627
fi
628
if [ -f "chunker_player$SUFFIX" ]; then
629
	echo "chunker_player OK"
630
	C_PLAYER_EXE=`ls -la chunker_player$SUFFIX`
631
	echo "$C_PLAYER_EXE"
632
	#now we want the bare name
633
	C_PLAYER_EXE=`ls chunker_player$SUFFIX`
634
else
635
	echo "chunker_player FAIL"
636
fi
637

    
638
cd "$BASE_UL_DIR/../Streamer"
639
echo "Check if the http binary is among these winestreamers:"
640
ls -la winestreamer* | grep -v ".o$"
641
echo "Your UL-enabled winestreamer has these flags:"
642
if [ -n "$ALTO" ]; then
643
	GREP_ALTO_EXPR="-alto"
644
	GREP_ALTO_FLAGS=""
645
	echo "ALTO: enabled"
646
else
647
	GREP_ALTO_EXPR="-alto"
648
	GREP_ALTO_FLAGS="-v"
649
	echo "ALTO: disabled"
650
fi
651
if [ "$STATIC" = "1" ]; then
652
	GREP_STATIC_EXPR="-halfstatic"
653
	GREP_STATIC_FLAGS=""
654
	echo "STATIC: halfstatic"
655
elif [ "$STATIC" = "2" ]; then
656
	GREP_STATIC_EXPR="-static"
657
	GREP_STATIC_FLAGS=""
658
	echo "STATIC: static"
659
else
660
	GREP_STATIC_EXPR="static"
661
	GREP_STATIC_FLAGS="-v"
662
	echo "STATIC: dynamic"
663
fi
664
echo "IO: $IO"
665
IO="-"$IO
666
echo "Hence your UL-enabled winestreamer should be..."
667
O_TARGET_EXE=`ls winestreamer* | grep -v ".o$" | grep $GREP_STATIC_FLAGS -e "$GREP_STATIC_EXPR" | grep $GREP_ALTO_FLAGS -e "$GREP_ALTO_EXPR" | grep -e "$IO"`
668
#O_TARGET_EXE=`ls winestreamer* | grep -v ".o$" | grep -e "$IO"`
669
echo "$O_TARGET_EXE"
670
if [ -f "$O_TARGET_EXE" ]; then
671
	echo "...and i found it."
672
else
673
	echo "...but sadly it appears build FAILED!."
674
fi
675

    
676
#creating conf file with executable name inside
677
cd "$BASE_UL_DIR/chunker_player"
678
echo "$O_TARGET_EXE" > peer_exec_name.conf
679

    
680
#packaging for distribution
681
cd "$BASE_UL_DIR/chunker_player"
682
if [ -f "$BASE_UL_DIR/../Streamer/$O_TARGET_EXE" -a -f "$C_PLAYER_EXE" ]; then
683
	echo "============== PACKAGING NAPAPLAYER ==================="
684
	rm -f -r napaplayer
685
	mkdir napaplayer
686
	mkdir napaplayer/icons
687
	cp icons/* napaplayer/icons/
688
	cp channels.conf napaplayer/
689
	cp peer_exec_name.conf napaplayer/
690
	cp runme$SCRIPT_SUFFIX napaplayer/
691
	cp README napaplayer/
692
	cp napalogo*.bmp napaplayer/
693
	cp *.ttf napaplayer/
694
	cp "$C_PLAYER_EXE" napaplayer/
695
	if [ -n "$MINGW" ]; then
696
		cp "$BASE_UL_DIR/../Streamer/$O_TARGET_EXE" napaplayer/
697
	else
698
		cp "$BASE_UL_DIR/../Streamer/$O_TARGET_EXE" napaplayer/
699
	fi
700
	if [ -n "$MINGW" ]; then
701
		cp "$LOCAL_LIBICONV/bin/libiconv-2.dll" napaplayer/libiconv2.dll
702
		if [ -f "$LOCAL_LIBINTL/bin/libintl-8.dll" ]; then
703
			cp "$LOCAL_LIBINTL/bin/libintl-8.dll" napaplayer/
704
		else
705
			cp "$LOCAL_LIBINTL/bin/libintl3.dll" napaplayer/libintl-8.dll
706
		fi
707
		cp "$LOCAL_PLIBC/bin/libplibc-1.dll" napaplayer/
708
		cp "$LOCAL_PTHREAD/bin/pthreadGC2.dll" napaplayer/
709
		cp "$LOCAL_ABS_SDL/bin/SDL.dll" napaplayer/
710
		rm -f -r napaplayer.zip
711
		zip -r napaplayer napaplayer
712
		if [ -s "napaplayer.zip" ]; then
713
			#it has size>0. OK!
714
			echo "Here it is your napaplayer package. Enjoy!"
715
			ls -la napaplayer.zip
716
		else
717
			echo "Sorry something went wrong during packaging napaplayer."
718
		fi
719
	else
720
		rm -f -r napaplayer.tar.gz
721
		tar cvfz napaplayer.tar.gz napaplayer
722
		if [ -s "napaplayer.tar.gz" ]; then
723
			#it has size>0. OK!
724
			echo "Here it is your napaplayer tarball. Enjoy!"
725
			ls -la napaplayer.tar.gz
726
		else
727
			echo "Sorry something went wrong during packaging napaplayer."
728
		fi
729
	fi
730
else
731
	echo ""
732
	echo "Not packaging napaplayer since build failed."
733
fi
734

    
735
echo "Finished build UL script"
736