dnl
dnl File:        configure.in
dnl Revision:    $Id: 1a56a7f769d2451ea629e5372e5e7907142e6798 $
dnl Created:     1994/06/18
dnl Author:      Leif Hedstrom<hedstrom@inf.ethz.ch>
dnl		 Martin S. Utesch <wstd@hl.siemens.de>
dnl 		 Peter W. Osel <pwo@GUUG.DE>
dnl 		 R.K. Owen <rk@owen.sj.ca.us>
dnl
dnl Process this file with autoconf to produce a configure script
dnl You need autoconf 2.52 or better!
dnl
dnl ---------------------------------------------------------------------------
AC_INIT(modules,3.2)
AC_CONFIG_AUX_DIR(config)
AM_INIT_AUTOMAKE(1.9.6 foreign dejagnu no-installinfo dist-bzip2)
AC_CONFIG_SRCDIR([version.c])
AM_CONFIG_HEADER(config.h)
AC_PREREQ(2.59)

dnl ---------------------------------------------------------------------------
dnl Autoheader "templates" (was acconfig.h)
AH_TOP([
/*****
 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   Description:	config.h.in (generated by autoheader from	     **
 **			configure.ac)					     **
 ** 									     **
 ** ************************************************************************ **
 ****/

/** ** Copyright *********************************************************** **
 ** 									     **
 ** Copyright 1991-1994 by John L. Furlan.                      	     **
 ** see LICENSE.GPL, which must be provided, for details		     **
 ** 									     ** 
 ** ************************************************************************ **/
])
dnl ---------------------------------------------------------------------------
dnl
dnl Some special substitution we need:
dnl
dnl ---------------------------------------------------------------------------
dnl Need to know if versioning is asked for before setting certain paths
dnl --enable-versioning		Use modules versioning 	[DEF]
dnl --disable-versioning	Without  - " -
dnl ---------------------------------------------------------------------------
dnl
AC_SUBST(WANTS_VERSIONING)
AC_SUBST(VERSIONING)
AC_SUBST(NOTVERSIONING)
AH_TEMPLATE([WANTS_VERSIONING],[
WANTS_VERSIONING Does the system want to use modules versions])
AC_ARG_ENABLE(versioning,
	AC_HELP_STRING([--enable-versioning], [use modules versioning [[yes]]]),
	if test "$enableval" = "yes"; then
	    WANTS_VERSIONING=1
	    AC_DEFINE(WANTS_VERSIONING,1)
	    VERSIONING=""
	    NOTVERSIONING="#"
	else
	    WANTS_VERSIONING=0
	    AC_DEFINE(WANTS_VERSIONING,0)
	    VERSIONING="#"
	    NOTVERSIONING=""
	fi, WANTS_VERSIONING=1
	    AC_DEFINE(WANTS_VERSIONING,1)
	    VERSIONING=""
	    NOTVERSIONING="#"
)
dnl
dnl ---------------------------------------------------------------------------
dnl Get Modules version & date
dnl ---------------------------------------------------------------------------
dnl DATE		Module package date
dnl VERSION		Module package version
dnl
AC_SUBST(VERSION)
AC_SUBST(DATE)
VERSION='(unknown)'
VERSION=`sed -n -e 's/^.*version_string.*"\(.*\)";$/\1/p' ${srcdir}/version.c`
AC_MSG_RESULT([VERSION = $VERSION])
DATE='(DDMmmYYYY)'
DATE=`sed -n -e 's/^.*date_string.*"\(.*\)";$/\1/p' ${srcdir}/version.c`
AC_MSG_RESULT([DATE = $DATE])
echo "configuring for Modules $VERSION		$DATE"
dnl ---------------------------------------------------------------------------
dnl Set PREFIX and related based on WANTS_VERSIONING
dnl ---------------------------------------------------------------------------
AC_SUBST(DEFAULTPATH)
AC_SUBST(BASEPREFIX)
DEFAULTPATH=default
AH_TEMPLATE([BASEPREFIX],[ BASEPREFIX: Usually equivalent to /usr/local])
AH_TEMPLATE([PREFIX],[
PREFIX: Usually equivalent to /usr/local/Modules[/version_number]])
AH_TEMPLATE([MODULES_INIT_DIR],[
MODULES_INIT_DIR: Directory that contains the modules init files.])

if test "$exec_prefix" != "NONE" ; then
  EXECPREFIX=$exec_prefix
# can not have versioning if specifying exec-prefix
  if test "$WANTS_VERSIONING" -eq 1 ; then
     AC_MSG_ERROR([You can not have versioning if --exec-prefix is specified
must disable with --disable-versioning ])
  fi
fi
if test "$prefix" != "NONE" ; then
  if test "$WANTS_VERSIONING" -eq 1 ; then
    DEFAULTPATH=$prefix/Modules/default
    NODEFAULTPATH=$prefix/Modules/$VERSION
    BASEPREFIX=$prefix
    prefix=$BASEPREFIX/Modules/$VERSION
    export prefix
  else
    DEFAULTPATH=$prefix/Modules
    NODEFAULTPATH=$prefix/Modules
    BASEPREFIX=$prefix
    prefix=$BASEPREFIX/Modules
    export prefix
  fi
  PREFIX=$prefix
