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