AC_INIT(gd.c)

TOP_DIR=`pwd`

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

AC_CHECKING(for tclConfig.sh)
for tcldir in tcl8.1.1 tcl8.0.4 tcl8.0.3 tcl8.0 tcl7.6 tcl7.5
do
    if test -d ../$tcldir
    then
	TCL_TOP_DIR=`(cd ../$tcldir; pwd)`
	break
    fi
done

if test -z "$TCL_TOP_DIR"
then
    eval "TCL_CONFIG_FILE=$libdir/tclConfig.sh"
    if test -f $TCL_CONFIG_FILE
    then
	AC_MSG_RESULT($TCL_CONFIG_FILE)
	. $TCL_CONFIG_FILE
    else
	AC_MSG_RESULT(not found)
	AC_MSG_ERROR(Cannot locate tclConfig.sh)
    fi
else
    AC_MSG_RESULT($TCL_TOP_DIR/unix/tclConfig.sh)
    . $TCL_TOP_DIR/unix/tclConfig.sh
fi


AC_CHECKING(for tclxConfig.sh)
for tclxdir in tclX8.1.1 tclX8.0.4 tclX8.0.3 tclX8.0.2 tclX7.6.0 tclX7.5.3-a1 tclX7.5.2
do
    if test -d ../$tclxdir
    then
	TCLX_TOP_DIR=`(cd ../$tclxdir; pwd)`
	break
    fi
done
if test -z "$TCLX_TOP_DIR"
then
    eval "TCLX_CONFIG_FILE=$libdir/tclxConfig.sh"
    if test -f $TCLX_CONFIG_FILE
    then
	AC_MSG_RESULT($TCLX_CONFIG_FILE)
	. $TCLX_CONFIG_FILE
    else
	AC_MSG_RESULT(not found)
	AC_MSG_ERROR(Cannot locate tclxConfig.sh)
    fi
else
    AC_MSG_RESULT($TCLX_TOP_DIR/unix/tclxConfig.sh)
    . $TCLX_TOP_DIR/tcl/unix/tclxConfig.sh
fi


GD_VERSION='1.2'
GD_MAJOR_VERSION='1'
GD_MINOR_VERSION='2'
VERSION=$GD_VERSION

AC_SUBST(GD_VERSION)
AC_SUBST(GD_MAJOR_VERSION)
AC_SUBST(GD_MINOR_VERSION)

AC_PROG_CC

VERSION=$GD_VERSION
SHLIB_SUFFIX=${TCL_SHLIB_SUFFIX}

eval "GD_SHARED_LIB_FILE=libgd${TCL_SHARED_LIB_SUFFIX}"
eval "GD_UNSHARED_LIB_FILE=libgd${TCL_UNSHARED_LIB_SUFFIX}"

AC_ARG_ENABLE(shared,
    [  --enable-shared         build libtk as a shared library],
    [ok=$enableval], [ok=no])
if test "$ok" = "yes" -a "${TCL_SHLIB_SUFFIX}" != ""; then
    SHLIB_CFLAGS="${TCL_SHLIB_CFLAGS}"
    eval "GD_LIB_FILE=libgd${TCL_SHARED_LIB_SUFFIX}"
    GD_UNSHARED_LIB_FILE=dont_build_shared
    GD_PROGS=""
else
    SHLIB_CFLAGS=""
    eval "GD_LIB_FILE=libgd${TCL_UNSHARED_LIB_SUFFIX}"
    GD_SHARED_LIB_FILE=dont_build_shared
    GD_PROGS="webgif giftogd gddemo"
fi

# Note:  in the following variable, it's important to use the absolute
# path name of the Tcl directory rather than "..":  this is because
# AIX remembers this path and will attempt to use it at run-time to look
# up the Tcl library.
# Also note: this code pulled in from tk's configure, but maybe not very
# useful right now.

if test "${TCL_LIB_VERSIONS_OK}" = "ok"; then
    GD_BUILD_LIB_SPEC="-L`pwd` -lgd${VERSION}"
    GD_LIB_SPEC="-L\${GD_EXEC_PREFIX}/lib -lgd${VERSION}"
else
    GD_BUILD_LIB_SPEC="-L`pwd` -lgd`echo ${VERSION} | tr -d .`"
    GD_LIB_SPEC="-L\${GD_EXEC_PREFIX}/lib -lgd`echo ${VERSION} | tr -d .`"
fi

#-------------------------------------------------------------------
#       Use data from *Config.sh files instead of figuring it out
#-------------------------------------------------------------------

AC_SUBST(TOP_DIR)
AC_SUBST(TCL_TOP_DIR)
AC_SUBST(TCLX_TOP_DIR)

AC_SUBST(TCL_PREFIX)
AC_SUBST(TCL_EXEC_PREFIX)
AC_SUBST(TCL_LIBS)
AC_SUBST(TCL_DL_LIBS)
AC_SUBST(TCL_LD_FLAGS)
AC_SUBST(TCL_BUILD_LIB_SPEC)
AC_SUBST(TCL_SHLIB_LD)
AC_SUBST(TCL_SHLIB_SUFFIX)
AC_SUBST(TCL_SHLIB_LD_LIBS)
AC_SUBST(TCL_DL_LIBS)
AC_SUBST(TCL_LD_FLAGS)
AC_SUBST(TCL_LD_SEARCH_FLAGS)
AC_SUBST(TCL_LIB_HNAME)
AC_SUBST(TCL_RANLIB)
AC_SUBST(TCL_CC)
AC_SUBST(TCL_DEFS)

AC_SUBST(GD_VERSION)
AC_SUBST(GD_MAJOR_VERSION)
AC_SUBST(GD_MINOR_VERSION)
AC_SUBST(GD_SHARED_LIB_FILE)
AC_SUBST(GD_UNSHARED_LIB_FILE)
AC_SUBST(GD_LIB_FILE)
AC_SUBST(GD_LIB_SPEC)
AC_SUBST(GD_BUILD_LIB_SPEC)
AC_SUBST(GD_PROGS)

AC_SUBST(SHLIB_CFLAGS)

AC_OUTPUT(Makefile pkgIndex.tcl gdConfig.sh)
