
#--------------------------------------------------------------------
# Sample configure.in for Tcl Extensions.  The only places you should
# need to modify this file are marked by the string __CHANGE__
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# __CHANGE__
# This very first macro is used to verify that the configure script can 
# find the sources.  The argument to AC_INIT should be a unique filename
# for this package, and can be a relative path, such as:
#
#--------------------------------------------------------------------
define(XOTclVersion, 1.2.0)

AC_INIT(XOTcl, XOTclVersion)

AC_CONFIG_AUX_DIR(../config)
# m4_pattern_allow(LIBOBJS)

AC_ARG_WITH(gdbm,
        [  --with-gdbm=GDBM_INCLUDE_DIR[,GDBM_LIB_DIR]
            absolute path to gdbm.h and optionally the path to the library, 
           --without-gdbm disables build of Tcl Gdbm],
        [with_gdbm=$withval], [with_gdbm=no])
AC_ARG_WITH(actiweb,
        [  --with-actiweb=yes|no,
           --without-actiweb disables actiweb components],
        [with_actiweb=$withval], [with_actiweb=no])
AC_ARG_WITH(xotclsh,
        [  --with-xotclsh=yes|no,
	   --without-xotclsh disables built of xotclsh],
        [with_xotclsh=$withval], [with_xotclsh=no])
AC_ARG_WITH(xowish,
        [  --with-xowish=yes|no,
	   --without-xowish disables built of xowish],
        [with_xowish=$withval], [with_xowish=no])
AC_ARG_WITH(all,
        [  --with-all=yes|no,
	   --without-all disables built of all],
        [with_all=$withval], [with_all=no])
AC_ARG_WITH(all,
        [  --with-all=yes|no,
	   --without-all disables built of all],
        [with_all=$withval], [with_all=no])
AC_ARG_WITH(tclinclude, 
        [  --with-tclinclude       directory containing the public Tcl  header files.], 
         with_tclinclude=${withval})

if test "$with_all" = yes; then
   with_actiweb=yes
   with_xotclsh=yes
   with_xowish=yes
   with_gdbm=yes
fi
   
if test "$with_actiweb" = yes; then
   test_actiweb="test-actiweb"
   libdirs_actiweb="actiweb rdf registry store xml patterns"
   apps_actiweb="actiweb persistence"
   AC_CONFIG_SUBDIRS(../library/store/XOTclSdbm/)
   if ! test "$with_gdbm" = no; then
      AC_CONFIG_SUBDIRS(../library/store/XOTclGdbm/)
   fi
   AC_CONFIG_SUBDIRS(../library/xml/TclExpat-1.1/)
else
   test_actiweb=""
   libdirs_actiweb=""
   apps_actiweb=""
fi

if test "$with_xotclsh" = yes; then XOTCLSH="xotclsh" ; else XOTCLSH=""; fi
if test "$with_xowish" = yes;  then XOWISH="xowish"   ; else XOWISH=""; fi


#--------------------------------------------------------------------
# __CHANGE__
# Set your package name and version numbers here.  The NODOT_VERSION is
# required for constructing the library name on systems that don't like
# dots in library names (Windows).  The VERSION variable is used on the
# other systems.
#--------------------------------------------------------------------

PACKAGE=xotcl

# do not modify the following lines manually, they are generated with changeXOTclVersion
XOTCL_MAJOR_VERSION=1
XOTCL_MINOR_VERSION=2
XOTCL_RELEASE_LEVEL=.0

MAJOR_VERSION=${XOTCL_MAJOR_VERSION}
MINOR_VERSION=${XOTCL_MINOR_VERSION}
PATCHLEVEL=${XOTCL_RELEASE_LEVEL}

VERSION=${XOTCL_MAJOR_VERSION}.${XOTCL_MINOR_VERSION}
FULLVERSION=XOTclVersion
NODOT_VERSION=${XOTCL_MAJOR_VERSION}${XOTCL_MINOR_VERSION}

AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

AC_SUBST(FULLVERSION)
AC_SUBST(PATCHLEVEL)
AC_SUBST(exec_prefix)
AC_SUBST(MAJOR_VERSION)
AC_SUBST(MINOR_VERSION)

echo "Configuring XOTcl Version $VERSION"


