# File obtained from TCLJAVA at http://cvs.sourceforge.net/viewcvs.py/*checkout*/tcljava/tcljava/tcljava.m4?rev=1.27 #------------------------------------------------------------------------ # AC_MSG_LOG( MSG, ?LOGONLY? ) # # Write the message out to the config.log file and the console. # If 1 is passed as the second argument, then write to the # config.log file only. # # Arguments: # 1. The message to log # 2. Optional boolean, if true then write to config.log only #------------------------------------------------------------------------ AC_DEFUN([AC_MSG_LOG], [ echo $1 >&AS_MESSAGE_LOG_FD m4_ifval([$2],,[echo $1]) ]) #------------------------------------------------------------------------ # AC_GREP_FILE( PATTERN, FILE, ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]) # # Use grep to search for a pattern in a file. If the pattern # is not found then return a non zero exit status. No information # will be echoed to the screen by this macro. # # Arguments: # 1. The pattern to search for # 2. The name of the file to be grep'ed # 3. The script to execute if PATTERN is found in FILE # 4. The script to execute if PATTERN is not found in FILE (optional) #------------------------------------------------------------------------ AC_DEFUN([AC_GREP_FILE], [ AC_MSG_LOG([grep in $2 for pattern '"$1"'], 1) if (grep "$1" $2 > /dev/null 2>&1) ; then AC_MSG_LOG([grep result : yes], 1) $3 else AC_MSG_LOG([grep result : no], 1) m4_ifval([$4], [ $4 ])dnl fi ]) #------------------------------------------------------------------------ # AC_JAVA_WITH_JDK # # Check to see if the --with-jdk command line option is given. # If it was, then set ac_java_with_jdk to the DIR argument. # # Arguments: # NONE # # VARIABLES SET: # ac_java_with_jdk can be set to the directory where the jdk lives # ac_java_jvm_name can be set to "jdk" #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_WITH_JDK], [ AC_ARG_WITH(jdk, [ --with-jdk=DIR use Sun's JDK from DIR], ok=$withval, ok=no) if test "$ok" = "no" ; then NO=op elif test "$ok" = "yes" || test ! -d "$ok"; then AC_MSG_ERROR([--with-jdk=DIR option, must pass a valid DIR]) elif test "$ok" != "no" ; then ac_java_jvm_dir=$ok ac_java_jvm_name=jdk fi ]) #------------------------------------------------------------------------ # AC_JAVA_WITH_KAFFE # # Check to see if the --with-kaffe command line option is given. # If it was, then set ac_java_with_kaffe to the DIR argument. # # Arguments: # NONE # # VARIABLES SET: # ac_java_jvm_dir can be set to the directory where the kaffe lives # ac_java_jvm_name cab be set to "kaffe" #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_WITH_KAFFE], [ AC_ARG_WITH(kaffe, [ --with-kaffe=DIR use Kaffe Open JVM], ok=$withval, ok=no) if test "$ok" = "no" ; then NO=op elif test "$ok" = "yes" || test ! -d "$ok"; then AC_MSG_ERROR([--with-kaffe=DIR option, must pass a valid DIR]) elif test "$ok" != "no" ; then ac_java_jvm_dir=$ok ac_java_jvm_name=kaffe fi ]) #------------------------------------------------------------------------ # AC_JAVA_WITH_JIKES # # Check to see if the --with-jikes command line option is given. # If it was, then set JAVAC to the jikes compiler. We default # to using jikes if it can be found event if --with-jikes is not given. # # If you want to use jikes as a cross compiler, you will need to # use this macro before AC_JAVA_DETECT_JVM and set the CLASSPATH # env variable before running configure. # # Arguments: # NONE # # VARIABLES SET: # JAVAC #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_WITH_JIKES], [ AC_ARG_WITH(jikes, [ --with-jikes=PROG use jikes compiler given by PROG, if PROG is not given look for jikes on the PATH.], ok=$withval, ok=yes) if test "$ok" = "no" ; then JIKES= else if test "$ok" = "yes"; then AC_PATH_PROG(JIKES, jikes, $JAVAC) else JIKES=$ok fi AC_MSG_LOG([Using JIKES=$JIKES], 1) fi ]) #------------------------------------------------------------------------ # AC_PROG_JAVAC # # If JAVAC is not already defined, then search for "javac" on # the path. If a java compiler is found, then test it to make # sure it actually works. # # Arguments: # NONE # # VARIABLES SET: # JAVAC can be set to the path name of the java compiler # JAVAC_FLAGS can be set to compiler specific flags # ac_java_jvm_dir can be set to the jvm's root directory #------------------------------------------------------------------------ AC_DEFUN([AC_PROG_JAVAC], [ if test "x$JAVAC" = "x" ; then AC_PATH_PROG(JAVAC, javac) if test "x$JAVAC" = "x" ; then AC_MSG_ERROR([javac not found on PATH ... did you forget --with-jdk=DIR]) fi fi if test ! -f "$JAVAC" ; then AC_MSG_ERROR([javac '$JAVAC' does not exist. Perhaps Java is not installed or you passed a bad dir to a --with option.]) fi # Check for Solaris install which uses a symlink in /usr/bin to /usr/java/bin if test -h "$JAVAC" ; then BASE=`basename $JAVAC` DIR=`dirname $JAVAC` if test -f $DIR/../java/bin/$BASE ; then JAVAC=`cd $DIR/../java/bin;pwd`/$BASE fi fi # If we were searching for javac, then set ac_java_jvm_dir if test "x$ac_java_jvm_dir" = "x"; then TMP=`dirname $JAVAC` TMP=`dirname $TMP` ac_java_jvm_dir=$TMP fi # If the user wanted to use jikes instead of javac, set that now if test "x$JIKES" != "x" ; then JAVAC=$JIKES fi # FIXME : add detection of command line arguments for JAVAC JAVAC_FLAGS=-g JAVAC_D_FLAG=-d dnl Test out the Java compiler with an empty class AC_MSG_CHECKING([to see if the java compiler works]) AC_JAVA_TRY_COMPILE(,,works=yes) if test "$works" = "yes" ; then AC_MSG_RESULT($works) else AC_MSG_ERROR([Could not compile simple Java program with '$JAVAC']) fi AC_MSG_LOG([Using JAVAC=$JAVAC], 1) ]) #------------------------------------------------------------------------ # AC_JAVA_TRY_COMPILE(imports, main-body, action-if-worked, [action-if-failed]) # # Try to compile a Java program. This works a lot like AC_TRY_COMPILE # except is supports Java instead of C or C++. This macro will create # a file named Test.java and try to compile it. # # Arguments: # imports should contain Java import statements like [import java.util.*;] # main-body should contain the code to appear in the main() method # action-if-worked should contain the code to run if the compile worked # action-if-failed should contain the code to run if the compile failed (optional) #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_TRY_COMPILE], [ cat << \EOF > conftest.java // [#]line __oline__ "configure" [$1] public class conftest { public static void main(String[[]] argv) { [$2] } } EOF CLASSPATH=$ac_java_classpath export CLASSPATH cmd="$JAVAC ${JAVAC_FLAGS} conftest.java" if (echo $cmd >&AS_MESSAGE_LOG_FD ; eval $cmd >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD) ; then echo "yes" >&AS_MESSAGE_LOG_FD $3 else echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD cat conftest.java >&AS_MESSAGE_LOG_FD echo "configure: CLASSPATH was $CLASSPATH" >&AS_MESSAGE_LOG_FD m4_ifval([$4], [ $4 ])dnl fi ]) #------------------------------------------------------------------------ # AC_JAVA_DETECT_JVM # # Figure out what JVM to build with. If no JVM was already defined # using a --with command line option then we search for one # by looking for the javac executable. # # Arguments: # NONE # # VARIABLES SET: # JAVAC # ac_java_jvm_version can be set to 1.1, 1.2, or 1.3 # ac_java_jvm_dir can be set to the jvm's root directory # # DEPENDS ON: # This macro can depend on the values set by the following macros: # AC_JAVA_WITH_JDK # AC_JAVA_WITH_KAFFE # AC_PROG_JAVAC #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_DETECT_JVM], [ # if we do not know the jvm dir, javac will be found on the PATH if test "x$JAVAC" = "x" && test "x$ac_java_jvm_dir" != "x"; then ac_java_jvm_dir=`cd $ac_java_jvm_dir ; pwd` JAVAC=$ac_java_jvm_dir/bin/javac${EXEEXT} fi # Search for and test the javac compiler AC_PROG_JAVAC AC_MSG_LOG([Java found in $ac_java_jvm_dir]) # Try to detect non JDK JVMs. If we can't, then just assume a jdk AC_MSG_CHECKING([type of jvm]) if test "x$ac_java_jvm_name" = "x" ; then AC_JAVA_TRY_COMPILE([import kaffe.lang.Application;],,ac_java_jvm_name=kaffe) fi if test "x$ac_java_jvm_name" = "x" ; then AC_JAVA_TRY_COMPILE([import gnu.java.io.EncodingManager;],,ac_java_jvm_name=gcj) fi if test "x$ac_java_jvm_name" = "x" ; then ac_java_jvm_name=jdk fi AC_MSG_RESULT([$ac_java_jvm_name]) case "$ac_java_jvm_name" in gcj) DO=nothing ;; jdk) DO=nothing ;; kaffe) DO=nothing ;; *) AC_MSG_ERROR(['$ac_java_jvm_name' is not a supported JVM]) ;; esac # Try to detect the version of java that is installed AC_MSG_CHECKING([java API version]) # The class java.lang.StrictMath is new to 1.3 AC_JAVA_TRY_COMPILE([import java.lang.StrictMath;], , ac_java_jvm_version=1.3) # The class java.lang.Package is new to 1.2 if test "x$ac_java_jvm_version" = "x" ; then AC_JAVA_TRY_COMPILE([import java.lang.Package;], , ac_java_jvm_version=1.2) fi # The class java.lang.reflect.Method is new to 1.1 if test "x$ac_java_jvm_version" = "x" ; then AC_JAVA_TRY_COMPILE([import java.lang.reflect.Method;], , ac_java_jvm_version=1.1) fi if test "x$ac_java_jvm_version" = "x" ; then AC_MSG_ERROR([Could not detect Java version 1.1 or newer]) fi AC_MSG_RESULT([$ac_java_jvm_version]) ]) #------------------------------------------------------------------------ # AC_JAVA_JNI_INCLUDE # # Figure out where jni.h and jni_md.h include files are installed. # # Arguments: # NONE # # VARIABLES SET: # ac_java_jvm_jni_include_flags : Flags that we pass to the compiler # so that it can locate JNI headers. (for example: -I/usr/jdk/include) # # DEPENDS ON: # This macro must be run after the AC_JAVA_DETECT_JVM macro as # it depends on the ac_java_jvm_dir variable. #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_JNI_INCLUDE], [ # Look for jni.h in the subdirectory $ac_java_jvm_dir/include F=$ac_java_jvm_dir/include/jni.h if test -f "$F" ; then ac_java_jvm_jni_include_flags="-I`dirname $F`" else F=`ls $ac_java_jvm_dir/include/*/jni.h 2>/dev/null` if test -f "$F" ; then ac_java_jvm_jni_include_flags="-I`dirname $F`" else AC_MSG_ERROR([Could not locate Java's jni.h include file]) fi fi # Look for jni_md.h in an arch specific subdirectory # we assume that there is only one arch subdirectory, # if that is not the case we would need to use $host # FIXME: check to make sure this works in case the above else # branch is taken, (a include subdir for an arch?) F=`ls $ac_java_jvm_dir/include/*/jni_md.h 2>/dev/null` if test -f "$F" ; then ac_java_jvm_jni_include_flags="$ac_java_jvm_jni_include_flags -I`dirname $F`" else F=`ls $ac_java_jvm_dir/include/kaffe/jtypes.h 2>/dev/null` if test -f "$F" ; then ac_java_jvm_jni_include_flags="$ac_java_jvm_jni_include_flags -I`dirname $F`" fi fi AC_MSG_LOG([Using the following JNI include flags $ac_java_jvm_jni_include_flags]) # Make sure a simple #include will compile. AC_REQUIRE([AC_PROG_CC]) AC_CACHE_CHECK(to see if jni.h can be included, ac_java_jvm_jni_working,[ AC_LANG_PUSH(C) ac_saved_cflags=$CFLAGS CFLAGS="$CFLAGS $ac_java_jvm_jni_include_flags" AC_TRY_COMPILE([ #include ],[return 0;], ac_java_jvm_jni_working=yes, AC_MSG_ERROR([could not compile file that includes jni.h])) AC_LANG_POP() CFLAGS=$ac_saved_cflags ]) # FIXME: should we look for or require a include/native_threads dir? ]) #------------------------------------------------------------------------ # AC_JAVA_JNI_LIBS # # Figure out where the native threads libraries for JNI live. # # Arguments: # NONE # # VARIABLES SET: # ac_java_jvm_ld_preload : list of libraries to include in LD_PROLOAD # ac_java_jvm_ld_bind_now : if set to 1, then use LD_BIND_NOW=1 # ac_java_jvm_jni_lib_flags : library flags that we will pass to the compiler. # For instance, we might pass -L/usr/jdk/lib -ljava # ac_java_jvm_jni_lib_runtime_path : colon seperated path of directories # that is typically passed to rld. # # DEPENDS ON: # This macro must be run after the AC_JAVA_DETECT_JVM macro as # it depends on the ac_java_jvm_dir variable. #------------------------------------------------------------------------ AC_DEFUN([AC_JAVA_JNI_LIBS], [ machine=`uname -m` case "$machine" in i?86) machine=i386 ;; esac if test "$ac_java_jvm_name" = "kaffe" ; then # Kaffe JVM under Cygwin (untested, is -lpthread needed?) F=lib/kaffevm.dll if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-lpthread -L$D -lkaffevm" fi fi # Kaffe JVM under Unix F=lib/libkaffevm.so if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-lpthread -L$D -lkaffevm -ldl" # Kaffe requires lib/kaffe on the lib path or it fails to load D=$ac_java_jvm_dir/lib/kaffe ac_java_jvm_jni_lib_runtime_path="${ac_java_jvm_jni_lib_runtime_path}:$D" else F=jre/lib/$machine/libkaffevm.so AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-lpthread -L$D -lkaffevm -ldl" # Kaffe needs the machine dir on the lib path ac_java_jvm_jni_lib_runtime_path="${ac_java_jvm_jni_lib_runtime_path}:$D" fi fi fi fi # Check for known JDK installation layouts if test "$ac_java_jvm_name" = "jdk"; then # IBM JDK 1.3 for Linux F=jre/bin/libjava.so if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-lpthread -L$D -ljawt" fi fi # Sun JDK 1.2 for Solaris F=jre/lib/sparc/libjava.so if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-lthread -L$D -ljawt" fi fi # Sun/Blackdown JDK 1.3 and 1.4 for Linux # The "classic" vm is only supported in 1.3 and it core dumps # when loading the java package. Use the "client" vm # unless "classic" is the only one available. F=jre/lib/$machine/libjava.so if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D=`dirname $ac_java_jvm_dir/$F` ac_java_jvm_jni_lib_runtime_path=$D ac_java_jvm_jni_lib_flags="-L$D -ljawt" fi fi # IBM JDK 1.3 for Win32 F=lib/jawt.lib if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_LOG([Looking for $ac_java_jvm_dir/$F], 1) if test -f $ac_java_jvm_dir/$F ; then AC_MSG_LOG([Found $ac_java_jvm_dir/$F], 1) D1=$ac_java_jvm_dir/jre/bin ac_java_jvm_jni_lib_runtime_path="${D1}" ac_java_jvm_jni_lib_flags="$ac_java_jvm_dir/$F" fi fi fi # Generate error for unsupported JVM layout if test "x$ac_java_jvm_jni_lib_flags" = "x" ; then AC_MSG_ERROR([Could not detect the location of the Java shared library. You will need to update tcljava.m4 to add support for this JVM configuration.]) fi AC_MSG_LOG([Using the following JNI library flags $ac_java_jvm_jni_lib_flags]) AC_MSG_LOG([Using the following runtime library path $ac_java_jvm_jni_lib_runtime_path]) AC_MSG_LOG([Using LD_PRELOAD=$ac_java_jvm_ld_preload], 1) AC_MSG_LOG([Using LD_BIND_NOW=$ac_java_jvm_ld_bind_now], 1) ])