dnl Process this file with autoconf to produce a configure script.

dnl NOTES:
dnl * As of 1.34, we no longer use and test for "nope" to indicate
dnl   an empty variable.  Instead, we use `VAR=' (set the variable
dnl   to nothing) and `test -z "$VAR"' or `test -n "$VAR"' as the
dnl   case may be.  --ttn, 2000/08/04 12:11:26

AC_INIT
AC_CONFIG_SRCDIR([Include/wad.h])
AC_PREREQ(2.53)

# Set name for machine-dependent library files
AC_SUBST(MACHDEP)
AC_MSG_CHECKING(MACHDEP)
if test -z "$MACHDEP"
then
	if test -f /usr/lib/NextStep/software_version; then
		set X `hostinfo | grep 'NeXT Mach.*:' | \
			sed -e 's/://' -e 's/\./_/'` && \
		ac_sys_system=next && ac_sys_release=$4
		MACHDEP="$ac_sys_system$ac_sys_release$ac_sys_cpu"
	else
		ac_sys_system=`uname -s`
		if test "$ac_sys_system" = "AIX" ; then
			ac_sys_release=`uname -v`
		else
			ac_sys_release=`uname -r`
		fi
		ac_md_system=`echo $ac_sys_system |
				   tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
		ac_md_release=`echo $ac_sys_release |
				   tr -d '[/ ]' | sed 's/\..*//'`
		MACHDEP="$ac_md_system$ac_md_release"
	fi
	case MACHDEP in
	'')	MACHDEP=unknown;;
	esac
fi
AC_MSG_RESULT($MACHDEP)

AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB

dnl Checks for programs.

AC_SUBST(AR)
AC_CHECK_PROGS(AR, ar aal, ar)

dnl Checks for header files.
AC_HEADER_STDC
dnl Checks for library functions.

# Set info about shared libraries.
AC_SUBST(SO)
AC_SUBST(LDSHARED)
AC_SUBST(CCSHARED)

# SO is the extension of shared libraries `(including the dot!)
# -- usually .so, .sl on HP-UX
AC_MSG_CHECKING(SO)
if test -z "$SO"
then
	case $ac_sys_system in
	hp*|HP*)   SO=.sl;;
	*)	   SO=.so;;
	esac
fi
AC_MSG_RESULT($SO)

# WAD Options
AC_SUBST(WADOPT)
AC_MSG_CHECKING(WADOPT)
if test -z "$WADOPT"
then
	case $ac_sys_system/$ac_sys_release in
	SunOS/5*) WADOPT="-DWAD_SOLARIS";;
	Linux*) WADOPT="-DWAD_LINUX";;
	*)	WADOPT="-DWAD_UNKWOWN";;
	esac
fi
AC_MSG_RESULT($WADOPT)


# LDSHARED is the ld *command* used to create shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
# (Shared libraries in this instance are shared modules to be loaded into
# Python, as opposed to building Python itself as a shared library.)
AC_MSG_CHECKING(LDSHARED)
if test -z "$LDSHARED"
then
	case $ac_sys_system/$ac_sys_release in
	AIX*) LDSHARED="\$(srcdir)/ld_so_aix \$(CC)";;
	IRIX/5*) LDSHARED="ld -shared";;
	IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";;
	SunOS/4*) LDSHARED="ld";;
	SunOS/5*) LDSHARED="ld -G";;
	hp*|HP*) LDSHARED="ld -b";;
	OSF*) LDSHARED="ld -shared -expect_unresolved \"*\"";;
	DYNIX/ptx*) LDSHARED="ld -G";;
	next/*)
		if test "$ns_dyld"
		then LDSHARED='$(CC) $(LDFLAGS) -bundle -prebind'
		else LDSHARED='$(CC) $(CFLAGS) -nostdlib -r';
		fi
                if test "$with_next_framework" ; then
		    LDSHARED="$LDSHARED \$(LDLIBRARY)"
		fi ;;
	Linux*) LDSHARED="gcc -shared";;
	dgux*) LDSHARED="ld -G";;
	FreeBSD*/3*) LDSHARED="gcc -shared";;
	FreeBSD*|OpenBSD*) LDSHARED="ld -Bshareable";;
	NetBSD*)
		if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
		then
			LDSHARED="cc -shared"
		else
			LDSHARED="ld -Bshareable"
		fi;;
	SCO_SV*) LDSHARED="cc -G -KPIC -Ki486 -belf -Wl,-Bexport";;
	*)	LDSHARED="ld";;
	esac
