dnl Process this file with autoconf to produce a configure script.

dnl init autoconf
AC_INIT(ac.c)
dnl macros for automake
AM_INIT_AUTOMAKE(acct, 6.3.5, no-define-symbols)
AM_CONFIG_HEADER(config.h)

AC_ARG_PROGRAM
AC_PROG_CC
if test "x${ac_cv_prog_gcc}" = "xyes"; then
 CFLAGS="${CFLAGS} -Wall -Wmissing-prototypes"
fi
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_AIX
AC_MINIX
AC_ISC_POSIX

AM_C_PROTOTYPES
AC_C_CONST

AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
dnl AC_HEADER_MAJOR
MKTIME_C="mktime.c" MKTIME_O="mktime.o"
AC_CHECK_FUNC(mktime,
              AC_DEFINE(HAVE_MKTIME)
              MKTIME_C="" MKTIME_O="" )
AC_CHECK_FUNC(getpagesize, AC_DEFINE(HAVE_GETPAGESIZE))
AC_CHECK_FUNC(rename, AC_DEFINE(HAVE_RENAME))
AC_CHECK_HEADERS(limits.h stdlib.h unistd.h string.h)
dnl
dnl crunky time stuff
dnl
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/time.h)
dnl
dnl find out where various programs reside on this system
dnl
AC_PATH_PROGS(SYS_LAST, last, echo, /bin /etc /sbin /usr/bin /usr/etc /usr/sbin /usr/ucb /usr/local/bin /usr/local/etc /usr/local/sbin )
AC_PATH_PROGS(SYS_LASTCOMM, lastcomm, echo, /bin /etc /sbin /usr/bin /usr/etc /usr/sbin /usr/ucb /usr/local/bin /usr/local/etc /usr/local/sbin )
AC_PATH_PROGS(SYS_AC, ac, echo, /bin /etc /sbin /usr/bin /usr/etc /usr/sbin /usr/ucb /usr/local/bin /usr/local/etc /usr/local/sbin )
AC_PATH_PROGS(SYS_SA, sa, echo, /bin /etc /sbin /usr/bin /usr/etc /usr/sbin /usr/ucb /usr/local/bin /usr/local/etc /usr/local/sbin )
dnl
dnl find out what fields are valid in utmp.h
dnl
AC_EGREP_HEADER(ut_id, utmp.h, AC_DEFINE(HAVE_UT_ID), )
AC_EGREP_HEADER(ut_pid, utmp.h, AC_DEFINE(HAVE_UT_PID), )
AC_EGREP_HEADER(ut_host, utmp.h, AC_DEFINE(HAVE_UT_HOST), )
AC_EGREP_HEADER(ut_addr, utmp.h, AC_DEFINE(HAVE_UT_ADDR), )
AC_EGREP_HEADER(ut_type, utmp.h, AC_DEFINE(HAVE_UT_TYPE), )
dnl
dnl figure out where acct.h lives
dnl and whether fields are int/comp_t
dnl
AC_CHECK_HEADER(sys/acct.h,
		AC_DEFINE(HAVE_SYS_ACCT_H)
		DUMP_ACCT_PROG=dump-acct
		ACCTON_PROG=accton
		LASTCOMM_PROG=lastcomm
		SA_PROG=sa
		ACCTON_MAN=accton.8
		LASTCOMM_MAN=lastcomm.1
		SA_MAN=sa.8
		AC_HEADER_EGREP(ac_utime, sys/acct.h,
				AC_DEFINE(HAVE_ACUTIME)
				AC_HEADER_EGREP(comp_t.*ac_utime, sys/acct.h,
						AC_DEFINE(ACUTIME_COMPT))
		)
		AC_HEADER_EGREP(ac_stime, sys/acct.h,
				AC_DEFINE(HAVE_ACSTIME)
				AC_HEADER_EGREP(comp_t.*ac_stime, sys/acct.h,
						AC_DEFINE(ACSTIME_COMPT))
		)
		AC_HEADER_EGREP(ac_etime, sys/acct.h,
				AC_DEFINE(HAVE_ACETIME)
				AC_HEADER_EGREP(comp_t.*ac_etime, sys/acct.h,
						AC_DEFINE(ACETIME_COMPT))
		)
		AC_HEADER_EGREP(ac_io,    sys/acct.h,
				AC_DEFINE(HAVE_ACIO)
				AC_HEADER_EGREP(comp_t.*ac_io,    sys/acct.h,
						AC_DEFINE(ACIO_COMPT))
		)
		AC_HEADER_EGREP(ac_mem,   sys/acct.h,
				AC_DEFINE(HAVE_ACMEM)
				AC_HEADER_EGREP(comp_t.*ac_mem,   sys/acct.h,
						AC_DEFINE(ACMEM_COMPT))
		)
		AC_HEADER_EGREP(comp_t,   sys/acct.h, AC_DEFINE(HAVE_COMP_T))
		,
  dnl
  dnl here is the "else" clause for the above AC_CHECK_HEADER
  dnl (for older versions of linux, which didn't have a sys/acct.h)
  dnl
  AC_CHECK_HEADER(linux/acct.h,
		  AC_DEFINE(HAVE_LINUX_ACCT_H)
		  DUMP_ACCT_PROG=dump-acct
		  ACCTON_PROG=accton
		  LASTCOMM_PROG=lastcomm
		  SA_PROG=sa
		  ACCTON_MAN=accton.8
		  LASTCOMM_MAN=lastcomm.1
		  SA_MAN=sa.8
		  AC_HEADER_EGREP(ac_utime, linux/acct.h,
				  AC_DEFINE(HAVE_ACUTIME)
				  AC_HEADER_EGREP(comp_t.*ac_utime,
						  linux/acct.h,
						  AC_DEFINE(ACUTIME_COMPT))
		  )
		  AC_HEADER_EGREP(ac_stime, linux/acct.h,
				  AC_DEFINE(HAVE_ACSTIME)
				  AC_HEADER_EGREP(comp_t.*ac_stime,
						  linux/acct.h,
						  AC_DEFINE(ACSTIME_COMPT))
		  )
		  AC_HEADER_EGREP(ac_etime, linux/acct.h,
				  AC_DEFINE(HAVE_ACETIME)
				  AC_HEADER_EGREP(comp_t.*ac_etime,
						  linux/acct.h,
						  AC_DEFINE(ACETIME_COMPT))
		  )
		  AC_HEADER_EGREP(ac_io,    linux/acct.h,
				  AC_DEFINE(HAVE_ACIO)
				  AC_HEADER_EGREP(comp_t.*ac_io, linux/acct.h,
						  AC_DEFINE(ACIO_COMPT))
		  )
		  AC_HEADER_EGREP(ac_mem,   linux/acct.h,
				  AC_DEFINE(HAVE_ACMEM)
				  AC_HEADER_EGREP(comp_t.*ac_mem, linux/acct.h,
						  AC_DEFINE(ACMEM_COMPT))
		  )
		  AC_HEADER_EGREP(comp_t,   linux/acct.h, AC_DEFINE(HAVE_COMP_T))
		  , )
)
dnl
dnl find out where utmp/pacct are stored
dnl
AC_TRY_RUN(
[
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_LINUX_ACCT_H
# include <linux/acct.h>
#else
# include <sys/acct.h>
#endif
#include <utmp.h>

#ifndef WTMP_FILE
#  if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__linux__)
#    define WTMP_FILE "/var/log/wtmp"
#  else
#    if defined(sun) || defined(AMIX)
#      define WTMP_FILE "/var/adm/wtmp"
#    else
#      if defined(sgi) || defined(SVR4)
#        define WTMP_FILE "/usr/adm/wtmp"
#      else
#        define WTMP_FILE "/usr/adm/wtmp"
#      endif
#    endif
#  endif
#endif

#ifndef ACCT_FILE
#  if defined(__FreeBSD__) || defined(__linux__)
#    define ACCT_FILE "/var/account/pacct"
#  else
#    if defined(__NetBSD__)
#      define ACCT_FILE "/var/account/acct"
#    else
#      if defined(sun) || defined(AMIX)
#        define ACCT_FILE "/var/adm/pacct"
#      else
#        if defined(sgi) || defined(SVR4) || defined(M_XENIX)
#          define ACCT_FILE "/usr/adm/pacct"
#        else
#          define ACCT_FILE "/usr/adm/acct"
#        endif
#      endif
#    endif
#  endif
#endif

#ifndef SAVACCT_FILE
#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
#    define SAVACCT_FILE "/var/account/savacct"
#  else
#    if defined(sun) || defined(AMIX)
#      define SAVACCT_FILE "/var/adm/savacct"
#    else
#      if defined(sgi) || defined(SVR4)
#        define SAVACCT_FILE "/usr/adm/savacct"
#      else
#        define SAVACCT_FILE "/usr/adm/savacct"
#      endif
#    endif
#  endif
#endif

#ifndef USRACCT_FILE
#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
#    define USRACCT_FILE "/var/account/usracct"
#  else
#    if defined(sun) || defined(AMIX)
#      define USRACCT_FILE "/var/adm/usracct"
#    else
#      if defined(sgi) || defined(SVR4)
#        define USRACCT_FILE "/usr/adm/usracct"
#      else
#        define USRACCT_FILE "/usr/adm/usracct"
#      endif
#    endif
#  endif
#endif

main ()
{
  FILE *fp;
  fp = fopen ("locs", "w");
  fprintf (fp, "WTMP_FILE_LOC=%s\n", WTMP_FILE);
  fprintf (fp, "ACCT_FILE_LOC=%s\n", ACCT_FILE);
  fprintf (fp, "SAVACCT_FILE_LOC=%s\n", SAVACCT_FILE);
  fprintf (fp, "USRACCT_FILE_LOC=%s\n", USRACCT_FILE);
  fclose (fp);
  exit (0);
}
], . ./locs; rm locs,
   echo "Error -- could not locate your wtmp and acct files."; exit 1,
   echo "Sorry -- you cannot cross-compile this package (FIXME)."; exit 1 )
AC_TYPE_PID_T dnl for sys/acct.h
AC_TYPE_UID_T dnl same as above
AC_TYPE_SIZE_T
AC_HEADER_DIRENT
echo checking for kitchen sink... You find a ring in the sink!

dnl Substitute program names for automake
AC_SUBST(DUMP_ACCT_PROG)
AC_SUBST(ACCTON_PROG)
AC_SUBST(LASTCOMM_PROG)
AC_SUBST(SA_PROG)

dnl Substitute manual page names for automake
AC_SUBST(ACCTON_MAN)
AC_SUBST(LASTCOMM_MAN)
AC_SUBST(SA_MAN)

dnl Substitutions for mktime
AC_SUBST(MKTIME_C)
AC_SUBST(MKTIME_O)

dnl Substitutions for file locations
AC_SUBST(WTMP_FILE_LOC)
AC_SUBST(ACCT_FILE_LOC)
AC_SUBST(SAVACCT_FILE_LOC)
AC_SUBST(USRACCT_FILE_LOC)

dnl Dump the makefiles and etc.
AC_OUTPUT(Makefile files.h version.h, [test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h])
