dnl
dnl	aegis - a project change supervisor
dnl	Copyright (C) 1994, 1995, 1997-1999, 2001-2004 Peter Miller;
dnl	All rights reserved.
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 2 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, write to the Free Software
dnl	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
dnl
dnl MANIFEST: how to configure aegis, input to the GNU autoconf program
dnl
AC_INIT(install-sh)
AC_CONFIG_HEADER(common/config.h)
AC_PROG_CC
AC_PROG_CPP

dnl
dnl	Look for an existing Aegis installation, and use the "aegis
dnl	--configured" command to replicate its configuration.
dnl	Unless they said --witn-no-aegis-configured
dnl
if test "x$prefix" = "xNONE"
then
    if test "x$with_no_aegis_configured" = "x"; then
	cfgval=`aegis --configured 2> /dev/null`
	if test $? -eq 0; then
	    eval "$cfgval"
	else
	    cfgval=`which aegis 2> /dev/null`
	    if test $? -ne 0; then
		case "$cfgval" in
		/bin/aegis )
		    prefix=/
		    ;;
		*/bin/aegis )
		    prefix=`echo $cfgval | sed 's|/bin/aegis$||'`
		    ;;
		esac
	    fi
	fi
    fi
fi

dnl
dnl	Avoid the /usr/ucb/cc compiler, it screws up readdir,
dnl	some systems seem to have the ucb one early in the path.
dnl
dnl	ranlib is unneccessary, but setting it to : will
dnl	not work, so set it to echo.
dnl
dnl	This test must be before the stdarg test
dnl	and before AC_C_CONST
dnl
if test -z "$GCC" ; then
AC_MSG_CHECKING([for Pyramid])
AC_EGREP_CPP(yes,[#ifdef __pyrsoft
  yes
#endif], CC="/usr/ccs/bin/cc"
RANLIB="echo no need to ranlib"
AC_MSG_RESULT(yes),AC_MSG_RESULT(no))
fi

AC_PROG_INSTALL
AC_PROG_YACC
AC_PROG_RANLIB
AC_MINIX
AC_ISC_POSIX
AC_OBJEXT
AC_EXEEXT

dnl Solaris 2.5.1 and below wide-character support
AC_CHECK_FUNC(wschr, ,
	unset ac_cv_func_wschr
	AC_CHECK_LIB(w, wschr))
AC_CHECK_FUNC(gettext, ,
	unset ac_cv_func_gettext
	AC_CHECK_LIB(intl, gettext))
AC_CHECK_FUNC(setsockopt, ,
	unset ac_cv_func_setsockopt
	AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_LIB(m, main)
AC_CHECK_LIB(rx, main)
AC_CHECK_LIB(z, main)
AC_CHECK_LIB(magic, magic_file)
dnl The -lclu library is for OSF/1 clustering
AC_CHECK_LIB(clu, main)
AC_CHECK_LIB(curl, curl_multi_perform)
AC_CHECK_PROGS(MSGFMT, gmsgfmt msgfmt, msgfmt)
AC_CHECK_PROGS(MSGCAT, gmsgcat msgcat)
AC_CHECK_PROGS(GROFF, groff roff)
AC_CHECK_PROGS(SOELIM, roffpp gsoelim soelim)
AC_CHECK_PROGS(AWK, gawk nawk awk, awk)
AC_PATH_PROG(WISH, wish, /usr/local/bin/wish)

AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
AC_DEFINE_UNQUOTED(CONF_PERL, ["$PERL"],
[Set this to be the absolute path of a Perl interpreter.])

dnl
dnl	See if we are using GNU diff
dnl
AC_MSG_CHECKING([for GNU diff])
HAVE_GNU_DIFF=no
if diff --version > conftest.out 2>&1
then
    if grep 'GNU diff' conftest.out > conftest.err 2>&1
    then
	AC_DEFINE(HAVE_GNU_DIFF, 1,
	    [Define this symbol of your system has GNU diff.])
	HAVE_GNU_DIFF=yes
    fi
fi
AC_MSG_RESULT([$HAVE_GNU_DIFF])

dnl
dnl	Test if groff takes -ms or -mgs for the macro package.
dnl
AC_MSG_CHECKING([for $GROFF -ms macros])
if test `echo ' ' | groff -mgs 2> /dev/null | wc -l` -gt 0
then
	GROFF_MS_MACROS=gs
else
	GROFF_MS_MACROS=s
fi
AC_SUBST(GROFF_MS_MACROS)
AC_MSG_RESULT([-m$GROFF_MS_MACROS])

dnl
dnl	Test if groff takes -mm or -mgm for the macro package.
dnl
AC_MSG_CHECKING([for $GROFF -mm macros])
if test `echo ' ' | groff -mgm 2> /dev/null | wc -l` -gt 0
then
	GROFF_MM_MACROS=gm
else
	GROFF_MM_MACROS=m
fi
AC_SUBST(GROFF_MM_MACROS)
AC_MSG_RESULT([-m$GROFF_MM_MACROS])

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))

