1dnl Process this file with autoconf to produce a configure script.
2dnl Written in 1999 by Christian Bauer et al.
3dnl Adapted for ARAnyM by Milan Jurik
4dnl Adapted to automake by Thorsten Otto
5
6m4_define(ARANYM_VERSION, m4_esyscmd([sed -n -e 's/#define.*VER_MAJOR.*\([0-9][0-9]*\).*$/\1./p
7s/#define.*VER_MINOR.*\([0-9][0.9]*\).*$/\1./p
8s/#define.*VER_MICRO.*\([0-9][0-9]*\).*$/\1/p' src/include/version.h | tr -d '\n']))
9
10AC_INIT(aranym, ARANYM_VERSION, [aranym@googlegroups.com],,[https://github.com/aranym/aranym])
11AC_PREREQ(2.52)
12AC_CONFIG_HEADER(config.h)
13AC_CONFIG_MACRO_DIR([m4])
14AC_CONFIG_AUX_DIR([.])
15AC_CONFIG_SRCDIR([src/hostscreen.cpp])
16
17dnl Define list of provided Native Features
18PROVIDES_NF="audio bootstrap xhdi"
19
20dnl Canonical system information.
21AC_CANONICAL_HOST
22
23AM_INIT_AUTOMAKE(check-news m4_esyscmd([case `automake --version | head -n 1` in
24                             *1.10*);;
25                             *) echo subdir-objects color-tests;;
26                             esac]))
27AM_MAINTAINER_MODE([disable])
28
29dnl Silent rules
30# Support silent build rules, requires at least automake-1.11. Disable
31# by either passing --disable-silent-rules to configure or passing V=1
32# to make
33m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
34
35AH_TOP([
36#ifndef __ARANYM_CONFIG_H__
37#define __ARANYM_CONFIG_H__
38
39#if defined(__linux__) && !defined(__ANDROID__)
40#include "linux/libcwrap.h"
41#endif
42
43#ifndef _FORTIFY_SOURCE
44#  define _FORTIFY_SOURCE 2
45#endif
46
47])
48
49dnl Options.
50AC_ARG_ENABLE(nat-debug,     [AC_HELP_STRING([--enable-nat-debug], [enable native debugger support (default=yes)])], [WANT_NATDEBUG=$enableval], [WANT_NATDEBUG=yes])
51
52AC_ARG_ENABLE(full-debug,    [AC_HELP_STRING([--enable-full-debug], [enable full debug outputs (default=no)])], [WANT_FULLDEBUG=$enableval], [WANT_FULLDEBUG=no])
53
54AC_ARG_ENABLE(debug,
55[AC_HELP_STRING([--enable-debug=which], [specify wether to use internal debugger (default=no)])],
56[ case "$enableval" in
57    default | yes | uae | ndebug)  USE_DEBUGGER=yes;;
58         no)  USE_DEBUGGER="no";;
59	  *)  AC_MSG_ERROR([--enable-debug takes only one of the following values: default, uae, ndebug, no]);;
60  esac
61],
62[USE_DEBUGGER=no
63])
64
65AC_ARG_ENABLE(fullhistory,     [AC_HELP_STRING([--enable-fullhistory], [enable full history for debugger (default=no)])], [WANT_HISTORY=$enableval], [WANT_HISTORY=no])
66
67AC_ARG_ENABLE(flightrecorder,  [AC_HELP_STRING([--enable-flightrecorder], [enable CPU flight recorder (default=no)])], [WANT_FLIGHTRECORDER=$enableval], [WANT_FLIGHTRECORDER=no])
68
69AC_ARG_ENABLE(fullmmu,         [AC_HELP_STRING([--enable-fullmmu], [enable full 68040 MMU (default=no)])], [WANT_MMU=$enableval], [WANT_MMU=no])
70
71AC_ARG_ENABLE(atc,
72[AC_HELP_STRING([--enable-atc=ATC], [select type of ATC for MMU (default=full)])],
73[ case "$enableval" in
74        full)  ATC_TYPE="full";;
75       small)  ATC_type="small";;
76          no)  ATC_TYPE="no";;
77           *)  AC_MSG_ERROR([--enable-atc takes only one of the following values: full, small, no]);;
78  esac
79], [ATC_TYPE=full])
80
81AC_ARG_ENABLE(realstop,        [AC_HELP_STRING([--enable-realstop], [enable real STOP instruction (default=yes)])], [WANT_REALSTOP=$enableval], [WANT_REALSTOP=yes])
82
83AC_ARG_ENABLE(dsp,             [AC_HELP_STRING([--enable-dsp], [enable DSP 56001 (default=yes)])], [WANT_DSP=$enableval], [WANT_DSP=yes])
84
85AC_ARG_ENABLE(dsp-disasm,      [AC_HELP_STRING([--enable-dsp-disasm], [enable DSP 56001 disassembler (default=no)])], [WANT_DSP_DISASM=$enableval], [WANT_DSP_DISASM=no])
86
87AC_ARG_ENABLE(protect2k,       [AC_HELP_STRING([--enable-protect2k], [enable first 2kB of RAM Super protection (default=yes)])], [WANT_PROTECT2K=$enableval], [WANT_PROTECT2K=yes])
88
89AC_ARG_ENABLE(fixedfastram,    [AC_HELP_STRING([--enable-fixedfastram=X], [use fixed size FastRAM of X MB (default=no)])], [WANT_FIXEDFASTRAM=$enableval], [WANT_FIXEDFASTRAM=no])
90
91AC_ARG_ENABLE(fixedvideoram,   [AC_HELP_STRING([--enable-fixedvideoram], [use fixed start of VideoRAM (default=no)])], [WANT_FIXEDVIDEORAM=$enableval], [WANT_FIXEDVIDEORAM=no])
92
93AC_ARG_ENABLE(blitmemmove,     [AC_HELP_STRING([--enable-blitmemmove], [enable Blitter memmove rout (default=no)])], [WANT_BLITMEMMOVE=$enableval], [WANT_BLITMEMMOVE=no])
94
95AC_ARG_ENABLE(blitsdlblit,     [AC_HELP_STRING([--enable-blitsdlblit], [enable SDL blitting routine EXPERIMENTAL UNSUPPORTED BUGGY (default=no)])], [WANT_BLITSDLBLIT=$enableval], [WANT_BLITSDLBLIT=no])
96
97AC_ARG_ENABLE(hostfs,          [AC_HELP_STRING([--enable-hostfs], [enable hostfs support (default=yes)])], [WANT_HOSTFS=$enableval], [WANT_HOSTFS=yes])
98
99AC_ARG_ENABLE(ctrlkey,
100[AC_HELP_STRING([--enable-ctrlkey=WHICH], [specify which key to use for control key emulation (default=both)])],
101[ case "$enableval" in
102    dnl default is both
103    ctrl)	    CONTROL_KEY="ctrl";;
104    meta)		CONTROL_KEY="meta";;
105    both)		CONTROL_KEY="both";;
106    *)		AC_MSG_ERROR([--enable-ctrlkey takes only one of the following values: ctrl, meta, both]);;
107  esac
108],
109[ CONTROL_KEY="both"
110])
111
112AC_ARG_ENABLE(gui,             [AC_HELP_STRING([--enable-gui], [enable GUI (default=yes)])], [WANT_SDLGUI=$enableval], [WANT_SDLGUI=yes])
113
114AC_ARG_ENABLE(opengl,          [AC_HELP_STRING([--enable-opengl], [enable OpenGL (default=yes)])], [WANT_OPENGL=$enableval], [WANT_OPENGL=yes])
115
116AC_ARG_WITH(mesa-headers,      [AC_HELP_STRING([--with-mesa-headers], [Path to Mesa header files])], [WITH_MESAINC=$withval], [WITH_MESAINC=no])
117
118AC_ARG_ENABLE(nfpci,           [AC_HELP_STRING([--enable-nfpci], [enable NatFeat PCI (default=no)])], [WANT_NFPCI=$enableval], [WANT_NFPCI=no])
119
120AC_ARG_ENABLE(usbhost,         [AC_HELP_STRING([--enable-usbhost], [enable NatFeat USB (default=no)])], [WANT_USBHOST=$enableval], [WANT_USBHOST=no])
121
122AC_ARG_ENABLE(nfosmesa,        [AC_HELP_STRING([--enable-nfosmesa], [enable NatFeat OSMesa (default=no)])], [WANT_NFOSMESA=$enableval], [WANT_NFOSMESA=no])
123
124AC_ARG_ENABLE(nfjpeg,          [AC_HELP_STRING([--enable-nfjpeg], [enable NatFeat JPEG (default=yes)])], [WANT_NFJPEG=$enableval], [WANT_NFJPEG=yes])
125
126AC_ARG_ENABLE(nfclipbrd,       [AC_HELP_STRING([--enable-nfclipbrd], [enable NatFeat Clipboard (default=yes)])], [WANT_NFCLIPBRD=$enableval], [WANT_NFCLIPBRD=yes])
127
128AC_ARG_ENABLE(nfvdi,           [AC_HELP_STRING([--enable-nfvdi], [enable NatFeat VDI (default=yes)])], [WANT_NFVDI=$enableval], [WANT_NFVDI=yes])
129
130AC_ARG_ENABLE(scsi,            [AC_HELP_STRING([--enable-nfscsi], [enable NatFeat SCSI (default=yes)])], [WANT_NFSCSI=$enableval], [WANT_NFSCSI=yes])
131
132AC_ARG_ENABLE(nfexec,          [AC_HELP_STRING([--enable-nfexec], [enable NatFeat host file execution (default=yes)])], [WANT_NFEXEC=$enableval], [WANT_NFEXEC=yes])
133
134AC_ARG_ENABLE(ata-cdrom,       [AC_HELP_STRING([--enable-ata-cdrom], [enable ATA CD-ROM emulation (default=yes)])], [WANT_CDROM=$enableval], [WANT_CDROM=yes])
135
136AC_ARG_ENABLE(epslimiter,      [AC_HELP_STRING([--enable-epslimiter], [enable Exception per second limiter (default=no)])], [WANT_EPSLIMITER=$enableval], [WANT_EPSLIMITER=no])
137
138AC_ARG_ENABLE(lilo,            [AC_HELP_STRING([--enable-lilo], [enable Linux-m68k loader (default=no)])], WANT_LILO="$enableval", WANT_LILO="no")
139
140AC_ARG_ENABLE(rtctimer,        [AC_HELP_STRING([--enable-rtctimer], [enable Linux /dev/rtc as source timer (default=yes)])], WANT_RTCTIMER="$enableval", WANT_RTCTIMER="yes")
141
142AC_ARG_ENABLE(parallelx86,     [AC_HELP_STRING([--enable-parallelx86], [enable Linux X86 hw access for parallel port (default=no)])], [WANT_PARALLELX86=$enableval], [WANT_PARALLELX86=no])
143
144AC_ARG_ENABLE(parport,         [AC_HELP_STRING([--enable-parport], [enable Linux /dev/parport access for parallel port (default=yes)])], [WANT_PARALLELPARPORT=$enableval], [WANT_PARALLELPARPORT=yes])
145
146AC_ARG_ENABLE(serialport,      [AC_HELP_STRING([--enable-serialport], [enable Unix /dev/ttySn serial port support (default=yes)])], [WANT_UNIXSERIALPORT=$enableval], [WANT_UNIXSERIALPORT=yes])
147
148AC_ARG_WITH(fink,              [AC_HELP_STRING([--with-fink], [Use Fink suite to build Aranym on MacOSX (default=no)])], [WITH_FINK=$withval], [WITH_FINK=no])
149
150AC_ARG_WITH(classicconfig,     [AC_HELP_STRING([--with-classicconfig], [Use Classic config names on MacOSX (default=no)])], [WITH_CLASSIC_CONFIG=$withval], [WITH_CLASSIC_CONFIG=no])
151
152dnl FPU emulation core.
153if [[ "x$WANT_MMU" = "xyes" ]]; then
154    SUGGESTED_AUTO_FPE_CORE_TEST_ORDER="mpfr ieee uae"
155else
156    SUGGESTED_AUTO_FPE_CORE_TEST_ORDER="ieee uae"
157fi
158AC_ARG_ENABLE(fpe,
159[AC_HELP_STRING([--enable-fpe=FPE], [specify which fpu emulator to use (default=auto)])],
160[ case "$enableval" in
161    dnl default is always ieee, if architecture has this fp format
162    auto)	FPE_CORE_TEST_ORDER=$SUGGESTED_AUTO_FPE_CORE_TEST_ORDER;;
163    ieee)	FPE_CORE_TEST_ORDER="ieee";;
164    uae)	FPE_CORE_TEST_ORDER="uae";;
165    x86)	FPE_CORE_TEST_ORDER="x86";;
166    mpfr)	FPE_CORE_TEST_ORDER="mpfr";;
167    *)		AC_MSG_ERROR([--enable-fpe takes only one of the following values: auto, uae, x86, ieee, mpfr]);;
168  esac
169],
170[ FPE_CORE_TEST_ORDER=$SUGGESTED_AUTO_FPE_CORE_TEST_ORDER
171])
172
173dnl Addressing modes.
174AC_ARG_ENABLE(addressing,
175[AC_HELP_STRING([--enable-addressing=AM], [specify the addressing mode to use (default=fastest)])],
176[ case "$enableval" in
177    direct)	ADDRESSING_TEST_ORDER="direct";;
178    normal)	ADDRESSING_TEST_ORDER="normal";;
179    fixed)	ADDRESSING_TEST_ORDER="fixed";;
180    *)		AC_MSG_ERROR([--enable-addressing takes only one of the following values: direct, fixed, normal]);;
181  esac
182],
183[ ADDRESSING_TEST_ORDER="direct normal"
184])
185
186AC_ARG_ENABLE(addr-check,
187[AC_HELP_STRING([--enable-addr-check=AM], [specify the memory check to use (default=page)])],
188[ case "$enableval" in
189    no)		MEMORY_CHECK="no";;
190    full)	MEMORY_CHECK="full";;
191    page)	MEMORY_CHECK="page";;
192    hwsp)	MEMORY_CHECK="hwsp";;
193    pagehwsp)	MEMORY_CHECK="pagehwsp";;
194    sseg)	MEMORY_CHECK="sseg";;
195    *)		AC_MSG_ERROR([--enable-addr-check takes only one of the following values: no, full, page, hwsp, pagehwsp, sseg]);;
196  esac
197],
198[ MEMORY_CHECK="page"
199])
200
201dnl Experimental hacks around spcflags handling.
202AC_ARG_ENABLE(spcflags-excl, [AC_HELP_STRING([--enable-spcflags-excl], [enable exclusive spcflags handling (default=no)])], [WANT_SPCFLAGS_EXCL=$enableval], [WANT_SPCFLAGS_EXCL=no])
203
204dnl JIT compiler options.
205AC_ARG_ENABLE(jit-compiler, [AC_HELP_STRING([--enable-jit-compiler], [enable JIT compiler (default=no)])], [WANT_JIT=$enableval], [WANT_JIT=no])
206AC_ARG_ENABLE(jit2, [AC_HELP_STRING([--enable-jit2], [enable JIT (v2) compiler (experimental/ARM only) (default=no)])], [WANT_JIT2=$enableval], [WANT_JIT2=no])
207
208AC_ARG_ENABLE(jit-fpu,
209[AC_HELP_STRING([--enable-jit-fpu], [enable JIT compiler for FPU instructions (default=no)])], [WANT_JIT_FPU=$enableval], [WANT_JIT_FPU=no])
210
211AC_ARG_ENABLE(jit-debug,       [AC_HELP_STRING([--enable-jit-debug], [activate native code disassemblers (default=no)])], [WANT_JIT_DEBUG=$enableval], [WANT_JIT_DEBUG=no])
212
213AC_ARG_ENABLE(ethernet,        [AC_HELP_STRING([--enable-ethernet], [enable ethernet card emulation (default=yes)])], [WANT_ETHERNET=$enableval], [WANT_ETHERNET=yes])
214
215AC_ARG_ENABLE(bpf-ethernet,    [AC_HELP_STRING([--enable-bpf-ethernet], [enable ethernet card emulation using BPF (default=no)])], [WANT_BFP_ETHERNET=$enableval], [WANT_BFP_ETHERNET=no])
216
217AC_ARG_ENABLE(cxx-exceptions,  [AC_HELP_STRING([--enable-cxx-exceptions], [enable the use of C++ try/catch instead of setjmp/longjmp (default=yes)])], [WANT_CXX_EXCEPTIONS=$enableval], [WANT_CXX_EXCEPTIONS=yes])
218
219dnl Host OS type (host is build if not cross-compiling).
220ANDROID_OS=no
221case "$host_os" in
222  *android*)	OS_TYPE=linux
223		ANDROID_OS=yes
224		LIBS="$LIBS -lgnustl_static -llog"
225	;;
226  linux*)	OS_TYPE=linux;;
227  openbsd*)	OS_TYPE=openbsd
228		CFLAGS="$CFLAGS -I/usr/local/include"
229		LIBS="$LIBS -L/usr/local/lib"
230		;;
231  netbsd*)	OS_TYPE=netbsd;;
232  freebsd*|kfreebsd*-gnu)	OS_TYPE=freebsd;;
233  solaris*)	OS_TYPE=solaris;;
234  darwin*)	OS_TYPE=darwin;;
235  cygwin*)	OS_TYPE=cygwin;;
236  irix*)	OS_TYPE=irix;;
237  mint*)	OS_TYPE=mint;;
238  beos*|haiku*)	OS_TYPE=beos;;
239  mingw*)	OS_TYPE=mingw;;
240  *)		OS_TYPE=unknown;;
241esac
242AM_CONDITIONAL([OS_TYPE_linux], test "$OS_TYPE" = "linux")
243AM_CONDITIONAL([OS_TYPE_openbsd], test "$OS_TYPE" = "openbsd")
244AM_CONDITIONAL([OS_TYPE_netbsd], test "$OS_TYPE" = "netbsd")
245AM_CONDITIONAL([OS_TYPE_freebsd], test "$OS_TYPE" = "freebsd")
246AM_CONDITIONAL([OS_TYPE_solaris], test "$OS_TYPE" = "solaris")
247AM_CONDITIONAL([OS_TYPE_darwin], test "$OS_TYPE" = "darwin")
248AM_CONDITIONAL([OS_TYPE_cygwin], test "$OS_TYPE" = "cygwin")
249AM_CONDITIONAL([OS_TYPE_irix], test "$OS_TYPE" = "irix")
250AM_CONDITIONAL([OS_TYPE_mint], test "$OS_TYPE" = "mint")
251AM_CONDITIONAL([OS_TYPE_beos], test "$OS_TYPE" = "beos")
252AM_CONDITIONAL([OS_TYPE_mingw], test "$OS_TYPE" = "mingw")
253AM_CONDITIONAL([OS_TYPE_unknown], test "$OS_TYPE" = "unknown")
254AM_CONDITIONAL([ANDROID_OS], test "$ANDROID_OS" = "yes")
255AM_CONDITIONAL([WITH_FINK], test "$WITH_FINK" = "yes")
256if test "$OS_TYPE" = "unknown"; then
257  OS_TYPE=`echo $host_os | sed -e 's/-/_/g' | sed -e 's/\./_/g'`
258fi
259#
260# provide some defaults on cygwin,
261# where we use the MinGW version of the SDL library,
262# to simplify standard configuration.
263# But only if the user did not override it.
264#
265if test "$OS_TYPE" = "cygwin"; then
266  if test "$prefix" = NONE; then
267    prefix=/usr
268  fi
269fi
270DEFINES="$DEFINES -DOS_$OS_TYPE"
271AC_DEFINE_UNQUOTED([OS_TYPE], "$OS_TYPE", [Define OS type])
272
273if test "$OS_TYPE" = "darwin"; then
274	# Make sure MPFR (and other 3rd party libs installed by MacPorts) are found
275	# Note that the order of these flags may be different
276	# in the Xcode project, which is important atleast for the
277	# SDL framework because we want to use the headers from
278	# the official build rather than the ones from MacPorts,
279	# which are only suitable for a single target architecture
280	LDFLAGS="$LDFLAGS -L/opt/local/lib"
281	CPPFLAGS="$CPPFLAGS -I/opt/local/include"
282	# SOURCE_ROOT is set when running from Xcode project
283	if test "$XCODE_VERSION_ACTUAL" != "" -a "$SOURCE_ROOT" != ""; then
284		LDFLAGS="$LDFLAGS -L$SOURCE_ROOT/external/lib"
285		CPPFLAGS="$CPPFLAGS -I$SOURCE_ROOT/external/include"
286	fi
287fi
288
289dnl Target CPU type.
290ARCHFLAGS=
291HAVE_I386=false
292HAVE_ARM=false
293HAVE_SPARC=false
294HAVE_POWERPC=false
295HAVE_X86_64=false
296case "$host_cpu" in
297  i386* | i486* | i586* | i686* | i786* )
298	CPU_TYPE=i386
299	HAVE_I386=true
300	if [[ "x$OS_TYPE" = "xdarwin" ]]; then
301		ARCHFLAGS="-arch i386"
302        if [[ "x$DEVELOPER_SDK_DIR" = "x" ]]; then
303            DEVELOPER_SDK_DIR=/Developer/SDKs
304        fi
305        if [[ ! -d "$DEVELOPER_SDK_DIR" ]]; then
306            AC_MSG_ERROR([Cannot find SDKs directory at $DEVELOPER_SDK_DIR])
307        fi
308		case "$host_os" in
309			darwin8* | darwin9* )	ISYSROOT="-mmacosx-version-min=10.4 -isysroot $DEVELOPER_SDK_DIR/MacOSX10.4u.sdk";;
310			darwin10* )	ISYSROOT="-mmacosx-version-min=10.4 -isysroot $DEVELOPER_SDK_DIR/MacOSX10.5.sdk";;
311			darwin11* | darwin12* )	ISYSROOT="-mmacosx-version-min=10.5";;
312			darwin13* )	ISYSROOT="-mmacosx-version-min=10.7";;
313			darwin14* )	ISYSROOT="-mmacosx-version-min=10.10";;
314            darwin15* )	ISYSROOT="-mmacosx-version-min=10.10";;
315            darwin16* )	ISYSROOT="-mmacosx-version-min=10.10";;
316            darwin17* )	ISYSROOT="-mmacosx-version-min=10.13";;
317			*)
318				AC_MSG_ERROR([Sorry, unknown Darwin version: $host_os])
319				;;
320		esac
321		dnl Add the ARCHFLAGS here to let configure check for the target and not host capabilities.
322		CPPFLAGS="$CPPFLAGS $ISYSROOT $ARCHFLAGS"
323		LDFLAGS="$LDFLAGS $ISYSROOT $ARCHFLAGS"
324	fi
325	;;
326  sparc* ) CPU_TYPE=sparc HAVE_SPARC=true;;
327  arm* ) CPU_TYPE=arm HAVE_ARM=true
328         CFLAGS="$CFLAGS -ffast-math"
329         CXXFLAGS="$CXXFLAGS -ffast-math"
330  	;;
331  powerpc* )
332	CPU_TYPE=powerpc
333	HAVE_POWERPC=true
334	if [[ "x$OS_TYPE" = "xdarwin" ]]; then
335		ARCHFLAGS="-arch ppc"
336		ISYSROOT="-mmacosx-version-min=10.3"
337		dnl Add the ARCHFLAGS here to let configure check for the target and not host capabilities.
338		CPPFLAGS="$CPPFLAGS $ISYSROOT $ARCHFLAGS"
339		LDFLAGS="$LDFLAGS $ISYSROOT $ARCHFLAGS"
340	fi
341	;;
342  x86_64* ) CPU_TYPE=x86_64 HAVE_X86_64=true;;
343  *) CPU_TYPE=unknown;;
344esac
345AM_CONDITIONAL([CPU_TYPE_x86], test "$CPU_TYPE" = "i386")
346AM_CONDITIONAL([CPU_TYPE_x86_64], test "$CPU_TYPE" = "x86_64")
347AM_CONDITIONAL([CPU_TYPE_sparc], test "$CPU_TYPE" = "sparc")
348AM_CONDITIONAL([CPU_TYPE_arm], test "$CPU_TYPE" = "arm")
349AM_CONDITIONAL([CPU_TYPE_powerpc], test "$CPU_TYPE" = "powerpc")
350AM_CONDITIONAL([CPU_TYPE_unknown], test "$CPU_TYPE" = "unknown")
351if test "$CPU_TYPE" = "unknown"; then
352  CPU_TYPE=`echo $host_cpu | sed -e 's/-/_/g'`
353fi
354DEFINES="$DEFINES -DCPU_$CPU_TYPE"
355AC_DEFINE_UNQUOTED([CPU_TYPE], "$CPU_TYPE", [Define CPU type])
356
357dnl Checks for programs.
358AC_PROG_CC
359AC_PROG_CC_C_O
360AC_PROG_OBJC
361AC_PROG_CPP
362AC_PROG_CXX
363AC_PROG_CXXCPP
364AX_PROG_CC_FOR_BUILD
365AX_PROG_CXX_FOR_BUILD
366AC_PROG_MAKE_SET
367AC_PROG_INSTALL
368AC_PROG_MKDIR_P
369AC_PROG_RANLIB
370AC_PATH_PROG(PERL, perl)
371AC_CHECK_TOOLS(WINDRES, [windres], :)
372PKG_PROG_PKG_CONFIG
373m4_ifndef([PKG_CHECK_MODULES], [AC_DEFUN([PKG_CHECK_MODULES], [true])])
374
375dnl Checks for header files.
376AC_HEADER_STDC
377AC_HEADER_DIRENT
378AC_CHECK_HEADERS(unistd.h fcntl.h sys/mman.h mach/mach.h sys/ioctl.h)
379AC_CHECK_HEADERS(getopt.h)
380AC_CHECK_HEADERS(termios.h termio.h alloca.h sys/statfs.h sys/statvfs.h)
381AC_CHECK_HEADERS(sys/types.h sys/stat.h sys/vfs.h utime.h sys/param.h)
382AC_CHECK_HEADERS(sys/mount.h types.h stat.h ext2fs/ext2_fs.h)
383AC_CHECK_HEADERS(sys/socket.h)
384AC_CHECK_HEADERS(linux/if.h linux/if_tun.h net/if.h net/if_tun.h, [], [], [
385#ifdef HAVE_SYS_SOCKET_H
386#include <sys/socket.h>
387#endif
388])
389AC_CHECK_HEADERS(net/bpf.h)
390
391dnl Checks for typedefs, structures, and compiler characteristics.
392AC_C_BIGENDIAN
393AC_C_CONST
394AC_C_INLINE
395AC_C_VOLATILE
396AC_CHECK_SIZEOF(short, 2)
397AC_CHECK_SIZEOF(int, 4)
398AC_CHECK_SIZEOF(long, 4)
399AC_CHECK_SIZEOF(long long, 8)
400AC_CHECK_SIZEOF(float, 4)
401AC_CHECK_SIZEOF(double, 8)
402AC_CHECK_SIZEOF(long double, 12)
403AC_CHECK_SIZEOF(void *, 4)
404AC_TYPE_OFF_T
405AC_CHECK_TYPE(loff_t, off_t)
406AC_TYPE_SIZE_T
407AC_CHECK_TYPE(ssize_t, size_t)
408AC_TYPE_SIGNAL
409AC_HEADER_TIME
410AC_STRUCT_TM
411AC_SYS_LARGEFILE
412gl_TM_GMTOFF
413gl_STAT_TIME
414
415AC_CXX_BOOL
416
417dnl Checks for libraries
418AC_CHECK_LIB(m, sin, [LIBS="$LIBS -lm"])
419
420dnl Checks for library functions.
421AC_CHECK_FUNCS(strdup)
422AC_CHECK_FUNCS(sigaction signal sigsetjmp)
423AC_CHECK_FUNCS(mmap mprotect munmap)
424AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect sbrk)
425AC_CHECK_FUNCS(strchr memcpy bcopy)
426AC_CHECK_FUNCS(usleep gettimeofday)
427AC_CHECK_FUNCS(fseeko fsync futimes futimens link readlink symlink lstat truncate pathconf)
428AC_CHECK_FUNCS(canonicalize_file_name realpath)
429
430AC_CACHE_CHECK([whether sigsetjmp is supported],
431  ac_cv_have_sigsetjmp, [
432  AC_TRY_LINK([
433    #include <signal.h>
434    #include <setjmp.h>
435  ], [
436    sigjmp_buf b;
437    sigsetjmp(b, 1);
438    siglongjmp(b, 1);
439  ],
440  ac_cv_have_sigsetjmp=yes, ac_cv_have_sigsetjmp=no
441  )
442])
443if test "$ac_cv_have_sigsetjmp" = "yes"; then
444  AC_DEFINE([HAVE_SIGSETJMP], 1)
445fi
446
447dnl Darwin seems to define mach_task_self() instead of task_self().
448AC_CHECK_FUNCS(mach_task_self task_self)
449
450AC_DEFINE([DIRSEPARATOR], "/", [Default directory separator])
451
452AH_TEMPLATE([ARANYMHOME], [Default ARAnyM directory])
453AH_TEMPLATE([HAVE_O_FSYNC], [Define if you want to use FreeBSD's imitation of O_SYNC])
454AH_TEMPLATE([ARANYMCONFIG], [Default ARAnyM config file])
455AH_TEMPLATE([ARANYMNVRAM], [Default ARAnyM NVRAM file])
456AH_TEMPLATE([ARANYMKEYMAP], [Default ARAnyM keymap])
457AH_TEMPLATE([HAVE_LIBUDEV], [Define if you have <libudev.h> and libraries])
458
459if test "$OS_TYPE" = "linux"; then
460   AC_CHECK_HEADERS([libudev.h])
461   if test "$ac_cv_header_libudev_h" = yes; then
462      AC_CHECK_LIB(udev, udev_monitor_new_from_netlink, [LIBS="$LIBS -ludev"])
463      if test $ac_cv_lib_udev_udev_monitor_new_from_netlink = yes; then
464        AC_DEFINE([HAVE_LIBUDEV])
465      fi
466   fi
467fi
468
469case "$host_os" in
470  linux*)
471    ;;
472  cygwin*|mingw*)
473    AC_DEFINE([ARANYMHOME], "aranym")
474    ;;
475  solaris*)
476    AC_DEFINE([_XOPEN_SOURCE], 500, [Define if needed])
477    AC_DEFINE([_POSIX_C_SOURCE], 199506L, [Define if needed])
478    DEFINES="$DEFINES -DBSD_COMP -D__EXTENSIONS__"
479    ;;
480  freebsd*|kfreebsd*-gnu)
481    AC_DEFINE([HAVE_O_FSYNC], 1)
482    ;;
483  darwin*)
484	AC_DEFINE([HAVE_O_FSYNC], 1)
485	if test "x$WITH_FINK" = "xyes"; then
486		AC_DEFINE([ARANYMHOME], "aranym")
487	else
488		AC_DEFINE([ARANYMHOME], "ARAnyM")
489
490		if test "x$WITH_CLASSIC_CONFIG" = "xyes"; then
491			echo "Using classic config"
492			AC_DEFINE([ARANYMCONFIG], "config")
493			AC_DEFINE([ARANYMNVRAM], "nvram")
494			AC_DEFINE([ARANYMKEYMAP], "keymap")
495		else
496			echo "Using preference files"
497			AC_DEFINE([ARANYMCONFIG], "org.aranym.amcfg")
498			AC_DEFINE([ARANYMNVRAM], "org.aranym.nvram")
499			AC_DEFINE([ARANYMKEYMAP], "org.aranym.keymap")
500		fi
501
502		BUNDLE_FRAMEWORKS= dnl Empty list of frameworks to bundle
503
504		dnl Check for some important frameworks
505		ARANYM_CHECK_FRAMEWORK(AppKit, [])
506		ARANYM_CHECK_FRAMEWORK(CoreFoundation, [#include <CoreFoundation/CoreFoundation.h>])
507		ARANYM_CHECK_FRAMEWORK(IOKit, [#include <IOKit/IOKitLib.h>])
508		ARANYM_CHECK_FRAMEWORK(Security, [#include <Security/Security.h>])
509
510        dnl We (Mac OS X target) don't want to use PKG_CONFIG even if it exists (e.g. in /opt)
511        PKG_CONFIG=""
512
513	fi
514	;;
515  beos*|haiku*)
516    dnl Find tools needed to add resources
517    AC_PATH_PROG(BEOS_XRES, xres, [AC_MSG_ERROR([xres not found.])])
518    AC_PATH_PROG(BEOS_RC, rc, [AC_MSG_ERROR([rc not found.])])
519    AC_PATH_PROG(BEOS_SETVERSION, setversion, [AC_MSG_ERROR([setversion not found.])])
520    WANT_UNIXSERIALPORT=no
521    ac_cv_tun_tap_support=no
522    ;;
523  *)
524    ;;
525esac
526
527dnl Check that the host supports TUN/TAP devices
528AC_CACHE_CHECK([whether TUN/TAP is supported],
529  ac_cv_tun_tap_support, [
530  AC_TRY_COMPILE([
531    #if defined(HAVE_LINUX_IF_H) && defined(HAVE_LINUX_IF_TUN_H)
532    #ifdef HAVE_SYS_SOCKET_H
533    #include <sys/socket.h>
534    #endif
535    #include <linux/if.h>
536    #include <linux/if_tun.h>
537    #endif
538    #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_IF_TUN_H)
539    #include <net/if.h>
540    #include <net/if_tun.h>
541    #endif
542  ], [
543    struct ifreq ifr;
544    memset(&ifr, 0, sizeof(ifr));
545    ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
546  ],
547  ac_cv_tun_tap_support=yes, ac_cv_tun_tap_support=no
548  )
549])
550
551dnl Check that the host supports BPF devices
552AC_CACHE_CHECK([whether BPF is supported],
553  ac_cv_bpf_support, [
554  AC_TRY_COMPILE([
555    #if defined(HAVE_NET_BPF_H)
556    #include <net/bpf.h>
557    #endif
558  ], [
559    struct bpf_program filter;
560  ],
561  ac_cv_bpf_support=yes, ac_cv_bpf_support=no
562  )
563])
564
565
566dnl Various checks if the system supports vm_allocate() and the like functions.
567have_mach_vm=no
568if [[ "x$ac_cv_func_vm_allocate" = "xyes" -a "x$ac_cv_func_vm_deallocate" = "xyes" -a \
569      "x$ac_cv_func_vm_protect" = "xyes" ]]; then
570  have_mach_vm=yes
571fi
572AC_TRANSLATE_DEFINE(HAVE_MACH_VM, $have_mach_vm,
573  [Define if your system has a working vm_allocate()-based memory allocator.])
574
575case "$host_os" in
576  darwin*)	OSdarwinReq="#define OS_darwin";;
577  *)		OSdarwinReq= ;;
578esac
579
580dnl Check that vm_allocate(), vm_protect() work
581if [[ "x$have_mach_vm" = "xyes" ]]; then
582
583AC_CACHE_CHECK([whether vm_protect works],
584  ac_cv_vm_protect_works, [
585  AC_LANG_SAVE
586  AC_LANG_CPLUSPLUS
587  ac_cv_vm_protect_works=yes
588  dnl First the tests that should segfault
589  for test_def in NONE_READ NONE_WRITE READ_WRITE; do
590    AC_TRY_RUN([
591      #define CONFIGURE_TEST_VM_MAP
592      #define TEST_VM_PROT_$test_def
593	  $OSdarwinReq
594      #include "$srcdir/src/Unix/vm_alloc.cpp"
595    ], ac_cv_vm_protect_works=no, rm -f core,
596    dnl When cross-compiling, do not assume anything
597    ac_cv_vm_protect_works="guessing no"
598    )
599  done
600  AC_TRY_RUN([
601    #define CONFIGURE_TEST_VM_MAP
602    #define TEST_VM_PROT_RDWR_WRITE
603    $OSdarwinReq
604    #include "$srcdir/src/Unix/vm_alloc.cpp"
605  ], , ac_cv_vm_protect_works=no,
606  dnl When cross-compiling, do not assume anything
607  ac_cv_vm_protect_works="guessing no"
608  )
609  AC_LANG_RESTORE
610  ]
611)
612
613dnl Remove support for vm_allocate() if vm_protect() does not work
614if [[ "x$have_mach_vm" = "xyes" ]]; then
615  case $ac_cv_vm_protect_works in
616    *yes) have_mach_vm=yes;;
617    *no) have_mach_vm=no;;
618  esac
619fi
620AC_TRANSLATE_DEFINE(HAVE_MACH_VM, $have_mach_vm,
621  [Define if your system has a working vm_allocate()-based memory allocator.])
622
623fi dnl HAVE_MACH_VM
624
625dnl Various checks if the system supports mmap() and the like functions.
626dnl ... and Mach memory allocators are not supported
627have_mmap_vm=no
628if [[ "x$ac_cv_func_mmap" = "xyes" -a "x$ac_cv_func_munmap" = "xyes" -a \
629      "x$ac_cv_func_mprotect" = "xyes" ]]; then
630  if [[ "x$have_mach_vm" = "xno" ]]; then
631    have_mmap_vm=yes
632  fi
633fi
634AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, $have_mmap_vm,
635  [Define if your system has a working mmap()-based memory allocator.])
636
637dnl Check that mmap() and associated functions work.
638if [[ "x$have_mmap_vm" = "xyes" ]]; then
639
640dnl Check if we have a working anonymous mmap()
641AC_CACHE_CHECK([whether mmap supports MAP_ANON],
642  ac_cv_mmap_anon, [
643  AC_LANG_SAVE
644  AC_LANG_CPLUSPLUS
645  AC_TRY_RUN([
646    #define HAVE_MMAP_ANON
647    #define CONFIGURE_TEST_VM_MAP
648    #define TEST_VM_MMAP_ANON
649    #include "$srcdir/src/Unix/vm_alloc.cpp"
650  ], ac_cv_mmap_anon=yes, ac_cv_mmap_anon=no,
651  dnl When cross-compiling, do not assume anything.
652  ac_cv_mmap_anon="guessing no"
653  )
654  AC_LANG_RESTORE
655  ]
656)
657AC_TRANSLATE_DEFINE(HAVE_MMAP_ANON, $ac_cv_mmap_anon,
658  [Define if <sys/mman.h> defines MAP_ANON and mmap()'ing with MAP_ANON works.])
659
660AC_CACHE_CHECK([whether mmap supports MAP_ANONYMOUS],
661  ac_cv_mmap_anonymous, [
662  AC_LANG_SAVE
663  AC_LANG_CPLUSPLUS
664  AC_TRY_RUN([
665    #define HAVE_MMAP_ANONYMOUS
666    #define CONFIGURE_TEST_VM_MAP
667    #define TEST_VM_MMAP_ANON
668    #include "$srcdir/src/Unix/vm_alloc.cpp"
669  ], ac_cv_mmap_anonymous=yes, ac_cv_mmap_anonymous=no,
670  dnl When cross-compiling, do not assume anything.
671  ac_cv_mmap_anonymous="guessing no"
672  )
673  AC_LANG_RESTORE
674  ]
675)
676AC_TRANSLATE_DEFINE(HAVE_MMAP_ANONYMOUS, $ac_cv_mmap_anonymous,
677  [Define if <sys/mman.h> defines MAP_ANONYMOUS and mmap()'ing with MAP_ANONYMOUS works.])
678
679AC_CACHE_CHECK([whether mprotect works],
680  ac_cv_mprotect_works, [
681  AC_LANG_SAVE
682  AC_LANG_CPLUSPLUS
683  ac_cv_mprotect_works=yes
684  dnl First the tests that should segfault
685  for test_def in NONE_READ NONE_WRITE READ_WRITE; do
686    AC_TRY_RUN([
687      #define CONFIGURE_TEST_VM_MAP
688      #define TEST_VM_PROT_$test_def
689      #include "$srcdir/src/Unix/vm_alloc.cpp"
690    ], ac_cv_mprotect_works=no, rm -f core,
691    dnl When cross-compiling, do not assume anything
692    ac_cv_mprotect_works="guessing no"
693    )
694  done
695  AC_TRY_RUN([
696    #define CONFIGURE_TEST_VM_MAP
697    #define TEST_VM_PROT_RDWR_WRITE
698    #include "$srcdir/src/Unix/vm_alloc.cpp"
699  ], , ac_cv_mprotect_works=no,
700  dnl When cross-compiling, do not assume anything
701  ac_cv_mprotect_works="guessing no"
702  )
703  AC_LANG_RESTORE
704  ]
705)
706
707dnl Remove support for mmap() if mprotect() does not work
708if [[ "x$have_mmap_vm" = "xyes" ]]; then
709  case $ac_cv_mprotect_works in
710    *yes) have_mmap_vm=yes;;
711    *no) have_mmap_vm=no;;
712  esac
713fi
714AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, $have_mmap_vm,
715  [Define if your system has a working mmap()-based memory allocator.])
716
717fi dnl HAVE_MMAP_VM
718
719AH_TEMPLATE(HAVE_WIN32_VM, [Define if your system has a working VirtualAlloc()-based memory allocator.])
720if test "$OS_TYPE" = mingw; then
721	AC_DEFINE([HAVE_WIN32_VM])
722        if $HAVE_I386; then
723		LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
724	fi
725fi
726
727dnl Check signal handlers need to be reinstalled
728AC_CACHE_CHECK([whether signal handlers need to be reinstalled],
729  ac_cv_signal_need_reinstall, [
730  AC_LANG_SAVE
731  AC_LANG_CPLUSPLUS
732  AC_TRY_RUN([
733    #include <stdlib.h>
734    #ifdef HAVE_UNISTD_H
735    #include <unistd.h>
736    #endif
737    #include <signal.h>
738    static int handled_signal = 0;
739    RETSIGTYPE sigusr1_handler(int) { handled_signal++; }
740    int main(void) { /* returns 0 if signals need not to be reinstalled */
741      signal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1);
742      exit(handled_signal == 2);
743    }
744  ], ac_cv_signal_need_reinstall=yes, ac_cv_signal_need_reinstall=no,
745  dnl When cross-compiling, do not assume anything.
746  ac_cv_signal_need_reinstall="guessing yes"
747  )
748  AC_LANG_RESTORE
749  ]
750)
751AC_TRANSLATE_DEFINE(SIGNAL_NEED_REINSTALL, $ac_cv_signal_need_reinstall,
752  [Define if your system requires signals to be reinstalled.])
753
754dnl Check if sigaction handlers need to be reinstalled
755AC_CACHE_CHECK([whether sigaction handlers need to be reinstalled],
756  ac_cv_sigaction_need_reinstall, [
757  AC_LANG_SAVE
758  AC_LANG_CPLUSPLUS
759  AC_TRY_RUN([
760    #include <stdlib.h>
761    #ifdef HAVE_UNISTD_H
762    #include <unistd.h>
763    #endif
764    #include <signal.h>
765    static int handled_signal = 0;
766    RETSIGTYPE sigusr1_handler(int) { handled_signal++; }
767    typedef RETSIGTYPE (*signal_handler)(int);
768    static signal_handler mysignal(int sig, signal_handler handler) {
769      struct sigaction old_sa;
770      struct sigaction new_sa;
771      new_sa.sa_handler = handler;
772      return ((sigaction(sig,&new_sa,&old_sa) < 0) ? SIG_IGN : old_sa.sa_handler);
773    }
774    int main(void) { /* returns 0 if signals need not to be reinstalled */
775      mysignal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1);
776      exit(handled_signal == 2);
777    }
778  ], ac_cv_sigaction_need_reinstall=yes, ac_cv_sigaction_need_reinstall=no,
779  dnl When cross-compiling, do not assume anything.
780  ac_cv_sigaction_need_reinstall="guessing yes"
781  )
782  AC_LANG_RESTORE
783  ]
784)
785AC_TRANSLATE_DEFINE(SIGACTION_NEED_REINSTALL, $ac_cv_sigaction_need_reinstall,
786  [Define if your system requires sigactions to be reinstalled.])
787
788dnl Check if we have vasprintf (_GNU_SOURCE)
789AC_CACHE_CHECK([for vasprintf],
790  ac_cv_have_vasprintf, [
791  AC_LANG_SAVE
792  AC_LANG_CPLUSPLUS
793  AC_TRY_COMPILE([
794    #define _GNU_SOURCE
795    #include <stdarg.h>
796    #include <stdio.h>
797  ], [
798    va_list a;
799    vasprintf(NULL, NULL, a);
800  ],
801  [ac_cv_have_vasprintf=yes],
802  [ac_cv_have_vasprintf=no]
803  )
804  AC_LANG_RESTORE
805  ]
806)
807AC_TRANSLATE_DEFINE(HAVE_VASPRINTF, $ac_cv_have_vasprintf,
808  [Define if your system supports vasprintf function with GNU SOURCEs])
809if [[ "x$ac_cv_have_vasprintf" = "xyes" ]]; then
810  DEFINES="$DEFINES -D_GNU_SOURCE"
811fi
812
813AC_CACHE_CHECK([for sighandler_t],
814  ac_cv_have_sighandler_t, [
815  AC_LANG_SAVE
816  AC_LANG_CPLUSPLUS
817  AC_TRY_COMPILE([
818    #define _GNU_SOURCE
819    #include <signal.h>
820    #include <stdio.h>
821  ], [
822    signal(0, (sighandler_t)NULL);
823  ],
824  [ac_cv_have_sighandler_t=yes],
825  [ac_cv_have_sighandler_t=no]
826  )
827  AC_LANG_RESTORE
828  ]
829)
830AC_TRANSLATE_DEFINE(HAVE_SIGHANDLER_T, $ac_cv_have_sighandler_t,
831  [Define if <signal.h> doesn't define sighandler_t])
832
833dnl Check if we have getopt_long
834AC_CACHE_CHECK([for getopt_long],
835  ac_cv_have_getopt_long, [
836  AC_LANG_SAVE
837  AC_LANG_CPLUSPLUS
838  AC_TRY_COMPILE([
839    #define _GNU_SOURCE
840    #include <unistd.h>
841    #include <getopt.h>
842  ], [
843    getopt_long(0, NULL, NULL, NULL, NULL);
844  ],
845  [ac_cv_have_getopt_long=yes],
846  [ac_cv_have_getopt_long=no]
847  )
848  AC_LANG_RESTORE
849  ]
850)
851AC_TRANSLATE_DEFINE(HAVE_GETOPT_H, $ac_cv_have_getopt_long)
852
853AM_CONDITIONAL([NEED_GETOPT], test "$ac_cv_have_getopt_long" = "no")
854
855
856dnl Check if we have __builtin_bswap16/32
857AC_CACHE_CHECK([for __builtin_bswap16],
858  ac_cv_have___builtin_bswap16, [
859  AC_LANG_SAVE
860  AC_LANG_CPLUSPLUS
861  AC_TRY_COMPILE([
862    #include <stdarg.h>
863    #include <stdio.h>
864    unsigned short v;
865  ], [
866    v = __builtin_bswap16(v);
867  ],
868  [ac_cv_have___builtin_bswap16=yes],
869  [ac_cv_have___builtin_bswap16=no]
870  )
871  AC_LANG_RESTORE
872  ]
873)
874AC_TRANSLATE_DEFINE(HAVE___BUILTIN_BSWAP16, $ac_cv_have___builtin_bswap16,
875  [Define if your compiler supports __builtin_bswap16])
876AC_CACHE_CHECK([for __builtin_bswap32],
877  ac_cv_have___builtin_bswap32, [
878  AC_LANG_SAVE
879  AC_LANG_CPLUSPLUS
880  AC_TRY_COMPILE([
881    #include <stdarg.h>
882    #include <stdio.h>
883    unsigned int v;
884  ], [
885    v = __builtin_bswap32(v);
886  ],
887  [ac_cv_have___builtin_bswap32=yes],
888  [ac_cv_have___builtin_bswap32=no]
889  )
890  AC_LANG_RESTORE
891  ]
892)
893AC_TRANSLATE_DEFINE(HAVE___BUILTIN_BSWAP32, $ac_cv_have___builtin_bswap32,
894  [Define if your compiler supports __builtin_bswap32])
895
896
897AH_TEMPLATE([MAP_META_TO_CONTROL], [Define if you want to map the meta key to the emulated control key])
898AH_TEMPLATE([MAP_CONTROL_TO_CONTROL], [Define if you want to map the control key to the emulated control key])
899case $CONTROL_KEY in
900	meta)
901		AC_DEFINE([MAP_META_TO_CONTROL], 1)
902		;;
903	both)
904		AC_DEFINE([MAP_META_TO_CONTROL], 1)
905		AC_DEFINE([MAP_CONTROL_TO_CONTROL], 1)
906		;;
907	ctrl)
908		AC_DEFINE([MAP_CONTROL_TO_CONTROL], 1)
909		;;
910esac
911
912if [[ "x$WANT_JIT" = "xyes" ]]; then
913  WANT_EXSIGSEGV=yes
914  MEMORY_CHECK=sseg
915fi
916
917AH_TEMPLATE([ARAM_PAGE_CHECK], [Define if you want to try out a different memory check])
918AH_TEMPLATE([NOCHECKBOUNDARY], [Define if you don't want to use check memory boundary])
919AH_TEMPLATE([EXTENDED_SIGSEGV], [Define if you want to use extended segfault handler])
920AH_TEMPLATE([RAMENDNEEDED], [Define if you want protect end of memory])
921AH_TEMPLATE([HW_SIGSEGV], [Define if you want to use extended segfault handler also for HW space])
922case $MEMORY_CHECK in
923  no)   AC_DEFINE([NOCHECKBOUNDARY], 1)
924        ;;
925  page) AC_DEFINE([ARAM_PAGE_CHECK], 1)
926        ;;
927  hwsp) ADDRESSING_TEST_ORDER="fixed"
928        WANT_EXSIGSEGV="yes"
929        AC_DEFINE([NOCHECKBOUNDARY], 1)
930	AC_DEFINE([EXTENDED_SIGSEGV], 1)
931        AC_DEFINE([RAMENDNEEDED])
932        ;;
933  pagehwsp) ADDRESSING_TEST_ORDER="fixed"
934        WANT_EXSIGSEGV="yes"
935        AC_DEFINE([ARAM_PAGE_CHECK], 1)
936        AC_DEFINE([NOCHECKBOUNDARY], 1)
937	AC_DEFINE([EXTENDED_SIGSEGV], 1)
938        AC_DEFINE([RAMENDNEEDED], 1)
939        ;;
940   sseg) ADDRESSING_TEST_ORDER="fixed"
941        WANT_EXSIGSEGV="yes"
942        AC_DEFINE([NOCHECKBOUNDARY], 1)
943	AC_DEFINE([RAMENDNEEDED], 1)
944        AC_DEFINE([EXTENDED_SIGSEGV], 1)
945	AC_DEFINE([HW_SIGSEGV], 1)
946        ;;
947  *) ;;
948esac
949
950dnl Full opcode's history
951if [[ "x$WANT_HISTORY" = "xyes" ]]; then
952    AC_DEFINE([FULL_HISTORY], 1, [Define if you want to use full history])
953fi
954
955dnl CPU flight recorder
956if [[ "x$WANT_FLIGHTRECORDER" = "xyes" ]]; then
957     AC_DEFINE([FLIGHT_RECORDER], 1, [Define if you want to use CPU flight recorder])
958fi
959
960dnl ATA CD-ROM emulation
961if [[ "x$WANT_CDROM" = "xyes" ]]; then
962     AC_DEFINE([SUPPORT_CDROM], 1, [Define if you want to use ATA CD-ROM emulation])
963fi
964
965dnl Full MMU
966if [[ "x$WANT_MMU" = "xyes" ]]; then
967    AC_DEFINE([FULLMMU], 1, [Define if using full MMU])
968fi
969AM_CONDITIONAL([FULLMMU], test "$WANT_MMU" = "yes")
970
971dnl Small ATC
972if [[ "x$ATC_TYPE" = "xsmall" ]]; then
973    AC_DEFINE([SMALL_ATC], 1, [Define if using only small ATC])
974fi
975
976dnl Full ATC
977if [[ "x$ATC_TYPE" = "xno" ]]; then
978    AC_DEFINE([DISABLE_ATC], 1, [Define if not using full ATC])
979fi
980
981dnl DSP
982if [[ "x$WANT_DSP" = "xyes" ]]; then
983    AC_DEFINE([DSP_EMULATION], 1, [Define if using DSP])
984    dnl DSP disassembler
985    if [[ "x$WANT_DSP_DISASM" = "xyes" ]]; then
986        AC_DEFINE([DSP_DISASM], 1, [Define if DSP disassembly])
987    fi
988fi
989AM_CONDITIONAL([WANT_DSP], test "$WANT_DSP" = "yes")
990AM_CONDITIONAL([WANT_DSP_DISASM], test "$WANT_DSP_DISASM" = "yes")
991
992AH_TEMPLATE([FIXED_VIDEORAM], [Define if you want fixed position of VideoRAM])
993AH_TEMPLATE([PROTECT2K], [Define if you want to protect first 2kB of RAM against user mode access])
994
995dnl protect first 2kB of RAM
996if [[ "x$WANT_PROTECT2K" != "xno" ]]; then
997  AC_DEFINE([PROTECT2K], 1, [Define if you want to protect first 2kB of RAM against user mode access])
998fi
999
1000dnl fixed size FastRAM
1001if [[ "x$WANT_FIXEDFASTRAM" != "xno" ]]; then
1002  AC_DEFINE_UNQUOTED([FixedSizeFastRAM], $WANT_FIXEDFASTRAM, [Define if you want FastRAM of fixed size])
1003fi
1004
1005dnl fixed start of VideoRAM
1006if [[ "x$WANT_FIXEDVIDEORAM" = "xyes" ]]; then
1007  AC_DEFINE([FIXED_VIDEORAM], 1)
1008else
1009  if [[ "x$WANT_MMU" = "xyes" ]]; then
1010    AC_MSG_WARN([Protection of first 2kB RAM enabled as well - won't hurt])
1011    AC_DEFINE([PROTECT2K], 1)
1012  fi
1013  if [[ "x$WANT_BLITSDLBLIT" = "xyes" ]]; then
1014    AC_MSG_WARN([Blitter SDL surface blitting support needs fixed position of VideoRAM])
1015    AC_DEFINE([FIXED_VIDEORAM], 1)
1016    WANT_FIXEDVIDEORAM="yes"
1017  fi
1018fi
1019
1020dnl Full STOP instruction
1021if [[ "x$WANT_REALSTOP" = "xyes" ]]; then
1022  AC_DEFINE([ENABLE_REALSTOP], 1, [Define if you want real STOP instruction implementation])
1023  WANT_SPCFLAGS_EXCL=yes
1024fi
1025
1026dnl Blitter memmove acceleration
1027if [[ "x$WANT_BLITMEMMOVE" = "xyes" ]]; then
1028  AC_DEFINE([BLITTER_MEMMOVE], 1, [Define if you want accelerated blitter output])
1029fi
1030
1031  if [[ "x$WANT_BLITSDLBLIT" = "xyes" ]]; then
1032    AC_MSG_WARN([Blitter SDL surface blitting support needs fixed position of VideoRAM])
1033    AC_DEFINE([FIXED_VIDEORAM], 1)
1034    WANT_FIXEDVIDEORAM="yes"
1035  fi
1036dnl Blitter SDL surface blitting
1037if [[ "x$WANT_BLITSDLBLIT" = "xyes" ]]; then
1038  AC_DEFINE([BLITTER_SDLBLIT], 1, [Define if you want even more accelerated blitter output])
1039  AC_DEFINE([BLITTER_MEMMOVE], 1, [Define if you want accelerated blitter output])	dnl required for the SDLBLIT
1040fi
1041
1042AH_TEMPLATE([ETHERNET_SUPPORT], [Define if you want to use ethernet card emulation])
1043dnl Ethernet card emulation
1044HAVE_ETHERNET=no
1045NEED_ARATAPIF=no
1046if [[ "x$WANT_ETHERNET" = "xyes" ]]; then
1047  if [[ "x$ac_cv_tun_tap_support" = "xyes" ]]; then
1048    AC_DEFINE([ETHERNET_SUPPORT], 1)
1049    NEED_ARATAPIF="yes"
1050    HAVE_ETHERNET="yes"
1051  elif test "x$OS_TYPE" = "xcygwin" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1052    AC_DEFINE([ETHERNET_SUPPORT], 1)
1053    HAVE_ETHERNET="yes"
1054  elif [[ "x$OS_TYPE" = "xdarwin" ]]; then
1055    AC_DEFINE([ETHERNET_SUPPORT], 1)
1056    if [[ "x$WANT_BFP_ETHERNET" = "xyes" ]]; then
1057      AC_TRANSLATE_DEFINE(ENABLE_BPF, $ac_cv_bpf_support,
1058        [Define if your system supports BPF devices.])
1059    else
1060      AC_MSG_WARN([Ethernet won't work without TunTap driver for Mac OS X. See http://tuntaposx.sourceforge.net/])
1061    fi
1062    HAVE_ETHERNET="yes"
1063  else
1064    AC_MSG_WARN([Ethernet interface not supported on your system])
1065  fi
1066fi
1067AM_CONDITIONAL([NEED_ARATAPIF], test "$NEED_ARATAPIF" = "yes")
1068AM_CONDITIONAL([ETHERNET_SUPPORT], test "$HAVE_ETHERNET" = "yes")
1069
1070
1071if [[ "x$HAVE_ETHERNET" = "xyes" ]]; then
1072  PROVIDES_NF="$PROVIDES_NF ethernet"
1073fi
1074
1075dnl Support for direct access to host's fs
1076if [[ "x$WANT_HOSTFS" = "xyes" ]]; then
1077  AC_DEFINE([HOSTFS_SUPPORT], 1, [Define if you want to use direct access to host's fs])
1078  PROVIDES_NF="$PROVIDES_NF hostfs"
1079fi
1080AM_CONDITIONAL([HOSTFS_SUPPORT], test "$WANT_HOSTFS" = "yes")
1081
1082
1083dnl SDL GUI
1084if test "x$WANT_SDLGUI" = "xyes" ; then
1085  AC_DEFINE([SDL_GUI], 1, [Define if you want to build SDL GUI])
1086fi
1087AM_CONDITIONAL([SDL_GUI], test "$WANT_SDLGUI" = yes)
1088
1089
1090dnl C++ exceptions
1091if [[ "x$WANT_EXSIGSEGV" = "xyes" ]]; then
1092  WANT_CXX_EXCEPTIONS="no"
1093fi
1094if [[ "x$WANT_CXX_EXCEPTIONS" = "xno" ]]; then
1095  AC_DEFINE(EXCEPTIONS_VIA_LONGJMP, 1, [Define if you want to use setjmp/longjmp instead of C++ exceptions])
1096fi
1097
1098AH_TEMPLATE(NO_NESTED_SIGSEGV, [Define if OS needs to cleanly exit sigsegv handler])
1099
1100
1101dnl Extended signal segmentation fault handler
1102dnl if you add support for os/cpu combinations here,
1103dnl don't forget to update the list of source files
1104dnl in src/Makefile.am, inside "if EXTENDED_SIGSEGV"
1105if [[ "x$WANT_EXSIGSEGV" = "xyes" ]]; then
1106  case "$host_os" in
1107    linux*)
1108      case "$CPU_TYPE" in
1109        i386)
1110          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1111	  ;;
1112	x86_64)
1113          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1114          ;;
1115	arm)
1116          CFLAGS="$CFLAGS -marm"
1117          CXXFLAGS="$CXXFLAGS -marm"
1118          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1119          ;;
1120        *)
1121          AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1122          ;;
1123      esac
1124      ;;
1125    openbsd*)
1126      case "$CPU_TYPE" in
1127        i386)
1128          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1129	  ;;
1130	x86_64)
1131          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1132          ;;
1133        *)
1134          AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1135          ;;
1136      esac
1137      ;;
1138    darwin*)
1139      if [[ "x$CPU_TYPE" = "powerpc" ]]; then
1140        AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1141      else
1142        AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1143      fi
1144      ;;
1145    netbsd*)
1146      if $HAVE_I386 || $HAVE_X86_64; then
1147        :
1148      else
1149        AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1150      fi
1151      ;;
1152    freebsd*|kfreebsd*-gnu)
1153      case "$CPU_TYPE" in
1154        i386)
1155          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1156	  ;;
1157	x86_64)
1158          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1159
1160	  dnl FreeBSD is using clang which requires additional options, may be to be set in
1161	  dnl general for clang in the future
1162  	  case "$host_os" in
1163          freebsd*)
1164            CFLAGS="$CFLAGS -mstackrealign"
1165	    CXXFLAGS="$CXXFLAGS -mstackrealign"
1166            ;;
1167          *) :
1168            ;;
1169          esac
1170          ;;
1171        *)
1172          AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1173          ;;
1174      esac
1175      ;;
1176    cygwin*|mingw*)
1177      if $HAVE_I386 || $HAVE_X86_64; then
1178        AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1179      else
1180        AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1181      fi
1182      ;;
1183    solaris*)
1184      case "$CPU_TYPE" in
1185        i386)
1186	  ;;
1187	x86_64)
1188	  ;;
1189        *)
1190          AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1191          ;;
1192      esac
1193      ;;
1194    beos* | haiku*)
1195      case "$CPU_TYPE" in
1196        i386)
1197          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1198	      ;;
1199	x86_64)
1200          AC_DEFINE(NO_NESTED_SIGSEGV, 1)
1201          ;;
1202        *)
1203          AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1204          ;;
1205       esac
1206       dnl disabled for now: compiles, but panics kernel :(
1207       AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1208       ;;
1209    *)
1210      AC_MSG_ERROR([Sorry, extended segfault handler not supported on your platform])
1211      ;;
1212  esac
1213fi
1214AM_CONDITIONAL([EXTENDED_SIGSEGV], test "$WANT_EXSIGSEGV" = yes)
1215
1216dnl Determine the addressing mode to use
1217ADDRESSING_MODE=""
1218AC_MSG_CHECKING([for the addressing mode to use])
1219for am in $ADDRESSING_TEST_ORDER; do
1220  case $am in
1221  direct)
1222    if [[ "x$HAVE_MMAP_VM" = "xno" -a "x$HAVE_MACH_VM" = "xno" ]]; then
1223      continue
1224    fi
1225    dnl Problems with Solaris
1226    if [[ "x$OS_TYPE" = "xsolaris" ]]; then
1227      continue
1228    fi
1229    ADDRESSING_MODE="direct"
1230    DEFINES="$DEFINES -DDIRECT_ADDRESSING"
1231    break
1232    ;;
1233  fixed)
1234    if [[ "x$HAVE_MMAP_VM" = "xno" -a "x$HAVE_MACH_VM" = "xno" ]]; then
1235      continue
1236    fi
1237    if test "$OS_TYPE" = "linux" && ( $HAVE_I386 || $HAVE_X86_64 || $HAVE_ARM ); then
1238      ADDRESSING_MODE="fixed (0x51000000)"
1239      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1240      break
1241    fi
1242    if test "$OS_TYPE" = "freebsd" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1243      ADDRESSING_MODE="fixed (0x51000000)"
1244      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1245      break
1246    fi
1247    if test "$OS_TYPE" = "openbsd" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1248      ADDRESSING_MODE="fixed (0x51000000)"
1249      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1250      break
1251    fi
1252    if test "$OS_TYPE" = "darwin" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1253      ADDRESSING_MODE="fixed (0x51000000)"
1254      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1255      break
1256    fi
1257    if test "$OS_TYPE" = "cygwin" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1258      ADDRESSING_MODE="fixed (0x51000000)"
1259      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1260      break
1261    fi
1262    if test "$OS_TYPE" = "mingw" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1263      ADDRESSING_MODE="fixed (0x51000000)"
1264      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1265      break
1266    fi
1267    if test "$OS_TYPE" = "solaris" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1268      ADDRESSING_MODE="fixed (0x51000000)"
1269      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1270      break
1271    fi
1272    if test "$OS_TYPE" = "beos" && ( $HAVE_I386 || $HAVE_X86_64 ); then
1273      ADDRESSING_MODE="fixed (0x51000000)"
1274      DEFINES="$DEFINES -DFIXED_ADDRESSING -DFMEMORY=0x51000000"
1275      break
1276    fi
1277    ;;
1278  normal)
1279    ADDRESSING_MODE="normal"
1280    DEFINES="$DEFINES -DNORMAL_ADDRESSING"
1281    break
1282    ;;
1283  *)
1284    AC_MSG_ERROR([Internal configure.in script error for $am addressing mode])
1285  esac
1286done
1287AC_MSG_RESULT($ADDRESSING_MODE)
1288if [[ "x$ADDRESSING_MODE" = "x" ]]; then
1289  AC_MSG_ERROR([Sorry, no suitable addressing mode in $ADDRESSING_TEST_ORDER])
1290fi
1291
1292dnl Check for GAS.
1293HAVE_GAS=no
1294AC_MSG_CHECKING(for GAS .p2align feature)
1295cat >conftest.S << EOF
1296	.text
1297	.p2align 5
1298EOF
1299if $CC conftest.S -c -o conftest.o >/dev/null 2>&1 ; then HAVE_GAS=yes; fi
1300AC_MSG_RESULT($HAVE_GAS)
1301
1302dnl (gb) Do not merge constants since it breaks fpu/fpu_x86.cpp.
1303dnl As of 2001/08/02, this affects the following compilers:
1304dnl Official: probably gcc-3.1 (mainline CVS)
1305dnl Mandrake: gcc-2.96 >= 0.59mdk, gcc-3.0.1 >= 0.1mdk
1306dnl Red Hat : gcc-2.96 >= 89, gcc-3.0 >= 1
1307if [[ "x$GCC" = "xyes" -a "x$FPE_CORE" = "xx86" ]]; then
1308  SAVED_CXXFLAGS="$CXXFLAGS"
1309  CXXFLAGS="$CXXFLAGS -fno-merge-constants"
1310  AC_CACHE_CHECK([whether GCC supports constants merging], ac_cv_gcc_constants_merging, [
1311    AC_LANG_SAVE
1312    AC_LANG_CPLUSPLUS
1313    AC_TRY_COMPILE([],[],[ac_cv_gcc_constants_merging=yes],[ac_cv_gcc_constants_merging=no])
1314    AC_LANG_RESTORE
1315  ])
1316  if [[ "x$ac_cv_gcc_constants_merging" != "xyes" ]]; then
1317    CXXFLAGS="$SAVED_CXXFLAGS"
1318  fi
1319fi
1320
1321dnl Select appropriate CPU source and REGPARAM define.
1322ASM_OPTIMIZATIONS=none
1323
1324dnl gb-- JITSRCS and GENJITSRCS will be emptied later if the JIT is not available
1325dnl gb-- Other platforms should define their own set of noflags file variants
1326CAN_JIT=no
1327JITSRCS=
1328GENJITSRCS="compemu1.cpp compemu2.cpp compemu3.cpp compemu4.cpp compemu5.cpp compemu6.cpp compemu7.cpp compemu8.cpp"
1329GENCOMP_ARCH=
1330
1331AH_TEMPLATE([HAVE_CFLAG_NO_REDZONE], [define if your compiler understand -mno-red-zone])
1332
1333if test "$GCC" = yes && $HAVE_I386; then
1334  dnl i386 CPU
1335  DEFINES="$DEFINES -DUNALIGNED_PROFITABLE -DREGPARAM=\"__attribute__((regparm(3)))\""
1336  if [[ "x$HAVE_GAS" = "xyes" ]]; then
1337    ASM_OPTIMIZATIONS=i386
1338    DEFINES="$DEFINES -DX86_ASSEMBLY -DOPTIMIZED_FLAGS -DSAHF_SETO_PROFITABLE"
1339    CAN_JIT=yes
1340    GENCOMP_ARCH=x86
1341  fi
1342elif test "$GCC" = yes && $HAVE_X86_64; then
1343  dnl x86-64 CPU
1344  DEFINES="$DEFINES -DUNALIGNED_PROFITABLE"
1345  if [[ "x$HAVE_GAS" = "xyes" ]]; then
1346    ASM_OPTIMIZATIONS="x86-64"
1347    DEFINES="$DEFINES -DX86_64_ASSEMBLY -DOPTIMIZED_FLAGS"
1348    CAN_JIT=yes
1349    GENCOMP_ARCH=x86
1350	SAVED_CXXFLAGS="$CXXFLAGS"
1351	CXXFLAGS="$CXXFLAGS -mno-red-zone"
1352	  AC_CACHE_CHECK([whether GCC supports -mno-red-zone], ac_cv_gcc_no_red_zone, [
1353	    AC_LANG_SAVE
1354	    AC_LANG_CPLUSPLUS
1355	    AC_TRY_COMPILE([],[],[ac_cv_gcc_no_red_zone=yes],[ac_cv_gcc_no_red_zone=no])
1356	    AC_LANG_RESTORE
1357	  ])
1358	  CXXFLAGS="$SAVED_CXXFLAGS"
1359	  if [[ "x$ac_cv_gcc_no_red_zone" = "xyes" ]]; then
1360	     AC_DEFINE([HAVE_CFLAG_NO_REDZONE], 1)
1361	  fi
1362  fi
1363elif test "$GCC" = yes && $HAVE_SPARC; then
1364  dnl SPARC CPU
1365  case "$host_os" in
1366  solaris*)
1367    AC_MSG_CHECKING(SPARC CPU architecture)
1368    SPARC_TYPE=`solaris/which_sparc`
1369    AC_MSG_RESULT($SPARC_TYPE)
1370    case "$SPARC_TYPE" in
1371    SPARC_V8)
1372      ASM_OPTIMIZATIONS="SPARC V8 architecture"
1373      DEFINES="$DEFINES -DSPARC_V8_ASSEMBLY" dnl -DOPTIMIZED_FLAGS"
1374      CFLAGS="$CFLAGS -Wa,-Av8"
1375      CXXFLAGS="$CXXFLAGS -Wa,-Av8"
1376      ;;
1377    SPARC_V9)
1378      ASM_OPTIMIZATIONS="SPARC V9 architecture"
1379      DEFINES="$DEFINES -DSPARC_V9_ASSEMBLY" dnl -DOPTIMIZED_FLAGS"
1380      CFLAGS="$CFLAGS -Wa,-Av9"
1381      CXXFLAGS="$CXXFLAGS -Wa,-Av9"
1382      ;;
1383    esac
1384    ;;
1385  esac
1386elif test "$GCC" = yes && $HAVE_ARM; then
1387  dnl ARM CPU
1388  if [[ "x$HAVE_GAS" = "xyes" ]]; then
1389    case "$host_cpu" in
1390	armv6*|armv7*|armv8*|armv9*)
1391           ASM_OPTIMIZATIONS="ARM/V6 architecture w optimized flags"
1392	   DEFINES="$DEFINES -DARMV6_ASSEMBLY -DARM_ASSEMBLY -DOPTIMIZED_FLAGS"
1393           CFLAGS="$CFLAGS -march=armv6"
1394           CXXFLAGS="$CXXFLAGS -march=armv6"
1395	   ;;
1396	*)
1397	   dnl Hack until we find a better way
1398           case "$host_os" in
1399                *-androideabi)
1400                        ASM_OPTIMIZATIONS="ARM/V6 architecture w optimized flags"
1401                        DEFINES="$DEFINES -DARMV6_ASSEMBLY -DARM_ASSEMBLY -DOPTIMIZED_FLAGS"
1402                        ;;
1403                *)
1404                        ASM_OPTIMIZATIONS="ARM/generic w optimized flags"
1405                        DEFINES="$DEFINES -DARM_ASSEMBLY -DOPTIMIZED_FLAGS"
1406                        ;;
1407           esac
1408	   ;;
1409    esac
1410    GENCOMP_ARCH=arm
1411    CAN_JIT=yes
1412  fi
1413fi
1414
1415dnl Check for JIT Version 2
1416if [[ "x$WANT_JIT2" = "xyes" ]]; then
1417  if $HAVE_ARM; then
1418    DEFINES="$DEFINES -DUSE_JIT2=1"
1419  else
1420    AC_MSG_ERROR([JIT Version 2 is only available for ARM])
1421  fi
1422fi
1423
1424AM_CONDITIONAL([GENCOMP_ARCH_X86], test "$GENCOMP_ARCH" = "x86")
1425AM_CONDITIONAL([GENCOMP_ARCH_ARM], test "$GENCOMP_ARCH" = "arm")
1426
1427
1428dnl JIT sources if available
1429if [[ "x$WANT_JIT" = "xyes" -a "x$CAN_JIT" = "xyes" ]]; then
1430  if [[ "x$WANT_MMU" = "xyes" ]]; then
1431      AC_MSG_ERROR([MMU&JIT in combination are not supported])
1432  fi
1433  JITSRCS="$JITSRCS uae_cpu/compiler/compemu_support.cpp"
1434  DEFINES="$DEFINES -DUSE_JIT=1"
1435
1436  dnl JIT is buggy with strict-aliasing, it seems (FIXME!)
1437  CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
1438
1439  if [[ "x$WANT_JIT_DEBUG" = "xyes" ]]; then
1440    DEFINES="$DEFINES -DJIT_DEBUG=1"
1441  fi
1442
1443  if [[ "x$WANT_JIT_FPU" = "xyes" ]]; then
1444    DEFINES="$DEFINES -DUSE_JIT_FPU=1"
1445  fi
1446  if test "$OS_TYPE" != darwin && $HAVE_X86_64; then
1447     # Force text address; needed at least on ArchLinux
1448     # where it is otherwise set to a high memory address
1449     # which is not in the range for the JIT addressing scheme
1450     LDFLAGS="$LDFLAGS -Wl,-Ttext-segment=0x10000000"
1451  fi
1452else
1453  WANT_JIT=no
1454  WANT_JIT_FPU=no
1455  WANT_JIT_DEBUG=no
1456  JITSRCS=""
1457  GENJITSRCS=""
1458fi
1459AM_CONDITIONAL([USE_JIT], test "$WANT_JIT" = "yes")
1460AM_CONDITIONAL([USE_JIT_FPU], test "$WANT_JIT_FPU" = "yes")
1461AM_CONDITIONAL([USE_JIT2], test "$WANT_JIT2" = "yes")
1462
1463
1464dnl Select appropriate FPU source.
1465gcc_AC_C_FLOAT_FORMAT
1466AC_CHECK_HEADERS(ieee754.h ieeefp.h floatingpoint.h nan.h math.h)
1467
1468if [[ "x$WANT_JIT_FPU" = "xyes" -a "x$FPE_CORE_TEST_ORDER" != "xieee" ]]; then
1469dnl  AC_MSG_WARN([Sorry, JIT-FPU supports only the "ieee" FPE implementation])
1470  FPE_CORE_TEST_ORDER="ieee"
1471  dnl Restore previous variables. FPE_CORE_STR and FPUSRCS are overwritten
1472fi
1473
1474AH_TEMPLATE([USES_FPU_CORE], [FPU core])
1475
1476for fpe in $FPE_CORE_TEST_ORDER; do
1477  case $fpe in
1478  ieee)
1479    case $ac_cv_c_float_format in
1480    IEEE*)
1481      FPE_CORE="IEEE fpu core"
1482      AC_DEFINE([USES_FPU_CORE], "IEEE")
1483      DEFINES="$DEFINES -DFPU_IEEE"
1484      dnl Math functions not mandated by C99 standard
1485      AC_CHECK_FUNCS(isnanl isinfl)
1486      dnl Math functions required by C99 standard, but probably not
1487      dnl implemented everywhere. In that case, we fall back to the
1488      dnl regular variant for doubles.
1489      AC_CHECK_FUNCS(logl log10l expl powl exp2l pow2l exp10l pow10l fabsl sqrtl log1pl expm1l exp2 pow2)
1490      AC_CHECK_FUNCS(sinl cosl tanl sinhl coshl tanhl)
1491      AC_CHECK_FUNCS(asinl acosl atanl asinhl acoshl atanhl)
1492      AC_CHECK_FUNCS(floorl ceill truncl roundl)
1493      case $CPU_TYPE in
1494        alpha)
1495          dnl Maybe -mieee-with-inexact
1496	  CXXFLAGS="$CXXFLAGS -mieee"
1497	  LDFLAGS="$LDFLAGS -mieee"
1498	  break
1499	  ;;
1500        *)
1501          ;;
1502      esac
1503      break
1504      ;;
1505    esac
1506    ;;
1507  x86)
1508    if test ":$GCC:$HAVE_I386:$HAVE_GAS:" = ":yes:true:yes:" -o ":$GCC:$HAVE_X86_64:$HAVE_GAS:" = ":yes:true:yes:"; then
1509      FPE_CORE="i387 fpu core"
1510      DEFINES="$DEFINES -DFPU_X86"
1511      break
1512    fi
1513    ;;
1514  uae)
1515    FPE_CORE="uae fpu core"
1516    AC_DEFINE([USES_FPU_CORE], "UAE")
1517    DEFINES="$DEFINES -DFPU_UAE"
1518    break
1519    ;;
1520  mpfr)
1521    AC_CHECK_LIB(mpfr, mpfr_set_zero, [LIBS="$LIBS -lmpfr -lgmp"], [], [-lgmp])
1522    if test $ac_cv_lib_mpfr_mpfr_set_zero = yes; then
1523      FPE_CORE="mpfr fpu core"
1524      AC_DEFINE([USES_FPU_CORE], "MPFR")
1525      DEFINES="$DEFINES -DFPU_MPFR"
1526      break
1527    fi
1528    ;;
1529  *)
1530    AC_MSG_ERROR([Internal configure.in script error for $fpe fpu core])
1531    ;;
1532  esac
1533done
1534if [[ "x$FPE_CORE" = "x" ]]; then
1535  AC_MSG_ERROR([Sorry, no suitable FPU core found in $FPE_CORE_TEST_ORDER])
1536fi
1537AM_CONDITIONAL([FPU_IEEE], test "$fpe" = "ieee")
1538AM_CONDITIONAL([FPU_X86], test "$fpe" = "x86")
1539AM_CONDITIONAL([FPU_UAE], test "$fpe" = "uae")
1540AM_CONDITIONAL([FPU_MPFR], test "$fpe" = "mpfr")
1541
1542
1543dnl Check for certain math functions
1544AC_CHECK_FUNCS(atanh)
1545AC_CHECK_FUNCS(isnan isinf finite isnormal signbit)
1546
1547AH_TEMPLATE([DEBUGGER], [Define if using some internal debugger])
1548dnl Select debugger
1549if [[ "x$WANT_JIT" = "xno" ]]; then
1550  dnl new debugger
1551  if [[ "$USE_DEBUGGER" = "yes" ]]; then
1552    AC_DEFINE([DEBUGGER], 1)
1553  fi
1554else
1555  if [[ "$USE_DEBUGGER" = "yes" ]]; then
1556    AC_MSG_WARN([interactive debugger not usable with JIT])
1557    USE_DEBUGGER=no
1558  fi
1559fi
1560AM_CONDITIONAL([USE_DEBUGGER], test "$USE_DEBUGGER" = yes)
1561
1562AH_TEMPLATE([DISASM_USE_OPCODES],[Define if using the opcodes library for disassembly])
1563AH_TEMPLATE([DISASM_USE_BUILTIN],[Define if using the builtin disassembler])
1564
1565AC_ARG_WITH(opcodes,
1566[AC_HELP_STRING(--with-opcodes=DIR, [specify the directory where the opcodes library is located])],
1567with_opcodes=$withval, with_opcodes=)
1568
1569AC_ARG_ENABLE(disasm,
1570[AC_HELP_STRING(--enable-disasm=builtin|opcodes, [Specify which library to use for disassembly @<:@none@:>@])],
1571enable_disasm=$enableval,
1572enable_disasm=no; enable_disasm_defaulted=yes)
1573case "$enable_disasm" in
1574no|builtin|opcodes)
1575	;;
1576yes|auto)
1577	enable_disasm=auto
1578	;;
1579*)
1580	AC_MSG_ERROR([unknown disassembler $enable_disasm])
1581	;;
1582esac
1583
1584# check wether we need disassembly support, and which one
1585DISASM_CFLAGS=
1586DISASM_LIBS=
1587if test "$USE_DEBUGGER" != no -o "$WANT_HISTORY" = yes; then
1588   if test "$enable_disasm" = no; then
1589     if test "$enable_disasm_defaulted" = "yes"; then
1590        if test "$with_opcodes" != ""; then
1591          enable_disasm=opcodes
1592        else
1593          enable_disasm=auto
1594        fi
1595     else
1596        AC_MSG_WARN([you have requested debug support but disabled disassembly.
1597The debugger needs some disassembling support.])
1598     fi
1599   fi
1600fi
1601if test "$enable_disasm" = auto -o "$enable_disasm" = opcodes; then
1602   CPPFLAGS_save="$CPPFLAGS"
1603   LIBS_save="$LIBS"
1604   if test "$with_opcodes" != ""; then
1605      if test -f "$with_opcodes/build-dir/bfd/bfd.h" ; then
1606        OPCODES_CFLAGS="-I$with_opcodes/build-dir/bfd -I$with_opcodes/build-dir/libiberty -I$with_opcodes/build-dir/opcodes"
1607        OPCODES_LIBS="-L$with_opcodes/build-dir/bfd -L$with_opcodes/build-dir/libiberty -L$with_opcodes/build-dir/opcodes"
1608      else
1609        OPCODES_CFLAGS="-I$with_opcodes/include"
1610        OPCODES_LIBS="-L$with_opcodes/lib"
1611      fi
1612      CPPFLAGS="$CPPFLAGS $OPCODES_CFLAGS"
1613   fi
1614   OPCODES_LIBS="$OPCODES_LIBS -lopcodes -lbfd -lz -ldl"
1615   found=no
1616   AC_CHECK_HEADERS(bfd.h,found=yes,found=no)
1617   AC_CHECK_HEADERS(dis-asm.h,found=yes,found=no)
1618   CPPFLAGS="$CPPFLAGS_save"
1619   AC_CHECK_LIB([opcodes], print_insn_m68k, found=yes,
1620   	   [unset ac_cv_lib_opcodes_print_insn_m68k
1621            OPCODES_LIBS="$OPCODES_LIBS -liberty"
1622	    AC_CHECK_LIB([opcodes], print_insn_m68k, found=yes,
1623		found=no,
1624		[$OPCODES_LIBS])],
1625	[$OPCODES_LIBS])
1626   LIBS="$LIBS_save"
1627   AC_MSG_CHECKING([for opcodes usability])
1628   if test "$found" = "yes"; then
1629      AC_DEFINE(DISASM_USE_OPCODES)
1630      DISASM_CFLAGS="$OPCODES_CFLAGS"
1631      DISASM_LIBS="$OPCODES_LIBS"
1632      AC_MSG_RESULT($found)
1633      if test "$with_opcodes" != ""; then
1634        DISASM_LIBS="$DISASM_LIBS -Wl,-rpath,$with_opcodes/lib"
1635      fi
1636      enable_disasm=opcodes
1637   else
1638      AC_MSG_RESULT($found)
1639      if test "$enable_disasm" = "opcodes"; then
1640        AC_MSG_NOTICE([
1641
1642Required libraries not found.
1643You may have to specify the path to the correct directory.
1644If your system isn't m68k-based, the libraries may be installed
1645in some unusual place (maybe something like
1646/usr/$host/m68k-unknown-linux-gnu).
1647In the meantime, i will use the builtin support.
1648])
1649      fi
1650      enable_disasm=auto
1651   fi
1652fi
1653if test "$enable_disasm" = auto -o "$enable_disasm" = builtin; then
1654   AC_DEFINE(DISASM_USE_BUILTIN)
1655   enable_disasm=builtin
1656fi
1657AC_SUBST(DISASM_CFLAGS)
1658AC_SUBST(DISASM_LIBS)
1659AM_CONDITIONAL(DISASM_USE_BUILTIN, test "$enable_disasm" = "builtin")
1660AM_CONDITIONAL(DISASM_USE_OPCODES, test "$enable_disasm" = "opcodes")
1661
1662
1663dnl Exclusive spcflags handling
1664if [[ "x$WANT_SPCFLAGS_EXCL" = "xyes" ]]; then
1665  DEFINES="$DEFINES -DENABLE_EXCLUSIVE_SPCFLAGS"
1666fi
1667
1668dnl UAE CPU sources for all architectures.
1669CPUSRCS="$CPUSRCS $JITSRCS"
1670GENCPUSRCS="$GENCPUSRCS cpudefs.cpp cpustbl.cpp cpufunctbl.cpp $GENJITSRCS"
1671
1672dnl Remove the "-g" option if set for GCC.
1673if [[ "x$GCC" = "xyes" ]]; then
1674  if test "$ac_test_CFLAGS" != set; then
1675    CFLAGS=`echo $CFLAGS | sed -e 's/-g\b//g'`
1676  fi
1677  if test "$ac_test_CXXFLAGS" != set; then
1678    CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-g\b//g'`
1679  fi
1680fi
1681if [[ "x$WANT_NATDEBUG" = "xyes" ]]; then
1682  DBGSP="-g"
1683  WFLAGS=""
1684  if [[ "x$GCC" = "xyes" ]]; then
1685    WFLAGS="$WFLAGS -W -Wall -Wundef"
1686  fi
1687else
1688  DBGSP=""
1689  WFLAGS=""
1690fi
1691
1692if [[ "x$WANT_FULLDEBUG" = "xyes" ]]; then
1693  CFLAGS="$CFLAGS -DWHOLEDEBUG"
1694  CXXFLAGS="$CXXFLAGS -DWHOLEDEBUG"
1695fi
1696
1697dnl Remove the "-O2" option if set for GCC and set the "-O3" option.
1698dnl Do this only if it was defaulted by configure
1699if [[ "x$GCC" = "xyes" ]]; then
1700  if test "$ac_test_CFLAGS" != set; then
1701    CFLAGS=`echo $CFLAGS | sed -e 's/-O2//g'`
1702    CFLAGS="-O3 $CFLAGS"
1703  fi
1704  if test "$ac_test_CXXFLAGS" != set; then
1705    CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-O2//g'`
1706    CXXFLAGS="-O3 $CXXFLAGS"
1707  fi
1708fi
1709
1710dnl Or if we have -Ofast
1711if [[ "x$HAVE_OFAST" = "xyes" ]]; then
1712  CFLAGS="`echo $CFLAGS | sed -e 's/-g//g'` -Ofast"
1713  CXXFLAGS="`echo $CXXFLAGS | sed -e 's/-g//g'` -Ofast"
1714  CXXFLAGS="-LANG:std $CXXFLAGS"
1715  LDFLAGS="$LDFLAGS -ipa"
1716fi
1717
1718dnl Check for SDL and/or SDL2
1719m4_define(use_sdl2_default, yes)
1720m4_case(use_sdl2_default, yes,
1721[AC_ARG_ENABLE(sdl2,    [AC_HELP_STRING([--disable-sdl2], [disable use of SDL2 even if available (default=no)])], , [enable_sdl2=auto])],
1722[AC_ARG_ENABLE(sdl2,    [AC_HELP_STRING([--enable-sdl2], [use SDL2 if available (default=no)])], , [enable_sdl2=no])])
1723
1724SDL_CFLAGS=
1725SDL_LIBS=
1726no_sdl=yes
1727no_sdl2=yes
1728if test "$OS_TYPE" == darwin -a "$WITH_FINK" = no; then
1729	ARANYM_CHECK_FRAMEWORK(SDL, [])
1730	if test "$have_framework_SDL" = yes ; then
1731		ARANYM_CHECK_FRAMEWORK_LOCATION(SDL)
1732        	sdl_version="`defaults read $SDL_LOCATION/Resources/Info.plist CFBundleShortVersionString`"
1733		# SDL 1.2.15 has still 1.2.14 in the Info.plist file
1734		if test "$sdl_version" = "1.2.14"; then
1735			if test `defaults read $SDL_LOCATION/Resources/Info.plist BuildMachineOSBuild` = "12F2518"; then
1736				sdl_version=1.2.15
1737			fi
1738		fi
1739        	no_sdl=no
1740	fi
1741    if test "$enable_sdl2" != no; then
1742		ARANYM_CHECK_FRAMEWORK(SDL2, [])
1743		if test "$have_framework_SDL2" = yes ; then
1744			ARANYM_CHECK_FRAMEWORK_LOCATION(SDL2)
1745            sdl2_version="`defaults read $SDL2_LOCATION/Resources/Info.plist CFBundleShortVersionString`"
1746            no_sdl2=no
1747		fi
1748	fi
1749else
1750	dnl Try macro from sdl.m4 and sdl2.m4
1751	AM_PATH_SDL(1.2.12)
1752	if test "$enable_sdl2" != no; then
1753		AM_PATH_SDL2(2.0.3)
1754	fi
1755fi
1756if test "$no_sdl" = yes -a "$no_sdl2" = yes; then
1757	AC_MSG_ERROR([*** neither SDL nor SDL2 found! ***])
1758else
1759	AS_CASE("$host",
1760		[arm*-*-linux*],[on_rpi=`awk -v r=0 '/^Hardware@<:@ \t@:>@+:@<:@ \t@:>@+BCM2708/ { ++r;} /^Serial@<:@ \t@:>@+:/ { ++r; } END { print ((r > 1) ? "yes" : "no");}' /proc/cpuinfo`],
1761		[on_rpi="no"])
1762
1763	if test "$on_rpi" = yes; then
1764		AC_DEFINE(USE_FIXED_CONSOLE_FBVIDEOMODE, 1, [Define if console framebuffer does not support changing host video mode])
1765	fi
1766fi
1767if test "$no_sdl2" = yes -a "$enable_sdl2" = yes; then
1768	AC_MSG_ERROR([*** SDL2 was requested, but was not found ***])
1769fi
1770if test "$no_sdl2" != yes -a "$enable_sdl2" != no; then
1771	enable_sdl2=yes
1772fi
1773if test "$have_framework_SDL" = yes -o "$have_framework_SDL2" = yes; then
1774	if test "$enable_sdl2" = yes; then
1775		SDL_CFLAGS="-I$SDL2_LOCATION/Headers"
1776		BUNDLE_FRAMEWORKS="$BUNDLE_FRAMEWORKS $SDL2_LOCATION"
1777		SDL_LIBS="$SDL2_LIBS"
1778		sdl_version="$sdl2_version"
1779	else
1780		SDL_CFLAGS="-I$SDL_LOCATION/Headers"
1781		BUNDLE_FRAMEWORKS="$BUNDLE_FRAMEWORKS $SDL_LOCATION"
1782	fi
1783else
1784	if test "$enable_sdl2" = yes; then
1785		SDL_CFLAGS="$SDL2_CFLAGS"
1786		SDL_LIBS="$SDL2_LIBS"
1787		sdl_version="$sdl2_version"
1788	fi
1789fi
1790AM_CONDITIONAL([ENABLE_SDL2], test "$enable_sdl2" = yes)
1791#
1792# SDL2 on macOS needs 10.6 or above
1793if test "$enable_sdl2" = yes -a "$OS_TYPE" == darwin; then
1794	export MACOSX_DEPLOYMENT_TARGET=10.6
1795fi
1796
1797dnl Check for jpeg library
1798have_jpeglib_h=no
1799have_jpeglib_lib=no
1800AC_CHECK_HEADERS(jpeglib.h, have_jpeglib_h=yes)
1801if test "$have_jpeglib_h" = yes; then
1802	AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, have_jpeglib_lib=yes)
1803fi
1804if test "$have_jpeglib_h" = yes -a "$have_jpeglib_lib" = yes; then
1805	AC_DEFINE(HAVE_JPEGLIB, 1, [Define if you have jpeglib])
1806	JPEG_LIBS="-ljpeg"
1807fi
1808AC_SUBST([JPEG_LIBS])
1809
1810if test "$have_jpeglib_lib" = no; then
1811dnl Check for SDL_Image
1812if test "$enable_sdl2" = yes; then
1813	ARANYM_CHECK_FRAMEWORK(SDL2_image, [])
1814else
1815	ARANYM_CHECK_FRAMEWORK(SDL_image, [])
1816fi
1817if test "$have_framework_SDL2_image" = yes ; then
1818	ARANYM_CHECK_FRAMEWORK_LOCATION(SDL2_image)
1819	SDL_CFLAGS="$SDL_CFLAGS -I$SDL2_image_LOCATION/Headers"
1820	BUNDLE_FRAMEWORKS="$BUNDLE_FRAMEWORKS $SDL2_image_LOCATION"
1821	have_sdlimage_lib=yes
1822	have_sdlimage_h=yes
1823elif test "$have_framework_SDL_image" = yes ; then
1824	ARANYM_CHECK_FRAMEWORK_LOCATION(SDL_image)
1825	CPPFLAGS="$CPPFLAGS -I$SDL_image_LOCATION/Headers"
1826	BUNDLE_FRAMEWORKS="$BUNDLE_FRAMEWORKS $SDL_image_LOCATION"
1827	have_sdlimage_lib=yes
1828	have_sdlimage_h=yes
1829else
1830	tmp_cflags="$CFLAGS"
1831	tmp_cppflags="$CPPFLAGS"
1832	tmp_ldflags="$LDFLAGS"
1833	CFLAGS="$CFLAGS $SDL_CFLAGS"
1834	CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
1835	LDFLAGS="$LDFLAGS $SDL_LIBS"
1836
1837	case "$host" in
1838		# the mixed environment on cygwin usually
1839		# causes link tests against SDL fail here,
1840		# just assume it is present
1841		*-*-cygwin*)
1842			have_sdlimage_lib=yes
1843			have_sdlimage_h=yes
1844			if test "$enable_sdl2" = yes; then
1845				SDL_LIBS="$SDL_LIBS `echo $SDL_LIBS | sed -e 's/SDL2.dll/SDL2_image.dll/'`"
1846			else
1847				SDL_LIBS="$SDL_LIBS `echo $SDL_LIBS | sed -e 's/SDL.dll/SDL_image.dll/'`"
1848			fi
1849			;;
1850		*-*-mingw*)
1851			have_sdlimage_lib=yes
1852			have_sdlimage_h=yes
1853			if test "$enable_sdl2" = yes; then
1854				SDL_LIBS="$SDL_LIBS -lSDL2_image"
1855			else
1856				SDL_LIBS="$SDL_LIBS -lSDL_image"
1857			fi
1858			;;
1859		*)
1860			AC_CHECK_HEADER(SDL_image.h, have_sdlimage_h=yes, havesdlimage_h=no)
1861			AC_CHECK_LIB(SDL_image, IMG_isJPG, have_sdlimage_lib=yes, have_sdlimage_lib=no)
1862			if test "$have_sdlimage_h" = yes -a "$have_sdlimage_lib" = yes; then
1863				if test "$enable_sdl2" = yes; then
1864					SDL_LIBS="$SDL_LIBS -lSDL2_image"
1865				else
1866					SDL_LIBS="$SDL_LIBS -lSDL_image"
1867				fi
1868			fi
1869			;;
1870	esac
1871
1872	CFLAGS="$tmp_cflags"
1873	CPPFLAGS="$tmp_cppflags"
1874	LDFLAGS="$tmp_ldflags"
1875fi
1876if test "$have_sdlimage_h" = yes -a "$have_sdlimage_lib" = yes; then
1877	AC_DEFINE(HAVE_SDL_IMAGE, 1, [Define if you have SDL_image])
1878fi
1879fi
1880
1881dnl Add OpenGL ?
1882if test "x$WANT_OPENGL" = "xyes"; then
1883	have_opengl="no"
1884	if test "x$PKG_CONFIG" != "x"; then
1885		PKG_CHECK_MODULES([GL], [gl], have_opengl="yes", have_opengl="no")
1886	fi
1887	if test "x$GL_LIBS" = "x"; then
1888		case "$host" in
1889			*-*-cygwin* | *-*-mingw*)
1890				GL_LIBS="-lopengl32"
1891				;;
1892			*-*-darwin*)
1893				GL_LIBS="-Wl,-framework,OpenGL"
1894				;;
1895			*)
1896				GL_LIBS="-lGL"
1897				;;
1898		esac
1899	fi
1900	case "$host" in
1901		# the mixed environment on cygwin usually
1902		# causes link tests against SDL fail here,
1903		# just assume it is present
1904		*-*-cygwin* | *-*-mingw*)
1905			have_opengl=yes
1906			;;
1907	esac
1908	AC_MSG_CHECKING(for OpenGL support)
1909	tmp_cflags="$CFLAGS"
1910	tmp_libs="$LIBS"
1911	if test "$have_opengl" = no; then
1912		CFLAGS="$CFLAGS $SDL_CFLAGS"
1913		LIBS="$LIBS $SDL_LIBS $GL_LIBS"
1914		AC_TRY_COMPILE([
1915			 #include "SDL_opengl.h"
1916			],[],[have_opengl="yes"])
1917	fi
1918	AC_MSG_RESULT($have_opengl)
1919	CFLAGS="$tmp_cflags"
1920	LIBS="$tmp_libs"
1921	if test "x$have_opengl" = "xyes"; then
1922		AC_DEFINE([ENABLE_OPENGL], 1, [Define if OpenGL enabled])
1923	else
1924		WANT_OPENGL="no"
1925	fi
1926fi
1927AM_CONDITIONAL([ENABLE_OPENGL], test "$WANT_OPENGL" = yes)
1928
1929
1930dnl Check for zlib
1931if [[ "x$WANT_LILO" = "xyes" ]]; then
1932	have_zlib=no
1933	# Search using pkg-config
1934	if test "x$PKG_CONFIG" != "x"; then
1935		PKG_CHECK_MODULES([ZLIB], [zlib], [have_zlib=yes], [have_zlib=no])
1936	fi
1937
1938	# Fallback to autoconf (helps in Ubuntu 10.04 LTS)
1939	if test "$have_zlib" = "no"; then
1940		AC_CHECK_LIB(z, gzopen, [have_zlib=yes], [have_zlib=no])
1941	fi
1942
1943	if test "$have_zlib" = "yes"; then
1944		AC_DEFINE([HAVE_LIBZ], 1, [Define if zlib enabled])
1945	fi
1946else
1947	have_zlib="not required"
1948fi
1949
1950dnl Check for libusb-1.0
1951WITH_USBHOST="no"
1952if test "x$WANT_USBHOST" = "xyes"; then
1953  # Search using pkg-config
1954    if test "x$PKG_CONFIG" != "x"; then
1955      PKG_CHECK_MODULES([LIBUSB], [libusb-1.0], [WITH_USBHOST="yes"], [WITH_USBHOST="no"])
1956    fi
1957
1958  # Search the library and headers directly
1959    if test "x$WITH_USBHOST" = "xno"; then
1960      AC_CHECK_HEADER(libusb-1.0/libusb.h, [WITH_USBHOST="yes"], [WITH_USBHOST="no"])
1961      if test "x$WITH_USBHOST" = "xyes"; then
1962        AC_CHECK_LIB(usb-1.0, libusb_init, [], [WITH_USBHOST="no"])
1963        LIBUSB_LIBS="-lusb-1.0"
1964      fi
1965    fi
1966
1967    if test "x$WITH_USBHOST" = "xno"; then
1968      AC_MSG_WARN([libusb is missing, USB NF disabled])
1969    fi
1970fi
1971
1972dnl Linux loader
1973
1974if [[ "x$WANT_LILO" = "xyes" ]]; then
1975	if [[ "x$WANT_MMU" = "xyes" ]]; then
1976		AC_DEFINE([ENABLE_LILO], 1, [Define if lilo enabled])
1977	else
1978		AC_MSG_ERROR([Linux kernel requires functional MMU emulation])
1979	fi
1980fi
1981
1982dnl Natfeat CD-ROM driver
1983
1984AH_TEMPLATE([NFCDROM_SUPPORT], [Define if you want to use host CD-ROM driver])
1985NFCDROM_DRIVER=""
1986case "$host_os" in
1987	linux*)
1988		if [[ "$ANDROID_OS" != "yes" ]]; then
1989			AC_DEFINE([NFCDROM_LINUX_SUPPORT], 1, [Define if you want to use Linux support as CD-ROM driver])
1990			NFCDROM_DRIVER="linux"
1991		fi
1992		;;
1993	mingw*|cygwin*)
1994		AC_DEFINE([NFCDROM_WIN32_SUPPORT], 1, [Define if you want to use Win32 support as CD-ROM driver])
1995		NFCDROM_DRIVER="win32"
1996		;;
1997esac
1998if test "$enable_sdl2" != yes; then
1999	test "$NFCDROM_DRIVER" != "" && NFCDROM_DRIVER="${NFCDROM_DRIVER},"
2000	NFCDROM_DRIVER="${NFCDROM_DRIVER}sdl"
2001fi
2002if test "$NFCDROM_DRIVER" != ""; then
2003	AC_DEFINE([NFCDROM_SUPPORT], 1)
2004else
2005	NFCDROM_DRIVER=no
2006fi
2007PROVIDES_NF="$PROVIDES_NF cdrom($NFCDROM_DRIVER)"
2008AM_CONDITIONAL([NFCDROM_SUPPORT], test "$NFCDROM_DRIVER" != "no")
2009
2010
2011dnl Natfeat PCI driver
2012
2013if [[ "x$WANT_NFPCI" = "xyes" ]]; then
2014	case "$host_os" in
2015		linux*)
2016			AC_DEFINE([NFPCI_SUPPORT], 1, [Define if you want to use host PCI driver])
2017			AC_DEFINE([NFPCI_LINUX_SUPPORT], 1, [Define if you want to use Linux PCI driver])
2018			PROVIDES_NF="$PROVIDES_NF pci"
2019			;;
2020		*)
2021			AC_MSG_ERROR([*** NatFeats PCI not supported by this OS ***])
2022			WANT_NFPCI="no"
2023			;;
2024	esac
2025fi
2026AM_CONDITIONAL([NFPCI_SUPPORT], test "$WANT_NFPCI" = "yes")
2027AM_CONDITIONAL([NFPCI_LINUX_SUPPORT], test "$WANT_NFPCI" = "yes" -a "$OS_TYPE" = "linux")
2028
2029dnl Natfeat USB driver
2030
2031if [[ "x$WANT_USBHOST" = "xyes" -a "x$WITH_USBHOST" = "xyes" ]]; then
2032	AC_DEFINE([USBHOST_SUPPORT], 1, [Define if you want to use host USB driver])
2033	LIBS="$LIBS $LIBUSB_LIBS"
2034	PROVIDES_NF="$PROVIDES_NF usb"
2035else
2036	WANT_USBHOST=no
2037fi
2038AM_CONDITIONAL([USBHOST_SUPPORT], test "$WANT_USBHOST" = yes)
2039
2040dnl Natfeat SCSI driver
2041
2042AH_TEMPLATE([NFSCSI_SUPPORT], [Define if you want to use host SCSI driver])
2043if [[ "x$WANT_NFSCSI" = "xyes" ]]; then
2044	case "$host_os" in
2045		linux*)
2046			AC_CHECK_HEADERS(scsi/sg.h)
2047			if test "$ac_cv_header_scsi_sg_h" != yes; then
2048				WANT_NFSCSI=no
2049			fi
2050			;;
2051		*)
2052			WANT_NFSCSI=no
2053			;;
2054	esac
2055	if test "$WANT_NFSCSI" = "no"; then
2056		AC_MSG_WARN([*** NatFeats SCSI not supported by this OS ***])
2057	else
2058		AC_DEFINE([NFSCSI_SUPPORT], 1)
2059		PROVIDES_NF="$PROVIDES_NF scsi"
2060	fi
2061fi
2062
2063dnl Natfeat OSMesa driver
2064
2065AH_TEMPLATE([NFOSMESA_SUPPORT], [Define if you want to use host OSMesa driver])
2066if test "x$WANT_NFOSMESA" = "xyes"; then
2067	have_osmesa=no
2068	if test "x$PKG_CONFIG" != "x"; then
2069		PKG_CHECK_MODULES([OSMESA], [osmesa], have_osmesa=yes, :)
2070	fi
2071	if test "$have_osmesa" = "no"; then
2072		have_osmesa=yes
2073		AC_CHECK_HEADERS(GL/osmesa.h)
2074	fi
2075	if test "$have_osmesa" = "yes"; then
2076		CPPFLAGS="$CPPFLAGS $OSMESA_CFLAGS"
2077		AC_DEFINE([NFOSMESA_SUPPORT], 1)
2078	else
2079		WANT_NFOSMESA="no"
2080	fi
2081fi
2082AM_CONDITIONAL([NFOSMESA_SUPPORT], test "$WANT_NFOSMESA" = yes)
2083
2084if [[ "x$WANT_NFOSMESA" = "xyes" ]]; then
2085	PROVIDES_NF="$PROVIDES_NF osmesa"
2086fi
2087
2088dnl Natfeat JPEG decoder
2089
2090AH_TEMPLATE([NFJPEG_SUPPORT], [Define if you want to use host JPEG decoder])
2091if [[ "x$WANT_NFJPEG" = "xyes" ]]; then
2092	if test "$have_jpeglib_lib" = "yes"; then
2093		AC_DEFINE([NFJPEG_SUPPORT])
2094		PROVIDES_NF="$PROVIDES_NF jpeg"
2095	elif test "$have_sdlimage_h" = "yes" -a "$have_sdlimage_lib" = "yes"; then
2096		AC_DEFINE([NFJPEG_SUPPORT])
2097		PROVIDES_NF="$PROVIDES_NF jpeg"
2098	else
2099		WANT_NFJPEG="no"
2100                AC_MSG_WARN([no jpeg library found, JPEG NF disabled])
2101	fi
2102fi
2103AM_CONDITIONAL([NFJPEG_SUPPORT], test "$WANT_NFJPEG" = yes)
2104
2105
2106dnl Natfeat VDI driver
2107
2108if [[ "x$WANT_NFVDI" = "xyes" ]]; then
2109	AC_DEFINE([NFVDI_SUPPORT], 1, [Define if you want to use NF VDI driver])
2110	NFVDI_DRIVER="sw"
2111	if [[ "x$WANT_OPENGL" = "xyes" ]]; then
2112		NFVDI_DRIVER="opengl,$NFVDI_DRIVER"
2113	fi
2114	PROVIDES_NF="$PROVIDES_NF vdi($NFVDI_DRIVER)"
2115fi
2116AM_CONDITIONAL([NFVDI_SUPPORT], test "$WANT_NFVDI" = "yes")
2117
2118dnl Natfeat Clipboard driver
2119
2120AH_TEMPLATE([NFCLIPBRD_SUPPORT], [Define if you want to use Clipboard])
2121if [[ "x$WANT_NFCLIPBRD" = "xyes" ]]; then
2122	case $OS_TYPE in
2123	cygwin | mingw)
2124		AC_DEFINE([NFCLIPBRD_SUPPORT], 1)
2125		;;
2126	darwin)
2127		AC_DEFINE([NFCLIPBRD_SUPPORT], 1)
2128		# X-Headers are not always available on macOS
2129		tmp_cppflags="$CPPFLAGS"
2130		# not nice to hardcode the path here,
2131		# but it is also hardcoded in the XCode project
2132		CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
2133		AC_CHECK_HEADERS(X11/Xlib.h)
2134		CPPFLAGS="$tmp_cppflags"
2135		;;
2136	beos | haiku)
2137		AC_DEFINE([NFCLIPBRD_SUPPORT], 1)
2138		LIBS="$LIBS -lbe"
2139		;;
2140	*)
2141		AC_CHECK_LIB(X11, XOpenDisplay,[SDL_LIBS="$SDL_LIBS -lX11"],,[-L/usr/X11R6/lib])
2142		if [[ "x$ac_cv_lib_X11_XOpenDisplay" = "xyes" ]]; then
2143			AC_DEFINE([NFCLIPBRD_SUPPORT], 1)
2144		else
2145		     	AC_MSG_ERROR([Sorry, NatFeat Clipboard not implemented on your platform yet])
2146			WANT_NFCLIPBRD="no"
2147		fi
2148		;;
2149	esac
2150fi
2151AM_CONDITIONAL([NFCLIPBRD_SUPPORT], test "$WANT_NFCLIPBRD" = yes)
2152
2153dnl Natfeat host exec driver
2154
2155if [[ "$WANT_NFEXEC" = yes -a "$WANT_HOSTFS" != yes ]]; then
2156	AC_MSG_WARN([NF exec disabled due to lack of support from HOSTFS])
2157	WANT_NFEXEC=no
2158fi
2159if [[ "$WANT_NFEXEC" = yes ]]; then
2160	AC_DEFINE([NFEXEC_SUPPORT], 1, [Define if you want to use NF host exec driver])
2161	PROVIDES_NF="$PROVIDES_NF exec"
2162fi
2163AM_CONDITIONAL([NFEXEC_SUPPORT], test "$WANT_NFEXEC" = "yes")
2164
2165
2166if [[ "x$WANT_NFCLIPBRD" = "xyes" ]]; then
2167	PROVIDES_NF="$PROVIDES_NF clipboard"
2168fi
2169
2170dnl Exception per second limiter
2171
2172if [[ "x$WANT_EPSLIMITER" = "xyes" ]]; then
2173	AC_DEFINE([ENABLE_EPSLIMITER], 1, [Define if you want to use EPS limiter])
2174fi
2175
2176dnl Linux /dev/rtc source timer
2177
2178if test "x$WANT_RTCTIMER" = "xyes" ; then
2179	if test "x$OS_TYPE" = "xlinux"; then
2180		AC_DEFINE([RTC_TIMER], 1, [Define if you want to use Linux /dev/rtc as source timer])
2181	else
2182		WANT_RTCTIMER="no"
2183	fi
2184fi
2185
2186dnl Linux/X86 hardware access for parallel port
2187
2188if test "x$WANT_PARALLELX86" = "xyes" ; then
2189	if test "x$OS_TYPE" = "xlinux" && $HAVE_I386; then
2190		AC_DEFINE([ENABLE_PARALLELX86], 1, [Define if you want to use Linux/X86 hardware access for parallel port])
2191	else
2192		WANT_PARALLELX86="no"
2193	fi
2194fi
2195AM_CONDITIONAL([ENABLE_PARALLELX86], test "$WANT_PARALLELX86" = yes)
2196
2197dnl Linux /dev/parport access for parallel port
2198
2199if test "x$WANT_PARALLELPARPORT" = "xyes" ; then
2200	if test "x$OS_TYPE" = "xlinux"; then
2201		AC_DEFINE([ENABLE_PARALLELPARPORT], 1, [Define if you want to use Linux /dev/parport access for parallel port])
2202	else
2203		WANT_PARALLELPARPORT="no"
2204	fi
2205fi
2206AM_CONDITIONAL([ENABLE_PARALLELPARPORT], test "$WANT_PARALLELPARPORT" = yes)
2207
2208dnl Linux /dev/sequencer MIDI support
2209
2210if test "x$OS_TYPE" = "xlinux"; then
2211	AC_DEFINE([ENABLE_MIDI_SEQUENCER], 1, [Define if you want to use Linux /dev/sequencer support])
2212fi
2213
2214dnl Serial port support
2215
2216if test "x$WANT_UNIXSERIALPORT" = "xyes" ; then
2217	if test "x$ac_cv_header_termios_h" = "xyes" -a "x$ac_cv_header_sys_ioctl_h" = "xyes"; then
2218		AC_DEFINE([ENABLE_SERIALUNIX], 1, [Define if you want to use /dev/ttyXXX access for serial port])
2219	else
2220		WANT_UNIXSERIALPORT="no"
2221	fi
2222fi
2223AM_CONDITIONAL([ENABLE_SERIALUNIX], test "$WANT_UNIXSERIALPORT" = yes)
2224
2225AC_DEFINE_UNQUOTED([PROVIDES_NATFEATS], "$PROVIDES_NF", [List of Native Features])
2226
2227dnl Data directory
2228
2229APP=aranym
2230case "$host_os" in
2231	darwin*)
2232		if test "x$WITH_FINK" = "xyes"; then
2233			TARGET="\$(APP)"
2234		else
2235			TARGET="\$(APP_BUNDLE)"
2236		fi
2237		ARANYM_DATADIR="\"\\\"\${datadir}/\${APP}\\\"\""
2238		;;
2239	mingw*) TARGET="\$(APP)"
2240		ARANYM_DATADIR="\"\\\"./\${APP}\\\"\""
2241		;;
2242	*)	TARGET="\$(APP)"
2243		ARANYM_DATADIR="\"\\\"\${datadir}/\${APP}\\\"\""
2244		;;
2245esac
2246CFLAGS="$CFLAGS -DARANYM_DATADIR=$ARANYM_DATADIR"
2247CXXFLAGS="$CXXFLAGS -DARANYM_DATADIR=$ARANYM_DATADIR"
2248
2249dnl Remove the ARCHFLAGS again as they must be handled separately inside the Makefile.
2250if [[ "x$ARCHFLAGS" != "x" ]]; then
2251	CPPFLAGS=`echo $CPPFLAGS | sed -e "s:$ARCHFLAGS::g"`
2252	LDFLAGS=`echo $LDFLAGS | sed -e "s:$ARCHFLAGS::g"`
2253fi
2254
2255AH_BOTTOM([
2256#endif /* __ARANYM_CONFIG_H__ */
2257])
2258
2259dnl Generate Makefile.
2260
2261ARCH="$CPU_TYPE"
2262
2263AC_SUBST(ARCH)
2264AC_SUBST(WFLAGS)
2265AC_SUBST(DEFINES)
2266AC_SUBST(DBGSP)
2267AC_SUBST(TARGET)
2268AC_SUBST(CPU_TYPE)
2269AC_SUBST(ARCHFLAGS)
2270AC_SUBST(SDL_CFLAGS)
2271AC_SUBST(SDL_LIBS)
2272AC_SUBST(BUNDLE_FRAMEWORKS)
2273AC_SUBST(ZLIB_CFLAGS)
2274AC_SUBST(ZLIB_LIBS)
2275AC_SUBST(GENCOMP_ARCH)
2276AC_SUBST(CXX_FOR_BUILD)
2277AC_SUBST(CC_FOR_BUILD)
2278AC_SUBST(CFLAGS_FOR_BUILD)
2279AC_SUBST(CXXFLAGS_FOR_BUILD)
2280AC_SUBST(LDFLAGS_FOR_BUILD)
2281
2282if test "$am__include" = "include"; then am__include=-include; fi
2283
2284AC_CONFIG_FILES([
2285Makefile
2286src/Makefile
2287src/uae_cpu/Makefile
2288doc/Makefile
2289])
2290
2291AC_OUTPUT
2292
2293dnl Print summary.
2294echo
2295echo "ARAnyM configuration summary:"
2296echo
2297echo "SDL version ................... ........ : $sdl_version"
2298echo "Use exclusive spcflags handling ........ : $WANT_SPCFLAGS_EXCL"
2299echo "Use JIT compiler ....................... : $WANT_JIT"
2300echo "Use JIT compiler for FPU instructions .. : $WANT_JIT_FPU"
2301echo "JIT debug mode ......................... : $WANT_JIT_DEBUG"
2302echo "Floating-Point emulation core .......... : $FPE_CORE"
2303echo "Assembly optimizations ................. : $ASM_OPTIMIZATIONS"
2304echo "Addressing mode ........................ : $ADDRESSING_MODE"
2305ATC_TYPE_MSG=
2306if [[ "x$WANT_MMU" = "xyes" ]]; then
2307    case "$ATC_TYPE" in
2308		full)	ATC_TYPE_MSG=" (with ATC)";;
2309		small)	ATC_TYPE_MSG=" (with small ATC)";;
2310		no)	ATC_TYPE_MSG=" (without ATC)";;
2311    esac
2312fi
2313echo "Full MMU support ....................... : $WANT_MMU$ATC_TYPE_MSG"
2314echo "Linux /dev/rtc source timer ............ : $WANT_RTCTIMER"
2315echo "Real STOP implementation ............... : $WANT_REALSTOP"
2316echo "DSP 56001 support ...................... : $WANT_DSP"
2317echo "DSP 56001 disassembly support .......... : $WANT_DSP_DISASM"
2318echo "Debugger ............................... : $USE_DEBUGGER"
2319echo "Check memory ........................... : $MEMORY_CHECK"
2320echo "First 2kB of RAM Supervisor protected... : $WANT_PROTECT2K"
2321echo "FastRAM fixed size ..................... : $WANT_FIXEDFASTRAM"
2322echo "Fixed position of VideoRAM ............. : $WANT_FIXEDVIDEORAM"
2323echo "Blitter memmove acceleration ........... : $WANT_BLITMEMMOVE"
2324echo "Blitter SDL blit acceleration .......... : $WANT_BLITSDLBLIT"
2325echo "Support for hostfs ..................... : $WANT_HOSTFS"
2326echo "Support for ethernet ................... : $HAVE_ETHERNET"
2327echo "GUI .................................... : $WANT_SDLGUI"
2328echo "OpenGL ................................. : $WANT_OPENGL"
2329echo "Linux-m68k loader ...................... : $WANT_LILO"
2330echo "Zlib ................................... : $have_zlib"
2331echo "libusb-1.0.............................. : $WITH_USBHOST"
2332echo "NatFeat CD-ROM driver .................. : $NFCDROM_DRIVER"
2333echo "NatFeat PCI driver ..................... : $WANT_NFPCI"
2334echo "NatFeat USB driver ..................... : $WANT_USBHOST"
2335echo "NatFeat OSMesa driver .................. : $WANT_NFOSMESA"
2336echo "NatFeat JPEG decoder ................... : $WANT_NFJPEG"
2337echo "NatFeat Clipboard ...................... : $WANT_NFCLIPBRD"
2338echo "NatFeat VDI driver ..................... : $WANT_NFVDI"
2339echo "NatFeat SCSI driver .................... : $WANT_NFSCSI"
2340echo "NatFeat host exec driver ............... : $WANT_NFEXEC"
2341echo "Exception per second limiter ........... : $WANT_EPSLIMITER"
2342echo "Linux/X86 h/w access for parallel port.. : $WANT_PARALLELX86"
2343echo "Linux /dev/parport for parallel port.... : $WANT_PARALLELPARPORT"
2344echo "Unix /dev/ttySn for serial port......... : $WANT_UNIXSERIALPORT"
2345echo "Use C++ exceptions for m68k exceptions.. : $WANT_CXX_EXCEPTIONS"
2346echo
2347echo "Configuration done. Now type \"make\" (or \"gmake\")."
2348