#--------------------------------------------------------------------
# We put this here so that you can compile with -DVERSION="1.2" to
# encode the package version directly into the source files.
#--------------------------------------------------------------------

eval AC_DEFINE_UNQUOTED(VERSION, "${VERSION}")

#------------------------------------------------------------------------
# Handle the --prefix=... option
#------------------------------------------------------------------------

if test "${prefix}" = "NONE"; then
    prefix=/usr/local
fi
if test "${exec_prefix}" = "NONE"; then
    exec_prefix=$prefix
fi

#--------------------------------------------------------------------
# Check whether --enable-gcc or --disable-gcc was given.  Do this 
# before AC_CYGWIN is called so the compiler can 
# be fully tested by built-in autoconf tools.
# This macro also calls AC_PROG_CC to set the compiler if --enable-gcc
# was not used.
#--------------------------------------------------------------------

SC_ENABLE_GCC
AC_PROG_INSTALL
SC_CONFIG_CFLAGS

#--------------------------------------------------------------------
# Checks to see if the make program sets the $MAKE variable.
#--------------------------------------------------------------------

AC_PROG_MAKE_SET

#--------------------------------------------------------------------
# Find ranlib
#--------------------------------------------------------------------

AC_PROG_RANLIB

#--------------------------------------------------------------------
# This macro performs additional compiler tests.
#--------------------------------------------------------------------

AC_CYGWIN

#--------------------------------------------------------------------
# Determines the correct binary file extension (.o, .obj, .exe etc.)
#--------------------------------------------------------------------

AC_OBJEXT
AC_EXEEXT

#--------------------------------------------------------------------
# "cygpath" is used on windows to generate native path names for include
# files.
# These variables should only be used with the compiler and linker since
# they generate native path names.
#
# Unix tclConfig.sh points SRC_DIR at the top-level directory of
# the Tcl sources, while the Windows tclConfig.sh points SRC_DIR at
# the win subdirectory.  Hence the different usages of SRC_DIR below.
#
# This must be done before calling SC_PUBLIC_TCL_HEADERS
#
# RELPATH is used to locate binary extensions relative to the lib directory.
# It is only needed if mkIndex.tcl can't generate an installed pkgIndex.tcl
# file for you.
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT*|*CYGWIN_98*|*CYGWIN_95*)
	CYGPATH="cygpath -w"
	AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
	RELPATH=".. .. bin"
    ;;
    *)
	CYGPATH=echo
	RELPATH=..
    ;;
esac

AC_SUBST(CYGPATH)
AC_SUBST(RELPATH)

#--------------------------------------------------------------------
# Includes for this package
#--------------------------------------------------------------------

TOP_DIR=${srcdir}/..
XOTCL_GENERIC_DIR_NATIVE=`${CYGPATH} ${TOP_DIR}/generic`
XOTCL_WIN_DIR_NATIVE=`${CYGPATH} ${TOP_DIR}/win`
XOTCL_UNIX_DIR_NATIVE=`${CYGPATH} ${TOP_DIR}/unix`

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT*|*CYGWIN_98*|*CYGWIN_95*)
	XOTCL_PLATFORM_DIR_NATIVE=${XOTCL_WIN_DIR_NATIVE}
    ;;
    *)
	XOTCL_PLATFORM_DIR_NATIVE=${XOTCL_UNIX_DIR_NATIVE}
    ;;
esac

XOTCL_INCLUDES="-I\"${XOTCL_GENERIC_DIR_NATIVE}\" -I\"${XOTCL_PLATFORM_DIR_NATIVE}\""

AC_SUBST(XOTCL_GENERIC_DIR_NATIVE)
AC_SUBST(XOTCL_WIN_DIR_NATIVE)
AC_SUBST(XOTCL_UNIX_DIR_NATIVE)
AC_SUBST(XOTCL_INCLUDES)

#--------------------------------------------------------------------
# Load the tclConfig.sh file
#--------------------------------------------------------------------

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG

case "`pwd`" in
	*aolserver*)
		echo "Pre-configuring AOL-Server (xotcl)"
		AOL_DEFINES="-DAOL_SERVER -DUSE_TCL8X -I/usr/local/aolserver/include -I$TCL_SRC_DIR/generic"
		FORCE_NO_STUBS=1
	;;
	*)
		AOL_DEFINES=""
		FORCE_NO_STUBS=0
	;;
	esac
