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 |
| 19 | dnl @author David Reiss <dreiss@facebook.com> |
| 20 | dnl @version 2009-02-09 |
| 21 | dnl @license AllPermissive |
| 22 | dnl |
| 23 | dnl Copyright (C) 2009 David Reiss |
| 24 | dnl Copying and distribution of this file, with or without modification, |
| 25 | dnl are permitted in any medium without royalty provided the copyright |
| 26 | dnl notice and this notice are preserved. |
| 27 | |
| 28 | |
| 29 | AC_DEFUN([AX_JAVAC_AND_JAVA], |
| 30 | [ |
| 31 | |
| 32 | dnl Hard-coded default commands to test. |
| 33 | JAVAC_PROGS="javac,jikes,gcj -C" |
| 34 | JAVA_PROGS="java,kaffe" |
| 35 | |
| 36 | dnl Allow the user to specify an alternative. |
| 37 | if test -n "$JAVAC" ; then |
| 38 | JAVAC_PROGS="$JAVAC" |
| 39 | fi |
| 40 | if test -n "$JAVA" ; then |
| 41 | JAVA_PROGS="$JAVA" |
| 42 | fi |
| 43 | |
| 44 | AC_MSG_CHECKING(for javac and java) |
| 45 | |
| 46 | echo "public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java |
| 47 | success=no |
| 48 | oIFS="$IFS" |
| 49 | |
| 50 | IFS="," |
| 51 | for JAVAC in $JAVAC_PROGS ; do |
| 52 | IFS="$oIFS" |
| 53 | |
| 54 | echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD |
| 55 | if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then |
| 56 | |
| 57 | IFS="," |
| 58 | for JAVA in $JAVA_PROGS ; do |
| 59 | IFS="$oIFS" |
| 60 | |
| 61 | echo "Running \"$JAVA configtest_ax_javac_and_java\"" >&AS_MESSAGE_LOG_FD |
| 62 | if $JAVA configtest_ax_javac_and_java >&AS_MESSAGE_LOG_FD 2>&1 ; then |
| 63 | success=yes |
| 64 | break 2 |
| 65 | fi |
| 66 | |
| 67 | done |
| 68 | |
| 69 | fi |
| 70 | |
| 71 | done |
| 72 | |
| 73 | rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class |
| 74 | |
| 75 | if test "$success" != "yes" ; then |
| 76 | AC_MSG_RESULT(no) |
| 77 | JAVAC="" |
| 78 | JAVA="" |
| 79 | else |
| 80 | AC_MSG_RESULT(yes) |
| 81 | fi |
| 82 | |
| 83 | ax_javac_and_java="$success" |
| 84 | |
| 85 | ]) |