#--------------------------------------------------------------------
# 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:
#
# AC_INIT(../generic/tcl.h)
#--------------------------------------------------------------------

AC_INIT(generic/itk.h)
AC_CONFIG_AUX_DIR(../config)

#--------------------------------------------------------------------
# __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=itk

MAJOR_VERSION=3
MINOR_VERSION=2
PATCHLEVEL=.0

VERSION=${MAJOR_VERSION}.${MINOR_VERSION}
NODOT_VERSION=${MAJOR_VERSION}${MINOR_VERSION}


AC_SUBST(PACKAGE)
AC_SUBST(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}")

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

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

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

AC_SUBST(CYGPATH)
AC_SUBST(RELPATH)

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

ITK_GENERIC_DIR_NATIVE=`${CYGPATH} ${srcdir}/generic`
ITK_WIN_DIR_NATIVE=`${CYGPATH} ${srcdir}/win`
ITK_UNIX_DIR_NATIVE=`${CYGPATH} ${srcdir}/unix`

case "`uname -s`" in
    *win32* | *WIN32* | *CYGWIN_NT*|*CYGWIN_98*|*CYGWIN_95*)
	ITK_PLATFORM_DIR_NATIVE=${ITK_WIN_DIR_NATIVE}
    ;;
    *)
	ITK_PLATFORM_DIR_NATIVE=${ITK_UNIX_DIR_NATIVE}
    ;;
esac

ITK_INCLUDES="-I\"${ITK_GENERIC_DIR_NATIVE}\" -I\"${ITK_PLATFORM_DIR_NATIVE}\""

AC_SUBST(ITK_GENERIC_DIR_NATIVE)
AC_SUBST(ITK_WIN_DIR_NATIVE)
AC_SUBST(ITK_UNIX_DIR_NATIVE)
AC_SUBST(ITK_INCLUDES)

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

SC_PATH_TCLCONFIG
SC_LOAD_TCLCONFIG

#--------------------------------------------------------------------
# Load the tkConfig.sh file
#--------------------------------------------------------------------

SC_PATH_TKCONFIG
SC_LOAD_TKCONFIG

AC_ARG_WITH(itcl, [  --with-itclinclude=DIR          use Itcl headers from DIR],
        ITCL_LIB_DIR=$withval, ITCL_LIB_DIR=`cd ${srcdir}/../itcl; pwd`)

if test ! -r "${ITCL_LIB_DIR}/generic/itclInt.h" ; then
    AC_MSG_ERROR(Can't find Itcl private header files.  Use --with-itclinclude to specify the directory containing the Itcl private headers on your system.)
fi

ITCL_INCLUDES=-I\"`${CYGPATH} ${ITCL_LIB_DIR}/generic`\"
AC_SUBST(ITCL_INCLUDES)

#--------------------------------------------------------------------
# The value for this should have been cached during the Itcl configuration.
# Make sure the cache-ID that appears here is the same as the one that
# appears in the Itcl configure script.
#--------------------------------------------------------------------

AC_MSG_CHECKING(for name if Itcl stub library)
AC_CACHE_VAL(ac_cv_itclstub_LIB_FILE, ac_cv_itclstub_LIB_FILE="NONE")
if test x"${ac_cv_itclstub_LIB_FILE}" = x"NONE" ; then
    AC_MSG_ERROR(Can't find name of Itcl stub library.  How did this happen?)
else
    AC_MSG_RESULT(${ac_cv_itclstub_LIB_FILE})
fi
itclstub_LIB_FILE=${ac_cv_itclstub_LIB_FILE}
AC_SUBST(itclstub_LIB_FILE)

SC_LIB_SPEC(tkstub, ${TK_BIN_DIR})
AC_SUBST(tkstub_LIB_SPEC)

SC_LIB_SPEC(itclstub, ../itcl)

#--------------------------------------------------------------------
# __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

#SC_PUBLIC_TK_HEADERS
SC_PRIVATE_TK_HEADERS

#--------------------------------------------------------------------
# __CHANGE__
# A few miscellaneous platform-specific items:
#
# Define a special symbol for Windows (BUILD_itk 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_UNQUOTED(BUILD_${PACKAGE})
	CLEANFILES="*.lib *.dll *.exp *.ilk *.pdb vc50.pch"
	PLATFORM_SOURCES='$(WIN_SOURCES)'
	PLATFORM_OBJECTS='$(WIN_OBJECTS)'
	PLATFORM_DIR='$(WIN_DIR)'
    ;;
    *)
	CLEANFILES=
	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)

#--------------------------------------------------------------------
# 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.
#--------------------------------------------------------------------

if test "${SHARED_BUILD}" = "1" ; then
    AC_DEFINE(USE_TCL_STUBS)
    AC_DEFINE(USE_TK_STUBS)
    AC_DEFINE(USE_ITCL_STUBS)
fi

#--------------------------------------------------------------------
# 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}"

#--------------------------------------------------------------------
# Shared libraries and static libraries have different names.
#--------------------------------------------------------------------

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} \"`${CYGPATH} ../itcl/${itclstub_LIB_FILE}`\" ${tkstub_LIB_SPEC} "
	    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="${tkstub_LIB_SPEC} ${TCL_BUILD_STUB_LIB_SPEC} ../itcl/${itclstub_LIB_FILE}"
	    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(itkstub_LIB_FILE)
AC_SUBST(itk_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

#--------------------------------------------------------------------
# A wish shell is needed to run the test suite.
#--------------------------------------------------------------------

SC_PROG_WISH

#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
#--------------------------------------------------------------------

AC_OUTPUT([Makefile \
	pkgIndex.tcl])
