summaryrefslogtreecommitdiff
path: root/aclocal/ax_java.m4
blob: 301586c2e46debeaf1e765e8ae11d214593cd8d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
dnl
dnl The following commonly available Java macros converted to AX prefix 
dnl in support of proper thrift/autoconf extension naming rules
dnl

divert(-1)

autoconf M4 macros for Java programs
Copyright Stephane Bortzmeyer <bortzmeyer@pasteur.fr>, 1999
Released under the GPL licence

A sample configure.in is at the end of this file. Each macro is
documented by comments before its definition. Here is a summary:

AX_PROG_JAVAC: finds a Java compiler
AX_PROG_JAVA: finds a Java virtual machine
AX_CHECK_CLASS: finds if we have the given class (beware of CLASSPATH!)
AX_CHECK_RQRD_CLASS: finds if we have the given class and stops otherwise

divert(0)


divert(-1)
AX_PROG_JAVAC tests an existing Java compiler. It uses the environment
variable JAVAC then tests in sequence various common Java compilers. For
political reasons, it starts with the free ones.
If you want to force a specific compiler:
 - at the configure.in level, set JAVAC=yourcompiler before calling 
   AX_PROG_JAVAC
 - at the configure level, setenv JAVAC
You can use the JAVAC variable in your Makefile.in, with @JAVAC@.

*Warning*: its success or failure can depend on a proper setting of the
CLASSPATH env. variable.

TODO: allow to exclude compilers (rationale: most Java programs cannot compile
with some compilers like guavac).
divert(0)

AC_DEFUN([AX_PROG_JAVAC],[
test -z "$JAVAC" && AC_CHECK_PROGS(JAVAC, "gcj -C" guavac jikes javac)
test -z "$JAVAC" && AC_MSG_ERROR([no acceptable Java compiler found in \$PATH])
AX_PROG_JAVAC_WORKS
])


divert(-1)
AX_PROG_JAVA tests an existing Java virtual machine. It uses the 
environment variable JAVA then tests in sequence various common Java 
virtual machines. For political reasons, it starts with the free ones.
You *must* call [AX_PROG_JAVAC] before.
If you want to force a specific VM:
 - at the configure.in level, set JAVA=yourvm before calling AX_PROG_JAVA
 - at the configure level, setenv JAVA
You can use the JAVA variable in your Makefile.in, with @JAVA@.

*Warning*: its success or failure can depend on a proper setting of the
CLASSPATH env. variable.

TODO: allow to exclude virtual machines (rationale: most Java programs 
cannot run with some VM like kaffe).

TODO: allow to call this macro without [AX_PROG_JAVAC] before, using a
class included uuencoded as an here document and uudecoded on the fly
(check uudecode first) (rationale: a Java package can have no sources).
divert(0)

AC_DEFUN([AX_PROG_JAVA],[
test -z "$JAVA" && AC_CHECK_PROGS(JAVA, kaffe java)
test -z "$JAVA" && AC_MSG_ERROR([no acceptable Java virtual machine found in \$PATH])
AX_PROG_JAVA_WORKS
])


divert(-1)
AX_CHECK_CLASS tests the existence of a given Java class, either in
a jar or in a '.class' file. 

*Warning*: its success or failure can depend on a proper setting of the
CLASSPATH env. variable.
divert(0)

AC_DEFUN([AX_CHECK_CLASS],[
CLASS=$1
echo -n "Testing if we have Java class $CLASS... "
JAVA_TEST=Test.java
CLASS=`echo $CLASS|sed 's/\./_/g'`
cat << \EOF > $JAVA_TEST
import $1;
public class Test {
}
EOF
if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then
  eval HAVE_$CLASS=yes
  eval HAVE_LAST_CLASS=yes
  echo "yes"
else
  eval HAVE_$CLASS=no
  eval HAVE_LAST_CLASS=no
  echo "no (check config.log, CLASSPATH may be wrong?)"
fi
rm -f $JAVA_TEST
])


divert(-1)
AX_CHECK_RQRD_CLASS tests the existence of a given Java class, either in
a jar or in a '.class' file and fails if it doesn't exist.

*Warning*: its success or failure can depend on a proper setting of the
CLASSPATH env. variable.
divert(0)

AC_DEFUN([AX_CHECK_RQRD_CLASS],[
CLASS=`echo $1|sed 's/\./_/g'`
AX_CHECK_CLASS($1)
if test "$HAVE_LAST_CLASS" = "no"; then
	AC_MSG_ERROR([Required class $1 missing, exiting.])
fi
])


divert(-1)
AX_CHECK_CLASSPATH just displays the CLASSPATH, for the edification
of the user.
divert(0)

AC_DEFUN([AX_CHECK_CLASSPATH],[
if test -z "$CLASSPATH"; then
	echo "You have no CLASSPATH, I hope it is good"
else
	echo "You have CLASSPATH $CLASSPATH, hope it is correct"
fi
])


