dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/crctab.c)
AM_INIT_AUTOMAKE(lrzsz, 0.12.20)
AM_CONFIG_HEADER(config.h)


dnl AC_C_CROSS is in AC_PROG_CC since 2.12
AC_PREREQ(2.12)

PACKAGE_VERSION="$PACKAGE-$VERSION"
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_DEFINE_UNQUOTED(PACKAGE_VERSION, "$PACKAGE_VERSION")
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(PACKAGE_VERSION)

ALL_LINGUAS="de"

AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

changequote(,)dnl
case $VERSION in
	[0-9]*.[0-9]*.[0-9]*) README_ALPHA="README-alpha";;
	*) README_ALPHA=;;
esac
changequote([, ])dnl


AC_ARG_ENABLE(timesync,
	[--disable-timesync   exclude support for timesync protocol],
	[if test "$enableval" = "no" ; then 
		:
	  else
		AC_DEFINE(ENABLE_TIMESYNC)
	  fi],
	[AC_DEFINE(ENABLE_TIMESYNC)])
AC_SUBST(ENABLE_TIMESYNC)
AC_ARG_ENABLE(pubdir,
	[--enable-pubdir=/path   include support for a public writeable directory],
	[if test "$enableval" = "no" ; then 
		: 
	  else 
	    AC_DEFINE_UNQUOTED(PUBDIR,"$enableval")
	  fi])
AC_ARG_ENABLE(mkdir,
	[--disable-mkdir   disable support for creating directories (lrz)],
	[if test "$enableval" = "no" ; then 
		:
	  else
	  	AC_DEFINE(ENABLE_MKDIR)
	  fi],
	[AC_DEFINE(ENABLE_MKDIR)])
AC_ARG_ENABLE(syslog,
	[--enable-syslog=FACILITY,{force,default,optional} include syslogsupport],
	[
	  if test "$enableval" = "no" ; then 
		:
	  else
	    case "$enableval" in
	    *,*)
			level=`echo $enableval|sed -e 's/^.*,//'`
			fac=`echo $enableval|sed -e 's/,.*$//'`
			AC_DEFINE_UNQUOTED(ENABLE_SYSLOG,$fac)
			;;
		*)
			lookup_facility=LOG_UUCP
			level="$enableval"
			;;
		esac
	  	if test "$level" = "force" ; then
		  AC_DEFINE(ENABLE_SYSLOG_FORCE)
	  	else 
	  	  if test "$level" = "optional" ; then
	  	    :
	  	  else
		    AC_DEFINE(ENABLE_SYSLOG_DEFAULT)
		  fi
	  	fi
	  fi],[
		AC_DEFINE(ENABLE_SYSLOG_DEFAULT)
		lookup_facility=LOG_UUCP
	  ])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
dnl AC_PROG_INSTALL  included in AM_INIT_AUTOMAKE
dnl AC_PROG_MAKE_SET included in AM_INIT_AUTOMAKE
AC_PROG_RANLIB
AC_ISC_POSIX
AC_AIX
AC_MINIX
AM_C_PROTOTYPES
AC_C_CONST
AC_C_INLINE

if test `hostname` = tirka.ohse.de -a "$cross_compiling" = no ; then
    test $prefix = NONE && prefix=/usr
	if test -z "$CFLAGS" ; then 
	    case "$CC" in 
		*gcc*)
			CFLAGS="-Wall -Wstrict-prototypes -Wmissing-prototypes"
			# -Wnested_externs entfernt wegen dcgettext()
			CFLAGS="$CFLAGS -Wpointer-arith -Wcast-qual -Wcast-align"
			CFLAGS="$CFLAGS -Winline -Wwrite-strings -Wshadow -Wmissing-braces"
			CFLAGS="$CFLAGS -Wcomments -fforce-mem -fforce-addr -O2 -m486 -pipe"
			CFLAGS="$CFLAGS -malign-loops=2 -malign-jumps=2 -malign-functions=2 -g3"
			;;
		esac
	fi
fi
case "$CFLAGS" in
*-Wstrict-prototypes*)
	AC_DEFINE(STRICT_PROTOTYPES)
	;;
esac

