-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-chocolate-doom-sdl2
468 lines (368 loc) · 10.8 KB
/
build-chocolate-doom-sdl2
1
2
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
179
180
181
182
183
184
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#!/bin/sh
#
# Build script to automatically build Chocolate Doom. This will work
# on OSX and Linux, and hopefully Cygwin as well (havent tried)
#
# To build on OSX:
# 1. Install Xcode (available on your OSX DVDs or from the Apple
# website)
# 2. Type:
# curl http://www.chocolate-doom.org/build-chocolate-doom | sh
#
# To build on Linux:
# 1. Make sure gcc is installed (depends on your distribution).
# 2. Type:
# wget -O - http://www.chocolate-doom.org/build-chocolate-doom | sh
#
CHOCOLATE_DOOM_DIR=~/chocolate-doom-sdl2
PACKAGES_DIR=$CHOCOLATE_DOOM_DIR/packages
BUILD_DIR=$CHOCOLATE_DOOM_DIR/build
# Check if the specified string matches the glob pattern.
pattern_match() {
pattern="$1"
case "$2" in
$pattern)
true
;;
*)
false
;;
esac
}
# Determine if a given program is in the PATH.
have_tool() {
tool=$1
result=1
SAVE_IFS=$IFS
IFS=:
for dir in $PATH; do
if [ -e $dir/$tool ]; then
# echo $dir/$tool
result=0
break
fi
done
IFS=$SAVE_IFS
return $result
}
# Download a given URL to stdout.
get_url() {
url=$1
if have_tool curl; then
curl $url
return
fi
if have_tool wget; then
wget $url -O -
return
fi
# Desperate?
for l in lynx links elinks; do
if have_tool $l; then
echo "Using $l to download $url..." >&2
$l -source $url
return
fi
done
echo "No tool available to retrieve URLs. Please install curl or wget." >&2
exit -1
}
# Extract a tar.gz file.
extract_targz() {
file=$1
gunzip < $1 | tar -x
}
# Download a file to the packages directory.
download_file() {
url=$1
file=$2
if get_url $url$file > $PACKAGES_DIR/$file.part; then
mv $PACKAGES_DIR/$file.part $PACKAGES_DIR/$file
return 0
else
echo "File $file failed to download! Please try again."
return 1
fi
}
# fetch_from_git(git_url, checkout_dir_name)
# Check module out from Git.
fetch_from_git() {
git_url=$1
checkout_dir_name=$2
checkout_path="$BUILD_DIR/$checkout_dir_name"
if [ ! -e "$checkout_path" ]; then
if ! git clone "$git_url" "$checkout_path"; then
echo "Failed to check out $checkout_dir_name from Git"
exit
fi
# We want to build the SDL2 branch rather than master.
pushd "$checkout_path"
git checkout sdl2-branch
popd
else
pushd "$checkout_path"
git pull
popd
fi
}
# fetch_module(base_url, module_name, version)
# Download the specified module.
fetch_module() {
url=$1
module=$2
version=$3
echo =======================================================
echo Building $module version $version
echo =======================================================
echo
if [ ! -e $PACKAGES_DIR/$module-$version.tar.gz ]; then
echo Downloading tar file...
download_file $url $module-$version.tar.gz
fi
echo Extracting...
cd $BUILD_DIR
if ! extract_targz $PACKAGES_DIR/$module-$version.tar.gz; then
rm -f $PACKAGES_DIR/$module-$version.tar.gz
echo Archive failed to extract and is possibly corrupted.
echo Please run this script again.
exit
fi
}
# build_module(module_dir, args)
# Build the specified module.
build_module() {
module=$1
args=$2
echo Building module...
cd "$BUILD_DIR/$module"
(./configure --with-sdl-prefix=$SDL_PREFIX --prefix=$INSTALL_DIR $args) || exit
make || exit
# Install the package
echo $INSTALL_MESSAGE
$INSTALL_COMMAND make install || exit
# Remove any libtool .la files that were installed by the build - they
# aren't needed and can cause build problems with dependency ordering
# when cross-compiling to MingW.
rm -f $INSTALL_DIR/lib/*.la
echo Build complete.
echo
}
# fetch_and_build_module(base_url, module_name, version, args)
# Build a module, downloading from http:
fetch_and_build_module() {
url=$1
module=$2
version=$3
args=$4
fetch_module "$url" "$module" "$version"
build_module "$module-$version" "$args"
}
autogen_module() {
module=$1
cd "$BUILD_DIR/$module"
# This is what is normally found in the autogen.sh script. The
# commands are run here directly as some slight tweaks are needed.
mkdir autotools
aclocal -I "$SDL_PREFIX/share/aclocal" || exit
autoheader || exit
automake -a -c || exit
autoconf || exit
automake || exit
}
# Check if a given header file is in the standard include directory or
# SDL include directory.
have_header() {
headerfile=$1
echo "#include <$headerfile>" | cpp $SDL_CFLAGS $CPPFLAGS > /dev/null
result=$?
if [ $result = 0 ]; then
echo "Have $headerfile"
else
echo "Don't have $headerfile"
fi
return $result
}
usage() {
echo
echo "Usage:"
echo "$0 : Install into home directory"
echo "$0 -su : Install globally onto system using 'su'"
echo "$0 -sudo : Install globally onto system using 'sudo'"
echo
echo "Extra options:"
echo "-git : Build latest version from Git HEAD."
echo "-extra-libs : Build extra optional libraries that can make"
echo " Chocolate Doom even more awesome."
echo "-host=<spec> : Cross-compile for the specified target."
echo
exit 0
}
if pattern_match "* *" "$HOME"; then
echo
echo "The path to your home directory contains a space:"
echo
echo " HOME=$HOME"
echo
echo "This script will probably fail to build - reset HOME to point"
echo "somewhere else. For example, type:"
echo
echo " mkdir /home/user"
echo " HOME=/home/user"
echo
exit -1
fi
if ! have_tool gcc; then
echo "No compiler found. Please install gcc!" >&2
exit -1
fi
# Parse command line arguments:
#git_build=false
git_build=true
force_build_sdl=false
build_libsamplerate=false
build_libflac=false
build_libvorbis=false
build_libpng=false
INSTALL_DIR=$CHOCOLATE_DOOM_DIR/install
INSTALL_COMMAND=
INSTALL_MESSAGE="Installing..."
GIT_CO_NAME=chocolate-doom-git
HOST_ARG=
for arg in "$@"; do
case "$arg" in
"-su")
INSTALL_DIR=/usr/local
INSTALL_COMMAND=su -c
INSTALL_MESSAGE="Type the root password:"
;;
"-sudo")
INSTALL_DIR=/usr/local
INSTALL_COMMAND=sudo
INSTALL_MESSAGE="Type your password:"
;;
-host=*)
HOST_ARG="-$arg"
# Build libraries from scratch when cross compiling:
force_build_sdl=true
;;
"-extra-libs")
build_libsamplerate=true
build_libpng=true
build_libflac=true
build_libvorbis=true
;;
"-git")
git_build=true
;;
*)
usage
;;
esac
done
# Make all our build directories etc
mkdir $CHOCOLATE_DOOM_DIR
mkdir $PACKAGES_DIR
mkdir $BUILD_DIR
MACOSX_DEPLOYMENT_TARGET=10.5
PATH="$INSTALL_DIR/bin:$PATH"
CPPFLAGS="-I$INSTALL_DIR/include -I$INSTALL_DIR/include/SDL"
LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS"
export MACOSX_DEPLOYMENT_TARGET
export CPPFLAGS
export LDFLAGS
SDL_BUILD_OPTIONS=""
if [ `uname` = "Darwin" ]; then
SDL_BUILD_OPTIONS="--disable-video-x11 $SDL_BUILD_OPTIONS"
CC="gcc -m32"
export CC
CXX="g++ -m32"
export CXX
LDFLAGS="-lobjc $LDFLAGS"
else
LDFLAGS="-Wl,-rpath -Wl,$INSTALL_DIR/lib $LDFLAGS"
fi
# Windows build?
if [ `uname` = "Cygwin" ] || pattern_match "*mingw*" "$HOST_ARG"; then
echo
echo "Windows build: installing supplementary DirectX headers."
echo
if [ ! -e $PACKAGES_DIR/directx-devel.tar.gz ]; then
download_file http://www.libsdl.org/extras/win32/common/ \
directx-devel.tar.gz
fi
mkdir -p $INSTALL_DIR
cd $INSTALL_DIR
extract_targz $PACKAGES_DIR/directx-devel.tar.gz
fi
SDL_CFLAGS=
SDL_PREFIX=`sdl-config --prefix`
if [ $? = 0 ] && ! $force_build_sdl; then
# SDL is installed on the system
SDL_CFLAGS=`sdl-config --cflags`
else
# SDL not installed; we must build it
SDL_PREFIX=$INSTALL_DIR
fetch_and_build_module http://www.libsdl.org/release/ SDL2 2.0.3 \
"$SDL_BUILD_OPTIONS $HOST_ARG"
fi
# Optional libraries first:
if $build_libsamplerate; then
if $force_build_sdl || ! have_header samplerate.h; then
fetch_and_build_module http://www.chocolate-doom.org/depends/ \
libsamplerate 0.1.8 "$HOST_ARG"
fi
fi
if $build_libpng; then
if $force_build_sdl || ! have_header png.h; then
fetch_and_build_module http://www.chocolate-doom.org/depends/ \
libpng 1.6.10 "$HOST_ARG"
fi
fi
if $build_libvorbis; then
if $force_build_sdl || ! have_header vorbis/vorbisfile.h; then
fetch_and_build_module http://www.chocolate-doom.org/depends/ \
libogg 1.3.1 "$HOST_ARG"
fetch_and_build_module http://www.chocolate-doom.org/depends/ \
libvorbis 1.3.4 "$HOST_ARG"
fi
fi
if $build_libflac; then
if $force_build_sdl || ! have_header FLAC/stream_decoder.h; then
flac_opts="--disable-asm-optimizations" # Causes problems
fetch_and_build_module http://www.chocolate-doom.org/depends/ \
flac 1.2.1 "$HOST_ARG $flac_opts"
fi
fi
if $force_build_sdl || ! have_header SDL_net.h; then
# SDL_net not installed; we must build it
fetch_and_build_module http://www.libsdl.org/projects/SDL_net/release/ \
SDL2_net 2.0.0 "$HOST_ARG"
fi
if $force_build_sdl || ! have_header SDL_mixer.h; then
# SDL_mixer not installed; we must build it
# Disable dependencies on external libraries for sound file formats:
mixer_opts="--disable-music-mod --disable-music-mp3 \
--disable-music-flac-shared --disable-music-ogg-shared"
# ...except ones we're building.
if ! $build_libflac; then
mixer_opts="$mixer_opts --disable-music-flac"
fi
if ! $build_libvorbis; then
mixer_opts="$mixer_opts --disable-music-ogg"
fi
fetch_and_build_module http://www.libsdl.org/projects/SDL_mixer/release/ \
SDL2_mixer 2.0.0 "$HOST_ARG $mixer_opts"
fi
# Build Chocolate Doom. We can build the stable version or check out
# the latest code from Git.
if $git_build; then
GIT_URL=https://github.com/fragglet/chocolate-doom.git
fetch_from_git "$GIT_URL" "$GIT_CO_NAME"
autogen_module "$GIT_CO_NAME"
build_module "$GIT_CO_NAME" "$HOST_ARG"
else
# Download and build latest release.
fetch_and_build_module \
http://www.chocolate-doom.org/downloads/2.1.0/ \
chocolate-doom 2.1.0 "$HOST_ARG"
fi