strtod-obsolete: Fix license.
[gnulib/ericb.git] / m4 / javacomp.m4
blob3bc54ac97d20f61ee7c871b11a293cec312390f4
1 # javacomp.m4 serial 13
2 dnl Copyright (C) 2001-2003, 2006-2007, 2009-2017 Free Software Foundation,
3 dnl Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # Prerequisites of javacomp.sh.
9 # gt_JAVACOMP([source-version], [target-version])
10 # Sets HAVE_JAVACOMP to nonempty if javacomp.sh will allow Java source code
11 # according to source-version to be compiled to Java bytecode classes in the
12 # target-version format.
14 # source-version can be:    support for
15 #           1.3             inner classes
16 #           1.4             assert keyword
17 #           1.5             generic classes and methods
18 #           1.6             (not supported)
19 #           1.7             switch(string)
20 #           1.8             lambdas
21 # Instead of source-version 1.6, use 1.5, since Java 6 did not introduce any
22 # language changes. See
23 # http://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html
25 # target-version can be:  classfile version:
26 #           1.1                 45.3
27 #           1.2                 46.0
28 #           1.3                 47.0
29 #           1.4                 48.0
30 #           1.5                 49.0
31 #           1.6                 50.0
32 #           1.7                 51.0
33 #           1.8                 52.0
34 # The classfile version of a .class file can be determined through the "file"
35 # command. More portably, the classfile major version can be determined through
36 # "od -A n -t d1 -j 7 -N 1 classfile".
37 # target-version can also be omitted. In this case, the required target-version
38 # is determined from the found JVM (see macro gt_JAVAEXEC):
39 #      target-version   for JVM
40 #           1.1         JDK 1.1, jview
41 #           1.2         JDK/JRE 1.2
42 #           1.3         JDK/JRE 1.3, gij 3.3, 3.4
43 #           1.4         JDK/JRE 1.4, gij 4.0, 4.1
44 #           1.5         JDK/JRE 1.5
45 #           1.6         JDK/JRE 1.6
46 #           1.7         JDK/JRE 1.7
47 #           1.8         JDK/JRE 1.8
48 # Note: gij >= 3.3 can in some cases handle classes compiled with -target 1.4,
49 # and gij >= 4.1 can in some cases partially handle classes compiled with
50 # -target 1.5, but I have no idea how complete this support is.
52 # Specifying target-version is useful when building a library (.jar) that is
53 # useful outside the given package. Omitting target-version is useful when
54 # building an application.
56 # It is unreasonable to ask for:
57 #   - target-version < 1.4 with source-version >= 1.4, or
58 #   - target-version < 1.5 with source-version >= 1.5, or
59 #   - target-version < 1.6 with source-version >= 1.6,
60 # because even Sun's/Oracle's javac doesn't support these combinations.
62 # It is redundant to ask for a target-version > source-version, since the
63 # smaller target-version = source-version will also always work and newer JVMs
64 # support the older target-versions too. Except for the case
65 # target-version = 1.4, source-version = 1.3, which allows gcj versions 3.0
66 # to 3.2 to be used.
68 AC_DEFUN([gt_JAVACOMP],
70   ifelse([$2], [], [AC_REQUIRE([gt_JAVAEXEC])], [])
71   AC_EGREP_CPP([yes], [
72 #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
73   yes
74 #endif
75 ], CLASSPATH_SEPARATOR=';', CLASSPATH_SEPARATOR=':')
76   source_version=$1
77   test -n "$source_version" || {
78     AC_MSG_ERROR([missing source-version argument to gt_@&t@JAVACOMP])
79   }
80   ifelse([$2], [],
81     [if test -n "$HAVE_JAVAEXEC"; then
82        dnl Use $CONF_JAVA to determine the JVM's version.
83 changequote(,)dnl
84        cat > conftestver.java <<EOF
85 public class conftestver {
86   public static void main (String[] args) {
87     System.out.println(System.getProperty("java.specification.version"));
88   }
90 EOF
91 changequote([,])dnl
92        dnl A precompiled version of conftestver.java, compiled with
93        dnl "javac -target 1.1". This avoids having to compile conftestver.java
94        dnl during each test for a suitable Java compiler.
95        dnl For the conversion from binary to this ASCII encapsulation, avoiding
96        dnl to assume the presence of uudecode, use the command
97        dnl   $ od -A n -t o1 < conftestver.class | tr ' ' '\012'| sort | uniq | sed -e '/^$/d' -e 's,^,\\,' | tr -d '\012'
98        dnl and the long tr command in opposite direction.
99        dnl Finally move the position corresponding to \055 to the last position,
100        dnl to work around a coreutils-5.x bug.
101        echo 'yzwx!$!I!D,!)!3+!4!5*!6,!4!7,!8!9)!:)!;"!(MeienN"!$FGW"!%Ojab"!2QeibRohZblVYZgb"!%hYei"!9FXQfYpYKgYidKUnleidLGW"!,Ujol_bPegb"!3_jicnbmnpblJfYpY/!*!+)!</!=!>"!=fYpYJmkb_ece_YnejiJpblmeji/!?!@)!A/!B!C"!._jicnbmnpbl"!3fYpYKgYidKSZfb_n"!3fYpYKgYidKUqmnbh"!$jon"!8QfYpYKejKTleinUnlbYhL"!.dbnTljkblnq"!EFQfYpYKgYidKUnleidLGQfYpYKgYidKUnleidL"!6fYpYKejKTleinUnlbYh"!)kleingi"!8FQfYpYKgYidKUnleidLGW!D!(!)!!!!!#!"!*!+!"!,!!!@!"!"!!!&Hu!"r!!!"!.!!!(!"!!!"!+!/!0!"!,!!!F!#!"!!!/s!#5$v!%t!&r!!!"!.!!!,!#!!!$!.!%!"!1!!!#!2' \
102          | tr -d '\012\015' \
103          | tr '!"#$%&()*+,./0123456789:;<=>?@ABCDEFGHJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzI' '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\046\050\051\052\056\057\073\074\076\103\106\114\116\117\120\123\124\126\133\141\142\143\144\145\146\147\151\152\154\155\156\157\160\162\163\164\165\166\171\261\262\266\267\270\272\276\312\376\055' \
104          > conftestver.class
105        target_version=`{
106          unset JAVA_HOME
107          echo "$as_me:__oline__: CLASSPATH=.${CLASSPATH:+$CLASSPATH_SEPARATOR$CLASSPATH} $CONF_JAVA conftestver" >&AS_MESSAGE_LOG_FD
108          CLASSPATH=.${CLASSPATH:+$CLASSPATH_SEPARATOR$CLASSPATH} $CONF_JAVA conftestver 2>&AS_MESSAGE_LOG_FD
109        }`
110        case "$target_version" in
111          1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8) ;;
112          null)
113            dnl JDK 1.1.X returns null.
114            target_version=1.1 ;;
115          *) AC_MSG_WARN([unknown target-version $target_version, please update gt_@&t@JAVACOMP macro])
116             target_version=1.1 ;;
117        esac
118      else
119        target_version="1.1"
120      fi
121     ],
122     [target_version=$2])
123   case "$source_version" in
124     1.3) goodcode='class conftest {}'
125          failcode='class conftestfail { static { assert(true); } }' ;;
126     1.4) goodcode='class conftest     { static { assert(true); } }'
127          failcode='class conftestfail<T> { T foo() { return null; } }' ;;
128     1.5) goodcode='class conftest<T>     { T foo() { return null; } }'
129          failcode='class conftestfail { void foo () { switch ("A") {} } }' ;;
130     1.7) goodcode='class conftest     { void foo () { switch ("A") {} } }'
131          failcode='class conftestfail { void foo () { Runnable r = () -> {}; } }' ;;
132     1.8) goodcode='class conftest     { void foo () { Runnable r = () -> {}; } }'
133          failcode='class conftestfail syntax error' ;;
134     *) AC_MSG_ERROR([invalid source-version argument to gt_@&t@JAVACOMP: $source_version]) ;;
135   esac
136   case "$target_version" in
137     1.1) cfversion=45 ;;
138     1.2) cfversion=46 ;;
139     1.3) cfversion=47 ;;
140     1.4) cfversion=48 ;;
141     1.5) cfversion=49 ;;
142     1.6) cfversion=50 ;;
143     1.7) cfversion=51 ;;
144     1.8) cfversion=52 ;;
145     *) AC_MSG_ERROR([invalid target-version argument to gt_@&t@JAVACOMP: $target_version]) ;;
146   esac
147   # Function to output the classfile version of a file (8th byte) in decimal.
148   if od -A x < /dev/null >/dev/null 2>/dev/null; then
149     # Use POSIX od.
150     func_classfile_version ()
151     {
152       od -A n -t d1 -j 7 -N 1 "[$]1"
153     }
154   else
155     # Use BSD hexdump.
156     func_classfile_version ()
157     {
158       dd if="[$]1" bs=1 count=1 skip=7 2>/dev/null | hexdump -e '1/1 "%3d "'
159       echo
160     }
161   fi
162   AC_MSG_CHECKING([for Java compiler])
163   dnl
164   dnl The support of GNU gcj for target-version and source-version:
165   dnl
166   dnl   gcj 3.0.4 to 4.2 does not have a way to specify the target-version.
167   dnl   It always assumes target-version=1.4 but labels the class files as 1.1.
168   dnl   One consequence of this is that gcj compiles GetURL.java to invalid
169   dnl   bytecode, which crashes with a VerifyError when executed by Sun Java
170   dnl   1.3.1. The bug is registered as java/7066, see
171   dnl   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7066
172   dnl   gcj 4.3 and newer has an option -ftarget=1.X.
173   dnl
174   dnl   For gcj < 3.3, the source-version always is 1.3.
175   dnl   For 3.3 <= gcj < 4.3, the source-version defaults to 1.4; option
176   dnl   "-fno-assert" switches to source-version 1.3.
177   dnl   gcj >= 4.3 has an option -fsource=1.X.
178   dnl
179   dnl The support of Sun/Oracle javac for target-version and source-version:
180   dnl
181   dnl   javac 1.3:   -target 1.1 1.2 1.3               default: 1.1
182   dnl                                                  source always: 1.3
183   dnl
184   dnl   javac 1.4:   -target 1.1 1.2 1.3 1.4           default: 1.2
185   dnl                -source 1.3 1.4                   default: 1.3
186   dnl                -target 1.1/1.2/1.3 only possible with -source 1.3 or no -source
187   dnl
188   dnl   javac 1.5:   -target 1.1 1.2 1.3 1.4 1.5       default: 1.5
189   dnl                -source 1.3 1.4 1.5               default: 1.5
190   dnl                -target 1.1/1.2/1.3 only possible with -source 1.3
191   dnl                -target 1.4 only possible with -source 1.3/1.4
192   dnl
193   dnl   javac 1.6:   -target 1.1 1.2 1.3 1.4 1.5 1.6   default: 1.6
194   dnl                -source 1.3 1.4 1.5 1.6           default: 1.5
195   dnl                -target 1.1/1.2/1.3 only possible with -source 1.3
196   dnl                -target 1.4 only possible with -source 1.3/1.4
197   dnl                -target 1.5 only possible with -source 1.3/1.4/1.5 or no -source
198   dnl
199   dnl   javac 1.7:   -target 1.1 1.2 1.3 1.4 1.5 1.6 1.7  default: 1.7
200   dnl                -source 1.3 1.4 1.5 1.6 1.7          default: 1.7
201   dnl                -target 1.1/1.2/1.3 only possible with -source 1.3
202   dnl                -target 1.4 only possible with -source 1.3/1.4
203   dnl                -target 1.5 only possible with -source 1.3/1.4/1.5
204   dnl                -target 1.6 only possible with -source 1.3/1.4/1.5/1.6
205   dnl
206   dnl   javac 1.8:   -target 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8  default: 1.8
207   dnl                -source [1.3 1.4 1.5] 1.6 1.7 1.8        default: 1.8
208   dnl                -target 1.1/1.2/1.3 only possible with -source 1.3
209   dnl                -target 1.4 only possible with -source 1.3/1.4
210   dnl                -target 1.5 only possible with -source 1.3/1.4/1.5
211   dnl                -target 1.6 only possible with -source 1.3/1.4/1.5/1.6
212   dnl                -target 1.7 only possible with -source 1.3/1.4/1.5/1.6/1.7
213   dnl
214   dnl The support of jikes for target-version and source-version:
215   dnl
216   dnl   jikes 1.14 does not have a way to specify the target-version. It
217   dnl   always assumes target-version=1.1.
218   dnl
219   dnl   For jikes 1.14, the source-version always is 1.3.
220   dnl
221   CONF_JAVAC=
222   HAVE_JAVAC_ENVVAR=
223   HAVE_GCJ_C=
224   HAVE_JAVAC=
225   HAVE_JIKES=
226   HAVE_JAVACOMP=
227 changequote(,)dnl
228   cat > conftestlib.java <<EOF
229 public class conftestlib {
230   public static void main (String[] args) {
231   }
234 changequote([,])dnl
235   echo "$goodcode" > conftest.java
236   echo "$failcode" > conftestfail.java
237   dnl If the user has set the JAVAC environment variable, use that, if it
238   dnl satisfies the constraints (possibly after adding -target and -source
239   dnl options).
240   if test -n "$JAVAC"; then
241     dnl Try the original $JAVAC.
242     if $JAVAC --version 2>/dev/null | sed -e 1q | grep gcj > /dev/null; then
243       dnl It's a version of gcj.
244 changequote(,)dnl
245       if $JAVAC --version 2>/dev/null | sed -e 's,^[^0-9]*,,' -e 1q | sed -e '/^4\.[012]/d' | grep '^[4-9]' >/dev/null; then
246 changequote([,])dnl
247         dnl It's a version of gcj >= 4.3. Assume the classfile versions are correct.
248         dnl Try $JAVAC.
249         rm -f conftest.class
250         if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
251              $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
252            } \
253            && test -f conftest.class \
254            && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
255           dnl Try adding -fsource option if it is useful.
256           rm -f conftest.class
257           rm -f conftestfail.class
258           if { echo "$as_me:__oline__: $JAVAC -fsource=$source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
259                $JAVAC -fsource="$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
260              } \
261              && test -f conftest.class \
262              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
263              && { echo "$as_me:__oline__: $JAVAC -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
264                   $JAVAC -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
265                 } \
266              && test -f conftestfail.class \
267              && ! { echo "$as_me:__oline__: $JAVAC -fsource=$source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
268                     $JAVAC -fsource="$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
269                   }; then
270             CONF_JAVAC="$JAVAC -fsource=$source_version"
271             HAVE_JAVAC_ENVVAR=1
272             HAVE_JAVACOMP=1
273           else
274             CONF_JAVAC="$JAVAC"
275             HAVE_JAVAC_ENVVAR=1
276             HAVE_JAVACOMP=1
277           fi
278         else
279           dnl Try with -fsource and -ftarget options.
280           rm -f conftest.class
281           rm -f conftestfail.class
282           if { echo "$as_me:__oline__: $JAVAC -fsource=$source_version -ftarget=$target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
283                $JAVAC -fsource="$source_version" -ftarget="$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
284              } \
285              && test -f conftest.class \
286              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
287             CONF_JAVAC="$JAVAC -fsource=$source_version -ftarget=$target_version"
288             HAVE_JAVAC_ENVVAR=1
289             HAVE_JAVACOMP=1
290           fi
291         fi
292       else
293         dnl It's a version of gcj < 4.3. Ignore the version of conftest.class.
294         if test "$target_version" = 1.4 && test "$source_version" = 1.4; then
295           dnl Try $JAVAC.
296           rm -f conftest.class
297           if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
298                $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
299              } \
300              && test -f conftest.class; then
301             CONF_JAVAC="$JAVAC"
302             HAVE_JAVAC_ENVVAR=1
303             HAVE_JAVACOMP=1
304           fi
305         else
306           if test "$target_version" = 1.4 && test "$source_version" = 1.3; then
307             dnl Try $JAVAC and "$JAVAC -fno-assert". But add -fno-assert only if
308             dnl it makes a difference. (It could already be part of $JAVAC.)
309             javac_works=
310             rm -f conftest.class
311             if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
312                  $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
313                } \
314                && test -f conftest.class; then
315               javac_works=1
316             fi
317             javac_noassert_works=
318             rm -f conftest.class
319             if { echo "$as_me:__oline__: $JAVAC -fno-assert -d . conftest.java" >&AS_MESSAGE_LOG_FD
320                  $JAVAC -fno-assert -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
321                } \
322                && test -f conftest.class; then
323               javac_noassert_works=1
324             fi
325             if test -n "$javac_works" && test -n "$javac_noassert_works"; then
326               rm -f conftestfail.class
327               if { echo "$as_me:__oline__: $JAVAC -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
328                    $JAVAC -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
329                  } \
330                  && test -f conftestfail.class \
331                  && ! { echo "$as_me:__oline__: $JAVAC -fno-assert -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
332                         $JAVAC -fno-assert -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
333                       }; then
334                 dnl "$JAVAC -fno-assert" works better than $JAVAC.
335                 javac_works=
336               fi
337             fi
338             if test -n "$javac_works"; then
339               CONF_JAVAC="$JAVAC"
340               HAVE_JAVAC_ENVVAR=1
341               HAVE_JAVACOMP=1
342             else
343               if test -n "$javac_noassert_works"; then
344                 CONF_JAVAC="$JAVAC -fno-assert"
345                 HAVE_JAVAC_ENVVAR=1
346                 HAVE_JAVACOMP=1
347               fi
348             fi
349           fi
350         fi
351       fi
352     else
353       dnl It's not gcj. Assume the classfile versions are correct.
354       dnl Try $JAVAC.
355       rm -f conftest.class
356       if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD
357            $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
358          } \
359          && test -f conftest.class \
360          && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
361         dnl Try adding -source option if it is useful.
362         rm -f conftest.class
363         rm -f conftestfail.class
364         if { echo "$as_me:__oline__: $JAVAC -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
365              $JAVAC -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
366            } \
367            && test -f conftest.class \
368            && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
369            && { echo "$as_me:__oline__: $JAVAC -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
370                 $JAVAC -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
371               } \
372            && test -f conftestfail.class \
373            && ! { echo "$as_me:__oline__: $JAVAC -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
374                   $JAVAC -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
375                 }; then
376           CONF_JAVAC="$JAVAC -source $source_version"
377           HAVE_JAVAC_ENVVAR=1
378           HAVE_JAVACOMP=1
379         else
380           CONF_JAVAC="$JAVAC"
381           HAVE_JAVAC_ENVVAR=1
382           HAVE_JAVACOMP=1
383         fi
384       else
385         dnl Try with -target option alone. (Sun javac 1.3.1 has the -target
386         dnl option but no -source option.)
387         rm -f conftest.class
388         if { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
389              $JAVAC -target "$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
390            } \
391            && test -f conftest.class \
392            && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
393           dnl Try adding -source option if it is useful.
394           rm -f conftest.class
395           rm -f conftestfail.class
396           if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
397                $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
398              } \
399              && test -f conftest.class \
400              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
401              && { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
402                   $JAVAC -target "$target_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
403                 } \
404              && test -f conftestfail.class \
405              && ! { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
406                     $JAVAC -target "$target_version" -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
407                   }; then
408             CONF_JAVAC="$JAVAC -target $target_version -source $source_version"
409             HAVE_JAVAC_ENVVAR=1
410             HAVE_JAVACOMP=1
411           else
412             CONF_JAVAC="$JAVAC -target $target_version"
413             HAVE_JAVAC_ENVVAR=1
414             HAVE_JAVACOMP=1
415           fi
416         else
417           dnl Maybe this -target option requires a -source option? Try with
418           dnl -target and -source options. (Supported by Sun javac 1.4 and
419           dnl higher.)
420           rm -f conftest.class
421           if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
422                $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
423              } \
424              && test -f conftest.class \
425              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
426             CONF_JAVAC="$JAVAC -target $target_version -source $source_version"
427             HAVE_JAVAC_ENVVAR=1
428             HAVE_JAVACOMP=1
429           fi
430         fi
431       fi
432     fi
433   fi
434   if test -z "$HAVE_JAVACOMP"; then
435     pushdef([AC_MSG_CHECKING],[:])dnl
436     pushdef([AC_CHECKING],[:])dnl
437     pushdef([AC_MSG_RESULT],[:])dnl
438     AC_CHECK_PROG([HAVE_GCJ_IN_PATH], [gcj], [yes])
439     AC_CHECK_PROG([HAVE_JAVAC_IN_PATH], [javac], [yes])
440     AC_CHECK_PROG([HAVE_JIKES_IN_PATH], [jikes], [yes])
441     popdef([AC_MSG_RESULT])dnl
442     popdef([AC_CHECKING])dnl
443     popdef([AC_MSG_CHECKING])dnl
444     if test -z "$HAVE_JAVACOMP" && test -n "$HAVE_GCJ_IN_PATH"; then
445       dnl Test for a good gcj version (>= 3.0).
446 changequote(,)dnl
447       if gcj --version 2>/dev/null | sed -e 's,^[^0-9]*,,' -e 1q | sed -e '/^3\.[01]/d' | grep '^[3-9]' >/dev/null; then
448 changequote([,])dnl
449         dnl See if libgcj.jar is well installed.
450         if { echo "$as_me:__oline__: gcj -C -d . conftestlib.java" >&AS_MESSAGE_LOG_FD
451              gcj -C -d . conftestlib.java >&AS_MESSAGE_LOG_FD 2>&1
452            }; then
453           dnl OK, gcj works.
454 changequote(,)dnl
455           if gcj --version 2>/dev/null | sed -e 's,^[^0-9]*,,' -e 1q | sed -e '/^4\.[012]/d' | grep '^[4-9]' >/dev/null; then
456 changequote([,])dnl
457             dnl It's a version of gcj >= 4.3. Assume the classfile versions are correct.
458             dnl Try gcj.
459             rm -f conftest.class
460             if { echo "$as_me:__oline__: gcj -C -d . conftest.java" >&AS_MESSAGE_LOG_FD
461                  gcj -C -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
462                } \
463                && test -f conftest.class \
464                && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
465               dnl Try adding -fsource option if it is useful.
466               rm -f conftest.class
467               rm -f conftestfail.class
468               if { echo "$as_me:__oline__: gcj -C -fsource=$source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
469                    gcj -C -fsource="$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
470                  } \
471                  && test -f conftest.class \
472                  && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
473                  && { echo "$as_me:__oline__: gcj -C -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
474                       gcj -C -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
475                     } \
476                  && test -f conftestfail.class \
477                  && ! { echo "$as_me:__oline__: gcj -C -fsource=$source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
478                         gcj -C -fsource="$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
479                       }; then
480                 CONF_JAVAC="gcj -C -fsource=$source_version"
481                 HAVE_JAVAC_ENVVAR=1
482                 HAVE_JAVACOMP=1
483               else
484                 CONF_JAVAC="gcj -C"
485                 HAVE_JAVAC_ENVVAR=1
486                 HAVE_JAVACOMP=1
487               fi
488             else
489               dnl Try with -fsource and -ftarget options.
490               rm -f conftest.class
491               rm -f conftestfail.class
492               if { echo "$as_me:__oline__: gcj -C -fsource=$source_version -ftarget=$target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
493                    gcj -C -fsource="$source_version" -ftarget="$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
494                  } \
495                  && test -f conftest.class \
496                  && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
497                 CONF_JAVAC="gcj -C -fsource=$source_version -ftarget=$target_version"
498                 HAVE_JAVAC_ENVVAR=1
499                 HAVE_JAVACOMP=1
500               fi
501             fi
502           else
503             dnl It's a version of gcj < 4.3. Ignore the version of conftest.class.
504             dnl Now test whether it supports the desired target-version and
505             dnl source-version.
506             if test "$target_version" = 1.4 && test "$source_version" = 1.4; then
507               rm -f conftest.class
508               if { echo "$as_me:__oline__: gcj -C -d . conftest.java" >&AS_MESSAGE_LOG_FD
509                    gcj -C -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
510                  } \
511                  && test -f conftest.class; then
512                 CONF_JAVAC="gcj -C"
513                 HAVE_GCJ_C=1
514                 HAVE_JAVACOMP=1
515               fi
516             else
517               if test "$target_version" = 1.4 && test "$source_version" = 1.3; then
518                 dnl Try gcj and "gcj -fno-assert". But add -fno-assert only if
519                 dnl it works (not gcj < 3.3).
520                 rm -f conftest.class
521                 if { echo "$as_me:__oline__: gcj -C -fno-assert -d . conftest.java" >&AS_MESSAGE_LOG_FD
522                      gcj -C -fno-assert -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
523                    } \
524                    && test -f conftest.class; then
525                   CONF_JAVAC="gcj -C -fno-assert"
526                   HAVE_GCJ_C=1
527                   HAVE_JAVACOMP=1
528                 else
529                   rm -f conftest.class
530                   if { echo "$as_me:__oline__: gcj -C -d . conftest.java" >&AS_MESSAGE_LOG_FD
531                        gcj -C -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
532                      } \
533                      && test -f conftest.class; then
534                     CONF_JAVAC="gcj -C"
535                     HAVE_GCJ_C=1
536                     HAVE_JAVACOMP=1
537                   fi
538                 fi
539               fi
540             fi
541           fi
542         fi
543       fi
544     fi
545     if test -z "$HAVE_JAVACOMP" && test -n "$HAVE_JAVAC_IN_PATH"; then
546       dnl Test whether javac is usable.
547       if { javac -version >/dev/null 2>/dev/null || test $? -le 2; } \
548          && ( if javac -help 2>&1 >/dev/null | grep at.dms.kjc.Main >/dev/null && javac -help 2>/dev/null | grep 'released.*2000' >/dev/null ; then exit 1; else exit 0; fi ); then
549         dnl OK, javac works.
550         dnl Now test whether it supports the desired target-version and
551         dnl source-version.
552         rm -f conftest.class
553         if { echo "$as_me:__oline__: javac -d . conftest.java" >&AS_MESSAGE_LOG_FD
554              javac -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
555            } \
556            && test -f conftest.class \
557            && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
558           dnl Try adding -source option if it is useful.
559           rm -f conftest.class
560           rm -f conftestfail.class
561           if { echo "$as_me:__oline__: javac -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
562                javac -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
563              } \
564              && test -f conftest.class \
565              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
566              && { echo "$as_me:__oline__: javac -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
567                   javac -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
568                 } \
569              && test -f conftestfail.class \
570              && ! { echo "$as_me:__oline__: javac -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
571                     javac -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
572                   }; then
573             CONF_JAVAC="javac -source $source_version"
574             HAVE_JAVAC=1
575             HAVE_JAVACOMP=1
576           else
577             CONF_JAVAC="javac"
578             HAVE_JAVAC=1
579             HAVE_JAVACOMP=1
580           fi
581         else
582           dnl Try with -target option alone. (Sun javac 1.3.1 has the -target
583           dnl option but no -source option.)
584           rm -f conftest.class
585           if { echo "$as_me:__oline__: javac -target $target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
586                javac -target "$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
587              } \
588              && test -f conftest.class \
589              && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
590             dnl Try adding -source option if it is useful.
591             rm -f conftest.class
592             rm -f conftestfail.class
593             if { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
594                  javac -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
595                } \
596                && test -f conftest.class \
597                && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \
598                && { echo "$as_me:__oline__: javac -target $target_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
599                     javac -target "$target_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
600                   } \
601                && test -f conftestfail.class \
602                && ! { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD
603                       javac -target "$target_version" -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1
604                     }; then
605               CONF_JAVAC="javac -target $target_version -source $source_version"
606               HAVE_JAVAC=1
607               HAVE_JAVACOMP=1
608             else
609               CONF_JAVAC="javac -target $target_version"
610               HAVE_JAVAC=1
611               HAVE_JAVACOMP=1
612             fi
613           else
614             dnl Maybe this -target option requires a -source option? Try with
615             dnl -target and -source options. (Supported by Sun javac 1.4 and
616             dnl higher.)
617             rm -f conftest.class
618             if { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD
619                  javac -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
620                } \
621                && test -f conftest.class \
622                && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then
623               CONF_JAVAC="javac -target $target_version -source $source_version"
624               HAVE_JAVAC=1
625               HAVE_JAVACOMP=1
626             fi
627           fi
628         fi
629       fi
630     fi
631     if test -z "$HAVE_JAVACOMP" && test -n "$HAVE_JIKES_IN_PATH"; then
632       dnl Test whether jikes is usable.
633       if { jikes >/dev/null 2>/dev/null || test $? = 1; } \
634          && (
635               # See if the existing CLASSPATH is sufficient to make jikes work.
636               unset JAVA_HOME
637               jikes conftestlib.java >&AS_MESSAGE_LOG_FD 2>&1
638               error=$?
639               rm -f conftestlib.class
640               exit $error
641             ); then
642         dnl OK, jikes works.
643         dnl Now test whether it supports the desired target-version and
644         dnl source-version.
645         if test "$source_version" = 1.3; then
646           CONF_JAVAC="jikes"
647           HAVE_JIKES=1
648           HAVE_JAVACOMP=1
649         fi
650       fi
651     fi
652   fi
653   rm -f conftest*.java conftest*.class
654   if test -n "$HAVE_JAVACOMP"; then
655     ac_result="$CONF_JAVAC"
656   else
657     ac_result="no"
658   fi
659   AC_MSG_RESULT([$ac_result])
660   AC_SUBST([CONF_JAVAC])
661   AC_SUBST([CLASSPATH])
662   AC_SUBST([CLASSPATH_SEPARATOR])
663   AC_SUBST([HAVE_JAVAC_ENVVAR])
664   AC_SUBST([HAVE_GCJ_C])
665   AC_SUBST([HAVE_JAVAC])
666   AC_SUBST([HAVE_JIKES])