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

AC_CONFIG_HEADER(config.h:config.hin)

dnl Checks for support programs

AC_PATH_PROGS(AWK, [gawk nawk mawk awk])

dnl Checks for NeXT -posix
AC_MSG_CHECKING(whether we have NeXT system, and so need -posix)
if test -d /NextAdmin
then CFLAGS=-posix
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi

dnl Checks for compiler
AC_PROG_CC
AC_PROG_CXX

dnl Checks for ALL (IBM RS/6000 c89 needs _ALL_SOURCE when ioctl.h is
dnl used with winsize)
AC_MSG_CHECKING(whether we need _ALL_SOURCE)
all=no
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/ioctl.h>
struct winsize w;
], , , all=maybe)
if test $all = maybe ; then
AC_TRY_COMPILE([
#define _ALL_SOURCE
#include <sys/types.h>
#include <sys/ioctl.h>
struct winsize w;
], , AC_DEFINE(_ALL_SOURCE) all=yes)
fi
if test $all = maybe ; then all=no ; fi
AC_MSG_RESULT($all)

dnl Checks for POSIX (HP-UX c89 needs _POSIX_SOURCE when stat.h is used)
AC_MSG_CHECKING(whether we need _POSIX_SOURCE)
posix=no
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/stat.h>
struct stat buffer;
], , , posix=maybe)
if test $posix = maybe ; then
AC_TRY_COMPILE([
#define _POSIX_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
struct stat buffer;
], , AC_DEFINE(_POSIX_SOURCE) posix=yes)
fi
if test $posix = maybe ; then posix=no ; fi
AC_MSG_RESULT($posix)

dnl Checks for Standard C and C++ function declarations.
AC_MSG_CHECKING(for Standard C and C++ function declarations)
AC_TRY_COMPILE([void foo(void){}
int bar(int x, float y, char z){return 1;}], ,
  [AC_MSG_RESULT(yes)
    AC_DEFINE(HAVE_STDC)],
    AC_MSG_RESULT(no))

dnl Checks for SunOS C++ free() argument type bug
AC_MSG_CHECKING(for SunOS C++ free() argument type bug)
freebug=no
AC_TRY_COMPILE([#include <stdlib.h>],
[void *p; p = (void*)0; free(p)],
, freebug=maybe)

if test $freebug = maybe ; then
AC_TRY_COMPILE([#include <stdlib.h>],
[void *p; p = (void*)0; free((char*)p)],
AC_DEFINE(FREE_CAST_IS_CHAR_STAR) freebug=yes)
fi
if test $freebug = maybe ; then freebug=no ; fi
AC_MSG_RESULT($freebug)

dnl Checks for Standard C alert character
AC_MSG_CHECKING(for Standard C alert character)
havealert=yes
AC_TRY_RUN(int main(){return((int)'\a'-007);},
    [havealert=yes
     AC_DEFINE(HAVE_ALERT_CHAR)],
    havealert=no,
    havealert=no)
AC_MSG_RESULT($havealert)

dnl Checks for programs.

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(conio.h ctype.h descrip.h errno.h fcntl.h io.h \
iodef.h jpidef.h libc.h limits.h osfcn.h pwd.h regex.h regexp.h \
rms.h sgtty.h ssdef.h stat.h stdio.h stdlib.h string.h sys/ioctl.h \
sys/param.h sys/stat.h sys/types.h termio.h termios.h time.h \
tt2def.h ttdef.h types.h unistd.h unixio.h )

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_STRUCT_TM

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_UTIME_NULL
AC_REPLACE_FUNCS(strtol)
AC_CHECK_FUNCS(getcwd getwd re_comp strcspn strdup strspn strstr strtod strtol)

AC_MSG_CHECKING(for ioctl prototype)
AC_EGREP_CPP([ioctl[ 	]*[(]],
[
#include <sys/ioctl.h>
#include <unistd.h>
],
[
AC_DEFINE(HAVE_IOCTL_PROTOTYPE)
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
])

dnl Remove -g from CFLAGS if we are compiling with lcc because it
dnl produces bad debug symbol tables on Sun Solaris 2.x.
if test "$CC" = "lcc"
then
    CFLAGS="`echo $CFLAGS | sed -e 's/-g //g' -e 's/ -g$//g' -e 's/^-g$//'`"
fi

AC_OUTPUT(Makefile)
