Fix #7600: Don't read uninitialised memory when parsing GS language files.
[openttd-github.git] / configure
blob7a13a96c88918602fb58278c964149b7214f2130
1 #!/bin/sh
3 # $Id$
5 # This file is part of OpenTTD.
6 # OpenTTD 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.
7 # OpenTTD 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.
8 # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 check_path_characters() {
11 if [ -n "`echo $ROOT_DIR | grep '[^-_A-Za-z0-9\/\\\.:]'`" ]; then
12 echo "WARNING: The path contains a non-alphanumeric character that might cause"
13 echo " failures in subsequent build stages. Any failures with the build"
14 echo " will most likely be caused by this."
18 CONFIGURE_EXECUTABLE="$_"
19 # On *nix systems those two are equal when ./configure is done
20 if [ "$0" != "$CONFIGURE_EXECUTABLE" ]; then
21 # On some systems, when ./configure is triggered from 'make'
22 # the $_ is filled with 'make'. So if that is true, skip 'make'
23 # and use $0 (and hope that is correct ;))
24 if [ -n "`echo $CONFIGURE_EXECUTABLE | grep make`" ]; then
25 CONFIGURE_EXECUTABLE="$0"
26 else
27 CONFIGURE_EXECUTABLE="$CONFIGURE_EXECUTABLE $0"
30 # Find out where configure is (in what dir)
31 ROOT_DIR="`dirname $0`"
32 # For MSYS/MinGW we want to know the FULL path. This as that path is generated
33 # once you call an outside binary. Having the same path for the rest is needed
34 # for dependency checking.
35 # pwd -W returns said FULL path, but doesn't exist on others so fall back.
36 ROOT_DIR="`cd $ROOT_DIR && (pwd -W 2>/dev/null || pwd 2>/dev/null)`"
38 check_path_characters
40 # Same here as for the ROOT_DIR above
41 PWD="`pwd -W 2>/dev/null || pwd 2>/dev/null`"
42 PREFIX="$PWD/bin"
44 . $ROOT_DIR/config.lib
46 # Set default dirs
47 OBJS_DIR="$PWD/objs"
48 BASE_SRC_OBJS_DIR="$OBJS_DIR"
49 LANG_OBJS_DIR="$OBJS_DIR/lang"
50 GRF_OBJS_DIR="$OBJS_DIR/extra_grf"
51 SETTING_OBJS_DIR="$OBJS_DIR/setting"
52 BIN_DIR="$PREFIX"
53 SRC_DIR="$ROOT_DIR/src"
54 LANG_DIR="$SRC_DIR/lang"
55 MEDIA_DIR="$ROOT_DIR/media"
56 SOURCE_LIST="$ROOT_DIR/source.list"
58 if [ "$1" = "--reconfig" ] || [ "$1" = "--reconfigure" ]; then
59 if [ ! -f "config.cache" ]; then
60 echo "can't reconfigure, because never configured before"
61 exit 1
63 # Make sure we don't lock config.cache
64 cat config.cache | sed 's@\\ @\\\\ @g' > cache.tmp
65 sh cache.tmp
66 RET=$?
67 rm -f cache.tmp
68 exit $RET
71 set_default
72 detect_params "$@"
73 check_params
74 save_params
75 make_cflags_and_ldflags
77 EXE=""
78 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "OS2" ]; then
79 EXE=".exe"
82 TTD="openttd$EXE"
83 STRGEN="strgen$EXE"
84 DEPEND="depend$EXE"
85 SETTINGSGEN="settings_gen$EXE"
87 if [ -z "$sort" ]; then
88 PIPE_SORT="sed s@a@a@"
89 else
90 PIPE_SORT="$sort"
93 if [ ! -f "$LANG_DIR/english.txt" ]; then
94 echo "Languages not found in $LANG_DIR. Can't continue without it."
95 echo "Please make sure the dir exists and contains at least english.txt"
98 # Read the source.list and process it
99 AWKCOMMAND='
101 /^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
102 /^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
103 /^( *)#if/ {
104 gsub(" ", "", $0);
105 gsub("^#if ", "", $0);
107 if (deep != skip) { deep += 1; next; }
109 deep += 1;
111 if ($0 == "ALLEGRO" && "'$allegro_config'" == "") { next; }
112 if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
113 if ($0 == "PNG" && "'$png_config'" == "") { next; }
114 if ($0 == "OSX" && "'$os'" != "OSX") { next; }
115 if ($0 == "OS2" && "'$os'" != "OS2") { next; }
116 if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; }
117 if ($0 == "AI" && "'$enable_ai'" == "0") { next; }
118 if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; }
119 if ($0 == "HAIKU" && "'$os'" != "HAIKU") { next; }
120 if ($0 == "WIN32" && "'$os'" != "MINGW" &&
121 "'$os'" != "CYGWIN" && "'$os'" != "MSVC") { next; }
122 if ($0 == "MSVC" && "'$os'" != "MSVC") { next; }
123 if ($0 == "DIRECTMUSIC" && "'$with_direct_music'" == "0") { next; }
124 if ($0 == "FLUIDSYNTH" && "'$fluidsynth'" == "" ) { next; }
125 if ($0 == "USE_XAUDIO2" && "'$with_xaudio2'" == "0") { next; }
126 if ($0 == "USE_THREADS" && "'$with_threads'" == "0") { next; }
127 if ($0 == "USE_SSE" && "'$with_sse'" != "1") { next; }
129 skip += 1;
131 next;
133 /^( *)#/ { next }
134 /^$/ { next }
135 /\.h$/ { next }
136 /\.hpp$/ { next }
138 if (deep == skip) {
139 gsub(" ", "", $0);
140 print $0;
145 # Read the source.list and process it
146 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
147 SRCS="`< $ROOT_DIR/source.list tr '\r' '\n' | $awk \"$AWKCOMMAND\" | LC_ALL=C $PIPE_SORT`"
149 OBJS_C="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.c$/ { gsub(\".c$\", \".o\", $0); print $0; }'`"
150 OBJS_CPP="`echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.cpp$/ { gsub(\".cpp$\", \".o\", $0); print $0; }'`"
151 OBJS_MM="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.mm$/ { gsub(\".mm$\", \".o\", $0); print $0; }'`"
152 OBJS_RC="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.rc$/ { gsub(\".rc$\", \".o\", $0); print $0; }'`"
153 SRCS="` echo \"$SRCS\" | $awk ' { ORS = \" \" } { print $0; }'`"
155 # In makefiles, we always use -u for sort
156 if [ -z "$sort" ]; then
157 sort="sed s@a@a@"
158 else
159 sort="$sort -u"
162 CONFIGURE_FILES="$ROOT_DIR/configure $ROOT_DIR/config.lib $ROOT_DIR/Makefile.in $ROOT_DIR/Makefile.grf.in $ROOT_DIR/Makefile.lang.in $ROOT_DIR/Makefile.src.in $ROOT_DIR/Makefile.bundle.in $ROOT_DIR/Makefile.setting.in"
164 generate_main
165 generate_lang
166 generate_settings
167 generate_grf
168 generate_src
170 check_path_characters