dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run to configure the
dnl	Makefile in this directory.
AC_INIT(../src/tcljava/tcl/lang/InternalRep.java)
# RCS: @(#) $Id: configure.in,v 1.24 1999/11/02 00:10:01 redman Exp $


#--------------------------------------------------------------------
# 	Version identification info (also set in source files)
#--------------------------------------------------------------------
TCLJAVA_VERSION=1.2.5
TCLJAVA_NODOT_VERSION=`echo $TCLJAVA_VERSION | sed -e 's/\.//g'`

# Convert into full path name
srcdir=`cd $srcdir ; pwd`

MSG="srcdir is $srcdir"
echo $MSG >&5
echo $MSG



# the very first thing we need to do update the dist version number.
# we only need to do this when releasing new versions of the code
# so only the code maintainer will need to do this.

TOOLS=$srcdir/tools

if test -d $TOOLS ; then

    # Check that grep is working by looking for the match to the
    # current version number in the configure.in file.

    if env grep "TCLJAVA_VERSION=$TCLJAVA_VERSION" $srcdir/configure.in > /dev/null; then
        DO=nothing
    else
	AC_MSG_ERROR([TCLJAVA_VERSION grep failed.
        did you rerun autoconf after changing the version number in configure.in?])
    fi

    # Check that the files we need actually exist

    if test ! -d $TOOLS/vutil ; then
	echo "$TOOLS/vutil does not exist"
	exit 1
    fi

    if test ! -f $TOOLS/vutil/vsub.sh ; then
	echo "$TOOLS/vutil/vsub.sh does not exist"
	exit 1
    fi

    # Find out if we need to update the version numbers by checking to
    # see if the one we got differs from the one in the file "current".

    if env grep "TCLJAVA_VERSION=$TCLJAVA_VERSION" $TOOLS/vutil/current > /dev/null; then
        # If they are the same we do not need to update
	DO=nothing
    else
        # Otherwise we do need to update
        echo "Updating version numbers in the source files to $TCLJAVA_VERSION"
	
        TMP_CWD=`pwd`
        cd $TOOLS/vutil
        sh vsub.sh $TCLJAVA_VERSION
        cd $TMP_CWD
    fi
fi




# Output file ids
# 6 checking for... messages and results
# 5 compiler messages saved in config.log


#--------------------------------------------------------------------
#	Locate which java tool to build.  If the --with-build option
#	is used, that overides everthing.  Otherwise configure for
#	both Tcl Blend and Jacl.
#--------------------------------------------------------------------

AC_ARG_WITH(build, [  --with-build=DIR        select which system to build (jacl or tclblend)],
	TCLJAVA=$withval, TCLJAVA=NONE)

if test $TCLJAVA != "NONE"; then
    if test $TCLJAVA != "jacl" && test $TCLJAVA != "tclblend"; then 
	AC_MSG_ERROR([Cannot build --with-build='$TCLJAVA': use 'jacl' or 'tclblend'])
    fi
fi

#BOTH will automatically be set to true when configuring Jacl and Tcl Blend
BOTH=false


if test $TCLJAVA = "NONE"; then
    if test -f $srcdir/../src/tclblend/tcl/lang/Interp.java; then
	TCLJAVA=tclblend
    elif test -f $srcdir/../src/jacl/tcl/lang/Interp.java; then 
	TCLJAVA=jacl
    else
	AC_MSG_ERROR([Cannot find source files to build either Jacl or Tcl Blend])
    fi

    if test -f $srcdir/../src/jacl/tcl/lang/Interp.java && test $TCLJAVA = "tclblend"; then
        MSG="configuring for both jacl and tcl blend"
        echo $MSG >&5
        echo $MSG
        BOTH=true
    fi
fi




#
# These variables are used to keep track of info about the JVM install
# that we are using. Different JVMs will have different things that
# need to be tested so we need to be able to determine which one we
# are using when running configure. Once the Makefile is create we
# SHOULD NOT need to know which JVM we are using to compile.
#

# The root is the java install
JAVA_DIR=""

# One of jdk (the default), kaffe, japhar, ...
JAVA_NAME=""




#--------------------------------------------------------------------
#	See if there was a command-line option for where the kaffe is;
#       if it is none, look for kaffe on the path.
#--------------------------------------------------------------------

AC_ARG_WITH(kaffe, [  --with-kaffe=DIR        use Kaffe-JVM binaries from DIR], KAFFE_DIR=$withval, KAFFE_DIR=NONE)

if test "$KAFFE_DIR" != "NONE"; then
    # if --with-kaffe was given then we need to make sure no other JVM was
    # configured with a --with option

    if test "$JAVA_NAME" != ""; then
        AC_MSG_ERROR([--with-kaffe can not be used with the --with-$JAVA_NAME option.]);
    fi

    if test ! -d "$KAFFE_DIR"; then
        AC_MSG_ERROR([directory '$KAFFE_DIR' given to --with-kaffe option does not exist.])
    fi

    JAVA_NAME=kaffe


    # currently the kaffe JVM does not work well enough to be used
    # to build and run tcl blend or jacl. Once it does work this
    # error message should be removed so that --with-kaffe can be used

    #echo "Sorry: --with-kaffe is currently disabled because of bugs in"
    #echo "       the implementation of the kaffe JVM. Once the bugs"
    #echo "       in kaffe are fixed it will be enabled."
    #exit 1

fi

if test "$JAVA_NAME" = "kaffe" && test ! -d "$KAFFE_DIR"; then
    if test "$KAFFE_DIR" != "" && test "$KAFFE_DIR" != "yes"; then
        AC_MSG_WARN(['$KAFFE_DIR' is not a directory, so we search for the kaffe.])
    fi
    AC_PATH_PROG(TMP_KAFFE, kaffe)
    if test -x "$TMP_KAFFE"; then	
	TMP_KAFFE=`dirname $TMP_KAFFE`
	KAFFE_DIR=`dirname $TMP_KAFFE`
    else
        AC_MSG_ERROR([Failed to find kaffe, perhaps kaffe is not installed?
Try --with-kaffe=DIR.])
    fi
