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