AC_SUBST(AOL_DEFINES)


#--------------------------------------------------------------------
# check for tclCompile.h (needed, when compiled without full source)
if test -f "$TCL_SRC_DIR/generic/tclCompile.h"; then
   HAVE_TCL_COMPILE_H="-DHAVE_TCL_COMPILE_H=1"
else
   HAVE_TCL_COMPILE_H=""
fi
AC_SUBST(HAVE_TCL_COMPILE_H)
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# __CHANGE__
# Choose which headers you need.  Extension authors should try very
# hard to only rely on the Tcl public header files.  Internal headers
# contain private data structures and are subject to change without
# notice.
# This must be done AFTER calling SC_PATH_TCLCONFIG/SC_LOAD_TCLCONFIG
# so that we can extract TCL_SRC_DIR from the config file (in the case
# of private headers
#--------------------------------------------------------------------

#SC_PUBLIC_TCL_HEADERS
SC_PRIVATE_TCL_HEADERS

if test x"${with_tclinclude}" != x ; then
   if test -f "${with_tclinclude}/tcl.h" ; then
      TCL_INCLUDES="-I${with_tclinclude} ${TCL_INCLUDES}"
   else
      AC_MSG_ERROR([${with_tclinclude} directory does not contain Tcl header file tcl.h])
   fi
fi

#--------------------------------------------------------------------
# check for TK
#--------------------------------------------------------------------

if test "$with_xowish" = yes;  then
       SC_PATH_TKCONFIG
       SC_LOAD_TKCONFIG
       SC_PUBLIC_TK_HEADERS
       SC_PROG_WISH
fi
#--------------------------------------------------------------------
 

#--------------------------------------------------------------------
# __CHANGE__
# A few miscellaneous platform-specific items:
#
# Define a special symbol for Windows (BUILD_xotcl in this case) so
# that we create the export library with the dll.  See sha1.h on how
# to use this.
#
# Windows creates a few extra files that need to be cleaned up.
# You can add more files to clean if your extension creates any extra
# files.
#
# Define any extra compiler flags in the PACKAGE_CFLAGS variable.
# These will be appended to the current set of compiler flags for
# your system.
#--------------------------------------------------------------------

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT*|*CYGWIN_98*|*CYGWIN_95*)
	AC_DEFINE(BUILD_xotcl)
	CLEANFILES="*.lib *.dll *.exp *.ilk *.pdb vc50.pch vc60.pch"
	PLATFORM_SOURCES='$(WIN_SOURCES)'
	PLATFORM_OBJECTS='$(WIN_OBJECTS)'
	PLATFORM_DIR='$(WIN_DIR)'
    ;;
    *)
	CLEANFILES="*.o *.so *~ core gmon.out config.*"
	PLATFORM_SOURCES='$(UNIX_SOURCES)'
	PLATFORM_OBJECTS='$(UNIX_OBJECTS)'
	PLATFORM_DIR='$(UNIX_DIR)'
    ;;
esac

AC_SUBST(CLEANFILES)
AC_SUBST(PLATFORM_SOURCES)
AC_SUBST(PLATFORM_OBJECTS)
AC_SUBST(PLATFORM_DIR)

#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
# So far only Tcl responds to this one.
#--------------------------------------------------------------------

SC_ENABLE_THREADS

#--------------------------------------------------------------------
# The statement below defines a collection of symbols related to
# building as a shared library instead of a static library.
#--------------------------------------------------------------------

SC_ENABLE_SHARED

#--------------------------------------------------------------------
# This macro figures out what flags to use with the compiler/linker
# when building shared/static debug/optimized objects.  This information
# is all taken from the tclConfig.sh file.
#--------------------------------------------------------------------

CFLAGS_DEBUG=${TCL_CFLAGS_DEBUG}
CFLAGS_OPTIMIZE=${TCL_CFLAGS_OPTIMIZE}
LDFLAGS_DEBUG=${TCL_LDFLAGS_DEBUG}
LDFLAGS_OPTIMIZE=${TCL_LDFLAGS_OPTIMIZE}
SHLIB_LD=${TCL_SHLIB_LD}
STLIB_LD=${TCL_STLIB_LD}
SHLIB_CFLAGS=${TCL_SHLIB_CFLAGS}

