1#!/bin/sh
2#
3# configure -- custom configure script for ScummVM.
4#
5# ScummVM is the legal property of its developers, whose names
6# are too numerous to list here. Please refer to the COPYRIGHT
7# file distributed with this source distribution.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22#
23
24# NLS nuisances.
25LC_ALL=C
26export LC_ALL
27LANGUAGE=C
28export LANGUAGE
29
30# Save the current environment variables for next runs
31SAVED_CONFIGFLAGS=$@
32SAVED_LDFLAGS=$LDFLAGS
33SAVED_CXX=$CXX
34SAVED_CXXFLAGS=$CXXFLAGS
35SAVED_CPPFLAGS=$CPPFLAGS
36SAVED_ASFLAGS=$ASFLAGS
37SAVED_WINDRESFLAGS=$WINDRESFLAGS
38SAVED_SDL_CONFIG=$SDL_CONFIG
39
40# Use environment vars if set
41CXXFLAGS="$CXXFLAGS $CPPFLAGS"
42
43# Backslashes into forward slashes:
44# The following OS/2 specific code is performed to deal with handling of backslashes by ksh.
45# Borrowed from the Sane configure script
46
47if test "$ac_emxsupport" != "no" -a "$ac_emxsupport" != "NO"; then
48	ac_save_IFS="$IFS"
49	IFS="\\"
50	ac_TEMP_PATH=
51	for ac_dir in $PATH; do
52		IFS=$ac_save_IFS
53		if test -z "$ac_TEMP_PATH"; then
54			ac_TEMP_PATH="$ac_dir"
55		else
56			ac_TEMP_PATH="$ac_TEMP_PATH/$ac_dir"
57		fi
58	done
59	PATH="$ac_TEMP_PATH"
60	export PATH
61	unset ac_TEMP_PATH
62fi
63
64set_var() {
65	eval ${1}='${2}'
66}
67
68get_var() {
69	eval echo \$${1}
70}
71
72append_var() {
73	VAR=${1}
74	shift
75	if eval test -z \"\$${VAR}\" ; then
76		eval ${VAR}='$@'
77	else
78		eval ${VAR}=\"\$${VAR} \"'$@'
79	fi
80}
81
82prepend_var() {
83	VAR=${1}
84	shift
85	if eval test -z \"\$${VAR}\" ; then
86		eval ${VAR}='$@'
87	else
88		eval ${VAR}='$@'\" \$${VAR}\"
89	fi
90}
91
92# Add an engine: id name build subengines base-games dependencies
93add_engine() {
94	_engines="${_engines} ${1}"
95	if test "${3}" = "no" ; then
96		set_var _wip_engines "${_wip_engines} ${1}"
97	fi
98	set_var _engine_${1}_name "${2}"
99	set_var _engine_${1}_build "${3}"
100	set_var _engine_${1}_build_default "${3}"
101	set_var _engine_${1}_subengines "${4}"
102	set_var _engine_${1}_base "${5}"
103	set_var _engine_${1}_deps "${6}"
104	for sub in ${4}; do
105		set_var _engine_${sub}_sub "yes"
106		set_var _engine_${sub}_parent "${1}"
107	done
108}
109
110# Add a feature: id name settings-list
111add_feature() {
112	set_var _feature_${1}_name "${2}"
113	# This is a list of settings, where one must be "yes" for the feature to
114	# be enabled
115	set_var _feature_${1}_settings "${3}"
116}
117
118_srcdir=`dirname $0`
119
120# Read list of engines
121for i in $_srcdir/engines/*/configure.engine; do
122	. "$i"
123done
124
125#
126# Default settings
127#
128#ResidualVM defaults: faad=no, opengles=no, tremor=no mt32emu=no, translation=no,
129# flac=no, seq_midi=no, snd_io=no, timidity=no fluidsynth=no, opengles2=no
130# eventrec=no, build_scalers=no, build_hq_scalers=no, sdlnet=no, libcurl=no, cloud=no
131#
132# Default lib behaviour yes/no/auto
133_vorbis=auto
134_sdlnet=no
135_libcurl=no
136_tremor=no
137_tremolo=no
138_flac=no
139_mad=auto
140_alsa=no
141_seq_midi=no
142_sndio=no
143_timidity=no
144_zlib=auto
145_mpeg2=auto
146_sparkle=auto
147_osxdockplugin=auto
148_jpeg=auto
149_png=auto
150_theoradec=auto
151_faad=no
152_fluidsynth=no
153_glew=auto
154_opengl=auto
155_opengles=no
156_opengles2=no
157_opengl_shaders=auto
158_readline=auto
159_freetype2=auto
160_iconv=auto
161_taskbar=auto
162_updates=no
163_libunity=auto
164# Default option behavior yes/no
165_debug_build=auto
166_release_build=auto
167_optimizations=auto
168_use_cxx11=no
169_verbose_build=no
170_text_console=no
171_mt32emu=no
172_build_scalers=no
173_build_hq_scalers=no
174_enable_prof=no
175_global_constructors=no
176_bink=yes
177_cloud=no
178# Default vkeybd/keymapper/eventrec options
179_vkeybd=no
180_keymapper=no
181_eventrec=no
182# GUI translation options
183_translation=yes
184# Default platform settings
185_backend=sdl
186_16bit=auto
187_highres=auto
188_savegame_timestamp=auto
189_dynamic_modules=no
190_elf_loader=no
191_plugins_default=static
192_plugin_prefix=
193_plugin_suffix=
194_nasm=auto
195_optimization_level=
196_default_optimization_level=-O2
197# Default commands
198_ranlib=ranlib
199_strip=strip
200_ar="ar cru"
201_as="as"
202_windres=windres
203_stagingpath="staging"
204_win32path="C:/residualvm"
205_amigaospath="Games:ResidualVM"
206_staticlibpath=
207_xcodetoolspath=
208_sparklepath=
209_sdlconfig=sdl2-config
210_libcurlconfig=curl-config
211_freetypeconfig=freetype-config
212_sdlpath="$PATH"
213_freetypepath="$PATH"
214_libcurlpath="$PATH"
215_nasmpath="$PATH"
216NASMFLAGS=""
217NASM=""
218_tainted_build=no
219# The following variables are automatically detected, and should not
220# be modified otherwise. Consider them read-only.
221_posix=no
222_endian=unknown
223_need_memalign=yes
224_have_x86=no
225
226# Add (virtual) features
227add_feature 16bit "16bit color" "_16bit"
228add_feature cloud "cloud" "_cloud"
229add_feature faad "libfaad" "_faad"
230add_feature flac "FLAC" "_flac"
231add_feature freetype2 "FreeType2" "_freetype2"
232add_feature highres "high resolution" "_highres"
233add_feature mad "MAD" "_mad"
234add_feature jpeg "JPEG" "_jpeg"
235add_feature png "PNG" "_png"
236add_feature theoradec "libtheoradec" "_theoradec"
237add_feature vorbis "Vorbis file support" "_vorbis _tremor"
238add_feature zlib "zlib" "_zlib"
239
240
241
242# Directories for installing ScummVM.
243# This list is closely based on what GNU autoconf does,
244# although the default value for datadir differs.
245# Like GNU autoconf, we distinguish datadir and datarootdir
246# to make it possible to change e.g. the location of the
247# man pages independently of that of the engine data files,
248# which are placed inside $datadir/residualvm
249prefix=NONE
250exec_prefix=NONE
251bindir='${exec_prefix}/bin'
252libdir='${exec_prefix}/lib'
253datarootdir='${prefix}/share'
254datadir='${datarootdir}/residualvm'
255mandir='${prefix}/man'
256docdir='${datarootdir}/doc/residualvm'
257#localedir='${datarootdir}/locale'
258
259# For cross compiling
260_host=""
261_host_cpu=""
262_host_vendor=""
263_host_os=""
264_host_alias=""
265
266_port_mk="ports.mk"
267
268# Use temp files in the build directory
269TMPO=./residualvm-conf
270TMPC=${TMPO}.cpp
271TMPLOG=config.log
272
273cc_check_no_clean() {
274	echo >> "$TMPLOG"
275	cat "$TMPC" >> "$TMPLOG"
276	echo >> "$TMPLOG"
277	echo "$CXX $LDFLAGS $CXXFLAGS $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
278	rm -f "$TMPO$HOSTEXEEXT"
279	if test "-c" = "$*" ; then
280		( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
281	else
282		( $CXX $LDFLAGS $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
283	fi
284	TMPR="$?"
285	echo "return code: $TMPR" >> "$TMPLOG"
286	echo >> "$TMPLOG"
287	return "$TMPR"
288}
289
290cc_check_clean() {
291	rm -rf $TMPC $TMPO $TMPO.o $TMPO.dSYM $TMPO$HOSTEXEEXT "$@"
292}
293
294cc_check() {
295	cc_check_no_clean "$@"
296	TMPR="$?"
297	cc_check_clean
298	return "$TMPR"
299}
300
301cc_check_define() {
302cat > $TMPC << EOF
303int main(void) {
304	#ifndef $1
305	syntax error
306	#endif
307	return 0;
308}
309EOF
310	cc_check -c
311	return $?
312}
313
314gcc_get_define() {
315	echo "" | $CXX -dM -E - | fgrep "$1" | head -n1 | cut -d ' ' -f 3-
316}
317
318#
319# Function to provide echo -n for bourne shells that don't have it
320#
321echo_n() {
322	printf "$@"
323}
324
325echocheck() {
326	echo_n "Checking for $@... "
327}
328
329# Add a line of data to config.mk.
330add_line_to_config_mk() {
331	_config_mk_data="$_config_mk_data"'
332'"$1"
333}
334
335# Add a line of data to config.h.
336add_line_to_config_h() {
337	_config_h_data="$_config_h_data"'
338'"$1"
339}
340
341# Conditionally add a line of data to config.h. Takes two parameters:
342# The first one can be set to 'no' to "comment out" the line, i.e.
343# make it ineffective, use 'yes' otherwise.
344# The second param is the line to insert.
345add_to_config_h_if_yes() {
346	if test "$1" = yes ; then
347		add_line_to_config_h "$2"
348	else
349		add_line_to_config_h "/* $2 */"
350	fi
351}
352
353# Conditionally add a line of data to config.mk. Takes two parameters:
354# The first one can be set to 'no' to "comment out" the line, i.e.
355# make it ineffective, use 'yes' otherwise.
356# The second param is the line to insert.
357add_to_config_mk_if_yes() {
358	if test "$1" = yes ; then
359		add_line_to_config_mk "$2"
360	else
361		add_line_to_config_mk "# $2"
362	fi
363}
364
365# Conditionally add a '#define' line to config.h. Takes two parameters:
366# The first one can be set to 'yes' or 'no'. If 'yes' is used, then
367# the line "#define $2" is added to config.h, otherwise "#undef $2".
368define_in_config_h_if_yes() {
369	if test "$1" = yes ; then
370		add_line_to_config_h "#define $2"
371	else
372		add_line_to_config_h "#undef $2"
373	fi
374}
375
376# Conditionally add definitions to config.h and config.mk. Takes two parameters:
377# The first one can be set to 'yes' or 'no'. If 'yes' is used, then
378# the line "#define $2" is added to config.h and "$2 = 1" to config.mk.
379# Otherwise "#undef $2" is added to config.h and "# $2 = 1" to config.mk
380define_in_config_if_yes() {
381	if test "$1" = yes ; then
382		add_line_to_config_h "#define $2"
383		add_line_to_config_mk "$2 = 1"
384	else
385		add_line_to_config_h "#undef $2"
386		add_line_to_config_mk "# $2 = 1"
387	fi
388}
389
390#
391# Determine sdl-config
392#
393# TODO: small bit of code to test sdl usability
394find_sdlconfig() {
395	echo_n "Looking for sdl-config... "
396	sdlconfigs="$SDL_CONFIG:$_sdlconfig:sdl2-config:sdl12-config:sdl11-config:sdl-config"
397	_sdlconfig=
398
399	IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR"
400	for path_dir in $_sdlpath; do
401		#reset separator to parse sdlconfigs
402		IFS=":"
403		for sdlconfig in $sdlconfigs; do
404			if test -f "$path_dir/$sdlconfig" ; then
405				_sdlconfig="$path_dir/$sdlconfig"
406				echo $_sdlconfig
407				# Save the prefix
408				_sdlpath=$path_dir
409				if test `basename $path_dir` = bin ; then
410					_sdlpath=`dirname $path_dir`
411				fi
412				# break at first sdl-config found in path
413				break 2
414			fi
415		done
416	done
417
418	IFS="$ac_save_ifs"
419
420	if test -z "$_sdlconfig"; then
421		echo "none found!"
422		exit 1
423	fi
424}
425
426#
427# Determine freetype-config
428#
429find_freetypeconfig() {
430	echo_n "Looking for freetype-config... "
431	freetypeconfigs="$_freetypeconfig"
432	_freetypeconfig=
433
434	IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR"
435	for path_dir in $_freetypepath; do
436		#reset separator to parse freetypeconfigs
437		IFS=":"
438		for freetypeconfig in $freetypeconfigs; do
439			if test -f "$path_dir/$freetypeconfig" ; then
440				_freetypeconfig="$path_dir/$freetypeconfig"
441				echo $_freetypeconfig
442				# Save the prefix
443				_freetypepath=$path_dir
444				if test `basename $path_dir` = bin ; then
445					_freetypepath=`dirname $path_dir`
446				fi
447				# break at first freetype-config found in path
448				break 2
449			fi
450		done
451	done
452
453	IFS="$ac_save_ifs"
454
455	if test -z "$_freetypeconfig"; then
456		echo "none found!"
457	fi
458}
459
460#
461# Determine curl-config
462#
463find_libcurlconfig() {
464	echo_n "Looking for curl-config... "
465	libcurlconfigs="$_libcurlconfig"
466	_libcurlconfig=
467
468	IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR"
469	for path_dir in $_libcurlpath; do
470		#reset separator to parse sdlconfigs
471		IFS=":"
472		for libcurlconfig in $libcurlconfigs; do
473			if test -f "$path_dir/$libcurlconfig" ; then
474				_libcurlconfig="$path_dir/$libcurlconfig"
475				echo $_libcurlconfig
476				# Save the prefix
477				_libcurlpath=$path_dir
478				if test `basename $path_dir` = bin ; then
479					_libcurlpath=`dirname $path_dir`
480				fi
481				# break at first curl-config found in path
482				break 2
483			fi
484		done
485	done
486
487	IFS="$ac_save_ifs"
488
489	if test -z "$_libcurlconfig"; then
490		echo "none found!"
491	fi
492}
493
494#
495# Determine extension used for executables
496#
497get_system_exe_extension() {
498	case $1 in
499	arm-riscos)
500		_exeext=",ff8"
501		;;
502	3ds | dreamcast | ds | gamecube | n64 | ps2 | psp | wii)
503		_exeext=".elf"
504		;;
505	gph-linux)
506		_exeext=".gph"
507		;;
508	mingw* | *os2-emx | wince)
509		_exeext=".exe"
510		;;
511	*)
512		_exeext=""
513		;;
514	esac
515}
516
517#
518# Generic options functions
519#
520
521# Show the configure help line for an option
522option_help() {
523	if test "${3}" != "" ; then
524		tmpopt_prefix="${3}"
525	else
526		tmpopt_prefix="--"
527	fi
528	tmpopt=`echo $1 | sed 's/_/-/g'`
529	option=`echo "${tmpopt_prefix}${tmpopt}                       " | sed "s/\(.\{23\}\).*/\1/"`
530	echo "  ${option}  ${2}"
531}
532
533# Show an error about an unknown option
534option_error() {
535	echo "error: unrecognized option: $ac_option
536Try \`$0 --help' for more information." >&2
537	exit 1
538}
539
540# Show an error about an unknown engine
541engine_option_error() {
542	echo "error: unrecognized engine: $1
543Try \`$0 --help' for more information." >&2
544	exit 1
545}
546
547# Show an error about an invalid subengine option
548subengine_option_error() {
549	echo "error: this option is invalid for the subengine $1: $ac_option
550Try \`$0 --help' for more information." >&2
551	exit 1
552}
553
554
555#
556# Feature handling functions
557#
558
559# Get the name of the feature
560get_feature_name() {
561	get_var _feature_$1_name
562}
563
564# Check whether the feature is enabled
565get_feature_state() {
566	for i in `get_var _feature_$1_settings`; do
567		if test `get_var $i` = "yes"; then
568			echo "yes"
569			return
570		fi
571	done
572	echo "no"
573}
574
575
576#
577# Engine handling functions
578#
579
580# Get the name of the engine
581get_engine_name() {
582	get_var _engine_$1_name
583}
584
585# Will this engine be built?
586get_engine_build() {
587	get_var _engine_$1_build
588}
589
590# Was this engine set to be built by default?
591get_engine_build_default() {
592	get_var _engine_$1_build_default
593}
594
595# Get the subengines
596get_engine_subengines() {
597	get_var _engine_$1_subengines
598}
599
600# Get the dependencies
601get_engine_dependencies() {
602	get_var _engine_$1_deps
603}
604
605# Get the base engine game support description
606get_engine_base() {
607	get_var _engine_$1_base
608}
609
610# Ask if this is a subengine
611get_engine_sub() {
612	sub=`get_var _engine_$1_sub`
613	if test -z "$sub" ; then
614		sub=no
615	fi
616	echo $sub
617}
618
619# Get a subengine's parent (undefined for non-subengines)
620get_subengine_parent() {
621	get_var _engine_$1_parent
622}
623
624# Enable *all* engines
625engine_enable_all() {
626	for engine in $_engines; do
627		set_var _engine_${engine}_build "yes"
628	done
629}
630
631# Disable *all* engines
632engine_disable_all() {
633	for engine in $_engines; do
634		set_var _engine_${engine}_build "no"
635	done
636}
637
638# Enable the given engine
639engine_enable() {
640	# Get the parameter
641	if ( echo $1 | grep ':' ) 2> /dev/null > /dev/null ; then
642		eng=`echo $1 | cut -d ':' -f 1`
643		opt=`echo $1 | cut -d ':' -f 2`
644	else
645		eng=$1
646		opt=yes
647	fi
648	engine=`echo $eng | sed 's/-/_/g'`
649
650	# Filter the parameter for the subengines
651	if test "`get_engine_sub ${engine}`" != "no" ; then
652		if test "$opt" != "yes" ; then
653			subengine_option_error ${engine}
654			return
655		fi
656		parent=`get_subengine_parent ${engine}`
657		if test `get_engine_build ${parent}` = "no" ; then
658			set_var _engine_${parent}_build "yes"
659		fi
660	fi
661
662	if test "$opt" = "static" -o "$opt" = "dynamic" -o "$opt" = "yes" ; then
663		if test "`get_engine_name ${engine}`" != "" ; then
664			set_var _engine_${engine}_build "$opt"
665		else
666			engine_option_error ${engine}
667		fi
668	else
669		option_error
670	fi
671}
672
673# Disable the given engine
674engine_disable() {
675	# Filter malformed options
676	if ( echo $1 | grep '=' ) 2> /dev/null > /dev/null ; then
677		option_error
678		return
679	fi
680
681	engine=`echo $1 | sed 's/-/_/g'`
682	if test "`get_engine_name ${engine}`" != "" ; then
683		set_var _engine_${engine}_build "no"
684	else
685		engine_option_error ${engine}
686	fi
687}
688
689# Check whether the engine's dependencies are met
690# If that is not the case disable the engine
691check_engine_deps() {
692	unmet_deps=""
693
694	# Check whether the engine is enabled
695	if test `get_engine_build $1` != "no" ; then
696		# Collect unmet dependencies
697		for dep in `get_engine_dependencies $1`; do
698			if test `get_feature_state $dep` = "no"; then
699				feature_name=`get_feature_name $dep`
700				unmet_deps="${unmet_deps}${feature_name} "
701			fi
702		done
703
704		# Check whether there is any unmet dependency
705		if test -n "$unmet_deps"; then
706			echo "WARNING: Disabling engine "`get_engine_name $1`" because the following dependencies are unmet: "$unmet_deps
707			engine_disable $1
708		fi
709	fi
710}
711
712# Show the configure help line for a given engine
713show_engine_help() {
714	name=`get_engine_name $1`
715	option_help "${1}" "${name} engine" "  "
716	for sub in `get_engine_subengines $1`; do
717		show_subengine_help $sub $1
718	done
719}
720
721# Show the configure help line for a given subengine
722show_subengine_help() {
723	name=`get_engine_name $1`
724	parent=`get_engine_name $2`
725	option_help "${1}" "${name} in ${parent} engine" "  "
726}
727
728# Prepare the strings about the engines to build
729prepare_engine_build_strings() {
730	string=`get_engine_build_string $1 static`
731	if test -n "$string" ; then
732		_engines_built_static="${_engines_built_static}#$string@"
733	fi
734
735	string=`get_engine_build_string $1 dynamic`
736	if test -n "$string" ; then
737		_engines_built_dynamic="${_engines_built_dynamic}#$string@"
738	fi
739
740	string=`get_engine_build_string $1 no`
741	if test -n "$string" ; then
742		_engines_skipped="${_engines_skipped}#$string@"
743	fi
744
745	string=`get_engine_build_string $1 wip`
746	if test -n "$string" ; then
747		_engines_built_wip="${_engines_built_wip}#$string@"
748	fi
749
750}
751
752# Get the string about building an engine
753get_engine_build_string() {
754	engine=$1
755	request_status=$2
756	engine_string=""
757	engine_build=`get_engine_build $1`
758	engine_build_default=`get_engine_build_default $engine`
759	show=no
760
761	# Convert static/dynamic to yes to ease the check of subengines
762	if test $engine_build = no; then
763		subengine_filter=no
764	else
765		subengine_filter=yes
766	fi
767
768	# Check if the current engine should be shown for the current status
769	if test $engine_build = $request_status ; then
770		show=yes
771	else
772		# Test for disabled sub-engines
773		if test $request_status = no ; then
774			for subeng in `get_engine_subengines $engine` ; do
775				if test `get_engine_build $subeng` = no ; then
776					# In this case we to display _disabled_ subengines
777					subengine_filter=no
778					show=yes
779				fi
780			done
781		fi
782		# Test for enabled wip sub-engines
783		if test $request_status = wip ; then
784			for subeng in `get_engine_subengines $engine` ; do
785				if test `get_engine_build $subeng` != no -a `get_engine_build_default $subeng` = no ; then
786					show=yes
787				fi
788			done
789		fi
790	fi
791
792
793	# Check if it is a wip engine
794	if test "$request_status" = "wip" -a "$engine_build" != "no" -a  "$engine_build_default" = no; then
795		show=yes
796	fi
797
798	# The engine should be shown, build the string
799	if test $show = yes ; then
800		engine_string=`get_subengines_build_string $engine $subengine_filter $request_status`
801		engine_string="`get_engine_name $engine` $engine_string"
802	fi
803
804	echo "$engine_string"
805}
806
807# Get the string about building subengines
808get_subengines_build_string() {
809	parent_engine=$1
810	subengine_filter=$2
811	request_status=$3
812	parent_engine_build_default=`get_engine_build_default $parent_engine`
813	subengine_string=""
814
815	# If the base engine isn't built at all, no need to list subengines
816	# in any of the possible categories.
817	if test `get_engine_build $parent_engine` = no; then
818		return
819	fi
820
821	all=yes
822	# If there are no subengines, never display "[all games]" (for brevity).
823	if test -z "`get_engine_subengines $parent_engine`"; then
824		all=no
825	fi
826	# If the base engine does not fit the category we're displaying here
827	# (WIP or Skipped), we should never show "[all games]"
828	if test "$request_status" = wip; then
829		if test $parent_engine_build_default = yes; then
830			all=no
831		fi
832	fi
833	if test "$request_status" = no; then
834		# If we're here, the parent engine is built, so no need to check that.
835		all=no
836	fi
837
838
839	# In the static/dynamic categories, also display the engine's base games.
840	if test -n "`get_engine_subengines $parent_engine`" -a $request_status != no -a $request_status != wip; then
841		subengine_string="[`get_engine_base $parent_engine`]"
842	fi
843
844	for subeng in `get_engine_subengines $parent_engine` ; do
845		subengine_build=`get_engine_build $subeng`
846		subengine_build_default=`get_engine_build_default $subeng`
847
848		# Display this subengine if it matches the filter, unless it is
849		# a stable subengine in the WIP request.
850		if test $subengine_build = $subengine_filter -a \! \( "$request_status" = wip -a "$subengine_build_default" = yes \) ; then
851			s="[`get_engine_name $subeng`]"
852			if test -n "$subengine_string"; then
853				subengine_string="$subengine_string $s"
854			else
855				subengine_string="$s"
856			fi
857		else
858			all=no
859		fi
860	done
861
862	# Summarize the full list, where applicable
863	if test $all = yes ; then
864		subengine_string="[all games]"
865	fi
866
867	echo "$subengine_string"
868}
869
870#
871# Check any parameters we received
872#
873# TODO:
874# * Change --disable-mad / --enable-mad to the way it's done in autoconf:
875#  That is, --without-mad / --with-mad=/prefix/to/mad. Useful for people
876#  who have Mad/Vorbis/ALSA installed in a non-standard locations.
877#
878
879for parm in "$@" ; do
880	if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then
881		for engine in $_engines; do
882			if test `get_engine_sub $engine` = no ; then
883				engines_help="$engines_help`show_engine_help $engine`
884"
885			fi
886		done
887		cat << EOF
888
889Usage: $0 [OPTIONS]...
890
891Configuration:
892  -h, --help              display this help and exit
893  --backend=BACKEND       backend to build (android, sdl) [sdl]
894
895Installation directories:
896  --prefix=PREFIX         install architecture-independent files in PREFIX
897                          [/usr/local]
898  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
899                          [PREFIX]
900
901By default, \`make install' will install all the files in
902\`/usr/local/bin', \`/usr/local/lib' etc.  You can specify
903an installation prefix other than \`/usr/local' using \`--prefix',
904for instance \`--prefix=\$HOME'.
905
906For better control, use the options below.
907
908Fine tuning of the installation directories:
909  --bindir=DIR            user executables [EPREFIX/bin]
910  --libdir=DIR            object code libraries [EPREFIX/lib]
911  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
912  --datadir=DIR           read-only architecture-independent data
913                          [DATAROOTDIR/residualvm]
914  --mandir=DIR            man documentation [DATAROOTDIR/man]
915  --docdir=DIR            documentation root [DATAROOTDIR/doc/residualvm]
916
917Special configuration feature:
918  --host=HOST             cross-compile to target HOST (arm-linux, ...)
919                          special targets: android-arm for Android ARM
920                                           android-mips for Android MIPS
921                                           android-x86 for Android x86
922                                           ps3 for PlayStation 3
923
924Game engines:
925  --enable-all-engines     enable all engines, including those which are
926                           broken or unsupported
927  --disable-all-engines    disable all engines
928  --enable-engine=<engine name>[,<engine name>...] enable engine(s) listed
929  --disable-engine=<engine name>[,<engine name>...] disable engine(s) listed
930  --enable-engine-static=<engine name>[,<engine name>...]
931      enable engine(s) listed as static builtin (when plugins are enabled)
932  --enable-engine-dynamic=<engine name>[,<engine name>...]
933      enable engine(s) listed as dynamic plugin (when plugins are enabled)
934    The values of <engine name> for these options are as follows:
935$engines_help
936Optional Features:
937  --enable-c++11           build as C++11 if the compiler allows that
938  --disable-debug          disable building with debugging symbols
939  --enable-Werror          treat warnings as errors
940  --enable-release         enable building in release mode (this activates
941                           optimizations)
942  --enable-release-mode    enable building in release mode (without optimizations)
943  --enable-optimizations   enable optimizations
944  --enable-profiling       enable profiling
945  --enable-plugins         enable the support for dynamic plugins
946  --default-dynamic        make plugins dynamic by default
947  --disable-savegame-timestamp don't use timestamps for blank savegame descriptions
948  --disable-translation    don't build support for translated messages
949  --disable-taskbar        don't build support for taskbar and launcher integration
950  --disable-cloud          don't build cloud support
951  --enable-vkeybd          build virtual keyboard support
952  --enable-keymapper       build key mapper support
953  --enable-updates         build support for updates
954  --enable-text-console    use text console instead of graphical console
955  --enable-verbose-build   enable regular echoing of commands during build
956                           process
957  --disable-bink           don't build with Bink video support
958
959Optional Libraries:
960  --with-alsa-prefix=DIR   Prefix where alsa is installed (optional)
961  --disable-alsa           disable ALSA midi sound support [autodetect]
962
963  --with-ogg-prefix=DIR    Prefix where libogg is installed (optional)
964  --with-vorbis-prefix=DIR Prefix where libvorbis is installed (optional)
965  --disable-vorbis         disable Ogg Vorbis support [autodetect]
966
967  --with-tremor-prefix=DIR Prefix where tremor is installed (optional)
968  --disable-tremor         disable tremor support [autodetect]
969
970  --with-mad-prefix=DIR    Prefix where libmad is installed (optional)
971  --disable-mad            disable libmad (MP3) support [autodetect]
972
973  --with-flac-prefix=DIR   Prefix where libFLAC is installed (optional)
974  --disable-flac           disable FLAC support [autodetect]
975
976  --with-zlib-prefix=DIR   Prefix where zlib is installed (optional)
977  --disable-zlib           disable zlib (compression) support [autodetect]
978
979  --with-mpeg2-prefix=DIR  Prefix where libmpeg2 is installed (optional)
980  --enable-mpeg2           enable mpeg2 codec for cutscenes [autodetect]
981
982  --with-opengl-prefix=DIR Prefix where OpenGL (ES) is installed (optional)
983  --disable-opengl         disable OpenGL (ES) support [autodetect]
984  --disable-opengl-shaders disable use of modern OpenGL with shaders
985  --force-opengles2        only detect OpenGL ES2
986
987  --with-glew-prefix=DIR   Prefix where GLEW is installed (optional)
988  --disable-glew           disable GLEW support [autodetect]
989
990  --with-jpeg-prefix=DIR   Prefix where libjpeg is installed (optional)
991  --disable-jpeg           disable JPEG decoder [autodetect]
992
993  --with-png-prefix=DIR    Prefix where libpng is installed (optional)
994  --disable-png            disable PNG decoder [autodetect]
995
996  --with-theoradec-prefix=DIR Prefix where libtheoradec is installed (optional)
997  --disable-theoradec      disable Theora decoder [autodetect]
998
999  --with-faad-prefix=DIR   Prefix where libfaad is installed (optional)
1000  --disable-faad           disable AAC decoder [autodetect]
1001
1002  --with-fluidsynth-prefix=DIR  Prefix where libfluidsynth is
1003                           installed (optional)
1004  --disable-fluidsynth     disable fluidsynth MIDI driver [autodetect]
1005
1006  --with-sparkle-prefix=DIR   Prefix where sparkle is installed (OS X/Windows only - optional)
1007  --disable-sparkle        disable sparkle automatic update support [OS X/Windows only - autodetect]
1008
1009  --disable-osx-dock-plugin disable the NSDockTilePlugin support [Mac OS X only - autodetect]
1010
1011  --with-sdl-prefix=DIR    Prefix where the sdl-config script is
1012                           installed (optional)
1013
1014  --with-freetype2-prefix=DIR Prefix where the freetype-config script is
1015                           installed (optional)
1016  --disable-freetype2     disable freetype2 TTF library usage [autodetect]
1017
1018  --with-iconv-prefix=DIR  Prefix where iconv is installed (optional)
1019  --disable-iconv          disable iconv support [autodetect]
1020
1021  --with-nasm-prefix=DIR   Prefix where nasm executable is installed (optional)
1022  --disable-nasm           disable assembly language optimizations [autodetect]
1023
1024  --with-readline-prefix=DIR    Prefix where readline is installed (optional)
1025  --disable-readline       disable readline support in text console [autodetect]
1026
1027  --with-libunity-prefix=DIR   Prefix where libunity is installed (optional)
1028  --disable-libunity           disable Unity launcher integration [autodetect]
1029
1030  --with-sndio-prefix=DIR  Prefix where sndio is installed (optional)
1031  --disable-sndio          disable sndio MIDI driver [autodetect]
1032
1033  --with-sdlnet-prefix=DIR  Prefix where SDL_Net is
1034                           installed (optional)
1035  --disable-sdlnet         disable SDL_Net networking library [autodetect]
1036  --disable-libcurl        disable libcurl networking library [autodetect]
1037
1038Some influential environment variables:
1039  LDFLAGS        linker flags, e.g. -L<lib dir> if you have libraries in a
1040                 nonstandard directory <lib dir>
1041  CXX            C++ compiler command
1042  CXXFLAGS       C++ compiler flags
1043  CPPFLAGS       C++ preprocessor flags, e.g. -I<include dir> if you have
1044                 headers in a nonstandard directory <include dir>
1045  ASFLAGS        assembler flags
1046  WINDRESFLAGS   Windows resource compiler flags
1047
1048EOF
1049		exit 0
1050	fi
1051done # for parm in ...
1052
1053
1054#
1055# If we're not showing help, greet the user and start the log file
1056#
1057echo "Running ResidualVM configure..."
1058echo "Configure run on" `date` > $TMPLOG
1059cat >> $TMPLOG <<EOF
1060Invocation command line was:
1061$0 $@
1062Saved environment variables:
1063LDFLAGS="$SAVED_LDFLAGS" CXX="$SAVED_CXX" CXXFLAGS="$SAVED_CXXFLAGS" CPPFLAGS="$SAVED_CPPFLAGS" ASFLAGS="$SAVED_ASFLAGS" WINDRESFLAGS="$SAVED_WINDRESFLAGS" SDL_CONFIG="$SAVED_SDL_CONFIG"
1064EOF
1065
1066
1067for ac_option in $@; do
1068	case "$ac_option" in
1069#	--disable-16bit)          _16bit=no       ;; #ResidualVM: not supported
1070#	--enable-highres)         _highres=yes    ;; #ResidualVM: not supported
1071#	--disable-highres)        _highres=no     ;; #ResidualVM: not supported
1072	--disable-savegame-timestamp) _savegame_timestamp=no ;;
1073#	--disable-scalers)        _build_scalers=no ;; #ResidualVM: not supported
1074#	--disable-hq-scalers)     _build_hq_scalers=no ;; #ResidualVM: not supported
1075	--enable-alsa)            _alsa=yes       ;;
1076	--disable-alsa)           _alsa=no        ;;
1077	--enable-seq-midi)        _seq_midi=yes   ;;
1078	--disable-seq-midi)       _seq_midi=no    ;;
1079	--enable-sndio)           _sndio=yes      ;;
1080	--disable-sndio)          _sndio=no       ;;
1081	--enable-timidity)        _timidity=yes   ;;
1082	--disable-timidity)       _timidity=no    ;;
1083	--enable-vorbis)          _vorbis=yes     ;;
1084	--disable-vorbis)         _vorbis=no      ;;
1085	--enable-tremor)          _tremor=yes     ;;
1086	--disable-tremor)         _tremor=no      ;;
1087	--enable-flac)            _flac=yes       ;;
1088	--disable-flac)           _flac=no        ;;
1089	--enable-mad)             _mad=yes        ;;
1090	--disable-mad)            _mad=no         ;;
1091	--enable-zlib)            _zlib=yes       ;;
1092	--disable-zlib)           _zlib=no        ;;
1093	--enable-sparkle)         _sparkle=yes    ;;
1094	--disable-sparkle)        _sparkle=no     ;;
1095	--enable-osx-dock-plugin) _osxdockplugin=yes;;
1096	--disable-osx-dock-plugin) _osxdockplugin=no;;
1097	--enable-nasm)            _nasm=yes       ;;
1098	--disable-nasm)           _nasm=no        ;;
1099	--enable-mpeg2)           _mpeg2=yes      ;;
1100	--disable-mpeg2)          _mpeg2=no       ;;
1101	--disable-jpeg)           _jpeg=no        ;;
1102	--enable-jpeg)            _jpeg=yes       ;;
1103	--disable-png)            _png=no         ;;
1104	--enable-png)             _png=yes        ;;
1105	--disable-theoradec)      _theoradec=no   ;;
1106	--enable-theoradec)       _theoradec=yes  ;;
1107	--disable-faad)           _faad=no        ;;
1108	--enable-faad)            _faad=yes       ;;
1109	--disable-fluidsynth)     _fluidsynth=no  ;;
1110	--enable-fluidsynth)      _fluidsynth=yes ;; #ResidualVM specific option
1111	--enable-readline)        _readline=yes   ;;
1112	--disable-readline)       _readline=no    ;;
1113	--enable-freetype2)       _freetype2=yes  ;;
1114	--disable-freetype2)      _freetype2=no   ;;
1115	--enable-iconv)           _iconv=yes      ;;
1116	--disable-iconv)          _iconv=no       ;;
1117	--enable-taskbar)         _taskbar=yes    ;;
1118	--disable-taskbar)        _taskbar=no     ;;
1119	--enable-sdlnet)          _sdlnet=yes     ;;
1120	--disable-sdlnet)         _sdlnet=no      ;;
1121	--enable-libcurl)         _libcurl=yes     ;;
1122	--disable-libcurl)        _libcurl=no      ;;
1123	--enable-cloud)           _cloud=yes      ;;
1124	--disable-cloud)          _cloud=no       ;;
1125	--enable-updates)         _updates=yes    ;;
1126	--disable-updates)        _updates=no     ;;
1127	--enable-libunity)        _libunity=yes   ;;
1128	--disable-libunity)       _libunity=no    ;;
1129	--enable-glew)            _glew=yes       ;; #ResidualVM specific option
1130	--disable-glew)           _glew=no        ;; #ResidualVM specific option
1131	--enable-opengl)          _opengl=yes     ;;
1132	--disable-opengl)         _opengl=no      ;;
1133	--enable-opengl-shaders)  _opengl_shaders=yes     ;; #ResidualVM specific option
1134	--disable-opengl-shaders) _opengl_shaders=no      ;; #ResidualVM specific option
1135	--force-opengles2)        _opengles2=yes  ;; #ResidualVM specific option
1136	--enable-bink)            _bink=yes       ;;
1137	--disable-bink)           _bink=no        ;;
1138	--enable-verbose-build)   _verbose_build=yes ;;
1139	--enable-plugins)         _dynamic_modules=yes ;;
1140	--default-dynamic)        _plugins_default=dynamic ;;
1141#	--enable-mt32emu)         _mt32emu=yes    ;; #ResidualVM: not supported
1142#	--disable-mt32emu)        _mt32emu=no     ;; #ResidualVM: not supported
1143	--enable-translation)     _translation=yes ;;
1144	--disable-translation)    _translation=no ;;
1145	--enable-vkeybd)          _vkeybd=yes     ;;
1146	--disable-vkeybd)         _vkeybd=no      ;;
1147	--enable-keymapper)       _keymapper=yes  ;;
1148	--disable-keymapper)      _keymapper=no   ;;
1149#	--enable-eventrecorder)   _eventrec=yes  ;; #ResidualVM: not supported
1150#	--disable-eventrecorder)  _eventrec=no   ;; #ResidualVM: not supported
1151	--enable-text-console)    _text_console=yes ;;
1152	--disable-text-console)   _text_console=no ;;
1153	--with-fluidsynth-prefix=*)
1154		arg=`echo $ac_option | cut -d '=' -f 2`
1155		FLUIDSYNTH_CFLAGS="-I$arg/include"
1156		FLUIDSYNTH_LIBS="-L$arg/lib"
1157		;;
1158	--with-mpeg2-prefix=*)
1159		arg=`echo $ac_option | cut -d '=' -f 2`
1160		MPEG2_CFLAGS="-I$arg/include"
1161		MPEG2_LIBS="-L$arg/lib"
1162		;;
1163	--with-alsa-prefix=*)
1164		arg=`echo $ac_option | cut -d '=' -f 2`
1165		ALSA_CFLAGS="-I$arg/include"
1166		ALSA_LIBS="-L$arg/lib"
1167		;;
1168	--with-sndio-prefix=*)
1169		arg=`echo $ac_option | cut -d '=' -f 2`
1170		SNDIO_CFLAGS="-I$arg/include"
1171		SNDIO_LIBS="-L$arg/lib"
1172		;;
1173	--with-ogg-prefix=*)
1174		arg=`echo $ac_option | cut -d '=' -f 2`
1175		OGG_CFLAGS="-I$arg/include"
1176		OGG_LIBS="-L$arg/lib"
1177		;;
1178	--with-vorbis-prefix=*)
1179		arg=`echo $ac_option | cut -d '=' -f 2`
1180		VORBIS_CFLAGS="-I$arg/include"
1181		VORBIS_LIBS="-L$arg/lib"
1182		;;
1183	--with-tremor-prefix=*)
1184		arg=`echo $ac_option | cut -d '=' -f 2`
1185		TREMOR_CFLAGS="-I$arg/include"
1186		TREMOR_LIBS="-L$arg/lib"
1187		;;
1188	--with-flac-prefix=*)
1189		arg=`echo $ac_option | cut -d '=' -f 2`
1190		FLAC_CFLAGS="-I$arg/include"
1191		FLAC_LIBS="-L$arg/lib"
1192		;;
1193	--with-mad-prefix=*)
1194		arg=`echo $ac_option | cut -d '=' -f 2`
1195		MAD_CFLAGS="-I$arg/include"
1196		MAD_LIBS="-L$arg/lib"
1197		;;
1198	--with-jpeg-prefix=*)
1199		arg=`echo $ac_option | cut -d '=' -f 2`
1200		JPEG_CFLAGS="-I$arg/include"
1201		JPEG_LIBS="-L$arg/lib"
1202		;;
1203	--with-png-prefix=*)
1204		arg=`echo $ac_option | cut -d '=' -f 2`
1205		PNG_CFLAGS="-I$arg/include"
1206		PNG_LIBS="-L$arg/lib"
1207		;;
1208	--with-theoradec-prefix=*)
1209		arg=`echo $ac_option | cut -d '=' -f 2`
1210		THEORADEC_CFLAGS="-I$arg/include"
1211		THEORADEC_LIBS="-L$arg/lib"
1212		;;
1213	--with-faad-prefix=*)
1214		arg=`echo $ac_option | cut -d '=' -f 2`
1215		FAAD_CFLAGS="-I$arg/include"
1216		FAAD_LIBS="-L$arg/lib"
1217		;;
1218	--with-zlib-prefix=*)
1219		arg=`echo $ac_option | cut -d '=' -f 2`
1220		ZLIB_CFLAGS="-I$arg/include"
1221		ZLIB_LIBS="-L$arg/lib"
1222		;;
1223	--with-sparkle-prefix=*)
1224		arg=`echo $ac_option | cut -d '=' -f 2`
1225		_sparklepath=$arg
1226		;;
1227	--with-readline-prefix=*)
1228		arg=`echo $ac_option | cut -d '=' -f 2`
1229		READLINE_CFLAGS="-I$arg/include"
1230		READLINE_LIBS="-L$arg/lib"
1231		;;
1232	--with-libunity-prefix=*)
1233		arg=`echo $ac_option | cut -d '=' -f 2`
1234		LIBUNITY_CFLAGS="-I$arg/include"
1235		LIBUNITY_LIBS="-L$arg/lib"
1236		;;
1237	--with-opengl-prefix=*)
1238		arg=`echo $ac_option | cut -d '=' -f 2`
1239		OPENGL_CFLAGS="-I$arg/include"
1240		OPENGL_LIBS="-L$arg/lib"
1241		;;
1242	--with-glew-prefix=*) #ResidualVM specific option
1243		arg=`echo $ac_option | cut -d '=' -f 2`
1244		GLEW_CFLAGS="-I$arg/include"
1245		GLEW_LIBS="-L$arg/lib"
1246		;;
1247	--with-iconv-prefix=*)
1248		arg=`echo $ac_option | cut -d '=' -f 2`
1249		ICONV_CFLAGS="-I$arg/include"
1250		ICONV_LIBS="-L$arg/lib"
1251		;;
1252	--with-sdlnet-prefix=*)
1253		arg=`echo $ac_option | cut -d '=' -f 2`
1254		SDL_NET_CFLAGS="-I$arg/include"
1255		SDL_NET_LIBS="-L$arg/lib"
1256		;;
1257	--backend=*)
1258		_backend=`echo $ac_option | cut -d '=' -f 2`
1259		;;
1260	--enable-c++11)
1261		_use_cxx11=yes
1262		;;
1263	--disable-c++11)
1264		_use_cxx11=no
1265		;;
1266	--enable-debug)
1267		_debug_build=yes
1268		;;
1269	--disable-debug)
1270		_debug_build=no
1271		;;
1272	--enable-Werror)
1273		append_var CXXFLAGS "-Werror"
1274		;;
1275	--enable-release-mode)
1276		_release_build=yes
1277		;;
1278	--disable-release-mode)
1279		_release_build=no
1280		;;
1281	--enable-release)
1282		_release_build=yes
1283		_optimizations=yes
1284		;;
1285	--disable-release)
1286		_release_build=no
1287		_optimizations=no
1288		;;
1289	--enable-optimizations)
1290		_optimizations=yes
1291		;;
1292	--disable-optimizations)
1293		_optimizations=no
1294		;;
1295	--enable-profiling)
1296		_enable_prof=yes
1297		;;
1298	--with-sdl-prefix=*)
1299		arg=`echo $ac_option | cut -d '=' -f 2`
1300		_sdlpath="$arg:$arg/bin"
1301		;;
1302	--with-freetype2-prefix=*)
1303		arg=`echo $ac_option | cut -d '=' -f 2`
1304		_freetypepath="$arg:$arg/bin"
1305		;;
1306	--with-nasm-prefix=*)
1307		arg=`echo $ac_option | cut -d '=' -f 2`
1308		_nasmpath="$arg:$arg/bin"
1309		;;
1310	--with-staticlib-prefix=*)
1311		_staticlibpath=`echo $ac_option | cut -d '=' -f 2`
1312		;;
1313	--with-xcodetools-path=*)
1314		_xcodetoolspath=`echo $ac_option | cut -d '=' -f 2`
1315		;;
1316	--host=*)
1317		_host=`echo $ac_option | cut -d '=' -f 2`
1318		;;
1319	--prefix=*)
1320		prefix=`echo $ac_option | cut -d '=' -f 2`
1321		;;
1322	--exec-prefix=*)
1323		exec_prefix=`echo $ac_option | cut -d '=' -f 2`
1324		;;
1325	--bindir=*)
1326		bindir=`echo $ac_option | cut -d '=' -f 2`
1327		;;
1328	--libdir=*)
1329		libdir=`echo $ac_option | cut -d '=' -f 2`
1330		;;
1331	--datarootdir=*)
1332		datarootdir=`echo $ac_option | cut -d '=' -f 2`
1333		;;
1334	--datadir=*)
1335		datadir=`echo $ac_option | cut -d '=' -f 2`
1336		;;
1337	--mandir=*)
1338		mandir=`echo $ac_option | cut -d '=' -f 2`
1339		;;
1340	--docdir=*)
1341		docdir=`echo $ac_option | cut -d '=' -f 2`
1342		;;
1343	--enable-all-engines)
1344		engine_enable_all
1345		;;
1346	--disable-all-engines)
1347		engine_disable_all
1348		;;
1349	--enable-engine=* | --enable-engines=*)
1350		for engine_name in `echo $ac_option | cut -d '=' -f 2- | tr ',' '\n'`; do
1351			engine_enable "${engine_name}"
1352		done
1353		;;
1354	--enable-engine-static=* | --enable-engines-static=*)
1355		for engine_name in `echo $ac_option | cut -d '=' -f 2- | tr ',' '\n'`; do
1356			engine_enable "${engine_name}:static"
1357		done
1358		;;
1359	--enable-engine-dynamic=* | --enable-engines-dynamic=*)
1360		for engine_name in `echo $ac_option | cut -d '=' -f 2- | tr ',' '\n'`; do
1361			engine_enable "${engine_name}:dynamic"
1362		done
1363		;;
1364	--disable-engine=* | --disable-engines=*)
1365		for engine_name in `echo $ac_option | cut -d '=' -f 2 | tr ',' '\n'`; do
1366			engine_disable ${engine_name}
1367		done
1368		;;
1369	*)
1370		option_error
1371		;;
1372	esac;
1373done;
1374
1375guessed_host=`$_srcdir/config.guess`
1376get_system_exe_extension $guessed_host
1377NATIVEEXEEXT=$_exeext
1378
1379case $_host in
13803ds)
1381	_host_os=3ds
1382	_host_cpu=arm
1383	_host_alias=arm-none-eabi
1384	;;
1385android | android-arm | android-v7a | android-arm-v7a | ouya)
1386	_host_os=android
1387	_host_cpu=arm
1388	_host_alias=arm-linux-androideabi
1389	;;
1390android-mips)
1391	_host_os=android
1392	_host_cpu=mipsel
1393	_host_alias=mipsel-linux-android
1394	;;
1395android-x86)
1396	_host_os=android
1397	_host_cpu=i686
1398	_host_alias=i686-linux-android
1399	;;
1400androidsdl-armeabi | androidsdl-armeabi-v7a)
1401	_host_os=androidsdl
1402	_host_cpu=arm
1403	_host_alias=arm-linux-androideabi
1404	;;
1405androidsdl-arm64-v8a)
1406	_host_os=androidsdl
1407	_host_cpu=aarch64
1408	_host_alias=aarch64-linux-android
1409	;;
1410androidsdl-mips)
1411	_host_os=androidsdl
1412	_host_cpu=mipsel
1413	_host_alias=mipsel-linux-android
1414	;;
1415androidsdl-x86)
1416	_host_os=androidsdl
1417	_host_cpu=i686
1418	_host_alias=i686-linux-android
1419	;;
1420androidsdl-x86_64)
1421	_host_os=androidsdl
1422	_host_cpu=x86_64
1423	_host_alias=x86_64-linux-android
1424	;;
1425arm-riscos)
1426	_host_os=riscos
1427	_host_cpu=arm
1428	;;
1429raspberrypi)
1430	_host_os=linux
1431	_host_cpu=arm
1432	# This tuple is the one used by the official Rpi toolchain.
1433	# It may change in the future.
1434	_host_alias=arm-linux-gnueabihf
1435	;;
1436caanoo)
1437	_host_os=gph-linux
1438	_host_cpu=arm
1439	_host_alias=arm-none-linux-gnueabi
1440	;;
1441dingux | gcw0)
1442	_host_os=linux
1443	_host_cpu=mipsel
1444	_host_alias=mipsel-linux
1445	;;
1446dreamcast)
1447	_host_os=dreamcast
1448	_host_cpu=sh
1449	_host_alias=sh-elf
1450	append_var CXXFLAGS "-ml -m4-single-only"
1451	append_var LDFLAGS "-ml -m4-single-only"
1452	;;
1453ds)
1454	_host_os=ds
1455	_host_cpu=arm
1456	_host_alias=arm-eabi
1457	;;
1458gamecube)
1459	_host_os=gamecube
1460	_host_cpu=powerpc
1461	_host_alias=powerpc-eabi
1462	;;
1463gp2x)
1464	_host_os=gph-linux
1465	_host_cpu=arm
1466	_host_alias=arm-open2x-linux
1467	;;
1468gp2xwiz)
1469	_host_os=gph-linux
1470	_host_cpu=arm
1471	_host_alias=arm-open2x-linux
1472	;;
1473i586-mingw32msvc)
1474	_host_os=mingw32msvc
1475	_host_cpu=i586
1476	;;
1477iphone)
1478	_host_os=iphone
1479	_host_cpu=arm
1480	_host_alias=arm-apple-darwin9
1481	;;
1482ios7)
1483	_host_os=iphone
1484	_host_cpu=arm
1485	_host_alias=arm-apple-darwin11
1486	;;
1487linupy)
1488	_host_os=linux
1489	_host_cpu=arm
1490	;;
1491maemo)
1492	_host_os=maemo
1493	_host_cpu=arm
1494	_host_alias=arm-linux
1495
1496	# The prefix is always the same on Maemo so we hardcode the default
1497	# here. It is still possible to define a custom prefix which is
1498	# needed when packaging the app with a user-specific app ID.
1499	test "x$prefix" = xNONE && prefix=/opt/residualvm
1500	# Maemo apps are installed into app-specific directories. The
1501	# default directory structure of ScummVM makes no sense here so we
1502	# hardcode Maemo specific directories here.
1503	datarootdir='${prefix}/share'
1504	datadir=/opt/residualvm/share
1505	docdir='${datarootdir}/doc/residualvm'
1506	;;
1507motoezx)
1508	_host_os=linux
1509	_host_cpu=arm
1510	_host_alias=arm-linux-gnu
1511	;;
1512motomagx)
1513	_host_os=linux
1514	_host_cpu=arm
1515	_host_alias=arm-linux-gnueabi
1516	;;
1517n64)
1518	_host_os=n64
1519	_host_cpu=mips
1520	_host_alias=mips64
1521	;;
1522neuros)
1523	_host_os=linux
1524	_host_cpu=arm
1525	;;
1526openpandora)
1527	_host_os=linux
1528	_host_cpu=arm
1529	_host_alias=arm-angstrom-linux-gnueabi
1530	;;
1531ppc-amigaos)
1532	_host_os=amigaos
1533	_host_cpu=powerpc
1534	;;
1535ps2)
1536	_host_os=ps2
1537	_host_cpu=mips64r5900el
1538	_host_alias=ee
1539	# PS2 bogus dirs: they actually depend on launch medium
1540	datadir='host:data'
1541	docdir='host:docs'
1542	;;
1543ps3)
1544	_host_os=ps3
1545	_host_cpu=powerpc
1546	_host_alias=powerpc64-ps3-elf
1547
1548	# The prefix is always the same on PS3 so we hardcode the default
1549	# here. It is still possible to define a custom prefix which is
1550	# needed when packaging the app with a user-specific app ID.
1551	test "x$prefix" = xNONE && prefix=/dev_hdd0/game/RESI12000/USRDIR
1552	# PS3 apps are installed into app-specific directories. The
1553	# default directory structure of ScummVM makes no sense here so we
1554	# hardcode PS3 specific directories here.
1555	datarootdir='${prefix}/data'
1556	datadir='${datarootdir}'
1557	docdir='${prefix}/doc'
1558	;;
1559psp2)
1560	_host_os=psp2
1561	_host_cpu=arm
1562	_host_alias=arm-vita-eabi
1563
1564	# The prefix is always the same on PSP2 so we hardcode the default
1565	# here. It is still possible to define a custom prefix which is
1566	# needed when packaging the app with a user-specific app ID.
1567	test "x$prefix" = xNONE && prefix=app0:
1568	# PSP2 apps are installed into app-specific directories. The
1569	# default directory structure of ScummVM makes no sense here so we
1570	# hardcode PSP2 specific directories here.
1571	datarootdir='${prefix}/data'
1572	datadir='${datarootdir}'
1573	docdir='${prefix}/doc'
1574	;;
1575psp)
1576	_host_os=psp
1577	_host_cpu=mipsallegrexel
1578	_host_alias=psp
1579	;;
1580samsungtv)
1581	_host_os=linux
1582	_host_cpu=arm
1583	_host_alias=arm-linux-gnueabi
1584	;;
1585tizen)
1586 	_host_os=tizen
1587	_host_cpu=arm
1588	_host_alias=arm-linux-gnueabi
1589	;;
1590webos)
1591	_host_os=webos
1592	_host_cpu=arm
1593	_host_alias=arm-none-linux-gnueabi
1594	# The prefix is always the same on WebOS so we hardcode the default
1595	# here. It is still possible to define a custom prefix which is
1596	# needed when packaging the app with a user-specific app ID.
1597	test "x$prefix" = xNONE && prefix=/media/cryptofs/apps/usr/palm/applications/org.residualvm.residualvm
1598	# WebOS apps are installed into app-specific directories. The
1599	# default directory structure of ScummVM makes no sense here so we
1600	# hardcode WebOS specific directories here.
1601	datarootdir='${prefix}/data'
1602	datadir='${datarootdir}'
1603	docdir='${prefix}/doc'
1604	;;
1605wii)
1606	_host_os=wii
1607	_host_cpu=powerpc
1608	_host_alias=powerpc-eabi
1609	;;
1610wince)
1611	_host_os=wince
1612	_host_cpu=arm
1613	_host_alias=arm-mingw32ce
1614	;;
1615*)
1616	if test -n "$_host"; then
1617		guessed_host=`$_srcdir/config.sub $_host`
1618	fi
1619	_host_cpu=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
1620	_host_vendor=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
1621	_host_os=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
1622	;;
1623esac
1624
1625if test -z "$_host_alias"; then
1626	_host_alias="$_host_cpu-$_host_os"
1627else
1628	# if _host_alias was set, default to the standard GNU tools
1629	_ranlib=$_host_alias-ranlib
1630	_strip=$_host_alias-strip
1631	_ar="$_host_alias-ar cru"
1632	_as="$_host_alias-as"
1633	_windres=$_host_alias-windres
1634fi
1635
1636#
1637# Determine extra build flags for debug and/or release builds
1638#
1639
1640case $_host in
1641caanoo | gp2x | gp2xwiz | openpandora | ps2 | psp2)
1642	if test "$_debug_build" = auto; then
1643		# If you want to debug one of these platforms, use '--disable-optimizations --enable-debug'
1644		_debug_build=no
1645	fi
1646
1647	if test "$_optimizations" = auto; then
1648		# Enable optimizations by default.
1649		_optimizations=yes
1650	fi
1651	;;
1652esac
1653
1654if test "$_debug_build" != no; then
1655	# debug mode not explicitly disabled -> compile with debug information
1656	case $_host_os in
1657	amigaos*)
1658		# AmigaOS debugger uses plain stabs, with no gdb extensions.
1659		append_var CXXFLAGS "-gstabs"
1660	;;
1661	*)
1662		# Use the system default format for debug info.
1663		append_var CXXFLAGS "-g"
1664	esac
1665fi
1666
1667if test "$_release_build" = yes; then
1668	# Add a define, which indicates we are doing
1669	# an build for a release version.
1670	append_var DEFINES "-DRELEASE_BUILD"
1671fi
1672
1673
1674#
1675# Determine extension used for executables
1676#
1677get_system_exe_extension $_host_os
1678HOSTEXEPRE=
1679HOSTEXEEXT=$_exeext
1680
1681#
1682# Determine separator used for $PATH
1683#
1684case $_host_os in
1685os2-emx*)
1686	SEPARATOR=";"
1687	;;
1688*)
1689	SEPARATOR=":"
1690	;;
1691esac
1692
1693#
1694# Platform specific sanity checks
1695#
1696case $_host_os in
1697android)
1698	if test -z "$ANDROID_SDK"; then
1699		echo "Please set ANDROID_SDK in your environment. export ANDROID_SDK=<path to Android SDK>"
1700		exit 1
1701	fi
1702	if test -z "$ANDROID_NDK"; then
1703		echo "Please set ANDROID_NDK in your environment. export ANDROID_NDK=<path to Android NDK>"
1704		exit 1
1705	fi
1706	;;
17073ds | ds | gamecube | wii)
1708	if test -z "$DEVKITPRO"; then
1709		echo "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to devkitPRO>"
1710		exit 1
1711	fi
1712	;;
1713n64)
1714	if test -z "$N64SDK"; then
1715		echo "Please set N64SDK in your environment. export N64SDK=<path to n64 sdk>"
1716		exit 1
1717	fi
1718	;;
1719ps2)
1720	if test -z "$PS2SDK"; then
1721		echo "Please set PS2SDK in your environment. export PS2SDK=<path to ps2 sdk>"
1722		exit 1
1723	fi
1724	;;
1725ps3)
1726	if test -z "$PS3DEV"; then
1727		echo "Please set PS3DEV in your environment. export PS3DEV=<path to ps3 toolchain>"
1728		exit 1
1729	fi
1730	if test -z "$PSL1GHT"; then
1731		echo "Please set PSL1GHT in your environment. export PSL1GHT=<path to psl1ght>"
1732		exit 1
1733	fi
1734	;;
1735psp2)
1736	if test -z "$VITASDK"; then
1737		echo "Please set VITASDK in your environment. export VITASDK=<path to psp2 toolchain>"
1738		exit 1
1739	fi
1740	;;
1741psp)
1742	if test -z "$PSPDEV"; then
1743		PSPDEV=`psp-config --pspdev-path`
1744	fi
1745	# TODO: Should we also insist on a valid PSPDEV value?
1746	if test -z "$PSPSDK"; then
1747		PSPSDK=`psp-config --pspsdk-path`
1748	fi
1749	if test -z "$PSPSDK"; then
1750		echo "Please set PSPSDK in your environment. export PSPSDK=<path to psp sdk>"
1751		exit 1
1752	fi
1753	;;
1754tizen)
1755	if test -z "$TIZEN_ROOTSTRAP"; then
1756		echo "Please set TIZEN_ROOTSTRAP in your environment. export TIZEN_ROOTSTRAP=<path to Tizen SDK device profile>"
1757		exit 1
1758	fi
1759	;;
1760webos)
1761	if test -z "$WEBOS_SDK"; then
1762		echo "Please set WEBOS_SDK in your environment. export WEBOS_SDK=<path to WebOS SDK>"
1763		exit 1
1764	fi
1765	if test -z "$WEBOS_PDK"; then
1766		echo "Please set WEBOS_PDK in your environment. export WEBOS_PDK=<path to WebOS PDK>"
1767		exit 1
1768	fi
1769	;;
1770*)
1771	;;
1772esac
1773
1774#
1775# Determine the C++ compiler
1776#
1777echo_n "Looking for C++ compiler... "
1778
1779# Check whether the given command is a working C++ compiler
1780test_compiler() {
1781	cat > tmp_cxx_compiler.cpp << EOF
1782	class Foo { int a; };
1783	int main(int argc, char **argv) {
1784		Foo *a = new Foo(); delete a; return 0;
1785	}
1786EOF
1787
1788	echo "testing compiler: $1" >> "$TMPLOG"
1789
1790	if test -n "$_host"; then
1791		# In cross-compiling mode, we cannot run the result
1792		eval "$1 $CXXFLAGS -o $TMPO.o -c tmp_cxx_compiler.cpp" 2> /dev/null && cc_check_clean tmp_cxx_compiler.cpp
1793	else
1794		eval "$1 $CXXFLAGS $LDFLAGS -o $TMPO$HOSTEXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "$TMPO$HOSTEXEEXT 2> /dev/null" && cc_check_clean tmp_cxx_compiler.cpp
1795	fi
1796}
1797
1798# Prepare a list of candidates for the C++ compiler
1799if test -n "$CXX" && test_compiler "$CXX"; then
1800	# Use the compiler specified in CXX
1801	echo $CXX
1802else
1803	if test -n "$_host"; then
1804		compilers="$_host_alias-g++ $_host_alias-c++ $_host-g++ $_host-c++"
1805	else
1806		compilers="g++ c++"
1807	fi
1808
1809	# Iterate over all candidates, pick the first working one
1810	CXX=
1811	for compiler in $compilers; do
1812		if test_compiler $compiler; then
1813			echo "success testing compiler: $compiler" >> "$TMPLOG"
1814			CXX=$compiler
1815			echo $CXX
1816			break
1817		else
1818			echo "failure testing compiler: $compiler" >> "$TMPLOG"
1819		fi
1820	done
1821fi
1822
1823if test -z "$CXX"; then
1824	echo "none found!"
1825	exit 1
1826fi
1827
1828# By default, use the C++ compiler as linker
1829LD=$CXX
1830
1831#
1832# Determine the compiler version
1833#
1834echocheck "compiler version"
1835
1836# Some compilers pretend to be gcc to ease compatibility with
1837# common Linux etc. programs. We first check for some of these here.
1838have_gcc=no
1839cc_check_define __GNUC__ && have_gcc=yes
1840have_icc=no
1841cc_check_define __INTEL_COMPILER && have_icc=yes
1842have_clang=no
1843cc_check_define __clang__ && have_clang=yes
1844
1845if test "$have_icc" = yes; then
1846	add_line_to_config_mk 'HAVE_ICC = 1'
1847
1848	# Make ICC error out on unknown command line options instead of printing
1849	# a warning. This is for example required to make the -Wglobal-destructors
1850	# detection work correctly.
1851	append_var CXXFLAGS "-diag-error 10006,10148"
1852
1853	# ICC doesn't accept all gcc options, so we disable have_gcc, even if
1854	# ICC does have the gcc-compatibility defines.
1855	have_gcc=no
1856fi
1857
1858if test "$have_clang" = yes; then
1859	add_line_to_config_mk 'HAVE_CLANG = 1'
1860
1861	# clang does accept all gcc options we use, so we keep have_gcc
1862fi
1863
1864if test "$have_gcc" = yes; then
1865	add_line_to_config_mk 'HAVE_GCC = 1'
1866	_cxx_major=`gcc_get_define __GNUC__`
1867	_cxx_minor=`gcc_get_define __GNUC_MINOR__`
1868	cxx_version="`( $CXX -dumpversion ) 2>&1`"
1869
1870	if test "$have_clang" = yes; then
1871		# Clang sets a gcc version number for compatibility.
1872		# We keep that as _cxx_minor/_cxx_major for later
1873		# compiler version checks.
1874
1875		# For the version reported in the configure log (cxx_version),
1876		# we get the actual clang version.
1877		cxx_version=`gcc_get_define __clang_version__`
1878		cxx_version="`echo "${cxx_version}" | sed -e 's/"\([^ ]*\) .*/\1/'`"
1879		cxx_version="clang $cxx_version, ok"
1880	elif test "$_cxx_major" -eq 2 && test "$_cxx_minor" -ge 95 || \
1881	   test "$_cxx_major" -gt 2 ; then
1882		cxx_version="$cxx_version, ok"
1883		cxx_verc_fail=no
1884	else
1885		cxx_version="$cxx_version, bad"
1886		cxx_verc_fail=yes
1887	fi
1888elif test "$have_icc" = yes; then
1889	cxx_version="`( $CXX -dumpversion ) 2>/dev/null`"
1890	_cxx_major="`echo "${cxx_version}" | sed -ne 's/\([0-9][0-9]*\)\..*/\1/gp'`"
1891	_cxx_minor="`echo "${cxx_version}" | sed -ne 's/[0-9][0-9]*\.\([0-9][0-9]*\)/\1/gp'`"
1892	cxx_version="ICC $cxx_version, ok"
1893else
1894	# TODO: Big scary warning about unsupported compilers
1895	cxx_version=`( $CXX -version ) 2>&1`
1896	if test "$?" -eq 0; then
1897		cxx_version="`echo "${cxx_version}" | sed -ne 's/^.*[^0-9]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/gp'`"
1898		if test -z "${cxx_version}"; then
1899			cxx_version="not found"
1900			cxx_verc_fail=yes
1901		fi
1902		echo non-gcc compiler version ${cxx_version}
1903	else
1904		cxx_version="not found"
1905		cxx_verc_fail=yes
1906		echo found non-gcc compiler version ${cxx_version}
1907	fi
1908
1909	case $_host_os in
1910		irix*)
1911			case $cxx_version in
1912				7.4.4*)
1913					# We just assume this is SGI MIPSpro
1914					_cxx_major=7
1915					_cxx_minor=4
1916					cxx_verc_fail=no
1917					add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MDupdate "$(*D)/$(DEPDIR)/$(*F).d"'
1918					add_line_to_config_mk '-include Makedepend'
1919					;;
1920				*)
1921					cxx_version="$cxx_version, bad"
1922					cxx_verc_fail=yes
1923					;;
1924			esac
1925			;;
1926		*)
1927			cxx_version="$cxx_version, bad"
1928			cxx_verc_fail=yes
1929			;;
1930	esac
1931fi
1932
1933echo "$cxx_version"
1934
1935#
1936# Bail out now if no useable compiler was found.
1937#
1938if test "$cxx_verc_fail" = yes ; then
1939	echo
1940	echo "The version of your compiler is not supported at this time"
1941	echo "Please ensure you are using GCC >= 2.95"
1942	exit 1
1943fi
1944
1945#
1946# Check whether the compiler supports C++11
1947#
1948have_cxx11=no
1949cat > $TMPC << EOF
1950int main(int argc, char *argv[]) { if (argv == nullptr) return -1; else return 0; }
1951EOF
1952cc_check -std=c++11 && have_cxx11=yes
1953if test "$_use_cxx11" = "yes" ; then
1954	_use_cxx11=$have_cxx11
1955fi
1956
1957#
1958# Setup compiler specific CXXFLAGS now that we know the compiler version.
1959# Foremost, this means enabling various warnings.
1960# In addition, we set CXX_UPDATE_DEP_FLAG for GCC >= 3.0 and for ICC.
1961#
1962if test "$have_gcc" = yes ; then
1963	if test "$_cxx_major" -ge "3" ; then
1964		# Try to use ANSI mode when C++11 is disabled.
1965		if test "$_use_cxx11" = "no" ; then
1966			case $_host_os in
1967			# newlib-based system include files suppress non-C89 function
1968			# declarations under __STRICT_ANSI__
1969			3ds | amigaos* | android | androidsdl | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | ps3 | psp2 | tizen | wii | wince )
1970				;;
1971			*)
1972				append_var CXXFLAGS "-ansi"
1973				;;
1974			esac
1975		fi
1976		append_var CXXFLAGS "-W -Wno-unused-parameter"
1977		add_line_to_config_mk 'HAVE_GCC3 = 1'
1978		add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
1979	fi;
1980
1981	if test "$_cxx_major" -eq 4 && test "$_cxx_minor" -ge 3 || \
1982	   test "$_cxx_major" -gt 4 ; then
1983		append_var CXXFLAGS "-Wno-empty-body"
1984	else
1985		append_var CXXFLAGS "-Wconversion"
1986	fi;
1987elif test "$have_icc" = yes ; then
1988	add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
1989fi;
1990
1991#
1992# Update status about C++11 mode
1993#
1994echo_n "Building as C++11... "
1995if test "$_use_cxx11" = "yes" ; then
1996	append_var CXXFLAGS "-std=c++11"
1997fi
1998echo $_use_cxx11
1999
2000# By default, we add -pedantic to the CXXFLAGS to catch some potentially
2001# non-portable constructs, like use of GNU extensions.
2002# However, some platforms use GNU extensions in system header files, so
2003# for these we must not use -pedantic.
2004case $_host_os in
2005android | androidsdl | gamecube | psp | tizen | wii | webos)
2006	;;
2007*)
2008	# ICC does not support pedantic, while GCC and clang do.
2009	if test "$have_icc" = no ; then
2010		# We *do* want the 'long long' extension.
2011		append_var CXXFLAGS "-pedantic -Wno-long-long"
2012	fi
2013	;;
2014esac
2015
2016# If possible, we want to use -Wglobal-constructors
2017# However, not all compilers support that, so check whether the active one does.
2018echocheck "whether -Wglobal-constructors work"
2019cat > $TMPC << EOF
2020int main() { return 0; }
2021EOF
2022cc_check -Wglobal-constructors -Werror && _global_constructors=yes
2023
2024if test "$_global_constructors" = yes; then
2025	append_var CXXFLAGS "-Wglobal-constructors"
2026fi
2027echo $_global_constructors
2028
2029# If the compiler supports the -Wundefined-var-template flag, silence that warning.
2030# We get this warning a lot with regard to the Singleton class as we explicitly
2031# instantiate each specialisation. An alternate way to deal with it would be to
2032# change the way we instantiate the singleton classes as done in PR #967.
2033# Note: we check the -Wundefined-var-template as gcc does not error out on unknown
2034# -Wno-xxx flags.
2035echocheck "whether -Wno-undefined-var-template work"
2036cat > $TMPC << EOF
2037int main() { return 0; }
2038EOF
2039cc_check -Wundefined-var-template -Werror && _no_undefined_var_template=yes
2040
2041if test "$_no_undefined_var_template" = yes; then
2042	append_var CXXFLAGS "-Wno-undefined-var-template"
2043fi
2044echo $_no_undefined_var_template
2045
2046echo_n "Checking for $_host_alias-strings... " >> "$TMPLOG"
2047if `which $_host_alias-strings >/dev/null 2>&1`; then
2048_strings=$_host_alias-strings
2049echo yes >> "$TMPLOG"
2050else
2051_strings=strings
2052echo no >> "$TMPLOG"
2053fi
2054
2055#
2056# Check for endianness
2057#
2058echo_n "Checking endianness... "
2059cat > tmp_endianness_check.cpp << EOF
2060unsigned short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
2061unsigned short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
2062void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; }
2063unsigned short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
2064unsigned short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
2065void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; }
2066int main() { _ascii (); _ebcdic (); return 0; }
2067EOF
2068$CXX $CXXFLAGS -c -o $TMPO.o tmp_endianness_check.cpp
2069if $_strings $TMPO.o | grep BIGenDianSyS >/dev/null; then
2070	_endian=big
2071elif $_strings $TMPO.o | grep LiTTleEnDian >/dev/null; then
2072	_endian=little
2073fi
2074echo $_endian;
2075cc_check_clean tmp_endianness_check.cpp
2076
2077case $_endian in
2078	big)
2079		add_line_to_config_h '#undef SCUMM_LITTLE_ENDIAN'
2080		add_line_to_config_h '#define SCUMM_BIG_ENDIAN'
2081		;;
2082	little)
2083		add_line_to_config_h '#define SCUMM_LITTLE_ENDIAN'
2084		add_line_to_config_h '#undef SCUMM_BIG_ENDIAN'
2085		;;
2086	*)
2087		exit 1
2088		;;
2089esac
2090
2091#
2092# Determine a data type with the given length
2093#
2094find_type_with_size() {
2095	for datatype in int short char long "long long" __int64 "long long int" unknown; do
2096		cat > tmp_find_type_with_size.cpp << EOF
2097typedef $datatype ac__type_sizeof_;
2098int main() {
2099	static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) == $1)];
2100	test_array [0] = 0;
2101	return 0;
2102}
2103EOF
2104		if $CXX $CXXFLAGS -c -o $TMPO.o tmp_find_type_with_size.cpp 2>/dev/null ; then
2105			break
2106		else
2107			if test "$datatype" = "unknown"; then
2108				echo "couldn't find data type with $1 bytes"
2109				exit 1
2110			fi
2111			continue
2112		fi
2113	done
2114	cc_check_clean tmp_find_type_with_size.cpp
2115	echo $datatype
2116}
2117
2118#
2119# Check whether the system is 32-bit
2120#
2121pointer_is_32bit() {
2122	cat > tmp_pointer_is_32bit.cpp << EOF
2123int main() {
2124	static int test_array[1 - 2 * !(sizeof(void *) == 4)];
2125	test_array[0] = 0;
2126	return 0;
2127}
2128EOF
2129	$CXX $CXXFLAGS -c -o $TMPO.o tmp_pointer_is_32bit.cpp 2>/dev/null
2130	status=$?
2131	cc_check_clean tmp_pointer_is_32bit.cpp
2132	return $status
2133}
2134
2135echo_n "Checking 64-bitness... "
2136pointer_is_32bit
2137if test $? -eq 0; then
2138	type_ptr=int32
2139	echo "no"
2140	add_line_to_config_h "/* #define SCUMM_64BITS */"
2141else
2142	type_ptr=int64
2143	echo "yes"
2144	add_line_to_config_h "#define SCUMM_64BITS"
2145fi
2146
2147#
2148# Determine data type sizes
2149#
2150echo_n "Type with 1 byte... "
2151type_1_byte=`find_type_with_size 1`
2152TMPR="$?"
2153echo "$type_1_byte"
2154test $TMPR -eq 0 || exit 1	# check exit code of subshell
2155
2156echo_n "Type with 2 bytes... "
2157type_2_byte=`find_type_with_size 2`
2158TMPR="$?"
2159echo "$type_2_byte"
2160test $TMPR -eq 0 || exit 1	# check exit code of subshell
2161
2162echo_n "Type with 4 bytes... "
2163type_4_byte=`find_type_with_size 4`
2164TMPR="$?"
2165echo "$type_4_byte"
2166test $TMPR -eq 0 || exit 1	# check exit code of subshell
2167
2168echo_n "Type with 8 bytes... "
2169type_8_byte=`find_type_with_size 8`
2170TMPR="$?"
2171echo "$type_8_byte"
2172if test $TMPR -eq 0; then
2173	_def_64bit_type_signed="typedef signed $type_8_byte int64;"
2174	_def_64bit_type_unsigned="typedef unsigned $type_8_byte uint64;"
2175fi
2176# force cleanup after check for 8 bytes type
2177cc_check_clean tmp_find_type_with_size.cpp
2178
2179#
2180# Check whether memory alignment is required
2181#
2182# For some CPU types, unaligned memory access is either not supported at
2183# all (and so leads to a crash), requires a super-slow emulation via an
2184# exception handler, or just results in incorrect results.
2185# On the other hand, accessing data in a manner that works regardless of
2186# alignment can be a lot slower than regular access, so we don't want
2187# to use it if we don't have to.
2188#
2189# So we do the following: For CPU families where we know whether unaligned
2190# access is safe & fast, we enable / disable unaligned access accordingly.
2191# Otherwise, we just disable memory alignment.
2192#
2193# NOTE: In the past, for non-cross compiled builds, we would also run some code
2194# which would try to test whether unaligned access worked or not. But this test
2195# could not reliably determine whether unaligned access really worked in all
2196# situations (and across different implementations of the target CPU arch), nor
2197# whether it was fast (as opposed to slowly emulated by fault handlers). Hence,
2198# we do not use this approach anymore.
2199#
2200# NOTE: The only kinds of unaligned access we allow are for 2 byte and 4
2201# byte loads / stores. No promises are made for bigger sizes, such as 8
2202# or 16 byte loads, for which architectures may behave differently than
2203# for the smaller sizes.
2204echo_n "Alignment required... "
2205case $_host_cpu in
2206	i[3-6]86 | amd64 | x86_64 | powerpc* | ppc*)
2207		# Unaligned access should work
2208		_need_memalign=no
2209		;;
2210	alpha* | arm* | bfin* | hp* | mips* | sh* | sparc* | ia64 | nv1*)
2211		# Unaligned access is not supported or extremely slow.
2212		_need_memalign=yes
2213		;;
2214	*)
2215		# Status of unaligned access is unknown, so assume the worst.
2216		_need_memalign=yes
2217		;;
2218esac
2219echo "$_need_memalign"
2220
2221define_in_config_h_if_yes $_need_memalign 'SCUMM_NEED_ALIGNMENT'
2222
2223#
2224# Check the CPU architecture
2225#
2226echo_n "Checking host CPU architecture... "
2227case $_host_cpu in
2228	arm*)
2229		echo "ARM"
2230		case $_host_alias in
2231			# Apple's as does not support the syntax we use in our ARM
2232			# assembly. We simply do not enable it.
2233			arm-apple-darwin9)
2234				;;
2235			arm-apple-darwin10)
2236				;;
2237			arm-apple-darwin11)
2238				;;
2239			# psvita does not like the asm code...
2240			arm-vita-eabi)
2241				;;
2242
2243			*)
2244				define_in_config_if_yes yes 'USE_ARM_SCALER_ASM'
2245				# FIXME: The following feature exhibits a bug. It produces distorted
2246				# sound since 9003ce517ff9906b0288f9f7c02197fd091d4554. The ARM
2247				# assembly will need to be properly adapted to the changes to the C
2248				# code in 8f5a7cde2f99de9fef849b0ff688906f05f4643e.
2249				# See bug #6957: "AUDIO: ARM ASM sound code causes distorted audio on 32 bit armv6"
2250				#define_in_config_if_yes yes 'USE_ARM_SOUND_ASM'
2251				define_in_config_if_yes yes 'USE_ARM_SMUSH_ASM'
2252				define_in_config_if_yes yes 'USE_ARM_GFX_ASM'
2253				# FIXME: The following feature exhibits a bug during the intro scene of Indy 4
2254				# (on Pandora and iPhone at least)
2255				#define_in_config_if_yes yes 'USE_ARM_COSTUME_ASM'
2256				;;
2257		esac
2258
2259		append_var DEFINES "-DARM_TARGET"
2260		;;
2261	i[3-6]86)
2262		echo "x86"
2263		_have_x86=yes
2264		define_in_config_h_if_yes $_have_x86 'HAVE_X86'
2265		;;
2266	mips*)
2267		echo "MIPS"
2268		append_var DEFINES "-DMIPS_TARGET"
2269		;;
2270	powerpc* | ppc*)
2271		echo "PowerPC"
2272		append_var DEFINES "-DPPC_TARGET"
2273		;;
2274	amd64 | x86_64)
2275		echo "x86_64"
2276		;;
2277	*)
2278		echo "unknown ($_host_cpu)"
2279		;;
2280esac
2281
2282
2283#
2284# Determine build settings
2285#
2286echo_n "Checking hosttype... "
2287echo $_host_os
2288case $_host_os in
2289	3ds)
2290		_optimization_level=-O2
2291		append_var DEFINES "-D__3DS__"
2292		append_var DEFINES "-DARM"
2293		append_var DEFINES "-DARM11"
2294		append_var CXXFLAGS "-march=armv6k"
2295		append_var CXXFLAGS "-mtune=mpcore"
2296		append_var CXXFLAGS "-mword-relocations"
2297		append_var CXXFLAGS "-mfloat-abi=hard"
2298		append_var CXXFLAGS "-ffunction-sections"
2299		append_var CXXFLAGS "-fomit-frame-pointer"
2300		append_var CXXFLAGS "-I$DEVKITPRO/libctru/include"
2301		append_var CXXFLAGS "-I$DEVKITPRO/portlibs/3ds/include"
2302		if test "$_dynamic_modules" = no ; then
2303			append_var LDFLAGS "-Wl,--gc-sections"
2304		else
2305			append_var LDFLAGS "-Wl,--no-gc-sections"
2306		fi
2307		append_var LDFLAGS "-L$DEVKITPRO/portlibs/3ds/lib"
2308		append_var LIBS "-lcitro3d -lctru"
2309		;;
2310	amigaos*)
2311		append_var LDFLAGS "-Wl,--export-dynamic"
2312		append_var LDFLAGS "-L/sdk/local/newlib/lib"
2313		# We have to use 'long' for our 4 byte typedef because AmigaOS already typedefs (u)int32
2314		# as (unsigned) long, and consequently we'd get a compiler error otherwise.
2315		type_4_byte='long'
2316		# Supress format warnings as the long 4 byte causes noisy warnings.
2317		append_var CXXFLAGS "-Wno-format"
2318		add_line_to_config_mk 'AMIGAOS = 1'
2319		_port_mk="backends/platform/sdl/amigaos/amigaos.mk"
2320		;;
2321	android)
2322		case $_host in
2323			android | android-arm)
2324				append_var CXXFLAGS "-march=armv5te"
2325				append_var CXXFLAGS "-mtune=xscale"
2326				append_var CXXFLAGS "-msoft-float"
2327				ABI="armeabi"
2328				# Platform version 9 is used by ResidualVM
2329				ANDROID_PLATFORM=9
2330				ANDROID_PLATFORM_ARCH="arm"
2331				;;
2332			android-v7a | android-arm-v7a)
2333				append_var CXXFLAGS "-march=armv7-a"
2334				append_var CXXFLAGS "-mfloat-abi=softfp"
2335				append_var CXXFLAGS "-mfpu=vfp"
2336				append_var LDFLAGS "-Wl,--fix-cortex-a8"
2337				ABI="armeabi-v7a"
2338				ANDROID_PLATFORM=9
2339				ANDROID_PLATFORM_ARCH="arm"
2340				;;
2341			android-mips)
2342				append_var CXXFLAGS "-march=mips32"
2343				append_var CXXFLAGS "-mtune=mips32"
2344				ABI="mips"
2345				# Platform version 9 is needed as earlier versions of platform do not support this arch.
2346				ANDROID_PLATFORM=9
2347				ANDROID_PLATFORM_ARCH="mips"
2348				;;
2349			android-x86)
2350				append_var CXXFLAGS "-march=i686"
2351				append_var CXXFLAGS "-mtune=i686"
2352				ABI="x86"
2353				# Platform version 9 is needed as earlier versions of platform do not support this arch.
2354				ANDROID_PLATFORM=9
2355				ANDROID_PLATFORM_ARCH="x86"
2356				;;
2357			ouya)
2358				append_var CXXFLAGS "-march=armv7-a"
2359				append_var CXXFLAGS "-mtune=cortex-a9"
2360				append_var CXXFLAGS "-mfloat-abi=softfp"
2361				append_var CXXFLAGS "-mfpu=neon"
2362				ABI="armeabi-v7a"
2363				ANDROID_PLATFORM=9
2364				ANDROID_PLATFORM_ARCH="arm"
2365				;;
2366		esac
2367
2368		# Setup platform version and arch
2369		append_var CXXFLAGS "--sysroot=$ANDROID_NDK/platforms/android-$ANDROID_PLATFORM/arch-$ANDROID_PLATFORM_ARCH"
2370		append_var LDFLAGS "--sysroot=$ANDROID_NDK/platforms/android-$ANDROID_PLATFORM/arch-$ANDROID_PLATFORM_ARCH"
2371
2372		append_var CXXFLAGS "-fpic"
2373		append_var CXXFLAGS "-ffunction-sections"
2374		append_var CXXFLAGS "-funwind-tables"
2375		if test "$_debug_build" = yes; then
2376			append_var CXXFLAGS "-fno-omit-frame-pointer"
2377			append_var CXXFLAGS "-fno-strict-aliasing"
2378		else
2379			append_var CXXFLAGS "-fomit-frame-pointer"
2380			append_var CXXFLAGS "-fstrict-aliasing"
2381		fi
2382		append_var CXXFLAGS "-finline-limit=300"
2383		_optimization_level=-Os
2384
2385		if test "$_host" = android -o "$_host" = android-arm; then
2386			append_var CXXFLAGS "-mthumb-interwork"
2387			# FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
2388			append_var CXXFLAGS "-D__ARM_ARCH_5__"
2389			append_var CXXFLAGS "-D__ARM_ARCH_5T__"
2390			append_var CXXFLAGS "-D__ARM_ARCH_5E__"
2391			append_var CXXFLAGS "-D__ARM_ARCH_5TE__"
2392		fi
2393
2394		# surpress 'mangling of 'va_list' has changed in GCC 4.4' warning
2395		append_var CXXFLAGS "-Wno-psabi"
2396
2397		if test "$_host" = android -o "$_host" = android-arm; then
2398			append_var LDFLAGS "-mthumb-interwork"
2399		fi
2400
2401		append_var LDFLAGS "-L$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/`$CXX -dumpversion`/libs/$ABI/"
2402		append_var LIBS "-lsupc++"
2403		add_line_to_config_mk "ANDROID_SDK = $ANDROID_SDK"
2404		if test -d "$ANDROID_SDK"/build-tools; then
2405			_build_tools_version=`cd "$ANDROID_SDK"/build-tools && ls -1 | sort -rn | head -1`
2406			add_line_to_config_mk "ANDROID_BTOOLS = build-tools/$_build_tools_version"
2407		else
2408			add_line_to_config_mk "ANDROID_BTOOLS = platform-tools"
2409		fi
2410		_seq_midi=no
2411		;;
2412	beos*)
2413		append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
2414		# Needs -lbind -lsocket for the timidity MIDI driver
2415		LDFLAGS="-L/boot/home/config/lib"
2416		CFLAGS="-I/boot/home/config/include"
2417		append_var CXXFLAGS "-fhuge-objects"
2418		append_var LIBS "-lbind -lsocket"
2419		_seq_midi=no
2420		;;
2421	cygwin*)
2422		echo ERROR: Cygwin building is not supported by ScummVM anymore. Consider using MinGW.
2423		exit 1
2424		;;
2425	darwin*)
2426		# Pass -mlongcall to gcc so that it emits long calls
2427		# which will allow for calls larger than 32MB. The linker
2428		# will discard the calls if they are not needed, but we
2429		# need to ensure the compiler emits them in the first place.
2430		case $_host_cpu in
2431		powerpc*)
2432			append_var CFLAGS "-mlongcall"
2433			append_var CXXFLAGS "-mlongcall"
2434			;;
2435		esac
2436
2437		append_var DEFINES "-DMACOSX"
2438		append_var LIBS "-framework AudioUnit -framework AudioToolbox -framework Carbon -framework CoreMIDI"
2439		# SDL2 doesn't seem to add Cocoa for us.
2440		append_var LIBS "-framework Cocoa"
2441		add_line_to_config_mk 'MACOSX = 1'
2442
2443		# Now we may have MacPorts or Fink installed
2444		# Which put libraries and headers in non-standard places
2445		# Checking them here
2446
2447		# MacPorts
2448		# There is no way to get the prefix, so implementing a hack here
2449		macport_version=`port version 2>/dev/null`
2450		if test "$?" -eq 0; then
2451			macport_version="`echo "${macport_version}" | sed -ne 's/Version: \([0-9]\.[0-9]\.[0-9]\)/\1/gp'`"
2452			echo_n "You seem to be running MacPorts version ${macport_version}..."
2453
2454			macport_prefix=`which port`
2455			# strip off /bin/port from /opt/local/bin/port
2456			macport_prefix=`dirname ${macport_prefix}`
2457			macport_prefix=`dirname ${macport_prefix}`
2458
2459			echo "adding ${macport_prefix} to paths"
2460
2461			LDFLAGS="-L${macport_prefix}/lib $LDFLAGS"
2462			CXXFLAGS="-I${macport_prefix}/include $CXXFLAGS"
2463
2464			if test -z "$_staticlibpath"; then
2465				_staticlibpath=${macport_prefix}
2466				echo "Set staticlib-prefix to ${_staticlibpath}"
2467			fi
2468		fi
2469
2470		# Fink
2471		# There is no way to get the prefix, so implementing a hack here
2472		fink_version=`fink -V 2>/dev/null`
2473		if test "$?" -eq 0; then
2474			fink_version="`echo "${fink_version}" | sed -ne 's/Package manager version: \([0-9.]*\)/\1/gp'`"
2475			echo_n "You seem to be running Fink version ${fink_version}..."
2476
2477			fink_prefix=`which fink`
2478			# strip off /bin/fink from /sw/bin/port
2479			fink_prefix=`dirname ${fink_prefix}`
2480			fink_prefix=`dirname ${fink_prefix}`
2481
2482			echo "adding ${fink_prefix} to paths"
2483
2484			LDFLAGS="-L${fink_prefix}/lib $LDFLAGS"
2485			CXXFLAGS="-I${fink_prefix}/include $CXXFLAGS"
2486
2487			if test -z "$_staticlibpath"; then
2488				_staticlibpath=${fink_prefix}
2489				echo "Set staticlib-prefix to ${_staticlibpath}"
2490			fi
2491		fi
2492
2493		# Homebrew
2494		brew_version=`brew -v 2>/dev/null`
2495		if test "$?" -eq 0; then
2496			brew_version="`echo "${brew_version}" | sed -ne 's/Homebrew \([0-9.]*\)/\1/gp'`"
2497			echo_n "You seem to be running Homebrew version ${brew_version}..."
2498
2499			brew_prefix=`brew --prefix`
2500
2501			echo "adding ${brew_prefix} to paths"
2502
2503			LDFLAGS="-L${brew_prefix}/lib $LDFLAGS"
2504			CXXFLAGS="-I${brew_prefix}/include $CXXFLAGS"
2505
2506			if test -z "$_staticlibpath"; then
2507				_staticlibpath=${brew_prefix}
2508				echo "Set staticlib-prefix to ${_staticlibpath}"
2509			fi
2510		fi
2511
2512		# If _staticlibpath is not set yet try first /sw (fink) then /usr/local
2513		# (the macports case is handled above).
2514		if test -z "$_staticlibpath"; then
2515			if test -d "/sw"; then
2516				_staticlibpath=/sw
2517				echo "Set staticlib-prefix to ${_staticlibpath}"
2518			elif test -d "/usr/local"; then
2519				_staticlibpath=/usr/local
2520				echo "Set staticlib-prefix to ${_staticlibpath}"
2521			else
2522				echo "Could not determine prefix for static libraries"
2523			fi
2524		fi
2525
2526		# If _xcodetoolspath is not set yet use xcode-select to get the path
2527		if test -z "$_xcodetoolspath"; then
2528			_xcodetoolspath=`xcode-select -print-path`/Tools
2529			if test -d "$_xcodetoolspath"; then
2530				echo "Set xcodetools-path to ${_xcodetoolspath}"
2531			else
2532				_xcodetoolspath=
2533				echo "Could not determine path for Xcode Tools"
2534			fi
2535		fi
2536		;;
2537	dreamcast)
2538		append_var DEFINES "-D__DC__"
2539		append_var DEFINES "-DNONSTANDARD_PORT"
2540		;;
2541	ds)
2542		append_var DEFINES "-D__DS__"
2543		append_var DEFINES "-DNDS"
2544		append_var DEFINES "-DARM9"
2545		append_var DEFINES "-DARM"
2546		append_var DEFINES "-DNONSTANDARD_PORT"
2547		append_var CXXFLAGS "-isystem $DEVKITPRO/libnds/include"
2548		append_var CXXFLAGS "-isystem $DEVKITPRO/devkitARM/arm-eabi/include"
2549		append_var CXXFLAGS "-mcpu=arm9tdmi"
2550		append_var CXXFLAGS "-mtune=arm9tdmi"
2551		append_var CXXFLAGS "-fomit-frame-pointer"
2552		append_var CXXFLAGS "-mthumb-interwork"
2553		append_var CXXFLAGS "-ffunction-sections"
2554		append_var CXXFLAGS "-fdata-sections"
2555		append_var CXXFLAGS "-fno-strict-aliasing"
2556		append_var CXXFLAGS "-fuse-cxa-atexit"
2557		append_var LDFLAGS "-specs=ds_arm9.specs"
2558		append_var LDFLAGS "-mthumb-interwork"
2559		append_var LDFLAGS "-mno-fpu"
2560		append_var LDFLAGS "-Wl,-Map,map.txt"
2561		if test "$_dynamic_modules" = no ; then
2562			append_var LDFLAGS "-Wl,--gc-sections"
2563		else
2564			append_var LDFLAGS "-Wl,--no-gc-sections"
2565			# TODO automate this required 2 step linking phase
2566			# append_var LDFLAGS "-Wl,--retain-symbols-file,ds.syms"
2567		fi
2568		append_var LDFLAGS "-L$DEVKITPRO/libnds/lib"
2569		append_var LIBS "-lnds9"
2570		;;
2571	freebsd*|dragonfly*)
2572		append_var LDFLAGS "-L/usr/local/lib"
2573		append_var CXXFLAGS "-I/usr/local/include"
2574		;;
2575	gamecube)
2576		_optimization_level=-Os
2577		append_var CXXFLAGS "-mogc"
2578		append_var CXXFLAGS "-mcpu=750"
2579		append_var CXXFLAGS "-meabi"
2580		append_var CXXFLAGS "-mhard-float"
2581		append_var CXXFLAGS "-ffunction-sections"
2582		append_var CXXFLAGS "-fdata-sections"
2583		append_var CXXFLAGS "-fmodulo-sched"
2584		append_var CXXFLAGS "-fuse-cxa-atexit"
2585		append_var CXXFLAGS "-I$DEVKITPRO/libogc/include"
2586		# libogc is required to link the cc tests (includes _start())
2587		append_var LDFLAGS "-mogc"
2588		append_var LDFLAGS "-mcpu=750"
2589		append_var LDFLAGS "-L$DEVKITPRO/libogc/lib/cube"
2590		append_var LDFLAGS "-logc"
2591		if test "$_dynamic_modules" = "yes" ; then
2592			# retarded toolchain patch forces --gc-sections, overwrite it
2593			append_var LDFLAGS "-Wl,--no-gc-sections"
2594		fi
2595		;;
2596	haiku*)
2597		append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
2598		# Needs -lnetwork for the timidity MIDI driver
2599		append_var LIBS "-lnetwork"
2600		_seq_midi=no
2601		;;
2602	irix*)
2603		append_var DEFINES "-DIRIX"
2604		append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
2605		append_var LIBS "-lmd -lfastm -lm"
2606		_ranlib=:
2607		;;
2608	linux* | uclinux*)
2609		# When not cross-compiling, enable large file support, but don't
2610		# care if getconf doesn't exist or doesn't recognize LFS_CFLAGS.
2611		if test -z "$_host"; then
2612			append_var CXXFLAGS "`getconf LFS_CFLAGS 2>/dev/null`"
2613		fi
2614		;;
2615	maemo)
2616		append_var DEFINES "-DMAEMO"
2617		;;
2618	mingw*)
2619		append_var DEFINES "-DWIN32"
2620		append_var DEFINES "-D__USE_MINGW_ANSI_STDIO=0"
2621		append_var LDFLAGS "-static-libgcc -static-libstdc++"
2622		append_var LIBS "-lmingw32 -lwinmm -lgdi32"
2623		append_var OBJS "residualvmwinres.o"
2624		add_line_to_config_mk 'WIN32 = 1'
2625		;;
2626	mint*)
2627		append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
2628		;;
2629	msys)
2630		echo ERROR: Using the MSYS shell in msys mode is not supported. Please use the MSYS shell in mingw mode instead.
2631		exit 1
2632		;;
2633	n64)
2634		append_var DEFINES "-D__N64__"
2635		append_var DEFINES "-DLIMIT_FPS"
2636		append_var DEFINES "-DNONSTANDARD_PORT"
2637		append_var DEFINES "-DDISABLE_COMMAND_LINE"
2638		append_var DEFINES "-DDISABLE_DEFAULT_SAVEFILEMANAGER"
2639		append_var DEFINES "-DDISABLE_DOSBOX_OPL"
2640		append_var DEFINES "-DDISABLE_FANCY_THEMES"
2641		append_var DEFINES "-DDISABLE_NES_APU"
2642		append_var DEFINES "-DDISABLE_SID"
2643		append_var DEFINES "-DREDUCE_MEMORY_USAGE"
2644		add_line_to_config_mk 'N64 = 1'
2645		;;
2646	ps2)
2647		append_var CXXFLAGS "-G2"
2648		append_var DEFINES "-D_EE"
2649		append_var DEFINES "-D__PLAYSTATION2__"
2650		if test -z "$PS2SDK_OLD"; then
2651			append_var DEFINES "-D__NEW_PS2SDK__"
2652		fi
2653		;;
2654	ps3)
2655		# Force use of SDL and freetype from the ps3 toolchain
2656		_sdlpath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
2657		_freetypepath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
2658		_libcurlpath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
2659
2660		append_var DEFINES "-DPLAYSTATION3"
2661		append_var CXXFLAGS "-mcpu=cell -mminimal-toc -I$PSL1GHT/ppu/include -I$PS3DEV/portlibs/ppu/include"
2662		append_var LDFLAGS "-L$PSL1GHT/ppu/lib -L$PS3DEV/portlibs/ppu/lib"
2663		# The network libraries are statically linked and need to be specified in the following order
2664		append_var SDL_NET_LIBS "-lSDL_net -lnet -lsysmodule"
2665		add_line_to_config_mk 'PLAYSTATION3 = 1'
2666		add_line_to_config_h "#define PREFIX \"${prefix}\""
2667		;;
2668	psp2)
2669		_freetypepath="$VITASDK/arm-vita-eabi/bin"
2670		_freetype2=yes
2671		_libcurlpath="$VITASDK/arm-vita-eabi/bin"
2672		append_var CXXFLAGS "--sysroot=$VITASDK/arm-vita-eabi"
2673		append_var LDFLAGS "--sysroot=$VITASDK/arm-vita-eabi"
2674		append_var DEFINES "-DPSP2 -DSYSTEM_NOT_SUPPORTING_D_TYPE"
2675		append_var CXXFLAGS "-Wl,-q -I$VITASDK/arm-vita-eabi/include"
2676		append_var CXXFLAGS "-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard"
2677		append_var LDFLAGS "-Wl,-q -L$VITASDK/arm-vita-eabi/lib"
2678		#the next line fixes a crash when starting scumm-7-8 games (The Dig etc.)
2679		#when either -O2, -O3 or -Os optimizations are enabled
2680		append_var CXXFLAGS "-fno-optimize-sibling-calls"
2681		#the next line fixes "branch out of range" error in gob engine when -Os is used
2682		append_var CXXFLAGS "-mlong-calls"
2683		if test "$_debug_build" = no; then
2684		#optimize for smallest file size. This is necessary to prevent a crash on startup
2685		#due to the large executable file size when many engines are enabled
2686		#for example when --enable-all-engines is used to enable all the unstable engines
2687			_optimization_level=-Os
2688		fi
2689		if test "$_debug_build" = yes; then
2690			_optimization_level=-O0
2691			append_var DEFINES "-D__PSP2_DEBUG__"
2692			append_var LIBS "-lpsp2shell"
2693		fi
2694		add_line_to_config_mk 'PSP2 = 1'
2695		add_line_to_config_h "#define PREFIX \"${prefix}\""
2696		;;
2697	psp)
2698		if test -d "$PSPDEV/psp/lib"; then
2699			append_var LDFLAGS "-L$PSPDEV/psp/lib"
2700		fi
2701		append_var LDFLAGS "-L$PSPSDK/lib"
2702		append_var LDFLAGS "-specs=$_srcdir/backends/platform/psp/psp.spec"
2703		_optimization_level=-O3
2704		append_var CXXFLAGS "-I$PSPSDK/include"
2705		# FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
2706		append_var CXXFLAGS "-D_PSP_FW_VERSION=150"
2707		add_line_to_config_mk 'PSP = 1'
2708		;;
2709	solaris*)
2710		append_var DEFINES "-DSOLARIS"
2711		append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
2712		# Needs -lbind -lsocket for the timidity MIDI driver
2713		append_var LIBS "-lnsl -lsocket"
2714		;;
2715	tizen)
2716		add_line_to_config_mk "TIZEN_ROOTSTRAP = $TIZEN_ROOTSTRAP"
2717		append_var LDFLAGS "--sysroot=${TIZEN_ROOTSTRAP}"
2718		append_var LDFLAGS "-L${TIZEN_LIBS}/lib"
2719		append_var CXXFLAGS "-I${TIZEN_LIBS}/include"
2720		;;
2721	webos)
2722		append_var CXXFLAGS "--sysroot=$WEBOS_PDK/arm-gcc/sysroot"
2723		append_var CXXFLAGS "-I$WEBOS_PDK/include"
2724		append_var CXXFLAGS "-I$WEBOS_PDK/include/SDL"
2725		append_var CXXFLAGS "-I$WEBOS_PDK/device/usr/include"
2726		# These compiler options are needed to support the Palm Pixi
2727		append_var CXXFLAGS "-mcpu=arm1136jf-s"
2728		append_var CXXFLAGS "-mfpu=vfp "
2729		append_var CXXFLAGS "-mfloat-abi=softfp"
2730		append_var LDFLAGS "-L$WEBOS_PDK/device/lib"
2731		append_var LDFLAGS "-L$WEBOS_PDK/device/usr/lib"
2732		append_var LDFLAGS "-Wl,--allow-shlib-undefined"
2733		append_var LDFLAGS "--sysroot=$WEBOS_PDK/arm-gcc/sysroot"
2734		add_line_to_config_mk "WEBOS_SDK = $WEBOS_SDK"
2735		_seq_midi=no
2736		;;
2737	wii)
2738		_optimization_level=-Os
2739		append_var CXXFLAGS "-mrvl"
2740		append_var CXXFLAGS "-mcpu=750"
2741		append_var CXXFLAGS "-meabi"
2742		append_var CXXFLAGS "-mhard-float"
2743		append_var CXXFLAGS "-ffunction-sections"
2744		append_var CXXFLAGS "-fdata-sections"
2745		append_var CXXFLAGS "-fmodulo-sched"
2746		append_var CXXFLAGS "-fuse-cxa-atexit"
2747		append_var CXXFLAGS "-I$DEVKITPRO/libogc/include"
2748		# libogc is required to link the cc tests (includes _start())
2749		append_var LDFLAGS "-mrvl"
2750		append_var LDFLAGS "-mcpu=750"
2751		append_var LDFLAGS "-L$DEVKITPRO/libogc/lib/wii"
2752		append_var LDFLAGS "-logc"
2753		if test "$_dynamic_modules" = "yes" ; then
2754			# retarded toolchain patch forces --gc-sections, overwrite it
2755			append_var LDFLAGS "-Wl,--no-gc-sections"
2756		fi
2757		;;
2758	wince)
2759		_optimization_level=-O3
2760		append_var CXXFLAGS "-fno-inline-functions"
2761		append_var CXXFLAGS "-march=armv4"
2762		append_var CXXFLAGS "-mtune=xscale"
2763		append_var DEFINES "-D_WIN32_WCE=300"
2764		append_var DEFINES "-D__ARM__"
2765		append_var DEFINES "-D_ARM_"
2766		append_var DEFINES "-DUNICODE"
2767		append_var DEFINES "-DFPM_DEFAULT"
2768		append_var DEFINES "-DNONSTANDARD_PORT"
2769		append_var DEFINES "-DWRAP_MALLOC"
2770		append_var DEFINES "-DWIN32"
2771		append_var DEFINES "-Dcdecl="
2772		append_var DEFINES "-D__cdecl__="
2773		add_line_to_config_mk "WRAP_MALLOC = 1"
2774		;;
2775esac
2776
2777if test -n "$_host"; then
2778	# Cross-compiling mode - add your target here if needed
2779	echo "Cross-compiling to $_host"
2780	case "$_host" in
2781		3ds)
2782			append_var DEFINES "-DDISABLE_FANCY_THEMES"
2783			append_var DEFINES "-DDISABLE_SID"
2784			append_var DEFINES "-DDISABLE_NES_APU"
2785			_backend="3ds"
2786			_build_scalers=no
2787			_vkeybd=yes
2788			_mt32emu=no
2789			# Should use Tremor instead of Vorbis
2790			_vorbis=no
2791			_port_mk="backends/platform/3ds/3ds.mk"
2792			;;
2793		android | android-arm | android-v7a | android-arm-v7a | android-mips | android-x86 | ouya)
2794			# we link a .so as default
2795			append_var LDFLAGS "-shared"
2796			append_var LDFLAGS "-Wl,-Bsymbolic,--no-undefined"
2797			HOSTEXEPRE=lib
2798			HOSTEXEEXT=.so
2799			_backend="android"
2800			_port_mk="backends/platform/android/android.mk"
2801			_build_scalers=no
2802			_seq_midi=no
2803			_mt32emu=no
2804			_timidity=no
2805			;;
2806		androidsdl | androidsdl-armeabi | androidsdl-armeabi-v7a | androidsdl-mips | androidsdl-x86 | androidsdl-arm64-v8a | androidsdl-x86_64)
2807			DEFINES="$DEFINES -DANDROIDSDL"
2808			_unix=yes
2809			_seq_midi=no
2810			_timidity=no
2811			_backend="androidsdl"
2812			_port_mk="backends/platform/androidsdl/androidsdl.mk"
2813			;;
2814		arm-linux|arm*-linux-gnueabi|arm-*-linux)
2815			;;
2816		arm-riscos|linupy)
2817			append_var DEFINES "-DLINUPY"
2818			;;
2819		bfin*)
2820			;;
2821		caanoo)
2822			append_var DEFINES "-DCAANOO"
2823			if test "$_debug_build" = no; then
2824				# Use -O3 on the Caanoo for non-debug builds.
2825				_optimization_level=-O3
2826			fi
2827			append_var CXXFLAGS "-mcpu=arm926ej-s"
2828			append_var CXXFLAGS "-mtune=arm926ej-s"
2829			_backend="gph"
2830			_build_hq_scalers=no
2831			_savegame_timestamp=no
2832			_vkeybd=yes
2833			_seq_midi=no
2834			_mt32emu=no
2835			_timidity=no
2836			_port_mk="backends/platform/gph/caanoo-bundle.mk"
2837			;;
2838		*darwin*)
2839			_ranlib=$_host-ranlib
2840			_strip=$_host-strip
2841			;;
2842		dingux)
2843			append_var DEFINES "-DDINGUX"
2844			append_var DEFINES "-DDISABLE_DOSBOX_OPL"
2845			append_var DEFINES "-DREDUCE_MEMORY_USAGE"
2846			append_var CXXFLAGS "-msoft-float"
2847			append_var CXXFLAGS "-mips32"
2848			_backend="dingux"
2849			_mt32emu=no
2850			_optimization_level=-O3
2851			# Disable alsa midi to get the port build on OpenDingux toolchain
2852			_alsa=no
2853			# Disable cloud and SDL_Net due to outdated toolchain
2854			_cloud=no
2855			_sdlnet=no
2856			_libcurl=no
2857			_vkeybd=yes
2858			_build_hq_scalers=no
2859			_keymapper=no
2860			# Force disable vorbis on dingux, it has terrible performance compared to tremor
2861			_vorbis=no
2862			# Force disable seq on dingux, no way to use it and it would get enabled by default with configure
2863			_seq_midi=no
2864			_port_mk="backends/platform/dingux/dingux.mk"
2865			;;
2866		raspberrypi)
2867			# This is needed because the official cross compiler doesn't have multiarch enabled
2868			# but Raspbian does.
2869			# Be careful as it's the linker (LDFLAGS) which must know about sysroot.
2870			# These are needed to build against Raspbian's libSDL.
2871			append_var LDFLAGS "--sysroot=$RPI_ROOT"
2872			append_var LDFLAGS "-B$RPI_ROOT/usr/lib/arm-linux-gnueabihf"
2873			append_var LDFLAGS "-Xlinker --rpath-link=$RPI_ROOT/usr/lib/arm-linux-gnueabihf"
2874			append_var LDFLAGS "-Xlinker --rpath-link=$RPI_ROOT/lib/arm-linux-gnueabihf"
2875			append_var LDFLAGS "-Xlinker --rpath-link=$RPI_ROOT/opt/vc/lib"
2876			append_var LDFLAGS "-L$RPI_ROOT/opt/vc/lib"
2877			# This is so optional OpenGL ES includes are found.
2878			append_var CXXFLAGS "-I$RPI_ROOT/opt/vc/include"
2879			_savegame_timestamp=no
2880			_eventrec=no
2881			_build_scalers=no
2882			_build_hq_scalers=no
2883			# We prefer SDL2 on the Raspberry Pi: acceleration now depends on it
2884			# since SDL2 manages dispmanx/GLES2 very well internally.
2885			# SDL1 is bit-rotten on this platform.
2886			_sdlconfig=sdl2-config
2887			# OpenGL ES support is mature enough as to be the best option on
2888			# the Raspberry Pi, so it's enabled by default.
2889			# The Raspberry Pi always supports OpenGL ES 2.0 contexts, thus we
2890			# take advantage of those.
2891			_opengl_mode=gles2
2892			;;
2893		dreamcast)
2894			append_var DEFINES "-DDISABLE_DEFAULT_SAVEFILEMANAGER"
2895			append_var DEFINES "-DDISABLE_TEXT_CONSOLE"
2896			append_var DEFINES "-DDISABLE_COMMAND_LINE"
2897			# Enable serial debugging output only when --enable-debug is passed
2898			if test "$_release_build" = yes -o "$_debug_build" != yes; then
2899				append_var DEFINES "-DNOSERIAL"
2900			fi
2901			_optimization_level=-O3
2902			append_var CXXFLAGS "-funroll-loops"
2903			append_var CXXFLAGS "-fschedule-insns2"
2904			append_var CXXFLAGS "-fomit-frame-pointer"
2905			append_var CXXFLAGS "-fdelete-null-pointer-checks"
2906			_backend="dc"
2907			_build_scalers=no
2908			_mad=yes
2909			_zlib=yes
2910			if test -z "$RONINDIR"; then
2911				add_line_to_config_mk "ronindir := /usr/local/ronin"
2912			else
2913				add_line_to_config_mk "ronindir := $RONINDIR"
2914			fi
2915			_port_mk="backends/platform/dc/dreamcast.mk"
2916			;;
2917		ds)
2918			append_var DEFINES "-DDISABLE_COMMAND_LINE"
2919			append_var DEFINES "-DDISABLE_DEFAULT_SAVEFILEMANAGER"
2920			append_var DEFINES "-DDISABLE_DOSBOX_OPL"
2921			append_var DEFINES "-DDISABLE_FANCY_THEMES"
2922			append_var DEFINES "-DDISABLE_SID"
2923			append_var DEFINES "-DDISABLE_NES_APU"
2924			append_var DEFINES "-DDISABLE_TEXT_CONSOLE"
2925			append_var DEFINES "-DREDUCE_MEMORY_USAGE"
2926			append_var DEFINES "-DSTREAM_AUDIO_FROM_DISK"
2927			append_var DEFINES "-DVECTOR_RENDERER_FORMAT=1555"
2928			_backend="ds"
2929			_build_scalers=no
2930			_mt32emu=no
2931			_port_mk="backends/platform/ds/ds.mk"
2932			;;
2933		gamecube)
2934			_backend="wii"
2935			_build_scalers=no
2936			_vkeybd=yes
2937			_mt32emu=no
2938			_port_mk="backends/platform/wii/wii.mk"
2939			add_line_to_config_mk 'GAMECUBE = 1'
2940			add_line_to_config_h '#define AUDIO_REVERSE_STEREO'
2941			add_line_to_config_h '#define GAMECUBE'
2942			add_line_to_config_h "/* #define DEBUG_WII_USBGECKO */"
2943			add_line_to_config_h "/* #define DEBUG_WII_MEMSTATS */"
2944			add_line_to_config_h "/* #define DEBUG_WII_GDB */"
2945			add_line_to_config_h "#define USE_WII_DI"
2946			;;
2947		gcw0)
2948			_sysroot=`$CXX --print-sysroot`
2949			_sdlpath=$_sysroot/usr/bin
2950			append_var DEFINES "-DDINGUX -DGCW0 -DGUI_ONLY_FULLSCREEN"
2951			append_var DEFINES "-DREDUCE_MEMORY_USAGE"
2952			append_var CXXFLAGS "-mips32"
2953			_backend="dingux"
2954			_alsa=no
2955			_mt32emu=no
2956			_seq_midi=no
2957			_timidity=no
2958			_build_scalers=yes
2959			_optimization_level=-O3
2960			_vkeybd=yes
2961			_keymapper=yes
2962			_vorbis=no
2963			_sdlconfig=sdl-config
2964			_port_mk="backends/platform/dingux/dingux.mk"
2965			;;
2966		gp2x)
2967			append_var DEFINES "-DGP2X"
2968			append_var CXXFLAGS "-march=armv4t"
2969			append_var ASFLAGS "-mfloat-abi=soft"
2970			append_var LDFLAGS "-static"
2971			_backend="gph"
2972			_build_hq_scalers=no
2973			_savegame_timestamp=no
2974			_vkeybd=yes
2975			_seq_midi=no
2976			_mt32emu=no
2977			_timidity=no
2978			_port_mk="backends/platform/gph/gp2x-bundle.mk"
2979			;;
2980		gp2xwiz)
2981			append_var DEFINES "-DGP2XWIZ"
2982			append_var CXXFLAGS "-mcpu=arm926ej-s"
2983			append_var CXXFLAGS "-mtune=arm926ej-s"
2984			append_var ASFLAGS "-mfloat-abi=soft"
2985			_backend="gph"
2986			_build_hq_scalers=no
2987			_savegame_timestamp=no
2988			_vkeybd=yes
2989			_seq_midi=no
2990			_mt32emu=no
2991			_timidity=no
2992			_port_mk="backends/platform/gph/gp2xwiz-bundle.mk"
2993			;;
2994		iphone)
2995			append_var DEFINES "-DIPHONE"
2996			append_var ASFLAGS "-arch armv6"
2997			_backend="iphone"
2998			_build_scalers=no
2999			_mt32emu=no
3000			_seq_midi=no
3001			_timidity=no
3002			;;
3003		ios7)
3004			append_var DEFINES "-DIPHONE"
3005			_backend="ios7"
3006			_build_scalers=no
3007			_seq_midi=no
3008			_timidity=no
3009			;;
3010		m68k-atari-mint)
3011			append_var DEFINES "-DSYSTEM_NOT_SUPPORTING_D_TYPE"
3012			_ranlib=m68k-atari-mint-ranlib
3013			_ar="m68k-atari-mint-ar cru"
3014			_seq_midi=no
3015			;;
3016		maemo)
3017			_optimization_level=-Os
3018			append_var CXXFLAGS "-mcpu=arm926ej-s"
3019			append_var CXXFLAGS "-fomit-frame-pointer"
3020			append_var INCLUDES "-I/usr/X11R6/include"
3021			append_var LIBS "-lX11"
3022			append_var LIBS "-L/usr/lib"
3023
3024			_backend="maemo"
3025			_vkeybd=yes
3026			_keymapper=yes
3027			_build_hq_scalers=no
3028			_mt32emu=no
3029			_alsa=no
3030			_mad=yes
3031			_tremor=yes
3032			_zlib=yes
3033			;;
3034		*mingw32*)
3035			_sdlconfig=$_host-sdl-config
3036			_windres=$_host-windres
3037			_ar="$_host-ar cru"
3038			_ranlib=$_host-ranlib
3039			;;
3040		mips-sgi*)
3041			append_var LDFLAGS "-static-libgcc"
3042			append_var LIBS "-laudio"
3043			;;
3044		motoezx)
3045			append_var DEFINES "-DMOTOEZX"
3046			append_var ASFLAGS "-mfpu=vfp"
3047			_backend="linuxmoto"
3048			_build_hq_scalers=no
3049			_mt32emu=no
3050			_vkeybd=yes
3051			_seq_midi=no
3052			_port_mk="backends/platform/linuxmoto/linuxmoto.mk"
3053			;;
3054		motomagx)
3055			append_var DEFINES "-DMOTOMAGX"
3056			append_var ASFLAGS "-mfpu=vfp"
3057			_backend="linuxmoto"
3058			_build_hq_scalers=no
3059			_mt32emu=no
3060			_vkeybd=yes
3061			_seq_midi=no
3062			_port_mk="backends/platform/linuxmoto/linuxmoto.mk"
3063			;;
3064		n64)
3065			append_var CXXFLAGS "-mno-extern-sdata"
3066			append_var CXXFLAGS "--param max-inline-insns-auto=20"
3067			append_var CXXFLAGS "-fomit-frame-pointer"
3068			append_var CXXFLAGS "-march=vr4300"
3069			append_var CXXFLAGS "-mtune=vr4300"
3070			append_var CXXFLAGS "-mhard-float"
3071			append_var LDFLAGS "-march=vr4300"
3072			append_var LDFLAGS "-mtune=vr4300"
3073			append_var LDFLAGS "-nodefaultlibs"
3074			append_var LDFLAGS "-nostartfiles"
3075			append_var LDFLAGS "-mno-crt0"
3076			append_var LDFLAGS "-L$N64SDK/hkz-libn64"
3077			append_var LDFLAGS "-L$N64SDK/lib"
3078			append_var LDFLAGS "-T n64ld_cpp.x -Xlinker -Map -Xlinker residualvm.map"
3079			_backend="n64"
3080			_mt32emu=no
3081			_build_scalers=no
3082			_savegame_timestamp=no
3083			_translation=no
3084			_keymapper=no
3085			_text_console=no
3086			_vkeybd=yes
3087			_dynamic_modules=no
3088			_plugins_default=static
3089			# Force use of libmad, libtremor and zlib
3090			_mad=no
3091			_tremor=yes
3092			_zlib=yes
3093			_port_mk="backends/platform/n64/n64.mk"
3094			;;
3095		neuros)
3096			append_var DEFINES "-DNEUROS"
3097			_backend='null'
3098			_build_hq_scalers=no
3099			_mt32emu=no
3100			;;
3101		openpandora)
3102			append_var DEFINES "-DOPENPANDORA"
3103			append_var DEFINES "-DREDUCE_MEMORY_USAGE"
3104			if test "$_release_build" = no; then
3105				append_var DEFINES "-DOP_DEBUG"
3106			fi
3107
3108			# Use -O3 on the OpenPandora for optimized builds.
3109			if test "$_optimizations" = yes; then
3110				_optimization_level=-O3
3111			fi
3112
3113			define_in_config_if_yes yes 'USE_ARM_NEON_ASPECT_CORRECTOR'
3114			append_var CXXFLAGS "-march=armv7-a"
3115			append_var CXXFLAGS "-mtune=cortex-a8"
3116			append_var CXXFLAGS "-mfloat-abi=softfp"
3117			append_var CXXFLAGS "-mfpu=neon"
3118			append_var CXXFLAGS "-fsingle-precision-constant"
3119			append_var ASFLAGS "-mfloat-abi=softfp"
3120			_backend="openpandora"
3121			_build_hq_scalers=yes
3122			_vkeybd=no
3123			_mt32emu=no
3124			_seq_midi=no
3125			_port_mk="backends/platform/openpandora/op-bundle.mk"
3126			;;
3127		ppc-amigaos)
3128			# PPC Linker requires this to fix relocation errors
3129			append_var CXXFLAGS "-mlongcall"
3130
3131			# Only static builds link successfully on buildbot
3132			LDFLAGS=`echo $LDFLAGS | sed 's/-use-dynld//'`
3133			append_var LDFLAGS "-static"
3134
3135			# toolchain binaries prefixed by host
3136			_ranlib=$_host-ranlib
3137			_strip=$_host-strip
3138			_ar="$_host-ar cru"
3139			_as="$_host-as"
3140			_windres=$_host-windres
3141
3142			_port_mk="backends/platform/sdl/amigaos/amigaos.mk"
3143			;;
3144		ps2)
3145			append_var DEFINES "-DDISABLE_TEXT_CONSOLE"
3146			append_var DEFINES "-DDISABLE_COMMAND_LINE"
3147			append_var DEFINES "-DDISABLE_DOSBOX_OPL"
3148			append_var DEFINES "-DDISABLE_SID"
3149			append_var DEFINES "-DDISABLE_NES_APU"
3150			append_var CXXFLAGS "-fno-exceptions"
3151			append_var CXXFLAGS "-fno-rtti"
3152			_backend="ps2"
3153			_build_scalers=no
3154			_mt32emu=no
3155			# HACK to enable mad & zlib (they are not properly detected due to linker issues).
3156			# This trick doesn't work for tremor right now, as the PS2 port the resulting library
3157			# libtremor, while our code later on expects it to be called libvorbisidec.
3158			# TODO: Enable tremor, e.g. by adding  -ltremor or by renaming the lib.
3159			# Disable this for older SDK as this breaks the build otherwise...
3160			if test -z "$PS2SDK_OLD"; then
3161				_tremor=yes
3162			fi
3163			_mad=yes
3164			_zlib=yes
3165			# HACK to fix compilation of C source files for now.
3166			add_line_to_config_mk 'CC := ee-gcc'
3167			add_line_to_config_mk 'CFLAGS := -std=c99 -W -Wno-unused-parameter -Wconversion -pedantic -G2 -s -O2 -Wuninitialized'
3168			# HACK to fix linking for now. It seems ee-g++ does not handle linking correctly.
3169			LD=ee-gcc
3170
3171			if test "$_debug_build" = yes; then
3172				# TODO: Setup debug build properly
3173				append_var DEFINES "-D__PS2_DEBUG__"
3174				#append_var INCLUDES "-I$(PS2GDB)/ee"
3175				#append_var LDFLAGS "-L$(PS2GDB)/lib"
3176				append_var LDFLAGS "-lps2gdbStub"
3177				append_var LDFLAGS "-lps2ip"
3178				append_var LDFLAGS "-ldebug"
3179			else
3180				# If not building for debug mode, strip binaries.
3181				append_var CXXFLAGS "-s"
3182			fi
3183			;;
3184		ps3)
3185			_mt32emu=no
3186			_timidity=no
3187			_vkeybd=yes
3188			_eventrec=no
3189			_port_mk="backends/platform/sdl/ps3/ps3.mk"
3190			;;
3191		psp2)
3192			_backend="psp2"
3193			_vkeybd=yes
3194			_build_scalers=yes
3195			_build_hq_scalers=no
3196			_mt32emu=no
3197			_timidity=no
3198			_eventrec=no
3199			_port_mk="backends/platform/sdl/psp2/psp2.mk"
3200			;;
3201		psp)
3202			_backend="psp"
3203			_build_scalers=no
3204			_mt32emu=no
3205			_port_mk="backends/platform/psp/psp.mk"
3206			;;
3207		samsungtv)
3208			append_var DEFINES "-DSAMSUNGTV"
3209			append_var DEFINES "-DDISABLE_COMMAND_LINE"
3210			append_var ASFLAGS "-mfpu=vfp"
3211			HOSTEXEEXT=".so"
3212			_backend="samsungtv"
3213			_mt32emu=no
3214			_vkeybd=yes
3215			;;
3216		tizen)
3217			_unix=yes
3218			_backend="tizen"
3219			_port_mk="backends/platform/tizen/tizen.mk"
3220			_arm_asm=yes
3221			_build_scalers=no
3222			_seq_midi=no
3223			_mt32emu=no
3224			_timidity=no
3225			_vkeybd=yes
3226			# Tizen relies on the OpenGL ES output thus we always enable it.
3227			_opengl_mode=gles
3228			;;
3229		webos)
3230			_backend="webos"
3231			_port_mk="backends/platform/webos/webos.mk"
3232			_build_scalers=yes
3233			_build_hq_scalers=no
3234			_timidity=no
3235			_mt32emu=no
3236			_seq_midi=no
3237			_vkeybd=no
3238			_keymapper=yes
3239			add_line_to_config_mk "HOST_COMPILER = `uname`"
3240			;;
3241		wii)
3242			_backend="wii"
3243			_build_scalers=no
3244			_vkeybd=yes
3245			_port_mk="backends/platform/wii/wii.mk"
3246			add_line_to_config_mk 'GAMECUBE = 0'
3247			add_line_to_config_h '#define AUDIO_REVERSE_STEREO'
3248			add_line_to_config_h "#define DEBUG_WII_USBGECKO"
3249			add_line_to_config_h "/* #define DEBUG_WII_MEMSTATS */"
3250			add_line_to_config_h "/* #define DEBUG_WII_GDB */"
3251			add_line_to_config_h "#define USE_WII_DI"
3252			add_line_to_config_h "#define USE_WII_SMB"
3253			add_line_to_config_h "#define USE_WII_KBD"
3254			;;
3255		wince)
3256			append_var LDFLAGS "-Wl,--stack,65536"
3257			_tremolo=yes
3258			_backend="wince"
3259			_detectlang=yes
3260			_mt32emu=no
3261			_port_mk="backends/platform/wince/wince.mk"
3262			;;
3263		*)
3264			echo "WARNING: Unknown target, continuing with auto-detected values"
3265			;;
3266	esac
3267fi
3268
3269#
3270# Backend related stuff
3271#
3272case $_backend in
3273	3ds)
3274		;;
3275	android)
3276		append_var DEFINES "-DREDUCE_MEMORY_USAGE"
3277		append_var CXXFLAGS "-Wa,--noexecstack"
3278		append_var LDFLAGS "-Wl,-z,noexecstack"
3279		append_var INCLUDES "-isystem $ANDROID_NDK/sources/cxx-stl/system/include"
3280		;;
3281	androidsdl)
3282		;;
3283	dc)
3284		append_var INCLUDES '-I$(srcdir)/backends/platform/dc'
3285		append_var INCLUDES '-isystem $(ronindir)/include'
3286		append_var LDFLAGS "-Wl,-Ttext,0x8c010000"
3287		append_var LDFLAGS "-nostartfiles"
3288		append_var LDFLAGS '$(ronindir)/lib/crt0.o'
3289		append_var LDFLAGS '-L$(ronindir)/lib'
3290		# Enable serial debugging output only when --enable-debug is passed
3291		if test "$_release_build" = yes -o "$_debug_build" != yes; then
3292			append_var LIBS "-lronin-noserial -lm"
3293		else
3294			append_var LIBS "-lronin -lm"
3295		fi
3296		;;
3297	dingux)
3298		append_var DEFINES "-DDINGUX"
3299		;;
3300	ds)
3301		append_var INCLUDES '-I$(srcdir)/backends/platform/ds/arm9/source'
3302		append_var INCLUDES '-I$(srcdir)/backends/platform/ds/commoninclude'
3303		append_var INCLUDES '-Ibackends/platform/ds/arm9/data'
3304		;;
3305	gph)
3306		# On the GPH devices we want fancy themes but do not want the load/save thumbnail grid.
3307		append_var DEFINES "-DDISABLE_SAVELOADCHOOSER_GRID"
3308		append_var DEFINES "-DGPH_DEVICE"
3309		append_var DEFINES "-DREDUCE_MEMORY_USAGE"
3310		if test "$_debug_build" = yes; then
3311			append_var DEFINES "-DGPH_DEBUG"
3312		fi
3313		;;
3314	iphone)
3315		append_var LIBS "-lobjc -framework UIKit -framework CoreGraphics -framework OpenGLES"
3316		append_var LIBS "-framework QuartzCore -framework CoreFoundation -framework Foundation"
3317		append_var LIBS "-framework AudioToolbox -framework CoreAudio"
3318		;;
3319	ios7)
3320		append_var LIBS "-lobjc -framework UIKit -framework CoreGraphics -framework OpenGLES"
3321		append_var LIBS "-framework QuartzCore -framework CoreFoundation -framework Foundation"
3322		append_var LIBS "-framework AudioToolbox -framework CoreAudio"
3323		append_var LDFLAGS "-miphoneos-version-min=7.1 -arch armv7"
3324		append_var CFLAGS "-miphoneos-version-min=7.1 -arch armv7"
3325		append_var CXXFLAGS "-miphoneos-version-min=7.1 -arch armv7"
3326		if test -n "$SDKROOT"; then
3327			append_var LDFLAGS "-mlinker-version=134.9 -B/usr/local/bin/arm-apple-darwin11-"
3328			append_var CFLAGS "-isysroot $SDKROOT -F$SDKROOT/System/Library/Frameworks"
3329			append_var CXXFLAGS "-isysroot $SDKROOT -I$SDKROOT/usr/include/c++/4.2.1 -F$SDKROOT/System/Library/Frameworks"
3330		fi
3331		;;
3332	linuxmoto)
3333		append_var DEFINES "-DLINUXMOTO"
3334		;;
3335	maemo)
3336		append_var DEFINES "-DMAEMO"
3337		;;
3338	n64)
3339		append_var INCLUDES '-I$(N64SDK)/include'
3340		append_var INCLUDES '-I$(N64SDK)/mips64/include'
3341		append_var INCLUDES '-I$(N64SDK)/hkz-libn64'
3342		append_var INCLUDES '-I$(srcdir)/backends/platform/n64'
3343		append_var LIBS "-lpakfs -lframfs -ln64 -ln64utils -lromfs"
3344		append_var LIBS "-lm -lstdc++ -lz"
3345		;;
3346	null)
3347		append_var DEFINES "-DUSE_NULL_DRIVER"
3348		;;
3349	openpandora)
3350		;;
3351	ps2)
3352		append_var DEFINES "-D_EE"
3353		append_var DEFINES "-DFORCE_RTL"
3354		append_var INCLUDES "-I$PS2SDK/ee/include"
3355		append_var INCLUDES "-I$PS2SDK/common/include"
3356		append_var INCLUDES "-I$PS2SDK/ports/include"
3357		if test "$_dynamic_modules" = no ; then
3358			append_var LDFLAGS "-mno-crt0"
3359			append_var LDFLAGS "$PS2SDK/ee/startup/crt0.o"
3360			append_var LDFLAGS "-T $PS2SDK/ee/startup/linkfile"
3361		fi
3362		append_var LDFLAGS "-L$PS2SDK/ee/lib"
3363		append_var LDFLAGS "-L$PS2SDK/ports/lib"
3364		append_var LIBS "-lmc -lpad -lmouse -lhdd -lpoweroff -lsjpcm"
3365		append_var LIBS "-lm -lc -lfileXio -lkernel -lstdc++"
3366		;;
3367	psp)
3368		append_var DEFINES "-D__PSP__"
3369		append_var DEFINES "-DDISABLE_COMMAND_LINE"
3370		append_var DEFINES "-DDISABLE_DOSBOX_OPL"
3371		append_var LIBS "-lpng"
3372		append_var LIBS "-Wl,-Map,mapfile.txt"
3373		;;
3374	psp2)
3375		append_var LIBS "-lvitashaders -lSDL2 -lvita2d_fbo -lSceCommonDialog_stub"
3376		append_var LIBS "-lSceSysmodule_stub -lSceDisplay_stub -lSceGxm_stub"
3377		append_var LIBS "-lSceAudio_stub -lSceCtrl_stub -lScePower_stub"
3378		append_var LIBS "-lSceNet_stub -lSceNetCtl_stub -lSceAppMgr_stub -lScePgf_stub"
3379		append_var DEFINES "-DSDL_BACKEND"
3380		add_line_to_config_mk "SDL_BACKEND = 1"
3381		add_line_to_config_mk "USE_SDL2 = 1"
3382		append_var MODULES "backends/platform/sdl"
3383		append_var INCLUDES "-I$VITASDK/arm-vita-eabi/include/SDL2"
3384		;;
3385	samsungtv)
3386		append_var DEFINES "-DSAMSUNGTV"
3387		append_var LDFLAGS "-shared"
3388		append_var LDFLAGS "-fpic"
3389		;;
3390	sdl)
3391		;;
3392	tizen)
3393		# dirent.h not available. NONSTANDARD_PORT==ensure portdefs.h is included
3394		append_var DEFINES "-DTIZEN -DDISABLE_STDIO_FILESTREAM -DNONSTANDARD_PORT"
3395		append_var DEFINES "-DNO_STDERR_STDOUT"
3396		append_var DEFINES "-DDISABLE_COMMAND_LINE"
3397		append_var INCLUDES '-I$(srcdir)/backends/platform/tizen'
3398		append_var INCLUDES '-I$(TIZEN_ROOTSTRAP)/usr/include'
3399		append_var INCLUDES '-I$(TIZEN_ROOTSTRAP)/usr/include/osp'
3400		if test "$_debug_build" = yes; then
3401			append_var CXXFLAGS "-D_DEBUG -DBUILD_DLL -O0 -g3"
3402		fi
3403		# created a shared library for inclusion via the eclipse build
3404		append_var CXXFLAGS "-Wno-psabi"
3405		append_var CXXFLAGS "--sysroot=${TIZEN_ROOTSTRAP}"
3406		append_var CXXFLAGS "-fmessage-length=0"
3407		append_var CXXFLAGS "-fPIC"
3408		HOSTEXEPRE=lib
3409		HOSTEXEEXT=.a
3410		;;
3411	webos)
3412		# There is no sdl-config in the WebOS PDK so we don't use find_sdlconfig here.
3413		# The PDL library acts as the WebOS device toolchain, and is required to control the virtual keyboard among other OS-level events.
3414		append_var LIBS "-lSDL -lpdl"
3415		append_var DEFINES "-DWEBOS"
3416		append_var DEFINES "-DSDL_BACKEND"
3417		add_line_to_config_mk "SDL_BACKEND = 1"
3418		append_var MODULES "backends/platform/sdl"
3419		;;
3420	wii)
3421		append_var DEFINES "-D__WII__"
3422		append_var DEFINES "-DGEKKO"
3423		case $_host_os in
3424		gamecube)
3425			append_var LIBS "-lgxflux -liso9660 -lfat -logc -ldb"
3426			;;
3427		*)
3428			append_var LIBS "-lgxflux -ldi -liso9660 -ltinysmb -lfat -lwiiuse -lbte -logc -lwiikeyboard -ldb"
3429			;;
3430		esac
3431		;;
3432	wince)
3433		append_var INCLUDES '-I$(srcdir)/backends/platform/wince'
3434		append_var INCLUDES '-I$(srcdir)/backends/platform/wince/CEgui'
3435		append_var INCLUDES '-I$(srcdir)/backends/platform/wince/CEkeys'
3436		append_var LIBS "-static -lSDL"
3437		append_var DEFINES "-DSDL_BACKEND"
3438		add_line_to_config_mk "SDL_BACKEND = 1"
3439		;;
3440	*)
3441		echo "support for $_backend backend not implemented in configure script yet"
3442		exit 1
3443		;;
3444esac
3445append_var MODULES "backends/platform/$_backend"
3446
3447#
3448# Setup SDL specifics for SDL based backends
3449#
3450case $_backend in
3451	androidsdl | dingux | gph | linuxmoto | maemo | openpandora | samsungtv | sdl)
3452		find_sdlconfig
3453		append_var INCLUDES "`$_sdlconfig --prefix="$_sdlpath" --cflags`"
3454		append_var LIBS "`$_sdlconfig --prefix="$_sdlpath" --libs`"
3455		append_var DEFINES "-DSDL_BACKEND"
3456		add_line_to_config_mk "SDL_BACKEND = 1"
3457
3458		_sdlversion=`$_sdlconfig --version`
3459		case $_sdlversion in
3460			2.0.*)
3461				add_line_to_config_mk "USE_SDL2 = 1"
3462				append_var SDL_NET_LIBS "-lSDL2_net"
3463				;;
3464			*)
3465				append_var SDL_NET_LIBS "-lSDL_net"
3466				;;
3467		esac
3468
3469		# Check for SDL_Net
3470		echocheck "SDL_Net"
3471		if test "$_sdlnet" = auto ; then
3472			_sdlnet=no
3473			cat > $TMPC << EOF
3474#include "SDL_net.h"
3475int main(int argc, char *argv[]) { SDLNet_Init(); return 0; }
3476EOF
3477			cc_check $SDL_NET_LIBS $LIBS $INCLUDES $SDL_NET_CFLAGS && _sdlnet=yes
3478		fi
3479		if test "$_sdlnet" = yes ; then
3480			# Some platforms require SDL to be after SDL_Net, thus we prepend var
3481			prepend_var LIBS "$SDL_NET_LIBS"
3482			append_var INCLUDES "$SDL_NET_CFLAGS"
3483		fi
3484		define_in_config_if_yes "$_sdlnet" 'USE_SDL_NET'
3485		echo "$_sdlnet"
3486
3487		;;
3488esac
3489
3490
3491#
3492# Enable 16bit support only for backends which support it
3493#
3494case $_backend in
3495	3ds | android | androidsdl | dingux | dc | gph | iphone | ios7 | maemo | openpandora | psp | psp2 | samsungtv | sdl | tizen | webos | wii)
3496		if test "$_16bit" = auto ; then
3497			_16bit=yes
3498		else
3499			_16bit=no
3500		fi
3501		;;
3502	*)
3503		_16bit=no
3504		;;
3505esac
3506
3507#
3508# Enable High resolution engines (>320x240) support only for backends which support it
3509#
3510case $_host in
3511	gcw0)
3512		if test "$_highres" = yes ; then
3513			_highres=yes
3514		else
3515			_highres=no
3516		fi
3517		;;
3518	*)
3519		if test "$_highres" = no ; then
3520			_highres=no
3521		else
3522			_highres=yes
3523		fi
3524		;;
3525esac
3526
3527#
3528# Enable Event Recorder only for backends that support it
3529#
3530case $_backend in
3531	sdl)
3532		if test "$_eventrec" = auto ; then
3533			_eventrec=yes
3534		fi
3535		;;
3536	*)
3537		_eventrec=no
3538		;;
3539esac
3540
3541#
3542# Disable savegame timestamp support for backends which don't have a reliable real time clock
3543#
3544case $_backend in
3545	gph | n64)
3546		if test "$_savegame_timestamp" = auto ; then
3547			_savegame_timestamp=no
3548		else
3549			_savegame_timestamp=yes
3550		fi
3551		;;
3552	*)
3553		if test "$_savegame_timestamp" = auto ; then
3554			_savegame_timestamp=yes
3555		else
3556			_savegame_timestamp=no
3557		fi
3558		;;
3559esac
3560
3561#
3562# Determine whether host is POSIX compliant, or at least POSIX
3563# compatible enough to support our POSIX code (including dlsym(),
3564# mkdir() and some other APIs).
3565#
3566# TODO: Instead of basing this on the host name, we should really base
3567# this on the presence of features (such as the dlsym and mkdir APIs).
3568#
3569echo_n "Checking if host is POSIX compliant... "
3570case $_host_os in
3571	amigaos* | cygwin* | dreamcast | ds | gamecube | mingw* | n64 | ps2 | ps3 | psp2 | psp | wii | wince)
3572		_posix=no
3573		;;
3574	3ds | android | androidsdl | beos* | bsd* | darwin* | dragonfly* | freebsd* | gnu* | gph-linux | haiku* | hpux* | iphone | ios7 | irix*| k*bsd*-gnu* | linux* | maemo | mint* | netbsd* | openbsd* | solaris* | sunos* | uclinux* | webos)
3575		_posix=yes
3576		;;
3577	os2-emx*)
3578		_posix=yes	# FIXME: Really???
3579		;;
3580	*)
3581		# given this is a shell script, we might assume some type of posix.
3582		# However, the host system might be a totally different one, so
3583		# we can assume nothing about it.
3584		# Indeed, as mentioned further above, we really should test for the
3585		# presences of relevant APIs on the host anyway...
3586		_posix=no
3587		;;
3588esac
3589echo $_posix
3590
3591if test "$_posix" = yes ; then
3592	append_var DEFINES "-DPOSIX"
3593	add_line_to_config_mk 'POSIX = 1'
3594fi
3595
3596#
3597# Check whether to enable a verbose build
3598#
3599echo_n "Checking whether to have a verbose build... "
3600echo "$_verbose_build"
3601add_to_config_mk_if_yes "$_verbose_build" 'VERBOSE_BUILD = 1'
3602
3603
3604#
3605# If a specific optimization level was requested, enable optimizations
3606#
3607if test -n "$_optimization_level" ; then
3608	# Ports will specify an optimization level and expect that to be enabled
3609	if test "$_optimizations" != no ; then
3610		_optimizations=yes
3611	fi
3612else
3613	_optimization_level=$_default_optimization_level
3614fi
3615
3616#
3617# Check whether to enable optimizations
3618#
3619if test "$_optimizations" = yes ; then
3620	# Enable optimizations. This also
3621	# makes it possible to use -Wuninitialized, so let's do that.
3622	append_var CXXFLAGS "$_optimization_level"
3623	append_var CXXFLAGS "-Wuninitialized"
3624fi
3625
3626#
3627# Check whether plugin support is requested and possible
3628#
3629echo_n "Checking whether building plugins was requested... "
3630echo "$_dynamic_modules"
3631_mak_plugins=
3632
3633if test "$_dynamic_modules" = yes ; then
3634	echo_n "Checking whether building plugins is supported... "
3635	case $_host_os in
3636	android)
3637		_plugin_prefix="lib"
3638		_plugin_suffix=".so"
3639		append_var CXXFLAGS "-fpic"
3640		append_var LIBS "-ldl"
3641# Work around an Android 2.0+ run-time linker bug:
3642# The linker doesn't actually look in previously
3643# loaded libraries when trying to resolve symbols -
3644# effectively turning all dlopen(RTLD_GLOBAL) calls
3645# into dlopen(RTLD_LOCAL).  It *does* look in
3646# DT_NEEDED libraries, so the workaround is to add an
3647# (otherwise unnecessary) dependency from plugins back
3648# to the main libscummvm.so.
3649_mak_plugins='
3650PLUGIN_EXTRA_DEPS = libresidualvm.so
3651PLUGIN_LDFLAGS  += $(LDFLAGS) -L. -lresidualvm
3652PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3653POST_OBJS_FLAGS := -Wl,-no-whole-archive
3654'
3655		;;
3656	darwin*)
3657		_plugin_prefix=""
3658		_plugin_suffix=".plugin"
3659		append_var LIBS "-ldl"
3660_mak_plugins='
3661PLUGIN_EXTRA_DEPS = $(EXECUTABLE)
3662PLUGIN_LDFLAGS  += -bundle -bundle_loader $(EXECUTABLE) -exported_symbols_list "$(srcdir)/plugin.exp"
3663PRE_OBJS_FLAGS  := -all_load
3664POST_OBJS_FLAGS :=
3665'
3666		;;
3667	dreamcast)
3668		_plugin_prefix=""
3669		_plugin_suffix=".plg"
3670_mak_plugins='
3671PLUGIN_EXTRA_DEPS	= $(abspath $(srcdir)/backends/platform/dc/plugin.x $(srcdir)/backends/platform/dc/plugin.syms) $(EXECUTABLE) backends/platform/dc/plugin_head.o
3672PLUGIN_LDFLAGS		= -ml -m4-single-only -nostartfiles -Wl,-q,-T$(srcdir)/backends/platform/dc/plugin.x,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/platform/dc/plugin.syms backends/platform/dc/plugin_head.o
3673PRE_OBJS_FLAGS		:= -Wl,--whole-archive
3674POST_OBJS_FLAGS		:= -Wl,--no-whole-archive
3675'
3676		;;
3677	ds)
3678		_elf_loader=yes
3679		append_var DEFINES "-DELF_LOADER_CXA_ATEXIT"
3680		append_var DEFINES "-DUNCACHED_PLUGINS"
3681		append_var DEFINES "-DELF_NO_MEM_MANAGER"
3682_mak_plugins='
3683PLUGIN_LDFLAGS		+= -Wl,-T$(srcdir)/backends/plugins/ds/plugin.ld -mthumb-interwork -mno-fpu
3684'
3685		;;
3686	freebsd*|dragonfly*)
3687		_plugin_prefix="lib"
3688		_plugin_suffix=".so"
3689		append_var CXXFLAGS "-fPIC"
3690_mak_plugins='
3691PLUGIN_EXTRA_DEPS =
3692PLUGIN_LDFLAGS  += -shared
3693PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3694POST_OBJS_FLAGS := -Wl,-no-whole-archive
3695'
3696		;;
3697	gamecube | wii)
3698		_elf_loader=yes
3699		append_var DEFINES "-DELF_LOADER_CXA_ATEXIT"
3700		append_var DEFINES "-DUNCACHED_PLUGINS"
3701_mak_plugins='
3702PLUGIN_LDFLAGS		+= -Wl,-T$(srcdir)/backends/plugins/wii/plugin.ld
3703'
3704		;;
3705	gph*)
3706		_plugin_prefix=""
3707		_plugin_suffix=".plugin"
3708		append_var CXXFLAGS "-fpic"
3709		append_var LIBS "-ldl"
3710_mak_plugins='
3711PLUGIN_EXTRA_DEPS = $(EXECUTABLE)
3712PLUGIN_LDFLAGS  += -shared
3713PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3714POST_OBJS_FLAGS := -Wl,-no-whole-archive
3715'
3716		;;
3717	irix*)
3718		_plugin_prefix="lib"
3719		_plugin_suffix=".so"
3720		append_var CXXFLAGS "-fpic"
3721		append_var LIBS "-ldl"
3722_mak_plugins='
3723PLUGIN_EXTRA_DEPS =
3724PLUGIN_LDFLAGS  += -shared -static-libgcc
3725PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3726POST_OBJS_FLAGS := -Wl,-no-whole-archive
3727'
3728		;;
3729
3730	linux* | gnu* | k*bsd*-gnu*)
3731		_plugin_prefix="lib"
3732		_plugin_suffix=".so"
3733		append_var CXXFLAGS "-fPIC"
3734		append_var LIBS "-ldl"
3735_mak_plugins='
3736PLUGIN_EXTRA_DEPS =
3737PLUGIN_LDFLAGS  += -shared
3738PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3739POST_OBJS_FLAGS := -Wl,-no-whole-archive
3740'
3741		;;
3742	*mingw32* | mingw64)
3743		_plugin_prefix=""
3744		_plugin_suffix=".dll"
3745_mak_plugins='
3746PLUGIN_EXTRA_DEPS	= $(EXECUTABLE)
3747PLUGIN_LDFLAGS		:= -Wl,--enable-auto-import -shared ./libresidualvm.a
3748PRE_OBJS_FLAGS		:= -Wl,--whole-archive
3749POST_OBJS_FLAGS		:= -Wl,--export-all-symbols -Wl,--no-whole-archive -Wl,--out-implib,./libresidualvm.a
3750'
3751		;;
3752	wince)
3753		append_var DEFINES "-DUNCACHED_PLUGINS"
3754		HOSTEXEEXT=".dll"
3755		_plugin_prefix=""
3756		_plugin_suffix=".plugin"
3757_mak_plugins='
3758PLUGIN_EXTRA_DEPS	= $(EXECUTABLE)
3759PLUGIN_LDFLAGS		:= -shared -lresidualvm -L.
3760PRE_OBJS_FLAGS		:= -Wl,--whole-archive
3761POST_OBJS_FLAGS		:= -Wl,--export-all-symbols -Wl,--no-whole-archive -Wl,--out-implib,./libresidualvm.a -shared
3762'
3763		;;
3764	ps2)
3765		_elf_loader=yes
3766		append_var DEFINES "-DUNCACHED_PLUGINS"
3767_mak_plugins='
3768LDFLAGS         += -mno-crt0 $(PS2SDK)/ee/startup/crt0.o -Wl,-T$(srcdir)/backends/plugins/ps2/main_prog.ld
3769PLUGIN_LDFLAGS  += -mno-crt0 $(PS2SDK)/ee/startup/crt0.o -Wl,-T$(srcdir)/backends/plugins/ps2/plugin.ld -lstdc++ -lc
3770'
3771		;;
3772	psp)
3773		_elf_loader=yes
3774		append_var DEFINES "-DUNCACHED_PLUGINS"
3775_mak_plugins='
3776LDFLAGS				+= -Wl,-T$(srcdir)/backends/plugins/psp/main_prog.ld
3777PLUGIN_LDFLAGS		+= -Wl,-T$(srcdir)/backends/plugins/psp/plugin.ld -lstdc++ -lc
3778'
3779		;;
3780	webos)
3781		_plugin_prefix="lib"
3782		_plugin_suffix=".so"
3783		append_var CXXFLAGS "-fpic"
3784		append_var LIBS "-ldl"
3785_mak_plugins='
3786PLUGIN_EXTRA_DEPS =
3787PLUGIN_LDFLAGS  += -shared $(LDFLAGS)
3788PRE_OBJS_FLAGS  := -Wl,-export-dynamic -Wl,-whole-archive
3789POST_OBJS_FLAGS := -Wl,-no-whole-archive
3790'
3791		;;
3792	*)
3793		_dynamic_modules=no
3794		_mak_plugins=
3795		;;
3796	esac
3797	echo "$_dynamic_modules"
3798fi
3799
3800#
3801# Check whether integrated ELF loader support is requested
3802#
3803define_in_config_if_yes "$_elf_loader" 'USE_ELF_LOADER'
3804
3805if test "$_elf_loader" = yes; then
3806	_plugin_prefix=""
3807	_plugin_suffix=".plg"
3808	_mak_plugins='
3809PLUGIN_EXTRA_DEPS	= $(EXECUTABLE)
3810PLUGIN_LDFLAGS		= -nostartfiles backends/plugins/elf/version.o -Wl,-q,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/plugins/elf/plugin.syms
3811PRE_OBJS_FLAGS		:= -Wl,--whole-archive
3812POST_OBJS_FLAGS		:= -Wl,--no-whole-archive
3813'"$_mak_plugins"
3814fi
3815
3816#
3817# Set up some common plugin settings in config.h and config.mk, if enabled
3818#
3819define_in_config_if_yes "$_dynamic_modules" 'DYNAMIC_MODULES'
3820
3821if test "$_dynamic_modules" = yes ; then
3822	add_line_to_config_h "#define PLUGIN_PREFIX	\"$_plugin_prefix\""
3823	add_line_to_config_h "#define PLUGIN_SUFFIX	\"$_plugin_suffix\""
3824	add_line_to_config_mk "PLUGIN_PREFIX := $_plugin_prefix"
3825	add_line_to_config_mk "PLUGIN_SUFFIX := $_plugin_suffix"
3826fi
3827
3828
3829#
3830# Check whether integrated MT-32 emulator support is requested
3831#
3832define_in_config_if_yes "$_mt32emu" 'USE_MT32EMU'
3833
3834#
3835# Check whether 16bit color support is requested
3836#
3837define_in_config_if_yes "$_16bit" 'USE_RGB_COLOR'
3838
3839#
3840# Check whether High resolution graphics support is requested
3841#
3842define_in_config_if_yes "$_highres" 'USE_HIGHRES'
3843
3844#
3845# Check whether save games use the current time as default description
3846#
3847define_in_config_if_yes "$_savegame_timestamp" 'USE_SAVEGAME_TIMESTAMP'
3848
3849#
3850# Check whether to enable the (hq) scalers
3851#
3852if test "$_build_scalers" = no ; then
3853	_build_hq_scalers=no
3854fi
3855define_in_config_if_yes "$_build_scalers" 'USE_SCALERS'
3856
3857define_in_config_if_yes "$_build_hq_scalers" 'USE_HQ_SCALERS'
3858
3859#
3860# Check for math lib
3861#
3862cat > $TMPC << EOF
3863int main(void) { return 0; }
3864EOF
3865cc_check -lm && append_var LIBS "-lm"
3866
3867#
3868# Check for Ogg Vorbis
3869#
3870echocheck "Ogg Vorbis"
3871if test "$_vorbis" = auto ; then
3872	_vorbis=no
3873	cat > $TMPC << EOF
3874#include <vorbis/codec.h>
3875int main(void) { vorbis_packet_blocksize(0,0); return 0; }
3876EOF
3877	cc_check $OGG_CFLAGS $OGG_LIBS $VORBIS_CFLAGS $VORBIS_LIBS \
3878		-lvorbisfile -lvorbis -logg && _vorbis=yes
3879fi
3880if test "$_vorbis" = yes ; then
3881	append_var LIBS "$OGG_LIBS $VORBIS_LIBS -lvorbisfile -lvorbis -logg"
3882	append_var INCLUDES "$OGG_CFLAGS $VORBIS_CFLAGS"
3883fi
3884define_in_config_if_yes "$_vorbis" 'USE_VORBIS'
3885echo "$_vorbis"
3886
3887#
3888# Check for Tremor
3889#
3890echocheck "Tremor"
3891if test "$_tremolo" = yes ; then
3892	_tremor=yes
3893fi
3894
3895if test "$_tremor" = auto ; then
3896	_tremor=no
3897	cat > $TMPC << EOF
3898#include <tremor/ivorbiscodec.h>
3899int main(void) { vorbis_info_init(0); return 0; }
3900EOF
3901	cc_check $TREMOR_CFLAGS $TREMOR_LIBS -lvorbisidec && \
3902	_tremor=yes
3903fi
3904if test "$_tremor" = yes && test "$_vorbis" = no; then
3905	add_line_to_config_h '#define USE_TREMOR'
3906	add_line_to_config_h '#define USE_VORBIS'
3907	if test "$_tremolo" = yes ; then
3908		add_line_to_config_h '#define USE_TREMOLO'
3909		append_var LIBS "$TREMOR_LIBS -ltremolo"
3910	elif test "$_host" = ps2 ; then
3911		LIBS="-ltremor $LIBS"
3912	else
3913		append_var LIBS "$TREMOR_LIBS -lvorbisidec"
3914	fi
3915	append_var INCLUDES "$TREMOR_CFLAGS"
3916else
3917	if test "$_vorbis" = yes; then
3918		_tremor="no (Ogg Vorbis/Tremor support is mutually exclusive)"
3919	fi
3920	add_line_to_config_h '#undef USE_TREMOR'
3921fi
3922add_to_config_mk_if_yes "$_tremor" 'USE_TREMOR = 1'
3923echo "$_tremor"
3924
3925#
3926# Check for FLAC
3927#
3928echocheck "FLAC >= 1.0.1"
3929if test "$_flac" = auto ; then
3930	_flac=no
3931	cat > $TMPC << EOF
3932#include <FLAC/format.h>
3933int main(void) { return FLAC__STREAM_SYNC_LEN >> 30; /* guaranteed to be 0 */ }
3934EOF
3935	if test "$_vorbis" = yes ; then
3936		cc_check $FLAC_CFLAGS $FLAC_LIBS $OGG_CFLAGS $OGG_LIBS \
3937			-lFLAC -logg && _flac=yes
3938	else
3939		cc_check $FLAC_CFLAGS $FLAC_LIBS \
3940			-lFLAC && _flac=yes
3941	fi
3942fi
3943if test "$_flac" = yes ; then
3944	if test "$_vorbis" = yes ; then
3945		append_var LIBS "$FLAC_LIBS $OGG_LIBS -lFLAC -logg"
3946	else
3947		append_var LIBS "$FLAC_LIBS -lFLAC"
3948	fi
3949	append_var INCLUDES "$FLAC_CFLAGS"
3950fi
3951define_in_config_if_yes "$_flac" 'USE_FLAC'
3952echo "$_flac"
3953
3954#
3955# Check for MAD (MP3 library)
3956#
3957echocheck "MAD"
3958if test "$_mad" = auto ; then
3959	_mad=no
3960	cat > $TMPC << EOF
3961#include <mad.h>
3962int main(void) { return 0; }
3963EOF
3964	cc_check $MAD_CFLAGS $MAD_LIBS -lmad && _mad=yes
3965fi
3966if test "$_mad" = yes ; then
3967	append_var LIBS "$MAD_LIBS -lmad"
3968	append_var INCLUDES "$MAD_CFLAGS"
3969fi
3970define_in_config_if_yes "$_mad" 'USE_MAD'
3971echo "$_mad"
3972
3973#
3974# Check for ALSA
3975#
3976echocheck "ALSA >= 0.9"
3977if test "$_alsa" = auto ; then
3978	_alsa=no
3979	cat > $TMPC << EOF
3980#include <alsa/asoundlib.h>
3981int main(void) { return (!(SND_LIB_MAJOR==0 && SND_LIB_MINOR==9)); }
3982EOF
3983	cc_check $ALSA_CFLAGS $ALSA_LIBS -lasound && _alsa=yes
3984fi
3985if test "$_alsa" = yes ; then
3986	append_var LIBS "$ALSA_LIBS -lasound"
3987	append_var INCLUDES "$ALSA_CFLAGS"
3988fi
3989define_in_config_if_yes "$_alsa" 'USE_ALSA'
3990echo "$_alsa"
3991
3992#
3993# Check for libjpeg
3994#
3995echocheck "libjpeg >= v6b"
3996if test "$_jpeg" = auto ; then
3997	_jpeg=no
3998	cat > $TMPC << EOF
3999#include <stdio.h>
4000#include <jpeglib.h>
4001int main(void) {
4002#if JPEG_LIB_VERSION >= 62
4003#else
4004  syntax error
4005#endif
4006  return 0;
4007}
4008EOF
4009	cc_check $JPEG_CFLAGS $JPEG_LIBS -ljpeg && _jpeg=yes
4010fi
4011if test "$_jpeg" = yes ; then
4012	append_var LIBS "$JPEG_LIBS -ljpeg"
4013	append_var INCLUDES "$JPEG_CFLAGS"
4014fi
4015define_in_config_if_yes "$_jpeg" 'USE_JPEG'
4016echo "$_jpeg"
4017
4018#
4019# Check for PNG
4020#
4021echocheck "PNG >= 1.2.8"
4022if test "$_png" = auto ; then
4023	_png=no
4024	cat > $TMPC << EOF
4025#include <png.h>
4026int main(void) {
4027#if PNG_LIBPNG_VER >= 10208
4028#else
4029  syntax error
4030#endif
4031  return 0;
4032}
4033EOF
4034	cc_check $PNG_CFLAGS $PNG_LIBS -lpng -lz && _png=yes
4035fi
4036if test "$_png" = yes ; then
4037	append_var LIBS "$PNG_LIBS -lpng -lz"
4038	append_var INCLUDES "$PNG_CFLAGS"
4039fi
4040define_in_config_if_yes "$_png" 'USE_PNG'
4041echo "$_png"
4042
4043#
4044# Check for Theora Decoder
4045#
4046echocheck "libtheoradec >= 1.0"
4047if test "$_vorbis" = no ; then
4048	echo "skipping. no vorbis"
4049	_theoradec=notsupported
4050fi
4051if test "$_theoradec" = auto ; then
4052	_theoradec=no
4053	cat > $TMPC << EOF
4054#include <theora/theoradec.h>
4055#include <vorbis/codec.h>
4056int main(void) { th_ycbcr_buffer yuv; th_decode_ycbcr_out(NULL, yuv);  }
4057EOF
4058	cc_check $THEORADEC_CFLAGS $THEORADEC_LIBS -ltheoradec && _theoradec=yes
4059fi
4060if test "$_theoradec" = yes ; then
4061	append_var LIBS "$THEORADEC_LIBS -ltheoradec"
4062	append_var INCLUDES "$THEORADEC_CFLAGS"
4063fi
4064define_in_config_if_yes "$_theoradec" 'USE_THEORADEC'
4065if test ! "$_theoradec" = notsupported ; then
4066	echo "$_theoradec"
4067fi
4068
4069#
4070# Check for the AAC decoder
4071#
4072echocheck "libfaad"
4073if test "$_faad" = auto ; then
4074	_faad=no
4075	cat > $TMPC << EOF
4076#include <neaacdec.h>
4077int main(void) { NeAACDecGetCapabilities(); return 0; }
4078EOF
4079	cc_check $FAAD_CFLAGS $FAAD_LIBS -lfaad && _faad=yes
4080fi
4081if test "$_faad" = yes ; then
4082	append_var LIBS "$FAAD_LIBS -lfaad"
4083	append_var INCLUDES "$FAAD_CFLAGS"
4084fi
4085define_in_config_if_yes "$_faad" 'USE_FAAD'
4086echo "$_faad"
4087
4088#
4089# Check for SEQ MIDI
4090#
4091echocheck "SEQ MIDI"
4092if test "$_seq_midi" = auto ; then
4093	# TODO: Test for /dev/sequencer presence? Or maybe just for /dev ?
4094	# For now, we just always enable it when "posix" mode is on (backends
4095	# that do not want it can disable it by setting _seq_midi=no).
4096	_seq_midi="$_posix"
4097fi
4098define_in_config_h_if_yes "$_seq_midi" 'USE_SEQ_MIDI'
4099echo "$_seq_midi"
4100
4101#
4102# Check for sndio
4103#
4104echocheck "sndio"
4105if test "$_sndio" = auto ; then
4106	_sndio=no
4107	cat > $TMPC << EOF
4108#include <sndio.h>
4109int main(void) { struct sio_par par; sio_initpar(&par); return 0; }
4110EOF
4111	cc_check $SNDIO_CFLAGS $SNDIO_LIBS -lsndio && _sndio=yes
4112fi
4113if test "$_sndio" = yes ; then
4114	append_var LIBS "$SNDIO_LIBS -lsndio"
4115	append_var INCLUDES "$SNDIO_CFLAGS"
4116fi
4117define_in_config_h_if_yes "$_sndio" 'USE_SNDIO'
4118echo "$_sndio"
4119
4120#
4121# Check for TiMidity(++)
4122#
4123echocheck "TiMidity"
4124if test "$_timidity" = auto ; then
4125	# TODO: Is there a good possibility of auto detecting whether we
4126	# should include TiMidity support? It can only be used on Unix
4127	# currently so we use that as "detection" for now.
4128	_timidity="$_posix"
4129fi
4130define_in_config_h_if_yes "$_timidity" 'USE_TIMIDITY'
4131echo "$_timidity"
4132
4133#
4134# Check for ZLib
4135#
4136echocheck "zlib"
4137if test "$_zlib" = auto ; then
4138	_zlib=no
4139	cat > $TMPC << EOF
4140#include <string.h>
4141#include <zlib.h>
4142int main(void) { return strcmp(ZLIB_VERSION, zlibVersion()); }
4143EOF
4144	cc_check $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes
4145fi
4146if test "$_zlib" = yes ; then
4147	append_var ZLIB_LIBS "-lz"
4148	append_var LIBS "$ZLIB_LIBS"
4149	append_var INCLUDES "$ZLIB_CFLAGS"
4150fi
4151define_in_config_if_yes "$_zlib" 'USE_ZLIB'
4152echo "$_zlib"
4153
4154#
4155# Check for LibMPEG2
4156#
4157echocheck "libmpeg2 >= 0.4.0"
4158if test "$_mpeg2" = auto ; then
4159	_mpeg2=no
4160	cat > $TMPC << EOF
4161typedef signed $type_1_byte int8_t;
4162typedef signed $type_2_byte int16_t;
4163typedef signed $type_4_byte int32_t;
4164
4165typedef unsigned $type_1_byte uint8_t;
4166typedef unsigned $type_2_byte uint16_t;
4167typedef unsigned $type_4_byte uint32_t;
4168
4169extern "C" {
4170#include <mpeg2dec/mpeg2.h>
4171}
4172
4173int main(void) {
4174	#if MPEG2_RELEASE < MPEG2_VERSION(0, 4, 0)
4175	#error libmpeg2 version too low
4176	#endif
4177
4178	/* mpeg2_state_t first appears in 0.4.0 */
4179	mpeg2_state_t state;
4180
4181	return 0;
4182}
4183EOF
4184
4185	if test -n "$_host"; then
4186		# don't execute while cross compiling
4187		cc_check $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && _mpeg2=yes
4188	else
4189		cc_check_no_clean $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && $TMPO$HOSTEXEEXT && _mpeg2=yes
4190		cc_check_clean
4191	fi
4192fi
4193if test "$_mpeg2" = yes ; then
4194	append_var INCLUDES "$MPEG2_CFLAGS"
4195	append_var LIBS "$MPEG2_LIBS -lmpeg2"
4196fi
4197define_in_config_if_yes "$_mpeg2" 'USE_MPEG2'
4198echo "$_mpeg2"
4199
4200#
4201# Check for Sparkle if updates support is enabled
4202#
4203#
4204# Check is NSDockTilePlugIn protocol is supported
4205#
4206case $_host_os in
4207	darwin*)
4208		echocheck "Sparkle"
4209		if test "$_updates" = no; then
4210			_sparkle=no
4211		else
4212			if test ! -z $_sparklepath ; then
4213				SPARKLE_CFLAGS="-F$_sparklepath"
4214				SPARKLE_LIBS="-F$_sparklepath"
4215			fi
4216			if test "$_sparkle" = auto ; then
4217				_sparkle=no
4218				cat > $TMPC << EOF
4219#include <Cocoa/Cocoa.h>
4220#include <Sparkle/Sparkle.h>
4221int main(void) { SUUpdater *updater = [SUUpdater sharedUpdater]; return 0; }
4222EOF
4223				cc_check $SPARKLE_CFLAGS $SPARKLE_LIBS -framework Sparkle -ObjC++ -lobjc && _sparkle=yes
4224			fi
4225			if test "$_sparkle" = yes ; then
4226				append_var LIBS "$SPARKLE_LIBS -framework Sparkle"
4227				append_var INCLUDES "$SPARKLE_CFLAGS"
4228			fi
4229			define_in_config_if_yes "$_sparkle" 'USE_SPARKLE'
4230		fi
4231		echo "$_sparkle"
4232	;;
4233	mingw*)
4234		echocheck "Sparkle"
4235		if test "$_updates" = no; then
4236			_sparkle=no
4237		else
4238			if test ! -z $_sparklepath ; then
4239				SPARKLE_CFLAGS="-I$_sparklepath/include"
4240				SPARKLE_LIBS="-L$_sparklepath/Release -L$_sparklepath/x64/Release"
4241			fi
4242			if test "$_sparkle" = auto ; then
4243				_sparkle=no
4244				cat > $TMPC << EOF
4245#include <winsparkle.h>
4246int main(void) { win_sparkle_get_update_check_interval(); return 0; }
4247EOF
4248				cc_check $SPARKLE_CFLAGS $SPARKLE_LIBS -lWinSparkle && _sparkle=yes
4249			fi
4250			if test "$_sparkle" = yes ; then
4251				append_var LIBS "$SPARKLE_LIBS -lWinSparkle"
4252				append_var INCLUDES "$SPARKLE_CFLAGS"
4253			fi
4254			define_in_config_if_yes "$_sparkle" 'USE_SPARKLE'
4255		fi
4256		echo "$_sparkle"
4257	;;
4258	*)
4259		_sparkle=no
4260	;;
4261esac
4262
4263#
4264# Check for libcurl to be present
4265#
4266if test "$_libcurl" != "no"; then
4267
4268	# Look for the curl-config script
4269	find_libcurlconfig
4270
4271	if test -z "$_libcurlconfig"; then
4272		_libcurl=no
4273	else
4274		LIBCURL_LIBS=`$_libcurlconfig --libs`
4275		LIBCURL_CFLAGS=`$_libcurlconfig --cflags`
4276
4277		case $_host_os in
4278			amigaos*)
4279				append_var LIBCURL_LIBS "-lpthread"
4280			;;
4281			psp2*)
4282				append_var LIBCURL_LIBS "-lssl -lcrypto"
4283			;;
4284		esac
4285
4286		if test "$_libcurl" = "auto"; then
4287			_libcurl=no
4288
4289			cat > $TMPC << EOF
4290			#include <curl/curl.h>
4291			int main(int argc, char *argv[]) {
4292				int x;
4293				curl_easy_setopt(NULL,CURLOPT_URL,NULL);
4294				x=CURL_ERROR_SIZE;
4295				x=CURLOPT_WRITEFUNCTION;
4296				x=CURLOPT_WRITEDATA;
4297				x=CURLOPT_ERRORBUFFER;
4298				x=CURLOPT_STDERR;
4299				x=CURLOPT_VERBOSE;
4300
4301				curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
4302				if (data->features & CURL_VERSION_SSL)
4303					return 0;
4304				return 1;
4305			}
4306EOF
4307
4308			cc_check_no_clean $LIBCURL_CFLAGS $LIBCURL_LIBS
4309			if test "$?" -eq 0; then
4310				if test -n "$_host"; then
4311					# In cross-compiling mode, we cannot run the result, assume SSL is available
4312					_libcurl=yes
4313				else
4314					$TMPO$HOSTEXEEXT
4315					if test "$?" -eq 0; then
4316						_libcurl=yes
4317					else
4318						_libcurl="no SSL support"
4319					fi
4320				fi
4321			fi
4322			cc_check_clean
4323		fi
4324
4325		if test "$_libcurl" = "yes"; then
4326			append_var LIBS "$LIBCURL_LIBS"
4327			append_var INCLUDES "$LIBCURL_CFLAGS"
4328		fi
4329	fi
4330
4331fi
4332
4333echocheck "libcurl"
4334echo "$_libcurl"
4335
4336define_in_config_if_yes "$_libcurl" "USE_LIBCURL"
4337
4338#
4339# Check whether to build cloud integration support
4340#
4341echo_n "Cloud integration... "
4342if test "$_cloud" = "no"; then
4343	echo "no"
4344else
4345	_cloud=no
4346	if test "$_sdlnet" = "yes"; then
4347		_cloud=yes
4348		echo_n "local"
4349	fi
4350	if test "$_libcurl" = "yes"; then
4351		if test "$_cloud" = "yes"; then echo_n ", "; fi
4352		_cloud=yes
4353		echo_n "servers"
4354	fi
4355	if test "$_cloud" = "no"; then
4356		echo_n "no"
4357	fi
4358	echo  # newline
4359fi
4360define_in_config_if_yes $_cloud 'USE_CLOUD'
4361
4362#
4363# Check is NSDockTilePlugIn protocol is supported
4364#
4365case $_host_os in
4366	darwin*)
4367		# NSDockTilePlugIn was added in OS X 10.6, so will not be available when compiling on older OS X versions.
4368		echocheck "DockTilePlugin"
4369		if test "$_osxdockplugin" = auto ; then
4370			_osxdockplugin=no
4371			cat > $TMPC << EOF
4372#include <Cocoa/Cocoa.h>
4373@interface ScummVMDockTilePlugIn : NSObject <NSDockTilePlugIn> {
4374}
4375@end
4376EOF
4377			cc_check -c -ObjC++ && _osxdockplugin=yes
4378		fi
4379		define_in_config_if_yes "$_osxdockplugin" 'USE_DOCKTILEPLUGIN'
4380		echo "$_osxdockplugin"
4381	;;
4382	*)
4383		_osxdockplugin=no
4384	;;
4385esac
4386
4387#
4388# Check for FluidSynth
4389#
4390echocheck "FluidSynth"
4391
4392append_var FLUIDSYNTH_LIBS "-lfluidsynth"
4393case $_host_os in
4394	mingw*)
4395		FLUIDSYNTH_STATIC_LIBS="$FLUIDSYNTH_LIBS -lglib-2.0 -lintl -liconv -lws2_32 -lole32 -lshlwapi -lpcre -ldsound -lwinmm"
4396	;;
4397
4398	darwin*)
4399		FLUIDSYNTH_STATIC_LIBS="$FLUIDSYNTH_LIBS -framework Foundation -framework CoreMIDI -framework CoreAudio -lglib-2.0 -lintl -liconv -lreadline"
4400	;;
4401
4402	iphone)
4403		FLUIDSYNTH_STATIC_LIBS="$FLUIDSYNTH_LIBS -framework Foundation -framework CoreMIDI -lglib-2.0 -lintl -liconv"
4404	;;
4405
4406	*)
4407		FLUIDSYNTH_STATIC_LIBS="$FLUIDSYNTH_LIBS -lglib-2.0 -lintl -liconv"
4408	;;
4409esac
4410
4411if test "$_fluidsynth" = auto; then
4412	_fluidsynth=no
4413	cat > $TMPC << EOF
4414#include <fluidsynth.h>
4415int main(void) { delete_fluid_settings(new_fluid_settings()); return 0; }
4416EOF
4417	cc_check_no_clean $FLUIDSYNTH_CFLAGS $FLUIDSYNTH_LIBS && _fluidsynth=yes
4418	if test "$_fluidsynth" != yes; then
4419		FLUIDSYNTH_LIBS="$FLUIDSYNTH_STATIC_LIBS"
4420		cc_check_no_clean $FLUIDSYNTH_CFLAGS $FLUIDSYNTH_LIBS && _fluidsynth=yes
4421	fi
4422	cc_check_clean
4423fi
4424if test "$_fluidsynth" = yes; then
4425	append_var LIBS "$FLUIDSYNTH_LIBS"
4426	append_var INCLUDES "$FLUIDSYNTH_CFLAGS"
4427fi
4428define_in_config_if_yes "$_fluidsynth" 'USE_FLUIDSYNTH'
4429echo "$_fluidsynth"
4430
4431#
4432# Check for readline if text_console is enabled
4433#
4434echocheck "readline"
4435if test "$_text_console" = yes ; then
4436	_READLINE_LIBS="-lreadline"
4437	if test "$_readline" = auto ; then
4438		_readline=no
4439		cat > $TMPC << EOF
4440#include <stdio.h>
4441#include <readline/readline.h>
4442#include <readline/history.h>
4443
4444int main(void) {
4445	char *x = readline("");
4446}
4447EOF
4448		cc_check_no_clean $READLINE_CFLAGS $READLINE_LIBS $_READLINE_LIBS && _readline=yes
4449		if test "$_readline" = no ; then
4450			_READLINE_LIBS="-lreadline -ltermcap"
4451			cc_check_no_clean $READLINE_CFLAGS $READLINE_LIBS $_READLINE_LIBS && _readline=yes
4452		fi
4453	fi
4454	cc_check_clean
4455	echo "$_readline"
4456else
4457	_readline=no
4458	echo "skipping (text console disabled)"
4459fi
4460
4461if test "$_readline" = yes ; then
4462	append_var LIBS "$READLINE_LIBS $_READLINE_LIBS"
4463	append_var INCLUDES "$READLINE_CFLAGS"
4464
4465	#
4466	# Check the type of rl_completion_entry_function.
4467	# It can be int(*)(const char *, int) or char *(*)(const char *, int).
4468	#
4469	cat > $TMPC << EOF
4470#include <stdio.h>
4471#include <readline/readline.h>
4472#include <readline/history.h>
4473
4474int readline_completionFunction(const char *, int);
4475
4476int main(void) {
4477	char *x = readline("");
4478	rl_completion_entry_function = &readline_completionFunction;
4479}
4480EOF
4481	cc_check -c && add_line_to_config_h '#define USE_READLINE_INT_COMPLETION'
4482
4483fi
4484define_in_config_h_if_yes "$_readline" 'USE_READLINE'
4485
4486define_in_config_h_if_yes "$_text_console" 'USE_TEXT_CONSOLE_FOR_DEBUGGER'
4487
4488#
4489# Check for Unity if taskbar integration is enabled
4490#
4491echocheck "libunity"
4492if test "$_unix" = no || test "$_taskbar" = no; then
4493	_libunity=no
4494else
4495if test "$_libunity" = auto ; then
4496	case $_host_os in
4497		mingw*)
4498			# pkgconfig and unity are not supported on mingw
4499			_libunity=no
4500			;;
4501		*)
4502			# Unity has a lots of dependencies, update the libs and cflags var with them
4503			LIBUNITY_LIBS="$LIBUNITY_LIBS `pkg-config --libs 'unity > 3.8.1' 2>> "$TMPLOG"`"
4504			LIBUNITY_CFLAGS="$LIBUNITY_CFLAGS `pkg-config --cflags 'unity > 3.8.1' 2>> "$TMPLOG"`"
4505			_libunity=no
4506			cat > $TMPC << EOF
4507#include <unity.h>
4508int main(void) {
4509	unity_launcher_entry_get_for_desktop_id("residualvm.desktop");
4510	return 0;
4511}
4512EOF
4513			cc_check $LIBUNITY_CFLAGS $LIBUNITY_LIBS && _libunity=yes
4514			;;
4515	esac
4516fi
4517if test "$_libunity" = yes ; then
4518	if test "$LIBUNITY_CFLAGS" = "" || test "$LIBUNITY_LIBS" = ""; then
4519		LIBUNITY_LIBS="$LIBUNITY_LIBS `pkg-config --libs 'unity > 3.8.1' 2>> "$TMPLOG"`"
4520		LIBUNITY_CFLAGS="$LIBUNITY_CFLAGS `pkg-config --cflags 'unity > 3.8.1' 2>> "$TMPLOG"`"
4521	fi
4522	append_var LIBS "$LIBUNITY_LIBS"
4523	append_var INCLUDES "$LIBUNITY_CFLAGS"
4524fi
4525define_in_config_h_if_yes "$_libunity" 'USE_UNITY'
4526fi
4527echo "$_libunity"
4528
4529#
4530# Check for FreeType2 to be present
4531#
4532if test "$_freetype2" != "no"; then
4533
4534	# Look for the freetype-config script
4535	find_freetypeconfig
4536
4537	if test -z "$_freetypeconfig"; then
4538		_freetype2=no
4539	else
4540		FREETYPE2_LIBS=`$_freetypeconfig --prefix="$_freetypepath" --libs`
4541		FREETYPE2_CFLAGS=`$_freetypeconfig --prefix="$_freetypepath" --cflags`
4542
4543		if test "$_freetype2" = "auto"; then
4544			_freetype2=no
4545
4546			cat > $TMPC << EOF
4547#include <ft2build.h>
4548#include FT_FREETYPE_H
4549
4550int main(int argc, char *argv[]) {
4551	FT_Library library;
4552	FT_Error error = FT_Init_FreeType(&library);
4553	FT_Done_FreeType(library);
4554}
4555EOF
4556
4557			cc_check_no_clean $FREETYPE2_CFLAGS $FREETYPE2_LIBS && _freetype2=yes
4558			# Modern freetype-config scripts accept --static to get all
4559			# required flags for static linking. We abuse this to detect
4560			# FreeType2 builds which are static themselves.
4561			if test "$_freetype2" != "yes"; then
4562				FREETYPE2_LIBS=`$_freetypeconfig --prefix="$_freetypepath" --static --libs 2>/dev/null`
4563				cc_check_no_clean $FREETYPE2_CFLAGS $FREETYPE2_LIBS && _freetype2=yes
4564			fi
4565			cc_check_clean
4566		fi
4567
4568		if test "$_freetype2" = "yes"; then
4569			append_var LIBS "$FREETYPE2_LIBS"
4570			append_var INCLUDES "$FREETYPE2_CFLAGS"
4571		fi
4572	fi
4573
4574fi
4575
4576echocheck "FreeType2"
4577echo "$_freetype2"
4578
4579define_in_config_if_yes "$_freetype2" "USE_FREETYPE2"
4580
4581
4582# ResidualVM specific start ->
4583#
4584# Check for GLEW
4585#
4586echocheck "GL Extension Wrangler (GLEW)"
4587if test "$_glew" != "no" && test "$_opengl" = "no"; then
4588	_glew=no
4589	echo "cannot use GLEW without OpenGL"
4590elif test "$_glew" != "no" && test "$_opengles2" = "yes"; then
4591	_glew=no
4592	echo "not needed with OpenGL ES v2"
4593else
4594
4595	case $_host_os in
4596	darwin*)
4597		_GLEW_LIBS="-lGLEW"
4598		;;
4599	mingw*)
4600		_GLEW_CFLAGS="-DGLEW_STATIC"
4601		_GLEW_LIBS="-lglu32 -lglew32 -lopengl32"
4602		;;
4603	*)
4604		_GLEW_LIBS="-lGLU -lGLEW"
4605		;;
4606	esac
4607
4608	if test "$_glew" = auto; then
4609		_glew=no
4610		cat > $TMPC << EOF
4611#include <GL/glew.h>
4612int main(void) {
4613	glewInit();
4614	return 0;
4615}
4616EOF
4617		cc_check $DEFINES $GLEW_CFLAGS $_GLEW_CFLAGS $GLEW_LIBS $_GLEW_LIBS && _glew=yes
4618	fi
4619
4620	if test "$_glew" = yes ; then
4621		append_var LIBS "$GLEW_LIBS $_GLEW_LIBS"
4622		append_var INCLUDES "$GLEW_CFLAGS $_GLEW_CFLAGS"
4623	fi
4624
4625	echo "$_glew"
4626fi
4627
4628define_in_config_if_yes "$_glew" "USE_GLEW"
4629
4630
4631#
4632# Check for OpenGL (ES)
4633#
4634echocheck "OpenGL"
4635
4636case $_backend in
4637	openpandora)
4638		# Only enable OpenGL ES on the OpanPandora if --enable-opengl is passed in explicitly.
4639		if test "$_opengl" = yes ; then
4640			_opengl=yes
4641			_opengles=yes
4642			OPENGL_LIBS="-lGLES_CM -lEGL -lX11"
4643			OPENGL_CFLAGS="$OPENGL_LIBS"
4644			append_var LIBS "$OPENGL_LIBS"
4645			append_var INCLUDES "$OPENGL_CFLAGS"
4646		fi
4647		;;
4648esac
4649
4650if test "$_opengl" = auto ; then
4651	_opengl=no
4652	if test "$_backend" = "sdl" || test "$_backend" = "android"; then
4653		# Try different header filenames
4654		# 1) GL/gl.h         This is usually used on POSIX and Windows systems
4655		# 2) OpenGL/gl.h     This is used on Mac OS X
4656		# 3) GLES2/gl2.h     This is used for OpenGL ES 2.x
4657		# 4) GLES/gl.h       This is used for OpenGL ES 1.x
4658		for i in "GL/gl.h" "OpenGL/gl.h" "GLES2/gl2.h" "GLES/gl.h"; do
4659			# Test the current header for OpenGL
4660			if test "$_opengles2" = no ; then
4661				cat > $TMPC << EOF
4662#include <$i>
4663#include <stdio.h>
4664int main(void) { printf("ANTIVIRUS FALSE POSITIVE WORKAROUND"); return GL_VERSION_1_1; }
4665EOF
4666				cc_check $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS && _opengl=yes && break
4667			fi
4668
4669			# Test the current header for OpenGL ES2
4670			cat > $TMPC << EOF
4671#include <$i>
4672int main(void) { return GL_ES_VERSION_2_0; }
4673EOF
4674			cc_check $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS && _opengl=yes && _opengles2=yes && break
4675
4676			# Test the current header for OpenGL ES
4677			if test "$_opengles2" = no ; then
4678				cat > $TMPC << EOF
4679#include <$i>
4680int main(void) { return GL_OES_VERSION_1_1; }
4681EOF
4682				cc_check $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS && _opengl=yes && _opengles=yes && break
4683			fi
4684		done
4685	fi
4686fi
4687if test "$_opengl" = yes ; then
4688	# Our simple test case
4689	cat > $TMPC << EOF
4690int main(void) { return 0; }
4691EOF
4692
4693	_opengl=no
4694	# Try different library names
4695	if test "$_opengles" = "yes" ; then
4696		# 1) GLES_CM    This is usually used for OpenGL ES 1.1 (Common profile)
4697		# 2) GLESv1_CM  This is used by the Windows Mali OpenGL ES 1.1 Emulator
4698		# 3) glesv1     This is used by the Linux Mali OpenGL ES 1.1 Emulator
4699		_opengles=no
4700		for lib in "-lGLES_CM" "-lGLESv1_CM" "-lglesv1"; do
4701			if cc_check_no_clean $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS $lib
4702				then
4703				_opengl=yes
4704				_opengles=yes
4705				append_var OPENGL_LIBS "$lib"
4706				break
4707			fi
4708		done
4709	elif test "$_opengles2" = yes ; then
4710		_opengles2=no
4711		if cc_check_no_clean $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS "-lGLESv2"
4712			then
4713			_opengl=yes
4714			_opengles2=yes
4715			append_var OPENGL_LIBS "-lGLESv2"
4716		fi
4717	else
4718		case $_host_os in
4719		darwin*)
4720			OPENGL_LIBS="-framework OpenGL"
4721			;;
4722		mingw*)
4723			OPENGL_LIBS="-lopengl32"
4724			;;
4725		*)
4726			OPENGL_LIBS="-lGL"
4727			;;
4728		esac
4729		if cc_check_no_clean $DEFINES $OPENGL_CFLAGS $OPENGL_LIBS
4730			then
4731			_opengl=yes
4732		fi
4733	fi
4734
4735	if test "$_opengl" = yes ; then
4736		append_var LIBS "$OPENGL_LIBS"
4737		append_var INCLUDES "$OPENGL_CFLAGS"
4738		if test "$_opengl_shaders" = auto; then
4739			_opengl_shaders=$_glew
4740		fi
4741		if test "$_opengl_shaders" = yes && test "$_opengles2" = no && test "$_glew" = no; then
4742			echo "WARNING: OpenGL Shader support requires GLEW!"
4743			_opengl_shaders=no
4744		fi
4745	else
4746		_opengl_shaders=no
4747	fi
4748	cc_check_clean
4749fi
4750
4751
4752if test "$_opengles" = "yes" ; then
4753	echo "yes (OpenGL ES)"
4754elif test "$_opengles2" = "yes" ; then
4755	echo "yes (OpenGL ES2)"
4756else
4757	if test "$_opengl_shaders" = "yes" ; then
4758		echo "$_opengl (shaders enabled)"
4759	elif test "$_opengl" = "yes" ; then
4760		echo "$_opengl (shaders disabled)"
4761	else
4762		echo "no"
4763	fi
4764fi
4765
4766define_in_config_if_yes "$_opengl" "USE_OPENGL"
4767define_in_config_if_yes "$_opengles" "USE_GLES"
4768define_in_config_if_yes "$_opengles2" "USE_GLES2"
4769define_in_config_if_yes "$_opengl_shaders" "USE_OPENGL_SHADERS"
4770
4771#
4772# Check for iconv
4773#
4774echo_n "Checking whether iconv.h is present... "
4775if test "$_iconv" = auto ; then
4776	_iconv=no
4777	cat > $TMPC << EOF
4778#include <iconv.h>
4779int main(int, char **) {
4780	return 0;
4781}
4782EOF
4783	cc_check $ICONV_CFLAGS $ICONV_LIBS && _iconv=yes
4784fi
4785
4786create_iconv_test() {
4787	cat > $TMPC << EOF
4788#include <iconv.h>
4789int main(int, char **) {
4790	iconv_t iconv = iconv_open("UTF-32", "SJIS");
4791	iconv_close(iconv);
4792	return 0;
4793}
4794EOF
4795}
4796echo "$_iconv"
4797
4798if test "$_iconv" = yes ; then
4799	echo_n "Checking whether iconv needs linking against libiconv... "
4800
4801	needs_iconvlib='auto'
4802	create_iconv_test
4803	cc_check $ICONV_CFLAGS $ICONV_LIBS -liconv && needs_iconvlib='yes'
4804	# We do check linking without -liconv here too, just in case
4805	# it would fail otherwise too
4806	create_iconv_test
4807	cc_check $ICONV_CFLAGS $ICONV_LIBS && needs_iconvlib='no'
4808
4809	if test "$needs_iconvlib" = auto ; then
4810		_iconv=no
4811		echo "does not link at all"
4812	else
4813		if test "$needs_iconvlib" = yes ; then
4814			append_var ICONV_LIBS "-liconv"
4815		fi
4816		echo "$needs_iconvlib"
4817
4818		echo_n "Checking signature of iconv... "
4819		uses_const=no
4820
4821		cat > $TMPC << EOF
4822#include <iconv.h>
4823int main(int argc, char **argv) {
4824	iconv_t iconvP;
4825	const char **inbuf = 0;
4826	iconv(iconvP, inbuf, 0, 0, 0);
4827	return 0;
4828}
4829EOF
4830		cc_check $ICONV_CFLAGS $ICONV_LIBS && uses_const=yes
4831
4832		if test "$uses_const" = yes ; then
4833			echo "iconv_t, const char **, size_t *, char **, size_t *"
4834		else
4835			echo "iconv_t, char **, size_t *, char **, size_t *"
4836		fi
4837
4838		define_in_config_if_yes "$uses_const" 'ICONV_USES_CONST'
4839	fi
4840fi
4841
4842if test "$_iconv" = yes ; then
4843	append_var LIBS "$ICONV_LIBS"
4844	append_var INCLUDES "$ICONV_CFLAGS"
4845fi
4846
4847echocheck "iconv"
4848define_in_config_if_yes "$_iconv" 'USE_ICONV'
4849echo "$_iconv"
4850# ResidualVM specific ends here <-
4851
4852
4853#
4854# Check for Linux CD-ROM support
4855#
4856case $_host_os in
4857	*linux*)
4858		echocheck "Linux CD-ROM"
4859		linuxcd=no
4860		cat > $TMPC << EOF
4861#include <linux/cdrom.h>
4862#include <sys/types.h>
4863int main(void) {
4864	int x = CDROMREADAUDIO;
4865	dev_t dev;
4866	return major(dev) + x;
4867}
4868EOF
4869		cc_check && linuxcd=yes
4870		define_in_config_if_yes "$linuxcd" 'USE_LINUXCD'
4871		echo "$linuxcd"
4872		;;
4873esac
4874
4875
4876#
4877# Check for nasm
4878#
4879if test "$_have_x86" = yes ; then
4880	echocheck "nasm"
4881	if test "$_nasm" = no ; then
4882		echo "disabled"
4883	else
4884		IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=$SEPARATOR
4885
4886		for path_dir in $_nasmpath; do
4887			if test -x "$path_dir/nasm$NATIVEEXEEXT" ; then
4888				NASM="$path_dir/nasm$NATIVEEXEEXT"
4889				NASMFLAGS="-O1 -g"
4890				echo $NASM
4891				break
4892			fi
4893		done
4894
4895		# fallback to the nasm compatible yasm
4896		if test x$NASM = x -o x$NASM = x'"$NASM"'; then
4897			for path_dir in $_nasmpath; do
4898				if test -x "$path_dir/yasm$NATIVEEXEEXT" ; then
4899					NASM="$path_dir/yasm$NATIVEEXEEXT"
4900					NASMFLAGS="-a x86 -m x86"
4901					echo $NASM
4902					break
4903				fi
4904			done
4905		fi
4906
4907		IFS="$ac_save_ifs"
4908
4909		if test x$NASM = x -o x$NASM = x'"$NASM"'; then
4910			echo "not found"
4911			_nasm=no
4912		else
4913			case $_host_os in
4914				darwin*)
4915					append_var NASMFLAGS "-f macho"
4916				;;
4917				mingw*)
4918					append_var NASMFLAGS "-f win32"
4919				;;
4920				os2-emx*)
4921					append_var NASMFLAGS "-f aout"
4922				;;
4923				*)
4924					append_var NASMFLAGS "-f elf"
4925				;;
4926			esac
4927			_nasm=yes
4928		fi
4929	fi
4930fi
4931
4932define_in_config_if_yes $_nasm 'USE_NASM'
4933
4934#
4935# Enable vkeybd / keymapper / event recorder
4936#
4937define_in_config_if_yes $_vkeybd 'ENABLE_VKEYBD'
4938define_in_config_if_yes $_keymapper 'ENABLE_KEYMAPPER'
4939define_in_config_if_yes $_eventrec 'ENABLE_EVENTRECORDER'
4940
4941#
4942# Check if the keymapper and the event recorder are enabled simultaneously
4943#
4944if test "$_keymapper" = yes ; then
4945	if test "$_eventrec" = yes ; then
4946		echo "ERROR: The keymapper and the event recorder cannot be enabled simultaneously currently, please disable one of the two"
4947		exit 1
4948	fi
4949fi
4950
4951# Check whether to build translation support
4952#
4953echo_n "Building translation support... "
4954define_in_config_if_yes $_translation 'USE_TRANSLATION'
4955if test "$_translation" = no ; then
4956	echo "no"
4957else
4958	echo_n "yes ("
4959
4960	if test "$_detectlang" != yes ; then
4961		cat > $TMPC << EOF
4962#include <locale.h>
4963int main(void) { setlocale(LC_ALL, ""); return 0; }
4964EOF
4965		_detectlang=no
4966		cc_check $LDFLAGS $CXXFLAGS && _detectlang=yes
4967	fi
4968
4969	define_in_config_h_if_yes $_detectlang 'USE_DETECTLANG'
4970	if test "$_detectlang" = yes ; then
4971		echo "with runtime language detection)"
4972	else
4973		echo "without runtime language detection)"
4974	fi
4975fi
4976
4977#
4978# Check whether to build taskbar integration support
4979#
4980echo_n "Building taskbar integration support... "
4981if test "$_taskbar" = "no"; then
4982	echo "no"
4983else
4984	case $_host_os in
4985	mingw*)
4986		append_var LIBS "-lole32 -luuid"
4987		echo "win32"
4988		_taskbar=yes
4989		;;
4990	darwin*)
4991		echo "osx"
4992		_taskbar=yes
4993		;;
4994	*)
4995		if test "$_libunity" = yes; then
4996			echo "unity"
4997			_taskbar=yes
4998		else
4999			echo "no"
5000			_taskbar=no
5001		fi
5002		;;
5003	esac
5004fi
5005define_in_config_if_yes $_taskbar 'USE_TASKBAR'
5006
5007#
5008# Check whether to build Bink video support
5009#
5010echo_n "Building Bink video support... "
5011define_in_config_if_yes $_bink 'USE_BINK'
5012echo "$_bink"
5013
5014#
5015# Check whether to build updates support
5016#
5017echo_n "Building updates support... "
5018define_in_config_if_yes $_updates 'USE_UPDATES'
5019if test "$_updates" = yes; then
5020	if test "$_sparkle" = yes; then
5021		echo "Sparkle"
5022	else
5023		echo "$_updates"
5024	fi
5025else
5026	echo "$_updates"
5027fi
5028
5029#
5030# Check whether to activate engines (ResidualVM specific)
5031#
5032if test `get_engine_build monkey4` = yes && test ! "$_mpeg2" = yes ; then
5033	echo "...disabling support for video cutscenes in PS2 version of Escape from Monkey Island. mpeg2dec is required"
5034fi
5035
5036if test `get_engine_build monkey4` = yes && test ! "$_bink" = yes ; then
5037	echo "...disabling Escape from Monkey Island. bink is required"
5038	engine_disable monkey4
5039fi
5040
5041if test `get_engine_build myst3` = yes && test ! "$_bink" = yes ; then
5042	echo "...disabling Myst 3 engine. bink is required"
5043	engine_disable myst3
5044fi
5045
5046if test `get_engine_build stark` = yes && test ! "$_opengl_shaders" = yes ; then
5047	echo "...disabling STARK engine. OpenGL with shaders is required"
5048	engine_disable stark
5049fi
5050
5051#
5052# Figure out installation directories
5053#
5054test "x$prefix" = xNONE && prefix=/usr/local
5055test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
5056
5057case $_host_os in
5058	mingw*)
5059		# Windows stores all the external data files in executable file.
5060		;;
5061	*)
5062		append_var DEFINES "-DDATA_PATH=\\\"$datadir\\\""
5063		;;
5064esac
5065
5066case $_backend in
5067	openpandora)
5068		# Add ../plugins as a path so plugins can be found when running from a .PND.
5069		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"../plugins\\\""
5070		;;
5071	maemo | webos)
5072		# The WebOS and Maemo apps want the plugins in the "lib" directory
5073		# without a scummvm sub directory.
5074		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"$libdir\\\""
5075		;;
5076	ps2)
5077		# PS2 bogus dir: it actually depends on launch medium
5078		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"host:plugins\\\""
5079		;;
5080	*)
5081		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"$libdir/residualvm\\\""
5082		;;
5083esac
5084
5085#
5086# Set variables for profiling.
5087# We need to do it here to prevent mess-ups with the tests e.g. on the PSP
5088#
5089if test "$_enable_prof" = yes ; then
5090	append_var CXXFLAGS "-pg"
5091	append_var LDFLAGS "-pg"
5092	append_var DEFINES "-DENABLE_PROFILING"
5093fi
5094
5095echo_n "Backend... "
5096echo_n "$_backend"
5097
5098if test "$_backend" = "sdl" -a -n "$_sdlversion"; then
5099	echo_n " ($_sdlversion)"
5100fi
5101
5102if test "$_nasm" = yes ; then
5103	echo_n ", assembly routines"
5104fi
5105
5106if test "$_16bit" = yes ; then
5107	: # residualvm not use it
5108fi
5109
5110if test "$_highres" = yes ; then
5111	: # residualvm not use it
5112fi
5113
5114if test "$_savegame_timestamp" = yes ; then
5115	echo_n ", savegame timestamp"
5116fi
5117
5118if test "$_build_scalers" = yes ; then
5119	if test "$_build_hq_scalers" = yes ; then
5120		: # residualvm not use it
5121	else
5122		: # residualvm not use it
5123	fi
5124fi
5125
5126if test "$_mt32emu" = yes ; then
5127	echo_n ", MT-32 emulator"
5128fi
5129
5130if test "$_text_console" = yes ; then
5131	echo_n ", text console"
5132fi
5133
5134if test "$_vkeybd" = yes ; then
5135	echo_n ", virtual keyboard"
5136fi
5137
5138if test "$_keymapper" = yes ; then
5139	echo_n ", keymapper"
5140fi
5141
5142if test "$_eventrec" = yes ; then
5143	echo_n ", event recorder"
5144fi
5145
5146if test "$_cloud" = yes ; then
5147	echo ", cloud"
5148else
5149	echo
5150fi
5151
5152#
5153# Some last-minute backend specific stuff, executed
5154# after all of CXXFLAGS, LDFLAGS, LIBS etc. have been setup
5155#
5156case $_backend in
5157	3ds)
5158		if test "$_freetype2" = yes -a "$_png" = yes; then
5159			append_var LIBS "-lpng"
5160		fi
5161		if test "$_tremor" = yes -o "$_flac" = yes; then
5162			append_var LIBS "-logg"
5163		fi
5164		;;
5165	android)
5166		# ssp at this point so the cxxtests link
5167		if test "$_debug_build" = yes; then
5168			append_var CXXFLAGS "-fstack-protector"
5169		else
5170			append_var CXXFLAGS "-fno-stack-protector"
5171		fi
5172
5173		static_libs=''
5174		system_libs=''
5175		for lib in $LIBS; do
5176			case $lib in
5177			-lz|-lm|-ldl|-landroid|-lGLESv1_CM|-lGLESv2) # ResidualVM specific
5178				system_libs="$system_libs $lib"
5179				;;
5180			*)
5181				static_libs="$static_libs $lib"
5182				;;
5183			esac
5184		done
5185
5186		# -lgcc is carefully placed here - we want to catch
5187		# all toolchain symbols in *our* libraries rather
5188		# than pick up anything unhygenic from the Android libs.
5189		LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -landroid" # ResidualVM removed: -lGLESv1_CM
5190		;;
5191	n64)
5192		# Move some libs down here, otherwise some symbols requires by libvorbis aren't found
5193		# during linking stage
5194		append_var LIBS "-lc -lgcc -lnosys"
5195		;;
5196esac
5197
5198
5199#
5200# Engine selection
5201#
5202_engines_built_static=""
5203_engines_built_dynamic=""
5204_engines_skipped=""
5205
5206# Show a message if looping over engines takes longer than 5 secs
5207sh -c "
5208	touch config.gnomes
5209	sleep 5
5210	if test -f config.gnomes; then
5211		printf 'Employing little gnomes...'
5212		rm -f config.gnomes
5213	fi" 2>/dev/null &
5214
5215for engine in $_engines; do
5216	# Check whether all dependencies are available
5217	check_engine_deps $engine
5218
5219	if test "`get_engine_sub $engine`" = "no" ; then
5220		# It's a main engine
5221		if test `get_engine_build $engine` = no ; then
5222			isbuilt=no
5223		else
5224			# If dynamic plugins aren't supported, mark
5225			# all the engines as static
5226			if test $_dynamic_modules = no ; then
5227				set_var _engine_${engine}_build "static"
5228			else
5229				# If it wasn't explicitly marked as static or
5230				# dynamic, use the configured default
5231				if test `get_engine_build $engine` = yes ; then
5232					set_var _engine_${engine}_build "${_plugins_default}"
5233				fi
5234			fi
5235
5236			# Prepare the defines
5237			if test `get_engine_build $engine` = dynamic ; then
5238				isbuilt=DYNAMIC_PLUGIN
5239			else
5240				set_var _engine_${engine}_build "static"
5241				isbuilt=STATIC_PLUGIN
5242			fi
5243		fi
5244	else
5245		# It's a subengine, just say yes or no
5246		if test "`get_engine_build $engine`" = "no" ; then
5247			isbuilt=no
5248		else
5249			isbuilt=1
5250		fi
5251	fi
5252
5253	# Save the settings
5254	defname="ENABLE_`echo $engine | tr '[a-z]' '[A-Z]'`"
5255	if test "$isbuilt" = "no" ; then
5256		add_line_to_config_mk "# $defname"
5257	else
5258		add_line_to_config_mk "$defname = $isbuilt"
5259	fi
5260done
5261
5262# Sort engines to place our headline engine at start...
5263# No technical reason, just historical convention
5264headline_engine=grim
5265_sorted_engines="${headline_engine}"
5266for engine in $_engines; do
5267	if test "${engine}" != "${headline_engine}" ; then
5268		_sorted_engines="${_sorted_engines} ${engine}"
5269	fi
5270done
5271
5272# Prepare the information to be shown
5273for engine in $_sorted_engines; do
5274	if test "`get_engine_sub $engine`" = "no" ; then
5275		# It's a main engine
5276		prepare_engine_build_strings $engine
5277	fi
5278done
5279
5280#
5281# Detection of WIP/unstable engines
5282#
5283for engine in $_engines; do
5284	engine_build=`get_engine_build $engine`
5285	engine_build_default=`get_engine_build_default $engine`
5286	if test $engine_build != no -a $engine_build_default = no ; then
5287		set_var _tainted_build "yes"
5288	fi
5289done
5290
5291add_to_config_h_if_yes `get_var _tainted_build` '#define TAINTED_BUILD'
5292
5293# Complete the message on slow systems
5294if test -f config.gnomes ; then
5295	# Kill does not work well here as it produces nasty 'Killed' message
5296	rm -rf config.gnomes
5297else
5298	echo " work is done"
5299fi
5300
5301#
5302# Show which engines ("frontends") are to be built
5303#
5304echo
5305if test -n "$_engines_built_static" ; then
5306	echo "Engines (builtin):"
5307	echo "$_engines_built_static" | sed 's/@/\
5308/g
5309s/#/    /g'
5310fi
5311
5312if test -n "$_engines_built_dynamic" ; then
5313	echo "Engines (plugins):"
5314	echo "$_engines_built_dynamic" | sed 's/@/\
5315/g
5316s/#/    /g'
5317fi
5318
5319if test -n "$_engines_skipped" ; then
5320	echo "Engines Skipped:"
5321	echo "$_engines_skipped" | sed 's/@/\
5322/g
5323s/#/    /g'
5324fi
5325
5326if test -n "$_engines_built_wip" ; then
5327	echo "WARNING: This ResidualVM build contains the following UNSTABLE engines:"
5328	echo "$_engines_built_wip" | sed 's/@/\
5329/g
5330s/#/    /g'
5331fi
5332
5333echo
5334echo "Creating config.h"
5335cat > config.h << EOF
5336/* This file is automatically generated by configure */
5337/* DO NOT EDIT MANUALLY */
5338
5339#ifndef CONFIG_H
5340#define CONFIG_H
5341
5342$_config_h_data
5343
5344/* Data types */
5345typedef unsigned $type_1_byte byte;
5346typedef unsigned int uint;
5347typedef unsigned $type_1_byte uint8;
5348typedef unsigned $type_2_byte uint16;
5349typedef unsigned $type_4_byte uint32;
5350typedef signed $type_1_byte int8;
5351typedef signed $type_2_byte int16;
5352typedef signed $type_4_byte int32;
5353EOF
5354
5355if test -n "$_def_64bit_type_unsigned"  ; then
5356cat >> config.h << EOF
5357
5358/* 64-bit stuff */
5359$_def_64bit_type_signed
5360#if defined(__APPLE__) && !defined(__ppc__)
5361#ifndef _UINT64
5362#define _UINT64
5363$_def_64bit_type_unsigned
5364#endif
5365#else
5366$_def_64bit_type_unsigned
5367#endif
5368#define HAVE_INT64
5369EOF
5370fi
5371
5372cat >> config.h << EOF
5373
5374#endif /* CONFIG_H */
5375EOF
5376
5377echo "Creating config.mk"
5378cat > config.mk << EOF
5379# -------- Generated by configure -----------
5380
5381CXX := $CXX
5382CXXFLAGS := $CXXFLAGS
5383LD := $LD
5384LIBS += $LIBS
5385RANLIB := $_ranlib
5386STRIP := $_strip
5387AR := $_ar
5388AS := $_as
5389ASFLAGS := $ASFLAGS
5390WINDRES := $_windres
5391WINDRESFLAGS := $WINDRESFLAGS
5392STAGINGPATH=$_stagingpath
5393WIN32PATH=$_win32path
5394AMIGAOSPATH=$_amigaospath
5395STATICLIBPATH=$_staticlibpath
5396XCODETOOLSPATH=$_xcodetoolspath
5397SPARKLEPATH=$_sparklepath
5398SDLCONFIG=$_sdlconfig
5399
5400ABI := $ABI
5401
5402BACKEND := $_backend
5403MODULES += $MODULES
5404MODULE_DIRS += $MODULE_DIRS
5405EXEPRE := $HOSTEXEPRE
5406EXEEXT := $HOSTEXEEXT
5407NASM := $NASM
5408NASMFLAGS := $NASMFLAGS
5409ZLIB_LIBS := $ZLIB_LIBS
5410ZLIB_CFLAGS := $ZLIB_CFLAGS
5411
5412prefix = $prefix
5413exec_prefix = $exec_prefix
5414bindir = $bindir
5415libdir = $libdir
5416datarootdir = $datarootdir
5417datadir = $datadir
5418mandir = $mandir
5419docdir = $docdir
5420
5421$_config_mk_data
5422
5423INCLUDES += $INCLUDES
5424OBJS += $OBJS
5425DEFINES += $DEFINES
5426LDFLAGS += $LDFLAGS
5427
5428$_mak_plugins
5429
5430port_mk = $_port_mk
5431
5432SAVED_CONFIGFLAGS  := $SAVED_CONFIGFLAGS
5433SAVED_LDFLAGS      := $SAVED_LDFLAGS
5434SAVED_CXX          := $SAVED_CXX
5435SAVED_CXXFLAGS     := $SAVED_CXXFLAGS
5436SAVED_CPPFLAGS     := $SAVED_CPPFLAGS
5437SAVED_ASFLAGS      := $SAVED_ASFLAGS
5438SAVED_WINDRESFLAGS := $SAVED_WINDRESFLAGS
5439SAVED_SDL_CONFIG   := $SAVED_SDL_CONFIG
5440EOF
5441
5442#
5443# Create a custom Makefile when building outside the source tree
5444# TODO: Add a better check than just looking for 'Makefile'
5445#
5446if test ! -f Makefile.common ; then
5447echo "Creating Makefile"
5448
5449cat > Makefile << EOF
5450# -------- Generated by configure -----------
5451srcdir = $_srcdir
5452vpath %.h \$(srcdir)
5453vpath %.cpp \$(srcdir)
5454vpath %.c \$(srcdir)
5455vpath %.m \$(srcdir)
5456vpath %.mm \$(srcdir)
5457vpath %.asm \$(srcdir)
5458vpath %.s \$(srcdir)
5459vpath %.S \$(srcdir)
5460include \$(srcdir)/Makefile
5461EOF
5462
5463fi
5464
5465# Ensure engines folder exists prior to trying to generate
5466# files into it (used for out-of-tree-builds)
5467mkdir -p engines
5468
5469echo "Creating engines/engines.mk"
5470cat > engines/engines.mk << EOF
5471# This file is automatically generated by configure
5472# DO NOT EDIT MANUALLY
5473# This file is being included by "Makefile.common"
5474EOF
5475
5476for engine in $_sorted_engines; do
5477	j=`echo $engine | tr '[:lower:]' '[:upper:]'`
5478	if test "`get_engine_sub $engine`" = "no" ; then
5479		# main engine
5480		cat >> engines/engines.mk << EOF
5481
5482ifdef ENABLE_$j
5483DEFINES += -DENABLE_$j=\$(ENABLE_$j)
5484MODULES += engines/$engine
5485EOF
5486
5487	for subeng in `get_engine_subengines $engine` ; do
5488		k=`echo $subeng | tr '[:lower:]' '[:upper:]'`
5489		cat >> engines/engines.mk << EOF
5490
5491ifdef ENABLE_$k
5492DEFINES += -DENABLE_$k
5493endif
5494EOF
5495	done
5496
5497	cat >> engines/engines.mk << EOF
5498endif
5499EOF
5500	fi
5501done
5502
5503echo "Creating engines/plugins_table.h"
5504cat > engines/plugins_table.h << EOF
5505/* This file is automatically generated by configure */
5506/* DO NOT EDIT MANUALLY */
5507// This file is being included by "base/plugins.cpp"
5508EOF
5509
5510for engine in $_sorted_engines; do
5511	if test "`get_engine_sub $engine`" = "no" ; then
5512		j=`echo $engine | tr '[:lower:]' '[:upper:]'`
5513		cat >> engines/plugins_table.h << EOF
5514#if PLUGIN_ENABLED_STATIC($j)
5515LINK_PLUGIN($j)
5516#endif
5517EOF
5518	fi
5519done
5520