forked from ufoaiorg/ufoai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·535 lines (488 loc) · 12.4 KB
/
configure
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#! /bin/sh
#set -e
#set -x
CONFIG_H=config.h
MAKEFILE_LOCAL=Makefile.local
DEBUG=1
UNIVERSAL=
HARD_LINKED_GAME=
HARD_LINKED_CGAME=1
PARANOID=
PROFILING=
PREFIX=/usr/local
PKGDATADIR=
PKGBINDIR=
PKGLIBDIR=
LOCALEDIR=
USE_SIGNALS=1
MODE=
CROSS=
USE_CCACHE=
STATIC=
W2K=
SSE=
DISABLE_DEPENDENCY_TRACKING=
HOST_OS=`uname | sed -e s/_.*// | tr '[:upper:]' '[:lower:]'`
TARGET_OS=${HOST_OS}
if [ "${HOST_OS}" = "sunos" ] || [ "${HOST_OS}" = "darwin" ]; then
TARGET_ARCH=`uname -p | sed -e s/i.86/i386/`
else
TARGET_ARCH=`uname -m | sed -e s/i.86/i386/`
fi
add_line_to_makefile_local() {
makefile_local_data="${makefile_local_data}"'
'"$1"
}
error() {
echo $@
exit 1
}
add_to_makefile_local_quote() {
VALUE=`get_var $1`
if [ -n "$VALUE" ]; then
add_line_to_makefile_local "$1 ?= \"$VALUE\""
[ -n "$2" ] && echo $2
else
add_line_to_makefile_local "# $1 ?= \"$VALUE\""
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_to_makefile_local() {
VALUE=`get_var $1`
if [ -n "$VALUE" ]; then
add_line_to_makefile_local "$1 ?= $VALUE"
[ -n "$2" ] && echo $2
else
add_line_to_makefile_local "# $1 ?= $VALUE"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_line_to_config_h() {
config_h_data="${config_h_data}"'
'"$1"
}
add_to_config_h_quote() {
VALUE=`get_var $1`
if [ -n "$VALUE" ] && [ "$VALUE" != "no" ]; then
add_line_to_config_h "#define $1 \"$VALUE\""
[ -n "$2" ] && echo $2
else
add_line_to_config_h "/* #define $1 \"$VALUE\" */"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_to_config_h() {
VALUE=`get_var $1`
if [ -n "$VALUE" ] && [ "$VALUE" != "no" ]; then
add_line_to_config_h "#define $1 $VALUE"
[ -n "$2" ] && echo $2
else
add_line_to_config_h "/* #define $1 $VALUE */"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
config_h() {
add_to_config_h PARANOID "Enable paranoid build"
add_to_config_h HARD_LINKED_GAME "Enable hard linked game"
add_to_config_h HARD_LINKED_CGAME "Enable hard linked cgame"
add_to_config_h USE_SIGNALS "Use signal handler"
add_to_config_h_quote PKGDATADIR "Setting custom data directory"
add_to_config_h_quote PKGLIBDIR "Setting custom library directory"
add_to_config_h_quote LOCALEDIR "Setting custom locale directory"
}
makefile_local() {
add_to_makefile_local DEBUG "Debug build"
add_to_makefile_local PROFILING "Enable profiling"
add_to_makefile_local STATIC "Enable static linking"
add_to_makefile_local W2K "Enable Windows 2000 compatibility"
add_to_makefile_local SSE "Enable Streaming SIMD Extensions"
add_to_makefile_local HARD_LINKED_GAME
add_to_makefile_local HARD_LINKED_CGAME
add_to_makefile_local DISABLE_DEPENDENCY_TRACKING "Disable dependency tracking"
add_to_makefile_local UNIVERSAL "Build a universal binary"
add_to_makefile_local TARGET_OS "Compile for ${TARGET_OS}"
add_to_makefile_local TARGET_ARCH "Compile for ${TARGET_ARCH}"
add_to_makefile_local MODE "Compile in ${MODE} mode"
add_to_makefile_local_quote CC "Found cc ${CC}"
add_to_makefile_local_quote CXX "Found cxx ${CXX}"
add_to_makefile_local_quote CROSS "Using tools prefix ${CROSS}"
add_to_makefile_local_quote PKGBINDIR "Using bindir ${PKGBINDIR}"
add_to_makefile_local_quote PKGDATADIR "Using datadir ${PKGDATADIR}"
add_to_makefile_local_quote PKGLIBDIR "Using libdir ${PKGLIBDIR}"
add_to_makefile_local_quote LOCALEDIR "Using localedir ${LOCALEDIR}"
add_to_makefile_local_quote PREFIX "Using prefix ${PREFIX}"
add_to_makefile_local_quote PROGRAM_ZIP "Found zip"
add_to_makefile_local_quote PROGRAM_PYTHON "Found python"
echo "Build modules:"
for i in `get_modules`; do
add_to_makefile_local ${i}_DISABLE
if [ "`get_var ${i}_DISABLE`" = "yes" ]; then
echo "Disable $i"
else
echo "Build $i"
fi
done
}
check_header_cc() {
if [ -n "${2}" ]; then
( echo "#include <${1}>" | ${CROSS}${CC} ${CFLAGS} $(${CROSS}pkg-config --cflags ${2}) -o /dev/null -xc -c - 2> /dev/null ) && echo "1" || echo ""
else
( echo "#include <${1}>" | ${CROSS}${CC} ${CFLAGS} -o /dev/null -xc -c - 2> /dev/null ) && echo "1" || echo ""
fi
}
check_header() {
HEADER=$1
HAVE=HAVE_`echo ${HEADER%.*} | sed 's,/,_,g' | tr '[a-z]' '[A-Z]'`_H
VALUE=`get_var $HAVE`
if [ "$VALUE" != "no" ]; then
set_var $HAVE `check_header_cc $1 $2`
add_to_config_h $HAVE "Found $1" "Could not find $1" $2
add_to_makefile_local $HAVE
else
add_to_config_h $HAVE "Found $1" "Disable $1"
fi
}
check_headers() {
check_header "xvid.h"
check_header "theora/theora.h"
check_header "execinfo.h"
check_header "bfd.h"
check_header "sys/utsname.h"
check_header "link.h"
check_header "CUnit/Basic.h"
check_header "mxml.h"
check_header "picomodel.h"
check_header "gtk/gtk.h" "gtk+-2.0"
check_header "gtksourceview/gtksourceview.h" "gtksourceview-2.0"
check_header "libxml/parser.h" "libxml-2.0"
#check_header "jpeglib.h"
check_header "AL/al.h" "openal"
check_header "gtk/gtkglwidget.h" "gtkglext-1.0"
if [ "$HAVE_CUNIT_BASIC_H" != "1" ]; then
set_var "testall_DISABLE" "yes"
fi
if [ "$HAVE_GTK_GTK_H" != "1" ] || [ "$HAVE_GTKSOURCEVIEW_GTKSOURCEVIEW_H" != "1" ] || [ "$HAVE_GTK_GTKGLWIDGET_H" != "1" ]; then
set_var "uforadiant_DISABLE" "yes"
fi
}
check_compiler() {
# TODO improve compiler check
if [ ! "${CC}" = "" ]; then
${CC} --help > /dev/null 2>&1
if [ $? -ne 0 ]; then
error "Could not find specified compiler: ${CC}"
fi
fi
if [ "${CC}" = "" ]; then
for i in cc gcc; do
if [ "${CC}" = "" ]; then
$i --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
CC=$i
fi
fi
done
fi
if [ "${CC}" = "" ]; then
error "Could not find a compiler in your path"
fi
# TODO implement compiler check
CXX=${CXX:-c++}
if [ "${TARGET_OS}" = "android" ]; then
CROSS="arm-linux-androideabi-"
fi
if [ "${TARGET_OS}" = "mingw32" ] && [ "${HOST_OS}" != "mingw32" ]; then
CROSS="i686-pc-mingw32-"
fi
if [ -n "${CROSS}" ]; then
# TODO Add a check for this
echo "Cross compiling, make sure that ${CROSS}${CC} is in your path"
fi
}
usage() {
echo "Usage: $0"
echo " --help show this help message"
echo " --enable-ccache use ccache for building"
echo " --enable-hardlinkedgame hard link the server game code"
echo " --enable-hardlinkedcgame hard link the client game code"
echo " --enable-paranoid compile in paranoid mode with extra checks"
echo " --enable-profiling activates profiling"
echo " --enable-release build with optimizations"
echo " --enable-static enable static linking"
echo " --enable-universal enable universal build"
echo " --enable-w2k enable Windows 2000 compatibility"
if [ -n "$(echo ${TARGET_ARCH} | grep -e '^i.86$' -e '^x86_64$')" ]; then
echo " --enable-sse enable Streaming SIMD Extensions"
fi
echo " --disable-execinfo disable backtraces for crashes"
echo " --disable-signals disable the use of a signal handler"
echo
echo " --target-os= specify the target os"
(cd build/platforms; for i in *.mk; do echo " * ${i%.mk}"; done)
echo
echo " --bindir= path for the ufoai binaries"
echo " --datadir= path for the ufoai game data"
echo " --libdir= path for the ufoai shared objects"
echo " --localedir= path for the ufoai translations"
echo " --prefix= prefix for directories"
echo
echo " --disable-* specify which target should not get built"
echo " --enable-* specify which target should get built"
echo " --enable-only-* disable all other targets"
(cd build/modules; for i in *.mk; do echo " * ${i%.mk}"; done)
echo
echo " --disable-dependency-tracking"
exit 1
}
make_var() {
echo "$1" | sed 's/-/_/g'
}
set_var() {
eval $(make_var "$1")=\""$2"\"
}
get_var() {
eval echo \${$(make_var "$1")}
}
get_modules() {
(cd build/modules; for i in *.mk; do echo "${i%.mk}"; done)
}
check_path_characters() {
# Find out where configure is (in what dir)
ROOT_DIR="`dirname $0`"
# For MSYS/MinGW we want to know the FULL path. This as that path is generated
# once you call an outside binary. Having the same path for the rest is needed
# for dependency checking.
# pwd -W returns said FULL path, but doesn't exist on others so fall back.
ROOT_DIR="`cd $ROOT_DIR && (pwd -W 2>/dev/null || pwd 2>/dev/null)`"
if [ -n "`echo \"$ROOT_DIR\" | grep '[^-\w\/\\\.:]~?'`" ]; then
echo "WARNING: The path contains a non-alphanumeric character that might cause"
echo " failures in subsequent build stages. Any failures with the build"
echo " will most likely be caused by this."
echo " $ROOT_DIR"
fi
if [ -n "`echo \"$ROOT_DIR\" | grep '[\(\)]'`" ]; then
echo "ERROR: The path contains a square character that cause"
echo " failures in subsequent build stages!!!"
echo " $ROOT_DIR"
exit 1
fi
}
check_ccache() {
if [ "$USE_CCACHE" = "yes" ]; then
ccache --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Use ccache"
CC="ccache $CC"
CXX="ccache $CXX"
else
echo "Could not find ccache in your path"
fi
fi
}
check_program() {
HAVE=PROGRAM_`echo $1 | tr '[a-z]' '[A-Z]'`
$1 --help > /dev/null 2>&1
if [ $? -ne 127 ]; then
echo "Found $1"
set_var $HAVE $1
else
echo "Could not find $1"
set_var $HAVE
fi
}
check_programs() {
check_program zip
check_program python
check_program doxygen
}
check_target_os() {
local FOUND=0
for i in build/platforms/*.mk; do
if [ `basename $i .mk` = $1 ]; then
FOUND=1
fi
done
[ $FOUND -eq 0 ] && echo "invalid target-os given: $1" && exit 1
}
check_module() {
local FOUND=0
for i in `get_modules`; do
if [ $i = $1 ]; then
FOUND=1
fi
done
[ $FOUND -eq 0 ] && error "invalid module given: $1"
}
enable_only() {
for i in `get_modules`; do
if [ "$i" = "$1" ]; then
set_var "${i}_DISABLE" ""
else
set_var "${i}_DISABLE" "yes"
fi
done
}
check_path_characters
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
usage
;;
--enable-ccache)
USE_CCACHE="yes"
;;
--disable-ccache)
USE_CCACHE="no"
;;
--enable-release)
MODE=release
DEBUG=
;;
--disable-release)
MODE=debug
DEBUG=1
;;
--enable-static)
STATIC=1
;;
--disable-static)
STATIC=
;;
--enable-universal)
UNIVERSAL=1
DISABLE_DEPENDENCY_TRACKING=1
;;
--disable-universal)
UNIVERSAL=
;;
--enable-hardlinkedgame)
HARD_LINKED_GAME=1
;;
--disable-hardlinkedgame)
HARD_LINKED_GAME=
;;
--enable-hardlinkedcgame)
HARD_LINKED_CGAME=1
;;
--disable-hardlinkedcgame)
HARD_LINKED_CGAME=
;;
--enable-paranoid)
PARANOID=1
;;
--disable-paranoid)
PARANOID=
;;
--enable-profiling)
PROFILING=1
;;
--disable-profiling)
PROFILING=
;;
--enable-w2k)
W2K=1
;;
--disable-w2k)
W2K=
;;
--enable-sse)
if [ -z "$(echo ${TARGET_ARCH} | grep -e '^i.86$' -e '^x86_64$')" ] ;then
echo "invalid $1 option for your CPU"
exit 1
fi
SSE=1
;;
--disable-sse)
SSE=0
;;
--enable-signals)
USE_SIGNALS=1
;;
--disable-signals)
USE_SIGNALS=
;;
--enable-execinfo)
HAVE_EXECINFO_H=yes
;;
--disable-execinfo)
HAVE_EXECINFO_H=no
;;
--disable-dependency-tracking)
DISABLE_DEPENDENCY_TRACKING=1
;;
--prefix=*)
PREFIX="${1#*=}"
;;
--datadir=*)
PKGDATADIR="${1#*=}"
;;
--libdir=*)
PKGLIBDIR="${1#*=}"
;;
--localedir=*)
LOCALEDIR="${1#*=}"
;;
--bindir=*)
PKGBINDIR="${1#*=}"
;;
--target-os=*)
TARGET_OS="${1#*=}"
check_target_os $TARGET_OS
;;
--disable-*)
OPTION="${1#--disable-}"
check_module $OPTION
set_var "${OPTION}_DISABLE" "yes"
;;
--enable-only-*)
OPTION="${1#--enable-only-}"
HARD_LINKED_GAME=1
HARD_LINKED_CGAME=1
check_module $OPTION
enable_only $OPTION
;;
--enable-*)
OPTION="${1#--enable-}"
check_module $OPTION
set_var "${OPTION}_DISABLE" ""
;;
CC=*) CC="${1#CC=}";;
CXX=*) CXX="${1#CXX=}";;
CFLAGS=*) CFLAGS="${1#*=}";;
LDFLAGS=*) LDFLAGS="${1#*=}";;
*)
echo "invalid option $1"
exit 1
;;
esac
shift
done
[ "${TARGET_OS}" = "mingw32" ] && TARGET_ARCH=i386
[ "${TARGET_OS}" = "android" ] && TARGET_ARCH=arm && enable_only ufo
[ "${TARGET_OS}" = "darwin" ] && USE_SIGNALS=
PKGDATADIR=${PKGDATADIR:-${PREFIX}/games/ufoai}
PKGBINDIR=${PKGBINDIR:-${PREFIX}/bin}
PKGLIBDIR=${PKGLIBDIR:-${PREFIX}/lib}
check_compiler
check_programs
check_ccache
check_headers
makefile_local
config_h
cat > ${MAKEFILE_LOCAL} << EOF
# -------- Automatically generated -----------
$makefile_local_data
# allow to specify your own targets
-include config.mk
EOF
cat > ${CONFIG_H} << EOF
/* This file is automatically generated */
#ifndef CONFIG_H
#define CONFIG_H
$config_h_data
#endif
EOF