dnl
dnl     fhist - file history and comparison tools
dnl     Copyright (C) 1994-2010 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(install-sh)
AC_CONFIG_HEADER(common/config.h)
AC_PROG_CC
AC_PROG_CPP

AC_EXEEXT
AC_OBJEXT
AC_PROG_INSTALL
AC_PROG_YACC
AC_PROG_RANLIB
AC_MINIX
AC_ISC_POSIX
AC_HAVE_LIBRARY(w32)    dnl DG/UX wide character support
AC_HAVE_LIBRARY(w)      dnl Solaris wide character support
AC_HAVE_LIBRARY(intl)
AC_CHECK_PROGS(SOELIM, roffpp gsoelim soelim)
AC_CHECK_PROGS(MSGFMT, gmsgfmt msgfmt, msgfmt)
AC_CHECK_PROGS(MSGCAT, gmsgcat msgcat)
AC_CHECK_PROGS(GROFF, groff roff)

dnl! need this for libexplain
AC_SYS_LARGEFILE

AC_HAVE_LIBRARY(explain)

dnl
dnl     Make sure soelim understands the -I option
dnl
if test -n "$SOELIM"; then
AC_MSG_CHECKING([that $SOELIM understands the -I option])
echo ".so version.so" > conftest.in 2>&5
$SOELIM -Ietc -Ibl/etc -Iblbl/etc conftest.in > conftest.out 2>&5
if grep 1998 conftest.out 1>&5 2>&5; then
        AC_MSG_RESULT([yes])
