David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 1 | dnl |
| 2 | dnl The following commonly available Java macros converted to AX prefix |
| 3 | dnl in support of proper thrift/autoconf extension naming rules |
| 4 | dnl |
| 5 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 6 | dnl autoconf M4 macros for Java programs |
| 7 | dnl Copyright Stephane Bortzmeyer <bortzmeyer@pasteur.fr>, 1999 |
| 8 | dnl Released under the GPL licence |
| 9 | dnl |
| 10 | dnl A sample configure.in is at the end of this file. Each macro is |
| 11 | dnl documented by comments before its definition. Here is a summary: |
| 12 | dnl |
| 13 | dnl AX_PROG_JAVAC: finds a Java compiler |
| 14 | dnl AX_PROG_JAVA: finds a Java virtual machine |
| 15 | dnl AX_CHECK_CLASS: finds if we have the given class (beware of CLASSPATH!) |
| 16 | dnl AX_CHECK_RQRD_CLASS: finds if we have the given class and stops otherwise |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 17 | |
| 18 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 19 | dnl AX_PROG_JAVAC tests an existing Java compiler. It uses the environment |
| 20 | dnl variable JAVAC then tests in sequence various common Java compilers. For |
| 21 | dnl political reasons, it starts with the free ones. |
| 22 | dnl If you want to force a specific compiler: |
| 23 | dnl - at the configure.in level, set JAVAC=yourcompiler before calling |
| 24 | dnl AX_PROG_JAVAC |
| 25 | dnl - at the configure level, setenv JAVAC |
| 26 | dnl You can use the JAVAC variable in your Makefile.in, with @JAVAC@. |
| 27 | dnl |
| 28 | dnl *Warning*: its success or failure can depend on a proper setting of the |
| 29 | dnl CLASSPATH env. variable. |
| 30 | dnl |
| 31 | dnl TODO: allow to exclude compilers (rationale: most Java programs cannot compile |
| 32 | dnl with some compilers like guavac). |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 33 | |
| 34 | AC_DEFUN([AX_PROG_JAVAC],[ |
Bryan Duxbury | 9a75aa5 | 2009-01-29 01:37:01 +0000 | [diff] [blame] | 35 | test -z "$JAVAC" && AC_CHECK_PROGS(JAVAC, "gcj -C" guavac jikes javac) |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 36 | test -z "$JAVAC" && AC_MSG_ERROR([no acceptable Java compiler found in \$PATH]) |
| 37 | AX_PROG_JAVAC_WORKS |
| 38 | ]) |
| 39 | |
| 40 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 41 | dnl AX_PROG_JAVA tests an existing Java virtual machine. It uses the |
| 42 | dnl environment variable JAVA then tests in sequence various common Java |
| 43 | dnl virtual machines. For political reasons, it starts with the free ones. |
| 44 | dnl You *must* call [AX_PROG_JAVAC] before. |
| 45 | dnl If you want to force a specific VM: |
| 46 | dnl - at the configure.in level, set JAVA=yourvm before calling AX_PROG_JAVA |
| 47 | dnl - at the configure level, setenv JAVA |
| 48 | dnl You can use the JAVA variable in your Makefile.in, with @JAVA@. |
| 49 | dnl |
| 50 | dnl *Warning*: its success or failure can depend on a proper setting of the |
| 51 | dnl CLASSPATH env. variable. |
| 52 | dnl |
| 53 | dnl TODO: allow to exclude virtual machines (rationale: most Java programs |
| 54 | dnl cannot run with some VM like kaffe). |
| 55 | dnl |
| 56 | dnl TODO: allow to call this macro without [AX_PROG_JAVAC] before, using a |
| 57 | dnl class included uuencoded as an here document and uudecoded on the fly |
| 58 | dnl (check uudecode first) (rationale: a Java package can have no sources). |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 59 | |
| 60 | AC_DEFUN([AX_PROG_JAVA],[ |
| 61 | test -z "$JAVA" && AC_CHECK_PROGS(JAVA, kaffe java) |
| 62 | test -z "$JAVA" && AC_MSG_ERROR([no acceptable Java virtual machine found in \$PATH]) |
| 63 | AX_PROG_JAVA_WORKS |
| 64 | ]) |
| 65 | |
| 66 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 67 | dnl AX_CHECK_CLASS tests the existence of a given Java class, either in |
| 68 | dnl a jar or in a '.class' file. |
| 69 | dnl |
| 70 | dnl *Warning*: its success or failure can depend on a proper setting of the |
| 71 | dnl CLASSPATH env. variable. |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 72 | |
| 73 | AC_DEFUN([AX_CHECK_CLASS],[ |
| 74 | CLASS=$1 |
| 75 | echo -n "Testing if we have Java class $CLASS... " |
| 76 | JAVA_TEST=Test.java |
| 77 | CLASS=`echo $CLASS|sed 's/\./_/g'` |
| 78 | cat << \EOF > $JAVA_TEST |
| 79 | import $1; |
| 80 | public class Test { |
| 81 | } |
| 82 | EOF |
| 83 | if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then |
| 84 | eval HAVE_$CLASS=yes |
| 85 | eval HAVE_LAST_CLASS=yes |
| 86 | echo "yes" |
| 87 | else |
| 88 | eval HAVE_$CLASS=no |
| 89 | eval HAVE_LAST_CLASS=no |
| 90 | echo "no (check config.log, CLASSPATH may be wrong?)" |
| 91 | fi |
| 92 | rm -f $JAVA_TEST |
| 93 | ]) |
| 94 | |
| 95 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 96 | dnl AX_CHECK_RQRD_CLASS tests the existence of a given Java class, either in |
| 97 | dnl a jar or in a '.class' file and fails if it doesn't exist. |
| 98 | dnl |
| 99 | dnl *Warning*: its success or failure can depend on a proper setting of the |
| 100 | dnl CLASSPATH env. variable. |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 101 | |
| 102 | AC_DEFUN([AX_CHECK_RQRD_CLASS],[ |
| 103 | CLASS=`echo $1|sed 's/\./_/g'` |
| 104 | AX_CHECK_CLASS($1) |
| 105 | if test "$HAVE_LAST_CLASS" = "no"; then |
| 106 | AC_MSG_ERROR([Required class $1 missing, exiting.]) |
| 107 | fi |
| 108 | ]) |
| 109 | |
| 110 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 111 | dnl AX_CHECK_CLASSPATH just displays the CLASSPATH, for the edification |
| 112 | dnl of the user. |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 113 | |
| 114 | AC_DEFUN([AX_CHECK_CLASSPATH],[ |
| 115 | if test -z "$CLASSPATH"; then |
| 116 | echo "You have no CLASSPATH, I hope it is good" |
| 117 | else |
| 118 | echo "You have CLASSPATH $CLASSPATH, hope it is correct" |
| 119 | fi |
| 120 | ]) |
| 121 | |
| 122 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 123 | dnl Internal use |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 124 | |
| 125 | AC_DEFUN([AX_PROG_JAVA_WORKS],[ |
| 126 | echo -n "Testing if $JAVA works... " |
| 127 | JAVA_TEST=Test.java |
| 128 | CLASS_TEST=Test.class |
| 129 | TEST=Test |
| 130 | changequote(, )dnl |
| 131 | cat << \EOF > $JAVA_TEST |
| 132 | public class Test { |
| 133 | public static void main (String args[]) {} |
| 134 | } |
| 135 | EOF |
| 136 | changequote([, ])dnl |
| 137 | if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then |
| 138 | if AC_TRY_COMMAND($JAVA $TEST) >/dev/null 2>&1; then |
| 139 | echo "yes" |
| 140 | else |
| 141 | echo "no" |
| 142 | AC_MSG_ERROR(The Java VM $JAVA failed (see config.log, check the CLASSPATH?)) |
| 143 | fi |
| 144 | else |
| 145 | AC_MSG_ERROR(The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)) |
| 146 | fi |
| 147 | rm -f $JAVA_TEST $CLASS_TEST |
| 148 | ] |
| 149 | ) |
| 150 | |
| 151 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 152 | dnl Internal use |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 153 | |
| 154 | AC_DEFUN([AX_PROG_JAVAC_WORKS],[ |
| 155 | echo -n "Testing if $JAVAC works... " |
| 156 | JAVA_TEST=Test.java |
| 157 | CLASS_TEST=Test.class |
| 158 | cat << \EOF > $JAVA_TEST |
| 159 | public class Test { |
| 160 | } |
| 161 | EOF |
| 162 | if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then |
| 163 | echo "yes" |
| 164 | else |
| 165 | echo "no" |
| 166 | AC_MSG_ERROR([The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)]) |
| 167 | fi |
| 168 | rm -f $JAVA_TEST $CLASS_TEST |
| 169 | ]) |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 174 | dnl TODO: add a AX_CHECK_JAVA_SOURCE where the user can give a complete |
| 175 | dnl Java source to compile or to compile and run. |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 176 | |
| 177 | |
| 178 | |
David Reiss | 0a136c8 | 2008-12-22 19:54:12 +0000 | [diff] [blame] | 179 | dnl dnl This is a sample configure.in |
| 180 | dnl dnl Process this file with autoconf to produce a configure script. |
| 181 | dnl dnl Drop the [] around the macro names |
| 182 | dnl |
| 183 | dnl [ |
| 184 | dnl |
| 185 | dnl AC_INIT(UnTag.java) |
| 186 | dnl |
| 187 | dnl dnl Checks for programs. |
| 188 | dnl AX_CHECK_CLASSPATH |
| 189 | dnl AX_PROG_JAVAC |
| 190 | dnl AX_PROG_JAVA |
| 191 | dnl |
| 192 | dnl dnl Checks for classes |
| 193 | dnl AX_CHECK_RQRD_CLASS(org.xml.sax.Parser) |
| 194 | dnl AX_CHECK_RQRD_CLASS(com.jclark.xml.sax.Driver) |
| 195 | dnl |
| 196 | dnl AC_OUTPUT(Makefile) |
| 197 | dnl |
| 198 | dnl ] |
David Reiss | f8dcf03 | 2008-02-23 22:07:39 +0000 | [diff] [blame] | 199 | |
| 200 | |
| 201 | dnl @synopsis AX_CHECK_JUNIT |
| 202 | dnl |
| 203 | dnl AX_CHECK_JUNIT tests the availability of the Junit testing |
| 204 | dnl framework, and set some variables for conditional compilation |
| 205 | dnl of the test suite by automake. |
| 206 | dnl |
| 207 | dnl If available, JUNIT is set to a command launching the text |
| 208 | dnl based user interface of Junit, @JAVA_JUNIT@ is set to $JAVA_JUNIT |
| 209 | dnl and @TESTS_JUNIT@ is set to $TESTS_JUNIT, otherwise they are set |
| 210 | dnl to empty values. |
| 211 | dnl |
| 212 | dnl You can use these variables in your Makefile.am file like this : |
| 213 | dnl |
| 214 | dnl # Some of the following classes are built only if junit is available |
| 215 | dnl JAVA_JUNIT = Class1Test.java Class2Test.java AllJunitTests.java |
| 216 | dnl |
| 217 | dnl noinst_JAVA = Example1.java Example2.java @JAVA_JUNIT@ |
| 218 | dnl |
| 219 | dnl EXTRA_JAVA = $(JAVA_JUNIT) |
| 220 | dnl |
| 221 | dnl TESTS_JUNIT = AllJunitTests |
| 222 | dnl |
| 223 | dnl TESTS = StandaloneTest1 StandaloneTest2 @TESTS_JUNIT@ |
| 224 | dnl |
| 225 | dnl EXTRA_TESTS = $(TESTS_JUNIT) |
| 226 | dnl |
| 227 | dnl AllJunitTests : |
| 228 | dnl echo "#! /bin/sh" > $@ |
| 229 | dnl echo "exec @JUNIT@ my.package.name.AllJunitTests" >> $@ |
| 230 | dnl chmod +x $@ |
| 231 | dnl |
| 232 | dnl @author Luc Maisonobe |
| 233 | dnl @version $Id: ac_check_junit.ac,v 12.0 2004/11/17 03:43:38 bostic Exp $ |
| 234 | dnl |
| 235 | AC_DEFUN([AX_CHECK_JUNIT],[ |
| 236 | AC_CACHE_VAL(ax_cv_prog_JUNIT,[ |
| 237 | AX_CHECK_CLASS(junit.textui.TestRunner) |
| 238 | if test x"`eval 'echo $ac_cv_class_junit_textui_TestRunner'`" != xno ; then |
| 239 | ax_cv_prog_JUNIT='$(CLASSPATH_ENV) $(JAVA) $(JAVAFLAGS) junit.textui.TestRunner' |
| 240 | fi]) |
| 241 | AC_MSG_CHECKING([for junit]) |
| 242 | if test x"`eval 'echo $ax_cv_prog_JUNIT'`" != x ; then |
| 243 | JUNIT="$ax_cv_prog_JUNIT" |
| 244 | JAVA_JUNIT='$(JAVA_JUNIT)' |
| 245 | TESTS_JUNIT='$(TESTS_JUNIT)' |
| 246 | else |
| 247 | JUNIT= |
| 248 | JAVA_JUNIT= |
| 249 | TESTS_JUNIT= |
| 250 | fi |
| 251 | AC_MSG_RESULT($JAVA_JUNIT) |
| 252 | AC_SUBST(JUNIT) |
| 253 | AC_SUBST(JAVA_JUNIT) |
| 254 | AC_SUBST(TESTS_JUNIT)]) |