dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which tries to guess your system
dnl	configuration so that no manual editing of the Makefile should be
dnl	necessary
dnl
dnl $Id$
dnl

AC_INIT(uulib.c)
AC_PREREQ(2.9)
AC_CONFIG_HEADER(config.h)

#
# package revision
#
VERSION=0.5
PATCH=20

AC_ARG_WITH(cc,,CC=$with_cc)
AC_ARG_WITH(cflags,,CFLAGS=$with_cflags)

AC_PROG_CC
AC_PROG_CPP
wi_PROTOTYPES
AC_PROG_MAKE_SET
AC_PROG_RANLIB

if test "$wi_cv_prototypes" = no ; then
	AC_WARN([Your compiler does not support function prototyping and])
	AC_WARN([is not able to properly compile this package. What a pity.])
        AC_WARN([Get gcc, or any compiler that supports function prototypes.])
	exit 1
fi

#
# Checks for header files and library functions
#

AC_HEADER_STDC
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_CHECK_HEADERS(fcntl.h unistd.h memory.h malloc.h errno.h)
AC_CHECK_HEADERS(io.h sys/time.h)

CFLAGS="$CFLAGS -D_GNU_SOURCE"
AC_CHECK_FUNCS(gettimeofday fgetc_unlocked)
dnl AC_CHECK_FUNCS(strcasecmp strncasecmp strcasestr)

AC_CHECK_FUNC(tempnam,,AC_DEFINE(tempnam,FP_tempnam))

AC_CHECK_FUNC(chmod,AC_DEFINE(HAVE_CHMOD))
AC_CHECK_FUNC(umask,AC_DEFINE(HAVE_UMASK))
AC_CHECK_FUNC(mkstemp,AC_DEFINE(HAVE_MKSTEMP))

#
# strerror might be internally defined. this would cause a
# CHECK_FUNCS(strerror) to fail because it'd be called with
# zero arguments. So use our own code.
#
AC_MSG_CHECKING([for strerror])
AC_TRY_LINK([
char *blubb() { return (char *) strerror (42); }
],[
(void) blubb();
],have_strerror=yes,AC_DEFINE(strerror,FP_strerror)
have_strerror=no)
AC_MSG_RESULT($have_strerror)

AC_MSG_CHECKING([for stdin])
AC_TRY_LINK([
#include <stdio.h>
char *blubb() { FILE *in, *out; in=stdin; out=stdout; return (char*)0; }
],[
(void) blubb();
],have_stdio=yes,AC_DEFINE(HAVE_STDIO)
have_stdio=no)
AC_MSG_RESULT($have_stdio)

if test "$ac_cv_header_stdc" = "no" ; then
	AC_CHECK_HEADERS(stdarg.h varargs.h)
	if test "$ac_cv_header_stdarg_h" = "no" ; then
	if test "$ac_cv_header_varargs_h" = "no" ; then
		AC_MSG_ERROR([neither stdarg.h nor varargs.h present])
	fi
	fi
fi

#
# Check whether this is a DOS-Based system. Another bogus test.
# Don't even bother to print a message. This code is needed so
# that autoheader includes the #undef into the final config.h
# and we can change the definition by hand on a really DOS
# system (where ./configure doesn't work anyway ...)
#

if false ; then
	AC_DEFINE(SYSTEM_DOS)
	AC_DEFINE(SYSTEM_QUICKWIN)
	AC_DEFINE(SYSTEM_WINDLL)
	AC_DEFINE(SYSTEM_OS2)
fi

#
# On some systems (so far, OS2 and WINDOWS), functions that are exported
# from a DLL must be declared specifically.
#

AC_DEFINE_UNQUOTED(UUEXPORT,)
AC_DEFINE_UNQUOTED(TOOLEXPORT,)

#
# set version number
#
AC_MSG_CHECKING([version number])
version_number="$VERSION"pl"$PATCH"
AC_MSG_RESULT($version_number)
AC_SUBST(VERSION)
AC_SUBST(PATCH)

#
# done
#

AC_OUTPUT(Makefile)

