(svn r27868) -Update from Eints:
[openttd.git] / config.lib
blob3d10aaa3fdd270bb9ce684f044aa861c9b09b248
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 [ -z "`echo $endian | egrep '^(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 [ -z "`echo $os | egrep '^(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 [ -z "`echo $cpu_type | egrep '^(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 [ -z "`echo $enable_debug | egrep '^[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 [ -z "`echo $enable_desync_debug | egrep '^[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                 has_lto=`($cxx_build -dumpspecs 2>&1 | grep '\%{flto') || ($cxx_build -help ipo 2>&1 | grep '\-ipo')`
668                 if [ -n "$has_lto" ]; then
669                         log 1 "using link time optimization... yes"
670                 else
671                         enable_lto="0"
672                         log 1 "using link time optimization... no"
673                         log 1 "WARNING: you selected link time optimization but it is not found."
674                         sleep 5
675                 fi
676         else
677                 log 1 "using link time optimization... no"
678         fi
681         if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
682                 if [ "$with_osx_sysroot" = "1" ]; then
683                         with_osx_sysroot="0"
685                         log 1 "checking OSX sysroot... not OSX, skipping"
686                 else
687                         log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
688                         exit 1
689                 fi
690         fi
692         if [ "$with_osx_sysroot" != "0" ]; then
693                 if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
694                         # Sysroot manually specified? Check for usability
695                         log 1 "checking OSX sysroot... $with_osx_sysroot"
696                         if ! check_osx_sdk "$with_osx_sysroot"; then
697                                 log 1 "Passed sysroot not found/not functional"
698                                 exit 1
699                         fi
700                 else
701                         # If autodetect and no universal, use system default
702                         if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
703                                 log 1 "checking OSX sysroot... no (use system default)"
704                         else
705                                 log 1 "checking OSX sysroot... automatically"
706                                 detect_osx_sdk
707                         fi
708                 fi
710                 if [ -n "$osx_sdk_path" ]; then
711                         if [ "$enable_universal" != "0" ]; then
712                                 if [ -z "$osx_sdk_104_path" ]; then
713                                         log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
714                                         log 1 "WARNING: binary will only run on OSX 10.5 or later"
715                                         osx_sdk_104_path="$osx_sdk_path"
716                                 fi
717                                 OSX_SYSROOT="-isysroot $osx_sdk_104_path"
718                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
719                         else
720                                 OSX_SYSROOT="-isysroot $osx_sdk_path"
721                                 OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
722                         fi
723                 fi
724         else
725                 if [ "$os" = "OSX" ]; then
726                         log 1 "checking OSX sysroot... no (use system default)"
727                 fi
728         fi
730         detect_allegro
731         detect_sdl
732         detect_cocoa
734         if [ "$enable_dedicated" != "0" ]; then
735                 log 1 "checking GDI video driver... dedicated server, skipping"
736                 log 1 "checking dedicated... found"
738                 if [ "$enable_network" = "0" ]; then
739                         log 1 "configure: error: building a dedicated server without network support is pointless"
740                         exit 1
741                 fi
742         else
743                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
744                         log 1 "checking GDI video driver... found"
745                 else
746                         log 1 "checking GDI video driver... not Windows, skipping"
747                 fi
749                 if [ -z "$allegro_config" ] && [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
750                         log 1 "configure: error: no video driver development files found"
751                         log 1 " If you want a dedicated server use --enable-dedicated as parameter"
752                         exit 1
753                 else
754                         log 1 "checking dedicated... not selected"
755                 fi
756         fi
758         if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
759                 log 1 "checking console application... not Windows, skipping"
760         elif [ "$enable_console" = "1" ] && [ "$enable_dedicated" != "0" ]; then
761                 log 1 "checking console application... dedicated server, enabled"
762                 enable_console="2"
763         elif [ "$enable_console" = "1" ]; then
764                 log 1 "checking console application... disabled (only used when forced)"
765                 enable_console="0"
766         elif [ "$enable_console" = "0" ]; then
767                 log 1 "checking console application... disabled"
768         else
769                 log 1 "checking console application... enabled"
770         fi
772         if [ "$enable_network" = "1" ] && [ "$os" = "DOS" ]; then
773                 log 1 "checking network... DOS, skipping"
774                 enable_network=0
775         elif [ "$enable_network" != "0" ]; then
776                 log 1 "checking network... found"
777         else
778                 log 1 "checking network... disabled"
779         fi
781         log 1 "checking squirrel... found"
782         SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include"
784         if [ "$enable_translator" != "0" ]; then
785                 log 1 "checking translator... debug"
786                 # -t shows TODO items, normally they are muted
787                 strgen_flags="-t"
788         else
789                 log 1 "checking translator... no"
790                 strgen_flags=""
791         fi
793         if [ "$enable_assert" != "0" ]; then
794                 log 1 "checking assert... enabled"
795         else
796                 log 1 "checking assert... disabled"
797         fi
799         pre_detect_with_zlib=$with_zlib
800         detect_zlib
802         if [ "$with_zlib" = "0" ] || [ -z "$zlib-config" ]; then
803                 log 1 "WARNING: zlib was not detected or disabled"
804                 log 1 "WARNING: OpenTTD doesn't require zlib, but it does mean that many features"
805                 log 1 "WARNING: (like loading most old savegames/scenarios, loading heightmaps,"
806                 log 1 "WARNING: using PNG, or using fonts, ...) will be disabled."
807                 if [ "$pre_detect_with_zlib" = "0" ]; then
808                         log 1 "WARNING: We strongly suggest you to install zlib."
809                 else
810                         log 1 "configure: error: no zlib detected"
811                         log 1 " If you want to compile without zlib use --without-zlib as parameter"
812                         exit
813                 fi
814         fi
816         pre_detect_with_lzma=$with_lzma
817         detect_lzma
819         if [ "$with_lzma" = "0" ] || [ -z "$lzma_config" ]; then
820                 log 1 "WARNING: lzma was not detected or disabled"
821                 log 1 "WARNING: OpenTTD doesn't require lzma, but it does mean that many features"
822                 log 1 "WARNING: (like loading most savegames/scenarios and joining most servers)"
823                 log 1 "WARNING: will be disabled."
824                 if [ "$pre_detect_with_lzma" = "0" ]; then
825                         log 1 "WARNING: We strongly suggest you to install liblzma."
826                         log 1 "configure: error: no liblzma detected"
827                 else
828                         log 1 " If you want to compile without lzma use --without-lzma as parameter"
829                         exit
830                 fi
831         fi
833         pre_detect_with_lzo2=$with_lzo2
834         detect_lzo2
836         if [ "$with_lzo2" = "0" ] || [ -z "$lzo2" ]; then
837                 log 1 "WARNING: liblzo2 was not detected or disabled"
838                 log 1 "WARNING: OpenTTD doesn't require liblzo2, but it does mean that"
839                 log 1 "WARNING: loading old savegames/scenarios will be disabled."
840                 if [ "$pre_detect_with_lzo2" = "0" ]; then
841                         log 1 "WARNING: We strongly suggest you to install liblzo2."
842                 else
843                         log 1 "configure: error: no liblzo2 detected"
844                         log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
845                         exit
846                 fi
847         fi
849         detect_xdg_basedir
850         detect_png
851         detect_freetype
852         detect_fontconfig
853         detect_icu_layout
854         detect_icu_sort
855         detect_pspconfig
856         detect_libtimidity
858         if [ "$with_direct_music" != "0" ]; then
859                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ]; then
860                         if [ "$with_direct_music" != "1" ]; then
861                                 log 1 "configure: error: direct-music is only supported on Win32 targets"
862                                 exit 1
863                         fi
864                         with_direct_music="0"
866                         log 1 "checking direct-music... not Windows, skipping"
867                 else
868                         check_direct_music
869                 fi
870         fi
872         detect_sort
874         if [ "$os" = "OSX" ] && [ "$endian" = "AUTO" ]; then
875                 endian="PREPROCESSOR"
876         fi
878         log 1 "checking endianness... $endian"
880         # Suppress language errors when there is a version defined, indicating a release
881         #  It just isn't pretty if any release produces warnings in the languages.
882         if [ -f "$ROOT_DIR/version" ]; then
883                 lang_suppress="yes"
884                 log 1 "suppress language errors... yes"
885         else
886                 lang_suppress=""
887                 log 1 "suppress language errors... no"
888         fi
890         if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
891                 if [ "$os" = "MORPHOS" ]; then
892                         strip_arg="--strip-all --strip-unneeded --remove-section .comment"
893                 elif [ "$os" = "OSX" ]; then
894                         strip_arg=""
895                 elif [ "$os" = "OS2" ]; then
896                         strip_arg=""
897                         # OS2 uses strip via gcc, because it needs to be feed to emxbind
898                         LDFLAGS="$LDFLAGS -s"
899                 elif [ "$os" = "SUNOS" ]; then
900                         # The GNU strip does know -s, the non-GNU doesn't
901                         #  So try to detect it (in a bit of an ugly way)
902                         strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
903                 else
904                         strip_arg="-s"
905                 fi
907                 log 1 "checking stripping... $strip $strip_arg"
908         else
909                 strip=""
910                 log 1 "checking stripping... skipped"
911         fi
913         if [ "$with_distcc" = "0" ]; then
914                 log 1 "checking distcc... no"
915         elif [ "$with_distcc" = "1" ]; then
916                 with_distcc="0"
918                 log 1 "checking distcc... no (only used when forced)"
919         elif [ "$with_distcc" = "2" ]; then
920                 distcc="distcc"
921         else
922                 distcc="$with_distcc"
923         fi
924         if [ "$with_distcc" != "0" ]; then
925                 res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
926                 if [ "$res" != "distcc" ]; then
927                         distcc=""
928                         log 1 "checking distcc... no"
929                         if [ "$with_distcc" = "2" ]; then
930                                 log 1 "configure: error: no distcc detected, but was forced to be used"
931                                 exit 1
932                         fi
933                         if [ "$with_distcc" != "1" ]; then
934                                 log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
935                                 exit 1
936                         fi
937                 fi
939                 log 1 "checking distcc... $distcc"
940         fi
942         if [ "$with_ccache" = "0" ]; then
943                 log 1 "checking ccache... no"
944         elif [ "$with_ccache" = "1" ]; then
945                 with_ccache="0"
947                 log 1 "checking ccache... no (only used when forced)"
948         elif [ "$with_ccache" = "2" ]; then
949                 ccache="ccache"
950         else
951                 ccache="$with_ccache"
952         fi
953         if [ "$with_ccache" != "0" ]; then
954                 res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
955                 if [ "$res" != "ccache" ]; then
956                         ccache=""
957                         log 1 "checking ccache... no"
958                         if [ "$with_ccache" = "2" ]; then
959                                 log 1 "configure: error: no ccache detected, but was forced to be used"
960                                 exit 1
961                         fi
962                         if [ "$with_ccache" != "1" ]; then
963                                 log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
964                                 exit 1
965                         fi
966                 fi
968                 log 1 "checking ccache... $ccache"
969         fi
971         detect_grfcodec
972         detect_nforenum
974         if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
975                 log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
976                 nforenum=""
977         fi
979         if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
980                 log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
981                 grfcodec=""
982         fi
984         if [ "$os" = "DOS" ]; then
985                 with_threads="0"
986         fi
988         if [ "$os" != "OSX" ] && [ "$with_application_bundle" != "0" ]; then
989                 if [ "$with_application_bundle" = "1" ]; then
990                         with_application_bundle="0"
992                         log 1 "checking OSX application bundle... not OSX, skipping"
993                 else
994                         log 1 "configure: error: --with-application-bundle only works if OSX is the target"
995                         exit 1
996                 fi
997         fi
999         if [ "$os" = "OSX" ] && [ "$with_application_bundle" = "1" ]; then
1000                 OSXAPP="OpenTTD.app"
1001         else
1002                 OSXAPP=""
1003         fi
1005         if [ "$os" = "OSX" ]; then
1006                 # Test on ppc970 (G5) - we can optimize there
1008                 if [ "$enable_osx_g5" != "0" ]; then
1009                         log 1 "detecting ppc970 (G5)... yes (forced)"
1010                 else
1011                         # First, are we a real OSX system, else we can't detect it
1012                         native=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | grep darwin`
1013                         # If $host doesn't match $build , we are cross-compiling
1014                         if [ -n "$native" ] && [ "$build" = "$host" ]; then
1015                                 $cxx_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
1016                                 res=`./G5_detector`
1017                                 rm -f G5_detector
1018                                 if [ -n "$res" ]; then
1019                                         # This is G5, add flags for it
1020                                         enable_osx_g5="2"
1022                                         log 1 "detecting ppc970 (G5)... yes"
1023                                 else
1024                                         enable_osx_g5="0"
1026                                         log 1 "detecting ppc970 (G5)... no"
1027                                 fi
1028                         else
1029                                 enable_osx_g5="0"
1031                                 log 1 "detecting ppc970 (G5)... no (cross-compiling)"
1032                         fi
1033                 fi
1034         else
1035                 if [ "$enable_osx_g5" != "0" ]; then
1036                         log 1 "configure: error: ppc970 (OSX G5) selected, but not compiling for OSX"
1037                         log 1 "configure: error: either select OSX as OS, or deselect ppc970"
1039                         exit 1
1040                 fi
1041         fi
1043         if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
1044                 log 1 "checking revision... svn detection"
1045         elif [ -d "$ROOT_DIR/../.svn" ] && [ -n "`svn help 2>/dev/null`" ] && [ -n "`LC_ALL=C svn info $ROOT_DIR/.. | grep '^URL:.*tags$'`" ]; then
1046                 # subversion changed its behaviour; now not all folders have a .svn folder,
1047                 # but only the root folder. Since making tags requires a (sparse) checkout
1048                 # of the tags folder, the folder of the tag does not have a .svn folder
1049                 # anymore and this fails to detect the subversion repository checkout.
1050                 log 1 "checking revision... svn detection (tag)"
1051         elif [ -d "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
1052                 log 1 "checking revision... git detection"
1053         elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`HGPLAIN= hg help 2>/dev/null`" ]; then
1054                 log 1 "checking revision... hg detection"
1055         elif [ -f "$ROOT_DIR/.ottdrev" ]; then
1056                 log 1 "checking revision... source tarball"
1057         else
1058                 log 1 "checking revision... no detection"
1059                 log 1 "WARNING: there is no means to determine the version."
1060                 log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenTTD."
1061                 log 1 "WARNING: you can only join game servers that have been compiled without"
1062                 log 1 "WARNING:   version detection."
1063                 log 1 "WARNING: there is a great chance you desync."
1064                 log 1 "WARNING: USE WITH CAUTION!"
1066                 sleep 5
1067         fi
1069         if [ "$doc_dir" = "1" ]; then
1070                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1071                         doc_dir="share/doc/openttd"
1072                 else
1073                         doc_dir="$data_dir/docs"
1074                 fi
1075         else
1076                 doc_dir="`echo $doc_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1077         fi
1079         if [ "$icon_theme_dir" = "1" ]; then
1080                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1081                         icon_theme_dir="share/icons/hicolor"
1082                 else
1083                         icon_theme_dir=""
1084                 fi
1085         else
1086                 icon_theme_dir="`echo $icon_theme_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1087         fi
1089         if [ "$personal_dir" = "1" ]; then
1090                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ] || [ "$os" = "DOS" ] || [ "$os" = "HAIKU" ]; then
1091                         personal_dir="OpenTTD"
1092                 elif [ "$os" = "OSX" ]; then
1093                         personal_dir="Documents/OpenTTD"
1094                 else
1095                         personal_dir=".openttd"
1096                 fi
1097         else
1098                 personal_dir="`echo $personal_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1099         fi
1101         if [ "$shared_dir" = "1" ]; then
1102                 # we are using default values
1103                 if [ "$os" = "OSX" ]; then
1104                         shared_dir="/Library/Application\\\\ Support/OpenTTD"
1105                 else
1106                         shared_dir=""
1107                 fi
1108         else
1109                 shared_dir="`echo $shared_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1110         fi
1112         if [ "$man_dir" = "1" ]; then
1113                 # add manpage on UNIX systems
1114                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OSX" ]; then
1115                         man_dir="share/man/man6"
1116                 else
1117                         man_dir=""
1118                 fi
1119         else
1120                 man_dir="`echo $man_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1121         fi
1123         if [ "$menu_dir" = "1" ]; then
1124                 # add a freedesktop menu item only for some UNIX systems
1125                 if [ "$os" = "UNIX" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ]; then
1126                         menu_dir="share/applications"
1127                 else
1128                         menu_dir=""
1129                 fi
1130         else
1131                 menu_dir="`echo $menu_dir | sed 's@\([^\]\)\\\\ @\1\\\\\\\\ @g;s@\([^\]\) @\1\\\\\\\\ @g'`"
1132         fi
1134         detect_iconv
1136         if [ -n "$personal_dir" ]
1137         then
1138                 log 1 "personal home directory... $personal_dir"
1139         else
1140                 log 1 "personal home directory... none"
1141         fi
1143         if [ -n "$shared_dir" ]
1144         then
1145                 log 1 "shared data directory... $shared_dir"
1146         else
1147                 log 1 "shared data directory... none"
1148         fi
1150         if [ -n "$install_dir" ]
1151         then
1152                 log 1 "installation directory... $install_dir"
1153         else
1154                 log 1 "installation directory... none"
1155         fi
1157         if [ -n "$icon_theme_dir" ]
1158         then
1159                 log 1 "icon theme directory... $icon_theme_dir"
1160         else
1161                 log 1 "icon theme directory... none"
1162         fi
1164         if [ -n "$man_dir" ]
1165         then
1166                 log 1 "manual page directory... $man_dir"
1167         else
1168                 log 1 "manual page directory... none"
1169         fi
1171         if [ -n "$menu_dir" ]
1172         then
1173                 log 1 "menu item directory... $menu_dir"
1174         else
1175                 log 1 "menu item directory... none"
1176         fi
1179 make_compiler_cflags() {
1180         # Params:
1181         # $1 - compiler
1182         # $2 - name of the cflags variable
1183         # $3 - name of the cxxflags variable
1184         # $4 - name of the ldflags variable
1185         # $5 - name of the features variable
1187         eval eval "flags=\\\$$2"
1188         eval eval "cxxflags=\\\$$3"
1189         eval eval "ldflags=\\\$$4"
1190         eval eval "features=\\\$$5"
1192         if [ `basename $1 | cut -c 1-3` = "icc" ]; then
1193                 # Enable some things only for certain ICC versions
1194                 cc_version=`$1 -dumpversion | cut -c 1-4 | sed s@\\\.@@g`
1196                 flags="$flags -rdynamic"
1197                 ldflags="$ldflags -rdynamic"
1199                 if [ -z "$first_time_icc_check" ]; then
1200                         first_time_icc_check=no
1201                         if [ $cc_version -lt 90 ]; then
1202                                 log 1 "WARNING: you seem to be using a very old version of ICC"
1203                                 log 1 "WARNING: OpenTTD hasn't been tested with this version"
1204                                 sleep 5
1205                         elif [ $cc_version -lt 120 ]; then
1206                                 log 1 "WARNING: you seem to be using an unsupported ICC version"
1207                                 log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenTTD"
1208                                 sleep 5
1209                         fi
1210                 fi
1212                 flags="$flags -Wall"
1213                 # remark #111: statement is unreachable
1214                 flags="$flags -wd111"
1215                 # remark #181: argument is incompatible with corresponding format string conversion
1216                 # ICC is very picky about signedness of operands, warnings provided by GCC are enough
1217                 flags="$flags -wd181"
1218                 # remark #271: trailing comma is nonstandard
1219                 flags="$flags -wd271"
1220                 # remark #280: selector expression is constant
1221                 flags="$flags -wd280"
1222                 # remark #304: access control not specified ("public" by default)
1223                 flags="$flags -wd304"
1224                 # remark #383: value copied to temporary, reference to temporary used
1225                 flags="$flags -wd383"
1226                 # remark #444: destructor for base class ... is not virtual
1227                 flags="$flags -wd444"
1228                 # remark #593: variable ... was set but never used
1229                 flags="$flags -wd593"
1230                 # warning #654: overloaded virtual function ... is only partially overridden in class ...
1231                 flags="$flags -wd654"
1232                 # remark #810: conversion from ... to ... may lose significant bits
1233                 flags="$flags -wd810"
1234                 # remark #869: parameter ... was never referenced
1235                 flags="$flags -wd869"
1236                 # warning #873: function ... ::operator new ... has no corresponding operator delete ...
1237                 flags="$flags -wd873"
1238                 # remark #981: operands are evaluated in unspecified order
1239                 flags="$flags -wd981"
1240                 # remark #1418: external function definition with no prior declaration
1241                 flags="$flags -wd1418"
1242                 # remark #1419: external declaration in primary source file
1243                 flags="$flags -wd1419"
1244                 # remark #1572: floating-point equality and inequality
1245                 flags="$flags -wd1572"
1246                 # remark #1599: declaration hides variable/parameter ...
1247                 flags="$flags -wd1599"
1248                 # remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
1249                 flags="$flags -wd1720"
1251                 if [ $cc_version -lt 110 ]; then
1252                         # warns about system headers with recent glibc:
1253                         # warning #1292: attribute "__nonnull__" ignored
1254                         flags="$flags -wd1292"
1255                 fi
1257                 if [ $cc_version -ge 100 ]; then
1258                         # warning #1899: multicharacter character literal (potential portability problem)
1259                         flags="$flags -wd1899"
1260                         # vec report defaults to telling where it did loop vectorisation, which is not very important
1261                         flags="$flags -vec-report=0 "
1262                 fi
1264                 if [ $cc_version -ge 110 ]; then
1265                         # remark #2259: non-pointer conversion from ... to ... may lose significant bits
1266                         flags="$flags -wd2259"
1267                         # Use c++0x mode so static_assert() is available
1268                         cxxflags="$cxxflags -std=c++0x"
1269                 fi
1271                 if [ "$enable_lto" != "0" ]; then
1272                         has_ipo=`$1 -help ipo | grep '\-ipo'`
1273                         if [ -n "$has_ipo" ]; then
1274                                 # Use IPO (only if we see IPO exists and is requested)
1275                                 flags="$flags -ipo"
1276                                 features="$features lto"
1277                         fi
1278                 fi
1279         elif [ `basename $1 | grep 'clang'` ]; then
1280                 # Enable some things only for certain clang versions
1281                 cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
1283                 # aliasing rules are not held in openttd code
1284                 flags="$flags -fno-strict-aliasing"
1286                 # -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
1287                 # -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
1288                 flags="$flags -Wall -W -Wextra"
1290                 # warning: unused parameter '...'
1291                 flags="$flags -Wno-unused-parameter"
1293                 # warning: expression result unused
1294                 flags="$flags -Wno-unused-value"
1296                 # warning: multi-character character constant
1297                 flags="$flags -Wno-multichar"
1299                 # warning: explicitly assigning a variable of type '...' to itself
1300                 # it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
1301                 flags="$flags -Wno-self-assign"
1303                 if [ "$cc_version" -lt "30" ]; then
1304                         # warning: equality comparison with extraneous parentheses
1305                         flags="$flags -Wno-parentheses"
1306                         # warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
1307                         flags="$flags -Wno-sign-compare"
1308                 fi
1310                 if [ "$cc_version" -ge "30" ]; then
1311                         # warning: equality comparison with extraneous parentheses
1312                         # this warning could be useful, but it warns about code in squirrel
1313                         flags="$flags -Wno-parentheses-equality"
1314                 fi
1316                 if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
1317                         # ccache and distcc run separate preprocess and compile passes,
1318                         # both are fed with the same CFLAGS. Unfortunately, clang
1319                         # complains about -I when compiling preprocessed files:
1320                         # "clang: warning: argument unused during compilation: '-I /usr/include'"
1321                         flags="$flags -Qunused-arguments"
1322                 fi
1324                 if [ "$enable_assert" -eq "0" ]; then
1325                         # do not warn about unused variables when building without asserts
1326                         flags="$flags -Wno-unused-variable"
1327                 fi
1329                 if [ "$cc_version" -ge "33" ]; then
1330                         # clang completed C++11 support in version 3.3
1331                         flags="$flags -std=c++11"
1332                 fi
1334                 # rdynamic is used to get useful stack traces from crash reports.
1335                 ldflags="$ldflags -rdynamic"
1336         else
1337                 # Enable some things only for certain GCC versions
1338                 # cc_version = major_version * 100 + minor_version
1339                 # For example: "3.3" -> 303, "4.9.2" -> 409, "6" -> 600, "23.5" -> 2305
1340                 cc_version=`$1 -dumpversion | $awk -F . '{printf "%d%02d", $1, $2}'`
1342                 if [ $cc_version -lt 303 ]; then
1343                         log 1 "configure: error: gcc older than 3.3 can't compile OpenTTD because of its poor template support"
1344                         exit 1
1345                 fi
1347                 flags="$flags -Wall -Wno-multichar -Wsign-compare -Wundef"
1348                 flags="$flags -Wwrite-strings -Wpointer-arith"
1349                 flags="$flags -W -Wno-unused-parameter -Wredundant-decls"
1350                 flags="$flags -Wformat=2 -Wformat-security"
1352                 if [ $enable_assert -eq 0 ]; then
1353                         # Do not warn about unused variables when building without asserts
1354                         flags="$flags -Wno-unused-variable"
1355                         if [ $cc_version -ge 406 ]; then
1356                                 # GCC 4.6 gives more warnings, disable them too
1357                                 flags="$flags -Wno-unused-but-set-variable"
1358                                 flags="$flags -Wno-unused-but-set-parameter"
1359                         fi
1360                 fi
1362                 if [ $cc_version -ge 304 ]; then
1363                         # Warn when a variable is used to initialise itself:
1364                         # int a = a;
1365                         flags="$flags -Winit-self"
1366                 fi
1368                 if [ $cc_version -ge 400 ]; then
1369                         # GCC 4.0+ complains about that we break strict-aliasing.
1370                         #  On most places we don't see how to fix it, and it doesn't
1371                         #  break anything. So disable strict-aliasing to make the
1372                         #  compiler all happy.
1373                         flags="$flags -fno-strict-aliasing"
1374                         # Warn about casting-out 'const' with regular C-style cast.
1375                         #  The preferred way is const_cast<>() which doesn't warn.
1376                         flags="$flags -Wcast-qual"
1377                 fi
1379                 if [ $cc_version -ge 402 ]; then
1380                         # GCC 4.2+ automatically assumes that signed overflows do
1381                         # not occur in signed arithmetics, whereas we are not
1382                         # sure that they will not happen. It furthermore complains
1383                         # about its own optimized code in some places.
1384                         flags="$flags -fno-strict-overflow"
1385                         # GCC 4.2 no longer includes -Wnon-virtual-dtor in -Wall.
1386                         # Enable it in order to be consistent with older GCC versions.
1387                         flags="$flags -Wnon-virtual-dtor"
1388                 fi
1390                 if [ $cc_version -ge 403 ] && [ $cc_version -lt 600 ]; then
1391                         # Use gnu++0x mode so static_assert() is available.
1392                         # Don't use c++0x, it breaks mingw (with gcc 4.4.0).
1393                         cxxflags="$cxxflags -std=gnu++0x"
1394                 fi
1396                 if [ $cc_version -eq 405 ]; then
1397                         # Prevent optimisation supposing enums are in a range specified by the standard
1398                         # For details, see http://gcc.gnu.org/PR43680
1399                         flags="$flags -fno-tree-vrp"
1400                 fi
1402                 if [ $cc_version -eq 407 ]; then
1403                         # Disable -Wnarrowing which gives many warnings, such as:
1404                         # warning: narrowing conversion of '...' from 'unsigned int' to 'int' inside { } [-Wnarrowing]
1405                         # They are valid according to the C++ standard, but useless.
1406                         cxxflags="$cxxflags -Wno-narrowing"
1407                 fi
1409                 if [ $cc_version -ge 407 ]; then
1410                         # Disable bogus 'attempt to free a non-heap object' warning
1411                         flags="$flags -Wno-free-nonheap-object"
1412                 fi
1414                 if [ $cc_version -ge 600 ]; then
1415                         # -flifetime-dse=2 (default since GCC 6) doesn't play
1416                         # well with our custom pool item allocator
1417                         cxxflags="$cxxflags -flifetime-dse=1 -std=gnu++14"
1418                 fi
1420                 if [ "$enable_lto" != "0" ]; then
1421                         # GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
1422                         has_lto=`$1 -dumpspecs | grep '\%{flto'`
1423                         if [ -n "$has_lto" ]; then
1424                                 # Use LTO only if we see LTO exists and is requested
1425                                 if [ $cc_version -lt 406 ]; then
1426                                         flags="$flags -flto"
1427                                 else
1428                                         flags="$flags -flto=jobserver"
1429                                 fi
1430                                 ldflags="$ldflags -fwhole-program"
1431                                 features="$features lto"
1432                         fi
1433                 fi
1435                 has_rdynamic=`$1 -dumpspecs | grep rdynamic`
1436                 if [ -n "$has_rdynamic" ]; then
1437                         # rdynamic is used to get useful stack traces from crash reports.
1438                         flags="$flags -rdynamic"
1439                         ldflags="$ldflags -rdynamic"
1440                 fi
1441         fi
1443         eval "$2=\"$flags\""
1444         eval "$3=\"$cxxflags\""
1445         eval "$4=\"$ldflags\""
1446         eval "$5=\"$features\""
1449 make_cflags_and_ldflags() {
1450         # General CFlags for BUILD
1451         CFLAGS_BUILD="$CFLAGS_BUILD"
1452         # Special CXXFlags for BUILD
1453         CXXFLAGS_BUILD="$CXXFLAGS_BUILD"
1454         # LDFLAGS for BUILD
1455         LDFLAGS_BUILD="$LDFLAGS_BUILD"
1456         # FEATURES for BUILD (lto)
1457         FEATURES_BUILD=""
1458         # General CFlags for HOST
1459         CFLAGS="$CFLAGS"
1460         # Special CXXFlags for HOST
1461         CXXFLAGS="$CXXFLAGS"
1462         # Libs to compile. In fact this is just LDFLAGS
1463         LIBS="-lstdc++"
1464         # LDFLAGS used for HOST
1465         LDFLAGS="$LDFLAGS"
1466         # FEATURES for HOST (lto)
1467         FEATURES=""
1469         make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "CXXFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
1470         make_compiler_cflags "$cc_host" "CFLAGS" "CXXFLAGS" "LDFLAGS" "FEATURES"
1472         CFLAGS="$CFLAGS -D$os"
1473         CFLAGS_BUILD="$CFLAGS_BUILD -D$os"
1475         if [ "$enable_debug" = "0" ]; then
1476                 # No debug, add default stuff
1477                 OBJS_SUBDIR="release"
1478                 if [ "$os" = "MORPHOS" ]; then
1479                         CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
1480                         LDFLAGS="$LDFLAGS -noixemul"
1481                 fi
1483                 if [ "$enable_profiling" = "0" ]; then
1484                         # -fomit-frame-pointer and -pg do not go well together (gcc errors they are incompatible)
1485                         CFLAGS="-fomit-frame-pointer $CFLAGS"
1486                 fi
1487                 CFLAGS="-O2 $CFLAGS"
1488         else
1489                 OBJS_SUBDIR="debug"
1491                 # Each debug level reduces the optimization by a bit
1492                 if [ $enable_debug -ge 1 ]; then
1493                         CFLAGS="$CFLAGS -g -D_DEBUG"
1494                         if [ "$os" = "PSP" ]; then
1495                                 CFLAGS="$CFLAGS -G0"
1496                         fi
1497                 fi
1498                 if [ $enable_debug -ge 2 ]; then
1499                         CFLAGS="$CFLAGS -fno-inline"
1500                 fi
1501                 if [ $enable_debug -ge 3 ]; then
1502                         CFLAGS="$CFLAGS -O0"
1503                 else
1504                         CFLAGS="$CFLAGS -O2"
1505                 fi
1506         fi
1508         if [ $enable_debug -le 2 ]; then
1509                 cc_host_is_gcc=`basename "$cc_host" | grep "gcc" 2>/dev/null`
1510                 if [ -n "$cc_host_is_gcc" ]; then
1511                         # Define only when compiling with GCC. Some GLIBC versions use GNU
1512                         # extensions in a way that breaks build with at least ICC.
1513                         # This requires -O1 or more, so debug level 3 (-O0) is excluded.
1514                         CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
1515                 fi
1517                 cc_build_is_gcc=`basename "$cc_build" | grep "gcc" 2>/dev/null`
1518                 if [ -n "$cc_build_is_gcc" ]; then
1519                         # Just add -O1 to the tools needed for building.
1520                         CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
1521                 fi
1522         fi
1524         if [ "$os" = "OSX" ] && [ $cc_version -eq 400 ]; then
1525                 # Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
1526                 # wrongly optimizing ^= in loops. This disables the failing optimisation.
1527                 CFLAGS="$CFLAGS -fno-expensive-optimizations"
1528         fi
1530         if [ "$enable_profiling" != "0" ]; then
1531                 CFLAGS="$CFLAGS -pg"
1532                 LDFLAGS="$LDFLAGS -pg"
1533         fi
1535         if [ "$with_threads" = "0" ]; then
1536                 CFLAGS="$CFLAGS -DNO_THREADS"
1537         fi
1538         if [ "$with_sse" = "1" ]; then
1539                 CFLAGS="$CFLAGS -DWITH_SSE"
1540         fi
1542         if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
1543                 if [ "$os" = "CYGWIN" ]; then
1544                         flags="$flags -mwin32"
1545                         LDFLAGS="$LDFLAGS -mwin32"
1546                 fi
1547                 if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
1548                         if [ $cc_version -lt 406 ]; then
1549                                 flags="$flags -mno-cygwin"
1550                                 LDFLAGS="$LDFLAGS -mno-cygwin"
1551                         fi
1553                         if [ "$enable_console" != "0" ]; then
1554                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,console"
1555                         else
1556                                 LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
1557                         fi
1559                         LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
1561                         if [ $cc_version -ge 404 ]; then
1562                                 LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
1563                         fi
1564                         if [ $cc_version -ge 407 ]; then
1565                                 CFLAGS="$CFLAGS -mno-ms-bitfields"
1566                         fi
1567                 fi
1568         fi
1570         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
1571                 LIBS="$LIBS -lpthread"
1572         fi
1574         if [ "$os" != "CYGWIN" ] && [ "$os" != "HAIKU" ] && [ "$os" != "MINGW" ] && [ "$os" != "DOS" ] && [ "$os" != "WINCE" ]; then
1575                 LIBS="$LIBS -lc"
1576         fi
1577         if [ "$os" = "WINCE" ]; then
1578                 LIBS="$LIBS -lcoredll -lcorelibc -laygshell -lws2 -e WinMainCRTStartup"
1579         fi
1580         if [ "$os" = "PSP" ]; then
1581                 CFLAGS="$CFLAGS -I`$psp_config -p`/include"
1582                 LDFLAGS="$LDFLAGS -L`$psp_config -p`/lib"
1584                 CFLAGS="$CFLAGS -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150"
1585                 LIBS="$LIBS -D_PSP_FW_VERSION=150 -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lm"
1586         fi
1588         if [ "$os" = "MORPHOS" ]; then
1589                 # -Wstrict-prototypes generates much noise because of system headers
1590                 CFLAGS="$CFLAGS -Wno-strict-prototypes"
1591         fi
1593         if [ "$os" = "OPENBSD" ]; then
1594                 LIBS="$LIBS -pthread"
1595         fi
1597         if [ "$os" = "OSX" ]; then
1598                 LDFLAGS="$LDFLAGS -framework Cocoa"
1600                 # Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
1601                 CFLAGS="$CFLAGS -isystem/opt/local/include"
1603                 if [ "$enable_dedicated" = "0" ] && ([ "$cpu_type" = "32" ] || [ "$enable_universal" != "0" ]); then
1604                         LIBS="$LIBS -framework QuickTime"
1605                 else
1606                         CFLAGS="$CFLAGS -DNO_QUICKTIME"
1607                 fi
1609                 if [ "$enable_universal" = "0" ]; then
1610                         # Universal builds set this elsewhere
1611                         CFLAGS="$OSX_SYSROOT $CFLAGS"
1612                         LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
1613                 fi
1614         fi
1616         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ]; then
1617                 LIBS="$LIBS -lmidi -lbe"
1618         fi
1620         # Most targets act like UNIX, just with some additions
1621         if [ "$os" = "BEOS" ] || [ "$os" = "HAIKU" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "DRAGONFLY" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
1622                 CFLAGS="$CFLAGS -DUNIX"
1623         fi
1624         # And others like Windows
1625         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
1626                 CFLAGS="$CFLAGS -DWIN"
1627         fi
1629         if [ -n "$allegro_config" ]; then
1630                 CFLAGS="$CFLAGS -DWITH_ALLEGRO"
1631                 CFLAGS="$CFLAGS `$allegro_config --cflags`"
1632                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1633                         if [ "$enable_static" != "0" ]; then
1634                                 LIBS="$LIBS `$allegro_config --static --libs`"
1635                         else
1636                                 LIBS="$LIBS `$allegro_config --libs`"
1637                         fi
1638                 fi
1639         fi
1641         if [ -n "$sdl_config" ]; then
1642                 CFLAGS="$CFLAGS -DWITH_SDL"
1643                 # SDL must not add _GNU_SOURCE as it breaks many platforms
1644                 CFLAGS="$CFLAGS `$sdl_config --cflags | sed 's@-D_GNU_SOURCE[^ ]*@@'`"
1645                 if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
1646                         if [ "$enable_static" != "0" ]; then
1647                                 LIBS="$LIBS `$sdl_config --static-libs`"
1648                         else
1649                                 LIBS="$LIBS `$sdl_config --libs`"
1650                         fi
1651                 fi
1652         fi
1654         if [ "$with_cocoa" != "0" ]; then
1655                 CFLAGS="$CFLAGS -DWITH_COCOA"
1656                 LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox"
1658                 if [ "$enable_cocoa_quartz" != "0" ]; then
1659                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUARTZ"
1660                 fi
1662                 if [ "$enable_cocoa_quickdraw" != "0" ]; then
1663                         CFLAGS="$CFLAGS -DENABLE_COCOA_QUICKDRAW"
1664                 fi
1665         fi
1667         if [ "$with_zlib" != "0" ]; then
1668                 CFLAGS="$CFLAGS -DWITH_ZLIB"
1669                 CFLAGS="$CFLAGS `$zlib_config --cflags | tr '\n\r' '  '`"
1670                 if [ "$enable_static" != "0" ]; then
1671                         LIBS="$LIBS `$zlib_config --libs --static | tr '\n\r' '  '`"
1672                 else
1673                         LIBS="$LIBS `$zlib_config --libs | tr '\n\r' '  '`"
1674                 fi
1675         fi
1677         if [ -n "$lzma_config" ]; then
1678                 CFLAGS="$CFLAGS -DWITH_LZMA"
1679                 CFLAGS="$CFLAGS `$lzma_config --cflags | tr '\n\r' '  '`"
1681                 if [ "$enable_static" != "0" ]; then
1682                         CFLAGS="$CFLAGS -DLZMA_API_STATIC"
1683                         LIBS="$LIBS `$lzma_config --libs --static | tr '\n\r' '  '`"
1684                 else
1685                         LIBS="$LIBS `$lzma_config --libs | tr '\n\r' '  '`"
1686                 fi
1687         fi
1689         if [ "$with_lzo2" != "0" ]; then
1690                 if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
1691                         LIBS="$LIBS $lzo2"
1692                 else
1693                         LIBS="$LIBS -llzo2"
1694                 fi
1695                 CFLAGS="$CFLAGS -DWITH_LZO"
1696         fi
1698         if [ -n "$xdg_basedir_config" ]; then
1699                 CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
1700                 CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
1702                 if [ "$enable_static" != "0" ]; then
1703                         LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
1704                 else
1705                         LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
1706                 fi
1707         fi
1709         # 64bit machines need -D_SQ64
1710         if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
1711                 CFLAGS="$CFLAGS -D_SQ64"
1712         fi
1713         CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
1715         if [ -n "$png_config" ]; then
1716                 CFLAGS="$CFLAGS -DWITH_PNG"
1717                 CFLAGS="$CFLAGS `$png_config --cflags | tr '\n\r' '  '`"
1719                 if [ "$enable_static" != "0" ]; then
1720                         LIBS="$LIBS `$png_config --libs --static | tr '\n\r' '  '`"
1721                 else
1722                         LIBS="$LIBS `$png_config --libs | tr '\n\r' '  '`"
1723                 fi
1724         fi
1726         if [ -n "$fontconfig_config" ]; then
1727                 CFLAGS="$CFLAGS -DWITH_FONTCONFIG"
1728                 CFLAGS="$CFLAGS `$fontconfig_config --cflags | tr '\n\r' '  '`"
1730                 if [ "$enable_static" != "0" ]; then
1731                         LIBS="$LIBS `$fontconfig_config --libs --static | tr '\n\r' '  '`"
1732                 else
1733                         LIBS="$LIBS `$fontconfig_config --libs | tr '\n\r' '  '`"
1734                 fi
1735         fi
1737         if [ -n "$freetype_config" ]; then
1738                 CFLAGS="$CFLAGS -DWITH_FREETYPE"
1739                 CFLAGS="$CFLAGS `$freetype_config --cflags | tr '\n\r' '  '`"
1741                 if [ "$enable_static" != "0" ]; then
1742                         LIBS="$LIBS `$freetype_config --libs --static | tr '\n\r' '  '`"
1743                 else
1744                         LIBS="$LIBS `$freetype_config --libs | tr '\n\r' '  '`"
1745                 fi
1746         fi
1748         if [ -n "$icu_layout_config" ]; then
1749                 CFLAGS="$CFLAGS -DWITH_ICU_LAYOUT"
1750                 CFLAGS="$CFLAGS `$icu_layout_config --cflags | tr '\n\r' '  '`"
1752                 if [ "$static_icu" != "0" ]; then
1753                         LIBS="$LIBS `$icu_layout_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1754                 else
1755                         LIBS="$LIBS `$icu_layout_config --libs | tr '\n\r' '  '`"
1756                 fi
1757         fi
1759         if [ -n "$icu_sort_config" ]; then
1760                 CFLAGS="$CFLAGS -DWITH_ICU_SORT"
1761                 CFLAGS="$CFLAGS `$icu_sort_config --cflags | tr '\n\r' '  '`"
1763                 if [ "$static_icu" != "0" ]; then
1764                         LIBS="$LIBS `$icu_sort_config --libs --static | tr '\n\r' '  ' | sed s/-licu/-lsicu/g`"
1765                 else
1766                         LIBS="$LIBS `$icu_sort_config --libs | tr '\n\r' '  '`"
1767                 fi
1768         fi
1771         if [ "$with_direct_music" != "0" ]; then
1772                 CFLAGS="$CFLAGS -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT"
1773                 # GCC 4.0+ doesn't like the DirectX includes (gives tons of
1774                 #  warnings on it we won't be able to fix). For now just
1775                 #  suppress those warnings.
1776                 if [ $cc_version -ge 400 ]; then
1777                         CFLAGS="$CFLAGS -Wno-non-virtual-dtor"
1778                 fi
1779         fi
1781         if [ -n "$libtimidity_config" ]; then
1782                 CFLAGS="$CFLAGS -DLIBTIMIDITY"
1783                 CFLAGS="$CFLAGS `$libtimidity_config --cflags | tr '\n\r' '  '`"
1785                 if [ "$enable_static" != "0" ]; then
1786                         LIBS="$LIBS `$libtimidity_config --libs --static | tr '\n\r' '  '`"
1787                 else
1788                         LIBS="$LIBS `$libtimidity_config --libs | tr '\n\r' '  '`"
1789                 fi
1790         fi
1792         if [ "$with_iconv" != "0" ]; then
1793                 CFLAGS="$CFLAGS -DWITH_ICONV"
1794                 if [ "$link_to_iconv" = "yes" ]; then
1795                         LIBS="$LIBS -liconv"
1796                         if [ "$with_iconv" != "2" ]; then
1797                                 CFLAGS="$CFLAGS -I$with_iconv/include"
1798                                 LIBS="$LIBS -L$with_iconv/lib"
1799                         fi
1800                 fi
1802                 if [ "$os" != "OSX" ] && [ "$have_non_const_iconv" != "no" ]; then
1803                         CFLAGS="$CFLAGS -DHAVE_NON_CONST_ICONV"
1804                 fi
1805         fi
1807         if [ -n "$with_midi" ]; then
1808                 CFLAGS="$CFLAGS -DEXTERNAL_PLAYER=\\\\\"$with_midi\\\\\""
1809         fi
1810         if [ -n "$with_midi_arg" ]; then
1811                 CFLAGS="$CFLAGS -DMIDI_ARG=\\\\\"$with_midi_arg\\\\\""
1812         fi
1814         if [ "$enable_dedicated" != "0" ]; then
1815                 CFLAGS="$CFLAGS -DDEDICATED"
1816         fi
1818         if [ "$enable_unicode" != "0" ]; then
1819                 CFLAGS="$CFLAGS -DUNICODE -D_UNICODE"
1820         fi
1822         if [ "$enable_network" != "0" ]; then
1823                 CFLAGS="$CFLAGS -DENABLE_NETWORK"
1825                 if [ "$os" = "BEOS" ]; then
1826                         LDFLAGS="$LDFLAGS -lbind -lsocket"
1827                 fi
1829                 if [ "$os" = "HAIKU" ]; then
1830                         LDFLAGS="$LDFLAGS -lnetwork"
1831                 fi
1833                 if [ "$os" = "SUNOS" ]; then
1834                         LDFLAGS="$LDFLAGS -lnsl -lsocket"
1835                 fi
1836         fi
1838         if [ "$enable_static" != "0" ]; then
1839                 # OSX can't handle -static in LDFLAGS
1840                 if [ "$os" != "OSX" ]; then
1841                         LDFLAGS="$LDFLAGS -static"
1842                 fi
1843         fi
1845         if [ "$enable_assert" = "0" ]; then
1846                 CFLAGS="$CFLAGS -DNDEBUG"
1847                 CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
1848         fi
1850         if [ "$enable_desync_debug" != "0" ]; then
1851                 CFLAGS="$CFLAGS -DRANDOM_DEBUG"
1852         fi
1854         if [ "$enable_osx_g5" != "0" ]; then
1855                 CFLAGS="$CFLAGS -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
1856         fi
1858         if [ -n "$personal_dir" ]; then
1859                 CFLAGS="$CFLAGS -DWITH_PERSONAL_DIR -DPERSONAL_DIR=\\\\\"$personal_dir\\\\\""
1860         fi
1862         if [ -n "$shared_dir" ]; then
1863                 CFLAGS="$CFLAGS -DWITH_SHARED_DIR -DSHARED_DIR=\\\\\"$shared_dir\\\\\""
1864         fi
1866         CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
1868         if [ "$enable_lto" != "0" ]; then
1869                 lto_build=`echo "$FEATURES_BUILD" | grep "lto"`
1870                 lto_host=`echo "$FEATURES" | grep "lto"`
1871                 if [ -z "$lto_build$lto_host" ]; then
1872                         log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
1873                         log 1 "WARNING: LTO/IPO has been disabled"
1874                 fi
1875                 if [ -n "$lto_build" ]; then
1876                         LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
1877                 fi
1878                 if [ -n "$lto_host" ]; then
1879                         LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
1880                 fi
1881         fi
1883         log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD"
1884         log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD"
1885         log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD"
1886         log 1 "using CFLAGS... $CFLAGS"
1887         log 1 "using CXXFLAGS... $CXXFLAGS"
1888         log 1 "using LDFLAGS... $LIBS $LDFLAGS"
1890         # Makedepend doesn't like something like: -isysroot /OSX/blabla
1891         #  so convert it to: -isysroot -OSX/blabla. makedepend just ignores
1892         #  any - command it doesn't know, so we are pretty save.
1893         # Lovely hackish, not?
1894         # Btw, this almost always comes from outside the configure, so it is
1895         #  not something we can control.
1896         # Also make makedepend aware of compiler's built-in defines.
1897         if [ "$with_makedepend" != "0" ] || [ "$enable_builtin_depend" != "0" ]; then
1898                 # Append CXXFLAGS possibly containing -std=c++0x
1899                 cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
1901                 # Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
1902                 cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
1903         else
1904                 makedepend=""
1905         fi
1907         if [ "$with_distcc" != "0" ]; then
1908                 cc_host="$distcc $cc_host"
1909                 cxx_host="$distcc $cxx_host"
1910                 log 1 ""
1911                 log 1 " NOTICE: remind yourself to use 'make -jN' to make use of distcc"
1912                 log 1 ""
1913         fi
1915         if [ "$with_ccache" != "0" ]; then
1916                 cc_host="$ccache $cc_host"
1917                 cxx_host="$ccache $cxx_host"
1918         fi
1921 check_compiler() {
1922         # Params:
1923         # $1 - Type for message (build / host)
1924         # $2 - What to fill with the found compiler
1925         # $3 - System to try
1926         # $4 - Compiler to try
1927         # $5 - Env-setting to try
1928         # $6 - GCC alike to try
1929         # $7 - CC alike to try
1930         # $8 - "0" gcc, "1" g++, "2" windres, "3" strip, "4" lipo
1931         # $9 - What the command is to check for
1933         if [ -n "$3" ]; then
1934                 # Check for system
1935                 if [ -z "$6" ]; then
1936                         compiler="$3"
1937                 else
1938                         compiler="$3-$6"
1939                 fi
1940                 machine=`eval $compiler $9 2>/dev/null`
1941                 ret=$?
1942                 eval "$2=\"$compiler\""
1944                 log 2 "executing $compiler $9"
1945                 log 2 "  returned $machine"
1946                 log 2 "  exit code $ret"
1948                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1949                         if [ -z "$5" ]; then
1950                                 log 1 "checking $1... $compiler not found"
1951                                 log 1 "I couldn't detect any $6 binary for $3"
1952                                 exit 1
1953                         else
1954                                 compiler="$3-$5"
1955                         fi
1956                         machine=`eval $compiler $9 2>/dev/null`
1957                         ret=$?
1958                         eval "$2=\"$compiler\""
1960                         log 2 "executing $compiler $9"
1961                         log 2 "  returned $machine"
1962                         log 2 "  exit code $ret"
1964                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1965                                 log 1 "checking $1... $compiler not found"
1966                                 log 1 "I couldn't detect any $5 binary for $3"
1967                                 exit 1
1968                         fi
1969                 fi
1971                 if [ "$machine" != "$3" ] && ( [ "$8" = "0" ] || [ "$8" = "1" ] ); then
1972                         log 1 "checking $1... expected $3, found $machine"
1973                         log 1 "the compiler suggests it doesn't build code for the machine you specified"
1974                         exit 1
1975                 fi
1976         elif [ -n "$4" ]; then
1977                 # Check for manual compiler
1978                 machine=`$4 $9 2>/dev/null`
1979                 ret=$?
1980                 eval "$2=\"$4\""
1982                 log 2 "executing $4 $9"
1983                 log 2 "  returned $machine"
1984                 log 2 "  exit code $ret"
1986                 if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
1987                         log 1 "checking $1... $4 not found"
1988                         log 1 "the selected binary doesn't seem to be a $6 binary"
1989                         exit 1
1990                 fi
1991         else
1992                 # Nothing given, autodetect
1994                 if [ -n "$5" ]; then
1995                         machine=`$5 $9 2>/dev/null`
1996                         ret=$?
1997                         eval "$2=\"$5\""
1999                         log 2 "executing $5 $9"
2000                         log 2 "  returned $machine"
2001                         log 2 "  exit code $ret"
2003                         # The user defined a GCC that doesn't reply to $9.. abort
2004                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2005                                 log 1 "checking $1... $5 unusable"
2006                                 log 1 "the CC environment variable is set, but it doesn't seem to be a $6 binary"
2007                                 log 1 "please redefine the CC/CXX environment to a $6 binary"
2008                                 exit 1
2009                         fi
2010                 else
2011                         log 2 "checking $1... CC/CXX not set (skipping)"
2013                         # No $5, so try '$6'
2014                         machine=`$6 $9 2>/dev/null`
2015                         ret=$?
2016                         eval "$2=\"$6\""
2018                         log 2 "executing $6 $9"
2019                         log 2 "  returned $machine"
2020                         log 2 "  exit code $ret"
2022                         if ( [ -z "$machine" ] && [ "$8" != "3" ] ) || [ "$ret" != "0" ]; then
2023                                 # Maybe '$7'?
2024                                 machine=`$7 $9 2>/dev/null`
2025                                 ret=$?
2026                                 eval "$2=\"$7\""
2028                                 log 2 "executing $7 $9"
2029                                 log 2 "  returned $machine"
2030                                 log 2 "  exit code $ret"
2032                                 # All failed, abort
2033                                 if [ -z "$machine" ]; then
2034                                         log 1 "checking $1... $6 not found"
2035                                         log 1 "I couldn't detect any $6 binary on your system"
2036                                         log 1 "please define the CC/CXX environment to where it is located"
2038                                         exit 1
2039                                 fi
2040                         fi
2041                 fi
2042         fi
2044         if [ "$8" != "0" ]; then
2045                 eval "res=\$$2"
2046                 log 1 "checking $1... $res"
2047         else
2048                 log 1 "checking $1... $machine"
2049         fi
2052 check_build() {
2053         if [ "$os" = "FREEBSD" ]; then
2054                 # FreeBSD's C compiler does not support dump machine.
2055                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2056                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CXX" "g++" "c++" "0" "-dumpmachine"
2057         else
2058                 check_compiler "build system type" "cc_build" "$build" "$cc_build" "$CC" "gcc" "cc" "0" "-dumpmachine"
2059         fi
2062 check_host() {
2063         # By default the host is the build
2064         if [ -z "$host" ]; then host="$build"; fi
2066         if [ "$os" = "FREEBSD" ]; then
2067                 # FreeBSD's C compiler does not support dump machine.
2068                 # However, removing C support is not possible because PSP must be linked with the C compiler.
2069                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CXX" "g++" "c++" "0" "-dumpmachine"
2070         else
2071                 check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
2072         fi
2075 check_cxx_build() {
2076         check_compiler "build c++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
2079 check_cxx_host() {
2080         # By default the host is the build
2081         if [ -z "$host" ]; then host="$build"; fi
2082         check_compiler "host c++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
2085 check_windres() {
2086         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2087                 check_compiler "host windres" "windres" "$host" "$windres" "$WINDRES" "windres" "windres" "2" "-V"
2088         fi
2091 check_strip() {
2092         if [ "$os" = "OS2" ]; then
2093                 # OS2 via gcc is a bit weird.. stripping HAS to be done via emxbind, which is via gcc directly
2094                 log 1 "checking host strip... using gcc -s option"
2095         elif [ "$os" = "OSX" ]; then
2096                 # Most targets have -V in strip, to see if they exists... OSX doesn't.. so execute something
2097                 echo "int main(int argc, char *argv[]) { }" > strip.test.c
2098                 $cxx_host strip.test.c -o strip.test
2099                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "strip.test"
2100                 rm -f strip.test.c strip.test
2101         else
2102                 check_compiler "host strip" "strip" "$host" "$strip" "$STRIP" "strip" "strip" "3" "-V"
2103         fi
2106 check_lipo() {
2107         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
2108                 echo "int main(int argc, char *argv[]) { }" > lipo.test.c
2109                 $cxx_host lipo.test.c -o lipo.test
2110                 check_compiler "host lipo" "lipo" "$host" "$lipo" "$LIPO" "lipo" "lipo" "4" "-info lipo.test"
2111                 rm -f lipo.test.c lipo.test
2112         fi
2115 check_osx_sdk() {
2116         local sysroot=""
2117         if [ -n "$1" ]; then
2118                 if echo "$1" | grep -q / ; then
2119                         # Seems to be a file system path
2120                         osx_sdk_path="$1"
2121                 else
2122                         osx_sdk_path="/Developer/SDKs/MacOSX$1.sdk"
2123                 fi
2124                 if [ ! -d "$osx_sdk_path" ]; then
2125                         # No directory, not present or garbage
2126                         return 1
2127                 fi
2129                 # Set minimum version to 10.4 as that's when kCGBitmapByteOrder32Host was introduced
2130                 sysroot="-isysroot $osx_sdk_path -Wl,-syslibroot,$osx_sdk_path -mmacosx-version-min=10.4"
2131         fi
2133 cat > tmp.osx.mm << EOF
2134 #include <Cocoa/Cocoa.h>
2135 int main() {
2136         kCGBitmapByteOrder32Host;
2137         return 0;
2140         execute="$cxx_host $sysroot $CFLAGS tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2141         eval $execute > /dev/null
2142         ret=$?
2143         log 2 "executing $execute"
2144         log 2 "  exit code $ret"
2145         rm -f tmp.osx.mm tmp.osx
2146         return $ret
2149 check_direct_music() {
2150         echo "
2151                 #include <windows.h>
2152                 #include <dmksctrl.h>
2153                 #include <dmusici.h>
2154                 #include <dmusicc.h>
2155                 #include <dmusicf.h>
2156                 int main(int argc, char *argv[]) { }" > direct_music.test.c
2157         $cxx_host $CFLAGS direct_music.test.c -o direct_music.test 2> /dev/null
2158         res=$?
2159         rm -f direct_music.test.c direct_music.test
2161         if [ "$res" != "0" ]; then
2162                 if [ "$with_direct_music" != "1" ]; then
2163                         log 1 "configure: error: direct-music is not available on this system"
2164                         exit 1
2165                 fi
2166                 with_direct_music="0"
2168                 log 1 "checking direct-music... not found"
2169         else
2170                 log 1 "checking direct-music... found"
2171         fi
2174 check_makedepend() {
2175         if [ "$enable_builtin_depend" != "0" ]; then
2176                 with_makedepend="0"
2177         fi
2179         if [ "$with_makedepend" = "0" ]; then
2180                 log 1 "checking makedepend... disabled"
2181                 return
2182         fi
2184         if [ "$with_makedepend" = "1" ] || [ "$with_makedepend" = "2" ]; then
2185                 makedepend="makedepend"
2186         else
2187                 makedepend="$with_makedepend"
2188         fi
2190         rm -f makedepend.tmp
2191         touch makedepend.tmp
2192         res=`$makedepend -fmakedepend.tmp 2>/dev/null`
2193         res=$?
2194         log 2 "executing $makedepend -f makedepend.tmp"
2195         log 2 "  returned `cat makedepend.tmp`"
2196         log 2 "  exit code $ret"
2198         if [ ! -s makedepend.tmp ]; then
2199                 rm -f makedepend.tmp makedepend.tmp.bak
2201                 if [ "$with_makedepend" = "2" ]; then
2202                         log 1 "checking makedepend... not found"
2204                         log 1 "I couldn't detect any makedepend on your system"
2205                         log 1 "please locate it via --makedepend=[binary]"
2207                         exit 1
2208                 elif [ "$with_makedepend" != "1" ]; then
2209                         log 1 "checking makedepend... $makedepend not found"
2211                         log 1 "the selected file doesn't seem to be a valid makedepend binary"
2213                         exit 1
2214                 else
2215                         log 1 "checking makedepend... not found"
2217                         with_makedepend="0"
2218                         return
2219                 fi
2220         fi
2222         rm -f makedepend.tmp makedepend.tmp.bak
2224         log 1 "checking makedepend... $makedepend"
2227 check_version() {
2228         # $1 - requested version (major.minor)
2229         # $2 - version we got (major.minor)
2231         if [ -z "$2" ]; then
2232                 return 0
2233         fi
2235         req_major=`echo $1 | cut -d. -f1`
2236         got_major=`echo $2 | cut -d. -f1`
2237         if [ $got_major -lt $req_major ]; then
2238                 return 0
2239         elif [ $got_major -gt $req_major ]; then
2240                 return 1
2241         fi
2243         req_minor=`echo $1 | cut -d. -f2`
2244         got_minor=`echo $2 | cut -d. -f2`
2245         if [ $got_minor -lt $req_minor ]; then
2246                 return 0
2247         fi
2248         return 1
2251 detect_awk() {
2252         # Not all awks allow gsub(), so we test for that here! It is in fact all we need...
2254         # These awks are known to work. Test for them explicit
2255         awks="gawk mawk nawk"
2257         awk_prefix="echo \"a.c b.c c.c\" | tr ' ' \\\\n | "
2258         awk_param="' { ORS = \" \" } /\.c$/   { gsub(\".c$\",   \".o\", \$0); print \$0; }' 2>/dev/null"
2259         awk_result="a.o b.o c.o "
2260         log 2 "Detecing awk..."
2262         log 2 "Trying: $awk_prefix $awk $awk_param"
2263         res=`eval $awk_prefix $awk $awk_param`
2264         log 2 "Result: '$res'"
2265         if [ "$res" != "$awk_result" ] && [ "$awk" = "awk" ]; then
2266                 # User didn't supply his own awk, so try to detect some other known working names for an awk
2267                 for awk in $awks; do
2268                         log 2 "Trying: $awk_prefix $awk $awk_param"
2269                         res=`eval $awk_prefix $awk $awk_param`
2270                         log 2 "Result: '$res'"
2271                         if [ "$res" = "$awk_result" ]; then break; fi
2272                 done
2274                 if [ "$res" != "$awk_result" ]; then
2275                         log 1 "checking awk... not found"
2276                         log 1 "configure: error: no awk found"
2277                         log 1 "configure: error: please install one of the following: $awks"
2278                         exit 1
2279                 fi
2280         fi
2281         if [ "$res" != "$awk_result" ]; then
2282                 log 1 "checking awk... not found"
2283                 log 1 "configure: error: you supplied '$awk' but it doesn't seem a valid gawk or mawk"
2284                 exit 1
2285         fi
2287         log 1 "checking awk... $awk"
2290 detect_os() {
2291         if [ "$os" = "DETECT" ]; then
2292                 # Detect UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, HPUX, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP
2294                 # Try first via dumpmachine, then via uname
2295                 os=`echo "$host" | tr '[A-Z]' '[a-z]' | $awk '
2296                                         /linux/        { print "UNIX";      exit}
2297                                         /darwin/       { print "OSX";       exit}
2298                                         /freebsd/      { print "FREEBSD";   exit}
2299                                         /dragonfly/    { print "DRAGONFLY"; exit}
2300                                         /openbsd/      { print "OPENBSD";   exit}
2301                                         /netbsd/       { print "NETBSD";    exit}
2302                                         /hp-ux/        { print "HPUX";      exit}
2303                                         /morphos/      { print "MORPHOS";   exit}
2304                                         /beos/         { print "BEOS";      exit}
2305                                         /haiku/        { print "HAIKU";     exit}
2306                                         /sunos/        { print "SUNOS";     exit}
2307                                         /solaris/      { print "SUNOS";     exit}
2308                                         /cygwin/       { print "CYGWIN";    exit}
2309                                         /mingw/        { print "MINGW";     exit}
2310                                         /os2/          { print "OS2";       exit}
2311                                         /dos/          { print "DOS";       exit}
2312                                         /wince/        { print "WINCE";     exit}
2313                                         /psp/          { print "PSP";       exit}
2314                 '`
2316                 if [ -z "$os" ]; then
2317                         os=`LC_ALL=C uname | tr '[A-Z]' '[a-z]' | $awk '
2318                                         /linux/        { print "UNIX";      exit}
2319                                         /darwin/       { print "OSX";       exit}
2320                                         /freebsd/      { print "FREEBSD";   exit}
2321                                         /dragonfly/    { print "DRAGONFLY"; exit}
2322                                         /openbsd/      { print "OPENBSD";   exit}
2323                                         /netbsd/       { print "NETBSD";    exit}
2324                                         /hp-ux/        { print "HPUX";      exit}
2325                                         /morphos/      { print "MORPHOS";   exit}
2326                                         /beos/         { print "BEOS";      exit}
2327                                         /haiku/        { print "HAIKU";     exit}
2328                                         /sunos/        { print "SUNOS";     exit}
2329                                         /cygwin/       { print "CYGWIN";    exit}
2330                                         /mingw/        { print "MINGW";     exit}
2331                                         /os\/2/        { print "OS2";       exit}
2332                                         /gnu/          { print "UNIX";      exit}
2333                         '`
2334                 fi
2336                 if [ -z "$os" ]; then
2337                         log 1 "detecting OS... none detected"
2338                         log 1 "I couldn't detect your OS. Please use --os=OS to force one"
2339                         log 1 "Allowed values are: UNIX, OSX, FREEBSD, DRAGONFLY, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, WINCE, and PSP"
2340                         exit 1
2341                 fi
2343                 log 1 "detecting OS... $os"
2344         else
2345                 log 1 "forcing OS... $os"
2346         fi
2349 detect_allegro() {
2350         # 0 means no, 1 is auto-detect, 2 is force
2351         if [ "$with_allegro" = "0" ]; then
2352                 log 1 "checking Allegro... disabled"
2354                 allegro_config=""
2355                 return 0
2356         fi
2358         if [ "$with_allegro" = "2" ] && [ "$with_cocoa" = "2" ]; then
2359                 log 1 "configure: error: it is impossible to compile both Allegro and COCOA"
2360                 log 1 "configure: error: please deselect one of them and try again"
2361                 exit 1
2362         fi
2364         if [ "$with_allegro" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2365                 log 1 "configure: error: it is impossible to compile a dedicated with Allegro"
2366                 log 1 "configure: error: please deselect one of them and try again"
2367                 exit 1
2368         fi
2370         if [ "$enable_dedicated" != "0" ]; then
2371                 log 1 "checking Allegro... dedicated server, skipping"
2373                 allegro_config=""
2374                 return 0
2375         fi
2377         # By default on OSX we don't use Allegro. The rest is auto-detect
2378         if [ "$with_allegro" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2379                 log 1 "checking Allegro... OSX, skipping"
2381                 allegro_config=""
2382                 return 0
2383         fi
2385         detect_pkg_config "$with_allegro" "allegro" "allegro_config" "4.4"
2389 detect_sdl() {
2390         # 0 means no, 1 is auto-detect, 2 is force
2391         if [ "$with_sdl" = "0" ]; then
2392                 log 1 "checking SDL... disabled"
2394                 sdl_config=""
2395                 return 0
2396         fi
2398         if [ "$with_sdl" = "2" ] && [ "$with_cocoa" = "2" ]; then
2399                 log 1 "configure: error: it is impossible to compile both SDL and COCOA"
2400                 log 1 "configure: error: please deselect one of them and try again"
2401                 exit 1
2402         fi
2404         if [ "$with_sdl" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2405                 log 1 "configure: error: it is impossible to compile a dedicated with SDL"
2406                 log 1 "configure: error: please deselect one of them and try again"
2407                 exit 1
2408         fi
2410         if [ "$enable_dedicated" != "0" ]; then
2411                 log 1 "checking SDL... dedicated server, skipping"
2413                 sdl_config=""
2414                 return 0
2415         fi
2417         # By default on OSX we don't use SDL. The rest is auto-detect
2418         if [ "$with_sdl" = "1" ] && [ "$os" = "OSX" ] && [ "$with_cocoa" != "0" ]; then
2419                 log 1 "checking SDL... OSX, skipping"
2421                 sdl_config=""
2422                 return 0
2423         fi
2425         if [ "$os" = "OSX" ]; then
2426                 log 1 "WARNING: sdl is known to fail on some versions of Mac OS X"
2427                 log 1 "WARNING: with some hardware configurations. Use at own risk!"
2428                 sleep 5
2429         fi
2431         detect_pkg_config "$with_sdl" "sdl" "sdl_config" "1.2"
2434 detect_osx_sdk() {
2435         # Try to find the best SDK available. For a normal build this
2436         # is currently the 10.5 SDK as this is needed to compile all
2437         # optional code. Because such an executable won't run on 10.4
2438         # or lower, also check for the 10.4u SDK when doing an universal
2439         # build.
2441         # Check for the 10.5 SDK, but try 10.6 if that fails
2442         check_osx_sdk "10.5" || check_osx_sdk "10.6" || osx_sdk_path=""
2444         if [ -z "$osx_sdk_path" ] || [ "$enable_universal" != "0" ]; then
2445                 # No better SDK or universal build enabled? Check 10.4u SDK as well
2446                 local old_sdk="$osx_sdk_path"
2447                 if check_osx_sdk "10.4u"; then
2448                         osx_sdk_104_path="$osx_sdk_path"
2449                 else
2450                         osx_sdk_104_path=""
2451                 fi
2452                 if [ -z "$old_sdk" ]; then
2453                         osx_sdk_path="$osx_sdk_104_path"
2454                 else
2455                         osx_sdk_path="$old_sdk"
2456                 fi
2457         fi
2459         if [ -z "$osx_sdk_path" ]; then
2460                 log 1 "Your system SDK is probably too old"
2461                 log 1 "Please install/upgrade your Xcode to >= 2.5"
2463                 exit 1
2464         fi
2467 detect_cocoa() {
2468         # 0 means no, 1 is auto-detect, 2 is force
2469         if [ "$with_cocoa" = "0" ]; then
2470                 log 1 "checking COCOA... disabled"
2472                 return 0
2473         fi
2475         if [ "$with_cocoa" = "2" ] && [ "$enable_dedicated" != "0" ]; then
2476                 log 1 "configure: error: it is impossible to compile a dedicated with COCOA"
2477                 log 1 "configure: error: please deselect one of them and try again"
2478                 exit 1
2479         fi
2481         if [ "$enable_dedicated" != "0" ]; then
2482                 log 1 "checking COCOA... dedicated server, skipping"
2484                 with_cocoa="0"
2485                 return 0
2486         fi
2488         # By default on OSX we use COCOA. The rest doesn't support it
2489         if [ "$with_cocoa" = "1" ] && [ "$os" != "OSX" ]; then
2490                 log 1 "checking COCOA... not OSX, skipping"
2492                 with_cocoa="0"
2493                 return 0
2494         fi
2496         if [ "$os" != "OSX" ]; then
2497                 log 1 "checking COCOA... not OSX"
2499                 log 1 "configure: error: COCOA video driver is only supported for OSX"
2500                 exit 1
2501         fi
2503         log 1 "checking COCOA... found"
2506         if [ "$enable_cocoa_quartz" != "0" ]; then
2507                 log 1 "checking whether to enable the Quartz window subdriver... yes"
2508         else
2509                 log 1 "checking whether to enable the Quartz window subdriver... no"
2510         fi
2512         detect_quickdraw
2515 detect_quickdraw() {
2516         # 0 means no, 1 is auto-detect, 2 is force
2517         if [ "$enable_cocoa_quickdraw" = "0" ]; then
2518                 log 1 "checking Quickdraw window subdriver... disabled"
2519                 return 0
2520         fi
2522         # Assume QuickDraw is available when doing an universal build
2523         if [ "$enable_universal" != "0" ]; then
2524                 log 1 "checking Quickdraw window subdriver... found"
2525                 return 0
2526         fi
2528         # 64 bits doesn't have quickdraw
2529         if [ "$cpu_type" = "64" ]; then
2530                 enable_cocoa_quickdraw="0"
2531                 log 1 "checking Quickdraw window subdriver... disabled (64 bits)"
2532                 return 0
2533         fi
2535 cat > tmp.osx.mm << EOF
2536 #include <AvailabilityMacros.h>
2537 #import <Cocoa/Cocoa.h>
2538 int main(int argc, char *argv[]) { SetEmptyRgn(NULL); return 0; }
2540         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS -mmacosx-version-min=10.3 tmp.osx.mm -framework Cocoa -o tmp.osx 2>&1"
2541         eval $execute > /dev/null
2542         ret=$?
2543         log 2 "executing $execute"
2544         log 2 "  exit code $ret"
2545         rm -f tmp.osx.mm tmp.osx
2546         if [ "$ret" != "0" ]; then
2547                 log 1 "checking Quickdraw window subdriver... not found"
2549                 # It was forced, so it should be found.
2550                 if [ "$enable_cocoa_quickdraw" != "1" ]; then
2551                         log 1 "configure: error: Quickdraw window driver could not be found"
2552                         exit 1
2553                 fi
2555                 enable_cocoa_quickdraw=0
2556                 return 0
2557         fi
2559         enable_cocoa_quickdraw=1
2560         log 1 "checking Quickdraw window subdriver... found"
2563 detect_library() {
2564         # $1 - config-param ($with_zlib value)
2565         # $2 - library name ('zlib', sets $zlib)
2566         # $3 - static library name (libz.a)
2567         # $4 - header directory ()
2568         # $5 - header name (zlib.h)
2569         # $6 - force static (if non-empty)
2571         if [ -n "$6" ]; then force_static="1"; fi
2573         # 0 means no, 1 is auto-detect, 2 is force
2574         if [ "$1" = "0" ]; then
2575                 log 1 "checking $2... disabled"
2577                 eval "$2=\"\""
2578                 return 0
2579         fi
2581         log 2 "detecting $2"
2583         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2584                 eval "$2=`ls -1 /usr/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2585                 eval "res=\$$2"
2586                 if [ -z "$res" ]; then
2587                         log 2 "  trying /usr/include/$4$5... no"
2588                         eval "$2=`ls -1 /usr/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2589                 fi
2590                 eval "res=\$$2"
2591                 if [ -z "$res" ]; then
2592                         log 2 "  trying /usr/local/include/$4$5... no"
2593                         eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2594                 fi
2595                 eval "res=\$$2"
2596                 if [ -z "$res" ]; then
2597                         log 2 "  trying /mingw/include/$4$5... no"
2598                         eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2599                 fi
2600                 eval "res=\$$2"
2601                 if [ -z "$res" ]; then
2602                         log 2 "  trying /opt/local/include/$4$5... no"
2603                 fi
2604                 if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then
2605                         eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2606                         eval "res=\$$2"
2607                         if [ -z "$res" ]; then
2608                                 log 2 "  trying /usr/pkg/include/$4$5... no"
2609                         fi
2610                 fi
2611                 if [ -z "$res" ] && [ "$os" = "HAIKU" ]; then
2612                         if [ -z "$includeDir" ]; then
2613                                 includeDir=`finddir B_SYSTEM_HEADERS_DIRECTORY`
2614                         fi
2615                         eval "$2=`ls -1 $includeDir/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
2616                         eval "res=\$$2"
2617                         if [ -z "$res" ]; then
2618                                 log 2 "  trying $includeDir/$4$5... no"
2619                         fi
2620                 fi
2622                 eval "res=\$$2"
2623                 if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then
2624                         eval "res=\$$2"
2625                         log 2 "  trying $res... found"
2626                         # Now find the static lib, if needed
2627                         eval "$2=`ls /lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2628                         eval "res=\$$2"
2629                         if [ -z "$res" ]; then
2630                                 log 2 "  trying /lib/$3... no"
2631                                 eval "$2=`ls /usr/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2632                         fi
2633                         eval "res=\$$2"
2634                         if [ -z "$res" ]; then
2635                                 log 2 "  trying /usr/lib/$3... no"
2636                                 eval "$2=`ls /usr/local/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2637                         fi
2638                         eval "res=\$$2"
2639                         if [ -z "$res" ]; then
2640                                 log 2 "  trying /usr/local/lib/$3... no"
2641                                 eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
2642                         fi
2643                         eval "res=\$$2"
2644                         if [ -z "$res" ]; then
2645                                 log 2 "  trying /mingw/lib/$3... no"
2646                                 log 1 "configure: error: $2 couldn't be found"
2647                                 log 1 "configure: error: you requested a static link, but I can't find $3"
2649                                 exit 1
2650                         fi
2651                 fi
2652         else
2653                 # Make sure it exists
2654                 if [ -f "$1" ]; then
2655                         eval "$2=`ls $1 2>/dev/null`"
2656                 else
2657                         eval "$2=`ls $1/$3 2>/dev/null`"
2658                 fi
2659         fi
2661         eval "res=\$$2"
2662         if [ -z "$res" ]; then
2663                 log 1 "checking $2... not found"
2664                 if [ "$1" = "2" ]; then
2665                         log 1 "configure: error: $2 couldn't be found"
2667                         exit 1
2668                 elif [ "$1" != "1" ]; then
2669                         log 1 "configure: error: $2 couldn't be found"
2670                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2672                         exit 1
2673                 fi
2675                 eval "with_$2=0"
2677                 return 0
2678         fi
2680         eval "res=\$$2"
2681         log 2 "  trying $res... found"
2683         log 1 "checking $2... found"
2686 detect_zlib() {
2687         detect_pkg_config "$with_zlib" "zlib" "zlib_config" "1.2"
2690 detect_lzo2() {
2691         detect_library "$with_lzo2" "lzo2" "liblzo2.a" "lzo/" "lzo1x.h"
2694 detect_libtimidity() {
2695         detect_pkg_config "$with_libtimidity" "libtimidity" "libtimidity_config" "0.1" "1"
2698 detect_pkg_config() {
2699         # $1 - config-param ($with_lzma value)
2700         # $2 - package name ('liblzma')
2701         # $3 - config name ('lzma_config', sets $lzma_config)
2702         # $4 - minimum module version ('2.3')
2703         # $5 - check for dedicated, 1 is "skif if dedicated"
2705         # 0 means no, 1 is auto-detect, 2 is force
2706         if [ "$1" = "0" ]; then
2707                 log 1 "checking $2... disabled"
2709                 eval "$3=\"\""
2710                 return 0
2711         fi
2713         if [ "$5" = "1" ] && [ "$1" = "1" ] && [ "$enable_dedicated" != "0" ]; then
2714                 log 1 "checking $2... dedicated server, skipping"
2716                 eval "$3=\"\""
2717                 return 0
2718         fi
2720         log 2 "detecting $2"
2722         if [ "$1" = "1" ] || [ "$1" = "" ] || [ "$1" = "2" ]; then
2723                 pkg_config_call="$pkg_config $2"
2724         else
2725                 pkg_config_call="$1"
2726         fi
2728         version=`$pkg_config_call --modversion 2>/dev/null`
2729         ret=$?
2730         check_version "$4" "$version"
2731         version_ok=$?
2732         log 2 "executing $pkg_config_call --modversion"
2733         log 2 "  returned $version"
2734         log 2 "  exit code $ret"
2736         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version_ok" != "1" ]; then
2737                 if [ -n "$version" ] && [ "$version_ok" != "1" ]; then
2738                         log 1 "checking $2... needs at least version $4, $2 NOT enabled"
2739                 else
2740                         log 1 "checking $2... not found"
2741                 fi
2743                 # It was forced, so it should be found.
2744                 if [ "$1" != "1" ]; then
2745                         log 1 "configure: error: $pkg_config $2 couldn't be found"
2746                         log 1 "configure: error: you supplied '$1', but it seems invalid"
2747                         exit 1
2748                 fi
2750                 eval "$3=\"\""
2751                 return 0
2752         fi
2754         eval "$3=\"$pkg_config_call\""
2755         log 1 "checking $2... found"
2758 detect_lzma() {
2759         detect_pkg_config "$with_lzma" "liblzma" "lzma_config" "5.0"
2762 detect_xdg_basedir() {
2763         detect_pkg_config "$with_xdg_basedir" "libxdg-basedir" "xdg_basedir_config" "1.2"
2766 detect_png() {
2767         detect_pkg_config "$with_png" "libpng" "png_config" "1.2"
2770 detect_freetype() {
2771         detect_pkg_config "$with_freetype" "freetype2" "freetype_config" "2.2" "1"
2774 detect_fontconfig() {
2775         # 0 means no, 1 is auto-detect, 2 is force
2776         if [ "$with_fontconfig" = "0" ]; then
2777                 log 1 "checking libfontconfig... disabled"
2779                 fontconfig_config=""
2780                 return 0
2781         fi
2782         if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
2783                 log 1 "checking libfontconfig... WIN32, skipping"
2784                 fontconfig_config=""
2785                 return 0
2786         fi
2788         if [ "$os" = "OSX" ]; then
2789                 log 1 "checking libfontconfig... OSX, skipping"
2790                 fontconfig_config=""
2791                 return 0
2792         fi
2794         detect_pkg_config "$with_fontconfig" "fontconfig" "fontconfig_config" "2.3" "1"
2797 detect_icu_layout() {
2798         detect_pkg_config "$with_icu_layout" "icu-lx" "icu_layout_config" "4.8" "1"
2801 detect_icu_sort() {
2802         detect_pkg_config "$with_icu_sort" "icu-i18n" "icu_sort_config" "4.8" "1"
2805 detect_pspconfig() {
2806         # 0 means no, 1 is auto-detect, 2 is force
2807         if [ "$with_psp_config" = "0" ]; then
2808                 log 1 "checking psp-config... disabled"
2810                 psp_config=""
2811                 return 0
2812         fi
2814         if [ "$with_psp_config" = "1" ] && [ "$os" != "PSP" ]; then
2815                 log 1 "checking psp-config... not PSP, skipping"
2817                 psp_config="";
2818                 return 0
2819         fi
2821         if [ "$os" != "PSP" ]; then
2822                 log 1 "checking psp-config... not PSP"
2824                 log 1 "configure: error: psp-config is only supported for PSP"
2825                 exit 1
2826         fi
2828         if [ "$with_psp_config" = "1" ] || [ "$with_psp_config" = "" ] || [ "$with_psp_config" = "2" ]; then
2829                 psp_config="psp-config"
2830         else
2831                 psp_config="$with_psp_config"
2832         fi
2834         version=`$psp_config -p 2>/dev/null`
2835         ret=$?
2836         log 2 "executing $psp_config -p"
2837         log 2 "  returned $version"
2838         log 2 "  exit code $ret"
2840         if [ -z "$version" ] || [ "$ret" != "0" ]; then
2841                 log 1 "checking psp-config... not found"
2842                 log 1 "configure: error: psp-config couldn't be found"
2844                 # It was forced, so it should be found.
2845                 if [ "$with_psp_config" != "1" ]; then
2846                         log 1 "configure: error: you supplied '$with_psp_config', but it seems invalid"
2847                 fi
2848                 exit 1
2849         fi
2851         log 1 "checking psp-config... found"
2854 detect_iconv() {
2855         # 0 means no, 1 is auto-detect, 2 is force
2856         if [ "$with_iconv" = "0" ]; then
2857                 log 1 "checking iconv... disabled"
2859                 return 0
2860         fi
2862         if [ "$with_iconv" = "1" ] && [ "$os" != "OSX" ]; then
2863                 log 1 "checking iconv... not OSX, skipping"
2864                 with_iconv="0"
2866                 return 0
2867         fi
2869         # Try to find iconv.h, seems to only thing to detect iconv with
2871         if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
2872                 iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
2873                 if [ -z "$iconv" ]; then
2874                         iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
2875                 fi
2876         else
2877                 # Make sure it exists
2878                 iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
2879         fi
2881         if [ -z "$iconv" ]; then
2882                 log 1 "checking iconv... not found"
2883                 if [ "$with_iconv" = "2" ]; then
2884                         log 1 "configure: error: iconv couldn't be found"
2886                         exit 1
2887                 elif [ "$with_iconv" != "1" ]; then
2888                         log 1 "configure: error: iconv couldn't be found"
2889                         log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
2891                         exit 1
2892                 fi
2894                 return 0
2895         fi
2897         if [ "$with_iconv" = "1" ]; then
2898                 with_iconv="2"
2899         fi
2901         log 2 "found iconv in $iconv"
2903         log 1 "checking iconv... found"
2905         # There are different implementations of iconv. The older ones,
2906         # e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
2907         # IEEE 1003.1 (2004), pass a non-const pointer.
2909         cat > tmp.iconv.cpp << EOF
2910 #include "src/stdafx.h"
2911 #include <iconv.h>
2912 int main() {
2913         static char buf[1024];
2914         iconv_t convd = 0;
2915         const char *inbuf = "";
2916         char *outbuf  = buf;
2917         size_t outlen = 1023;
2918         size_t inlen  = 0;
2919         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2922         execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2923         eval $execute > /dev/null
2924         ret=$?
2925         log 2 "executing $execute"
2926         log 2 "  exit code $ret"
2927         if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
2928         log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
2930         cat > tmp.iconv.cpp << EOF
2931 #include "src/stdafx.h"
2932 #include <iconv.h>
2933 int main() {
2934         static char buf[1024];
2935         iconv_t convd = 0;
2936         char *inbuf = "";
2937         char *outbuf  = buf;
2938         size_t outlen = 1023;
2939         size_t inlen  = 0;
2940         return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
2943         execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
2944         eval $execute > /dev/null
2945         ret=$?
2946         log 2 "executing $execute"
2947         log 2 "  exit code $ret"
2948         if [ "$ret" = "0" ]; then link_to_iconv="no"; else link_to_iconv="yes"; fi
2949         log 1 "checking whether to link to iconv... $link_to_iconv"
2950         rm -f tmp.iconv tmp.iconv.cpp
2953 _detect_sort() {
2954         sort_test_in="d
2959         sort_test_out="a
2964         log 2 "running echo <array> | $1"
2966         if [ "`echo \"$sort_test_in\" | $1 2>/dev/null`" = "$sort_test_out" ]; then
2967                 sort="$1"
2968                 log 2 "  result was valid"
2969         else
2970                 log 2 "  result was invalid"
2971         fi
2974 detect_sort() {
2975         if [ "$with_sort" = "0" ]; then
2976                 log 1 "checking sort... disabled"
2978                 return
2979         fi
2981         if [ "$with_sort" = "1" ] || [ "$with_sort" = "2" ]; then
2982                 _detect_sort "sort"
2983                 if [ -z "$sort" ]; then _detect_sort "/sbin/sort"; fi
2984                 if [ -z "$sort" ]; then _detect_sort "/usr/sbin/sort"; fi
2985                 if [ -z "$sort" ]; then _detect_sort "/usr/local/sbin/sort"; fi
2986                 if [ -z "$sort" ]; then _detect_sort "/bin/sort"; fi
2987                 if [ -z "$sort" ]; then _detect_sort "/usr/bin/sort"; fi
2988                 if [ -z "$sort" ]; then _detect_sort "/usr/local/bin/sort"; fi
2989         else
2990                 _detect_sort "$with_sort"
2991         fi
2993         if [ -z "$sort" ]; then
2994                 if [ "$with_sort" = "2" ]; then
2995                         log 1 "checking sort... not found"
2997                         log 1 "configure: error: couldn't detect sort on your system"
2998                         exit 1
2999                 elif [ "$with_sort" != "1" ]; then
3000                         log 1 "checking sort... $with_sort not found"
3002                         log 1 "configure: error: '$with_sort' doesn't look like a sort to me"
3003                         log 1 "configure: error: please verify its location and function and try again"
3005                         exit 1
3006                 else
3007                         log 1 "checking sort... not found"
3008                 fi
3009         else
3010                 log 1 "checking sort... $sort"
3011         fi
3014 detect_grfcodec() {
3015         # 0 means no, 1 is auto-detect, 2 is force
3016         if [ "$with_grfcodec" = "0" ]; then
3017                 log 1 "checking grfcodec... disabled"
3019                 grfcodec=""
3020                 return 0
3021         fi
3023         if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
3024                 grfcodec="grfcodec"
3025         else
3026                 grfcodec="$with_grfcodec"
3027         fi
3029         version=`$grfcodec -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3030         ret=$?
3031         log 2 "executing grfcodec -v"
3032         log 2 "  returned $version"
3033         log 2 "  exit code $ret"
3035         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3036                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3037                         log 1 "checking grfcodec... needs at least version 6.0.5 (r985), disabled"
3038                 else
3039                         log 1 "checking grfcodec... not found"
3040                 fi
3042                 # It was forced, so it should be found.
3043                 if [ "$with_grfcodec" != "1" ]; then
3044                         log 1 "configure: error: grfcodec couldn't be found"
3045                         log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
3046                         exit 1
3047                 fi
3049                 grfcodec=""
3050                 return 0
3051         fi
3053         log 1 "checking grfcodec... found"
3056 detect_nforenum() {
3057         # 0 means no, 1 is auto-detect, 2 is force
3058         if [ "$with_nforenum" = "0" ]; then
3059                 log 1 "checking nforenum... disabled"
3061                 nforenum=""
3062                 return 0
3063         fi
3065         if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
3066                 nforenum="nforenum"
3067         else
3068                 nforenum="$with_nforenum"
3069         fi
3071         version=`$nforenum -v 2>/dev/null | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/'`
3072         ret=$?
3073         log 2 "executing nforenum -v"
3074         log 2 "  returned $version"
3075         log 2 "  exit code $ret"
3077         if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "985" ]; then
3078                 if [ -n "$version" ] && [ "$version" -lt "985" ]; then
3079                         log 1 "checking nforenum... needs at least version 6.0.5 (r985), disabled"
3080                 else
3081                         log 1 "checking nforenum... not found"
3082                 fi
3084                 # It was forced, so it should be found.
3085                 if [ "$with_nforenum" != "1" ]; then
3086                         log 1 "configure: error: nforenum couldn't be found"
3087                         log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
3088                         exit 1
3089                 fi
3091                 nforenum=""
3092                 return 0
3093         fi
3095         log 1 "checking nforenum... found"
3098 detect_cputype() {
3099         if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
3100                 log 1 "forcing cpu-type... $cpu_type bits"
3101                 return;
3102         fi
3103         echo "#define _SQ64 1" > tmp.64bit.cpp
3104         echo "#include \"src/stdafx.h\"" >> tmp.64bit.cpp
3105         echo "assert_compile(sizeof(size_t) == 8);" >> tmp.64bit.cpp
3106         echo "int main() { return 0; }" >> tmp.64bit.cpp
3107         execute="$cxx_host $CFLAGS tmp.64bit.cpp -o tmp.64bit -DTESTING 2>&1"
3108         cpu_type="`eval $execute 2>/dev/null`"
3109         ret=$?
3110         log 2 "executing $execute"
3111         log 2 "  returned $cpu_type"
3112         log 2 "  exit code $ret"
3113         if [ "$ret" = "0" ]; then cpu_type="64"; else cpu_type="32"; fi
3114         log 1 "detecting cpu-type... $cpu_type bits"
3115         rm -f tmp.64bit tmp.64bit.cpp
3118 detect_sse_capable_architecture() {
3119         # 0 means no, 1 is auto-detect, 2 is force
3120         if [ "$with_sse" = "0" ]; then
3121                 log 1 "checking SSE... disabled"
3122                 return
3123         fi
3125         echo "#define _SQ64 1" > tmp.sse.cpp
3126         echo "#include <xmmintrin.h>" >> tmp.sse.cpp
3127         echo "#include <smmintrin.h>" >> tmp.sse.cpp
3128         echo "#include <tmmintrin.h>" >> tmp.sse.cpp
3129         echo "int main() { return 0; }" >> tmp.sse.cpp
3130         execute="$cxx_host -msse4.1 $CFLAGS tmp.sse.cpp -o tmp.sse 2>&1"
3131         sse="`eval $execute 2>/dev/null`"
3132         ret=$?
3133         log 2 "executing $execute"
3134         log 2 "  returned $sse"
3135         log 2 "  exit code $ret"
3136         if [ "$ret" = "0" ]; then
3137                 log 1 "detecting SSE... found"
3138         else
3139                 # It was forced, so it should be found.
3140                 if [ "$with_sse" != "1" ]; then
3141                         log 1 "configure: error: SSE couln't be found"
3142                         log 1 "configure: error: you force enabled SSE, but it seems unavailable"
3143                         exit 1
3144                 fi
3146                 log 1 "detecting SSE... not found"
3147                 with_sse="0"
3148         fi
3149         rm -f tmp.sse tmp.exe tmp.sse.cpp
3152 make_sed() {
3153         T_CFLAGS="$CFLAGS"
3154         T_CXXFLAGS="$CXXFLAGS"
3155         T_LDFLAGS="$LDFLAGS"
3157         SRC_OBJS_DIR="$BASE_SRC_OBJS_DIR/$OBJS_SUBDIR"
3159         # All the data needed to compile a single target
3160         #  Make sure if you compile multiple targets to
3161         #  use multiple OBJS_DIR, because all in-between
3162         #  binaries are stored in there, and nowhere else.
3163         SRC_REPLACE="
3164                 s@!!CC_HOST!!@$cc_host@g;
3165                 s@!!CXX_HOST!!@$cxx_host@g;
3166                 s@!!CC_BUILD!!@$cc_build@g;
3167                 s@!!CXX_BUILD!!@$cxx_build@g;
3168                 s@!!WINDRES!!@$windres@g;
3169                 s@!!STRIP!!@$strip $strip_arg@g;
3170                 s@!!LIPO!!@$lipo@g;
3171                 s@!!CFLAGS!!@$T_CFLAGS@g;
3172                 s@!!CFLAGS_BUILD!!@$CFLAGS_BUILD@g;
3173                 s@!!CXXFLAGS!!@$T_CXXFLAGS@g;
3174                 s@!!CXXFLAGS_BUILD!!@$CXXFLAGS_BUILD@g;
3175                 s@!!STRGEN_FLAGS!!@$strgen_flags@g;
3176                 s@!!LIBS!!@$LIBS@g;
3177                 s@!!LDFLAGS!!@$T_LDFLAGS@g;
3178                 s@!!LDFLAGS_BUILD!!@$LDFLAGS_BUILD@g;
3179                 s@!!BIN_DIR!!@$BIN_DIR@g;
3180                 s@!!ROOT_DIR!!@$ROOT_DIR@g;
3181                 s@!!MEDIA_DIR!!@$MEDIA_DIR@g;
3182                 s@!!SOURCE_LIST!!@$SOURCE_LIST@g;
3183                 s@!!SRC_OBJS_DIR!!@$SRC_OBJS_DIR@g;
3184                 s@!!LANG_OBJS_DIR!!@$LANG_OBJS_DIR@g;
3185                 s@!!GRF_OBJS_DIR!!@$GRF_OBJS_DIR@g;
3186                 s@!!SETTING_OBJS_DIR!!@$SETTING_OBJS_DIR@g;
3187                 s@!!SRC_DIR!!@$SRC_DIR@g;
3188                 s@!!SCRIPT_SRC_DIR!!@$SCRIPT_SRC_DIR@g;
3189                 s@!!OSXAPP!!@$OSXAPP@g;
3190                 s@!!LANG_DIR!!@$LANG_DIR@g;
3191                 s@!!TTD!!@$TTD@g;
3192                 s@!!BINARY_DIR!!@$prefix_dir/$binary_dir@g;
3193                 s@!!DATA_DIR!!@$prefix_dir/$data_dir@g;
3194                 s@!!DOC_DIR!!@$prefix_dir/$doc_dir@g;
3195                 s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3196                 s@!!ICON_DIR!!@$prefix_dir/$icon_dir@g;
3197                 s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3198                 s@!!PERSONAL_DIR!!@$personal_dir@g;
3199                 s@!!SHARED_DIR!!@$shared_dir@g;
3200                 s@!!INSTALL_DIR!!@$install_dir@g;
3201                 s@!!BINARY_NAME!!@$binary_name@g;
3202                 s@!!STRGEN!!@$STRGEN@g;
3203                 s@!!ENDIAN_CHECK!!@$ENDIAN_CHECK@g;
3204                 s@!!DEPEND!!@$DEPEND@g;
3205                 s@!!SETTINGSGEN!!@$SETTINGSGEN@g;
3206                 s@!!ENDIAN_FORCE!!@$endian@g;
3207                 s@!!STAGE!!@$STAGE@g;
3208                 s@!!MAKEDEPEND!!@$makedepend@g;
3209                 s@!!CFLAGS_MAKEDEP!!@$cflags_makedep@g;
3210                 s@!!SORT!!@$sort@g;
3211                 s@!!CONFIG_CACHE_COMPILER!!@config.cache.compiler@g;
3212                 s@!!CONFIG_CACHE_LINKER!!@config.cache.linker@g;
3213                 s@!!CONFIG_CACHE_ENDIAN!!@config.cache.endian@g;
3214                 s@!!CONFIG_CACHE_SOURCE!!@config.cache.source@g;
3215                 s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
3216                 s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
3217                 s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
3218                 s@!!LANG_SUPPRESS!!@$lang_suppress@g;
3219                 s@!!OBJS_C!!@$OBJS_C@g;
3220                 s@!!OBJS_CPP!!@$OBJS_CPP@g;
3221                 s@!!OBJS_MM!!@$OBJS_MM@g;
3222                 s@!!OBJS_RC!!@$OBJS_RC@g;
3223                 s@!!SRCS!!@$SRCS@g;
3224                 s@!!OS!!@$os@g;
3225                 s@!!CONFIGURE_FILES!!@$CONFIGURE_FILES@g;
3226                 s@!!AWK!!@$awk@g;
3227                 s@!!DISTCC!!@$distcc@g;
3228                 s@!!NFORENUM!!@$nforenum@g;
3229                 s@!!GRFCODEC!!@$grfcodec@g;
3230         "
3232         if [ "$icon_theme_dir" != "" ]; then
3233                 SRC_REPLACE="$SRC_REPLACE
3234                         s@!!ICON_THEME_DIR!!@$prefix_dir/$icon_theme_dir@g;
3235                 "
3236         else
3237                 SRC_REPLACE="$SRC_REPLACE
3238                         s@!!ICON_THEME_DIR!!@@g;
3239                 "
3240         fi
3242         if [ "$man_dir" != "" ]; then
3243                 SRC_REPLACE="$SRC_REPLACE
3244                         s@!!MAN_DIR!!@$prefix_dir/$man_dir@g;
3245                 "
3246         else
3247                 SRC_REPLACE="$SRC_REPLACE
3248                         s@!!MAN_DIR!!@@g;
3249                 "
3250         fi
3252         if [ "$menu_dir" != "" ]; then
3253                 SRC_REPLACE="$SRC_REPLACE
3254                         s@!!MENU_DIR!!@$prefix_dir/$menu_dir@g;
3255                 "
3256         else
3257                 SRC_REPLACE="$SRC_REPLACE
3258                         s@!!MENU_DIR!!@@g;
3259                 "
3260         fi
3263 generate_menu_item() {
3264         MENU_REPLACE="
3265                 s@!!TTD!!@$TTD@g;
3266                 s@!!MENU_GROUP!!@$menu_group@g;
3267                 s@!!MENU_NAME!!@$menu_name@g
3268         "
3269         log 1 "Generating menu item..."
3270         mkdir -p media
3271         < $ROOT_DIR/media/openttd.desktop.in sed "$MENU_REPLACE" > media/openttd.desktop
3274 generate_main() {
3275         STAGE="[MAIN]"
3277         make_sed
3279         # Create the main Makefile
3280         log 1 "Generating Makefile..."
3281         echo "# Auto-generated file from 'Makefile.in' -- DO NOT EDIT" > Makefile
3282         < $ROOT_DIR/Makefile.in sed "$SRC_REPLACE" >> Makefile
3283         cp $ROOT_DIR/Makefile.bundle.in Makefile.bundle
3284         echo "# Auto-generated file -- DO NOT EDIT" > Makefile.am
3285         echo >> Makefile.am
3286         # Make the copy of the source-list, so we don't trigger an unwanted recompile
3287         cp $SOURCE_LIST config.cache.source.list
3288         # Add the current directory, so we don't trigger an unwanted recompile
3289         echo "`pwd`" > config.cache.pwd
3290         # Make sure config.cache is OLDER then config.cache.source.list
3291         touch config.cache
3292         touch config.pwd
3294         if [ "$menu_dir" != "" ]; then
3295                 generate_menu_item
3296         fi
3299 generate_lang() {
3300         STAGE="[LANG]"
3302         make_sed
3304         # Create the language file
3305         mkdir -p $LANG_OBJS_DIR
3307         log 1 "Generating lang/Makefile..."
3308         echo "# Auto-generated file from 'Makefile.lang.in' -- DO NOT EDIT" > $LANG_OBJS_DIR/Makefile
3309         < $ROOT_DIR/Makefile.lang.in sed "$SRC_REPLACE" >> $LANG_OBJS_DIR/Makefile
3310         echo "DIRS += $LANG_OBJS_DIR" >> Makefile.am
3311         echo "LANG_DIRS += $LANG_OBJS_DIR" >> Makefile.am
3314 generate_settings() {
3315         STAGE="[SETTING]"
3317         make_sed
3319         # Create the language file
3320         mkdir -p $SETTING_OBJS_DIR
3322         log 1 "Generating setting/Makefile..."
3323         echo "# Auto-generated file from 'Makefile.settings.in' -- DO NOT EDIT" > $SETTING_OBJS_DIR/Makefile
3324         < $ROOT_DIR/Makefile.setting.in sed "$SRC_REPLACE" >> $SETTING_OBJS_DIR/Makefile
3325         echo "DIRS += $SETTING_OBJS_DIR" >> Makefile.am
3328 generate_grf() {
3329         STAGE="[BASESET]"
3331         make_sed
3333         # Create the language file
3334         mkdir -p $GRF_OBJS_DIR
3336         log 1 "Generating grf/Makefile..."
3337         echo "# Auto-generated file from 'Makefile.grf.in' -- DO NOT EDIT" > $GRF_OBJS_DIR/Makefile
3338         < $ROOT_DIR/Makefile.grf.in sed "$SRC_REPLACE" >> $GRF_OBJS_DIR/Makefile
3339         echo "DIRS += $GRF_OBJS_DIR" >> Makefile.am
3342 generate_src_normal() {
3343         STAGE=$1
3345         make_sed
3347         # Create the source file
3348         mkdir -p $SRC_OBJS_DIR
3350         log 1 "Generating $2/Makefile..."
3351         echo "# Auto-generated file from 'Makefile.src.in' -- DO NOT EDIT" > $SRC_OBJS_DIR/Makefile
3352         < $ROOT_DIR/Makefile.src.in sed "$SRC_REPLACE" >> $SRC_OBJS_DIR/Makefile
3353         echo "DIRS += $SRC_OBJS_DIR" >> Makefile.am
3354         echo "SRC_DIRS += $SRC_OBJS_DIR" >> Makefile.am
3357 generate_src_osx() {
3358         cc_host_orig="$cc_host"
3359         cxx_host_orig="$cxx_host"
3360         CFLAGS_orig="$CFLAGS"
3361         LDFLAGS_orig="$LDFLAGS"
3363         for type in $enable_universal; do
3365                 if [ -n "$osx_sdk_104_path" ]; then
3366                         # Use 10.4 SDK for 32-bit targets
3367                         CFLAGS="-isysroot $osx_sdk_104_path $CFLAGS_orig"
3368                         LDFLAGS="-Wl,-syslibroot,$osx_sdk_104_path $LDFLAGS_orig"
3369                 fi
3371                 # We don't want to duplicate the x86_64 stuff for each target, so do it once here
3372                 if [ "$type" = "ppc64" ] || [ "$type" = "x86_64" ]; then
3373                         # 64 bits is always 10.5 or higher. Furthermore it has a non const ICONV
3374                         # and they also removed support for QuickTime/QuickDraw
3375                         if [ -n "$osx_sdk_path" ]; then
3376                                 CFLAGS="-isysroot $osx_sdk_path $CFLAGS_orig"
3377                                 LDFLAGS="-Wl,-syslibroot,$osx_sdk_path $LDFLAGS_orig"
3378                         fi
3379                         CFLAGS="$CFLAGS -D_SQ64 -DNO_QUICKTIME -UENABLE_COCOA_QUICKDRAW"
3380                         LIBS="`echo $LIBS | sed 's/-framework QuickTime//'`"
3381                 fi
3383                 case $type in
3384                         ppc)
3385                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc"
3386                                 cc_host="$cc_host_orig -arch ppc -mmacosx-version-min=10.3"
3387                                 cxx_host="$cxx_host_orig -arch ppc -mmacosx-version-min=10.3"
3388                                 generate_src_normal "[ppc]" "objs/ppc";;
3389                         ppc970)
3390                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc970"
3391                                 cc_host="$cc_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3392                                 cxx_host="$cxx_host_orig -arch ppc970 -mmacosx-version-min=10.3 -mcpu=G5 -mpowerpc64 -mtune=970 -mcpu=970 -mpowerpc-gpopt"
3393                                 generate_src_normal "[ppc970]" "objs/ppc970";;
3394                         i386)
3395                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/i386"
3396                                 cc_host="$cc_host_orig -arch i386 -mmacosx-version-min=10.4"
3397                                 cxx_host="$cxx_host_orig -arch i386 -mmacosx-version-min=10.4"
3398                                 generate_src_normal "[i386]" "objs/i386";;
3399                         ppc64)
3400                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/ppc64"
3401                                 cc_host="$cc_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3402                                 cxx_host="$cxx_host_orig -arch ppc64 -mmacosx-version-min=10.5"
3403                                 generate_src_normal "[ppc64]" "objs/ppc64";;
3404                         x86_64)
3405                                 BASE_SRC_OBJS_DIR="$OBJS_DIR/x86_64"
3406                                 cc_host="$cc_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3407                                 cxx_host="$cxx_host_orig -arch x86_64 -mmacosx-version-min=10.5"
3408                                 generate_src_normal "[x86_64]" "objs/x86_64";;
3409                         *) log 1 "Unknown architecture requested for universal build: $type";;
3410                 esac
3411         done
3414 generate_src() {
3415         if [ "$os" = "OSX" ] && [ "$enable_universal" != "0" ]; then
3416                 generate_src_osx
3417         else
3418                 generate_src_normal "[SRC]" "objs"
3419         fi
3422 showhelp() {
3423         echo "'configure' configures OpenTTD."
3424         echo ""
3425         echo "Usage: $0 [OPTION]... [VAR=VALUE]..."
3426         echo ""
3427         echo "To assign environment variables (e.g., CC, CFLAGS...), specify them as"
3428         echo "VAR=VALUE.  See below for descriptions of some of the useful variables."
3429         echo ""
3430         echo "Defaults for the options are specified in brackets."
3431         echo ""
3432         echo "Configuration:"
3433         echo "  -h, --help                     display this help and exit"
3434         echo ""
3435         echo "System types:"
3436         echo "  --build=BUILD                  configure for building on BUILD [guessed]"
3437         echo "  --host=HOST                    cross-compile to build programs to run"
3438         echo "                                 on HOST [BUILD]"
3439         echo "  --windres=WINDRES              the windres to use [HOST-windres]"
3440         echo "  --strip=STRIP                  the strip to use [HOST-strip]"
3441         echo "  --awk=AWK                      the awk to use in configure [awk]"
3442         echo "  --pkg-config=PKG-CONFIG        the pkg-config to use in configure [pkg-config]"
3443         echo "  --lipo=LIPO                    the lipo to use (OSX ONLY) [HOST-lipo]"
3444         echo "  --os=OS                        the OS we are compiling for [DETECT]"
3445         echo "                                 DETECT/UNIX/OSX/FREEBSD/DRAGONFLY/OPENBSD/"
3446         echo "                                 NETBSD/MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/"
3447         echo "                                 MINGW/OS2/DOS/WINCE/PSP/HAIKU"
3448         echo "  --endian=ENDIAN                set the endian of the HOST (AUTO/LE/BE)"
3449         echo ""
3450         echo "Paths:"
3451         echo "  --prefix-dir=dir               specifies the prefix for all installed"
3452         echo "                                 files [/usr/local]"
3453         echo "  --binary-dir=dir               location of the binary. Will be prefixed"
3454         echo "                                 with the prefix-dir [games]"
3455         echo "  --data-dir=dir                 location of data files (lang, data, gm)."
3456         echo "                                 Will be prefixed with the prefix-dir"
3457         echo "                                 [share/games/openttd]"
3458         echo "  --doc-dir=dir                  location of the doc files"
3459         echo "                                 Will be prefixed with the prefix-dir"
3460         echo "                                 [$doc_dir]"
3461         echo "  --icon-dir=dir                 location of icons. Will be prefixed"
3462         echo "                                 with the prefix-dir [share/pixmaps]"
3463         echo "  --icon-theme-dir=dir           location of icon theme."
3464         echo "                                 Will be prefixed with the prefix-dir"
3465         echo "                                 and postfixed with size-dirs [$icon_theme_dir]"
3466         echo "  --man-dir=dir                  location of the manual page (UNIX only)"
3467         echo "                                 Will be prefixed with the prefix-dir"
3468         echo "                                 [$man_dir]"
3469         echo "  --menu-dir=dir                 location of the menu item. (UNIX only, except OSX)"
3470         echo "                                 Will be prefixed with the prefix-dir"
3471         echo "                                 [share/applications]"
3472         echo "  --personal-dir=dir             location of the personal directory"
3473         echo "                                 [os-dependent default]"
3474         echo "  --shared-dir=dir               location of shared data files"
3475         echo "                                 [os-dependent default]"
3476         echo "  --install-dir=dir              specifies the root to install to."
3477         echo "                                 Useful to install into jails [/]"
3478         echo "  --binary-name                  the name used for the binary, icons,"
3479         echo "                                 desktop file, etc. when installing [openttd]"
3480         echo ""
3481         echo "Features and packages:"
3482         echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
3483         echo "  --enable-desync-debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
3484         echo "  --enable-profiling             enables profiling"
3485         echo "  --enable-lto                   enables GCC's Link Time Optimization (LTO)/ICC's"
3486         echo "                                 Interprocedural Optimization if available"
3487         echo "  --enable-dedicated             compile a dedicated server (without video)"
3488         echo "  --enable-static                enable static compile (doesn't work for"
3489         echo "                                 all HOSTs)"
3490         echo "  --enable-translator            enable extra output for translators"
3491         echo "  --enable-universal[=ARCH]      enable universal builds (OSX ONLY). Allowed is any combination"
3492         echo "                                 of architectures: i386 ppc ppc970 ppc64 x86_64"
3493         echo "                                 Default architectures are: i386 ppc"
3494         echo "  --enable-osx-g5                enables optimizations for ppc970 (G5) (OSX ONLY)"
3495         echo "  --disable-cocoa-quartz         disable the quartz window mode driver for Cocoa (OSX ONLY)"
3496         echo "  --disable-cocoa-quickdraw      disable the quickdraw window mode driver for Cocoa (OSX ONLY)"
3497         echo "  --disable-unicode              disable unicode support to build win9x"
3498         echo "                                 version (Win32 ONLY)"
3499         echo "  --enable-console               compile as a console application instead of as a GUI application."
3500         echo "                                 If this setting is active, debug output will appear in the same"
3501         echo "                                 console instead of opening a new window. (Win32 ONLY)"
3502         echo "  --disable-network              disable network support"
3503         echo "  --disable-assert               disable asserts (continue on errors)"
3504         echo "  --enable-strip                 enable any possible stripping"
3505         echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
3506         echo "                                 (OSX ONLY)"
3507         echo "  --without-application-bundle   disable generation of application bundle"
3508         echo "                                 (OSX ONLY)"
3509         echo "  --without-menu-entry           Don't generate a menu item (Freedesktop based only)"
3510         echo "  --menu-group=group             Category in which the menu item will be placed (Freedesktop based only)"
3511         echo "  --menu-name=name               Name of the menu item when placed [OpenTTD]"
3512         echo "  --with-direct-music            enable direct music support (Win32 ONLY)"
3513         echo "  --with-sort=sort               define a non-default location for sort"
3514         echo "  --with-midi=midi               define which midi-player to use"
3515         echo "  --with-midi-arg=arg            define which args to use for the"
3516         echo "                                 midi-player"
3517         echo "  --with-libtimidity[=\"pkg-config libtimidity\"]"
3518         echo "                                 enables libtimidity support"
3519         echo "  --with-allegro[=\"pkg-config allegro\"]"
3520         echo "                                 enables Allegro video driver support"
3521         echo "  --with-cocoa                   enables COCOA video driver (OSX ONLY)"
3522         echo "  --with-sdl[=\"pkg-config sdl\"]  enables SDL video driver support"
3523         echo "  --with-zlib[=\"pkg-config zlib\"]"
3524         echo "                                 enables zlib support"
3525         echo "  --with-liblzma[=\"pkg-config liblzma\"]"
3526         echo "                                 enables liblzma support"
3527         echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
3528         echo "  --with-png[=\"pkg-config libpng\"]"
3529         echo "                                 enables libpng support"
3530         echo "  --with-freetype[=\"pkg-config freetype2\"]"
3531         echo "                                 enables libfreetype support"
3532         echo "  --with-fontconfig[=\"pkg-config fontconfig\"]"
3533         echo "                                 enables fontconfig support"
3534         echo "  --with-xdg-basedir[=\"pkg-config libxdg-basedir\"]"
3535         echo "                                 enables XDG base directory support"
3536         echo "  --with-icu                     enables icu components for layout and sorting"
3537         echo "  --with-icu-layout[=\"pkg-config icu-lx\"]"
3538         echo "                                 enables icu components for layouting (right-to-left support)"
3539         echo "  --with-icu-sort[=\"pkg-config icu-i18n\"]"
3540         echo "                                 enables icu components for locale specific string sorting"
3541         echo "  --static-icu                   try to link statically (libsicu instead of"
3542         echo "                                 libicu; can fail as the new name is guessed)"
3543         echo "  --with-iconv[=iconv-path]      enables iconv support"
3544         echo "  --with-psp-config[=psp-config] enables psp-config support (PSP ONLY)"
3545         echo "  --disable-builtin-depend       disable use of builtin deps finder"
3546         echo "  --with-makedepend[=makedepend] enables makedepend support"
3547         echo "  --with-ccache                  enables ccache support"
3548         echo "  --with-distcc                  enables distcc support"
3549         echo "  --without-grfcodec             disable usage of grfcodec and re-generation of base sets"
3550         echo "  --without-threads              disable threading support"
3551         echo "  --without-sse                  disable SSE support (x86/x86_64 only)"
3552         echo ""
3553         echo "Some influential environment variables:"
3554         echo "  CC                             C compiler command"
3555         echo "  CXX                            C++ compiler command"
3556         echo "  CFLAGS                         C compiler flags"
3557         echo "  CXXFLAGS                       C++ compiler flags"
3558         echo "  WINDRES                        windres command"
3559         echo "  LDFLAGS                        linker flags, e.g. -L<lib dir> if you"
3560         echo "                                 have libraries in a nonstandard"
3561         echo "                                 directory <lib dir>"
3562         echo "  CFLAGS_BUILD                   C compiler flags for build time tool generation"
3563         echo "  CXXFLAGS_BUILD                 C++ compiler flags for build time tool generation"
3564         echo "  LDFLAGS_BUILD                  linker flags for build time tool generation"
3565         echo ""
3566         echo "Use these variables to override the choices made by 'configure' or to help"
3567         echo "it to find libraries and programs with nonstandard names/locations."