dnl
dnl	Test to see if stdarg.h is available *and* works.
dnl
AC_MSG_CHECKING([for working stdarg.h])
AC_TRY_RUN([
#include <stdarg.h>
char *foo = "test";
#if defined(__GNUC__) || __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
dnl	Test to see if mblen is available *and* works.
dnl
AC_MSG_CHECKING([for working mblen])
AC_TRY_RUN([
#include <stdlib.h>
int main(){mblen(0,0);
exit(mblen("OK", 2) != 1);}],
AC_DEFINE(HAVE_MBLEN,1,
[Define this symbol of your system has mblen AND it works.])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
AC_MSG_RESULT(cross))

AC_CHECK_HEADERS(curl/curl.h fcntl.h iso646.h libgettext.h libintl.h limits.h \
	locale.h magic.h memory.h mntent.h regex.h rxposix.h stddef.h stdlib.h \
	string.h unistd.h wchar.h wctype.h widec.h zlib.h sys/clu.h \
	sys/ioctl.h)
AC_HEADER_DIRENT
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_C_CONST
AC_SYS_LONG_FILE_NAMES
AC_CHECK_FUNCS(clu_info getpgrp gettext gettimeofday iswctype magic_file \
	mbrtowc pathconf regcomp seteuid setlocale setresuid setreuid \
	sighold sigprocmask snprintf strcasecmp strncasecmp strerror \
	strftime strsignal strtoul strverscmp tcgetpgrp vsnprintf wcrtomb \
	wcslen wcwidth)

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	Check to see if mbstate_t is defined.
dnl
AC_MSG_CHECKING([for mbstate_t])
AC_TRY_COMPILE([
#include <ctype.h>
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
/* Solaris bug 1250837: include wchar.h before widec.h */
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
#ifdef HAVE_WIDEC_H
#include <widec.h>
#endif
#ifdef HAVE_WCTYPE_H
#include <wctype.h>
#endif
],
[ mbstate_t x; ],
AC_DEFINE(HAVE_MBSTATE_T,1,
[Define this symbol of your system has the mbstate_t type defined.
It is usually in <stddef.h> or <wchar.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>
/* Solaris bug 1250837: include wchar.h before widec.h */
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
#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.])
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, [])
AC_MSG_RESULT(empty),
AC_MSG_RESULT(cross))

dnl
dnl	Test to see if the pw_comment field exists in
dnl	the passwd struct defined in the <pwd.h> include file.
dnl
AC_MSG_CHECKING([for pw_comment in struct passwd])
AC_TRY_COMPILE([#include <pwd.h>], [struct passwd *pw;
pw = getpwnam("root"); printf("%s\n", pw->pw_comment);],
AC_DEFINE(HAVE_pw_comment,1,
[Define this symbol if your system has
the pw_comment field in the passwd struct defined in <pwd.h>.])
AC_MSG_RESULT(yes),AC_MSG_RESULT(no))dnl

dnl
dnl	Test to see if the tm_zone field exists in
dnl	the passwd tm defined in the <time.h> include file.
dnl
AC_MSG_CHECKING([for tm_zone in struct tm])
AC_TRY_COMPILE([
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif], [struct tm *tm;
printf("%s\n", tm->tm_zone);],
AC_DEFINE(HAVE_tm_zone,1,
[Define this symbol if your system has
the tm_zone field in the tm struct defined in <time.h>.])
AC_MSG_RESULT(yes),AC_MSG_RESULT(no))dnl

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 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 aegis 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 "bindir=$bindir"
eval "datadir=$datadir"
eval "libdir=$libdir"
eval "mandir=$mandir"
eval "sharedstatedir=$sharedstatedir"
case "$datadir" in
*/aegis/* | */aegis )
	;;
*)
	datadir="${datadir}/aegis"
	;;
esac
case "$libdir" in
*/aegis/* | */aegis )
	;;
*)
	libdir="${libdir}/aegis"
	;;
esac
case "$sharedstatedir" in
*/aegis/* | */aegis )
	;;
*)
	sharedstatedir="${sharedstatedir}/aegis"
	;;
esac

dnl support for NLSDIR option
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)

dnl
dnl	See if there is already existing library files
dnl	Use uid/gid if so, otherwise use 3/3
dnl
dnl	Cygwin always runs in "single user" mode, so this test isn't
dnl	useful.  Just default the values to the preferred ones.
dnl
if test "x$AEGIS_UID" = "x"; then
    AC_MSG_CHECKING([for owner of aegis library files])
    AEGIS_UID=3
    AEGIS_GID=3
    if test "$OSTYPE" != "cygwin32" -a "$OSTYPE" != "cygwin" ; then
    if test -f ${sharedstatedir}/lockfile -o -f ${libdir}/lockfile ; then
	cat > conftest.$ac_ext << 'EOF'
