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