-AC_PREREQ(2.60)
-AC_INIT([yoink],[0.1],[chaz@dogcows.com])
+
+#
+# Yoink
+# Process this file with autoconf to produce a configure script.
+#
+
+AC_PREREQ([2.60])
+
+AC_INIT([Yoink], [0.1], [chaz@dogcows.com], [yoink])
+
+AC_CANONICAL_TARGET
+
+AC_CONFIG_SRCDIR([src/GameLayer.cc])
+AC_CONFIG_MACRO_DIR([m4])
+
AM_INIT_AUTOMAKE
-AC_CONFIG_SRCDIR([src/yoink.cc])
+
+
+#
+# Checks for programs.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AC_PROG_CXX
-AC_PROG_LIBTOOL
+AC_PROG_CC
+AC_PROG_CPP
AC_PROG_INSTALL
-
+AC_PROG_RANLIB
AM_PROG_CC_C_O
+PKG_PROG_PKG_CONFIG
+
+AC_PATH_PROGS([DOXYGEN], [doxygen])
+AC_SUBST(DOXYGEN)
+
+#
+# Configure platform-specific stuff.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+case "${host}" in
+ *mingw32*)
+ MINGW32=yes
+ WIN32=yes
+ AC_PATH_PROGS([WINDRES], [windres $host_alias-windres $host_os-windres])
+ if test "x$WINDRES" = x
+ then
+ AC_MSG_ERROR([windres could not be found])
+ fi
+ AC_SUBST(WINDRES)
+ AC_PATH_PROGS([MAKENSIS], [makensis])
+ AC_SUBST(MAKENSIS)
+ ;;
+ *cygwin*)
+ CYGWIN=yes
+ WIN32=yes
+ ;;
+ *-apple-darwin*)
+ MACOSX=yes
+ LIBS="$LIBS -Wl,-framework"
+ ;;
+ *-linux-gnu*)
+ LINUX=yes
+ ;;
+esac
+
+AM_CONDITIONAL([LINUX], test "$LINUX" = "yes")
+AM_CONDITIONAL([WIN32], test "$WIN32" = "yes")
+
+
+#
+# Checks for configuration arguments.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+AC_ARG_ENABLE([debug],
+ [ --enable-debug include debugging symbols and features],
+ [debug=$enableval],
+ [debug=no])
+
+AC_ARG_ENABLE([double-precision],
+ [ --enable-double-precision use double-precision numbers],
+ [double_precision=$enableval],
+ [double_precision=no])
+
+AC_ARG_ENABLE([profile],
+ [ --enable-profile make a binary for use with gprof profiler],
+ [profile=$enableval],
+ [profile=no])
+
+AC_ARG_ENABLE([extra-warnings],
+ [ --enable-extra-warnings make the gcc compiler give more warnings],
+ [extra_warnings=$enableval],
+ [extra_warnings=no])
+
+AC_ARG_ENABLE([threads],
+ [ --enable-threads use threads for some parallel tasks],
+ [threads=$enableval],
+ [threads=no])
+
+AC_ARG_ENABLE([gtk],
+ [ --enable-gtk enable GTK+ info/warning dialogs],
+ [gtk=$enableval],
+ [gtk=no])
+
+AC_ARG_ENABLE([qt4],
+ [ --enable-qt4 enable QT info/warning dialogs],
+ [qt4=$enableval],
+ [qt4=no])
+
+AC_ARG_WITH([log-level],
+ [AS_HELP_STRING([--with-log-level=NUM],
+ [0, none... 1, errors... 4, everything (default: 3)])],
+ [log_level=$withval],
+ [log_level=3])
+
+
+if test x$debug = xyes
+then
+ CFLAGS="$CFLAGS -DDEBUG -Wall -Wno-uninitialized"
+ CXXFLAGS="$CXXFLAGS -DDEBUG -Wall -Wno-uninitialized"
+else
+ CFLAGS="$CFLAGS -DNDEBUG"
+ CXXFLAGS="$CXXFLAGS -DNDEBUG"
+fi
+
+if test x$double_precision = xyes
+then
+ AC_DEFINE([USE_DOUBLE_PRECISION], 1,
+ [Define to 1 if you want to use doubles instead of floats.])
+fi
+
+if test x$profile = xyes
+then
+ CFLAGS="$CFLAGS -pg"
+ CXXFLAGS="$CXXFLAGS -pg"
+ AC_DEFINE([PROFILING_ENABLED], 1,
+ [Define to 1 if profiling is built in.])
+fi
+
+if test x$extra_warnings = xyes
+then
+ CFLAGS="$CFLAGS -Wextra -Wno-unused-parameter"
+ CXXFLAGS="$CXXFLAGS -Wextra -Wno-unused-parameter"
+fi
+
+if test x$threads = xyes
+then
+ AC_DEFINE([USE_THREADS], 1,
+ [Define to 1 if you want to use threads for parallel tasks.])
+fi
+
+if test x$gtk = xyes
+then
+ AC_DEFINE([USE_GTK], 1,
+ [Define to 1 if you want to use GTK+ info/error dialogs.])
+else
+if test x$qt4 = xyes
+then
+ AC_DEFINE([USE_QT4], 1,
+ [Define to 1 if you want to use QT info/error dialogs.])
+fi
+fi
+
+AC_DEFINE_UNQUOTED([YOINK_LOGLEVEL], [$log_level],
+ [Define to detail level of logging.])
+
+
+if test "x$prefix" = xNONE
+then
+ prefix="$ac_default_prefix"
+fi
+
+if test x$WIN32 = xyes
+then
+ DATADIR="data"
+else
+ eval eval DATADIR="${datadir}/$PACKAGE"
+fi
+
+AC_SUBST([DATADIR])
+AC_DEFINE_UNQUOTED([YOINK_DATADIR], ["$DATADIR"],
+ [Define to path of game asset directory.])
+
+
+#
+# Split the version number into components.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+VERSION_MAJOR=$(echo $VERSION | cut -d. -f1)
+VERSION_MINOR=$(echo $VERSION | cut -d. -f2)
+VERSION_REVISION=$(echo $VERSION | cut -d. -f3)
+
+AC_DEFINE_UNQUOTED([VERSION_MAJOR], [${VERSION_MAJOR:-0}],
+ [Define to major version number component.])
+
+AC_DEFINE_UNQUOTED([VERSION_MINOR], [${VERSION_MINOR:-0}],
+ [Define to minor version number component.])
+
+AC_DEFINE_UNQUOTED([VERSION_REVISION], [${VERSION_REVISION:-0}],
+ [Define to revision version number component.])
+
+if test x$WIN32 = xyes
+then
+ PVERSION="${VERSION_MAJOR:-0}.${VERSION_MINOR:-0}.${VERSION_REVISION:-0}.0"
+ AC_SUBST([PVERSION])
+fi
+
+# these are used in src/yoink.rc
+
+
+#
+# Checks for system functions/headers and compiler characteristics.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+AC_C_STRINGIZE
+AC_C_INLINE
+
+AC_TYPE_UINT8_T
+AC_TYPE_UINT16_T
+AC_TYPE_UINT32_T
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+
+AC_FUNC_ERROR_AT_LINE
+AC_FUNC_STRTOD
+AC_CHECK_FUNCS([nanosleep strchr strcspn strrchr strstr])
+
+AC_HEADER_STDBOOL
+AC_HEADER_STDC
+AC_CHECK_HEADERS([stddef.h stdint.h stdlib.h string.h unistd.h])
+
+
+#
+# Checks for build dependencies.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+##### boost #####
+website="http://www.boost.org/"
+BOOST_SMART_PTR
+BOOST_STRING_ALGO
+BOOST_BIND
+BOOST_FUNCTION
+
+##### SDL #####
+website="http://www.libsdl.org/"
+AM_PATH_SDL([1.2.10],
+ [CFLAGS="$CFLAGS $SDL_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
+ LIBS="$LIBS $SDL_LIBS"])
+
+##### opengl, glu #####
+website="http://www.mesa3d.org/"
+AC_CHECK_HEADERS([GL/gl.h GL/glu.h],,
+ [missing=yes
+ echo "***** Missing GL headers ($website) *****"])
+if test x$WIN32 == xyes
+then
+# autoconf library search macro doesn't find opengl32 on windows because it uses
+# different name hashing, but it links fine; assume it's there
+ LIBS="$LIBS -lglu32 -lopengl32"
+else
+ AC_SEARCH_LIBS([glEnable], [GL MesaGL],,
+ [missing=yes
+ echo "***** Missing libGL ($website) *****"])
+ AC_SEARCH_LIBS([gluDisk], [GLU MesaGLU],,
+ [missing=yes
+ echo "***** Missing libGLU ($website) *****"])
+fi
+
+##### openal, alut #####
+website="http://connect.creativelabs.com/openal/"
+AC_CHECK_HEADERS([AL/al.h AL/alut.h],,
+ [missing=yes
+ echo "***** Missing OpenAL headers ($website) *****"])
+AC_SEARCH_LIBS([alEnable], [openal openal32],,
+ [missing=yes
+ echo "***** Missing libopenal ($website) *****"])
+AC_SEARCH_LIBS([alutInit], [alut],,
+ [missing=yes
+ echo "***** Missing libalut ($website) *****"])
+
+##### SDL_image #####
+website="http://www.libsdl.org/projects/SDL_image/"
+AC_CHECK_HEADERS([SDL/SDL_image.h],,
+ [missing=yes
+ echo "***** Missing SDL_image header ($website) *****"])
+AC_SEARCH_LIBS([IMG_Load], [SDL_image],,
+ [missing=yes
+ echo "***** Missing libSDL_image ($website) *****"])
+
+##### libvorbis #####
+website="http://www.xiph.org/downloads/"
+AC_CHECK_HEADERS([vorbis/codec.h vorbis/vorbisfile.h],,
+ [missing=yes
+ echo "***** Missing vorbis headers ($website) *****"])
+AC_SEARCH_LIBS([ov_open], [vorbisfile],,
+ [missing=yes
+ echo "***** Missing libvorbisfile ($website) *****"])
+
+##### liblua #####
+website="http://www.lua.org/"
+AC_CHECK_HEADERS([lua.h],,
+ [missing=yes
+ echo "***** Missing lua headers ($website) *****"])
+AC_SEARCH_LIBS([lua_load], [lua],,
+ [missing=yes
+ echo "***** Missing liblua ($website) *****"])
+
+if test x$gtk = xyes
+then
+ ##### GTK+ 2.0 #####
+ website="http://www.gtk.org/"
+ PKG_CHECK_MODULES([GTK], [gtk+-2.0],
+ [LIBS="$LIBS $GTK_LIBS"
+ CFLAGS="$CFLAGS $GTK_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $GTK_CFLAGS"],
+ [missing=yes
+ echo "***** Missing GTK+-2.0 ($website) *****"])
+fi
+
+if test x$qt4 = xyes
+then
+ ##### QT4 #####
+ website="http://qt.nokia.com/"
+ PKG_CHECK_MODULES([QT], [QtGui],
+ [LIBS="$LIBS $QT_LIBS"
+ CFLAGS="$CFLAGS $QT_CFLAGS"
+ CXXFLAGS="$CXXFLAGS $QT_CFLAGS"],
+ [missing=yes
+ echo "***** Missing QT ($website) *****"])
+fi
+
+##### librt (optional) #####
+AC_SEARCH_LIBS([clock_gettime], [rt],
+ [AC_DEFINE([HAVE_CLOCK_GETTIME], 1,
+ [Define to 1 if you have the 'clock_gettime' function.])])
+
+
+if test x$missing == xyes
+then
+ AC_MSG_ERROR([please install missing dependencies (see messages above)])
+fi
+
+
+#
+# Find the data files to install.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+DATA_FILES=$(echo $(cd data; \
+ find . -name "*.lua" \
+ -o -name "*.ogg" \
+ -o -name "*.png" \
+ -o -name "yoinkrc"))
+AC_SUBST([DATA_FILES])
+
+
+#
+# Create the build files.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
AC_CONFIG_FILES([Makefile
- src/Makefile])
+ data/Makefile
+ src/Makefile
+ doc/Makefile doc/yoink.6
+ win32/Makefile win32/build-installer.sh])
+
+AC_CONFIG_HEADERS([src/config.h])
+
AC_OUTPUT
+
+#
+# Print a friendly little message.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+echo ""
+echo " Configuration complete! :-)"
+echo ""
+echo " Target: $target"
+echo " Prefix: $prefix"
+echo " Data Directory: $DATADIR"
+echo " Log Level: $log_level"
+echo " Debug: $debug"
+echo " Double Precision: $double_precision"
+echo " Profile: $profile"
+echo " Extra Warnings: $extra_warnings"
+echo ""
+echo " To finish the installation, execute:"
+echo " make"
+echo " make install"
+echo ""
+