dnl
dnl     aegis - a project change supervisor
dnl     Copyright (C) 1994-2000, 2002, 2003, 2008, 2009, 2011 Peter Miller
dnl
dnl     This program is free software; you can redistribute it and/or modify
dnl     it under the terms of the GNU General Public License as published by
dnl     the Free Software Foundation; either version 3 of the License, or
dnl     (at your option) any later version.
dnl
dnl     This program is distributed in the hope that it will be useful,
dnl     but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl     GNU General Public License for more details.
dnl
dnl     You should have received a copy of the GNU General Public License
dnl     along with this program. If not, see
dnl     <http://www.gnu.org/licenses/>.
dnl
AC_INIT(libtardy/patchlevel.h)
AC_CONFIG_HEADER(libtardy/config.h)
AC_PROG_CXX
dnl AC_PROG_CPP

AC_PROG_INSTALL
AC_PROG_YACC
AC_PROG_RANLIB
AC_AIX
AC_MINIX
AC_SYS_LARGEFILE
AC_CHECK_LIB(socket, main)

AC_CHECK_LIB(z, main)

dnl!
dnl!    If the libz.h is not present, Tardy will fail to compile.
dnl!    If the -lz is not present, Tardy will fail to link.
dnl!
if test "$ac_cv_lib_z_main" != "yes"
then
    AC_MSG_RESULT([
        You must to install the zlib compression library to compile Tardy.
        Homepage: http://zlib.net/])
    OK=no
    if apt-get --version > /dev/null 2> /dev/null
    then
        AC_MSG_RESULT([
        The following command may be used to install it:
        sudo apt-get install zlib1g-dev
])
        OK=yes
    fi
    if yum --version > /dev/null 2> /dev/null
    then
        AC_MSG_RESULT([
        The following command may be used to install it:
        sudo yum install zlib-devel
])
        OK=yes
    fi
    if test "$OK" != "yes"
    then
        AC_MSG_RESULT([
        If you are using a package based install, you will need the
        zlib-dev or zlib-devel package, or similar.
])
    fi
    exit 1
fi

AC_CHECK_LIB(explain, explain_open_or_die)

dnl!
dnl!    If the libexplain library is not present, Tardy will fail to compile.
dnl!
if test "$ac_cv_lib_explain_explain_open_or_die" != "yes"
then
    AC_MSG_RESULT([
        You must to install the libexplain error library to compile Tardy.
        Homepage: http://libexplain.sourceforge.net/])
    OK=no
    if apt-get --version > /dev/null 2> /dev/null
    then
        AC_MSG_RESULT([
        The following command may be used to install it:
        sudo apt-get install libexplain-dev
])
        OK=yes
    fi
    if yum --version > /dev/null 2> /dev/null
    then
        AC_MSG_RESULT([
        The following command may be used to install it:
        sudo yum install libexplain-devel
])
        OK=yes
    fi
    if test "$OK" != "yes"
    then
        AC_MSG_RESULT([
        If you are using a package based install, you will need the
        libexplain-dev or libexplain-devel package, or similar.
])
    fi
    exit 1
fi

dnl
dnl     Test to see if stdarg.h is available *and* works.
dnl
AC_MSG_CHECKING([for working stdarg.h])
AC_TEST_PROGRAM([
#include <stdarg.h>
char *foo = "test";
#if defined(__STDC__) && __STDC__
int test(char*,...);
#endif
int test(fmt)char*fmt;{va_list ap;char*a;int x;
va_start(ap,fmt);a=va_arg(ap,char*);x=(a!=foo);va_end(ap);return x;}
int main(argc,argv)int argc;char**argv;{
exit(test("",foo));}]
, AC_DEFINE(HAVE_STDARG_H,1,
[Define this symbol of your system has <stdarg.h> AND it works.])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
AC_MSG_RESULT(cross))dnl

AC_HAVE_HEADERS(         \
    fcntl.h              \
    limits.h             \
    memory.h             \
    stddef.h             \
    stdlib.h             \
    string.h             \
    sys/types.h          \
    sys/param.h          \
    sys/stat.h           \
    sys/sysmacros.h      \
    unistd.h             \
    zlib.h               \
    )
AC_HEADER_DIRENT
AC_RETSIGTYPE
AC_SIZE_T
AC_TIME_WITH_SYS_TIME
AC_CONST
AC_LONG_FILE_NAMES
AC_HAVE_FUNCS(           \
    getpgrp              \
    memmem               \
    snprintf             \
    strcasecmp           \
    strerror             \
    strftime             \
    strverscmp           \
    tcgetpgrp            \
    vsnprintf            \
    )

dnl
dnl     Test to see if getpgrp() or getpgrp(0) should be used to
dnl     discover the process group of the current process.
dnl
AC_MSG_CHECKING([for appropriate getpgrp argument])
AC_TEST_PROGRAM([
int main(argc, argv) int argc; char **argv; {
#ifdef HAVE_GETPGRP
if (getpgrp(32767) == getpgrp(0)) exit(2);
#endif
exit(0); }]
, AC_DEFINE(CONF_getpgrp_arg, 0,
[Set this to a suitable argument for the getpgrp function to discover
the process group of the current process.])
AC_MSG_RESULT(zero),
AC_DEFINE(CONF_getpgrp_arg, [])
AC_MSG_RESULT(empty),
AC_MSG_RESULT(cross))dnl

dnl!
dnl! Check that several symbols are declared.
dnl!
AC_CHECK_DECLS([strcasecmp, strverscmp, memmem], [], [],
    [[#include <string.h>]])

dnl
dnl     Test to find a Bourne shell which understands functions
dnl
AC_MSG_CHECKING([for a Bourne shell which understands functions])
if test "z$SH" = "z"; then
    if test -f /bin/sh5; then
        SH=/bin/sh5
    else
        SH=/bin/sh
    fi
fi
AC_SUBST(SH)
AC_DEFINE_UNQUOTED(CONF_SHELL, ["$SH"],
[Set this to be the absolute path of a Bourne shell
which understands functions.])
AC_MSG_RESULT($SH)

AH_TOP([/*
 *      tardy - tar postprocessor
 *      Copyright (C) 1994-2003, 2008, 2009, 2011 Peter Miller
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 3 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program. If not, see
 *      <http://www.gnu.org/licenses/>.
 */

#ifndef COMMON_CONFIG_H
#define COMMON_CONFIG_H
])

AH_BOTTOM([
#endif /* COMMON_CONFIG_H */
])

AC_OUTPUT(Makefile etc/howto.conf)
