dnl use autoconf 2.12 or higher (2.14 preferred) to generate the configure script

dnl ============================================================================
dnl First of all, definitions of our headers and lookups of generic programs...
dnl ============================================================================
AC_INIT(src/ftpd.c)

divert(0)dnl
#
# Copyright (c) 1999,2000 WU-FTPD Development Group.  
# All rights reserved.
#  
# Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994  
#   The Regents of the University of California. 
# Portions Copyright (c) 1993, 1994 Washington University in Saint Louis.  
# Portions Copyright (c) 1996, 1998 Berkeley Software Design, Inc.  
# Portions Copyright (c) 1989 Massachusetts Institute of Technology.  
# Portions Copyright (c) 1998 Sendmail, Inc.  
# Portions Copyright (c) 1983, 1995, 1996, 1997 Eric P.  Allman.  
# Portions Copyright (c) 1997 by Stan Barber.  
# Portions Copyright (c) 1997 by Kent Landfield.  
# Portions Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997  
#   Free Software Foundation, Inc.    
#  
# Use and distribution of this software and its source code are governed   
# by the terms and conditions of the WU-FTPD Software License ("LICENSE").  
#  
# If you did not receive a copy of the license, it may be obtained online  
# at http://www.wu-ftpd.org/license.html.  
#
# $Id: configure.in,v 1.50 2000/07/01 17:42:15 wuftpd Exp $
#
undivert(0)