AC_SUBST(CFLAGS_DEBUG)
AC_SUBST(CFLAGS_OPTIMIZE)
AC_SUBST(STLIB_LD)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LDFLAGS)
AC_SUBST(SHLIB_SUFFIX)

#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols 
# option.
#--------------------------------------------------------------------

SC_ENABLE_SYMBOLS

if test "${SHARED_BUILD}" = "1" ; then
    CFLAGS='${CFLAGS_DEFAULT} ${CFLAGS_WARNING} ${SHLIB_CFLAGS}'
else
    CFLAGS='${CFLAGS_DEFAULT} ${CFLAGS_WARNING}'
fi

#--------------------------------------------------------------------
# Everyone should be linking against the Tcl stub library.  If you
# can't for some reason, remove this definition.  If you aren't using
# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
# link against the non-stubbed Tcl library.
#--------------------------------------------------------------------
TCL_STUB_LIB_DEFINE=""
STUB_SOURCES=""
STUB_OBJECTS=""
STUB_SHELL_OBJECTS=""
STUB_LIB_BINARY=""
#echo "AOL force no stubs ? ${FORCE_NO_STUBS}"
# no stubs for tcl 8.0 versions 
if test "${TCL_MAJOR_VERSION}" = "8" -a "${TCL_MINOR_VERSION}" = "0"; then
	FORCE_NO_STUBS=1
fi

if test "${SHARED_BUILD}" = "1" -a "${FORCE_NO_STUBS}" = "0" ; then
	TCL_STUB_LIB_DEFINE="-DUSE_TCL_STUBS"
	STUB_SOURCES="\$(STUB_SOURCES)"
	STUB_OBJECTS="\$(STUB_OBJECTS)"
	STUB_SHELL_OBJECTS="\$(STUB_SHELL_OBJECTS)"
	STUB_LIB_BINARY="\$(STUB_LIB_BINARY)"
fi
AC_SUBST(TCL_STUB_LIB_DEFINE)
AC_SUBST(STUB_SOURCES)
AC_SUBST(STUB_OBJECTS)
AC_SUBST(STUB_SHELL_OBJECTS)
AC_SUBST(STUB_LIB_BINARY)
AC_SUBST(RANLIB_STUB)

#--------------------------------------------------------------------
# This macro generates a line to use when building a library.  It
# depends on values set by the SC_ENABLE_SHARED, SC_ENABLE_SYMBOLS,
# and SC_LOAD_TCLCONFIG macros above.
#--------------------------------------------------------------------

SC_MAKE_LIB

#--------------------------------------------------------------------
# eval these two values to dereference the ${DBGX} variable.
#--------------------------------------------------------------------

#eval "SHARED_LIB_SUFFIX=${TCL_SHARED_LIB_SUFFIX}"
#eval "UNSHARED_LIB_SUFFIX=${TCL_UNSHARED_LIB_SUFFIX}"

eval "SHARED_LIB_SUFFIX=${VERSION}${TCL_DBGX}${TCL_SHLIB_SUFFIX}"
eval "UNSHARED_LIB_SUFFIX=${VERSION}${TCL_DBGX}.a"

AC_SUBST(SHARED_LIB_SUFFIX)
AC_SUBST(UNSHARED_LIB_SUFFIX)
#--------------------------------------------------------------------
# Shared libraries and static libraries have different names.
#--------------------------------------------------------------------
RANLIB_STUB="${RANLIB}"
case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT*|*CYGWIN_98*|*CYGWIN_95*)
	if test "${SHARED_BUILD}" = "1" ; then
	    SHLIB_LD_LIBS="\"`cygpath -w ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\" ${TCL_SHLIB_LD_LIBS}"
	    eval "${PACKAGE}_LIB_FILE=${PACKAGE}${SHARED_LIB_SUFFIX}"
	    RANLIB=:
	else
	    eval "${PACKAGE}_LIB_FILE=${PACKAGE}${UNSHARED_LIB_SUFFIX}"
	fi
	eval "${PACKAGE}stub_LIB_FILE=${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	;;
    *)
	if test "${SHARED_BUILD}" = "1" ; then
	    #SHLIB_LD_LIBS="${TCL_BUILD_STUB_LIB_SPEC}"
	    SHLIB_LD_LIBS="${TCL_STUB_LIB_SPEC}"
	    eval "${PACKAGE}_LIB_FILE=lib${PACKAGE}${SHARED_LIB_SUFFIX}"
	    RANLIB=:
	else
	    eval "${PACKAGE}_LIB_FILE=lib${PACKAGE}${UNSHARED_LIB_SUFFIX}"
	fi
	eval "${PACKAGE}stub_LIB_FILE=lib${PACKAGE}stub${UNSHARED_LIB_SUFFIX}"
	;;
