dnl
dnl OpenUniverse autoconf file
dnl
dnl Based on plib and xracer autoconf scripts
dnl

AC_INIT(src/ou.cpp)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(openuniverse, 1.0beta3)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_CXXCPP
AC_PROG_INSTALL
AM_PROG_LEX
AC_PROG_YACC

AC_ARG_WITH(glui-libs,[  --with-glui-libs=DIR    Specify GLUI library location],GLUI_LIB="$withval")
AC_ARG_WITH(glui-inc, [  --with-glui-inc=DIR     Specify GLUI headers location],OU_EXTRA_CFLAGS="$OU_EXTRA_CFLAGS -I$withval -DHAVE_GLUI")


AC_ARG_WITH(
 gl-libs,
 [  --with-gl-libs=DIR      Specify OpenGL library location],
 OULIBS="$OULIBS -L$withval")

AC_ARG_WITH(
 gl-inc,
 [  --with-gl-inc=DIR       Specify OpenGL header file location],
 OUFLAGS="$OUFLAGS -I$withval")

AC_ARG_WITH(
 glut-libs,
 [  --with-glut-libs=DIR    Specify GLUT library location],
 OULIBS="$OULIBS -L$withval")

AC_ARG_WITH(
 glut-inc,
 [  --with-glut-inc=DIR     Specify GLUT header file location],
 OUFLAGS="$OUFLAGS -I$withval")



CFLAGS="$CFLAGS $OUFLAGS $OU_EXTRA_CFLAGS"
CXXFLAGS="$CXXFLAGS $OUFLAGS $OU_EXTRA_CFLAGS"
LIBS="$LIBS $OULIBS $GLUI_LIB"

dnl Check for X11.
AC_PATH_XTRA

LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lXmu -lXi -lXext -lX11 $X_EXTRA_LIBS"
CFLAGS="$CFLAGS $X_CFLAGS"

dnl Check for OpenGL. Taken partly from the plib sources.
AC_CHECK_LIB(GL,glNewList)

if test "x$ac_cv_lib_GL_glNewList" = "xno" ; then
        dnl Check for MesaGL.
        AC_CHECK_LIB(MesaGL, glNewList,,
                     AC_MSG_ERROR(GL library was not found))
fi

AC_CHECK_LIB(GLU,gluLookAt)

if test "x$ac_cv_lib_GLU_gluLookAt" = "xno"; then
        dnl Check for MesaGLU.
        AC_CHECK_LIB(MesaGLU, gluLookAt,,
        AC_MSG_ERROR(GLU library was not found))
fi


dnl Check for GLUT.
AC_CHECK_LIB(glut, glutKeyboardUpFunc,,
             AC_MSG_ERROR(GLUT library version >= 3.7 not found))

dnl Check for JPEG library.
AC_CHECK_LIB(jpeg, jpeg_start_decompress,,
             AC_MSG_ERROR(jpeg library not found))



dnl Checks for header files.

AC_HEADER_STDC

AC_CHECK_HEADERS(GL/gl.h GL/glut.h)
AC_CHECK_HEADER(joystick.h, AC_DEFINE(JOYSTICK_IS_PRESENT))
AC_CHECK_HEADER(linux/joystick.h, AC_DEFINE(LINUX_JOYSTICK_IS_PRESENT))

AC_DEFINE(TEXTURE_DIR,"$texture_dir")
AC_DEFINE(FONT_DIR,"$font_dir")
AC_DEFINE(MODEL_DIR,"$model_dir")
AC_DEFINE(DATA_DIR,"$data_dir")
AC_DEFINE(CONF_DIR,"$conf_dir")
AC_DEFINE(SHOTS_DIR,"$shots_dir")
AC_DEFINE(EVENTS_DIR,"$events_dir")

AC_OUTPUT( Makefile          \
           src/Makefile     \
           data/Makefile     \
           3dmodels/Makefile     \
           textures/Makefile     \
           fonts/Makefile     \
           conf/Makefile     \
           docs/Makefile     \
          )

AC_MSG_RESULT()
AC_MSG_RESULT()
AC_MSG_RESULT(********************************************************************)
AC_MSG_RESULT(*** Before compiling OpenUniverse take a look at the configuration )
AC_MSG_RESULT(*** file in the conf directory. Default configuration file is tuned )
AC_MSG_RESULT(*** for a GeForce card so if you own a less powerful card you'll )
AC_MSG_RESULT(*** have to edit that file and read carefully )
AC_MSG_RESULT(********************************************************************)
AC_MSG_RESULT()
AC_MSG_RESULT()