#line __oline__ "configure"
#include <sys/types.h>
#include <sys/stat.h>
main(ac,av)int ac; char **av;{struct stat st;
if (stat(*(av+1),&st)!=0)exit(1);
printf("%d\n", ac>2?st.st_gid:st.st_uid);exit(0);}
EOF
	if AC_TRY_EVAL(ac_link); then
		if maybe=`./conftest ${sharedstatedir}/lockfile`; then
			AEGIS_UID=$maybe
		else
			if maybe=`./conftest ${libdir}/lockfile`; then
				AEGIS_UID=$maybe
			fi
		fi
		if maybe=`./conftest ${sharedstatedir}/lockfile gid`; then
			AEGIS_GID=$maybe
		else
			if maybe=`./conftest ${libdir}/lockfile gid`; then
				AEGIS_GID=$maybe
			fi
		fi
	fi
	rm -rf conftest*
    fi
    fi
    AC_SUBST(AEGIS_UID)
    AC_SUBST(AEGIS_GID)
    AC_MSG_RESULT([$AEGIS_UID, $AEGIS_GID])
fi

dnl
dnl	Test to see if enums are the same size as ints
dnl
AC_MSG_CHECKING([for enums of int size])
AC_TRY_RUN([
int main(argc, argv) int argc; char **argv; {
enum foo { bar, baz } fubar;
exit(sizeof(fubar) != sizeof(int));
}], AC_DEFINE(CONF_enum_is_int,1,
[Define this symbol if your compiler
makes all enums the same size as ints.])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
AC_MSG_RESULT(cross))

dnl
dnl	If the libz.h is not present, Aegis will fail to compile.
dnl	If the -lz is not present, Aegis will fail to link.
dnl
if test "$ac_cv_lib_z_main" != "yes" -o "$ac_cv_header_zlib_h" != "yes"
then
  AC_MSG_RESULT([])
  AC_MSG_RESULT([	You need to install the GNU zlib compression])
  AC_MSG_RESULT([	library, and then re-run this install script.])
  AC_MSG_RESULT([	Remember to use \`\`rm config.cache'' before you do.])
  AC_MSG_RESULT([])
fi

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
  po_files=yes
else
  po_files=no
  AC_MSG_RESULT([])
  AC_MSG_RESULT([	Aegis will emit much more useful error messages if])
  AC_MSG_RESULT([	you install GNU \`\`gettext'' and then re-run this])
  AC_MSG_RESULT([	./configure script.])
  AC_MSG_RESULT([	Remember to use \`\`rm config.cache'' before you do.])
  AC_MSG_RESULT([])
fi
AC_SUBST(po_files)

dnl
dnl	If the soelim program exists, and understands the -I option,
dnl	arrange for the Makefile to install the .ps files from the
dnl	documentation source files.
dnl
if test -n "$SOELIM"
then
  if $SOELIM -I. /dev/null > /dev/null 2>&1
  then
    : nothing
  else
    AC_MSG_RESULT([
	The $SOELIM program does not understand the -I option.
	GNU Groff 1.15 or later works correctly.
	See the BUILDING file for details.])
    GROFF=
  fi
fi
if test -n "$GROFF"
then
  HAVE_GROFF=yes
else
  HAVE_GROFF=no
  AC_MSG_RESULT([
	The Aegis documentation set and manual pages will
	be formatted and installed if you first install
	GNU Groff 1.15 or later and then re-run this ./configure script.
	Remember to use \`\`rm config.cache'' before you do.
])
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)

AH_TOP(
[/*
 *	aegis - project change supervisor
 *	Copyright (C) 1991-2004 Peter Miller;
 *	All rights reserved.
 *
 *	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 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, write to the Free Software
 *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 *
 * MANIFEST: template common/config.h file
 */

#ifndef COMMON_CONFIG_H
#define COMMON_CONFIG_H
])

AH_BOTTOM(
[/*
 * This defines the file creation mask.  See umask(2) for more information.
 * Some bits are not available, because aegis is _meant_ to be paranoid.
 * Owner: always has read, write and search/exec.
 * Group: always has read and search/exec, so that developers can get at the
 *	baseline.  There is never group write, because then developers
 *	could trash the baseline, which is counter-productive.
 * Others: There is never others write, for the same reason as group.
 *	Others read and search/execute is configurable.
 *
 * The permissions mask in binary looks like
 *	000 010 X1X
 * where the Xs may be configured.
 *
 * Alternatives for default umask are thus
 *	027	others get nothing
 *	026	others can execute the results if they know where they are going
 *	022	others can see and copy and execute anything
 *	023	don't do this (why is left as an exersize for the reader)
 *
 * Projects have a configurable umask, this is just the default.
 *	See aepattr(1) for more information.
 */
#define DEFAULT_UMASK 026

/*
 * These symbols define where non-system user IDs start,
 * and where non-system group IDs start.
 * This is mostly to ensure that accounts "root" and "bin"
 * and "uucp" are not project owners.
 */
#define AEGIS_MIN_UID 100
#define AEGIS_MIN_GID 10

/*
 * There is more to do, but we need to insulate it from config.status,
 * because it screws up the #undef lines.  They are all implications of
 * the above information, so there is no need for you to edit the file,
 * if you are configuring Aegis manually.
 */
#include <config.messy.h>

#endif /* COMMON_CONFIG_H */])


AC_OUTPUT(Makefile lib/cshrc lib/profile etc/libdir.so
	common/libdir.c etc/compat.2.3)
