
AC_INIT(src/njam.cpp)
VERSION=0.1.25
PACKAGE=njam
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($PACKAGE,"$VERSION")
CFLAGS="$CFLAGS"

dnl Determine default prefix
if test "x$prefix" = "xNONE"; then
  prefix="/usr/local"
fi

AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl ---- Checks for header files.

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h strings.h sys/ioctl.h sys/time.h unistd.h)


AC_ARG_WITH(sdl,     [  --with-sdl              build SDL interface], [], [with_sdl=yes])


dnl ---- SDL component needs: libvorbisfile.la libsmpeg.la libogg.la

if test "$with_sdl" != "no" ; then
AC_CHECK_PROG(SDL_CONFIG, sdl-config,yes)
if test x$SDL_CONFIG = "x"; then
  AC_MSG_ERROR([SDL_CONFIG not found!!! Install sdl libs])
fi

if test "$SDL_CONFIG" ; then
SDL_LIBS="`sdl-config --libs`"
SDL_CFLAGS="`sdl-config --cflags`"
INCS="$INCS $SDL_CFLAGS"
AC_CHECK_LIB(SDL, SDL_Init, [
AC_CHECK_HEADERS(SDL/SDL.h, ,[
AC_MSG_ERROR(SDL found but headers are missing!!)
with_sdl=no
])], [with_sdl=no], $SDL_LIBS)

AC_CHECK_LIB(SDL_image, IMG_Load, ,[
AC_MSG_ERROR([SDL_image libs and headers are missing!! Install sdl-image libs]) 
], $SDL_LIBS)
SDL_LIBS="$SDL_LIBS -lSDL_image"

AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, ,[
AC_MSG_ERROR([SDL_mixer libs and headers are missing!! Install sdl-mixer libs]) 
], $SDL_LIBS)
SDL_LIBS="$SDL_LIBS -lSDL_mixer"

AC_CHECK_LIB(SDL_net, SDLNet_TCP_Open, ,[
AC_MSG_ERROR([SDL_net libs and headers are missing!! Install sdl-net libs]) 
], $SDL_LIBS)
SDL_LIBS="$SDL_LIBS -lSDL_net"

else
with_sdl=no
fi
fi

AC_SUBST(SDL_CFLAGS)
AC_SUBST(SDL_LIBS)

CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"

dnl Determine if maintainer portions of the Makefiles should be included.
dnl AM_MAINTAINER_MODE

dnl default prefix
DEFAULT_PREFIX="$prefix"
AC_SUBST(DEFAULT_PREFIX)

dnl datadir
DEFAULT_LIBDIR="$datadir"
AC_SUBST(DEFAULT_LIBDIR)


dnl Print results
AC_MSG_RESULT([])
AC_MSG_RESULT([ $PACKAGE version $VERSION configured successfully.])
AC_MSG_RESULT([])
AC_MSG_RESULT([Using '$DEFAULT_PREFIX' for installation.])
AC_MSG_RESULT([Using '$DEFAULT_LIBDIR' for installation libraries.])
AC_MSG_RESULT([Using '$CXX' for C++ compiler.])
AC_MSG_RESULT([Building with '$SDL_CFLAGS' for C++ compiler flags.])
AC_MSG_RESULT([Building with '$SDL_LIBS' for linker flags.])
AC_MSG_RESULT([])

AC_OUTPUT(Makefile
src/Makefile
)
