David Reiss | d9cdf42 | 2009-03-13 21:25:29 +0000 | [diff] [blame] | 1 | dnl @synopsis AX_JAVAC_AND_JAVA |
| 2 | dnl |
| 3 | dnl Test for the presence of a JDK. |
| 4 | dnl |
| 5 | dnl If "JAVA" is defined in the environment, that will be the only |
| 6 | dnl java command tested. Otherwise, a hard-coded list will be used. |
| 7 | dnl Similarly for "JAVAC". |
| 8 | dnl |
| 9 | dnl This macro does not currenly support testing for a particular |
| 10 | dnl Java version, the presence of a particular class, testing for |
| 11 | dnl only one of "java" and "javac", or compiling or running |
| 12 | dnl user-provided Java code. |
| 13 | dnl |
| 14 | dnl After AX_JAVAC_AND_JAVA runs, the shell variables "success" and |
| 15 | dnl "ax_javac_and_java" are set to "yes" or "no", and "JAVAC" and |
| 16 | dnl "JAVA" are set to the appropriate commands. |
| 17 | dnl |
| 18 | dnl @category Java |
David Reiss | d9cdf42 | 2009-03-13 21:25:29 +0000 | [diff] [blame] | 19 | dnl @version 2009-02-09 |
| 20 | dnl @license AllPermissive |
| 21 | dnl |
| 22 | dnl Copyright (C) 2009 David Reiss |
| 23 | dnl Copying and distribution of this file, with or without modification, |
| 24 | dnl are permitted in any medium without royalty provided the copyright |
| 25 | dnl notice and this notice are preserved. |
| 26 | |
| 27 | |
| 28 | AC_DEFUN([AX_JAVAC_AND_JAVA], |
| 29 | [ |
| 30 | |
| 31 | dnl Hard-coded default commands to test. |
| 32 | JAVAC_PROGS="javac,jikes,gcj -C" |
| 33 | JAVA_PROGS="java,kaffe" |
| 34 | |
| 35 | dnl Allow the user to specify an alternative. |
| 36 | if test -n "$JAVAC" ; then |
| 37 | JAVAC_PROGS="$JAVAC" |
| 38 | fi |
| 39 | if test -n "$JAVA" ; then |
| 40 | JAVA_PROGS="$JAVA" |
| 41 | fi |
| 42 | |
| 43 | AC_MSG_CHECKING(for javac and java) |
| 44 | |
| 45 | echo "public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java |
| 46 | success=no |
| 47 | oIFS="$IFS" |
| 48 | |
| 49 | IFS="," |
| 50 | for JAVAC in $JAVAC_PROGS ; do |
| 51 | IFS="$oIFS" |
| 52 | |
| 53 | echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD |
| 54 | if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then |
| 55 | |
| 56 | IFS="," |
| 57 | for JAVA in $JAVA_PROGS ; do |
| 58 | IFS="$oIFS" |
| 59 | |
| 60 | echo "Running \"$JAVA configtest_ax_javac_and_java\"" >&AS_MESSAGE_LOG_FD |
| 61 | if $JAVA configtest_ax_javac_and_java >&AS_MESSAGE_LOG_FD 2>&1 ; then |
| 62 | success=yes |
| 63 | break 2 |
| 64 | fi |
| 65 | |
| 66 | done |
| 67 | |
| 68 | fi |
| 69 | |
| 70 | done |
| 71 | |
| 72 | rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class |
| 73 | |
| 74 | if test "$success" != "yes" ; then |
| 75 | AC_MSG_RESULT(no) |
| 76 | JAVAC="" |
| 77 | JAVA="" |
| 78 | else |
| 79 | AC_MSG_RESULT(yes) |
| 80 | fi |
| 81 | |
| 82 | ax_javac_and_java="$success" |
| 83 | |
| 84 | ]) |