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