Move FollowWormhole into the track follower base classes
[openttd/fttd.git] / config.lib
blobf3d3e108fad7e266a7fbc1b0fa88d2343acb6d1c
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         os="DETECT"
33         endian="AUTO"
34         cpu_type="DETECT"
35         config_log="config.log"
36         prefix_dir="/usr/local"
37         binary_dir="games"
38         data_dir="share/games/openttd"
39         doc_dir="1"
40         icon_dir="share/pixmaps"
41         icon_theme_dir="1"
42         personal_dir="1"
43         shared_dir="1"
44         install_dir="/"
45         man_dir="1"
46         menu_dir="1"
47         menu_group="Game;"
48         menu_name="OpenTTD"
49         binary_name="openttd"
50         enable_debug="0"
51         enable_desync_debug="0"
52         enable_profiling="0"
53         enable_lto="0"
54         enable_dedicated="0"
55         enable_network="1"
56         enable_static="1"
57         enable_translator="0"
58         enable_unicode="1"
59         enable_console="1";
60         enable_assert="1"
61         enable_strip="0"
62         enable_universal="0"
63         enable_osx_g5="0"
64         enable_cocoa_quartz="1"
65         enable_cocoa_quickdraw="1"
66         with_osx_sysroot="1"
67         with_application_bundle="1"
68         with_menu_entry="1"
69         with_allegro="1"
70         with_sdl="1"
71         with_cocoa="1"
72         with_zlib="1"
73         with_lzma="1"
74         with_lzo2="1"
75         with_xdg_basedir="1"
76         with_png="1"
77         enable_builtin_depend="1"
78         with_makedepend="0"
79         with_direct_music="1"
80         with_sort="1"
81         with_iconv="1"
82         with_midi=""
83         with_midi_arg=""
84         with_libtimidity="1"
85         with_freetype="1"
86         with_fontconfig="1"
87         with_icu="1"
88         static_icu="0"
89         with_psp_config="1"
90         with_threads="1"
91         with_distcc="1"
92         with_ccache="1"
93         with_nforenum="1"
94         with_grfcodec="1"
96         save_params_array="
97                 build
98                 host
99                 cc_build
100                 cc_host
101                 cxx_build
102                 cxx_host
103                 windres
104                 strip
105                 lipo
106                 awk
107                 os
108                 endian
109                 cpu_type
110                 config_log
111                 prefix_dir
112                 binary_dir
113                 data_dir
114                 doc_dir
115                 icon_dir
116                 icon_theme_dir
117                 man_dir
118                 menu_dir
119                 personal_dir
120                 shared_dir
121                 install_dir
122                 menu_group
123                 menu_name
124                 binary_name
125                 enable_debug
126                 enable_desync_debug
127                 enable_profiling
128                 enable_lto
129                 enable_dedicated
130                 enable_network
131                 enable_static
132                 enable_translator
133                 enable_unicode
134                 enable_console
135                 enable_assert
136                 enable_strip
137                 enable_universal
138                 enable_osx_g5
139                 enable_cocoa_quartz
140                 enable_cocoa_quickdraw
141                 with_osx_sysroot
142                 with_application_bundle
143                 with_allegro
144                 with_sdl
145                 with_cocoa
146                 with_zlib
147                 with_lzma
148                 with_lzo2
149                 with_xdg_basedir
150                 with_png
151                 enable_builtin_depend
152                 with_makedepend
153                 with_direct_music
154                 with_sort
155                 with_iconv
156                 with_midi
157                 with_midi_arg
158                 with_libtimidity
159                 with_freetype
160                 with_fontconfig
161                 with_icu
162                 static_icu
163                 with_psp_config
164                 with_threads
165                 with_distcc
166                 with_ccache
167                 with_grfcodec
168                 with_nforenum
169         CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD"
172 detect_params() {
173         # Walk over all params from the user and override any default settings if
174         #  needed. This also handles any invalid option.
175         for p in "$@"; do
176                 if [ -n "$prev_p" ]; then
177                         eval "$prev_p=\$p"
178                         prev_p=
179                         continue
180                 fi
182                 optarg=`expr "x$p" : 'x[^=]*=\(.*\)'`
184                 case "$p" in
185                         --help | -h | -\?)            showhelp; exit 0;;
187                         --config-log)                 prev_p="config_log";;
188                         --config-log=*)               config_log="$optarg";;
190                         --build)                      prev_p="build";;
191                         --build=*)                    build="$optarg";;
193                         --host)                       prev_p="host";;
194                         --host=*)                     host="$optarg";;
196                         --os)                         prev_p="os";;
197                         --os=*)                       os="$optarg";;
199                         --cpu-type)                   prev_p="cpu_type";;
200                         --cpu-type=*)                 cpu_type="$optarg";;
202                         --cc-build)                   prev_p="cc_build";;
203                         --cc-build=*)                 cc_build="$optarg";;
204                         --cc-host)                    prev_p="cc_host";;
205                         --cc-host=*)                  cc_host="$optarg";;
206                         --cxx-build)                  prev_p="cxx_build";;
207                         --cxx-build=*)                cxx_build="$optarg";;
208                         --cxx-host)                   prev_p="cxx_host";;
209                         --cxx-host=*)                 cxx_host="$optarg";;
210                         --windres)                    prev_p="windres";;
211                         --windres=*)                  windres="$optarg";;
212                         --awk)                        prev_p="awk";;
213                         --awk=*)                      awk="$optarg";;
214                         --strip)                      prev_p="strip";;
215                         --strip=*)                    strip="$optarg";;
216                         --lipo)                       prev_p="lipo";;
217                         --lipo=*)                     lipo="$optarg";;
219                         --endian)                     prev_p="endian";;
220                         --endian=*)                   endian="$optarg";;
224                         # Alias --prefix with --prefix-dir, for compatibility with GNU autotools
225                         --prefix-dir | --prefix)      prev_p="prefix_dir";;
226                         --prefix-dir=* | --prefix=*)  prefix_dir="$optarg";;
228                         --binary-dir)                 prev_p="binary_dir";;
229                         --binary-dir=*)               binary_dir="$optarg";;
231                         --data-dir)                   prev_p="data_dir";;
232                         --data-dir=*)                 data_dir="$optarg";;
234                         --doc-dir)                    prev_p="doc_dir";;
235                         --doc-dir=*)                  doc_dir="$optarg";;
237                         --icon-dir)                   prev_p="icon_dir";;
238                         --icon-dir=*)                 icon_dir="$optarg";;
240                         --icon-theme-dir)             prev_p="icon_theme_dir";;
241                         --icon-theme-dir=*)           icon_theme_dir="$optarg";;
242                         --without-icon-theme)         icon_theme_dir="";;
244                         --menu-dir)                   prev_p="menu_dir";;
245                         --menu-dir=*)                 menu_dir="$optarg";;
246                         --without-menu-entry)         menu_dir="";;
248                         --menu-name)                  prev_p="menu_name";;
249                         --menu-name=*)                menu_name="$optarg";;
251                         --binary-name)                prev_p="binary_name";;
252                         --binary-name=*)              binary_name="$optarg";;
254                         --man-dir)                    prev_p="man_dir";;
255                         --man-dir=*)                  man_dir="$optarg";;
257                         --personal-dir)               prev_p="personal_dir";;
258                         --personal-dir=*)             personal_dir="$optarg";;
259                         --without-personal-dir)       personal_dir="";;
261                         --shared-dir)                 prev_p="shared_dir";;
262                         --shared-dir=*)               shared_dir="$optarg";;
263                         --without-shared-dir)         shared_dir="";;
265                         --install-dir)                prev_p="install_dir";;
266                         --install-dir=*)              install_dir="$optarg";;
270                         --menu-group)                 prev_p="menu_group";;
271                         --menu-group=*)               menu_group="$optarg";;
275                         --enable-debug)               enable_debug="1";;
276                         --enable-debug=*)             enable_debug="$optarg";;
277                         --enable-desync-debug)        enable_desync_debug="1";;
278                         --enable-desync-debug=*)      enable_desync_debug="$optarg";;
279                         --enable-profiling)           enable_profiling="1";;
280                         --enable-profiling=*)         enable_profiling="$optarg";;
281                         --enable-lto)                 enable_lto="1";;
282                         --enable-lto=*)               enable_lto="$optarg";;
283                         --enable-ipo)                 enable_lto="1";;
284                         --enable-ipo=*)               enable_lto="$optarg";;
285                         --enable-dedicated)           enable_dedicated="1";;
286                         --enable-dedicated=*)         enable_dedicated="$optarg";;
287                         --enable-network)             enable_network="2";;
288                         --enable-network=*)           enable_network="$optarg";;
289                         --disable-network)            enable_network="0";;
290                         --disable-static)             enable_static="0";;
291                         --enable-static)              enable_static="2";;
292                         --enable-static=*)            enable_static="$optarg";;
293                         --disable-translator)         enable_translator="0";;
294                         --enable-translator)          enable_translator="2";;
295                         --enable-translator=*)        enable_translator="$optarg";;
296                         --disable-assert)             enable_assert="0";;
297                         --enable-assert)              enable_assert="2";;
298                         --enable-assert=*)            enable_assert="$optarg";;
299                         --disable-strip)              enable_strip="0";;
300                         --enable-strip)               enable_strip="2";;
301                         --enable-strip=*)             enable_strip="$optarg";;
302                         --disable-universal)          enable_universal="0";;
303                         --enable-universal)           enable_universal="i386 ppc";;
304                         --enable-universal=*)         enable_universal="$optarg";;
305                         --disable-osx-g5)             enable_osx_g5="0";;
306                         --enable-osx-g5)              enable_osx_g5="2";;
307                         --enable-osx-g5=*)            enable_osx_g5="$optarg";;
308                         --disable-unicode)            enable_unicode="0";;
309                         --enable-unicode)             enable_unicode="2";;
310                         --enable-unicode=*)           enable_unicode="$optarg";;
311                         --disable-console)            enable_console="0";;
312                         --enable-console)             enable_console="2";;
313                         --enable-console=*)           enable_console="$optarg";;
315                         --disable-cocoa-quartz)       enable_cocoa_quartz="0";;
316                         --enable-cocoa-quartz)        enable_cocoa_quartz="2";;
317                         --enable-cocoa-quartz=*)      enable_cocoa_quartz="$optarg";;
318                         --disable-cocoa-quickdraw)    enable_cocoa_quickdraw="0";;
319                         --enable-cocoa-quickdraw)     enable_cocoa_quickdraw="2";;
320                         --enable-cocoa-quickdraw=*)   enable_cocoa_quickdraw="$optarg";;
322                         --with-allegro)               with_allegro="2";;
323                         --without-allegro)            with_allegro="0";;
324                         --with-allegro=*)             with_allegro="$optarg";;
326                         --with-sdl)                   with_sdl="2";;
327                         --without-sdl)                with_sdl="0";;
328                         --with-sdl=*)                 with_sdl="$optarg";;
330                         --with-cocoa)                 with_cocoa="2";;
331                         --without-cocoa)              with_cocoa="0";;
332                         --with-cocoa=*)               with_cocoa="$optarg";;
334                         --with-zlib)                  with_zlib="2";;
335                         --without-zlib)               with_zlib="0";;
336                         --with-zlib=*)                with_zlib="$optarg";;
338                         --with-lzma)                  with_lzma="2";;
339                         --without-lzma)               with_lzma="0";;
340                         --with-lzma=*)                with_lzma="$optarg";;
341                         --with-liblzma)               with_lzma="2";;
342                         --without-liblzma)            with_lzma="0";;
343                         --with-liblzma=*)             with_lzma="$optarg";;
345                         --with-lzo2)                  with_lzo2="2";;
346                         --without-lzo2)               with_lzo2="0";;
347                         --with-lzo2=*)                with_lzo2="$optarg";;
348                         --with-liblzo2)               with_lzo2="2";;
349                         --without-liblzo2)            with_lzo2="0";;
350                         --with-liblzo2=*)             with_lzo2="$optarg";;
352                         --with-xdg-basedir)           with_xdg_basedir="2";;
353                         --without-xdg-basedir)        with_xdg_basedir="0";;
354                         --with-xdg-basedir=*)         with_xdg_basedir="$optarg";;
355                         --with-libxdg-basedir)        with_xdg_basedir="2";;
356                         --without-libxdg-basedir)     with_xdg_basedir="0";;
357                         --with-libxdg-basedir=*)      with_xdg_basedir="$optarg";;
359                         --with-png)                   with_png="2";;
360                         --without-png)                with_png="0";;
361                         --with-png=*)                 with_png="$optarg";;
362                         --with-libpng)                with_png="2";;
363                         --without-libpng)             with_png="0";;
364                         --with-libpng=*)              with_png="$optarg";;
366                         --with-libtimidity)           with_libtimidity="2";;
367                         --without-libtimidity)        with_libtimidity="0";;
368                         --with-libtimidity=*)         with_libtimidity="$optarg";;
370                         --with-freetype)              with_freetype="2";;
371                         --without-freetype)           with_freetype="0";;
372                         --with-freetype=*)            with_freetype="$optarg";;
373                         --with-libfreetype)           with_freetype="2";;
374                         --without-libfreetype)        with_freetype="0";;
375                         --with-libfreetype=*)         with_freetype="$optarg";;
377                         --with-fontconfig)            with_fontconfig="2";;
378                         --without-fontconfig)         with_fontconfig="0";;
379                         --with-fontconfig=*)          with_fontconfig="$optarg";;
380                         --with-libfontconfig)         with_fontconfig="2";;
381                         --without-libfontconfig)      with_fontconfig="0";;
382                         --with-libfontconfig=*)       with_fontconfig="$optarg";;
384                         --with-icu)                   with_icu="2";;
385                         --without-icu)                with_icu="0";;
386                         --with-icu=*)                 with_icu="$optarg";;
387                         --with-libicu)                with_icu="2";;
388                         --without-libicu)             with_icu="0";;
389                         --with-libicu=*)              with_icu="$optarg";;
390                         --static-icu)                 static_icu="1";;
391                         --static-icu=*)               static_icu="$optarg";;
392                         --static-libicu)              static_icu="1";;
393                         --static-libicu=*)            static_icu="$optarg";;
395                         --with-psp-config)            with_psp_config="2";;
396                         --without-psp-config)         with_psp_config="0";;
397                         --with-psp-config=*)          with_psp_config="$optarg";;
399                         --disable-builtin-depend)     enable_builtin_depend="0";;
400                         --enable-builtin-depend)      enable_builtin_depend="2";;
401                         --enable-builtin-depend=*)    enable_builtin_depend="$optarg";;
403                         --with-makedepend)            with_makedepend="2";;
404                         --without-makedepend)         with_makedepend="0";;
405                         --with-makedepend=*)          with_makedepend="$optarg";;
407                         --with-direct-music)          with_direct_music="2";;
408                         --without-direct-music)       with_direct_music="0";;
409                         --with-direct-music=*)        with_direct_music="$optarg";;
411                         --with-sort)                  with_sort="2";;
412                         --without-sort)               with_sort="0";;
413                         --with-sort=*)                with_sort="$optarg";;
415                         --with-iconv)                 with_iconv="2";;
416                         --without-iconv)              with_iconv="0";;
417                         --with-iconv=*)               with_iconv="$optarg";;
419                         --with-midi=*)                with_midi="$optarg";;
420                         --with-midi-arg=*)            with_midi_arg="$optarg";;
422                         --without-distcc)             with_distcc="0";;
423                         --with-distcc)                with_distcc="2";;
424                         --with-distcc=*)              with_distcc="$optarg";;
426                         --without-ccache)             with_ccache="0";;
427                         --with-ccache)                with_ccache="2";;
428                         --with-ccache=*)              with_ccache="$optarg";;
430                         --without-nforenum)           with_nforenum="0";;
431                         --with-nforenum)              with_nforenum="2";;
432                         --with-nforenum=*)            with_nforenum="$optarg";;
434                         --without-grfcodec)           with_grfcodec="0";;
435                         --with-grfcodec)              with_grfcodec="2";;
436                         --with-grfcodec=*)            with_grfcodec="$optarg";;
438                         --without-osx-sysroot)        with_osx_sysroot="0";;
439                         --with-osx-sysroot)           with_osx_sysroot="2";;
440                         --with-osx-sysroot=*)         with_osx_sysroot="$optarg";;
442                         --without-application-bundle) with_application_bundle="0";;
443                         --with-application-bundle)    with_application_bundle="1";;
444                         --with-application-bundle=*)  with_application_bundle="$optarg";;
446                         --without-threads)            with_threads="0";;
447                         --with-threads)               with_threads="1";;
448                         --with-threads=*)             with_threads="$optarg";;
450                         CC=* | --CC=*)                CC="$optarg";;
451                         CXX=* | --CXX=*)              CXX="$optarg";;
452                         CFLAGS=* | --CFLAGS=*)        CFLAGS="$optarg";;
453                         CXXFLAGS=* | --CXXFLAGS=*)    CXXFLAGS="$optarg";;
454                         LDFLAGS=* | --LDFLAGS=*)      LDFLAGS="$optarg";;
455                         CFLAGS_BUILD=* | --CFLAGS_BUILD=* | --CFLAGS-BUILD=*)     CFLAGS_BUILD="$optarg";;
456                         CXXFLAGS_BUILD=* | --CXXFLAGS_BUILD=* | --CXXFLAGS-BUILD=*) CXXFLAGS_BUILD="$optarg";;
457                         LDFLAGS_BUILD=* | --LDFLAGS_BUILD=* | --LDFLAGS-BUILD=*)   LDFLAGS_BUILD="$optarg";;
459                         --ignore-extra-parameters)    ignore_extra_parameters="1";;
461                         --* | -*)
462                                 if [ "$ignore_extra_parameters" = "0" ]; then
463                                         log 1 "Unknown option $p"
464                                         exit 1
465                                 else
466                                         log 1 "Unknown option $p ignored"
467                                 fi
468                                 ;;
469                 esac
470         done
472         if [ -n "$prev_p" ]; then
473                 log 1 "configure: error: missing argument to --$prev_p"
474                 exit 1
475         fi
477         # Clean the logfile
478         echo "" > $config_log
479         log 2 "Invocation: $0 $*"
482 save_params() {
483         # Here we save all params, so we can later on do an exact redo of this
484         #  configuration, without having the user to re-input stuff
486         echo "Running configure with following options:" >> $config_log
487         echo "" >> $config_log
489         configure="$CONFIGURE_EXECUTABLE --ignore-extra-parameters"
490         for p in $save_params_array; do
491                 eval "v=\"\$$p\""
492                 p=`echo "$p" | sed 's@_@-@g;s@\n@@g;s@ @\\ @g'`
493                 # Only save those params that aren't empty
494                 configure="$configure --$p=\"$v\""
495         done
497         echo "$configure" >> $config_log
498         echo "$configure" > config.cache
499         echo "" >> $config_log
502 check_params() {
503         # Some params want to be in full uppercase, else they might not work as
504         # expected.. fix that here
506         endian=`echo $endian | tr '[a-z]' '[A-Z]'`
507         os=`echo $os | tr '[a-z]' '[A-Z]'`
508         cpu_type=`echo $cpu_type | tr '[a-z]' '[A-Z]'`
510         # Check if all params have valid values
512         # Endian only allows AUTO, LE and, BE
513         if ! echo $endian | egrep -q '^(AUTO|LE|BE|PREPROCESSOR)$'; then
514                 log 1 "configure: error: invalid option --endian=$endian"
515                 log 1 " Available options are: --endian=[AUTO|LE|BE]"
516                 exit 1
517         fi
518         if [ "$endian" = "PREPROCESSOR" ] && [ "$os" != "OSX" ]; then
519                 log 1 "configure: error: invalid option --endian=$endian"
520                 log 1 " PREPROCESSOR is only available for OSX"
521                 exit 1
522         fi
523         # OS only allows DETECT, UNIX, OSX, FREEBSD, OPENBSD, MORPHOS, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
524         if ! echo $os | egrep -q '^(DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP)$'; then
525                 log 1 "configure: error: invalid option --os=$os"
526                 log 1 " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP]"
527                 exit 1
528         fi
529         # cpu_type can be either 32 or 64
530         if ! echo $cpu_type | egrep -q '^(32|64|DETECT)$'; then
531                 log 1 "configure: error: invalid option --cpu-type=$cpu_type"
532                 log 1 " Available options are: --cpu-type[=DETECT|32|64]"
533                 exit 1
534         fi
535         # enable_debug should be between 0 and 4
536         if ! echo $enable_debug | egrep -q '^[0123]$'; then
537                 log 1 "configure: error: invalid option --enable-debug=$enable_debug"
538                 log 1 " Available options are: --enable-debug[=0123]"
539                 exit 1
540         fi
542         # enable_desync_debug should be between 0 and 3
543         if ! echo $enable_desync_debug | egrep -q '^[012]$'; then
544                 log 1 "configure: error: invalid option --enable-desync-debug=$enable_desync_debug"
545                 log 1 " Available options are: --enable-desync-debug[=012]"
546                 exit 1
547         fi
549         detect_awk
551         detect_os
553         check_build
554         check_host
556         # Check for universal builds; they only make sense for OSX, so fail if enabled for another OS
557         if [ "$enable_universal" = "0" ]; then
558                 log 1 "checking universal build... no"
559         else
560                 if [ "$os" != "OSX" ]; then
561                         log 1 "configure: error: --enable-universal only works on OSX"
562                         exit 1
563                 fi
564                 log 1 "checking universal build... yes, for: $enable_universal"
565         fi
567         # Already detected by check_build
568         log 1 "checking build cc... $cc_build"
569         log 1 "checking host cc... $cc_host"
571         check_cxx_build
572         check_cxx_host
573         check_windres
574         if [ "$enable_strip" != "0" ]; then
575                 check_strip
576         else
577                 log 1 "checking strip... disabled"
578         fi
579         check_lipo
581         if [ "$enable_builtin_depend" != "0" ]; then
582                 log 1 "checking builtin depend... yes"
583                 makedepend="\$(SRC_OBJS_DIR)/\$(DEPEND)"
584         else
585                 log 1 "checking builtin depend... no"
586         fi
588         check_makedepend
589         detect_cputype
591         if [ "$enable_static" = "1" ]; then
592                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "DOS" ]; then
593                         enable_static="2"
594                 else
595                         enable_static="0"
596                 fi
597         fi
599         if [ "$enable_static" != "0" ]; then
600                 log 1 "checking static... yes"
602                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "OSX" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "DOS" ]; then
603                         log 1 "WARNING: static is only known to work on Windows, DOS, MacOSX and MorphOS"
604                         log 1 "WARNING: use static at your own risk on this platform"
606                         sleep 5
607                 fi
608         else
609                 log 1 "checking static... no"
610         fi
612         if [ "$enable_unicode" = "1" ]; then
613                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "DOS" ]; then
614                         enable_unicode="2"
615                 else
616                         enable_unicode="0"
617                 fi
618         fi
620         if [ "$enable_unicode" != "0" ]; then
621                 log 1 "checking unicode... yes"
622         else
623                 log 1 "checking unicode... no"
624         fi
626         # Show what we configured
627         if [ "$enable_debug" = "0" ]; then
628                 log 1 "using debug level... no"
629         elif [ "$enable_profiling" != "0" ]; then
630                 log 1 "using debug level... profiling (debug level $enable_debug)"
631         else
632                 log 1 "using debug level... level $enable_debug"
633         fi
635         if [ "$enable_desync_debug" = "0" ]; then
636                 log 1 "using desync debug level... no"
637         else
638                 log 1 "using desync debug level... level $enable_desync_debug"
639                 log 1 "WARNING: desync debug functions slow down the game considerably."
640                 log 1 "WARNING: use only when you are instructed to do so"
641                 log 1 "         or when you know what you are doing."
643                 sleep 5
644         fi
646         if [ "$enable_lto" != "0" ]; then
647                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
648                 if $cxx_build -dumpspecs 2>&1 | grep -q '\%{flto' || $cxx_build -help ipo 2>&1 | grep -q '\-ipo'; then
649                         log 1 "using link time optimization... yes"
650                 else
651                         enable_lto="0"
652                         log 1 "using link time optimization... no"
653                         log 1 "WARNING: you selected link time optimization but it is not found."
654                         sleep 5
655                 fi
656         else
657                 log 1 "using link time optimization... no"
658         fi
661         if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
662                 if [ "$with_osx_sysroot" = "1" ]; then
663                         with_osx_sysroot="0"
665                         log 1 "checking OSX sysroot... not OSX, skipping"
666                 else
667                         log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
668                         exit 1
669                 fi
670         fi
672         if [ "$with_osx_sysroot" != "0" ]; then
673                 if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
674                         # Sysroot manually specified? Check for usability
675                         log 1 "checking OSX sysroot... $with_osx_sysroot"
676                         if ! check_osx_sdk "$with_osx_sysroot"; then
677                                 log 1 "Passed sysroot not found/not functional"
678                                 exit 1
679                         fi
680                 else
681                         # If autodetect and no universal, use system default
682                         if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
683                                 log 1 "checking OSX sysroot... no (use system default)"
684                         else
685                                 log 1 "checking OSX sysroot... automatically"
686                                 detect_osx_sdk
687                         fi
688                 fi
690                 if [ -n "$osx_sdk_path" ]; then
691                         if [ "$enable_universal" != "0" ]; then
692                                 if [ -z "$osx_sdk_104_path" ]; then
693                                         log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
694                                         log 1 "WARNING: binary will only run on OSX 10.5 or later"
695                                         osx_sdk_104_path="$osx_sdk_path"
696                                 fi
697                                 OSX_SYSROOT="-isysroot $osx_sdk_104_path"
698                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
699                         else
700                                 OSX_SYSROOT="-isysroot $osx_sdk_path"
701                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
702                         fi
703                 fi
704         else
705                 if [ "$os" = "OSX" ]; then
706                         log 1 "checking OSX sysroot... no (use system default)"
707                 fi
708         fi
710         detect_allegro
711         detect_sdl
712         detect_cocoa
714         if [ "$enable_dedicated" != "0" ]; then
715                 log 1 "checking GDI video driver... dedicated server, skipping"
716                 log 1 "checking dedicated... found"
718                 if [ "$enable_network" = "0" ]; then
719                         log 1 "configure: error: building a dedicated server without network support is pointless"
720                         exit 1
721                 fi
722         else
723                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
724                         log 1 "checking GDI video driver... found"
725                 else
726                         log 1 "checking GDI video driver... not Windows, skipping"
727                 fi
729                 if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
730                         log 1 "configure: error: no video driver development files found"
731                         log 1 " If you want a dedicated server use --enable-dedicated as parameter"
732                         exit 1
733                 else
734                         log 1 "checking dedicated... not selected"
735                 fi
736         fi
738         if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
739                 log 1 "checking console application... not Windows, skipping"
740         elif [ "$enable_console" = "1" ] && [ "$enable_dedicated" != "0" ]; then
741                 log 1 "checking console application... dedicated server, enabled"
742                 enable_console="2"
743         elif [ "$enable_console" = "1" ]; then
744                 log 1 "checking console application... disabled (only used when forced)"
745                 enable_console="0"
746         elif [ "$enable_console" = "0" ]; then
747                 log 1 "checking console application... disabled"
748         else
749                 log 1 "checking console application... enabled"
750         fi
752         if [ "$enable_network" = "1" ] && [ "$os" = "DOS" ]; then
753                 log 1 "checking network... DOS, skipping"
754                 enable_network=0
755         elif [ "$enable_network" != "0" ]; then
756                 log 1 "checking network... found"
757         else
758                 log 1 "checking network... disabled"
759         fi
761         log 1 "checking squirrel... found"
762         SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"
764         if [ "$enable_translator" != "0" ]; then
765                 log 1 "checking translator... debug"
766                 # -t shows TODO items, normally they are muted
767                 strgen_flags="-t"
768         else
769                 log 1 "checking translator... no"
770                 strgen_flags=""
771         fi
773         if [ "$enable_assert" != "0" ]; then
774                 log 1 "checking assert... enabled"
775         else
776                 log 1 "checking assert... disabled"
777         fi
779         pre_detect_with_zlib=$with_zlib
780         detect_zlib
782         if [ "$with_zlib" = "0" ] || [ -z "$zlib" ]; then
783                 log 1 "WARNING: zlib was not detected or disabled"
784                 log 1 "WARNING: OpenTTD doesn't require zlib, but it does mean that many features"
785                 log 1 "WARNING: (like loading most old savegames/scenarios, loading heightmaps,"
786                 log 1 "WARNING: using PNG, or using fonts, ...) will be disabled."
787                 if [ "$pre_detect_with_zlib" = "0" ]; then
788                         log 1 "WARNING: We strongly suggest you to install zlib."
789                 else
790                         log 1 "configure: error: no zlib detected"
791                         log 1 " If you want to compile without zlib use --without-zlib as parameter"
792                         exit
793                 fi
794         fi
796         pre_detect_with_lzma=$with_lzma
797         detect_lzma
799         if [ "$with_lzma" = "0" ] || [ -z "$lzma_config" ]; then
800                 log 1 "WARNING: lzma was not detected or disabled"
801                 log 1 "WARNING: OpenTTD doesn't require lzma, but it does mean that many features"
802                 log 1 "WARNING: (like loading most savegames/scenarios and joining most servers)"
803                 log 1 "WARNING: will be disabled."
804                 if [ "$pre_detect_with_lzma" = "0" ]; then
805                         log 1 "WARNING: We strongly suggest you to install liblzma."
806                         log 1 "configure: error: no liblzma detected"
807                 else
808                         log 1 " If you want to compile without lzma use --without-lzma as parameter"
809                         exit
810                 fi
811         fi
813         pre_detect_with_lzo2=$with_lzo2
814         detect_lzo2
816         if [ "$with_lzo2" = "0" ] || [ -z "$lzo2" ]; then
817                 log 1 "WARNING: liblzo2 was not detected or disabled"
818                 log 1 "WARNING: OpenTTD doesn't require liblzo2, but it does mean that"
819                 log 1 "WARNING: loading old savegames/scenarios will be disabled."
820                 if [ "$pre_detect_with_lzo2" = "0" ]; then
821                         log 1 "WARNING: We strongly suggest you to install liblzo2."
822                 else
823                         log 1 "configure: error: no liblzo2 detected"
824                         log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
825                         exit
826                 fi
827         fi
829         detect_xdg_basedir
830         detect_png
831         detect_freetype
832         detect_fontconfig
833         detect_icu
834         detect_pspconfig
835         detect_libtimidity
837         if [ "$with_direct_music" != "0" ]; then
838                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
839                         if [ "$with_direct_music" != "1" ]; then
840                                 log 1 "configure: error: direct-music is only supported on Win32 targets"
841                                 exit 1
842                         fi
843                         with_direct_music="0"
845                         log 1 "checking direct-music... not Windows, skipping"
846                 else
847                         check_direct_music
848                 fi
849         fi
851         detect_sort
853         if [ "$os" = "OSX" ] && [ "$endian" = "AUTO" ]; then
854                 endian="PREPROCESSOR"
855         fi
857         log 1 "checking endianess... $endian"
859         # Suppress language errors when there is a version defined, indicating a release
860         #  It just isn't pretty if any release produces warnings in the languages.
861         if [ -f "$ROOT_DIR/version" ]; then
862                 lang_suppress="yes"
863                 log 1 "suppress language errors... yes"
864         else
865                 lang_suppress=""
866                 log 1 "suppress language errors... no"
867         fi
869         if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
870                 if [ "$os" = "MORPHOS" ]; then
871                         strip_arg="--strip-all --strip-unneeded --remove-section .comment"
872                 elif [ "$os" = "OSX" ]; then
873                         strip_arg=""
874                 elif [ "$os" = "OS2" ]; then
875                         strip_arg=""
876                         # OS2 uses strip via gcc, because it needs to be feed to emxbind
877                         LDFLAGS="$LDFLAGS -s"
878                 elif [ "$os" = "SUNOS" ]; then
879                         # The GNU strip does know -s, the non-GNU doesn't
880                         #  So try to detect it (in a bit of an ugly way)
881                         strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
882                 else
883                         strip_arg="-s"
884                 fi
886                 log 1 "checking stripping... $strip $strip_arg"
887         else
888                 strip=""
889                 log 1 "checking stripping... skipped"
890         fi
892         if [ "$with_distcc" = "0" ]; then
893                 log 1 "checking distcc... no"
894         elif [ "$with_distcc" = "1" ]; then
895                 with_distcc="0"
897                 log 1 "checking distcc... no (only used when forced)"
898         elif [ "$with_distcc" = "2" ]; then
899                 distcc="distcc"
900         else
901                 distcc="$with_distcc"
902         fi
903         if [ "$with_distcc" != "0" ]; then
904                 res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
905                 if [ "$res" != "distcc" ]; then
906                         distcc=""
907                         log 1 "checking distcc... no"
908                         if [ "$with_distcc" = "2" ]; then
909                                 log 1 "configure: error: no distcc detected, but was forced to be used"
910                                 exit 1
911                         fi
912                         if [ "$with_distcc" != "1" ]; then
913                                 log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
914                                 exit 1
915                         fi
916                 fi
918                 log 1 "checking distcc... $distcc"
919         fi
921         if [ "$with_ccache" = "0" ]; then
922                 log 1 "checking ccache... no"
923         elif [ "$with_ccache" = "1" ]; then
924                 with_ccache="0"
926                 log 1 "checking ccache... no (only used when forced)"
927         elif [ "$with_ccache" = "2" ]; then
928                 ccache="ccache"
929         else
930                 ccache="$with_ccache"
931         fi
932         if [ "$with_ccache" != "0" ]; then
933                 res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
934                 if [ "$res" != "ccache" ]; then
935                         ccache=""
936                         log 1 "checking ccache... no"
937                         if [ "$with_ccache" = "2" ]; then
938                                 log 1 "configure: error: no ccache detected, but was forced to be used"
939                                 exit 1
940                         fi
941                         if [ "$with_ccache" != "1" ]; then
942                                 log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
943                                 exit 1
944                         fi
945                 fi
947                 log 1 "checking ccache... $ccache"
948         fi
950         detect_grfcodec
951         detect_nforenum
953         if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
954                 log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
955                 nforenum=""
956         fi
958         if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
959                 log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
960                 grfcodec=""
961         fi
963         if [ "$os" = "DOS" ]; then
964                 with_threads="0"
965         fi
967         if [ "$os" != "OSX" ] && [ "$with_application_bundle" != "0" ]; then
968                 if [ "$with_application_bundle" = "1" ]; then
969                         with_application_bundle="0"
971                         log 1 "checking OSX application bundle... not OSX, skipping"
972                 else
973                         log 1 "configure: error: --with-application-bundle only works if OSX is the target"
974                         exit 1
975                 fi
976         fi
978         if [ "$os" = "OSX" ] && [ "$with_application_bundle" = "1" ]; then
979                 OSXAPP="OpenTTD.app"
980         else
981                 OSXAPP=""
982         fi
984         if [ "$os" = "OSX" ]; then
985                 # Test on ppc970 (G5) - we can optimize there
987                 if [ "$enable_osx_g5" != "0" ]; then
988                         log 1 "detecting ppc970 (G5)... yes (forced)"
989                 else
990                         # First, are we a real OSX system, else we can't detect it
991                         native=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | grep darwin`
992                         # If $host doesn't match $build , we are cross-compiling
993                         if [ -n "$native" ] && [ "$build" = "$host" ]; then
994                                 $cxx_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
995                                 res=`./G5_detector`
996                                 rm -f G5_detector
997                                 if [ -n "$res" ]; then
998                                         # This is G5, add flags for it
999                                         enable_osx_g5="2"
1001                                         log 1 "detecting ppc970 (G5)... yes"
1002                                 else
1003                                         enable_osx_g5="0"
1005                                         log 1 "detecting ppc970 (G5)... no"
1006                                 fi
1007                         else
1008                                 enable_osx_g5="0"
1010                                 log 1 "detecting ppc970 (G5)... no (cross-compiling)"
1011                         fi
1012                 fi
1013         else
1014                 if [ "$enable_osx_g5" != "0" ]; then
1015                         log 1 "configure: error: ppc970 (OSX G5) selected, but not compiling for OSX"
1016                         log 1 "configure: error: either select OSX as OS, or deselect ppc970"
1018                         exit 1
1019                 fi
1020         fi
1022         if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
1023                 log 1 "checking revision... svn detection"
1024         elif [ -d "$ROOT_DIR/../.svn" ] && [ -n "`svn help 2>/dev/null`" ] && LC_ALL=C svn info $ROOT_DIR/.. | grep -q '^URL:.*tags$'; then
1025                 # subversion changed its behaviour; now not all folders have a .svn folder,
1026                 # but only the root folder. Since making tags requires a (sparse) checkout
1027                 # of the tags folder, the folder of the tag does not have a .svn folder
1028                 # anymore and this fails to detect the subversion repository checkout.
1029                 log 1 "checking revision... svn detection (tag)"
1030         elif [ -d "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
1031                 log 1 "checking revision... git detection"
1032         elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`hg help 2>/dev/null`" ]; then
1033                 log 1 "checking revision... hg detection"
1034         elif [ -f "$ROOT_DIR/.ottdrev" ]; then
1035                 log 1 "checking revision... source tarball"
1036         else
1037                 log 1 "checking revision... no detection"
1038                 log 1 "WARNING: there is no means to determine the version."
1039                 log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenTTD."
1040                 log 1 "WARNING: you can only join game servers that have been compiled without"
1041                 log 1 "WARNING:   version detection."
1042                 log 1 "WARNING: there is a great chance you desync."
1043                 log 1 "WARNING: USE WITH CAUTION!"
1045                 sleep 5
1046         fi
1048         if [ "$doc_dir" = "1" ]; then
1049                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1050                         doc_dir="share/doc/openttd"
1051                 else
1052                         doc_dir="$data_dir/docs"
1053                 fi
1054         else
1055                 doc_dir="`echo $doc_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1056         fi
1058         if [ "$icon_theme_dir" = "1" ]; then
1059                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1060                         icon_theme_dir="share/icons/hicolor"
1061                 else
1062                         icon_theme_dir=""
1063                 fi
1064         else
1065                 icon_theme_dir="`echo $icon_theme_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1066         fi
1068         if [ "$personal_dir" = "1" ]; then
1069                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ] || [ "$os" = "DOS" ] || [ "$os" = "HAIKU" ]; then
1070                         personal_dir="OpenTTD"
1071                 elif [ "$os" = "OSX" ]; then
1072                         personal_dir="Documents/OpenTTD"
1073                 else
1074                         personal_dir=".openttd"
1075                 fi
1076         else
1077                 personal_dir="`echo $personal_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1078         fi
1080         if [ "$shared_dir" = "1" ]; then
1081                 # we are using default values
1082                 if [ "$os" = "OSX" ]; then
1083                         shared_dir="/Library/Application\\\\ Support/OpenTTD"
1084                 else
1085                         shared_dir=""
1086                 fi
1087         else
1088                 shared_dir="`echo $shared_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1089         fi
1091         if [ "$man_dir" = "1" ]; then
1092                 # add manpage on UNIX systems
1093                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OSX" ]; then
1094                         man_dir="share/man/man6"
1095                 else
1096                         man_dir=""
1097                 fi
1098         else
1099                 man_dir="`echo $man_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1100         fi
1102         if [ "$menu_dir" = "1" ]; then
1103                 # add a freedesktop menu item only for some UNIX systems
1104                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1105                         menu_dir="share/applications"
1106                 else
1107                         menu_dir=""
1108                 fi
1109         else
1110                 menu_dir="`echo $menu_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1111         fi
1113         detect_iconv
1115         if [ -n "$personal_dir" ]
1116         then
1117                 log 1 "personal home directory... $personal_dir"
1118         else
1119                 log 1 "personal home directory... none"
1120         fi
1122         if [ -n "$shared_dir" ]
1123         then
1124                 log 1 "shared data directory... $shared_dir"
1125         else
1126                 log 1 "shared data directory... none"
1127         fi
1129         if [ -n "$install_dir" ]
1130         then
1131                 log 1 "installation directory... $install_dir"
1132         else
1133                 log 1 "installation directory... none"
1134         fi
1136         if [ -n "$icon_theme_dir" ]
1137         then
1138                 log 1 "icon theme directory... $icon_theme_dir"
1139         else
1140                 log 1 "icon theme directory... none"
1141         fi
1143         if [ -n "$man_dir" ]
1144         then
1145                 log 1 "manual page directory... $man_dir"
1146         else
1147                 log 1 "manual page directory... none"
1148         fi
1150         if [ -n "$menu_dir" ]
1151         then
1152                 log 1 "menu item directory... $menu_dir"
1153         else
1154                 log 1 "menu item directory... none"
1155         fi
1158 make_compiler_cflags() {
1159         # Params:
1160         # $1 - compiler
1161         # $2 - name of the cflags variable
1162         # $3 - name of the cxxflags variable
1163         # $4 - name of the ldflags variable
1164         # $5 - name of the features variable
1166         eval eval "flags=\\\$$2"
1167         eval eval "cxxflags=\\\$$3"
1168         eval eval "ldflags=\\\$$4"
1169         eval eval "features=\\\$$5"
1171         if [ `basename $1 | cut -c 1-3` = "icc" ]; then
1172                 # Enable some things only for certain ICC versions
1173                 cc_version=`$1 -dumpversion | cut -c 1-4 | sed s@\\\.@@g`
1175                 flags="$flags -rdynamic"
1176                 ldflags="$ldflags -rdynamic"
1178                 if [ -z "$first_time_icc_check" ]; then
1179                         first_time_icc_check=no
1180                         if [ $cc_version -lt 90 ]; then
1181                                 log 1 "WARNING: you seem to be using a very old version of ICC"
1182                                 log 1 "WARNING: OpenTTD hasn't been tested with this version"
1183                                 sleep 5
1184                         elif [ $cc_version -lt 120 ]; then
1185                                 log 1 "WARNING: you seem to be using an unsupported ICC version"
1186                                 log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD"
1187                                 sleep 5
1188                         fi
1189                 fi
1191                 flags="$flags -Wall"
1192                 # remark #111: statement is unreachable
1193                 flags="$flags -wd111"
1194                 # remark #181: argument is incompatible with corresponding format string conversion
1195                 # ICC is very picky about signedness of operands, warnings provided by GCC are enough
1196                 flags="$flags -wd181"
1197                 # remark #271: trailing comma is nonstandard
1198                 flags="$flags -wd271"
1199                 # remark #280: selector expression is constant
1200                 flags="$flags -wd280"
1201                 # remark #304: access control not specified ("public" by default)
1202                 flags="$flags -wd304"
1203                 # remark #383: value copied to temporary, reference to temporary used
1204                 flags="$flags -wd383"
1205                 # remark #444: destructor for base class ... is not virtual
1206                 flags="$flags -wd444"
1207                 # remark #593: variable ... was set but never used
1208                 flags="$flags -wd593"
1209                 # warning #654: overloaded virtual function ... is only partially overridden in class ...
1210                 flags="$flags -wd654"
1211                 # remark #810: conversion from ... to ... may lose significant bits
1212                 flags="$flags -wd810"
1213                 # remark #869: parameter ... was never referenced
1214                 flags="$flags -wd869"
1215                 # warning #873: function ... ::operator new ... has no corresponding operator delete ...
1216                 flags="$flags -wd873"
1217                 # remark #981: operands are evaluated in unspecified order
1218                 flags="$flags -wd981"
1219                 # remark #1418: external function definition with no prior declaration
1220                 flags="$flags -wd1418"
1221                 # remark #1419: external declaration in primary source file
1222                 flags="$flags -wd1419"
1223                 # remark #1572: floating-point equality and inequality
1224                 flags="$flags -wd1572"
1225                 # remark #1599: declaration hides variable/parameter ...
1226                 flags="$flags -wd1599"
1227                 # remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
1228                 flags="$flags -wd1720"
1230                 if [ $cc_version -lt 110 ]; then
1231                         # warns about system headers with recent glibc:
1232                         # warning #1292: attribute "__nonnull__" ignored
1233                         flags="$flags -wd1292"
1234                 fi
1236                 if [ $cc_version -ge 100 ]; then
1237                         # warning #1899: multicharacter character literal (potential portability problem)
1238                         flags="$flags -wd1899"
1239                         # vec report defaults to telling where it did loop vectorisation, which is not very important
1240                         flags="$flags -vec-report=0 "
1241                 fi
1243                 if [ $cc_version -ge 110 ]; then
1244                         # remark #2259: non-pointer conversion from ... to ... may lose significant bits
1245                         flags="$flags -wd2259"
1246                         # Use c++0x mode so static_assert() is available
1247                         cxxflags="$cxxflags -std=c++0x"
1248                 fi
1250                 if [ "$enable_lto" != "0" ] && $1 -help ipo | grep -q '\-ipo'; then
1251                         # Use IPO (only if we see IPO exists and is requested)
1252                         flags="$flags -ipo"
1253                         features="$features lto"
1254                 fi
1255         elif basename $1 | grep -q 'clang'; then
1256                 # Enable some things only for certain clang versions
1257                 cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
1259                 # aliasing rules are not held in openttd code
1260                 flags="$flags -fno-strict-aliasing"
1262                 # -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
1263                 # -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
1264                 flags="$flags -Wall -W"
1266                 # warning: unused parameter '...'
1267                 flags="$flags -Wno-unused-parameter"
1269                 # warning: expression result unused
1270                 flags="$flags -Wno-unused-value"
1272                 # warning: multi-character character constant
1273                 flags="$flags -Wno-multichar"
1275                 # warning: explicitly assigning a variable of type '...' to itself
1276                 # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
1277                 flags="$flags -Wno-self-assign"
1279                 if [ "$cc_version" -lt "30" ]; then
1280                         # warning: equality comparison with extraneous parentheses
1281                         flags="$flags -Wno-parentheses"
1282                         # warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
1283                         flags="$flags -Wno-sign-compare"
1284                 fi
1286                 if [ "$cc_version" -ge "30" ]; then
1287                         # warning: equality comparison with extraneous parentheses
1288                         # this warning could be useful, but it warns about code in squirrel
1289                         flags="$flags -Wno-parentheses-equality"
1290                 fi
1292                 if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
1293                         # ccache and distcc run separate preprocess and compile passes,
1294                         # both are fed with the same CFLAGS. Unfortunately, clang
1295                         # complains about -I when compiling preprocessed files:
1296                         # "clang: warning: argument unused during compilation: '-I /usr/include'"
1297                         flags="$flags -Qunused-arguments"
1298                 fi
1300                 if [ "$enable_assert" -eq "0" ]; then
1301                         # do not warn about unused variables when building without asserts
1302                         flags="$flags -Wno-unused-variable"
1303                 fi
1305                 # rdynamic is used to get useful stack traces from crash reports.
1306                 ldflags="$ldflags -rdynamic"
1307         else
1308                 # Enable some things only for certain GCC versions
1309                 cc_version=`$1 -dumpversion | cut -c 1,3`
1311                 if [ $cc_version -lt 33 ]; then
1312                         log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
1313                         exit 1
1314                 fi
1316                 flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
1317                 flags="$flags -Wwrite-strings -Wpointer-arith"
1318                 flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
1319                 flags="$flags -Wformat=2 -Wformat-security"
1321                 if [ $enable_assert -eq 0 ]; then
1322                         # Do not warn about unused variables when building without asserts
1323                         flags="$flags -Wno-unused-variable"
1324                         if [ $cc_version -ge 46 ]; then
1325                                 # GCC 4.6 gives more warnings, disable them too
1326                                 flags="$flags -Wno-unused-but-set-variable"
1327                                 flags="$flags -Wno-unused-but-set-parameter"
1328                         fi
1329                 fi
1331                 if [ $cc_version -ge 34 ]; then
1332                         # Warn when a variable is used to initialise itself:
1333                         # int a = a;
1334                         flags="$flags -Winit-self"
1335                 fi
1337                 if [ $cc_version -ge 40 ]; then
1338                         # GCC 4.0+ complains about that we break strict-aliasing.
1339                         #  On most places we don't see how to fix it, and it doesn't
1340                         #  break anything. So disable strict-aliasing to make the
1341                         #  compiler all happy.
1342                         flags="$flags -fno-strict-aliasing"
1343                         # Warn about casting-out 'const' with regular C-style cast.
1344                         #  The preferred way is const_cast<>() which doesn't warn.
1345                         flags="$flags -Wcast-qual"
1346                 fi
1348                 if [ $cc_version -ge 42 ]; then
1349                         # GCC 4.2+ automatically assumes that signed overflows do
1350                         # not occur in signed arithmetics, whereas we are not
1351                         # sure that they will not happen. It furthermore complains
1352                         # about its own optimized code in some places.
1353                         flags="$flags -fno-strict-overflow"
1354                         # GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
1355                         # Enable it in order to be consistent with older GCC versions.
1356                         flags="$flags -Wnon-virtual-dtor"
1357                 fi
1359                 if [ $cc_version -ge 43 ]; then
1360                         # Use gnu++0x mode so static_assert() is available.
1361                         # Don't use c++0x, it breaks mingw (with gcc 4.4.0).
1362                         cxxflags="$cxxflags -std=gnu++0x"
1363                 fi
1365                 if [ $cc_version -eq 45 ]; then
1366                         # Prevent optimisation supposing enums are in a range specified by the standard
1367                         # For details, see http://gcc.gnu.org/PR43680
1368                         flags="$flags -fno-tree-vrp"
1369                 fi
1371                 if [ $cc_version -ge 47 ]; then
1372                         # Disable -Wnarrowing which gives many warnings, such as:
1373                         # warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
1374                         # They are valid according to the C++ standard, but useless.
1375                         cxxflags="$cxxflags -Wno-narrowing"
1376                         # Disable bogus 'attempt to free a non-heap object' warning
1377                         flags="$flags -Wno-free-nonheap-object"
1378                 fi
1380                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
1381                 if [ "$enable_lto" != "0" ] && $1 -dumpspecs | grep -q '\%{flto'; then
1382                         # Use LTO only if we see LTO exists and is requested
1383                         if [ $cc_version -lt 46 ]; then
1384                                 flags="$flags -flto"
1385                         else
1386                                 flags="$flags -flto=jobserver"
1387                         fi
1388                         ldflags="$ldflags -fwhole-program"
1389                         features="$features lto"
1390                 fi
1392                 if $1 -dumpspecs | grep -q rdynamic; then
1393                         # rdynamic is used to get useful stack traces from crash reports.
1394                         flags="$flags -rdynamic"
1395                         ldflags="$ldflags -rdynamic"
1396                 fi
1397         fi
1399         eval "$2=\"$flags\""
1400         eval "$3=\"$cxxflags\""
1401         eval "$4=\"$ldflags\""
1402         eval "$5=\"$features\""
1405 make_cflags_and_ldflags() {
1406         # General CFlags for BUILD
1407         CFLAGS_BUILD="$CFLAGS_BUILD"
1408         # Special CXXFlags for BUILD
1409         CXXFLAGS_BUILD="$CXXFLAGS_BUILD"
1410         # LDFLAGS for BUILD
1411         LDFLAGS_BUILD="$LDFLAGS_BUILD"
1412         # FEATURES for BUILD (lto)
1413         FEATURES_BUILD=""
1414         # General CFlags for HOST
1415         CFLAGS="$CFLAGS"
1416         # Special CXXFlags for HOST
1417         CXXFLAGS="$CXXFLAGS"
1418         # Libs to compile. In fact this is just LDFLAGS
1419         LIBS="-lstdc++"
1420         # LDFLAGS used for HOST
1421         LDFLAGS="$LDFLAGS"
1422         # FEATURES for HOST (lto)
1423         FEATURES=""
1425         make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "CXXFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
1426         make_compiler_cflags "$cc_host" "CFLAGS" "CXXFLAGS" "LDFLAGS" "FEATURES"
1428         CFLAGS="$CFLAGS -D$os"
1430         if [ "$enable_debug" = "0" ]; then
1431                 # No debug, add default stuff
1432                 OBJS_SUBDIR="release"
1433                 if [ "$os" = "MORPHOS" ]; then
1434                         CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
1435                         LDFLAGS="$LDFLAGS -noixemul"
1436                 fi
1438                 CFLAGS="-O2 -fomit-frame-pointer $CFLAGS"
1439         else
1440                 OBJS_SUBDIR="debug"
1442                 # Each debug level reduces the optimization by a bit
1443                 if [ $enable_debug -ge 1 ]; then
1444                         CFLAGS="$CFLAGS -g -D_DEBUG"
1445                         if [ "$os" = "PSP" ]; then
1446                                 CFLAGS="$CFLAGS -G0"
1447                         fi
1448                 fi
1449                 if [ $enable_debug -ge 2 ]; then
1450                         CFLAGS="$CFLAGS -fno-inline"
1451                 fi
1452                 if [ $enable_debug -ge 3 ]; then
1453                         CFLAGS="$CFLAGS -O0"
1454                 else
1455                         CFLAGS="$CFLAGS -O2"
1456                 fi
1457         fi
1459         if [ $enable_debug -le 2 ]; then
1460                 if basename "$cc_host" | grep -q "gcc"; then
1461                         # Define only when compiling with GCC. Some GLIBC versions use GNU
1462                         # extensions in a way that breaks build with at least ICC.
1463                         # This requires -O1 or more, so debug level 3 (-O0) is excluded.
1464                         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
1465                 fi
1467                 if basename "$cc_build" | grep -q "gcc"; then
1468                         # Just add -O1 to the tools needed for building.
1469                         CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
1470                 fi
1471         fi
1473         if [ "$os" = "OSX" ] && [ $cc_version -eq 40 ]; then
1474                 # Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
1475                 # wrongly optimizing ^= in loops. This disables the failing optimisation.
1476                 CFLAGS="$CFLAGS -fno-expensive-optimizations"
1477         fi
1479         if [ "$enable_profiling" != "0" ]; then
1480                 CFLAGS="$CFLAGS -p"
1481                 LDFLAGS="$LDFLAGS -pg"
1482         fi
1484         if [ "$with_threads" = "0" ]; then
1485                 CFLAGS="$CFLAGS -DNO_THREADS"
1486         fi
1488         if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
1489                 if [ "$os" = "CYGWIN" ]; then
1490                         flags="$flags -mwin32"
1491                         LDFLAGS="$LDFLAGS -mwin32"
1492                 fi
1493                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1494                         if [ $cc_version -lt 46 ]; then
1495                                 flags="$flags -mno-cygwin"
1496                                 LDFLAGS="$LDFLAGS -mno-cygwin"
1497                         fi
1499                         if [ "$enable_console" != "0" ]; then
1500                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
1501                         else
1502                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
1503                         fi
1505                         LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
1507                         if [ $cc_version -ge 44 ]; then
1508                                 LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
1509                         fi
1510                         if [ $cc_version -ge 47 ]; then
1511                                 CFLAGS="$CFLAGS -mno-ms-bitfields"
1512                         fi
1513                 fi
1514         fi
1516         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "FREEBSD" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
1517                 LIBS="$LIBS -lpthread"
1518         fi
1520         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "MINGW" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ]; then
1521                 LIBS="$LIBS -lc"
1522         fi
1523         if [ "$os" = "WINCE" ]; then
1524                 LIBS="$LIBS -lcoredll -lcorelibc -laygshell -lws2 -e WinMainCRTStartup"
1525         fi
1526         if [ "$os" = "PSP" ]; then
1527                 CFLAGS="$CFLAGS -I`$psp_config -p`/include"
1528                 LDFLAGS="$LDFLAGS -L`$psp_config -p`/lib"
1530                 CFLAGS="$CFLAGS -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150"
1531                 LIBS="$LIBS -D_PSP_FW_VERSION=150 -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lm"
1532         fi
1534         if [ "$os" = "MORPHOS" ]; then
1535                 # -Wstrict-prototypes generates much noise because of system headers
1536                 CFLAGS="$CFLAGS -Wno-strict-prototypes"
1537         fi
1539         if [ "$os" = "OPENBSD" ]; then
1540                 LIBS="$LIBS -pthread"
1541         fi
1543         if [ "$os" = "FREEBSD" ]; then
1544                 LIBS="$LIBS -lpthread"
1545         fi
1547         if [ "$os" = "OSX" ]; then
1548                 LDFLAGS="$LDFLAGS -framework Cocoa"
1550                 # Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
1551                 CFLAGS="$CFLAGS -isystem/opt/local/include"
1553                 if [ "$enable_dedicated" = "0" ] && ([ "$cpu_type" = "32" ] || [ "$enable_universal" != "0" ]); then
1554                         LIBS="$LIBS -framework QuickTime"
1555                 else
1556                         CFLAGS="$CFLAGS -DNO_QUICKTIME"
1557                 fi
1559                 if [ "$enable_universal" = "0" ]; then
1560                         # Universal builds set this elsewhere
1561                         CFLAGS="$OSX_SYSROOT $CFLAGS"
1562                         LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
1563                 fi
1565                 if [ "$enable_universal" = "0" ] && [ $cc_version -gt 40 ]; then
1566                         # Only set the min version when not doing an universal build.
1567                         # Universal builds set the version elsewhere.
1568                         if [ "$cpu_type" = "64" ]; then
1569                                 CFLAGS="$CFLAGS -mmacosx-version-min=10.5"
1570                         else
1571                                 gcc_cpu=`$cc_host -dumpmachine`
1572                                 if [ "`echo $gcc_cpu | cut -c 1-3`" = "ppc" -o "`echo $gcc_cpu | cut -c 1-7`" = "powerpc" ]; then
1573                                         # PowerPC build can run on 10.3
1574                                         CFLAGS="$CFLAGS -mmacosx-version-min=10.3"
1575                                 else
1576                                         # Intel is only available starting from 10.4
1577                                         CFLAGS="$CFLAGS -mmacosx-version-min=10.4"
1578                                 fi
1579                         fi
1580                 fi
1581         fi
1583         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ]; then
1584                 LIBS="$LIBS -lmidi -lbe"
1585         fi
1587         # Most targets act like UNIX, just with some additions
1588         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
1589                 CFLAGS="$CFLAGS -DUNIX"
1590         fi
1591         # And others like Windows
1592         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
1593                 CFLAGS="$CFLAGS -DWIN"
1594         fi
1596         if [ -n "$allegro_config" ]; then
1597                 CFLAGS="$CFLAGS -DWITH_ALLEGRO"
1598                 CFLAGS="$CFLAGS `$allegro_config --cflags`"
1599                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1600                         if [ "$enable_static" != "0" ]; then
1601                                 LIBS="$LIBS `$allegro_config --static --libs`"
1602                         else
1603                                 LIBS="$LIBS `$allegro_config --libs`"
1604                         fi
1605                 fi
1606         fi
1608         if [ -n "$sdl_config" ]; then
1609                 CFLAGS="$CFLAGS -DWITH_SDL"
1610                 # SDL must not add _GNU_SOURCE as it breaks many platforms
1611                 CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
1612                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1613                         if [ "$enable_static" != "0" ]; then
1614                                 LIBS="$LIBS `$sdl_config --static-libs`"
1615                         else
1616                                 LIBS="$LIBS `$sdl_config --libs`"
1617                         fi
1618                 fi
1619         fi
1621         if [ "$with_cocoa" != "0" ]; then
1622                 CFLAGS="$CFLAGS -DWITH_COCOA"
1623                 LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox"
1625                 if [ "$enable_cocoa_quartz" != "0" ]; then
1626                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUARTZ"
1627                 fi
1629                 if [ "$enable_cocoa_quickdraw" != "0" ]; then
1630                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUICKDRAW"
1631                 fi
1632         fi
1634         if [ "$with_zlib" != "0" ]; then
1635                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1636                         LIBS="$LIBS $zlib"
1637                 else
1638                         LIBS="$LIBS -lz"
1639                 fi
1640                 CFLAGS="$CFLAGS -DWITH_ZLIB"
1641         fi
1643         if [ -n "$lzma_config" ]; then
1644                 CFLAGS="$CFLAGS -DWITH_LZMA"
1645                 CFLAGS="$CFLAGS `$lzma_config --cflags | tr '\n\r' '  '`"
1647                 if [ "$enable_static" != "0" ]; then
1648                         CFLAGS="$CFLAGS -DLZMA_API_STATIC"
1649                         LIBS="$LIBS `$lzma_config --libs --static | tr '\n\r' '  '`"
1650                 else
1651                         LIBS="$LIBS `$lzma_config --libs | tr '\n\r' '  '`"
1652                 fi
1653         fi
1655         if [ "$with_lzo2" != "0" ]; then
1656                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1657                         LIBS="$LIBS $lzo2"
1658                 else
1659                         LIBS="$LIBS -llzo2"
1660                 fi
1661                 CFLAGS="$CFLAGS -DWITH_LZO"
1662         fi
1664         if [ -n "$xdg_basedir_config" ]; then
1665                 CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
1666                 CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
1668                 if [ "$enable_static" != "0" ]; then
1669                         LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
1670                 else
1671                         LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
1672                 fi
1673         fi
1675         # 64bit machines need -D_SQ64
1676         if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
1677                 CFLAGS="$CFLAGS -D_SQ64"
1678         fi
1679         CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
1681         if [ -n "$png_config" ]; then
1682                 CFLAGS="$CFLAGS -DWITH_PNG"
1683                 CFLAGS="$CFLAGS `$png_config --cppflags --I_opts | tr '\n\r' '  '`"
1685                 # The extra flags are unneeded for latest libpng-config, but some versions are so broken...
1686                 if [ "$enable_static" != "0" ]; then
1687                         if [ "$os" = "OSX" ]; then
1688                                 LIBS="$LIBS `$png_config --prefix`/lib/libpng.a"
1689                         else
1690                                 LIBS="$LIBS `$png_config --static --ldflags | tr '\n\r' '  '`"
1691                         fi
1692                 else
1693                         LIBS="$LIBS `$png_config --ldflags | tr '\n\r' '  '`"
1694                 fi
1695         fi
1697         if [ -n "$fontconfig_config" ]; then
1698                 CFLAGS="$CFLAGS -DWITH_FONTCONFIG"
1699                 CFLAGS="$CFLAGS `$fontconfig_config --cflags | tr '\n\r' '  '`"
1701                 if [ "$enable_static" != "0" ]; then
1702                         if [ "$os" = "OSX" ]; then
1703                                 # fontconfig_config goes via pkg-config on all systems, which doesn't know --prefix
1704                                 # Also, despite the reason we link to the .a file ourself (because we can't use -static), we do need to ask pkg-config about possible other deps
1705                                 LIBS="$LIBS `$fontconfig_config --variable=prefix`/lib/libfontconfig.a `$fontconfig_config --libs --static | sed s@-lfontconfig@@`"
1706                         else
1707                                 LIBS="$LIBS `$fontconfig_config --libs --static | tr '\n\r' '  '`"
1708                         fi
1709                 else
1710                         LIBS="$LIBS `$fontconfig_config --libs | tr '\n\r' '  '`"
1711                 fi
1712         fi
1714         if [ -n "$freetype_config" ]; then
1715                 CFLAGS="$CFLAGS -DWITH_FREETYPE"
1716                 CFLAGS="$CFLAGS `$freetype_config --cflags | tr '\n\r' '  '`"
1718                 if [ "$enable_static" != "0" ]; then
1719                         if [ "$os" = "OSX" ]; then
1720                                 LIBS="$LIBS `$freetype_config --prefix`/lib/libfreetype.a"
1721                         else
1722                                 # Is it possible to do static with freetype, if so: how?
1723                                 LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1724                         fi
1725                 else
1726                         LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1727                 fi
1728         fi
1730         if [ -n "$icu_config" ]; then
1731                 CFLAGS="$CFLAGS -DWITH_ICU"
1732                 CFLAGS="$CFLAGS `$icu_config --cppflags | tr '\n\r' '  '`"
1734                 # Some icu-configs have the 'feature' of not adding a space where others do add the space
1735                 if [ "$static_icu" != "0" ]; then
1736                         LIBS="$LIBS `$icu_config --ldflags-searchpath` `($icu_config --ldflags-libsonly; $icu_config --ldflags-layout) | tr '\n\r' '  ' | sed s/licu/lsicu/g`"
1737                 else
1738                         LIBS="$LIBS `$icu_config --ldflags-searchpath` `($icu_config --ldflags-libsonly; $icu_config --ldflags-layout) | tr '\n\r' '  '`"
1739                 fi
1740         fi
1743         if [ "$with_direct_music" != "0" ]; then
1744                 CFLAGS="$CFLAGS -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT"
1745                 # GCC 4.0+ doesn't like the DirectX includes (gives tons of
1746                 #  warnings on it we won't be able to fix). For now just
1747                 #  suppress those warnings.
1748                 if [ $cc_version -ge 40 ]; then
1749                         CFLAGS="$CFLAGS -Wno-non-virtual-dtor"
1750                 fi
1751         fi
1753         if [ -n "$libtimidity" ]; then
1754                 if [ "$enable_static" != "0" ]; then
1755                         LIBS="$LIBS $libtimidity"
1756                 else
1757                         LIBS="$LIBS -ltimidity"
1758                 fi
1759                 CFLAGS="$CFLAGS -DLIBTIMIDITY"
1760         fi
1762         if [ "$with_iconv" != "0" ]; then
1763                 CFLAGS="$CFLAGS -DWITH_ICONV"
1764                 if [ "$link_to_iconv" = "yes" ]; then
1765                         LIBS="$LIBS -liconv"
1766                         if [ "$with_iconv" != "2" ]; then
1767                                 CFLAGS="$CFLAGS -I$with_iconv/include"
1768                                 LIBS="$LIBS -L$with_iconv/lib"
1769                         fi
1770                 fi
1772                 if [ "$os" != "OSX" ] && [ "$have_non_const_iconv" != "no" ]; then
1773                         CFLAGS="$CFLAGS -DHAVE_NON_CONST_ICONV"
1774                 fi
1775         fi
1777         if [ -n "$with_midi" ]; then
1778                 CFLAGS="$CFLAGS -DEXTERNAL_PLAYER=\\\\\"$with_midi\\\\\""
1779         fi
1780         if [ -n "$with_midi_arg" ]; then
1781                 CFLAGS="$CFLAGS -DMIDI_ARG=\\\\\"$with_midi_arg\\\\\""
1782         fi
1784         if [ "$enable_dedicated" != "0" ]; then
1785                 CFLAGS="$CFLAGS -DDEDICATED"
1786         fi
1788         if [ "$enable_unicode" != "0" ]; then
1789                 CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
1790         fi
1792         if [ "$enable_network" != "0" ]; then
1793                 CFLAGS="$CFLAGS -DENABLE_NETWORK"
1795                 if [ "$os" = "BEOS" ]; then
1796                         LDFLAGS="$LDFLAGS -lbind -lsocket"
1797                 fi
1799                 if [ "$os" = "HAIKU" ]; then
1800                         LDFLAGS="$LDFLAGS -lnetwork"
1801                 fi
1803                 if [ "$os" = "SUNOS" ]; then
1804                         LDFLAGS="$LDFLAGS -lnsl -lsocket"
1805                 fi
1806         fi
1808         if [ "$enable_static" != "0" ]; then
1809                 # OSX can't handle -static in LDFLAGS
1810                 if [ "$os" != "OSX" ]; then
1811                         LDFLAGS="$LDFLAGS -static"
1812                 fi
1813         fi
1815         if [ "$enable_assert" = "0" ]; then
1816                 CFLAGS="$CFLAGS -DNDEBUG"
1817                 CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
1818         fi
1820         if [ "$enable_desync_debug" != "0" ]; then
1821                 CFLAGS="$CFLAGS -DRANDOM_DEBUG"
1822         fi
1824         if [ "$enable_osx_g5" != "0" ]; then
1825                 CFLAGS="$CFLAGS -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
1826         fi
1828         if [ -n "$personal_dir" ]; then
1829                 CFLAGS="$CFLAGS -DWITH_PERSONAL_DIR -DPERSONAL_DIR=\\\\\"$personal_dir\\\\\""
1830         fi
1832         if [ -n "$shared_dir" ]; then
1833                 CFLAGS="$CFLAGS -DWITH_SHARED_DIR -DSHARED_DIR=\\\\\"$shared_dir\\\\\""
1834         fi
1836         CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
1838         if [ "$enable_lto" != "0" ]; then
1839                 lto_warn=1
1840                 if echo "$FEATURES_BUILD" | grep -q "lto"; then
1841                         LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
1842                         lto_warn=0
1843                 fi
1844                 if echo "$FEATURES" | grep -q "lto"; then
1845                         LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
1846                         lto_warn=0
1847                 fi
1848                 if [ "$lto_warn" != "0" ]; then
1849                         log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
1850                         log 1 "WARNING: LTO/IPO has been disabled"
1851                 fi
1852         fi
1854         log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD"
1855         log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD"
1856         log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD"
1857         log 1 "using CFLAGS... $CFLAGS"
1858         log 1 "using CXXFLAGS... $CXXFLAGS"
1859         log 1 "using LDFLAGS... $LIBS $LDFLAGS"
1861         # Makedepend doesn't like something like: -isysroot /OSX/blabla
1862         #  so convert it to: -isysroot -OSX/blabla. makedepend just ignores
1863         #  any - command it doesn't know, so we are pretty save.
1864         # Lovely hackish, not?
1865         # Btw, this almost always comes from outside the configure, so it is
1866         #  not something we can control.
1867         # Also make makedepend aware of compiler's built-in defines.
1868         if [ "$with_makedepend" != "0" ] || [ "$enable_builtin_depend" != "0" ]; then
1869                 # Append CXXFLAGS possibly containing -std=c++0x
1870                 cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
1872                 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
1873                 cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
1874         else
1875                 makedepend=""
1876         fi
1878         if [ "$with_distcc" != "0" ]; then
1879                 cc_host="$distcc $cc_host"
1880                 cxx_host="$distcc $cxx_host"
1881                 log 1 ""
1882                 log 1 " NOTICE: remind yourself to use 'make -jN' to make use of distcc"
1883                 log 1 ""
1884         fi
1886         if [ "$with_ccache" != "0" ]; then
1887                 cc_host="$ccache $cc_host"
1888                 cxx_host="$ccache $cxx_host"
1889         fi
1892 check_compiler() {
1893         # Params:
1894         # $1 - Type for message (build / host)
1895         # $2 - What to fill with the found compiler
1896         # $3 - System to try
1897         # $4 - Compiler to try
1898         # $5 - Env-setting to try
1899         # $6 - GCC alike to try
1900         # $7 - CC alike to try
1901         # $8 - "0" gcc, "1" g++, "2" windres, "3" strip, "4" lipo
1902         # $9 - What the command is to check for
1904         if [ -n "$3" ]; then
1905                 # Check for system
1906                 if [ -z "$6" ]; then
1907                         compiler="$3"
1908                 else
1909                         compiler="$3-$6"
1910                 fi
1911                 machine=`eval $compiler $9 2>/dev/null`
1912                 ret=$?
1913                 eval "$2=\"$compiler\""
1915                 log 2 "executing $compiler $9"
1916                 log 2 "  returned $machine"
1917                 log 2 "  exit code $ret"
1919                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1920                         log 1 "checking $1... $compiler not found"
1921                         log 1 "I couldn't detect any $6 binary for $3"
1922                         exit 1
1923                 fi
1925                 if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
1926                         log 1 "checking $1... expected $3, found $machine"
1927                         log 1 "the compiler suggests it doesn't build code for the machine you specified"
1928                         exit 1
1929                 fi
1930         elif [ -n "$4" ]; then
1931                 # Check for manual compiler
1932                 machine=`$4 $9 2>/dev/null`
1933                 ret=$?
1934                 eval "$2=\"$4\""
1936                 log 2 "executing $4 $9"
1937                 log 2 "  returned $machine"
1938                 log 2 "  exit code $ret"
1940                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1941                         log 1 "checking $1... $4 not found"
1942                         log 1 "the selected binary doesn't seem to be a $6 binary"
1943                         exit 1
1944                 fi
1945         else
1946                 # Nothing given, autodetect
1948                 if [ -n "$5" ]; then
1949                         machine=`$5 $9 2>/dev/null`
1950                         ret=$?
1951                         eval "$2=\"$5\""
1953                         log 2 "executing $5 $9"
1954                         log 2 "  returned $machine"
1955                         log 2 "  exit code $ret"
1957                         # The user defined a GCC that doesn't reply to $9.. abort
1958                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1959                                 log 1 "checking $1... $5 unusable"
1960                                 log 1 "the CC environment variable is set, but it doesn't seem to be a $6 binary"
1961                                 log 1 "please redefine the CC/CXX environment to a $6 binary"
1962                                 exit 1
1963                         fi
1964                 else
1965                         log 2 "checking $1... CC/CXX not set (skipping)"
1967                         # No $5, so try '$6'
1968                         machine=`$6 $9 2>/dev/null`
1969                         ret=$?
1970                         eval "$2=\"$6\""
1972                         log 2 "executing $6 $9"
1973                         log 2 "  returned $machine"
1974                         log 2 "  exit code $ret"
1976                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1977                                 # Maybe '$7'?
1978                                 machine=`$7 $9 2>/dev/null`
1979                                 ret=$?
1980                                 eval "$2=\"$7\""
1982                                 log 2 "executing $7 $9"
1983                                 log 2 "  returned $machine"
1984                                 log 2 "  exit code $ret"
1986                                 # All failed, abort
1987                                 if [ -z "$machine" ]; then
1988                                         log 1 "checking $1... $6 not found"
1989                                         log 1 "I couldn't detect any $6 binary on your system"
1990                                         log 1 "please define the CC/CXX environment to where it is located"
1992                                         exit 1
1993                                 fi
1994                         fi
1995                 fi
1996         fi
1998         if [ "$8" != "0" ]; then
1999                 eval "res=\$$2"
2000                 log 1 "checking $1... $res"
2001         else
2002                 log 1 "checking $1... $machine"
2003         fi
2006 check_build() {
2007         if [ "$os" = "FREEBSD" ]; then
2008                 # FreeBSD's C compiler does not support dump machine.
2009                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2010                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CXX" "g++" "c++" "0" "-dumpmachine"
2011         else
2012                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CC" "gcc" "cc" "0" "-dumpmachine"
2013         fi
2016 check_host() {
2017         # By default the host is the build
2018         if [ -z "$host" ]; then host="$build"; fi
2020         if [ "$os" = "FREEBSD" ]; then
2021                 # FreeBSD's C compiler does not support dump machine.
2022                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2023                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CXX" "g++" "c++" "0" "-dumpmachine"
2024         else
2025                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
2026         fi
2029 check_cxx_build() {
2030         check_compiler "build c++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
2033 check_cxx_host() {
2034         # By default the host is the build
2035         if [ -z "$host" ]; then host="$build"; fi
2036         check_compiler "host c++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
2039 check_windres() {
2040         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2041                 check_compiler "host windres" "windres" "$host" "$windres" "$WINDRES" "windres" "windres" "2" "-V"
2042         fi
2045 check_strip() {
2046         if [ "$os" = "OS2" ]; then
2047                 # OS2 via gcc is a bit weird.. stripping HAS to be done via emxbind, which is via gcc directly
2048                 log 1 "checking host strip... using gcc -s option"
2049         elif [ "$os" = "OSX" ]; then
2050                 # Most targets have -V in strip, to see if they exists... OSX doesn't.. so execute something
2051                 echo "int main(int argc, char *argv[]) { }" > strip.test.c
2052                 $cxx_host strip.test.c -o strip.test
2053                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "strip.test"
2054                 rm -f strip.test.c strip.test
2055         else
2056                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "-V"
2057         fi
2060 check_lipo() {
2061         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
2062                 echo "int main(int argc, char *argv[]) { }" > lipo.test.c
2063                 $cxx_host lipo.test.c -o lipo.test
2064                 check_compiler "host lipo" "lipo" "$host" "$lipo" "$LIPO" "lipo" "lipo" "4" "-info lipo.test"
2065                 rm -f lipo.test.c lipo.test
2066         fi
2069 check_osx_sdk() {
2070         local sysroot=""
2071         if [ -n "$1" ]; then
2072                 if echo "$1" | grep -q / ; then
2073                         # Seems to be a file system path
2074                         osx_sdk_path="$1"
2075                 else
2076                         osx_sdk_path="/Developer/SDKs/MacOSX$1.sdk"
2077                 fi
2078                 if [ ! -d "$osx_sdk_path" ]; then
2079                         # No directory, not present or garbage
2080                         return 1
2081                 fi
2083                 # Set minimum version to 10.4 as that's when kCGBitmapByteOrder32Host was introduced
2084                 sysroot="-isysroot $osx_sdk_path -Wl,-syslibroot,$osx_sdk_path -mmacosx-version-min=10.4"
2085         fi
2087 cat > tmp.osx.mm << EOF
2088 #include <Cocoa/Cocoa.h>
2089 int main() {
2090         kCGBitmapByteOrder32Host;
2091         return 0;
2094         execute="$cxx_host $sysroot $CFLAGS tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2095         eval $execute > /dev/null
2096         ret=$?
2097         log 2 "executing $execute"
2098         log 2 "  exit code $ret"
2099         rm -f tmp.osx.mm tmp.osx
2100         return $ret
2103 check_direct_music() {
2104         echo "
2105                 #include <windows.h>
2106                 #include <dmksctrl.h>
2107                 #include <dmusici.h>
2108                 #include <dmusicc.h>
2109                 #include <dmusicf.h>
2110                 int main(int argc, char *argv[]) { }" > direct_music.test.c
2111         $cxx_host $CFLAGS direct_music.test.c -o direct_music.test 2> /dev/null
2112         res=$?
2113         rm -f direct_music.test.c direct_music.test
2115         if [ "$res" != "0" ]; then
2116                 if [ "$with_direct_music" != "1" ]; then
2117                         log 1 "configure: error: direct-music is not available on this system"
2118                         exit 1
2119                 fi
2120                 with_direct_music="0"
2122                 log 1 "checking direct-music... not found"
2123         else
2124                 log 1 "checking direct-music... found"
2125         fi
2128 check_makedepend() {
2129         if [ "$enable_builtin_depend" != "0" ]; then
2130                 with_makedepend="0"
2131         fi
2133         if [ "$with_makedepend" = "0" ]; then
2134                 log 1 "checking makedepend... disabled"
2135                 return
2136         fi
2138         if [ "$with_makedepend" = "1" ] || [ "$with_makedepend" = "2" ]; then
2139                 makedepend="makedepend"
2140         else
2141                 makedepend="$with_makedepend"
2142         fi
2144         rm -f makedepend.tmp
2145         touch makedepend.tmp
2146         res=`$makedepend -fmakedepend.tmp 2>/dev/null`
2147         res=$?
2148         log 2 "executing $makedepend -f makedepend.tmp"
2149         log 2 "  returned `cat makedepend.tmp`"
2150         log 2 "  exit code $ret"
2152         if [ ! -s makedepend.tmp ]; then
2153                 rm -f makedepend.tmp makedepend.tmp.bak
2155                 if [ "$with_makedepend" = "2" ]; then
2156                         log 1 "checking makedepend... not found"
2158                         log 1 "I couldn't detect any makedepend on your system"
2159                         log 1 "please locate it via --makedepend=[binary]"
2161                         exit 1
2162                 elif [ "$with_makedepend" != "1" ]; then
2163                         log 1 "checking makedepend... $makedepend not found"
2165                         log 1 "the selected file doesn't seem to be a valid makedepend binary"
2167                         exit 1
2168                 else
2169                         log 1 "checking makedepend... not found"
2171                         with_makedepend="0"
2172                         return
2173                 fi
2174         fi
2176         rm -f makedepend.tmp makedepend.tmp.bak
2178         log 1 "checking makedepend... $makedepend"
2181 check_version() {
2182         # $1 - requested version (major.minor)
2183         # $2 - version we got (major.minor)
2185         if [ -z "$2" ]; then
2186                 return 0
2187         fi
2189         req_major=`echo $1 | cut -d. -f1`
2190         got_major=`echo $2 | cut -d. -f1`
2191         if [ $got_major -lt $req_major ]; then
2192                 return 0
2193         elif [ $got_major -gt $req_major ]; then
2194                 return 1
2195         fi
2197         req_minor=`echo $1 | cut -d. -f2`
2198         got_minor=`echo $2 | cut -d. -f2`
2199         if [ $got_minor -lt $req_minor ]; then
2200                 return 0
2201         fi
2202         return 1
2205 detect_awk() {
2206         # Not all awks allow gsub(), so we test for that here! It is in fact all we need...
2208         # These awks are known to work. Test for them explicit
2209         awks="gawk mawk nawk"
2211         awk_prefix="echo \"a.c b.c c.c\" | tr ' ' \\\\n | "
2212         awk_param="' { ORS = \" \" } /\.c$/   { gsub(\".c$\",   \".o\", \$0); print \$0; }' 2>/dev/null"
2213         awk_result="a.o b.o c.o "
2214         log 2 "Detecing awk..."
2216         log 2 "Trying: $awk_prefix $awk $awk_param"
2217         res=`eval $awk_prefix $awk $awk_param`
2218         log 2 "Result: '$res'"
2219         if [ "$res" != "$awk_result" ] && [ "$awk" = "awk" ]; then
2220                 # User didn't supply his own awk, so try to detect some other known working names for an awk
2221                 for awk in $awks; do
2222                         log 2 "Trying: $awk_prefix $awk $awk_param"
2223                         res=`eval $awk_prefix $awk $awk_param`
2224                         log 2 "Result: '$res'"
2225                         if [ "$res" = "$awk_result" ]; then break; fi
2226                 done
2228                 if [ "$res" != "$awk_result" ]; then
2229                         log 1 "checking awk... not found"
2230                         log 1 "configure: error: no awk found"
2231                         log 1 "configure: error: please install one of the following: $awks"
2232                         exit 1
2233                 fi
2234         fi
2235         if [ "$res" != "$awk_result" ]; then
2236                 log 1 "checking awk... not found"
2237                 log 1 "configure: error: you supplied '$awk' but it doesn't seem a valid gawk or mawk"
2238                 exit 1
2239         fi
2241         log 1 "checking awk... $awk"
2244 detect_os() {
2245         if [ "$os" = "DETECT" ]; then
2246                 # Detect UNIX, OSX, FREEBSD, OPENBSD, NETBSD, HPUX, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
2248                 # Try first via dumpmachine, then via uname
2249                 os=`echo "$host" | tr '[A-Z]' '[a-z]' | $awk '
2250                                         /linux/        { print "UNIX";    exit}
2251                                         /darwin/       { print "OSX";     exit}
2252                                         /freebsd/      { print "FREEBSD"; exit}
2253                                         /openbsd/      { print "OPENBSD"; exit}
2254                                         /netbsd/       { print "NETBSD";  exit}
2255                                         /hp-ux/        { print "HPUX";    exit}
2256                                         /morphos/      { print "MORPHOS"; exit}
2257                                         /beos/         { print "BEOS";    exit}
2258                                         /haiku/        { print "HAIKU";   exit}
2259                                         /sunos/        { print "SUNOS";   exit}
2260                                         /solaris/      { print "SUNOS";   exit}
2261                                         /cygwin/       { print "CYGWIN";  exit}
2262                                         /mingw/        { print "MINGW";   exit}
2263                                         /os2/          { print "OS2";     exit}
2264                                         /dos/          { print "DOS";     exit}
2265                                         /wince/        { print "WINCE";   exit}
2266                                         /psp/          { print "PSP";     exit}
2267                 '`
2269                 if [ -z "$os" ]; then
2270                         os=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | $awk '
2271                                         /linux/        { print "UNIX";    exit}
2272                                         /darwin/       { print "OSX";     exit}
2273                                         /freebsd/      { print "FREEBSD"; exit}
2274                                         /openbsd/      { print "OPENBSD"; exit}
2275                                         /netbsd/       { print "NETBSD";  exit}
2276                                         /hp-ux/        { print "HPUX";    exit}
2277                                         /morphos/      { print "MORPHOS"; exit}
2278                                         /beos/         { print "BEOS";    exit}
2279                                         /haiku/        { print "HAIKU";   exit}
2280                                         /sunos/        { print "SUNOS";   exit}
2281                                         /cygwin/       { print "CYGWIN";  exit}
2282                                         /mingw/        { print "MINGW";   exit}
2283                                         /os\/2/        { print "OS2";     exit}
2284                                         /gnu/          { print "UNIX";    exit}
2285                         '`
2286                 fi
2288                 if [ -z "$os" ]; then
2289                         log 1 "detecting OS... none detected"
2290                         log 1 "I couldn't detect your OS. Please use --os=OS to force one"
2291                         log 1 "Allowed values are: UNIX, OSX, FREEBSD, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP"
2292                         exit 1
2293                 fi
2295                 log 1 "detecting OS... $os"
2296         else
2297                 log 1 "forcing OS... $os"
2298         fi
2301 detect_allegro() {
2302         # 0 means no, 1 is auto-detect, 2 is force
2303         if [ "$with_allegro" = "0" ]; then
2304                 log 1 "checking Allegro... disabled"
2306                 allegro_config=""
2307                 return 0
2308         fi
2310         if [ "$with_allegro" = "2" ] && [ "$with_cocoa" = "2" ]; then
2311                 log 1 "configure: error: it is impossible to compile both Allegro and COCOA"
2312                 log 1 "configure: error: please deselect one of them and try again"
2313                 exit 1
2314         fi
2316         if [ "$with_allegro" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2317                 log 1 "configure: error: it is impossible to compile a dedicated with Allegro"
2318                 log 1 "configure: error: please deselect one of them and try again"
2319                 exit 1
2320         fi
2322         if [ "$enable_dedicated" != "0" ]; then
2323                 log 1 "checking Allegro... dedicated server, skipping"
2325                 allegro_config=""
2326                 return 0
2327         fi
2329         # By default on OSX we don't use SDL. The rest is auto-detect
2330         if [ "$with_allegro" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2331                 log 1 "checking Allegro... OSX, skipping"
2333                 allegro_config=""
2334                 return 0
2335         fi
2337         if [ "$with_allegro" = "1" ] || [ "$with_allegro" = "" ] || [ "$with_allegro" = "2" ]; then
2338                 allegro_config="allegro-config"
2339         else
2340                 allegro_config="$with_allegro"
2341         fi
2343         version=`$allegro_config --version 2>/dev/null`
2344         ret=$?
2345         log 2 "executing $allegro_config --version"
2346         log 2 "  returned $version"
2347         log 2 "  exit code $ret"
2349         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2350                 log 1 "checking Allegro... not found"
2352                 # It was forced, so it should be found.
2353                 if [ "$with_allegro" != "1" ]; then
2354                         log 1 "configure: error: allegro-config couldn't be found"
2355                         log 1 "configure: error: you supplied '$with_allegro', but it seems invalid"
2356                         exit 1
2357                 fi
2359                 allegro_config=""
2360                 return 0
2361         fi
2363         log 1 "checking Allegro... found"
2367 detect_sdl() {
2368         # 0 means no, 1 is auto-detect, 2 is force
2369         if [ "$with_sdl" = "0" ]; then
2370                 log 1 "checking SDL... disabled"
2372                 sdl_config=""
2373                 return 0
2374         fi
2376         if [ "$with_sdl" = "2" ] && [ "$with_cocoa" = "2" ]; then
2377                 log 1 "configure: error: it is impossible to compile both SDL and COCOA"
2378                 log 1 "configure: error: please deselect one of them and try again"
2379                 exit 1
2380         fi
2382         if [ "$with_sdl" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2383                 log 1 "configure: error: it is impossible to compile a dedicated with SDL"
2384                 log 1 "configure: error: please deselect one of them and try again"
2385                 exit 1
2386         fi
2388         if [ "$enable_dedicated" != "0" ]; then
2389                 log 1 "checking SDL... dedicated server, skipping"
2391                 sdl_config=""
2392                 return 0
2393         fi
2395         # By default on OSX we don't use SDL. The rest is auto-detect
2396         if [ "$with_sdl" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2397                 log 1 "checking SDL... OSX, skipping"
2399                 sdl_config=""
2400                 return 0
2401         fi
2403         if [ "$os" = "OSX" ]; then
2404                 log 1 "WARNING: sdl is known to fail on some versions of Mac OS X"
2405                 log 1 "WARNING: with some hardware configurations. Use at own risk!"
2406                 sleep 5
2407         fi
2409         if [ "$with_sdl" = "1" ] || [ "$with_sdl" = "" ] || [ "$with_sdl" = "2" ]; then
2410                 sdl_config="sdl-config"
2411         else
2412                 sdl_config="$with_sdl"
2413         fi
2415         version=`$sdl_config --version 2>/dev/null`
2416         ret=$?
2417         log 2 "executing $sdl_config --version"
2418         log 2 "  returned $version"
2419         log 2 "  exit code $ret"
2421         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2422                 log 1 "checking SDL... not found"
2424                 # It was forced, so it should be found.
2425                 if [ "$with_sdl" != "1" ]; then
2426                         log 1 "configure: error: sdl-config couldn't be found"
2427                         log 1 "configure: error: you supplied '$with_sdl', but it seems invalid"
2428                         exit 1
2429                 fi
2431                 sdl_config=""
2432                 return 0
2433         fi
2435         log 1 "checking SDL... found"
2438 detect_osx_sdk() {
2439         # Try to find the best SDK available. For a normal build this
2440         # is currently the 10.5 SDK as this is needed to compile all
2441         # optional code. Because such an executable won't run on 10.4
2442         # or lower, also check for the 10.4u SDK when doing an universal
2443         # build.
2445         # Check for the 10.5 SDK, but try 10.6 if that fails
2446         check_osx_sdk "10.5" || check_osx_sdk "10.6" || osx_sdk_path=""
2448         if [ -z "$osx_sdk_path" ] || [ "$enable_universal" != "0" ]; then
2449                 # No better SDK or universal build enabled? Check 10.4u SDK as well
2450                 local old_sdk="$osx_sdk_path"
2451                 if check_osx_sdk "10.4u"; then
2452                         osx_sdk_104_path="$osx_sdk_path"
2453                 else
2454                         osx_sdk_104_path=""
2455                 fi
2456                 if [ -z "$old_sdk" ]; then
2457                         osx_sdk_path="$osx_sdk_104_path"
2458                 else
2459                         osx_sdk_path="$old_sdk"
2460                 fi
2461         fi
2463         if [ -z "$osx_sdk_path" ]; then
2464                 log 1 "Your system SDK is probably too old"
2465                 log 1 "Please install/upgrade your Xcode to >= 2.5"
2467                 exit 1
2468         fi
2471 detect_cocoa() {
2472         # 0 means no, 1 is auto-detect, 2 is force
2473         if [ "$with_cocoa" = "0" ]; then
2474                 log 1 "checking COCOA... disabled"
2476                 return 0
2477         fi
2479         if [ "$with_cocoa" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2480                 log 1 "configure: error: it is impossible to compile a dedicated with COCOA"
2481                 log 1 "configure: error: please deselect one of them and try again"
2482                 exit 1
2483         fi
2485         if [ "$enable_dedicated" != "0" ]; then
2486                 log 1 "checking COCOA... dedicated server, skipping"
2488                 with_cocoa="0"
2489                 return 0
2490         fi
2492         # By default on OSX we use COCOA. The rest doesn't support it
2493         if [ "$with_cocoa" = "1" ] && [ "$os" != "OSX" ]; then
2494                 log 1 "checking COCOA... not OSX, skipping"
2496                 with_cocoa="0"
2497                 return 0
2498         fi
2500         if [ "$os" != "OSX" ]; then
2501                 log 1 "checking COCOA... not OSX"
2503                 log 1 "configure: error: COCOA video driver is only supported for OSX"
2504                 exit 1
2505         fi
2507         log 1 "checking COCOA... found"
2510         if [ "$enable_cocoa_quartz" != "0" ]; then
2511                 log 1 "checking whether to enable the Quartz window subdriver... yes"
2512         else
2513                 log 1 "checking whether to enable the Quartz window subdriver... no"
2514         fi
2516         detect_quickdraw
2519 detect_quickdraw() {
2520         # 0 means no, 1 is auto-detect, 2 is force
2521         if [ "$enable_cocoa_quickdraw" = "0" ]; then
2522                 log 1 "checking Quickdraw window subdriver... disabled"
2523                 return 0
2524         fi
2526         # Assume QuickDraw is available when doing an universal build
2527         if [ "$enable_universal" != "0" ]; then
2528                 log 1 "checking Quickdraw window subdriver... found"
2529                 return 0
2530         fi
2532         # 64 bits doesn't have quickdraw
2533         if [ "$cpu_type" = "64" ]; then
2534                 enable_cocoa_quickdraw="0"
2535                 log 1 "checking Quickdraw window subdriver... disabled (64 bits)"
2536                 return 0
2537         fi
2539 cat > tmp.osx.mm << EOF
2540 #include <AvailabilityMacros.h>
2541 #import <Cocoa/Cocoa.h>
2542 int main(int argc, char *argv[]) { SetEmptyRgn(NULL); return 0; }
2544         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS -mmacosx-version-min=10.3 tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2545         eval $execute > /dev/null
2546         ret=$?
2547         log 2 "executing $execute"
2548         log 2 "  exit code $ret"
2549         rm -f tmp.osx.mm tmp.osx
2550         if [ "$ret" != "0" ]; then
2551                 log 1 "checking Quickdraw window subdriver... not found"
2553                 # It was forced, so it should be found.
2554                 if [ "$enable_cocoa_quickdraw" != "1" ]; then
2555                         log 1 "configure: error: Quickdraw window driver could not be found"
2556                         exit 1
2557                 fi
2559                 enable_cocoa_quickdraw=0
2560                 return 0
2561         fi
2563         enable_cocoa_quickdraw=1
2564         log 1 "checking Quickdraw window subdriver... found"
2567 detect_library() {
2568         # $1 - config-param ($with_zlib value)
2569         # $2 - library name ('zlib', sets $zlib)
2570         # $3 - static library name (libz.a)
2571         # $4 - header directory ()
2572         # $5 - header name (zlib.h)
2573         # $6 - force static (if non-empty)
2575         if [ -n "$6" ]; then force_static="1"; fi
2577         # 0 means no, 1 is auto-detect, 2 is force
2578         if [ "$1" = "0" ]; then
2579                 log 1 "checking $2... disabled"
2581                 eval "$2=\"\""
2582                 return 0
2583         fi
2585         log 2 "detecting $2"
2587         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2588                 eval "$2=`ls -1 /usr/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2589                 eval "res=\$$2"
2590                 if [ -z "$res" ]; then
2591                         log 2 "  trying /usr/include/$4$5... no"
2592                         eval "$2=`ls -1 /usr/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2593                 fi
2594                 eval "res=\$$2"
2595                 if [ -z "$res" ]; then
2596                         log 2 "  trying /usr/local/include/$4$5... no"
2597                         eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2598                 fi
2599                 eval "res=\$$2"
2600                 if [ -z "$res" ]; then
2601                         log 2 "  trying /mingw/include/$4$5... no"
2602                         eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2603                 fi
2604                 eval "res=\$$2"
2605                 if [ -z "$res" ]; then
2606                         log 2 "  trying /opt/local/include/$4$5... no"
2607                 fi
2608                 if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then
2609                         eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2610                         eval "res=\$$2"
2611                         if [ -z "$res" ]; then
2612                                 log 2 "  trying /usr/pkg/include/$4$5... no"
2613                         fi
2614                 fi
2615                 if [ -z "$res" ] && [ "$os" = "HAIKU" ]; then
2616                         eval "$2=`ls -1 /boot/common/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2617                         eval "res=\$$2"
2618                         if [ -z "$res" ]; then
2619                                 log 2 "  trying /boot/common/include/$4$5... no"
2620                         fi
2621                 fi
2623                 eval "res=\$$2"
2624                 if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then
2625                         eval "res=\$$2"
2626                         log 2 "  trying $res... found"
2627                         # Now find the static lib, if needed
2628                         eval "$2=`ls /lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2629                         eval "res=\$$2"
2630                         if [ -z "$res" ]; then
2631                                 log 2 "  trying /lib/$3... no"
2632                                 eval "$2=`ls /usr/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2633                         fi
2634                         eval "res=\$$2"
2635                         if [ -z "$res" ]; then
2636                                 log 2 "  trying /usr/lib/$3... no"
2637                                 eval "$2=`ls /usr/local/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2638                         fi
2639                         eval "res=\$$2"
2640                         if [ -z "$res" ]; then
2641                                 log 2 "  trying /usr/local/lib/$3... no"
2642                                 eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2643                         fi
2644                         eval "res=\$$2"
2645                         if [ -z "$res" ]; then
2646                                 log 2 "  trying /mingw/lib/$3... no"
2647                                 log 1 "configure: error: $2 couldn't be found"
2648                                 log 1 "configure: error: you requested a static link, but I can't find $3"
2650                                 exit 1
2651                         fi
2652                 fi
2653         else
2654                 # Make sure it exists
2655                 if [ -f "$1" ]; then
2656                         eval "$2=`ls $1 2>/dev/null`"
2657                 else
2658                         eval "$2=`ls $1/$3 2>/dev/null`"
2659                 fi
2660         fi
2662         eval "res=\$$2"
2663         if [ -z "$res" ]; then
2664                 log 1 "checking $2... not found"
2665                 if [ "$1" = "2" ]; then
2666                         log 1 "configure: error: $2 couldn't be found"
2668                         exit 1
2669                 elif [ "$1" != "1" ]; then
2670                         log 1 "configure: error: $2 couldn't be found"
2671                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2673                         exit 1
2674                 fi
2676                 eval "with_$2=0"
2678                 return 0
2679         fi
2681         eval "res=\$$2"
2682         log 2 "  trying $res... found"
2684         log 1 "checking $2... found"
2687 detect_zlib() {
2688         detect_library "$with_zlib" "zlib" "libz.a" "" "zlib.h"
2691 detect_lzo2() {
2692         detect_library "$with_lzo2" "lzo2" "liblzo2.a" "lzo/" "lzo1x.h"
2695 detect_libtimidity() {
2696         detect_library "$with_libtimidity" "libtimidity" "libtimidity.a" "" "timidity.h"
2699 detect_lzma() {
2700         # 0 means no, 1 is auto-detect, 2 is force
2701         if [ "$with_lzma" = "0" ]; then
2702                 log 1 "checking liblzma... disabled"
2704                 lzma_config=""
2705                 return 0
2706         fi
2708         if [ "$with_lzma" = "1" ] || [ "$with_lzma" = "" ] || [ "$with_lzma" = "2" ]; then
2709                 lzma_config="pkg-config liblzma"
2710         else
2711                 lzma_config="$with_lzma"
2712         fi
2714         version=`$lzma_config --modversion 2>/dev/null`
2715         ret=$?
2716         log 2 "executing $lzma_config --modversion"
2717         log 2 "  returned $version"
2718         log 2 "  exit code $ret"
2720         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2721                 log 1 "checking liblzma... not found"
2723                 # It was forced, so it should be found.
2724                 if [ "$with_lzma" != "1" ]; then
2725                         log 1 "configure: error: pkg-config liblzma couldn't be found"
2726                         log 1 "configure: error: you supplied '$with_lzma', but it seems invalid"
2727                         exit 1
2728                 fi
2730                 lzma_config=""
2731                 return 0
2732         fi
2734         log 1 "checking liblzma... found"
2737 detect_xdg_basedir() {
2738         # 0 means no, 1 is auto-detect, 2 is force
2739         if [ "$with_xdg_basedir" = "0" ]; then
2740                 log 1 "checking libxdg_basedir... disabled"
2742                 xdg_basedir_config=""
2743                 return 0
2744         fi
2746         if [ "$with_xdg_basedir" = "1" ] || [ "$with_xdg_basedir" = "" ] || [ "$with_xdg_basedir" = "2" ]; then
2747                 xdg_basedir_config="pkg-config libxdg-basedir"
2748         else
2749                 xdg_basedir_config="$with_xdg_basedir"
2750         fi
2752         version=`$xdg_basedir_config --modversion 2>/dev/null`
2753         ret=$?
2754         log 2 "executing $xdg_basedir_config --modversion"
2755         log 2 "  returned $version"
2756         log 2 "  exit code $ret"
2758         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2759                 log 1 "checking libxdg_basedir... not found"
2761                 # It was forced, so it should be found.
2762                 if [ "$with_xdg_basedir" != "1" ]; then
2763                         log 1 "configure: error: pkg-config libxdg_basedir couldn't be found"
2764                         log 1 "configure: error: you supplied '$with_xdg_basedir', but it seems invalid"
2765                         exit 1
2766                 fi
2768                 xdg_basedir_config=""
2769                 return 0
2770         fi
2772         log 1 "checking libxdg_basedir... found"
2775 detect_png() {
2776         # 0 means no, 1 is auto-detect, 2 is force
2777         if [ "$with_png" = "0" ]; then
2778                 log 1 "checking libpng... disabled"
2780                 png_config=""
2781                 return 0
2782         fi
2784         if [ "$with_zlib" = "0" ] || [ -z "$zlib" ]; then
2785                 if [ "$with_png" != "1" ]; then
2786                         log 1 "checking libpng... no zlib"
2787                         log 1 "ERROR: libpng was forced, but zlib was not detected / disabled."
2788                         log 1 "ERROR: libpng depends on zlib."
2790                         exit 1
2791                 fi
2793                 log 1 "checking libpng... no zlib, skipping"
2795                 png_config=""
2796                 return 0
2797         fi
2799         if [ "$with_png" = "1" ] || [ "$with_png" = "" ] || [ "$with_png" = "2" ]; then
2800                 png_config="libpng-config"
2801         else
2802                 png_config="$with_png"
2803         fi
2805         version=`$png_config --version 2>/dev/null`
2806         ret=$?
2807         log 2 "executing $png_config --version"
2808         log 2 "  returned $version"
2809         log 2 "  exit code $ret"
2811         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2812                 log 1 "checking libpng... not found"
2814                 # It was forced, so it should be found.
2815                 if [ "$with_png" != "1" ]; then
2816                         log 1 "configure: error: libpng-config couldn't be found"
2817                         log 1 "configure: error: you supplied '$with_png', but it seems invalid"
2818                         exit 1
2819                 fi
2821                 png_config=""
2822                 return 0
2823         fi
2825         log 1 "checking libpng... found"
2828 detect_freetype() {
2829         # 0 means no, 1 is auto-detect, 2 is force
2830         if [ "$with_freetype" = "0" ]; then
2831                 log 1 "checking libfreetype... disabled"
2833                 freetype_config=""
2834                 return 0
2835         fi
2836         if [ "$with_freetype" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2837                 log 1 "checking libfreetype... dedicated server, skipping"
2839                 freetype_config=""
2840                 return 0
2841         fi
2843         if [ "$with_zlib" = "0" ] || [ -z "$zlib" ]; then
2844                 if [ "$with_freetype" != "1" ]; then
2845                         log 1 "checking libfreetype... no zlib"
2846                         log 1 "ERROR: libfreetype was forced, but zlib was not detected / disabled."
2847                         log 1 "ERROR: libfreetype depends on zlib."
2849                         exit 1
2850                 fi
2852                 log 1 "checking libfreetype... no zlib, skipping"
2854                 freetype_config=""
2855                 return 0
2856         fi
2858         if [ "$with_freetype" = "1" ] || [ "$with_freetype" = "" ] || [ "$with_freetype" = "2" ]; then
2859                 freetype_config="freetype-config"
2860         else
2861                 freetype_config="$with_freetype"
2862         fi
2864         version=`$freetype_config --version 2>/dev/null`
2865         ret=$?
2866         log 2 "executing freetype_config --version"
2867         log 2 "  returned $version"
2868         log 2 "  exit code $ret"
2870         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2871                 log 1 "checking libfreetype... not found"
2873                 # It was forced, so it should be found.
2874                 if [ "$with_freetype" != "1" ]; then
2875                         log 1 "configure: error: freetype-config couldn't be found"
2876                         log 1 "configure: error: you supplied '$with_freetype', but it seems invalid"
2877                         exit 1
2878                 fi
2880                 freetype_config=""
2881                 return 0
2882         fi
2884         log 1 "checking libfreetype... found"
2887 detect_fontconfig() {
2888         # 0 means no, 1 is auto-detect, 2 is force
2889         if [ "$with_fontconfig" = "0" ]; then
2890                 log 1 "checking libfontconfig... disabled"
2892                 fontconfig_config=""
2893                 return 0
2894         fi
2895         if [ "$with_fontconfig" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2896                 log 1 "checking libfontconfig... dedicated server, skipping"
2898                 fontconfig_config=""
2899                 return 0
2900         fi
2901         if [ "$with_fontconfig" != "2" ] && [ -z "$freetype_config" ]; then
2902                 log 1 "checking libfontconfig... no freetype, skipping"
2904                 fontconfig_config=""
2905                 return 0
2906         fi
2908         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2909                 log 1 "checking libfontconfig... WIN32, skipping"
2910                 fontconfig_config=""
2911                 return 0
2912         fi
2914         if [ "$os" = "OSX" ]; then
2915                 log 1 "checking libfontconfig... OSX, skipping"
2916                 fontconfig_config=""
2917                 return 0
2918         fi
2920         if [ "$with_fontconfig" = "1" ] || [ "$with_fontconfig" = "" ] || [ "$with_fontconfig" = "2" ]; then
2921                 fontconfig_config="pkg-config fontconfig"
2922         else
2923                 fontconfig_config="$with_fontconfig"
2924         fi
2926         version=`$fontconfig_config --modversion 2>/dev/null`
2927         ret=$?
2928         check_version '2.3' "$version"
2929         version_ok=$?
2930         log 2 "executing $fontconfig_config --modversion"
2931         log 2 "  returned $version"
2932         log 2 "  exit code $ret"
2934         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2935                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2936                         log 1 "checking libfontconfig... needs at least version 2.3.0, fontconfig NOT enabled"
2937                 else
2938                         log 1 "checking libfontconfig... not found"
2939                 fi
2941                 # It was forced, so it should be found.
2942                 if [ "$with_fontconfig" != "1" ]; then
2943                         log 1 "configure: error: fontconfig-config couldn't be found"
2944                         log 1 "configure: error: you supplied '$with_fontconfig', but it seems invalid"
2945                         exit 1
2946                 fi
2948                 fontconfig_config=""
2949                 return 0
2950         fi
2952         log 1 "checking libfontconfig... found"
2955 detect_icu() {
2956         # 0 means no, 1 is auto-detect, 2 is force
2957         if [ "$with_icu" = "0" ]; then
2958                 log 1 "checking libicu... disabled"
2960                 icu_config=""
2961                 return 0
2962         fi
2963         if [ "$with_icu" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2964                 log 1 "checking libicu... dedicated server, skipping"
2966                 icu_config=""
2967                 return 0
2968         fi
2970         if [ "$with_icu" = "1" ] || [ "$with_icu" = "" ] || [ "$with_icu" = "2" ]; then
2971                 icu_config="icu-config"
2972         else
2973                 icu_config="$with_icu"
2974         fi
2976         version=`$icu_config --version 2>/dev/null`
2977         ret=$?
2978         check_version '3.6' "$version"
2979         version_ok=$?
2980         log 2 "executing $icu_config --version"
2981         log 2 "  returned $version"
2982         log 2 "  exit code $ret"
2984         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2985                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2986                         log 1 "checking libicu... needs at least version 3.6.0, icu NOT enabled"
2987                 else
2988                         log 1 "checking libicu... not found"
2989                 fi
2991                 # It was forced, so it should be found.
2992                 if [ "$with_icu" != "1" ]; then
2993                         log 1 "configure: error: icu-config couldn't be found"
2994                         log 1 "configure: error: you supplied '$with_icuconfig', but it seems invalid"
2995                         exit 1
2996                 fi
2998                 icu_config=""
2999                 return 0
3000         fi
3002         log 1 "checking libicu... found"
3005 detect_pspconfig() {
3006         # 0 means no, 1 is auto-detect, 2 is force
3007         if [ "$with_psp_config" = "0" ]; then
3008                 log 1 "checking psp-config... disabled"
3010                 psp_config=""
3011                 return 0
3012         fi
3014         if [ "$with_psp_config" = "1" ] && [ "$os" != "PSP" ]; then
3015                 log 1 "checking psp-config... not PSP, skipping"
3017                 psp_config="";
3018                 return 0
3019         fi
3021         if [ "$os" != "PSP" ]; then
3022                 log 1 "checking psp-config... not PSP"
3024                 log 1 "configure: error: psp-config is only supported for PSP"
3025                 exit 1
3026         fi
3028         if [ "$with_psp_config" = "1" ] || [ "$with_psp_config" = "" ] || [ "$with_psp_config" = "2" ]; then
3029                 psp_config="psp-config"
3030         else
3031                 psp_config="$with_psp_config"
3032         fi
3034         version=`$psp_config -p 2>/dev/null`
3035         ret=$?
3036         log 2 "executing $psp_config -p"
3037         log 2 "  returned $version"
3038         log 2 "  exit code $ret"
3040         if [ -z "$version" ] || [ "$ret" != "0" ]; then
3041                 log 1 "checking psp-config... not found"
3042                 log 1 "configure: error: psp-config couldn't be found"
3044                 # It was forced, so it should be found.
3045                 if [ "$with_psp_config" != "1" ]; then
3046                         log 1 "configure: error: you supplied '$with_psp_config', but it seems invalid"
3047                 fi
3048                 exit 1
3049         fi
3051         log 1 "checking psp-config... found"
3054 detect_iconv() {
3055         # 0 means no, 1 is auto-detect, 2 is force
3056         if [ "$with_iconv" = "0" ]; then
3057                 log 1 "checking iconv... disabled"
3059                 return 0
3060         fi
3062         if [ "$with_iconv" = "1" ] && [ "$os" != "OSX" ]; then
3063                 log 1 "checking iconv... not OSX, skipping"
3064                 with_iconv="0"
3066                 return 0
3067         fi
3069         # Try to find iconv.h, seems to only thing to detect iconv with
3071         if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
3072                 iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
3073                 if [ -z "$iconv" ]; then
3074                         iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
3075                 fi
3076         else
3077                 # Make sure it exists
3078                 iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
3079         fi
3081         if [ -z "$iconv" ]; then
3082                 log 1 "checking iconv... not found"
3083                 if [ "$with_iconv" = "2" ]; then
3084                         log 1 "configure: error: iconv couldn't be found"
3086                         exit 1
3087                 elif [ "$with_iconv" != "1" ]; then
3088                         log 1 "configure: error: iconv couldn't be found"
3089                         log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
3091                         exit 1
3092                 fi
3094                 return 0
3095         fi
3097         if [ "$with_iconv" = "1" ]; then
3098                 with_iconv="2"
3099         fi
3101         log 2 "found iconv in $iconv"
3103         log 1 "checking iconv... found"
3105         # There are different implementations of iconv. The older ones,
3106         # e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
3107         # IEEE 1003.1 (2004), pass a non-const pointer.
3109         cat > tmp.iconv.cpp << EOF
3110 #include "src/stdafx.h"
3111 #include <iconv.h>
3112 int main() {
3113         static char buf[1024];
3114         iconv_t convd = 0;
3115         const char *inbuf = "";
3116         char *outbuf  = buf;
3117         size_t outlen = 1023;
3118         size_t inlen  = 0;
3119         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
3122         execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
3123         eval $execute > /dev/null
3124         ret=$?
3125         log 2 "executing $execute"
3126         log 2 "  exit code $ret"
3127         if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
3128         log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
3130         cat > tmp.iconv.cpp << EOF
3131 #include "src/stdafx.h"
3132 #include <iconv.h>
3133 int main() {
3134         static char buf[1024];
3135         iconv_t convd = 0;
3136         char *inbuf = "";
3137         char *outbuf  = buf;
3138         size_t outlen = 1023;
3139         size_t inlen  = 0;
3140         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
3143         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
3144         eval $execute > /dev/null
3145         ret=$?
3146         log 2 "executing $execute"
3147         log 2 "  exit code $ret"
3148         if [ "$ret" = "0" ]; then link_to_iconv="no"; else link_to_iconv="yes"; fi
3149         log 1 "checking whether to link to iconv... $link_to_iconv"
3150         rm -f tmp.iconv tmp.iconv.cpp
3153 _detect_sort() {
3154         sort_test_in="d
3159         sort_test_out="a
3164         log 2 "running echo <array> | $1"
3166         if [ "`echo \"$sort_test_in\" | $1 2>/dev/null`" = "$sort_test_out" ]; then
3167                 sort="$1"
3168                 log 2 "  result was valid"
3169         else
3170                 log 2 "  result was invalid"
3171         fi
3174 detect_sort() {
3175         if [ "$with_sort" = "0" ]; then
3176                 log 1 "checking sort... disabled"
3178                 return
3179         fi
3181         if [ "$with_sort" = "1" ] || [ "$with_sort" = "2" ]; then
3182                 _detect_sort "sort"
3183                 if [ -z "$sort" ]; then _detect_sort "/sbin/sort"; fi
3184                 if [ -z "$sort" ]; then _detect_sort "/usr/sbin/sort"; fi
3185                 if [ -z "$sort" ]; then _detect_sort "/usr/local/sbin/sort"; fi
3186                 if [ -z "$sort" ]; then _detect_sort "/bin/sort"; fi
3187                 if [ -z "$sort" ]; then _detect_sort "/usr/bin/sort"; fi
3188                 if [ -z "$sort" ]; then _detect_sort "/usr/local/bin/sort"; fi
3189         else
3190                 _detect_sort "$with_sort"
3191         fi
3193         if [ -z "$sort" ]; then
3194                 if [ "$with_sort" = "2" ]; then
3195                         log 1 "checking sort... not found"
3197                         log 1 "configure: error: couldn't detect sort on your system"
3198                         exit 1
3199                 elif [ "$with_sort" != "1" ]; then
3200                         log 1 "checking sort... $with_sort not found"
3202                         log 1 "configure: error: '$with_sort' doesn't look like a sort to me"
3203                         log 1 "configure: error: please verify its location and function and try again"
3205                         exit 1
3206                 else
3207                         log 1 "checking sort... not found"
3208                 fi
3209         else
3210                 log 1 "checking sort... $sort"
3211         fi
3214 detect_grfcodec() {
3215         # 0 means no, 1 is auto-detect, 2 is force
3216         if [ "$with_grfcodec" = "0" ]; then
3217                 log 1 "checking grfcodec... disabled"
3219                 grfcodec=""
3220                 return 0
3221         fi
3223         if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
3224                 grfcodec="grfcodec"
3225         else
3226                 grfcodec="$with_grfcodec"
3227         fi
3229         version=`$grfcodec -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3230         ret=$?
3231         log 2 "executing grfcodec -v"
3232         log 2 "  returned $version"
3233         log 2 "  exit code $ret"
3235         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "949" ]; then
3236                 if [ -n "$version" ] && [ "$version" -lt "949" ]; then
3237                         log 1 "checking grfcodec... needs at least version 6.0.2 (r949), disabled"
3238                 else
3239                         log 1 "checking grfcodec... not found"
3240                 fi
3242                 # It was forced, so it should be found.
3243                 if [ "$with_grfcodec" != "1" ]; then
3244                         log 1 "configure: error: grfcodec couldn't be found"
3245                         log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
3246                         exit 1
3247                 fi
3249                 grfcodec=""
3250                 return 0
3251         fi
3253         log 1 "checking grfcodec... found"
3256 detect_nforenum() {
3257         # 0 means no, 1 is auto-detect, 2 is force
3258         if [ "$with_nforenum" = "0" ]; then
3259                 log 1 "checking nforenum... disabled"
3261                 nforenum=""
3262                 return 0
3263         fi
3265         if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
3266                 nforenum="nforenum"
3267         else
3268                 nforenum="$with_nforenum"
3269         fi
3271         version=`$nforenum -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3272         ret=$?
3273         log 2 "executing nforenum -v"
3274         log 2 "  returned $version"
3275         log 2 "  exit code $ret"
3277         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "949" ]; then
3278                 if [ -n "$version" ] && [ "$version" -lt "949" ]; then
3279                         log 1 "checking nforenum... needs at least version 6.0.2 (r949), disabled"
3280                 else
3281                         log 1 "checking nforenum... not found"
3282                 fi
3284                 # It was forced, so it should be found.
3285                 if [ "$with_nforenum" != "1" ]; then
3286                         log 1 "configure: error: nforenum couldn't be found"
3287                         log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
3288                         exit 1
3289                 fi
3291                 nforenum=""
3292                 return 0
3293         fi
3295         log 1 "checking nforenum... found"
3298 detect_cputype() {
3299         if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
3300                 log 1 "forcing cpu-type... $cpu_type bits"
3301                 return;
3302         fi
3303         echo "#define _SQ64 1" > tmp.64bit.cpp
3304         echo "#include \"src/stdafx.h\"" >> tmp.64bit.cpp
3305         echo "assert_compile(sizeof(size_t) == 8);" >> tmp.64bit.cpp
3306         echo "int main() { return 0; }" >> tmp.64bit.cpp
3307         execute="$cxx_host $CFLAGS tmp.64bit.cpp -o tmp.64bit -DTESTING 2>&1"
3308         cpu_type="`eval $execute 2>/dev/null`"
3309         ret=$?
3310         log 2 "executing $execute"
3311         log 2 "  returned $cpu_type"
3312         log 2 "  exit code $ret"
3313         if [ "$ret" = "0" ]; then cpu_type="64"; else cpu_type="32"; fi
3314         log 1 "detecting cpu-type... $cpu_type bits"
3315         rm -f tmp.64bit tmp.64bit.cpp
3318 make_sed() {
3319         T_CFLAGS="$CFLAGS"
3320         T_CXXFLAGS="$CXXFLAGS"
3321         T_LDFLAGS="$LDFLAGS"
3323         SRC_OBJS_DIR="$BASE_SRC_OBJS_DIR/$OBJS_SUBDIR"
3325         # All the data needed to compile a single target
3326         #  Make sure if you compile multiple targets to
3327         #  use multiple OBJS_DIR, because all in-between
3328         #  binaries are stored in there, and nowhere else.
3329         SRC_REPLACE="
3330                 s@!!CC_HOST!!@$cc_host@g;
3331                 s@!!CXX_HOST!!@$cxx_host@g;
3332                 s@!!CC_BUILD!!@$cc_build@g;
3333                 s@!!CXX_BUILD!!@$cxx_build@g;
3334                 s@!!WINDRES!!@$windres@g;
3335                 s@!!STRIP!!@$strip $strip_arg@g;
3336                 s@!!LIPO!!@$lipo@g;
3337                 s@!!CFLAGS!!@$T_CFLAGS@g;
3338                 s@!!CFLAGS_BUILD!!@$CFLAGS_BUILD@g;
3339                 s@!!CXXFLAGS!!@$T_CXXFLAGS@g;
3340                 s@!!CXXFLAGS_BUILD!!@$CXXFLAGS_BUILD@g;
3341                 s@!!STRGEN_FLAGS!!@$strgen_flags@g;
3342                 s@!!LIBS!!@$LIBS@g;
3343                 s@!!LDFLAGS!!@$T_LDFLAGS@g;
3344                 s@!!LDFLAGS_BUILD!!@$LDFLAGS_BUILD@g;
3345                 s@!!BIN_DIR!!@$BIN_DIR@g;
3346                 s@!!ROOT_DIR!!@$ROOT_DIR@g;
3347                 s@!!MEDIA_DIR!!@$MEDIA_DIR@g;
3348                 s@!!SOURCE_LIST!!@$SOURCE_LIST@g;
3349                 s@!!SRC_OBJS_DIR!!@$SRC_OBJS_DIR@g;
3350                 s@!!LANG_OBJS_DIR!!@$LANG_OBJS_DIR@g;
3351                 s@!!GRF_OBJS_DIR!!@$GRF_OBJS_DIR@g;
3352                 s@!!SETTING_OBJS_DIR!!@$SETTING_OBJS_DIR@g;
3353                 s@!!SRC_DIR!!@$SRC_DIR@g;
3354                 s@!!SCRIPT_SRC_DIR!!@$SCRIPT_SRC_DIR@g;
3355                 s@!!OSXAPP!!@$OSXAPP@g;
3356                 s@!!LANG_DIR!!@$LANG_DIR@g;
3357                 s@!!TTD!!@$TTD@g;
3358                 s@!!BINARY_DIR!!@$prefix_dir/$binary_dir@g;
3359                 s@!!DATA_DIR!!@$prefix_dir/$data_dir@g;
3360                 s@!!DOC_DIR!!@$prefix_dir/$doc_dir@g;
3361                 s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3362                 s@!!ICON_DIR!!@$prefix_dir/$icon_dir@g;
3363                 s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3364                 s@!!PERSONAL_DIR!!@$personal_dir@g;
3365                 s@!!SHARED_DIR!!@$shared_dir@g;
3366                 s@!!INSTALL_DIR!!@$install_dir@g;
3367                 s@!!BINARY_NAME!!@$binary_name@g;
3368                 s@!!STRGEN!!@$STRGEN@g;
3369                 s@!!ENDIAN_CHECK!!@$ENDIAN_CHECK@g;
3370                 s@!!DEPEND!!@$DEPEND@g;
3371                 s@!!SETTINGSGEN!!@$SETTINGSGEN@g;
3372                 s@!!ENDIAN_FORCE!!@$endian@g;
3373                 s@!!STAGE!!@$STAGE@g;
3374                 s@!!MAKEDEPEND!!@$makedepend@g;
3375                 s@!!CFLAGS_MAKEDEP!!@$cflags_makedep@g;
3376                 s@!!SORT!!@$sort@g;
3377                 s@!!CONFIG_CACHE_COMPILER!!@config.cache.compiler@g;
3378                 s@!!CONFIG_CACHE_LINKER!!@config.cache.linker@g;
3379                 s@!!CONFIG_CACHE_ENDIAN!!@config.cache.endian@g;
3380                 s@!!CONFIG_CACHE_SOURCE!!@config.cache.source@g;
3381                 s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
3382                 s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
3383                 s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
3384                 s@!!LANG_SUPPRESS!!@$lang_suppress@g;
3385                 s@!!OBJS_C!!@$OBJS_C@g;
3386                 s@!!OBJS_CPP!!@$OBJS_CPP@g;
3387                 s@!!OBJS_MM!!@$OBJS_MM@g;
3388                 s@!!OBJS_RC!!@$OBJS_RC@g;
3389                 s@!!SRCS!!@$SRCS@g;
3390                 s@!!OS!!@$os@g;
3391                 s@!!CONFIGURE_FILES!!@$CONFIGURE_FILES@g;
3392                 s@!!AWK!!@$awk@g;
3393                 s@!!DISTCC!!@$distcc@g;
3394                 s@!!NFORENUM!!@$nforenum@g;
3395                 s@!!GRFCODEC!!@$grfcodec@g;
3396         "
3398         if [ "$icon_theme_dir" != "" ]; then
3399                 SRC_REPLACE="$SRC_REPLACE
3400                         s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3401                 "
3402         else
3403                 SRC_REPLACE="$SRC_REPLACE
3404                         s@!!ICON_THEME_DIR!!@@g;
3405                 "
3406         fi
3408         if [ "$man_dir" != "" ]; then
3409                 SRC_REPLACE="$SRC_REPLACE
3410                         s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3411                 "
3412         else
3413                 SRC_REPLACE="$SRC_REPLACE
3414                         s@!!MAN_DIR!!@@g;
3415                 "
3416         fi
3418         if [ "$menu_dir" != "" ]; then
3419                 SRC_REPLACE="$SRC_REPLACE
3420                         s@!!MENU_DIR!!@$prefix_dir/$menu_dir@g;
3421                 "
3422         else
3423                 SRC_REPLACE="$SRC_REPLACE
3424                         s@!!MENU_DIR!!@@g;
3425                 "
3426         fi
3429 generate_menu_item() {
3430         MENU_REPLACE="
3431                 s@!!TTD!!@$TTD@g;
3432                 s@!!MENU_GROUP!!@$menu_group@g;
3433                 s@!!MENU_NAME!!@$menu_name@g
3434         "
3435         log 1 "Generating menu item..."
3436         mkdir -p media
3437         < $ROOT_DIR/media/openttd.desktop.in sed "$MENU_REPLACE" > media/openttd.desktop
3440 generate_main() {
3441         STAGE="[MAIN]"
3443         make_sed
3445         # Create the main Makefile
3446         log 1 "Generating Makefile..."
3447         echo "# Auto-generated file from 'Makefile.in' -- DO NOT EDIT" > Makefile
3448         < $ROOT_DIR/Makefile.in sed "$SRC_REPLACE" >> Makefile
3449         cp $ROOT_DIR/Makefile.bundle.in Makefile.bundle
3450         echo "# Auto-generated file -- DO NOT EDIT" > Makefile.am
3451         echo >> Makefile.am
3452         # Make the copy of the source-list, so we don't trigger an unwanted recompile
3453         cp $SOURCE_LIST config.cache.source.list
3454         # Add the current directory, so we don't trigger an unwanted recompile
3455         echo "`pwd`" > config.cache.pwd
3456         # Make sure config.cache is OLDER then config.cache.source.list
3457         touch config.cache
3458         touch config.pwd
3460         if [ "$menu_dir" != "" ]; then
3461                 generate_menu_item
3462         fi
3465 generate_lang() {
3466         STAGE="[LANG]"
3468         make_sed
3470         # Create the language file
3471         mkdir -p $LANG_OBJS_DIR
3473         log 1 "Generating lang/Makefile..."
3474         echo "# Auto-generated file from 'Makefile.lang.in' -- DO NOT EDIT" > $LANG_OBJS_DIR/Makefile
3475         < $ROOT_DIR/Makefile.lang.in sed "$SRC_REPLACE" >> $LANG_OBJS_DIR/Makefile
3476         echo "DIRS += $LANG_OBJS_DIR" >> Makefile.am
3477         echo "LANG_DIRS += $LANG_OBJS_DIR" >> Makefile.am
3480 generate_settings() {
3481         STAGE="[SETTING]"
3483         make_sed
3485         # Create the language file
3486         mkdir -p $SETTING_OBJS_DIR
3488         log 1 "Generating setting/Makefile..."
3489         echo "# Auto-generated file from 'Makefile.settings.in' -- DO NOT EDIT" > $SETTING_OBJS_DIR/Makefile
3490         < $ROOT_DIR/Makefile.setting.in sed "$SRC_REPLACE" >> $SETTING_OBJS_DIR/Makefile
3491         echo "DIRS += $SETTING_OBJS_DIR" >> Makefile.am
3494 generate_grf() {
3495         STAGE="[BASESET]"
3497         make_sed
3499         # Create the language file
3500         mkdir -p $GRF_OBJS_DIR
3502         log 1 "Generating grf/Makefile..."
3503         echo "# Auto-generated file from 'Makefile.grf.in' -- DO NOT EDIT" > $GRF_OBJS_DIR/Makefile
3504         < $ROOT_DIR/Makefile.grf.in sed "$SRC_REPLACE" >> $GRF_OBJS_DIR/Makefile
3505         echo "DIRS += $GRF_OBJS_DIR" >> Makefile.am
3508 generate_src_normal() {
3509         STAGE=$1
3511         make_sed
3513         # Create the source file
3514         mkdir -p $SRC_OBJS_DIR
3516         log 1 "Generating $2/Makefile..."
3517         echo "# Auto-generated file from 'Makefile.src.in' -- DO NOT EDIT" > $SRC_OBJS_DIR/Makefile
3518         < $ROOT_DIR/Makefile.src.in sed "$SRC_REPLACE" >> $SRC_OBJS_DIR/Makefile
3519         echo "DIRS += $SRC_OBJS_DIR" >> Makefile.am
3520         echo "SRC_DIRS += $SRC_OBJS_DIR" >> Makefile.am
3523 generate_src_osx() {
3524         cc_host_orig="$cc_host"
3525         cxx_host_orig="$cxx_host"
3526         CFLAGS_orig="$CFLAGS"
3527         LDFLAGS_orig="$LDFLAGS"
3529         for type in $enable_universal; do
3531                 if [ -n "$osx_sdk_104_path" ]; then
3532                         # Use 10.4 SDK for 32-bit targets
3533                         CFLAGS="-isysroot $osx_sdk_104_path $CFLAGS_orig"
3534                         LDFLAGS="-Wl,-syslibroot,$osx_sdk_104_path $LDFLAGS_orig"
3535                 fi
3537                 # We don't want to duplicate the x86_64 stuff for each target, so do it once here
3538                 if [ "$type" = "ppc64" ] || [ "$type" = "x86_64" ]; then
3539                         # 64 bits is always 10.5 or higher. Furthermore it has a non const ICONV
3540                         # and they also removed support for QuickTime/QuickDraw
3541                         if [ -n "$osx_sdk_path" ]; then
3542                                 CFLAGS="-isysroot $osx_sdk_path $CFLAGS_orig"
3543                                 LDFLAGS="-Wl,-syslibroot,$osx_sdk_path $LDFLAGS_orig"
3544                         fi
3545                         CFLAGS="$CFLAGS -D_SQ64 -DNO_QUICKTIME -UENABLE_COCOA_QUICKDRAW"
3546                         LIBS="`echo $LIBS | sed 's/-framework QuickTime//'`"
3547                 fi
3549                 case $type in
3550                         ppc)
3551                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc"
3552                                 cc_host="$cc_host_orig -arch ppc -mmacosx-version-min=10.3"
3553                                 cxx_host="$cxx_host_orig -arch ppc -mmacosx-version-min=10.3"
3554                                 generate_src_normal "[ppc]" "objs/ppc";;
3555                         ppc970)
3556                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc970"
3557                                 cc_host="$cc_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3558                                 cxx_host="$cxx_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3559                                 generate_src_normal "[ppc970]" "objs/ppc970";;
3560                         i386)
3561                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/i386"
3562                                 cc_host="$cc_host_orig -arch i386 -mmacosx-version-min=10.4"
3563                                 cxx_host="$cxx_host_orig -arch i386 -mmacosx-version-min=10.4"
3564                                 generate_src_normal "[i386]" "objs/i386";;
3565                         ppc64)
3566                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc64"
3567                                 cc_host="$cc_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3568                                 cxx_host="$cxx_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3569                                 generate_src_normal "[ppc64]" "objs/ppc64";;
3570                         x86_64)
3571                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/x86_64"
3572                                 cc_host="$cc_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3573                                 cxx_host="$cxx_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3574                                 generate_src_normal "[x86_64]" "objs/x86_64";;
3575                         *) log 1 "Unknown architecture requested for universal build: $type";;
3576                 esac
3577         done
3580 generate_src() {
3581         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
3582                 generate_src_osx
3583         else
3584                 generate_src_normal "[SRC]" "objs"
3585         fi
3588 showhelp() {
3589         echo "'configure' configures OpenTTD."
3590         echo ""
3591         echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
3592         echo ""
3593         echo "To assign environment variables (e.g., CC, CFLAGS...), specify them as"
3594         echo "VAR=VALUE.  See below for descriptions of some of the useful variables."
3595         echo ""
3596         echo "Defaults for the options are specified in brackets."
3597         echo ""
3598         echo "Configuration:"
3599         echo "  -h, --help                     display this help and exit"
3600         echo ""
3601         echo "System types:"
3602         echo "  --build=BUILD                  configure for building on BUILD [guessed]"
3603         echo "  --host=HOST                    cross-compile to build programs to run"
3604         echo "                                 on HOST [BUILD]"
3605         echo "  --windres=WINDRES              the windres to use [HOST-windres]"
3606         echo "  --strip=STRIP                  the strip to use [HOST-strip]"
3607         echo "  --awk=AWK                      the awk to use in configure [awk]"
3608         echo "  --lipo=LIPO                    the lipo to use (OSX ONLY) [HOST-lipo]"
3609         echo "  --os=OS                        the OS we are compiling for [DETECT]"
3610         echo "                                 DETECT/UNIX/OSX/FREEBSD/OPENBSD/NETBSD/"
3611         echo "                                 MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/MINGW/OS2/"
3612         echo "                                 DOS/WINCE/PSP/HAIKU"
3613         echo "  --endian=ENDIAN                set the endian of the HOST (AUTO/LE/BE)"
3614         echo ""
3615         echo "Paths:"
3616         echo "  --prefix-dir=dir               specifies the prefix for all installed"
3617         echo "                                 files [/usr/local]"
3618         echo "  --binary-dir=dir               location of the binary. Will be prefixed"
3619         echo "                                 with the prefix-dir [games]"
3620         echo "  --data-dir=dir                 location of data files (lang, data, gm)."
3621         echo "                                 Will be prefixed with the prefix-dir"
3622         echo "                                 [share/games/openttd]"
3623         echo "  --doc-dir=dir                  location of the doc files"
3624         echo "                                 Will be prefixed with the prefix-dir"
3625         echo "                                 [$doc_dir]"
3626         echo "  --icon-dir=dir                 location of icons. Will be prefixed"
3627         echo "                                 with the prefix-dir [share/pixmaps]"
3628         echo "  --icon-theme-dir=dir           location of icon theme."
3629         echo "                                 Will be prefixed with the prefix-dir"
3630         echo "                                 and postfixed with size-dirs [$icon_theme_dir]"
3631         echo "  --man-dir=dir                  location of the manual page (UNIX only)"
3632         echo "                                 Will be prefixed with the prefix-dir"
3633         echo "                                 [$man_dir]"
3634         echo "  --menu-dir=dir                 location of the menu item. (UNIX only, except OSX)"
3635         echo "                                 Will be prefixed with the prefix-dir"
3636         echo "                                 [share/applications]"
3637         echo "  --personal-dir=dir             location of the personal directory"
3638         echo "                                 [os-dependent default]"
3639         echo "  --shared-dir=dir               location of shared data files"
3640         echo "                                 [os-dependent default]"
3641         echo "  --install-dir=dir              specifies the root to install to."
3642         echo "                                 Useful to install into jails [/]"
3643         echo "  --binary-name                  the name used for the binary, icons,"
3644         echo "                                 desktop file, etc. when installing [openttd]"
3645         echo ""
3646         echo "Features and packages:"
3647         echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
3648         echo "  --enable-desync-debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
3649         echo "  --enable-profiling             enables profiling"
3650         echo "  --enable-lto                   enables GCC's Link Time Optimization (LTO)/ICC's"
3651         echo "                                 Interprocedural Optimization if available"
3652         echo "  --enable-dedicated             compile a dedicated server (without video)"
3653         echo "  --enable-static                enable static compile (doesn't work for"
3654         echo "                                 all HOSTs)"
3655         echo "  --enable-translator            enable extra output for translators"
3656         echo "  --enable-universal[=ARCH]      enable universal builds (OSX ONLY). Allowed is any combination"
3657         echo "                                 of architectures: i386 ppc ppc970 ppc64 x86_64"
3658         echo "                                 Default architectures are: i386 ppc"
3659         echo "  --enable-osx-g5                enables optimizations for ppc970 (G5) (OSX ONLY)"
3660         echo "  --disable-cocoa-quartz         disable the quartz window mode driver for Cocoa (OSX ONLY)"
3661         echo "  --disable-cocoa-quickdraw      disable the quickdraw window mode driver for Cocoa (OSX ONLY)"
3662         echo "  --disable-unicode              disable unicode support to build win9x"
3663         echo "                                 version (Win32 ONLY)"
3664         echo "  --enable-console               compile as a console application instead of as a GUI application."
3665         echo "                                 If this setting is active, debug output will appear in the same"
3666         echo "                                 console instead of opening a new window. (Win32 ONLY)"
3667         echo "  --disable-network              disable network support"
3668         echo "  --disable-assert               disable asserts (continue on errors)"
3669         echo "  --enable-strip                 enable any possible stripping"
3670         echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
3671         echo "                                 (OSX ONLY)"
3672         echo "  --without-application-bundle   disable generation of application bundle"
3673         echo "                                 (OSX ONLY)"
3674         echo "  --without-menu-entry           Don't generate a menu item (Freedesktop based only)"
3675         echo "  --menu-group=group             Category in which the menu item will be placed (Freedesktop based only)"
3676         echo "  --menu-name=name               Name of the menu item when placed [OpenTTD]"
3677         echo "  --with-direct-music            enable direct music support (Win32 ONLY)"
3678         echo "  --with-sort=sort               define a non-default location for sort"
3679         echo "  --with-midi=midi               define which midi-player to use"
3680         echo "  --with-midi-arg=arg            define which args to use for the"
3681         echo "                                 midi-player"
3682         echo "  --with-libtimidity             enables libtimidity support"
3683         echo "  --with-allegro[=allegro-config]"
3684         echo "                                 enables Allegro video driver support"
3685         echo "  --with-cocoa                   enables COCOA video driver (OSX ONLY)"
3686         echo "  --with-sdl[=sdl-config]        enables SDL video driver support"
3687         echo "  --with-zlib[=zlib.a]           enables zlib support"
3688         echo "  --with-liblzma[=\"pkg-config liblzma\"]"
3689         echo "                                 enables liblzma support"
3690         echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
3691         echo "  --with-png[=libpng-config]     enables libpng support"
3692         echo "  --with-freetype[=freetype-config]"
3693         echo "                                 enables libfreetype support"
3694         echo "  --with-fontconfig[=\"pkg-config fontconfig\"]"
3695         echo "                                 enables fontconfig support"
3696         echo "  --with-xdg-basedir[=\"pkg-config libxdg-basedir\"]"
3697         echo "                                 enables XDG base directory support"
3698         echo "  --with-icu[=icu-config]        enables icu (used for right-to-left support)"
3699         echo "  --static-icu                   try to link statically (libsicu instead of"
3700         echo "                                 libicu; can fail as the new name is guessed)"
3701         echo "  --with-iconv[=iconv-path]      enables iconv support"
3702         echo "  --with-psp-config[=psp-config] enables psp-config support (PSP ONLY)"
3703         echo "  --disable-builtin-depend       disable use of builtin deps finder"
3704         echo "  --with-makedepend[=makedepend] enables makedepend support"
3705         echo "  --with-ccache                  enables ccache support"
3706         echo "  --with-distcc                  enables distcc support"
3707         echo "  --without-grfcodec             disable usage of grfcodec and re-generation of base sets"
3708         echo ""
3709         echo "Some influential environment variables:"
3710         echo "  CC                             C compiler command"
3711         echo "  CXX                            C++ compiler command"
3712         echo "  CFLAGS                         C compiler flags"
3713         echo "  CXXFLAGS                       C++ compiler flags"
3714         echo "  WINDRES                        windres command"
3715         echo "  LDFLAGS                        linker flags, e.g. -L<lib dir> if you"
3716         echo "                                 have libraries in a nonstandard"
3717         echo "                                 directory <lib dir>"
3718         echo "  CFLAGS_BUILD                   C compiler flags for build time tool generation"
3719         echo "  CXXFLAGS_BUILD                 C++ compiler flags for build time tool generation"
3720         echo "  LDFLAGS_BUILD                  linker flags for build time tool generation"
3721         echo ""
3722         echo "Use these variables to override the choices made by 'configure' or to help"
3723         echo "it to find libraries and programs with nonstandard names/locations."