dnl
dnl  $Id: configure.in,v 1.5 2001/06/19 23:14:48 psavola Exp $
dnl
dnl   Authors:
dnl    Lars Fenneberg		<lf@elemental.net>	 
dnl
dnl   This software is Copyright 1996-2000 by the above mentioned author(s), 
dnl   All Rights Reserved.
dnl
dnl   The license which is distributed with this software in the file COPYRIGHT
dnl   applies to this software. If your distribution is missing this file, you
dnl   may request it from <lf@elemental.net>.
dnl
dnl

AC_REVISION ($Id: configure.in,v 1.5 2001/06/19 23:14:48 psavola Exp $)
AC_INIT(radvd.c)

AC_CANONICAL_SYSTEM
VERSION=`cat ${srcdir}/VERSION | grep -v '^#' | tr -d '\012'`
AM_INIT_AUTOMAKE(radvd,$VERSION,true)

echo $ac_n "building for architecture""... $ac_c" 1>&6
case "$target" in
	*linux*)
		AC_MSG_RESULT(linux)
                arch=linux
        ;;
        *bsd*)
		AC_MSG_RESULT(bsd44)
                arch=bsd44
        ;;
        *)      
		AC_MSG_RESULT(unknown)
		AC_MSG_ERROR(
[currently only Linux and BSD 4.4 with NRL's IPv6 code are
supported. If you have such a system and it is not guessed correctly 
you must specifiy it with --target on the configure command line])
        ;;
esac

dnl Determine CC and preset CFLAGS
AC_PROG_CC