fi

if test "$JAVA_NAME" = "kaffe"; then
    if test -d "$KAFFE_DIR"; then
        # Convert into full path name
        JAVA_DIR=`cd $KAFFE_DIR ; pwd`
    else
        AC_MSG_ERROR([kaffe directory '$KAFFE_DIR' does not exist, perhaps kaffe is not installed?
Try --with-kaffe=DIR.])
    fi
fi






#--------------------------------------------------------------------
#	See if there was a command-line option for where the JDK is;  if
#	not, check to see if the JAVA_HOME environment variable is set;
#       if it is none, look for javac on the path. The -with-jdk option
#       must be processed after any other --with options for JVMs.
#--------------------------------------------------------------------

AC_ARG_WITH(jdk, [  --with-jdk=DIR          use Sun's JDK Java binaries from DIR, defaults to the value of the JAVA_HOME environment variable],
    JDK_DIR=$withval, JDK_DIR=NONE)

if test "$JDK_DIR" = "NONE"; then
    # no --with-jdk argument was given so we default to the value in JAVA_HOME
    # as long a no other JVM was configured with the --with option

    if test "$JAVA_NAME" = ""; then
        JAVA_NAME=jdk
        JDK_DIR=$JAVA_HOME
    fi
else
    # if --with-jdk was given then we need to make sure no other JVM was
    # configured with a --with option

    if test "$JAVA_NAME" != ""; then
        AC_MSG_ERROR([--with-jdk can not be used with the --with-$JAVA_NAME option.])
    fi

    if test "$JDK_DIR" != "yes" && test ! -d "$JDK_DIR"; then
        AC_MSG_ERROR([directory '$JDK_DIR' given to --with-jdk option does not exist.])
    fi

    JAVA_NAME=jdk
fi

if test "$JAVA_NAME" = "jdk" && test ! -d "$JDK_DIR"; then
    if test "$JDK_DIR" != "" && test "$JDK_DIR" != "yes"; then
        AC_MSG_WARN(['$JDK_DIR' is not a directory, so we search for the java compiler.])
    fi
    AC_PATH_PROG(TMP_JAVAC, javac)
    if test -x "$TMP_JAVAC"; then	
	TMP_JAVAC=`dirname $TMP_JAVAC`
	JDK_DIR=`dirname $TMP_JAVAC`
    else
        AC_MSG_ERROR([Failed to find javac, perhaps Java is not installed?
Try --with-jdk=DIR, or set the JAVA_HOME environment variable.])
    fi
fi

if test "$JAVA_NAME" = "jdk"; then
    if test -d "$JDK_DIR"; then
        # Convert into full path name
        JAVA_DIR=`cd $JDK_DIR ; pwd`
    else
        AC_MSG_ERROR([jdk directory '$JDK_DIR' does not exist, perhaps Java is not installed?
Try --with-jdk=DIR, or set the JAVA_HOME environment variable.])
    fi
fi


# At this point we should have found a valid JVM so we check for
# the valid possibilities now so we can skip extra checks later

case "$JAVA_NAME" in
    jdk) DO=nothing ;;
    kaffe) DO=nothing ;;
    *) AC_MSG_ERROR(['$JAVA_NAME' is not a supported JVM]) ;;
esac


MSG="Java found at $JAVA_DIR"
echo $MSG
echo $MSG >&5
echo "JAVA_NAME is $JAVA_NAME" >&5



#------------------------------------------------------------------
#
# Check to make sure we know the names of the .zip or .jar files
# that need to be included in the CLASSPATH
#
#------------------------------------------------------------------

AC_MSG_CHECKING([for zip or jar files to include on CLASSPATH])
JAVA_CLASSPATH=""

if test "$JAVA_NAME" = "kaffe"; then
    if test -f $JAVA_DIR/share/kaffe/Klasses.jar; then
        JAVA_CLASSPATH=$JAVA_DIR/share/kaffe/Klasses.jar
    fi
elif test "$JAVA_NAME" = "jdk"; then
    if test -f $JAVA_DIR/lib/classes.zip; then
        # JDK1.1 requires classes.zip in CLASSPATH
        JAVA_CLASSPATH=$JAVA_DIR/lib/classes.zip
    elif test -f $JAVA_DIR/jre/lib/rt.jar; then
        # JDK1.2 does not require system libs in CLASSPATH
        # but we need them for compilers and tclblend
        JAVA_CLASSPATH=$JAVA_DIR/jre/lib/rt.jar
    elif test "`uname -s`" = "IRIX"; then
        # JDK1.1.5 under IRIX
        if test -f $JAVA_DIR/lib/rt.jar; then
            JAVA_CLASSPATH=$JAVA_DIR/lib/rt.jar
        else
            AC_MSG_ERROR([could not find $JAVA_DIR/lib/rt.jar for IRIX system])
        fi
        if test -f $JAVA_DIR/lib/dev.jar; then
            JAVA_CLASSPATH=$JAVA_CLASSPATH:$JAVA_DIR/lib/dev.jar
        fi
    fi
fi

if test "$JAVA_CLASSPATH" = ""; then
    AC_MSG_ERROR([could not find zip or jar files to include on CLASSPATH.])
else
    echo "Using JAVA_CLASSPATH=$JAVA_CLASSPATH" >&5
    AC_MSG_RESULT($JAVA_CLASSPATH)
fi



#------------------------------------------------------------------
#
# Check for the java runtime
#
#------------------------------------------------------------------

AC_MSG_CHECKING([for the java runtime])
case "$JAVA_NAME" in
    jdk) NAME=java ;;
    kaffe) NAME=kaffe ;;
