dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/ls.c)
AC_CONFIG_HEADER(config.h)
AC_SUBST(PROGS)dnl
AC_SUBST(LIBPROGS)dnl

# We want these before the checks, so the checks can modify their values.
test -z "$CFLAGS" && CFLAGS= auto_cflags=1
test -z "$LDFLAGS" && LDFLAGS=

AC_PROG_CC

# If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O2"

AC_SUBST(CFLAGS)dnl
AC_SUBST(LDFLAGS)dnl

AC_PROG_CPP
AC_GCC_TRADITIONAL
AC_PROG_RANLIB
AC_PROG_YACC
AC_AIX
AC_MINIX
AC_ISC_POSIX
AC_MAJOR_HEADER
AC_DIR_HEADER
AC_RETSIGTYPE

echo checking how to get list of mounted filesystems
mounted=

# DEC Alpha running OSF/1.
AC_COMPILE_CHECK(, [
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/fs_types.h>],
[struct statfs *stats;
numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); ],
  AC_DEFINE(MOUNTED_GETFSSTAT) mounted=1)
if test -z "$mounted"; then
# SVR4
AC_HEADER_EGREP(getmntent, sys/mnttab.h,
  AC_DEFINE(MOUNTED_GETMNTENT2) mounted=1)
fi
if test -z "$mounted"; then
# AIX.
AC_TEST_CPP([#include <fshelp.h>],
  AC_DEFINE(MOUNTED_VMOUNT) mounted=1)
fi
if test -z "$mounted"; then
# SVR3
AC_TEST_CPP([#include <sys/statfs.h>
#include <sys/fstyp.h>
#include <mnttab.h>],
  AC_DEFINE(MOUNTED_FREAD_FSTYP) mounted=1)
fi
if test -z "$mounted"; then
# 4.3BSD
AC_TEST_CPP([#include <mntent.h>],
  AC_DEFINE(MOUNTED_GETMNTENT1) mounted=1)
fi
if test -z "$mounted"; then
# 4.4BSD and DEC OSF/1.
AC_HEADER_EGREP(f_type;, sys/mount.h,
  AC_DEFINE(MOUNTED_GETMNTINFO) mounted=1)
fi
if test -z "$mounted"; then
# Ultrix
AC_TEST_CPP([#include <sys/fs_types.h>
#include <sys/mount.h>],
  AC_DEFINE(MOUNTED_GETMNT) mounted=1)
fi
if test -z "$mounted"; then
# SVR2
AC_TEST_CPP([#include <mnttab.h>],
  AC_DEFINE(MOUNTED_FREAD) mounted=1)
fi

echo checking how to get filesystem space usage
space=

# DEC Alpha running OSF/1
AC_TEST_PROGRAM([
#include <sys/types.h>
#include <sys/mount.h>
main ()
{
struct statfs fsd;
fsd.f_fsize = 0;
exit (statfs (".", &fsd, sizeof (struct statfs)));
}], AC_DEFINE(STAT_STATFS3_OSF1) space=1)
if test -z "$space"; then
# SVR4
AC_TEST_CPP([#include <sys/statvfs.h>
#include <sys/fstyp.h>], AC_DEFINE(STAT_STATVFS) space=1)
fi
if test -z "$space"; then
# AIX
AC_HEADER_EGREP(f_nlsdirtype, sys/statfs.h,
  AC_DEFINE(STAT_STATFS2_BSIZE) space=1)
fi
if test -z "$space"; then
# SVR3
AC_TEST_CPP([#include <sys/statfs.h>],
  AC_DEFINE(STAT_STATFS4) space=1)
fi
if test -z "$space"; then
# 4.3BSD
AC_TEST_CPP([#include <sys/vfs.h>],
  AC_DEFINE(STAT_STATFS2_BSIZE) space=1)
fi
if test -z "$space"; then
# 4.4BSD
AC_DEFINE(STAT_STATFS2_FSIZE) space=1
fi
if test -z "$space"; then
# SVR2
AC_TEST_CPP([#include <sys/filsys.h>],
  AC_DEFINE(STAT_READ) space=1)
fi
if test -z "$space"; then
# Ultrix
AC_TEST_CPP([#include <sys/mount.h>],
  AC_DEFINE(STAT_STATFS2_FS_DATA) space=1)
fi
if test -n "$mounted" && test -n "$space"; then
  PROGS="$PROGS df" LIBOBJS="$LIBOBJS fsusage.o mountlist.o"
fi

AC_UID_T
AC_GETGROUPS_T
AC_SIZEOF_TYPE(int,sizevar)
AC_CONST
AC_STDC_HEADERS
AC_STRUCT_TM
AC_TIME_WITH_SYS_TIME
AC_STAT_MACROS_BROKEN
AC_HAVE_HEADERS(string.h fcntl.h limits.h sys/time.h errno.h unistd.h)
AC_REPLACE_FUNCS(fnmatch mkdir mktime stpcpy strdup strstr rename)
AC_HAVE_FUNCS(strerror ftime getcwd mkfifo memcpy bcopy gettimeofday)
AC_COMPILE_CHECK(ftruncate, , [ftruncate();],
  AC_DEFINE(HAVE_FTRUNCATE), ftruncate_missing=1)
if test -n "$ftruncate_missing"; then
AC_COMPILE_CHECK(fcntl emulation of ftruncate,
[#include <sys/types.h>
#include <fcntl.h>], [
#if !defined(F_CHSIZE) && !defined(F_FREESP)
chsize();
#endif
], AC_DEFINE(HAVE_FTRUNCATE) LIBOBJS="$LIBOBJS ftruncate.o")
fi

case "$LIBOBJS" in
*rename.o*)
  LIBPROGS="$LIBPROGS mvdir"
  ;;
esac

AC_VPRINTF
AC_ALLOCA
AC_ST_BLOCKS
AC_UTIME_NULL
AC_XENIX_DIR
AC_IRIX_SUN
AC_DYNIX_SEQ
# Check for libypsec.a on Dolphin M88K machines.
AC_HAVE_LIBRARY(ypsec)

# m88k running dgux 5.4 needs this
AC_HAVE_LIBRARY(-ldgc)

echo checking for AFS
false && AC_DEFINE(AFS)

AC_OUTPUT(Makefile lib/Makefile src/Makefile man/Makefile)
