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