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