fi
AC_MSG_RESULT($LDSHARED)


# CXXSHARED is the C++ *command* used to create shared library
AC_SUBST(CXXLINK)

AC_MSG_CHECKING(CXXLINK)
if test -z "$CXXLINK"
then
	case $ac_sys_system/$ac_sys_release in
	SunOS/5*) if test "$GCC" = yes;
             then CXXLINK="g++ -shared";
             else CXXLINK="CC -G";
             fi;;
	Linux*) CXXLINK="g++ -shared";;
	*)	CXXLINK="g++";;
	esac
fi
AC_MSG_RESULT($CXXLINK)

# CCSHARED are the C *flags* used to create objects to go into a shared
# library (module) -- this is only needed for a few systems
AC_MSG_CHECKING(CCSHARED)
if test -z "$CCSHARED"
then
	case $ac_sys_system/$ac_sys_release in
	hp*|HP*) if test "$GCC" = yes;
		 then CCSHARED="-fpic";
		 else CCSHARED="+z";
		 fi;;
	Linux*) CCSHARED="-fpic";;
	FreeBSD*|OpenBSD*) CCSHARED="-fpic";;
	NetBSD*) CCSHARED="-fPIC";;
	SCO_SV*) CCSHARED="-KPIC -dy -Bdynamic";;
	IRIX*/6*)  case $CC in
		   *gcc*) CCSHARED="-shared";;
		   *) CCSHARED="";;
		   esac;;
	esac
fi
AC_MSG_RESULT($CCSHARED)

AC_SUBST(CXXSHARED)
# CCSHARED are the C *flags* used to create objects to go into a shared
# library (module) -- this is only needed for a few systems
AC_MSG_CHECKING(CXXSHARED)
if test -z "$CXXSHARED"
then
	case $ac_sys_system/$ac_sys_release in
	Linux*) CXXSHARED="-fpic";;
	SunOS/5*) if test "$GCC" = yes;
             then CXXSHARED="-fpic";
             else CXXSHARED="-Kpic";
             fi;;
	esac
fi
AC_MSG_RESULT($CXXSHARED)

# RPATH is the path used to look for shared library files.
AC_MSG_CHECKING(RPATH)
if test -z "$RPATH"
then
	case $ac_sys_system/$ac_sys_release in
	SunOS/5*) RPATH="\"-R\"";;
	Linux*) RPATH="-Xlinker -rpath ";;
	*)	RPATH="";;
	esac
fi
AC_MSG_RESULT($RPATH)
AC_SUBST(RPATH)

#--------------------------------------------------------------------
#	Try to locate the Tcl package
#--------------------------------------------------------------------

TCLINCLUDE=
TCLLIB=
TCLPACKAGE=
MAKETCL=

AC_ARG_WITH(tcl,[  --with-tcl=path         Set location of Tcl package],[
	TCLPACKAGE="$withval"], [TCLPACKAGE=])
AC_ARG_WITH(tclincl,[  --with-tclincl=path     Set location of Tcl include directory],[
	TCLINCLUDE="-I$withval"], [TCLINCLUDE=])
AC_ARG_WITH(tcllib,[  --with-tcllib=path      Set location of Tcl library directory],[
	TCLLIB="-L$withval"], [TCLLIB=])

if test -z "$TCLINCLUDE"; then
   if test -n "$TCLPACKAGE"; then
	TCLINCLUDE="-I$TCLPACKAGE/include"
   fi
fi

if test -z "$TCLLIB"; then
   if test -n "$TCLPACKAGE"; then
	TCLLIB="-L$TCLPACKAGE/lib"
   fi
fi