dnl Needed for normal compile
AC_PROG_INSTALL
AC_PATH_PROG(RM, rm, NOTFOUND)
if test "x$RM" = xNOTFOUND; then
	AC_MSG_ERROR(can't find rm in your path - check PATH)
fi
AC_PATH_PROG(SED, sed, NOTFOUND)
if test "x$SED" = xNOTFOUND; then
	AC_MSG_ERROR(can't find sed in your path - check PATH)
fi
dnl Not needed
AC_PATH_PROG(LN, ln)
AC_PROG_YACC
AM_PROG_LEX
AC_PATH_PROG(TAR, tar)
AC_PATH_PROG(GZIP, gzip)

dnl Check where to put the logfile
AC_MSG_CHECKING(where to put logfile)
AC_ARG_WITH(logfile,
[  --with-logfile          Path to the radvd logfile [/var/log/radvd.log]],
	PATH_RADVD_LOG=$withval,
	PATH_RADVD_LOG=/var/log/radvd.log)
AC_MSG_RESULT($PATH_RADVD_LOG)

dnl Check where to put the pidfile
AC_MSG_CHECKING(where to put pidfile)
AC_ARG_WITH(pidfile,
[  --with-pidfile          Path to the radvd pidfile [/var/run/radvd.pid]],
	PATH_RADVD_PID=$withval,
	PATH_RADVD_PID=/var/run/radvd.pid)
AC_MSG_RESULT($PATH_RADVD_PID)

dnl Check where to put the configfile
AC_MSG_CHECKING(where to find configfile)
AC_ARG_WITH(configfile,
[  --with-configfile       Path to the radvd config file [SYSCONF/radvd.conf]],
	PATH_RADVD_CONF=$withval,
	PATH_RADVD_CONF=${sysconfdir}/radvd.conf)
AC_MSG_RESULT($PATH_RADVD_CONF)

dnl Checking which syslog facility to use
AC_MSG_CHECKING(which syslog facility to use)
AC_ARG_WITH(facility,
[  --with-facility         Syslog facility to use when using syslog logging],
	LOG_FACILITY=$withval,
	LOG_FACILITY=LOG_DAEMON)
AC_MSG_RESULT($LOG_FACILITY)

dnl Checks for libraries.

AC_CHECK_LIB(c, inet_ntop,,
 AC_CHECK_LIB(inet6, inet_ntop,
  LIBS="$LIBS -linet6"
  ,
  unset ac_cv_lib_inet6_inet_ntop
  oldldflags=$LDFLAGS
  LDFLAGS="$LDFLAGS -L/usr/inet6/lib"
  echo $ac_n "with -L/usr/inet6/lib: $ac_c" 1>&6
  AC_CHECK_LIB(inet6, inet_ntop,
   LIBS="$LIBS -linet6"
   ,
   unset ac_cv_lib_inet6_inet_ntop
   LDFLAGS=$oldldflags
   LDFLAGS="$LDFLAGS -L/usr/ipv6/lib"
   echo $ac_n "with -L/usr/ipv6/lib: $ac_c" 1>&6
   AC_CHECK_LIB(inet6, inet_ntop,
    LIBS="$LIBS -linet6"
    ,
    AC_MSG_ERROR(can't continue without libinet6.a library - check your LDFLAGS)
   )
  )
 )
)
# prevent caching
unset ac_cv_lib_inet6_inet_ntop

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/time.h)
AC_HEADER_TIME

AC_CHECK_HEADER(netinet/ipv6.h, hdrfound=yes,
 AC_CHECK_HEADER(netinet/ip6.h, hdrfound=yes, hdrfound=no)
)
if test "$hdrfound" = no
then
 AC_MSG_CHECKING(for netinet/ip6.h or ipv6.h in /usr/inet6/include)
 if test -f /usr/inet6/include/netinet/ipv6.h
 then
  AC_MSG_RESULT([yes (netinet/ipv6.h)])
  CPPFLAGS="$CPPFLAGS -I/usr/inet6/include"
 elif test -f /usr/inet6/include/netinet/ip6.h
 then
  AC_MSG_RESULT([yes (netinet/ip6.h)])
  CPPFLAGS="$CPPFLAGS -I/usr/inet6/include"
 else
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(for netinet/ip6.h or ipv6.h in /usr/ipv6/include)
  if test -f /usr/ipv6/include/netinet/ipv6.h
  then
   AC_MSG_RESULT([yes (netinet/ipv6.h)])
   CPPFLAGS="$CPPFLAGS -I/usr/ipv6/include"
  elif test -f /usr/ipv6/include/netinet/ip6.h
  then
   AC_MSG_RESULT([yes (netinet/ip6.h)])
   CPPFLAGS="$CPPFLAGS -I/usr/ipv6/include"
  fi
 fi
fi
unset hdrfound

AC_CHECK_HEADERS(sys/sockio.h getopt.h inttypes.h)
AC_CHECK_HEADERS(net/if_dl.h net/if_types.h net/if_arp.h)
AC_CHECK_HEADERS(machine/param.h)
AC_CHECK_HEADERS(machine/limits.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

AC_MSG_CHECKING(whether struct sockaddr_in6 has sin6_scope_id)
AC_TRY_COMPILE([#include <sys/types.h>
#include <netinet/in.h>], [static struct sockaddr_in6 ac_sin6; int ac_size = 
sizeof (ac_sin6.sin6_scope_id);], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SIN6_SCOPE_ID)],
AC_MSG_RESULT(no))

AC_MSG_CHECKING(whether struct in6_addr has u6_addrXX and defines s6_addrXX)
AC_TRY_COMPILE([#include <netinet/in.h>], [static struct in6_addr in6_u; 
int u =  in6_u.s6_addr16;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_IN6_ADDR_S6_ADDR)],
AC_MSG_RESULT(no))

dnl Checks for library functions.
AC_CHECK_FUNCS(getopt_long)

AC_LINK_FILES(device-${arch}.c, device.c)

AC_SUBST(VERSION)
AC_SUBST(PATH_RADVD_CONF)
AC_SUBST(PATH_RADVD_PID)
AC_SUBST(PATH_RADVD_LOG)
AC_SUBST(LOG_FACILITY)

AM_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
