Also scroll tile separators in the train depot
[openttd/fttd.git] / config.lib
blob59c75b6309124fa0deedf3e6860e32e4ad69f645
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         endian="AUTO"
35         cpu_type="DETECT"
36         config_log="config.log"
37         prefix_dir="/usr/local"
38         binary_dir="games"
39         data_dir="share/games/openttd"
40         doc_dir="1"
41         icon_dir="share/pixmaps"
42         icon_theme_dir="1"
43         personal_dir="1"
44         shared_dir="1"
45         install_dir="/"
46         man_dir="1"
47         menu_dir="1"
48         menu_group="Game;"
49         menu_name="OpenTTD"
50         binary_name="openttd"
51         enable_debug="0"
52         enable_desync_debug="0"
53         enable_profiling="0"
54         enable_lto="0"
55         enable_dedicated="0"
56         enable_network="1"
57         enable_static="1"
58         enable_translator="0"
59         enable_unicode="1"
60         enable_console="1";
61         enable_assert="1"
62         enable_strip="0"
63         enable_universal="0"
64         enable_osx_g5="0"
65         enable_cocoa_quartz="1"
66         enable_cocoa_quickdraw="1"
67         with_osx_sysroot="1"
68         with_application_bundle="1"
69         with_menu_entry="1"
70         with_allegro="1"
71         with_sdl="1"
72         with_cocoa="1"
73         with_zlib="1"
74         with_lzma="1"
75         with_lzo2="1"
76         with_xdg_basedir="1"
77         with_png="1"
78         enable_builtin_depend="1"
79         with_makedepend="0"
80         with_direct_music="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_psp_config="1"
92         with_threads="1"
93         with_distcc="1"
94         with_ccache="1"
95         with_nforenum="1"
96         with_grfcodec="1"
97         with_sse="1"
99         save_params_array="
100                 build
101                 host
102                 cc_build
103                 cc_host
104                 cxx_build
105                 cxx_host
106                 windres
107                 strip
108                 lipo
109                 awk
110                 pkg_config
111                 os
112                 endian
113                 cpu_type
114                 config_log
115                 prefix_dir
116                 binary_dir
117                 data_dir
118                 doc_dir
119                 icon_dir
120                 icon_theme_dir
121                 man_dir
122                 menu_dir
123                 personal_dir
124                 shared_dir
125                 install_dir
126                 menu_group
127                 menu_name
128                 binary_name
129                 enable_debug
130                 enable_desync_debug
131                 enable_profiling
132                 enable_lto
133                 enable_dedicated
134                 enable_network
135                 enable_static
136                 enable_translator
137                 enable_unicode
138                 enable_console
139                 enable_assert
140                 enable_strip
141                 enable_universal
142                 enable_osx_g5
143                 enable_cocoa_quartz
144                 enable_cocoa_quickdraw
145                 with_osx_sysroot
146                 with_application_bundle
147                 with_allegro
148                 with_sdl
149                 with_cocoa
150                 with_zlib
151                 with_lzma
152                 with_lzo2
153                 with_xdg_basedir
154                 with_png
155                 enable_builtin_depend
156                 with_makedepend
157                 with_direct_music
158                 with_sort
159                 with_iconv
160                 with_midi
161                 with_midi_arg
162                 with_libtimidity
163                 with_freetype
164                 with_fontconfig
165                 with_icu_layout
166                 with_icu_sort
167                 static_icu
168                 with_psp_config
169                 with_threads
170                 with_distcc
171                 with_ccache
172                 with_grfcodec
173                 with_nforenum
174                 with_sse
175         CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD PKG_CONFIG_PATH PKG_CONFIG_LIBDIR"
178 detect_params() {
179         # Walk over all params from the user and override any default settings if
180         #  needed. This also handles any invalid option.
181         for p in "$@"; do
182                 if [ -n "$prev_p" ]; then
183                         eval "$prev_p=\$p"
184                         prev_p=
185                         continue
186                 fi
188                 optarg=`expr "x$p" : 'x[^=]*=\(.*\)'`
190                 case "$p" in
191                         --help | -h | -\?)            showhelp; exit 0;;
193                         --config-log)                 prev_p="config_log";;
194                         --config-log=*)               config_log="$optarg";;
196                         --build)                      prev_p="build";;
197                         --build=*)                    build="$optarg";;
199                         --host)                       prev_p="host";;
200                         --host=*)                     host="$optarg";;
202                         --os)                         prev_p="os";;
203                         --os=*)                       os="$optarg";;
205                         --cpu-type)                   prev_p="cpu_type";;
206                         --cpu-type=*)                 cpu_type="$optarg";;
208                         --cc-build)                   prev_p="cc_build";;
209                         --cc-build=*)                 cc_build="$optarg";;
210                         --cc-host)                    prev_p="cc_host";;
211                         --cc-host=*)                  cc_host="$optarg";;
212                         --cxx-build)                  prev_p="cxx_build";;
213                         --cxx-build=*)                cxx_build="$optarg";;
214                         --cxx-host)                   prev_p="cxx_host";;
215                         --cxx-host=*)                 cxx_host="$optarg";;
216                         --windres)                    prev_p="windres";;
217                         --windres=*)                  windres="$optarg";;
218                         --awk)                        prev_p="awk";;
219                         --awk=*)                      awk="$optarg";;
220                         --pkg-config)                 prev_p="pkg_config";;
221                         --pkg-config=*)               pkg_config="$optarg";;
222                         --strip)                      prev_p="strip";;
223                         --strip=*)                    strip="$optarg";;
224                         --lipo)                       prev_p="lipo";;
225                         --lipo=*)                     lipo="$optarg";;
227                         --endian)                     prev_p="endian";;
228                         --endian=*)                   endian="$optarg";;
232                         # Alias --prefix with --prefix-dir, for compatibility with GNU autotools
233                         --prefix-dir | --prefix)      prev_p="prefix_dir";;
234                         --prefix-dir=* | --prefix=*)  prefix_dir="$optarg";;
236                         --binary-dir)                 prev_p="binary_dir";;
237                         --binary-dir=*)               binary_dir="$optarg";;
239                         --data-dir)                   prev_p="data_dir";;
240                         --data-dir=*)                 data_dir="$optarg";;
242                         --doc-dir)                    prev_p="doc_dir";;
243                         --doc-dir=*)                  doc_dir="$optarg";;
245                         --icon-dir)                   prev_p="icon_dir";;
246                         --icon-dir=*)                 icon_dir="$optarg";;
248                         --icon-theme-dir)             prev_p="icon_theme_dir";;
249                         --icon-theme-dir=*)           icon_theme_dir="$optarg";;
250                         --without-icon-theme)         icon_theme_dir="";;
252                         --menu-dir)                   prev_p="menu_dir";;
253                         --menu-dir=*)                 menu_dir="$optarg";;
254                         --without-menu-entry)         menu_dir="";;
256                         --menu-name)                  prev_p="menu_name";;
257                         --menu-name=*)                menu_name="$optarg";;
259                         --binary-name)                prev_p="binary_name";;
260                         --binary-name=*)              binary_name="$optarg";;
262                         --man-dir)                    prev_p="man_dir";;
263                         --man-dir=*)                  man_dir="$optarg";;
265                         --personal-dir)               prev_p="personal_dir";;
266                         --personal-dir=*)             personal_dir="$optarg";;
267                         --without-personal-dir)       personal_dir="";;
269                         --shared-dir)                 prev_p="shared_dir";;
270                         --shared-dir=*)               shared_dir="$optarg";;
271                         --without-shared-dir)         shared_dir="";;
273                         --install-dir)                prev_p="install_dir";;
274                         --install-dir=*)              install_dir="$optarg";;
278                         --menu-group)                 prev_p="menu_group";;
279                         --menu-group=*)               menu_group="$optarg";;
283                         --enable-debug)               enable_debug="1";;
284                         --enable-debug=*)             enable_debug="$optarg";;
285                         --enable-desync-debug)        enable_desync_debug="1";;
286                         --enable-desync-debug=*)      enable_desync_debug="$optarg";;
287                         --enable-profiling)           enable_profiling="1";;
288                         --enable-profiling=*)         enable_profiling="$optarg";;
289                         --enable-lto)                 enable_lto="1";;
290                         --enable-lto=*)               enable_lto="$optarg";;
291                         --enable-ipo)                 enable_lto="1";;
292                         --enable-ipo=*)               enable_lto="$optarg";;
293                         --enable-dedicated)           enable_dedicated="1";;
294                         --enable-dedicated=*)         enable_dedicated="$optarg";;
295                         --enable-network)             enable_network="2";;
296                         --enable-network=*)           enable_network="$optarg";;
297                         --disable-network)            enable_network="0";;
298                         --disable-static)             enable_static="0";;
299                         --enable-static)              enable_static="2";;
300                         --enable-static=*)            enable_static="$optarg";;
301                         --disable-translator)         enable_translator="0";;
302                         --enable-translator)          enable_translator="2";;
303                         --enable-translator=*)        enable_translator="$optarg";;
304                         --disable-assert)             enable_assert="0";;
305                         --enable-assert)              enable_assert="2";;
306                         --enable-assert=*)            enable_assert="$optarg";;
307                         --disable-strip)              enable_strip="0";;
308                         --enable-strip)               enable_strip="2";;
309                         --enable-strip=*)             enable_strip="$optarg";;
310                         --disable-universal)          enable_universal="0";;
311                         --enable-universal)           enable_universal="i386 ppc";;
312                         --enable-universal=*)         enable_universal="$optarg";;
313                         --disable-osx-g5)             enable_osx_g5="0";;
314                         --enable-osx-g5)              enable_osx_g5="2";;
315                         --enable-osx-g5=*)            enable_osx_g5="$optarg";;
316                         --disable-unicode)            enable_unicode="0";;
317                         --enable-unicode)             enable_unicode="2";;
318                         --enable-unicode=*)           enable_unicode="$optarg";;
319                         --disable-console)            enable_console="0";;
320                         --enable-console)             enable_console="2";;
321                         --enable-console=*)           enable_console="$optarg";;
323                         --disable-cocoa-quartz)       enable_cocoa_quartz="0";;
324                         --enable-cocoa-quartz)        enable_cocoa_quartz="2";;
325                         --enable-cocoa-quartz=*)      enable_cocoa_quartz="$optarg";;
326                         --disable-cocoa-quickdraw)    enable_cocoa_quickdraw="0";;
327                         --enable-cocoa-quickdraw)     enable_cocoa_quickdraw="2";;
328                         --enable-cocoa-quickdraw=*)   enable_cocoa_quickdraw="$optarg";;
330                         --with-allegro)               with_allegro="2";;
331                         --without-allegro)            with_allegro="0";;
332                         --with-allegro=*)             with_allegro="$optarg";;
334                         --with-sdl)                   with_sdl="2";;
335                         --without-sdl)                with_sdl="0";;
336                         --with-sdl=*)                 with_sdl="$optarg";;
338                         --with-cocoa)                 with_cocoa="2";;
339                         --without-cocoa)              with_cocoa="0";;
340                         --with-cocoa=*)               with_cocoa="$optarg";;
342                         --with-zlib)                  with_zlib="2";;
343                         --without-zlib)               with_zlib="0";;
344                         --with-zlib=*)                with_zlib="$optarg";;
346                         --with-lzma)                  with_lzma="2";;
347                         --without-lzma)               with_lzma="0";;
348                         --with-lzma=*)                with_lzma="$optarg";;
349                         --with-liblzma)               with_lzma="2";;
350                         --without-liblzma)            with_lzma="0";;
351                         --with-liblzma=*)             with_lzma="$optarg";;
353                         --with-lzo2)                  with_lzo2="2";;
354                         --without-lzo2)               with_lzo2="0";;
355                         --with-lzo2=*)                with_lzo2="$optarg";;
356                         --with-liblzo2)               with_lzo2="2";;
357                         --without-liblzo2)            with_lzo2="0";;
358                         --with-liblzo2=*)             with_lzo2="$optarg";;
360                         --with-xdg-basedir)           with_xdg_basedir="2";;
361                         --without-xdg-basedir)        with_xdg_basedir="0";;
362                         --with-xdg-basedir=*)         with_xdg_basedir="$optarg";;
363                         --with-libxdg-basedir)        with_xdg_basedir="2";;
364                         --without-libxdg-basedir)     with_xdg_basedir="0";;
365                         --with-libxdg-basedir=*)      with_xdg_basedir="$optarg";;
367                         --with-png)                   with_png="2";;
368                         --without-png)                with_png="0";;
369                         --with-png=*)                 with_png="$optarg";;
370                         --with-libpng)                with_png="2";;
371                         --without-libpng)             with_png="0";;
372                         --with-libpng=*)              with_png="$optarg";;
374                         --with-libtimidity)           with_libtimidity="2";;
375                         --without-libtimidity)        with_libtimidity="0";;
376                         --with-libtimidity=*)         with_libtimidity="$optarg";;
378                         --with-freetype)              with_freetype="2";;
379                         --without-freetype)           with_freetype="0";;
380                         --with-freetype=*)            with_freetype="$optarg";;
381                         --with-libfreetype)           with_freetype="2";;
382                         --without-libfreetype)        with_freetype="0";;
383                         --with-libfreetype=*)         with_freetype="$optarg";;
385                         --with-fontconfig)            with_fontconfig="2";;
386                         --without-fontconfig)         with_fontconfig="0";;
387                         --with-fontconfig=*)          with_fontconfig="$optarg";;
388                         --with-libfontconfig)         with_fontconfig="2";;
389                         --without-libfontconfig)      with_fontconfig="0";;
390                         --with-libfontconfig=*)       with_fontconfig="$optarg";;
392                         --with-icu)                   with_icu_layout="2";with_icu_sort="2";;
393                         --without-icu)                with_icu_layout="0";with_icu_sort="0";;
394                         --with-icu=*)                 with_icu_layout="$optarg";with_icu_sort="$optarg";;
395                         --with-libicu)                with_icu_layout="2";with_icu_sort="2";;
396                         --without-libicu)             with_icu_layout="0";with_icu_sort="0";;
397                         --with-libicu=*)              with_icu_layout="$optarg";with_icu_sort="$optarg";;
398                         --with-icu-layout)            with_icu_layout="2";;
399                         --without-icu-layout)         with_icu_layout="0";;
400                         --with-icu-layout=*)          with_icu_layout="$optarg";;
401                         --with-icu-sort)              with_icu_sort="2";;
402                         --without-icu-sort)           with_icu_sort="0";;
403                         --with-icu-sort=*)            with_icu_sort="$optarg";;
404                         --static-icu)                 static_icu="1";;
405                         --static-icu=*)               static_icu="$optarg";;
406                         --static-libicu)              static_icu="1";;
407                         --static-libicu=*)            static_icu="$optarg";;
409                         --with-psp-config)            with_psp_config="2";;
410                         --without-psp-config)         with_psp_config="0";;
411                         --with-psp-config=*)          with_psp_config="$optarg";;
413                         --disable-builtin-depend)     enable_builtin_depend="0";;
414                         --enable-builtin-depend)      enable_builtin_depend="2";;
415                         --enable-builtin-depend=*)    enable_builtin_depend="$optarg";;
417                         --with-makedepend)            with_makedepend="2";;
418                         --without-makedepend)         with_makedepend="0";;
419                         --with-makedepend=*)          with_makedepend="$optarg";;
421                         --with-direct-music)          with_direct_music="2";;
422                         --without-direct-music)       with_direct_music="0";;
423                         --with-direct-music=*)        with_direct_music="$optarg";;
425                         --with-sort)                  with_sort="2";;
426                         --without-sort)               with_sort="0";;
427                         --with-sort=*)                with_sort="$optarg";;
429                         --with-iconv)                 with_iconv="2";;
430                         --without-iconv)              with_iconv="0";;
431                         --with-iconv=*)               with_iconv="$optarg";;
433                         --with-midi=*)                with_midi="$optarg";;
434                         --with-midi-arg=*)            with_midi_arg="$optarg";;
436                         --without-distcc)             with_distcc="0";;
437                         --with-distcc)                with_distcc="2";;
438                         --with-distcc=*)              with_distcc="$optarg";;
440                         --without-ccache)             with_ccache="0";;
441                         --with-ccache)                with_ccache="2";;
442                         --with-ccache=*)              with_ccache="$optarg";;
444                         --without-nforenum)           with_nforenum="0";;
445                         --with-nforenum)              with_nforenum="2";;
446                         --with-nforenum=*)            with_nforenum="$optarg";;
448                         --without-grfcodec)           with_grfcodec="0";;
449                         --with-grfcodec)              with_grfcodec="2";;
450                         --with-grfcodec=*)            with_grfcodec="$optarg";;
452                         --without-osx-sysroot)        with_osx_sysroot="0";;
453                         --with-osx-sysroot)           with_osx_sysroot="2";;
454                         --with-osx-sysroot=*)         with_osx_sysroot="$optarg";;
456                         --without-application-bundle) with_application_bundle="0";;
457                         --with-application-bundle)    with_application_bundle="1";;
458                         --with-application-bundle=*)  with_application_bundle="$optarg";;
460                         --without-threads)            with_threads="0";;
461                         --with-threads)               with_threads="1";;
462                         --with-threads=*)             with_threads="$optarg";;
464                         --without-sse)                with_sse="0";;
465                         --with-sse)                   with_sse="1";;
466                         --with-sse=*)                 with_sse="$optarg";;
468                         CC=* | --CC=*)                CC="$optarg";;
469                         CXX=* | --CXX=*)              CXX="$optarg";;
470                         CFLAGS=* | --CFLAGS=*)        CFLAGS="$optarg";;
471                         CXXFLAGS=* | --CXXFLAGS=*)    CXXFLAGS="$optarg";;
472                         LDFLAGS=* | --LDFLAGS=*)      LDFLAGS="$optarg";;
473                         CFLAGS_BUILD=* | --CFLAGS_BUILD=* | --CFLAGS-BUILD=*)     CFLAGS_BUILD="$optarg";;
474                         CXXFLAGS_BUILD=* | --CXXFLAGS_BUILD=* | --CXXFLAGS-BUILD=*) CXXFLAGS_BUILD="$optarg";;
475                         LDFLAGS_BUILD=* | --LDFLAGS_BUILD=* | --LDFLAGS-BUILD=*)   LDFLAGS_BUILD="$optarg";;
476                         PKG_CONFIG_PATH=* | --PKG_CONFIG_PATH=* | --PKG-CONFIG-PATH=*) PKG_CONFIG_PATH="$optarg";;
477                         PKG_CONFIG_LIBDIR=* | --PKG_CONFIG_LIBDIR=* | --PKG-CONFIG-LIBDIR=*) PKG_CONFIG_LIBDIR="$optarg";;
479                         --ignore-extra-parameters)    ignore_extra_parameters="1";;
481                         --* | -*)
482                                 if [ "$ignore_extra_parameters" = "0" ]; then
483                                         log 1 "Unknown option $p"
484                                         exit 1
485                                 else
486                                         log 1 "Unknown option $p ignored"
487                                 fi
488                                 ;;
489                 esac
490         done
492         if [ -n "$prev_p" ]; then
493                 log 1 "configure: error: missing argument to --$prev_p"
494                 exit 1
495         fi
497         # Clean the logfile
498         echo "" > $config_log
499         log 2 "Invocation: $0 $*"
502 save_params() {
503         # Here we save all params, so we can later on do an exact redo of this
504         #  configuration, without having the user to re-input stuff
506         echo "Running configure with following options:" >> $config_log
507         echo "" >> $config_log
509         configure="$CONFIGURE_EXECUTABLE --ignore-extra-parameters"
510         for p in $save_params_array; do
511                 eval "v=\"\$$p\""
512                 p=`echo "$p" | sed 's@_@-@g;s@\n@@g;s@ @\\ @g'`
513                 # Only save those params that aren't empty
514                 configure="$configure --$p=\"$v\""
515         done
517         echo "$configure" >> $config_log
518         echo "$configure" > config.cache
519         echo "" >> $config_log
522 # Export a variable so tools like pkg-config can see it when invoked.
523 # If the variable contains an empty string then unset it.
524 # $1 - name of the variable to export or unset
525 export_or_unset() {
526         eval local value=\$$1
527         if [ -n "$value" ]; then
528                 export $1;
529                 log 2 "using $1=$value";
530         else
531                 unset $1;
532                 log 2 "not using $1";
533         fi
536 check_params() {
537         # Some params want to be in full uppercase, else they might not work as
538         # expected.. fix that here
540         endian=`echo $endian | tr '[a-z]' '[A-Z]'`
541         os=`echo $os | tr '[a-z]' '[A-Z]'`
542         cpu_type=`echo $cpu_type | tr '[a-z]' '[A-Z]'`
544         # Export some variables to be used by pkg-config
545         #
546         # PKG_CONFIG_LIBDIR variable musn't be set if we are not willing to
547         # override the default pkg-config search path, it musn't be an empty
548         # string. If the variable is empty (e.g. when an empty string comes
549         # from config.cache) then unset it. This way the "don't override" state
550         # will be properly preserved when (re)configuring.
551         export_or_unset PKG_CONFIG_PATH
552         export_or_unset PKG_CONFIG_LIBDIR
554         # Check if all params have valid values
556         # Endian only allows AUTO, LE and, BE
557         if ! echo $endian | egrep -q '^(AUTO|LE|BE|PREPROCESSOR)$'; then
558                 log 1 "configure: error: invalid option --endian=$endian"
559                 log 1 " Available options are: --endian=[AUTO|LE|BE]"
560                 exit 1
561         fi
562         if [ "$endian" = "PREPROCESSOR" ] && [ "$os" != "OSX" ]; then
563                 log 1 "configure: error: invalid option --endian=$endian"
564                 log 1 " PREPROCESSOR is only available for OSX"
565                 exit 1
566         fi
567         # OS only allows DETECT, UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, MORPHOS, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
568         if ! echo $os | egrep -q '^(DETECT|UNIX|OSX|FREEBSD|DRAGONFLY|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP)$'; then
569                 log 1 "configure: error: invalid option --os=$os"
570                 log 1 " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|DRAGONFLY|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP]"
571                 exit 1
572         fi
573         # cpu_type can be either 32 or 64
574         if ! echo $cpu_type | egrep -q '^(32|64|DETECT)$'; then
575                 log 1 "configure: error: invalid option --cpu-type=$cpu_type"
576                 log 1 " Available options are: --cpu-type[=DETECT|32|64]"
577                 exit 1
578         fi
579         # enable_debug should be between 0 and 4
580         if ! echo $enable_debug | egrep -q '^[0123]$'; then
581                 log 1 "configure: error: invalid option --enable-debug=$enable_debug"
582                 log 1 " Available options are: --enable-debug[=0123]"
583                 exit 1
584         fi
586         # enable_desync_debug should be between 0 and 3
587         if ! echo $enable_desync_debug | egrep -q '^[012]$'; then
588                 log 1 "configure: error: invalid option --enable-desync-debug=$enable_desync_debug"
589                 log 1 " Available options are: --enable-desync-debug[=012]"
590                 exit 1
591         fi
593         detect_awk
595         detect_os
597         check_build
598         check_host
600         # Check for universal builds; they only make sense for OSX, so fail if enabled for another OS
601         if [ "$enable_universal" = "0" ]; then
602                 log 1 "checking universal build... no"
603         else
604                 if [ "$os" != "OSX" ]; then
605                         log 1 "configure: error: --enable-universal only works on OSX"
606                         exit 1
607                 fi
608                 log 1 "checking universal build... yes, for: $enable_universal"
609         fi
611         # Already detected by check_build
612         log 1 "checking build cc... $cc_build"
613         log 1 "checking host cc... $cc_host"
615         check_cxx_build
616         check_cxx_host
617         check_windres
618         if [ "$enable_strip" != "0" ]; then
619                 check_strip
620         else
621                 log 1 "checking strip... disabled"
622         fi
623         check_lipo
625         if [ "$enable_builtin_depend" != "0" ]; then
626                 log 1 "checking builtin depend... yes"
627                 makedepend="\$(SRC_OBJS_DIR)/\$(DEPEND)"
628         else
629                 log 1 "checking builtin depend... no"
630         fi
632         check_makedepend
633         detect_cputype
634         detect_sse_capable_architecture
636         if [ "$enable_static" = "1" ]; then
637                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "DOS" ]; then
638                         enable_static="2"
639                 else
640                         enable_static="0"
641                 fi
642         fi
644         if [ "$enable_static" != "0" ]; then
645                 log 1 "checking static... yes"
647                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "OSX" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "DOS" ]; then
648                         log 1 "WARNING: static is only known to work on Windows, DOS, MacOSX and MorphOS"
649                         log 1 "WARNING: use static at your own risk on this platform"
651                         sleep 5
652                 fi
653         else
654                 log 1 "checking static... no"
655         fi
657         if [ "$enable_unicode" = "1" ]; then
658                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "DOS" ]; then
659                         enable_unicode="2"
660                 else
661                         enable_unicode="0"
662                 fi
663         fi
665         if [ "$enable_unicode" != "0" ]; then
666                 log 1 "checking unicode... yes"
667         else
668                 log 1 "checking unicode... no"
669         fi
671         # Show what we configured
672         if [ "$enable_debug" = "0" ]; then
673                 log 1 "using debug level... no"
674         elif [ "$enable_profiling" != "0" ]; then
675                 log 1 "using debug level... profiling (debug level $enable_debug)"
676         else
677                 log 1 "using debug level... level $enable_debug"
678         fi
680         if [ "$enable_desync_debug" = "0" ]; then
681                 log 1 "using desync debug level... no"
682         else
683                 log 1 "using desync debug level... level $enable_desync_debug"
684                 log 1 "WARNING: desync debug functions slow down the game considerably."
685                 log 1 "WARNING: use only when you are instructed to do so"
686                 log 1 "         or when you know what you are doing."
688                 sleep 5
689         fi
691         if [ "$enable_lto" != "0" ]; then
692                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
693                 if $cxx_build -dumpspecs 2>&1 | grep -q '\%{flto' || $cxx_build -help ipo 2>&1 | grep -q '\-ipo'; then
694                         log 1 "using link time optimization... yes"
695                 else
696                         enable_lto="0"
697                         log 1 "using link time optimization... no"
698                         log 1 "WARNING: you selected link time optimization but it is not found."
699                         sleep 5
700                 fi
701         else
702                 log 1 "using link time optimization... no"
703         fi
706         if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
707                 if [ "$with_osx_sysroot" = "1" ]; then
708                         with_osx_sysroot="0"
710                         log 1 "checking OSX sysroot... not OSX, skipping"
711                 else
712                         log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
713                         exit 1
714                 fi
715         fi
717         if [ "$with_osx_sysroot" != "0" ]; then
718                 if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
719                         # Sysroot manually specified? Check for usability
720                         log 1 "checking OSX sysroot... $with_osx_sysroot"
721                         if ! check_osx_sdk "$with_osx_sysroot"; then
722                                 log 1 "Passed sysroot not found/not functional"
723                                 exit 1
724                         fi
725                 else
726                         # If autodetect and no universal, use system default
727                         if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
728                                 log 1 "checking OSX sysroot... no (use system default)"
729                         else
730                                 log 1 "checking OSX sysroot... automatically"
731                                 detect_osx_sdk
732                         fi
733                 fi
735                 if [ -n "$osx_sdk_path" ]; then
736                         if [ "$enable_universal" != "0" ]; then
737                                 if [ -z "$osx_sdk_104_path" ]; then
738                                         log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
739                                         log 1 "WARNING: binary will only run on OSX 10.5 or later"
740                                         osx_sdk_104_path="$osx_sdk_path"
741                                 fi
742                                 OSX_SYSROOT="-isysroot $osx_sdk_104_path"
743                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
744                         else
745                                 OSX_SYSROOT="-isysroot $osx_sdk_path"
746                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
747                         fi
748                 fi
749         else
750                 if [ "$os" = "OSX" ]; then
751                         log 1 "checking OSX sysroot... no (use system default)"
752                 fi
753         fi
755         detect_allegro
756         detect_sdl
757         detect_cocoa
759         if [ "$enable_dedicated" != "0" ]; then
760                 log 1 "checking GDI video driver... dedicated server, skipping"
761                 log 1 "checking dedicated... found"
763                 if [ "$enable_network" = "0" ]; then
764                         log 1 "configure: error: building a dedicated server without network support is pointless"
765                         exit 1
766                 fi
767         else
768                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
769                         log 1 "checking GDI video driver... found"
770                 else
771                         log 1 "checking GDI video driver... not Windows, skipping"
772                 fi
774                 if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
775                         log 1 "configure: error: no video driver development files found"
776                         log 1 " If you want a dedicated server use --enable-dedicated as parameter"
777                         exit 1
778                 else
779                         log 1 "checking dedicated... not selected"
780                 fi
781         fi
783         if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
784                 log 1 "checking console application... not Windows, skipping"
785         elif [ "$enable_console" = "1" ] && [ "$enable_dedicated" != "0" ]; then
786                 log 1 "checking console application... dedicated server, enabled"
787                 enable_console="2"
788         elif [ "$enable_console" = "1" ]; then
789                 log 1 "checking console application... disabled (only used when forced)"
790                 enable_console="0"
791         elif [ "$enable_console" = "0" ]; then
792                 log 1 "checking console application... disabled"
793         else
794                 log 1 "checking console application... enabled"
795         fi
797         if [ "$enable_network" = "1" ] && [ "$os" = "DOS" ]; then
798                 log 1 "checking network... DOS, skipping"
799                 enable_network=0
800         elif [ "$enable_network" != "0" ]; then
801                 log 1 "checking network... found"
802         else
803                 log 1 "checking network... disabled"
804         fi
806         log 1 "checking squirrel... found"
807         SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"
809         if [ "$enable_translator" != "0" ]; then
810                 log 1 "checking translator... debug"
811                 # -t shows TODO items, normally they are muted
812                 strgen_flags="-t"
813         else
814                 log 1 "checking translator... no"
815                 strgen_flags=""
816         fi
818         if [ "$enable_assert" != "0" ]; then
819                 log 1 "checking assert... enabled"
820         else
821                 log 1 "checking assert... disabled"
822         fi
824         pre_detect_with_zlib=$with_zlib
825         detect_zlib
827         if [ "$with_zlib" = "0" ] || [ -z "$zlib-config" ]; then
828                 log 1 "WARNING: zlib was not detected or disabled"
829                 log 1 "WARNING: OpenTTD doesn't require zlib, but it does mean that many features"
830                 log 1 "WARNING: (like loading most old savegames/scenarios, loading heightmaps,"
831                 log 1 "WARNING: using PNG, or using fonts, ...) will be disabled."
832                 if [ "$pre_detect_with_zlib" = "0" ]; then
833                         log 1 "WARNING: We strongly suggest you to install zlib."
834                 else
835                         log 1 "configure: error: no zlib detected"
836                         log 1 " If you want to compile without zlib use --without-zlib as parameter"
837                         exit
838                 fi
839         fi
841         pre_detect_with_lzma=$with_lzma
842         detect_lzma
844         if [ "$with_lzma" = "0" ] || [ -z "$lzma_config" ]; then
845                 log 1 "WARNING: lzma was not detected or disabled"
846                 log 1 "WARNING: OpenTTD doesn't require lzma, but it does mean that many features"
847                 log 1 "WARNING: (like loading most savegames/scenarios and joining most servers)"
848                 log 1 "WARNING: will be disabled."
849                 if [ "$pre_detect_with_lzma" = "0" ]; then
850                         log 1 "WARNING: We strongly suggest you to install liblzma."
851                         log 1 "configure: error: no liblzma detected"
852                 else
853                         log 1 " If you want to compile without lzma use --without-lzma as parameter"
854                         exit
855                 fi
856         fi
858         pre_detect_with_lzo2=$with_lzo2
859         detect_lzo2
861         if [ "$with_lzo2" = "0" ] || [ -z "$lzo2" ]; then
862                 log 1 "WARNING: liblzo2 was not detected or disabled"
863                 log 1 "WARNING: OpenTTD doesn't require liblzo2, but it does mean that"
864                 log 1 "WARNING: loading old savegames/scenarios will be disabled."
865                 if [ "$pre_detect_with_lzo2" = "0" ]; then
866                         log 1 "WARNING: We strongly suggest you to install liblzo2."
867                 else
868                         log 1 "configure: error: no liblzo2 detected"
869                         log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
870                         exit
871                 fi
872         fi
874         detect_xdg_basedir
875         detect_png
876         detect_freetype
877         detect_fontconfig
878         detect_icu_layout
879         detect_icu_sort
880         detect_pspconfig
881         detect_libtimidity
883         if [ "$with_direct_music" != "0" ]; then
884                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
885                         if [ "$with_direct_music" != "1" ]; then
886                                 log 1 "configure: error: direct-music is only supported on Win32 targets"
887                                 exit 1
888                         fi
889                         with_direct_music="0"
891                         log 1 "checking direct-music... not Windows, skipping"
892                 else
893                         check_direct_music
894                 fi
895         fi
897         detect_sort
899         if [ "$os" = "OSX" ] && [ "$endian" = "AUTO" ]; then
900                 endian="PREPROCESSOR"
901         fi
903         log 1 "checking endianness... $endian"
905         # Suppress language errors when there is a version defined, indicating a release
906         #  It just isn't pretty if any release produces warnings in the languages.
907         if [ -f "$ROOT_DIR/version" ]; then
908                 lang_suppress="yes"
909                 log 1 "suppress language errors... yes"
910         else
911                 lang_suppress=""
912                 log 1 "suppress language errors... no"
913         fi
915         if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
916                 if [ "$os" = "MORPHOS" ]; then
917                         strip_arg="--strip-all --strip-unneeded --remove-section .comment"
918                 elif [ "$os" = "OSX" ]; then
919                         strip_arg=""
920                 elif [ "$os" = "OS2" ]; then
921                         strip_arg=""
922                         # OS2 uses strip via gcc, because it needs to be feed to emxbind
923                         LDFLAGS="$LDFLAGS -s"
924                 elif [ "$os" = "SUNOS" ]; then
925                         # The GNU strip does know -s, the non-GNU doesn't
926                         #  So try to detect it (in a bit of an ugly way)
927                         strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
928                 else
929                         strip_arg="-s"
930                 fi
932                 log 1 "checking stripping... $strip $strip_arg"
933         else
934                 strip=""
935                 log 1 "checking stripping... skipped"
936         fi
938         if [ "$with_distcc" = "0" ]; then
939                 log 1 "checking distcc... no"
940         elif [ "$with_distcc" = "1" ]; then
941                 with_distcc="0"
943                 log 1 "checking distcc... no (only used when forced)"
944         elif [ "$with_distcc" = "2" ]; then
945                 distcc="distcc"
946         else
947                 distcc="$with_distcc"
948         fi
949         if [ "$with_distcc" != "0" ]; then
950                 res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
951                 if [ "$res" != "distcc" ]; then
952                         distcc=""
953                         log 1 "checking distcc... no"
954                         if [ "$with_distcc" = "2" ]; then
955                                 log 1 "configure: error: no distcc detected, but was forced to be used"
956                                 exit 1
957                         fi
958                         if [ "$with_distcc" != "1" ]; then
959                                 log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
960                                 exit 1
961                         fi
962                 fi
964                 log 1 "checking distcc... $distcc"
965         fi
967         if [ "$with_ccache" = "0" ]; then
968                 log 1 "checking ccache... no"
969         elif [ "$with_ccache" = "1" ]; then
970                 with_ccache="0"
972                 log 1 "checking ccache... no (only used when forced)"
973         elif [ "$with_ccache" = "2" ]; then
974                 ccache="ccache"
975         else
976                 ccache="$with_ccache"
977         fi
978         if [ "$with_ccache" != "0" ]; then
979                 res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
980                 if [ "$res" != "ccache" ]; then
981                         ccache=""
982                         log 1 "checking ccache... no"
983                         if [ "$with_ccache" = "2" ]; then
984                                 log 1 "configure: error: no ccache detected, but was forced to be used"
985                                 exit 1
986                         fi
987                         if [ "$with_ccache" != "1" ]; then
988                                 log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
989                                 exit 1
990                         fi
991                 fi
993                 log 1 "checking ccache... $ccache"
994         fi
996         detect_grfcodec
997         detect_nforenum
999         if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
1000                 log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
1001                 nforenum=""
1002         fi
1004         if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
1005                 log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
1006                 grfcodec=""
1007         fi
1009         if [ "$os" = "DOS" ]; then
1010                 with_threads="0"
1011         fi
1013         if [ "$os" != "OSX" ] && [ "$with_application_bundle" != "0" ]; then
1014                 if [ "$with_application_bundle" = "1" ]; then
1015                         with_application_bundle="0"
1017                         log 1 "checking OSX application bundle... not OSX, skipping"
1018                 else
1019                         log 1 "configure: error: --with-application-bundle only works if OSX is the target"
1020                         exit 1
1021                 fi
1022         fi
1024         if [ "$os" = "OSX" ] && [ "$with_application_bundle" = "1" ]; then
1025                 OSXAPP="OpenTTD.app"
1026         else
1027                 OSXAPP=""
1028         fi
1030         if [ "$os" = "OSX" ]; then
1031                 # Test on ppc970 (G5) - we can optimize there
1033                 if [ "$enable_osx_g5" != "0" ]; then
1034                         log 1 "detecting ppc970 (G5)... yes (forced)"
1035                 else
1036                         # First, are we a real OSX system, else we can't detect it
1037                         native=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | grep darwin`
1038                         # If $host doesn't match $build , we are cross-compiling
1039                         if [ -n "$native" ] && [ "$build" = "$host" ]; then
1040                                 $cxx_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
1041                                 res=`./G5_detector`
1042                                 rm -f G5_detector
1043                                 if [ -n "$res" ]; then
1044                                         # This is G5, add flags for it
1045                                         enable_osx_g5="2"
1047                                         log 1 "detecting ppc970 (G5)... yes"
1048                                 else
1049                                         enable_osx_g5="0"
1051                                         log 1 "detecting ppc970 (G5)... no"
1052                                 fi
1053                         else
1054                                 enable_osx_g5="0"
1056                                 log 1 "detecting ppc970 (G5)... no (cross-compiling)"
1057                         fi
1058                 fi
1059         else
1060                 if [ "$enable_osx_g5" != "0" ]; then
1061                         log 1 "configure: error: ppc970 (OSX G5) selected, but not compiling for OSX"
1062                         log 1 "configure: error: either select OSX as OS, or deselect ppc970"
1064                         exit 1
1065                 fi
1066         fi
1068         if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
1069                 log 1 "checking revision... svn detection"
1070         elif [ -d "$ROOT_DIR/../.svn" ] && [ -n "`svn help 2>/dev/null`" ] && LC_ALL=C svn info $ROOT_DIR/.. | grep -q '^URL:.*tags$'; then
1071                 # subversion changed its behaviour; now not all folders have a .svn folder,
1072                 # but only the root folder. Since making tags requires a (sparse) checkout
1073                 # of the tags folder, the folder of the tag does not have a .svn folder
1074                 # anymore and this fails to detect the subversion repository checkout.
1075                 log 1 "checking revision... svn detection (tag)"
1076         elif [ -e "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
1077                 log 1 "checking revision... git detection"
1078         elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`HGPLAIN= hg help 2>/dev/null`" ]; then
1079                 log 1 "checking revision... hg detection"
1080         elif [ -f "$ROOT_DIR/.ottdrev" ]; then
1081                 log 1 "checking revision... source tarball"
1082         else
1083                 log 1 "checking revision... no detection"
1084                 log 1 "WARNING: there is no means to determine the version."
1085                 log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenTTD."
1086                 log 1 "WARNING: you can only join game servers that have been compiled without"
1087                 log 1 "WARNING:   version detection."
1088                 log 1 "WARNING: there is a great chance you desync."
1089                 log 1 "WARNING: USE WITH CAUTION!"
1091                 sleep 5
1092         fi
1094         if [ "$doc_dir" = "1" ]; then
1095                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1096                         doc_dir="share/doc/openttd"
1097                 else
1098                         doc_dir="$data_dir/docs"
1099                 fi
1100         else
1101                 doc_dir="`echo $doc_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1102         fi
1104         if [ "$icon_theme_dir" = "1" ]; then
1105                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1106                         icon_theme_dir="share/icons/hicolor"
1107                 else
1108                         icon_theme_dir=""
1109                 fi
1110         else
1111                 icon_theme_dir="`echo $icon_theme_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1112         fi
1114         if [ "$personal_dir" = "1" ]; then
1115                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ] || [ "$os" = "DOS" ] || [ "$os" = "HAIKU" ]; then
1116                         personal_dir="OpenTTD"
1117                 elif [ "$os" = "OSX" ]; then
1118                         personal_dir="Documents/OpenTTD"
1119                 else
1120                         personal_dir=".openttd"
1121                 fi
1122         else
1123                 personal_dir="`echo $personal_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1124         fi
1126         if [ "$shared_dir" = "1" ]; then
1127                 # we are using default values
1128                 if [ "$os" = "OSX" ]; then
1129                         shared_dir="/Library/Application\\\\ Support/OpenTTD"
1130                 else
1131                         shared_dir=""
1132                 fi
1133         else
1134                 shared_dir="`echo $shared_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1135         fi
1137         if [ "$man_dir" = "1" ]; then
1138                 # add manpage on UNIX systems
1139                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OSX" ]; then
1140                         man_dir="share/man/man6"
1141                 else
1142                         man_dir=""
1143                 fi
1144         else
1145                 man_dir="`echo $man_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1146         fi
1148         if [ "$menu_dir" = "1" ]; then
1149                 # add a freedesktop menu item only for some UNIX systems
1150                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1151                         menu_dir="share/applications"
1152                 else
1153                         menu_dir=""
1154                 fi
1155         else
1156                 menu_dir="`echo $menu_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1157         fi
1159         detect_iconv
1161         if [ -n "$personal_dir" ]
1162         then
1163                 log 1 "personal home directory... $personal_dir"
1164         else
1165                 log 1 "personal home directory... none"
1166         fi
1168         if [ -n "$shared_dir" ]
1169         then
1170                 log 1 "shared data directory... $shared_dir"
1171         else
1172                 log 1 "shared data directory... none"
1173         fi
1175         if [ -n "$install_dir" ]
1176         then
1177                 log 1 "installation directory... $install_dir"
1178         else
1179                 log 1 "installation directory... none"
1180         fi
1182         if [ -n "$icon_theme_dir" ]
1183         then
1184                 log 1 "icon theme directory... $icon_theme_dir"
1185         else
1186                 log 1 "icon theme directory... none"
1187         fi
1189         if [ -n "$man_dir" ]
1190         then
1191                 log 1 "manual page directory... $man_dir"
1192         else
1193                 log 1 "manual page directory... none"
1194         fi
1196         if [ -n "$menu_dir" ]
1197         then
1198                 log 1 "menu item directory... $menu_dir"
1199         else
1200                 log 1 "menu item directory... none"
1201         fi
1204 make_compiler_cflags() {
1205         # Params:
1206         # $1 - compiler
1207         # $2 - name of the cflags variable
1208         # $3 - name of the cxxflags variable
1209         # $4 - name of the ldflags variable
1210         # $5 - name of the features variable
1212         eval eval "flags=\\\$$2"
1213         eval eval "cxxflags=\\\$$3"
1214         eval eval "ldflags=\\\$$4"
1215         eval eval "features=\\\$$5"
1217         if [ `basename $1 | cut -c 1-3` = "icc" ]; then
1218                 # Enable some things only for certain ICC versions
1219                 cc_version=`$1 -dumpversion | cut -c 1-4 | sed s@\\\.@@g`
1221                 flags="$flags -rdynamic"
1222                 ldflags="$ldflags -rdynamic"
1224                 if [ -z "$first_time_icc_check" ]; then
1225                         first_time_icc_check=no
1226                         if [ $cc_version -lt 90 ]; then
1227                                 log 1 "WARNING: you seem to be using a very old version of ICC"
1228                                 log 1 "WARNING: OpenTTD hasn't been tested with this version"
1229                                 sleep 5
1230                         elif [ $cc_version -lt 120 ]; then
1231                                 log 1 "WARNING: you seem to be using an unsupported ICC version"
1232                                 log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD"
1233                                 sleep 5
1234                         fi
1235                 fi
1237                 flags="$flags -Wall"
1238                 # remark #111: statement is unreachable
1239                 flags="$flags -wd111"
1240                 # remark #181: argument is incompatible with corresponding format string conversion
1241                 # ICC is very picky about signedness of operands, warnings provided by GCC are enough
1242                 flags="$flags -wd181"
1243                 # remark #271: trailing comma is nonstandard
1244                 flags="$flags -wd271"
1245                 # remark #280: selector expression is constant
1246                 flags="$flags -wd280"
1247                 # remark #304: access control not specified ("public" by default)
1248                 flags="$flags -wd304"
1249                 # remark #383: value copied to temporary, reference to temporary used
1250                 flags="$flags -wd383"
1251                 # remark #444: destructor for base class ... is not virtual
1252                 flags="$flags -wd444"
1253                 # remark #593: variable ... was set but never used
1254                 flags="$flags -wd593"
1255                 # warning #654: overloaded virtual function ... is only partially overridden in class ...
1256                 flags="$flags -wd654"
1257                 # remark #810: conversion from ... to ... may lose significant bits
1258                 flags="$flags -wd810"
1259                 # remark #869: parameter ... was never referenced
1260                 flags="$flags -wd869"
1261                 # warning #873: function ... ::operator new ... has no corresponding operator delete ...
1262                 flags="$flags -wd873"
1263                 # remark #981: operands are evaluated in unspecified order
1264                 flags="$flags -wd981"
1265                 # remark #1418: external function definition with no prior declaration
1266                 flags="$flags -wd1418"
1267                 # remark #1419: external declaration in primary source file
1268                 flags="$flags -wd1419"
1269                 # remark #1572: floating-point equality and inequality
1270                 flags="$flags -wd1572"
1271                 # remark #1599: declaration hides variable/parameter ...
1272                 flags="$flags -wd1599"
1273                 # remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
1274                 flags="$flags -wd1720"
1276                 if [ $cc_version -lt 110 ]; then
1277                         # warns about system headers with recent glibc:
1278                         # warning #1292: attribute "__nonnull__" ignored
1279                         flags="$flags -wd1292"
1280                 fi
1282                 if [ $cc_version -ge 100 ]; then
1283                         # warning #1899: multicharacter character literal (potential portability problem)
1284                         flags="$flags -wd1899"
1285                         # vec report defaults to telling where it did loop vectorisation, which is not very important
1286                         flags="$flags -vec-report=0 "
1287                 fi
1289                 if [ $cc_version -ge 110 ]; then
1290                         # remark #2259: non-pointer conversion from ... to ... may lose significant bits
1291                         flags="$flags -wd2259"
1292                         # Use c++0x mode so static_assert() is available
1293                         cxxflags="$cxxflags -std=c++0x"
1294                 fi
1296                 if [ "$enable_lto" != "0" ] && $1 -help ipo | grep -q '\-ipo'; then
1297                         # Use IPO (only if we see IPO exists and is requested)
1298                         flags="$flags -ipo"
1299                         features="$features lto"
1300                 fi
1301         elif basename $1 | grep -q 'clang'; then
1302                 # Enable some things only for certain clang versions
1303                 cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
1305                 # aliasing rules are not held in openttd code
1306                 flags="$flags -fno-strict-aliasing"
1308                 # -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
1309                 # -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
1310                 flags="$flags -Wall -W -Wextra"
1312                 # warning: unused parameter '...'
1313                 flags="$flags -Wno-unused-parameter"
1315                 # warning: expression result unused
1316                 flags="$flags -Wno-unused-value"
1318                 # warning: multi-character character constant
1319                 flags="$flags -Wno-multichar"
1321                 # warning: explicitly assigning a variable of type '...' to itself
1322                 # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
1323                 flags="$flags -Wno-self-assign"
1325                 if [ "$cc_version" -lt "30" ]; then
1326                         # warning: equality comparison with extraneous parentheses
1327                         flags="$flags -Wno-parentheses"
1328                         # warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
1329                         flags="$flags -Wno-sign-compare"
1330                 fi
1332                 if [ "$cc_version" -ge "30" ]; then
1333                         # warning: equality comparison with extraneous parentheses
1334                         # this warning could be useful, but it warns about code in squirrel
1335                         flags="$flags -Wno-parentheses-equality"
1336                 fi
1338                 if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
1339                         # ccache and distcc run separate preprocess and compile passes,
1340                         # both are fed with the same CFLAGS. Unfortunately, clang
1341                         # complains about -I when compiling preprocessed files:
1342                         # "clang: warning: argument unused during compilation: '-I /usr/include'"
1343                         flags="$flags -Qunused-arguments"
1344                 fi
1346                 if [ "$enable_assert" -eq "0" ]; then
1347                         # do not warn about unused variables when building without asserts
1348                         flags="$flags -Wno-unused-variable"
1349                 fi
1351                 if [ "$cc_version" -ge "33" ]; then
1352                         # clang completed C++11 support in version 3.3
1353                         flags="$flags -std=c++11"
1354                 fi
1356                 # rdynamic is used to get useful stack traces from crash reports.
1357                 ldflags="$ldflags -rdynamic"
1358         else
1359                 # Enable some things only for certain GCC versions
1360                 # cc_version = major_version * 100 + minor_version
1361                 # For example: "3.3" -> 303, "4.9.2" -> 409, "6" -> 600, "23.5" -> 2305
1362                 cc_version=`$1 -dumpversion | $awk -F . '{printf "%d%02d", $1, $2}'`
1364                 if [ $cc_version -lt 303 ]; then
1365                         log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
1366                         exit 1
1367                 fi
1369                 flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
1370                 flags="$flags -Wwrite-strings -Wpointer-arith"
1371                 flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
1372                 flags="$flags -Wformat=2 -Wformat-security"
1374                 if [ $enable_assert -eq 0 ]; then
1375                         # Do not warn about unused variables when building without asserts
1376                         flags="$flags -Wno-unused-variable"
1377                         if [ $cc_version -ge 406 ]; then
1378                                 # GCC 4.6 gives more warnings, disable them too
1379                                 flags="$flags -Wno-unused-but-set-variable"
1380                                 flags="$flags -Wno-unused-but-set-parameter"
1381                         fi
1382                 fi
1384                 if [ $cc_version -ge 304 ]; then
1385                         # Warn when a variable is used to initialise itself:
1386                         # int a = a;
1387                         flags="$flags -Winit-self"
1388                 fi
1390                 if [ $cc_version -ge 400 ]; then
1391                         # GCC 4.0+ complains about that we break strict-aliasing.
1392                         #  On most places we don't see how to fix it, and it doesn't
1393                         #  break anything. So disable strict-aliasing to make the
1394                         #  compiler all happy.
1395                         flags="$flags -fno-strict-aliasing"
1396                         # Warn about casting-out 'const' with regular C-style cast.
1397                         #  The preferred way is const_cast<>() which doesn't warn.
1398                         flags="$flags -Wcast-qual"
1399                 fi
1401                 if [ $cc_version -ge 402 ]; then
1402                         # GCC 4.2+ automatically assumes that signed overflows do
1403                         # not occur in signed arithmetics, whereas we are not
1404                         # sure that they will not happen. It furthermore complains
1405                         # about its own optimized code in some places.
1406                         flags="$flags -fno-strict-overflow"
1407                         # GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
1408                         # Enable it in order to be consistent with older GCC versions.
1409                         flags="$flags -Wnon-virtual-dtor"
1410                 fi
1412                 if [ $cc_version -ge 403 ] && [ $cc_version -lt 600 ]; then
1413                         # Use gnu++0x mode so static_assert() is available.
1414                         # Don't use c++0x, it breaks mingw (with gcc 4.4.0).
1415                         cxxflags="$cxxflags -std=gnu++0x"
1416                 fi
1418                 if [ $cc_version -eq 405 ]; then
1419                         # Prevent optimisation supposing enums are in a range specified by the standard
1420                         # For details, see http://gcc.gnu.org/PR43680
1421                         flags="$flags -fno-tree-vrp"
1422                 fi
1424                 if [ $cc_version -eq 407 ]; then
1425                         # Disable -Wnarrowing which gives many warnings, such as:
1426                         # warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
1427                         # They are valid according to the C++ standard, but useless.
1428                         cxxflags="$cxxflags -Wno-narrowing"
1429                 fi
1431                 if [ $cc_version -ge 407 ]; then
1432                         # Disable bogus 'attempt to free a non-heap object' warning
1433                         flags="$flags -Wno-free-nonheap-object"
1434                 fi
1436                 if [ $cc_version -ge 600 ]; then
1437                         # -flifetime-dse=2 (default since GCC 6) doesn't play
1438                         # well with our custom pool item allocator
1439                         cxxflags="$cxxflags -flifetime-dse=1 -std=gnu++14"
1440                 fi
1442                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
1443                 if [ "$enable_lto" != "0" ] && $1 -dumpspecs | grep -q '\%{flto'; then
1444                         # Use LTO only if we see LTO exists and is requested
1445                         if [ $cc_version -lt 406 ]; then
1446                                 flags="$flags -flto"
1447                         else
1448                                 flags="$flags -flto=jobserver"
1449                         fi
1450                         ldflags="$ldflags -fwhole-program"
1451                         features="$features lto"
1452                 fi
1454                 if $1 -dumpspecs | grep -q rdynamic; then
1455                         # rdynamic is used to get useful stack traces from crash reports.
1456                         flags="$flags -rdynamic"
1457                         ldflags="$ldflags -rdynamic"
1458                 fi
1459         fi
1461         eval "$2=\"$flags\""
1462         eval "$3=\"$cxxflags\""
1463         eval "$4=\"$ldflags\""
1464         eval "$5=\"$features\""
1467 make_cflags_and_ldflags() {
1468         # General CFlags for BUILD
1469         CFLAGS_BUILD="$CFLAGS_BUILD"
1470         # Special CXXFlags for BUILD
1471         CXXFLAGS_BUILD="$CXXFLAGS_BUILD"
1472         # LDFLAGS for BUILD
1473         LDFLAGS_BUILD="$LDFLAGS_BUILD"
1474         # FEATURES for BUILD (lto)
1475         FEATURES_BUILD=""
1476         # General CFlags for HOST
1477         CFLAGS="$CFLAGS"
1478         # Special CXXFlags for HOST
1479         CXXFLAGS="$CXXFLAGS"
1480         # Libs to compile. In fact this is just LDFLAGS
1481         LIBS="-lstdc++"
1482         # LDFLAGS used for HOST
1483         LDFLAGS="$LDFLAGS"
1484         # FEATURES for HOST (lto)
1485         FEATURES=""
1487         make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "CXXFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
1488         make_compiler_cflags "$cc_host" "CFLAGS" "CXXFLAGS" "LDFLAGS" "FEATURES"
1490         CFLAGS="$CFLAGS -D$os"
1491         CFLAGS_BUILD="$CFLAGS_BUILD -D$os"
1493         if [ "$enable_debug" = "0" ]; then
1494                 # No debug, add default stuff
1495                 OBJS_SUBDIR="release"
1496                 if [ "$os" = "MORPHOS" ]; then
1497                         CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
1498                         LDFLAGS="$LDFLAGS -noixemul"
1499                 fi
1501                 if [ "$enable_profiling" = "0" ]; then
1502                         # -fomit-frame-pointer and -pg do not go well together (gcc errors they are incompatible)
1503                         CFLAGS="-fomit-frame-pointer $CFLAGS"
1504                 fi
1505                 CFLAGS="-O2 $CFLAGS"
1506         else
1507                 OBJS_SUBDIR="debug"
1509                 # Each debug level reduces the optimization by a bit
1510                 if [ $enable_debug -ge 1 ]; then
1511                         CFLAGS="$CFLAGS -g -D_DEBUG"
1512                         if [ "$os" = "PSP" ]; then
1513                                 CFLAGS="$CFLAGS -G0"
1514                         fi
1515                 fi
1516                 if [ $enable_debug -ge 2 ]; then
1517                         CFLAGS="$CFLAGS -fno-inline"
1518                 fi
1519                 if [ $enable_debug -ge 3 ]; then
1520                         CFLAGS="$CFLAGS -O0"
1521                 else
1522                         CFLAGS="$CFLAGS -O2"
1523                 fi
1524         fi
1526         if [ $enable_debug -le 2 ]; then
1527                 if basename "$cc_host" | grep -q "gcc"; then
1528                         # Define only when compiling with GCC. Some GLIBC versions use GNU
1529                         # extensions in a way that breaks build with at least ICC.
1530                         # This requires -O1 or more, so debug level 3 (-O0) is excluded.
1531                         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
1532                 fi
1534                 if basename "$cc_build" | grep -q "gcc"; then
1535                         # Just add -O1 to the tools needed for building.
1536                         CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
1537                 fi
1538         fi
1540         if [ "$os" = "OSX" ] && [ $cc_version -eq 400 ]; then
1541                 # Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
1542                 # wrongly optimizing ^= in loops. This disables the failing optimisation.
1543                 CFLAGS="$CFLAGS -fno-expensive-optimizations"
1544         fi
1546         if [ "$enable_profiling" != "0" ]; then
1547                 CFLAGS="$CFLAGS -pg"
1548                 LDFLAGS="$LDFLAGS -pg"
1549         fi
1551         if [ "$with_threads" = "0" ]; then
1552                 CFLAGS="$CFLAGS -DNO_THREADS"
1553         fi
1554         if [ "$with_sse" = "1" ]; then
1555                 CFLAGS="$CFLAGS -DWITH_SSE"
1556         fi
1558         if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
1559                 if [ "$os" = "CYGWIN" ]; then
1560                         flags="$flags -mwin32"
1561                         LDFLAGS="$LDFLAGS -mwin32"
1562                 fi
1563                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1564                         if [ $cc_version -lt 406 ]; then
1565                                 flags="$flags -mno-cygwin"
1566                                 LDFLAGS="$LDFLAGS -mno-cygwin"
1567                         fi
1569                         if [ "$enable_console" != "0" ]; then
1570                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
1571                         else
1572                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
1573                         fi
1575                         LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
1577                         if [ $cc_version -ge 404 ]; then
1578                                 LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
1579                         fi
1580                         if [ $cc_version -ge 407 ]; then
1581                                 CFLAGS="$CFLAGS -mno-ms-bitfields"
1582                         fi
1583                 fi
1584         fi
1586         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
1587                 LIBS="$LIBS -lpthread"
1588         fi
1590         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "MINGW" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ]; then
1591                 LIBS="$LIBS -lc"
1592         fi
1593         if [ "$os" = "WINCE" ]; then
1594                 LIBS="$LIBS -lcoredll -lcorelibc -laygshell -lws2 -e WinMainCRTStartup"
1595         fi
1596         if [ "$os" = "PSP" ]; then
1597                 CFLAGS="$CFLAGS -I`$psp_config -p`/include"
1598                 LDFLAGS="$LDFLAGS -L`$psp_config -p`/lib"
1600                 CFLAGS="$CFLAGS -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150"
1601                 LIBS="$LIBS -D_PSP_FW_VERSION=150 -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lm"
1602         fi
1604         if [ "$os" = "MORPHOS" ]; then
1605                 # -Wstrict-prototypes generates much noise because of system headers
1606                 CFLAGS="$CFLAGS -Wno-strict-prototypes"
1607         fi
1609         if [ "$os" = "OPENBSD" ]; then
1610                 LIBS="$LIBS -pthread"
1611         fi
1613         if [ "$os" = "OSX" ]; then
1614                 LDFLAGS="$LDFLAGS -framework Cocoa"
1616                 # Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
1617                 CFLAGS="$CFLAGS -isystem/opt/local/include"
1619                 if [ "$enable_dedicated" = "0" ] && ([ "$cpu_type" = "32" ] || [ "$enable_universal" != "0" ]); then
1620                         LIBS="$LIBS -framework QuickTime"
1621                 else
1622                         CFLAGS="$CFLAGS -DNO_QUICKTIME"
1623                 fi
1625                 if [ "$enable_universal" = "0" ]; then
1626                         # Universal builds set this elsewhere
1627                         CFLAGS="$OSX_SYSROOT $CFLAGS"
1628                         LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
1629                 fi
1630         fi
1632         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ]; then
1633                 LIBS="$LIBS -lmidi -lbe"
1634         fi
1636         # Most targets act like UNIX, just with some additions
1637         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
1638                 CFLAGS="$CFLAGS -DUNIX"
1639         fi
1640         # And others like Windows
1641         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
1642                 CFLAGS="$CFLAGS -DWIN"
1643         fi
1645         if [ -n "$allegro_config" ]; then
1646                 CFLAGS="$CFLAGS -DWITH_ALLEGRO"
1647                 CFLAGS="$CFLAGS `$allegro_config --cflags`"
1648                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1649                         if [ "$enable_static" != "0" ]; then
1650                                 LIBS="$LIBS `$allegro_config --static --libs`"
1651                         else
1652                                 LIBS="$LIBS `$allegro_config --libs`"
1653                         fi
1654                 fi
1655         fi
1657         if [ -n "$sdl_config" ]; then
1658                 CFLAGS="$CFLAGS -DWITH_SDL"
1659                 # SDL must not add _GNU_SOURCE as it breaks many platforms
1660                 CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
1661                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1662                         if [ "$enable_static" != "0" ]; then
1663                                 LIBS="$LIBS `$sdl_config --static-libs`"
1664                         else
1665                                 LIBS="$LIBS `$sdl_config --libs`"
1666                         fi
1667                 fi
1668         fi
1670         if [ "$with_cocoa" != "0" ]; then
1671                 CFLAGS="$CFLAGS -DWITH_COCOA"
1672                 LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox"
1674                 if [ "$enable_cocoa_quartz" != "0" ]; then
1675                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUARTZ"
1676                 fi
1678                 if [ "$enable_cocoa_quickdraw" != "0" ]; then
1679                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUICKDRAW"
1680                 fi
1681         fi
1683         if [ "$with_zlib" != "0" ]; then
1684                 CFLAGS="$CFLAGS -DWITH_ZLIB"
1685                 CFLAGS="$CFLAGS `$zlib_config --cflags | tr '\n\r' '  '`"
1686                 if [ "$enable_static" != "0" ]; then
1687                         LIBS="$LIBS `$zlib_config --libs --static | tr '\n\r' '  '`"
1688                 else
1689                         LIBS="$LIBS `$zlib_config --libs | tr '\n\r' '  '`"
1690                 fi
1691         fi
1693         if [ -n "$lzma_config" ]; then
1694                 CFLAGS="$CFLAGS -DWITH_LZMA"
1695                 CFLAGS="$CFLAGS `$lzma_config --cflags | tr '\n\r' '  '`"
1697                 if [ "$enable_static" != "0" ]; then
1698                         CFLAGS="$CFLAGS -DLZMA_API_STATIC"
1699                         LIBS="$LIBS `$lzma_config --libs --static | tr '\n\r' '  '`"
1700                 else
1701                         LIBS="$LIBS `$lzma_config --libs | tr '\n\r' '  '`"
1702                 fi
1703         fi
1705         if [ "$with_lzo2" != "0" ]; then
1706                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1707                         LIBS="$LIBS $lzo2"
1708                 else
1709                         LIBS="$LIBS -llzo2"
1710                 fi
1711                 CFLAGS="$CFLAGS -DWITH_LZO"
1712         fi
1714         if [ -n "$xdg_basedir_config" ]; then
1715                 CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
1716                 CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
1718                 if [ "$enable_static" != "0" ]; then
1719                         LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
1720                 else
1721                         LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
1722                 fi
1723         fi
1725         # 64bit machines need -D_SQ64
1726         if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
1727                 CFLAGS="$CFLAGS -D_SQ64"
1728         fi
1729         CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
1731         if [ -n "$png_config" ]; then
1732                 CFLAGS="$CFLAGS -DWITH_PNG"
1733                 CFLAGS="$CFLAGS `$png_config --cflags | tr '\n\r' '  '`"
1735                 if [ "$enable_static" != "0" ]; then
1736                         LIBS="$LIBS `$png_config --libs --static | tr '\n\r' '  '`"
1737                 else
1738                         LIBS="$LIBS `$png_config --libs | tr '\n\r' '  '`"
1739                 fi
1740         fi
1742         if [ -n "$fontconfig_config" ]; then
1743                 CFLAGS="$CFLAGS -DWITH_FONTCONFIG"
1744                 CFLAGS="$CFLAGS `$fontconfig_config --cflags | tr '\n\r' '  '`"
1746                 if [ "$enable_static" != "0" ]; then
1747                         LIBS="$LIBS `$fontconfig_config --libs --static | tr '\n\r' '  '`"
1748                 else
1749                         LIBS="$LIBS `$fontconfig_config --libs | tr '\n\r' '  '`"
1750                 fi
1751         fi
1753         if [ -n "$freetype_config" ]; then
1754                 CFLAGS="$CFLAGS -DWITH_FREETYPE"
1755                 CFLAGS="$CFLAGS `$freetype_config --cflags | tr '\n\r' '  '`"
1757                 if [ "$enable_static" != "0" ]; then
1758                         LIBS="$LIBS `$freetype_config --libs --static | tr '\n\r' '  '`"
1759                 else
1760                         LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1761                 fi
1762         fi
1764         if [ -n "$icu_layout_config" ]; then
1765                 CFLAGS="$CFLAGS -DWITH_ICU_LAYOUT"
1766                 CFLAGS="$CFLAGS `$icu_layout_config --cflags | tr '\n\r' '  '`"
1768                 if [ "$static_icu" != "0" ]; then
1769                         LIBS="$LIBS `$icu_layout_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1770                 else
1771                         LIBS="$LIBS `$icu_layout_config --libs | tr '\n\r' '  '`"
1772                 fi
1773         fi
1775         if [ -n "$icu_sort_config" ]; then
1776                 CFLAGS="$CFLAGS -DWITH_ICU_SORT"
1777                 CFLAGS="$CFLAGS `$icu_sort_config --cflags | tr '\n\r' '  '`"
1779                 if [ "$static_icu" != "0" ]; then
1780                         LIBS="$LIBS `$icu_sort_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1781                 else
1782                         LIBS="$LIBS `$icu_sort_config --libs | tr '\n\r' '  '`"
1783                 fi
1784         fi
1787         if [ "$with_direct_music" != "0" ]; then
1788                 CFLAGS="$CFLAGS -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT"
1789                 # GCC 4.0+ doesn't like the DirectX includes (gives tons of
1790                 #  warnings on it we won't be able to fix). For now just
1791                 #  suppress those warnings.
1792                 if [ $cc_version -ge 400 ]; then
1793                         CFLAGS="$CFLAGS -Wno-non-virtual-dtor"
1794                 fi
1795         fi
1797         if [ -n "$libtimidity_config" ]; then
1798                 CFLAGS="$CFLAGS -DLIBTIMIDITY"
1799                 CFLAGS="$CFLAGS `$libtimidity_config --cflags | tr '\n\r' '  '`"
1801                 if [ "$enable_static" != "0" ]; then
1802                         LIBS="$LIBS `$libtimidity_config --libs --static | tr '\n\r' '  '`"
1803                 else
1804                         LIBS="$LIBS `$libtimidity_config --libs | tr '\n\r' '  '`"
1805                 fi
1806         fi
1808         if [ "$with_iconv" != "0" ]; then
1809                 CFLAGS="$CFLAGS -DWITH_ICONV"
1810                 if [ "$link_to_iconv" = "yes" ]; then
1811                         LIBS="$LIBS -liconv"
1812                         if [ "$with_iconv" != "2" ]; then
1813                                 CFLAGS="$CFLAGS -I$with_iconv/include"
1814                                 LIBS="$LIBS -L$with_iconv/lib"
1815                         fi
1816                 fi
1818                 if [ "$os" != "OSX" ] && [ "$have_non_const_iconv" != "no" ]; then
1819                         CFLAGS="$CFLAGS -DHAVE_NON_CONST_ICONV"
1820                 fi
1821         fi
1823         if [ -n "$with_midi" ]; then
1824                 CFLAGS="$CFLAGS -DEXTERNAL_PLAYER=\\\\\"$with_midi\\\\\""
1825         fi
1826         if [ -n "$with_midi_arg" ]; then
1827                 CFLAGS="$CFLAGS -DMIDI_ARG=\\\\\"$with_midi_arg\\\\\""
1828         fi
1830         if [ "$enable_dedicated" != "0" ]; then
1831                 CFLAGS="$CFLAGS -DDEDICATED"
1832         fi
1834         if [ "$enable_unicode" != "0" ]; then
1835                 CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
1836         fi
1838         if [ "$enable_network" != "0" ]; then
1839                 CFLAGS="$CFLAGS -DENABLE_NETWORK"
1841                 if [ "$os" = "BEOS" ]; then
1842                         LDFLAGS="$LDFLAGS -lbind -lsocket"
1843                 fi
1845                 if [ "$os" = "HAIKU" ]; then
1846                         LDFLAGS="$LDFLAGS -lnetwork"
1847                 fi
1849                 if [ "$os" = "SUNOS" ]; then
1850                         LDFLAGS="$LDFLAGS -lnsl -lsocket"
1851                 fi
1852         fi
1854         if [ "$enable_static" != "0" ]; then
1855                 # OSX can't handle -static in LDFLAGS
1856                 if [ "$os" != "OSX" ]; then
1857                         LDFLAGS="$LDFLAGS -static"
1858                 fi
1859         fi
1861         if [ "$enable_assert" = "0" ]; then
1862                 CFLAGS="$CFLAGS -DNDEBUG"
1863                 CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
1864         fi
1866         if [ "$enable_desync_debug" != "0" ]; then
1867                 CFLAGS="$CFLAGS -DRANDOM_DEBUG"
1868         fi
1870         if [ "$enable_osx_g5" != "0" ]; then
1871                 CFLAGS="$CFLAGS -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
1872         fi
1874         if [ -n "$personal_dir" ]; then
1875                 CFLAGS="$CFLAGS -DWITH_PERSONAL_DIR -DPERSONAL_DIR=\\\\\"$personal_dir\\\\\""
1876         fi
1878         if [ -n "$shared_dir" ]; then
1879                 CFLAGS="$CFLAGS -DWITH_SHARED_DIR -DSHARED_DIR=\\\\\"$shared_dir\\\\\""
1880         fi
1882         CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
1884         if [ "$enable_lto" != "0" ]; then
1885                 lto_warn=1
1886                 if echo "$FEATURES_BUILD" | grep -q "lto"; then
1887                         LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
1888                         lto_warn=0
1889                 fi
1890                 if echo "$FEATURES" | grep -q "lto"; then
1891                         LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
1892                         lto_warn=0
1893                 fi
1894                 if [ "$lto_warn" != "0" ]; then
1895                         log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
1896                         log 1 "WARNING: LTO/IPO has been disabled"
1897                 fi
1898         fi
1900         log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD"
1901         log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD"
1902         log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD"
1903         log 1 "using CFLAGS... $CFLAGS"
1904         log 1 "using CXXFLAGS... $CXXFLAGS"
1905         log 1 "using LDFLAGS... $LIBS $LDFLAGS"
1907         # Makedepend doesn't like something like: -isysroot /OSX/blabla
1908         #  so convert it to: -isysroot -OSX/blabla. makedepend just ignores
1909         #  any - command it doesn't know, so we are pretty save.
1910         # Lovely hackish, not?
1911         # Btw, this almost always comes from outside the configure, so it is
1912         #  not something we can control.
1913         # Also make makedepend aware of compiler's built-in defines.
1914         if [ "$with_makedepend" != "0" ] || [ "$enable_builtin_depend" != "0" ]; then
1915                 # Append CXXFLAGS possibly containing -std=c++0x
1916                 cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
1918                 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
1919                 cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
1920         else
1921                 makedepend=""
1922         fi
1924         if [ "$with_distcc" != "0" ]; then
1925                 cc_host="$distcc $cc_host"
1926                 cxx_host="$distcc $cxx_host"
1927                 log 1 ""
1928                 log 1 " NOTICE: remind yourself to use 'make -jN' to make use of distcc"
1929                 log 1 ""
1930         fi
1932         if [ "$with_ccache" != "0" ]; then
1933                 cc_host="$ccache $cc_host"
1934                 cxx_host="$ccache $cxx_host"
1935         fi
1938 check_compiler() {
1939         # Params:
1940         # $1 - Type for message (build / host)
1941         # $2 - What to fill with the found compiler
1942         # $3 - System to try
1943         # $4 - Compiler to try
1944         # $5 - Env-setting to try
1945         # $6 - GCC alike to try
1946         # $7 - CC alike to try
1947         # $8 - "0" gcc, "1" g++, "2" windres, "3" strip, "4" lipo
1948         # $9 - What the command is to check for
1950         if [ -n "$3" ]; then
1951                 # Check for system
1952                 if [ -z "$6" ]; then
1953                         compiler="$3"
1954                 else
1955                         compiler="$3-$6"
1956                 fi
1957                 machine=`eval $compiler $9 2>/dev/null`
1958                 ret=$?
1959                 eval "$2=\"$compiler\""
1961                 log 2 "executing $compiler $9"
1962                 log 2 "  returned $machine"
1963                 log 2 "  exit code $ret"
1965                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1966                         if [ -z "$5" ]; then
1967                                 log 1 "checking $1... $compiler not found"
1968                                 log 1 "I couldn't detect any $6 binary for $3"
1969                                 exit 1
1970                         else
1971                                 compiler="$3-$5"
1972                         fi
1973                         machine=`eval $compiler $9 2>/dev/null`
1974                         ret=$?
1975                         eval "$2=\"$compiler\""
1977                         log 2 "executing $compiler $9"
1978                         log 2 "  returned $machine"
1979                         log 2 "  exit code $ret"
1981                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1982                                 log 1 "checking $1... $compiler not found"
1983                                 log 1 "I couldn't detect any $5 binary for $3"
1984                                 exit 1
1985                         fi
1986                 fi
1988                 if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
1989                         log 1 "checking $1... expected $3, found $machine"
1990                         log 1 "the compiler suggests it doesn't build code for the machine you specified"
1991                         exit 1
1992                 fi
1993         elif [ -n "$4" ]; then
1994                 # Check for manual compiler
1995                 machine=`$4 $9 2>/dev/null`
1996                 ret=$?
1997                 eval "$2=\"$4\""
1999                 log 2 "executing $4 $9"
2000                 log 2 "  returned $machine"
2001                 log 2 "  exit code $ret"
2003                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2004                         log 1 "checking $1... $4 not found"
2005                         log 1 "the selected binary doesn't seem to be a $6 binary"
2006                         exit 1
2007                 fi
2008         else
2009                 # Nothing given, autodetect
2011                 if [ -n "$5" ]; then
2012                         machine=`$5 $9 2>/dev/null`
2013                         ret=$?
2014                         eval "$2=\"$5\""
2016                         log 2 "executing $5 $9"
2017                         log 2 "  returned $machine"
2018                         log 2 "  exit code $ret"
2020                         # The user defined a GCC that doesn't reply to $9.. abort
2021                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2022                                 log 1 "checking $1... $5 unusable"
2023                                 log 1 "the CC environment variable is set, but it doesn't seem to be a $6 binary"
2024                                 log 1 "please redefine the CC/CXX environment to a $6 binary"
2025                                 exit 1
2026                         fi
2027                 else
2028                         log 2 "checking $1... CC/CXX not set (skipping)"
2030                         # No $5, so try '$6'
2031                         machine=`$6 $9 2>/dev/null`
2032                         ret=$?
2033                         eval "$2=\"$6\""
2035                         log 2 "executing $6 $9"
2036                         log 2 "  returned $machine"
2037                         log 2 "  exit code $ret"
2039                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2040                                 # Maybe '$7'?
2041                                 machine=`$7 $9 2>/dev/null`
2042                                 ret=$?
2043                                 eval "$2=\"$7\""
2045                                 log 2 "executing $7 $9"
2046                                 log 2 "  returned $machine"
2047                                 log 2 "  exit code $ret"
2049                                 # All failed, abort
2050                                 if [ -z "$machine" ]; then
2051                                         log 1 "checking $1... $6 not found"
2052                                         log 1 "I couldn't detect any $6 binary on your system"
2053                                         log 1 "please define the CC/CXX environment to where it is located"
2055                                         exit 1
2056                                 fi
2057                         fi
2058                 fi
2059         fi
2061         if [ "$8" != "0" ]; then
2062                 eval "res=\$$2"
2063                 log 1 "checking $1... $res"
2064         else
2065                 log 1 "checking $1... $machine"
2066         fi
2069 check_build() {
2070         if [ "$os" = "FREEBSD" ]; then
2071                 # FreeBSD's C compiler does not support dump machine.
2072                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2073                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CXX" "g++" "c++" "0" "-dumpmachine"
2074         else
2075                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CC" "gcc" "cc" "0" "-dumpmachine"
2076         fi
2079 check_host() {
2080         # By default the host is the build
2081         if [ -z "$host" ]; then host="$build"; fi
2083         if [ "$os" = "FREEBSD" ]; then
2084                 # FreeBSD's C compiler does not support dump machine.
2085                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2086                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CXX" "g++" "c++" "0" "-dumpmachine"
2087         else
2088                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
2089         fi
2092 check_cxx_build() {
2093         check_compiler "build c++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
2096 check_cxx_host() {
2097         # By default the host is the build
2098         if [ -z "$host" ]; then host="$build"; fi
2099         check_compiler "host c++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
2102 check_windres() {
2103         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2104                 check_compiler "host windres" "windres" "$host" "$windres" "$WINDRES" "windres" "windres" "2" "-V"
2105         fi
2108 check_strip() {
2109         if [ "$os" = "OS2" ]; then
2110                 # OS2 via gcc is a bit weird.. stripping HAS to be done via emxbind, which is via gcc directly
2111                 log 1 "checking host strip... using gcc -s option"
2112         elif [ "$os" = "OSX" ]; then
2113                 # Most targets have -V in strip, to see if they exists... OSX doesn't.. so execute something
2114                 echo "int main(int argc, char *argv[]) { }" > strip.test.c
2115                 $cxx_host strip.test.c -o strip.test
2116                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "strip.test"
2117                 rm -f strip.test.c strip.test
2118         else
2119                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "-V"
2120         fi
2123 check_lipo() {
2124         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
2125                 echo "int main(int argc, char *argv[]) { }" > lipo.test.c
2126                 $cxx_host lipo.test.c -o lipo.test
2127                 check_compiler "host lipo" "lipo" "$host" "$lipo" "$LIPO" "lipo" "lipo" "4" "-info lipo.test"
2128                 rm -f lipo.test.c lipo.test
2129         fi
2132 check_osx_sdk() {
2133         local sysroot=""
2134         if [ -n "$1" ]; then
2135                 if echo "$1" | grep -q / ; then
2136                         # Seems to be a file system path
2137                         osx_sdk_path="$1"
2138                 else
2139                         osx_sdk_path="/Developer/SDKs/MacOSX$1.sdk"
2140                 fi
2141                 if [ ! -d "$osx_sdk_path" ]; then
2142                         # No directory, not present or garbage
2143                         return 1
2144                 fi
2146                 # Set minimum version to 10.4 as that's when kCGBitmapByteOrder32Host was introduced
2147                 sysroot="-isysroot $osx_sdk_path -Wl,-syslibroot,$osx_sdk_path -mmacosx-version-min=10.4"
2148         fi
2150 cat > tmp.osx.mm << EOF
2151 #include <Cocoa/Cocoa.h>
2152 int main() {
2153         kCGBitmapByteOrder32Host;
2154         return 0;
2157         execute="$cxx_host $sysroot $CFLAGS tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2158         eval $execute > /dev/null
2159         ret=$?
2160         log 2 "executing $execute"
2161         log 2 "  exit code $ret"
2162         rm -f tmp.osx.mm tmp.osx
2163         return $ret
2166 check_direct_music() {
2167         echo "
2168                 #include <windows.h>
2169                 #include <dmksctrl.h>
2170                 #include <dmusici.h>
2171                 #include <dmusicc.h>
2172                 #include <dmusicf.h>
2173                 int main(int argc, char *argv[]) { }" > direct_music.test.c
2174         $cxx_host $CFLAGS direct_music.test.c -o direct_music.test 2> /dev/null
2175         res=$?
2176         rm -f direct_music.test.c direct_music.test
2178         if [ "$res" != "0" ]; then
2179                 if [ "$with_direct_music" != "1" ]; then
2180                         log 1 "configure: error: direct-music is not available on this system"
2181                         exit 1
2182                 fi
2183                 with_direct_music="0"
2185                 log 1 "checking direct-music... not found"
2186         else
2187                 log 1 "checking direct-music... found"
2188         fi
2191 check_makedepend() {
2192         if [ "$enable_builtin_depend" != "0" ]; then
2193                 with_makedepend="0"
2194         fi
2196         if [ "$with_makedepend" = "0" ]; then
2197                 log 1 "checking makedepend... disabled"
2198                 return
2199         fi
2201         if [ "$with_makedepend" = "1" ] || [ "$with_makedepend" = "2" ]; then
2202                 makedepend="makedepend"
2203         else
2204                 makedepend="$with_makedepend"
2205         fi
2207         rm -f makedepend.tmp
2208         touch makedepend.tmp
2209         res=`$makedepend -fmakedepend.tmp 2>/dev/null`
2210         res=$?
2211         log 2 "executing $makedepend -f makedepend.tmp"
2212         log 2 "  returned `cat makedepend.tmp`"
2213         log 2 "  exit code $ret"
2215         if [ ! -s makedepend.tmp ]; then
2216                 rm -f makedepend.tmp makedepend.tmp.bak
2218                 if [ "$with_makedepend" = "2" ]; then
2219                         log 1 "checking makedepend... not found"
2221                         log 1 "I couldn't detect any makedepend on your system"
2222                         log 1 "please locate it via --makedepend=[binary]"
2224                         exit 1
2225                 elif [ "$with_makedepend" != "1" ]; then
2226                         log 1 "checking makedepend... $makedepend not found"
2228                         log 1 "the selected file doesn't seem to be a valid makedepend binary"
2230                         exit 1
2231                 else
2232                         log 1 "checking makedepend... not found"
2234                         with_makedepend="0"
2235                         return
2236                 fi
2237         fi
2239         rm -f makedepend.tmp makedepend.tmp.bak
2241         log 1 "checking makedepend... $makedepend"
2244 check_version() {
2245         # $1 - requested version (major.minor)
2246         # $2 - version we got (major.minor)
2248         if [ -z "$2" ]; then
2249                 return 0
2250         fi
2252         req_major=`echo $1 | cut -d. -f1`
2253         got_major=`echo $2 | cut -d. -f1`
2254         if [ $got_major -lt $req_major ]; then
2255                 return 0
2256         elif [ $got_major -gt $req_major ]; then
2257                 return 1
2258         fi
2260         req_minor=`echo $1 | cut -d. -f2`
2261         got_minor=`echo $2 | cut -d. -f2`
2262         if [ $got_minor -lt $req_minor ]; then
2263                 return 0
2264         fi
2265         return 1
2268 detect_awk() {
2269         # Not all awks allow gsub(), so we test for that here! It is in fact all we need...
2271         # These awks are known to work. Test for them explicit
2272         awks="gawk mawk nawk"
2274         awk_prefix="echo \"a.c b.c c.c\" | tr ' ' \\\\n | "
2275         awk_param="' { ORS = \" \" } /\.c$/   { gsub(\".c$\",   \".o\", \$0); print \$0; }' 2>/dev/null"
2276         awk_result="a.o b.o c.o "
2277         log 2 "Detecing awk..."
2279         log 2 "Trying: $awk_prefix $awk $awk_param"
2280         res=`eval $awk_prefix $awk $awk_param`
2281         log 2 "Result: '$res'"
2282         if [ "$res" != "$awk_result" ] && [ "$awk" = "awk" ]; then
2283                 # User didn't supply his own awk, so try to detect some other known working names for an awk
2284                 for awk in $awks; do
2285                         log 2 "Trying: $awk_prefix $awk $awk_param"
2286                         res=`eval $awk_prefix $awk $awk_param`
2287                         log 2 "Result: '$res'"
2288                         if [ "$res" = "$awk_result" ]; then break; fi
2289                 done
2291                 if [ "$res" != "$awk_result" ]; then
2292                         log 1 "checking awk... not found"
2293                         log 1 "configure: error: no awk found"
2294                         log 1 "configure: error: please install one of the following: $awks"
2295                         exit 1
2296                 fi
2297         fi
2298         if [ "$res" != "$awk_result" ]; then
2299                 log 1 "checking awk... not found"
2300                 log 1 "configure: error: you supplied '$awk' but it doesn't seem a valid gawk or mawk"
2301                 exit 1
2302         fi
2304         log 1 "checking awk... $awk"
2307 detect_os() {
2308         if [ "$os" = "DETECT" ]; then
2309                 # Detect UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, HPUX, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
2311                 # Try first via dumpmachine, then via uname
2312                 case `echo "$host" | tr '[A-Z]' '[a-z]'` in
2313                         *linux*)     os=UNIX;;
2314                         *darwin*)    os=OSX;;
2315                         *freebsd*)   os=FREEBSD;;
2316                         *dragonfly*) os=DRAGONFLY;;
2317                         *openbsd*)   os=OPENBSD;;
2318                         *netbsd*)    os=NETBSD;;
2319                         *hp-ux*)     os=HPUX;;
2320                         *morphos*)   os=MORPHOS;;
2321                         *beos*)      os=BEOS;;
2322                         *haiku*)     os=HAIKU;;
2323                         *sunos*)     os=SUNOS;;
2324                         *solaris*)   os=SUNOS;;
2325                         *cygwin*)    os=CYGWIN;;
2326                         *mingw*)     os=MINGW;;
2327                         *os2*)       os=OS2;;
2328                         *dos*)       os=DOS;;
2329                         *wince*)     os=WINCE;;
2330                         *psp*)       os=PSP;;
2331                 esac
2333                 if [ "$os" = "DETECT" ]; then
2334                         case `LC_ALL=C uname | tr '[A-Z]' '[a-z]'` in
2335                                 *linux*)     os=UNIX;;
2336                                 *darwin*)    os=OSX;;
2337                                 *freebsd*)   os=FREEBSD;;
2338                                 *dragonfly*) os=DRAGONFLY;;
2339                                 *openbsd*)   os=OPENBSD;;
2340                                 *netbsd*)    os=NETBSD;;
2341                                 *hp-ux*)     os=HPUX;;
2342                                 *morphos*)   os=MORPHOS;;
2343                                 *beos*)      os=BEOS;;
2344                                 *haiku*)     os=HAIKU;;
2345                                 *sunos*)     os=SUNOS;;
2346                                 *cygwin*)    os=CYGWIN;;
2347                                 *mingw*)     os=MINGW;;
2348                                 *os/2*)      os=OS2;;
2349                                 *gnu*)       os=UNIX;;
2350                         esac
2351                 fi
2353                 if [ "$os" = "DETECT" ]; then
2354                         log 1 "detecting OS... none detected"
2355                         log 1 "I couldn't detect your OS. Please use --os=OS to force one"
2356                         log 1 "Allowed values are: UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP"
2357                         exit 1
2358                 fi
2360                 log 1 "detecting OS... $os"
2361         else
2362                 log 1 "forcing OS... $os"
2363         fi
2366 detect_allegro() {
2367         # 0 means no, 1 is auto-detect, 2 is force
2368         if [ "$with_allegro" = "0" ]; then
2369                 log 1 "checking Allegro... disabled"
2371                 allegro_config=""
2372                 return 0
2373         fi
2375         if [ "$with_allegro" = "2" ] && [ "$with_cocoa" = "2" ]; then
2376                 log 1 "configure: error: it is impossible to compile both Allegro and COCOA"
2377                 log 1 "configure: error: please deselect one of them and try again"
2378                 exit 1
2379         fi
2381         if [ "$with_allegro" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2382                 log 1 "configure: error: it is impossible to compile a dedicated with Allegro"
2383                 log 1 "configure: error: please deselect one of them and try again"
2384                 exit 1
2385         fi
2387         if [ "$enable_dedicated" != "0" ]; then
2388                 log 1 "checking Allegro... dedicated server, skipping"
2390                 allegro_config=""
2391                 return 0
2392         fi
2394         # By default on OSX we don't use Allegro. The rest is auto-detect
2395         if [ "$with_allegro" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2396                 log 1 "checking Allegro... OSX, skipping"
2398                 allegro_config=""
2399                 return 0
2400         fi
2402         detect_pkg_config "$with_allegro" "allegro" "allegro_config" "4.4"
2406 detect_sdl() {
2407         # 0 means no, 1 is auto-detect, 2 is force
2408         if [ "$with_sdl" = "0" ]; then
2409                 log 1 "checking SDL... disabled"
2411                 sdl_config=""
2412                 return 0
2413         fi
2415         if [ "$with_sdl" = "2" ] && [ "$with_cocoa" = "2" ]; then
2416                 log 1 "configure: error: it is impossible to compile both SDL and COCOA"
2417                 log 1 "configure: error: please deselect one of them and try again"
2418                 exit 1
2419         fi
2421         if [ "$with_sdl" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2422                 log 1 "configure: error: it is impossible to compile a dedicated with SDL"
2423                 log 1 "configure: error: please deselect one of them and try again"
2424                 exit 1
2425         fi
2427         if [ "$enable_dedicated" != "0" ]; then
2428                 log 1 "checking SDL... dedicated server, skipping"
2430                 sdl_config=""
2431                 return 0
2432         fi
2434         # By default on OSX we don't use SDL. The rest is auto-detect
2435         if [ "$with_sdl" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2436                 log 1 "checking SDL... OSX, skipping"
2438                 sdl_config=""
2439                 return 0
2440         fi
2442         if [ "$os" = "OSX" ]; then
2443                 log 1 "WARNING: sdl is known to fail on some versions of Mac OS X"
2444                 log 1 "WARNING: with some hardware configurations. Use at own risk!"
2445                 sleep 5
2446         fi
2448         detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2"
2451 detect_osx_sdk() {
2452         # Try to find the best SDK available. For a normal build this
2453         # is currently the 10.5 SDK as this is needed to compile all
2454         # optional code. Because such an executable won't run on 10.4
2455         # or lower, also check for the 10.4u SDK when doing an universal
2456         # build.
2458         # Check for the 10.5 SDK, but try 10.6 if that fails
2459         check_osx_sdk "10.5" || check_osx_sdk "10.6" || osx_sdk_path=""
2461         if [ -z "$osx_sdk_path" ] || [ "$enable_universal" != "0" ]; then
2462                 # No better SDK or universal build enabled? Check 10.4u SDK as well
2463                 local old_sdk="$osx_sdk_path"
2464                 if check_osx_sdk "10.4u"; then
2465                         osx_sdk_104_path="$osx_sdk_path"
2466                 else
2467                         osx_sdk_104_path=""
2468                 fi
2469                 if [ -z "$old_sdk" ]; then
2470                         osx_sdk_path="$osx_sdk_104_path"
2471                 else
2472                         osx_sdk_path="$old_sdk"
2473                 fi
2474         fi
2476         if [ -z "$osx_sdk_path" ]; then
2477                 log 1 "Your system SDK is probably too old"
2478                 log 1 "Please install/upgrade your Xcode to >= 2.5"
2480                 exit 1
2481         fi
2484 detect_cocoa() {
2485         # 0 means no, 1 is auto-detect, 2 is force
2486         if [ "$with_cocoa" = "0" ]; then
2487                 log 1 "checking COCOA... disabled"
2489                 return 0
2490         fi
2492         if [ "$with_cocoa" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2493                 log 1 "configure: error: it is impossible to compile a dedicated with COCOA"
2494                 log 1 "configure: error: please deselect one of them and try again"
2495                 exit 1
2496         fi
2498         if [ "$enable_dedicated" != "0" ]; then
2499                 log 1 "checking COCOA... dedicated server, skipping"
2501                 with_cocoa="0"
2502                 return 0
2503         fi
2505         # By default on OSX we use COCOA. The rest doesn't support it
2506         if [ "$with_cocoa" = "1" ] && [ "$os" != "OSX" ]; then
2507                 log 1 "checking COCOA... not OSX, skipping"
2509                 with_cocoa="0"
2510                 return 0
2511         fi
2513         if [ "$os" != "OSX" ]; then
2514                 log 1 "checking COCOA... not OSX"
2516                 log 1 "configure: error: COCOA video driver is only supported for OSX"
2517                 exit 1
2518         fi
2520         log 1 "checking COCOA... found"
2523         if [ "$enable_cocoa_quartz" != "0" ]; then
2524                 log 1 "checking whether to enable the Quartz window subdriver... yes"
2525         else
2526                 log 1 "checking whether to enable the Quartz window subdriver... no"
2527         fi
2529         detect_quickdraw
2532 detect_quickdraw() {
2533         # 0 means no, 1 is auto-detect, 2 is force
2534         if [ "$enable_cocoa_quickdraw" = "0" ]; then
2535                 log 1 "checking Quickdraw window subdriver... disabled"
2536                 return 0
2537         fi
2539         # Assume QuickDraw is available when doing an universal build
2540         if [ "$enable_universal" != "0" ]; then
2541                 log 1 "checking Quickdraw window subdriver... found"
2542                 return 0
2543         fi
2545         # 64 bits doesn't have quickdraw
2546         if [ "$cpu_type" = "64" ]; then
2547                 enable_cocoa_quickdraw="0"
2548                 log 1 "checking Quickdraw window subdriver... disabled (64 bits)"
2549                 return 0
2550         fi
2552 cat > tmp.osx.mm << EOF
2553 #include <AvailabilityMacros.h>
2554 #import <Cocoa/Cocoa.h>
2555 int main(int argc, char *argv[]) { SetEmptyRgn(NULL); return 0; }
2557         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS -mmacosx-version-min=10.3 tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2558         eval $execute > /dev/null
2559         ret=$?
2560         log 2 "executing $execute"
2561         log 2 "  exit code $ret"
2562         rm -f tmp.osx.mm tmp.osx
2563         if [ "$ret" != "0" ]; then
2564                 log 1 "checking Quickdraw window subdriver... not found"
2566                 # It was forced, so it should be found.
2567                 if [ "$enable_cocoa_quickdraw" != "1" ]; then
2568                         log 1 "configure: error: Quickdraw window driver could not be found"
2569                         exit 1
2570                 fi
2572                 enable_cocoa_quickdraw=0
2573                 return 0
2574         fi
2576         enable_cocoa_quickdraw=1
2577         log 1 "checking Quickdraw window subdriver... found"
2580 detect_library() {
2581         # $1 - config-param ($with_zlib value)
2582         # $2 - library name ('zlib', sets $zlib)
2583         # $3 - static library name (libz.a)
2584         # $4 - header directory ()
2585         # $5 - header name (zlib.h)
2586         # $6 - force static (if non-empty)
2588         if [ -n "$6" ]; then force_static="1"; fi
2590         # 0 means no, 1 is auto-detect, 2 is force
2591         if [ "$1" = "0" ]; then
2592                 log 1 "checking $2... disabled"
2594                 eval "$2=\"\""
2595                 return 0
2596         fi
2598         log 2 "detecting $2"
2600         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2601                 eval "$2=`ls -1 /usr/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2602                 eval "res=\$$2"
2603                 if [ -z "$res" ]; then
2604                         log 2 "  trying /usr/include/$4$5... no"
2605                         eval "$2=`ls -1 /usr/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2606                 fi
2607                 eval "res=\$$2"
2608                 if [ -z "$res" ]; then
2609                         log 2 "  trying /usr/local/include/$4$5... no"
2610                         eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2611                 fi
2612                 eval "res=\$$2"
2613                 if [ -z "$res" ]; then
2614                         log 2 "  trying /mingw/include/$4$5... no"
2615                         eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2616                 fi
2617                 eval "res=\$$2"
2618                 if [ -z "$res" ]; then
2619                         log 2 "  trying /opt/local/include/$4$5... no"
2620                 fi
2621                 if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then
2622                         eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2623                         eval "res=\$$2"
2624                         if [ -z "$res" ]; then
2625                                 log 2 "  trying /usr/pkg/include/$4$5... no"
2626                         fi
2627                 fi
2628                 if [ -z "$res" ] && [ "$os" = "HAIKU" ]; then
2629                         if [ -z "$includeDir" ]; then
2630                                 includeDir=`finddir B_SYSTEM_HEADERS_DIRECTORY`
2631                         fi
2632                         eval "$2=`ls -1 $includeDir/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2633                         eval "res=\$$2"
2634                         if [ -z "$res" ]; then
2635                                 log 2 "  trying $includeDir/$4$5... no"
2636                         fi
2637                 fi
2639                 eval "res=\$$2"
2640                 if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then
2641                         eval "res=\$$2"
2642                         log 2 "  trying $res... found"
2643                         # Now find the static lib, if needed
2644                         eval "$2=`ls /lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2645                         eval "res=\$$2"
2646                         if [ -z "$res" ]; then
2647                                 log 2 "  trying /lib/$3... no"
2648                                 eval "$2=`ls /usr/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2649                         fi
2650                         eval "res=\$$2"
2651                         if [ -z "$res" ]; then
2652                                 log 2 "  trying /usr/lib/$3... no"
2653                                 eval "$2=`ls /usr/local/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2654                         fi
2655                         eval "res=\$$2"
2656                         if [ -z "$res" ]; then
2657                                 log 2 "  trying /usr/local/lib/$3... no"
2658                                 eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2659                         fi
2660                         eval "res=\$$2"
2661                         if [ -z "$res" ]; then
2662                                 log 2 "  trying /mingw/lib/$3... no"
2663                                 log 1 "configure: error: $2 couldn't be found"
2664                                 log 1 "configure: error: you requested a static link, but I can't find $3"
2666                                 exit 1
2667                         fi
2668                 fi
2669         else
2670                 # Make sure it exists
2671                 if [ -f "$1" ]; then
2672                         eval "$2=`ls $1 2>/dev/null`"
2673                 else
2674                         eval "$2=`ls $1/$3 2>/dev/null`"
2675                 fi
2676         fi
2678         eval "res=\$$2"
2679         if [ -z "$res" ]; then
2680                 log 1 "checking $2... not found"
2681                 if [ "$1" = "2" ]; then
2682                         log 1 "configure: error: $2 couldn't be found"
2684                         exit 1
2685                 elif [ "$1" != "1" ]; then
2686                         log 1 "configure: error: $2 couldn't be found"
2687                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2689                         exit 1
2690                 fi
2692                 eval "with_$2=0"
2694                 return 0
2695         fi
2697         eval "res=\$$2"
2698         log 2 "  trying $res... found"
2700         log 1 "checking $2... found"
2703 detect_zlib() {
2704         detect_pkg_config "$with_zlib" "zlib" "zlib_config" "1.2"
2707 detect_lzo2() {
2708         detect_library "$with_lzo2" "lzo2" "liblzo2.a" "lzo/" "lzo1x.h"
2711 detect_libtimidity() {
2712         detect_pkg_config "$with_libtimidity" "libtimidity" "libtimidity_config" "0.1" "1"
2715 detect_pkg_config() {
2716         # $1 - config-param ($with_lzma value)
2717         # $2 - package name ('liblzma')
2718         # $3 - config name ('lzma_config', sets $lzma_config)
2719         # $4 - minimum module version ('2.3')
2720         # $5 - check for dedicated, 1 is "skif if dedicated"
2722         # 0 means no, 1 is auto-detect, 2 is force
2723         if [ "$1" = "0" ]; then
2724                 log 1 "checking $2... disabled"
2726                 eval "$3=\"\""
2727                 return 0
2728         fi
2730         if [ "$5" = "1" ] && [ "$1" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2731                 log 1 "checking $2... dedicated server, skipping"
2733                 eval "$3=\"\""
2734                 return 0
2735         fi
2737         log 2 "detecting $2"
2739         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2740                 pkg_config_call="$pkg_config $2"
2741         else
2742                 pkg_config_call="$1"
2743         fi
2745         version=`$pkg_config_call --modversion 2>/dev/null`
2746         ret=$?
2747         check_version "$4" "$version"
2748         version_ok=$?
2749         log 2 "executing $pkg_config_call --modversion"
2750         log 2 "  returned $version"
2751         log 2 "  exit code $ret"
2753         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2754                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2755                         log 1 "checking $2... needs at least version $4, $2 NOT enabled"
2756                 else
2757                         log 1 "checking $2... not found"
2758                 fi
2760                 # It was forced, so it should be found.
2761                 if [ "$1" != "1" ]; then
2762                         log 1 "configure: error: $pkg_config $2 couldn't be found"
2763                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2764                         exit 1
2765                 fi
2767                 eval "$3=\"\""
2768                 return 0
2769         fi
2771         eval "$3=\"$pkg_config_call\""
2772         log 1 "checking $2... found"
2775 detect_lzma() {
2776         detect_pkg_config "$with_lzma" "liblzma" "lzma_config" "5.0"
2779 detect_xdg_basedir() {
2780         detect_pkg_config "$with_xdg_basedir" "libxdg-basedir" "xdg_basedir_config" "1.2"
2783 detect_png() {
2784         detect_pkg_config "$with_png" "libpng" "png_config" "1.2"
2787 detect_freetype() {
2788         detect_pkg_config "$with_freetype" "freetype2" "freetype_config" "2.2" "1"
2791 detect_fontconfig() {
2792         # 0 means no, 1 is auto-detect, 2 is force
2793         if [ "$with_fontconfig" = "0" ]; then
2794                 log 1 "checking libfontconfig... disabled"
2796                 fontconfig_config=""
2797                 return 0
2798         fi
2799         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2800                 log 1 "checking libfontconfig... WIN32, skipping"
2801                 fontconfig_config=""
2802                 return 0
2803         fi
2805         if [ "$os" = "OSX" ]; then
2806                 log 1 "checking libfontconfig... OSX, skipping"
2807                 fontconfig_config=""
2808                 return 0
2809         fi
2811         detect_pkg_config "$with_fontconfig" "fontconfig" "fontconfig_config" "2.3" "1"
2814 detect_icu_layout() {
2815         detect_pkg_config "$with_icu_layout" "icu-lx" "icu_layout_config" "4.8" "1"
2818 detect_icu_sort() {
2819         detect_pkg_config "$with_icu_sort" "icu-i18n" "icu_sort_config" "4.8" "1"
2822 detect_pspconfig() {
2823         # 0 means no, 1 is auto-detect, 2 is force
2824         if [ "$with_psp_config" = "0" ]; then
2825                 log 1 "checking psp-config... disabled"
2827                 psp_config=""
2828                 return 0
2829         fi
2831         if [ "$with_psp_config" = "1" ] && [ "$os" != "PSP" ]; then
2832                 log 1 "checking psp-config... not PSP, skipping"
2834                 psp_config="";
2835                 return 0
2836         fi
2838         if [ "$os" != "PSP" ]; then
2839                 log 1 "checking psp-config... not PSP"
2841                 log 1 "configure: error: psp-config is only supported for PSP"
2842                 exit 1
2843         fi
2845         if [ "$with_psp_config" = "1" ] || [ "$with_psp_config" = "" ] || [ "$with_psp_config" = "2" ]; then
2846                 psp_config="psp-config"
2847         else
2848                 psp_config="$with_psp_config"
2849         fi
2851         version=`$psp_config -p 2>/dev/null`
2852         ret=$?
2853         log 2 "executing $psp_config -p"
2854         log 2 "  returned $version"
2855         log 2 "  exit code $ret"
2857         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2858                 log 1 "checking psp-config... not found"
2859                 log 1 "configure: error: psp-config couldn't be found"
2861                 # It was forced, so it should be found.
2862                 if [ "$with_psp_config" != "1" ]; then
2863                         log 1 "configure: error: you supplied '$with_psp_config', but it seems invalid"
2864                 fi
2865                 exit 1
2866         fi
2868         log 1 "checking psp-config... found"
2871 detect_iconv() {
2872         # 0 means no, 1 is auto-detect, 2 is force
2873         if [ "$with_iconv" = "0" ]; then
2874                 log 1 "checking iconv... disabled"
2876                 return 0
2877         fi
2879         if [ "$with_iconv" = "1" ] && [ "$os" != "OSX" ]; then
2880                 log 1 "checking iconv... not OSX, skipping"
2881                 with_iconv="0"
2883                 return 0
2884         fi
2886         # Try to find iconv.h, seems to only thing to detect iconv with
2888         if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
2889                 iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
2890                 if [ -z "$iconv" ]; then
2891                         iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
2892                 fi
2893         else
2894                 # Make sure it exists
2895                 iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
2896         fi
2898         if [ -z "$iconv" ]; then
2899                 log 1 "checking iconv... not found"
2900                 if [ "$with_iconv" = "2" ]; then
2901                         log 1 "configure: error: iconv couldn't be found"
2903                         exit 1
2904                 elif [ "$with_iconv" != "1" ]; then
2905                         log 1 "configure: error: iconv couldn't be found"
2906                         log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
2908                         exit 1
2909                 fi
2911                 return 0
2912         fi
2914         if [ "$with_iconv" = "1" ]; then
2915                 with_iconv="2"
2916         fi
2918         log 2 "found iconv in $iconv"
2920         log 1 "checking iconv... found"
2922         # There are different implementations of iconv. The older ones,
2923         # e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
2924         # IEEE 1003.1 (2004), pass a non-const pointer.
2926         cat > tmp.iconv.cpp << EOF
2927 #include "src/stdafx.h"
2928 #include <iconv.h>
2929 int main() {
2930         static char buf[1024];
2931         iconv_t convd = 0;
2932         const char *inbuf = "";
2933         char *outbuf  = buf;
2934         size_t outlen = 1023;
2935         size_t inlen  = 0;
2936         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2939         execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2940         eval $execute > /dev/null
2941         ret=$?
2942         log 2 "executing $execute"
2943         log 2 "  exit code $ret"
2944         if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
2945         log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
2947         cat > tmp.iconv.cpp << EOF
2948 #include "src/stdafx.h"
2949 #include <iconv.h>
2950 int main() {
2951         static char buf[1024];
2952         iconv_t convd = 0;
2953         char *inbuf = "";
2954         char *outbuf  = buf;
2955         size_t outlen = 1023;
2956         size_t inlen  = 0;
2957         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2960         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2961         eval $execute > /dev/null
2962         ret=$?
2963         log 2 "executing $execute"
2964         log 2 "  exit code $ret"
2965         if [ "$ret" = "0" ]; then link_to_iconv="no"; else link_to_iconv="yes"; fi
2966         log 1 "checking whether to link to iconv... $link_to_iconv"
2967         rm -f tmp.iconv tmp.iconv.cpp
2970 _detect_sort() {
2971         sort_test_in="d
2976         sort_test_out="a
2981         log 2 "running echo <array> | $1"
2983         if [ "`echo \"$sort_test_in\" | $1 2>/dev/null`" = "$sort_test_out" ]; then
2984                 sort="$1"
2985                 log 2 "  result was valid"
2986         else
2987                 log 2 "  result was invalid"
2988         fi
2991 detect_sort() {
2992         if [ "$with_sort" = "0" ]; then
2993                 log 1 "checking sort... disabled"
2995                 return
2996         fi
2998         if [ "$with_sort" = "1" ] || [ "$with_sort" = "2" ]; then
2999                 _detect_sort "sort"
3000                 if [ -z "$sort" ]; then _detect_sort "/sbin/sort"; fi
3001                 if [ -z "$sort" ]; then _detect_sort "/usr/sbin/sort"; fi
3002                 if [ -z "$sort" ]; then _detect_sort "/usr/local/sbin/sort"; fi
3003                 if [ -z "$sort" ]; then _detect_sort "/bin/sort"; fi
3004                 if [ -z "$sort" ]; then _detect_sort "/usr/bin/sort"; fi
3005                 if [ -z "$sort" ]; then _detect_sort "/usr/local/bin/sort"; fi
3006         else
3007                 _detect_sort "$with_sort"
3008         fi
3010         if [ -z "$sort" ]; then
3011                 if [ "$with_sort" = "2" ]; then
3012                         log 1 "checking sort... not found"
3014                         log 1 "configure: error: couldn't detect sort on your system"
3015                         exit 1
3016                 elif [ "$with_sort" != "1" ]; then
3017                         log 1 "checking sort... $with_sort not found"
3019                         log 1 "configure: error: '$with_sort' doesn't look like a sort to me"
3020                         log 1 "configure: error: please verify its location and function and try again"
3022                         exit 1
3023                 else
3024                         log 1 "checking sort... not found"
3025                 fi
3026         else
3027                 log 1 "checking sort... $sort"
3028         fi
3031 detect_grfcodec() {
3032         # 0 means no, 1 is auto-detect, 2 is force
3033         if [ "$with_grfcodec" = "0" ]; then
3034                 log 1 "checking grfcodec... disabled"
3036                 grfcodec=""
3037                 return 0
3038         fi
3040         if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
3041                 grfcodec="grfcodec"
3042         else
3043                 grfcodec="$with_grfcodec"
3044         fi
3046         version=`$grfcodec -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3047         ret=$?
3048         log 2 "executing grfcodec -v"
3049         log 2 "  returned $version"
3050         log 2 "  exit code $ret"
3052         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3053                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3054                         log 1 "checking grfcodec... needs at least version 6.0.5 (r985), disabled"
3055                 else
3056                         log 1 "checking grfcodec... not found"
3057                 fi
3059                 # It was forced, so it should be found.
3060                 if [ "$with_grfcodec" != "1" ]; then
3061                         log 1 "configure: error: grfcodec couldn't be found"
3062                         log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
3063                         exit 1
3064                 fi
3066                 grfcodec=""
3067                 return 0
3068         fi
3070         log 1 "checking grfcodec... found"
3073 detect_nforenum() {
3074         # 0 means no, 1 is auto-detect, 2 is force
3075         if [ "$with_nforenum" = "0" ]; then
3076                 log 1 "checking nforenum... disabled"
3078                 nforenum=""
3079                 return 0
3080         fi
3082         if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
3083                 nforenum="nforenum"
3084         else
3085                 nforenum="$with_nforenum"
3086         fi
3088         version=`$nforenum -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3089         ret=$?
3090         log 2 "executing nforenum -v"
3091         log 2 "  returned $version"
3092         log 2 "  exit code $ret"
3094         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3095                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3096                         log 1 "checking nforenum... needs at least version 6.0.5 (r985), disabled"
3097                 else
3098                         log 1 "checking nforenum... not found"
3099                 fi
3101                 # It was forced, so it should be found.
3102                 if [ "$with_nforenum" != "1" ]; then
3103                         log 1 "configure: error: nforenum couldn't be found"
3104                         log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
3105                         exit 1
3106                 fi
3108                 nforenum=""
3109                 return 0
3110         fi
3112         log 1 "checking nforenum... found"
3115 detect_cputype() {
3116         if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
3117                 log 1 "forcing cpu-type... $cpu_type bits"
3118                 return;
3119         fi
3120         echo "#define _SQ64 1" > tmp.64bit.cpp
3121         echo "#include \"src/stdafx.h\"" >> tmp.64bit.cpp
3122         echo "assert_compile(sizeof(size_t) == 8);" >> tmp.64bit.cpp
3123         echo "int main() { return 0; }" >> tmp.64bit.cpp
3124         execute="$cxx_host $CFLAGS tmp.64bit.cpp -o tmp.64bit -DTESTING 2>&1"
3125         cpu_type="`eval $execute 2>/dev/null`"
3126         ret=$?
3127         log 2 "executing $execute"
3128         log 2 "  returned $cpu_type"
3129         log 2 "  exit code $ret"
3130         if [ "$ret" = "0" ]; then cpu_type="64"; else cpu_type="32"; fi
3131         log 1 "detecting cpu-type... $cpu_type bits"
3132         rm -f tmp.64bit tmp.64bit.cpp
3135 detect_sse_capable_architecture() {
3136         # 0 means no, 1 is auto-detect, 2 is force
3137         if [ "$with_sse" = "0" ]; then
3138                 log 1 "checking SSE... disabled"
3139                 return
3140         fi
3142         echo "#define _SQ64 1" > tmp.sse.cpp
3143         echo "#include <xmmintrin.h>" >> tmp.sse.cpp
3144         echo "#include <smmintrin.h>" >> tmp.sse.cpp
3145         echo "#include <tmmintrin.h>" >> tmp.sse.cpp
3146         echo "int main() { return 0; }" >> tmp.sse.cpp
3147         execute="$cxx_host -msse4.1 $CFLAGS tmp.sse.cpp -o tmp.sse 2>&1"
3148         sse="`eval $execute 2>/dev/null`"
3149         ret=$?
3150         log 2 "executing $execute"
3151         log 2 "  returned $sse"
3152         log 2 "  exit code $ret"
3153         if [ "$ret" = "0" ]; then
3154                 log 1 "detecting SSE... found"
3155         else
3156                 # It was forced, so it should be found.
3157                 if [ "$with_sse" != "1" ]; then
3158                         log 1 "configure: error: SSE couln't be found"
3159                         log 1 "configure: error: you force enabled SSE, but it seems unavailable"
3160                         exit 1
3161                 fi
3163                 log 1 "detecting SSE... not found"
3164                 with_sse="0"
3165         fi
3166         rm -f tmp.sse tmp.exe tmp.sse.cpp
3169 make_sed() {
3170         T_CFLAGS="$CFLAGS"
3171         T_CXXFLAGS="$CXXFLAGS"
3172         T_LDFLAGS="$LDFLAGS"
3174         SRC_OBJS_DIR="$BASE_SRC_OBJS_DIR/$OBJS_SUBDIR"
3176         # All the data needed to compile a single target
3177         #  Make sure if you compile multiple targets to
3178         #  use multiple OBJS_DIR, because all in-between
3179         #  binaries are stored in there, and nowhere else.
3180         SRC_REPLACE="
3181                 s@!!CC_HOST!!@$cc_host@g;
3182                 s@!!CXX_HOST!!@$cxx_host@g;
3183                 s@!!CC_BUILD!!@$cc_build@g;
3184                 s@!!CXX_BUILD!!@$cxx_build@g;
3185                 s@!!WINDRES!!@$windres@g;
3186                 s@!!STRIP!!@$strip $strip_arg@g;
3187                 s@!!LIPO!!@$lipo@g;
3188                 s@!!CFLAGS!!@$T_CFLAGS@g;
3189                 s@!!CFLAGS_BUILD!!@$CFLAGS_BUILD@g;
3190                 s@!!CXXFLAGS!!@$T_CXXFLAGS@g;
3191                 s@!!CXXFLAGS_BUILD!!@$CXXFLAGS_BUILD@g;
3192                 s@!!STRGEN_FLAGS!!@$strgen_flags@g;
3193                 s@!!LIBS!!@$LIBS@g;
3194                 s@!!LDFLAGS!!@$T_LDFLAGS@g;
3195                 s@!!LDFLAGS_BUILD!!@$LDFLAGS_BUILD@g;
3196                 s@!!BIN_DIR!!@$BIN_DIR@g;
3197                 s@!!ROOT_DIR!!@$ROOT_DIR@g;
3198                 s@!!MEDIA_DIR!!@$MEDIA_DIR@g;
3199                 s@!!SOURCE_LIST!!@$SOURCE_LIST@g;
3200                 s@!!SRC_OBJS_DIR!!@$SRC_OBJS_DIR@g;
3201                 s@!!LANG_OBJS_DIR!!@$LANG_OBJS_DIR@g;
3202                 s@!!GRF_OBJS_DIR!!@$GRF_OBJS_DIR@g;
3203                 s@!!SETTING_OBJS_DIR!!@$SETTING_OBJS_DIR@g;
3204                 s@!!SRC_DIR!!@$SRC_DIR@g;
3205                 s@!!SCRIPT_SRC_DIR!!@$SCRIPT_SRC_DIR@g;
3206                 s@!!OSXAPP!!@$OSXAPP@g;
3207                 s@!!LANG_DIR!!@$LANG_DIR@g;
3208                 s@!!TTD!!@$TTD@g;
3209                 s@!!BINARY_DIR!!@$prefix_dir/$binary_dir@g;
3210                 s@!!DATA_DIR!!@$prefix_dir/$data_dir@g;
3211                 s@!!DOC_DIR!!@$prefix_dir/$doc_dir@g;
3212                 s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3213                 s@!!ICON_DIR!!@$prefix_dir/$icon_dir@g;
3214                 s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3215                 s@!!PERSONAL_DIR!!@$personal_dir@g;
3216                 s@!!SHARED_DIR!!@$shared_dir@g;
3217                 s@!!INSTALL_DIR!!@$install_dir@g;
3218                 s@!!BINARY_NAME!!@$binary_name@g;
3219                 s@!!STRGEN!!@$STRGEN@g;
3220                 s@!!ENDIAN_CHECK!!@$ENDIAN_CHECK@g;
3221                 s@!!DEPEND!!@$DEPEND@g;
3222                 s@!!SETTINGSGEN!!@$SETTINGSGEN@g;
3223                 s@!!ENDIAN_FORCE!!@$endian@g;
3224                 s@!!STAGE!!@$STAGE@g;
3225                 s@!!MAKEDEPEND!!@$makedepend@g;
3226                 s@!!CFLAGS_MAKEDEP!!@$cflags_makedep@g;
3227                 s@!!SORT!!@$sort@g;
3228                 s@!!CONFIG_CACHE_COMPILER!!@config.cache.compiler@g;
3229                 s@!!CONFIG_CACHE_LINKER!!@config.cache.linker@g;
3230                 s@!!CONFIG_CACHE_ENDIAN!!@config.cache.endian@g;
3231                 s@!!CONFIG_CACHE_SOURCE!!@config.cache.source@g;
3232                 s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
3233                 s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
3234                 s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
3235                 s@!!LANG_SUPPRESS!!@$lang_suppress@g;
3236                 s@!!OBJS_C!!@$OBJS_C@g;
3237                 s@!!OBJS_CPP!!@$OBJS_CPP@g;
3238                 s@!!OBJS_MM!!@$OBJS_MM@g;
3239                 s@!!OBJS_RC!!@$OBJS_RC@g;
3240                 s@!!SRCS!!@$SRCS@g;
3241                 s@!!OS!!@$os@g;
3242                 s@!!CONFIGURE_FILES!!@$CONFIGURE_FILES@g;
3243                 s@!!AWK!!@$awk@g;
3244                 s@!!DISTCC!!@$distcc@g;
3245                 s@!!NFORENUM!!@$nforenum@g;
3246                 s@!!GRFCODEC!!@$grfcodec@g;
3247         "
3249         if [ "$icon_theme_dir" != "" ]; then
3250                 SRC_REPLACE="$SRC_REPLACE
3251                         s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3252                 "
3253         else
3254                 SRC_REPLACE="$SRC_REPLACE
3255                         s@!!ICON_THEME_DIR!!@@g;
3256                 "
3257         fi
3259         if [ "$man_dir" != "" ]; then
3260                 SRC_REPLACE="$SRC_REPLACE
3261                         s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3262                 "
3263         else
3264                 SRC_REPLACE="$SRC_REPLACE
3265                         s@!!MAN_DIR!!@@g;
3266                 "
3267         fi
3269         if [ "$menu_dir" != "" ]; then
3270                 SRC_REPLACE="$SRC_REPLACE
3271                         s@!!MENU_DIR!!@$prefix_dir/$menu_dir@g;
3272                 "
3273         else
3274                 SRC_REPLACE="$SRC_REPLACE
3275                         s@!!MENU_DIR!!@@g;
3276                 "
3277         fi
3280 generate_menu_item() {
3281         MENU_REPLACE="
3282                 s@!!TTD!!@$TTD@g;
3283                 s@!!MENU_GROUP!!@$menu_group@g;
3284                 s@!!MENU_NAME!!@$menu_name@g
3285         "
3286         log 1 "Generating menu item..."
3287         mkdir -p media
3288         < $ROOT_DIR/media/openttd.desktop.in sed "$MENU_REPLACE" > media/openttd.desktop
3291 generate_main() {
3292         STAGE="[MAIN]"
3294         make_sed
3296         # Create the main Makefile
3297         log 1 "Generating Makefile..."
3298         echo "# Auto-generated file from 'Makefile.in' -- DO NOT EDIT" > Makefile
3299         < $ROOT_DIR/Makefile.in sed "$SRC_REPLACE" >> Makefile
3300         cp $ROOT_DIR/Makefile.bundle.in Makefile.bundle
3301         echo "# Auto-generated file -- DO NOT EDIT" > Makefile.am
3302         echo >> Makefile.am
3303         # Make the copy of the source-list, so we don't trigger an unwanted recompile
3304         cp $SOURCE_LIST config.cache.source.list
3305         # Add the current directory, so we don't trigger an unwanted recompile
3306         echo "`pwd`" > config.cache.pwd
3307         # Make sure config.cache is OLDER then config.cache.source.list
3308         touch config.cache
3309         touch config.pwd
3311         if [ "$menu_dir" != "" ]; then
3312                 generate_menu_item
3313         fi
3316 generate_lang() {
3317         STAGE="[LANG]"
3319         make_sed
3321         # Create the language file
3322         mkdir -p $LANG_OBJS_DIR
3324         log 1 "Generating lang/Makefile..."
3325         echo "# Auto-generated file from 'Makefile.lang.in' -- DO NOT EDIT" > $LANG_OBJS_DIR/Makefile
3326         < $ROOT_DIR/Makefile.lang.in sed "$SRC_REPLACE" >> $LANG_OBJS_DIR/Makefile
3327         echo "DIRS += $LANG_OBJS_DIR" >> Makefile.am
3328         echo "LANG_DIRS += $LANG_OBJS_DIR" >> Makefile.am
3331 generate_settings() {
3332         STAGE="[SETTING]"
3334         make_sed
3336         # Create the language file
3337         mkdir -p $SETTING_OBJS_DIR
3339         log 1 "Generating setting/Makefile..."
3340         echo "# Auto-generated file from 'Makefile.settings.in' -- DO NOT EDIT" > $SETTING_OBJS_DIR/Makefile
3341         < $ROOT_DIR/Makefile.setting.in sed "$SRC_REPLACE" >> $SETTING_OBJS_DIR/Makefile
3342         echo "DIRS += $SETTING_OBJS_DIR" >> Makefile.am
3345 generate_grf() {
3346         STAGE="[BASESET]"
3348         make_sed
3350         # Create the language file
3351         mkdir -p $GRF_OBJS_DIR
3353         log 1 "Generating grf/Makefile..."
3354         echo "# Auto-generated file from 'Makefile.grf.in' -- DO NOT EDIT" > $GRF_OBJS_DIR/Makefile
3355         < $ROOT_DIR/Makefile.grf.in sed "$SRC_REPLACE" >> $GRF_OBJS_DIR/Makefile
3356         echo "DIRS += $GRF_OBJS_DIR" >> Makefile.am
3359 generate_src_normal() {
3360         STAGE=$1
3362         make_sed
3364         # Create the source file
3365         mkdir -p $SRC_OBJS_DIR
3367         log 1 "Generating $2/Makefile..."
3368         echo "# Auto-generated file from 'Makefile.src.in' -- DO NOT EDIT" > $SRC_OBJS_DIR/Makefile
3369         < $ROOT_DIR/Makefile.src.in sed "$SRC_REPLACE" >> $SRC_OBJS_DIR/Makefile
3370         echo "DIRS += $SRC_OBJS_DIR" >> Makefile.am
3371         echo "SRC_DIRS += $SRC_OBJS_DIR" >> Makefile.am
3374 generate_src_osx() {
3375         cc_host_orig="$cc_host"
3376         cxx_host_orig="$cxx_host"
3377         CFLAGS_orig="$CFLAGS"
3378         LDFLAGS_orig="$LDFLAGS"
3380         for type in $enable_universal; do
3382                 if [ -n "$osx_sdk_104_path" ]; then
3383                         # Use 10.4 SDK for 32-bit targets
3384                         CFLAGS="-isysroot $osx_sdk_104_path $CFLAGS_orig"
3385                         LDFLAGS="-Wl,-syslibroot,$osx_sdk_104_path $LDFLAGS_orig"
3386                 fi
3388                 # We don't want to duplicate the x86_64 stuff for each target, so do it once here
3389                 if [ "$type" = "ppc64" ] || [ "$type" = "x86_64" ]; then
3390                         # 64 bits is always 10.5 or higher. Furthermore it has a non const ICONV
3391                         # and they also removed support for QuickTime/QuickDraw
3392                         if [ -n "$osx_sdk_path" ]; then
3393                                 CFLAGS="-isysroot $osx_sdk_path $CFLAGS_orig"
3394                                 LDFLAGS="-Wl,-syslibroot,$osx_sdk_path $LDFLAGS_orig"
3395                         fi
3396                         CFLAGS="$CFLAGS -D_SQ64 -DNO_QUICKTIME -UENABLE_COCOA_QUICKDRAW"
3397                         LIBS="`echo $LIBS | sed 's/-framework QuickTime//'`"
3398                 fi
3400                 case $type in
3401                         ppc)
3402                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc"
3403                                 cc_host="$cc_host_orig -arch ppc -mmacosx-version-min=10.3"
3404                                 cxx_host="$cxx_host_orig -arch ppc -mmacosx-version-min=10.3"
3405                                 generate_src_normal "[ppc]" "objs/ppc";;
3406                         ppc970)
3407                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc970"
3408                                 cc_host="$cc_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3409                                 cxx_host="$cxx_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3410                                 generate_src_normal "[ppc970]" "objs/ppc970";;
3411                         i386)
3412                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/i386"
3413                                 cc_host="$cc_host_orig -arch i386 -mmacosx-version-min=10.4"
3414                                 cxx_host="$cxx_host_orig -arch i386 -mmacosx-version-min=10.4"
3415                                 generate_src_normal "[i386]" "objs/i386";;
3416                         ppc64)
3417                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc64"
3418                                 cc_host="$cc_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3419                                 cxx_host="$cxx_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3420                                 generate_src_normal "[ppc64]" "objs/ppc64";;
3421                         x86_64)
3422                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/x86_64"
3423                                 cc_host="$cc_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3424                                 cxx_host="$cxx_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3425                                 generate_src_normal "[x86_64]" "objs/x86_64";;
3426                         *) log 1 "Unknown architecture requested for universal build: $type";;
3427                 esac
3428         done
3431 generate_src() {
3432         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
3433                 generate_src_osx
3434         else
3435                 generate_src_normal "[SRC]" "objs"
3436         fi
3439 showhelp() {
3440         echo "'configure' configures OpenTTD."
3441         echo ""
3442         echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
3443         echo ""
3444         echo "To assign environment variables (e.g., CC, CFLAGS...), specify them as"
3445         echo "VAR=VALUE.  See below for descriptions of some of the useful variables."
3446         echo ""
3447         echo "Defaults for the options are specified in brackets."
3448         echo ""
3449         echo "Configuration:"
3450         echo "  -h, --help                     display this help and exit"
3451         echo ""
3452         echo "System types:"
3453         echo "  --build=BUILD                  configure for building on BUILD [guessed]"
3454         echo "  --host=HOST                    cross-compile to build programs to run"
3455         echo "                                 on HOST [BUILD]"
3456         echo "  --windres=WINDRES              the windres to use [HOST-windres]"
3457         echo "  --strip=STRIP                  the strip to use [HOST-strip]"
3458         echo "  --awk=AWK                      the awk to use in configure [awk]"
3459         echo "  --pkg-config=PKG-CONFIG        the pkg-config to use in configure [pkg-config]"
3460         echo "  --lipo=LIPO                    the lipo to use (OSX ONLY) [HOST-lipo]"
3461         echo "  --os=OS                        the OS we are compiling for [DETECT]"
3462         echo "                                 DETECT/UNIX/OSX/FREEBSD/DRAGONFLY/OPENBSD/"
3463         echo "                                 NETBSD/MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/"
3464         echo "                                 MINGW/OS2/DOS/WINCE/PSP/HAIKU"
3465         echo "  --endian=ENDIAN                set the endian of the HOST (AUTO/LE/BE)"
3466         echo ""
3467         echo "Paths:"
3468         echo "  --prefix-dir=dir               specifies the prefix for all installed"
3469         echo "                                 files [/usr/local]"
3470         echo "  --binary-dir=dir               location of the binary. Will be prefixed"
3471         echo "                                 with the prefix-dir [games]"
3472         echo "  --data-dir=dir                 location of data files (lang, data, gm)."
3473         echo "                                 Will be prefixed with the prefix-dir"
3474         echo "                                 [share/games/openttd]"
3475         echo "  --doc-dir=dir                  location of the doc files"
3476         echo "                                 Will be prefixed with the prefix-dir"
3477         echo "                                 [$doc_dir]"
3478         echo "  --icon-dir=dir                 location of icons. Will be prefixed"
3479         echo "                                 with the prefix-dir [share/pixmaps]"
3480         echo "  --icon-theme-dir=dir           location of icon theme."
3481         echo "                                 Will be prefixed with the prefix-dir"
3482         echo "                                 and postfixed with size-dirs [$icon_theme_dir]"
3483         echo "  --man-dir=dir                  location of the manual page (UNIX only)"
3484         echo "                                 Will be prefixed with the prefix-dir"
3485         echo "                                 [$man_dir]"
3486         echo "  --menu-dir=dir                 location of the menu item. (UNIX only, except OSX)"
3487         echo "                                 Will be prefixed with the prefix-dir"
3488         echo "                                 [share/applications]"
3489         echo "  --personal-dir=dir             location of the personal directory"
3490         echo "                                 [os-dependent default]"
3491         echo "  --shared-dir=dir               location of shared data files"
3492         echo "                                 [os-dependent default]"
3493         echo "  --install-dir=dir              specifies the root to install to."
3494         echo "                                 Useful to install into jails [/]"
3495         echo "  --binary-name                  the name used for the binary, icons,"
3496         echo "                                 desktop file, etc. when installing [openttd]"
3497         echo ""
3498         echo "Features and packages:"
3499         echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
3500         echo "  --enable-desync-debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
3501         echo "  --enable-profiling             enables profiling"
3502         echo "  --enable-lto                   enables GCC's Link Time Optimization (LTO)/ICC's"
3503         echo "                                 Interprocedural Optimization if available"
3504         echo "  --enable-dedicated             compile a dedicated server (without video)"
3505         echo "  --enable-static                enable static compile (doesn't work for"
3506         echo "                                 all HOSTs)"
3507         echo "  --enable-translator            enable extra output for translators"
3508         echo "  --enable-universal[=ARCH]      enable universal builds (OSX ONLY). Allowed is any combination"
3509         echo "                                 of architectures: i386 ppc ppc970 ppc64 x86_64"
3510         echo "                                 Default architectures are: i386 ppc"
3511         echo "  --enable-osx-g5                enables optimizations for ppc970 (G5) (OSX ONLY)"
3512         echo "  --disable-cocoa-quartz         disable the quartz window mode driver for Cocoa (OSX ONLY)"
3513         echo "  --disable-cocoa-quickdraw      disable the quickdraw window mode driver for Cocoa (OSX ONLY)"
3514         echo "  --disable-unicode              disable unicode support to build win9x"
3515         echo "                                 version (Win32 ONLY)"
3516         echo "  --enable-console               compile as a console application instead of as a GUI application."
3517         echo "                                 If this setting is active, debug output will appear in the same"
3518         echo "                                 console instead of opening a new window. (Win32 ONLY)"
3519         echo "  --disable-network              disable network support"
3520         echo "  --disable-assert               disable asserts (continue on errors)"
3521         echo "  --enable-strip                 enable any possible stripping"
3522         echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
3523         echo "                                 (OSX ONLY)"
3524         echo "  --without-application-bundle   disable generation of application bundle"
3525         echo "                                 (OSX ONLY)"
3526         echo "  --without-menu-entry           Don't generate a menu item (Freedesktop based only)"
3527         echo "  --menu-group=group             Category in which the menu item will be placed (Freedesktop based only)"
3528         echo "  --menu-name=name               Name of the menu item when placed [OpenTTD]"
3529         echo "  --with-direct-music            enable direct music support (Win32 ONLY)"
3530         echo "  --with-sort=sort               define a non-default location for sort"
3531         echo "  --with-midi=midi               define which midi-player to use"
3532         echo "  --with-midi-arg=arg            define which args to use for the"
3533         echo "                                 midi-player"
3534         echo "  --with-libtimidity[=\"pkg-config libtimidity\"]"
3535         echo "                                 enables libtimidity support"
3536         echo "  --with-allegro[=\"pkg-config allegro\"]"
3537         echo "                                 enables Allegro video driver support"
3538         echo "  --with-cocoa                   enables COCOA video driver (OSX ONLY)"
3539         echo "  --with-sdl[=\"pkg-config sdl\"]  enables SDL video driver support"
3540         echo "  --with-zlib[=\"pkg-config zlib\"]"
3541         echo "                                 enables zlib support"
3542         echo "  --with-liblzma[=\"pkg-config liblzma\"]"
3543         echo "                                 enables liblzma support"
3544         echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
3545         echo "  --with-png[=\"pkg-config libpng\"]"
3546         echo "                                 enables libpng support"
3547         echo "  --with-freetype[=\"pkg-config freetype2\"]"
3548         echo "                                 enables libfreetype support"
3549         echo "  --with-fontconfig[=\"pkg-config fontconfig\"]"
3550         echo "                                 enables fontconfig support"
3551         echo "  --with-xdg-basedir[=\"pkg-config libxdg-basedir\"]"
3552         echo "                                 enables XDG base directory support"
3553         echo "  --with-icu                     enables icu components for layout and sorting"
3554         echo "  --with-icu-layout[=\"pkg-config icu-lx\"]"
3555         echo "                                 enables icu components for layouting (right-to-left support)"
3556         echo "  --with-icu-sort[=\"pkg-config icu-i18n\"]"
3557         echo "                                 enables icu components for locale specific string sorting"
3558         echo "  --static-icu                   try to link statically (libsicu instead of"
3559         echo "                                 libicu; can fail as the new name is guessed)"
3560         echo "  --with-iconv[=iconv-path]      enables iconv support"
3561         echo "  --with-psp-config[=psp-config] enables psp-config support (PSP ONLY)"
3562         echo "  --disable-builtin-depend       disable use of builtin deps finder"
3563         echo "  --with-makedepend[=makedepend] enables makedepend support"
3564         echo "  --with-ccache                  enables ccache support"
3565         echo "  --with-distcc                  enables distcc support"
3566         echo "  --without-grfcodec             disable usage of grfcodec and re-generation of base sets"
3567         echo "  --without-threads              disable threading support"
3568         echo "  --without-sse                  disable SSE support (x86/x86_64 only)"
3569         echo ""
3570         echo "Some influential environment variables:"
3571         echo "  CC                             C compiler command"
3572         echo "  CXX                            C++ compiler command"
3573         echo "  CFLAGS                         C compiler flags"
3574         echo "  CXXFLAGS                       C++ compiler flags"
3575         echo "  WINDRES                        windres command"
3576         echo "  LDFLAGS                        linker flags, e.g. -L<lib dir> if you"
3577         echo "                                 have libraries in a nonstandard"
3578         echo "                                 directory <lib dir>"
3579         echo "  CFLAGS_BUILD                   C compiler flags for build time tool generation"
3580         echo "  CXXFLAGS_BUILD                 C++ compiler flags for build time tool generation"
3581         echo "  LDFLAGS_BUILD                  linker flags for build time tool generation"
3582         echo "  PKG_CONFIG_PATH                additional library search paths (see \"man pkg-config\")"
3583         echo "  PKG_CONFIG_LIBDIR              replace the default library search path (see \"man pkg-config\")"
3584         echo ""
3585         echo "Use these variables to override the choices made by 'configure' or to help"
3586         echo "it to find libraries and programs with nonstandard names/locations."