dnl
dnl $Id: configure.in,v 1.7 1997/09/17 00:45:35 mhw Exp $
dnl
dnl This file in input to autoconf.  It consists of a series of m4
dnl macros which expand to produce the shell script "configure".
dnl Anything which is not an m4 macro is copied directly to the output.
dnl
dnl Start things up.  If the specified file doesn't exist, configure
dnl will complain.

AC_INIT(common/pgpBase.h)

dnl The following tests need to know that we intend to produce a config.h
dnl file, even though this won't expand to any shell script code until
dnl AC_OUTPUT time.
AC_CONFIG_HEADER(unix/pgpPFLConfig.h)

dnl The following directory is where we will find the ancillary scripts,
dnl like install-sh, config.sub, and config.guess.
AC_CONFIG_AUX_DIR(unix/config)

dnl Checks for programs.
# Find a compiler to use.
# Check 1) The $CC environment varaible, 2) gcc, 3) acc, and 4) cc.
dnl This used to be just AC-CHECK-PROGS(CC, gcc acc, cc), but...
# This deals with brain-damaged Sun systems that place a bogus cc or
# acc executable in the $PATH, which just prints an error and exit.
# We deal with this by actually trying to compile a trivial test program.
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
  AC_MSG_CHECKING(For C compiler (cached))
  CC="$ac_cv_prog_CC"
  AC_MSG_RESULT($CC)
elif test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
  AC_MSG_CHECKING(For C compiler)
  AC_MSG_RESULT($CC)
else
  IFS="${IFS=	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  echo 'main(){return 0;}' > conftest.$ac_ext
  for ac_prog in gcc acc cc; do
# Extract the first word of "$ac_prog", so it can be a program name with args.
    set dummy $ac_prog; ac_word=$2
    AC_MSG_CHECKING(for $ac_word)
    for ac_dir in $PATH; do
      test -z "$ac_dir" && ac_dir=.
      if test -r "$ac_dir/$ac_word"; then
        CC="$ac_prog"
        if eval $ac_compile; then
          ac_cv_prog_CC="$ac_prog"
        fi
        break
      fi
    done
    CC="$ac_cv_prog_CC"
    if test -n "$CC"; then
      AC_MSG_RESULT($ac_dir/$CC)
      break;
    fi
    AC_MSG_RESULT(no)
  done
  if test ! -n "$CC"; then
    AC_MSG_ERROR(no C compiler found)
  fi
  IFS="$ac_save_ifs"
  rm -f conftest*
fi
AC_SUBST(CC)

AC_CACHE_CHECK(whether we are using GNU CC, ac_cv_prog_gcc,
[dnl The semicolon is to pacify NeXT's syntax-checking cpp.
cat > conftest.c <<EOF
#ifdef __GNUC__
  yes;
#endif
EOF
if ${CC-cc} -E conftest.c 2>&AC_FD_CC | egrep yes >/dev/null 2>&1; then
  ac_cv_prog_gcc=yes
else
  ac_cv_prog_gcc=no
fi])

if test $ac_cv_prog_gcc = yes; then
  if test "${CFLAGS+set}" != set; then
AC_CACHE_CHECK(whether ${CC-cc} accepts -g, ac_cv_prog_gcc_g,
[echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
  ac_cv_prog_gcc_g=yes
else
  ac_cv_prog_gcc_g=no
fi
rm -f conftest*
])
  fi
fi

# Now, figure out what CFLAGS we want.  If the user didn't ask specifically,
# we're going to use some ideas of our own.
if test "${CFLAGS+set}" != set; then

# Prefer optimizing, with debugging a second
if test $ac_cv_prog_gcc$ac_cv_prog_gcc_g = yesyes; then
  CFLAGS="-O -g"
else
  CFLAGS=-O
fi

dnl This ugly hack is to get warnings enabled where possible.
AC_MSG_CHECKING(for useful warning options (\$WARN))
if test "${WARN+set}" != set; then
  if test $ac_cv_prog_gcc = yes; then
    WARN="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
-Wwrite-strings"
  elif $CC -flags 2>&1 | grep SunSoft >/dev/null 2>&1 ||
	$CC -flags 2>&1 | grep SunPro >/dev/null 2>&1; then
    if $CC -flags 2>&1 | grep 'checking' | grep '^-vc' > /dev/null 2>&1; then
      WARN=-vc
    elif $CC -flags 2>&1 | grep 'checking' | grep '^-v ' > /dev/null 2>&1; then
      WARN=-v
    fi
    if $CC -flags 2>&1 | grep '^-xstrconst' > /dev/null 2>&1; then
      WARN="${WARN}${WARN+ }-xstrconst"
    fi
  fi
  # Any other compiler's warning flags?
fi
AC_MSG_RESULT(${WARN-none})
AC_SUBST(WARN)

