dnl
dnl	configure.in script for Tile World
dnl

AC_INIT(tworld.c)

test -z "$CC" && CC="gcc"
test -z "$CFLAGS" && CFLAGS=" -Wall -Wextra -O2 -fomit-frame-pointer -DNDEBUG"
test -z "$LDFLAGS" && LDFLAGS=" -Wall -Wextra -s"

dnl
dnl	--with-debug turns on debugging options
dnl

AC_ARG_WITH(debug,
	    [  --with-debug            Build with debugging info],
	    [if test $withval = yes ; then
	       CFLAGS=" -Wall -Wextra -ggdb"
	       LDFLAGS=" -Wall -Wextra -ggdb"
	     fi])

LOADLIBES=""
OSHWCFLAGS=$CFLAGS
sharedir='${datarootdir}/tworld'
otherobjs=""

dnl
dnl	--with-sharedir=DIR overrides default value of $datarootdir/tworld
dnl	for the shared data directory.
dnl

AC_ARG_WITH(sharedir,
	    [  --with-sharedir=DIR     Explicitly set the shared data directory],
	    [sharedir=$withval])

dnl
dnl	--with-sdl selects SDL as the OS/hardware layer.
dnl	(Currently this is the only OS/hardware layer option.)
dnl

OSHWDIR="sdl"

AC_ARG_WITH(sdl,
	    [  --with-sdl              Build SDL version (default)],
	    [if test $withval = yes ; then
	       OSHWDIR="sdl"
	     fi])

if test -d "oshw-$OSHWDIR" ; then
  echo using $OSHWDIR for OS/hardware layer ...
  rm -f oshw
  ln -s oshw-$OSHWDIR oshw
else
  AC_MSG_ERROR([OS/hardware layer "$OSHWDIR" not available])
fi

if test "$OSHWDIR" = "sdl" ; then
  AC_CHECK_PROG(sdlpresent, sdl-config, yes, no)
  if test -z "$sdlpresent" ; then
    AC_MSG_ERROR([SDL installation not found.])
  fi
  OSHWCFLAGS=$OSHWCFLAGS' $(shell sdl-config --cflags)'
  LOADLIBES=$LOADLIBES' $(shell sdl-config --libs)'
fi

dnl
dnl	--with-win32 puts some Windows-specific lines in the Makefile
dnl

AC_ARG_WITH(win32,
	    [  --with-win32            Set defaults for a windows build],
	    [if test $withval = yes ; then
	       sharedir="."
	     fi])

dnl
dnl	Done with processing.
dnl

AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(OSHWCFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LOADLIBES)
AC_SUBST(sharedir)

AC_OUTPUT(Makefile oshw/Makefile)
