Translations update
[openttd/fttd.git] / config.lib
blob33a7e9f72294af99e68a900fb801ebd8d4aa918d
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"
95         with_sse="1"
97         save_params_array="
98                 build
99                 host
100                 cc_build
101                 cc_host
102                 cxx_build
103                 cxx_host
104                 windres
105                 strip
106                 lipo
107                 awk
108                 os
109                 endian
110                 cpu_type
111                 config_log
112                 prefix_dir
113                 binary_dir
114                 data_dir
115                 doc_dir
116                 icon_dir
117                 icon_theme_dir
118                 man_dir
119                 menu_dir
120                 personal_dir
121                 shared_dir
122                 install_dir
123                 menu_group
124                 menu_name
125                 binary_name
126                 enable_debug
127                 enable_desync_debug
128                 enable_profiling
129                 enable_lto
130                 enable_dedicated
131                 enable_network
132                 enable_static
133                 enable_translator
134                 enable_unicode
135                 enable_console
136                 enable_assert
137                 enable_strip
138                 enable_universal
139                 enable_osx_g5
140                 enable_cocoa_quartz
141                 enable_cocoa_quickdraw
142                 with_osx_sysroot
143                 with_application_bundle
144                 with_allegro
145                 with_sdl
146                 with_cocoa
147                 with_zlib
148                 with_lzma
149                 with_lzo2
150                 with_xdg_basedir
151                 with_png
152                 enable_builtin_depend
153                 with_makedepend
154                 with_direct_music
155                 with_sort
156                 with_iconv
157                 with_midi
158                 with_midi_arg
159                 with_libtimidity
160                 with_freetype
161                 with_fontconfig
162                 with_icu
163                 static_icu
164                 with_psp_config
165                 with_threads
166                 with_distcc
167                 with_ccache
168                 with_grfcodec
169                 with_nforenum
170                 with_sse
171         CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD"
174 detect_params() {
175         # Walk over all params from the user and override any default settings if
176         #  needed. This also handles any invalid option.
177         for p in "$@"; do
178                 if [ -n "$prev_p" ]; then
179                         eval "$prev_p=\$p"
180                         prev_p=
181                         continue
182                 fi
184                 optarg=`expr "x$p" : 'x[^=]*=\(.*\)'`
186                 case "$p" in
187                         --help | -h | -\?)            showhelp; exit 0;;
189                         --config-log)                 prev_p="config_log";;
190                         --config-log=*)               config_log="$optarg";;
192                         --build)                      prev_p="build";;
193                         --build=*)                    build="$optarg";;
195                         --host)                       prev_p="host";;
196                         --host=*)                     host="$optarg";;
198                         --os)                         prev_p="os";;
199                         --os=*)                       os="$optarg";;
201                         --cpu-type)                   prev_p="cpu_type";;
202                         --cpu-type=*)                 cpu_type="$optarg";;
204                         --cc-build)                   prev_p="cc_build";;
205                         --cc-build=*)                 cc_build="$optarg";;
206                         --cc-host)                    prev_p="cc_host";;
207                         --cc-host=*)                  cc_host="$optarg";;
208                         --cxx-build)                  prev_p="cxx_build";;
209                         --cxx-build=*)                cxx_build="$optarg";;
210                         --cxx-host)                   prev_p="cxx_host";;
211                         --cxx-host=*)                 cxx_host="$optarg";;
212                         --windres)                    prev_p="windres";;
213                         --windres=*)                  windres="$optarg";;
214                         --awk)                        prev_p="awk";;
215                         --awk=*)                      awk="$optarg";;
216                         --strip)                      prev_p="strip";;
217                         --strip=*)                    strip="$optarg";;
218                         --lipo)                       prev_p="lipo";;
219                         --lipo=*)                     lipo="$optarg";;
221                         --endian)                     prev_p="endian";;
222                         --endian=*)                   endian="$optarg";;
226                         # Alias --prefix with --prefix-dir, for compatibility with GNU autotools
227                         --prefix-dir | --prefix)      prev_p="prefix_dir";;
228                         --prefix-dir=* | --prefix=*)  prefix_dir="$optarg";;
230                         --binary-dir)                 prev_p="binary_dir";;
231                         --binary-dir=*)               binary_dir="$optarg";;
233                         --data-dir)                   prev_p="data_dir";;
234                         --data-dir=*)                 data_dir="$optarg";;
236                         --doc-dir)                    prev_p="doc_dir";;
237                         --doc-dir=*)                  doc_dir="$optarg";;
239                         --icon-dir)                   prev_p="icon_dir";;
240                         --icon-dir=*)                 icon_dir="$optarg";;
242                         --icon-theme-dir)             prev_p="icon_theme_dir";;
243                         --icon-theme-dir=*)           icon_theme_dir="$optarg";;
244                         --without-icon-theme)         icon_theme_dir="";;
246                         --menu-dir)                   prev_p="menu_dir";;
247                         --menu-dir=*)                 menu_dir="$optarg";;
248                         --without-menu-entry)         menu_dir="";;
250                         --menu-name)                  prev_p="menu_name";;
251                         --menu-name=*)                menu_name="$optarg";;
253                         --binary-name)                prev_p="binary_name";;
254                         --binary-name=*)              binary_name="$optarg";;
256                         --man-dir)                    prev_p="man_dir";;
257                         --man-dir=*)                  man_dir="$optarg";;
259                         --personal-dir)               prev_p="personal_dir";;
260                         --personal-dir=*)             personal_dir="$optarg";;
261                         --without-personal-dir)       personal_dir="";;
263                         --shared-dir)                 prev_p="shared_dir";;
264                         --shared-dir=*)               shared_dir="$optarg";;
265                         --without-shared-dir)         shared_dir="";;
267                         --install-dir)                prev_p="install_dir";;
268                         --install-dir=*)              install_dir="$optarg";;
272                         --menu-group)                 prev_p="menu_group";;
273                         --menu-group=*)               menu_group="$optarg";;
277                         --enable-debug)               enable_debug="1";;
278                         --enable-debug=*)             enable_debug="$optarg";;
279                         --enable-desync-debug)        enable_desync_debug="1";;
280                         --enable-desync-debug=*)      enable_desync_debug="$optarg";;
281                         --enable-profiling)           enable_profiling="1";;
282                         --enable-profiling=*)         enable_profiling="$optarg";;
283                         --enable-lto)                 enable_lto="1";;
284                         --enable-lto=*)               enable_lto="$optarg";;
285                         --enable-ipo)                 enable_lto="1";;
286                         --enable-ipo=*)               enable_lto="$optarg";;
287                         --enable-dedicated)           enable_dedicated="1";;
288                         --enable-dedicated=*)         enable_dedicated="$optarg";;
289                         --enable-network)             enable_network="2";;
290                         --enable-network=*)           enable_network="$optarg";;
291                         --disable-network)            enable_network="0";;
292                         --disable-static)             enable_static="0";;
293                         --enable-static)              enable_static="2";;
294                         --enable-static=*)            enable_static="$optarg";;
295                         --disable-translator)         enable_translator="0";;
296                         --enable-translator)          enable_translator="2";;
297                         --enable-translator=*)        enable_translator="$optarg";;
298                         --disable-assert)             enable_assert="0";;
299                         --enable-assert)              enable_assert="2";;
300                         --enable-assert=*)            enable_assert="$optarg";;
301                         --disable-strip)              enable_strip="0";;
302                         --enable-strip)               enable_strip="2";;
303                         --enable-strip=*)             enable_strip="$optarg";;
304                         --disable-universal)          enable_universal="0";;
305                         --enable-universal)           enable_universal="i386 ppc";;
306                         --enable-universal=*)         enable_universal="$optarg";;
307                         --disable-osx-g5)             enable_osx_g5="0";;
308                         --enable-osx-g5)              enable_osx_g5="2";;
309                         --enable-osx-g5=*)            enable_osx_g5="$optarg";;
310                         --disable-unicode)            enable_unicode="0";;
311                         --enable-unicode)             enable_unicode="2";;
312                         --enable-unicode=*)           enable_unicode="$optarg";;
313                         --disable-console)            enable_console="0";;
314                         --enable-console)             enable_console="2";;
315                         --enable-console=*)           enable_console="$optarg";;
317                         --disable-cocoa-quartz)       enable_cocoa_quartz="0";;
318                         --enable-cocoa-quartz)        enable_cocoa_quartz="2";;
319                         --enable-cocoa-quartz=*)      enable_cocoa_quartz="$optarg";;
320                         --disable-cocoa-quickdraw)    enable_cocoa_quickdraw="0";;
321                         --enable-cocoa-quickdraw)     enable_cocoa_quickdraw="2";;
322                         --enable-cocoa-quickdraw=*)   enable_cocoa_quickdraw="$optarg";;
324                         --with-allegro)               with_allegro="2";;
325                         --without-allegro)            with_allegro="0";;
326                         --with-allegro=*)             with_allegro="$optarg";;
328                         --with-sdl)                   with_sdl="2";;
329                         --without-sdl)                with_sdl="0";;
330                         --with-sdl=*)                 with_sdl="$optarg";;
332                         --with-cocoa)                 with_cocoa="2";;
333                         --without-cocoa)              with_cocoa="0";;
334                         --with-cocoa=*)               with_cocoa="$optarg";;
336                         --with-zlib)                  with_zlib="2";;
337                         --without-zlib)               with_zlib="0";;
338                         --with-zlib=*)                with_zlib="$optarg";;
340                         --with-lzma)                  with_lzma="2";;
341                         --without-lzma)               with_lzma="0";;
342                         --with-lzma=*)                with_lzma="$optarg";;
343                         --with-liblzma)               with_lzma="2";;
344                         --without-liblzma)            with_lzma="0";;
345                         --with-liblzma=*)             with_lzma="$optarg";;
347                         --with-lzo2)                  with_lzo2="2";;
348                         --without-lzo2)               with_lzo2="0";;
349                         --with-lzo2=*)                with_lzo2="$optarg";;
350                         --with-liblzo2)               with_lzo2="2";;
351                         --without-liblzo2)            with_lzo2="0";;
352                         --with-liblzo2=*)             with_lzo2="$optarg";;
354                         --with-xdg-basedir)           with_xdg_basedir="2";;
355                         --without-xdg-basedir)        with_xdg_basedir="0";;
356                         --with-xdg-basedir=*)         with_xdg_basedir="$optarg";;
357                         --with-libxdg-basedir)        with_xdg_basedir="2";;
358                         --without-libxdg-basedir)     with_xdg_basedir="0";;
359                         --with-libxdg-basedir=*)      with_xdg_basedir="$optarg";;
361                         --with-png)                   with_png="2";;
362                         --without-png)                with_png="0";;
363                         --with-png=*)                 with_png="$optarg";;
364                         --with-libpng)                with_png="2";;
365                         --without-libpng)             with_png="0";;
366                         --with-libpng=*)              with_png="$optarg";;
368                         --with-libtimidity)           with_libtimidity="2";;
369                         --without-libtimidity)        with_libtimidity="0";;
370                         --with-libtimidity=*)         with_libtimidity="$optarg";;
372                         --with-freetype)              with_freetype="2";;
373                         --without-freetype)           with_freetype="0";;
374                         --with-freetype=*)            with_freetype="$optarg";;
375                         --with-libfreetype)           with_freetype="2";;
376                         --without-libfreetype)        with_freetype="0";;
377                         --with-libfreetype=*)         with_freetype="$optarg";;
379                         --with-fontconfig)            with_fontconfig="2";;
380                         --without-fontconfig)         with_fontconfig="0";;
381                         --with-fontconfig=*)          with_fontconfig="$optarg";;
382                         --with-libfontconfig)         with_fontconfig="2";;
383                         --without-libfontconfig)      with_fontconfig="0";;
384                         --with-libfontconfig=*)       with_fontconfig="$optarg";;
386                         --with-icu)                   with_icu="2";;
387                         --without-icu)                with_icu="0";;
388                         --with-icu=*)                 with_icu="$optarg";;
389                         --with-libicu)                with_icu="2";;
390                         --without-libicu)             with_icu="0";;
391                         --with-libicu=*)              with_icu="$optarg";;
392                         --static-icu)                 static_icu="1";;
393                         --static-icu=*)               static_icu="$optarg";;
394                         --static-libicu)              static_icu="1";;
395                         --static-libicu=*)            static_icu="$optarg";;
397                         --with-psp-config)            with_psp_config="2";;
398                         --without-psp-config)         with_psp_config="0";;
399                         --with-psp-config=*)          with_psp_config="$optarg";;
401                         --disable-builtin-depend)     enable_builtin_depend="0";;
402                         --enable-builtin-depend)      enable_builtin_depend="2";;
403                         --enable-builtin-depend=*)    enable_builtin_depend="$optarg";;
405                         --with-makedepend)            with_makedepend="2";;
406                         --without-makedepend)         with_makedepend="0";;
407                         --with-makedepend=*)          with_makedepend="$optarg";;
409                         --with-direct-music)          with_direct_music="2";;
410                         --without-direct-music)       with_direct_music="0";;
411                         --with-direct-music=*)        with_direct_music="$optarg";;
413                         --with-sort)                  with_sort="2";;
414                         --without-sort)               with_sort="0";;
415                         --with-sort=*)                with_sort="$optarg";;
417                         --with-iconv)                 with_iconv="2";;
418                         --without-iconv)              with_iconv="0";;
419                         --with-iconv=*)               with_iconv="$optarg";;
421                         --with-midi=*)                with_midi="$optarg";;
422                         --with-midi-arg=*)            with_midi_arg="$optarg";;
424                         --without-distcc)             with_distcc="0";;
425                         --with-distcc)                with_distcc="2";;
426                         --with-distcc=*)              with_distcc="$optarg";;
428                         --without-ccache)             with_ccache="0";;
429                         --with-ccache)                with_ccache="2";;
430                         --with-ccache=*)              with_ccache="$optarg";;
432                         --without-nforenum)           with_nforenum="0";;
433                         --with-nforenum)              with_nforenum="2";;
434                         --with-nforenum=*)            with_nforenum="$optarg";;
436                         --without-grfcodec)           with_grfcodec="0";;
437                         --with-grfcodec)              with_grfcodec="2";;
438                         --with-grfcodec=*)            with_grfcodec="$optarg";;
440                         --without-osx-sysroot)        with_osx_sysroot="0";;
441                         --with-osx-sysroot)           with_osx_sysroot="2";;
442                         --with-osx-sysroot=*)         with_osx_sysroot="$optarg";;
444                         --without-application-bundle) with_application_bundle="0";;
445                         --with-application-bundle)    with_application_bundle="1";;
446                         --with-application-bundle=*)  with_application_bundle="$optarg";;
448                         --without-threads)            with_threads="0";;
449                         --with-threads)               with_threads="1";;
450                         --with-threads=*)             with_threads="$optarg";;
452                         --without-sse)                with_sse="0";;
453                         --with-sse)                   with_sse="1";;
454                         --with-sse=*)                 with_sse="$optarg";;
456                         CC=* | --CC=*)                CC="$optarg";;
457                         CXX=* | --CXX=*)              CXX="$optarg";;
458                         CFLAGS=* | --CFLAGS=*)        CFLAGS="$optarg";;
459                         CXXFLAGS=* | --CXXFLAGS=*)    CXXFLAGS="$optarg";;
460                         LDFLAGS=* | --LDFLAGS=*)      LDFLAGS="$optarg";;
461                         CFLAGS_BUILD=* | --CFLAGS_BUILD=* | --CFLAGS-BUILD=*)     CFLAGS_BUILD="$optarg";;
462                         CXXFLAGS_BUILD=* | --CXXFLAGS_BUILD=* | --CXXFLAGS-BUILD=*) CXXFLAGS_BUILD="$optarg";;
463                         LDFLAGS_BUILD=* | --LDFLAGS_BUILD=* | --LDFLAGS-BUILD=*)   LDFLAGS_BUILD="$optarg";;
465                         --ignore-extra-parameters)    ignore_extra_parameters="1";;
467                         --* | -*)
468                                 if [ "$ignore_extra_parameters" = "0" ]; then
469                                         log 1 "Unknown option $p"
470                                         exit 1
471                                 else
472                                         log 1 "Unknown option $p ignored"
473                                 fi
474                                 ;;
475                 esac
476         done
478         if [ -n "$prev_p" ]; then
479                 log 1 "configure: error: missing argument to --$prev_p"
480                 exit 1
481         fi
483         # Clean the logfile
484         echo "" > $config_log
485         log 2 "Invocation: $0 $*"
488 save_params() {
489         # Here we save all params, so we can later on do an exact redo of this
490         #  configuration, without having the user to re-input stuff
492         echo "Running configure with following options:" >> $config_log
493         echo "" >> $config_log
495         configure="$CONFIGURE_EXECUTABLE --ignore-extra-parameters"
496         for p in $save_params_array; do
497                 eval "v=\"\$$p\""
498                 p=`echo "$p" | sed 's@_@-@g;s@\n@@g;s@ @\\ @g'`
499                 # Only save those params that aren't empty
500                 configure="$configure --$p=\"$v\""
501         done
503         echo "$configure" >> $config_log
504         echo "$configure" > config.cache
505         echo "" >> $config_log
508 check_params() {
509         # Some params want to be in full uppercase, else they might not work as
510         # expected.. fix that here
512         endian=`echo $endian | tr '[a-z]' '[A-Z]'`
513         os=`echo $os | tr '[a-z]' '[A-Z]'`
514         cpu_type=`echo $cpu_type | tr '[a-z]' '[A-Z]'`
516         # Check if all params have valid values
518         # Endian only allows AUTO, LE and, BE
519         if ! echo $endian | egrep -q '^(AUTO|LE|BE|PREPROCESSOR)$'; then
520                 log 1 "configure: error: invalid option --endian=$endian"
521                 log 1 " Available options are: --endian=[AUTO|LE|BE]"
522                 exit 1
523         fi
524         if [ "$endian" = "PREPROCESSOR" ] && [ "$os" != "OSX" ]; then
525                 log 1 "configure: error: invalid option --endian=$endian"
526                 log 1 " PREPROCESSOR is only available for OSX"
527                 exit 1
528         fi
529         # OS only allows DETECT, UNIX, OSX, FREEBSD, OPENBSD, MORPHOS, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
530         if ! echo $os | egrep -q '^(DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP)$'; then
531                 log 1 "configure: error: invalid option --os=$os"
532                 log 1 " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|PSP]"
533                 exit 1
534         fi
535         # cpu_type can be either 32 or 64
536         if ! echo $cpu_type | egrep -q '^(32|64|DETECT)$'; then
537                 log 1 "configure: error: invalid option --cpu-type=$cpu_type"
538                 log 1 " Available options are: --cpu-type[=DETECT|32|64]"
539                 exit 1
540         fi
541         # enable_debug should be between 0 and 4
542         if ! echo $enable_debug | egrep -q '^[0123]$'; then
543                 log 1 "configure: error: invalid option --enable-debug=$enable_debug"
544                 log 1 " Available options are: --enable-debug[=0123]"
545                 exit 1
546         fi
548         # enable_desync_debug should be between 0 and 3
549         if ! echo $enable_desync_debug | egrep -q '^[012]$'; then
550                 log 1 "configure: error: invalid option --enable-desync-debug=$enable_desync_debug"
551                 log 1 " Available options are: --enable-desync-debug[=012]"
552                 exit 1
553         fi
555         detect_awk
557         detect_os
559         check_build
560         check_host
562         # Check for universal builds; they only make sense for OSX, so fail if enabled for another OS
563         if [ "$enable_universal" = "0" ]; then
564                 log 1 "checking universal build... no"
565         else
566                 if [ "$os" != "OSX" ]; then
567                         log 1 "configure: error: --enable-universal only works on OSX"
568                         exit 1
569                 fi
570                 log 1 "checking universal build... yes, for: $enable_universal"
571         fi
573         # Already detected by check_build
574         log 1 "checking build cc... $cc_build"
575         log 1 "checking host cc... $cc_host"
577         check_cxx_build
578         check_cxx_host
579         check_windres
580         if [ "$enable_strip" != "0" ]; then
581                 check_strip
582         else
583                 log 1 "checking strip... disabled"
584         fi
585         check_lipo
587         if [ "$enable_builtin_depend" != "0" ]; then
588                 log 1 "checking builtin depend... yes"
589                 makedepend="\$(SRC_OBJS_DIR)/\$(DEPEND)"
590         else
591                 log 1 "checking builtin depend... no"
592         fi
594         check_makedepend
595         detect_cputype
596         detect_sse_capable_architecture
598         if [ "$enable_static" = "1" ]; then
599                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "DOS" ]; then
600                         enable_static="2"
601                 else
602                         enable_static="0"
603                 fi
604         fi
606         if [ "$enable_static" != "0" ]; then
607                 log 1 "checking static... yes"
609                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "OSX" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "DOS" ]; then
610                         log 1 "WARNING: static is only known to work on Windows, DOS, MacOSX and MorphOS"
611                         log 1 "WARNING: use static at your own risk on this platform"
613                         sleep 5
614                 fi
615         else
616                 log 1 "checking static... no"
617         fi
619         if [ "$enable_unicode" = "1" ]; then
620                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "DOS" ]; then
621                         enable_unicode="2"
622                 else
623                         enable_unicode="0"
624                 fi
625         fi
627         if [ "$enable_unicode" != "0" ]; then
628                 log 1 "checking unicode... yes"
629         else
630                 log 1 "checking unicode... no"
631         fi
633         # Show what we configured
634         if [ "$enable_debug" = "0" ]; then
635                 log 1 "using debug level... no"
636         elif [ "$enable_profiling" != "0" ]; then
637                 log 1 "using debug level... profiling (debug level $enable_debug)"
638         else
639                 log 1 "using debug level... level $enable_debug"
640         fi
642         if [ "$enable_desync_debug" = "0" ]; then
643                 log 1 "using desync debug level... no"
644         else
645                 log 1 "using desync debug level... level $enable_desync_debug"
646                 log 1 "WARNING: desync debug functions slow down the game considerably."
647                 log 1 "WARNING: use only when you are instructed to do so"
648                 log 1 "         or when you know what you are doing."
650                 sleep 5
651         fi
653         if [ "$enable_lto" != "0" ]; then
654                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
655                 if $cxx_build -dumpspecs 2>&1 | grep -q '\%{flto' || $cxx_build -help ipo 2>&1 | grep -q '\-ipo'; then
656                         log 1 "using link time optimization... yes"
657                 else
658                         enable_lto="0"
659                         log 1 "using link time optimization... no"
660                         log 1 "WARNING: you selected link time optimization but it is not found."
661                         sleep 5
662                 fi
663         else
664                 log 1 "using link time optimization... no"
665         fi
668         if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
669                 if [ "$with_osx_sysroot" = "1" ]; then
670                         with_osx_sysroot="0"
672                         log 1 "checking OSX sysroot... not OSX, skipping"
673                 else
674                         log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
675                         exit 1
676                 fi
677         fi
679         if [ "$with_osx_sysroot" != "0" ]; then
680                 if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
681                         # Sysroot manually specified? Check for usability
682                         log 1 "checking OSX sysroot... $with_osx_sysroot"
683                         if ! check_osx_sdk "$with_osx_sysroot"; then
684                                 log 1 "Passed sysroot not found/not functional"
685                                 exit 1
686                         fi
687                 else
688                         # If autodetect and no universal, use system default
689                         if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
690                                 log 1 "checking OSX sysroot... no (use system default)"
691                         else
692                                 log 1 "checking OSX sysroot... automatically"
693                                 detect_osx_sdk
694                         fi
695                 fi
697                 if [ -n "$osx_sdk_path" ]; then
698                         if [ "$enable_universal" != "0" ]; then
699                                 if [ -z "$osx_sdk_104_path" ]; then
700                                         log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
701                                         log 1 "WARNING: binary will only run on OSX 10.5 or later"
702                                         osx_sdk_104_path="$osx_sdk_path"
703                                 fi
704                                 OSX_SYSROOT="-isysroot $osx_sdk_104_path"
705                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
706                         else
707                                 OSX_SYSROOT="-isysroot $osx_sdk_path"
708                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
709                         fi
710                 fi
711         else
712                 if [ "$os" = "OSX" ]; then
713                         log 1 "checking OSX sysroot... no (use system default)"
714                 fi
715         fi
717         detect_allegro
718         detect_sdl
719         detect_cocoa
721         if [ "$enable_dedicated" != "0" ]; then
722                 log 1 "checking GDI video driver... dedicated server, skipping"
723                 log 1 "checking dedicated... found"
725                 if [ "$enable_network" = "0" ]; then
726                         log 1 "configure: error: building a dedicated server without network support is pointless"
727                         exit 1
728                 fi
729         else
730                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
731                         log 1 "checking GDI video driver... found"
732                 else
733                         log 1 "checking GDI video driver... not Windows, skipping"
734                 fi
736                 if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
737                         log 1 "configure: error: no video driver development files found"
738                         log 1 " If you want a dedicated server use --enable-dedicated as parameter"
739                         exit 1
740                 else
741                         log 1 "checking dedicated... not selected"
742                 fi
743         fi
745         if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
746                 log 1 "checking console application... not Windows, skipping"
747         elif [ "$enable_console" = "1" ] && [ "$enable_dedicated" != "0" ]; then
748                 log 1 "checking console application... dedicated server, enabled"
749                 enable_console="2"
750         elif [ "$enable_console" = "1" ]; then
751                 log 1 "checking console application... disabled (only used when forced)"
752                 enable_console="0"
753         elif [ "$enable_console" = "0" ]; then
754                 log 1 "checking console application... disabled"
755         else
756                 log 1 "checking console application... enabled"
757         fi
759         if [ "$enable_network" = "1" ] && [ "$os" = "DOS" ]; then
760                 log 1 "checking network... DOS, skipping"
761                 enable_network=0
762         elif [ "$enable_network" != "0" ]; then
763                 log 1 "checking network... found"
764         else
765                 log 1 "checking network... disabled"
766         fi
768         log 1 "checking squirrel... found"
769         SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"
771         if [ "$enable_translator" != "0" ]; then
772                 log 1 "checking translator... debug"
773                 # -t shows TODO items, normally they are muted
774                 strgen_flags="-t"
775         else
776                 log 1 "checking translator... no"
777                 strgen_flags=""
778         fi
780         if [ "$enable_assert" != "0" ]; then
781                 log 1 "checking assert... enabled"
782         else
783                 log 1 "checking assert... disabled"
784         fi
786         pre_detect_with_zlib=$with_zlib
787         detect_zlib
789         if [ "$with_zlib" = "0" ] || [ -z "$zlib" ]; then
790                 log 1 "WARNING: zlib was not detected or disabled"
791                 log 1 "WARNING: OpenTTD doesn't require zlib, but it does mean that many features"
792                 log 1 "WARNING: (like loading most old savegames/scenarios, loading heightmaps,"
793                 log 1 "WARNING: using PNG, or using fonts, ...) will be disabled."
794                 if [ "$pre_detect_with_zlib" = "0" ]; then
795                         log 1 "WARNING: We strongly suggest you to install zlib."
796                 else
797                         log 1 "configure: error: no zlib detected"
798                         log 1 " If you want to compile without zlib use --without-zlib as parameter"
799                         exit
800                 fi
801         fi
803         pre_detect_with_lzma=$with_lzma
804         detect_lzma
806         if [ "$with_lzma" = "0" ] || [ -z "$lzma_config" ]; then
807                 log 1 "WARNING: lzma was not detected or disabled"
808                 log 1 "WARNING: OpenTTD doesn't require lzma, but it does mean that many features"
809                 log 1 "WARNING: (like loading most savegames/scenarios and joining most servers)"
810                 log 1 "WARNING: will be disabled."
811                 if [ "$pre_detect_with_lzma" = "0" ]; then
812                         log 1 "WARNING: We strongly suggest you to install liblzma."
813                         log 1 "configure: error: no liblzma detected"
814                 else
815                         log 1 " If you want to compile without lzma use --without-lzma as parameter"
816                         exit
817                 fi
818         fi
820         pre_detect_with_lzo2=$with_lzo2
821         detect_lzo2
823         if [ "$with_lzo2" = "0" ] || [ -z "$lzo2" ]; then
824                 log 1 "WARNING: liblzo2 was not detected or disabled"
825                 log 1 "WARNING: OpenTTD doesn't require liblzo2, but it does mean that"
826                 log 1 "WARNING: loading old savegames/scenarios will be disabled."
827                 if [ "$pre_detect_with_lzo2" = "0" ]; then
828                         log 1 "WARNING: We strongly suggest you to install liblzo2."
829                 else
830                         log 1 "configure: error: no liblzo2 detected"
831                         log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
832                         exit
833                 fi
834         fi
836         detect_xdg_basedir
837         detect_png
838         detect_freetype
839         detect_fontconfig
840         detect_icu
841         detect_pspconfig
842         detect_libtimidity
844         if [ "$with_direct_music" != "0" ]; then
845                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
846                         if [ "$with_direct_music" != "1" ]; then
847                                 log 1 "configure: error: direct-music is only supported on Win32 targets"
848                                 exit 1
849                         fi
850                         with_direct_music="0"
852                         log 1 "checking direct-music... not Windows, skipping"
853                 else
854                         check_direct_music
855                 fi
856         fi
858         detect_sort
860         if [ "$os" = "OSX" ] && [ "$endian" = "AUTO" ]; then
861                 endian="PREPROCESSOR"
862         fi
864         log 1 "checking endianness... $endian"
866         # Suppress language errors when there is a version defined, indicating a release
867         #  It just isn't pretty if any release produces warnings in the languages.
868         if [ -f "$ROOT_DIR/version" ]; then
869                 lang_suppress="yes"
870                 log 1 "suppress language errors... yes"
871         else
872                 lang_suppress=""
873                 log 1 "suppress language errors... no"
874         fi
876         if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
877                 if [ "$os" = "MORPHOS" ]; then
878                         strip_arg="--strip-all --strip-unneeded --remove-section .comment"
879                 elif [ "$os" = "OSX" ]; then
880                         strip_arg=""
881                 elif [ "$os" = "OS2" ]; then
882                         strip_arg=""
883                         # OS2 uses strip via gcc, because it needs to be feed to emxbind
884                         LDFLAGS="$LDFLAGS -s"
885                 elif [ "$os" = "SUNOS" ]; then
886                         # The GNU strip does know -s, the non-GNU doesn't
887                         #  So try to detect it (in a bit of an ugly way)
888                         strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
889                 else
890                         strip_arg="-s"
891                 fi
893                 log 1 "checking stripping... $strip $strip_arg"
894         else
895                 strip=""
896                 log 1 "checking stripping... skipped"
897         fi
899         if [ "$with_distcc" = "0" ]; then
900                 log 1 "checking distcc... no"
901         elif [ "$with_distcc" = "1" ]; then
902                 with_distcc="0"
904                 log 1 "checking distcc... no (only used when forced)"
905         elif [ "$with_distcc" = "2" ]; then
906                 distcc="distcc"
907         else
908                 distcc="$with_distcc"
909         fi
910         if [ "$with_distcc" != "0" ]; then
911                 res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
912                 if [ "$res" != "distcc" ]; then
913                         distcc=""
914                         log 1 "checking distcc... no"
915                         if [ "$with_distcc" = "2" ]; then
916                                 log 1 "configure: error: no distcc detected, but was forced to be used"
917                                 exit 1
918                         fi
919                         if [ "$with_distcc" != "1" ]; then
920                                 log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
921                                 exit 1
922                         fi
923                 fi
925                 log 1 "checking distcc... $distcc"
926         fi
928         if [ "$with_ccache" = "0" ]; then
929                 log 1 "checking ccache... no"
930         elif [ "$with_ccache" = "1" ]; then
931                 with_ccache="0"
933                 log 1 "checking ccache... no (only used when forced)"
934         elif [ "$with_ccache" = "2" ]; then
935                 ccache="ccache"
936         else
937                 ccache="$with_ccache"
938         fi
939         if [ "$with_ccache" != "0" ]; then
940                 res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
941                 if [ "$res" != "ccache" ]; then
942                         ccache=""
943                         log 1 "checking ccache... no"
944                         if [ "$with_ccache" = "2" ]; then
945                                 log 1 "configure: error: no ccache detected, but was forced to be used"
946                                 exit 1
947                         fi
948                         if [ "$with_ccache" != "1" ]; then
949                                 log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
950                                 exit 1
951                         fi
952                 fi
954                 log 1 "checking ccache... $ccache"
955         fi
957         detect_grfcodec
958         detect_nforenum
960         if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
961                 log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
962                 nforenum=""
963         fi
965         if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
966                 log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
967                 grfcodec=""
968         fi
970         if [ "$os" = "DOS" ]; then
971                 with_threads="0"
972         fi
974         if [ "$os" != "OSX" ] && [ "$with_application_bundle" != "0" ]; then
975                 if [ "$with_application_bundle" = "1" ]; then
976                         with_application_bundle="0"
978                         log 1 "checking OSX application bundle... not OSX, skipping"
979                 else
980                         log 1 "configure: error: --with-application-bundle only works if OSX is the target"
981                         exit 1
982                 fi
983         fi
985         if [ "$os" = "OSX" ] && [ "$with_application_bundle" = "1" ]; then
986                 OSXAPP="OpenTTD.app"
987         else
988                 OSXAPP=""
989         fi
991         if [ "$os" = "OSX" ]; then
992                 # Test on ppc970 (G5) - we can optimize there
994                 if [ "$enable_osx_g5" != "0" ]; then
995                         log 1 "detecting ppc970 (G5)... yes (forced)"
996                 else
997                         # First, are we a real OSX system, else we can't detect it
998                         native=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | grep darwin`
999                         # If $host doesn't match $build , we are cross-compiling
1000                         if [ -n "$native" ] && [ "$build" = "$host" ]; then
1001                                 $cxx_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
1002                                 res=`./G5_detector`
1003                                 rm -f G5_detector
1004                                 if [ -n "$res" ]; then
1005                                         # This is G5, add flags for it
1006                                         enable_osx_g5="2"
1008                                         log 1 "detecting ppc970 (G5)... yes"
1009                                 else
1010                                         enable_osx_g5="0"
1012                                         log 1 "detecting ppc970 (G5)... no"
1013                                 fi
1014                         else
1015                                 enable_osx_g5="0"
1017                                 log 1 "detecting ppc970 (G5)... no (cross-compiling)"
1018                         fi
1019                 fi
1020         else
1021                 if [ "$enable_osx_g5" != "0" ]; then
1022                         log 1 "configure: error: ppc970 (OSX G5) selected, but not compiling for OSX"
1023                         log 1 "configure: error: either select OSX as OS, or deselect ppc970"
1025                         exit 1
1026                 fi
1027         fi
1029         if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
1030                 log 1 "checking revision... svn detection"
1031         elif [ -d "$ROOT_DIR/../.svn" ] && [ -n "`svn help 2>/dev/null`" ] && LC_ALL=C svn info $ROOT_DIR/.. | grep -q '^URL:.*tags$'; then
1032                 # subversion changed its behaviour; now not all folders have a .svn folder,
1033                 # but only the root folder. Since making tags requires a (sparse) checkout
1034                 # of the tags folder, the folder of the tag does not have a .svn folder
1035                 # anymore and this fails to detect the subversion repository checkout.
1036                 log 1 "checking revision... svn detection (tag)"
1037         elif [ -d "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
1038                 log 1 "checking revision... git detection"
1039         elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`HGPLAIN= hg help 2>/dev/null`" ]; then
1040                 log 1 "checking revision... hg detection"
1041         elif [ -f "$ROOT_DIR/.ottdrev" ]; then
1042                 log 1 "checking revision... source tarball"
1043         else
1044                 log 1 "checking revision... no detection"
1045                 log 1 "WARNING: there is no means to determine the version."
1046                 log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenTTD."
1047                 log 1 "WARNING: you can only join game servers that have been compiled without"
1048                 log 1 "WARNING:   version detection."
1049                 log 1 "WARNING: there is a great chance you desync."
1050                 log 1 "WARNING: USE WITH CAUTION!"
1052                 sleep 5
1053         fi
1055         if [ "$doc_dir" = "1" ]; then
1056                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1057                         doc_dir="share/doc/openttd"
1058                 else
1059                         doc_dir="$data_dir/docs"
1060                 fi
1061         else
1062                 doc_dir="`echo $doc_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1063         fi
1065         if [ "$icon_theme_dir" = "1" ]; then
1066                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1067                         icon_theme_dir="share/icons/hicolor"
1068                 else
1069                         icon_theme_dir=""
1070                 fi
1071         else
1072                 icon_theme_dir="`echo $icon_theme_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1073         fi
1075         if [ "$personal_dir" = "1" ]; then
1076                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ] || [ "$os" = "DOS" ] || [ "$os" = "HAIKU" ]; then
1077                         personal_dir="OpenTTD"
1078                 elif [ "$os" = "OSX" ]; then
1079                         personal_dir="Documents/OpenTTD"
1080                 else
1081                         personal_dir=".openttd"
1082                 fi
1083         else
1084                 personal_dir="`echo $personal_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1085         fi
1087         if [ "$shared_dir" = "1" ]; then
1088                 # we are using default values
1089                 if [ "$os" = "OSX" ]; then
1090                         shared_dir="/Library/Application\\\\ Support/OpenTTD"
1091                 else
1092                         shared_dir=""
1093                 fi
1094         else
1095                 shared_dir="`echo $shared_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1096         fi
1098         if [ "$man_dir" = "1" ]; then
1099                 # add manpage on UNIX systems
1100                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OSX" ]; then
1101                         man_dir="share/man/man6"
1102                 else
1103                         man_dir=""
1104                 fi
1105         else
1106                 man_dir="`echo $man_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1107         fi
1109         if [ "$menu_dir" = "1" ]; then
1110                 # add a freedesktop menu item only for some UNIX systems
1111                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1112                         menu_dir="share/applications"
1113                 else
1114                         menu_dir=""
1115                 fi
1116         else
1117                 menu_dir="`echo $menu_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1118         fi
1120         detect_iconv
1122         if [ -n "$personal_dir" ]
1123         then
1124                 log 1 "personal home directory... $personal_dir"
1125         else
1126                 log 1 "personal home directory... none"
1127         fi
1129         if [ -n "$shared_dir" ]
1130         then
1131                 log 1 "shared data directory... $shared_dir"
1132         else
1133                 log 1 "shared data directory... none"
1134         fi
1136         if [ -n "$install_dir" ]
1137         then
1138                 log 1 "installation directory... $install_dir"
1139         else
1140                 log 1 "installation directory... none"
1141         fi
1143         if [ -n "$icon_theme_dir" ]
1144         then
1145                 log 1 "icon theme directory... $icon_theme_dir"
1146         else
1147                 log 1 "icon theme directory... none"
1148         fi
1150         if [ -n "$man_dir" ]
1151         then
1152                 log 1 "manual page directory... $man_dir"
1153         else
1154                 log 1 "manual page directory... none"
1155         fi
1157         if [ -n "$menu_dir" ]
1158         then
1159                 log 1 "menu item directory... $menu_dir"
1160         else
1161                 log 1 "menu item directory... none"
1162         fi
1165 make_compiler_cflags() {
1166         # Params:
1167         # $1 - compiler
1168         # $2 - name of the cflags variable
1169         # $3 - name of the cxxflags variable
1170         # $4 - name of the ldflags variable
1171         # $5 - name of the features variable
1173         eval eval "flags=\\\$$2"
1174         eval eval "cxxflags=\\\$$3"
1175         eval eval "ldflags=\\\$$4"
1176         eval eval "features=\\\$$5"
1178         if [ `basename $1 | cut -c 1-3` = "icc" ]; then
1179                 # Enable some things only for certain ICC versions
1180                 cc_version=`$1 -dumpversion | cut -c 1-4 | sed s@\\\.@@g`
1182                 flags="$flags -rdynamic"
1183                 ldflags="$ldflags -rdynamic"
1185                 if [ -z "$first_time_icc_check" ]; then
1186                         first_time_icc_check=no
1187                         if [ $cc_version -lt 90 ]; then
1188                                 log 1 "WARNING: you seem to be using a very old version of ICC"
1189                                 log 1 "WARNING: OpenTTD hasn't been tested with this version"
1190                                 sleep 5
1191                         elif [ $cc_version -lt 120 ]; then
1192                                 log 1 "WARNING: you seem to be using an unsupported ICC version"
1193                                 log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD"
1194                                 sleep 5
1195                         fi
1196                 fi
1198                 flags="$flags -Wall"
1199                 # remark #111: statement is unreachable
1200                 flags="$flags -wd111"
1201                 # remark #181: argument is incompatible with corresponding format string conversion
1202                 # ICC is very picky about signedness of operands, warnings provided by GCC are enough
1203                 flags="$flags -wd181"
1204                 # remark #271: trailing comma is nonstandard
1205                 flags="$flags -wd271"
1206                 # remark #280: selector expression is constant
1207                 flags="$flags -wd280"
1208                 # remark #304: access control not specified ("public" by default)
1209                 flags="$flags -wd304"
1210                 # remark #383: value copied to temporary, reference to temporary used
1211                 flags="$flags -wd383"
1212                 # remark #444: destructor for base class ... is not virtual
1213                 flags="$flags -wd444"
1214                 # remark #593: variable ... was set but never used
1215                 flags="$flags -wd593"
1216                 # warning #654: overloaded virtual function ... is only partially overridden in class ...
1217                 flags="$flags -wd654"
1218                 # remark #810: conversion from ... to ... may lose significant bits
1219                 flags="$flags -wd810"
1220                 # remark #869: parameter ... was never referenced
1221                 flags="$flags -wd869"
1222                 # warning #873: function ... ::operator new ... has no corresponding operator delete ...
1223                 flags="$flags -wd873"
1224                 # remark #981: operands are evaluated in unspecified order
1225                 flags="$flags -wd981"
1226                 # remark #1418: external function definition with no prior declaration
1227                 flags="$flags -wd1418"
1228                 # remark #1419: external declaration in primary source file
1229                 flags="$flags -wd1419"
1230                 # remark #1572: floating-point equality and inequality
1231                 flags="$flags -wd1572"
1232                 # remark #1599: declaration hides variable/parameter ...
1233                 flags="$flags -wd1599"
1234                 # remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
1235                 flags="$flags -wd1720"
1237                 if [ $cc_version -lt 110 ]; then
1238                         # warns about system headers with recent glibc:
1239                         # warning #1292: attribute "__nonnull__" ignored
1240                         flags="$flags -wd1292"
1241                 fi
1243                 if [ $cc_version -ge 100 ]; then
1244                         # warning #1899: multicharacter character literal (potential portability problem)
1245                         flags="$flags -wd1899"
1246                         # vec report defaults to telling where it did loop vectorisation, which is not very important
1247                         flags="$flags -vec-report=0 "
1248                 fi
1250                 if [ $cc_version -ge 110 ]; then
1251                         # remark #2259: non-pointer conversion from ... to ... may lose significant bits
1252                         flags="$flags -wd2259"
1253                         # Use c++0x mode so static_assert() is available
1254                         cxxflags="$cxxflags -std=c++0x"
1255                 fi
1257                 if [ "$enable_lto" != "0" ] && $1 -help ipo | grep -q '\-ipo'; then
1258                         # Use IPO (only if we see IPO exists and is requested)
1259                         flags="$flags -ipo"
1260                         features="$features lto"
1261                 fi
1262         elif basename $1 | grep -q 'clang'; then
1263                 # Enable some things only for certain clang versions
1264                 cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
1266                 # aliasing rules are not held in openttd code
1267                 flags="$flags -fno-strict-aliasing"
1269                 # -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
1270                 # -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
1271                 flags="$flags -Wall -W"
1273                 # warning: unused parameter '...'
1274                 flags="$flags -Wno-unused-parameter"
1276                 # warning: expression result unused
1277                 flags="$flags -Wno-unused-value"
1279                 # warning: multi-character character constant
1280                 flags="$flags -Wno-multichar"
1282                 # warning: explicitly assigning a variable of type '...' to itself
1283                 # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
1284                 flags="$flags -Wno-self-assign"
1286                 if [ "$cc_version" -lt "30" ]; then
1287                         # warning: equality comparison with extraneous parentheses
1288                         flags="$flags -Wno-parentheses"
1289                         # warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
1290                         flags="$flags -Wno-sign-compare"
1291                 fi
1293                 if [ "$cc_version" -ge "30" ]; then
1294                         # warning: equality comparison with extraneous parentheses
1295                         # this warning could be useful, but it warns about code in squirrel
1296                         flags="$flags -Wno-parentheses-equality"
1297                 fi
1299                 if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
1300                         # ccache and distcc run separate preprocess and compile passes,
1301                         # both are fed with the same CFLAGS. Unfortunately, clang
1302                         # complains about -I when compiling preprocessed files:
1303                         # "clang: warning: argument unused during compilation: '-I /usr/include'"
1304                         flags="$flags -Qunused-arguments"
1305                 fi
1307                 if [ "$enable_assert" -eq "0" ]; then
1308                         # do not warn about unused variables when building without asserts
1309                         flags="$flags -Wno-unused-variable"
1310                 fi
1312                 # rdynamic is used to get useful stack traces from crash reports.
1313                 ldflags="$ldflags -rdynamic"
1314         else
1315                 # Enable some things only for certain GCC versions
1316                 cc_version=`$1 -dumpversion | cut -c 1,3`
1318                 if [ $cc_version -lt 33 ]; then
1319                         log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
1320                         exit 1
1321                 fi
1323                 flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
1324                 flags="$flags -Wwrite-strings -Wpointer-arith"
1325                 flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
1326                 flags="$flags -Wformat=2 -Wformat-security"
1328                 if [ $enable_assert -eq 0 ]; then
1329                         # Do not warn about unused variables when building without asserts
1330                         flags="$flags -Wno-unused-variable"
1331                         if [ $cc_version -ge 46 ]; then
1332                                 # GCC 4.6 gives more warnings, disable them too
1333                                 flags="$flags -Wno-unused-but-set-variable"
1334                                 flags="$flags -Wno-unused-but-set-parameter"
1335                         fi
1336                 fi
1338                 if [ $cc_version -ge 34 ]; then
1339                         # Warn when a variable is used to initialise itself:
1340                         # int a = a;
1341                         flags="$flags -Winit-self"
1342                 fi
1344                 if [ $cc_version -ge 40 ]; then
1345                         # GCC 4.0+ complains about that we break strict-aliasing.
1346                         #  On most places we don't see how to fix it, and it doesn't
1347                         #  break anything. So disable strict-aliasing to make the
1348                         #  compiler all happy.
1349                         flags="$flags -fno-strict-aliasing"
1350                         # Warn about casting-out 'const' with regular C-style cast.
1351                         #  The preferred way is const_cast<>() which doesn't warn.
1352                         flags="$flags -Wcast-qual"
1353                 fi
1355                 if [ $cc_version -ge 42 ]; then
1356                         # GCC 4.2+ automatically assumes that signed overflows do
1357                         # not occur in signed arithmetics, whereas we are not
1358                         # sure that they will not happen. It furthermore complains
1359                         # about its own optimized code in some places.
1360                         flags="$flags -fno-strict-overflow"
1361                         # GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
1362                         # Enable it in order to be consistent with older GCC versions.
1363                         flags="$flags -Wnon-virtual-dtor"
1364                 fi
1366                 if [ $cc_version -ge 43 ]; then
1367                         # Use gnu++0x mode so static_assert() is available.
1368                         # Don't use c++0x, it breaks mingw (with gcc 4.4.0).
1369                         cxxflags="$cxxflags -std=gnu++0x"
1370                 fi
1372                 if [ $cc_version -eq 45 ]; then
1373                         # Prevent optimisation supposing enums are in a range specified by the standard
1374                         # For details, see http://gcc.gnu.org/PR43680
1375                         flags="$flags -fno-tree-vrp"
1376                 fi
1378                 if [ $cc_version -ge 47 ]; then
1379                         # Disable -Wnarrowing which gives many warnings, such as:
1380                         # warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
1381                         # They are valid according to the C++ standard, but useless.
1382                         cxxflags="$cxxflags -Wno-narrowing"
1383                         # Disable bogus 'attempt to free a non-heap object' warning
1384                         flags="$flags -Wno-free-nonheap-object"
1385                 fi
1387                 # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
1388                 if [ "$enable_lto" != "0" ] && $1 -dumpspecs | grep -q '\%{flto'; then
1389                         # Use LTO only if we see LTO exists and is requested
1390                         if [ $cc_version -lt 46 ]; then
1391                                 flags="$flags -flto"
1392                         else
1393                                 flags="$flags -flto=jobserver"
1394                         fi
1395                         ldflags="$ldflags -fwhole-program"
1396                         features="$features lto"
1397                 fi
1399                 if $1 -dumpspecs | grep -q rdynamic; then
1400                         # rdynamic is used to get useful stack traces from crash reports.
1401                         flags="$flags -rdynamic"
1402                         ldflags="$ldflags -rdynamic"
1403                 fi
1404         fi
1406         eval "$2=\"$flags\""
1407         eval "$3=\"$cxxflags\""
1408         eval "$4=\"$ldflags\""
1409         eval "$5=\"$features\""
1412 make_cflags_and_ldflags() {
1413         # General CFlags for BUILD
1414         CFLAGS_BUILD="$CFLAGS_BUILD"
1415         # Special CXXFlags for BUILD
1416         CXXFLAGS_BUILD="$CXXFLAGS_BUILD"
1417         # LDFLAGS for BUILD
1418         LDFLAGS_BUILD="$LDFLAGS_BUILD"
1419         # FEATURES for BUILD (lto)
1420         FEATURES_BUILD=""
1421         # General CFlags for HOST
1422         CFLAGS="$CFLAGS"
1423         # Special CXXFlags for HOST
1424         CXXFLAGS="$CXXFLAGS"
1425         # Libs to compile. In fact this is just LDFLAGS
1426         LIBS="-lstdc++"
1427         # LDFLAGS used for HOST
1428         LDFLAGS="$LDFLAGS"
1429         # FEATURES for HOST (lto)
1430         FEATURES=""
1432         make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "CXXFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
1433         make_compiler_cflags "$cc_host" "CFLAGS" "CXXFLAGS" "LDFLAGS" "FEATURES"
1435         CFLAGS="$CFLAGS -D$os"
1436         CFLAGS_BUILD="$CFLAGS_BUILD -D$os"
1438         if [ "$enable_debug" = "0" ]; then
1439                 # No debug, add default stuff
1440                 OBJS_SUBDIR="release"
1441                 if [ "$os" = "MORPHOS" ]; then
1442                         CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
1443                         LDFLAGS="$LDFLAGS -noixemul"
1444                 fi
1446                 if [ "$enable_profiling" = "0" ]; then
1447                         # -fomit-frame-pointer and -pg do not go well together (gcc errors they are incompatible)
1448                         CFLAGS="-fomit-frame-pointer $CFLAGS"
1449                 fi
1450                 CFLAGS="-O2 $CFLAGS"
1451         else
1452                 OBJS_SUBDIR="debug"
1454                 # Each debug level reduces the optimization by a bit
1455                 if [ $enable_debug -ge 1 ]; then
1456                         CFLAGS="$CFLAGS -g -D_DEBUG"
1457                         if [ "$os" = "PSP" ]; then
1458                                 CFLAGS="$CFLAGS -G0"
1459                         fi
1460                 fi
1461                 if [ $enable_debug -ge 2 ]; then
1462                         CFLAGS="$CFLAGS -fno-inline"
1463                 fi
1464                 if [ $enable_debug -ge 3 ]; then
1465                         CFLAGS="$CFLAGS -O0"
1466                 else
1467                         CFLAGS="$CFLAGS -O2"
1468                 fi
1469         fi
1471         if [ $enable_debug -le 2 ]; then
1472                 if basename "$cc_host" | grep -q "gcc"; then
1473                         # Define only when compiling with GCC. Some GLIBC versions use GNU
1474                         # extensions in a way that breaks build with at least ICC.
1475                         # This requires -O1 or more, so debug level 3 (-O0) is excluded.
1476                         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
1477                 fi
1479                 if basename "$cc_build" | grep -q "gcc"; then
1480                         # Just add -O1 to the tools needed for building.
1481                         CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
1482                 fi
1483         fi
1485         if [ "$os" = "OSX" ] && [ $cc_version -eq 40 ]; then
1486                 # Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
1487                 # wrongly optimizing ^= in loops. This disables the failing optimisation.
1488                 CFLAGS="$CFLAGS -fno-expensive-optimizations"
1489         fi
1491         if [ "$enable_profiling" != "0" ]; then
1492                 CFLAGS="$CFLAGS -pg"
1493                 LDFLAGS="$LDFLAGS -pg"
1494         fi
1496         if [ "$with_threads" = "0" ]; then
1497                 CFLAGS="$CFLAGS -DNO_THREADS"
1498         fi
1499         if [ "$with_sse" = "1" ]; then
1500                 CFLAGS="$CFLAGS -DWITH_SSE"
1501         fi
1503         if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
1504                 if [ "$os" = "CYGWIN" ]; then
1505                         flags="$flags -mwin32"
1506                         LDFLAGS="$LDFLAGS -mwin32"
1507                 fi
1508                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1509                         if [ $cc_version -lt 46 ]; then
1510                                 flags="$flags -mno-cygwin"
1511                                 LDFLAGS="$LDFLAGS -mno-cygwin"
1512                         fi
1514                         if [ "$enable_console" != "0" ]; then
1515                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
1516                         else
1517                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
1518                         fi
1520                         LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
1522                         if [ $cc_version -ge 44 ]; then
1523                                 LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
1524                         fi
1525                         if [ $cc_version -ge 47 ]; then
1526                                 CFLAGS="$CFLAGS -mno-ms-bitfields"
1527                         fi
1528                 fi
1529         fi
1531         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "FREEBSD" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
1532                 LIBS="$LIBS -lpthread"
1533         fi
1535         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "MINGW" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ]; then
1536                 LIBS="$LIBS -lc"
1537         fi
1538         if [ "$os" = "WINCE" ]; then
1539                 LIBS="$LIBS -lcoredll -lcorelibc -laygshell -lws2 -e WinMainCRTStartup"
1540         fi
1541         if [ "$os" = "PSP" ]; then
1542                 CFLAGS="$CFLAGS -I`$psp_config -p`/include"
1543                 LDFLAGS="$LDFLAGS -L`$psp_config -p`/lib"
1545                 CFLAGS="$CFLAGS -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150"
1546                 LIBS="$LIBS -D_PSP_FW_VERSION=150 -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lm"
1547         fi
1549         if [ "$os" = "MORPHOS" ]; then
1550                 # -Wstrict-prototypes generates much noise because of system headers
1551                 CFLAGS="$CFLAGS -Wno-strict-prototypes"
1552         fi
1554         if [ "$os" = "OPENBSD" ]; then
1555                 LIBS="$LIBS -pthread"
1556         fi
1558         if [ "$os" = "FREEBSD" ]; then
1559                 LIBS="$LIBS -lpthread"
1560         fi
1562         if [ "$os" = "OSX" ]; then
1563                 LDFLAGS="$LDFLAGS -framework Cocoa"
1565                 # Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
1566                 CFLAGS="$CFLAGS -isystem/opt/local/include"
1568                 if [ "$enable_dedicated" = "0" ] && ([ "$cpu_type" = "32" ] || [ "$enable_universal" != "0" ]); then
1569                         LIBS="$LIBS -framework QuickTime"
1570                 else
1571                         CFLAGS="$CFLAGS -DNO_QUICKTIME"
1572                 fi
1574                 if [ "$enable_universal" = "0" ]; then
1575                         # Universal builds set this elsewhere
1576                         CFLAGS="$OSX_SYSROOT $CFLAGS"
1577                         LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
1578                 fi
1580                 if [ "$enable_universal" = "0" ] && [ $cc_version -gt 40 ]; then
1581                         # Only set the min version when not doing an universal build.
1582                         # Universal builds set the version elsewhere.
1583                         if [ "$cpu_type" = "64" ]; then
1584                                 CFLAGS="$CFLAGS -mmacosx-version-min=10.5"
1585                         else
1586                                 gcc_cpu=`$cc_host -dumpmachine`
1587                                 if [ "`echo $gcc_cpu | cut -c 1-3`" = "ppc" -o "`echo $gcc_cpu | cut -c 1-7`" = "powerpc" ]; then
1588                                         # PowerPC build can run on 10.3
1589                                         CFLAGS="$CFLAGS -mmacosx-version-min=10.3"
1590                                 else
1591                                         # Intel is only available starting from 10.4
1592                                         CFLAGS="$CFLAGS -mmacosx-version-min=10.4"
1593                                 fi
1594                         fi
1595                 fi
1596         fi
1598         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ]; then
1599                 LIBS="$LIBS -lmidi -lbe"
1600         fi
1602         # Most targets act like UNIX, just with some additions
1603         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
1604                 CFLAGS="$CFLAGS -DUNIX"
1605         fi
1606         # And others like Windows
1607         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
1608                 CFLAGS="$CFLAGS -DWIN"
1609         fi
1611         if [ -n "$allegro_config" ]; then
1612                 CFLAGS="$CFLAGS -DWITH_ALLEGRO"
1613                 CFLAGS="$CFLAGS `$allegro_config --cflags`"
1614                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1615                         if [ "$enable_static" != "0" ]; then
1616                                 LIBS="$LIBS `$allegro_config --static --libs`"
1617                         else
1618                                 LIBS="$LIBS `$allegro_config --libs`"
1619                         fi
1620                 fi
1621         fi
1623         if [ -n "$sdl_config" ]; then
1624                 CFLAGS="$CFLAGS -DWITH_SDL"
1625                 # SDL must not add _GNU_SOURCE as it breaks many platforms
1626                 CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
1627                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1628                         if [ "$enable_static" != "0" ]; then
1629                                 LIBS="$LIBS `$sdl_config --static-libs`"
1630                         else
1631                                 LIBS="$LIBS `$sdl_config --libs`"
1632                         fi
1633                 fi
1634         fi
1636         if [ "$with_cocoa" != "0" ]; then
1637                 CFLAGS="$CFLAGS -DWITH_COCOA"
1638                 LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox"
1640                 if [ "$enable_cocoa_quartz" != "0" ]; then
1641                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUARTZ"
1642                 fi
1644                 if [ "$enable_cocoa_quickdraw" != "0" ]; then
1645                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUICKDRAW"
1646                 fi
1647         fi
1649         if [ "$with_zlib" != "0" ]; then
1650                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1651                         LIBS="$LIBS $zlib"
1652                 else
1653                         LIBS="$LIBS -lz"
1654                 fi
1655                 CFLAGS="$CFLAGS -DWITH_ZLIB"
1656         fi
1658         if [ -n "$lzma_config" ]; then
1659                 CFLAGS="$CFLAGS -DWITH_LZMA"
1660                 CFLAGS="$CFLAGS `$lzma_config --cflags | tr '\n\r' '  '`"
1662                 if [ "$enable_static" != "0" ]; then
1663                         CFLAGS="$CFLAGS -DLZMA_API_STATIC"
1664                         LIBS="$LIBS `$lzma_config --libs --static | tr '\n\r' '  '`"
1665                 else
1666                         LIBS="$LIBS `$lzma_config --libs | tr '\n\r' '  '`"
1667                 fi
1668         fi
1670         if [ "$with_lzo2" != "0" ]; then
1671                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1672                         LIBS="$LIBS $lzo2"
1673                 else
1674                         LIBS="$LIBS -llzo2"
1675                 fi
1676                 CFLAGS="$CFLAGS -DWITH_LZO"
1677         fi
1679         if [ -n "$xdg_basedir_config" ]; then
1680                 CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
1681                 CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
1683                 if [ "$enable_static" != "0" ]; then
1684                         LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
1685                 else
1686                         LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
1687                 fi
1688         fi
1690         # 64bit machines need -D_SQ64
1691         if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
1692                 CFLAGS="$CFLAGS -D_SQ64"
1693         fi
1694         CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
1696         if [ -n "$png_config" ]; then
1697                 CFLAGS="$CFLAGS -DWITH_PNG"
1698                 CFLAGS="$CFLAGS `$png_config --cflags | tr '\n\r' '  '`"
1700                 if [ "$enable_static" != "0" ]; then
1701                         if [ "$os" = "OSX" ]; then
1702                                 # png_config goes via pkg-config on all systems, which doesn't know --prefix
1703                                 # 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
1704                                 LIBS="$LIBS `$png_config --variable=prefix`/lib/libpng.a `$png_config --libs --static | sed s@-lpng[0-9]*@@`"
1705                         else
1706                                 LIBS="$LIBS `$png_config --libs --static | tr '\n\r' '  '`"
1707                         fi
1708                 else
1709                         LIBS="$LIBS `$png_config --libs | tr '\n\r' '  '`"
1710                 fi
1711         fi
1713         if [ -n "$fontconfig_config" ]; then
1714                 CFLAGS="$CFLAGS -DWITH_FONTCONFIG"
1715                 CFLAGS="$CFLAGS `$fontconfig_config --cflags | tr '\n\r' '  '`"
1717                 if [ "$enable_static" != "0" ]; then
1718                         if [ "$os" = "OSX" ]; then
1719                                 # fontconfig_config goes via pkg-config on all systems, which doesn't know --prefix
1720                                 # 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
1721                                 LIBS="$LIBS `$fontconfig_config --variable=prefix`/lib/libfontconfig.a `$fontconfig_config --libs --static | sed s@-lfontconfig@@`"
1722                         else
1723                                 LIBS="$LIBS `$fontconfig_config --libs --static | tr '\n\r' '  '`"
1724                         fi
1725                 else
1726                         LIBS="$LIBS `$fontconfig_config --libs | tr '\n\r' '  '`"
1727                 fi
1728         fi
1730         if [ -n "$freetype_config" ]; then
1731                 CFLAGS="$CFLAGS -DWITH_FREETYPE"
1732                 CFLAGS="$CFLAGS `$freetype_config --cflags | tr '\n\r' '  '`"
1734                 if [ "$enable_static" != "0" ]; then
1735                         if [ "$os" = "OSX" ]; then
1736                                 LIBS="$LIBS `$freetype_config --prefix`/lib/libfreetype.a"
1737                         else
1738                                 # Is it possible to do static with freetype, if so: how?
1739                                 LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1740                         fi
1741                 else
1742                         LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1743                 fi
1744         fi
1746         if [ -n "$icu_config" ]; then
1747                 CFLAGS="$CFLAGS -DWITH_ICU"
1748                 CFLAGS="$CFLAGS `$icu_config --cppflags | tr '\n\r' '  '`"
1750                 # Some icu-configs have the 'feature' of not adding a space where others do add the space
1751                 if [ "$static_icu" != "0" ]; then
1752                         LIBS="$LIBS `$icu_config --ldflags-searchpath` `($icu_config --ldflags-libsonly; $icu_config --ldflags-layout) | tr '\n\r' '  ' | sed s/licu/lsicu/g`"
1753                 else
1754                         LIBS="$LIBS `$icu_config --ldflags-searchpath` `($icu_config --ldflags-libsonly; $icu_config --ldflags-layout) | tr '\n\r' '  '`"
1755                 fi
1756         fi
1759         if [ "$with_direct_music" != "0" ]; then
1760                 CFLAGS="$CFLAGS -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT"
1761                 # GCC 4.0+ doesn't like the DirectX includes (gives tons of
1762                 #  warnings on it we won't be able to fix). For now just
1763                 #  suppress those warnings.
1764                 if [ $cc_version -ge 40 ]; then
1765                         CFLAGS="$CFLAGS -Wno-non-virtual-dtor"
1766                 fi
1767         fi
1769         if [ -n "$libtimidity" ]; then
1770                 if [ "$enable_static" != "0" ]; then
1771                         LIBS="$LIBS $libtimidity"
1772                 else
1773                         LIBS="$LIBS -ltimidity"
1774                 fi
1775                 CFLAGS="$CFLAGS -DLIBTIMIDITY"
1776         fi
1778         if [ "$with_iconv" != "0" ]; then
1779                 CFLAGS="$CFLAGS -DWITH_ICONV"
1780                 if [ "$link_to_iconv" = "yes" ]; then
1781                         LIBS="$LIBS -liconv"
1782                         if [ "$with_iconv" != "2" ]; then
1783                                 CFLAGS="$CFLAGS -I$with_iconv/include"
1784                                 LIBS="$LIBS -L$with_iconv/lib"
1785                         fi
1786                 fi
1788                 if [ "$os" != "OSX" ] && [ "$have_non_const_iconv" != "no" ]; then
1789                         CFLAGS="$CFLAGS -DHAVE_NON_CONST_ICONV"
1790                 fi
1791         fi
1793         if [ -n "$with_midi" ]; then
1794                 CFLAGS="$CFLAGS -DEXTERNAL_PLAYER=\\\\\"$with_midi\\\\\""
1795         fi
1796         if [ -n "$with_midi_arg" ]; then
1797                 CFLAGS="$CFLAGS -DMIDI_ARG=\\\\\"$with_midi_arg\\\\\""
1798         fi
1800         if [ "$enable_dedicated" != "0" ]; then
1801                 CFLAGS="$CFLAGS -DDEDICATED"
1802         fi
1804         if [ "$enable_unicode" != "0" ]; then
1805                 CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
1806         fi
1808         if [ "$enable_network" != "0" ]; then
1809                 CFLAGS="$CFLAGS -DENABLE_NETWORK"
1811                 if [ "$os" = "BEOS" ]; then
1812                         LDFLAGS="$LDFLAGS -lbind -lsocket"
1813                 fi
1815                 if [ "$os" = "HAIKU" ]; then
1816                         LDFLAGS="$LDFLAGS -lnetwork"
1817                 fi
1819                 if [ "$os" = "SUNOS" ]; then
1820                         LDFLAGS="$LDFLAGS -lnsl -lsocket"
1821                 fi
1822         fi
1824         if [ "$enable_static" != "0" ]; then
1825                 # OSX can't handle -static in LDFLAGS
1826                 if [ "$os" != "OSX" ]; then
1827                         LDFLAGS="$LDFLAGS -static"
1828                 fi
1829         fi
1831         if [ "$enable_assert" = "0" ]; then
1832                 CFLAGS="$CFLAGS -DNDEBUG"
1833                 CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
1834         fi
1836         if [ "$enable_desync_debug" != "0" ]; then
1837                 CFLAGS="$CFLAGS -DRANDOM_DEBUG"
1838         fi
1840         if [ "$enable_osx_g5" != "0" ]; then
1841                 CFLAGS="$CFLAGS -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
1842         fi
1844         if [ -n "$personal_dir" ]; then
1845                 CFLAGS="$CFLAGS -DWITH_PERSONAL_DIR -DPERSONAL_DIR=\\\\\"$personal_dir\\\\\""
1846         fi
1848         if [ -n "$shared_dir" ]; then
1849                 CFLAGS="$CFLAGS -DWITH_SHARED_DIR -DSHARED_DIR=\\\\\"$shared_dir\\\\\""
1850         fi
1852         CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
1854         if [ "$enable_lto" != "0" ]; then
1855                 lto_warn=1
1856                 if echo "$FEATURES_BUILD" | grep -q "lto"; then
1857                         LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
1858                         lto_warn=0
1859                 fi
1860                 if echo "$FEATURES" | grep -q "lto"; then
1861                         LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
1862                         lto_warn=0
1863                 fi
1864                 if [ "$lto_warn" != "0" ]; then
1865                         log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
1866                         log 1 "WARNING: LTO/IPO has been disabled"
1867                 fi
1868         fi
1870         log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD"
1871         log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD"
1872         log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD"
1873         log 1 "using CFLAGS... $CFLAGS"
1874         log 1 "using CXXFLAGS... $CXXFLAGS"
1875         log 1 "using LDFLAGS... $LIBS $LDFLAGS"
1877         # Makedepend doesn't like something like: -isysroot /OSX/blabla
1878         #  so convert it to: -isysroot -OSX/blabla. makedepend just ignores
1879         #  any - command it doesn't know, so we are pretty save.
1880         # Lovely hackish, not?
1881         # Btw, this almost always comes from outside the configure, so it is
1882         #  not something we can control.
1883         # Also make makedepend aware of compiler's built-in defines.
1884         if [ "$with_makedepend" != "0" ] || [ "$enable_builtin_depend" != "0" ]; then
1885                 # Append CXXFLAGS possibly containing -std=c++0x
1886                 cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
1888                 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
1889                 cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
1890         else
1891                 makedepend=""
1892         fi
1894         if [ "$with_distcc" != "0" ]; then
1895                 cc_host="$distcc $cc_host"
1896                 cxx_host="$distcc $cxx_host"
1897                 log 1 ""
1898                 log 1 " NOTICE: remind yourself to use 'make -jN' to make use of distcc"
1899                 log 1 ""
1900         fi
1902         if [ "$with_ccache" != "0" ]; then
1903                 cc_host="$ccache $cc_host"
1904                 cxx_host="$ccache $cxx_host"
1905         fi
1908 check_compiler() {
1909         # Params:
1910         # $1 - Type for message (build / host)
1911         # $2 - What to fill with the found compiler
1912         # $3 - System to try
1913         # $4 - Compiler to try
1914         # $5 - Env-setting to try
1915         # $6 - GCC alike to try
1916         # $7 - CC alike to try
1917         # $8 - "0" gcc, "1" g++, "2" windres, "3" strip, "4" lipo
1918         # $9 - What the command is to check for
1920         if [ -n "$3" ]; then
1921                 # Check for system
1922                 if [ -z "$6" ]; then
1923                         compiler="$3"
1924                 else
1925                         compiler="$3-$6"
1926                 fi
1927                 machine=`eval $compiler $9 2>/dev/null`
1928                 ret=$?
1929                 eval "$2=\"$compiler\""
1931                 log 2 "executing $compiler $9"
1932                 log 2 "  returned $machine"
1933                 log 2 "  exit code $ret"
1935                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1936                         log 1 "checking $1... $compiler not found"
1937                         log 1 "I couldn't detect any $6 binary for $3"
1938                         exit 1
1939                 fi
1941                 if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
1942                         log 1 "checking $1... expected $3, found $machine"
1943                         log 1 "the compiler suggests it doesn't build code for the machine you specified"
1944                         exit 1
1945                 fi
1946         elif [ -n "$4" ]; then
1947                 # Check for manual compiler
1948                 machine=`$4 $9 2>/dev/null`
1949                 ret=$?
1950                 eval "$2=\"$4\""
1952                 log 2 "executing $4 $9"
1953                 log 2 "  returned $machine"
1954                 log 2 "  exit code $ret"
1956                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1957                         log 1 "checking $1... $4 not found"
1958                         log 1 "the selected binary doesn't seem to be a $6 binary"
1959                         exit 1
1960                 fi
1961         else
1962                 # Nothing given, autodetect
1964                 if [ -n "$5" ]; then
1965                         machine=`$5 $9 2>/dev/null`
1966                         ret=$?
1967                         eval "$2=\"$5\""
1969                         log 2 "executing $5 $9"
1970                         log 2 "  returned $machine"
1971                         log 2 "  exit code $ret"
1973                         # The user defined a GCC that doesn't reply to $9.. abort
1974                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1975                                 log 1 "checking $1... $5 unusable"
1976                                 log 1 "the CC environment variable is set, but it doesn't seem to be a $6 binary"
1977                                 log 1 "please redefine the CC/CXX environment to a $6 binary"
1978                                 exit 1
1979                         fi
1980                 else
1981                         log 2 "checking $1... CC/CXX not set (skipping)"
1983                         # No $5, so try '$6'
1984                         machine=`$6 $9 2>/dev/null`
1985                         ret=$?
1986                         eval "$2=\"$6\""
1988                         log 2 "executing $6 $9"
1989                         log 2 "  returned $machine"
1990                         log 2 "  exit code $ret"
1992                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1993                                 # Maybe '$7'?
1994                                 machine=`$7 $9 2>/dev/null`
1995                                 ret=$?
1996                                 eval "$2=\"$7\""
1998                                 log 2 "executing $7 $9"
1999                                 log 2 "  returned $machine"
2000                                 log 2 "  exit code $ret"
2002                                 # All failed, abort
2003                                 if [ -z "$machine" ]; then
2004                                         log 1 "checking $1... $6 not found"
2005                                         log 1 "I couldn't detect any $6 binary on your system"
2006                                         log 1 "please define the CC/CXX environment to where it is located"
2008                                         exit 1
2009                                 fi
2010                         fi
2011                 fi
2012         fi
2014         if [ "$8" != "0" ]; then
2015                 eval "res=\$$2"
2016                 log 1 "checking $1... $res"
2017         else
2018                 log 1 "checking $1... $machine"
2019         fi
2022 check_build() {
2023         if [ "$os" = "FREEBSD" ]; then
2024                 # FreeBSD's C compiler does not support dump machine.
2025                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2026                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CXX" "g++" "c++" "0" "-dumpmachine"
2027         else
2028                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CC" "gcc" "cc" "0" "-dumpmachine"
2029         fi
2032 check_host() {
2033         # By default the host is the build
2034         if [ -z "$host" ]; then host="$build"; fi
2036         if [ "$os" = "FREEBSD" ]; then
2037                 # FreeBSD's C compiler does not support dump machine.
2038                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2039                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CXX" "g++" "c++" "0" "-dumpmachine"
2040         else
2041                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
2042         fi
2045 check_cxx_build() {
2046         check_compiler "build c++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
2049 check_cxx_host() {
2050         # By default the host is the build
2051         if [ -z "$host" ]; then host="$build"; fi
2052         check_compiler "host c++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
2055 check_windres() {
2056         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2057                 check_compiler "host windres" "windres" "$host" "$windres" "$WINDRES" "windres" "windres" "2" "-V"
2058         fi
2061 check_strip() {
2062         if [ "$os" = "OS2" ]; then
2063                 # OS2 via gcc is a bit weird.. stripping HAS to be done via emxbind, which is via gcc directly
2064                 log 1 "checking host strip... using gcc -s option"
2065         elif [ "$os" = "OSX" ]; then
2066                 # Most targets have -V in strip, to see if they exists... OSX doesn't.. so execute something
2067                 echo "int main(int argc, char *argv[]) { }" > strip.test.c
2068                 $cxx_host strip.test.c -o strip.test
2069                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "strip.test"
2070                 rm -f strip.test.c strip.test
2071         else
2072                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "-V"
2073         fi
2076 check_lipo() {
2077         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
2078                 echo "int main(int argc, char *argv[]) { }" > lipo.test.c
2079                 $cxx_host lipo.test.c -o lipo.test
2080                 check_compiler "host lipo" "lipo" "$host" "$lipo" "$LIPO" "lipo" "lipo" "4" "-info lipo.test"
2081                 rm -f lipo.test.c lipo.test
2082         fi
2085 check_osx_sdk() {
2086         local sysroot=""
2087         if [ -n "$1" ]; then
2088                 if echo "$1" | grep -q / ; then
2089                         # Seems to be a file system path
2090                         osx_sdk_path="$1"
2091                 else
2092                         osx_sdk_path="/Developer/SDKs/MacOSX$1.sdk"
2093                 fi
2094                 if [ ! -d "$osx_sdk_path" ]; then
2095                         # No directory, not present or garbage
2096                         return 1
2097                 fi
2099                 # Set minimum version to 10.4 as that's when kCGBitmapByteOrder32Host was introduced
2100                 sysroot="-isysroot $osx_sdk_path -Wl,-syslibroot,$osx_sdk_path -mmacosx-version-min=10.4"
2101         fi
2103 cat > tmp.osx.mm << EOF
2104 #include <Cocoa/Cocoa.h>
2105 int main() {
2106         kCGBitmapByteOrder32Host;
2107         return 0;
2110         execute="$cxx_host $sysroot $CFLAGS tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2111         eval $execute > /dev/null
2112         ret=$?
2113         log 2 "executing $execute"
2114         log 2 "  exit code $ret"
2115         rm -f tmp.osx.mm tmp.osx
2116         return $ret
2119 check_direct_music() {
2120         echo "
2121                 #include <windows.h>
2122                 #include <dmksctrl.h>
2123                 #include <dmusici.h>
2124                 #include <dmusicc.h>
2125                 #include <dmusicf.h>
2126                 int main(int argc, char *argv[]) { }" > direct_music.test.c
2127         $cxx_host $CFLAGS direct_music.test.c -o direct_music.test 2> /dev/null
2128         res=$?
2129         rm -f direct_music.test.c direct_music.test
2131         if [ "$res" != "0" ]; then
2132                 if [ "$with_direct_music" != "1" ]; then
2133                         log 1 "configure: error: direct-music is not available on this system"
2134                         exit 1
2135                 fi
2136                 with_direct_music="0"
2138                 log 1 "checking direct-music... not found"
2139         else
2140                 log 1 "checking direct-music... found"
2141         fi
2144 check_makedepend() {
2145         if [ "$enable_builtin_depend" != "0" ]; then
2146                 with_makedepend="0"
2147         fi
2149         if [ "$with_makedepend" = "0" ]; then
2150                 log 1 "checking makedepend... disabled"
2151                 return
2152         fi
2154         if [ "$with_makedepend" = "1" ] || [ "$with_makedepend" = "2" ]; then
2155                 makedepend="makedepend"
2156         else
2157                 makedepend="$with_makedepend"
2158         fi
2160         rm -f makedepend.tmp
2161         touch makedepend.tmp
2162         res=`$makedepend -fmakedepend.tmp 2>/dev/null`
2163         res=$?
2164         log 2 "executing $makedepend -f makedepend.tmp"
2165         log 2 "  returned `cat makedepend.tmp`"
2166         log 2 "  exit code $ret"
2168         if [ ! -s makedepend.tmp ]; then
2169                 rm -f makedepend.tmp makedepend.tmp.bak
2171                 if [ "$with_makedepend" = "2" ]; then
2172                         log 1 "checking makedepend... not found"
2174                         log 1 "I couldn't detect any makedepend on your system"
2175                         log 1 "please locate it via --makedepend=[binary]"
2177                         exit 1
2178                 elif [ "$with_makedepend" != "1" ]; then
2179                         log 1 "checking makedepend... $makedepend not found"
2181                         log 1 "the selected file doesn't seem to be a valid makedepend binary"
2183                         exit 1
2184                 else
2185                         log 1 "checking makedepend... not found"
2187                         with_makedepend="0"
2188                         return
2189                 fi
2190         fi
2192         rm -f makedepend.tmp makedepend.tmp.bak
2194         log 1 "checking makedepend... $makedepend"
2197 check_version() {
2198         # $1 - requested version (major.minor)
2199         # $2 - version we got (major.minor)
2201         if [ -z "$2" ]; then
2202                 return 0
2203         fi
2205         req_major=`echo $1 | cut -d. -f1`
2206         got_major=`echo $2 | cut -d. -f1`
2207         if [ $got_major -lt $req_major ]; then
2208                 return 0
2209         elif [ $got_major -gt $req_major ]; then
2210                 return 1
2211         fi
2213         req_minor=`echo $1 | cut -d. -f2`
2214         got_minor=`echo $2 | cut -d. -f2`
2215         if [ $got_minor -lt $req_minor ]; then
2216                 return 0
2217         fi
2218         return 1
2221 detect_awk() {
2222         # Not all awks allow gsub(), so we test for that here! It is in fact all we need...
2224         # These awks are known to work. Test for them explicit
2225         awks="gawk mawk nawk"
2227         awk_prefix="echo \"a.c b.c c.c\" | tr ' ' \\\\n | "
2228         awk_param="' { ORS = \" \" } /\.c$/   { gsub(\".c$\",   \".o\", \$0); print \$0; }' 2>/dev/null"
2229         awk_result="a.o b.o c.o "
2230         log 2 "Detecing awk..."
2232         log 2 "Trying: $awk_prefix $awk $awk_param"
2233         res=`eval $awk_prefix $awk $awk_param`
2234         log 2 "Result: '$res'"
2235         if [ "$res" != "$awk_result" ] && [ "$awk" = "awk" ]; then
2236                 # User didn't supply his own awk, so try to detect some other known working names for an awk
2237                 for awk in $awks; do
2238                         log 2 "Trying: $awk_prefix $awk $awk_param"
2239                         res=`eval $awk_prefix $awk $awk_param`
2240                         log 2 "Result: '$res'"
2241                         if [ "$res" = "$awk_result" ]; then break; fi
2242                 done
2244                 if [ "$res" != "$awk_result" ]; then
2245                         log 1 "checking awk... not found"
2246                         log 1 "configure: error: no awk found"
2247                         log 1 "configure: error: please install one of the following: $awks"
2248                         exit 1
2249                 fi
2250         fi
2251         if [ "$res" != "$awk_result" ]; then
2252                 log 1 "checking awk... not found"
2253                 log 1 "configure: error: you supplied '$awk' but it doesn't seem a valid gawk or mawk"
2254                 exit 1
2255         fi
2257         log 1 "checking awk... $awk"
2260 detect_os() {
2261         if [ "$os" = "DETECT" ]; then
2262                 # Detect UNIX, OSX, FREEBSD, OPENBSD, NETBSD, HPUX, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
2264                 # Try first via dumpmachine, then via uname
2265                 os=`echo "$host" | tr '[A-Z]' '[a-z]' | $awk '
2266                                         /linux/        { print "UNIX";    exit}
2267                                         /darwin/       { print "OSX";     exit}
2268                                         /freebsd/      { print "FREEBSD"; exit}
2269                                         /openbsd/      { print "OPENBSD"; exit}
2270                                         /netbsd/       { print "NETBSD";  exit}
2271                                         /hp-ux/        { print "HPUX";    exit}
2272                                         /morphos/      { print "MORPHOS"; exit}
2273                                         /beos/         { print "BEOS";    exit}
2274                                         /haiku/        { print "HAIKU";   exit}
2275                                         /sunos/        { print "SUNOS";   exit}
2276                                         /solaris/      { print "SUNOS";   exit}
2277                                         /cygwin/       { print "CYGWIN";  exit}
2278                                         /mingw/        { print "MINGW";   exit}
2279                                         /os2/          { print "OS2";     exit}
2280                                         /dos/          { print "DOS";     exit}
2281                                         /wince/        { print "WINCE";   exit}
2282                                         /psp/          { print "PSP";     exit}
2283                 '`
2285                 if [ -z "$os" ]; then
2286                         os=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | $awk '
2287                                         /linux/        { print "UNIX";    exit}
2288                                         /darwin/       { print "OSX";     exit}
2289                                         /freebsd/      { print "FREEBSD"; exit}
2290                                         /openbsd/      { print "OPENBSD"; exit}
2291                                         /netbsd/       { print "NETBSD";  exit}
2292                                         /hp-ux/        { print "HPUX";    exit}
2293                                         /morphos/      { print "MORPHOS"; exit}
2294                                         /beos/         { print "BEOS";    exit}
2295                                         /haiku/        { print "HAIKU";   exit}
2296                                         /sunos/        { print "SUNOS";   exit}
2297                                         /cygwin/       { print "CYGWIN";  exit}
2298                                         /mingw/        { print "MINGW";   exit}
2299                                         /os\/2/        { print "OS2";     exit}
2300                                         /gnu/          { print "UNIX";    exit}
2301                         '`
2302                 fi
2304                 if [ -z "$os" ]; then
2305                         log 1 "detecting OS... none detected"
2306                         log 1 "I couldn't detect your OS. Please use --os=OS to force one"
2307                         log 1 "Allowed values are: UNIX, OSX, FREEBSD, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP"
2308                         exit 1
2309                 fi
2311                 log 1 "detecting OS... $os"
2312         else
2313                 log 1 "forcing OS... $os"
2314         fi
2317 detect_allegro() {
2318         # 0 means no, 1 is auto-detect, 2 is force
2319         if [ "$with_allegro" = "0" ]; then
2320                 log 1 "checking Allegro... disabled"
2322                 allegro_config=""
2323                 return 0
2324         fi
2326         if [ "$with_allegro" = "2" ] && [ "$with_cocoa" = "2" ]; then
2327                 log 1 "configure: error: it is impossible to compile both Allegro and COCOA"
2328                 log 1 "configure: error: please deselect one of them and try again"
2329                 exit 1
2330         fi
2332         if [ "$with_allegro" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2333                 log 1 "configure: error: it is impossible to compile a dedicated with Allegro"
2334                 log 1 "configure: error: please deselect one of them and try again"
2335                 exit 1
2336         fi
2338         if [ "$enable_dedicated" != "0" ]; then
2339                 log 1 "checking Allegro... dedicated server, skipping"
2341                 allegro_config=""
2342                 return 0
2343         fi
2345         # By default on OSX we don't use SDL. The rest is auto-detect
2346         if [ "$with_allegro" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2347                 log 1 "checking Allegro... OSX, skipping"
2349                 allegro_config=""
2350                 return 0
2351         fi
2353         if [ "$with_allegro" = "1" ] || [ "$with_allegro" = "" ] || [ "$with_allegro" = "2" ]; then
2354                 allegro_config="allegro-config"
2355         else
2356                 allegro_config="$with_allegro"
2357         fi
2359         version=`$allegro_config --version 2>/dev/null`
2360         ret=$?
2361         log 2 "executing $allegro_config --version"
2362         log 2 "  returned $version"
2363         log 2 "  exit code $ret"
2365         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2366                 log 1 "checking Allegro... not found"
2368                 # It was forced, so it should be found.
2369                 if [ "$with_allegro" != "1" ]; then
2370                         log 1 "configure: error: allegro-config couldn't be found"
2371                         log 1 "configure: error: you supplied '$with_allegro', but it seems invalid"
2372                         exit 1
2373                 fi
2375                 allegro_config=""
2376                 return 0
2377         fi
2379         log 1 "checking Allegro... found"
2383 detect_sdl() {
2384         # 0 means no, 1 is auto-detect, 2 is force
2385         if [ "$with_sdl" = "0" ]; then
2386                 log 1 "checking SDL... disabled"
2388                 sdl_config=""
2389                 return 0
2390         fi
2392         if [ "$with_sdl" = "2" ] && [ "$with_cocoa" = "2" ]; then
2393                 log 1 "configure: error: it is impossible to compile both SDL and COCOA"
2394                 log 1 "configure: error: please deselect one of them and try again"
2395                 exit 1
2396         fi
2398         if [ "$with_sdl" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2399                 log 1 "configure: error: it is impossible to compile a dedicated with SDL"
2400                 log 1 "configure: error: please deselect one of them and try again"
2401                 exit 1
2402         fi
2404         if [ "$enable_dedicated" != "0" ]; then
2405                 log 1 "checking SDL... dedicated server, skipping"
2407                 sdl_config=""
2408                 return 0
2409         fi
2411         # By default on OSX we don't use SDL. The rest is auto-detect
2412         if [ "$with_sdl" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2413                 log 1 "checking SDL... OSX, skipping"
2415                 sdl_config=""
2416                 return 0
2417         fi
2419         if [ "$os" = "OSX" ]; then
2420                 log 1 "WARNING: sdl is known to fail on some versions of Mac OS X"
2421                 log 1 "WARNING: with some hardware configurations. Use at own risk!"
2422                 sleep 5
2423         fi
2425         if [ "$with_sdl" = "1" ] || [ "$with_sdl" = "" ] || [ "$with_sdl" = "2" ]; then
2426                 sdl_config="sdl-config"
2427         else
2428                 sdl_config="$with_sdl"
2429         fi
2431         version=`$sdl_config --version 2>/dev/null`
2432         ret=$?
2433         log 2 "executing $sdl_config --version"
2434         log 2 "  returned $version"
2435         log 2 "  exit code $ret"
2437         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2438                 log 1 "checking SDL... not found"
2440                 # It was forced, so it should be found.
2441                 if [ "$with_sdl" != "1" ]; then
2442                         log 1 "configure: error: sdl-config couldn't be found"
2443                         log 1 "configure: error: you supplied '$with_sdl', but it seems invalid"
2444                         exit 1
2445                 fi
2447                 sdl_config=""
2448                 return 0
2449         fi
2451         log 1 "checking SDL... found"
2454 detect_osx_sdk() {
2455         # Try to find the best SDK available. For a normal build this
2456         # is currently the 10.5 SDK as this is needed to compile all
2457         # optional code. Because such an executable won't run on 10.4
2458         # or lower, also check for the 10.4u SDK when doing an universal
2459         # build.
2461         # Check for the 10.5 SDK, but try 10.6 if that fails
2462         check_osx_sdk "10.5" || check_osx_sdk "10.6" || osx_sdk_path=""
2464         if [ -z "$osx_sdk_path" ] || [ "$enable_universal" != "0" ]; then
2465                 # No better SDK or universal build enabled? Check 10.4u SDK as well
2466                 local old_sdk="$osx_sdk_path"
2467                 if check_osx_sdk "10.4u"; then
2468                         osx_sdk_104_path="$osx_sdk_path"
2469                 else
2470                         osx_sdk_104_path=""
2471                 fi
2472                 if [ -z "$old_sdk" ]; then
2473                         osx_sdk_path="$osx_sdk_104_path"
2474                 else
2475                         osx_sdk_path="$old_sdk"
2476                 fi
2477         fi
2479         if [ -z "$osx_sdk_path" ]; then
2480                 log 1 "Your system SDK is probably too old"
2481                 log 1 "Please install/upgrade your Xcode to >= 2.5"
2483                 exit 1
2484         fi
2487 detect_cocoa() {
2488         # 0 means no, 1 is auto-detect, 2 is force
2489         if [ "$with_cocoa" = "0" ]; then
2490                 log 1 "checking COCOA... disabled"
2492                 return 0
2493         fi
2495         if [ "$with_cocoa" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2496                 log 1 "configure: error: it is impossible to compile a dedicated with COCOA"
2497                 log 1 "configure: error: please deselect one of them and try again"
2498                 exit 1
2499         fi
2501         if [ "$enable_dedicated" != "0" ]; then
2502                 log 1 "checking COCOA... dedicated server, skipping"
2504                 with_cocoa="0"
2505                 return 0
2506         fi
2508         # By default on OSX we use COCOA. The rest doesn't support it
2509         if [ "$with_cocoa" = "1" ] && [ "$os" != "OSX" ]; then
2510                 log 1 "checking COCOA... not OSX, skipping"
2512                 with_cocoa="0"
2513                 return 0
2514         fi
2516         if [ "$os" != "OSX" ]; then
2517                 log 1 "checking COCOA... not OSX"
2519                 log 1 "configure: error: COCOA video driver is only supported for OSX"
2520                 exit 1
2521         fi
2523         log 1 "checking COCOA... found"
2526         if [ "$enable_cocoa_quartz" != "0" ]; then
2527                 log 1 "checking whether to enable the Quartz window subdriver... yes"
2528         else
2529                 log 1 "checking whether to enable the Quartz window subdriver... no"
2530         fi
2532         detect_quickdraw
2535 detect_quickdraw() {
2536         # 0 means no, 1 is auto-detect, 2 is force
2537         if [ "$enable_cocoa_quickdraw" = "0" ]; then
2538                 log 1 "checking Quickdraw window subdriver... disabled"
2539                 return 0
2540         fi
2542         # Assume QuickDraw is available when doing an universal build
2543         if [ "$enable_universal" != "0" ]; then
2544                 log 1 "checking Quickdraw window subdriver... found"
2545                 return 0
2546         fi
2548         # 64 bits doesn't have quickdraw
2549         if [ "$cpu_type" = "64" ]; then
2550                 enable_cocoa_quickdraw="0"
2551                 log 1 "checking Quickdraw window subdriver... disabled (64 bits)"
2552                 return 0
2553         fi
2555 cat > tmp.osx.mm << EOF
2556 #include <AvailabilityMacros.h>
2557 #import <Cocoa/Cocoa.h>
2558 int main(int argc, char *argv[]) { SetEmptyRgn(NULL); return 0; }
2560         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS -mmacosx-version-min=10.3 tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2561         eval $execute > /dev/null
2562         ret=$?
2563         log 2 "executing $execute"
2564         log 2 "  exit code $ret"
2565         rm -f tmp.osx.mm tmp.osx
2566         if [ "$ret" != "0" ]; then
2567                 log 1 "checking Quickdraw window subdriver... not found"
2569                 # It was forced, so it should be found.
2570                 if [ "$enable_cocoa_quickdraw" != "1" ]; then
2571                         log 1 "configure: error: Quickdraw window driver could not be found"
2572                         exit 1
2573                 fi
2575                 enable_cocoa_quickdraw=0
2576                 return 0
2577         fi
2579         enable_cocoa_quickdraw=1
2580         log 1 "checking Quickdraw window subdriver... found"
2583 detect_library() {
2584         # $1 - config-param ($with_zlib value)
2585         # $2 - library name ('zlib', sets $zlib)
2586         # $3 - static library name (libz.a)
2587         # $4 - header directory ()
2588         # $5 - header name (zlib.h)
2589         # $6 - force static (if non-empty)
2591         if [ -n "$6" ]; then force_static="1"; fi
2593         # 0 means no, 1 is auto-detect, 2 is force
2594         if [ "$1" = "0" ]; then
2595                 log 1 "checking $2... disabled"
2597                 eval "$2=\"\""
2598                 return 0
2599         fi
2601         log 2 "detecting $2"
2603         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2604                 eval "$2=`ls -1 /usr/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2605                 eval "res=\$$2"
2606                 if [ -z "$res" ]; then
2607                         log 2 "  trying /usr/include/$4$5... no"
2608                         eval "$2=`ls -1 /usr/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2609                 fi
2610                 eval "res=\$$2"
2611                 if [ -z "$res" ]; then
2612                         log 2 "  trying /usr/local/include/$4$5... no"
2613                         eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2614                 fi
2615                 eval "res=\$$2"
2616                 if [ -z "$res" ]; then
2617                         log 2 "  trying /mingw/include/$4$5... no"
2618                         eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2619                 fi
2620                 eval "res=\$$2"
2621                 if [ -z "$res" ]; then
2622                         log 2 "  trying /opt/local/include/$4$5... no"
2623                 fi
2624                 if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then
2625                         eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2626                         eval "res=\$$2"
2627                         if [ -z "$res" ]; then
2628                                 log 2 "  trying /usr/pkg/include/$4$5... no"
2629                         fi
2630                 fi
2631                 if [ -z "$res" ] && [ "$os" = "HAIKU" ]; then
2632                         eval "$2=`ls -1 /boot/common/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2633                         eval "res=\$$2"
2634                         if [ -z "$res" ]; then
2635                                 log 2 "  trying /boot/common/include/$4$5... no"
2636                         fi
2637                 fi
2639                 eval "res=\$$2"
2640                 if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then
2641                         eval "res=\$$2"
2642                         log 2 "  trying $res... found"
2643                         # Now find the static lib, if needed
2644                         eval "$2=`ls /lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2645                         eval "res=\$$2"
2646                         if [ -z "$res" ]; then
2647                                 log 2 "  trying /lib/$3... no"
2648                                 eval "$2=`ls /usr/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2649                         fi
2650                         eval "res=\$$2"
2651                         if [ -z "$res" ]; then
2652                                 log 2 "  trying /usr/lib/$3... no"
2653                                 eval "$2=`ls /usr/local/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2654                         fi
2655                         eval "res=\$$2"
2656                         if [ -z "$res" ]; then
2657                                 log 2 "  trying /usr/local/lib/$3... no"
2658                                 eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2659                         fi
2660                         eval "res=\$$2"
2661                         if [ -z "$res" ]; then
2662                                 log 2 "  trying /mingw/lib/$3... no"
2663                                 log 1 "configure: error: $2 couldn't be found"
2664                                 log 1 "configure: error: you requested a static link, but I can't find $3"
2666                                 exit 1
2667                         fi
2668                 fi
2669         else
2670                 # Make sure it exists
2671                 if [ -f "$1" ]; then
2672                         eval "$2=`ls $1 2>/dev/null`"
2673                 else
2674                         eval "$2=`ls $1/$3 2>/dev/null`"
2675                 fi
2676         fi
2678         eval "res=\$$2"
2679         if [ -z "$res" ]; then
2680                 log 1 "checking $2... not found"
2681                 if [ "$1" = "2" ]; then
2682                         log 1 "configure: error: $2 couldn't be found"
2684                         exit 1
2685                 elif [ "$1" != "1" ]; then
2686                         log 1 "configure: error: $2 couldn't be found"
2687                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2689                         exit 1
2690                 fi
2692                 eval "with_$2=0"
2694                 return 0
2695         fi
2697         eval "res=\$$2"
2698         log 2 "  trying $res... found"
2700         log 1 "checking $2... found"
2703 detect_zlib() {
2704         detect_library "$with_zlib" "zlib" "libz.a" "" "zlib.h"
2707 detect_lzo2() {
2708         detect_library "$with_lzo2" "lzo2" "liblzo2.a" "lzo/" "lzo1x.h"
2711 detect_libtimidity() {
2712         detect_library "$with_libtimidity" "libtimidity" "libtimidity.a" "" "timidity.h"
2715 detect_pkg_config() {
2716         # $1 - config-param ($with_lzma value)
2717         # $2 - package name ('liblzma')
2718         # $3 - config name ('lzma_config', sets $lzma_config)
2719         # $4 - minimum module version ('2.3')
2721         # 0 means no, 1 is auto-detect, 2 is force
2722         if [ "$1" = "0" ]; then
2723                 log 1 "checking $2... disabled"
2725                 eval "$3=\"\""
2726                 return 0
2727         fi
2729         log 2 "detecting $2"
2731         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2732                 pkg_config_call="pkg-config $2"
2733         else
2734                 pkg_config_call="$1"
2735         fi
2737         version=`$pkg_config_call --modversion 2>/dev/null`
2738         ret=$?
2739         check_version "$4" "$version"
2740         version_ok=$?
2741         log 2 "executing $pkg_config_call --modversion"
2742         log 2 "  returned $version"
2743         log 2 "  exit code $ret"
2745         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2746                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2747                         log 1 "checking $2... needs at least version $4, $2 NOT enabled"
2748                 else
2749                         log 1 "checking $2... not found"
2750                 fi
2752                 # It was forced, so it should be found.
2753                 if [ "$1" != "1" ]; then
2754                         log 1 "configure: error: pkg-config $2 couldn't be found"
2755                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2756                         exit 1
2757                 fi
2759                 eval "$3=\"\""
2760                 return 0
2761         fi
2763         eval "$3=\"$pkg_config_call\""
2764         log 1 "checking $2... found"
2767 detect_lzma() {
2768         detect_pkg_config "$with_lzma" "liblzma" "lzma_config" "5.0"
2771 detect_xdg_basedir() {
2772         detect_pkg_config "$with_xdg_basedir" "libxdg-basedir" "xdg_basedir_config" "1.2"
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         detect_pkg_config "$with_png" "libpng" "png_config" "1.2"
2802 detect_freetype() {
2803         # 0 means no, 1 is auto-detect, 2 is force
2804         if [ "$with_freetype" = "0" ]; then
2805                 log 1 "checking libfreetype... disabled"
2807                 freetype_config=""
2808                 return 0
2809         fi
2810         if [ "$with_freetype" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2811                 log 1 "checking libfreetype... dedicated server, skipping"
2813                 freetype_config=""
2814                 return 0
2815         fi
2817         if [ "$with_zlib" = "0" ] || [ -z "$zlib" ]; then
2818                 if [ "$with_freetype" != "1" ]; then
2819                         log 1 "checking libfreetype... no zlib"
2820                         log 1 "ERROR: libfreetype was forced, but zlib was not detected / disabled."
2821                         log 1 "ERROR: libfreetype depends on zlib."
2823                         exit 1
2824                 fi
2826                 log 1 "checking libfreetype... no zlib, skipping"
2828                 freetype_config=""
2829                 return 0
2830         fi
2832         if [ "$with_freetype" = "1" ] || [ "$with_freetype" = "" ] || [ "$with_freetype" = "2" ]; then
2833                 freetype_config="freetype-config"
2834         else
2835                 freetype_config="$with_freetype"
2836         fi
2838         version=`$freetype_config --version 2>/dev/null`
2839         ret=$?
2840         log 2 "executing freetype_config --version"
2841         log 2 "  returned $version"
2842         log 2 "  exit code $ret"
2844         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2845                 log 1 "checking libfreetype... not found"
2847                 # It was forced, so it should be found.
2848                 if [ "$with_freetype" != "1" ]; then
2849                         log 1 "configure: error: freetype-config couldn't be found"
2850                         log 1 "configure: error: you supplied '$with_freetype', but it seems invalid"
2851                         exit 1
2852                 fi
2854                 freetype_config=""
2855                 return 0
2856         fi
2858         log 1 "checking libfreetype... found"
2861 detect_fontconfig() {
2862         # 0 means no, 1 is auto-detect, 2 is force
2863         if [ "$with_fontconfig" = "0" ]; then
2864                 log 1 "checking libfontconfig... disabled"
2866                 fontconfig_config=""
2867                 return 0
2868         fi
2869         if [ "$with_fontconfig" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2870                 log 1 "checking libfontconfig... dedicated server, skipping"
2872                 fontconfig_config=""
2873                 return 0
2874         fi
2875         if [ "$with_fontconfig" != "2" ] && [ -z "$freetype_config" ]; then
2876                 log 1 "checking libfontconfig... no freetype, skipping"
2878                 fontconfig_config=""
2879                 return 0
2880         fi
2882         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2883                 log 1 "checking libfontconfig... WIN32, skipping"
2884                 fontconfig_config=""
2885                 return 0
2886         fi
2888         if [ "$os" = "OSX" ]; then
2889                 log 1 "checking libfontconfig... OSX, skipping"
2890                 fontconfig_config=""
2891                 return 0
2892         fi
2894         detect_pkg_config "$with_fontconfig" "fontconfig" "fontconfig_config" "2.3"
2897 detect_icu() {
2898         # 0 means no, 1 is auto-detect, 2 is force
2899         if [ "$with_icu" = "0" ]; then
2900                 log 1 "checking libicu... disabled"
2902                 icu_config=""
2903                 return 0
2904         fi
2905         if [ "$with_icu" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2906                 log 1 "checking libicu... dedicated server, skipping"
2908                 icu_config=""
2909                 return 0
2910         fi
2912         if [ "$with_icu" = "1" ] || [ "$with_icu" = "" ] || [ "$with_icu" = "2" ]; then
2913                 icu_config="icu-config"
2914         else
2915                 icu_config="$with_icu"
2916         fi
2918         version=`$icu_config --version 2>/dev/null`
2919         ret=$?
2920         check_version '3.6' "$version"
2921         version_ok=$?
2922         log 2 "executing $icu_config --version"
2923         log 2 "  returned $version"
2924         log 2 "  exit code $ret"
2926         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2927                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2928                         log 1 "checking libicu... needs at least version 3.6.0, icu NOT enabled"
2929                 else
2930                         log 1 "checking libicu... not found"
2931                 fi
2933                 # It was forced, so it should be found.
2934                 if [ "$with_icu" != "1" ]; then
2935                         log 1 "configure: error: icu-config couldn't be found"
2936                         log 1 "configure: error: you supplied '$with_icuconfig', but it seems invalid"
2937                         exit 1
2938                 fi
2940                 icu_config=""
2941                 return 0
2942         fi
2944         log 1 "checking libicu... found"
2947 detect_pspconfig() {
2948         # 0 means no, 1 is auto-detect, 2 is force
2949         if [ "$with_psp_config" = "0" ]; then
2950                 log 1 "checking psp-config... disabled"
2952                 psp_config=""
2953                 return 0
2954         fi
2956         if [ "$with_psp_config" = "1" ] && [ "$os" != "PSP" ]; then
2957                 log 1 "checking psp-config... not PSP, skipping"
2959                 psp_config="";
2960                 return 0
2961         fi
2963         if [ "$os" != "PSP" ]; then
2964                 log 1 "checking psp-config... not PSP"
2966                 log 1 "configure: error: psp-config is only supported for PSP"
2967                 exit 1
2968         fi
2970         if [ "$with_psp_config" = "1" ] || [ "$with_psp_config" = "" ] || [ "$with_psp_config" = "2" ]; then
2971                 psp_config="psp-config"
2972         else
2973                 psp_config="$with_psp_config"
2974         fi
2976         version=`$psp_config -p 2>/dev/null`
2977         ret=$?
2978         log 2 "executing $psp_config -p"
2979         log 2 "  returned $version"
2980         log 2 "  exit code $ret"
2982         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2983                 log 1 "checking psp-config... not found"
2984                 log 1 "configure: error: psp-config couldn't be found"
2986                 # It was forced, so it should be found.
2987                 if [ "$with_psp_config" != "1" ]; then
2988                         log 1 "configure: error: you supplied '$with_psp_config', but it seems invalid"
2989                 fi
2990                 exit 1
2991         fi
2993         log 1 "checking psp-config... found"
2996 detect_iconv() {
2997         # 0 means no, 1 is auto-detect, 2 is force
2998         if [ "$with_iconv" = "0" ]; then
2999                 log 1 "checking iconv... disabled"
3001                 return 0
3002         fi
3004         if [ "$with_iconv" = "1" ] && [ "$os" != "OSX" ]; then
3005                 log 1 "checking iconv... not OSX, skipping"
3006                 with_iconv="0"
3008                 return 0
3009         fi
3011         # Try to find iconv.h, seems to only thing to detect iconv with
3013         if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
3014                 iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
3015                 if [ -z "$iconv" ]; then
3016                         iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
3017                 fi
3018         else
3019                 # Make sure it exists
3020                 iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
3021         fi
3023         if [ -z "$iconv" ]; then
3024                 log 1 "checking iconv... not found"
3025                 if [ "$with_iconv" = "2" ]; then
3026                         log 1 "configure: error: iconv couldn't be found"
3028                         exit 1
3029                 elif [ "$with_iconv" != "1" ]; then
3030                         log 1 "configure: error: iconv couldn't be found"
3031                         log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
3033                         exit 1
3034                 fi
3036                 return 0
3037         fi
3039         if [ "$with_iconv" = "1" ]; then
3040                 with_iconv="2"
3041         fi
3043         log 2 "found iconv in $iconv"
3045         log 1 "checking iconv... found"
3047         # There are different implementations of iconv. The older ones,
3048         # e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
3049         # IEEE 1003.1 (2004), pass a non-const pointer.
3051         cat > tmp.iconv.cpp << EOF
3052 #include "src/stdafx.h"
3053 #include <iconv.h>
3054 int main() {
3055         static char buf[1024];
3056         iconv_t convd = 0;
3057         const char *inbuf = "";
3058         char *outbuf  = buf;
3059         size_t outlen = 1023;
3060         size_t inlen  = 0;
3061         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
3064         execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
3065         eval $execute > /dev/null
3066         ret=$?
3067         log 2 "executing $execute"
3068         log 2 "  exit code $ret"
3069         if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
3070         log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
3072         cat > tmp.iconv.cpp << EOF
3073 #include "src/stdafx.h"
3074 #include <iconv.h>
3075 int main() {
3076         static char buf[1024];
3077         iconv_t convd = 0;
3078         char *inbuf = "";
3079         char *outbuf  = buf;
3080         size_t outlen = 1023;
3081         size_t inlen  = 0;
3082         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
3085         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
3086         eval $execute > /dev/null
3087         ret=$?
3088         log 2 "executing $execute"
3089         log 2 "  exit code $ret"
3090         if [ "$ret" = "0" ]; then link_to_iconv="no"; else link_to_iconv="yes"; fi
3091         log 1 "checking whether to link to iconv... $link_to_iconv"
3092         rm -f tmp.iconv tmp.iconv.cpp
3095 _detect_sort() {
3096         sort_test_in="d
3101         sort_test_out="a
3106         log 2 "running echo <array> | $1"
3108         if [ "`echo \"$sort_test_in\" | $1 2>/dev/null`" = "$sort_test_out" ]; then
3109                 sort="$1"
3110                 log 2 "  result was valid"
3111         else
3112                 log 2 "  result was invalid"
3113         fi
3116 detect_sort() {
3117         if [ "$with_sort" = "0" ]; then
3118                 log 1 "checking sort... disabled"
3120                 return
3121         fi
3123         if [ "$with_sort" = "1" ] || [ "$with_sort" = "2" ]; then
3124                 _detect_sort "sort"
3125                 if [ -z "$sort" ]; then _detect_sort "/sbin/sort"; fi
3126                 if [ -z "$sort" ]; then _detect_sort "/usr/sbin/sort"; fi
3127                 if [ -z "$sort" ]; then _detect_sort "/usr/local/sbin/sort"; fi
3128                 if [ -z "$sort" ]; then _detect_sort "/bin/sort"; fi
3129                 if [ -z "$sort" ]; then _detect_sort "/usr/bin/sort"; fi
3130                 if [ -z "$sort" ]; then _detect_sort "/usr/local/bin/sort"; fi
3131         else
3132                 _detect_sort "$with_sort"
3133         fi
3135         if [ -z "$sort" ]; then
3136                 if [ "$with_sort" = "2" ]; then
3137                         log 1 "checking sort... not found"
3139                         log 1 "configure: error: couldn't detect sort on your system"
3140                         exit 1
3141                 elif [ "$with_sort" != "1" ]; then
3142                         log 1 "checking sort... $with_sort not found"
3144                         log 1 "configure: error: '$with_sort' doesn't look like a sort to me"
3145                         log 1 "configure: error: please verify its location and function and try again"
3147                         exit 1
3148                 else
3149                         log 1 "checking sort... not found"
3150                 fi
3151         else
3152                 log 1 "checking sort... $sort"
3153         fi
3156 detect_grfcodec() {
3157         # 0 means no, 1 is auto-detect, 2 is force
3158         if [ "$with_grfcodec" = "0" ]; then
3159                 log 1 "checking grfcodec... disabled"
3161                 grfcodec=""
3162                 return 0
3163         fi
3165         if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
3166                 grfcodec="grfcodec"
3167         else
3168                 grfcodec="$with_grfcodec"
3169         fi
3171         version=`$grfcodec -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3172         ret=$?
3173         log 2 "executing grfcodec -v"
3174         log 2 "  returned $version"
3175         log 2 "  exit code $ret"
3177         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3178                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3179                         log 1 "checking grfcodec... needs at least version 6.0.5 (r985), disabled"
3180                 else
3181                         log 1 "checking grfcodec... not found"
3182                 fi
3184                 # It was forced, so it should be found.
3185                 if [ "$with_grfcodec" != "1" ]; then
3186                         log 1 "configure: error: grfcodec couldn't be found"
3187                         log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
3188                         exit 1
3189                 fi
3191                 grfcodec=""
3192                 return 0
3193         fi
3195         log 1 "checking grfcodec... found"
3198 detect_nforenum() {
3199         # 0 means no, 1 is auto-detect, 2 is force
3200         if [ "$with_nforenum" = "0" ]; then
3201                 log 1 "checking nforenum... disabled"
3203                 nforenum=""
3204                 return 0
3205         fi
3207         if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
3208                 nforenum="nforenum"
3209         else
3210                 nforenum="$with_nforenum"
3211         fi
3213         version=`$nforenum -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3214         ret=$?
3215         log 2 "executing nforenum -v"
3216         log 2 "  returned $version"
3217         log 2 "  exit code $ret"
3219         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3220                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3221                         log 1 "checking nforenum... needs at least version 6.0.5 (r985), disabled"
3222                 else
3223                         log 1 "checking nforenum... not found"
3224                 fi
3226                 # It was forced, so it should be found.
3227                 if [ "$with_nforenum" != "1" ]; then
3228                         log 1 "configure: error: nforenum couldn't be found"
3229                         log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
3230                         exit 1
3231                 fi
3233                 nforenum=""
3234                 return 0
3235         fi
3237         log 1 "checking nforenum... found"
3240 detect_cputype() {
3241         if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
3242                 log 1 "forcing cpu-type... $cpu_type bits"
3243                 return;
3244         fi
3245         echo "#define _SQ64 1" > tmp.64bit.cpp
3246         echo "#include \"src/stdafx.h\"" >> tmp.64bit.cpp
3247         echo "assert_compile(sizeof(size_t) == 8);" >> tmp.64bit.cpp
3248         echo "int main() { return 0; }" >> tmp.64bit.cpp
3249         execute="$cxx_host $CFLAGS tmp.64bit.cpp -o tmp.64bit -DTESTING 2>&1"
3250         cpu_type="`eval $execute 2>/dev/null`"
3251         ret=$?
3252         log 2 "executing $execute"
3253         log 2 "  returned $cpu_type"
3254         log 2 "  exit code $ret"
3255         if [ "$ret" = "0" ]; then cpu_type="64"; else cpu_type="32"; fi
3256         log 1 "detecting cpu-type... $cpu_type bits"
3257         rm -f tmp.64bit tmp.64bit.cpp
3260 detect_sse_capable_architecture() {
3261         # 0 means no, 1 is auto-detect, 2 is force
3262         if [ "$with_sse" = "0" ]; then
3263                 log 1 "checking SSE... disabled"
3264                 return
3265         fi
3267         echo "#define _SQ64 1" > tmp.sse.cpp
3268         echo "#include <xmmintrin.h>" >> tmp.sse.cpp
3269         echo "#include <smmintrin.h>" >> tmp.sse.cpp
3270         echo "#include <tmmintrin.h>" >> tmp.sse.cpp
3271         echo "int main() { return 0; }" >> tmp.sse.cpp
3272         execute="$cxx_host -msse4.1 $CFLAGS tmp.sse.cpp -o tmp.sse 2>&1"
3273         sse="`eval $execute 2>/dev/null`"
3274         ret=$?
3275         log 2 "executing $execute"
3276         log 2 "  returned $sse"
3277         log 2 "  exit code $ret"
3278         if [ "$ret" = "0" ]; then
3279                 log 1 "detecting SSE... found"
3280         else
3281                 # It was forced, so it should be found.
3282                 if [ "$with_sse" != "1" ]; then
3283                         log 1 "configure: error: SSE couln't be found"
3284                         log 1 "configure: error: you force enabled SSE, but it seems unavailable"
3285                         exit 1
3286                 fi
3288                 log 1 "detecting SSE... not found"
3289                 with_sse="0"
3290         fi
3291         rm -f tmp.sse tmp.exe tmp.sse.cpp
3294 make_sed() {
3295         T_CFLAGS="$CFLAGS"
3296         T_CXXFLAGS="$CXXFLAGS"
3297         T_LDFLAGS="$LDFLAGS"
3299         SRC_OBJS_DIR="$BASE_SRC_OBJS_DIR/$OBJS_SUBDIR"
3301         # All the data needed to compile a single target
3302         #  Make sure if you compile multiple targets to
3303         #  use multiple OBJS_DIR, because all in-between
3304         #  binaries are stored in there, and nowhere else.
3305         SRC_REPLACE="
3306                 s@!!CC_HOST!!@$cc_host@g;
3307                 s@!!CXX_HOST!!@$cxx_host@g;
3308                 s@!!CC_BUILD!!@$cc_build@g;
3309                 s@!!CXX_BUILD!!@$cxx_build@g;
3310                 s@!!WINDRES!!@$windres@g;
3311                 s@!!STRIP!!@$strip $strip_arg@g;
3312                 s@!!LIPO!!@$lipo@g;
3313                 s@!!CFLAGS!!@$T_CFLAGS@g;
3314                 s@!!CFLAGS_BUILD!!@$CFLAGS_BUILD@g;
3315                 s@!!CXXFLAGS!!@$T_CXXFLAGS@g;
3316                 s@!!CXXFLAGS_BUILD!!@$CXXFLAGS_BUILD@g;
3317                 s@!!STRGEN_FLAGS!!@$strgen_flags@g;
3318                 s@!!LIBS!!@$LIBS@g;
3319                 s@!!LDFLAGS!!@$T_LDFLAGS@g;
3320                 s@!!LDFLAGS_BUILD!!@$LDFLAGS_BUILD@g;
3321                 s@!!BIN_DIR!!@$BIN_DIR@g;
3322                 s@!!ROOT_DIR!!@$ROOT_DIR@g;
3323                 s@!!MEDIA_DIR!!@$MEDIA_DIR@g;
3324                 s@!!SOURCE_LIST!!@$SOURCE_LIST@g;
3325                 s@!!SRC_OBJS_DIR!!@$SRC_OBJS_DIR@g;
3326                 s@!!LANG_OBJS_DIR!!@$LANG_OBJS_DIR@g;
3327                 s@!!GRF_OBJS_DIR!!@$GRF_OBJS_DIR@g;
3328                 s@!!SETTING_OBJS_DIR!!@$SETTING_OBJS_DIR@g;
3329                 s@!!SRC_DIR!!@$SRC_DIR@g;
3330                 s@!!SCRIPT_SRC_DIR!!@$SCRIPT_SRC_DIR@g;
3331                 s@!!OSXAPP!!@$OSXAPP@g;
3332                 s@!!LANG_DIR!!@$LANG_DIR@g;
3333                 s@!!TTD!!@$TTD@g;
3334                 s@!!BINARY_DIR!!@$prefix_dir/$binary_dir@g;
3335                 s@!!DATA_DIR!!@$prefix_dir/$data_dir@g;
3336                 s@!!DOC_DIR!!@$prefix_dir/$doc_dir@g;
3337                 s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3338                 s@!!ICON_DIR!!@$prefix_dir/$icon_dir@g;
3339                 s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3340                 s@!!PERSONAL_DIR!!@$personal_dir@g;
3341                 s@!!SHARED_DIR!!@$shared_dir@g;
3342                 s@!!INSTALL_DIR!!@$install_dir@g;
3343                 s@!!BINARY_NAME!!@$binary_name@g;
3344                 s@!!STRGEN!!@$STRGEN@g;
3345                 s@!!ENDIAN_CHECK!!@$ENDIAN_CHECK@g;
3346                 s@!!DEPEND!!@$DEPEND@g;
3347                 s@!!SETTINGSGEN!!@$SETTINGSGEN@g;
3348                 s@!!ENDIAN_FORCE!!@$endian@g;
3349                 s@!!STAGE!!@$STAGE@g;
3350                 s@!!MAKEDEPEND!!@$makedepend@g;
3351                 s@!!CFLAGS_MAKEDEP!!@$cflags_makedep@g;
3352                 s@!!SORT!!@$sort@g;
3353                 s@!!CONFIG_CACHE_COMPILER!!@config.cache.compiler@g;
3354                 s@!!CONFIG_CACHE_LINKER!!@config.cache.linker@g;
3355                 s@!!CONFIG_CACHE_ENDIAN!!@config.cache.endian@g;
3356                 s@!!CONFIG_CACHE_SOURCE!!@config.cache.source@g;
3357                 s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
3358                 s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
3359                 s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
3360                 s@!!LANG_SUPPRESS!!@$lang_suppress@g;
3361                 s@!!OBJS_C!!@$OBJS_C@g;
3362                 s@!!OBJS_CPP!!@$OBJS_CPP@g;
3363                 s@!!OBJS_MM!!@$OBJS_MM@g;
3364                 s@!!OBJS_RC!!@$OBJS_RC@g;
3365                 s@!!SRCS!!@$SRCS@g;
3366                 s@!!OS!!@$os@g;
3367                 s@!!CONFIGURE_FILES!!@$CONFIGURE_FILES@g;
3368                 s@!!AWK!!@$awk@g;
3369                 s@!!DISTCC!!@$distcc@g;
3370                 s@!!NFORENUM!!@$nforenum@g;
3371                 s@!!GRFCODEC!!@$grfcodec@g;
3372         "
3374         if [ "$icon_theme_dir" != "" ]; then
3375                 SRC_REPLACE="$SRC_REPLACE
3376                         s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3377                 "
3378         else
3379                 SRC_REPLACE="$SRC_REPLACE
3380                         s@!!ICON_THEME_DIR!!@@g;
3381                 "
3382         fi
3384         if [ "$man_dir" != "" ]; then
3385                 SRC_REPLACE="$SRC_REPLACE
3386                         s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3387                 "
3388         else
3389                 SRC_REPLACE="$SRC_REPLACE
3390                         s@!!MAN_DIR!!@@g;
3391                 "
3392         fi
3394         if [ "$menu_dir" != "" ]; then
3395                 SRC_REPLACE="$SRC_REPLACE
3396                         s@!!MENU_DIR!!@$prefix_dir/$menu_dir@g;
3397                 "
3398         else
3399                 SRC_REPLACE="$SRC_REPLACE
3400                         s@!!MENU_DIR!!@@g;
3401                 "
3402         fi
3405 generate_menu_item() {
3406         MENU_REPLACE="
3407                 s@!!TTD!!@$TTD@g;
3408                 s@!!MENU_GROUP!!@$menu_group@g;
3409                 s@!!MENU_NAME!!@$menu_name@g
3410         "
3411         log 1 "Generating menu item..."
3412         mkdir -p media
3413         < $ROOT_DIR/media/openttd.desktop.in sed "$MENU_REPLACE" > media/openttd.desktop
3416 generate_main() {
3417         STAGE="[MAIN]"
3419         make_sed
3421         # Create the main Makefile
3422         log 1 "Generating Makefile..."
3423         echo "# Auto-generated file from 'Makefile.in' -- DO NOT EDIT" > Makefile
3424         < $ROOT_DIR/Makefile.in sed "$SRC_REPLACE" >> Makefile
3425         cp $ROOT_DIR/Makefile.bundle.in Makefile.bundle
3426         echo "# Auto-generated file -- DO NOT EDIT" > Makefile.am
3427         echo >> Makefile.am
3428         # Make the copy of the source-list, so we don't trigger an unwanted recompile
3429         cp $SOURCE_LIST config.cache.source.list
3430         # Add the current directory, so we don't trigger an unwanted recompile
3431         echo "`pwd`" > config.cache.pwd
3432         # Make sure config.cache is OLDER then config.cache.source.list
3433         touch config.cache
3434         touch config.pwd
3436         if [ "$menu_dir" != "" ]; then
3437                 generate_menu_item
3438         fi
3441 generate_lang() {
3442         STAGE="[LANG]"
3444         make_sed
3446         # Create the language file
3447         mkdir -p $LANG_OBJS_DIR
3449         log 1 "Generating lang/Makefile..."
3450         echo "# Auto-generated file from 'Makefile.lang.in' -- DO NOT EDIT" > $LANG_OBJS_DIR/Makefile
3451         < $ROOT_DIR/Makefile.lang.in sed "$SRC_REPLACE" >> $LANG_OBJS_DIR/Makefile
3452         echo "DIRS += $LANG_OBJS_DIR" >> Makefile.am
3453         echo "LANG_DIRS += $LANG_OBJS_DIR" >> Makefile.am
3456 generate_settings() {
3457         STAGE="[SETTING]"
3459         make_sed
3461         # Create the language file
3462         mkdir -p $SETTING_OBJS_DIR
3464         log 1 "Generating setting/Makefile..."
3465         echo "# Auto-generated file from 'Makefile.settings.in' -- DO NOT EDIT" > $SETTING_OBJS_DIR/Makefile
3466         < $ROOT_DIR/Makefile.setting.in sed "$SRC_REPLACE" >> $SETTING_OBJS_DIR/Makefile
3467         echo "DIRS += $SETTING_OBJS_DIR" >> Makefile.am
3470 generate_grf() {
3471         STAGE="[BASESET]"
3473         make_sed
3475         # Create the language file
3476         mkdir -p $GRF_OBJS_DIR
3478         log 1 "Generating grf/Makefile..."
3479         echo "# Auto-generated file from 'Makefile.grf.in' -- DO NOT EDIT" > $GRF_OBJS_DIR/Makefile
3480         < $ROOT_DIR/Makefile.grf.in sed "$SRC_REPLACE" >> $GRF_OBJS_DIR/Makefile
3481         echo "DIRS += $GRF_OBJS_DIR" >> Makefile.am
3484 generate_src_normal() {
3485         STAGE=$1
3487         make_sed
3489         # Create the source file
3490         mkdir -p $SRC_OBJS_DIR
3492         log 1 "Generating $2/Makefile..."
3493         echo "# Auto-generated file from 'Makefile.src.in' -- DO NOT EDIT" > $SRC_OBJS_DIR/Makefile
3494         < $ROOT_DIR/Makefile.src.in sed "$SRC_REPLACE" >> $SRC_OBJS_DIR/Makefile
3495         echo "DIRS += $SRC_OBJS_DIR" >> Makefile.am
3496         echo "SRC_DIRS += $SRC_OBJS_DIR" >> Makefile.am
3499 generate_src_osx() {
3500         cc_host_orig="$cc_host"
3501         cxx_host_orig="$cxx_host"
3502         CFLAGS_orig="$CFLAGS"
3503         LDFLAGS_orig="$LDFLAGS"
3505         for type in $enable_universal; do
3507                 if [ -n "$osx_sdk_104_path" ]; then
3508                         # Use 10.4 SDK for 32-bit targets
3509                         CFLAGS="-isysroot $osx_sdk_104_path $CFLAGS_orig"
3510                         LDFLAGS="-Wl,-syslibroot,$osx_sdk_104_path $LDFLAGS_orig"
3511                 fi
3513                 # We don't want to duplicate the x86_64 stuff for each target, so do it once here
3514                 if [ "$type" = "ppc64" ] || [ "$type" = "x86_64" ]; then
3515                         # 64 bits is always 10.5 or higher. Furthermore it has a non const ICONV
3516                         # and they also removed support for QuickTime/QuickDraw
3517                         if [ -n "$osx_sdk_path" ]; then
3518                                 CFLAGS="-isysroot $osx_sdk_path $CFLAGS_orig"
3519                                 LDFLAGS="-Wl,-syslibroot,$osx_sdk_path $LDFLAGS_orig"
3520                         fi
3521                         CFLAGS="$CFLAGS -D_SQ64 -DNO_QUICKTIME -UENABLE_COCOA_QUICKDRAW"
3522                         LIBS="`echo $LIBS | sed 's/-framework QuickTime//'`"
3523                 fi
3525                 case $type in
3526                         ppc)
3527                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc"
3528                                 cc_host="$cc_host_orig -arch ppc -mmacosx-version-min=10.3"
3529                                 cxx_host="$cxx_host_orig -arch ppc -mmacosx-version-min=10.3"
3530                                 generate_src_normal "[ppc]" "objs/ppc";;
3531                         ppc970)
3532                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc970"
3533                                 cc_host="$cc_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3534                                 cxx_host="$cxx_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3535                                 generate_src_normal "[ppc970]" "objs/ppc970";;
3536                         i386)
3537                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/i386"
3538                                 cc_host="$cc_host_orig -arch i386 -mmacosx-version-min=10.4"
3539                                 cxx_host="$cxx_host_orig -arch i386 -mmacosx-version-min=10.4"
3540                                 generate_src_normal "[i386]" "objs/i386";;
3541                         ppc64)
3542                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc64"
3543                                 cc_host="$cc_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3544                                 cxx_host="$cxx_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3545                                 generate_src_normal "[ppc64]" "objs/ppc64";;
3546                         x86_64)
3547                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/x86_64"
3548                                 cc_host="$cc_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3549                                 cxx_host="$cxx_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3550                                 generate_src_normal "[x86_64]" "objs/x86_64";;
3551                         *) log 1 "Unknown architecture requested for universal build: $type";;
3552                 esac
3553         done
3556 generate_src() {
3557         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
3558                 generate_src_osx
3559         else
3560                 generate_src_normal "[SRC]" "objs"
3561         fi
3564 showhelp() {
3565         echo "'configure' configures OpenTTD."
3566         echo ""
3567         echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
3568         echo ""
3569         echo "To assign environment variables (e.g., CC, CFLAGS...), specify them as"
3570         echo "VAR=VALUE.  See below for descriptions of some of the useful variables."
3571         echo ""
3572         echo "Defaults for the options are specified in brackets."
3573         echo ""
3574         echo "Configuration:"
3575         echo "  -h, --help                     display this help and exit"
3576         echo ""
3577         echo "System types:"
3578         echo "  --build=BUILD                  configure for building on BUILD [guessed]"
3579         echo "  --host=HOST                    cross-compile to build programs to run"
3580         echo "                                 on HOST [BUILD]"
3581         echo "  --windres=WINDRES              the windres to use [HOST-windres]"
3582         echo "  --strip=STRIP                  the strip to use [HOST-strip]"
3583         echo "  --awk=AWK                      the awk to use in configure [awk]"
3584         echo "  --lipo=LIPO                    the lipo to use (OSX ONLY) [HOST-lipo]"
3585         echo "  --os=OS                        the OS we are compiling for [DETECT]"
3586         echo "                                 DETECT/UNIX/OSX/FREEBSD/OPENBSD/NETBSD/"
3587         echo "                                 MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/MINGW/OS2/"
3588         echo "                                 DOS/WINCE/PSP/HAIKU"
3589         echo "  --endian=ENDIAN                set the endian of the HOST (AUTO/LE/BE)"
3590         echo ""
3591         echo "Paths:"
3592         echo "  --prefix-dir=dir               specifies the prefix for all installed"
3593         echo "                                 files [/usr/local]"
3594         echo "  --binary-dir=dir               location of the binary. Will be prefixed"
3595         echo "                                 with the prefix-dir [games]"
3596         echo "  --data-dir=dir                 location of data files (lang, data, gm)."
3597         echo "                                 Will be prefixed with the prefix-dir"
3598         echo "                                 [share/games/openttd]"
3599         echo "  --doc-dir=dir                  location of the doc files"
3600         echo "                                 Will be prefixed with the prefix-dir"
3601         echo "                                 [$doc_dir]"
3602         echo "  --icon-dir=dir                 location of icons. Will be prefixed"
3603         echo "                                 with the prefix-dir [share/pixmaps]"
3604         echo "  --icon-theme-dir=dir           location of icon theme."
3605         echo "                                 Will be prefixed with the prefix-dir"
3606         echo "                                 and postfixed with size-dirs [$icon_theme_dir]"
3607         echo "  --man-dir=dir                  location of the manual page (UNIX only)"
3608         echo "                                 Will be prefixed with the prefix-dir"
3609         echo "                                 [$man_dir]"
3610         echo "  --menu-dir=dir                 location of the menu item. (UNIX only, except OSX)"
3611         echo "                                 Will be prefixed with the prefix-dir"
3612         echo "                                 [share/applications]"
3613         echo "  --personal-dir=dir             location of the personal directory"
3614         echo "                                 [os-dependent default]"
3615         echo "  --shared-dir=dir               location of shared data files"
3616         echo "                                 [os-dependent default]"
3617         echo "  --install-dir=dir              specifies the root to install to."
3618         echo "                                 Useful to install into jails [/]"
3619         echo "  --binary-name                  the name used for the binary, icons,"
3620         echo "                                 desktop file, etc. when installing [openttd]"
3621         echo ""
3622         echo "Features and packages:"
3623         echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
3624         echo "  --enable-desync-debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
3625         echo "  --enable-profiling             enables profiling"
3626         echo "  --enable-lto                   enables GCC's Link Time Optimization (LTO)/ICC's"
3627         echo "                                 Interprocedural Optimization if available"
3628         echo "  --enable-dedicated             compile a dedicated server (without video)"
3629         echo "  --enable-static                enable static compile (doesn't work for"
3630         echo "                                 all HOSTs)"
3631         echo "  --enable-translator            enable extra output for translators"
3632         echo "  --enable-universal[=ARCH]      enable universal builds (OSX ONLY). Allowed is any combination"
3633         echo "                                 of architectures: i386 ppc ppc970 ppc64 x86_64"
3634         echo "                                 Default architectures are: i386 ppc"
3635         echo "  --enable-osx-g5                enables optimizations for ppc970 (G5) (OSX ONLY)"
3636         echo "  --disable-cocoa-quartz         disable the quartz window mode driver for Cocoa (OSX ONLY)"
3637         echo "  --disable-cocoa-quickdraw      disable the quickdraw window mode driver for Cocoa (OSX ONLY)"
3638         echo "  --disable-unicode              disable unicode support to build win9x"
3639         echo "                                 version (Win32 ONLY)"
3640         echo "  --enable-console               compile as a console application instead of as a GUI application."
3641         echo "                                 If this setting is active, debug output will appear in the same"
3642         echo "                                 console instead of opening a new window. (Win32 ONLY)"
3643         echo "  --disable-network              disable network support"
3644         echo "  --disable-assert               disable asserts (continue on errors)"
3645         echo "  --enable-strip                 enable any possible stripping"
3646         echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
3647         echo "                                 (OSX ONLY)"
3648         echo "  --without-application-bundle   disable generation of application bundle"
3649         echo "                                 (OSX ONLY)"
3650         echo "  --without-menu-entry           Don't generate a menu item (Freedesktop based only)"
3651         echo "  --menu-group=group             Category in which the menu item will be placed (Freedesktop based only)"
3652         echo "  --menu-name=name               Name of the menu item when placed [OpenTTD]"
3653         echo "  --with-direct-music            enable direct music support (Win32 ONLY)"
3654         echo "  --with-sort=sort               define a non-default location for sort"
3655         echo "  --with-midi=midi               define which midi-player to use"
3656         echo "  --with-midi-arg=arg            define which args to use for the"
3657         echo "                                 midi-player"
3658         echo "  --with-libtimidity             enables libtimidity support"
3659         echo "  --with-allegro[=allegro-config]"
3660         echo "                                 enables Allegro video driver support"
3661         echo "  --with-cocoa                   enables COCOA video driver (OSX ONLY)"
3662         echo "  --with-sdl[=sdl-config]        enables SDL video driver support"
3663         echo "  --with-zlib[=zlib.a]           enables zlib support"
3664         echo "  --with-liblzma[=\"pkg-config liblzma\"]"
3665         echo "                                 enables liblzma support"
3666         echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
3667         echo "  --with-png[=libpng-config]     enables libpng support"
3668         echo "  --with-freetype[=freetype-config]"
3669         echo "                                 enables libfreetype support"
3670         echo "  --with-fontconfig[=\"pkg-config fontconfig\"]"
3671         echo "                                 enables fontconfig support"
3672         echo "  --with-xdg-basedir[=\"pkg-config libxdg-basedir\"]"
3673         echo "                                 enables XDG base directory support"
3674         echo "  --with-icu[=icu-config]        enables icu (used for right-to-left support)"
3675         echo "  --static-icu                   try to link statically (libsicu instead of"
3676         echo "                                 libicu; can fail as the new name is guessed)"
3677         echo "  --with-iconv[=iconv-path]      enables iconv support"
3678         echo "  --with-psp-config[=psp-config] enables psp-config support (PSP ONLY)"
3679         echo "  --disable-builtin-depend       disable use of builtin deps finder"
3680         echo "  --with-makedepend[=makedepend] enables makedepend support"
3681         echo "  --with-ccache                  enables ccache support"
3682         echo "  --with-distcc                  enables distcc support"
3683         echo "  --without-grfcodec             disable usage of grfcodec and re-generation of base sets"
3684         echo "  --without-threads              disable threading support"
3685         echo "  --without-sse                  disable SSE support (x86/x86_64 only)"
3686         echo ""
3687         echo "Some influential environment variables:"
3688         echo "  CC                             C compiler command"
3689         echo "  CXX                            C++ compiler command"
3690         echo "  CFLAGS                         C compiler flags"
3691         echo "  CXXFLAGS                       C++ compiler flags"
3692         echo "  WINDRES                        windres command"
3693         echo "  LDFLAGS                        linker flags, e.g. -L<lib dir> if you"
3694         echo "                                 have libraries in a nonstandard"
3695         echo "                                 directory <lib dir>"
3696         echo "  CFLAGS_BUILD                   C compiler flags for build time tool generation"
3697         echo "  CXXFLAGS_BUILD                 C++ compiler flags for build time tool generation"
3698         echo "  LDFLAGS_BUILD                  linker flags for build time tool generation"
3699         echo ""
3700         echo "Use these variables to override the choices made by 'configure' or to help"
3701         echo "it to find libraries and programs with nonstandard names/locations."