dnl configure.in for cvs

AC_COPYRIGHT(
[Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
              1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
              Free Software Foundation, Inc.

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 2, 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.])

AC_INIT([Concurrent Versions System (CVS)],[1.12.13],
	[bug-cvs@nongnu.org],[cvs])
AC_CONFIG_SRCDIR(src/cvs.h)
AC_CONFIG_AUX_DIR(build-aux)
AM_INIT_AUTOMAKE([gnu 1.9.2 dist-bzip2 no-define])
AC_PREREQ(2.59)
dnl AM_GNU_GETTEXT_VERSION(0.14.6)

AC_PREFIX_PROGRAM(cvs)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

gl_USE_SYSTEM_EXTENSIONS

dnl This needs to be called to enable certain system extensions before calling
dnl a C compiler.
gl_EARLY

AC_PROG_CC
AM_PROG_CC_C_O

# Find the posix library needed on INTERACTIVE UNIX (ISC)
dnl
dnl From the Autoconf 2.53 manual (AC_ISC_POSIX):
dnl
dnl  For INTERACTIVE UNIX (ISC), add `-lcposix' to output variable
dnl  `LIBS' if necessary for POSIX facilities.  Call this after
dnl  `AC_PROG_CC' and before any other macros that use POSIX
dnl  interfaces.  INTERACTIVE UNIX is no longer sold, and Sun says that
dnl  they will drop support for it on 2006-07-23, so this macro is
dnl  becoming obsolescent.
dnl
AC_SEARCH_LIBS([strerror], [cposix])

dnl
dnl Autoconf stopped setting $ISC sometime before 2.53
dnl
dnl If this is still important, someone should come up with a generic test
dnl for whether _SYSV3 needs to be defined.  Removed code below:
dnl
dnl if test "$ISC" = yes; then
dnl CFLAGS="$CFLAGS -D_SYSV3"
dnl # And I don't like this...  In theory it should be found later if server is
dnl # enabled, but maybe something on INTERACTIVE UNIX (ISC) we didn't ask to
dnl # link with crypt tries?  Anyhow, the autoconf manual says we can delete
dnl # this ISC stuff on or after 2006-07-23 when Sun discontinues support and
dnl # ISC becomes obsolescent, but I suppose that is probably a matter of
dnl # opinion.
dnl #
dnl # N.B.  The reason for doing this is that some moron decided to put a stub
dnl # for crypt in libc that always returns NULL.  Without this here, the later
dnl # check will find the stub instead of the real thing, resulting in a server
dnl # that can't process crypted passwords correctly.
dnl
dnl # again, if we have to try and reenable this for ISC, someone should come
dnl # up with a generic test that figures out whether crypt is good or not -
dnl # Is it always returning NULL?
dnl LIBS="-lcrypt $LIBS"
dnl fi
dnl
dnl FIXME - This has been broken for at least a few months anyhow, so I'm
dnl removing the crypt lib define above, but the correct fix would be to
dnl provide a CRYPT_WORKS macro or the like that gets called sometime after
dnl the AC_SEARCH_LIBS call that normally finds crypt, and if crypt doesn't
dnl work, the macro should be retried with LIBS="-lcrypt $LIBS" forced.
dnl

AC_PROG_RANLIB
AC_PROG_LN_S
AC_SYS_LARGEFILE
AC_EXEEXT

AC_PATH_PROG(PERL, perl, no)
AC_PATH_PROG(CSH, csh, no)
# for contrib/rcs2log.sh & src/cvsbug.in.
AC_PATH_PROG(MKTEMP, mktemp, mktemp)
if test x"$MKTEMP" = xmktemp; then
	MKTEMP_SH_FUNCTION=$srcdir/mktemp.sh
else
	MKTEMP_SH_FUNCTION=/dev/null
fi
AC_SUBST_FILE(MKTEMP_SH_FUNCTION)
# for src/cvsbug.in
AC_PATH_PROG(SENDMAIL, sendmail, no, [$PATH:/usr/sbin:/usr/lib])
# For diff/util.c
AC_PATH_PROG(PR, pr, no)
if test x"$PR" != xno; then
	AC_DEFINE_UNQUOTED([PR_PROGRAM], ["$PR"], [Path to the pr utility])
fi

dnl FIXME This is truly gross.
missing_dir=`cd $ac_aux_dir && pwd`
dnl FIXME I pulled this default list from sanity.sh.  Perhaps these lists
dnl can be stored in one location?
dnl
dnl Yeah, put the value in a variable add it to the substitution list
dnl then have configure create sanity.sh from sanity.sh.in...
glocs="$PATH:/usr/local/bin:/usr/contrib/bin:/usr/gnu/bin:/local/bin:/local/gnu/bin:/gnu/bin"
AC_PATH_PROGS(ROFF, groff roff, $missing_dir/missing roff, $glocs)
AC_PATH_PROG(PS2PDF, ps2pdf, $missing_dir/missing ps2pdf)
AC_PATH_PROG(TEXI2DVI, texi2dvi, $missing_dir/missing texi2dvi)

AC_SYS_INTERPRETER
if test X"$ac_cv_sys_interpreter" != X"yes" ; then
  # silly trick to avoid problems in AC macros...
  ac_msg='perl scripts using #! may not be invoked properly'
  AC_MSG_WARN($ac_msg)
fi

# BSD's logo is a devil for a reason, hey?
AC_CACHE_CHECK(for BSD VPATH bug in make, ccvs_cv_bsd_make_vpath_bug,
[if test ! -d ac_test_dir ; then
	AC_TRY_COMMAND([mkdir ac_test_dir])
fi
cat >conftestmake <<EOF
VPATH = ac_test_dir
ac_test_target: ac_test_dep
	echo BSD VPATH bug present >&2
ac_test_dep: ac_test_dep_dep
EOF
touch ac_test_dir/ac_test_dep_dep
touch ac_test_dir/ac_test_dep
touch ac_test_target
# Don't know why, but the following test doesn't work under FreeBSD 4.2
# without this sleep command
sleep 1
if AC_TRY_COMMAND([make -f conftestmake 2>&1 >/dev/null |grep ^BSD\ VPATH\ bug\ present\$ >/dev/null]) ; then
	ccvs_cv_bsd_make_vpath_bug=yes
else
	ccvs_cv_bsd_make_vpath_bug=no
fi
AC_TRY_COMMAND([rm -rf ac_test_dir ac_test_target conftestmake])])
# We also don't need to worry about the bug when $srcdir = $builddir
AM_CONDITIONAL(MAKE_TARGETS_IN_VPATH, \
		test $ccvs_cv_bsd_make_vpath_bug = no \
		|| test $srcdir = .)

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(\
	direct.h \
	fcntl.h \
	io.h \
	memory.h \
	ndbm.h \
	stdint.h \
	syslog.h \
	sys/bsdtypes.h \
	sys/file.h \
	sys/param.h \
	sys/resource.h \
	sys/select.h \
	unistd.h \
	utime.h \
	zlib.h \
)
AC_HEADER_STAT

AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIGNAL

AC_CHECK_MEMBERS([struct stat.st_blksize])
AC_CHECK_MEMBERS([struct stat.st_rdev])

AC_FUNC_FSEEKO
if test $ac_cv_func_fseeko = no; then
    AC_LIBOBJ(fseeko)
    AC_LIBOBJ(ftello)
fi

# Replace functions with versions in lib/ when they can't be found.
AC_REPLACE_FUNCS(\
	waitpid \
)

AC_CACHE_CHECK([for getopt optreset variable], db_cv_optreset, [
AC_TRY_LINK([#include <unistd.h>], extern int optreset; optreset = 1;,
    [db_cv_optreset=yes], [db_cv_optreset=no])])
if test "$db_cv_optreset" = "yes"; then
	AC_DEFINE(HAVE_GETOPT_OPTRESET)
	AH_TEMPLATE(HAVE_GETOPT_OPTRESET,
	    [Define to 1 if getopt supports the optreset variable.])
fi

#
# Special hack for a SunOS 5.7 (aka Solaris 7) select() problem.
#
ccvs_FUNC_SELECT

#
# Begin GNULIB stuff.
#

# Look for functions from GNULIB and replace with versions in lib/ when
# necessary.
dnl This calls most of the GNULIB macros we need via the
dnl autogenerated m4/gnulib.m4.
gl_INIT
dnl For one reason or another, the autogenerated m4/gnulib.m4 wants
dnl AM_GNU_GETTEXT([external]) called directly from here.
dnl AM_GNU_GETTEXT([external])
dnl AM_GNU_GETTEXT_VERSION dnl work around for autoconf-2.57 bug.
# The error module still poses merge problems.
AC_FUNC_STRERROR_R
dnl The following macros can be called by other GNULIB macros but are also
dnl used by the UNIQUE_*_TYPE stuff below.  I don't want to rely on the GNULIB
dnl macros which call these to continue to do so, so use AC_REQUIRE, which can
dnl only be called from within another macro, to only call them only once.
AC_DEFUN([CCVS_CALL_GNULIB_MACROS_ONCE],
[AC_REQUIRE([gt_TYPE_LONGDOUBLE])
AC_REQUIRE([gt_TYPE_WCHAR_T])
AC_REQUIRE([gt_TYPE_WINT_T])
AC_REQUIRE([gl_AC_TYPE_INTMAX_T])
AC_REQUIRE([gl_FUNC_MMAP_ANON])
AC_REQUIRE([gl_AC_TYPE_LONG_LONG])])
CCVS_CALL_GNULIB_MACROS_ONCE()
dnl Until I persuade the GNULIB folks to integrate this module.
gl_GLOB

#
# End GNULIB stuff.
#



# Check for function existance.
AC_CHECK_FUNCS(\
	fchdir \
	fchmod \
	fsync \
	ftime \
	geteuid \
	getgroups \
	getpagesize \
	gettimeofday \
	initgroups \
	login \
	logout \
	mknod \
	regcomp \
	regerror \
	regexec \
	regfree \
	sigaction \
	sigblock \
	sigprocmask \
	sigsetmask \
	sigvec \
	timezone \
	tzset \
	vprintf \
	wait3 \
)

dnl
dnl Find the sizes of various types and set a variable for some if they
dnl are "unique", meaning it does not share a size with a lower precedence
dnl type.
dnl
dnl also, I snagged this cross_compiling line from openldap's autoconf,
dnl because I can't figure out how to stop autoconf from giving cross compiler
dnl related warnings each time the AC_CHECK_SIZEOF function is run
dnl
if test $cross_compiling = yes ; then
	AC_DEFINE(CROSS_COMPILING, 1, [define if cross compiling])
else
	AC_CHECK_SIZEOF(char)
	AC_CACHE_CHECK(for uniquely sized char,
		ccvs_cv_unique_int_type_char,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_char)" >/dev/null ; then
			ccvs_cv_unique_int_type_char=no
		else
			ccvs_cv_unique_int_type_char=yes\($ac_cv_sizeof_char\)
		fi])
	if test $ccvs_cv_unique_int_type_char != no ; then
		AC_DEFINE( UNIQUE_INT_TYPE_CHAR, 1,
                           [Define if char is the first integer type
		            detected with its size.])
	fi
	AC_CHECK_SIZEOF(short)
	AC_CACHE_CHECK(for uniquely sized short,
		ccvs_cv_unique_int_type_short,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_short)" >/dev/null ; then
			ccvs_cv_unique_int_type_short=no
		else
			ccvs_cv_unique_int_type_short=yes\($ac_cv_sizeof_short\)
		fi])
	if test $ccvs_cv_unique_int_type_short != no ; then
		AC_DEFINE( UNIQUE_INT_TYPE_SHORT, 1,
                           [Define if short is the first integer type
		            detected with its size.])
	fi
	AC_CHECK_SIZEOF(int)
	AC_CACHE_CHECK(for uniquely sized int,
		ccvs_cv_unique_int_type_int,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_int)" >/dev/null ; then
			ccvs_cv_unique_int_type_int=no
		else
			ccvs_cv_unique_int_type_int=yes\($ac_cv_sizeof_int\)
		fi])
	if test $ccvs_cv_unique_int_type_int != no ; then
		AC_DEFINE( UNIQUE_INT_TYPE_INT, 1,
                           [Define if int is the first integer type
		            detected with its size.])
	fi
	AC_CHECK_SIZEOF(long)
	AC_CACHE_CHECK(for uniquely sized long,
		ccvs_cv_unique_int_type_long,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_long)" >/dev/null ; then
			ccvs_cv_unique_int_type_long=no
		else
			ccvs_cv_unique_int_type_long=yes\($ac_cv_sizeof_long\)
		fi])
	if test $ccvs_cv_unique_int_type_long != no ; then
		AC_DEFINE(UNIQUE_INT_TYPE_LONG, 1,
                          [Define if long int is the first integer type
		           detected with its size.])
	fi
	if test $ac_cv_type_long_long != no; then
		AC_CHECK_SIZEOF(long long)
		AC_CACHE_CHECK(for uniquely sized long long,
			ccvs_cv_unique_int_type_long_long,
			[if set |grep ^ccvs_cv_unique_int_type_ \
				|grep "($ac_cv_sizeof_long_long)" >/dev/null ; then
				ccvs_cv_unique_int_type_long_long=no
			else
				ccvs_cv_unique_int_type_long_long=yes\($ac_cv_sizeof_long_long\)
			fi])
		if test $ccvs_cv_unique_int_type_long_long != no ; then
			AC_DEFINE(UNIQUE_INT_TYPE_LONG_LONG, 1,
				  [Define if long long is the first integer type
				   detected with its size.])
		fi
	fi
	AC_CHECK_SIZEOF(size_t)
	AC_CACHE_CHECK(for uniquely sized size_t,
		ccvs_cv_unique_int_type_size_t,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_size_t)" >/dev/null ; then
			ccvs_cv_unique_int_type_size_t=no
		else
			ccvs_cv_unique_int_type_size_t=yes\($ac_cv_sizeof_size_t\)
		fi])
	if test $ccvs_cv_unique_int_type_size_t != no ; then
		AC_DEFINE(UNIQUE_INT_TYPE_SIZE_T, 1,
                          [Define if size_t is the first integer type
		           detected with its size.])
	fi
	AC_CHECK_SIZEOF(ptrdiff_t)
	AC_CACHE_CHECK(for uniquely sized ptrdiff_t,
		ccvs_cv_unique_int_type_ptrdiff_t,
		[if set |grep ^ccvs_cv_unique_int_type_ \
			|grep "($ac_cv_sizeof_ptrdiff_t)" >/dev/null ; then
			ccvs_cv_unique_int_type_ptrdiff_t=no
		else
			ccvs_cv_unique_int_type_ptrdiff_t=yes\($ac_cv_sizeof_ptrdiff_t\)
		fi])
	if test $ccvs_cv_unique_int_type_ptrdiff_t != no ; then
		AC_DEFINE(UNIQUE_INT_TYPE_PTRDIFF_T, 1,
                          [Define if ptrdiff_t is the first integer type
		           detected with its size.])
	fi
	if test $gt_cv_c_wint_t != no; then
		AC_CHECK_SIZEOF(wint_t, [], [[#include <stdio.h>
#include <wchar.h>
]])
		AC_CACHE_CHECK(for uniquely sized wint_t,
			ccvs_cv_unique_int_type_wint_t,
			[if set |grep ^ccvs_cv_unique_int_type_ \
				|grep "($ac_cv_sizeof_wint_t)" >/dev/null ; then
				ccvs_cv_unique_int_type_wint_t=no
			else
				ccvs_cv_unique_int_type_wint_t=yes\($ac_cv_sizeof_wint_t\)
			fi])
		if test $ccvs_cv_unique_int_type_wint_t != no ; then
			AC_DEFINE( UNIQUE_INT_TYPE_WINT_T, 1,
				   [Define if wint_t is the first integer type
				    detected with its size.])
		fi
	fi
	if test $gt_cv_c_intmax_t != no; then
		AC_CHECK_SIZEOF(intmax_t, [], [[#include <stdio.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#endif
]])
		AC_CACHE_CHECK(for uniquely sized intmax_t,
			ccvs_cv_unique_int_type_intmax_t,
			[if set |grep ^ccvs_cv_unique_int_type_ \
				|grep "($ac_cv_sizeof_intmax_t)" >/dev/null ; then
				ccvs_cv_unique_int_type_intmax_t=no
			else
				ccvs_cv_unique_int_type_intmax_t=yes\($ac_cv_sizeof_intmax_t\)
			fi])
		if test $ccvs_cv_unique_int_type_intmax_t != no ; then
			AC_DEFINE( UNIQUE_INT_TYPE_INTMAX_T, 1,
                        	   [Define if intmax_t is the first integer type
			            detected with its size.])
		fi
	fi

	dnl
	dnl and the same for floats...
	dnl
	AC_CHECK_SIZEOF(float)
	AC_CACHE_CHECK(for uniquely sized float,
		ccvs_cv_unique_float_type_float,
		[if set |grep ^ccvs_cv_unique_float_type_ \
			|grep "($ac_cv_sizeof_float)" >/dev/null ; then
			ccvs_cv_unique_float_type_float=no
		else
			ccvs_cv_unique_float_type_float=yes\($ac_cv_sizeof_float\)
		fi])
	if test $ccvs_cv_unique_float_type_float != no ; then
		AC_DEFINE( UNIQUE_FLOAT_TYPE_FLOAT, 1,
                           [Define if float is the first floating point type
		            detected with its size.])
	fi
	AC_CHECK_SIZEOF(double)
	AC_CACHE_CHECK(for uniquely sized double,
		ccvs_cv_unique_float_type_double,
		[if set |grep ^ccvs_cv_unique_float_type_ \
			|grep "($ac_cv_sizeof_double)" >/dev/null ; then
			ccvs_cv_unique_float_type_double=no
		else
			ccvs_cv_unique_float_type_double=yes\($ac_cv_sizeof_double\)
		fi])
	if test $ccvs_cv_unique_float_type_double != no ; then
		AC_DEFINE( UNIQUE_FLOAT_TYPE_DOUBLE, 1,
                           [Define if double is the first floating point type
		            detected with its size.])
	fi
	if test $gt_cv_c_long_double != no; then
		AC_CHECK_SIZEOF(long double)
		AC_CACHE_CHECK(for uniquely sized long double,
			ccvs_cv_unique_float_type_long_double,
			[if set |grep ^ccvs_cv_unique_float_type_ \
				|grep "($ac_cv_sizeof_long_double)" >/dev/null ; then
				ccvs_cv_unique_float_type_long_double=no
			else
				ccvs_cv_unique_float_type_long_double=yes\($ac_cv_sizeof_long_double\)
			fi])
		if test $ccvs_cv_unique_float_type_long_double != no ; then
			AC_DEFINE(UNIQUE_FLOAT_TYPE_LONG_DOUBLE, 1,
				  [Define if long double is the first floating point
				   type detected with its size.])
		fi
	fi
fi

dnl
dnl The CVS coding standard (as specified in HACKING) is that if it exists
dnl in SunOS4 and ANSI, we use it.  CVS itself, of course, therefore doesn't
dnl need HAVE_* defines for such functions, but diff wants them.
dnl
AC_DEFINE(HAVE_STRCHR, 1,
[Define if you have strchr (always for CVS).])
AC_DEFINE(HAVE_MEMCHR, 1,
[Define if you have memchr (always for CVS).])

dnl
dnl Force lib/regex.c to use malloc instead of messing around with alloca
dnl and define the old re_comp routines that we use.
dnl
AC_DEFINE(REGEX_MALLOC, 1,
[Define to force lib/regex.c to use malloc instead of alloca.])
AC_DEFINE(_REGEX_RE_COMP, 1,
[Define to force lib/regex.c to define re_comp et al.])
dnl
dnl AC_FUNC_FORK([]) is rather baroque.  It seems to be rather more picky
dnl than, say, the Single Unix Specification (version 2), which simplifies
dnl a lot of cases by saying that the child process can't set any variables
dnl (thus avoiding problems with register allocation) or call any functions
dnl (thus avoiding problems with whether file descriptors are shared).
dnl It would be nice if we could just write to the Single Unix Specification.
dnl I think the only way to do redirection this way is by doing it in the
dnl parent, and then undoing it afterwards (analogous to windows-NT/run.c).
dnl That would appear to have a race condition if the user hits ^C (or
dnl some other signal) at the wrong time, as main_cleanup will try to use
dnl stdout/stderr.  So maybe we are stuck with AC_FUNC_FORK([]).
dnl
AC_FUNC_FORK([])
AC_FUNC_CLOSEDIR_VOID

dnl
dnl Check for shadow password support.
dnl
dnl We used to try to determine whether shadow passwords were actually in
dnl use or not, but the code has been changed to work right reguardless,
dnl so we can go back to a simple check.
AC_SEARCH_LIBS(getspnam, sec gen, AC_DEFINE(HAVE_GETSPNAM, 1,
[Define if you have the getspnam function.]))

AC_FUNC_UTIME_NULL
AC_SYS_LONG_FILE_NAMES

dnl for debugging code
CVS_FUNC_PRINTF_PTR

# Try to find connect and gethostbyname.
AC_CHECK_LIB(nsl, main)
AC_SEARCH_LIBS(connect, xnet socket inet,
  AC_DEFINE(HAVE_CONNECT, 1,
[Define if you have the connect function.]))
dnl no need to search nsl for gethostbyname here since we should have
dnl just added libnsl above if we found it.
AC_SEARCH_LIBS(gethostbyname, netinet)

AC_SUBST(cvs_client_objects)


dnl
dnl begin --with-*
dnl

dnl
dnl set $(KRB4) from --with-krb4=value -- WITH_KRB4
dnl
dnl If you change this, keep in mind that some systems have a bogus
dnl libkrb in the system libraries, so --with-krb4=value needs to
dnl override the system -lkrb.
dnl
KRB4=/usr/kerberos
define(WITH_KRB4,[
AC_ARG_WITH(
  [krb4],
  AC_HELP_STRING(
    [--with-krb4],
    [Kerberos 4 directory (default /usr/kerberos)]),
  [KRB4=$with_krb4],
)dnl
AC_MSG_CHECKING([for KRB4 in $KRB4])
AC_MSG_RESULT([])
AC_SUBST(KRB4)])dnl
WITH_KRB4

krb_h=
AC_MSG_CHECKING([for krb.h])
if test "$cross_compiling" != yes && test -r $KRB4/include/krb.h; then
   hold_cflags=$CFLAGS
   CFLAGS="$CFLAGS -I$KRB4/include"
   AC_TRY_LINK([#include <krb.h>],[int i;],
          [krb_h=yes krb_incdir=$KRB4/include],
          [CFLAGS=$hold_cflags
           AC_TRY_LINK([#include <krb.h>],[int i;],
             [krb_h=yes krb_incdir=])])
   CFLAGS=$hold_cflags
else
   AC_TRY_LINK([#include <krb.h>],[int i;],
             [krb_h=yes krb_incdir=])
fi
if test -z "$krb_h"; then
  AC_TRY_LINK([#include <krb.h>],[int i;],
    [krb_h=yes krb_incdir=],
    [if test "$cross_compiling" != yes && test -r $KRB4/include/kerberosIV/krb.h; then
       hold_cflags=$CFLAGS
       CFLAGS="$CFLAGS -I$KRB4/include/kerberosIV"
       AC_TRY_LINK([#include <krb.h>],[int i;],
	 [krb_h=yes krb_incdir=$KRB4/include/kerberosIV])
       CFLAGS=$hold_cflags
     fi])
fi
AC_MSG_RESULT($krb_h)

if test -n "$krb_h"; then
  krb_lib=
  if test "$cross_compiling" != yes && test -r $KRB4/lib/libkrb.a; then
       hold_ldflags=$LDFLAGS
       LDFLAGS="-L${KRB4}/lib $LDFLAGS"
       AC_CHECK_LIB(krb,printf,[krb_lib=yes krb_libdir=${KRB4}/lib],
           [LDFLAGS=$hold_ldflags
            # Using open here instead of printf so we don't
            # get confused by the cached value for printf from above.
            AC_CHECK_LIB(krb,open,[krb_lib=yes krb_libdir=])])
       LDFLAGS=$hold_ldflags
  else
       AC_CHECK_LIB(krb,printf,[krb_lib=yes krb_libdir=])
       AC_CHECK_FUNC(krb_recvauth,[krb_lib=yes krb_libdir=])
  fi
  if test -n "$krb_lib"; then
    AC_DEFINE([HAVE_KERBEROS], 1,
	      [Define if you have MIT Kerberos version 4 available.])
    cvs_client_objects="$cvs_client_objects kerberos4-client.o"
    test -n "${krb_libdir}" && LIBS="${LIBS} -L${krb_libdir}"
    # Put -L${krb_libdir} in LDFLAGS temporarily so that it appears before
    # -ldes in the command line.  Don't do it permanently so that we honor
    # the user's setting for LDFLAGS
    hold_ldflags=$LDFLAGS
    test -n "${krb_libdir}" && LDFLAGS="$LDFLAGS -L${krb_libdir}"
    AC_CHECK_LIB(des,printf,[LIBS="${LIBS} -ldes"])
    AC_CHECK_LIB(krb,krb_recvauth)
    AC_CHECK_LIB(krb4,krb_recvauth)
    LDFLAGS=$hold_ldflags
    if test -n "$krb_incdir"; then
      CPPFLAGS="$CPPFLAGS -I$krb_incdir"
    fi
  fi
fi
AC_CHECK_FUNCS(krb_get_err_text)


dnl
dnl WITH_GSSAPI is external
dnl
dnl TODO - I tried to put these in alphabetical order, but ACX_WITH_GSSAPI
dnl fails unless called after the KRB4 stuff.  I don't know why.
dnl
ACX_WITH_GSSAPI

dnl
dnl WITH_EXTERNAL_ZLIB is external
dnl
dnl ACX_WITH_EXTERNAL_ZLIB

dnl
dnl begin --with-rsh
dnl
dnl Many sites no longer desire the use of "rsh" as the default
dnl remote shell program. They typically favor "ssh" as the default

# What remote shell transport should our client cvs default to using?
AC_ARG_WITH(
  [rsh],
  AC_HELP_STRING(
    [--with-rsh],
    [The default remote shell CVS will use for :ext: transport
     (default ssh)]), ,
  [with_rsh="ssh rsh"])

if test no = "$with_rsh"; then
  AC_MSG_WARN([Failed to find usable remote shell. Using 'rsh'.])
  with_rsh=rsh
elif test yes = "$with_rsh"; then
  # Make --with-rsh mean the same thing as --with-rsh=rsh
  with_rsh=rsh
fi

if echo $with_rsh |grep ^/ >/dev/null; then
  # If $with_rsh is an absolute path, issue a warning if the executable
  # doesn't exist or isn't usable, but then trust the user and use it
  # regardless
  with_default_rsh=$with_rsh
  AC_MSG_CHECKING([for a remote shell])
  if ! test -f $with_rsh \
      || ! test -x $with_rsh; then
    # warn the user that they may encounter problems
    AC_MSG_WARN([$with_rsh is not a path to an executable file])
  fi
else
  # Search for a remote shell
  AC_CHECK_PROGS([with_default_rsh], [$with_rsh], "rsh")
fi

AC_DEFINE_UNQUOTED(
  [RSH_DFLT], ["$with_default_rsh"],
  [The default remote shell to use, if one does not specify the
   CVS_RSH environment variable.])
RSH_DFLT=$with_default_rsh
AC_SUBST(RSH_DFLT)
dnl done with finding a default CVS_RSH value
dnl
dnl end --with-rsh
dnl

dnl
dnl begin --with-editor
dnl
dnl Set the default editor to use for log messages
dnl

AC_ARG_VAR(
  [EDITOR],
  [The text editor CVS will use by default for log messages.])

# Let the confiscator request a specific editor
AC_ARG_WITH(
  [editor],
  AC_HELP_STRING(
    [--with-editor],
    [The default text editor CVS should use for log messages
     (default autoselects)]), ,
  [with_editor=yes])

# If --with-editor was supplied with an argument, let it override $EDITOR from
# the user's environment.  We need to unset EDITOR here because AC_CHECK_PROGS
# will let the value of EDITOR ride when it is set rather than searching.  We
# ignore the --without-editor case since it will be caught below.
if test -n "$EDITOR" && test yes != $with_editor; then
  AS_UNSET([EDITOR])
fi

# Set the default when --with-editor wasn't supplied or when it was supplied
# without an argument.
if test yes = $with_editor; then
  with_editor="vim vi emacs nano pico edit"
fi

if echo $with_editor |grep ^/ >/dev/null; then
  # If $with_editor is an absolute path, issue a warning if the executable
  # doesn't exist or isn't usable, but then trust the user and use it
  # regardless
  EDITOR=$with_editor
  AC_MSG_CHECKING([for an editor])
  AC_MSG_RESULT([$EDITOR])
  if ! test -f $with_editor \
      || ! test -x $with_editor; then
    # warn the user that they may encounter problems
    AC_MSG_WARN([\`$with_editor' is not a path to an executable file])
  fi
elif test no != "${with_editor}"; then
  # Search for an editor
  AC_CHECK_PROGS([EDITOR], [$with_editor], [no])
    if test no = "${EDITOR}"; then
      AC_MSG_ERROR([
    Failed to find a text file editor.  CVS cannot be compiled
    without a default log message editor.  Searched for
    \`$with_editor'.  Try \`configure --with-editor'.])
    fi
else
  AC_MSG_ERROR([
    CVS cannot be compiled without a default log message editor.
    Try \`configure --with-editor'.])
fi

dnl FIXME - Using --without-editor will probably break a compile at
dnl the moment, but maybe it is reasonable for someone to want to
dnl compile a CVS executable that refuses to run if no $EDITOR,
dnl $CVS_EDITOR, or -e option is specified?  Making a preliminary
dnl design decision in this direction, subject to discussion.
dnl
dnl Still don't know if the above would be useful, but we shouldn't
dnl be able to get here any longer without $EDITOR defined due to the
dnl error checking above.
AC_DEFINE_UNQUOTED(
  [EDITOR_DFLT], ["$EDITOR"],
  [The default editor to use, if one does not specify the "-e" option
   to cvs, or does not have an EDITOR environment variable.  If this
   is not set to an absolute path to an executable, use the shell to
   find where the editor actually is.  This allows sites with
   /usr/bin/vi or /usr/ucb/vi to work equally well (assuming that their
   PATH is reasonable).])

dnl
dnl done finding an editor
dnl
dnl end --with-editor
dnl



dnl
dnl --with-hardcoded-pam-service-name
dnl
AC_ARG_WITH(
  [hardcoded-pam-service-name],
  AC_HELP_STRING(
    [--with-hardcoded-pam-service-name],
    [Use this to hard code a service name for PAM CVS authentication.  The
     special name, `program_name', will cause CVS to use whatever name it
     was invoked as as the service name.  (defaults to `cvs')]),,
    [with_hardcoded_pam_service_name=cvs])

if test "x$with_hardcoded_pam_service_name" = xno ||
   test "x$with_hardcoded_pam_service_name" = xprogram_name; then
  AC_DEFINE([PAM_SERVICE_NAME], [program_name],
    [Define to set a service name for PAM.  This must be defined.  Define to
     `program_name', without the quotes, to use whatever name CVS was invoked
      as.  Otherwise, define to a double-quoted literal string, such as
      `"cvs"'.])
else
  if test x"$with_hardcoded_pam_service_name" = xyes; then
    with_hardcoded_pam_service_name=cvs
  fi
  AC_DEFINE_UNQUOTED([PAM_SERVICE_NAME], ["$with_hardcoded_pam_service_name"])
fi



dnl
dnl Find a temporary directory
dnl
AC_ARG_WITH(
  [tmpdir],
  AC_HELP_STRING(
    [--with-tmpdir],
    [The temporary directory CVS should use as a default
     (default autoselects)]))

AC_MSG_CHECKING([for temporary directory])
if test -z "$with_tmpdir" || test yes = "$with_tmpdir"; then
  for with_tmpdir in /tmp /var/tmp no; do
    if test -d "$with_tmpdir" && test -x "$with_tmpdir" \
        && test -w "$with_tmpdir" && test -r "$with_tmpdir"; then
      break
    fi
  done
  if test no = "$with_tmpdir"; then
    AC_MSG_WARN([Failed to find usable temporary directory.  Using '/tmp'.])
    with_tmpdir=/tmp
  fi
  AC_MSG_RESULT([$with_tmpdir])
elif ! echo "$with_tmpdir" |grep '^[[\\/]]'; then
  AC_MSG_RESULT([$with_tmpdir])
  AC_MSG_ERROR([--with-tmpdir requires an absolute path.])
elif ! test -d "$with_tmpdir" || ! test -x "$with_tmpdir" \
        || ! test -w "$with_tmpdir" || ! test -r "$with_tmpdir"; then
  AC_MSG_RESULT([$with_tmpdir])
  AC_MSG_WARN(
    [User supplied temporary directory ('$with_tmpdir') does not
     exist or lacks sufficient permissions for read/write.])
fi

AC_DEFINE_UNQUOTED(
  [TMPDIR_DFLT], ["$with_tmpdir"],
  [Directory used for storing temporary files, if not overridden by
   environment variables or the -T global option.  There should be little
   need to change this (-T is a better mechanism if you need to use a
   different directory for temporary files).])

dnl
dnl done finding tmpdir
dnl


dnl
dnl Get default umask
dnl

AC_ARG_WITH(
  [umask],
  AC_HELP_STRING(
    [--with-umask],
    [Set the umask CVS will use by default in the repository (default 002)]))

if test -z "$with_umask" || test yes = "$with_umask"; then
  with_umask=002
elif test no = "$with_umask"; then
  with_umask=000
fi

AC_DEFINE_UNQUOTED(
  [UMASK_DFLT], [$with_umask],
  [The default umask to use when creating or otherwise setting file or
   directory permissions in the repository.  Must be a value in the
   range of 0 through 0777.  For example, a value of 002 allows group
   rwx access and world rx access; a value of 007 allows group rwx
   access but no world access.  This value is overridden by the value
   of the CVSUMASK environment variable, which is interpreted as an
   octal number.])

dnl
dnl Done setting default umask
dnl

dnl
dnl Set CVS Administrator Group
dnl
AC_ARG_WITH(
  [cvs-admin-group],
  AC_HELP_STRING(
    [--with-cvs-admin-group=GROUP],
    [The CVS admin command is restricted to the members of this group.
     If this group does not exist, all users are allowed to run CVS admin.
     To disable the CVS admin command for all users, create an empty group
     by specifying the --with-cvs-admin-group= option.  To disable access
     control for CVS admin, run configure with the --without-cvs-admin-group
     option. (default 'cvsadmin')]), ,
  [with_cvs_admin_group=cvsadmin])

if test yes = "$with_cvs_admin_group"; then
  with_cvs_admin_group=cvsadmin
fi
if test no != "$with_cvs_admin_group"; then
  dnl FIXME We should warn if the group doesn't exist
  AC_DEFINE_UNQUOTED(
    [CVS_ADMIN_GROUP], ["$with_cvs_admin_group"],
    [The CVS admin command is restricted to the members of the group
     CVS_ADMIN_GROUP.  If this group does not exist, all users are
     allowed to run CVS admin.  To disable the CVS admin command for
     all users, create an empty CVS_ADMIN_GROUP by running configure
     with the --with-cvs-admin-group= option.  To disable access control
     for CVS admin, run configure with the --without-cvs-admin-group
     option in order to comment out the define below.])
fi

dnl
dnl Done setting CVS Administrator Group
dnl

dnl
dnl Set the NDBM library to use.
dnl
dnl XXX - FIXME - FIXME - FIXME - XXX
dnl
dnl This is very bad.  It should really autodetect an appropriate NDBM library
dnl and, if it doesn't find one, decide to use MY_NDBM.  I'm am defining
dnl this here since this is no worse than it worked when it was in options.h
dnl and I am cleaning out options.h so that the Windows version of CVS will
dnl compile properly for the next release.
dnl
dnl That's why this option is in the --with-* section rather than the
dnl --enable-* section.
dnl
dnl XXX - FIXME - FIXME - FIXME - XXX
dnl
AC_ARG_ENABLE(
  [cvs-ndbm],
  AC_HELP_STRING(
    [--enable-cvs-ndbm],
    [Use the NDBM library distributed with CVS rather than attempting to use
     a system NDBM library.  Disabling this may not work.  (default)]), ,
  [enable_cvs_ndbm=yes])
if test no != "$enable_cvs_ndbm"; then
  AC_DEFINE(
    [MY_NDBM], [1],
    [By default, CVS stores its modules and other such items in flat
     text files (MY_NDBM enables this).  Turning off MY_NDBM causes CVS
     to look for a system-supplied ndbm database library and use it
     instead.  That may speed things up, but the default setting
     generally works fine too.])
fi

dnl
dnl Done selecting NDBM library.
dnl



dnl
dnl end --with-*
dnl


dnl
dnl begin --enables
dnl


dnl
dnl begin --enable-client
dnl

# Check for options requesting client and server feature. If none are
# given and we have connect(), we want the full client & server arrangement.
AC_ARG_ENABLE(
  [client],
  AC_HELP_STRING(
    [--enable-client],
    [Include code for running as a remote client (default)]), ,
  [enable_client=$ac_cv_search_connect])
if test no != "$enable_client"; then
  AC_DEFINE(
    [CLIENT_SUPPORT], [1],
    [Define if you want CVS to be able to be a remote repository client.])
fi

dnl
dnl end --enable-client
dnl


dnl
dnl begin --enable-password-authenticated-client
dnl
AC_ARG_ENABLE(
  [password-authenticated-client],
  AC_HELP_STRING(
    [--enable-password-authenticated-client],
    [Enable pserver as a remote access method in the CVS client
     (default)]), ,
  [enable_password_authenticated_client=$enable_client])

if test xno != "x$enable_password_authenticated_client"; then
  if test xno != "x$enable_client"; then
    AC_DEFINE(
      [AUTH_CLIENT_SUPPORT], [1],
      [Enable AUTH_CLIENT_SUPPORT to enable pserver as a remote access
       method in the CVS client (default)])
  else
    AC_MSG_WARN(
      [--enable-password-authenticated-client is meaningless with
       the CVS client disabled (--disable-client)])
  fi
fi

dnl
dnl begin --enable-password-authenticated-client
dnl


dnl
dnl begin --enable-server
dnl

dnl
dnl Give the confiscator control over whether the server code is compiled
dnl
AC_ARG_ENABLE(
  [server],
  AC_HELP_STRING(
    [--enable-server],
    [Include code for running as a server (default)]), ,
  [enable_server=$ac_cv_search_connect])

if test no != "$enable_server"; then
  AC_DEFINE(
    [SERVER_SUPPORT], [1],
    [Define if you want CVS to be able to serve repositories to remote
     clients.])

  dnl
  dnl The auth server needs to be able to check passwords against passwd
  dnl file entries, so we only #define AUTH_SERVER_SUPPORT if we can
  dnl find the crypt function. 
  dnl
  AC_SEARCH_LIBS(
    [crypt], [crypt],
    [AC_DEFINE(
       [HAVE_CRYPT], [1],
       [Define if you have the crypt function.])
     AC_DEFINE(
       [AUTH_SERVER_SUPPORT], [1],
       [Define if you want to use the password authenticated server.])dnl
  ])dnl AC_SEARCH_LIBS

  dnl
  dnl Allow the configurer to enable server flowcontrol.  Read the help
  dnl strings below for a full explanation.
  dnl
  AC_ARG_ENABLE(
    [server-flow-control],
    AC_HELP_STRING(
      [--enable-server-flow-control],
      [If you are working with a large remote repository and a 'cvs
       checkout' is swamping your network and memory, define these to
       enable flow control.  You may optionally pass a low water mark
       in bytes and a high water mark in bytes, separated by commas.
       (default is enabled 1M,2M)]),
    [if test yes = $enable_server_flow_control; then
       enable_server_flow_control=1M,2M
     fi],
    [enable_server_flow_control=1M,2M])
  if test no != $enable_server_flow_control; then
    ccvs_lwm=`expr "$enable_server_flow_control" : '\(.*\),'`
    ccvs_hwm=`expr "$enable_server_flow_control" : '.*,\(.*\)'`
    ccvs_lwm_E=`expr "$ccvs_lwm" : '[[0-9]][[0-9]]*\(.*\)'`
    ccvs_lwm=`expr "$ccvs_lwm" : '\([[0-9]][[0-9]]*\)'`
    test "" != "$ccvs_lwm" || ccvs_lwm_E="?"
    case $ccvs_lwm_E in
        G) ccvs_lwm="$ccvs_lwm * 1024 * 1024 * 1024";;
        M) ccvs_lwm="$ccvs_lwm * 1024 * 1024";;
        k) ccvs_lwm="$ccvs_lwm * 1024";;
        b | '') ;;
        *) AC_MSG_ERROR([Can't parse argument to --enable-server-flow-control
                        ('$enable_server_flow_control') as <lwm>,<hwm>])
      esac
    ccvs_hwm_E=`expr "$ccvs_hwm" : '[[0-9]][[0-9]]*\(.*\)'`
    ccvs_hwm=`expr "$ccvs_hwm" : '\([[0-9]][[0-9]]*\).*'`
    test "" != "$ccvs_hwm" || ccvs_hwm_E="?"
    case $ccvs_hwm_E in
        G) ccvs_hwm="$ccvs_hwm * 1024 * 1024 * 1024";;
        M) ccvs_hwm="$ccvs_hwm * 1024 * 1024";;
        k) ccvs_hwm="$ccvs_hwm * 1024";;
        b | '') ccvs_hwm="$ccvs_hwm";;
        *) AC_MSG_ERROR([Can't parse argument to --enable-server-flow-control
                        ('$enable_server_flow_control') as <lwm>,<hwm>])
      esac

    AC_DEFINE(
      [SERVER_FLOWCONTROL], [1],
      [If you are working with a large remote repository and a 'cvs
       checkout' is swamping your network and memory, define these to
       enable flow control.  You will end up with even less probability of
       a consistent checkout (see Concurrency in cvs.texinfo), but CVS
       doesn't try to guarantee that anyway.  The master server process
       will monitor how far it is getting behind, if it reaches the high
       water mark, it will signal the child process to stop generating
       data when convenient (ie: no locks are held, currently at the
       beginning of a new directory).  Once the buffer has drained
       sufficiently to reach the low water mark, it will be signalled to
       start again.])
    AC_DEFINE_UNQUOTED(
      [SERVER_LO_WATER], [($ccvs_lwm)],
      [The low water mark in bytes for server flow control.  Required if
       SERVER_FLOWCONTROL is defined, and useless otherwise.])
    AC_DEFINE_UNQUOTED(
      [SERVER_HI_WATER], [($ccvs_hwm)],
      [The high water mark in bytes for server flow control.  Required if
       SERVER_FLOWCONTROL is defined, and useless otherwise.])
  fi # enable_server_flow_control
fi # enable_server

dnl
dnl end --enable-server
dnl


dnl
dnl begin --enable-proxy
dnl

dnl
dnl Give the confiscator control over whether the proxy server code is compiled
dnl
AC_ARG_ENABLE(
  [proxy],
  AC_HELP_STRING(
    [--enable-proxy],
    [Include code for running as a transparent proxy server.  Disabling this
     may produce a slight performance gain on some systems, at the expense of
     write proxy support. (default)]), ,
  [if test xno != "x$enable_client" && test xno != "x$enable_server"; then
     enable_proxy=yes
   else
     enable_proxy=no
   fi])

if test no != "$enable_proxy"; then
  if test xno = "x$enable_client" || test xno = "x$enable_server"; then
    AC_MSG_WARN(
      [--enable-proxy is meaningless when either the CVS client or the
       CVS server is disabled (--disable-client and --disable-server).])
  else
    AC_DEFINE(
      [PROXY_SUPPORT], [1],
      [Define if you want CVS to be able to serve as a transparent proxy for
       write operations.  Disabling this may produce a slight performance gain
       on some systems, at the expense of write proxy support.])
  fi
fi
dnl
dnl end --enable-proxy
dnl


dnl
dnl begin --enable-pam
dnl

dnl
dnl Check if PAM authentication is enabled
dnl
AC_ARG_ENABLE(
  [pam],
  AC_HELP_STRING(
    [--enable-pam],
    [Use to enable system authentication with PAM instead of using the 
    simple getpwnam interface.  This allows authentication (in theory) 
    with any PAM module, e.g. on systems with shadow passwords or via LDAP]), ,
  [enable_pam=no]
  )

if test yes = $enable_pam; then
  ac_pam_header_available=

  AC_CHECK_HEADER([security/pam_appl.h], [
    AC_DEFINE([HAVE_SECURITY_PAM_APPL_H], 1, [Define to 1 if security/pam_appl.h is available])
    ac_pam_header_available=1])

  if test -z "$ac_pam_header_available"; then
  AC_CHECK_HEADER([pam/pam_appl.h], [
    AC_DEFINE([HAVE_PAM_PAM_APPL_H], 1, [Define to 1 if pam/pam_appl.h is available])
    ac_pam_header_available=1])
  fi

  if test -z "$ac_pam_header_available"; then
    AC_MSG_ERROR([Could not find PAM headers])
  else
    AC_DEFINE(HAVE_PAM, 1, 
    [Define to enable system authentication with PAM instead of using the 
    simple getpwnam interface.  This allows authentication (in theory) 
    with any PAM module, e.g. on systems with shadow passwords or via LDAP])
    AC_CHECK_LIB(pam, pam_start, [LIBS="${LIBS} -lpam"],
      AC_MSG_ERROR([Could not find PAM libraries but the headers exist.
      Give the --disable-pam option to compile without PAM support (or fix
      your broken configuration)])
    )
  fi
fi

dnl
dnl end --enable-pam
dnl


dnl
dnl begin --enable-case-sensitivity
dnl

AC_ARG_ENABLE(
  [case-sensitivity],
  AC_HELP_STRING(
    [--enable-case-sensitivity],
    [Force CVS to expect a case sensitive file system.  Enabling this on a case
     insensitive system should have little effect on the server or client
     operation, though client users may ocassionally be suprised that the CVS
     server appears to be case sensitive.  Disabling this for a case sensitive
     server disables server support for case insensitive clients, which can
     confuse all users of case insensitive clients contacting the server.
     Disabling this for a case sensitive client will cause the client to ask
     servers to behave case insensitively, which could cause confusion for
     users, but also probably no real harm.  (default autoselects based on the
     case sensitivity of the file system containing the current working
     directory)]),
    [case "$enable_case_sensitivity" in
       yes | no | auto) ;;
       *)
          AC_MSG_ERROR([Unrecognized argument to --enable-case-sensitivity: \`$enable_case_sensitivity'.  Acceptable values are \`yes', \`no', and \`auto'.])
          ;;
     esac],
  [enable_case_sensitivity=auto])

acx_forced=' (forced)'
AC_MSG_CHECKING([for a case sensitive file system])
if test $enable_case_sensitivity = auto; then
  dnl
  dnl Check for a case insensitive filesystem, like Mac OS X and Windows have.
  dnl
  AC_CACHE_VAL([acx_cv_case_sensitive],
  [ rm -f ac_TEST_filenames_CASE_sensitive
    echo foo >ac_test_filenames_case_sensitive
    if test -f ac_TEST_filenames_CASE_sensitive; then
      acx_cv_case_sensitive=no
    else
      acx_cv_case_sensitive=yes
    fi
    rm ac_test_filenames_case_sensitive
  ])
  enable_case_sensitivity=$acx_cv_case_sensitive
  acx_forced=
fi
AC_MSG_RESULT([$enable_case_sensitivity$acx_forced])
if test $enable_case_sensitivity = no; then
  AC_DEFINE([FILENAMES_CASE_INSENSITIVE], [1],
            [Define if this executable will be running on case insensitive
             file systems.  In the client case, this means that it will request
             that the server pretend to be case insensitive if it isn't
             already.])
  dnl Compile fncase.c (containing fncase() & fncmp()) to handle file name
  dnl comparisons on case insensitive filesystems.
  AC_LIBOBJ(fncase)
fi

dnl
dnl end --enable-case-sensitivity
dnl


dnl
dnl begin --enable-encryption
dnl

dnl
dnl Use --enable-encryption to turn on encryption support, but ignore this
dnl option unless either client or server is enabled.
dnl
AC_ARG_ENABLE(
  [encryption],
  AC_HELP_STRING(
    [--enable-encryption],
    [Enable encryption support (disabled by default)]), ,
  [enable_encryption=no])
if test "x$enable_encryption" = xyes; then
  if test xno = "x$with_client" && test xno = "x$with_server"; then
    AC_MSG_WARN(
      [--enable-encryption is meaningless when neither the CVS client
       nor the CVS server is enabled (--disable-client and --disable-server).])
  else
    AC_DEFINE(
      [ENCRYPTION], [1],
      [Define to enable encryption support.])
  fi
fi

dnl
dnl end --enable-encryption
dnl


dnl
dnl begin --enable-force-editor
dnl

AC_ARG_ENABLE(
  [force-editor],
  AC_HELP_STRING(
    [--enable-force-editor],
    [When committing or importing files, you must enter a log message.
     Normally, you can do this either via the -m flag on the command
     line, the -F flag on the command line, or an editor will be started
     for you.  If you like to use logging templates (the rcsinfo file
     within the $CVSROOT/CVSROOT directory), you might want to force
     people to use the editor even if they specify a message with -m or
     -F.  --enable-force-editor will cause the -m or -F message to be
     appended to the temp file when the editor is started. (disabled
     by default)]), ,
  [enable_force_editor=no])

if test yes = "$enable_force_editor"; then
  AC_DEFINE(
    [FORCE_USE_EDITOR], [1],
    [When committing or importing files, you must enter a log message.
    Normally, you can do this either via the -m flag on the command
    line, the -F flag on the command line, or an editor will be started
    for you.  If you like to use logging templates (the rcsinfo file
    within the $CVSROOT/CVSROOT directory), you might want to force
    people to use the editor even if they specify a message with -m or
    -F.  Enabling FORCE_USE_EDITOR will cause the -m or -F message to be
    appended to the temp file when the editor is started.])
fi

dnl
dnl end --enable-force-editor
dnl


dnl
dnl begin --enable-lock-compatibility
dnl

# Check for options requesting client and server feature. If none are
# given and we have connect(), we want the full client & server arrangement.
AC_ARG_ENABLE(
  [lock-compatibility],
  AC_HELP_STRING(
    [--enable-lock-compatibility],
    [Include locking code which prevents versions of CVS earlier than 1.12.4
     directly accessing the same repositiory as this executable from ignoring
     this executable's promotable read locks.  If only CVS versions 1.12.4 and
     later will be accessing your repository directly (as a server or locally),
     you can safely disable this option in return for fewer disk accesses and a
     small speed increase.  Disabling this option when versions of CVS earlier
     than 1,12,4 _will_ be accessing your repository, however, is *VERY* *VERY*
     *VERY* dangerous and could result in data loss.  (enabled by default)]),,
  [enable_lock_compatibility=yes])

if test x$enable_lock_compatibility = xyes; then
  AC_DEFINE([LOCK_COMPATIBILITY], [1],
    [Define to include locking code which prevents versions of CVS earlier than
     1.12.4 directly accessing the same repositiory as this executable from
     ignoring this executable's promotable read locks.  If only CVS versions
     1.12.4 and later will be accessing your repository directly (as a server
     or locally), you can safely disable this option in return for fewer disk
     accesses and a small speed increase.  Disabling this option when versions
     of CVS earlier than 1,12,4 _will_ be accessing your repository, however,
     is *VERY* *VERY* *VERY* dangerous and could result in data loss.

     As such, by default, CVS is compiled with this code enabled.  If you are
     sure you would like this code disabled, you can disable it by passing the
     "--disable-lock-compatibility" option to configure or by commenting out
     the lines below.])
fi

dnl
dnl end --enable-lock-compatibility
dnl


dnl
dnl begin --enable-rootcommit
dnl

dnl
dnl I don't like this here, but I don't really like options.h, either.
dnl Besides, this is causing some problems currently when compiling under
dnl Windows and moving it here should avoid the issue (the wrong options.h
dnl is being used).
dnl
dnl I don't like making this a runtime option either.  I think I just don't
dnl like making it easy to get to, but putting it here goes along with the
dnl Autoconf ideal.
dnl
AC_ARG_ENABLE(
  [rootcommit],
  AC_HELP_STRING(
    [--enable-rootcommit],
    [Allow the root user to commit files (disabled by default)]), ,
  [enable_rootcommit=no])
if test "$enable_rootcommit" = no; then
  AC_DEFINE(
    [CVS_BADROOT], [1],
    [When committing a permanent change, CVS and RCS make a log entry of
     who committed the change.  If you are committing the change logged
     in as "root" (not under "su" or other root-priv giving program),
     CVS/RCS cannot determine who is actually making the change.

     As such, by default, CVS prohibits changes committed by users
     logged in as "root".  You can disable checking by passing the
     "--enable-rootcommit" option to configure or by commenting out the
     lines below.])
fi

dnl
dnl end --enable-rootcommit
dnl

dnl
dnl begin --enable-old-info-support
dnl
AC_ARG_ENABLE(
  [old-info-support],
  AC_HELP_STRING(
    [--enable-old-info-format-support],
    [Enable support for the pre 1.12.1 *info scripting hook format strings.
     Disable this option for a smaller executable once your scripting
     hooks have been updated to use the new *info format strings (default).]), ,
  [enable_old_info_format_support=yes])
if test "$enable_old_info_format_support" = yes; then
  AC_DEFINE(
    [SUPPORT_OLD_INFO_FMT_STRINGS], [1],
    [Enable support for the pre 1.12.1 *info scripting hook format strings.
     Disable this option for a smaller executable once your scripting
     hooks have been updated to use the new *info format strings by passing
     "--disable-old-info-format-support" option to configure or by commenting
     out the line below.])
fi

dnl
dnl end --enable-old-info-support
dnl


dnl
dnl begin --enable-config-override
dnl

AC_ARG_ENABLE(
  [config-override],
  AC_HELP_STRING(
    [--enable-config-override],
    [Set to a comma-seperated list of paths to directories (designated by
     trailing `/') and files, specifies the path prefixes (for directories) and
     paths to files the CVS server commands will allow configuration to be read
     from.  Specify `--enable-config-override=no' to disable config file
     overrides completely and `--enable-config-override=/' or simply
     `--enable-config-override' to allow all paths.  (Defaults to
     `SYSCONFDIR/cvs.conf,SYSCONFDIR/cvs/')]),,
  [# $sysconfdir may still contain variable references.  By default, this will
   # be to $prefix, and $prefix won't be set to its default value until later.
   # Compromise without setting $prefix for the rest of the file.
   cvs_save_prefix=$prefix
   if test "X$prefix" = XNONE; then
     prefix=$ac_prefix_default
   fi
   eval enable_config_override=`echo $sysconfdir/cvs.conf,$sysconfdir/cvs/`
   prefix=$cvs_save_prefix])