else
  if test "$WANTS_VERSIONING" -eq 1 ; then
    DEFAULTPATH=$ac_default_prefix/Modules/default
    NODEFAULTPATH=$ac_default_prefix/Modules/$VERSION
    BASEPREFIX=$ac_default_prefix
    ac_default_prefix=$BASEPREFIX/Modules/$VERSION
    export ac_default_prefix
  else
    DEFAULTPATH=$ac_default_prefix/Modules
    NODEFAULTPATH=$ac_default_prefix/Modules
    BASEPREFIX=$ac_default_prefix
    ac_default_prefix=$BASEPREFIX/Modules
    export ac_default_prefix
  fi
  PREFIX=$ac_default_prefix
fi
if test "$exec_prefix" != "NONE" ; then
  EXECPREFIX=$exec_prefix
else
  EXECPREFIX=$PREFIX
fi
MODULES_INIT_DIR=$EXECPREFIX/init
dnl ---------------------------------------------------------------------------
dnl --enable-use-default        Use PREFIX/default/ in init scripts [DEF]
dnl --disable-use-default       Use PREFIX/VERSION/ in init scripts
dnl ---------------------------------------------------------------------------
AC_DEFINE_UNQUOTED(MODULES_INIT_DIR, "$MODULES_INIT_DIR")
AC_ARG_ENABLE(use-default,
	AC_HELP_STRING([--enable-use-default],[use DEFAULTPATH in init scripts [[yes]]]),
	if test "$enableval" = "no" -o $WANTS_VERSIONING -eq 0; then
		DEFAULTPATH=$NODEFAULTPATH
	fi)
AC_MSG_RESULT([DEFAULTPATH = $DEFAULTPATH])
AC_MSG_RESULT([BASEPREFIX = $BASEPREFIX])
AC_MSG_RESULT([PREFIX = $PREFIX])
AC_MSG_RESULT([EXECPREFIX = $EXECPREFIX])
AC_DEFINE_UNQUOTED(BASEPREFIX, "$BASEPREFIX")
AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX")
export DEFAULTPATH
export NODEFAULTPATH
export BASEPREFIX
export MODULES_INIT_DIR
dnl ---------------------------------------------------------------------------
dnl Some standard autoconfig stuff
dnl Checks for programs
dnl ---------------------------------------------------------------------------
AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AM_PROG_CC_C_O
AC_PROG_MAKE_SET
AC_AIX
AC_ISC_POSIX
AC_PATH_PROG([UNAME],[uname],[""])
dnl ---------------------------------------------------------------------------
dnl Checks for header files
dnl ---------------------------------------------------------------------------

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(string.h memory.h stdlib.h unistd.h termio.h fcntl.h ctype.h \
	stdarg.h varargs.h syslog.h stdint.h)
AC_CHECK_HEADERS([sys/ioctl.h sys/termios.h sys/mode.h sys/stat.h sys/param.h \
		  errno.h assert.h locale.h])
dnl ---------------------------------------------------------------------------
dnl Checks for typedefs, structures, and compiler characteristics.
dnl ---------------------------------------------------------------------------
AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_SIZE_T
AC_STRUCT_TM
dnl ---------------------------------------------------------------------------
dnl Checks for library functions.
dnl ---------------------------------------------------------------------------
AC_FUNC_STRCOLL
AC_CHECK_FUNCS([strdup uname gethostname getdomainname \
	mktemp tmpnam tempnam \
	syslog dup2 setlocale])
dnl ---------------------------------------------------------------------------
dnl Checks for libraries
dnl ---------------------------------------------------------------------------
dnl Solaris 2.x: This requires -lnsl and -lsocket. If AC_PATH_XTRA
dnl              did not search for these, search them explicitly.
dnl              MUST be done BEFORE AC_PATH_XTRA!
dnl ---------------------------------------------------------------------------
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(nsl, t_accept)

dnl ---------------------------------------------------------------------------
dnl Check for X11 things
dnl ---------------------------------------------------------------------------
AC_PATH_X
AC_PATH_XTRA
if test "$no_x" != "yes"; then

	AH_TEMPLATE([HAS_X11LIBS],[
HAS_X11LIBS:
This symbol, if defined, indicates that the C program can use X11
directly.])
	AC_DEFINE(HAS_X11LIBS)
	AC_CHECK_LIB(X11, XMaxRequestSize,,,
		[-I ${ac_x_includes:-.} -L ${ac_x_libraries:-.}])
dnl	AC_CHECK_LIB(Xmu, XmuGetHostname,,,
dnl		[-I ${ac_x_includes:-.} -L ${ac_x_libraries:-.}])

fi
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([CPPSTDIN],[
CPPSTDIN:
This symbol contains the first part of the string which will invoke
the C preprocessor on the standard input and produce to standard
output.	 Typical value of "cc -E" or "/lib/cpp".])
EM_PATH_PROG_SEARCH(_CPPSTDIN, cpp, /lib /usr/lib /usr/lang \
	/usr/local/lang /usr/ccs/lib, [${CC} -E])
