dnl $Id: configure.in,v 1.179.2.3.2.37.2.4 2005/04/13 10:21:09 bfernhomberg Exp $
dnl configure.in for netatalk

AC_INIT(etc/afpd/main.c)

NETATALK_VERSION=`cat $srcdir/VERSION`
AC_SUBST(NETATALK_VERSION)

AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(netatalk, ${NETATALK_VERSION})
AM_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL
AC_PROG_PERL
AC_PROG_GREP
AC_PROG_PS

dnl *********************************************************************
dnl FIXME! FIXME! These should be selectable properly, and should produce
dnl the proper flags and defines...
dnl *********************************************************************

############################################
# we need dlopen/dlclose/dlsym/dlerror for PAM, the password database plugins and the plugin loading code
#AC_SEARCH_LIBS(dlopen, [dl])
# dlopen/dlclose/dlsym/dlerror will be checked again later and defines will be set then

dnl Checks for libraries.
dnl Replace `main' with a function in -labs:
dnl AC_CHECK_LIB(abs, main)
dnl Replace `main' with a function in -laudit:
dnl AC_CHECK_LIB(audit, main)
dnl Replace `main' with a function in -lauth:
dnl AC_CHECK_LIB(auth, main)
dnl Replace `main' with a function in -lcmd:
dnl AC_CHECK_LIB(cmd, main)
dnl Replace `main' with a function in -lcrypt:
dnl AC_CHECK_LIB(crypt, main)
dnl Replace `main' with a function in -ld:
dnl AC_CHECK_LIB(d, main)
dnl Replace `main' with a function in -ldl:
AC_CHECK_LIB(dl, dlopen)
dnl Replace `main' with a function in -lkauth:
dnl AC_CHECK_LIB(kauth, main)
dnl Replace `main' with a function in -lkrb:
dnl AC_CHECK_LIB(krb, main)
dnl Replace `main' with a function in -llwp:
dnl AC_CHECK_LIB(lwp, main)
dnl Replace `main' with a function in -ln:
dnl AC_CHECK_LIB(n, main)
dnl Replace `main' with a function in -lnsl:
AC_CHECK_LIB(nsl, main)
dnl Replace `main' with a function in -lprot:
dnl AC_CHECK_LIB(prot, main)
dnl Replace `main' with a function in -lrx:
dnl AC_CHECK_LIB(rx, main)
dnl Replace `main' with a function in -lrxkad:
dnl AC_CHECK_LIB(rxkad, main)
dnl Replace `main' with a function in -lsocket:
AC_CHECK_LIB(socket, socket)
dnl Replace `main' with a function in -lsys:
dnl AC_CHECK_LIB(sys, main)
dnl Replace `main' with a function in -lubik:
dnl AC_CHECK_LIB(ubik, main)


#
# Check presence of some functions
#
# Check for XPG4 access() function
# Be sure to test before adding AFS libs in LIBS path as AFS lib
# has such a function that works only on AFS filesystems.
AC_CHECK_FUNCS(access)
# 
AC_CHECK_FUNCS(pread pwrite)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h stdint.h strings.h time.h sys/param.h sys/fcntl.h sys/file.h sys/ioctl.h sys/time.h sys/mnttab.h sys/statvfs.h sys/stat.h sys/vfs.h mntent.h syslog.h unistd.h termios.h sys/termios.h netdb.h sgtty.h ufs/quota.h mount.h statfs.h sys/types.h dlfcn.h errno.h sys/errno.h sys/uio.h)
AC_CHECK_HEADER(sys/cdefs.h,,
	AC_MSG_RESULT([enabling generic cdefs.h from tree])
	CFLAGS="-I\$(top_srcdir)/sys/generic $CFLAGS"
)
AC_CHECK_HEADERS([sys/mount.h], , , 
[#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
])

AC_CHECK_HEADERS(langinfo.h locale.h sys/filio.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_RDEV
AC_HEADER_TIME
AC_STRUCT_TM

dnl --------------------------------------------------------------------------
dnl check if dlsym needs to add an underscore, uses libtool macros 
dnl --------------------------------------------------------------------------
AC_LTDL_DLLIB
AC_CHECK_FUNCS(dlopen dlsym dlclose)
AC_LTDL_DLSYM_USCORE
if test x"$libltdl_cv_need_uscore" = xyes; then
    AC_DEFINE(DLSYM_PREPEND_UNDERSCORE, 1, [BSD compatibility macro])
fi


dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_HEADER_MAJOR
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_UTIME_NULL
AC_FUNC_WAIT3
AC_CHECK_FUNCS(getcwd gethostname gettimeofday getusershell mkdir rmdir select socket strdup strcasestr strstr strtoul strchr memcpy)
AC_CHECK_FUNCS(backtrace_symbols)
AC_CHECK_FUNCS(setlocale nl_langinfo)
AC_CHECK_FUNCS(waitpid getcwd strdup strndup strnlen strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64)
AC_CHECK_FUNCS(strlcpy strlcat)
AC_CHECK_FUNCS(setlinebuf)
AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, [#include <time.h>])
AC_CACHE_SAVE

dnl Checks for (v)snprintf
NETATALK_SNPRINTF_CHECK

dnl --------------------------------------------------------------------------
dnl 64bit platform check
dnl --------------------------------------------------------------------------

AC_MSG_CHECKING([whether to check for 64bit libraries])
dnl Determine libdir name
case $host in
*-*-linux*)
  # Test if the compiler is 64bit
  echo 'int i;' > conftest.$ac_ext
  atalk_cv_cc_64bit_output=no
  if AC_TRY_EVAL(ac_compile); then
    case `/usr/bin/file conftest.$ac_objext` in
    *"ELF 64"*)
      atalk_cv_cc_64bit_output=yes
      ;;
    esac
  fi
  rm -rf conftest*
  ;;
