dnl $Id: configure.in,v 1.16 2002/07/11 16:22:33 knik Exp $
dnl
dnl Copyright (C) 2001 Krzysztof Nikiel
dnl
dnl
dnl
dnl Process this file with autoconf to produce a configure script.
AC_INIT(amiga/amiga_asm.h)
AC_CONFIG_HEADER(config.h)

a800_target=none
case "$target" in
	basic|curses|ncurses|svgalib|vga|dx|sdl|falcon)
	a800_target="$target" ;;
	x11|x11-shm|xview|xview-shm|motif)
	a800_target=x11-"$target" ;;
esac

if test "$a800_target" = none; then
	echo "to configure atari800 use: configure --target=<target>"
	echo "available atari800 targets are:"
	echo " basic"
	echo " curses ncurses"
	echo " svgalib"
	echo " vga  (dos only)"
	echo " dx   (directx)"
	echo " x11 x11-shm"
	echo " xview xview-shm"
	echo " motif"
	echo " sdl"
	echo " falcon"
	echo " "
	echo " "
	exit 1;
fi        

if test "${LDFLAGS+set}" != set; then
LDFLAGS=-s
fi
if test "${CFLAGS+set}" != set; then
CFLAGS='-O2 -Wall'
fi

AC_PROG_CC

a800_host=none
AC_CANONICAL_HOST
case $host_os in
  cygwin )
	a800_host=win
	if test "$a800_target" = dx; then 
		CC="gcc -mno-cygwin"
		ac_cv_prog_CC=$CC
		echo "using CC=$CC to disable cygwin library";
	fi
	;;
  mingw32 ) a800_host=win;;
  msdosdjgpp ) a800_host=dos;;
  linux ) a800_host=linux;;
  mint ) a800_host=falcon;;
esac

echo "$a800_host environment found"

AC_EXEEXT

case "$a800_host" in
  dos)	AC_DEFINE(DOS_DRIVES)
;;  
  win)	AC_DEFINE(WIN32,) 
	AC_DEFINE(BACK_SLASH)
	AC_DEFINE(DOS_DRIVES)
;;  
  falcon) AC_DEFINE(DOS_DRIVES)
	AC_DEFINE(BACK_SLASH)
  	AC_DEFINE(USE_CLOCK)
;;
esac

dnl Checks for programs.
dnl AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl Checks for libraries.

AC_DEFUN(NEED_LIB,
[AC_CHECK_LIB($1, main,, echo $1 library not found; exit 1)])

AC_CHECK_LIB(z, gzopen)

if test "$a800_host" != win; then
dnl Replace `main' with a function in -lm:
AC_CHECK_LIB(m, main)
fi

OBJ=

if test "$a800_host" = win; then
NEED_LIB(gdi32, main)
NEED_LIB(winmm, main)
OBJ=win32/atari.ro
fi

dnl set OBJ depending on target
case "$a800_target" in
basic)
AC_DEFINE(BASIC)
OBJ=atari_basic.o
;;
vga) 
	if test "$a800_host" != dos; then
		echo "cannot build vga outside dos"
		exit 1
	fi
	AC_DEFINE(VGA)
	OBJ="dos/atari_vga.o dos/vga_gfx.o dos/vga_asm.o"
;;
svgalib)
dnl Replace `main' with a function in -lvga:
NEED_LIB(vga, main)
AC_DEFINE(SVGALIB)
OBJ="atari_svgalib.o"
;;
curses)
dnl Replace `main' with a function in -lcurses:
NEED_LIB(curses, main)
AC_DEFINE(CURSES)
OBJ=atari_curses.o
;;
ncurses)
dnl Replace `main' with a function in -lncurses:
NEED_LIB(ncurses, main)
AC_DEFINE(NCURSES)
AC_DEFINE(CURSES)
OBJ=atari_curses.o
;;
dx)
dnl Replace `main' with a function in -lddraw:
NEED_LIB(ddraw, main)
dnl Replace `main' with a function in -ldinput:
NEED_LIB(dinput, main)
dnl Replace `main' with a function in -ldsound:
NEED_LIB(dsound, main)
dnl Replace `main' with a function in -ldxguid:
NEED_LIB(dxguid, main)