dnl Checks for libraries.
dnl SCO needs this.
AC_CHECK_LIB(socket,syslog,,,)
dnl BeOS needs this
AC_CHECK_LIB(be,syslog,,,)
dnl slowlartis needs this
AC_CHECK_LIB(nsl,gethostbyname,,,)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h sys/time.h unistd.h sys/times.h)
LRZSZ_HEADERS_TERM_IO
AC_CHECK_HEADERS(termios.h sys/termios.h termio.h sys/termio.h sgtty.h)
AC_CHECK_HEADERS(sys/mman.h utime.h syslog.h sys/syslog.h sys/param.h)
AC_CHECK_HEADERS(sys/select.h strings.h arpa/inet.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
LRZSZ_TYPE_SPEED_T
AC_STRUCT_ST_RDEV
AC_HEADER_TIME
lrzsz_HEADER_SYS_SELECT
AC_STRUCT_TM
LRZSZ_ERRNO_DECL

dnl Checks for library functions.
if test $cross_compiling = no ; then
	AC_FUNC_SETVBUF_REVERSED
fi
AC_TYPE_SIGNAL
dnl suggested by autoscan, but not really needed.
dnl AC_FUNC_UTIME_NULL
AC_FUNC_MMAP
AC_FUNC_ALLOCA
AC_EGREP_HEADER([struct.*utimbuf], utime.h, AC_DEFINE(HAVE_STRUCT_UTIMBUF))

AC_CHECK_FUNCS(gettimeofday settimeofday)
AC_CHECK_FUNCS(strchr memcpy select vprintf)
AC_CHECK_FUNCS(times rdchk utime syslog siginterrupt)
AC_REPLACE_FUNCS(mkdir mktime strerror strstr strdup strtoul strtol strpbrk)
AC_REPLACE_FUNCS(stpcpy strftime vasprintf)

AC_REPLACE_GNU_GETOPT

dnl for lib/error.c
AC_DEFINE(HAVE_STRERROR)


dnl special tests

dnl this is taken from taylor uucp.
dnl Check for the SCO buggy ftime; the code can cope with the bug,
dnl though it would prefer not to, so if we're cross-configuring we
dnl accept that ftime exists.
AC_CHECK_FUNC(ftime,
[AC_MSG_CHECKING(that ftime works correctly)
AC_CACHE_VAL(lrzsz_cv_sys_ftime_ok,
[AC_TRY_RUN([
#include <sys/types.h>
#include <sys/timeb.h>
#include <stdio.h>
main ()
{
  struct timeb s, slast;
  int c = 0;
  ftime (&slast);
  while (c < 10)
    {
      ftime (&s);
      if (s.time < slast.time
      || (s.time == slast.time && s.millitm < slast.millitm)) {
      fprintf(stderr,"s: %ld, %ld, slast: %ld, %ld\n",
      	s.time,s.millitm, slast.time,slast.millitm);
    exit (1);
	}
      if (s.time != slast.time)
    ++c;
      slast.time = s.time;
      slast.millitm = s.millitm;
    }
  exit (0);
}
],
lrzsz_cv_sys_ftime_ok=yes,
lrzsz_cv_sys_ftime_ok=no,
lrzsz_cv_sys_ftime_ok=runtime)])
case $lrzsz_cv_sys_ftime_ok in
yes) AC_DEFINE(HAVE_FTIME) AC_MSG_RESULT(yes) ;;
no)  AC_MSG_RESULT(no)
	AC_MSG_WARN(ftime seems to be buggy) ;;
runtime) AC_DEFINE(HAVE_FTIME)
	AC_MSG_RESULT(will check at run time) ;;
esac
])

dnl
AC_MSG_CHECKING([for timezone variable])
AC_CACHE_VAL(libquark_cv_var_timezone,[
AC_TRY_LINK([#include <time.h>],[return(int)(timezone/2);],
	[libquark_cv_var_timezone=yes],
	[libquark_cv_var_timezone=no])
])
if test $libquark_cv_var_timezone = yes ; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(HAVE_TIMEZONE_VAR)
else
	AC_MSG_RESULT(no)
fi
if test "x$lookup_facility" = x ; then
	:
else
	AC_MSG_CHECKING([for $lookup_facility])
	AC_CACHE_VAL(lrzsz_cv_lookup_facility,[
		AC_EGREP_CPP(ihave$lookup_facility, [
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
#include <sys/syslog.h>
#endif
#ifdef $lookup_facility
ihave$lookup_facility
#endif
		], lrzsz_cv_lookup_facility=yes, lrzsz_cv_lookup_facility=no)
	])
	if test $lrzsz_cv_lookup_facility = yes ; then
		AC_MSG_RESULT(yes)
		AC_DEFINE_UNQUOTED(ENABLE_SYSLOG,$lookup_facility)
	else
		AC_DEFINE(ENABLE_SYSLOG,LOG_USER)
		AC_MSG_RESULT(no)
	fi
fi


AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)

AM_GNU_GETTEXT

AC_DEFINE_UNQUOTED(LOCALEDIR,"$prefix/$DATADIRNAME")
AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)

AC_OUTPUT([Makefile intl/Makefile lib/Makefile testsuite/Makefile \
man/Makefile po/Makefile.in src/Makefile debian/rules Specfile systype \
src/lrzszbug],
[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile; 
chmod +x debian/rules;
test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h])
