1#!/bin/sh
2#
3# Some things this script could/should do when finished
4#
5# * detect whether it's a GNU compiler or not (for compiler settings)
6# * command line options to...
7#   - override the host settings (for cross compiles
8#   - whether to do a debug build (with -g) or an optimized build (-O3 etc.)
9# * detect whether the chosen backend is available (e.g. call sdl2-config)
10# * ....
11
12
13# use environment vars if set
14CXXFLAGS="$CXXFLAGS $CPPFLAGS"
15
16# default option behaviour yes/no
17_build_gui=yes
18_build_windowed=yes
19_build_sound=yes
20_build_debugger=yes
21_build_joystick=yes
22_build_cheats=yes
23_build_httplib=yes
24_build_png=yes
25_build_zip=yes
26_build_static=no
27_build_profile=no
28_build_debug=no
29_build_release=no
30
31# more defaults
32_ranlib=ranlib
33_install=install
34_ar="ar cru"
35_strip=strip
36_mkdir="mkdir -p"
37_echo=printf
38_cat=cat
39_rm="rm -f"
40_rm_rec="$_rm -r"
41_zip="zip -q"
42_cp=cp
43_windowspath=""
44_sdlconfig=sdl2-config
45_sdlpath="$PATH"
46_prefix=/usr/local
47
48_srcdir=`dirname $0`
49
50# TODO: We should really use mktemp(1) to determine a random tmp file name.
51# However, that tool might not be available everywhere.
52TMPO=${_srcdir}/stella-conf
53TMPC=${TMPO}.cxx
54TMPLOG=${_srcdir}/config.log
55
56# For cross compiling
57_host=""
58_host_cpu=""
59_host_vendor=""
60_host_os=""
61_host_prefix=""
62
63cc_check() {
64	echo >> "$TMPLOG"
65	cat "$TMPC" >> "$TMPLOG"
66	echo >> "$TMPLOG"
67	echo "$CXX $TMPC $CXXFLAGS $LDFLAGS -o $TMPO$EXEEXT $@" >> "$TMPLOG"
68	rm -f "$TMPO$EXEEXT"
69	( $CXX "$TMPC" $CXXFLAGS $LDFLAGS -o "$TMPO$EXEEXT" "$@" ) >> "$TMPLOG" 2>&1
70	TMP="$?"
71	echo >> "$TMPLOG"
72	return "$TMP"
73}
74
75cc_check_define() {
76cat > $TMPC << EOF
77int main(void) {
78	#ifndef $1
79	syntax error
80	#endif
81	return 0;
82}
83EOF
84	cc_check -c
85	return $?
86}
87
88echocheck () {
89	echo_n "Checking for $@... "
90}
91
92#
93# Check whether the given command is a working C++ compiler
94#
95test_compiler ()
96{
97cat <<EOF >tmp_cxx_compiler.cpp
98#include <memory>
99class Foo {
100	int a;
101};
102int main(int argc, char* argv[])
103{
104	std::shared_ptr<Foo> a = std::make_shared<Foo>();
105	return 0;
106}
107EOF
108
109if test -n "$_host"; then
110	# In cross-compiling mode, we cannot run the result
111	eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp 2> /dev/null" && rm -f tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp
112else
113	eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp 2> /dev/null" && eval "./tmp_cxx_compiler 2> /dev/null" && rm -f tmp_cxx_compiler$EXEEXT tmp_cxx_compiler.cpp
114fi
115}
116
117# Add a line of data to config.mk.
118add_line_to_config_mk() {
119	_config_mk_data="$_config_mk_data"'
120'"$1"
121}
122
123
124#
125# Determine sdl2-config
126#
127# TODO: small bit of code to test sdl useability
128find_sdlconfig()
129{
130	echo_n "Looking for sdl2-config... "
131	sdlconfigs="$_sdlconfig"
132	_sdlconfig=
133
134	IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR"
135	done=0
136	for path_dir in $_sdlpath; do
137                #reset separator to parse sdlconfigs
138                IFS=":"
139		for sdlconfig in $sdlconfigs; do
140			if test -x "$path_dir/$sdlconfig" ; then
141				_sdlconfig="$path_dir/$sdlconfig"
142				done=1
143				break
144			fi
145		done
146		if test $done -eq 1 ; then
147			echo $_sdlconfig
148			break
149		fi
150	done
151
152	IFS="$ac_save_ifs"
153
154	if test -z "$_sdlconfig"; then
155		echo "none found!"
156		exit 1
157	fi
158}
159
160#
161# Function to provide echo -n for bourne shells that don't have it
162#
163echo_n()
164{
165	printf "$@"
166}
167
168#
169# Greet user
170#
171
172echo "Running Stella configure..."
173echo "Configure run on" `date` > $TMPLOG
174
175#
176# Check any parameters we received
177#
178
179for parm in "$@" ; do
180  if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then
181    cat << EOF
182
183Usage: $0 [OPTIONS]...
184
185Configuration:
186  -h, --help             display this help and exit
187
188Installation directories:
189  --prefix=DIR           use this prefix for installing stella  [/usr/local]
190  --bindir=DIR           directory to install the stella binary [PREFIX/bin]
191  --docdir=DIR           directory to install documentation     [PREFIX/share/doc/stella]
192  --datadir=DIR          directory to install icons/data files  [PREFIX/share]
193
194Optional Features:
195  --enable-gui           enable/disable the entire built-in UI [enabled]
196  --disable-gui
197  --enable-sound         enable/disable sound support [enabled]
198  --disable-sound
199  --enable-debugger      enable/disable all debugger options [enabled]
200  --disable-debugger
201  --enable-joystick      enable/disable joystick support [enabled]
202  --disable-joystick
203  --enable-cheats        enable/disable cheatcode support [enabled]
204  --disable-cheats
205  --enable-png           enable/disable PNG image support [enabled]
206  --disable-png
207  --enable-zip           enable/disable ZIP file support [enabled]
208  --disable-zip
209  --enable-windowed      enable/disable windowed rendering modes [enabled]
210  --disable-windowed
211  --enable-shared        build shared binary [enabled]
212  --enable-static        build static binary (if possible) [disabled]
213  --disable-static
214  --enable-profile       build binary with profiling info [disabled]
215  --disable-profile
216  --enable-debug         build with debugging symbols [disabled]
217  --disable-debug
218
219Optional Libraries:
220  --with-sdl-prefix=DIR    Prefix where the sdl2-config script is installed (optional)
221  --with-libpng-prefix=DIR Prefix where libpng is installed (optional)
222  --with-zlib-prefix=DIR   Prefix where zlib is installed (optional)
223
224Some influential environment variables:
225  LDFLAGS	linker flags, e.g. -L<lib dir> if you have libraries in a
226  		nonstandard directory <lib dir>
227  CXX		C++ compiler command
228  CXXFLAGS	C++ compiler flags
229  CPPFLAGS	C++ preprocessor flags, e.g. -I<include dir> if you have
230  		headers in a nonstandard directory <include dir>
231
232EOF
233    exit 0
234  fi
235done # for parm in ...
236
237for ac_option in $@; do
238    case "$ac_option" in
239      --enable-gui)             _build_gui=yes       ;;
240      --disable-gui)            _build_gui=no        ;;
241      --enable-sound)           _build_sound=yes     ;;
242      --disable-sound)          _build_sound=no      ;;
243      --enable-debugger)        _build_debugger=yes  ;;
244      --disable-debugger)       _build_debugger=no   ;;
245      --enable-joystick)        _build_joystick=yes  ;;
246      --disable-joystick)       _build_joystick=no   ;;
247      --enable-cheats)          _build_cheats=yes    ;;
248      --disable-cheats)         _build_cheats=no     ;;
249      --enable-png)             _build_png=yes       ;;
250      --disable-png)            _build_png=no        ;;
251      --enable-zip)             _build_zip=yes       ;;
252      --disable-zip)            _build_zip=no        ;;
253      --enable-windowed)        _build_windowed=yes  ;;
254      --disable-windowed)       _build_windowed=no   ;;
255      --enable-shared)          _build_static=no     ;;
256      --enable-static)          _build_static=yes    ;;
257      --disable-static)         _build_static=no     ;;
258      --enable-profile)         _build_profile=yes   ;;
259      --disable-profile)        _build_profile=no    ;;
260      --enable-debug)           _build_debug=yes     ;;
261      --disable-debug)          _build_debug=no      ;;
262      --enable-release)         _build_release=yes   ;;
263      --disable-release)        _build_release=no    ;;
264      --with-sdl-prefix=*)
265        arg=`echo $ac_option | cut -d '=' -f 2`
266        _sdlpath="$arg:$arg/bin"
267        ;;
268      --with-libpng-prefix=*)
269        _prefix=`echo $ac_option | cut -d '=' -f 2`
270        LIBPNG_CFLAGS="-I$_prefix/include"
271        LIBPNG_LIBS="-L$_prefix/lib"
272        ;;
273      --with-zlib-prefix=*)
274        _prefix=`echo $ac_option | cut -d '=' -f 2`
275        ZLIB_CFLAGS="-I$_prefix/include"
276        ZLIB_LIBS="-L$_prefix/lib"
277        ;;
278      --host=*)
279        _host=`echo $ac_option | cut -d '=' -f 2`
280        ;;
281      --prefix=*)
282        _prefix=`echo $ac_option | cut -d '=' -f 2`
283        ;;
284      --bindir=*)
285        _bindir=`echo $ac_option | cut -d '=' -f 2`
286        ;;
287      --docdir=*)
288        _docdir=`echo $ac_option | cut -d '=' -f 2`
289        ;;
290      --datadir=*)
291        _datadir=`echo $ac_option | cut -d '=' -f 2`
292        ;;
293      *)
294        echo "warning: unrecognised option: $ac_option"
295        ;;
296    esac;
297done;
298
299CXXFLAGS="$CXXFLAGS $DEBFLAGS"
300
301case $_host in
302#linupy)
303#	_host_os=linux
304#	_host_cpu=arm
305#	;;
306#arm-riscos-aof)
307#	_host_os=riscos
308#	_host_cpu=arm
309#	;;
310#ppc-amigaos)
311#	_host_os=amigaos
312#	_host_cpu=ppc
313#	;;
314retron77)
315	_host_os=retron77
316	;;
317mingw32-cross)
318	_host_os=mingw32msvc
319	_host_cpu=i386
320	_host_prefix=i386-mingw32msvc
321	;;
322*)
323	guessed_host=`$_srcdir/config.guess`
324	_host_cpu=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
325	_host_os=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
326	_host_vendor=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
327	;;
328esac
329
330#
331# Determine extension used for executables
332#
333case $_host_os in
334mingw* | cygwin* |os2-emx*)
335	EXEEXT=".exe"
336	;;
337arm-riscos-aof)
338	EXEEXT=",ff8"
339	;;
340psp)
341	EXEEXT=".elf"
342	;;
343gp2x)
344	EXEEXT=""
345	;;
346*)
347	EXEEXT=""
348	;;
349esac
350
351#
352# Determine separator used for $PATH
353#
354case $_host_os in
355os2-emx* )
356        SEPARATOR=";"
357        ;;
358* )
359        SEPARATOR=":"
360        ;;
361esac
362
363
364#
365# Determine the C++ compiler
366#
367echo_n "Looking for C++ compiler... "
368if test -n "$CXX"; then
369	echo $CXX
370else
371	if test -n "$_host"; then
372		compilers="$_host_prefix-g++ $_host_prefix-c++ $_host_cpu-$_host_os-g++ $_host_cpu-$_host_os-c++ g++ c++"
373	else
374		compilers="g++ c++"
375	fi
376
377	for compiler in $compilers; do
378		if test_compiler "$compiler -std=c++17"; then
379			CXX=$compiler
380			echo $CXX
381			break
382		fi
383	done
384	if test -z "$CXX"; then
385		echo "none found!"
386		exit 1
387	fi
388fi
389
390#
391# Determine the compiler version
392
393echocheck "compiler version"
394
395have_clang=no
396cc_check_define __clang_version__ && have_clang=yes
397if test $have_clang = no; then
398	cc_check_define __clang__ && have_clang=yes
399fi
400have_gcc=no
401cc_check_define __GNUC__ && have_gcc=yes
402
403if test "$have_clang" = yes; then
404
405	clang_minor=$( $CXX -dM -E -x c /dev/null | grep __clang_minor__ | sed -E 's/.* ([0-9]+).*/\1/' )
406	clang_patch=$( $CXX -dM -E -x c /dev/null | grep __clang_patchlevel__ | sed -E 's/.* ([0-9]+).*/\1/' )
407	clang_major=$( $CXX -dM -E -x c /dev/null | grep __clang_major__ | sed -E 's/.* ([0-9]+).*/\1/' )
408
409	cxx_version="$clang_major.$clang_minor.$clang_patch"
410
411	is_xcode=$( $CXX -dM -E -x c /dev/null | grep __apple_build_version__ )
412
413  # Need at least version 8
414	if test -n "$is_xcode"; then
415		cxx_name="XCode $cxx_version"
416
417		if test $clang_major -ge 8; then
418			cxx_version="$cxx_version, ok"
419			cxx_verc_fail=no
420		else
421			cxx_version="$cxx_version, bad"
422			cxx_verc_fail=yes
423		fi
424
425		_make_def_CLANG_WARNINGS='CLANG_WARNINGS = 1'
426	else
427    # Need at least version 3.5
428		if [ $clang_major -ge 4 ] || [ $clang_major -eq 3 -a $clang_minor -ge 5 ]; then
429			cxx_version="$cxx_version, ok"
430			cxx_verc_fail=no
431		else
432			cxx_version="$cxx_version, bad"
433			cxx_verc_fail=yes
434		fi
435
436    # Only clang >= 5.0 supports extra warnings
437		if [ $clang_major -ge 5 ]; then
438			_make_def_CLANG_WARNINGS='CLANG_WARNINGS = 1'
439		fi
440	fi
441	CXXFLAGS="$CXXFLAGS"
442	_make_def_HAVE_CLANG='HAVE_CLANG = 1'
443	add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
444	echo "$cxx_version"
445
446elif test "$have_gcc" = yes; then
447	cxx_name=`( $cc -v ) 2>&1 | tail -n 1 | cut -d ' ' -f 1`
448	cxx_version=`( $CXX -dumpversion ) 2>&1`
449	if test "$?" -gt 0; then
450		cxx_version="not found"
451	fi
452
453	case $cxx_version in
454		[1-9]*)
455			_cxx_major=`echo $cxx_version | cut -d '.' -f 1`
456			_cxx_minor=`echo $cxx_version | cut -d '.' -f 2`
457			# Need at least version 4.7
458			if [ $_cxx_major -ge 5 ] || [ $_cxx_major -eq 4 -a $_cxx_minor -ge 7 ]; then
459				cxx_version="$cxx_version, ok"
460				cxx_verc_fail=no
461			else
462				cxx_version="$cxx_version, bad"
463				cxx_verc_fail=yes
464			fi
465			;;
466		'not found')
467			cxx_verc_fail=yes
468			;;
469		*)
470			cxx_version="$cxx_version, bad"
471			cxx_verc_fail=yes
472			;;
473	esac
474	CXXFLAGS="$CXXFLAGS"
475	add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
476	_make_def_HAVE_GCC='HAVE_GCC = 1'
477	echo "$cxx_version"
478
479else
480	cxx_version=`( $CXX -version ) 2>&1`
481	if test "$?" -eq 0; then
482		cxx_version="`echo "${cxx_version}" | sed -ne 's/^.*[^0-9]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/gp'`"
483		if test -z "${cxx_version}"; then
484			cxx_version="not found"
485			cxx_verc_fail=yes
486		fi
487		echo non-gcc compiler version ${cxx_version}
488	else
489		cxx_version="not found"
490		cxx_verc_fail=yes
491		echo found non-gcc compiler version ${cxx_version}
492	fi
493
494	CXXFLAGS="$CXXFLAGS"
495	case $_host_os in
496		irix*)
497			case $cxx_version in
498				7.4.4*)
499					# We just assume this is SGI MIPSpro
500					_cxx_major=7
501					_cxx_minor=4
502					cxx_verc_fail=no
503					add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MDupdate "$(*D)/$(DEPDIR)/$(*F).d"'
504					add_line_to_config_mk '-include Makedepend'
505					;;
506				*)
507					cxx_version="$cxx_version, bad"
508					cxx_verc_fail=yes
509					;;
510			esac
511		;;
512		*)
513			cxx_version="$cxx_version, bad"
514			cxx_verc_fail=yes
515		;;
516	esac
517
518fi
519
520
521if test "$cxx_verc_fail" = yes ; then
522	echo
523	echo "The version of your compiler is not supported at this time"
524	echo "Please ensure you are using GCC 5.0 / Clang 3.8 or above"
525	exit 1
526fi
527
528#
529# Do CXXFLAGS now we know the compiler version
530#
531
532if test -n "$_host"; then
533	# Cross-compiling mode - add your target here if needed
534	case "$_host" in
535    retron77)
536      echo "Compiling for $_host, disabling windowed mode, debugger and cheats."
537      _build_gui=yes
538      _build_windowed=no
539      _build_debugger=no
540      _build_cheats=no
541      _build_httplib=no
542      ;;
543		mingw32-cross)
544			echo "Cross-compiling for Windows using MinGW."
545			DEFINES="$DEFINES -DWIN32"
546			_host_os=win32
547			;;
548		*linux*)
549			echo "Cross-compiling to $_host target"
550			DEFINES="$DEFINES -DUNIX"
551			_host_os=unix
552			;;
553		*)
554			echo "Cross-compiling to unknown target, please add your target to configure."
555			exit 1
556			;;
557	esac
558
559else
560	#
561	# Determine build settings
562	#
563	# TODO - also add an command line option to override this?!?
564	echo_n "Checking hosttype... "
565	echo $_host_os
566	case $_host_os in
567		linux* | openbsd* | dragonfly* | freebsd* | kfreebsd* | netbsd* | bsd* | gnu0.* | sunos* | hpux* | beos*)
568			DEFINES="$DEFINES -DUNIX"
569			_host_os=unix
570			;;
571		darwin*)
572			DEFINES="$DEFINES -DUNIX -DDARWIN"
573			_host_os=darwin
574			;;
575		irix*)
576			DEFINES="$DEFINES -DUNIX"
577			_ranlib=:
578			_host_os=unix
579			;;
580		mingw*)
581			DEFINES="$DEFINES -DWIN32"
582			_host_os=win32
583			;;
584		os2*)
585			DEFINES="$DEFINES -DUNIX -DOS2"
586			_host_os=unix
587			;;
588		cygwin*)
589			DEFINES="$DEFINES -mno-cygwin -DWIN32"
590			LIBS="$LIBS -mno-cygwin -lmingw32 -lwinmm"
591			_host_os=win32
592			;;
593		os2*)
594			DEFINES="$DEFINES -DUNIX -DOS2"
595			_host_os=unix
596			;;
597		# given this is a shell script assume some type of unix
598		*)
599			echo "WARNING: could not establish system type, assuming unix like"
600			DEFINES="$DEFINES -DUNIX"
601			;;
602	esac
603fi
604
605# Cross-compilers use their own commands for the following functions
606if test -n "$_host_prefix"; then
607	_strip="$_host_prefix-$_strip"
608fi
609
610#
611# Check for ZLib
612#
613echocheck "zlib"
614if test "$_build_zip" = yes ; then
615	_zlib=no
616	cat > $TMPC << EOF
617#include <string.h>
618#include <zlib.h>
619int main(void) { return strcmp(ZLIB_VERSION, zlibVersion()); }
620EOF
621	cc_check $LDFLAGS $CXXFLAGS $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes
622
623  if test "$_zlib" = yes ; then
624    echo "$_zlib"
625  else
626    echo "disabled"
627    _build_png=no
628    _build_zip=no
629  fi
630else
631  echo "disabled"
632  _build_png=no
633  _build_zip=no
634fi
635
636#
637# Check for libpng
638#
639echocheck "libpng"
640if test "$_build_png" = yes ; then
641  _libpng=no
642  cat > $TMPC << EOF
643#include <stdio.h>
644#include <png.h>
645int main(void) { return printf("%s\n", PNG_HEADER_VERSION_STRING); }
646EOF
647  cc_check $LDFLAGS $CXXFLAGS $LIBPNG_CFLAGS $LIBPNG_LIBS `pkg-config --libs libpng` && _libpng=yes
648
649  if test "$_libpng" = yes ; then
650    echo "$_libpng"
651  else
652    echo "disabled"
653    _build_png=no
654  fi
655else
656  echo "disabled"
657  _build_png=no
658fi
659
660#
661# figure out installation directories
662#
663test -z "$_bindir" && _bindir="$_prefix/bin"
664test -z "$_docdir" && _docdir="$_prefix/share/doc/stella"
665test -z "$_datadir" && _datadir="$_prefix/share"
666
667echo
668echo_n "Summary:"
669echo
670
671if test "$_build_gui" = "yes" ; then
672	echo_n "   GUI enabled"
673	echo
674else
675	echo_n "   GUI disabled"
676	echo
677  _build_debugger=no
678  _build_cheats=no
679fi
680
681if test "$_build_sound" = "yes" ; then
682	echo_n "   Sound support enabled"
683	echo
684else
685	echo_n "   Sound support disabled"
686	echo
687fi
688
689if test "$_build_debugger" = "yes" ; then
690	echo_n "   Debugger support enabled"
691	echo
692else
693	echo_n "   Debugger support disabled"
694	echo
695fi
696
697if test "$_build_joystick" = yes ; then
698	echo_n "   Joystick support enabled"
699	echo
700else
701	echo_n "   Joystick support disabled"
702	echo
703fi
704
705if test "$_build_cheats" = yes ; then
706	echo_n "   Cheatcode support enabled"
707	echo
708else
709	echo_n "   Cheatcode support disabled"
710	echo
711fi
712
713if test "$_build_png" = yes ; then
714	echo_n "   PNG image support enabled"
715	echo
716else
717	echo_n "   PNG image support disabled"
718	echo
719fi
720
721if test "$_build_zip" = yes ; then
722	echo_n "   ZIP file support enabled"
723	echo
724else
725	echo_n "   ZIP file support disabled"
726	echo
727fi
728
729if test "$_build_windowed" = "yes" ; then
730	echo_n "   Windowed rendering modes enabled"
731	echo
732else
733	echo_n "   Windowed rendering modes disabled"
734	echo
735fi
736
737if test "$_build_static" = yes ; then
738	echo_n "   Static binary enabled"
739	echo
740else
741	echo_n "   Static binary disabled"
742	echo
743fi
744
745if test "$_build_profile" = yes ; then
746	echo_n "   Profiling enabled"
747	echo
748
749	_build_debug=yes
750else
751	echo_n "   Profiling disabled"
752	echo
753fi
754
755if test "$_build_debug" = yes ; then
756	echo_n "   Debug symbols enabled"
757	echo
758else
759	echo_n "   Debug symbols disabled"
760	echo
761fi
762
763#
764# Now, add the appropriate defines/libraries/headers
765#
766echo
767find_sdlconfig
768
769SRC="src"
770CORE="$SRC/emucore"
771COMMON="$SRC/common"
772TIA="$SRC/emucore/tia"
773TIA_FRAME_MANAGER="$SRC/emucore/tia/frame-manager"
774TV="$SRC/common/tv_filters"
775GUI="$SRC/gui"
776DBG="$SRC/debugger"
777DBGGUI="$SRC/debugger/gui"
778YACC="$SRC/yacc"
779CHEAT="$SRC/cheat"
780LIBPNG="$SRC/libpng"
781ZLIB="$SRC/zlib"
782SQLITE_REPO="$SRC/common/repository/sqlite"
783SQLITE_LIB="$SRC/sqlite"
784JSON="$SRC/json"
785HTTP_LIB="$SRC/httplib"
786
787INCLUDES="-I$CORE -I$COMMON -I$TV -I$TIA -I$TIA_FRAME_MANAGER -I$JSON -I$SQLITE_REPO -I$SQLITE_LIB"
788
789INCLUDES="$INCLUDES `$_sdlconfig --cflags`"
790if test "$_build_static" = yes ; then
791	_sdl_conf_libs="--static-libs"
792	LDFLAGS="-static $LDFLAGS"
793else
794	_sdl_conf_libs="--libs"
795fi
796
797LIBS="$LIBS `$_sdlconfig $_sdl_conf_libs`"
798LD=$CXX
799
800case $_host_os in
801		unix)
802			DEFINES="$DEFINES -DBSPF_UNIX"
803			MODULES="$MODULES $SRC/unix"
804			INCLUDES="$INCLUDES -I$SRC/unix"
805			;;
806		darwin)
807			DEFINES="$DEFINES -DBSPF_UNIX -DMACOS_KEYS"
808			MODULES="$MODULES $SRC/unix"
809			INCLUDES="$INCLUDES -I$SRC/unix"
810			if test "$have_clang" == yes; then
811				CXXFLAGS="$CXXFLAGS -Wno-poison-system-directories"
812			fi
813			;;
814    retron77)
815      DEFINES="$DEFINES -DBSPF_UNIX -DRETRON77"
816      MODULES="$MODULES $SRC/unix $SRC/unix/r77"
817      INCLUDES="$INCLUDES -I$SRC/unix -I$SRC/unix/r77"
818      ;;
819		win32)
820			DEFINES="$DEFINES -DBSPF_WINDOWS"
821			MODULES="$MODULES $SRC/windows"
822			INCLUDES="$INCLUDES -I$SRC/windows"
823			LIBS="$LIBS -lmingw32 -lwinmm"
824			;;
825		*)
826			echo "WARNING: host system not currently supported"
827			exit
828			;;
829esac
830
831if test "$_build_gui" = yes ; then
832	DEFINES="$DEFINES -DGUI_SUPPORT"
833	MODULES="$MODULES $GUI"
834	INCLUDES="$INCLUDES -I$GUI"
835fi
836
837if test "$_build_windowed" = yes ; then
838	DEFINES="$DEFINES -DWINDOWED_SUPPORT"
839fi
840
841if test "$_build_sound" = yes ; then
842	DEFINES="$DEFINES -DSOUND_SUPPORT"
843fi
844
845if test "$_build_debugger" = yes ; then
846	DEFINES="$DEFINES -DDEBUGGER_SUPPORT"
847	MODULES="$MODULES $DBG $DBGGUI $YACC"
848	INCLUDES="$INCLUDES -I$DBG -I$DBGGUI -I$YACC"
849fi
850
851if test "$_build_joystick" = yes ; then
852	DEFINES="$DEFINES -DJOYSTICK_SUPPORT"
853fi
854
855if test "$_build_cheats" = yes ; then
856	DEFINES="$DEFINES -DCHEATCODE_SUPPORT"
857	MODULES="$MODULES $CHEAT"
858	INCLUDES="$INCLUDES -I$CHEAT"
859fi
860
861if test "$_build_httplib" = yes ; then
862	DEFINES="$DEFINES -DHTTP_LIB_SUPPORT"
863	INCLUDES="$INCLUDES -I$HTTP_LIB"
864fi
865
866if test "$_build_png" = yes ; then
867	DEFINES="$DEFINES -DPNG_SUPPORT"
868  if test "$_libpng" = yes ; then
869    LIBS="$LIBS -lpng"
870  else
871    MODULES="$MODULES $LIBPNG"
872    INCLUDES="$INCLUDES -I$LIBPNG"
873  fi
874fi
875
876if test "$_build_zip" = yes ; then
877	DEFINES="$DEFINES -DZIP_SUPPORT"
878  if test "$_zlib" = yes ; then
879    LIBS="$LIBS -lz"
880  else
881    MODULES="$MODULES $ZLIB"
882    INCLUDES="$INCLUDES -I$ZLIB"
883  fi
884fi
885
886if test "$_build_profile" = no ; then
887	_build_profile=
888fi
889
890if test "$_build_debug" = no ; then
891	_build_debug=
892fi
893
894if test "$_build_release" = no ; then
895	_build_release=
896fi
897
898echo "Creating config.mak"
899cat > config.mak << EOF
900# -------- Generated by configure -----------
901
902CXX := $CXX
903CXXFLAGS := $CXXFLAGS
904LD := $LD
905LIBS += $LIBS
906RANLIB := $_ranlib
907INSTALL := $_install
908AR := $_ar
909MKDIR := $_mkdir
910ECHO := $_echo
911CAT := $_cat
912RM := $_rm
913RM_REC := $_rm_rec
914ZIP := $_zip
915CP := $_cp
916WINDOWSPATH=$_windowspath
917STRIP := $_strip
918LLVM_PROFDATA := llvm-profdata
919BINARY_LOADER :=
920
921MODULES += $MODULES
922MODULE_DIRS += $MODULE_DIRS
923EXEEXT := $EXEEXT
924
925PREFIX := $_prefix
926BINDIR := $_bindir
927DOCDIR := $_docdir
928DATADIR := $_datadir
929PROFILE := $_build_profile
930DEBUG   := $_build_debug
931RELEASE := $_build_release
932
933$_make_def_HAVE_GCC
934$_make_def_HAVE_CLANG
935$_make_def_CLANG_WARNINGS
936
937INCLUDES += $INCLUDES
938OBJS += $OBJS
939DEFINES += $DEFINES
940LDFLAGS += $LDFLAGS
941$_config_mk_data
942EOF
943
944# This should be taken care of elsewhere, but I'm not sure where
945rm -f stella-conf stella-conf.cxx
946
947if test "$_host_os" = darwin; then
948	cat <<EOI
949
950WARNING: plain UNIX-style builds on macOS without XCode are unsupported. Continue on your own risk...
951EOI
952fi
953