Fix FTBFS on architectures where char is unsigned
[tennix.git] / configure
blob46be30ea407b99ee89f300630b53e9e82fc1f208
1 #!/bin/sh
2 # Configuration script for Tennix
3 # 2013-07-27 Thomas Perl <m@thp.io>
5 V="1.2.0"
6 SILENT="1"
7 PYTHON="1"
8 PREFIX="/usr/local"
9 DEFAULT_CFLAGS="-I. -Wall"
11 if [ -z "$CC" ]; then
12 CC="gcc"
15 if [ -z "$CXX" ]; then
16 CXX="g++"
19 if [ -z "$CFLAGS" ]; then
20 CFLAGS=""
23 if [ -z "$LDFLAGS" ]; then
24 LDFLAGS=""
27 CFLAGS="$DEFAULT_CFLAGS $CFLAGS"
29 PLATFORM=""
31 GENERATED_HEADER="Generated: $(date)"
32 CONFIG_H="/* $GENERATED_HEADER */"
33 CONFIG_MK="# $GENERATED_HEADER"
35 NL='
38 fail() {
39 echo "ERROR: $1"
40 exit 1
43 set_make_variable() {
44 CONFIG_MK="$CONFIG_MK$NL$1 := $2"
47 define_macro() {
48 CONFIG_H="$CONFIG_H$NL#define $1"
51 undefine_macro() {
52 CONFIG_H="$CONFIG_H$NL#undef $1"
55 add_definition() {
56 define_macro $1
57 set_make_variable $1 1
60 no_definition() {
61 undefine_macro $1
62 set_make_variable $1 0
65 cond_definition() {
66 if [ $1 -eq 0 ]; then
67 add_definition $2
68 else
69 no_definition $2
73 check_cc() {
74 echo "int main() { return 0; }" | $CC $CFLAGS -x c -c -o /dev/null - 2>/dev/null
77 check_cxx() {
78 echo "class A { public: A() {} }; int main() { A a; }" | $CXX $CFLAGS -x c++ -c -o /dev/null -
81 check_linker_cc() {
82 echo "int main() { return 0; }" | $CC $CFLAGS $LDFLAGS -l$1 -x c -o /dev/null - 2>/dev/null
85 check_header_cc() {
86 echo "#include <$1>" | $CC $CFLAGS -c -x c -o /dev/null -c - 2>/dev/null
89 message_wrapper() {
90 printf "$1 ... "
91 shift
93 if [ $? -eq 0 ]; then
94 echo "yes"
95 return 0
96 else
97 echo "no"
98 return 1
102 check_sdl_lib() {
103 if ! which sdl-config >/dev/null 2>&1; then
104 return 1
107 CFLAGS="$(sdl-config --cflags) $CFLAGS"
108 LDFLAGS="$(sdl-config --libs) $LDFLAGS"
109 return 0
112 check_os() {
113 printf "Detecting operating system ... "
114 UNAME=$(uname -s)
115 case $UNAME in
116 Linux)
117 echo "Linux"
118 PLATFORM="linux"
120 Darwin)
121 echo "Mac OS X"
122 PLATFORM="osx"
125 echo "???"
126 fail "Unknown platform: $UNAME"
128 esac
131 check_compiler() {
132 message_wrapper "Testing working C compiler ($CC)" check_cc || fail "C compiler ($CC) not working"
133 message_wrapper "Testing working C++ compiler ($CXX)" check_cxx || fail "C++ compiler ($CXX) not working"
136 check_sdl() {
137 message_wrapper "Checking for SDL 1.2" check_sdl_lib
138 cond_definition $? HAVE_SDL
141 require_sdl() {
142 check_sdl || fail "SDL not found"
145 check_voice_files() {
146 message_wrapper "Checking for voice files" [ -f voice/deuce.ogg ]
147 cond_definition $? HAVE_VOICE_FILES
150 check_python_lib() {
151 if ! which python-config >/dev/null 2>&1; then
152 return 1
155 CFLAGS="$(python-config --cflags) $CFLAGS"
156 LDFLAGS="$(python-config --libs) $LDFLAGS"
157 return 0
160 check_tool_path() {
161 COMMAND=$1
162 VARIABLE=$2
164 if ! which $COMMAND >/dev/null 2>&1; then
165 return 1
168 if [ "$VARIABLE" != "" ]; then
169 set_make_variable $VARIABLE $(which $COMMAND 2>/dev/null)
173 check_tool() {
174 message_wrapper "Checking for $1" check_tool_path $*
177 require_tool() {
178 check_tool $* || fail "Required command '$1' not found"
181 check_python() {
182 message_wrapper "Checking for libpython" check_python_lib
183 cond_definition $? HAVE_PYTHON
186 check_header() {
187 message_wrapper "Checking for $1" check_header_cc $1
190 check_linker() {
191 message_wrapper "Checking for -l$1" check_linker_cc $1
194 check_library() {
195 LIBRARY=$1
196 HEADER=$2
197 DEFINE=$3
198 check_linker $LIBRARY
199 HAVE_LINKER=$?
200 check_header $HEADER
201 HAVE_HEADER=$?
202 if [ $HAVE_LINKER -eq 0 -a $HAVE_HEADER -eq 0 ]; then
203 add_definition $DEFINE
204 LDFLAGS="-l$LIBRARY $LDFLAGS"
205 else
206 no_definition $DEFINE
207 return 1
209 return 0
212 require_library() {
213 check_library $* || fail "Library $1 ($2) not found"
216 generate_dependencies() {
217 echo "Generating dependencies.mk"
218 rm -f dependencies.mk
220 echo "# $GENERATED_HEADER"
221 for filename in src/*.cc; do $CXX -MM $filename $CFLAGS -o -; done
222 )>dependencies.mk
225 write_config() {
226 echo "Writing config.h"
227 rm -f config.h
229 echo "$CONFIG_H"
230 echo "#define VERSION \"$V\""
231 echo "#define PREFIX \"$PREFIX\""
232 )>config.h
234 echo "Writing config.mk"
235 rm -f config.mk
237 echo "$CONFIG_MK"
238 echo "V = $V"
239 echo "SILENT = $SILENT"
240 echo "PREFIX = $PREFIX"
241 echo "PLATFORM = $PLATFORM"
242 echo "CC = $CC"
243 echo "CXX = $CXX"
244 echo "CFLAGS = $CFLAGS"
245 echo "CXXFLAGS = $CFLAGS"
246 echo "LDFLAGS = $LDFLAGS"
247 )>config.mk
250 usage() {
251 cat <<EOF
253 Usage: $0 [options]
255 Supported options:
256 --prefix PREFIX Install into PREFIX (default: $PREFIX)
257 --help | -h Show this help message
258 --with-debug Enable additional debugging output
259 --enable-update-rect Visualize screen updates
260 --enable-nonfree-locations Additional tennis courts on world map
261 --enable-fps-limit Limit frame rate
262 --disable-silent Disable silent make output
263 --disable-python Disable checking for Python
268 parse_arguments() {
269 while [ $# -gt 0 ]; do
270 case $1 in
271 --prefix)
272 [ $# -gt 1 ] || fail "Not enough arguments."
273 PREFIX="$2"
274 shift
276 --with-debug)
277 define_macro DEBUG
278 CFLAGS="-g $CFLAGS"
280 --enable-update-rect)
281 define_macro DRAW_UPDATE_RECTANGLE
283 --enable-nonfree-locations)
284 define_macro NONFREE_LOCATIONS
286 --enable-fps-limit)
287 define_macro ENABLE_FPS_LIMIT
289 --disable-silent)
290 SILENT="0"
292 --disable-python)
293 PYTHON="0"
295 -h|--help)
296 usage
297 exit 0
300 usage
301 fail "Unknown argument: $1"
303 esac
304 shift
305 done
308 # Parse command-line arguments
309 parse_arguments $*
311 # Check for compatible OS and working compiler
312 check_os
313 check_compiler
315 # Check for command-line tools needed for build
316 require_tool make
318 # Check for command-line tools required in makefile
319 require_tool ln LN
320 require_tool install INSTALL
321 require_tool rm RM
323 # Check for SDL 1.2 and libpython
324 require_sdl
325 [ "$PYTHON" != "0" ] && check_python
327 # Check for mandatory and optional libraries
328 require_library SDL_image SDL_image.h HAVE_SDL_IMAGE
329 require_library SDL_ttf SDL_ttf.h HAVE_SDL_TTF
330 check_library SDL_net SDL_net.h HAVE_SDL_NET
331 require_library SDL_mixer SDL_mixer.h HAVE_SDL_MIXER
333 # Check for optional game content
334 check_voice_files
336 # Save configuration results and generate dependency file
337 write_config
338 generate_dependencies