esac

dnl
dnl FIXME: Do we need something like this for Solaris 64bit?
dnl

case $host_cpu:$atalk_cv_cc_64bit_output in
powerpc64:yes | s390x:yes | sparc64:yes | x86_64:yes)
  atalk_libname="lib64"
  AC_MSG_RESULT([yes])
  ;;
*:*)
  atalk_libname="lib"
  AC_MSG_RESULT([no])
  ;;
esac

dnl --------------------------------------------------------------------------
dnl specific configuration comes in here:
dnl --------------------------------------------------------------------------


netatalk_cv_admin_group=yes
AC_MSG_CHECKING([for administrative group support])
AC_ARG_ENABLE(admin-group,
 	[  --disable-admin-group   disable admin group],[
        if test x"$enableval" = x"no"; then
		AC_DEFINE(ADMIN_GRP, 0, [Define if the admin group should be enabled])
		netatalk_cv_admin_group=no
		AC_MSG_RESULT([no])
	else
		AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
		AC_MSG_RESULT([yes])
        fi],[
		AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
		AC_MSG_RESULT([yes])
	]
)

NETATALK_AFS_CHECK

NETATALK_CONFIG_DIRS

AC_MSG_CHECKING([whether to use logfile])
AC_ARG_WITH(logfile,
	[  --with-logfile=PATH     path for file used by logger],[
        if test x"$withval" = x"no"; then
		AC_DEFINE(DISABLE_LOGGER, 1, [Define if the logger should not be used])
		AC_MSG_RESULT([no, syslog])
	elif test "$withval" != "yes"; then
		AC_DEFINE_UNQUOTED(LOGFILEPATH, "$withval", [Path to the log file])
		AC_MSG_RESULT([$withval])
	else
		AC_DEFINE_UNQUOTED(LOGFILEPATH, "/var/log/netatalk.log", [Path to the log file])
		AC_MSG_RESULT([/var/log/netatalk.log]) 
	fi],[
		AC_DEFINE(DISABLE_LOGGER, 1, [Define if the logger should not be used])
		AC_MSG_RESULT([no, syslog])
	]
)


netatalk_cv_with_cracklib=no
AC_ARG_WITH(cracklib,
	[  --with-cracklib=DICT    enable/set location of cracklib dictionary],[
	if test "x$withval" != "xno" ; then
		cracklib="$withval"
		AC_CHECK_LIB(crack, main, [
			AC_DEFINE(USE_CRACKLIB, 1, [Define if cracklib should be used])
			LIBS="$LIBS -lcrack"
			if test "$cracklib" = "yes"; then
				cracklib="/usr/$atalk_libname/cracklib_dict"
			fi
			AC_DEFINE_UNQUOTED(_PATH_CRACKLIB, "$cracklib",
				[path to cracklib dictionary])
			AC_MSG_RESULT([setting cracklib dictionary to $cracklib])
			netatalk_cv_with_cracklib=yes
			],[
			AC_MSG_ERROR([cracklib not found!])
			]
		)
	fi
	]
)
AC_MSG_CHECKING([for cracklib support])
AC_MSG_RESULT([$netatalk_cv_with_cracklib])

netatalk_cv_ddp_enabled=yes
AC_MSG_CHECKING([whether to enable DDP])
AC_ARG_ENABLE(ddp,
	[  --disable-ddp           disable DDP],[
	if test "$enableval" = "no"; then 
		AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
		AC_MSG_RESULT([no])
		netatalk_cv_ddp_enabled=no
	else
		AC_MSG_RESULT([yes])
	fi
	],[
		AC_MSG_RESULT([yes])
	]
)