AC_CONFIG_HEADER(config.h src/config.h)
AC_PREFIX_DEFAULT(/usr)
AC_CANONICAL_SYSTEM
AC_PROG_CC
AC_ISC_POSIX
AC_PROG_RANLIB
AC_PROG_YACC
AC_PROG_INSTALL
AC_CHECK_PROGS(AR, ar gar, NO)
if test $AR = NO; then
  AC_MSG_ERROR(Can\'t find ar or gar.)
fi
AC_SUBST(AR)
AC_HEADER_STDC
AC_HEADER_TIME

dnl Quick hack: Let the source know we don't want stuff like
dnl #ifdef LINUX...
AC_DEFINE(AUTOCONF)

dnl see if we support links...
AC_MSG_CHECKING(if we can do hard links)
ln configure src/link.tst 2>&5
if test -x src/link.tst; then
	CPLN="ln"
	rm -f src/link.tst
	AC_MSG_RESULT(yes - using ln)
else
	CPLN="cp"
	AC_MSG_RESULT(no - using cp)
fi
AC_SUBST(CPLN)


dnl ===========================================================================
dnl Accepted arguments to ./configure...
dnl ============================================================================
AC_ARG_WITH(etc-dir, 
    [  --with-etc-dir=PATH     read-only single-machine data in DIR [/etc]],
    ETCDIR=$with_etc_dir, ETCDIR=/etc)
AC_SUBST(ETCDIR)

AC_ARG_WITH(pid-dir, 
    [  --with-pid-dir=PATH     run/pid files [/var/run]],
    PIDDIR=$with_pid_dir, PIDDIR=/var/run)
AC_SUBST(PIDDIR)

AC_ARG_WITH(log-dir, 
    [  --with-log-dir=PATH     log files [/var/log]],
    LOGDIR=$with_log_dir, LOGDIR=/var/log)
AC_SUBST(LOGDIR)

AC_ARG_ENABLE(upload,	 
    [  --disable-upload        disable the UPLOAD keyword in ftpaccess],
    [ upload=$enableval ], [ upload=yes ])

AC_ARG_ENABLE(overwrite, 
    [  --disable-overwrite     disable the OVERWRITE keyword in ftpaccess],
    [ overwrite=$enableval ], [ overwrite=yes ])

AC_ARG_ENABLE(hostxs,	 
    [  --disable-hostxs        don't allow ALLOW/DENY keywords in ftpaccess],
    [ hostxs=$enableval ], [ hostxs=yes ])

AC_ARG_ENABLE(logfailed, 
    [  --disable-logfailed     don't log failed login attempts],
    [ logfailed=$enableval ], [ logfailed=yes ])

AC_ARG_ENABLE(logtoomany,
    [  --disable-logtoomany    don't log login attempts that failed because of limits],
    [ logtoomany=$enableval ], [ logtoomany=yes ])

AC_ARG_ENABLE(private,   
    [  --disable-private       don't support private files (SITE GROUP/SITE GPASS)],
    [ private=$enableval ], [ private=yes ])

AC_ARG_ENABLE(dnsretry,  
    [  --disable-dnsretry      don't retry failed DNS lookups],
    [ dnsretry=$enableval ], [ dnsretry=yes ])

AC_ARG_ENABLE(anononly,  
    [  --enable-anononly       allow only anonymous ftp connections],
    [ anononly=$enableval ], [ anononly=no ])

AC_ARG_ENABLE(paranoid,  
    [  --enable-paranoid       disable some "questionable" features],
    [ paranoid=$enableval ], [ paranoid=no ])

AC_ARG_ENABLE(quota,	 
    [  --enable-quota          add QUOTA support (if your OS supports it)],
    [ quota=$enableval ], [ quota=no ])

AC_ARG_ENABLE(pam,	 
    [  --enable-pam            add PAM support (needs PAM library)],
    [ pam=$enableval ], [ pam=no ])

AC_ARG_ENABLE(skey,	 
    [  --enable-skey           add S/KEY support (needs SKEY libraries)],
    [ skey=$enableval ], [ skey=no ])

AC_ARG_ENABLE(opie,	 
    [  --enable-opie           add OPIE support (needs OPIE libraries)],
    [ opie=$enableval ], [ opie=no ])

if test $skey = "yes" -o $skey = "y"
then
  if test $opie = "yes" -o $skey = "y"
  then
    AC_MSG_ERROR([*** YOU SHOULD NOT HAVE BOTH SKEY AND OPIE DEFINED!!!!!])
  fi
fi

AC_ARG_ENABLE(new-cd,    [  --disable-new-cd        new-cd causes \"cd ~\" to return to chroot-relative dir],
	[ newcd=$enableval ], [ newcd=yes ])
AC_ARG_ENABLE(chmod,	 [  --enable-chmod          allow ftp users to set SETUID/SETGID/STICKY bits],
	[ chmod=$enableval ], [ chmod=no ])
AC_ARG_ENABLE(rfc931,	 [  --enable-rfc931         do RFC931 lookups (more log information, but slower)],
	[ rfc931=$enableval ], [ rfc931=no ])
AC_ARG_ENABLE(ratios,    [  --enable-ratios         compile in support for upload-download ratios ],
       [ ratio=$enableval ], [ ratio=no ])
AC_ARG_ENABLE(passwd,    [  --enable-passwd         support alternative passwd/shadow files ],
	[ passwd=$enableval ], [ passwd=no ])
AC_ARG_ENABLE(daemon,	 [  --disable-daemon        don't allow running as standalone daemon],
	[ daemon=$enableval ], [ daemon=yes ])
AC_ARG_ENABLE(map-chdir, [  --disable-map-chdir     don't keep track of user's path changes],
	[ mapchdir=$enableval ], [ mapchdir=yes ])
AC_ARG_ENABLE(throughput,[  --disable-throughput    don't keep track of user's throughput],
	[ throughput=$enableval ], [ throughput=yes ])
AC_ARG_ENABLE(count,	 [  --disable-count         don't keep track of bytes for statistics],
	[ count=$enableval ], [ count=yes ])
AC_ARG_ENABLE(newlines,	 [  --disable-newlines      suppress some extra blank lines],
	[ newlines=$enableval ], [ newlines=yes ])
AC_ARG_ENABLE(crackers,  [  --enable-crackers       don't wait for password if the username doesn't exist],
	[ crackers=$enableval ], [ crackers=no ])
AC_ARG_ENABLE(verbose,	 [  --disable-verbose       disable verbose error logging],
	[ verbose=$enableval ], [ verbose=yes ])
AC_ARG_ENABLE(noop,      [  --enable-noop           NOOP command resets idle timeout],
	[ noop=$enableval ], [ noop=no ])
AC_ARG_ENABLE(log-rp,    [  --disable-log-rp        log the relative path rather than the real one],
	[ logrp=$enableval ], [ logrp=yes ])
AC_ARG_ENABLE(virtual,   [  --disable-virtual       don't support virtual servers],
	[ virtual=$enableval ], [ virtual=yes ])
AC_ARG_ENABLE(closedvirt,[  --disable-closedvirt    allow guests to log in to a virtual server],
	[ closedvirt=$enableval ], [ closedvirt=yes ])
AC_ARG_ENABLE(dns, 	 [  --disable-dns           skip all DNS lookups],
	[ dns=$enableval ], [ dns=yes ])
AC_ARG_ENABLE(port,	 [  --disable-port          don't allow port mode],
	[ port=$enableval ], [ port=yes ])
AC_ARG_ENABLE(pasv,	 [  --disable-pasv          don't allow passive mode],
	[ pasv=$enableval ], [ pasv=yes ])
AC_ARG_ENABLE(plsm,	 [  --disable-plsm          disable PID lock sleep messages (for busy sites)],
	[ plsm=$enableval ], [ plsm=yes ])
AC_ARG_ENABLE(pasvip,    [  --disable-pasvip        don't require require same IP for passive connections],
	[ pasvip=$enableval ], [ pasvip=yes ])
AC_ARG_ENABLE(anonymous, [  --disable-anonymous     don't allow anonymous ftp access],
	[ anonymous=$enableval ], [ anonymous=yes ])
AC_ARG_ENABLE(ls,	 [  --enable-ls             use the internal ls (EXPERIMENTAL)],
	[ ls=$enableval ], [ ls=no ])
AC_ARG_ENABLE(numericuid,[  --disable-numericuid    internal ls displays UID instead of username (faster)],
	[ numericuid=$enableval ], [ numericuid=yes ])
AC_ARG_ENABLE(hidesetuid,[  --disable-hidesetuid    show setuid/setgid bits in internal ls],
	[ hidesetuid=$enableval ], [ hidesetuid=yes ])
AC_ARG_ENABLE(mail,      [  --disable-mail          don't allow mail on upload],
	[ mail=$enableval ], [ mail=yes ])
AC_ARG_ENABLE(badclients,[  --enable-badclients     support broken clients (see CHANGES)],
	[ badclients=$enableval ], [ badclients=no ])
AC_ARG_WITH(bufsize,	 [  --with-bufsize=x        set buffer size to x],
	[ bufsize=$withval ], [ bufsize=no ])
AC_ARG_WITH(backlog,	 [  --with-backlog=x        number of incoming processes to backlog in daemon mode],
	[ backlog=$withval ], [ backlog=100 ])

LIBS=""

dnl ===========================================================================
dnl Checks for some system calls/headers...
dnl ============================================================================
AC_CHECK_HEADERS(dirent.h regex.h shadow.h security/pam_appl.h opie.h skey.h \
  syslog.h sys/syslog.h fcntl.h mntent.h stdlib.h unistd.h glob.h grp.h \
  ndir.h sys/dir.h sys/ndir.h string.h vmsdir.h sys/systeminfo.h \
  bsd/bsd.h sys/param.h values.h limits.h sys/types.h sys/mntent.h \
  sys/mnttab.h paths.h)
AC_CHECK_FUNCS(dirfd fchdir flock ftw getcwd getdtablesize pstat lstat \
  vprintf snprintf regexec regex fgetspent usercmp getusershell setuid vsnprintf \
  snprintf strcasestr strdup strerror strsep strstr syslog glob strcasecmp \
  strncasecmp sigprocmask quotactl getrlimit sysconf setsid memmove \
  strtoul)
AC_CHECK_FUNCS(seteuid setreuid setresuid, break)
AC_CHECK_FUNCS(setegid setregid setresgid, break)

AC_CHECK_LIB(crypt, crypt, result=yes, result=no)
if test $result = yes; then
	LIBS="$LIBS -lcrypt"
fi
USENSL=no
AC_CHECK_LIB(socket,socket,result=yes,result=no)
if test $result = yes; then
	LIBS="$LIBS -lsocket"
else
	AC_CHECK_LIB(socket,socket,result=yes,result=no,-lnsl)
	if test $result = yes; then
		LIBS = "$LIBS -lsocket -lnsl"
		USENSL=yes
	else
		AC_CHECK_LIB(socket,connect,result=yes,result=no)
		if test $result = yes; then
			LIBS="$LIBS -lsocket"
		else
			AC_CHECK_LIB(socket,connect,result=yes,result=no,-lnsl)
			if test $result = yes; then
				LIBS="$LIBS -lsocket -lnsl"
				USENSL=yes
			fi
		fi
	fi
fi
if test $USENSL != yes; then
	AC_CHECK_LIB(nsl,inet_addr,result=yes,result=no)
	if test $result = yes; then
		LIBS="$LIBS -lnsl"
	fi
fi

AC_MSG_CHECKING(for sys_siglist)
AC_TRY_COMPILE([#include <signal.h>
#include <stdio.h>],[ puts(sys_siglist[0]); ], result=yes, result=no)
AC_MSG_RESULT($result)
if test "$result" = "yes"; then
	AC_DEFINE(HAVE_SIGLIST)
fi

AC_MSG_CHECKING(type of qsort)
AC_TRY_COMPILE([#include <stdlib.h>
extern void qsort();],[  ], result=void, result=int)
AC_MSG_RESULT($result)
if test "$result" = "void"; then
	AC_DEFINE(QSORT_IS_VOID)
fi

AC_MSG_CHECKING(how to determine bytesize)
if test "$ac_cv_header_bsd_bsd_h" = "yes"; then
	AC_TRY_COMPILE([ #include <bsd/bsd.h> ],[ int i=NBBY ], NBBY=NBBY, NBBY=8)
else
	AC_TRY_COMPILE([ #include <sys/param.h> ],[ int i=NBBY ], NBBY=NBBY, NBBY=8)
fi
if test "$NBBY" = "8"; then
	AC_TRY_COMPILE([ #include <values.h> ],[ int i=BITSPERBYTE ], NBBY=BITSPERBYTE, NBBY=8)
	if test "$NBBY" = "8"; then
		AC_TRY_COMPILE([ #include <limits.h> ],[ int i=CHAR_BIT ], NBBY=CHAR_BIT, NBBY=8)
		if test "$NBBY" != "8"; then
			AC_DEFINE(NEED_LIMITS_H)
		else
			AC_TRY_COMPILE([ #include <sys/types.h> ],[ int i=NBBY ], NBBY=NBBY, NBBY=8)
		fi
	else
		AC_DEFINE(NEED_VALUES_H)
	fi
else
	if test "$ac_cv_header_bsd_bsd_h" = "yes"; then
		AC_DEFINE(NEED_BSD_BSD_H)
	else
		AC_DEFINE(NEED_SYS_PARAM_H)
	fi
fi
if test "$NBBY" = "8"; then
	AC_MSG_RESULT(can't be determined - assuming 8)
else
	AC_MSG_RESULT($NBBY)
fi
if test "$NBBY" != "NBBY"; then
	AC_DEFINE_UNQUOTED(NBBY,$NBBY)
fi

AC_MSG_CHECKING(if openlog requires 3 arguments)
AC_TRY_COMPILE([#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#ifdef HAVE_SYS_SYSLOG_H
#include <sys/syslog.h>
#endif],[ openlog("",0,0) ], result=yes, result=no)
AC_MSG_RESULT($result)
if test "$result" = "yes"; then
	AC_MSG_CHECKING(which facility openlog understands)
	AC_TRY_COMPILE([#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#ifdef HAVE_SYS_SYSLOG_H
#include <sys/syslog.h>
#endif],[ openlog("",0,LOG_FTP) ], result=yes, result=no)
	if test "$result" = "yes"; then
		FACILITY="LOG_FTP"
	else
		AC_TRY_COMPILE([#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#ifdef HAVE_SYS_SYSLOG_H
#include <sys/syslog.h>
#endif],[ openlog("",0,LOG_DAEMON) ], result=yes, result=no)
		if test "$result" = "yes"; then
			FACILITY="LOG_DAEMON"
		else
			AC_TRY_COMPILE([#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#ifdef HAVE_SYS_SYSLOG_H
#include <sys/syslog.h>
#endif], [ openlog("",0,LOG_LOCAL7)], result=yes, result=no)
			if test "$result" = "yes"; then
				FACILITY="LOG_LOCAL7"
			fi
		fi
	fi
	AC_MSG_RESULT($FACILITY)
	AC_DEFINE_UNQUOTED(FACILITY, $FACILITY)
fi

AC_MSG_CHECKING(type of getmntent function)
AC_TRY_COMPILE([#include <stdio.h>
#include <unistd.h>
#ifdef HAVE_MNTENT_H
#include <mntent.h>
#endif
#ifdef HAVE_SYS_MNTENT_H
#include <sys/mntent.h>
#endif
#ifdef HAVE_SYS_MNTTAB_H
#include <sys/mnttab.h>
#endif
#include <unistd.h>],[ (void) getmntent(0) ], result=new-style, result=old-style)
AC_MSG_RESULT($result)
if test "$result" = "old-style"; then
	AC_DEFINE(HAS_OLDSTYLE_GETMNTENT)
fi

dnl some systems (FreeBSD 3) require time.h to be included before utmp.h :/
AC_MSG_CHECKING(if there is a ut_host field in the utmp structure)
AC_TRY_COMPILE([
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#include <utmp.h>],[struct utmp ut; puts(ut.ut_host);],result=yes,result=no)
if test "$result" = "yes"; then
  AC_DEFINE(HAVE_UT_UT_HOST)
fi
AC_MSG_RESULT($result)

AC_MSG_CHECKING(if there is a ut_exit.e_termination field in the utmp structure)
AC_TRY_COMPILE([#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#include <utmp.h>],[struct utmp ut; ut.ut_exit.e_termination=0;],result=yes,result=no)
if test "$result" = "yes"; then
	AC_DEFINE(HAVE_UT_UT_EXIT_E_TERMINATION)
fi
AC_MSG_RESULT($result)

AC_MSG_CHECKING(if there is a pw_expire field in the pw structure)
AC_TRY_COMPILE([#include <pwd.h>],[ struct passwd *p; void *a=(void *)p->pw_expire; ],result=yes,result=no)
if test "$result" = "yes"; then
  AC_DEFINE(HAS_PW_EXPIRE)
fi
AC_MSG_RESULT($result)

AC_MSG_CHECKING(if there is a st_blksize field in the stat structure)
AC_TRY_COMPILE([#include <sys/stat.h>],[ struct stat *s; int a=(int)s->st_blksize; ],result=yes,result=no)
if test "$result" = "yes"; then
  AC_DEFINE(HAVE_ST_BLKSIZE)
fi
AC_MSG_RESULT($result)

AC_CHECK_FUNC(res_query, result=yes, result=no)
if test "$result" = "yes"; then
	AC_DEFINE(HAVE_LIBRESOLV)
else
	AC_CHECK_LIB(bind, res_query, result=yes, result=no)
	if test "$result" = "yes"; then
		AC_DEFINE(HAVE_LIBRESOLV)
               	LIBS="$LIBS -lbind"
	else
		AC_CHECK_LIB(resolv, res_query, result=yes, result=no)
	        if test "$result" = "yes"; then
			AC_DEFINE(HAVE_LIBRESOLV)
                	LIBS="$LIBS -lresolv"
	        fi
	fi
fi

AC_MSG_CHECKING(how to printf gr_gid)
AC_TRY_RUN([#include <sys/types.h>
#include <grp.h>
int main(int argc, char **argv) {
  struct group *grent;
  if(sizeof(grent->gr_gid)<=4)
    return 0;
  return 1;
}],[ result="u"
AC_DEFINE_UNQUOTED(GR_GID_FORMAT, "$result")
AC_MSG_RESULT(gr_gid is just a long - using %u)],
    [ result="no" ], [ result="no" ])
if test $result = "no"; then
  AC_TRY_RUN([#include <stdio.h>
  int main(int argc, char **argv) {
    if(printf("%qd",(long long) 1)==1)
      return 0;
    return 1;
  }],[ result="qd" ],[ result="no" ], [ result="no"])
  if test $result = "no"; then
    AC_TRY_RUN([#include <stdio.h>
    int main(int argc, char **argv) {
      if(printf("Ld",(long long) 1)==1)
        return 0;
      return 1;
    }],[ result="Ld" ],[ result="no" ], [ result="no" ])
    if test $result = "no"; then
      AC_TRY_RUN([#include <stdio.h>
      int main(int argc, char **argv) {
        if(printf("lld",(long long) 1)==1)
          return 0;
        return 1;
      }],[ result="lld" ],[ result="no" ], [ result="no" ])
      if test $result = "no"; then
        AC_TRY_RUN([#include <stdio.h>
        int main(int argc, char **argv) {
          if(printf("ld",(long long) 1)==1)
            return 0;
          return 1;
        }],[ result="ld" ],[ result="d" ], [ result="d" ])
      fi
    fi
  fi
  AC_DEFINE_UNQUOTED(GR_GID_FORMAT,"$result")
  AC_MSG_RESULT(%$result)
fi

AC_MSG_CHECKING(how to printf pw_uid)
AC_TRY_RUN([#include <sys/types.h>
#include <pwd.h>
int main(int argc, char **argv) {
  struct passwd *pwent;
  if(sizeof(pwent->pw_uid)<=4)
    return 0;
  return 1;
}],[ result="u"
AC_DEFINE_UNQUOTED(PW_UID_FORMAT, "$result")
AC_MSG_RESULT(uid_t is just a long - using %u)],[ result="no" ], [ result="no" ])
if test $result = "no"; then
  AC_TRY_RUN([#include <stdio.h>
  int main(int argc, char **argv) {
    if(printf("%qd",(long long) 1)==1)
      return 0;
    return 1;
  }],[ result="qd" ],[ result="no" ], [ result="no"])
  if test $result = "no"; then
    AC_TRY_RUN([#include <stdio.h>
    int main(int argc, char **argv) {
      if(printf("Ld",(long long) 1)==1)
        return 0;
      return 1;
    }],[ result="Ld" ],[ result="no" ], [ result="no" ])
    if test $result = "no"; then
      AC_TRY_RUN([#include <stdio.h>
      int main(int argc, char **argv) {
        if(printf("lld",(long long) 1)==1)
          return 0;
        return 1;
      }],[ result="lld" ],[ result="no" ], [ result="no" ])
      if test $result = "no"; then
        AC_TRY_RUN([#include <stdio.h>
        int main(int argc, char **argv) {
          if(printf("ld",(long long) 1)==1)
            return 0;
          return 1;
        }],[ result="ld" ],[ result="d" ], [ result="d" ])
      fi
    fi
  fi
  AC_DEFINE_UNQUOTED(PW_UID_FORMAT,"$result")
  AC_MSG_RESULT(%$result)
fi

AC_MSG_CHECKING(how to printf an off_t)
AC_TRY_RUN([#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/stat.h>
int main(int argc, char **argv) {
  if(sizeof(off_t)<=4)
    return 0;
  return 1;
}],[ result="u"
AC_DEFINE_UNQUOTED(L_FORMAT, "$result")
AC_MSG_RESULT(off_t is just a long - using %u)],[ result="no" ], [ result="no" ])
if test $result = "no"; then
  AC_TRY_RUN([#include <stdio.h>
  int main(int argc, char **argv) {
    char tstr[8];
    if(sprintf(tstr, "%qd",(long long) 1)==1)
      return 0;
    return 1;
  }],[ result="qd" ],[ result="no" ], [ result="no"])
  if test $result = "no"; then
    AC_TRY_RUN([#include <stdio.h>
    int main(int argc, char **argv) {
      char tstr[8];
      if(sprintf(tstr, "Ld",(long long) 1)==1)
        return 0;
      return 1;
    }],[ result="Ld" ],[ result="no" ], [ result="no" ])
    if test $result = "no"; then
      AC_TRY_RUN([#include <stdio.h>
      int main(int argc, char **argv) {
        char tstr[8];
        if(sprintf(tstr, "lld",(long long) 1)==1)
          return 0;
        return 1;
      }],[ result="lld" ],[ result="no" ], [ result="no" ])
      if test $result = "no"; then
        AC_TRY_RUN([#include <stdio.h>
        int main(int argc, char **argv) {
          char tstr[8];
          if(sprintf(tstr, "ld",(long long) 1)==1)
            return 0;
          return 1;
        }],[ result="ld" ],[ result="d" ], [ result="d" ])
      fi
    fi
  fi
  AC_DEFINE_UNQUOTED(L_FORMAT,"$result")
  AC_MSG_RESULT(using %$result)
fi
AC_MSG_CHECKING(how to printf a time_t)
AC_TRY_RUN([#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
int main(int argc, char **argv) {
  if(sizeof(time_t)<=4)
    return 0;
  return 1;
}],[ result="u"
AC_DEFINE_UNQUOTED(T_FORMAT, "$result")
AC_MSG_RESULT(time_t is just a long - using %u)],[ result="no" ], [ result="no" ])
if test $result = "no"; then
  AC_TRY_RUN([#include <stdio.h>
  int main(int argc, char **argv) {
    if(printf("%qd",(long long) 1)==1)
      return 0;
    return 1;
  }],[ result="qd" ],[ result="no" ], [ result="no"])
  if test $result = "no"; then
    AC_TRY_RUN([#include <stdio.h>
    int main(int argc, char **argv) {
      if(printf("Ld",(long long) 1)==1)
        return 0;
      return 1;
    }],[ result="Ld" ],[ result="no" ], [ result="no" ])
    if test $result = "no"; then
      AC_TRY_RUN([#include <stdio.h>
      int main(int argc, char **argv) {
        if(printf("lld",(long long) 1)==1)
          return 0;
        return 1;
      }],[ result="lld" ],[ result="no" ], [ result="no" ])
      if test $result = "no"; then
        AC_TRY_RUN([#include <stdio.h>
        int main(int argc, char **argv) {
          if(printf("ld",(long long) 1)==1)
            return 0;
          return 1;
        }],[ result="ld" ],[ result="d" ], [ result="d" ])
      fi
    fi
  fi
  AC_DEFINE_UNQUOTED(T_FORMAT,"$result")
  AC_MSG_RESULT(%$result)
fi


dnl ===========================================================================
dnl Handle some of the input generated above...
dnl ============================================================================
if test $ac_cv_func_usercmp != yes; then
	AUTHUSER=authuser.o
fi
if test $ac_cv_func_ftw != yes; then
	FTW=ftw.o
fi
if test $ac_cv_func_getusershell != yes; then
	GETUSERSHELL=getusershell.o
fi
if test $ac_cv_func_setuid != yes; then
	SCO=sco.o
else
	AC_DEFINE(HAVE_SETUID)
fi
if test $ac_cv_func_snprintf != yes; then
	SNPRINTF=snprintf.o
fi
if test $ac_cv_func_strcasestr != yes; then
	STRCASESTR=strcasestr.o
fi
if test $ac_cv_func_strdup != yes; then
	STRDUP=strdup.o
fi
if test $ac_cv_func_strerror != yes; then
	STRERROR=strerror.o
fi
if test $ac_cv_func_strsep != yes; then
	STRSEP=strsep.o
fi
if test $ac_cv_func_strstr != yes; then
	STRSTR=strstr.o
fi
if test $ac_cv_func_syslog != yes; then
	SYSLOG=syslog.o
fi
if test $ac_cv_func_glob != yes; then
	GLOB=glob.o
fi
if test $ac_cv_func_strcasecmp != yes; then
	STRCASECMP=strcasecmp.o
fi
if test $ac_cv_func_strncasecmp != yes; then
	STRNCASECMP=strncasecmp.o
fi
AC_SUBST(AUTHUSER)
AC_SUBST(FTW)
AC_SUBST(GETUSERSHELL)
AC_SUBST(SCO)
AC_SUBST(SNPRINTF)
AC_SUBST(STRCASESTR)
AC_SUBST(STRDUP)
AC_SUBST(STRERROR)
AC_SUBST(STRSEP)
AC_SUBST(STRSTR)
AC_SUBST(SYSLOG)
AC_SUBST(GLOB)
AC_SUBST(STRCASECMP)
AC_SUBST(STRNCASECMP)


dnl ===========================================================================
dnl Get the --enable, --disable, --with, --without stuff into the config files
dnl fix it up when necessary
dnl ============================================================================

if test $upload = yes; then
	AC_DEFINE(UPLOAD)
fi
if test $overwrite = yes; then
	AC_DEFINE(OVERWRITE)
fi
if test $hostxs = yes; then
	AC_DEFINE(HOST_ACCESS)
fi
if test $logfailed = yes; then
	AC_DEFINE(LOG_FAILED)
fi
if test $logtoomany = yes; then
	AC_DEFINE(LOG_TOOMANY)
fi
if test $private = no; then
	AC_DEFINE(NO_PRIVATE)
fi
if test $dnsretry = yes; then
	AC_DEFINE(DNS_TRYAGAIN)
fi
if test $anononly = yes; then
	if test $anonymous = no; then
		AC_MSG_ERROR(enable-anononly and disable-anonymous together don't make sense.)
	fi
	AC_DEFINE(ANON_ONLY)
fi
if test $paranoid = yes; then
	AC_DEFINE(PARANOID)
fi
if test $quota != no; then
	AC_CHECK_HEADERS(sys/quota.h sys/fs/ufs_quota.h ufs/quota.h jfs/quota.h ufs/ufs/quota.h linux/quota.h)
	if test $ac_cv_header_sys_quota.h = yes -o $ac_cv_header_sys_fs_ufs_quota_h = yes -o $ac_cv_header_ufs_quota_h = yes -o $ac_cv_header_jfs_quota_h = yes -o $ac_cv_header_ufs_ufs_quota_h = yes -o $ac_cv_header_linux_quota_h = yes; then
		quota=yes
	else
		if test $quota = yes; then
			AC_MSG_WARN(QUOTA not supported by OS - disabled)
		fi
		quota=no
	fi
	AC_MSG_CHECKING(for quota support)
	AC_MSG_RESULT($quota)
fi
if test $quota = yes; then
	dnl FIXME!!
	dnl I didn't find a way to reliably check for QUOTA_DEVICE...
	dnl so we're guessing at the system type, actually... :/

	if test $ac_cv_header_sys_quota_h = yes -o $ac_cv_header_sys_fs_ufs_quota_h = yes; then
		AC_DEFINE(QUOTA_DEVICE)
	fi

	AC_MSG_CHECKING(whether quota support is file- or inode based)
	AC_TRY_COMPILE([
#include <unistd.h>
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_QUOTA_H
#include <sys/quota.h>
#else
#ifdef HAVE_LINUX_QUOTA_H
#include <linux/quota.h>
#endif
#endif
#ifdef HAVE_SYS_FS_UFS_QUOTA_H
#include <sys/fs/ufs/quota.h>
#endif
#ifdef HAVE_UFS_QUOTA_H
#include <ufs/quota.h>
#endif
#ifdef HAVE_JFS_QUOTA_H
#include <jfs/quota.h>
#endif
#ifdef HAVE_UFS_UFS_QUOTA_H
#include <ufs/ufs/quota.h>
#endif
struct dqblk quota;],
[ int f=quota.dqb_ihardlimit; ], [ result=inode ], [ result=file ])
	AC_MSG_RESULT($result)
	if test $result = inode; then
		AC_DEFINE(QUOTA_INODE)
	fi
	AC_DEFINE(QUOTA)
fi
if test $ac_cv_header_security_pam_appl_h = no; then
  if test $pam = yes; then
    AC_MSG_WARN(You don\'t have PAM libraries, or you\'re using an incompatible PAM implementation. PAM support disabled.)
    pam=no
  fi
fi
if test $pam = yes; then
	AC_DEFINE(USE_PAM)
	LIBS="$LIBS -lpam"
	AC_CHECK_LIB(dl, dlopen, result=yes, result=no)
	if test $result = yes; then
		# Some PAM implementations require -ldl...
		LIBS="$LIBS -ldl"
	fi
fi
dnl ===========================================================================
dnl See if we have shadow passwords...
dnl ============================================================================
AC_CHECK_LIB(shadow, setspent, result=yes, result=no)
SHADOW_PASSWORD=0
LIBSHADOW=0
if test $result = yes; then
	LIBS="$LIBS -lshadow"
	SHADOW_PASSWORD=1
	LIBSHADOW=1
else
	AC_CHECK_LIB(shadow, getspnam, result=yes, result=no)
	if test $result = yes; then
		LIBS="$LIBS -lshadow"
		SHADOW_PASSWORD=1
		LIBSHADOW=1
	else
		AC_CHECK_LIB(c, setspent, result=yes, result=no)
		if test $result = yes; then
			SHADOW_PASSWORD=1
		fi
	fi
fi
if test $SHADOW_PASSWORD = 1; then
	if test $ac_cv_func_fgetspent != yes; then
		AC_CHECK_LIB(shadow, fgetspent, result=yes, result=no)
		if test $result = yes; then
			if test $LIBSHADOW != 1; then
				LIBS="$LIBS -lshadow"
			fi
		fi
	fi
	AC_DEFINE(SHADOW_PASSWORD)
fi
if test $ac_cv_header_skey_h = no; then
  if test $skey = yes; then
    AC_MSG_WARN(You don\'t have S/Key libraries, or you\'re using an incompatible implementation. S/Key support disabled.)
    skey=no
  fi
fi
if test $skey = yes; then
	AC_DEFINE(SKEY)
	LIBS="$LIBS -lskey"
fi
if test $ac_cv_header_opie_h = no; then
  if test $opie = yes; then
    AC_MSG_WARN(You don\'t have OPIE libraries, or you\'re using an incompatible implementation. OPIE support disabled.)
    opie=no
  fi
fi
if test $opie = yes; then
	AC_DEFINE(OPIE)
	LIBS="$LIBS -lopie"
fi
if test $newcd = yes; then
	AC_DEFINE(ALTERNATE_CD)
fi
if test $chmod = yes; then
	AC_DEFINE(UNRESTRICTED_CHMOD)
fi
if test $rfc931 = yes; then
	AC_DEFINE(USE_RFC931)
fi
if test "$ratio" = "yes"; then
	AC_DEFINE(RATIO)
fi
if test "$passwd" = "yes"; then
	AC_DEFINE(OTHER_PASSWD)
fi
if test $daemon = yes; then
	AC_DEFINE(DAEMON)
fi
if test $mapchdir = yes; then
	AC_DEFINE(MAPPING_CHDIR)
fi
if test $throughput = yes; then
	AC_DEFINE(THROUGHPUT)
fi
if test $count = yes; then
	AC_DEFINE(TRANSFER_COUNT)
	AC_DEFINE(TRANSFER_LIMIT)
fi
if test $newlines = no; then
	AC_DEFINE(NO_SUCKING_NEWLINES)
fi
if test $crackers = yes; then
	AC_DEFINE(HELP_CRACKERS)
fi
if test $verbose = yes; then
	AC_DEFINE(VERBOSE_ERROR_LOGING)
fi
if test $noop = no; then
	AC_DEFINE(IGNORE_NOOP)
fi
if test $logrp = yes; then
	AC_DEFINE(XFERLOG_REALPATH)
fi
if test $virtual = yes; then
	AC_DEFINE(VIRTUAL)
fi
if test $closedvirt = yes; then
	AC_DEFINE(CLOSED_VIRTUAL_SERVER)
fi
if test $dns = no; then
	AC_DEFINE(NO_DNS)
fi
if test $port = no; then
	if test $pasv = no; then
		AC_MSG_ERROR(Need at least PORT or PASV mode. Don't disable both.)
	fi
	AC_DEFINE(DISABLE_PORT)
fi
if test $pasv = no; then
	AC_DEFINE(DISABLE_PASV)
fi
if test $plsm = no; then
	AC_DEFINE(NO_PID_SLEEP_MSGS)
fi
if test $pasvip = yes; then
	AC_DEFINE(FIGHT_PASV_PORT_RACE)
fi
if test $anonymous = no; then
	AC_DEFINE(NO_ANONYMOUS_ACCESS)
fi
if test $ls = yes; then
	AC_DEFINE(INTERNAL_LS)
fi
if test $numericuid = yes; then
	AC_DEFINE(LS_NUMERIC_UIDS)
fi
if test $hidesetuid = yes; then
	AC_DEFINE(HIDE_SETUID)
fi
if test $mail = yes; then
	AC_DEFINE(MAIL_ADMIN)
fi
if test $badclients = yes; then
	AC_DEFINE(SUPPORT_BROKEN_CLIENTS)
fi

dnl TODO:is there a better check whether or not an argument is numeric???
if test x`expr $bufsize + 1 - 1 2>/dev/null` = x$bufsize; then
	AC_DEFINE_UNQUOTED(BUFFER_SIZE, $bufsize)
fi
if test x`expr $backlog + 1 - 1 2>/dev/null` = x$backlog; then
	AC_DEFINE_UNQUOTED(MAX_BACKLOG, $backlog)
else
	AC_DEFINE_UNQUOTED(MAX_BACKLOG, 100)
fi

AC_DEFINE_UNQUOTED(SIGNAL_TYPE, void)

LIBS="$LIBS -lsupport"

AC_SUBST(LIBS)

AC_DEFINE(USE_ETC)

dnl ===========================================================================
dnl Write results...
dnl ============================================================================

AC_OUTPUT(Makefile src/Makefile support/Makefile util/privatepw/Makefile src/pathnames.h)