esac
if test -x $JAVA_DIR/bin/$NAME; then
    JAVA=$JAVA_DIR/bin/$NAME
    echo "Using JAVA=$JAVA" >&5
    AC_MSG_RESULT($JAVA)
else
    AC_MSG_ERROR([
  Cannot find $JAVA_DIR/bin/$NAME.])
fi

#------------------------------------------------------------------
#
# Check for the remote debug java_g runtime
#
#------------------------------------------------------------------

AC_MSG_CHECKING([for the java_g runtime])
case "$JAVA_NAME" in
    jdk) NAME=java_g ;;
    kaffe) NAME=kaffe ;;
esac
if test -x $JAVA_DIR/bin/$NAME; then
    JAVA_G=$JAVA_DIR/bin/$NAME
    echo "Using JAVA_G=$JAVA_G" >&5
    AC_MSG_RESULT($JAVA_G)
else
    AC_MSG_WARN([
  Cannot find $JAVA_DIR/bin/$NAME.])
fi



#------------------------------------------------------------------
#
# Check for the javac compiler
#
#------------------------------------------------------------------

AC_MSG_CHECKING([for the java compiler])
case "$JAVA_NAME" in
    jdk) NAME=javac ;;
    kaffe) NAME=javac ;;
esac
if test -x $JAVA_DIR/bin/$NAME; then
    JAVAC=$JAVA_DIR/bin/$NAME
    echo "Using JAVAC=$JAVAC" >&5
    AC_MSG_RESULT($JAVAC)
else
    AC_MSG_ERROR([
  Cannot find $JAVA_DIR/bin/$NAME.])
fi





#------------------------------------------------------------------
#
# Check that we have the javah .h header generator
#
#------------------------------------------------------------------

if test $TCLJAVA = "tclblend" || test $BOTH = "true"; then

AC_MSG_CHECKING([for the java header program])
case "$JAVA_NAME" in
    jdk) NAME=javah ;;
    kaffe) NAME=kaffeh ;;
esac
if test -x $JAVA_DIR/bin/$NAME; then
    JAVAH=$JAVA_DIR/bin/$NAME
    echo "Using JAVAH=$JAVAH" >&5
    AC_MSG_RESULT($JAVAH)
else
    AC_MSG_ERROR([
  Cannot find $JAVA_DIR/bin/$NAME.])
fi

fi


#------------------------------------------------------------------
#
# Check that we have the jar archive utility
#
#------------------------------------------------------------------

AC_MSG_CHECKING([for the java archive program])
case "$JAVA_NAME" in
    jdk) NAME=jar ;;
    kaffe) NAME=jar ;;
esac
if test -x $JAVA_DIR/bin/$NAME; then
    JAR=$JAVA_DIR/bin/$NAME
    echo "Using JAR=$JAR" >&5
    AC_MSG_RESULT($JAR)
else
    AC_MSG_ERROR([
  Cannot find $JAVA_DIR/bin/$NAME.])
fi




#------------------------------------------------------------------
#
# Check that we have the jdb java debugger program
# jdb functionality will not be tested by the configure script
#
#------------------------------------------------------------------

if test $TCLJAVA = "jacl" || test $BOTH = "true"; then

    AC_MSG_CHECKING([for the java debugger program])
    case "$JAVA_NAME" in
        jdk) NAME=jdb ;;
        kaffe) NAME=jdb ;;
    esac
    if test -x $JAVA_DIR/bin/$NAME; then
        JDB=$JAVA_DIR/bin/$NAME
        echo "Using JDB=$JDB" >&5
        AC_MSG_RESULT($JDB)
    else
        AC_MSG_ERROR([Cannot find $JAVA_DIR/bin/$NAME.])
    fi
fi


#------------------------------------------------------------------
#
# Look on the path for ddd, if it is not found do nothing
# ddd functionality will not be tested by the configure script
#
#------------------------------------------------------------------

AC_PATH_PROG(TMP_DDD, ddd)
if test -x "$TMP_DDD"; then
    DDD=$TMP_DDD
fi





#--------------------------------------------------------------------
#	See if there was a command-line option for where jikes is; if
#       there was a command line option given but no argument was given
#       then search for jikes on the PATH.
#--------------------------------------------------------------------

AC_ARG_WITH(jikes, [  --with-jikes=PROG       use jikes compiler given by PROG, if PROG is not given look for jikes on the PATH.],
    JIKES=$withval, JIKES=yes)

if test "$JIKES" = "no"; then
    #do nothing
    JIKES=""
else
    AC_MSG_CHECKING([for the jikes java compiler])
    if test "$JIKES" = "" || test "$JIKES" = "yes"; then
        AC_MSG_RESULT([searching on PATH])
        AC_PATH_PROG(TMP_JIKES, jikes)

        if test "$TMP_JIKES" = ""; then
            MSG="Could not find jikes on the PATH. Defaulting to javac."
            echo $MSG >&5
            AC_MSG_RESULT([$MSG])
            JIKES=""
        else
            JIKES=$TMP_JIKES
        fi
    fi

    if test "$JIKES" != ""; then

        # Make sure jikes exists and is executable
        if test ! -f $JIKES || test ! -x $JIKES; then
            AC_MSG_ERROR([jikes executable '$JIKES' does not exist or is not executable.])
        fi

        AC_MSG_RESULT([$JIKES])

        JAVAC=$JIKES
        echo "Using JAVAC=$JAVAC" >&5
    fi

fi







#
# If we are compiling tclblend, then we need to:
# 1. Check that we have the native threads pack
# 2. Find the platform dependent include files
# 3. Find the platform dependent libraries
#

