dnl ***********************************************************************
dnl Process this file with autoconf to produce a configure script.
dnl ***********************************************************************
AC_PREREQ(2.50)
AC_INIT(openslp, 1.2.1, openslp-devel@lists.sourceforge.net)
AC_CONFIG_SRCDIR(slpd/slpd_main.c)
AM_INIT_AUTOMAKE

AC_CONFIG_HEADERS(config.h)

dnl ***********************************************************************
dnl We don't want /usr/etc or /usr/var
dnl ***********************************************************************
test "$prefix" = NONE && prefix=/usr
if test "$prefix" = '/usr'; then 
    # We don't want /usr/etc and /usr/var
    test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
    test "$sharedstatedir" = '${prefix}/com' && localstatedir=/var
    test "$localstatedir" = '${prefix}/var' && localstatedir=/var
fi

dnl ***********************************************************************
dnl Take care of the debug stuff
dnl ***********************************************************************
AC_ARG_ENABLE(debug,
[  --enable-debug          Turn on debugging (default off)],
debug=$enableval,
debug=no)

CFLAGS="${CFLAGS:=}"
LDFLAGS="${LDFLAGS:=}"

case "$debug" in
  yes) CFLAGS="-g -DDEBUG -D_REENTRANT=1 $CFLAGS" ;;
  no)  CFLAGS="-DNDEBUG -D_REENTRANT=1 $CFLAGS" ;;
  *) AC_MSG_ERROR(bad value ${debug} for --enable-debug) ;;
esac


dnl ***********************************************************************
dnl System type macros
dnl ***********************************************************************
AC_CANONICAL_HOST
case "$host_os" in
  *linux*) CFLAGS="$CFLAGS -DLINUX" ;;
  *solaris*) CFLAGS="$CFLAGS -DSOLARIS";;
  *aix*) CFLAGS="$CFLAGS -DAIX";;
  *hpux*) CFLAGS="$CFLAGS -DHPUX";;
esac


dnl ***********************************************************************
dnl SLPv1 support can be turned off
dnl ***********************************************************************
AC_ARG_ENABLE(slpv1,
[  --enable-slpv1          Turn on SLPv1 support (default on)],
slpv1=$enableval,
slpv1=yes)

dnl Conditional for optional SLPv1 support
AM_CONDITIONAL(ENABLE_SLPv1, test "$slpv1" = "yes")

if test "$slpv1" = "yes"; then
    AC_DEFINE(ENABLE_SLPv1, 1, [defined if struct sigaction has member sa_restorer])
fi

dnl ***********************************************************************
dnl Handle Predicates 
dnl ***********************************************************************
AC_ARG_ENABLE(predicates,
[  --disable-predicates    Turn off predicates],
predicates=$enableval,
predicates=yes)

dnl Conditional for optional predicates support
AM_CONDITIONAL(ENABLE_PREDICATES, test "$predicates" = "yes")

if test "$predicates" = "yes"; then
    AC_DEFINE(ENABLE_PREDICATES, 1, [defined if predicates are enabled])
fi

dnl ***********************************************************************
dnl Enable asyncronous support in libslp SLP API library 
dnl ***********************************************************************
AC_ARG_ENABLE(async-api,
[  --enable-async-api      Turn on asyncronous support (default off)],
asyncapi=$enableval,
asyncapi=no)

dnl Conditional for optional asyncronous support in libslp SLP API library
AM_CONDITIONAL(ENABLE_ASYNC_API, test "$asyncapi" = "yes")

if test "$asyncapi" = "yes"; then
    AC_DEFINE(ENABLE_ASYNC_API, 1, [defined if the async SLP API support is enabled])
fi

dnl ***********************************************************************
dnl Enable security support 
dnl ***********************************************************************
AC_ARG_ENABLE(slpv2-security,
[  --enable-slpv2-security Turn on security support (default off)],
slpv2security=$enableval,
slpv2security=no)

AC_CHECK_LIB(crypto, DSA_sign) 
AC_CHECK_FUNCS(DSA_verify DSA_size DSA_free SHA1)

dnl Conditional for optional security support in libslp SLP API library
AM_CONDITIONAL(ENABLE_SLPv2_SECURITY, test "$slpv2security" = "yes")
if test "$slpv2security" = "yes"; then
    AC_DEFINE(ENABLE_SLPv2_SECURITY, 1, [defined if the SLPv2 authentication support is enabled])
fi


dnl ***********************************************************************
dnl Checks for programs.
dnl ***********************************************************************
AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_LIBTOOL
AM_PROG_LEX
AC_PROG_YACC

dnl ***********************************************************************
dnl Set C/C++ compiler specific warning/optimization flags
dnl ***********************************************************************
if test X"$GCC" = X"yes"; then        
    CFLAGS="$CFLAGS -Wall"
    if test X"$debug" = X"yes"; then
       CFLAGS="$CFLAGS -Werror"
    fi
    if test X"$debug" = X"no"; then 
       OPTFLAGS="-O3"
    fi
    
elif $CC -V 2>&1 | grep "WorkShop Compilers"; then
    dnl Allow C++ style comments
    CFLAGS="$CFLAGS -xCC" 
    if test X"$debug" = X"no"; then
        OPTFLAGS="-fast"
        if echo $CC | grep "xarch=v9"; then
            dnl "-fast" sets -xarch=v8 disabling 64-bit mode, enable it again
            OPTFLAGS="$OPTFLAGS -xarch=v9"
        fi
    fi
elif echo $host_os | grep -i "osf" >/dev/null; then
    CFLAGS="$CFLAGS -std"
    if test X"$debug" = X"no"; then
        OPTFLAGS="-O"
    fi
else
    if test X"$debug" = X"no"; then
        OPTFLAGS="-O"
    fi
fi
CFLAGS="$CFLAGS $OPTFLAGS"

dnl ***********************************************************************
dnl Checks for header files.
dnl ***********************************************************************
AC_HEADER_STDC
AC_CHECK_HEADERS(string.h sys/types.h stdint.h netinet/in.h)

dnl ***********************************************************************
dnl Checks for data types.
dnl ***********************************************************************
OPENSLP_CHECK_TYPE(socklen_t, int, [defined to size_t if <sys/socket.h> does not support socklen_t data type])
OPENSLP_STRUCT_SA_RESTORER

dnl ***********************************************************************
dnl Checks for libraries.
dnl ***********************************************************************
AC_CHECK_LIB(resolv, inet_aton)
AC_CHECK_LIB(socket, main)
AC_CHECK_LIB(nsl, gethostbyname)
dnl AC_CHECK_LIB(m, main)
dnl AC_CHECK_FUNCS(ceil log10 strncasecmp strcasecmp )
AC_CHECK_FUNCS(strncasecmp strcasecmp)
dnl AC_OUTPUT( Makefile common/Makefile libslpattr/Makefile libslp/Makefile 
dnl 	slpd/Makefile slptool/Makefile test/Makefile slp.list )
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ common/Makefile ])
AC_CONFIG_FILES([ libslpattr/Makefile ])
AC_CONFIG_FILES([ libslp/Makefile ])
AC_CONFIG_FILES([ slpd/Makefile ])
AC_CONFIG_FILES([ slptool/Makefile ])
AC_CONFIG_FILES([ test/Makefile ])
AC_CONFIG_FILES([ slp.list ])
AC_OUTPUT

