# Filename: configure.in

AC_INIT(src/pracrod.cc)
AM_INIT_AUTOMAKE( pracrod, 1.0.1 )

dnl ======================
dnl Compile with debug options
dnl ======================
AC_ARG_WITH(debug,
	[  --with-debug            build with debug support (default=no)],
	[],
	[with_debug=no])
if test x$with_debug == xyes; then
    AC_MSG_WARN([*** Building with debug support!])
    AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output])
    CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0"
fi 

dnl ======================
dnl Compile without pentominos support
dnl ======================
AC_ARG_WITH(pentominos,
	[  --with-pentominos       build with pentominos support (default=yes)],
	[],
	[with_pentominos=yes])
if test x$with_pentominos == xno; then
    AC_MSG_WARN([*** Building without pentominos support!])
    AC_DEFINE_UNQUOTED(WITHOUT_PENTOMINOS, , [The project is configured not to use pentomimos])
fi 

dnl ======================
dnl Compile without uploadserver support
dnl ======================
AC_ARG_WITH(uploadserver,
	[  --with-uploadserver     build with uploadserver support (default=yes)],
	[],
	[with_uploadserver=yes])
if test x$with_uploadserver == xno; then
    AC_MSG_WARN([*** Building without uploadserver support!])
    AC_DEFINE_UNQUOTED(WITHOUT_UPLOADSERVER, , [The project is configured not to use the upload server])
fi 

dnl ======================
dnl Compile without db support
dnl ======================
AC_ARG_WITH(db,
	[  --with-db               build with db support (default=yes)],
	[],
	[with_db=yes])
if test x$with_db == xno; then
    AC_MSG_WARN([*** Building without db support!])
    AC_DEFINE_UNQUOTED(WITHOUT_DB, , [The project is configured not to use the db])
else
    dnl ======================
    dnl Check for libpqxx
    dnl ======================
    PKG_CHECK_MODULES(PQXX, libpqxx >= 2.6.8)
fi 

AC_PROG_CXX

AC_PROG_LIBTOOL
AM_PROG_LIBTOOL

AM_CONFIG_HEADER(config.h)
AC_STDC_HEADERS

dnl ======================
dnl Create the ETC var i config.h
dnl ======================
if echo "$prefix" | grep "NONE" > /dev/null
then
	MYPREFIX="/usr/local"
else
	MYPREFIX="${prefix}"
fi
AC_SUBST(MYPREFIX)
AC_DEFINE_UNQUOTED(ETC, "$MYPREFIX/etc", [The path to the config files])

dnl ======================
dnl Use efence in linking and includes
dnl ======================
AC_ARG_ENABLE(efence,
	[  --enable-efence         enable efence - for debugging only (no)],
	[], [ enable_efence=no])             
if test "x$enable_efence" = xno; then
	enable_efence=no
else
	LD_EFENCE="-lefence"
	AC_SUBST(LD_EFENCE)
	AC_DEFINE_UNQUOTED(USE_EFENCE, , [Use the efence includes])
fi

dnl ======================
dnl Use duma in linking and includes
dnl ======================
AC_ARG_ENABLE(duma,
	[  --enable-duma           enable duma - for debugging only (no)],
	[], [ enable_duma=no])             
if test "x$enable_duma" = xno; then
	enable_duma=no
else
	LD_EFENCE="-lduma"
	AC_SUBST(LD_DUMA)
	AC_DEFINE_UNQUOTED(USE_DUMA, , [Use the duma includes])
fi

dnl ======================
dnl Check for lua
dnl ======================
PKG_CHECK_MODULES(LUA, lua >= 5.1)

dnl ======================
dnl Create the XML var i config.h
dnl ======================
AC_DEFINE_UNQUOTED(XML, "$MYPREFIX/share/xml", [The path to the xml files])

dnl ======================
dnl Check for getopt
dnl ======================
AC_HAVE_HEADERS(getopt.h)

dnl ======================
dnl Check for libconfig++
dnl ======================
PKG_CHECK_MODULES(CONFIG, libconfig++ >= 1.0.1)

dnl ======================
dnl Check for eXpat library
dnl ======================
AC_CHECK_HEADER(expat.h, , AC_MSG_ERROR([*** eXpat header file not found!]))
AC_CHECK_LIB(expat, XML_ParserCreate, ,  AC_MSG_ERROR([*** eXpat library not found!]))


AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(LDFLAGS)


AC_OUTPUT(
	Makefile
	src/Makefile
	etc/Makefile
	man/Makefile
	xml/templates/Makefile
	xml/macros/Makefile
	xml/Makefile)