if test $TCLJAVA = "tclblend" || test $BOTH = "true"; then

    # Find the main java include directory

    case "$JAVA_NAME" in
        jdk)
            case "`uname -s`" in
	        OSF1)
                    JAVA_INCLUDE=$JAVA_DIR/include/java
                    ;;
                *)
                    JAVA_INCLUDE=$JAVA_DIR/include
                    ;;
            esac
            ;;
        kaffe)
            JAVA_INCLUDE=$JAVA_DIR/include/kaffe
            ;;
    esac

    if test ! -d $JAVA_INCLUDE; then
        AC_MSG_ERROR([include directory $JAVA_INCLUDE does not exist.])
    fi


    # We need to #include <jni.h> so make sure that we can find it

    AC_MSG_CHECKING([for jni.h include file])
    if test ! -f $JAVA_INCLUDE/jni.h; then
        AC_MSG_ERROR([Can not find JNI include file $JAVA_INCLUDE/jni.h.])
    else
        echo "Found JNI include file $JAVA_INCLUDE/jni.h." >&5
        AC_MSG_RESULT([$JAVA_INCLUDE/jni.h.])
    fi


    # Find out if we are using the JNI 1.1 or 1.2 interfaces

    AC_MSG_CHECKING([for JDK1_2 in $JAVA_INCLUDE/jni.h])

    if env grep JDK1_2 $JAVA_INCLUDE/jni.h | grep define 1>&5 2>&5 ; then
        JAVA_VERSION=1.2
        MSG="Looks like you are using a 1.2 JVM"
        echo $MSG >&5
        AC_MSG_RESULT([$MSG])
    else
        JAVA_VERSION=1.1
        MSG="Looks like you are using a 1.1 JVM"
        echo $MSG >&5
        AC_MSG_RESULT([$MSG])
    fi

    if test "$JAVA_VERSION" != "1.1" && test "$JAVA_VERSION" != "1.2"; then
        MSG="JAVA_VERSION must be one of 1.1 or 1.2, is was \"$JAVA_VERSION\""
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi



    # Start JDK only tests

    if test "$JAVA_NAME" = "jdk"; then

    #
    # Do checks that differ for each platform in one place
    #
    # 1) make sure native threads pack is installed
    # 2) Find the proper platform include directory
    # 3) Find the proper platform lib directory


    # Ugly hack needed for Sun's "production" directory structure
    PRODUCTION_RELEASE=0


    # Keep case statements in alphabetical order.
    case "`uname -s`" in
	HP-UX)
	    if test ! -d $JAVA_INCLUDE/native_threads; then
                AC_MSG_ERROR(['$JAVA_INCLUDE/native_threads'
does not exist. You must install the JDK Native Threads Pack to use tclblend.
See http://www.hp.com/esy/technology/jdk/products/software.html.])
            fi

            JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/hp-ux

            ARCH=PA_RISC
            ARCH_LIBNAME=lib
            ARCH_LIB=${ARCH_LIBNAME}/${ARCH}

            JAVA_SHLIB=libjava.sl
            TCLBLEND_LIBS="-lpthread -ljava"
            TCLBLEND_SHLIB_NAMES="libpthread.sl libjava.sl"

            TCLBLEND_LD_PRELOAD=
            TCLBLEND_LD_BIND_NOW=0

            ;;
	IRIX)
	    if test ! -d $JAVA_INCLUDE/native_threads; then
                AC_MSG_ERROR(['$JAVA_INCLUDE/native_threads'
does not exist. You must install the JDK Native Threads Pack to use tclBlend.
See http://www.sgi.com/Products/Evaluation/#jdk.])
            fi

            JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/irix

            ARCH=sgi
            ARCH_LIBNAME=lib32

            if test -d $JAVA_DIR/lib; then
                MSG="IRIX 64 bit java libs found, but using 32 bit libs by default"
                echo $MSG >&5
                AC_MSG_WARN([$MSG])
            fi

            ARCH_LIB=${ARCH_LIBNAME}/${ARCH}

            JAVA_SHLIB=libjava.so
            TCLBLEND_LIBS="-ljava -lpthread"
            TCLBLEND_SHLIB_NAMES="libjava.so libpthread.so"

            TCLBLEND_LD_PRELOAD=
            TCLBLEND_LD_BIND_NOW=1

            ;;
	Linux)
	    if test "$JAVA_VERSION" = "1.1" && \
                test ! -d $JAVA_INCLUDE/native_threads; then
                AC_MSG_ERROR(['$JAVA_INCLUDE/native_threads'
does not exist. You must install the JDK Native Threads Pack to use tclblend.
See http://www.blackdown.org/java-linux.html.])
            fi

            # Early Blackdown JDK include dir name was genunix
            if test -d $JAVA_INCLUDE/genunix; then
                JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/genunix
            else
                JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/linux
            fi

            case "`uname -m`" in
                alpha)  ARCH=alpha ;;
                i?86)   ARCH=i386 ;;
                mips)   ARCH=mips ;;
                ppc)    ARCH=ppc ;;
                sparc)  ARCH=sparc ;;
                *)      AC_MSG_ERROR([ARCH '`uname -m`' is not supported]) ;;
            esac

            ARCH_LIBNAME=lib
            ARCH_LIB=${ARCH_LIBNAME}/${ARCH}

            JAVA_SHLIB=libjava.so
            TCLBLEND_LIBS="-lpthread -ljava"
            TCLBLEND_SHLIB_NAMES="libpthread.so libjava.so"

            TCLBLEND_LD_PRELOAD="libpthread.so libjava.so"
            TCLBLEND_LD_BIND_NOW=1

            MSG="Using AWT GUI components under Tcl Blend with the Linux port of the JDK from Blackdown requires a special modification to jtclsh and the Makefile. See known_issues.txt for more info."
            echo $MSG >&5
            AC_MSG_WARN([$MSG])

            ;;
        OSF1)
            JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/alpha

            # Digital UNIX does not use the same arch and lib
            # setup as other JVMs
            ARCH_LIB=shlib

            JAVA_SHLIB=libjava.so
            TCLBLEND_LIBS="-ljava"
            TCLBLEND_SHLIB_NAMES="libjava.so"

            TCLBLEND_LD_PRELOAD=
            TCLBLEND_LD_BIND_NOW=0

            ;;
	SunOS) 
	    if test ! -d $JAVA_INCLUDE/native_threads; then
		if test "$JAVA_VERSION" = "1.1"; then
		    if test -r $JAVA_DIR/lib/sparc/native_threads; then
			AC_MSG_RESULT(['$JAVA_INCLUDE/native_threads'
does not exist, but '$JAVA_DIR/lib/sparc/native_threads' is readable,
so you are probably running the production JDK.])
		    else
                        AC_MSG_ERROR(['$JAVA_INCLUDE/native_threads'
does not exist. You must install the Solaris JDK Native Threads Pack to
use tclblend. See http://www.javasoft.com/products/jdk/1.1/index.html.])
                    fi
		fi
	    fi

            JAVA_ARCH_INCLUDE=$JAVA_INCLUDE/solaris

            ARCH=sparc
            ARCH_LIBNAME=lib
            ARCH_LIB=${ARCH_LIBNAME}/${ARCH}

            JAVA_SHLIB=libjava.so
            TCLBLEND_LIBS="-lthread -ljava"
            TCLBLEND_SHLIB_NAMES="libthread.so libjava.so"

            TCLBLEND_LD_PRELOAD=
            TCLBLEND_LD_BIND_NOW=0


            # Check for a "production" release which is really #@&%$ ugly.
            # It would of course be too much to ask for Sun to stick to
            # a single directory naming system.
            
            if  test ! -d $JAVA_DIR/$ARCH_LIB/green_threads &&
                test ! -d $JAVA_DIR/$ARCH_LIB/native_threads &&
                test ! -d $JAVA_DIR/jre/$ARCH_LIB/green_threads &&
                test ! -d $JAVA_DIR/jre/$ARCH_LIB/native_threads ; then
                PRODUCTION_RELEASE=1
                MSG="Sun JDK Production Release Detected."
                echo $MSG >&5
                AC_MSG_RESULT([$MSG])
            fi

	    ;;
	*)
            AC_MSG_ERROR([Sorry, the `uname -s` platform is not supported. You will need to edit the configure.in file to add the proper platform include and lib directories in order to configure and compile tclblend.])
            ;;
    esac


    #
    # Check architecture specific include directory
    #

    AC_MSG_CHECKING([for jni_md.h include file])
    if test -f $JAVA_ARCH_INCLUDE/jni_md.h; then
        MSG="$JAVA_ARCH_INCLUDE/jni_md.h"
        echo "Found $MSG" >&5
        AC_MSG_RESULT([$MSG])
    else
        MSG="Could not find $JAVA_ARCH_INCLUDE/jni_md.h"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi


    #
    # Check architecture specific lib directories
    #

    AC_MSG_CHECKING([the jdk arch lib directory])

    if test "$JAVA_VERSION" = "1.1"; then

        DIR=$JAVA_DIR/$ARCH_LIB
        if test ! -d $DIR; then
            MSG="jdk arch directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        fi

        DIR=$JAVA_DIR/$ARCH_LIB/green_threads
        if test ! -d $DIR; then
            MSG="jdk arch directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_WARN([$MSG])
        else
            JAVA_ARCH_GREEN_LIB=$DIR
            JAVA_ARCH_GREEN_RUNTIME_LIBS=$DIR
        fi

        LIB=$DIR/$JAVA_SHLIB
        if test ! -f $LIB; then
            MSG="jdk shared library $LIB does not exist"
            echo $MSG >&5
            AC_MSG_WARN([$MSG])
        fi

        DIR=$JAVA_DIR/$ARCH_LIB/native_threads
        if test ! -d $DIR; then
            MSG="jdk arch directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        else
            JAVA_ARCH_NATIVE_LIB=$DIR
            JAVA_ARCH_NATIVE_RUNTIME_LIBS=$DIR
        fi

        LIB=$DIR/$JAVA_SHLIB
        if test ! -f $LIB; then
            MSG="jdk shared library $LIB does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        fi

    else

        # if java 1.2 then look in the new jre lib locations

        DIR=$JAVA_DIR/jre/$ARCH_LIB
        if test ! -d $DIR; then
            MSG="jdk directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        else
            JAVA_ARCH_GREEN_LIB=$DIR
            JAVA_ARCH_GREEN_RUNTIME_LIBS=$DIR
            JAVA_ARCH_NATIVE_LIB=$DIR
            JAVA_ARCH_NATIVE_RUNTIME_LIBS=$DIR
        fi

        LIB=$DIR/$JAVA_SHLIB
        if test ! -f $LIB; then
            MSG="jdk shared library $LIB does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        fi

        # A "production" release has no green_threads or native_threads dir

        if test "$PRODUCTION_RELEASE" = "0"; then

        DIR=$JAVA_DIR/jre/$ARCH_LIB/green_threads
        if test ! -d $DIR; then
            MSG="jdk directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_WARN([$MSG])
        else
            JAVA_ARCH_GREEN_RUNTIME_LIBS=$JAVA_ARCH_GREEN_RUNTIME_LIBS:$DIR
        fi

        DIR=$JAVA_DIR/jre/$ARCH_LIB/native_threads
        if test ! -d $DIR; then
            MSG="jdk directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        else
            JAVA_ARCH_NATIVE_RUNTIME_LIBS=$JAVA_ARCH_NATIVE_RUNTIME_LIBS:$DIR
        fi

        DIR=$JAVA_DIR/jre/$ARCH_LIB/classic
        if test ! -d $DIR; then
            MSG="jdk directory $DIR does not exist"
            echo $MSG >&5
            AC_MSG_ERROR([$MSG])
        else
            if test "$JAVA_ARCH_GREEN_LIB" != ""; then
                JAVA_ARCH_GREEN_RUNTIME_LIBS=$JAVA_ARCH_GREEN_RUNTIME_LIBS:$DIR
            fi

            JAVA_ARCH_NATIVE_RUNTIME_LIBS=$JAVA_ARCH_NATIVE_RUNTIME_LIBS:$DIR
        fi

        fi
        # End of "production" if block

    fi

    AC_MSG_RESULT([$JAVA_ARCH_NATIVE_LIB])


    fi
    # End JDK only tests





    # Start Kaffe only tests

    if test "$JAVA_NAME" = "kaffe"; then

    DIR=$JAVA_DIR/lib
    if test ! -d $DIR; then
        MSG="kaffe directory $DIR does not exist"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    else
        JAVA_ARCH_NATIVE_LIB=$DIR
        JAVA_ARCH_NATIVE_RUNTIME_LIBS=$DIR
    fi
    
    DIR=$JAVA_DIR/lib/kaffe
    if test ! -d $DIR; then
        MSG="kaffe directory $DIR does not exist"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    else
        JAVA_ARCH_NATIVE_RUNTIME_LIBS=$JAVA_ARCH_NATIVE_RUNTIME_LIBS:$DIR
    fi

    LIB=$JAVA_DIR/lib/libkaffevm.so
    if test ! -f $LIB; then
        MSG="kaffe shared library $LIB does not exist"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    else
        TCLBLEND_LIBS="-lkaffevm -lpthread"
        TCLBLEND_SHLIB_NAMES="libkaffevm.so libpthread.so"
    fi

    TCLBLEND_LD_PRELOAD=
    TCLBLEND_LD_BIND_NOW=0

    fi
    # End Kaffe only tests




    AC_HEADER_STDC
    # generic/javaCmd.c calls memset
    AC_CHECK_FUNCS(memset)

fi

# End of tclblend's java platform detection section 







# Test the java tools supplied with the JVM


AC_MSG_CHECKING([the Java compiler])

CLASSPATH=$JAVA_CLASSPATH
export CLASSPATH
echo "Using CLASSPATH=$CLASSPATH" >&5

echo "Copied $srcdir/../src/Test.tcl to `pwd`" >&5
cp $srcdir/../src/Test.tcl .

rm -f Test.class
echo "$JAVAC -d . $srcdir/../src/Test.java" >&5
if env $JAVAC -d . $srcdir/../src/Test.java 1>&5 2>&5 &&
    test -f Test.class ; then
    AC_MSG_RESULT([the Java compiler works])

    AC_MSG_CHECKING([the -native flag to the Java runtime])

    CLASSPATH=$JAVA_CLASSPATH:.
    export CLASSPATH
    echo "Using CLASSPATH=$CLASSPATH" >&5

    if test "$JAVA_NAME" = "jdk"; then
	echo "$JAVA -native Test" >&5
    fi
    if test "$JAVA_NAME" = "jdk" &&
	test "`$JAVA -native Test 2>&5`" = "OK"; then
        JAVA_FLAGS=-native
        echo "the -native flag works" >&5
        AC_MSG_RESULT([the -native flag works])

        # -native does not work correctly under JDK 1.1.7 from Blackdown.
        # The problem is related to IO from a shell script.
	# Currently we ignore the JAVA_VERISON FLAG but we really should
	# fix that so that it works for the blackdown port of 1.2. 
        if test "`uname -s`" = "Linux"; then
            JAVA_FLAGS=""
            MSG="skipping -native option because jacl has some problems running with native threads on linux with JDK 1.1 from Blackdown"
            echo $MSG >&5
            AC_MSG_WARN([$MSG])
        fi
    else
        # If -native is not supported then run without it
	echo "$JAVA Test" >&5
	if test "`$JAVA Test 2>&5`" = "OK"; then
            JAVA_FLAGS=""
            MSG="the -native flag does not work"
            echo $MSG >&5
            AC_MSG_RESULT([$MSG])
        else
            AC_MSG_ERROR([could not run simple test program Test.class with $JAVA, you need to check the Java runtime to make sure it is installed correctly])
        fi
    fi

    if test $TCLJAVA = "tclblend" || test $BOTH = "true"; then
        #test out the javah program on our Test.class file and generate Test.h
        AC_MSG_CHECKING([the Java header generation program])

        CLASSPATH=$JAVA_CLASSPATH:.
        export CLASSPATH
        echo "Using CLASSPATH=$CLASSPATH" >&5

        rm -f Test.h
	echo "$JAVAH -jni -o Test.h Test" >&5
        if env $JAVAH -jni -o Test.h Test 2>&5 &&
	    test -f Test.h; then

	    # Echo the lines we might be looking for into config.log
            echo "# Possible matches for method foo" >&5
	    if env grep foo Test.h 1>&5 2>&5 ; then
                echo "# End of possible matches for method foo" >&5
            else
                echo "# No mathes for method foo" >&5
                AC_MSG_WARN([ no lines matched method foo in Test.h])
            fi

	    #make sure the JNI style func got defined in the file
            echo "egrep 'JNIEXPORT[[ |\t]]+void[[ |\t]]+JNICALL[[ |\t]]+Java_Test_foo' Test.h" >&5
	    if env egrep 'JNIEXPORT[[ |\t]]+void[[ |\t]]+JNICALL[[ |\t]]+Java_Test_foo' Test.h 1>&5 2>&5; then
                AC_MSG_RESULT([the Java header generation program works])
            else
                echo "No JNI signature matches found in Test.h" >&5
                AC_MSG_ERROR([Could not find native function definition in Test.h
generated by $JAVAH])
            fi

        else
            AC_MSG_ERROR([Could not generate header from Test.class with $JAVAH])
        fi
    fi

    AC_MSG_CHECKING([the Java archive program])
    echo  ""

    # use jar program to create an uncompressed archive

    CLASSPATH=$JAVA_CLASSPATH
    export CLASSPATH
    echo "Using CLASSPATH=$CLASSPATH" >&5

    rm -f Test.jar
    echo  "$JAR -cf0 Test.jar Test.class" >&5
    if env $JAR -cf0 Test.jar Test.class 2>&5 && test -f Test.jar; then
        AC_MSG_RESULT([the jar program creates uncompressed archives])
    else
        MSG="the jar program could not create an uncompressed archive"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi

    # test out extraction of .class file from an uncompressed jar

    rm -f Test.class
    echo  "$JAR -xf Test.jar" >&5
    if env $JAR -xf Test.jar 2>&5 && test -f Test.class; then
        AC_MSG_RESULT([the jar program extracts uncompressed archives])
    else
        MSG="the jar program could not extract from an uncompressed archive" 
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi

    # use jar program to create a compressed archive
    rm -f Test.jar
    echo  "$JAR -cf Test.jar Test.class" >&5
    if env $JAR -cf Test.jar Test.class 2>&5 && test -f Test.jar; then
        AC_MSG_RESULT([the jar program creates compressed archives])
    else
        MSG="the jar program could not create a compressed archive"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi

    # test out extraction of .class file from a compressed jar

    rm -f Test.class
    echo  "$JAR -xf Test.jar" >&5
    if env $JAR -xf Test.jar 2>&5 && test -f Test.class; then
        AC_MSG_RESULT([the jar program extracts compressed archives])
    else
        MSG="the jar program could not extract from a compressed archive"
        echo $MSG >&5
        AC_MSG_ERROR([$MSG])
    fi

    # clean up, people might think they need Test.jar
    rm -f Test.jar


    # Run Test.class again so that we are sure the jar
    # programs did not screw it up

    AC_MSG_CHECKING([that the jar program did not corrupt the test file])

    CLASSPATH=$JAVA_CLASSPATH:.
    export CLASSPATH
    echo "Using CLASSPATH=$CLASSPATH" >&5

    echo "$JAVA Test" >&5
    if test "`$JAVA Test 2>&5`" = "OK"; then
        AC_MSG_RESULT([it did not])
    else
        AC_MSG_ERROR([Test.class has been corrupted.])
    fi

    # Test.class is not removed because it is needed later
    # to verify that the installed shell is working.

else
    MSG="Could not compile simple test program Test.java
with $JAVAC"
    echo $MSG >&5
    AC_MSG_ERROR([$MSG])
fi



#--------------------------------------------------------------------
#	If the TCLJAVA variable equals tclblend or both then we 
#       need to grab some variables from the tclConfig.sh
#--------------------------------------------------------------------

if test $TCLJAVA = "tclblend" || test $BOTH = "true"; then

    #--------------------------------------------------------------------
    #	See if there was a command-line option for where Tcl is;  if
    #	not, assume that its top-level directory is a sibling of ours.
    #--------------------------------------------------------------------
    
    AC_ARG_WITH(tcl, [  --with-tcl=DIR          build directory for Tcl 8.X source release from DIR],
    	TCL_BIN_DIR=$withval, TCL_BIN_DIR="$srcdir/../../tcl8.0.5/unix")

    if test ! -d $TCL_BIN_DIR; then
        AC_MSG_ERROR([Tcl directory could not be located.
Use the --with-tcl=<dirName> configure flag to specify the location.])
    else
	TCL_BIN_DIR=`cd $TCL_BIN_DIR; pwd`
    fi

    echo "checking for Tcl build in $TCL_BIN_DIR"

    if test ! -f $TCL_BIN_DIR/tclConfig.sh; then
        # provide shortcut if --with-tcl=$PATH/tcl8.X was given
        if test -f $TCL_BIN_DIR/unix/tclConfig.sh; then
            TCL_BIN_DIR=$TCL_BIN_DIR/unix
        else
	    AC_MSG_ERROR([Tcl was not configured in the directory $TCL_BIN_DIR.])
        fi
    fi

    #--------------------------------------------------------------------
    #	Read in configuration information generated by Tcl for shared
    #	libraries, and arrange for it to be substituted into our
    #	Makefile.
    #--------------------------------------------------------------------

    file=$TCL_BIN_DIR/tclConfig.sh
    . $file
    if test $TCL_SHARED_BUILD -eq 0 ; then
	AC_MSG_ERROR([Tcl was not built correctly.  
Make sure Tcl was configured with --enable-shared.])
    fi

    CC=$TCL_CC
    SHLIB_CFLAGS=$TCL_SHLIB_CFLAGS
    SHLIB_LD=$TCL_SHLIB_LD
    SHLIB_LD_LIBS=$TCL_SHLIB_LD_LIBS
    SHLIB_SUFFIX=$TCL_SHLIB_SUFFIX
    SHLIB_VERSION=$TCL_SHLIB_VERSION

    if test "$TCL_DBGX" = "g"; then
        if test "$TCL_CFLAGS_DEBUG" = ""; then
            TCL_CFLAGS='-g'
        else
            TCL_CFLAGS=$TCL_CFLAGS_DEBUG
        fi
    else
        if test "$TCL_CFLAGS_OPTIMIZE" = ""; then
            TCL_CFLAGS='-O'
        else
            TCL_CFLAGS=$TCL_CFLAGS_OPTIMIZE
        fi
    fi

    # Default for SHLIB_LD_LIBS if empty (fixes tcl config bug)
    if test "`uname -s`" = "Linux" || test "`uname -s`" = "IRIX"; then
        if test "$SHLIB_LD_LIBS" = ""; then
            echo "Using SHLIB_LD_LIBS on `uname -s` workaround" >&5
            SHLIB_LD_LIBS='${LIBS}'
        else
            echo "Not using SHLIB_LD_LIBS on `uname -s` workaround" >&5
        fi
    fi

    # Fix up the TCL_LD_SEARCH_FLAGS when running under Solaris

    case "`uname -s`" in
        SunOS*)
            TCL_LD_SEARCH_FLAGS=`echo ${TCL_LD_SEARCH_FLAGS} | sed -e 's/-Wl,-R,/-R /'`
            ;;
        IRIX)
            TCL_LD_SEARCH_FLAGS=`echo ${TCL_LD_SEARCH_FLAGS} | sed -e 's/-Wl,-rpath,/-rpath /'`
            ;;
    esac

    # Define used when we compile with kaffe
    if test "$JAVA_NAME" = "kaffe"; then
        TCL_CFLAGS="$TCL_CFLAGS -DTCLBLEND_KAFFE"
    fi

    AC_SUBST(CC)
    AC_SUBST(SHLIB_CFLAGS)
    AC_SUBST(SHLIB_LD)
    AC_SUBST(SHLIB_LD_LIBS)
    AC_SUBST(SHLIB_SUFFIX)
    AC_SUBST(SHLIB_VERSION)
    AC_SUBST(TCL_BUILD_LIB_SPEC)
    AC_SUBST(TCL_DBGX)
    AC_SUBST(TCL_CFLAGS)
    AC_SUBST(TCL_LIBS)
    AC_SUBST(TCL_VERSION)
    AC_SUBST(TCL_SRC_DIR)
    AC_SUBST(TCL_BIN_DIR)
    AC_SUBST(TCL_LD_SEARCH_FLAGS)
    AC_SUBST(JAVA_ARCH_INCLUDE)
    AC_SUBST(JAVA_ARCH_GREEN_LIB)
    AC_SUBST(JAVA_ARCH_GREEN_RUNTIME_LIBS)
    AC_SUBST(JAVA_ARCH_NATIVE_LIB)
    AC_SUBST(JAVA_ARCH_NATIVE_RUNTIME_LIBS)
    AC_SUBST(TCLBLEND_LIBS)
    AC_SUBST(TCLBLEND_SHLIB_NAMES)
    AC_SUBST(TCLBLEND_LD_PRELOAD)
    AC_SUBST(TCLBLEND_LD_BIND_NOW)