else
        AC_MSG_RESULT([no])
        AC_MSG_RESULT([])
        AC_MSG_RESULT([ The FHist documentation set and manual pages])
        AC_MSG_RESULT([ will be formatted and installed installed if])
        AC_MSG_RESULT([ you first install GNU Groff 1.15 or later and then])
        AC_MSG_RESULT([ re-run this ./configure script.  Remember to])
        AC_MSG_RESULT([ use \`\`rm config.cache'' before you do.])
        AC_MSG_RESULT([])
        SOELIM=
fi
rm -rf conftest*
fi

dnl
dnl     Test to see where TIOCGWINSZ is defined.
dnl
AC_MSG_CHECKING([for TIOCGWINSZ])
AC_TRY_RUN([
#include <sys/ioctl.h>
int main(argc, argv)int argc; char **argv;{
#ifdef TIOCGWINSZ
struct winsize ws; ws.ws_col = 0; exit(ws.ws_col);
#else
exit(1);
#endif
}]
, AC_DEFINE(HAVE_winsize_SYS_IOCTL_H,1,
[Define this symbol if your system as <sys/ioctl.h> AND it defines
TIOCGWINSZ and struct winsize.])
AC_MSG_RESULT([sys/ioctl.h]),
AC_MSG_RESULT([not found]),
AC_MSG_RESULT(cross))

dnl
dnl     Test to see where struct winsize is defined.
dnl
AC_MSG_CHECKING([for struct winsize])
AC_TRY_RUN([
#include <termios.h>
int main(argc, argv)int argc; char **argv;{
#ifdef TIOCGWINSZ
struct winsize ws; ws.ws_col = 0; exit(ws.ws_col);
#else
exit(1);
#endif
}]
, AC_DEFINE(HAVE_winsize_TERMIOS_H,1,
[Define this symbol if your system as <termios.h> AND it defines
TIOCGWINSZ and struct winsize.])
AC_MSG_RESULT([termios.h]),
AC_MSG_RESULT([not found]),
AC_MSG_RESULT(cross))

AC_CHECK_HEADERS(iso646.h libgettext.h libintl.h limits.h locale.h memory.h \
        stddef.h stdlib.h string.h unistd.h wchar.h wctype.h widec.h)
AC_HEADER_DIRENT
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_C_CONST
AC_LONG_FILE_NAMES
AC_CHECK_FUNCS(atexit getpgrp gettext iswctype rename setlocale \
        sighold sigprocmask strcasecmp strerror strftime strsignal tcgetpgrp \
        wcslen)

dnl
dnl     Check to see if wint_t is defined.
dnl     The ANSI C standard states that this symbol shall be defined
dnl     by <wchar.h> and <wctype.h>.  The GNU people also define it in
dnl     <stddef.h>, but this is incorrect.
dnl
AC_MSG_CHECKING([for wint_t])
AC_TRY_COMPILE([
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
],
[ wint_t x; ],
AC_DEFINE(HAVE_WINT_T,1,
[Define this symbol of your system has the wint_t type defined.
It is usually in <stddef.h> or <wctype.h>])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))dnl

dnl
dnl     Test to see if iswprint is available *and* works.
dnl
AC_MSG_CHECKING([for working iswprint])
AC_TRY_RUN([
#include <ctype.h>
#ifdef HAVE_WIDEC_H
#include <widec.h>
#endif
#ifdef HAVE_WCTYPE_H
#include <wctype.h>
#endif
int main(argc,argv)int argc;char**argv;{
exit(iswprint('a') == 0);}]
, AC_DEFINE(HAVE_ISWPRINT,1,
[Define this symbol of your system has iswprint() AND it works.
(GNU libc v2 had a bug.)])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
AC_MSG_RESULT(cross))dnl

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_TRY_RUN([
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, [],
[Set this to a suitable argument for the getpgrp function to discover
the process group of the current process.])
AC_MSG_RESULT(empty),
AC_MSG_RESULT(cross))

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)

dnl
dnl     If the gettext function exists, assume the msgfmt program does
dnl     also, and arrange for the Makefile to install the .mo files
dnl     from the .po files.
dnl
if test "$ac_cv_func_gettext" = "yes"
then
  internationalization=yes
else
  internationalization=no
  AC_MSG_RESULT([])
  AC_MSG_RESULT([       FHist will emit much more useful error messages])
  AC_MSG_RESULT([       if you install GNU \`\`gettext'' and then])
  AC_MSG_RESULT([       re-run this ./configure script.  Remember to])
  AC_MSG_RESULT([       use \`\`rm config.cache'' before you do.])
  AC_MSG_RESULT([])
fi
AC_SUBST(internationalization)

dnl
dnl     Arrange for the existence of groff to affect the Makefile
dnl
if test -n "$GROFF"
then
        if test -n "$SOELIM"; then
                have_groff=yes
        else
                have_groff=no
        fi
else
        have_groff=no
        AC_MSG_RESULT([])
        AC_MSG_RESULT([ The FHist documentation set and manual pages])
        AC_MSG_RESULT([ will be formatted and installed installed if])
        AC_MSG_RESULT([ you first install GNU Groff and then])
        AC_MSG_RESULT([ re-run this ./configure script.  Remember to])
        AC_MSG_RESULT([ use \`\`rm config.cache'' before you do.])
        AC_MSG_RESULT([])
fi
AC_SUBST(have_groff)

# program prefix is the bit to add to the start of the name
if test ${PROGRAM_PREFIX-NONE} != NONE -a ${program_prefix-NONE} != NONE; then
PROGRAM_PREFIX=${program_prefix}
fi
AC_SUBST(PROGRAM_PREFIX)

# program suffix is the bit to add to the end of the name (before .exe)
if test ${PROGRAM_SUFFIX-NONE} != NONE -a ${program_suffix-NONE} != NONE; then
PROGRAM_SUFFIX=${program_suffix}
fi
AC_SUBST(PROGRAM_SUFFIX)

dnl
dnl Evaluate some of the variables, to remove ${prefix} references.
dnl This way, they can be used in C programs and Roff input.
dnl Make sure that fhist is mentioned in the libdir and datadir paths;
dnl add it if it is not already there.
dnl
test "x$prefix" = xNONE && prefix="${ac_default_prefix-/usr/local}"
test "x$exec_prefix" = xNONE && exec_prefix="$prefix"
eval "exec_prefix=$exec_prefix"
eval "bindir=$bindir"
eval "mandir=$mandir"
eval "libdir=$libdir"
eval "datadir=$datadir"
eval "sharedstatedir=$sharedstatedir"
case "$datadir" in
*/fhist/* | */fhist )
        ;;
*)
        datadir="${datadir}/fhist"
        ;;
esac
case "$libdir" in
*/fhist/* | */fhist )
        ;;
*)
        libdir="${libdir}/fhist"
        ;;
esac
case "$sharedstatedir" in
*/fhist/* | */fhist )
        ;;
*)
        sharedstatedir="${sharedstatedir}/fhist"
        ;;
esac

dnl
dnl support for NLSDIR option
dnl
AC_ARG_WITH(nlsdir,
        [  --with-nlsdir=PATH   specify where the locale stuff should go ])

if test "x$NLSDIR" = "x"; then
        if test "x$with_nlsdir" != "x"; then
                NLSDIR=$with_nlsdir
        else
                NLSDIR=${libdir}
        fi
fi
AC_SUBST(NLSDIR)


AH_TOP([#ifndef COMMON_CONFIG_H
#define COMMON_CONFIG_H])

AH_BOTTOM([#include <common/config.messy.h>
#endif /* COMMON_CONFIG_H */])

AC_OUTPUT(Makefile etc/libdir-h)