AC_DEFINE(DIRECTX)
OBJ="win32/atari_win32.o \
win32/screen.o \
win32/main.o \
win32/keyboard.o \
win32/atari.ro"
;;
sdl)
CFLAGS="$CFLAGS `sdl-config --cflags`"
LIBS="$LIBS `sdl-config --libs`"
OBJ="$OBJ \
atari_sdl.o"
;;
falcon)
LIBS="$LIBS -lgem"
OBJ="$OBJ \
atari_falcon.o \
falcon/c2p_uni.o \
falcon/c2p_unid.o \
falcon/videl.o \
falcon/ikbd.o"
;;
x11-*)
AC_PATH_X
if test -n "$x_includes"; then
CFLAGS="$CFLAGS -I$x_includes"
fi
if test -n "$x_libraries"; then
LDFLAGS="$LDFLAGS -L$x_libraries"
fi
dnl Replace `main' with a function in -lX11:
NEED_LIB(X11, main)
AC_DEFINE(X11)

case "$a800_target" in
*-shm)
dnl Replace `main' with a function in -lXext:
AC_CHECK_LIB(Xext, main)
AC_DEFINE(SHM)
;;
esac

case "$a800_target" in
x11-xview*)
dnl Replace `main' with a function in -lxview:
NEED_LIB(xview, main)
dnl Replace `main' with a function in -lolgx:
NEED_LIB(olgx, main)
AC_DEFINE(XVIEW)
;;
x11-motif)
dnl Replace `main' with a function in -lXm:
NEED_LIB(Xm, main)
dnl Replace `main' with a function in -lXt:
NEED_LIB(Xt, main)
dnl Replace `main' with a function in -lgen:
NEED_LIB(gen, main)
dnl Replace `main' with a function in -lsocket:
NEED_LIB(socket, main)
AC_DEFINE(MOTIF)
;;
esac

OBJ="$OBJ atari_x11.o"
;;
esac


dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h strings.h sys/ioctl.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(getcwd gettimeofday select strdup strerror strstr strtol)

dnl user defined part of configuration
echo

dnl DEF_FEATURE(symbol name, feature name, enable/disable,
dnl feature description, default action)
dnl 'enable/disable' means defining symbol enables/disables feature
dnl default action: y - define symbol, n - don't define
AC_DEFUN(DEF_FEATURE,
[
a800_ans=$5
AC_ARG_ENABLE($2, 
[  --$3-$2	ifelse($3, enable, Enable, Disable) $4 (default is ifelse(
$5, y, yes, $5, n, no,
[errprint(__file__ __line__: bad default action '$5')m4_exit(1)]
))],
[ if test "$enableval" = ifelse($3, enable, yes, $3, disable, no,
[errprint(__file__ __line__: bad enable/disable word '$3')m4_exit(1)]
) ; dnl syntax checking
  then
   a800_ans=y
  else
   a800_ans=n
  fi
])
if test "$a800_ans" = y ; then
	AC_DEFINE($1)
	AC_MSG_RESULT([$4 $3]d)
else
	AC_MSG_RESULT([$4 not $3]d)
fi
])


if test "$a800_host" = falcon; then dnl falcon host specific
DEF_FEATURE(CPUASS, cpuass, enable, using m68k assembler CPU core (falcon only), n)
if test "$a800_ans" = y; then
OBJ="$OBJ cpu_m68k.o"
fi
fi
DEF_FEATURE(VERY_SLOW, slow, enable, very slow computer support (disables generating screen completely), n)
DEF_FEATURE(NO_CYCLE_EXACT, scancolor, disable, color changes inside a scanline (cycle exact), n)
DEF_FEATURE(CRASH_MENU, crashmenu, enable, crash menu after CIM instruction, y)
DEF_FEATURE(MONITOR_BREAK, break, enable, BREAK command in monitor (slows CPU a little bit), y)
DEF_FEATURE(MONITOR_HINTS, hints, enable, hints in disassembler (addresses get human readable labels), y)
DEF_FEATURE(MONITOR_ASSEMBLER, asm, enable, assembler in monitor (you can enter ASM insns directly), y)
DEF_FEATURE(SNAILMETER, meter, enable, Snailmeter (shows how much is the emulator slower than original), n)