AC_MSG_CHECKING(for Tcl header files)
if test -z "$TCLINCLUDE"; then
AC_TRY_CPP([#include <tcl.h>], , TCLINCLUDE="")
if test -z "$TCLINCLUDE"; then
	dirs="$prefix/include /usr/local/include /usr/include /opt/local/include /home/sci/local/include"
	for i in $dirs ; do
		if test -r $i/tcl.h; then
			AC_MSG_RESULT($i)
			TCLINCLUDE="-I$i"
			MAKETCL="tcl"
			break
		fi
	done
fi
if test -z "$TCLINCLUDE"; then
	TCLINCLUDE=""
	MAKETCL=""
    	AC_MSG_RESULT(not found)
fi
else
        AC_MSG_RESULT($TCLINCLUDE)
fi

AC_SUBST(TCLINCLUDE)
AC_SUBST(MAKETCL)

#----------------------------------------------------------------
# Look for Python
#----------------------------------------------------------------

PYINCLUDE=
MAKEPYTHON=
PYLIB=
PYPACKAGE=

AC_ARG_WITH(py,[  --with-py=path          Set location of Python],[
	PYPACKAGE="$withval"], [PYPACKAGE=])
AC_ARG_WITH(pyincl,[  --with-pyincl=path      Set location of Python include directory],[
	PYINCLUDE="$withval"], [PYINCLUDE=])
AC_ARG_WITH(pylib,[  --with-pylib=path       Set location of Python library directory],[
	PYLIB="$withval"], [PYLIB=])

if test -z "$PYINCLUDE"; then
   if test -n "$PYPACKAGE"; then
	PYINCLUDE="$PYPACKAGE/include"
   fi
fi

if test -z "$PYLIB"; then
   if test -n "$PYPACKAGE"; then
	PYLIB="$PYPACKAGE/lib"
   fi
fi


AC_MSG_CHECKING(for Python header files)

dirs="$PYINCLUDE $PYINCLUDE/python2.0 $PYINCLUDE/python1.6 $PYINCLUDE/python1.5 $prefix/include/python2.0 $prefix/include/python1.6 $prefix/include/python1.5 /usr/local/include/python2.0 /usr/local/include/python1.6 /usr/local/include/python1.5 /usr/include/python1.5" 
for i in $dirs ; do
	if test -r $i/Python.h; then
		AC_MSG_RESULT($i)
		PYINCLUDE="-I$i"
		MAKEPYTHON="python"
		break
	fi
done
if test -z "$PYINCLUDE"; then
	PYINCLUDE=""
	MAKEPYTHON=""
    	AC_MSG_RESULT(not found)
fi

AC_SUBST(PYINCLUDE)
AC_SUBST(PYLINK)
AC_SUBST(MAKEPYTHON)

#----------------------------------------------------------------
# Look for Perl5
#----------------------------------------------------------------

PERLBIN=
MAKEPERL=

AC_ARG_WITH(perl5,[  --with-perl5=path       Set location of Perl5 executable],[ PERLBIN="$withval"], [PERLBIN=])

# First figure out what the name of Perl5 is

if test -z "$PERLBIN"; then
AC_CHECK_PROGS(PERL, perl5.004 perl5.003 perl5.002 perl5.001 perl5 perl)
else
PERL="$PERLBIN"
fi
AC_MSG_CHECKING(for Perl5 header files)
if test -n "$PERL"; then
	PERL5DIR=`($PERL -e 'use Config; print $Config{archlib};') 2>/dev/null`
	if test "$PERL5DIR" != ""; then
		dirs="$PERL5DIR $PERL5DIR/CORE"
		PERL5EXT=none
		for i in $dirs; do
			if test -r $i/perl.h; then
				AC_MSG_RESULT($i)
				PERL5EXT="-I$i"
				MAKEPERL="perl"
				break;
			fi
		done
		if test "$PERL5EXT" = none; then
			PERL5EXT=""
			MAKEPERL=""
			AC_MSG_RESULT(could not locate perl.h...using $PERL5EXT)
		fi
	else
		AC_MSG_RESULT(unable to determine perl5 configuration)
		PERL5EXT=""
		MAKEPERL=""
	fi
    else
       	AC_MSG_RESULT(could not figure out how to run perl5)
	PERL5EXT=""
	MAKEPERL=""
    fi

AC_SUBST(PERL5EXT)
AC_SUBST(MAKEPERL)

dnl We use the following in `AC_CONFIG_FILES' and "make distclean".
configure_substituted_files=`echo	\
    Wad/Makefile			\
    Python/Makefile    \
    Tcl/Makefile \
    Test/Makefile  \
    Prebuilt/linux/Makefile \
    Prebuilt/solaris/Makefile \
    Makefile				\
`
AC_SUBST(configure_substituted_files)

AC_CONFIG_FILES([$configure_substituted_files])
AC_OUTPUT

dnl configure.in ends here