esac

#--------------------------------------------------------------------
# __CHANGE__
# Change the name from exampeA_LIB_FILE to match your package name.
# Use the stub_LIB_FILE substitution if your package creates a stub
# library.
#--------------------------------------------------------------------

AC_SUBST(xotclstub_LIB_FILE)
AC_SUBST(xotcl_LIB_FILE)
AC_SUBST(SHLIB_LD_LIBS)

#--------------------------------------------------------------------
# Find tclsh so that we can run pkg_mkIndex to generate the pkgIndex.tcl
# file during the install process.  Don't run the TCLSH_PROG through
# ${CYGPATH} because it's being used directly by make.
# Require that we use a tclsh shell version 8.2 or later since earlier
# versions have bugs in the pkg_mkIndex routine.
#--------------------------------------------------------------------

SC_PROG_TCLSH

#
# XOTcl specific configs
#
XOTCL_BUILD_LIB_SPEC="-L`pwd` -lxotcl${VERSION}"
XOTCL_LIB_SPEC="-L${exec_prefix}/lib -lxotcl${VERSION}"

# stub libs are not build for 8.0
if test "${TCL_MAJOR_VERSION}" = "8" -a "${TCL_MINOR_VERSION}" = "0"; then
	XOTCL_STUB_LIB_FILE=""
	XOTCL_BUILD_STUB_LIB_SPEC=""
	XOTCL_STUB_LIB_SPEC=""
	XOTCL_BUILD_STUB_LIB_PATH=""
	XOTCL_STUB_LIB_PATH=""
	XOTCL_STUB_OBJECTS=""
else
#	XOTCL_STUB_LIB_FILE="libxotclstub${VERSION}"
	XOTCL_STUB_LIB_FILE=${xotclstub_LIB_FILE}
	XOTCL_BUILD_STUB_LIB_SPEC="-L`pwd` -lxotclstub${VERSION}"
	XOTCL_STUB_LIB_SPEC="-L${exec_prefix}/lib -lxotclstub${VERSION}"
	XOTCL_BUILD_STUB_LIB_PATH="`pwd`/${XOTCL_STUB_LIB_FILE}"
	XOTCL_STUB_LIB_PATH="${exec_prefix}/lib/${XOTCL_STUB_LIB_FILE}"
	AC_DEFINE(COMPILE_XOTCL_STUBS)
	XOTCL_STUB_OBJECTS="\$(STUB_OBJECTS)"
fi 

AC_SUBST(XOTCL_BUILD_LIB_SPEC)
AC_SUBST(XOTCL_LIB_SPEC)
AC_SUBST(XOTCL_STUB_LIB_FILE)
AC_SUBST(XOTCL_BUILD_STUB_LIB_SPEC)
AC_SUBST(XOTCL_STUB_LIB_SPEC)
AC_SUBST(XOTCL_BUILD_STUB_LIB_PATH)
AC_SUBST(XOTCL_STUB_LIB_PATH)
AC_SUBST(XOTCL_STUB_OBJECTS)
XOTCL_SRC_DIR=`pwd`/..
AC_SUBST(XOTCL_SRC_DIR)
AC_SUBST(XOTCLSH)
AC_SUBST(XOWISH)

AC_SUBST(test_actiweb)
AC_SUBST(libdirs_actiweb)
AC_SUBST(apps_actiweb)
#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
#--------------------------------------------------------------------

AC_OUTPUT([Makefile xotclConfig.sh xotclsh xowish xotcl.spec pkgIndex.unix])


