dnl Process this file with autoconf to produce a configure script.
AC_INIT(expense.c)

dnl AM_PROG_LIBTOOL

dnl Checks for programs.
AC_PROG_CC

# Compile options
ccoptions=""
AC_ARG_WITH(ccoptions,
[  --with-ccoptions=       Options to pass to your C compiler])

if test "x$with_ccoptions" != "x"; then
   ccoptions=$with_ccoptions
   CFLAGS=""
   AC_MSG_CHECKING(for supplied cc options)
   AC_MSG_RESULT(Using supplied cc options $ccoptions)
fi
AC_SUBST(ccoptions)
cflags=$CFLAGS
AC_SUBST(cflags)

dnl Check for pilot-link libs
pilot_prefix=""
AC_ARG_WITH(pilot_prefix,
 [  --with-pilot-prefix=    Prefix to top level of pilot-link files
                            (e.g., = /usr/local if the pilot-link includes
                             are in /usr/local/include
                             and libs are in /usr/local/lib)])

if test "x$with_pilot_prefix" != "x"; then
   pilot_prefix=$with_pilot_prefix
fi

dnl Make sure that the pilot-link stuff actually exists
AC_MSG_CHECKING(for pilot-link header files)
pilotinclude=no
for pilot_incl in $pilot_prefix/include /usr/include /usr/local/include \
    /usr/extra/pilot/include /usr/include/libpisock; do
   if test -r "$pilot_incl/pi-config.h" ; then
      pilotinclude=yes
      PILOT_FLAGS="$PILOT_FLAGS -I$pilot_incl"
      break
   fi
done

if test $pilotinclude = no ; then
   AC_MSG_RESULT(no)
   AC_MSG_ERROR(Could not find the pilot-link header files)
else
   AC_MSG_RESULT(found at $pilot_incl)
fi

dnl Solaris needs the socket library
AC_CHECK_LIB(socket, main, PILOT_LIBS=$PILOT_LIBS" -lsocket", , )

dnl Maybe installed
AC_MSG_CHECKING(for pilot library files)
pilotlibs=no
PILOT_LIBS="-lpisock"

for pilot_libs in $pilot_prefix/lib /usr/lib /usr/local/lib/ \
  /usr/extra/pilot/lib ; do
   if test -r "$pilot_libs/libpisock.so" ; then
      pilotlibs=yes
      PILOT_LIBS="-L$pilot_libs $PILOT_LIBS"
      break
   fi
done

if test $pilotlibs = no ; then
   AC_MSG_RESULT(no)
   AC_MSG_ERROR(Could not find the pilot-link libraries)
else
   AC_MSG_RESULT(found at $pilot_libs)
fi

dnl Solaris needs the socket library
AC_CHECK_LIB(socket, main, PILOT_LIBS=$PILOT_LIBS" -lsocket", , )

AC_ARG_ENABLE(pl-test, [  --disable-pl-test       Do not try to compile \
a test pilot-link program], enable_pl_test=no, enable_pl_test=yes)

if test "x$enable_pl_test" = "xyes"; then
   dnl Link a tiny program to make sure we have the environment right
   AC_MSG_CHECKING(to see if I can compile a pilot link program)
   ac_save_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS $PILOT_FLAGS"
   ac_save_LIBS="$LIBS"
   LIBS="$LIBS $PILOT_LIBS"

   pilotcompile=no

   AC_TRY_LINK([#include "pi-config.h" 
#include "pi-socket.h"], [pi_close (0);] , pilotcompile=yes, , )

   if test $pilotcompile = no ; then
      AC_MSG_RESULT(no)
      AC_MSG_ERROR(Could not compile a test pilot-link program)
   else
      AC_MSG_RESULT(ok)
      AC_SUBST(PILOT_FLAGS)
      AC_SUBST(PILOT_LIBS)
   fi

CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"

fi

dnl Checking for GTK version
AM_PATH_GTK(1.2.0,,
  AC_MSG_ERROR([*** GTK >= 1.2.0 not installed - please install first ***]))

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_PID_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_UTIME_NULL

AC_OUTPUT(Makefile)
