Change: Use name of cargo instead of Passengers/Mail in town statistics. (#6801)
[openttd-github.git] / config.lib
blobd6ebb68a1121fb2f7ff4afc575a2f57de971c015
1 # $Id$
3 # This file is part of OpenTTD.
4 # 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.
5 # 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.
6 # 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/>.
8 log() {
9         if [ $1 = "1" ]; then
10                 shift
11                 echo "$@"
12         else
13                 shift
14         fi
15         echo "$@" >> $config_log
18 set_default() {
19         ignore_extra_parameters="0"
20         # We set all kinds of defaults for params. Later on the user can override
21         # most of them; but if they don't, this default is used.
22         build=""
23         host=""
24         cc_build=""
25         cc_host=""
26         cxx_build=""
27         cxx_host=""
28         windres=""
29         strip=""
30         lipo=""
31         awk="awk"
32         pkg_config="pkg-config"
33         os="DETECT"
34         cpu_type="DETECT"
35         config_log="config.log"
36         prefix_dir="/usr/local"
37         binary_dir="games"
38         data_dir="share/games/openttd"
39         doc_dir="1"
40         icon_dir="share/pixmaps"
41         icon_theme_dir="1"
42         personal_dir="1"
43         shared_dir="1"
44         install_dir="/"
45         man_dir="1"
46         menu_dir="1"
47         menu_group="Game;"
48         menu_name="OpenTTD"
49         binary_name="openttd"
50         enable_debug="0"
51         enable_desync_debug="0"
52         enable_profiling="0"
53         enable_lto="0"
54         enable_dedicated="0"
55         enable_network="1"
56         enable_static="1"
57         enable_translator="0"
58         enable_unicode="1"
59         enable_console="1";
60         enable_assert="1"
61         enable_strip="0"
62         enable_universal="0"
63         enable_osx_g5="0"
64         enable_cocoa_quartz="1"
65         enable_cocoa_quickdraw="1"
66         with_osx_sysroot="1"
67         with_application_bundle="1"
68         with_menu_entry="1"
69         with_allegro="1"
70         with_sdl="1"
71         with_cocoa="1"
72         with_zlib="1"
73         with_lzma="1"
74         with_lzo2="1"
75         with_xdg_basedir="1"
76         with_png="1"
77         enable_builtin_depend="1"
78         with_makedepend="0"
79         with_direct_music="1"
80         with_xaudio2="1"
81         with_sort="1"
82         with_iconv="1"
83         with_midi=""
84         with_midi_arg=""
85         with_libtimidity="1"
86         with_freetype="1"
87         with_fontconfig="1"
88         with_icu_layout="1"
89         with_icu_sort="1"
90         static_icu="0"
91         with_threads="1"
92         with_distcc="1"
93         with_ccache="1"
94         with_nforenum="1"
95         with_grfcodec="1"
96         with_sse="1"
98         save_params_array="
99                 build
100                 host
101                 cc_build
102                 cc_host
103                 cxx_build
104                 cxx_host
105                 windres
106                 strip
107                 lipo
108                 awk
109                 pkg_config
110                 os
111                 cpu_type
112                 config_log
113                 prefix_dir
114                 binary_dir
115                 data_dir
116                 doc_dir
117                 icon_dir
118                 icon_theme_dir
119                 man_dir
120                 menu_dir
121                 personal_dir
122                 shared_dir
123                 install_dir
124                 menu_group
125                 menu_name
126                 binary_name
127                 enable_debug
128                 enable_desync_debug
129                 enable_profiling
130                 enable_lto
131                 enable_dedicated
132                 enable_network
133                 enable_static
134                 enable_translator
135                 enable_unicode
136                 enable_console
137                 enable_assert
138                 enable_strip
139                 enable_universal
140                 enable_osx_g5
141                 enable_cocoa_quartz
142                 enable_cocoa_quickdraw
143                 with_osx_sysroot
144                 with_application_bundle
145                 with_allegro
146                 with_sdl
147                 with_cocoa
148                 with_zlib
149                 with_lzma
150                 with_lzo2
151                 with_xdg_basedir
152                 with_png
153                 enable_builtin_depend
154                 with_makedepend
155                 with_direct_music
156                 with_xaudio2
157                 with_sort
158                 with_iconv
159                 with_midi
160                 with_midi_arg
161                 with_libtimidity
162                 with_freetype
163                 with_fontconfig
164                 with_icu_layout
165                 with_icu_sort
166                 static_icu
167                 with_threads
168                 with_distcc
169                 with_ccache
170                 with_grfcodec
171                 with_nforenum
172                 with_sse
173         CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD PKG_CONFIG_PATH PKG_CONFIG_LIBDIR"
176 detect_params() {
177         # Walk over all params from the user and override any default settings if
178         #  needed. This also handles any invalid option.
179         for p in "$@"; do
180                 if [ -n "$prev_p" ]; then
181                         eval "$prev_p=\$p"
182                         prev_p=
183                         continue
184                 fi
186                 optarg=`expr "x$p" : 'x[^=]*=\(.*\)'`
188                 case "$p" in
189                         --help | -h | -\?)            showhelp; exit 0;;
191                         --config-log)                 prev_p="config_log";;
192                         --config-log=*)               config_log="$optarg";;
194                         --build)                      prev_p="build";;
195                         --build=*)                    build="$optarg";;
197                         --host)                       prev_p="host";;
198                         --host=*)                     host="$optarg";;
200                         --os)                         prev_p="os";;
201                         --os=*)                       os="$optarg";;
203                         --cpu-type)                   prev_p="cpu_type";;
204                         --cpu-type=*)                 cpu_type="$optarg";;
206                         --cc-build)                   prev_p="cc_build";;
207                         --cc-build=*)                 cc_build="$optarg";;
208                         --cc-host)                    prev_p="cc_host";;
209                         --cc-host=*)                  cc_host="$optarg";;
210                         --cxx-build)                  prev_p="cxx_build";;
211                         --cxx-build=*)                cxx_build="$optarg";;
212                         --cxx-host)                   prev_p="cxx_host";;
213                         --cxx-host=*)                 cxx_host="$optarg";;
214                         --windres)                    prev_p="windres";;
215                         --windres=*)                  windres="$optarg";;
216                         --awk)                        prev_p="awk";;
217                         --awk=*)                      awk="$optarg";;
218                         --pkg-config)                 prev_p="pkg_config";;
219                         --pkg-config=*)               pkg_config="$optarg";;
220                         --strip)                      prev_p="strip";;
221                         --strip=*)                    strip="$optarg";;
222                         --lipo)                       prev_p="lipo";;
223                         --lipo=*)                     lipo="$optarg";;
227                         # Alias --prefix with --prefix-dir, for compatibility with GNU autotools
228                         --prefix-dir | --prefix)      prev_p="prefix_dir";;
229                         --prefix-dir=* | --prefix=*)  prefix_dir="$optarg";;
231                         --binary-dir)                 prev_p="binary_dir";;
232                         --binary-dir=*)               binary_dir="$optarg";;
234                         --data-dir)                   prev_p="data_dir";;
235                         --data-dir=*)                 data_dir="$optarg";;
237                         --doc-dir)                    prev_p="doc_dir";;
238                         --doc-dir=*)                  doc_dir="$optarg";;
240                         --icon-dir)                   prev_p="icon_dir";;
241                         --icon-dir=*)                 icon_dir="$optarg";;
243                         --icon-theme-dir)             prev_p="icon_theme_dir";;
244                         --icon-theme-dir=*)           icon_theme_dir="$optarg";;
245                         --without-icon-theme)         icon_theme_dir="";;
247                         --menu-dir)                   prev_p="menu_dir";;
248                         --menu-dir=*)                 menu_dir="$optarg";;
249                         --without-menu-entry)         menu_dir="";;
251                         --menu-name)                  prev_p="menu_name";;
252                         --menu-name=*)                menu_name="$optarg";;
254                         --binary-name)                prev_p="binary_name";;
255                         --binary-name=*)              binary_name="$optarg";;
257                         --man-dir)                    prev_p="man_dir";;
258                         --man-dir=*)                  man_dir="$optarg";;
260                         --personal-dir)               prev_p="personal_dir";;
261                         --personal-dir=*)             personal_dir="$optarg";;
262                         --without-personal-dir)       personal_dir="";;
264                         --shared-dir)                 prev_p="shared_dir";;
265                         --shared-dir=*)               shared_dir="$optarg";;
266                         --without-shared-dir)         shared_dir="";;
268                         --install-dir)                prev_p="install_dir";;
269                         --install-dir=*)              install_dir="$optarg";;
273                         --menu-group)                 prev_p="menu_group";;
274                         --menu-group=*)               menu_group="$optarg";;
278                         --enable-debug)               enable_debug="1";;
279                         --enable-debug=*)             enable_debug="$optarg";;
280                         --enable-desync-debug)        enable_desync_debug="1";;
281                         --enable-desync-debug=*)      enable_desync_debug="$optarg";;
282                         --enable-profiling)           enable_profiling="1";;
283                         --enable-profiling=*)         enable_profiling="$optarg";;
284                         --enable-lto)                 enable_lto="1";;
285                         --enable-lto=*)               enable_lto="$optarg";;
286                         --enable-ipo)                 enable_lto="1";;
287                         --enable-ipo=*)               enable_lto="$optarg";;
288                         --enable-dedicated)           enable_dedicated="1";;
289                         --enable-dedicated=*)         enable_dedicated="$optarg";;
290                         --enable-network)             enable_network="2";;
291                         --enable-network=*)           enable_network="$optarg";;
292                         --disable-network)            enable_network="0";;
293                         --disable-static)             enable_static="0";;
294                         --enable-static)              enable_static="2";;
295                         --enable-static=*)            enable_static="$optarg";;
296                         --disable-translator)         enable_translator="0";;
297                         --enable-translator)          enable_translator="2";;
298                         --enable-translator=*)        enable_translator="$optarg";;
299                         --disable-assert)             enable_assert="0";;
300                         --enable-assert)              enable_assert="2";;
301                         --enable-assert=*)            enable_assert="$optarg";;
302                         --disable-strip)              enable_strip="0";;
303                         --enable-strip)               enable_strip="2";;
304                         --enable-strip=*)             enable_strip="$optarg";;
305                         --disable-universal)          enable_universal="0";;
306                         --enable-universal)           enable_universal="i386 ppc";;
307                         --enable-universal=*)         enable_universal="$optarg";;
308                         --disable-osx-g5)             enable_osx_g5="0";;
309                         --enable-osx-g5)              enable_osx_g5="2";;
310                         --enable-osx-g5=*)            enable_osx_g5="$optarg";;
311                         --disable-unicode)            enable_unicode="0";;
312                         --enable-unicode)             enable_unicode="2";;
313                         --enable-unicode=*)           enable_unicode="$optarg";;
314                         --disable-console)            enable_console="0";;
315                         --enable-console)             enable_console="2";;
316                         --enable-console=*)           enable_console="$optarg";;
318                         --disable-cocoa-quartz)       enable_cocoa_quartz="0";;
319                         --enable-cocoa-quartz)        enable_cocoa_quartz="2";;
320                         --enable-cocoa-quartz=*)      enable_cocoa_quartz="$optarg";;
321                         --disable-cocoa-quickdraw)    enable_cocoa_quickdraw="0";;
322                         --enable-cocoa-quickdraw)     enable_cocoa_quickdraw="2";;
323                         --enable-cocoa-quickdraw=*)   enable_cocoa_quickdraw="$optarg";;
325                         --with-allegro)               with_allegro="2";;
326                         --without-allegro)            with_allegro="0";;
327                         --with-allegro=*)             with_allegro="$optarg";;
329                         --with-sdl)                   with_sdl="2";;
330                         --without-sdl)                with_sdl="0";;
331                         --with-sdl=*)                 with_sdl="$optarg";;
333                         --with-cocoa)                 with_cocoa="2";;
334                         --without-cocoa)              with_cocoa="0";;
335                         --with-cocoa=*)               with_cocoa="$optarg";;
337                         --with-zlib)                  with_zlib="2";;
338                         --without-zlib)               with_zlib="0";;
339                         --with-zlib=*)                with_zlib="$optarg";;
341                         --with-lzma)                  with_lzma="2";;
342                         --without-lzma)               with_lzma="0";;
343                         --with-lzma=*)                with_lzma="$optarg";;
344                         --with-liblzma)               with_lzma="2";;
345                         --without-liblzma)            with_lzma="0";;
346                         --with-liblzma=*)             with_lzma="$optarg";;
348                         --with-lzo2)                  with_lzo2="2";;
349                         --without-lzo2)               with_lzo2="0";;
350                         --with-lzo2=*)                with_lzo2="$optarg";;
351                         --with-liblzo2)               with_lzo2="2";;
352                         --without-liblzo2)            with_lzo2="0";;
353                         --with-liblzo2=*)             with_lzo2="$optarg";;
355                         --with-xdg-basedir)           with_xdg_basedir="2";;
356                         --without-xdg-basedir)        with_xdg_basedir="0";;
357                         --with-xdg-basedir=*)         with_xdg_basedir="$optarg";;
358                         --with-libxdg-basedir)        with_xdg_basedir="2";;
359                         --without-libxdg-basedir)     with_xdg_basedir="0";;
360                         --with-libxdg-basedir=*)      with_xdg_basedir="$optarg";;
362                         --with-png)                   with_png="2";;
363                         --without-png)                with_png="0";;
364                         --with-png=*)                 with_png="$optarg";;
365                         --with-libpng)                with_png="2";;
366                         --without-libpng)             with_png="0";;
367                         --with-libpng=*)              with_png="$optarg";;
369                         --with-libtimidity)           with_libtimidity="2";;
370                         --without-libtimidity)        with_libtimidity="0";;
371                         --with-libtimidity=*)         with_libtimidity="$optarg";;
373                         --with-freetype)              with_freetype="2";;
374                         --without-freetype)           with_freetype="0";;
375                         --with-freetype=*)            with_freetype="$optarg";;
376                         --with-libfreetype)           with_freetype="2";;
377                         --without-libfreetype)        with_freetype="0";;
378                         --with-libfreetype=*)         with_freetype="$optarg";;
380                         --with-fontconfig)            with_fontconfig="2";;
381                         --without-fontconfig)         with_fontconfig="0";;
382                         --with-fontconfig=*)          with_fontconfig="$optarg";;
383                         --with-libfontconfig)         with_fontconfig="2";;
384                         --without-libfontconfig)      with_fontconfig="0";;
385                         --with-libfontconfig=*)       with_fontconfig="$optarg";;
387                         --with-icu)                   with_icu_layout="2";with_icu_sort="2";;
388                         --without-icu)                with_icu_layout="0";with_icu_sort="0";;
389                         --with-icu=*)                 with_icu_layout="$optarg";with_icu_sort="$optarg";;
390                         --with-libicu)                with_icu_layout="2";with_icu_sort="2";;
391                         --without-libicu)             with_icu_layout="0";with_icu_sort="0";;
392                         --with-libicu=*)              with_icu_layout="$optarg";with_icu_sort="$optarg";;
393                         --with-icu-layout)            with_icu_layout="2";;
394                         --without-icu-layout)         with_icu_layout="0";;
395                         --with-icu-layout=*)          with_icu_layout="$optarg";;
396                         --with-icu-sort)              with_icu_sort="2";;
397                         --without-icu-sort)           with_icu_sort="0";;
398                         --with-icu-sort=*)            with_icu_sort="$optarg";;
399                         --static-icu)                 static_icu="1";;
400                         --static-icu=*)               static_icu="$optarg";;
401                         --static-libicu)              static_icu="1";;
402                         --static-libicu=*)            static_icu="$optarg";;
404                         --disable-builtin-depend)     enable_builtin_depend="0";;
405                         --enable-builtin-depend)      enable_builtin_depend="2";;
406                         --enable-builtin-depend=*)    enable_builtin_depend="$optarg";;
408                         --with-makedepend)            with_makedepend="2";;
409                         --without-makedepend)         with_makedepend="0";;
410                         --with-makedepend=*)          with_makedepend="$optarg";;
412                         --with-direct-music)          with_direct_music="2";;
413                         --without-direct-music)       with_direct_music="0";;
414                         --with-direct-music=*)        with_direct_music="$optarg";;
416                         --with-xaudio2)               with_xaudio2="2";;
417                         --without-xaudio2)            with_xaudio2="0";;
418                         --with-xaudio2=*)             with_xaudio2="$optarg";;
420                         --with-sort)                  with_sort="2";;
421                         --without-sort)               with_sort="0";;
422                         --with-sort=*)                with_sort="$optarg";;
424                         --with-iconv)                 with_iconv="2";;
425                         --without-iconv)              with_iconv="0";;
426                         --with-iconv=*)               with_iconv="$optarg";;
428                         --with-midi=*)                with_midi="$optarg";;
429                         --with-midi-arg=*)            with_midi_arg="$optarg";;
431                         --without-distcc)             with_distcc="0";;
432                         --with-distcc)                with_distcc="2";;
433                         --with-distcc=*)              with_distcc="$optarg";;
435                         --without-ccache)             with_ccache="0";;
436                         --with-ccache)                with_ccache="2";;
437                         --with-ccache=*)              with_ccache="$optarg";;
439                         --without-nforenum)           with_nforenum="0";;
440                         --with-nforenum)              with_nforenum="2";;
441                         --with-nforenum=*)            with_nforenum="$optarg";;
443                         --without-grfcodec)           with_grfcodec="0";;
444                         --with-grfcodec)              with_grfcodec="2";;
445                         --with-grfcodec=*)            with_grfcodec="$optarg";;
447                         --without-osx-sysroot)        with_osx_sysroot="0";;
448                         --with-osx-sysroot)           with_osx_sysroot="2";;
449                         --with-osx-sysroot=*)         with_osx_sysroot="$optarg";;
451                         --without-application-bundle) with_application_bundle="0";;
452                         --with-application-bundle)    with_application_bundle="1";;
453                         --with-application-bundle=*)  with_application_bundle="$optarg";;
455                         --without-threads)            with_threads="0";;
456                         --with-threads)               with_threads="1";;
457                         --with-threads=*)             with_threads="$optarg";;
459                         --without-sse)                with_sse="0";;
460                         --with-sse)                   with_sse="1";;
461                         --with-sse=*)                 with_sse="$optarg";;
463                         CC=* | --CC=*)                CC="$optarg";;
464                         CXX=* | --CXX=*)              CXX="$optarg";;
465                         CFLAGS=* | --CFLAGS=*)        CFLAGS="$optarg";;
466                         CXXFLAGS=* | --CXXFLAGS=*)    CXXFLAGS="$optarg";;
467                         LDFLAGS=* | --LDFLAGS=*)      LDFLAGS="$optarg";;
468                         CFLAGS_BUILD=* | --CFLAGS_BUILD=* | --CFLAGS-BUILD=*)     CFLAGS_BUILD="$optarg";;
469                         CXXFLAGS_BUILD=* | --CXXFLAGS_BUILD=* | --CXXFLAGS-BUILD=*) CXXFLAGS_BUILD="$optarg";;
470                         LDFLAGS_BUILD=* | --LDFLAGS_BUILD=* | --LDFLAGS-BUILD=*)   LDFLAGS_BUILD="$optarg";;
471                         PKG_CONFIG_PATH=* | --PKG_CONFIG_PATH=* | --PKG-CONFIG-PATH=*) PKG_CONFIG_PATH="$optarg";;
472                         PKG_CONFIG_LIBDIR=* | --PKG_CONFIG_LIBDIR=* | --PKG-CONFIG-LIBDIR=*) PKG_CONFIG_LIBDIR="$optarg";;
474                         --ignore-extra-parameters)    ignore_extra_parameters="1";;
476                         --* | -*)
477                                 if [ "$ignore_extra_parameters" = "0" ]; then
478                                         log 1 "Unknown option $p"
479                                         exit 1
480                                 else
481                                         log 1 "Unknown option $p ignored"
482                                 fi
483                                 ;;
484                 esac
485         done
487         if [ -n "$prev_p" ]; then
488                 log 1 "configure: error: missing argument to --$prev_p"
489                 exit 1
490         fi
492         # Clean the logfile
493         echo "" > $config_log
494         log 2 "Invocation: $0 $*"
497 save_params() {
498         # Here we save all params, so we can later on do an exact redo of this
499         #  configuration, without having the user to re-input stuff
501         echo "Running configure with following options:" >> $config_log
502         echo "" >> $config_log
504         configure="$CONFIGURE_EXECUTABLE --ignore-extra-parameters"
505         for p in $save_params_array; do
506                 eval "v=\"\$$p\""
507                 p=`echo "$p" | sed 's@_@-@g;s@\n@@g;s@ @\\ @g'`
508                 # Only save those params that aren't empty
509                 configure="$configure --$p=\"$v\""
510         done
512         echo "$configure" >> $config_log
513         echo "$configure" > config.cache
514         echo "" >> $config_log
517 # Export a variable so tools like pkg-config can see it when invoked.
518 # If the variable contains an empty string then unset it.
519 # $1 - name of the variable to export or unset
520 export_or_unset() {
521         eval local value=\$$1
522         if [ -n "$value" ]; then
523                 export $1;
524                 log 2 "using $1=$value";
525         else
526                 unset $1;
527                 log 2 "not using $1";
528         fi
531 check_params() {
532         # Some params want to be in full uppercase, else they might not work as
533         # expected.. fix that here
535         os=`echo $os | tr '[a-z]' '[A-Z]'`
536         cpu_type=`echo $cpu_type | tr '[a-z]' '[A-Z]'`
538         # Export some variables to be used by pkg-config
539         #
540         # PKG_CONFIG_LIBDIR variable musn't be set if we are not willing to
541         # override the default pkg-config search path, it musn't be an empty
542         # string. If the variable is empty (e.g. when an empty string comes
543         # from config.cache) then unset it. This way the "don't override" state
544         # will be properly preserved when (re)configuring.
545         export_or_unset PKG_CONFIG_PATH
546         export_or_unset PKG_CONFIG_LIBDIR
548         # Check if all params have valid values
550         # OS only allows DETECT, UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, MORPHOS, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, and DOS
551         if [ -z "`echo $os | egrep '^(DETECT|UNIX|OSX|FREEBSD|DRAGONFLY|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS)$'`" ]; then
552                 log 1 "configure: error: invalid option --os=$os"
553                 log 1 " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|DRAGONFLY|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS]"
554                 exit 1
555         fi
556         # cpu_type can be either 32 or 64
557         if [ -z "`echo $cpu_type | egrep '^(32|64|DETECT)$'`" ]; then
558                 log 1 "configure: error: invalid option --cpu-type=$cpu_type"
559                 log 1 " Available options are: --cpu-type[=DETECT|32|64]"
560                 exit 1
561         fi
562         # enable_debug should be between 0 and 4
563         if [ -z "`echo $enable_debug | egrep '^[0123]$'`" ]; then
564                 log 1 "configure: error: invalid option --enable-debug=$enable_debug"
565                 log 1 " Available options are: --enable-debug[=0123]"
566                 exit 1
567         fi
569         # enable_desync_debug should be between 0 and 3
570         if [ -z "`echo $enable_desync_debug | egrep '^[012]$'`" ]; then
571                 log 1 "configure: error: invalid option --enable-desync-debug=$enable_desync_debug"
572                 log 1 " Available options are: --enable-desync-debug[=012]"
573                 exit 1
574         fi
576         detect_awk
578         detect_os
580         check_build
581         check_host
583         # Check for universal builds; they only make sense for OSX, so fail if enabled for another OS
584         if [ "$enable_universal" = "0" ]; then
585                 log 1 "checking universal build... no"
586         else
587                 if [ "$os" != "OSX" ]; then
588                         log 1 "configure: error: --enable-universal only works on OSX"
589                         exit 1
590                 fi
591                 log 1 "checking universal build... yes, for: $enable_universal"
592         fi
594         # Already detected by check_build
595         log 1 "checking build cc... $cc_build"
596         log 1 "checking host cc... $cc_host"
598         check_cxx_build
599         check_cxx_host
600         check_windres
601         if [ "$enable_strip" != "0" ]; then
602                 check_strip
603         else
604                 log 1 "checking strip... disabled"
605         fi
606         check_lipo
608         if [ "$enable_builtin_depend" != "0" ]; then
609                 log 1 "checking builtin depend... yes"
610                 makedepend="\$(SRC_OBJS_DIR)/\$(DEPEND)"
611         else
612                 log 1 "checking builtin depend... no"
613         fi
615         check_makedepend
616         detect_cputype
617         detect_sse_capable_architecture
619         if [ "$enable_static" = "1" ]; then
620                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "DOS" ]; then
621                         enable_static="2"
622                 else
623                         enable_static="0"
624                 fi
625         fi
627         if [ "$enable_static" != "0" ]; then
628                 log 1 "checking static... yes"
630                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "OSX" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "DOS" ]; then
631                         log 1 "WARNING: static is only known to work on Windows, DOS, MacOSX and MorphOS"
632                         log 1 "WARNING: use static at your own risk on this platform"
634                         sleep 5
635                 fi
636         else
637                 log 1 "checking static... no"
638         fi
640         if [ "$enable_unicode" = "1" ]; then
641                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "DOS" ]; then
642                         enable_unicode="2"
643                 else
644                         enable_unicode="0"
645                 fi
646         fi
648         if [ "$enable_unicode" != "0" ]; then
649                 log 1 "checking unicode... yes"
650         else
651                 log 1 "checking unicode... no"
652         fi
654         # Show what we configured
655         if [ "$enable_debug" = "0" ]; then
656                 log 1 "using debug level... no"
657         elif [ "$enable_profiling" != "0" ]; then
658                 log 1 "using debug level... profiling (debug level $enable_debug)"
659         else
660                 log 1 "using debug level... level $enable_debug"
661         fi
663         if [ "$enable_desync_debug" = "0" ]; then
664                 log 1 "using desync debug level... no"
665         else
666                 log 1 "using desync debug level... level $enable_desync_debug"
667                 log 1 "WARNING: desync debug functions slow down the game considerably."
668                 log 1 "WARNING: use only when you are instructed to do so"
669                 log 1 "         or when you know what you are doing."
671                 sleep 5
672         fi
674         if [ "$enable_lto" != "0" ]; then
675                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
676                 has_lto=`($cxx_build -dumpspecs 2>&1 | grep '\%{flto') || ($cxx_build -help ipo 2>&1 | grep '\-ipo')`
677                 if [ -n "$has_lto" ]; then
678                         log 1 "using link time optimization... yes"
679                 else
680                         enable_lto="0"
681                         log 1 "using link time optimization... no"
682                         log 1 "WARNING: you selected link time optimization but it is not found."
683                         sleep 5
684                 fi
685         else
686                 log 1 "using link time optimization... no"
687         fi
690         if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
691                 if [ "$with_osx_sysroot" = "1" ]; then
692                         with_osx_sysroot="0"
694                         log 1 "checking OSX sysroot... not OSX, skipping"
695                 else
696                         log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
697                         exit 1
698                 fi
699         fi
701         if [ "$with_osx_sysroot" != "0" ]; then
702                 if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
703                         # Sysroot manually specified? Check for usability
704                         log 1 "checking OSX sysroot... $with_osx_sysroot"
705                         if ! check_osx_sdk "$with_osx_sysroot"; then
706                                 log 1 "Passed sysroot not found/not functional"
707                                 exit 1
708                         fi
709                 else
710                         # If autodetect and no universal, use system default
711                         if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
712                                 log 1 "checking OSX sysroot... no (use system default)"
713                         else
714                                 log 1 "checking OSX sysroot... automatically"
715                                 detect_osx_sdk
716                         fi
717                 fi
719                 if [ -n "$osx_sdk_path" ]; then
720                         if [ "$enable_universal" != "0" ]; then
721                                 if [ -z "$osx_sdk_104_path" ]; then
722                                         log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
723                                         log 1 "WARNING: binary will only run on OSX 10.5 or later"
724                                         osx_sdk_104_path="$osx_sdk_path"
725                                 fi
726                                 OSX_SYSROOT="-isysroot $osx_sdk_104_path"
727                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
728                         else
729                                 OSX_SYSROOT="-isysroot $osx_sdk_path"
730                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
731                         fi
732                 fi
733         else
734                 if [ "$os" = "OSX" ]; then
735                         log 1 "checking OSX sysroot... no (use system default)"
736                 fi
737         fi
739         detect_allegro
740         detect_sdl
741         detect_cocoa
743         if [ "$enable_dedicated" != "0" ]; then
744                 log 1 "checking GDI video driver... dedicated server, skipping"
745                 log 1 "checking dedicated... found"
747                 if [ "$enable_network" = "0" ]; then
748                         log 1 "configure: error: building a dedicated server without network support is pointless"
749                         exit 1
750                 fi
751         else
752                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
753                         log 1 "checking GDI video driver... found"
754                 else
755                         log 1 "checking GDI video driver... not Windows, skipping"
756                 fi
758                 if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
759                         log 1 "configure: error: no video driver development files found"
760                         log 1 " If you want a dedicated server use --enable-dedicated as parameter"
761                         exit 1
762                 else
763                         log 1 "checking dedicated... not selected"
764                 fi
765         fi
767         if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
768                 log 1 "checking console application... not Windows, skipping"
769         elif [ "$enable_console" = "1" ] && [ "$enable_dedicated" != "0" ]; then
770                 log 1 "checking console application... dedicated server, enabled"
771                 enable_console="2"
772         elif [ "$enable_console" = "1" ]; then
773                 log 1 "checking console application... disabled (only used when forced)"
774                 enable_console="0"
775         elif [ "$enable_console" = "0" ]; then
776                 log 1 "checking console application... disabled"
777         else
778                 log 1 "checking console application... enabled"
779         fi
781         if [ "$enable_network" = "1" ] && [ "$os" = "DOS" ]; then
782                 log 1 "checking network... DOS, skipping"
783                 enable_network=0
784         elif [ "$enable_network" != "0" ]; then
785                 log 1 "checking network... found"
786         else
787                 log 1 "checking network... disabled"
788         fi
790         log 1 "checking squirrel... found"
791         SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"
793         if [ "$enable_translator" != "0" ]; then
794                 log 1 "checking translator... debug"
795                 # -t shows TODO items, normally they are muted
796                 strgen_flags="-t"
797         else
798                 log 1 "checking translator... no"
799                 strgen_flags=""
800         fi
802         if [ "$enable_assert" != "0" ]; then
803                 log 1 "checking assert... enabled"
804         else
805                 log 1 "checking assert... disabled"
806         fi
808         pre_detect_with_zlib=$with_zlib
809         detect_zlib
811         if [ "$with_zlib" = "0" ] || [ -z "$zlib-config" ]; then
812                 log 1 "WARNING: zlib was not detected or disabled"
813                 log 1 "WARNING: OpenTTD doesn't require zlib, but it does mean that many features"
814                 log 1 "WARNING: (like loading most old savegames/scenarios, loading heightmaps,"
815                 log 1 "WARNING: using PNG, or using fonts, ...) will be disabled."
816                 if [ "$pre_detect_with_zlib" = "0" ]; then
817                         log 1 "WARNING: We strongly suggest you to install zlib."
818                 else
819                         log 1 "configure: error: no zlib detected"
820                         log 1 " If you want to compile without zlib use --without-zlib as parameter"
821                         exit
822                 fi
823         fi
825         pre_detect_with_lzma=$with_lzma
826         detect_lzma
828         if [ "$with_lzma" = "0" ] || [ -z "$lzma_config" ]; then
829                 log 1 "WARNING: lzma was not detected or disabled"
830                 log 1 "WARNING: OpenTTD doesn't require lzma, but it does mean that many features"
831                 log 1 "WARNING: (like loading most savegames/scenarios and joining most servers)"
832                 log 1 "WARNING: will be disabled."
833                 if [ "$pre_detect_with_lzma" = "0" ]; then
834                         log 1 "WARNING: We strongly suggest you to install liblzma."
835                         log 1 "configure: error: no liblzma detected"
836                 else
837                         log 1 " If you want to compile without lzma use --without-lzma as parameter"
838                         exit
839                 fi
840         fi
842         pre_detect_with_lzo2=$with_lzo2
843         detect_lzo2
845         if [ "$with_lzo2" = "0" ] || [ -z "$lzo2" ]; then
846                 log 1 "WARNING: liblzo2 was not detected or disabled"
847                 log 1 "WARNING: OpenTTD doesn't require liblzo2, but it does mean that"
848                 log 1 "WARNING: loading old savegames/scenarios will be disabled."
849                 if [ "$pre_detect_with_lzo2" = "0" ]; then
850                         log 1 "WARNING: We strongly suggest you to install liblzo2."
851                 else
852                         log 1 "configure: error: no liblzo2 detected"
853                         log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
854                         exit
855                 fi
856         fi
858         detect_xdg_basedir
859         detect_png
860         detect_freetype
861         detect_fontconfig
862         detect_icu_layout
863         detect_icu_sort
864         detect_libtimidity
866         if [ "$with_direct_music" != "0" ]; then
867                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
868                         if [ "$with_direct_music" != "1" ]; then
869                                 log 1 "configure: error: direct-music is only supported on Win32 targets"
870                                 exit 1
871                         fi
872                         with_direct_music="0"
874                         log 1 "checking direct-music... not Windows, skipping"
875                 else
876                         check_direct_music
877                 fi
878         fi
880         if [ "$with_xaudio2" != "0" ]; then
881                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
882                         if [ "$with_xaudio2" != "1" ]; then
883                                 log 1 "configure: error: xaudio2 is only supported on Win32 targets"
884                                 exit 1
885                         fi
886                         with_xaudio2="0"
888                         log 1 "checking xaudio2... not Windows, skipping"
889                 else
890                         check_xaudio2
891                 fi
892         fi
894         detect_sort
896         # Suppress language errors when there is a version defined, indicating a release
897         #  It just isn't pretty if any release produces warnings in the languages.
898         if [ -f "$ROOT_DIR/version" ]; then
899                 lang_suppress="yes"
900                 log 1 "suppress language errors... yes"
901         else
902                 lang_suppress=""
903                 log 1 "suppress language errors... no"
904         fi
906         if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
907                 if [ "$os" = "MORPHOS" ]; then
908                         strip_arg="--strip-all --strip-unneeded --remove-section .comment"
909                 elif [ "$os" = "OSX" ]; then
910                         strip_arg=""
911                 elif [ "$os" = "OS2" ]; then
912                         strip_arg=""
913                         # OS2 uses strip via gcc, because it needs to be feed to emxbind
914                         LDFLAGS="$LDFLAGS -s"
915                 elif [ "$os" = "SUNOS" ]; then
916                         # The GNU strip does know -s, the non-GNU doesn't
917                         #  So try to detect it (in a bit of an ugly way)
918                         strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
919                 else
920                         strip_arg="-s"
921                 fi
923                 log 1 "checking stripping... $strip $strip_arg"
924         else
925                 strip=""
926                 log 1 "checking stripping... skipped"
927         fi
929         if [ "$with_distcc" = "0" ]; then
930                 log 1 "checking distcc... no"
931         elif [ "$with_distcc" = "1" ]; then
932                 with_distcc="0"
934                 log 1 "checking distcc... no (only used when forced)"
935         elif [ "$with_distcc" = "2" ]; then
936                 distcc="distcc"
937         else
938                 distcc="$with_distcc"
939         fi
940         if [ "$with_distcc" != "0" ]; then
941                 res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
942                 if [ "$res" != "distcc" ]; then
943                         distcc=""
944                         log 1 "checking distcc... no"
945                         if [ "$with_distcc" = "2" ]; then
946                                 log 1 "configure: error: no distcc detected, but was forced to be used"
947                                 exit 1
948                         fi
949                         if [ "$with_distcc" != "1" ]; then
950                                 log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
951                                 exit 1
952                         fi
953                 fi
955                 log 1 "checking distcc... $distcc"
956         fi
958         if [ "$with_ccache" = "0" ]; then
959                 log 1 "checking ccache... no"
960         elif [ "$with_ccache" = "1" ]; then
961                 with_ccache="0"
963                 log 1 "checking ccache... no (only used when forced)"
964         elif [ "$with_ccache" = "2" ]; then
965                 ccache="ccache"
966         else
967                 ccache="$with_ccache"
968         fi
969         if [ "$with_ccache" != "0" ]; then
970                 res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
971                 if [ "$res" != "ccache" ]; then
972                         ccache=""
973                         log 1 "checking ccache... no"
974                         if [ "$with_ccache" = "2" ]; then
975                                 log 1 "configure: error: no ccache detected, but was forced to be used"
976                                 exit 1
977                         fi
978                         if [ "$with_ccache" != "1" ]; then
979                                 log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
980                                 exit 1
981                         fi
982                 fi
984                 log 1 "checking ccache... $ccache"
985         fi
987         detect_grfcodec
988         detect_nforenum
990         if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
991                 log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
992                 nforenum=""
993         fi
995         if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
996                 log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
997                 grfcodec=""
998         fi
1000         if [ "$os" = "DOS" ]; then
1001                 with_threads="0"
1002         fi
1004         if [ "$os" != "OSX" ] && [ "$with_application_bundle" != "0" ]; then
1005                 if [ "$with_application_bundle" = "1" ]; then
1006                         with_application_bundle="0"
1008                         log 1 "checking OSX application bundle... not OSX, skipping"
1009                 else
1010                         log 1 "configure: error: --with-application-bundle only works if OSX is the target"
1011                         exit 1
1012                 fi
1013         fi
1015         if [ "$os" = "OSX" ] && [ "$with_application_bundle" = "1" ]; then
1016                 OSXAPP="OpenTTD.app"
1017         else
1018                 OSXAPP=""
1019         fi
1021         if [ "$os" = "OSX" ]; then
1022                 # Test on ppc970 (G5) - we can optimize there
1024                 if [ "$enable_osx_g5" != "0" ]; then
1025                         log 1 "detecting ppc970 (G5)... yes (forced)"
1026                 else
1027                         # First, are we a real OSX system, else we can't detect it
1028                         native=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | grep darwin`
1029                         # If $host doesn't match $build , we are cross-compiling
1030                         if [ -n "$native" ] && [ "$build" = "$host" ]; then
1031                                 $cxx_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
1032                                 res=`./G5_detector`
1033                                 rm -f G5_detector
1034                                 if [ -n "$res" ]; then
1035                                         # This is G5, add flags for it
1036                                         enable_osx_g5="2"
1038                                         log 1 "detecting ppc970 (G5)... yes"
1039                                 else
1040                                         enable_osx_g5="0"
1042                                         log 1 "detecting ppc970 (G5)... no"
1043                                 fi
1044                         else
1045                                 enable_osx_g5="0"
1047                                 log 1 "detecting ppc970 (G5)... no (cross-compiling)"
1048                         fi
1049                 fi
1050         else
1051                 if [ "$enable_osx_g5" != "0" ]; then
1052                         log 1 "configure: error: ppc970 (OSX G5) selected, but not compiling for OSX"
1053                         log 1 "configure: error: either select OSX as OS, or deselect ppc970"
1055                         exit 1
1056                 fi
1057         fi
1059         if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
1060                 log 1 "checking revision... svn detection"
1061         elif [ -d "$ROOT_DIR/../.svn" ] && [ -n "`svn help 2>/dev/null`" ] && [ -n "`LC_ALL=C svn info $ROOT_DIR/.. | grep '^URL:.*tags$'`" ]; then
1062                 # subversion changed its behaviour; now not all folders have a .svn folder,
1063                 # but only the root folder. Since making tags requires a (sparse) checkout
1064                 # of the tags folder, the folder of the tag does not have a .svn folder
1065                 # anymore and this fails to detect the subversion repository checkout.
1066                 log 1 "checking revision... svn detection (tag)"
1067         elif [ -d "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
1068                 log 1 "checking revision... git detection"
1069         elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`HGPLAIN= hg help 2>/dev/null`" ]; then
1070                 log 1 "checking revision... hg detection"
1071         elif [ -f "$ROOT_DIR/.ottdrev" ]; then
1072                 log 1 "checking revision... source tarball"
1073         else
1074                 log 1 "checking revision... no detection"
1075                 log 1 "WARNING: there is no means to determine the version."
1076                 log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenTTD."
1077                 log 1 "WARNING: you can only join game servers that have been compiled without"
1078                 log 1 "WARNING:   version detection."
1079                 log 1 "WARNING: there is a great chance you desync."
1080                 log 1 "WARNING: USE WITH CAUTION!"
1082                 sleep 5
1083         fi
1085         if [ "$doc_dir" = "1" ]; then
1086                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1087                         doc_dir="share/doc/openttd"
1088                 else
1089                         doc_dir="$data_dir/docs"
1090                 fi
1091         else
1092                 doc_dir="`echo $doc_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1093         fi
1095         if [ "$icon_theme_dir" = "1" ]; then
1096                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1097                         icon_theme_dir="share/icons/hicolor"
1098                 else
1099                         icon_theme_dir=""
1100                 fi
1101         else
1102                 icon_theme_dir="`echo $icon_theme_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1103         fi
1105         if [ "$personal_dir" = "1" ]; then
1106                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "DOS" ] || [ "$os" = "HAIKU" ]; then
1107                         personal_dir="OpenTTD"
1108                 elif [ "$os" = "OSX" ]; then
1109                         personal_dir="Documents/OpenTTD"
1110                 else
1111                         personal_dir=".openttd"
1112                 fi
1113         else
1114                 personal_dir="`echo $personal_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1115         fi
1117         if [ "$shared_dir" = "1" ]; then
1118                 # we are using default values
1119                 if [ "$os" = "OSX" ]; then
1120                         shared_dir="/Library/Application\\\\ Support/OpenTTD"
1121                 else
1122                         shared_dir=""
1123                 fi
1124         else
1125                 shared_dir="`echo $shared_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1126         fi
1128         if [ "$man_dir" = "1" ]; then
1129                 # add manpage on UNIX systems
1130                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OSX" ]; then
1131                         man_dir="share/man/man6"
1132                 else
1133                         man_dir=""
1134                 fi
1135         else
1136                 man_dir="`echo $man_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1137         fi
1139         if [ "$menu_dir" = "1" ]; then
1140                 # add a freedesktop menu item only for some UNIX systems
1141                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1142                         menu_dir="share/applications"
1143                 else
1144                         menu_dir=""
1145                 fi
1146         else
1147                 menu_dir="`echo $menu_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1148         fi
1150         detect_iconv
1152         if [ -n "$personal_dir" ]
1153         then
1154                 log 1 "personal home directory... $personal_dir"
1155         else
1156                 log 1 "personal home directory... none"
1157         fi
1159         if [ -n "$shared_dir" ]
1160         then
1161                 log 1 "shared data directory... $shared_dir"
1162         else
1163                 log 1 "shared data directory... none"
1164         fi
1166         if [ -n "$install_dir" ]
1167         then
1168                 log 1 "installation directory... $install_dir"
1169         else
1170                 log 1 "installation directory... none"
1171         fi
1173         if [ -n "$icon_theme_dir" ]
1174         then
1175                 log 1 "icon theme directory... $icon_theme_dir"
1176         else
1177                 log 1 "icon theme directory... none"
1178         fi
1180         if [ -n "$man_dir" ]
1181         then
1182                 log 1 "manual page directory... $man_dir"
1183         else
1184                 log 1 "manual page directory... none"
1185         fi
1187         if [ -n "$menu_dir" ]
1188         then
1189                 log 1 "menu item directory... $menu_dir"
1190         else
1191                 log 1 "menu item directory... none"
1192         fi
1195 make_compiler_cflags() {
1196         # Params:
1197         # $1 - compiler
1198         # $2 - name of the cflags variable
1199         # $3 - name of the cxxflags variable
1200         # $4 - name of the ldflags variable
1201         # $5 - name of the features variable
1203         # Get the compiler to tell us who it is
1204         compiler="`$1 --version | head -n1 | cut -d' ' -f1`"
1206         eval eval "flags=\\\$$2"
1207         eval eval "cxxflags=\\\$$3"
1208         eval eval "ldflags=\\\$$4"
1209         eval eval "features=\\\$$5"
1211         if [ "$compiler" = "icc" ]; then
1212                 # Enable some things only for certain ICC versions
1213                 cc_version=`$1 -dumpversion | cut -c 1-4 | sed s@\\\.@@g`
1215                 flags="$flags -rdynamic"
1216                 ldflags="$ldflags -rdynamic"
1218                 if [ -z "$first_time_icc_check" ]; then
1219                         first_time_icc_check=no
1220                         if [ $cc_version -lt 90 ]; then
1221                                 log 1 "WARNING: you seem to be using a very old version of ICC"
1222                                 log 1 "WARNING: OpenTTD hasn't been tested with this version"
1223                                 sleep 5
1224                         elif [ $cc_version -lt 120 ]; then
1225                                 log 1 "WARNING: you seem to be using an unsupported ICC version"
1226                                 log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD"
1227                                 sleep 5
1228                         fi
1229                 fi
1231                 flags="$flags -Wall"
1232                 # remark #111: statement is unreachable
1233                 flags="$flags -wd111"
1234                 # remark #181: argument is incompatible with corresponding format string conversion
1235                 # ICC is very picky about signedness of operands, warnings provided by GCC are enough
1236                 flags="$flags -wd181"
1237                 # remark #271: trailing comma is nonstandard
1238                 flags="$flags -wd271"
1239                 # remark #280: selector expression is constant
1240                 flags="$flags -wd280"
1241                 # remark #304: access control not specified ("public" by default)
1242                 flags="$flags -wd304"
1243                 # remark #383: value copied to temporary, reference to temporary used
1244                 flags="$flags -wd383"
1245                 # remark #444: destructor for base class ... is not virtual
1246                 flags="$flags -wd444"
1247                 # remark #593: variable ... was set but never used
1248                 flags="$flags -wd593"
1249                 # warning #654: overloaded virtual function ... is only partially overridden in class ...
1250                 flags="$flags -wd654"
1251                 # remark #810: conversion from ... to ... may lose significant bits
1252                 flags="$flags -wd810"
1253                 # remark #869: parameter ... was never referenced
1254                 flags="$flags -wd869"
1255                 # warning #873: function ... ::operator new ... has no corresponding operator delete ...
1256                 flags="$flags -wd873"
1257                 # remark #981: operands are evaluated in unspecified order
1258                 flags="$flags -wd981"
1259                 # remark #1418: external function definition with no prior declaration
1260                 flags="$flags -wd1418"
1261                 # remark #1419: external declaration in primary source file
1262                 flags="$flags -wd1419"
1263                 # remark #1572: floating-point equality and inequality
1264                 flags="$flags -wd1572"
1265                 # remark #1599: declaration hides variable/parameter ...
1266                 flags="$flags -wd1599"
1267                 # remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
1268                 flags="$flags -wd1720"
1270                 if [ $cc_version -lt 110 ]; then
1271                         # warns about system headers with recent glibc:
1272                         # warning #1292: attribute "__nonnull__" ignored
1273                         flags="$flags -wd1292"
1274                 fi
1276                 if [ $cc_version -ge 100 ]; then
1277                         # warning #1899: multicharacter character literal (potential portability problem)
1278                         flags="$flags -wd1899"
1279                         # vec report defaults to telling where it did loop vectorisation, which is not very important
1280                         flags="$flags -vec-report=0 "
1281                 fi
1283                 if [ $cc_version -ge 110 ]; then
1284                         # remark #2259: non-pointer conversion from ... to ... may lose significant bits
1285                         flags="$flags -wd2259"
1286                         # Use c++0x mode so static_assert() is available
1287                         cxxflags="$cxxflags -std=c++0x"
1288                 fi
1290                 if [ "$enable_lto" != "0" ]; then
1291                         has_ipo=`$1 -help ipo | grep '\-ipo'`
1292                         if [ -n "$has_ipo" ]; then
1293                                 # Use IPO (only if we see IPO exists and is requested)
1294                                 flags="$flags -ipo"
1295                                 features="$features lto"
1296                         fi
1297                 fi
1298         elif [ "$compiler" = "clang" ]; then
1299                 # Enable some things only for certain clang versions
1300                 cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
1302                 # aliasing rules are not held in openttd code
1303                 flags="$flags -fno-strict-aliasing"
1305                 # -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
1306                 # -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
1307                 flags="$flags -Wall -W -Wextra"
1309                 # warning: unused parameter '...'
1310                 flags="$flags -Wno-unused-parameter"
1312                 # warning: expression result unused
1313                 flags="$flags -Wno-unused-value"
1315                 # warning: multi-character character constant
1316                 flags="$flags -Wno-multichar"
1318                 # warning: explicitly assigning a variable of type '...' to itself
1319                 # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
1320                 flags="$flags -Wno-self-assign"
1322                 if [ "$cc_version" -lt "30" ]; then
1323                         # warning: equality comparison with extraneous parentheses
1324                         flags="$flags -Wno-parentheses"
1325                         # warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
1326                         flags="$flags -Wno-sign-compare"
1327                 fi
1329                 if [ "$cc_version" -ge "30" ]; then
1330                         # warning: equality comparison with extraneous parentheses
1331                         # this warning could be useful, but it warns about code in squirrel
1332                         flags="$flags -Wno-parentheses-equality"
1333                 fi
1335                 if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
1336                         # ccache and distcc run separate preprocess and compile passes,
1337                         # both are fed with the same CFLAGS. Unfortunately, clang
1338                         # complains about -I when compiling preprocessed files:
1339                         # "clang: warning: argument unused during compilation: '-I /usr/include'"
1340                         flags="$flags -Qunused-arguments"
1341                 fi
1343                 if [ "$enable_assert" -eq "0" ]; then
1344                         # do not warn about unused variables when building without asserts
1345                         flags="$flags -Wno-unused-variable"
1346                 fi
1348                 if [ "$cc_version" -ge "33" ]; then
1349                         # clang completed C++11 support in version 3.3
1350                         flags="$flags -std=c++11"
1351                 fi
1353                 # rdynamic is used to get useful stack traces from crash reports.
1354                 ldflags="$ldflags -rdynamic"
1356         # Assume gcc, since it just uses argv[0] in its --version output
1357         else
1358                 # Enable some things only for certain GCC versions
1359                 # cc_version = major_version * 100 + minor_version
1360                 # For example: "3.3" -> 303, "4.9.2" -> 409, "6" -> 600, "23.5" -> 2305
1361                 cc_version=`$1 -dumpversion | $awk -F . '{printf "%d%02d", $1, $2}'`
1363                 if [ $cc_version -lt 303 ]; then
1364                         log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
1365                         exit 1
1366                 fi
1368                 flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
1369                 flags="$flags -Wwrite-strings -Wpointer-arith"
1370                 flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
1371                 flags="$flags -Wformat=2 -Wformat-security"
1373                 if [ $enable_assert -eq 0 ]; then
1374                         # Do not warn about unused variables when building without asserts
1375                         flags="$flags -Wno-unused-variable"
1376                         if [ $cc_version -ge 406 ]; then
1377                                 # GCC 4.6 gives more warnings, disable them too
1378                                 flags="$flags -Wno-unused-but-set-variable"
1379                                 flags="$flags -Wno-unused-but-set-parameter"
1380                         fi
1381                 fi
1383                 if [ $cc_version -ge 304 ]; then
1384                         # Warn when a variable is used to initialise itself:
1385                         # int a = a;
1386                         flags="$flags -Winit-self"
1387                 fi
1389                 if [ $cc_version -ge 400 ]; then
1390                         # GCC 4.0+ complains about that we break strict-aliasing.
1391                         #  On most places we don't see how to fix it, and it doesn't
1392                         #  break anything. So disable strict-aliasing to make the
1393                         #  compiler all happy.
1394                         flags="$flags -fno-strict-aliasing"
1395                         # Warn about casting-out 'const' with regular C-style cast.
1396                         #  The preferred way is const_cast<>() which doesn't warn.
1397                         flags="$flags -Wcast-qual"
1398                 fi
1400                 if [ $cc_version -ge 402 ]; then
1401                         # GCC 4.2+ automatically assumes that signed overflows do
1402                         # not occur in signed arithmetics, whereas we are not
1403                         # sure that they will not happen. It furthermore complains
1404                         # about its own optimized code in some places.
1405                         flags="$flags -fno-strict-overflow"
1406                         # GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
1407                         # Enable it in order to be consistent with older GCC versions.
1408                         flags="$flags -Wnon-virtual-dtor"
1409                 fi
1411                 if [ $cc_version -ge 403 ] && [ $cc_version -lt 600 ]; then
1412                         # Use gnu++0x mode so static_assert() is available.
1413                         # Don't use c++0x, it breaks mingw (with gcc 4.4.0).
1414                         cxxflags="$cxxflags -std=gnu++0x"
1415                 fi
1417                 if [ $cc_version -eq 405 ]; then
1418                         # Prevent optimisation supposing enums are in a range specified by the standard
1419                         # For details, see http://gcc.gnu.org/PR43680
1420                         flags="$flags -fno-tree-vrp"
1421                 fi
1423                 if [ $cc_version -eq 407 ]; then
1424                         # Disable -Wnarrowing which gives many warnings, such as:
1425                         # warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
1426                         # They are valid according to the C++ standard, but useless.
1427                         cxxflags="$cxxflags -Wno-narrowing"
1428                 fi
1430                 if [ $cc_version -ge 407 ]; then
1431                         # Disable bogus 'attempt to free a non-heap object' warning
1432                         flags="$flags -Wno-free-nonheap-object"
1433                 fi
1435                 if [ $cc_version -ge 600 ]; then
1436                         # -flifetime-dse=2 (default since GCC 6) doesn't play
1437                         # well with our custom pool item allocator
1438                         cxxflags="$cxxflags -flifetime-dse=1 -std=gnu++14"
1439                 fi
1441                 if [ "$enable_lto" != "0" ]; then
1442                         # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
1443                         has_lto=`$1 -dumpspecs | grep '\%{flto'`
1444                         if [ -n "$has_lto" ]; then
1445                                 # Use LTO only if we see LTO exists and is requested
1446                                 if [ $cc_version -lt 406 ]; then
1447                                         flags="$flags -flto"
1448                                 else
1449                                         flags="$flags -flto=jobserver"
1450                                 fi
1451                                 ldflags="$ldflags -fwhole-program"
1452                                 features="$features lto"
1453                         fi
1454                 fi
1456                 has_rdynamic=`$1 -dumpspecs | grep rdynamic`
1457                 if [ -n "$has_rdynamic" ]; then
1458                         # rdynamic is used to get useful stack traces from crash reports.
1459                         flags="$flags -rdynamic"
1460                         ldflags="$ldflags -rdynamic"
1461                 fi
1462         fi
1464         eval "$2=\"$flags\""
1465         eval "$3=\"$cxxflags\""
1466         eval "$4=\"$ldflags\""
1467         eval "$5=\"$features\""
1470 make_cflags_and_ldflags() {
1471         # General CFlags for BUILD
1472         CFLAGS_BUILD_ENV="$CFLAGS_BUILD"
1473         CFLAGS_BUILD=""
1474         # Special CXXFlags for BUILD
1475         CXXFLAGS_BUILD_ENV="$CXXFLAGS_BUILD"
1476         CXXFLAGS_BUILD=""
1477         # LDFLAGS for BUILD
1478         LDFLAGS_BUILD_ENV="$LDFLAGS_BUILD"
1479         LDFLAGS_BUILD=""
1480         # FEATURES for BUILD (lto)
1481         FEATURES_BUILD=""
1482         # General CFlags for HOST
1483         CFLAGS_ENV="$CFLAGS"
1484         CFLAGS=""
1485         # Special CXXFlags for HOST
1486         CXXFLAGS_ENV="$CXXFLAGS"
1487         CXXFLAGS=""
1488         # Libs to compile. In fact this is just LDFLAGS
1489         LIBS="-lstdc++"
1490         # LDFLAGS used for HOST
1491         LDFLAGS_ENV="$LDFLAGS"
1492         LDFLAGS=""
1493         # FEATURES for HOST (lto)
1494         FEATURES=""
1496         make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "CXXFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
1497         make_compiler_cflags "$cc_host" "CFLAGS" "CXXFLAGS" "LDFLAGS" "FEATURES"
1499         CFLAGS="$CFLAGS -D$os"
1500         CFLAGS_BUILD="$CFLAGS_BUILD -D$os"
1502         if [ "$enable_debug" = "0" ]; then
1503                 # No debug, add default stuff
1504                 OBJS_SUBDIR="release"
1505                 if [ "$os" = "MORPHOS" ]; then
1506                         CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
1507                         LDFLAGS="$LDFLAGS -noixemul"
1508                 fi
1510                 if [ "$enable_profiling" = "0" ]; then
1511                         # -fomit-frame-pointer and -pg do not go well together (gcc errors they are incompatible)
1512                         CFLAGS="-fomit-frame-pointer $CFLAGS"
1513                 fi
1514                 CFLAGS="-O2 $CFLAGS"
1515         else
1516                 OBJS_SUBDIR="debug"
1518                 # Each debug level reduces the optimization by a bit
1519                 if [ $enable_debug -ge 1 ]; then
1520                         CFLAGS="$CFLAGS -g -D_DEBUG"
1521                 fi
1522                 if [ $enable_debug -ge 2 ]; then
1523                         CFLAGS="$CFLAGS -fno-inline"
1524                 fi
1525                 if [ $enable_debug -ge 3 ]; then
1526                         CFLAGS="$CFLAGS -O0"
1527                 else
1528                         CFLAGS="$CFLAGS -O2"
1529                 fi
1530         fi
1532         if [ $enable_debug -le 2 ]; then
1533                 cc_host_is_gcc=`basename "$cc_host" | grep "gcc" 2>/dev/null`
1534                 if [ -n "$cc_host_is_gcc" ]; then
1535                         # Define only when compiling with GCC. Some GLIBC versions use GNU
1536                         # extensions in a way that breaks build with at least ICC.
1537                         # This requires -O1 or more, so debug level 3 (-O0) is excluded.
1538                         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
1539                 fi
1541                 cc_build_is_gcc=`basename "$cc_build" | grep "gcc" 2>/dev/null`
1542                 if [ -n "$cc_build_is_gcc" ]; then
1543                         # Just add -O1 to the tools needed for building.
1544                         CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
1545                 fi
1546         fi
1548         if [ "$os" = "OSX" ] && [ $cc_version -eq 400 ]; then
1549                 # Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
1550                 # wrongly optimizing ^= in loops. This disables the failing optimisation.
1551                 CFLAGS="$CFLAGS -fno-expensive-optimizations"
1552         fi
1554         if [ "$enable_profiling" != "0" ]; then
1555                 CFLAGS="$CFLAGS -pg"
1556                 LDFLAGS="$LDFLAGS -pg"
1557         fi
1559         if [ "$with_threads" = "0" ]; then
1560                 CFLAGS="$CFLAGS -DNO_THREADS"
1561         fi
1562         if [ "$with_sse" = "1" ]; then
1563                 CFLAGS="$CFLAGS -DWITH_SSE"
1564         fi
1566         if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
1567                 if [ "$os" = "CYGWIN" ]; then
1568                         flags="$flags -mwin32"
1569                         LDFLAGS="$LDFLAGS -mwin32"
1570                 fi
1571                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1572                         if [ $cc_version -lt 406 ]; then
1573                                 flags="$flags -mno-cygwin"
1574                                 LDFLAGS="$LDFLAGS -mno-cygwin"
1575                         fi
1577                         if [ "$enable_console" != "0" ]; then
1578                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
1579                         else
1580                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
1581                         fi
1583                         LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
1585                         if [ $cc_version -ge 404 ]; then
1586                                 LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
1587                         fi
1588                         if [ $cc_version -ge 407 ]; then
1589                                 CFLAGS="$CFLAGS -mno-ms-bitfields"
1590                         fi
1591                 fi
1592         fi
1594         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "OS2" ]; then
1595                 LIBS="$LIBS -lpthread"
1596         fi
1598         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "MINGW" ] && [ "$os" != "DOS" ]; then
1599                 LIBS="$LIBS -lc"
1600         fi
1602         if [ "$os" = "MORPHOS" ]; then
1603                 # -Wstrict-prototypes generates much noise because of system headers
1604                 CFLAGS="$CFLAGS -Wno-strict-prototypes"
1605         fi
1607         if [ "$os" = "OPENBSD" ]; then
1608                 LIBS="$LIBS -pthread"
1609         fi
1611         if [ "$os" = "OSX" ]; then
1612                 LDFLAGS="$LDFLAGS -framework Cocoa"
1614                 # Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
1615                 CFLAGS="$CFLAGS -isystem/opt/local/include"
1617                 if [ "$enable_dedicated" = "0" ] && ([ "$cpu_type" = "32" ] || [ "$enable_universal" != "0" ]); then
1618                         LIBS="$LIBS -framework QuickTime"
1619                 else
1620                         CFLAGS="$CFLAGS -DNO_QUICKTIME"
1621                 fi
1623                 if [ "$enable_universal" = "0" ]; then
1624                         # Universal builds set this elsewhere
1625                         CFLAGS="$OSX_SYSROOT $CFLAGS"
1626                         LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
1627                 fi
1628         fi
1630         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ]; then
1631                 LIBS="$LIBS -lmidi -lbe"
1632         fi
1634         # Most targets act like UNIX, just with some additions
1635         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
1636                 CFLAGS="$CFLAGS -DUNIX"
1637         fi
1638         # And others like Windows
1639         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1640                 CFLAGS="$CFLAGS -DWIN"
1641         fi
1643         if [ -n "$allegro_config" ]; then
1644                 CFLAGS="$CFLAGS -DWITH_ALLEGRO"
1645                 CFLAGS="$CFLAGS `$allegro_config --cflags`"
1646                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
1647                         if [ "$enable_static" != "0" ]; then
1648                                 LIBS="$LIBS `$allegro_config --static --libs`"
1649                         else
1650                                 LIBS="$LIBS `$allegro_config --libs`"
1651                         fi
1652                 fi
1653         fi
1655         if [ -n "$sdl_config" ]; then
1656                 CFLAGS="$CFLAGS -DWITH_SDL"
1657                 # SDL must not add _GNU_SOURCE as it breaks many platforms
1658                 CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
1659                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
1660                         if [ "$enable_static" != "0" ]; then
1661                                 LIBS="$LIBS `$sdl_config --static-libs`"
1662                         else
1663                                 LIBS="$LIBS `$sdl_config --libs`"
1664                         fi
1665                 fi
1666         fi
1668         if [ "$with_cocoa" != "0" ]; then
1669                 CFLAGS="$CFLAGS -DWITH_COCOA"
1670                 LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox"
1672                 if [ "$enable_cocoa_quartz" != "0" ]; then
1673                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUARTZ"
1674                 fi
1676                 if [ "$enable_cocoa_quickdraw" != "0" ]; then
1677                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUICKDRAW"
1678                 fi
1679         fi
1681         if [ "$with_zlib" != "0" ]; then
1682                 CFLAGS="$CFLAGS -DWITH_ZLIB"
1683                 CFLAGS="$CFLAGS `$zlib_config --cflags | tr '\n\r' '  '`"
1684                 if [ "$enable_static" != "0" ]; then
1685                         LIBS="$LIBS `$zlib_config --libs --static | tr '\n\r' '  '`"
1686                 else
1687                         LIBS="$LIBS `$zlib_config --libs | tr '\n\r' '  '`"
1688                 fi
1689         fi
1691         if [ -n "$lzma_config" ]; then
1692                 CFLAGS="$CFLAGS -DWITH_LZMA"
1693                 CFLAGS="$CFLAGS `$lzma_config --cflags | tr '\n\r' '  '`"
1695                 if [ "$enable_static" != "0" ]; then
1696                         CFLAGS="$CFLAGS -DLZMA_API_STATIC"
1697                         LIBS="$LIBS `$lzma_config --libs --static | tr '\n\r' '  '`"
1698                 else
1699                         LIBS="$LIBS `$lzma_config --libs | tr '\n\r' '  '`"
1700                 fi
1701         fi
1703         if [ "$with_lzo2" != "0" ]; then
1704                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1705                         LIBS="$LIBS $lzo2"
1706                 else
1707                         LIBS="$LIBS -llzo2"
1708                 fi
1709                 CFLAGS="$CFLAGS -DWITH_LZO"
1710         fi
1712         if [ -n "$xdg_basedir_config" ]; then
1713                 CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
1714                 CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
1716                 if [ "$enable_static" != "0" ]; then
1717                         LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
1718                 else
1719                         LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
1720                 fi
1721         fi
1723         # 64bit machines need -D_SQ64
1724         if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
1725                 CFLAGS="$CFLAGS -D_SQ64"
1726         fi
1727         CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
1729         if [ -n "$png_config" ]; then
1730                 CFLAGS="$CFLAGS -DWITH_PNG"
1731                 CFLAGS="$CFLAGS `$png_config --cflags | tr '\n\r' '  '`"
1733                 if [ "$enable_static" != "0" ]; then
1734                         LIBS="$LIBS `$png_config --libs --static | tr '\n\r' '  '`"
1735                 else
1736                         LIBS="$LIBS `$png_config --libs | tr '\n\r' '  '`"
1737                 fi
1738         fi
1740         if [ -n "$fontconfig_config" ]; then
1741                 CFLAGS="$CFLAGS -DWITH_FONTCONFIG"
1742                 CFLAGS="$CFLAGS `$fontconfig_config --cflags | tr '\n\r' '  '`"
1744                 if [ "$enable_static" != "0" ]; then
1745                         LIBS="$LIBS `$fontconfig_config --libs --static | tr '\n\r' '  '`"
1746                 else
1747                         LIBS="$LIBS `$fontconfig_config --libs | tr '\n\r' '  '`"
1748                 fi
1749         fi
1751         if [ -n "$freetype_config" ]; then
1752                 CFLAGS="$CFLAGS -DWITH_FREETYPE"
1753                 CFLAGS="$CFLAGS `$freetype_config --cflags | tr '\n\r' '  '`"
1755                 if [ "$enable_static" != "0" ]; then
1756                         LIBS="$LIBS `$freetype_config --libs --static | tr '\n\r' '  '`"
1757                 else
1758                         LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1759                 fi
1760         fi
1762         if [ -n "$icu_layout_config" ]; then
1763                 CFLAGS="$CFLAGS -DWITH_ICU_LAYOUT"
1764                 CFLAGS="$CFLAGS `$icu_layout_config --cflags | tr '\n\r' '  '`"
1766                 if [ "$static_icu" != "0" ]; then
1767                         LIBS="$LIBS `$icu_layout_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1768                 else
1769                         LIBS="$LIBS `$icu_layout_config --libs | tr '\n\r' '  '`"
1770                 fi
1771         fi
1773         if [ -n "$icu_sort_config" ]; then
1774                 CFLAGS="$CFLAGS -DWITH_ICU_SORT"
1775                 CFLAGS="$CFLAGS `$icu_sort_config --cflags | tr '\n\r' '  '`"
1777                 if [ "$static_icu" != "0" ]; then
1778                         LIBS="$LIBS `$icu_sort_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1779                 else
1780                         LIBS="$LIBS `$icu_sort_config --libs | tr '\n\r' '  '`"
1781                 fi
1782         fi
1785         if [ "$with_direct_music" != "0" ]; then
1786                 CFLAGS="$CFLAGS -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT"
1787                 # GCC 4.0+ doesn't like the DirectX includes (gives tons of
1788                 #  warnings on it we won't be able to fix). For now just
1789                 #  suppress those warnings.
1790                 if [ $cc_version -ge 400 ]; then
1791                         CFLAGS="$CFLAGS -Wno-non-virtual-dtor"
1792                 fi
1793         fi
1795         if [ "$with_xaudio2" != "0" ]; then
1796                 CFLAGS="$CFLAGS -DWITH_XAUDIO2"
1797         fi
1799         if [ -n "$libtimidity_config" ]; then
1800                 CFLAGS="$CFLAGS -DLIBTIMIDITY"
1801                 CFLAGS="$CFLAGS `$libtimidity_config --cflags | tr '\n\r' '  '`"
1803                 if [ "$enable_static" != "0" ]; then
1804                         LIBS="$LIBS `$libtimidity_config --libs --static | tr '\n\r' '  '`"
1805                 else
1806                         LIBS="$LIBS `$libtimidity_config --libs | tr '\n\r' '  '`"
1807                 fi
1808         fi
1810         if [ "$with_iconv" != "0" ]; then
1811                 CFLAGS="$CFLAGS -DWITH_ICONV"
1812                 if [ "$link_to_iconv" = "yes" ]; then
1813                         LIBS="$LIBS -liconv"
1814                         if [ "$with_iconv" != "2" ]; then
1815                                 CFLAGS="$CFLAGS -I$with_iconv/include"
1816                                 LIBS="$LIBS -L$with_iconv/lib"
1817                         fi
1818                 fi
1820                 if [ "$os" != "OSX" ] && [ "$have_non_const_iconv" != "no" ]; then
1821                         CFLAGS="$CFLAGS -DHAVE_NON_CONST_ICONV"
1822                 fi
1823         fi
1825         if [ -n "$with_midi" ]; then
1826                 CFLAGS="$CFLAGS -DEXTERNAL_PLAYER=\\\\\"$with_midi\\\\\""
1827         fi
1828         if [ -n "$with_midi_arg" ]; then
1829                 CFLAGS="$CFLAGS -DMIDI_ARG=\\\\\"$with_midi_arg\\\\\""
1830         fi
1832         if [ "$enable_dedicated" != "0" ]; then
1833                 CFLAGS="$CFLAGS -DDEDICATED"
1834         fi
1836         if [ "$enable_unicode" != "0" ]; then
1837                 CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
1838         fi
1840         if [ "$enable_network" != "0" ]; then
1841                 CFLAGS="$CFLAGS -DENABLE_NETWORK"
1843                 if [ "$os" = "BEOS" ]; then
1844                         LDFLAGS="$LDFLAGS -lbind -lsocket"
1845                 fi
1847                 if [ "$os" = "HAIKU" ]; then
1848                         LDFLAGS="$LDFLAGS -lnetwork"
1849                 fi
1851                 if [ "$os" = "SUNOS" ]; then
1852                         LDFLAGS="$LDFLAGS -lnsl -lsocket"
1853                 fi
1854         fi
1856         if [ "$enable_static" != "0" ]; then
1857                 # OSX can't handle -static in LDFLAGS
1858                 if [ "$os" != "OSX" ]; then
1859                         LDFLAGS="$LDFLAGS -static"
1860                 fi
1861         fi
1863         if [ "$enable_assert" = "0" ]; then
1864                 CFLAGS="$CFLAGS -DNDEBUG"
1865                 CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
1866         fi
1868         if [ "$enable_desync_debug" != "0" ]; then
1869                 CFLAGS="$CFLAGS -DRANDOM_DEBUG"
1870         fi
1872         if [ "$enable_osx_g5" != "0" ]; then
1873                 CFLAGS="$CFLAGS -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
1874         fi
1876         if [ -n "$personal_dir" ]; then
1877                 CFLAGS="$CFLAGS -DWITH_PERSONAL_DIR -DPERSONAL_DIR=\\\\\"$personal_dir\\\\\""
1878         fi
1880         if [ -n "$shared_dir" ]; then
1881                 CFLAGS="$CFLAGS -DWITH_SHARED_DIR -DSHARED_DIR=\\\\\"$shared_dir\\\\\""
1882         fi
1884         CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
1886         if [ "$enable_lto" != "0" ]; then
1887                 lto_build=`echo "$FEATURES_BUILD" | grep "lto"`
1888                 lto_host=`echo "$FEATURES" | grep "lto"`
1889                 if [ -z "$lto_build$lto_host" ]; then
1890                         log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
1891                         log 1 "WARNING: LTO/IPO has been disabled"
1892                 fi
1893                 if [ -n "$lto_build" ]; then
1894                         LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
1895                 fi
1896                 if [ -n "$lto_host" ]; then
1897                         LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
1898                 fi
1899         fi
1901         # All flags to be extended via the env
1902         CFLAGS_BUILD="$CFLAGS_BUILD $CFLAGS_BUILD_ENV"
1903         CXXFLAGS_BUILD="$CXXFLAGS_BUILD $CXXFLAGS_BUILD_ENV"
1904         LDFLAGS_BUILD="$LDFLAGS_BUILD $LDFLAGS_BUILD_ENV"
1905         CFLAGS="$CFLAGS $CFLAGS_ENV"
1906         CXXFLAGS="$CXXFLAGS $CXXFLAGS_ENV"
1907         LDFLAGS="$LDFLAGS $LDFLAGS_ENV"
1909         log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD"
1910         log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD"
1911         log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD"
1912         log 1 "using CFLAGS... $CFLAGS"
1913         log 1 "using CXXFLAGS... $CXXFLAGS"
1914         log 1 "using LDFLAGS... $LIBS $LDFLAGS"
1916         # Makedepend doesn't like something like: -isysroot /OSX/blabla
1917         #  so convert it to: -isysroot -OSX/blabla. makedepend just ignores
1918         #  any - command it doesn't know, so we are pretty save.
1919         # Lovely hackish, not?
1920         # Btw, this almost always comes from outside the configure, so it is
1921         #  not something we can control.
1922         # Also make makedepend aware of compiler's built-in defines.
1923         if [ "$with_makedepend" != "0" ] || [ "$enable_builtin_depend" != "0" ]; then
1924                 # Append CXXFLAGS possibly containing -std=c++0x
1925                 cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
1927                 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
1928                 cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
1929         else
1930                 makedepend=""
1931         fi
1933         if [ "$with_distcc" != "0" ]; then
1934                 cc_host="$distcc $cc_host"
1935                 cxx_host="$distcc $cxx_host"
1936                 log 1 ""
1937                 log 1 " NOTICE: remind yourself to use 'make -jN' to make use of distcc"
1938                 log 1 ""
1939         fi
1941         if [ "$with_ccache" != "0" ]; then
1942                 cc_host="$ccache $cc_host"
1943                 cxx_host="$ccache $cxx_host"
1944         fi
1947 check_compiler() {
1948         # Params:
1949         # $1 - Type for message (build / host)
1950         # $2 - What to fill with the found compiler
1951         # $3 - System to try
1952         # $4 - Compiler to try
1953         # $5 - Env-setting to try
1954         # $6 - GCC alike to try
1955         # $7 - CC alike to try
1956         # $8 - "0" gcc, "1" g++, "2" windres, "3" strip, "4" lipo
1957         # $9 - What the command is to check for
1959         if [ -n "$4" ]; then
1960                 # Check for manual compiler
1961                 machine=`$4 $9 2>/dev/null`
1962                 ret=$?
1963                 eval "$2=\"$4\""
1965                 log 2 "executing $4 $9"
1966                 log 2 "  returned $machine"
1967                 log 2 "  exit code $ret"
1969                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1970                         log 1 "checking $1... $4 not found"
1971                         log 1 "the selected binary doesn't seem to be a $6 binary"
1972                         exit 1
1973                 fi
1974         elif [ -n "$3" ]; then
1975                 # Check for system
1976                 if [ -z "$6" ]; then
1977                         compiler="$3"
1978                 else
1979                         compiler="$3-$6"
1980                 fi
1981                 machine=`eval $compiler $9 2>/dev/null`
1982                 ret=$?
1983                 eval "$2=\"$compiler\""
1985                 log 2 "executing $compiler $9"
1986                 log 2 "  returned $machine"
1987                 log 2 "  exit code $ret"
1989                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1990                         if [ -z "$5" ]; then
1991                                 log 1 "checking $1... $compiler not found"
1992                                 log 1 "I couldn't detect any $6 binary for $3"
1993                                 exit 1
1994                         else
1995                                 compiler="$3-$5"
1996                         fi
1997                         machine=`eval $compiler $9 2>/dev/null`
1998                         ret=$?
1999                         eval "$2=\"$compiler\""
2001                         log 2 "executing $compiler $9"
2002                         log 2 "  returned $machine"
2003                         log 2 "  exit code $ret"
2005                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2006                                 log 1 "checking $1... $compiler not found"
2007                                 log 1 "I couldn't detect any $5 binary for $3"
2008                                 exit 1
2009                         fi
2010                 fi
2012                 if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
2013                         log 1 "checking $1... expected $3, found $machine"
2014                         log 1 "the compiler suggests it doesn't build code for the machine you specified"
2015                         exit 1
2016                 fi
2017         else
2018                 # Nothing given, autodetect
2020                 if [ -n "$5" ]; then
2021                         machine=`$5 $9 2>/dev/null`
2022                         ret=$?
2023                         eval "$2=\"$5\""
2025                         log 2 "executing $5 $9"
2026                         log 2 "  returned $machine"
2027                         log 2 "  exit code $ret"
2029                         # The user defined a GCC that doesn't reply to $9.. abort
2030                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2031                                 log 1 "checking $1... $5 unusable"
2032                                 log 1 "the CC environment variable is set, but it doesn't seem to be a $6 binary"
2033                                 log 1 "please redefine the CC/CXX environment to a $6 binary"
2034                                 exit 1
2035                         fi
2036                 else
2037                         log 2 "checking $1... CC/CXX not set (skipping)"
2039                         # No $5, so try '$6'
2040                         machine=`$6 $9 2>/dev/null`
2041                         ret=$?
2042                         eval "$2=\"$6\""
2044                         log 2 "executing $6 $9"
2045                         log 2 "  returned $machine"
2046                         log 2 "  exit code $ret"
2048                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2049                                 # Maybe '$7'?
2050                                 machine=`$7 $9 2>/dev/null`
2051                                 ret=$?
2052                                 eval "$2=\"$7\""
2054                                 log 2 "executing $7 $9"
2055                                 log 2 "  returned $machine"
2056                                 log 2 "  exit code $ret"
2058                                 # All failed, abort
2059                                 if [ -z "$machine" ]; then
2060                                         log 1 "checking $1... $6 not found"
2061                                         log 1 "I couldn't detect any $6 binary on your system"
2062                                         log 1 "please define the CC/CXX environment to where it is located"
2064                                         exit 1
2065                                 fi
2066                         fi
2067                 fi
2068         fi
2070         if [ "$8" != "0" ]; then
2071                 eval "res=\$$2"
2072                 log 1 "checking $1... $res"
2073         else
2074                 log 1 "checking $1... $machine"
2075         fi
2078 check_build() {
2079         check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CC" "gcc" "cc" "0" "-dumpmachine"
2082 check_host() {
2083         # By default the host is the build
2084         if [ -z "$host" ]; then host="$build"; fi
2085         check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
2088 check_cxx_build() {
2089         check_compiler "build c++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
2092 check_cxx_host() {
2093         # By default the host is the build
2094         if [ -z "$host" ]; then host="$build"; fi
2095         check_compiler "host c++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
2098 check_windres() {
2099         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
2100                 check_compiler "host windres" "windres" "$host" "$windres" "$WINDRES" "windres" "windres" "2" "-V"
2101         fi
2104 check_strip() {
2105         if [ "$os" = "OS2" ]; then
2106                 # OS2 via gcc is a bit weird.. stripping HAS to be done via emxbind, which is via gcc directly
2107                 log 1 "checking host strip... using gcc -s option"
2108         elif [ "$os" = "OSX" ]; then
2109                 # Most targets have -V in strip, to see if they exists... OSX doesn't.. so execute something
2110                 echo "int main(int argc, char *argv[]) { }" > strip.test.c
2111                 $cxx_host strip.test.c -o strip.test
2112                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "strip.test"
2113                 rm -f strip.test.c strip.test
2114         else
2115                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "-V"
2116         fi
2119 check_lipo() {
2120         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
2121                 echo "int main(int argc, char *argv[]) { }" > lipo.test.c
2122                 $cxx_host lipo.test.c -o lipo.test
2123                 check_compiler "host lipo" "lipo" "$host" "$lipo" "$LIPO" "lipo" "lipo" "4" "-info lipo.test"
2124                 rm -f lipo.test.c lipo.test
2125         fi
2128 check_osx_sdk() {
2129         local sysroot=""
2130         if [ -n "$1" ]; then
2131                 if echo "$1" | grep -q / ; then
2132                         # Seems to be a file system path
2133                         osx_sdk_path="$1"
2134                 else
2135                         osx_sdk_path="/Developer/SDKs/MacOSX$1.sdk"
2136                 fi
2137                 if [ ! -d "$osx_sdk_path" ]; then
2138                         # No directory, not present or garbage
2139                         return 1
2140                 fi
2142                 # Set minimum version to 10.4 as that's when kCGBitmapByteOrder32Host was introduced
2143                 sysroot="-isysroot $osx_sdk_path -Wl,-syslibroot,$osx_sdk_path -mmacosx-version-min=10.4"
2144         fi
2146 cat > tmp.osx.mm << EOF
2147 #include <Cocoa/Cocoa.h>
2148 int main() {
2149         kCGBitmapByteOrder32Host;
2150         return 0;
2153         execute="$cxx_host $sysroot $CFLAGS tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2154         eval $execute > /dev/null
2155         ret=$?
2156         log 2 "executing $execute"
2157         log 2 "  exit code $ret"
2158         rm -f tmp.osx.mm tmp.osx
2159         return $ret
2162 check_direct_music() {
2163         echo "
2164                 #include <windows.h>
2165                 #include <dmksctrl.h>
2166                 #include <dmusici.h>
2167                 #include <dmusicc.h>
2168                 #include <dmusicf.h>
2169                 int main(int argc, char *argv[]) { }" > direct_music.test.c
2170         $cxx_host $CFLAGS direct_music.test.c -o direct_music.test 2> /dev/null
2171         res=$?
2172         rm -f direct_music.test.c direct_music.test
2174         if [ "$res" != "0" ]; then
2175                 if [ "$with_direct_music" != "1" ]; then
2176                         log 1 "configure: error: direct-music is not available on this system"
2177                         exit 1
2178                 fi
2179                 with_direct_music="0"
2181                 log 1 "checking direct-music... not found"
2182         else
2183                 log 1 "checking direct-music... found"
2184         fi
2187 check_xaudio2() {
2188         echo "
2189                 #include <windows.h>
2191                 #undef NTDDI_VERSION
2192                 #undef _WIN32_WINNT
2194                 #define NTDDI_VERSION    NTDDI_WIN8
2195                 #define _WIN32_WINNT     _WIN32_WINNT_WIN8
2197                 #include <xaudio2.h>
2198                 int main(int argc, char *argv[]) { }" > xaudio2.test.c
2199         $cxx_host $CFLAGS xaudio2.test.c -o xaudio2.test 2> /dev/null
2200         res=$?
2201         rm -f xaudio2.test.c xaudio2.test
2203         if [ "$res" != "0" ]; then
2204                 if [ "$with_xaudio2" != "1" ]; then
2205                         log 1 "configure: error: xaudio2 is not available on this system"
2206                         exit 1
2207                 fi
2208                 with_xaudio2="0"
2210                 log 1 "checking xaudio2... not found"
2211         else
2212                 log 1 "checking xaudio2... found"
2213         fi
2216 check_makedepend() {
2217         if [ "$enable_builtin_depend" != "0" ]; then
2218                 with_makedepend="0"
2219         fi
2221         if [ "$with_makedepend" = "0" ]; then
2222                 log 1 "checking makedepend... disabled"
2223                 return
2224         fi
2226         if [ "$with_makedepend" = "1" ] || [ "$with_makedepend" = "2" ]; then
2227                 makedepend="makedepend"
2228         else
2229                 makedepend="$with_makedepend"
2230         fi
2232         rm -f makedepend.tmp
2233         touch makedepend.tmp
2234         res=`$makedepend -fmakedepend.tmp 2>/dev/null`
2235         res=$?
2236         log 2 "executing $makedepend -f makedepend.tmp"
2237         log 2 "  returned `cat makedepend.tmp`"
2238         log 2 "  exit code $ret"
2240         if [ ! -s makedepend.tmp ]; then
2241                 rm -f makedepend.tmp makedepend.tmp.bak
2243                 if [ "$with_makedepend" = "2" ]; then
2244                         log 1 "checking makedepend... not found"
2246                         log 1 "I couldn't detect any makedepend on your system"
2247                         log 1 "please locate it via --makedepend=[binary]"
2249                         exit 1
2250                 elif [ "$with_makedepend" != "1" ]; then
2251                         log 1 "checking makedepend... $makedepend not found"
2253                         log 1 "the selected file doesn't seem to be a valid makedepend binary"
2255                         exit 1
2256                 else
2257                         log 1 "checking makedepend... not found"
2259                         with_makedepend="0"
2260                         return
2261                 fi
2262         fi
2264         rm -f makedepend.tmp makedepend.tmp.bak
2266         log 1 "checking makedepend... $makedepend"
2269 check_version() {
2270         # $1 - requested version (major.minor)
2271         # $2 - version we got (major.minor)
2273         if [ -z "$2" ]; then
2274                 return 0
2275         fi
2277         req_major=`echo $1 | cut -d. -f1`
2278         got_major=`echo $2 | cut -d. -f1`
2279         if [ $got_major -lt $req_major ]; then
2280                 return 0
2281         elif [ $got_major -gt $req_major ]; then
2282                 return 1
2283         fi
2285         req_minor=`echo $1 | cut -d. -f2`
2286         got_minor=`echo $2 | cut -d. -f2`
2287         if [ $got_minor -lt $req_minor ]; then
2288                 return 0
2289         fi
2290         return 1
2293 detect_awk() {
2294         # Not all awks allow gsub(), so we test for that here! It is in fact all we need...
2296         # These awks are known to work. Test for them explicit
2297         awks="gawk mawk nawk"
2299         awk_prefix="echo \"a.c b.c c.c\" | tr ' ' \\\\n | "
2300         awk_param="' { ORS = \" \" } /\.c$/   { gsub(\".c$\",   \".o\", \$0); print \$0; }' 2>/dev/null"
2301         awk_result="a.o b.o c.o "
2302         log 2 "Detecing awk..."
2304         log 2 "Trying: $awk_prefix $awk $awk_param"
2305         res=`eval $awk_prefix $awk $awk_param`
2306         log 2 "Result: '$res'"
2307         if [ "$res" != "$awk_result" ] && [ "$awk" = "awk" ]; then
2308                 # User didn't supply his own awk, so try to detect some other known working names for an awk
2309                 for awk in $awks; do
2310                         log 2 "Trying: $awk_prefix $awk $awk_param"
2311                         res=`eval $awk_prefix $awk $awk_param`
2312                         log 2 "Result: '$res'"
2313                         if [ "$res" = "$awk_result" ]; then break; fi
2314                 done
2316                 if [ "$res" != "$awk_result" ]; then
2317                         log 1 "checking awk... not found"
2318                         log 1 "configure: error: no awk found"
2319                         log 1 "configure: error: please install one of the following: $awks"
2320                         exit 1
2321                 fi
2322         fi
2323         if [ "$res" != "$awk_result" ]; then
2324                 log 1 "checking awk... not found"
2325                 log 1 "configure: error: you supplied '$awk' but it doesn't seem a valid gawk or mawk"
2326                 exit 1
2327         fi
2329         log 1 "checking awk... $awk"
2332 detect_os() {
2333         if [ "$os" = "DETECT" ]; then
2334                 # Detect UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, HPUX, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, and DOS
2336                 # Try first via dumpmachine, then via uname
2337                 os=`echo "$host" | tr '[A-Z]' '[a-z]' | $awk '
2338                                         /linux/        { print "UNIX";      exit}
2339                                         /darwin/       { print "OSX";       exit}
2340                                         /freebsd/      { print "FREEBSD";   exit}
2341                                         /dragonfly/    { print "DRAGONFLY"; exit}
2342                                         /openbsd/      { print "OPENBSD";   exit}
2343                                         /netbsd/       { print "NETBSD";    exit}
2344                                         /hp-ux/        { print "HPUX";      exit}
2345                                         /morphos/      { print "MORPHOS";   exit}
2346                                         /beos/         { print "BEOS";      exit}
2347                                         /haiku/        { print "HAIKU";     exit}
2348                                         /sunos/        { print "SUNOS";     exit}
2349                                         /solaris/      { print "SUNOS";     exit}
2350                                         /cygwin/       { print "CYGWIN";    exit}
2351                                         /mingw/        { print "MINGW";     exit}
2352                                         /os2/          { print "OS2";       exit}
2353                                         /dos/          { print "DOS";       exit}
2354                 '`
2356                 if [ -z "$os" ]; then
2357                         os=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | $awk '
2358                                         /linux/        { print "UNIX";      exit}
2359                                         /darwin/       { print "OSX";       exit}
2360                                         /freebsd/      { print "FREEBSD";   exit}
2361                                         /dragonfly/    { print "DRAGONFLY"; exit}
2362                                         /openbsd/      { print "OPENBSD";   exit}
2363                                         /netbsd/       { print "NETBSD";    exit}
2364                                         /hp-ux/        { print "HPUX";      exit}
2365                                         /morphos/      { print "MORPHOS";   exit}
2366                                         /beos/         { print "BEOS";      exit}
2367                                         /haiku/        { print "HAIKU";     exit}
2368                                         /sunos/        { print "SUNOS";     exit}
2369                                         /cygwin/       { print "CYGWIN";    exit}
2370                                         /mingw/        { print "MINGW";     exit}
2371                                         /os\/2/        { print "OS2";       exit}
2372                                         /gnu/          { print "UNIX";      exit}
2373                         '`
2374                 fi
2376                 if [ -z "$os" ]; then
2377                         log 1 "detecting OS... none detected"
2378                         log 1 "I couldn't detect your OS. Please use --os=OS to force one"
2379                         log 1 "Allowed values are: UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, and DOS"
2380                         exit 1
2381                 fi
2383                 log 1 "detecting OS... $os"
2384         else
2385                 log 1 "forcing OS... $os"
2386         fi
2389 detect_allegro() {
2390         # 0 means no, 1 is auto-detect, 2 is force
2391         if [ "$with_allegro" = "0" ]; then
2392                 log 1 "checking Allegro... disabled"
2394                 allegro_config=""
2395                 return 0
2396         fi
2398         if [ "$with_allegro" = "2" ] && [ "$with_cocoa" = "2" ]; then
2399                 log 1 "configure: error: it is impossible to compile both Allegro and COCOA"
2400                 log 1 "configure: error: please deselect one of them and try again"
2401                 exit 1
2402         fi
2404         if [ "$with_allegro" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2405                 log 1 "configure: error: it is impossible to compile a dedicated with Allegro"
2406                 log 1 "configure: error: please deselect one of them and try again"
2407                 exit 1
2408         fi
2410         if [ "$enable_dedicated" != "0" ]; then
2411                 log 1 "checking Allegro... dedicated server, skipping"
2413                 allegro_config=""
2414                 return 0
2415         fi
2417         # By default on OSX we don't use Allegro. The rest is auto-detect
2418         if [ "$with_allegro" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2419                 log 1 "checking Allegro... OSX, skipping"
2421                 allegro_config=""
2422                 return 0
2423         fi
2425         detect_pkg_config "$with_allegro" "allegro" "allegro_config" "4.4"
2429 detect_sdl() {
2430         # 0 means no, 1 is auto-detect, 2 is force
2431         if [ "$with_sdl" = "0" ]; then
2432                 log 1 "checking SDL... disabled"
2434                 sdl_config=""
2435                 return 0
2436         fi
2438         if [ "$with_sdl" = "2" ] && [ "$with_cocoa" = "2" ]; then
2439                 log 1 "configure: error: it is impossible to compile both SDL and COCOA"
2440                 log 1 "configure: error: please deselect one of them and try again"
2441                 exit 1
2442         fi
2444         if [ "$with_sdl" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2445                 log 1 "configure: error: it is impossible to compile a dedicated with SDL"
2446                 log 1 "configure: error: please deselect one of them and try again"
2447                 exit 1
2448         fi
2450         if [ "$enable_dedicated" != "0" ]; then
2451                 log 1 "checking SDL... dedicated server, skipping"
2453                 sdl_config=""
2454                 return 0
2455         fi
2457         # By default on OSX we don't use SDL. The rest is auto-detect
2458         if [ "$with_sdl" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2459                 log 1 "checking SDL... OSX, skipping"
2461                 sdl_config=""
2462                 return 0
2463         fi
2465         if [ "$os" = "OSX" ]; then
2466                 log 1 "WARNING: sdl is known to fail on some versions of Mac OS X"
2467                 log 1 "WARNING: with some hardware configurations. Use at own risk!"
2468                 sleep 5
2469         fi
2471         detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2"
2474 detect_osx_sdk() {
2475         # Try to find the best SDK available. For a normal build this
2476         # is currently the 10.5 SDK as this is needed to compile all
2477         # optional code. Because such an executable won't run on 10.4
2478         # or lower, also check for the 10.4u SDK when doing an universal
2479         # build.
2481         # Check for the 10.5 SDK, but try 10.6 if that fails
2482         check_osx_sdk "10.5" || check_osx_sdk "10.6" || osx_sdk_path=""
2484         if [ -z "$osx_sdk_path" ] || [ "$enable_universal" != "0" ]; then
2485                 # No better SDK or universal build enabled? Check 10.4u SDK as well
2486                 local old_sdk="$osx_sdk_path"
2487                 if check_osx_sdk "10.4u"; then
2488                         osx_sdk_104_path="$osx_sdk_path"
2489                 else
2490                         osx_sdk_104_path=""
2491                 fi
2492                 if [ -z "$old_sdk" ]; then
2493                         osx_sdk_path="$osx_sdk_104_path"
2494                 else
2495                         osx_sdk_path="$old_sdk"
2496                 fi
2497         fi
2499         if [ -z "$osx_sdk_path" ]; then
2500                 log 1 "Your system SDK is probably too old"
2501                 log 1 "Please install/upgrade your Xcode to >= 2.5"
2503                 exit 1
2504         fi
2507 detect_cocoa() {
2508         # 0 means no, 1 is auto-detect, 2 is force
2509         if [ "$with_cocoa" = "0" ]; then
2510                 log 1 "checking COCOA... disabled"
2512                 return 0
2513         fi
2515         if [ "$with_cocoa" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2516                 log 1 "configure: error: it is impossible to compile a dedicated with COCOA"
2517                 log 1 "configure: error: please deselect one of them and try again"
2518                 exit 1
2519         fi
2521         if [ "$enable_dedicated" != "0" ]; then
2522                 log 1 "checking COCOA... dedicated server, skipping"
2524                 with_cocoa="0"
2525                 return 0
2526         fi
2528         # By default on OSX we use COCOA. The rest doesn't support it
2529         if [ "$with_cocoa" = "1" ] && [ "$os" != "OSX" ]; then
2530                 log 1 "checking COCOA... not OSX, skipping"
2532                 with_cocoa="0"
2533                 return 0
2534         fi
2536         if [ "$os" != "OSX" ]; then
2537                 log 1 "checking COCOA... not OSX"
2539                 log 1 "configure: error: COCOA video driver is only supported for OSX"
2540                 exit 1
2541         fi
2543         log 1 "checking COCOA... found"
2546         if [ "$enable_cocoa_quartz" != "0" ]; then
2547                 log 1 "checking whether to enable the Quartz window subdriver... yes"
2548         else
2549                 log 1 "checking whether to enable the Quartz window subdriver... no"
2550         fi
2552         detect_quickdraw
2555 detect_quickdraw() {
2556         # 0 means no, 1 is auto-detect, 2 is force
2557         if [ "$enable_cocoa_quickdraw" = "0" ]; then
2558                 log 1 "checking Quickdraw window subdriver... disabled"
2559                 return 0
2560         fi
2562         # Assume QuickDraw is available when doing an universal build
2563         if [ "$enable_universal" != "0" ]; then
2564                 log 1 "checking Quickdraw window subdriver... found"
2565                 return 0
2566         fi
2568         # 64 bits doesn't have quickdraw
2569         if [ "$cpu_type" = "64" ]; then
2570                 enable_cocoa_quickdraw="0"
2571                 log 1 "checking Quickdraw window subdriver... disabled (64 bits)"
2572                 return 0
2573         fi
2575 cat > tmp.osx.mm << EOF
2576 #include <AvailabilityMacros.h>
2577 #import <Cocoa/Cocoa.h>
2578 int main(int argc, char *argv[]) { SetEmptyRgn(NULL); return 0; }
2580         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS -mmacosx-version-min=10.3 tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2581         eval $execute > /dev/null
2582         ret=$?
2583         log 2 "executing $execute"
2584         log 2 "  exit code $ret"
2585         rm -f tmp.osx.mm tmp.osx
2586         if [ "$ret" != "0" ]; then
2587                 log 1 "checking Quickdraw window subdriver... not found"
2589                 # It was forced, so it should be found.
2590                 if [ "$enable_cocoa_quickdraw" != "1" ]; then
2591                         log 1 "configure: error: Quickdraw window driver could not be found"
2592                         exit 1
2593                 fi
2595                 enable_cocoa_quickdraw=0
2596                 return 0
2597         fi
2599         enable_cocoa_quickdraw=1
2600         log 1 "checking Quickdraw window subdriver... found"
2603 detect_library() {
2604         # $1 - config-param ($with_zlib value)
2605         # $2 - library name ('zlib', sets $zlib)
2606         # $3 - static library name (libz.a)
2607         # $4 - header directory ()
2608         # $5 - header name (zlib.h)
2609         # $6 - force static (if non-empty)
2611         if [ -n "$6" ]; then force_static="1"; fi
2613         # 0 means no, 1 is auto-detect, 2 is force
2614         if [ "$1" = "0" ]; then
2615                 log 1 "checking $2... disabled"
2617                 eval "$2=\"\""
2618                 return 0
2619         fi
2621         log 2 "detecting $2"
2623         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2624                 eval "$2=`ls -1 /usr/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2625                 eval "res=\$$2"
2626                 if [ -z "$res" ]; then
2627                         log 2 "  trying /usr/include/$4$5... no"
2628                         eval "$2=`ls -1 /usr/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2629                 fi
2630                 eval "res=\$$2"
2631                 if [ -z "$res" ]; then
2632                         log 2 "  trying /usr/local/include/$4$5... no"
2633                         eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2634                 fi
2635                 eval "res=\$$2"
2636                 if [ -z "$res" ]; then
2637                         log 2 "  trying /mingw/include/$4$5... no"
2638                         eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2639                 fi
2640                 eval "res=\$$2"
2641                 if [ -z "$res" ]; then
2642                         log 2 "  trying /opt/local/include/$4$5... no"
2643                 fi
2644                 if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then
2645                         eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2646                         eval "res=\$$2"
2647                         if [ -z "$res" ]; then
2648                                 log 2 "  trying /usr/pkg/include/$4$5... no"
2649                         fi
2650                 fi
2651                 if [ -z "$res" ] && [ "$os" = "HAIKU" ]; then
2652                         if [ -z "$includeDir" ]; then
2653                                 includeDir=`finddir B_SYSTEM_HEADERS_DIRECTORY`
2654                         fi
2655                         eval "$2=`ls -1 $includeDir/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2656                         eval "res=\$$2"
2657                         if [ -z "$res" ]; then
2658                                 log 2 "  trying $includeDir/$4$5... no"
2659                         fi
2660                 fi
2662                 eval "res=\$$2"
2663                 if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then
2664                         eval "res=\$$2"
2665                         log 2 "  trying $res... found"
2666                         # Now find the static lib, if needed
2667                         eval "$2=`ls /lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2668                         eval "res=\$$2"
2669                         if [ -z "$res" ]; then
2670                                 log 2 "  trying /lib/$3... no"
2671                                 eval "$2=`ls /usr/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2672                         fi
2673                         eval "res=\$$2"
2674                         if [ -z "$res" ]; then
2675                                 log 2 "  trying /usr/lib/$3... no"
2676                                 eval "$2=`ls /usr/local/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2677                         fi
2678                         eval "res=\$$2"
2679                         if [ -z "$res" ]; then
2680                                 log 2 "  trying /usr/local/lib/$3... no"
2681                                 eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2682                         fi
2683                         eval "res=\$$2"
2684                         if [ -z "$res" ]; then
2685                                 log 2 "  trying /mingw/lib/$3... no"
2686                                 log 1 "configure: error: $2 couldn't be found"
2687                                 log 1 "configure: error: you requested a static link, but I can't find $3"
2689                                 exit 1
2690                         fi
2691                 fi
2692         else
2693                 # Make sure it exists
2694                 if [ -f "$1" ]; then
2695                         eval "$2=`ls $1 2>/dev/null`"
2696                 else
2697                         eval "$2=`ls $1/$3 2>/dev/null`"
2698                 fi
2699         fi
2701         eval "res=\$$2"
2702         if [ -z "$res" ]; then
2703                 log 1 "checking $2... not found"
2704                 if [ "$1" = "2" ]; then
2705                         log 1 "configure: error: $2 couldn't be found"
2707                         exit 1
2708                 elif [ "$1" != "1" ]; then
2709                         log 1 "configure: error: $2 couldn't be found"
2710                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2712                         exit 1
2713                 fi
2715                 eval "with_$2=0"
2717                 return 0
2718         fi
2720         eval "res=\$$2"
2721         log 2 "  trying $res... found"
2723         log 1 "checking $2... found"
2726 detect_zlib() {
2727         detect_pkg_config "$with_zlib" "zlib" "zlib_config" "1.2"
2730 detect_lzo2() {
2731         detect_library "$with_lzo2" "lzo2" "liblzo2.a" "lzo/" "lzo1x.h"
2734 detect_libtimidity() {
2735         detect_pkg_config "$with_libtimidity" "libtimidity" "libtimidity_config" "0.1" "1"
2738 detect_pkg_config() {
2739         # $1 - config-param ($with_lzma value)
2740         # $2 - package name ('liblzma')
2741         # $3 - config name ('lzma_config', sets $lzma_config)
2742         # $4 - minimum module version ('2.3')
2743         # $5 - check for dedicated, 1 is "skif if dedicated"
2745         # 0 means no, 1 is auto-detect, 2 is force
2746         if [ "$1" = "0" ]; then
2747                 log 1 "checking $2... disabled"
2749                 eval "$3=\"\""
2750                 return 0
2751         fi
2753         if [ "$5" = "1" ] && [ "$1" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2754                 log 1 "checking $2... dedicated server, skipping"
2756                 eval "$3=\"\""
2757                 return 0
2758         fi
2760         log 2 "detecting $2"
2762         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2763                 pkg_config_call="$pkg_config $2"
2764         else
2765                 pkg_config_call="$1"
2766         fi
2768         version=`$pkg_config_call --modversion 2>/dev/null`
2769         ret=$?
2770         check_version "$4" "$version"
2771         version_ok=$?
2772         log 2 "executing $pkg_config_call --modversion"
2773         log 2 "  returned $version"
2774         log 2 "  exit code $ret"
2776         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2777                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2778                         log 1 "checking $2... needs at least version $4, $2 NOT enabled"
2779                 else
2780                         log 1 "checking $2... not found"
2781                 fi
2783                 # It was forced, so it should be found.
2784                 if [ "$1" != "1" ]; then
2785                         log 1 "configure: error: $pkg_config $2 couldn't be found"
2786                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2787                         exit 1
2788                 fi
2790                 eval "$3=\"\""
2791                 return 0
2792         fi
2794         eval "$3=\"$pkg_config_call\""
2795         log 1 "checking $2... found"
2798 detect_lzma() {
2799         detect_pkg_config "$with_lzma" "liblzma" "lzma_config" "5.0"
2802 detect_xdg_basedir() {
2803         detect_pkg_config "$with_xdg_basedir" "libxdg-basedir" "xdg_basedir_config" "1.2"
2806 detect_png() {
2807         detect_pkg_config "$with_png" "libpng" "png_config" "1.2"
2810 detect_freetype() {
2811         detect_pkg_config "$with_freetype" "freetype2" "freetype_config" "2.2" "1"
2814 detect_fontconfig() {
2815         # 0 means no, 1 is auto-detect, 2 is force
2816         if [ "$with_fontconfig" = "0" ]; then
2817                 log 1 "checking libfontconfig... disabled"
2819                 fontconfig_config=""
2820                 return 0
2821         fi
2822         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
2823                 log 1 "checking libfontconfig... WIN32, skipping"
2824                 fontconfig_config=""
2825                 return 0
2826         fi
2828         if [ "$os" = "OSX" ]; then
2829                 log 1 "checking libfontconfig... OSX, skipping"
2830                 fontconfig_config=""
2831                 return 0
2832         fi
2834         detect_pkg_config "$with_fontconfig" "fontconfig" "fontconfig_config" "2.3" "1"
2837 detect_icu_layout() {
2838         detect_pkg_config "$with_icu_layout" "icu-lx" "icu_layout_config" "4.8" "1"
2841 detect_icu_sort() {
2842         detect_pkg_config "$with_icu_sort" "icu-i18n" "icu_sort_config" "4.8" "1"
2845 detect_iconv() {
2846         # 0 means no, 1 is auto-detect, 2 is force
2847         if [ "$with_iconv" = "0" ]; then
2848                 log 1 "checking iconv... disabled"
2850                 return 0
2851         fi
2853         if [ "$with_iconv" = "1" ] && [ "$os" != "OSX" ]; then
2854                 log 1 "checking iconv... not OSX, skipping"
2855                 with_iconv="0"
2857                 return 0
2858         fi
2860         # Try to find iconv.h, seems to only thing to detect iconv with
2862         if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
2863                 iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
2864                 if [ -z "$iconv" ]; then
2865                         iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
2866                 fi
2867         else
2868                 # Make sure it exists
2869                 iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
2870         fi
2872         if [ -z "$iconv" ]; then
2873                 log 1 "checking iconv... not found"
2874                 if [ "$with_iconv" = "2" ]; then
2875                         log 1 "configure: error: iconv couldn't be found"
2877                         exit 1
2878                 elif [ "$with_iconv" != "1" ]; then
2879                         log 1 "configure: error: iconv couldn't be found"
2880                         log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
2882                         exit 1
2883                 fi
2885                 return 0
2886         fi
2888         if [ "$with_iconv" = "1" ]; then
2889                 with_iconv="2"
2890         fi
2892         log 2 "found iconv in $iconv"
2894         log 1 "checking iconv... found"
2896         # There are different implementations of iconv. The older ones,
2897         # e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
2898         # IEEE 1003.1 (2004), pass a non-const pointer.
2900         cat > tmp.iconv.cpp << EOF
2901 #include "src/stdafx.h"
2902 #include <iconv.h>
2903 int main() {
2904         static char buf[1024];
2905         iconv_t convd = 0;
2906         const char *inbuf = "";
2907         char *outbuf  = buf;
2908         size_t outlen = 1023;
2909         size_t inlen  = 0;
2910         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2913         execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2914         eval $execute > /dev/null
2915         ret=$?
2916         log 2 "executing $execute"
2917         log 2 "  exit code $ret"
2918         if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
2919         log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
2921         cat > tmp.iconv.cpp << EOF
2922 #include "src/stdafx.h"
2923 #include <iconv.h>
2924 int main() {
2925         static char buf[1024];
2926         iconv_t convd = 0;
2927         char *inbuf = "";
2928         char *outbuf  = buf;
2929         size_t outlen = 1023;
2930         size_t inlen  = 0;
2931         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2934         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2935         eval $execute > /dev/null
2936         ret=$?
2937         log 2 "executing $execute"
2938         log 2 "  exit code $ret"
2939         if [ "$ret" = "0" ]; then link_to_iconv="no"; else link_to_iconv="yes"; fi
2940         log 1 "checking whether to link to iconv... $link_to_iconv"
2941         rm -f tmp.iconv tmp.iconv.cpp
2944 _detect_sort() {
2945         sort_test_in="d
2950         sort_test_out="a
2955         log 2 "running echo <array> | $1"
2957         if [ "`echo \"$sort_test_in\" | $1 2>/dev/null`" = "$sort_test_out" ]; then
2958                 sort="$1"
2959                 log 2 "  result was valid"
2960         else
2961                 log 2 "  result was invalid"
2962         fi
2965 detect_sort() {
2966         if [ "$with_sort" = "0" ]; then
2967                 log 1 "checking sort... disabled"
2969                 return
2970         fi
2972         if [ "$with_sort" = "1" ] || [ "$with_sort" = "2" ]; then
2973                 _detect_sort "sort"
2974                 if [ -z "$sort" ]; then _detect_sort "/sbin/sort"; fi
2975                 if [ -z "$sort" ]; then _detect_sort "/usr/sbin/sort"; fi
2976                 if [ -z "$sort" ]; then _detect_sort "/usr/local/sbin/sort"; fi
2977                 if [ -z "$sort" ]; then _detect_sort "/bin/sort"; fi
2978                 if [ -z "$sort" ]; then _detect_sort "/usr/bin/sort"; fi
2979                 if [ -z "$sort" ]; then _detect_sort "/usr/local/bin/sort"; fi
2980         else
2981                 _detect_sort "$with_sort"
2982         fi
2984         if [ -z "$sort" ]; then
2985                 if [ "$with_sort" = "2" ]; then
2986                         log 1 "checking sort... not found"
2988                         log 1 "configure: error: couldn't detect sort on your system"
2989                         exit 1
2990                 elif [ "$with_sort" != "1" ]; then
2991                         log 1 "checking sort... $with_sort not found"
2993                         log 1 "configure: error: '$with_sort' doesn't look like a sort to me"
2994                         log 1 "configure: error: please verify its location and function and try again"
2996                         exit 1
2997                 else
2998                         log 1 "checking sort... not found"
2999                 fi
3000         else
3001                 log 1 "checking sort... $sort"
3002         fi
3005 detect_grfcodec() {
3006         # 0 means no, 1 is auto-detect, 2 is force
3007         if [ "$with_grfcodec" = "0" ]; then
3008                 log 1 "checking grfcodec... disabled"
3010                 grfcodec=""
3011                 return 0
3012         fi
3014         if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
3015                 grfcodec="grfcodec"
3016         else
3017                 grfcodec="$with_grfcodec"
3018         fi
3020         version=`$grfcodec -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3021         ret=$?
3022         log 2 "executing grfcodec -v"
3023         log 2 "  returned $version"
3024         log 2 "  exit code $ret"
3026         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3027                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3028                         log 1 "checking grfcodec... needs at least version 6.0.5 (r985), disabled"
3029                 else
3030                         log 1 "checking grfcodec... not found"
3031                 fi
3033                 # It was forced, so it should be found.
3034                 if [ "$with_grfcodec" != "1" ]; then
3035                         log 1 "configure: error: grfcodec couldn't be found"
3036                         log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
3037                         exit 1
3038                 fi
3040                 grfcodec=""
3041                 return 0
3042         fi
3044         log 1 "checking grfcodec... found"
3047 detect_nforenum() {
3048         # 0 means no, 1 is auto-detect, 2 is force
3049         if [ "$with_nforenum" = "0" ]; then
3050                 log 1 "checking nforenum... disabled"
3052                 nforenum=""
3053                 return 0
3054         fi
3056         if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
3057                 nforenum="nforenum"
3058         else
3059                 nforenum="$with_nforenum"
3060         fi
3062         version=`$nforenum -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3063         ret=$?
3064         log 2 "executing nforenum -v"
3065         log 2 "  returned $version"
3066         log 2 "  exit code $ret"
3068         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3069                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3070                         log 1 "checking nforenum... needs at least version 6.0.5 (r985), disabled"
3071                 else
3072                         log 1 "checking nforenum... not found"
3073                 fi
3075                 # It was forced, so it should be found.
3076                 if [ "$with_nforenum" != "1" ]; then
3077                         log 1 "configure: error: nforenum couldn't be found"
3078                         log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
3079                         exit 1
3080                 fi
3082                 nforenum=""
3083                 return 0
3084         fi
3086         log 1 "checking nforenum... found"
3089 detect_cputype() {
3090         if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
3091                 log 1 "forcing cpu-type... $cpu_type bits"
3092                 return;
3093         fi
3094         echo "#define _SQ64 1" > tmp.64bit.cpp
3095         echo "#include \"src/stdafx.h\"" >> tmp.64bit.cpp
3096         echo "assert_compile(sizeof(size_t) == 8);" >> tmp.64bit.cpp
3097         echo "int main() { return 0; }" >> tmp.64bit.cpp
3098         execute="$cxx_host $CFLAGS tmp.64bit.cpp -o tmp.64bit -DTESTING 2>&1"
3099         cpu_type="`eval $execute 2>/dev/null`"
3100         ret=$?
3101         log 2 "executing $execute"
3102         log 2 "  returned $cpu_type"
3103         log 2 "  exit code $ret"
3104         if [ "$ret" = "0" ]; then cpu_type="64"; else cpu_type="32"; fi
3105         log 1 "detecting cpu-type... $cpu_type bits"
3106         rm -f tmp.64bit tmp.64bit.cpp
3109 detect_sse_capable_architecture() {
3110         # 0 means no, 1 is auto-detect, 2 is force
3111         if [ "$with_sse" = "0" ]; then
3112                 log 1 "checking SSE... disabled"
3113                 return
3114         fi
3116         echo "#define _SQ64 1" > tmp.sse.cpp
3117         echo "#include <xmmintrin.h>" >> tmp.sse.cpp
3118         echo "#include <smmintrin.h>" >> tmp.sse.cpp
3119         echo "#include <tmmintrin.h>" >> tmp.sse.cpp
3120         echo "int main() { return 0; }" >> tmp.sse.cpp
3121         execute="$cxx_host -msse4.1 $CFLAGS tmp.sse.cpp -o tmp.sse 2>&1"
3122         sse="`eval $execute 2>/dev/null`"
3123         ret=$?
3124         log 2 "executing $execute"
3125         log 2 "  returned $sse"
3126         log 2 "  exit code $ret"
3127         if [ "$ret" = "0" ]; then
3128                 log 1 "detecting SSE... found"
3129         else
3130                 # It was forced, so it should be found.
3131                 if [ "$with_sse" != "1" ]; then
3132                         log 1 "configure: error: SSE couln't be found"
3133                         log 1 "configure: error: you force enabled SSE, but it seems unavailable"
3134                         exit 1
3135                 fi
3137                 log 1 "detecting SSE... not found"
3138                 with_sse="0"
3139         fi
3140         rm -f tmp.sse tmp.exe tmp.sse.cpp
3143 make_sed() {
3144         T_CFLAGS="$CFLAGS"
3145         T_CXXFLAGS="$CXXFLAGS"
3146         T_LDFLAGS="$LDFLAGS"
3148         SRC_OBJS_DIR="$BASE_SRC_OBJS_DIR/$OBJS_SUBDIR"
3150         # All the data needed to compile a single target
3151         #  Make sure if you compile multiple targets to
3152         #  use multiple OBJS_DIR, because all in-between
3153         #  binaries are stored in there, and nowhere else.
3154         SRC_REPLACE="
3155                 s@!!CC_HOST!!@$cc_host@g;
3156                 s@!!CXX_HOST!!@$cxx_host@g;
3157                 s@!!CC_BUILD!!@$cc_build@g;
3158                 s@!!CXX_BUILD!!@$cxx_build@g;
3159                 s@!!WINDRES!!@$windres@g;
3160                 s@!!STRIP!!@$strip $strip_arg@g;
3161                 s@!!LIPO!!@$lipo@g;
3162                 s@!!CFLAGS!!@$T_CFLAGS@g;
3163                 s@!!CFLAGS_BUILD!!@$CFLAGS_BUILD@g;
3164                 s@!!CXXFLAGS!!@$T_CXXFLAGS@g;
3165                 s@!!CXXFLAGS_BUILD!!@$CXXFLAGS_BUILD@g;
3166                 s@!!STRGEN_FLAGS!!@$strgen_flags@g;
3167                 s@!!LIBS!!@$LIBS@g;
3168                 s@!!LDFLAGS!!@$T_LDFLAGS@g;
3169                 s@!!LDFLAGS_BUILD!!@$LDFLAGS_BUILD@g;
3170                 s@!!BIN_DIR!!@$BIN_DIR@g;
3171                 s@!!ROOT_DIR!!@$ROOT_DIR@g;
3172                 s@!!MEDIA_DIR!!@$MEDIA_DIR@g;
3173                 s@!!SOURCE_LIST!!@$SOURCE_LIST@g;
3174                 s@!!SRC_OBJS_DIR!!@$SRC_OBJS_DIR@g;
3175                 s@!!LANG_OBJS_DIR!!@$LANG_OBJS_DIR@g;
3176                 s@!!GRF_OBJS_DIR!!@$GRF_OBJS_DIR@g;
3177                 s@!!SETTING_OBJS_DIR!!@$SETTING_OBJS_DIR@g;
3178                 s@!!SRC_DIR!!@$SRC_DIR@g;
3179                 s@!!SCRIPT_SRC_DIR!!@$SCRIPT_SRC_DIR@g;
3180                 s@!!OSXAPP!!@$OSXAPP@g;
3181                 s@!!LANG_DIR!!@$LANG_DIR@g;
3182                 s@!!TTD!!@$TTD@g;
3183                 s@!!BINARY_DIR!!@$prefix_dir/$binary_dir@g;
3184                 s@!!DATA_DIR!!@$prefix_dir/$data_dir@g;
3185                 s@!!DOC_DIR!!@$prefix_dir/$doc_dir@g;
3186                 s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3187                 s@!!ICON_DIR!!@$prefix_dir/$icon_dir@g;
3188                 s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3189                 s@!!PERSONAL_DIR!!@$personal_dir@g;
3190                 s@!!SHARED_DIR!!@$shared_dir@g;
3191                 s@!!INSTALL_DIR!!@$install_dir@g;
3192                 s@!!BINARY_NAME!!@$binary_name@g;
3193                 s@!!STRGEN!!@$STRGEN@g;
3194                 s@!!DEPEND!!@$DEPEND@g;
3195                 s@!!SETTINGSGEN!!@$SETTINGSGEN@g;
3196                 s@!!STAGE!!@$STAGE@g;
3197                 s@!!MAKEDEPEND!!@$makedepend@g;
3198                 s@!!CFLAGS_MAKEDEP!!@$cflags_makedep@g;
3199                 s@!!SORT!!@$sort@g;
3200                 s@!!CONFIG_CACHE_COMPILER!!@config.cache.compiler@g;
3201                 s@!!CONFIG_CACHE_LINKER!!@config.cache.linker@g;
3202                 s@!!CONFIG_CACHE_SOURCE!!@config.cache.source@g;
3203                 s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
3204                 s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
3205                 s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
3206                 s@!!LANG_SUPPRESS!!@$lang_suppress@g;
3207                 s@!!OBJS_C!!@$OBJS_C@g;
3208                 s@!!OBJS_CPP!!@$OBJS_CPP@g;
3209                 s@!!OBJS_MM!!@$OBJS_MM@g;
3210                 s@!!OBJS_RC!!@$OBJS_RC@g;
3211                 s@!!SRCS!!@$SRCS@g;
3212                 s@!!OS!!@$os@g;
3213                 s@!!CONFIGURE_FILES!!@$CONFIGURE_FILES@g;
3214                 s@!!AWK!!@$awk@g;
3215                 s@!!DISTCC!!@$distcc@g;
3216                 s@!!NFORENUM!!@$nforenum@g;
3217                 s@!!GRFCODEC!!@$grfcodec@g;
3218         "
3220         if [ "$icon_theme_dir" != "" ]; then
3221                 SRC_REPLACE="$SRC_REPLACE
3222                         s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3223                 "
3224         else
3225                 SRC_REPLACE="$SRC_REPLACE
3226                         s@!!ICON_THEME_DIR!!@@g;
3227                 "
3228         fi
3230         if [ "$man_dir" != "" ]; then
3231                 SRC_REPLACE="$SRC_REPLACE
3232                         s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3233                 "
3234         else
3235                 SRC_REPLACE="$SRC_REPLACE
3236                         s@!!MAN_DIR!!@@g;
3237                 "
3238         fi
3240         if [ "$menu_dir" != "" ]; then
3241                 SRC_REPLACE="$SRC_REPLACE
3242                         s@!!MENU_DIR!!@$prefix_dir/$menu_dir@g;
3243                 "
3244         else
3245                 SRC_REPLACE="$SRC_REPLACE
3246                         s@!!MENU_DIR!!@@g;
3247                 "
3248         fi
3251 generate_menu_item() {
3252         MENU_REPLACE="
3253                 s@!!TTD!!@$TTD@g;
3254                 s@!!MENU_GROUP!!@$menu_group@g;
3255                 s@!!MENU_NAME!!@$menu_name@g
3256         "
3257         log 1 "Generating menu item..."
3258         mkdir -p media
3259         < $ROOT_DIR/media/openttd.desktop.in sed "$MENU_REPLACE" > media/openttd.desktop
3262 generate_main() {
3263         STAGE="[MAIN]"
3265         make_sed
3267         # Create the main Makefile
3268         log 1 "Generating Makefile..."
3269         echo "# Auto-generated file from 'Makefile.in' -- DO NOT EDIT" > Makefile
3270         < $ROOT_DIR/Makefile.in sed "$SRC_REPLACE" >> Makefile
3271         cp $ROOT_DIR/Makefile.bundle.in Makefile.bundle
3272         echo "# Auto-generated file -- DO NOT EDIT" > Makefile.am
3273         echo >> Makefile.am
3274         # Make the copy of the source-list, so we don't trigger an unwanted recompile
3275         cp $SOURCE_LIST config.cache.source.list
3276         # Add the current directory, so we don't trigger an unwanted recompile
3277         echo "`pwd`" > config.cache.pwd
3278         # Make sure config.cache is OLDER then config.cache.source.list
3279         touch config.cache
3280         touch config.pwd
3282         if [ "$menu_dir" != "" ]; then
3283                 generate_menu_item
3284         fi
3287 generate_lang() {
3288         STAGE="[LANG]"
3290         make_sed
3292         # Create the language file
3293         mkdir -p $LANG_OBJS_DIR
3295         log 1 "Generating lang/Makefile..."
3296         echo "# Auto-generated file from 'Makefile.lang.in' -- DO NOT EDIT" > $LANG_OBJS_DIR/Makefile
3297         < $ROOT_DIR/Makefile.lang.in sed "$SRC_REPLACE" >> $LANG_OBJS_DIR/Makefile
3298         echo "DIRS += $LANG_OBJS_DIR" >> Makefile.am
3299         echo "LANG_DIRS += $LANG_OBJS_DIR" >> Makefile.am
3302 generate_settings() {
3303         STAGE="[SETTING]"
3305         make_sed
3307         # Create the language file
3308         mkdir -p $SETTING_OBJS_DIR
3310         log 1 "Generating setting/Makefile..."
3311         echo "# Auto-generated file from 'Makefile.settings.in' -- DO NOT EDIT" > $SETTING_OBJS_DIR/Makefile
3312         < $ROOT_DIR/Makefile.setting.in sed "$SRC_REPLACE" >> $SETTING_OBJS_DIR/Makefile
3313         echo "DIRS += $SETTING_OBJS_DIR" >> Makefile.am
3316 generate_grf() {
3317         STAGE="[BASESET]"
3319         make_sed
3321         # Create the language file
3322         mkdir -p $GRF_OBJS_DIR
3324         log 1 "Generating grf/Makefile..."
3325         echo "# Auto-generated file from 'Makefile.grf.in' -- DO NOT EDIT" > $GRF_OBJS_DIR/Makefile
3326         < $ROOT_DIR/Makefile.grf.in sed "$SRC_REPLACE" >> $GRF_OBJS_DIR/Makefile
3327         echo "DIRS += $GRF_OBJS_DIR" >> Makefile.am
3330 generate_src_normal() {
3331         STAGE=$1
3333         make_sed
3335         # Create the source file
3336         mkdir -p $SRC_OBJS_DIR
3338         log 1 "Generating $2/Makefile..."
3339         echo "# Auto-generated file from 'Makefile.src.in' -- DO NOT EDIT" > $SRC_OBJS_DIR/Makefile
3340         < $ROOT_DIR/Makefile.src.in sed "$SRC_REPLACE" >> $SRC_OBJS_DIR/Makefile
3341         echo "DIRS += $SRC_OBJS_DIR" >> Makefile.am
3342         echo "SRC_DIRS += $SRC_OBJS_DIR" >> Makefile.am
3345 generate_src_osx() {
3346         cc_host_orig="$cc_host"
3347         cxx_host_orig="$cxx_host"
3348         CFLAGS_orig="$CFLAGS"
3349         LDFLAGS_orig="$LDFLAGS"
3351         for type in $enable_universal; do
3353                 if [ -n "$osx_sdk_104_path" ]; then
3354                         # Use 10.4 SDK for 32-bit targets
3355                         CFLAGS="-isysroot $osx_sdk_104_path $CFLAGS_orig"
3356                         LDFLAGS="-Wl,-syslibroot,$osx_sdk_104_path $LDFLAGS_orig"
3357                 fi
3359                 # We don't want to duplicate the x86_64 stuff for each target, so do it once here
3360                 if [ "$type" = "ppc64" ] || [ "$type" = "x86_64" ]; then
3361                         # 64 bits is always 10.5 or higher. Furthermore it has a non const ICONV
3362                         # and they also removed support for QuickTime/QuickDraw
3363                         if [ -n "$osx_sdk_path" ]; then
3364                                 CFLAGS="-isysroot $osx_sdk_path $CFLAGS_orig"
3365                                 LDFLAGS="-Wl,-syslibroot,$osx_sdk_path $LDFLAGS_orig"
3366                         fi
3367                         CFLAGS="$CFLAGS -D_SQ64 -DNO_QUICKTIME -UENABLE_COCOA_QUICKDRAW"
3368                         LIBS="`echo $LIBS | sed 's/-framework QuickTime//'`"
3369                 fi
3371                 case $type in
3372                         ppc)
3373                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc"
3374                                 cc_host="$cc_host_orig -arch ppc -mmacosx-version-min=10.3"
3375                                 cxx_host="$cxx_host_orig -arch ppc -mmacosx-version-min=10.3"
3376                                 generate_src_normal "[ppc]" "objs/ppc";;
3377                         ppc970)
3378                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc970"
3379                                 cc_host="$cc_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3380                                 cxx_host="$cxx_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3381                                 generate_src_normal "[ppc970]" "objs/ppc970";;
3382                         i386)
3383                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/i386"
3384                                 cc_host="$cc_host_orig -arch i386 -mmacosx-version-min=10.4"
3385                                 cxx_host="$cxx_host_orig -arch i386 -mmacosx-version-min=10.4"
3386                                 generate_src_normal "[i386]" "objs/i386";;
3387                         ppc64)
3388                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc64"
3389                                 cc_host="$cc_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3390                                 cxx_host="$cxx_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3391                                 generate_src_normal "[ppc64]" "objs/ppc64";;
3392                         x86_64)
3393                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/x86_64"
3394                                 cc_host="$cc_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3395                                 cxx_host="$cxx_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3396                                 generate_src_normal "[x86_64]" "objs/x86_64";;
3397                         *) log 1 "Unknown architecture requested for universal build: $type";;
3398                 esac
3399         done
3402 generate_src() {
3403         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
3404                 generate_src_osx
3405         else
3406                 generate_src_normal "[SRC]" "objs"
3407         fi
3410 showhelp() {
3411         echo "'configure' configures OpenTTD."
3412         echo ""
3413         echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
3414         echo ""
3415         echo "To assign environment variables (e.g., CC, CFLAGS...), specify them as"
3416         echo "VAR=VALUE.  See below for descriptions of some of the useful variables."
3417         echo ""
3418         echo "Defaults for the options are specified in brackets."
3419         echo ""
3420         echo "Configuration:"
3421         echo "  -h, --help                     display this help and exit"
3422         echo ""
3423         echo "System types:"
3424         echo "  --build=BUILD                  configure for building on BUILD [guessed]"
3425         echo "  --host=HOST                    cross-compile to build programs to run"
3426         echo "                                 on HOST [BUILD]"
3427         echo "  --windres=WINDRES              the windres to use [HOST-windres]"
3428         echo "  --strip=STRIP                  the strip to use [HOST-strip]"
3429         echo "  --awk=AWK                      the awk to use in configure [awk]"
3430         echo "  --pkg-config=PKG-CONFIG        the pkg-config to use in configure [pkg-config]"
3431         echo "  --lipo=LIPO                    the lipo to use (OSX ONLY) [HOST-lipo]"
3432         echo "  --os=OS                        the OS we are compiling for [DETECT]"
3433         echo "                                 DETECT/UNIX/OSX/FREEBSD/DRAGONFLY/OPENBSD/"
3434         echo "                                 NETBSD/MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/"
3435         echo "                                 MINGW/OS2/DOS/HAIKU"
3436         echo ""
3437         echo "Paths:"
3438         echo "  --prefix-dir=dir               specifies the prefix for all installed"
3439         echo "                                 files [/usr/local]"
3440         echo "  --binary-dir=dir               location of the binary. Will be prefixed"
3441         echo "                                 with the prefix-dir [games]"
3442         echo "  --data-dir=dir                 location of data files (lang, data, gm)."
3443         echo "                                 Will be prefixed with the prefix-dir"
3444         echo "                                 [share/games/openttd]"
3445         echo "  --doc-dir=dir                  location of the doc files"
3446         echo "                                 Will be prefixed with the prefix-dir"
3447         echo "                                 [$doc_dir]"
3448         echo "  --icon-dir=dir                 location of icons. Will be prefixed"
3449         echo "                                 with the prefix-dir [share/pixmaps]"
3450         echo "  --icon-theme-dir=dir           location of icon theme."
3451         echo "                                 Will be prefixed with the prefix-dir"
3452         echo "                                 and postfixed with size-dirs [$icon_theme_dir]"
3453         echo "  --man-dir=dir                  location of the manual page (UNIX only)"
3454         echo "                                 Will be prefixed with the prefix-dir"
3455         echo "                                 [$man_dir]"
3456         echo "  --menu-dir=dir                 location of the menu item. (UNIX only, except OSX)"
3457         echo "                                 Will be prefixed with the prefix-dir"
3458         echo "                                 [share/applications]"
3459         echo "  --personal-dir=dir             location of the personal directory"
3460         echo "                                 [os-dependent default]"
3461         echo "  --shared-dir=dir               location of shared data files"
3462         echo "                                 [os-dependent default]"
3463         echo "  --install-dir=dir              specifies the root to install to."
3464         echo "                                 Useful to install into jails [/]"
3465         echo "  --binary-name                  the name used for the binary, icons,"
3466         echo "                                 desktop file, etc. when installing [openttd]"
3467         echo ""
3468         echo "Features and packages:"
3469         echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
3470         echo "  --enable-desync-debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
3471         echo "  --enable-profiling             enables profiling"
3472         echo "  --enable-lto                   enables GCC's Link Time Optimization (LTO)/ICC's"
3473         echo "                                 Interprocedural Optimization if available"
3474         echo "  --enable-dedicated             compile a dedicated server (without video)"
3475         echo "  --enable-static                enable static compile (doesn't work for"
3476         echo "                                 all HOSTs)"
3477         echo "  --enable-translator            enable extra output for translators"
3478         echo "  --enable-universal[=ARCH]      enable universal builds (OSX ONLY). Allowed is any combination"
3479         echo "                                 of architectures: i386 ppc ppc970 ppc64 x86_64"
3480         echo "                                 Default architectures are: i386 ppc"
3481         echo "  --enable-osx-g5                enables optimizations for ppc970 (G5) (OSX ONLY)"
3482         echo "  --disable-cocoa-quartz         disable the quartz window mode driver for Cocoa (OSX ONLY)"
3483         echo "  --disable-cocoa-quickdraw      disable the quickdraw window mode driver for Cocoa (OSX ONLY)"
3484         echo "  --disable-unicode              disable unicode support to build win9x"
3485         echo "                                 version (Win32 ONLY)"
3486         echo "  --enable-console               compile as a console application instead of as a GUI application."
3487         echo "                                 If this setting is active, debug output will appear in the same"
3488         echo "                                 console instead of opening a new window. (Win32 ONLY)"
3489         echo "  --disable-network              disable network support"
3490         echo "  --disable-assert               disable asserts (continue on errors)"
3491         echo "  --enable-strip                 enable any possible stripping"
3492         echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
3493         echo "                                 (OSX ONLY)"
3494         echo "  --without-application-bundle   disable generation of application bundle"
3495         echo "                                 (OSX ONLY)"
3496         echo "  --without-menu-entry           Don't generate a menu item (Freedesktop based only)"
3497         echo "  --menu-group=group             Category in which the menu item will be placed (Freedesktop based only)"
3498         echo "  --menu-name=name               Name of the menu item when placed [OpenTTD]"
3499         echo "  --with-direct-music            enable direct music support (Win32 ONLY)"
3500         echo "  --with-sort=sort               define a non-default location for sort"
3501         echo "  --with-midi=midi               define which midi-player to use"
3502         echo "  --with-midi-arg=arg            define which args to use for the"
3503         echo "                                 midi-player"
3504         echo "  --with-libtimidity[=\"pkg-config libtimidity\"]"
3505         echo "                                 enables libtimidity support"
3506         echo "  --with-allegro[=\"pkg-config allegro\"]"
3507         echo "                                 enables Allegro video driver support"
3508         echo "  --with-cocoa                   enables COCOA video driver (OSX ONLY)"
3509         echo "  --with-sdl[=\"pkg-config sdl\"]  enables SDL video driver support"
3510         echo "  --with-zlib[=\"pkg-config zlib\"]"
3511         echo "                                 enables zlib support"
3512         echo "  --with-liblzma[=\"pkg-config liblzma\"]"
3513         echo "                                 enables liblzma support"
3514         echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
3515         echo "  --with-png[=\"pkg-config libpng\"]"
3516         echo "                                 enables libpng support"
3517         echo "  --with-freetype[=\"pkg-config freetype2\"]"
3518         echo "                                 enables libfreetype support"
3519         echo "  --with-fontconfig[=\"pkg-config fontconfig\"]"
3520         echo "                                 enables fontconfig support"
3521         echo "  --with-xdg-basedir[=\"pkg-config libxdg-basedir\"]"
3522         echo "                                 enables XDG base directory support"
3523         echo "  --with-icu                     enables icu components for layout and sorting"
3524         echo "  --with-icu-layout[=\"pkg-config icu-lx\"]"
3525         echo "                                 enables icu components for layouting (right-to-left support)"
3526         echo "  --with-icu-sort[=\"pkg-config icu-i18n\"]"
3527         echo "                                 enables icu components for locale specific string sorting"
3528         echo "  --static-icu                   try to link statically (libsicu instead of"
3529         echo "                                 libicu; can fail as the new name is guessed)"
3530         echo "  --with-iconv[=iconv-path]      enables iconv support"
3531         echo "  --disable-builtin-depend       disable use of builtin deps finder"
3532         echo "  --with-makedepend[=makedepend] enables makedepend support"
3533         echo "  --with-ccache                  enables ccache support"
3534         echo "  --with-distcc                  enables distcc support"
3535         echo "  --without-grfcodec             disable usage of grfcodec and re-generation of base sets"
3536         echo "  --without-threads              disable threading support"
3537         echo "  --without-sse                  disable SSE support (x86/x86_64 only)"
3538         echo ""
3539         echo "Some influential environment variables:"
3540         echo "  CC                             C compiler command"
3541         echo "  CXX                            C++ compiler command"
3542         echo "  CFLAGS                         C compiler flags"
3543         echo "  CXXFLAGS                       C++ compiler flags"
3544         echo "  WINDRES                        windres command"
3545         echo "  LDFLAGS                        linker flags, e.g. -L<lib dir> if you"
3546         echo "                                 have libraries in a nonstandard"
3547         echo "                                 directory <lib dir>"
3548         echo "  CFLAGS_BUILD                   C compiler flags for build time tool generation"
3549         echo "  CXXFLAGS_BUILD                 C++ compiler flags for build time tool generation"
3550         echo "  LDFLAGS_BUILD                  linker flags for build time tool generation"
3551         echo "  PKG_CONFIG_PATH                additional library search paths (see \"man pkg-config\")"
3552         echo "  PKG_CONFIG_LIBDIR              replace the default library search path (see \"man pkg-config\")"
3553         echo ""
3554         echo "Use these variables to override the choices made by 'configure' or to help"
3555         echo "it to find libraries and programs with nonstandard names/locations."