divert(-1)
Internal use
divert(0)

AC_DEFUN([AX_PROG_JAVA_WORKS],[
echo -n "Testing if $JAVA works... "
JAVA_TEST=Test.java
CLASS_TEST=Test.class
TEST=Test
changequote(, )dnl
cat << \EOF > $JAVA_TEST
public class Test {
	    public static void main (String args[]) {}
}
EOF
changequote([, ])dnl
if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then
  if AC_TRY_COMMAND($JAVA $TEST) >/dev/null 2>&1; then
    echo "yes"
  else
    echo "no"
    AC_MSG_ERROR(The Java VM $JAVA failed (see config.log, check the CLASSPATH?))
  fi
else
  AC_MSG_ERROR(The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?))
fi
rm -f $JAVA_TEST $CLASS_TEST
]
)


divert(-1)
Internal use
divert(0)

AC_DEFUN([AX_PROG_JAVAC_WORKS],[
echo -n "Testing if $JAVAC works... "
JAVA_TEST=Test.java
CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST
public class Test {
}
EOF
if AC_TRY_COMMAND($JAVAC $JAVA_TEST) >/dev/null 2>&1; then
  echo "yes"
else
  echo "no"
  AC_MSG_ERROR([The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?)])
fi
rm -f $JAVA_TEST $CLASS_TEST
])




divert(-1)
TODO: add a AX_CHECK_JAVA_SOURCE where the user can give a complete
Java source to compile or to compile and run.
divert(0)



divert(-1)
dnl This is a sample configure.in
dnl Process this file with autoconf to produce a configure script.
dnl Drop the [] around the macro names

[

AC_INIT(UnTag.java)

dnl Checks for programs.
AX_CHECK_CLASSPATH
AX_PROG_JAVAC
AX_PROG_JAVA

dnl Checks for classes
AX_CHECK_RQRD_CLASS(org.xml.sax.Parser)
AX_CHECK_RQRD_CLASS(com.jclark.xml.sax.Driver)

AC_OUTPUT(Makefile)

]

divert(0)


dnl @synopsis AX_CHECK_JUNIT
dnl
dnl AX_CHECK_JUNIT tests the availability of the Junit testing
dnl framework, and set some variables for conditional compilation
dnl of the test suite by automake.
dnl
dnl If available, JUNIT is set to a command launching the text
dnl based user interface of Junit, @JAVA_JUNIT@ is set to $JAVA_JUNIT
dnl and @TESTS_JUNIT@ is set to $TESTS_JUNIT, otherwise they are set
dnl to empty values.
dnl
dnl You can use these variables in your Makefile.am file like this :
dnl
dnl  # Some of the following classes are built only if junit is available
dnl  JAVA_JUNIT  = Class1Test.java Class2Test.java AllJunitTests.java
dnl
dnl  noinst_JAVA = Example1.java Example2.java @JAVA_JUNIT@
dnl
dnl  EXTRA_JAVA  = $(JAVA_JUNIT)
dnl
dnl  TESTS_JUNIT = AllJunitTests
dnl
dnl  TESTS       = StandaloneTest1 StandaloneTest2 @TESTS_JUNIT@
dnl
dnl  EXTRA_TESTS = $(TESTS_JUNIT)
dnl
dnl  AllJunitTests :
dnl     echo "#! /bin/sh" > $@
dnl     echo "exec @JUNIT@ my.package.name.AllJunitTests" >> $@
dnl     chmod +x $@
dnl
dnl @author Luc Maisonobe
dnl @version $Id: ac_check_junit.ac,v 12.0 2004/11/17 03:43:38 bostic Exp $
dnl
AC_DEFUN([AX_CHECK_JUNIT],[
AC_CACHE_VAL(ax_cv_prog_JUNIT,[
AX_CHECK_CLASS(junit.textui.TestRunner)
if test x"`eval 'echo $ac_cv_class_junit_textui_TestRunner'`" != xno ; then
  ax_cv_prog_JUNIT='$(CLASSPATH_ENV) $(JAVA) $(JAVAFLAGS) junit.textui.TestRunner'
fi])
AC_MSG_CHECKING([for junit])
if test x"`eval 'echo $ax_cv_prog_JUNIT'`" != x ; then
  JUNIT="$ax_cv_prog_JUNIT"
  JAVA_JUNIT='$(JAVA_JUNIT)'
  TESTS_JUNIT='$(TESTS_JUNIT)'
else
  JUNIT=
  JAVA_JUNIT=
  TESTS_JUNIT=
fi
AC_MSG_RESULT($JAVA_JUNIT)
AC_SUBST(JUNIT)
AC_SUBST(JAVA_JUNIT)
AC_SUBST(TESTS_JUNIT)])