configure.in [tools/Rusle2SoilsXMLCreator/pg/rusle2_from_ssurgo_build_newbackup] Revision:   Date:
dnl Process this file with autoconf to produce a configure script.

AC_INIT(rusle2_from_ssurgo.cc)
dnl Every other copy of the package version number gets its value from here
AM_INIT_AUTOMAKE(rusle2_from_ssurgo, 0.1.0)

dnl create a config.h file (Automake will add -DHAVE_CONFIG_H)
AM_CONFIG_HEADER(config.h)

AC_SUBST(VERSION)

ISODATE=`date +%Y-%m-%d`
AC_SUBST(ISODATE)

AC_CANONICAL_HOST

dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC
AC_PROG_CXX

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h sys/param.h sys/time.h time.h sys/mkdev.h sys/sysmacros.h string.h memory.h fcntl.h dirent.h sys/ndir.h ndir.h alloca.h locale.h stdlib.h libintl.h )


dnl ------- C++ Checks
AC_LANG_PUSH(C++)
AC_CHECK_HEADERS(cstdlib iostream fstream string cmath boost/lexical_cast.hpp, [], [AC_MSG_ERROR(Cannot find header file)])
AC_LANG_POP
dnl ------- END C++ CHECKS


dnl -- Debug flags

AC_ARG_WITH(debug,
	AC_HELP_STRING(
		[--with-debug],
		[Enable NDEBUG Flags]),
	[],
	[ AC_DEFINE(NDEBUG,1,[Define NDEBUG flag]) ])

dnl -- End Debug Flag




dnl Postgres Configuration
AC_PATH_PROGS(PG_CONFIG, pg_config)
if test -z "$PG_CONFIG" || test ! -r "$PG_CONFIG"; then
	        AC_MSG_ERROR([
PostgreSQL configuration script pg_config not found.  Make sure this is in your
command path before configuring.  Without it, the configure script has no way to
find the right location for the libpq library and its headers.
])
fi
with_postgres_include=`$PG_CONFIG --includedir`
AC_MSG_NOTICE([using PostgreSQL headers at $with_postgres_include])
with_postgres_lib=`$PG_CONFIG --libdir`
AC_MSG_NOTICE([using PostgreSQL libraries at $with_postgres_lib])

AC_SUBST(with_postgres_lib)
AC_SUBST(with_postgres_include)
AC_SUBST(POSTGRES_LIB)
POSTGRES_INCLUDE="-I${with_postgres_include}"
AC_SUBST(POSTGRES_INCLUDE)

AC_CHECK_HEADER([${with_postgres_include}/libpq-fe.h],[],[AC_MSG_ERROR([
Cannot find libpq-fe.h in ${with_postgres_include}.  Are you sure the libpq
headers are installed correctly?  They should be in the directory returned by
"pg_config --includedir".

If you do have libpq (the C-language client library for PostgreSQL) installed,
make sure you have the related development materials--mainly its header files--
as well as the library binary.  Some system distributions keep the two in
seperate packages with names like "alibrary" and "alibrary-dev", respectively.
In that case, make sure you have the latter installed as well.
])])


AC_MSG_CHECKING([for ability to compile source files using libpq])
AC_TRY_COMPILE([#include<${with_postgres_include}/libpq-fe.h>],[PQexec(0,"")],
[],
[AC_MSG_ERROR([
Could not compile a call to a basic libpq function.  There must be something
seriously wrong with the headers that "pg_config --includedir" pointed to; the
contents of config.log may give you a clue about the nature of the failure.
Source including the libpq header libpq-fe.h can be compiled, but a call to the
most basic libpq function PQexec() failed to compile successfully.  This is the
litmus test for a working libpq.
])])
AC_MSG_RESULT(yes)

LDFLAGS="$LDFLAGS -L${with_postgres_lib}"
CXXFLAGS="$CXXFLAGS -I${with_postgres_include}"

dnl
dnl End checking libpostgres


dnl
dnl libxml2 Configuration
AC_LANG_PUSH(C++)
AC_PATH_PROGS(XML2_CONFIG, xml2-config)
if test -z "$XML2_CONFIG" || test ! -r "$XML2_CONFIG"; then
		AC_MSG_ERROR([
libxml2 configuration script xml2-config not found. Make sure this is in your
command path before configuring. Without it, the configure script as no way to
find the right location for the libxml2 library and its headers.
])
fi
with_xml_include=`$XML2_CONFIG --cflags`
AC_MSG_NOTICE([using libxml2 headers at $with_xml_include])
with_xml_lib=`$XML2_CONFIG --libs`
AC_MSG_NOTICE([using libxml2 libraries at $with_xml_lib])

CXXFLAGS="$CXXFLAGS ${with_xml_include}"
CFLAGS="$CFLAGS ${with_xml_include}"

AC_SUBST(with_xml_lib)
AC_CHECK_HEADER([libxml/xmlversion.h],[],[AC_MSG_ERROR([
Cannot find libxml/xmlversion.h in ${with_xml_include}. Are you sure the libxml2
headers are installed correctly? The should be in the directory returned by 
"xml-config --cflags".])])

AC_MSG_CHECKING([for ability to compile source files using libxml2])
AC_TRY_COMPILE([#include<libxml/xmlversion.h>],[LIBXML_TEST_VERSION],
[],
[AC_MSG_ERROR([
Could not compile a call to a libxml2 version function.  There must be something
seriously wrong with the headers that "xml2-config --cflags" pointed to; the
contents of config.log may give you a clue about the nature of the failure.
This is the litmus test for a working libxml2.
])])
AC_MSG_RESULT(yes)
LDFLAGS="$LDFLAGS ${with_xml_lib}"
AC_LANG_POP

dnl
dnl End Checking libxml2

jm_CHECK_TYPE_STRUCT_UTIMBUF
AC_HEADER_MAJOR
AC_FUNC_ALLOCA
AC_STRUCT_TM
AC_STRUCT_ST_BLOCKS
AC_FUNC_CLOSEDIR_VOID
AC_CHECK_FUNCS(mkfifo)
AC_CHECK_FUNC(mknod)

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.
AC_CHECK_LIB(pq, PQprotocolVersion, [], [ AC_MSG_ERROR([libpq not found]) ] )

AC_OUTPUT(Makefile rusle2_from_ssurgo.lsm rusle2_from_ssurgo.spec)