fi
# ^^ end of CFLAGS inference section

AC_REQUIRE_CPP
# Finally, figure out the command to generate dependencies.
AC_CACHE_CHECK(how to make dependencies, ac_cv_prog_DEPEND,
[if test -n "$DEPEND"; then
  ac_cv_prog_DEPEND="$DEPEND"
else
  IFS="${IFS=	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  echo '#include "confdefs.h"' > conftest.c
  for ac_prog in "$CPP -M" "$CC -xM" "$CC -M"; do
    echo $ac_prog $CPPFLAGS conftest.c 1>&AC_FD_CC;
    if $ac_prog $CPPFLAGS conftest.c 2>&AC_FD_CC \
                    | egrep "conftest\.o" >/dev/null 2>&1; then
      ac_cv_prog_DEPEND="$ac_prog $CPPFLAGS"
      break
    fi
  done
  if test ! -n "$ac_cv_prog_DEPEND"; then
    ac_cv_prog_DEPEND=:
  fi
  IFS="$ac_save_ifs"
  rm -f conftest*
fi])
DEPEND="$ac_cv_prog_DEPEND"
AC_SUBST(DEPEND)

# Find a BSD-compatibile install program, with install-sh as a fallback.
AC_PROG_INSTALL

# Find "ranlib".  Sone systems don't have or need ranlib.  If so,
# ":" (do nothing) is used instead.
AC_PROG_RANLIB

# Use symlinks (ln -s) if possible.  If not, use hard links (ln).
AC_PROG_LN_S

# Figure out how to test for symlinks...  Check 'test -L' and then 'test -h'
AC_CACHE_CHECK(how to test for symlinks, ac_cv_prog_TEST_L,
[rm -f conftest
$ac_cv_prog_LN_S foo conftest
IFS="${IFS=	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
if ( test -L conftest ); then
  ac_cv_prog_TEST_L="test -L"
elif ( test -h conftest ); then
  ac_cv_prog_TEST_L="test -h"
else
  ac_cv_prog_TEST_L="test ! -f"
fi
IFS="$ac_save_ifs"
rm -f conftest*])
TEST_L="$ac_cv_prog_TEST_L"
AC_SUBST(TEST_L)

dnl Checks for libraries.
dnl (we don't have any)

dnl Checks for library functions.
AC_CHECK_FUNCS(gethrtime clock_gettime clock_getres gettimeofday \
	getitimer setitimer ftime mktemp mkstemp)

dnl Checks for header files.
# Check that this system has a set of properly working ANSI C header files.
# In particular, check for the existence of <stdlib.h>, <stdarg.h>,
# <string.h> and <float.h>.  Also check that <string.h> declares mem*,
# that <stdlib.h> declares free, and that the <ctype.h> macros work
# with values >= 128.
AC_HEADER_STDC

# Check for which system headers are available
AC_CHECK_HEADERS(fcntl.h limits.h stdarg.h stdlib.h unistd.h paths.h \
	dirent.h sys/ioctl.h sys/time.h sys/timeb.h sys/param.h sys/stat.h \
	sys/types.h)
AC_HEADER_TIME

dnl Checks for typedefs, structures, and compiler characteristics.
# Verify that the compiler supports const, and that it works.
# A lot of compilers sort of support const, but they have bugs
# that will prevent valid programs from compiling.
AC_C_CONST

# See if we have off_t in <sys/types.h> or <stdlib.h>.
# If not, define it as "long".
AC_TYPE_OFF_T

# See if we have size_t similarly.  If not, define it as unsigned.
AC_TYPE_SIZE_T

# Check for our style of unsigned typedefs in sys/types.h
AC_EGREP_HEADER([[^a-zA-Z0-9_]uchar[^a-zA-Z0-9_]], sys/types.h,
		AC_DEFINE(HAVE_UCHAR))
AC_EGREP_HEADER([[^a-zA-Z0-9_]ushort[^a-zA-Z0-9_]], sys/types.h,
		AC_DEFINE(HAVE_USHORT))
AC_EGREP_HEADER([[^a-zA-Z0-9_]uint[^a-zA-Z0-9_]], sys/types.h,
		AC_DEFINE(HAVE_UINT))
AC_EGREP_HEADER([[^a-zA-Z0-9_]ulong[^a-zA-Z0-9_]], sys/types.h,
		AC_DEFINE(HAVE_ULONG))

# The big bang!  Produce the output files.  This is config.cache, and
# config.status, which builds the config.h file and a long list of
# Makefiles.
dnl The value specified to AC_CONFIG_HEADER at the top if the file is
dnl used here.
PGP_AC_OUTPUT(
	Makefile
	common/Makefile
	common/file/Makefile
	common/prefs/Makefile
	common/util/Makefile,
	unix/config/pre.in, unix/config/post.in)
