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