if test "$a800_target" = svgalib; then dnl svgalib specific
DEF_FEATURE(SVGA_SPEEDUP, svgaspeed, enable, drawing every 1/50 sec only 1/refresh of screen (svgalib only), n)
DEF_FEATURE(USE_CURSORBLOCK, cursorblk, enable, using cursor keys/Ctrl for keyboard joystick (svgalib only), n)
DEF_FEATURE(JOYMOUSE, joymouse, enable, support for Toshiba Joystick Mouse (svgalib only), n)
fi

if test "$a800_host" = linux; then dnl linux specific
DEF_FEATURE(LINUX_JOYSTICK, linuxjoy, enable, LINUX Joystick (linux only), n)
fi

dnl sound support
DEF_FEATURE(SOUND, sound, enable, Sound Support, y)
if test "$a800_ans" = y; then

case "$a800_host" in
dos)
OBJ_SND="dos/sound_dos.o dos/dos_sb.o"
;;
win)
OBJ_SND="win32/sound.o"
;;
falcon)
OBJ_SND="sound_falcon.o falcon/sound_dma.o"
;;
*)
OBJ_SND="sound.o"
esac

if test "$a800_target" = sdl; then
	OBJ_SND=""
fi

OBJ="$OBJ $OBJ_SND"

DEF_FEATURE(NO_VOL_ONLY, volsound, disable, volume only sound (digitized sound effects), n)
if test "$a800_ans" = y; then
DEF_FEATURE(NO_CONSOL_SOUND, consound, disable, console sound (keyboard clicks), n)
DEF_FEATURE(SERIO_SOUND, sersound, enable, serial in/out sound, n)
fi	dnl digitized effects enabled
DEF_FEATURE(NOSNDINTER, sndinter, disable, Sound Interpolation, n)
DEF_FEATURE(CLIP, sndclip, enable, Sound Clipping, n)
if test "$a800_target" != falcon; then
DEF_FEATURE(STEREO, stereo, enable, Stereo Sound, n)
fi
fi	dnl sound enabled

case "$a800_target" in
x11-*) ;;
*)
DEF_FEATURE(BUFFERED_LOG, bufferlog, enable, buffered debug output (until the graphics mode switches back to text mode), n)
DEF_FEATURE(SET_LED, led, enable, disk LED diode emulation, n)
if test "$a800_ans" = y; then
DEF_FEATURE(NO_LED_ON_SCREEN, displayled, disable, LED on screen display, y)
fi
;;
esac


AC_CACHE_CHECK(unaligned long accesses, ac_cv_unaligned_long_ok,
[AC_TRY_RUN([
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf jmpbuf;
void bus_err()
{
	longjmp(jmpbuf, 1);
}
int main(void)
{
#ifndef SIGBUS
	return 0;
#else
	long l[2];

	if (setjmp(jmpbuf) == 0) {
		signal(SIGBUS, bus_err);
		*((long *) ((char *) l + 1)) = 1;
		signal(SIGBUS, SIG_DFL);
		return 0;
	}
	else {
		signal(SIGBUS, SIG_DFL);
		return 1;
	}
#endif
}], ac_cv_unaligned_long_ok=yes, ac_cv_unaligned_long_ok=no,
ac_cv_unaligned_long_ok=no)])
if test "$ac_cv_unaligned_long_ok" = yes; then 
AC_DEFINE(UNALIGNED_LONG_OK)
fi

AC_CHECK_SIZEOF(long, 4)

AC_C_BIGENDIAN

AC_SUBST(OBJ)

AC_OUTPUT(Makefile)