AC_MSG_CHECKING([whether to enable debug code])
AC_ARG_ENABLE(debug1,
	[  --enable-debug1         enable debug code],[
	if test "$enableval" != "no"; then
		if test "$enableval" = "yes"; then
			AC_DEFINE(DEBUG1, 1, [Define if debugging information should be included])
		else
			AC_DEFINE_UNQUOTED(DEBUG1, $enableval, [Define if debugging information should be included])
		fi 
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

AC_MSG_CHECKING([whether to enable verbose debug code])
AC_ARG_ENABLE(debug,
	[  --enable-debug          enable verbose debug code],[
	if test "$enableval" != "no"; then
		if test "$enableval" = "yes"; then
			AC_DEFINE(DEBUG, 1, [Define if verbose debugging information should be included])
		else
			AC_DEFINE_UNQUOTED(DEBUG, $enableval, [Define if verbose debugging information should be included])
		fi 
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

afp3=no
afp3set=no
AC_MSG_CHECKING([whether AFP 3.x calls should be enabled])
AC_ARG_ENABLE(afp3,
	[  --disable-afp3          disable AFP 3.x calls],
	[
	    if test x"$enableval" != x"no"; then
		afp3set=yes
		afp3=yes
		AC_MSG_RESULT([yes])
	    else
		AC_MSG_RESULT([no])
	    fi
	],[
	    AC_MSG_RESULT([yes])
	    afp3=yes
	]
)

if test x"$afp3" = x"yes"; then
        AC_SYS_LARGEFILE([
		AC_DEFINE(AFP3x, 1, [Define to enable AFP 3.x support])
	],[
		if test x"$afp3set" = x"yes"; then
			AC_MSG_ERROR([AFP 3.x support requires Large File Support.])
		else
			AC_MSG_WARN([AFP 3.x support requires Large File Support. AFP3.x support disabled])
			afp3=no
		fi
	])
fi

AC_CHECK_ICONV

dnl ----------- A NOTE ABOUT DROPKLUDGE
dnl The trouble with this fix is that if you know what the file is called, it
dnl can be read from the Unix side.  That's okay for most academic institutions
dnl since the students don't have telnet access to the Mac servers.  There is
dnl currently no one working on further development/fixes of DROPKLUDGE.
dnl -----------

netatalk_cv_dropkludge=no
AC_MSG_CHECKING([whether to enable experimental dropbox support])
AC_ARG_ENABLE(dropkludge,
	[  --enable-dropkludge     enable the experimental dropbox fix (INSECURE!) ],[
	if test "$enableval" = "yes"; then 
		AC_DEFINE(DROPKLUDGE, 1, [Define if you want to use the experimental dropkludge support])
		AC_MSG_RESULT([yes])
		netatalk_cv_dropkludge=yes
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

netatalk_cv_force_uidgid=no
AC_MSG_CHECKING([whether to enable forcing of uid/gid per volume])
AC_ARG_ENABLE(force-uidgid,
	[  --enable-force-uidgid   allow forcing of uid/gid per volume (BROKEN) ],[
	if test "$enableval" = "yes"; then
		AC_DEFINE(FORCE_UIDGID, 1, [Define if you want forcing of uid/gid per volume])
		AC_MSG_RESULT([enabling forcing of uid/gid per volume])
		AC_MSG_RESULT([yes])
		netatalk_cv_force_uidgid=yes
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

dnl Check for CNID database backends
bdb_required=no
AC_NETATALK_CNID([bdb_required=yes],[bdb_required=no])

dnl Check for Berkeley DB library
if test "x$bdb_required" = "xyes"; then
	AC_PATH_BDB(, [
		AC_MSG_RESULT([])
		AC_MSG_RESULT([Make sure you have the required Berkeley DB libraries AND headers installed.])
		AC_MSG_RESULT([You can download the latest version from http://www.sleepycat.com.])
		AC_MSG_RESULT([If you have installed BDB in a non standard location use the])
		AC_MSG_RESULT([--with-bdb=/path/to/bdb configure option and make sure])
		AC_MSG_RESULT([your linker is configured to check for libraries there.])
		AC_MSG_ERROR([Berkeley DB library required but not found!])
	])
fi

dnl Check for quota support
AC_CHECK_QUOTA

dnl Check for optional server location protocol support (used by MacOS X)
NETATALK_SRVLOC

dnl Check for PAM libs
netatalk_cv_use_pam=no
AC_PATH_PAM([
	use_pam_so=yes
	compile_pam=yes
	netatalk_cv_use_pam=yes
	AC_DEFINE(USE_PAM, 1, [Define to enable PAM support])
])

netatalk_cv_use_shadowpw=no
AC_ARG_WITH(shadow,
	[  --with-shadow           enable shadow password support [[auto]]],
	[netatalk_cv_use_shadowpw="$withval"],
	[netatalk_cv_use_shadowpw=auto]
)

if test "x$netatalk_cv_use_shadowpw" != "xno"; then
    AC_CHECK_HEADER([shadow.h])
    if test x"$ac_cv_header_shadow_h" = x"yes"; then
	netatalk_cv_use_shadowpw=yes
	AC_DEFINE(SHADOWPW, 1, [Define if shadow passwords should be used])
    else 
      if test "x$shadowpw" = "xyes"; then
        AC_MSG_ERROR([shadow support not available])
      else
       	netatalk_cv_use_shadowpw=no
      fi
    fi 
fi

AC_MSG_CHECKING([whether shadow support should be enabled])
if test "x$netatalk_cv_use_shadowpw" = "xyes"; then
	AC_MSG_RESULT([yes])
else
	AC_MSG_RESULT([no])
fi
	
	
	
netatalk_cv_use_shellcheck=yes
AC_MSG_CHECKING([whether checking for a valid shell should be enabled])
AC_ARG_ENABLE(shell-check,
	[  --disable-shell-check   disable checking for a valid shell],[
	if test "$enableval" = "no"; then 
		AC_DEFINE(DISABLE_SHELLCHECK, 1, [Define if shell check should be disabled])
		AC_MSG_RESULT([no])
		netatalk_cv_use_shellcheck=no
	else
		AC_MSG_RESULT([yes])
	fi
	],[
		AC_MSG_RESULT([yes])
	]
)

NETATALK_TCP_WRAPPERS

AC_MSG_CHECKING([whether system (fcntl) locking should be disabled])
AC_ARG_ENABLE(locking,
        [  --disable-locking       disable system locking],[
        	if test "$enableval" = "no"; then
                	AC_DEFINE(DISABLE_LOCKING, 1, [Define if system (fcntl) locking should be disabled])
	                AC_MSG_RESULT([yes])
		else
	                AC_MSG_RESULT([no])
        	fi
		
	],[
		AC_MSG_RESULT([no])
	]

)


AC_ARG_ENABLE(redhat,
	[  --enable-redhat         use redhat-style sysv configuration ],[
	if test "$enableval" = "yes"; then
		sysv_style=redhat
	fi
	AC_MSG_RESULT([enabling redhat-style sysv support])
	]
)

AC_ARG_ENABLE(suse,
	[  --enable-suse           use suse-style sysv configuration ],[
	if test "$enableval" = "yes"; then
		sysv_style=suse
	fi
	AC_MSG_RESULT([enabling suse-style sysv support])
	]
)

AC_ARG_ENABLE(gentoo,
	[  --enable-gentoo         use gentoo-style sysv configuration ],[
	if test "$enableval" = "yes"; then
		sysv_style=gentoo
	fi
	AC_MSG_RESULT([enabling gentoo-style sysv support])
	]
)

AC_ARG_ENABLE(cobalt,
	[  --enable-cobalt         use cobalt-style sysv configuration ],
	if test "$enableval" = "yes"; then
		sysv_style=cobalt
	fi
	AC_MSG_RESULT([enabling cobalt-style sysv support])
)

AC_ARG_ENABLE(netbsd,
	[  --enable-netbsd         use NetBSD-style rc.d configuration ],
	if test "x$enableval" = "xyes"; then
		sysv_style=netbsd
	fi
	AC_MSG_RESULT([enabling NetBSD-style rc.d support])
)

AC_ARG_ENABLE(debian,
	[  --enable-debian         use debian-style sysv configuration ],[
	if test "$enableval" = "yes"; then
		sysv_style=debian
	fi
	AC_MSG_RESULT([enabling debian-style sysv support])
	]
)

dnl ----- timelord compilation (disabled by default)
AC_MSG_CHECKING([whether timelord should be compiled])
compile_timelord=no
AC_ARG_ENABLE(timelord,
	[  --enable-timelord       enable compilation of timelord server],
	[compile_timelord="$enableval"],
	[compile_timelord="no"]
)
AC_MSG_RESULT([$compile_timelord])

dnl ----- a2boot compilation (disabled by default)
AC_MSG_CHECKING([whether a2boot should be compiled])
compile_a2boot=no
AC_ARG_ENABLE(a2boot,
	[  --enable-a2boot         enable compilation of Apple2 boot server],
	[compile_a2boot="$enableval"],
	[compile_a2boot="no"]
)
AC_MSG_RESULT([$compile_a2boot])

AC_ARG_WITH(uams-path,
	[  --with-uams-path=PATH   path to UAMs [[PKGCONF/uams]]],[
		uams_path="$withval"
	],[
		uams_path="${PKGCONFDIR}/uams"
	]
)

NETATALK_AC_CUPS

dnl --------------------------------------------------------------------------
dnl FHS stuff has to be done last because it overrides other defaults
dnl --------------------------------------------------------------------------

AC_MSG_CHECKING([whether to use Filesystem Hierarchy Standard (FHS) compatibility])
AC_ARG_ENABLE(fhs,
	[  --enable-fhs            use Filesystem Hierarchy Standard (FHS) compatibility],[
	if test "$enableval" = "yes"; then
		uams_path="${libdir}/netatalk"
		sysconfdir="/etc"
		PKGCONFDIR=${sysconfdir}/netatalk
		SERVERTEXT="${PKGCONFDIR}/msg"
		use_pam_so=yes
		mandir="/usr/share/man"
		AC_DEFINE(FHS_COMPATIBILITY, 1, [Define if you want compatibily with the FHS])
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

dnl --------------------------------------------------------------------------
dnl post-FHS substitutions, etc
dnl --------------------------------------------------------------------------

dnl ***** UAMS_PATH
dnl AC_DEFINE_UNQUOTED(UAMS_PATH, "${uams_path}",
dnl 	[path to UAMs [default=PKGCONF/uams]])
UAMS_PATH="${uams_path}"
AC_SUBST(UAMS_PATH)

dnl --------------------------------------------------------------------------
dnl drop in includes for top level directory structures here...
dnl --------------------------------------------------------------------------

dnl Note: $(top_srcdir)/include should be added before all other includes
dnl       so that includes from that directory a preferred to includes from
dnl       /usr/include or similar places.
LIBS="$LIBS -L\$(top_srcdir)/libatalk"
CFLAGS="-I\$(top_srcdir)/include $CFLAGS -I\$(top_srcdir)/sys"

dnl --------------------------------------------------------------------------
dnl specific configuration comes in here:
dnl --------------------------------------------------------------------------

dnl ac_cv_target_os is now host_os, ac_cv_target_cpu is now host_cpu

dnl --------------------- determine operating system from "target"
case "$host_os" in
	*aix*)				this_os=aix ;;
	*freebsd*) 			this_os=freebsd ;;
	*hpux11*)			this_os=hpux11 ;;
	*irix*)				this_os=irix ;;
	*linux*)   			this_os=linux ;;
	*osx*)				this_os=macosx ;;
	*darwin*)			this_os=macosx ;;
	*netbsd*) 			this_os=netbsd ;;
	*openbsd*) 			this_os=openbsd ;;
	*osf*) 				this_os=tru64 ;;
	*solaris*) 			this_os=solaris ;;
esac

case "$host_cpu" in
	i386|i486|i586|i686|k7)		this_cpu=x86 ;;
	alpha)						this_cpu=alpha ;;
	mips)						this_cpu=mips ;;
	powerpc|ppc)				this_cpu=ppc ;;
