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