AC_DEFINE_UNQUOTED(CPPSTDIN, "$_CPPSTDIN")
dnl
AH_TEMPLATE([CPPMINUS],[
CPPMINUS:
This symbol contains the second part of the string which will invoke
the C preprocessor on the standard input and produce to standard
output.  This symbol will have the value "-" if CPPSTDIN needs a minus
to specify standard input, otherwise the value is "".])
AC_DEFINE(CPPMINUS, "")
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([PHOSTNAME],[
PHOSTNAME:
Last resort to get the hostname, if uname() and gethostname()
are not available.])
AC_PATH_PROG([_PHOST],[hostname],[""])
test "$_PHOST" != ""  && AC_DEFINE_UNQUOTED(PHOSTNAME, "$_PHOST")
AC_PATH_PROG(RUNTEST, runtest, "./not_installed")
test "$RUNTEST" = "" && echo "Install DEJAGNU and rerun configure if you \
want to run the testsuite"

dnl
dnl Here we define some --with & --enable things:
dnl
dnl --with-split-size[=<size>]	With split size=<size>		[TEST]
dnl --without-split-size	Without  - " -
dnl
dnl --enable-cache		With directory cache
dnl --disable-cache		Without  - " -			[DEF]
dnl
dnl --enable-shell-funcs	With sh functions		[TEST]
dnl --disable-shell-funcs	Without  - " -
dnl
dnl --enable-shell-alias	With sh aliases			[TEST]
dnl --disable-shell-alias	Without  - " -
dnl
dnl --enable-shell-eval		With shell alias eval
dnl --disable-shell-eval	Without  - " -			[DEF]
dnl
dnl --enable-free		With free() calls
dnl --disable-free		Without  - " -			[DEF]
dnl
dnl --with-debug[=<option>]	Set up debugging level
dnl --without-debug		Without  - " -			[DEF]
dnl
dnl --enable-version-magic      Set .version magic requirement	[DEF]
dnl --disable-version-magic     .version need not have magic cookie
dnl
dnl --enable-beginenv		Use .modulesbeginenv for initial env.	[TEST]
dnl --disable-beginenv		Do not use .modulesbeginenv
dnl
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([LMSPLIT_SIZE],[
LMSPLIT_SIZE:
This symbol, if defined, will force the environment variable
_LM_FILES_ to be split into smaller "chunks".])
AC_MSG_CHECKING([if /bin/csh supports large environment variables])
#
# test to see how many chars can be set in the C-shell env.var.
#
em_split_size_total=0
if test -x /bin/csh ; then
cat  >_EMEOF.$$ <<'_EMEOF'
cat <<'!' | /bin/csh 2> /dev/null | tail -1
setenv X	""
setenv ZZZ	"0"
@ num=2
while ( $num < 10000 )
	setenv X	$X$ZZZ
	echo $num
	@ num++
end
!
_EMEOF
em_split_size_total=`/bin/sh _EMEOF.$$`
rm _EMEOF.$$
fi
if test "$cross_compiling" = "yes"; then
	em_split_size="cross"
AC_MSG_WARN([You must specify --with-split-size[=<size>]
when cross compiling ... configure can not guess whether the target system
C-shell can handle large environment variables or not.])
elif test $em_split_size_total -gt 4000 ; then
	em_split_size="no"
	AC_MSG_RESULT([yes - $em_split_size_total > 4000])
else
	# set split-size a little less
	em_split_size=`expr $em_split_size_total - 20`
	if test $em_split_size -lt 0 ; then
		em_split_size=1000
	fi
	AC_MSG_RESULT([no - $em_split_size_total < 4000 - splitting at $em_split_size])
fi
AC_ARG_WITH(split-size,
	AC_HELP_STRING([--with-split-size[=<size>]],[use split size=<size> [[test]]]),
	if test "${withval+set}" = "set" -a "$withval" != "no"; then
		if test "$withval" = "yes"; then
			withval=1000
		fi
		AC_MSG_NOTICE([csh split-size set to $withval])
		AC_DEFINE_UNQUOTED(LMSPLIT_SIZE, ${withval})
	else
		AC_MSG_NOTICE([csh split-size not set])
	fi,
	if test "$em_split_size" != "no" -a "$em_split_size" != "cross" ; then
		AC_MSG_NOTICE([csh split-size set to $em_split_size])
		AC_DEFINE_UNQUOTED(LMSPLIT_SIZE, ${em_split_size})
	else
		AC_MSG_NOTICE([csh split-size not set])
	fi)
dnl ---------------------------------------------------------------------------
dnl --with-static[=<option>]	With static linking
dnl --without-static		Without  - " -		[DEF]
dnl STATIC		Link the binary 'static'
dnl
AC_SUBST(STATIC)
dnl
AC_ARG_WITH(static,
	AC_HELP_STRING([--with-static[[=<option>]]],[use static linking [[no]]]),
	EM_SET_STATIC(STATIC, $withval))

