+ # Use BSD hexdump.
+ func_classfile_version ()
+ {
+ dd if="[$]1" bs=1 count=1 skip=7 2>/dev/null | hexdump -e '1/1 "%3d "'
+ echo
+ }
+ fi
+ AC_MSG_CHECKING([for Java compiler])
+ dnl
+ dnl The support of GNU gcj for target-version and source-version:
+ dnl
+ dnl gcj 3.0.4 to 4.1 does not have a way to specify the target-version.
+ dnl It always assumes target-version=1.4 but labels the class files as 1.1.
+ dnl One consequence of this is that gcj compiles GetURL.java to invalid
+ dnl bytecode, which crashes with a VerifyError when executed by Sun Java
+ dnl 1.3.1. The bug is registered as java/7066, see
+ dnl http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7066
+ dnl FIXME: Check new versions of gcj as they come out.
+ dnl
+ dnl For gcj < 3.3, the source-version always is 1.3.
+ dnl For gcj >= 3.3, the source-version defaults to 1.4; option
+ dnl "-fno-assert" switches to source-version 1.3.
+ dnl
+ dnl The support of Sun javac for target-version and source-version:
+ dnl
+ dnl javac 1.3: -target 1.1 1.2 1.3 default: 1.1
+ dnl source always: 1.3
+ dnl
+ dnl javac 1.4: -target 1.1 1.2 1.3 1.4 default: 1.2
+ dnl -source 1.3 1.4 default: 1.3
+ dnl -target 1.1/1.2/1.3 only possible with -source 1.3 or no -source
+ dnl
+ dnl javac 1.5: -target 1.1 1.2 1.3 1.4 1.5 default: 1.5
+ dnl -source 1.3 1.4 1.5 default: 1.5
+ dnl -target 1.1/1.2/1.3 only possible with -source 1.3
+ dnl -target 1.4 only possible with -source 1.3/1.4
+ dnl
+ dnl javac 1.6: -target 1.1 1.2 1.3 1.4 1.5 1.6 default: 1.6
+ dnl -source 1.3 1.4 1.5 1.6 default: 1.5
+ dnl -target 1.1/1.2/1.3 only possible with -source 1.3
+ dnl -target 1.4 only possible with -source 1.3/1.4
+ dnl -target 1.5 only possible with -source 1.3/1.4/1.5 or no -source
+ dnl
+ dnl The support of jikes for target-version and source-version:
+ dnl
+ dnl jikes 1.14 does not have a way to specify the target-version. It
+ dnl always assumes target-version=1.1.
+ dnl
+ dnl For jikes 1.14, the source-version always is 1.3.
+ dnl
+ CONF_JAVAC=
+ HAVE_JAVAC_ENVVAR=
+ HAVE_GCJ_C=
+ HAVE_JAVAC=
+ HAVE_JIKES=
+ HAVE_JAVACOMP=
+changequote(,)dnl
+ cat > conftestlib.java <<EOF
+public class conftestlib {
+ public static void main (String[] args) {
+ }
+}
+EOF
+changequote([,])dnl
+ echo "$goodcode" > conftest.java
+ echo "$failcode" > conftestfail.java
+ dnl If the user has set the JAVAC environment variable, use that, if it
+ dnl satisfies the constraints (possibly after adding -target and -source
+ dnl options).
+ if test -n "$JAVAC"; then
+ dnl Try the original $JAVAC.
+ if $JAVAC --version 2>/dev/null | sed -e 1q | grep gcj > /dev/null; then
+ dnl It's a version of gcj. Ignore the version of conftest.class.
+ if test "$target_version" = 1.4 && test "$source_version" = 1.4; then
+ dnl Try $JAVAC.
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class; then
+ CONF_JAVAC="$JAVAC"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ fi
+ else
+ if test "$target_version" = 1.4 && test "$source_version" = 1.3; then
+ dnl Try $JAVAC and "$JAVAC -fno-assert". But add -fno-assert only if
+ dnl it makes a difference. (It could already be part of $JAVAC.)
+ javac_works=
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class; then
+ javac_works=1
+ fi
+ javac_noassert_works=
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -fno-assert -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -fno-assert -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class; then
+ javac_noassert_works=1
+ fi
+ if test -n "$javac_works" && test -n "$javac_noassert_works"; then
+ rm -f conftestfail.class
+ if { echo "$as_me:__oline__: $JAVAC -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftestfail.class \
+ && ! { echo "$as_me:__oline__: $JAVAC -fno-assert -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -fno-assert -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ }; then
+ dnl "$JAVAC -fno-assert" works better than $JAVAC.
+ javac_works=
+ fi
+ fi
+ if test -n "$javac_works"; then
+ CONF_JAVAC="$JAVAC"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ else
+ if test -n "$javac_noassert_works"; then
+ CONF_JAVAC="$JAVAC -fno-assert"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ fi
+ fi
+ fi
+ fi
+ else
+ dnl It's not gcj. Assume the classfile versions are correct.
+ dnl Try $JAVAC.
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class \
+ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
+ dnl Try adding -source option if it is useful.
+ rm -f conftest.class
+ rm -f conftestfail.class
+ if { echo "$as_me:__oline__: $JAVAC -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class \
+ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
+ && { echo "$as_me:__oline__: $JAVAC -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftestfail.class \
+ && ! { echo "$as_me:__oline__: $JAVAC -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ }; then
+ CONF_JAVAC="$JAVAC -source $source_version"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ else
+ CONF_JAVAC="$JAVAC"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ fi
+ else
+ dnl Try with -target option alone. (Sun javac 1.3.1 has the -target
+ dnl option but no -source option.)
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -target "$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class \
+ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
+ dnl Try adding -source option if it is useful.
+ rm -f conftest.class
+ rm -f conftestfail.class
+ if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class \
+ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
+ && { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -target "$target_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftestfail.class \
+ && ! { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -target "$target_version" -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
+ }; then
+ CONF_JAVAC="$JAVAC -target $target_version -source $source_version"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ else
+ CONF_JAVAC="$JAVAC -target $target_version"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ fi
+ else
+ dnl Maybe this -target option requires a -source option? Try with
+ dnl -target and -source options. (Supported by Sun javac 1.4 and
+ dnl higher.)
+ rm -f conftest.class
+ if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class \
+ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
+ CONF_JAVAC="$JAVAC -target $target_version -source $source_version"
+ HAVE_JAVAC_ENVVAR=1
+ HAVE_JAVACOMP=1
+ fi
+ fi
+ fi
+ fi
+ fi
+ if test -z "$HAVE_JAVACOMP"; then