if test x"$enable_config_override" = xyes; then
  enable_config_override=/
fi

if test x"$enable_config_override" = xno; then :; else
  save_IFS=$IFS
  IFS=,
  arrayinit=""
  for path in $enable_config_override; do
    IFS=$save_IFS
    case "$path" in
      [[\\/$]]* | ?:[[\\/]]* )
	arrayinit="$arrayinit\"$path\", "
	;;
      *)  AC_MSG_ERROR(
          [expected comma separated list of absolute directory
           names for --enable-config-override, or \`no', not:
           \`$enable_config_override'
           (\`$path' invalid.)]);;
    esac
  done
  arrayinit="${arrayinit}NULL"

  AC_DEFINE_UNQUOTED(ALLOW_CONFIG_OVERRIDE, [$arrayinit],
    [Define this to a NULL terminated list of allowed path prefixes (for
     directories) and paths to files the CVS server will allow configuration to
     be read from when specified from the command line.])
fi

dnl
dnl end --enable-config-override
dnl



dnl
dnl end --enables
dnl



dnl For the moment we will assume that all systems which have
dnl the unixyness to run configure are unixy enough to do the
dnl PreservePermissions stuff.  I have this sinking feeling that
dnl things won't be that simple, before long.
dnl AC_DEFINE(PRESERVE_PERMISSIONS_SUPPORT, 1,
dnl [Define if this system supports chown(), link(), and friends.])

dnl On cygwin32, we configure like a Unix system, but we need some support
dnl libraries.  We do this at the end so that the new libraries are added at
dnl the end of LIBS.
dnl
dnl FIXME: We should be trying to meet the autoconf ideal of checking for
dnl the properties of the system rather than the name of the os here.  In other
dnl words, we should check the case sensitivty of the system and then for
dnl the support functions we are using and which library we find them in.
AC_CACHE_CHECK(for cygwin32, ccvs_cv_sys_cygwin32,
[AC_TRY_COMPILE([], [return __CYGWIN32__;],
ccvs_cv_sys_cygwin32=yes, ccvs_cv_sys_cygwin32=no)])
if test $ccvs_cv_sys_cygwin32 = yes; then
  LIBS="$LIBS -ladvapi32"

  dnl On Windows you can only change file times if you can write to
  dnl the file.  cygwin32 should really handle this for us, but as of
  dnl January 1998 it doesn't.
  AC_DEFINE(UTIME_EXPECTS_WRITABLE, 1,
[Define if utime requires write access to the file (true on Windows,
but not Unix).])

  dnl On Windows we must use setmode to change between binary and text
  dnl mode.  This probably doesn't really require two macro definitions
  AC_DEFINE(USE_SETMODE_STDOUT, 1,
[Define if setmode is required when writing binary data to stdout.])
  AC_DEFINE(HAVE_SETMODE, 1,
[Define if the diff library should use setmode for binary files.])
fi

dnl associate the setting of the execute bit with the individual scripts
AC_CONFIG_FILES(contrib/validate_repo, [chmod +x contrib/validate_repo])
AC_CONFIG_FILES(contrib/clmerge, [chmod +x contrib/clmerge])
AC_CONFIG_FILES(contrib/cln_hist, [chmod +x contrib/cln_hist])
AC_CONFIG_FILES(contrib/commit_prep, [chmod +x contrib/commit_prep])
AC_CONFIG_FILES(contrib/cvs_acls, [chmod +x contrib/cvs_acls])
AC_CONFIG_FILES(contrib/log, [chmod +x contrib/log])
AC_CONFIG_FILES(contrib/log_accum, [chmod +x contrib/log_accum])
AC_CONFIG_FILES(contrib/mfpipe, [chmod +x contrib/mfpipe])
AC_CONFIG_FILES(contrib/pvcs2rcs, [chmod +x contrib/pvcs2rcs])
AC_CONFIG_FILES(contrib/rcs2log:contrib/rcs2log.sh, [chmod +x contrib/rcs2log])
AC_CONFIG_FILES(contrib/rcslock, [chmod +x contrib/rcslock])
AC_CONFIG_FILES(contrib/sccs2rcs, [chmod +x contrib/sccs2rcs])
AC_CONFIG_FILES(doc/mkman:doc/mkman.pl, [chmod +x doc/mkman])
AC_CONFIG_FILES(src/cvsbug, [chmod +x src/cvsbug])

dnl the bulk files
AC_CONFIG_FILES([Makefile \
	  contrib/Makefile \
	  contrib/pam/Makefile \
	  cvs.spec \
	  diff/Makefile \
	  doc/Makefile \
	  doc/i18n/Makefile \
	  doc/i18n/pt_BR/Makefile \
	  lib/Makefile \
	  maint-aux/Makefile \
	  man/Makefile \
	  src/Makefile \
	  src/sanity.config.sh])

dnl AC_EXTRA_CONFIG_FILES([\
dnl 	  emx/Makefile \
dnl 	  os2/Makefile \
dnl 	  tools/Makefile \
dnl 	  vms/Makefile \
dnl 	  windows-NT/Makefile \
dnl 	  windows-NT/SCC/Makefile \
dnl 	  zlib/Makefile])

dnl and we're done
AC_OUTPUT



# Report the state of this version of CVS if this is from dev.
m4_bmatch(m4_defn([AC_PACKAGE_VERSION]),  [[0-9]*\.[0-9]*\.[0-9]*\.[0-9]],
[    cat <<EOF

You are about to use an unreleased version of CVS.  Be sure to
read the relevant mailing lists, most importantly <info-cvs@nongnu.org>.

Below you will find information on the status of this version of CVS.


EOF
    sed -n '/^\* Status/,$p' $srcdir/BUGS
])
