dnl Project: ipv6calc
dnl File   : configure.in
dnl Version: $Id: configure.in,v 1.31 2011/02/27 12:36:05 peter Exp $

dnl Process this file with autoconf to produce a configure script.
AC_INIT(ipv6calc, 0.81.0, ipv6calc@deepspace6.net, ipv6calc, http://www.deepspace6.net/projects/ipv6calc.html)

AC_DEFINE(COPYRIGHT_YEAR, "2011", [Copyright year])

COPYRIGHT_YEAR=2011
AC_SUBST(COPYRIGHT_YEAR)

dnl Define version header
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
dnl AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_MAKE_SET

dnl Checks for header files.
AC_HEADER_STDC

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_C_BIGENDIAN

dnl Checks for library functions.
AC_FUNC_MEMCMP
AC_CHECK_FUNCS(strspn strstr)

dnl Check for getopt
AC_CHECK_FUNC(getopt_long, [],
  [
    AC_LIBOBJ(../getopt/getopt)
    AC_LIBOBJ(../getopt/getopt1)
    GETOPT_INCLUDE=-I../getopt
    ENABLE_BUNDLED_GETOPT=1
  ])
AC_SUBST(GETOPT_INCLUDE)
AC_SUBST(ENABLE_BUNDLED_GETOPT)

dnl IP2Location support
AC_ARG_ENABLE([ip2location], 
	AS_HELP_STRING([--enable-ip2location],
	               [Enable IP2Location support (default: disabled)]),
	[
        IP2LOCATION="$enableval"
        IP2LOCATION_LIB="-lIP2Location"
    ],
    [IP2LOCATION="no"])

AC_ARG_WITH([ip2location-headers],
    AS_HELP_STRING([--with-ip2location-headers=DIR],
                   [IP2Location include files location]),
    [IP2LOCATION_INCLUDE="-I$withval"])

AC_ARG_WITH([ip2location-lib],
    AS_HELP_STRING([--with-ip2location-lib=DIR],
                   [IP2Location library location]),
    [IP2LOCATION_LIB="-L$withval $IP2LOCATION_LIB"])

AC_ARG_WITH([ip2location-static],
    AS_HELP_STRING([--with-ip2location-static],
                   [Explicitly link IP2Location statically (default=no)]),
    [if test "$withval" != "no"; then 
        IP2LOCATION_LIB="-Wl,-Bstatic $IP2LOCATION_LIB -Wl,-Bdynamic"
     fi])

if test "$IP2LOCATION" = "yes"; then
    CPPFLAGS="$CPPFLAGS $IP2LOCATION_INCLUDE"
    LDFLAGS="$LDFLAGS $IP2LOCATION_LIB"
    AC_CHECK_HEADER(IP2Location.h,,
        [AC_MSG_ERROR([IP2Location library header files not found])]
    )
    AC_CHECK_LIB(IP2Location,IP2Location_open,
        [
            AC_DEFINE(SUPPORT_IP2LOCATION, 1, Define if you want IP2Location support.)
        ],
        [
            AC_MSG_ERROR([IP2Location library header files were found but the library was not found])
        ])
fi

AC_SUBST(IP2LOCATION_INCLUDE)
AC_SUBST(IP2LOCATION_LIB)

dnl GeoIP support
AC_ARG_ENABLE([geoip], 
	AS_HELP_STRING([--enable-geoip],
	               [Enable GeoIP support (default: disabled)]),
    [
	if test "$enableval" != "no"; then
        	GEOIP="$enableval"
        	GEOIP_LIB="-lGeoIP"
	fi
    ],
    [GEOIP="no"])

AC_ARG_WITH([geoip-headers],
    AS_HELP_STRING([--with-geoip-headers=DIR],
                   [GeoIP include files location]),
    [GEOIP_INCLUDE="-I$withval"])

AC_ARG_WITH([geoip-lib],
    AS_HELP_STRING([--with-geoip-lib=DIR],
                   [GeoIP library location]),
    [GEOIP_LIB="-L$withval $GEOIP_LIB"])


AC_ARG_WITH([geoip-static],
    AS_HELP_STRING([--with-geoip-static],
                   [Explicitly link GeoIP statically (default=no)]),
    [if test "$withval" != "no"; then 
        GEOIP_LIB="-Wl,-Bstatic $GEOIP_LIB -Wl,-Bdynamic"
     fi])

AC_ARG_WITH([geoip-default-file],
       AS_HELP_STRING([--with-geoip-default-file=file],
               [Use a default GeoIP database file when ipv6calc is invoked with '--db-geoip-default|-G']),
       [AC_DEFINE_UNQUOTED(GEOIP_DEFAULT_FILE, "$withval", Define for a default GeoIP database file.)])

if test "$GEOIP" = "yes"; then
    CPPFLAGS="$CFLAGS $GEOIP_INCLUDE"
    LDFLAGS="$LDFLAGS $GEOIP_LIB"
    AC_CHECK_HEADER(GeoIP.h,,
        [AC_MSG_ERROR([GeoIP library header files not found])]
    )
    AC_CHECK_LIB(GeoIP, GeoIP_open,
        [
	        AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
        ],
        [
            AC_MSG_ERROR([GeoIP library header files were found but the library was not found])
        ])
fi

AC_SUBST(GEOIP_INCLUDE)
AC_SUBST(GEOIP_LIB)

dnl Files to create
AC_OUTPUT([Makefile
	md5/Makefile
	tools/Makefile
	getopt/Makefile
	ipv6calc/Makefile
	lib/Makefile
	man/Makefile
	ipv6logconv/Makefile
	ipv6loganon/Makefile
	ipv6logstats/Makefile
	contrib/ipv6calc.spec
	ipv6calcweb/ipv6calcweb.cgi ])