fi




#
# Check for the installed version of tclsh and wish. we need to use the
# one we compiled against because you can not compile with one version
# and then load into another. If you compiled Tcl Blend with Tcl 8.1 and
# then load it into a Tcl 8.0 interp, it will segfault.
#

if test $TCLJAVA = "tclblend" || test $BOTH = "true"; then

  # Check to make sure that tclsh has been built by looking for the
  # tclsh executable in the TCL_BIN_DIR directory.

  if test ! -x $TCL_BIN_DIR/tclsh; then
    AC_MSG_ERROR([Tcl was configued in $TCL_BIN_DIR, but it has not been built, please build it and run configure again.])
  fi

  # Double check that tclsh works and that it is tclsh8.0 or better
  # We need to set LD_LIBRARY_PATH and SHLIB_PATH so that Tcl can find its
  # shared library in the build directory on a Unix or HP-UX system.

  LD_LIBRARY_PATH=$TCL_BIN_DIR:$LD_LIBRARY_PATH
  export LD_LIBRARY_PATH
  SHLIB_PATH=$TCL_BIN_DIR:$SHLIB_PATH
  export SHLIB_PATH

  TCLSH_LOC=$TCL_BIN_DIR/tclsh
  rm -f tcl_version.tcl
  echo 'puts [[expr {[info tclversion] >= 8.0}]] ; exit 0' > tcl_version.tcl
  if test "`$TCLSH_LOC tcl_version.tcl 2>&5`" = "1"; then
      AC_MSG_RESULT([Tcl executable $TCLSH_LOC works])
      rm -f tcl_version.tcl
  else
      # If the shell did not run or it was not at least Tcl 8.0, generate error
      rm -f tcl_version.tcl
      AC_MSG_ERROR([$TCLSH_LOC does not work or is not the correct version])
  fi

  # Now check to see if "make install" has been run in the tcl directory.
  # The installed executable name is tclsh8.0, tclsh8.1, or tclsh8.2.
  # We also assume that wish is going to be installed in the same
  # location, which could be incorrect but oh well.

  TCLSH=$TCL_EXEC_PREFIX/bin/tclsh$TCL_VERSION
  WISH=$TCL_EXEC_PREFIX/bin/wish$TCL_VERSION

  if test ! -x $TCLSH; then
      AC_MSG_WARN([Tcl has not been installed yet, it must be installed before installing Tcl Blend])
  fi

  AC_SUBST(WISH)
  AC_SUBST(TCLSH)

fi



# Subst variables that are used in both jacl and tclblend

# Directory where we are building, used for CLASSPATH when we test
BUILD_DIR=`pwd`
AC_SUBST(BUILD_DIR)

AC_SUBST(JAVA)
AC_SUBST(JAVA_G)
AC_SUBST(JAVAC)
AC_SUBST(JAVAH)
AC_SUBST(JAR)
AC_SUBST(JDB)
AC_SUBST(DDD)

AC_SUBST(JAVA_CLASSPATH)
AC_SUBST(JAVA_FLAGS)
AC_SUBST(JAVA_INCLUDE)

AC_SUBST(TCLJAVA_VERSION)
AC_SUBST(TCLJAVA_NODOT_VERSION)
AC_SUBST(TCLJAVA)

if test $TCLJAVA = "jacl"; then 
    PROCESS_FILES="Makefile jaclsh"
elif test $TCLJAVA = "tclblend" && test $BOTH != "true"; then
    PROCESS_FILES="Makefile jtclsh"
else
    PROCESS_FILES="Makefile jtclsh jaclsh"
fi

AC_OUTPUT([$PROCESS_FILES])