dnl ---------------------------------------------------------------------------
AH_TEMPLATE([HAS_BOURNE_FUNCS],[
HAS_BOURNE_FUNCS:
This symbol, if defined, indicates that the Bourne shell can define aliases
as shell functions.])
AC_MSG_CHECKING([if /bin/sh supports functions])

if test "$cross_compiling" = "yes"; then
	em_bourne_funcs="cross"
AC_MSG_WARN([You must specify --enable-shell-funcs or --disable-shell-funcs
when cross compiling ... configure can not guess whether the target system
Bourne shell can handle shell functions or not.])
elif (
	cat <<_EMEOF | /bin/sh 2> /dev/null
if (xxx() { ls; }) > /dev/null 2>&1; then
	(exit 0); exit 0
else
	(exit 42); exit 42
fi
_EMEOF
	 
	if test $? = 0 ; then
		(exit 0); exit 0
	else
		(exit 42); exit 42
	fi
) ; then
	em_bourne_funcs="yes"
else
	em_bourne_funcs="no"
fi
AC_MSG_RESULT([$em_bourne_funcs])
AC_ARG_ENABLE(shell-funcs,
	AC_HELP_STRING([--enable-shell-funcs],[use sh functions [[test]]]),
	if test "$enableval" = "yes" ; then
	    AC_DEFINE(HAS_BOURNE_FUNCS)
	fi,
	if test "$em_bourne_funcs" = "cross" ; then
AC_MSG_ERROR([You did not --enable-shell-funcs or --disable-shell-funcs
when cross compiling ... aborting!])
	elif test "$em_bourne_funcs" = "yes" ; then
	    AC_DEFINE(HAS_BOURNE_FUNCS)
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([HAS_BOURNE_ALIAS],[
HAS_BOURNE_ALIAS:
This symbol, if defined, indicates that the Bourne shell can define aliases
(in other words not a "true" Bourne shell).])
AC_MSG_CHECKING([if /bin/sh supports aliases])

if test "$cross_compiling" = "yes"; then
	em_bourne_alias="cross"
AC_MSG_WARN([You must specify --enable-shell-alias or --disable-shell-alias
when cross compiling ... configure can not guess whether the target system
Bourne shell can handle shell aliases or not.])
elif (
	cat <<_EMEOF | /bin/sh 2> /dev/null
if (alias xxx='ls') > /dev/null 2>&1; then
	(exit 0); exit 0
else
	(exit 42); exit 42
fi
_EMEOF
	 
	if test $? = 0 ; then
		(exit 0); exit 0
	else
		(exit 42); exit 42
	fi
) ; then
	em_bourne_alias="yes"
else
	em_bourne_alias="no"
fi
AC_MSG_RESULT([$em_bourne_alias])
AC_ARG_ENABLE(shell-alias,
	AC_HELP_STRING([--enable-shell-alias],[use sh aliases [[test]]]),
	if test "$enableval" = "yes" ; then
	    AC_DEFINE(HAS_BOURNE_ALIAS)
	fi,
	if test "$em_bourne_alias" = "cross" ; then
AC_MSG_ERROR([You did not --enable-shell-alias or --disable-shell-alias
when cross compiling ... aborting!])
	elif test "$em_bourne_alias" = "yes" ; then
	    AC_DEFINE(HAS_BOURNE_ALIAS)
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([EVAL_ALIAS],[
EVAL_ALIAS:
This symbol, if defined, indicates that Modules should ask the shell
to evaluate aliases via stdout like other environment changes instead
of opening a file and then asking the shell to source the file and
then remove it.])
AC_ARG_ENABLE(shell-eval,
	AC_HELP_STRING([--enable-shell-eval],[use shell alias eval [[yes]]]),
	if test "$enableval" = "yes"; then
	    AC_DEFINE(EVAL_ALIAS)
	fi, AC_DEFINE(EVAL_ALIAS))
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([USE_FREE],[
USE_FREE:
By default, Modules will not call free() for any dynamic data. This
define enables these calls.])
AC_ARG_ENABLE(free,
	AC_HELP_STRING([--enable-free],[use free() calls [[no]]]),
	if test "$enableval" = "yes"; then
	    AC_DEFINE(USE_FREE)
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([CACHE_AVAIL],[
CACHE_AVAIL:
This symbol, if defined, indicates that Modules should cache the
directories in MODULEPATH when doing an avail.])
AC_ARG_ENABLE(cache,
	AC_HELP_STRING([--enable-cache],[use directory cache [[no]]]),
	if test "$enableval" = "yes"; then
	    AC_DEFINE(CACHE_AVAIL)
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([CACHE_UMASK],[
CACHE_UMASK:
This symbol, if defined, is used as the umask for creating
cachefiles for the module avail command.])
AC_ARG_WITH(cache-umask,
	AC_HELP_STRING([--with-cache-umask=<umask>],[use cache files umask=<umask> [[000]]]),
	if test "$withval" != "no"; then
	    test "$withval" = "yes" && withval=0
	    AC_DEFINE_UNQUOTED(CACHE_UMASK, ${withval})
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([WITH_DEBUG_INFO],[WITH_DEBUG_INFO: Debug info level if defined])
AC_ARG_WITH(debug,
	AC_HELP_STRING([--with-debug=<value>],[set debugging level <value> [[no]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="1"
		AC_DEFINE_UNQUOTED(WITH_DEBUG_INFO, ${withval})
	fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([VERSION_MAGIC],[
VERSION_MAGIC:
By default, .version files will be required to have the modulefile
magic cookie to be valid, else an error message will be printed out.])
AC_ARG_ENABLE(version-magic,
	AC_HELP_STRING([--enable-version-magic],[set .version magic requirement  [[yes]]]),
	if test "$enableval" != "no"; then
		AC_DEFINE(VERSION_MAGIC,1)
	else
		AC_DEFINE(VERSION_MAGIC,0)
	fi, AC_DEFINE(VERSION_MAGIC,1))
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([BEGINENV],[
BEGINENV:
Modules can save the initial user environment in the .modulesbeginenv
when the first module is loaded.  If enabled then the module update
subcommand will work.  If set to test, then this essentially enables
this feature, but will only work if the MODULESBEGINENV env.var is
set to a file name (e.g. '$HOME/.modulesbeginenv.$$'- modules will
do one-level of variable expansion.)])
AC_ARG_ENABLE(beginenv,
	AC_HELP_STRING([--enable-beginenv],[use .modulesbeginenv for initial env [[test]]]),
	if test "$enableval" = "yes"; then
		AC_DEFINE(BEGINENV,1)
	elif test "$enableval" = "test"; then
		AC_DEFINE(BEGINENV,99)
	fi, AC_DEFINE(BEGINENV,99))
dnl ---------------------------------------------------------------------------
dnl  Logging
dnl  The following option allow switching logging on and off
dnl  and provide a possibility to set up the default facilities
dnl ---------------------------------------------------------------------------
dnl WITH_LOGGING	Whether syslogging is enabled
dnl
AC_SUBST(WITH_LOGGING)
AH_TEMPLATE([WITH_LOGGING],[WITH_LOGGING: Syslog logging and facilities])
AH_TEMPLATE([WITH_LOG_DIR],[])
AH_TEMPLATE([WITH_LOG_FACILITY_VERBOSE],[])
AH_TEMPLATE([WITH_LOG_FACILITY_INFO],[])
AH_TEMPLATE([WITH_LOG_FACILITY_DEBUG],[])
AH_TEMPLATE([WITH_LOG_FACILITY_TRACE],[])
AH_TEMPLATE([WITH_LOG_FACILITY_WARN],[])
AH_TEMPLATE([WITH_LOG_FACILITY_PROB],[])
AH_TEMPLATE([WITH_LOG_FACILITY_ERROR],[])
AH_TEMPLATE([WITH_LOG_FACILITY_FATAL],[])
AH_TEMPLATE([WITH_LOG_FACILITY_PANIC],[])
WITH_LOGGING=0
AC_ARG_ENABLE(logging,
	AC_HELP_STRING([--enable-logging],[turn logging on                 [[no]]]),
	if test "$enableval" = "yes"; then
		AC_DEFINE(WITH_LOGGING)
		WITH_LOGGING=1
	fi)
AC_ARG_WITH(log-dir,
	AC_HELP_STRING([--with-log-dir=<value>],[select an alternate log dir.  [[no]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="/tmp"
		AC_DEFINE_UNQUOTED(WITH_LOG_DIR, "$withval")
	fi)
AC_ARG_WITH(log-facility-verbose,
	AC_HELP_STRING([--with-log-facility-verbose[=<facility>]],[Log facility    [[stderr]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="stderr"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_VERBOSE, "$withval")
	fi)
AC_ARG_WITH(log-facility-info,
	AC_HELP_STRING([--with-log-facility-info[=<facility>]],[Log facility    [[local7.notice]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.notice"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_INFO, "$withval")
	fi)
AC_ARG_WITH(log-facility-debug,
	AC_HELP_STRING([--with-log-facility-debug[=<facility>]],[Log facility    [[local7.notice]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.notice"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_DEBUG, "$withval")
	fi)
AC_ARG_WITH(log-facility-trace,
	AC_HELP_STRING([--with-log-facility-trace[=<facility>]],[Log facility    [[local7.notice]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.notice"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_TRACE, "$withval")
	fi)
AC_ARG_WITH(log-facility-warn,
	AC_HELP_STRING([--with-log-facility-warn[=<facility>]],[Log facility    [[local7.warning]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.warning"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_WARN, "$withval")
	fi)
AC_ARG_WITH(log-facility-problem,
	AC_HELP_STRING([--with-log-facility-problem[=<facility>]],[Log facility    [[local7.error]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.error"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_PROB, "$withval")
	fi)
AC_ARG_WITH(log-facility-error,
	AC_HELP_STRING([--with-log-facility-error[=<facility>]],[Log facility    [[local7.error]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.error"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_ERROR, "$withval")
	fi)
AC_ARG_WITH(log-facility-fatal,
	AC_HELP_STRING([--with-log-facility-fatal[=<facility>]],[Log facility    [[local7.error]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.error"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_FATAL, "$withval")
	fi)
AC_ARG_WITH(log-facility-panic,
	AC_HELP_STRING([--with-log-facility-panic[=<facility>]],[Log facility    [[local7.error]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval="local7.error"
		AC_DEFINE_UNQUOTED(WITH_LOG_FACILITY_PANIC, "$withval")
	fi)
dnl ---------------------------------------------------------------------------
dnl  Tracing
dnl  The following option allow switching tracing on and off on a
dnl  per module command basis
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([WITH_TRACE_LOAD],[Tracking])
AH_TEMPLATE([WITH_TRACE_UNLOAD],[])
AH_TEMPLATE([WITH_TRACE_SWITCH],[])
AH_TEMPLATE([WITH_TRACE_DISP],[])
AH_TEMPLATE([WITH_TRACE_LIST],[])
AH_TEMPLATE([WITH_TRACE_AVAIL],[])
AH_TEMPLATE([WITH_TRACE_HELP],[])
AH_TEMPLATE([WITH_TRACE_INIT],[])
AH_TEMPLATE([WITH_TRACE_USE],[])
AH_TEMPLATE([WITH_TRACE_UNUSE],[])
AH_TEMPLATE([WITH_TRACE_UPDATE],[])
AH_TEMPLATE([WITH_TRACE_PURGE],[])
AH_TEMPLATE([WITH_TRACE_CLEAR],[])
AH_TEMPLATE([WITH_TRACE_WHATIS],[])
AH_TEMPLATE([WITH_TRACE_APROPOS],[])

AC_ARG_WITH(trace-load,
	AC_HELP_STRING([--with-trace-load=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_LOAD, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_LOAD, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-unload,
	AC_HELP_STRING([--with-trace-unload=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_UNLOAD, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_UNLOAD, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-switch,
	AC_HELP_STRING([--with-trace-switch=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_SWITCH, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_SWITCH, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-disp,
	AC_HELP_STRING([--with-trace-disp=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_DISP, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_DISP, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-list,
	AC_HELP_STRING([--with-trace-list=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_LIST, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_LIST, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-avail,
	AC_HELP_STRING([--with-trace-avail=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_AVAIL, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_AVAIL, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-help,
	AC_HELP_STRING([--with-trace-help=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_HELP, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_HELP, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-init,
	AC_HELP_STRING([--with-trace-init=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_INIT, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_INIT, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-use,
	AC_HELP_STRING([--with-trace-use=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_USE, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_USE, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-unuse,
	AC_HELP_STRING([--with-trace-unuse=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_UNUSE, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_UNUSE, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-update,
	AC_HELP_STRING([--with-trace-update=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_UPDATE, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_UPDATE, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-purge,
	AC_HELP_STRING([--with-trace-purge=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_PURGE, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_PURGE, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-clear,
	AC_HELP_STRING([--with-trace-clear=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_CLEAR, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_CLEAR, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-whatis,
	AC_HELP_STRING([--with-trace-whatis=<value>],[specify a pattern for trace   [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_WHATIS, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_WHATIS, "$withval")
		fi
	fi)
AC_ARG_WITH(trace-apropos,
	AC_HELP_STRING([--with-trace-apropos=<value>],[specify a pattern for trace  [[no]]]),
	if test "$withval" != "no"; then
		if test "$withval" = "yes"; then
			AC_DEFINE_UNQUOTED(WITH_TRACE_APROPOS, _all_on)
		else
			AC_DEFINE_UNQUOTED(WITH_TRACE_APROPOS, "$withval")
		fi
	fi)
dnl ---------------------------------------------------------------------------
dnl Find libraries, functions and special programs
dnl	The dynamic loader library should only be probed for, if
dnl	static linking is not switched on!
dnl ---------------------------------------------------------------------------
AC_CHECK_LIB(m, log)
if test "${STATIC-foobar}" = "foobar"; then
    AC_CHECK_LIB(dl, dlopen)
fi

dnl
dnl--------------------------------------------------------------------
dnl Load the tclConfig.sh file
dnl--------------------------------------------------------------------

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG
EM_SET_TCL
EM_CHECK_TCL

dnl--------------------------------------------------------------------
dnl Load the tclxConfig.sh file
dnl search for tclx after tcl, not before, to benefit from tcl_includes
dnl--------------------------------------------------------------------

EM_PATH_TCLXCONFIG
EM_LOAD_TCLXCONFIG
dnl Skip TclX fine tuned selection if TclX not wanted
if test x"$with_tclxconfig" != x"no" ; then
    EM_SET_TCLX
    EM_CHECK_TCLX
fi
if test x"$no_tclx" != x"true"; then
	AH_TEMPLATE([HAS_TCLXLIBS],[
HAS_TCLXLIBS:
This symbol, if defined, indicates that Modules should support
extended TCL (tclX) commands.])
	AC_DEFINE(HAS_TCLXLIBS)
fi

dnl --------------------------------------------------------------------
dnl Find Python interpreter
dnl --------------------------------------------------------------------
AC_ARG_WITH(python,
	AC_HELP_STRING([--with-python=<bin>],[Python interpreter command to use [[python]]]),
	[python="$withval"], [python="python"])
# specified python is full path bin or uses env command
if test x"$python" = x"/usr/bin/env python" || test -x "$python" ; then
    AC_MSG_CHECKING([for $python])
    PYTHON="$python"
    AC_MSG_RESULT([yes])
# otherwise search for python bin in PATH
else
    AC_PATH_PROG([PYTHON],[$python],[])
fi
dnl Python is mandatory if installing from git repository to build ChangeLog
if test -z "$PYTHON" ; then
    if test -e ChangeLog ; then
        PYTHON="/usr/bin/env python"
    else
        AC_MSG_ERROR([Python command cannot be found, whereas required to build ChangeLog.])
    fi
fi

dnl ---------------------------------------------------------------------------
dnl
dnl   --with-module-path
dnl   --with-version-path
dnl   --with-tmp-dir
dnl   --with-autoload-path
dnl
dnl ---------------------------------------------------------------------------
dnl MODULEPATH		The modulepath we want
dnl
AC_SUBST(MODULEPATH)
AH_TEMPLATE([MODULEPATH],[
MODULEPATH: Directory that contains all the system module files])
AC_ARG_WITH(module-path,
	AC_HELP_STRING([--with-module-path=<path>],[use module path=<path> [[PREFIX/Modules/modulefiles]]]),
	MODULEPATH="$withval"
	AC_MSG_RESULT([MODULEPATH = $with_module_path])
	AC_DEFINE_UNQUOTED(MODULEPATH, "$withval")
	,
dnl 	AC_MSG_WARN([if using '--with-module-path': need to specify a path!])
	withval="$BASEPREFIX/Modules/modulefiles"
	AC_MSG_WARN([will use MODULEPATH=$withval : rerun configure using --with-module-path to override default])
	MODULEPATH="$withval"
	AC_DEFINE_UNQUOTED(MODULEPATH, "$withval"))
dnl ---------------------------------------------------------------------------
dnl VERSIONPATH		The modulepath different versions of modules
dnl
AC_SUBST(VERSIONPATH)
AH_TEMPLATE([VERSIONPATH],[
VERSIONPATH: Directory that contains the env.modules version files.])
AC_ARG_WITH(version-path,
	AC_HELP_STRING([--with-version-path=<path>],[use version path=<path> [[PREFIX/Modules/versions]]]),
	VERSIONPATH="$withval"
	AC_MSG_RESULT([VERSIONPATH = $with_version_path])
	AC_DEFINE_UNQUOTED(VERSIONPATH, "$withval")
	,
if test "$WANTS_VERSIONING" -eq 1 ; then
dnl AC_MSG_WARN([if using '--with-version-path': need to specify a path!])
	withval="$BASEPREFIX/Modules/versions"
	AC_MSG_WARN([will use VERSIONPATH=$withval : rerun configure using --with-version-path to override default])
	VERSIONPATH="$withval"
	AC_DEFINE_UNQUOTED(VERSIONPATH, "$withval")
fi)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([TMP_DIR],[TMP_DIR: tmp directory name])
AC_ARG_WITH(tmp-dir,
	AC_HELP_STRING([--with-tmp-dir=<dir>],[use <dir> as a temporary dir [[/tmp]]]),
        if test ! -d $withval ; then
           AC_MSG_ERROR([tmp dir $withval does not exist])
        fi
	AC_DEFINE_UNQUOTED(TMP_DIR, "$withval")
	AC_MSG_RESULT([TMP_DIR = $withval]),
        if test -d "/tmp" ; then
           AC_DEFINE_UNQUOTED(TMP_DIR, "/tmp")
        elif test -d "/var/tmp" ; then
           AC_DEFINE_UNQUOTED(TMP_DIR, "/var/tmp")
        fi
	)
dnl ---------------------------------------------------------------------------
AH_TEMPLATE([DEFAULTMANPATH],[DEFAULTMANPATH: default man path])
AC_ARG_WITH(man-path,
	AC_HELP_STRING([--with-man-path=<dir>],[use <dir> for the default MANPATH [[/usr/man:/usr/share/man]]]),
	AC_DEFINE_UNQUOTED(DEFAULTMANPATH, "$withval")
	AC_MSG_RESULT([DEFAULTMANPATH = $withval]),
        if test -d "/usr/man" ; then
           withval="/usr/man"
           if test -d "/usr/share/man" ; then
               withval="$withval:/usr/share/man"
	   fi
        elif test -d "/usr/share/man" ; then
           withval="/usr/share/man"
        fi
        AC_DEFINE_UNQUOTED(DEFAULTMANPATH, "$withval")
	)
	AC_MSG_RESULT([DEFAULTMANPATH = $withval])
dnl ---------------------------------------------------------------------------
dnl AUTOLOADPATH	directories where Tcl will search for libraries to load
dnl
AC_SUBST(AUTOLOADPATH)
AH_TEMPLATE([AUTOLOADPATH],[
AUTOLOADPATH:
This symbol, if defined, is the "default" path of directories
Tcl will look for functions to autoload.  It is space separated!])
AC_ARG_WITH(autoload-path,
	AC_HELP_STRING([--with-autoload-path=<path>],[use autoload path=<path> [[PREFIX/lib/tcl]]]),
	if test "$withval" = "no" || test "$withval" = "yes"; then
		if test "$prefix" != "NONE" ; then
			withval="$prefix/lib/tcl"
		else
			withval="$ac_default_prefix/lib/tcl"
		fi
	fi
	AUTOLOADPATH="$withval"
	AC_DEFINE_UNQUOTED(AUTOLOADPATH, "$withval"))
dnl ---------------------------------------------------------------------------
dnl   --with-etc-path
dnl   --with-skel-path
dnl   --with-dot-ext
dnl ---------------------------------------------------------------------------
dnl ETCPATH		Where to find the /etc/"login" files
dnl
AC_SUBST(ETCPATH)
AC_ARG_WITH(etc-path,
	AC_HELP_STRING([--with-etc-path=<path>],[use etc path=<path> [[/etc]]]),
	[if test "$withval" = "no" || test "$withval" = "yes"; then
		AC_MSG_WARN(
	[if using '--with-etc-path': need to specify a path! Using /etc])
		withval="/etc"
	fi
	ETCPATH="$withval"]
	,
	ETCPATH="/etc")
dnl ---------------------------------------------------------------------------
dnl SKELPATH		Where to find the $HOME/dot file skeletons
dnl
AC_SUBST(SKELPATH)
AC_ARG_WITH(skel-path,
	AC_HELP_STRING([--with-skel-path=<path>],[use skel path=<path> [[/etc/skel]]]),
	if test "$withval" = "no" || test "$withval" = "yes"; then
	AC_MSG_WARN([if using '--with-skel-path': need to specify a path! Using /etc/skel])
		withval="/etc/skel"
	fi
	SKELPATH="$withval"
	,
	SKELPATH="/etc/skel")
dnl ---------------------------------------------------------------------------
dnl DOT_EXT		Whether to use a dot-file extension
dnl EXTDIR		Which add.* script to include
dnl
AC_SUBST(DOT_EXT)
AC_SUBST(EXTDIR)
AH_TEMPLATE([DOT_EXT],[
DOT_EXT:
Set this to some extension value (e.g. .ext) to be appended onto
each shell dot-file name in the list for each shell for processing
the "module init*" commands.  For example - C-shell: .cshrc.ext,
.login.ext.])
AC_ARG_WITH(dot-ext,
	AC_HELP_STRING([--with-dot-ext=<.ext>],[append <.ext> (default=.ext) to shell dot files [[no]]]),
	if test "$withval" != "no"; then
		test "$withval" = "yes" && withval=".ext"
		AC_DEFINE_UNQUOTED(DOT_EXT, "$withval")
		EXTDIR="ext"
	else
		AC_DEFINE(DOT_EXT, "")
		EXTDIR="etc"
	fi,
	AC_DEFINE(DOT_EXT, "")
	EXTDIR="etc"
)
dnl ---------------------------------------------------------------------------
dnl helpful configure --help comments
m4_divert_once([HELP_WITH],[[

The default value or disposition is listed in the square brackets above.
Beware of new defaults for use-cache, beginenv.

Depending on the above configuration options  the files are approximately
placed in the following directory structure :
PREFIX/Modules/($MODULES_VERSION/ if modules-versioning)
	bin/
	init/
	man/
		man1/
		man4/
	modulefiles/
PREFIX/Modules/
	modulefiles/
	(versions/ if modules-versioning)

System modulefiles can safely be placed in:
PREFIX/Modules/modulefiles
]])
dnl ---------------------------------------------------------------------------
dnl Now put it all out!
dnl ---------------------------------------------------------------------------
AC_CONFIG_FILES([Makefile modules.lsm .spec doc/Makefile
	init/Makefile init/.modulespath
	doc/module.1 doc/modulefile.4
	etc/Makefile etc/add.modules etc/mkroot
	etc/skel/.cshrc etc/skel/.login 
	etc/skel/.kshenv etc/skel/.profile 
	etc/global/csh.cshrc etc/global/csh.login etc/global/csh.modules
	etc/global/bashrc etc/global/profile etc/global/profile.modules
	ext/Makefile ext/add.ext ext/mkroot
	ext/common/.cshrc ext/common/.login 
	ext/common/.kshenv ext/common/.profile 
	modulefiles/Makefile modulefiles/modules
	modulefiles/module-git modulefiles/module-info modulefiles/null
	modulefiles/use.own modulefiles/dot modulefiles/version
	])
AC_CONFIG_FILES([gitlog2changelog.py], [chmod +x gitlog2changelog.py])
dnl We want these to be recreated for each install
dnl	init/bash init/csh init/ksh init/perl.pm init/python.py init/sh init/zsh
AC_CONFIG_COMMANDS([default],[[date > stamp-h]],[[]])
AC_OUTPUT
dnl