esac

dnl --------------------- operating system specific flags (port from sys/*)

dnl ----- AIX specific -----
if test x"$this_os" = "xaix"; then
	AC_MSG_RESULT([ * AIX specific configuration])
	AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])

	dnl This is probably a lie; AIX 4.3 supports a 64-bit long
	dnl compilation environment.  It's enough to get things defined
	dnl right in endian.h provided that long long is supported, though.
	AC_DEFINE(HAVE_32BIT_LONGS, 1, [Define if the data type long has 32 bit])
fi

dnl ----- FreeBSD specific -----
if test x"$this_os" = "xfreebsd"; then 
	AC_MSG_RESULT([ * FreeBSD specific configuration])
	AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
	AC_DEFINE(FREEBSD, 1, [Define if OS is FreeBSD])
	AC_DEFINE(SENDFILE_FLAVOR_BSD, 1, [Define if the sendfile() function uses BSD semantics])
fi

dnl ----- HP-UX 11 specific -----
if test x"$this_os" = "xhpux11"; then
	AC_MSG_RESULT([ * HP-UX 11 specific configuration])

	AC_DEFINE(_ISOC9X_SOURCE, 1, [Compatibility macro])
	AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
fi

dnl ----- IRIX specific -----
if test x"$this_os" = "xirix"; then
	AC_MSG_RESULT([ * IRIX specific configuration])

	AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
fi

dnl ----- Linux specific -----
if test x"$this_os" = "xlinux"; then 
	AC_MSG_RESULT([ * Linux specific configuration])
	
	dnl ----- kernel 2.6 changed struct at_addr to atalk_addr
	AC_MSG_CHECKING([for struct atalk_addr])
dnl	AC_COMPILE_IFELSE([
	AC_TRY_COMPILE([
#include <sys/socket.h>
#include <asm/types.h>
#include <linux/atalk.h>

	struct atalk_addr foo;
],
[ ], [
		ac_have_atalk_addr=yes
		AC_MSG_RESULT([yes])
	], [
		AC_MSG_RESULT([no])
	])

if test "x$ac_have_atalk_addr" = "xyes"; then
	AC_DEFINE(HAVE_ATALK_ADDR, 1, [set if struct at_addr is called atalk_addr])
fi

	dnl ----- check if we need the quotactl wrapper
#	AC_CHECK_HEADERS(sys/quota.h linux/quota.h)
#	AC_CHECK_FUNC(quotactl,,
#		AC_DEFINE(NEED_QUOTACTL_WRAPPER, 1, [Define if the quotactl wrapper is needed])
#		AC_MSG_RESULT([enabling quotactl wrapper])
#	)

        # For quotas on Linux XFS filesystems
        AC_CHECK_HEADERS(linux/xqm.h linux/xfs_fs.h)
        AC_CHECK_HEADERS(xfs/libxfs.h xfs/xqm.h xfs/xfs_fs.h)
        # For linux > 2.5.56
        AC_CHECK_HEADERS(linux/dqblk_xfs.h)


	dnl ----- as far as I can tell, dbtob always does the wrong thing
	dnl ----- on every single version of linux I've ever played with.
	dnl ----- see etc/afpd/quota.c
	AC_DEFINE(HAVE_BROKEN_DBTOB, 1, [Define if dbtob is broken])

	netatalk_cv_linux_sendfile=no
dnl	disable this for now, code doesn't use sendfile anyway
dnl        AC_ARG_ENABLE(sendfile,
dnl	    [  --enable-sendfile       use sendfile syscall default (no) ],[
dnl	    	if test "$enableval" = "yes"; then
dnl	  		netatalk_cv_linux_sendfile=yes
dnl	    	fi
dnl	    	AC_MSG_RESULT([enabling sendfile syscall])
dnl	    ]
dnl       )

	if test x"$netatalk_cv_linux_sendfile" = "xyes"; then 
	    AC_CACHE_CHECK([for linux sendfile support],netatalk_cv_HAVE_SENDFILE,[
	    AC_TRY_LINK([#include <sys/sendfile.h>],
[\
int tofd, fromfd;
off_t offset;
size_t total;
ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
],
netatalk_cv_HAVE_SENDFILE=yes,netatalk_cv_HAVE_SENDFILE=no)])

# Try and cope with broken Linux sendfile....
	    AC_CACHE_CHECK([for broken linux sendfile support],netatalk_cv_HAVE_BROKEN_LINUX_SENDFILE,[
	    AC_TRY_LINK([\
#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
#undef _FILE_OFFSET_BITS
#endif
#include <sys/sendfile.h>],
[\
int tofd, fromfd;
off_t offset;
size_t total;
ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
],
netatalk_cv_HAVE_BROKEN_LINUX_SENDFILE=yes,netatalk_cv_HAVE_BROKEN_LINUX_SENDFILE=no,netatalk_cv_HAVE_BROKEN_SENDFILE=cross)])

	    if test x"$netatalk_cv_HAVE_SENDFILE" = x"yes"; then
    		AC_DEFINE(HAVE_SENDFILE,1,[Whether sendfile() is available])
		AC_DEFINE(SENDFILE_FLAVOR_LINUX,1,[Whether linux sendfile() API is available])
		AC_DEFINE(WITH_SENDFILE,1,[Whether sendfile() should be used])
	    elif test x"$netatalk_cv_HAVE_BROKEN_LINUX_SENDFILE" = x"yes"; then
		AC_DEFINE(SENDFILE_FLAVOR_LINUX,1,[Whether linux sendfile() API is available])
		AC_DEFINE(LINUX_BROKEN_SENDFILE_API,1,[Whether (linux) sendfile() is broken])
		AC_DEFINE(WITH_SENDFILE,1,[Whether sendfile should be used])
	    else
	  	netatalk_cv_linux_sendfile=no
		AC_MSG_RESULT(no);
	    fi
	fi

	dnl ----- Linux/alpha specific -----
	if test x"$this_cpu" = "xalpha"; then 
		AC_MSG_RESULT([enabling gcc memcpy bug workaround])
		AC_DEFINE(HAVE_GCC_MEMCPY_BUG, 1, [Define if memcpy is buggy])
	fi
	need_dash_r=no


fi

dnl ----- Mac OSX specific -----
if test x"$this_os" = "xmacosx"; then 
	AC_MSG_RESULT([ * Mac OSX specific configuration])
	AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
	AC_DEFINE(HAVE_2ARG_DBTOB, 1, [Define if dbtob takes two arguments])
	dnl AC_DEFINE(NO_DLFCN_H)
	AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
	AC_DEFINE(NO_QUOTA_SUPPORT, 1, [Define if Quota support should be disabled])
	AC_DEFINE(MACOSX_SERVER, 1, [Define if compiling for MacOS X Server])
fi

dnl ----- NetBSD specific -----
if test x"$this_os" = "xnetbsd"; then 
	AC_MSG_RESULT([ * NetBSD specific configuration])
	AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
	AC_DEFINE(NETBSD, 1, [Define if OS is FreeBSD])
	CFLAGS="-I\$(top_srcdir)/sys/netbsd -I/usr/include/kerberosIV $CFLAGS"
	need_dash_r=yes 

	dnl ----- NetBSD does not have crypt.h, uses unistd.h -----
	AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
fi

dnl ----- OpenBSD specific -----
if test x"$this_os" = "xopenbsd"; then 
	AC_MSG_RESULT([ * OpenBSD specific configuration])
	dnl ----- OpenBSD does not have crypt.h, uses unistd.h -----
	AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
fi

dnl ----- Solaris specific -----
if test x"$this_os" = "xsolaris"; then 
	AC_MSG_RESULT([ * Solaris specific configuration])
	AC_DEFINE(__svr4__, 1, [Solaris compatibility macro])
	AC_DEFINE(_ISOC9X_SOURCE, 1, [Compatibility macro])
	AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
	AC_DEFINE(SOLARIS, 1, [Solaris compatibility macro])
	CFLAGS="-I\$(top_srcdir)/sys/generic $CFLAGS"
	need_dash_r=yes
	sysv_style=solaris

	solaris_module=no
	AC_MSG_CHECKING([if we can build Solaris kernel module])
	if test -x /usr/ccs/bin/ld; then
		solaris_module=yes
	fi
	AC_MSG_RESULT([$solaris_module])

	COMPILE_64BIT_KMODULE=no
	KCFLAGS=""
	KLDFLAGS=""
	COMPILE_KERNEL_GCC=no

	if test "$solaris_module" = "yes"; then
	   dnl Solaris kernel module stuff
           AC_MSG_CHECKING([if we have to build a 64bit kernel module])

	   # check for isainfo, if not found it has to be a 32 bit kernel (<=2.6)	
	   if test -x /usr/bin/isainfo; then
		# check for 64 bit platform
		if isainfo -kv | grep '^64-bit'; then
			COMPILE_64BIT_KMODULE=yes
		fi
	   fi

	   AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])

	   if test "${GCC}" = yes; then
		COMPILE_KERNEL_GCC=yes
		if test "$COMPILE_64BIT_KMODULE" = yes; then
  	        
                        AC_MSG_CHECKING([if we can build a 64bit kernel module])
		        
                        case `$CC --version 2>/dev/null` in
			[[12]].* | 3.0.*)
				COMPILE_64BIT_KMODULE=no
				COMPILE_KERNEL_GCC=no	
				solaris_module=no;;
			*)
			       	# use for 64 bit
				KCFLAGS="-m64"
				#KLDFLAGS="-melf64_sparc"
				KLDFLAGS="-64";;
			esac	
			
			AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])
			
		else
			KCFLAGS=""
			KLDFLAGS=""
		fi
		KCFLAGS="$KCFLAGS -D_KERNEL -Wall -Wstrict-prototypes"
           else
		if test "$COMPILE_64BIT_KMODULE" = yes; then
                # use Sun CC (for a 64-bit kernel, uncomment " -xarch=v9 -xregs=no%appl ")
 			KCFLAGS="-xarch=v9 -xregs=no%appl"
			KLDFLAGS="-64"
		else
 			KCFLAGS=""
			KLDFLAGS=""
		fi
		KCFLAGS="-D_KERNEL $KCFLAGS -mno-app-regs -munaligned-doubles -fpcc-struct-return"
	   fi

           AC_CACHE_CHECK([for timeout_id_t],netatalk_cv_HAVE_TIMEOUT_ID_T,[
           AC_TRY_LINK([\
#include <sys/stream.h>
#include <sys/ddi.h>],
[\
timeout_id_t dummy;
],
netatalk_cv_HAVE_TIMEOUT_ID_T=yes,netatalk_cv_HAVE_TIMEOUT_ID_T=no,netatalk_cv_HAVE_TIMEOUT_ID_T=cross)])

	   AC_DEFINE(HAVE_TIMEOUT_ID_T, test x"$netatalk_cv_HAVE_TIMEOUT_ID" = x"yes", [define for timeout_id_t])
	fi

	AC_SUBST(COMPILE_KERNEL_GCC)
	AC_SUBST(COMPILE_64BIT_KMODULE)
	AC_SUBST(KCFLAGS)
	AC_SUBST(KLDFLAGS)
fi

dnl ----- Tru64 specific -----
if test x"$this_os" = "xtru64"; then 
	AC_MSG_RESULT([ * Tru64 specific configuration])
	AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
	AC_DEFINE(HAVE_64BIT_LONGS, 1, [Define if the data type long has 64 bit])
	dnl AC_DEFINE(USE_MOUNT_H)
	AC_DEFINE(USE_OLD_RQUOTA, 1, [Define to use old rquota])
	dnl AC_DEFINE(USE_UFS_QUOTA_H)
	AC_DEFINE(TRU64, 1, [Define on Tru64 platforms])
	AC_DEFINE(_OSF_SOURCE, 1, [Define if the *passwd UAMs should be used])
	AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Define for Berkeley DB 4])
	AC_CHECK_LIB(security,set_auth_parameters)
	CFLAGS="-I\$(top_srcdir)/sys/tru64 $CFLAGS"
	need_dash_r=no
	sysv_style=tru64
fi

dnl -- look for openssl
AC_PATH_SSL

dnl -- check for crypt
AC_CRYPT

dnl --------------------- check for building PGP UAM module

AC_MSG_CHECKING([whether the PGP UAM should be build])
AC_ARG_ENABLE(pgp-uam,
	[  --enable-pgp-uam        enable build of PGP UAM module],[
	if test "$enableval" = "yes"; then 
		if test "$compile_ssl" = "yes"; then 
			AC_DEFINE(UAM_PGP, 1, [Define if the PGP UAM module should be compiled])
			compile_pgp=yes
			AC_MSG_RESULT([yes])
		else
			AC_MSG_RESULT([no])
		fi
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

dnl --------------------- check for building Kerberos v4 UAM module

AC_MSG_CHECKING([whether the Kerberos IV UAM should be build])
AC_ARG_ENABLE(krb4-uam,
	[  --enable-krb4-uam       enable build of Kerberos v4 UAM module],[
	if test "$enableval" = "yes"; then
		AC_DEFINE(UAM_KRB4, 1, [Define if the Kerberos 4 UAM module should be compiled])
		compile_kerberos=yes
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
	],[
		AC_MSG_RESULT([no])
	]
)

dnl --------------------- check for building Kerberos V UAM module

netatalk_cv_build_krb5_uam=no
AC_ARG_ENABLE(krbV-uam,
	[  --enable-krbV-uam       enable build of Kerberos V UAM module],
	[
		if test x"$enableval" = x"yes"; then
			NETATALK_GSSAPI_CHECK([
				netatalk_cv_build_krb5_uam=yes
			],[
				AC_MSG_ERROR([need GSSAPI to build Kerberos V UAM])
			])
		fi
	]
	
)

AC_MSG_CHECKING([whether Kerberos V UAM should be build])
if test x"$netatalk_cv_build_krb5_uam" = x"yes"; then
	AC_MSG_RESULT([yes])
else
	AC_MSG_RESULT([no])
fi
AM_CONDITIONAL(USE_GSSAPI, test x"$netatalk_cv_build_krb5_uam" = x"yes")

dnl --------------------- overwrite the config files . . . or not.

AC_MSG_CHECKING([whether configuration files should be overwritten])
AC_ARG_ENABLE(overwrite,
	[  --enable-overwrite      overwrite configuration files during installation],
	[OVERWRITE_CONFIG="${enable_overwrite}"],
	[OVERWRITE_CONFIG="no"]
)
AC_MSG_RESULT([$OVERWRITE_CONFIG])

dnl --------------------- last minute substitutions

AC_SUBST(LIBS)
AC_SUBST(CFLAGS)
AC_SUBST(OVERWRITE_CONFIG)

AM_CONDITIONAL(SOLARIS_MODULE, test x$solaris_module = xyes)
AM_CONDITIONAL(COMPILE_TIMELORD, test x$compile_timelord = xyes)
AM_CONDITIONAL(COMPILE_A2BOOT, test x$compile_a2boot = xyes)
AM_CONDITIONAL(USE_DHX, test x$compile_ssl = xyes)
AM_CONDITIONAL(USE_KERBEROS, test x$compile_kerberos = xyes)
AM_CONDITIONAL(USE_PAM_SO, test x$use_pam_so = xyes)
AM_CONDITIONAL(USE_PAM, test x$netatalk_cv_install_pam = xyes)
AM_CONDITIONAL(BUILD_PAM, test x$compile_pam = xyes)
AM_CONDITIONAL(USE_PGP, test x$compile_pgp = xyes)
AM_CONDITIONAL(USE_COBALT, test x$sysv_style = xcobalt)
AM_CONDITIONAL(USE_NETBSD, test x$sysv_style = xnetbsd)
AM_CONDITIONAL(USE_REDHAT, test x$sysv_style = xredhat)
AM_CONDITIONAL(USE_SUSE, test x$sysv_style = xsuse)
AM_CONDITIONAL(USE_SHADOWPW, test x$shadowpw = xyes)
AM_CONDITIONAL(USE_TRU64, test x$sysv_style = xtru64)
AM_CONDITIONAL(USE_SOLARIS, test x$sysv_style = xsolaris)
AM_CONDITIONAL(USE_GENTOO, test x$sysv_style = xgentoo)
AM_CONDITIONAL(USE_DEBIAN, test x$sysv_style = xdebian)
AM_CONDITIONAL(USE_UNDEF, test x$sysv_style = x)

dnl --------------------- generate files

AC_OUTPUT([Makefile
	bin/Makefile
	bin/adv1tov2/Makefile
	bin/aecho/Makefile
	bin/afile/Makefile
	bin/afppasswd/Makefile
	bin/cnid/Makefile
	bin/cnid/cnid_maint
	bin/cnid/cnid2_create
	bin/getzones/Makefile
	bin/megatron/Makefile
	bin/nbp/Makefile
	bin/pap/Makefile
	bin/psorder/Makefile
	bin/uniconv/Makefile
	config/Makefile
	contrib/Makefile
	contrib/macusers/Makefile
	contrib/macusers/macusers
	contrib/nu/Makefile
	contrib/nu/nu
	contrib/printing/Makefile
	contrib/shell_utils/Makefile
	contrib/shell_utils/afpd-mtab.pl
	contrib/shell_utils/apple_cp
	contrib/shell_utils/apple_mv
	contrib/shell_utils/apple_rm
	contrib/shell_utils/asip-status.pl
	contrib/shell_utils/cleanappledouble.pl
	contrib/timelord/Makefile
	contrib/a2boot/Makefile
	distrib/Makefile
	distrib/config/Makefile
	distrib/config/netatalk-config
	distrib/initscripts/Makefile
	distrib/m4/Makefile
	doc/Makefile
	etc/Makefile
	etc/afpd/Makefile
	etc/atalkd/Makefile
	etc/cnid_dbd/Makefile
	etc/uams/Makefile
	etc/uams/uams_krb4/Makefile
	etc/papd/Makefile
	etc/psf/Makefile
	include/Makefile
	include/atalk/Makefile
	libatalk/Makefile
	libatalk/adouble/Makefile
	libatalk/asp/Makefile
	libatalk/atp/Makefile
	libatalk/cnid/Makefile
	libatalk/cnid/db3/Makefile
	libatalk/cnid/cdb/Makefile
	libatalk/cnid/last/Makefile
	libatalk/cnid/mtab/Makefile
	libatalk/cnid/dbd/Makefile
	libatalk/cnid/hash/Makefile
	libatalk/cnid/tdb/Makefile
	libatalk/compat/Makefile
	libatalk/dsi/Makefile
	libatalk/nbp/Makefile
	libatalk/netddp/Makefile
	libatalk/util/Makefile
	libatalk/tdb/Makefile
	libatalk/unicode/Makefile
	libatalk/unicode/charsets/Makefile
	macros/Makefile
	man/Makefile
	man/man1/Makefile
	man/man3/Makefile
	man/man4/Makefile
	man/man5/Makefile
	man/man8/Makefile
	sys/Makefile
	sys/generic/Makefile
	sys/generic/sys/Makefile
	sys/netatalk/Makefile
	sys/netbsd/Makefile
	sys/netbsd/netatalk/Makefile
	sys/solaris/Makefile
	sys/sunos/Makefile
	sys/ultrix/Makefile
	],
	[chmod a+x distrib/config/netatalk-config contrib/shell_utils/apple_*]
)

AC_NETATALK_LIBS_SUMMARY
AC_NETATALK_CONFIG_SUMMARY

