From: Bruno Haible Date: Sun, 11 Jun 2023 01:13:24 +0000 (+0200) Subject: javacomp-script, javacomp: Remove support for javac versions < 1.6. X-Git-Tag: v1.0~1223 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=16047d4c26c75adcf9c77696cdac38915658deb0;p=gnulib.git javacomp-script, javacomp: Remove support for javac versions < 1.6. * m4/javacomp.m4 (gt_JAVACOMP): State that the minimum source_version and the minimum target_version are 1.6. Map smaller values to 1.6. Complain if the java version is < 1.6. Use 1.6 as default, instead of 1.1. Don't bother trying the -target option alone. * lib/javacomp.h (compile_java_class): State that the minimum source_version and the minimum target_version are 1.6. * lib/javacomp.c (default_target_version): Complain if the java version is < 1.6. Use 1.6 as default, instead of 1.1. (SOURCE_VERSION_BOUND, source_version_index, get_goodcode_snippet, get_failcode_snippet): Adjust to the new minimum source_version = 1.6. (TARGET_VERSION_BOUND, target_version_index, corresponding_classfile_version): Adjust to the new minimum target_version = 1.6. (get_source_version_for_javac): Remove function. (is_envjavac_usable): Remove source_version_for_javac parameter. Don't bother trying the -target option alone. (is_javac_usable): Likewise. (compile_java_class): Map source_version < 1.6 to 1.6. Map target_version < 1.6 to 1.6. Use source_version instead of calling get_source_version_for_javac. --- diff --git a/ChangeLog b/ChangeLog index ba0e23fcd4..9f69453a99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2023-06-10 Bruno Haible + + javacomp-script, javacomp: Remove support for javac versions < 1.6. + * m4/javacomp.m4 (gt_JAVACOMP): State that the minimum source_version + and the minimum target_version are 1.6. Map smaller values to 1.6. + Complain if the java version is < 1.6. Use 1.6 as default, instead of + 1.1. Don't bother trying the -target option alone. + * lib/javacomp.h (compile_java_class): State that the minimum + source_version and the minimum target_version are 1.6. + * lib/javacomp.c (default_target_version): Complain if the java version + is < 1.6. Use 1.6 as default, instead of 1.1. + (SOURCE_VERSION_BOUND, source_version_index, get_goodcode_snippet, + get_failcode_snippet): Adjust to the new minimum source_version = 1.6. + (TARGET_VERSION_BOUND, target_version_index, + corresponding_classfile_version): Adjust to the new minimum + target_version = 1.6. + (get_source_version_for_javac): Remove function. + (is_envjavac_usable): Remove source_version_for_javac parameter. Don't + bother trying the -target option alone. + (is_javac_usable): Likewise. + (compile_java_class): Map source_version < 1.6 to 1.6. Map + target_version < 1.6 to 1.6. Use source_version instead of calling + get_source_version_for_javac. + 2023-06-10 Bruno Haible javacomp: Simplify after gcj support was removed. diff --git a/lib/javacomp.c b/lib/javacomp.c index b071f172de..19de05d1fd 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -94,10 +94,18 @@ default_target_version (void) /* Determine the version from the found JVM. */ java_version_cache = javaexec_version (); if (java_version_cache == NULL) - java_version_cache = "1.1"; + java_version_cache = "1.6"; + else if (java_version_cache[0] == '1' + && java_version_cache[1] == '.' + && java_version_cache[2] >= '1' && java_version_cache[2] <= '5' + && java_version_cache[3] == '\0') + { + error (0, 0, _("The java program is too old. Cannot compile Java code for this old version any more.")); + java_version_cache = "1.6"; + } else if ((java_version_cache[0] == '1' && java_version_cache[1] == '.' - && java_version_cache[2] >= '1' && java_version_cache[2] <= '8' + && java_version_cache[2] >= '6' && java_version_cache[2] <= '8' && java_version_cache[3] == '\0') || (java_version_cache[0] == '9' && java_version_cache[1] == '\0') @@ -115,7 +123,7 @@ default_target_version (void) like the preceding ones. */ java_version_cache = "11"; else - java_version_cache = "1.1"; + java_version_cache = "1.6"; } return java_version_cache; } @@ -123,25 +131,22 @@ default_target_version (void) /* ======================= Source version dependent ======================= */ /* Convert a source version to an index. */ -#define SOURCE_VERSION_BOUND 8 /* exclusive upper bound */ +#define SOURCE_VERSION_BOUND 6 /* exclusive upper bound */ static unsigned int source_version_index (const char *source_version) { if (source_version[0] == '1' && source_version[1] == '.') { - if ((source_version[2] >= '3' && source_version[2] <= '5') + if ((source_version[2] >= '6' && source_version[2] <= '8') && source_version[3] == '\0') - return source_version[2] - '3'; - if ((source_version[2] >= '7' && source_version[2] <= '8') - && source_version[3] == '\0') - return source_version[2] - '4'; + return source_version[2] - '6'; } else if (source_version[0] == '9' && source_version[1] == '\0') - return 5; + return 3; else if (source_version[0] == '1' && (source_version[1] >= '0' && source_version[1] <= '1') && source_version[2] == '\0') - return source_version[1] - '0' + 6; + return source_version[1] - '0' + 4; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return 0; } @@ -150,11 +155,7 @@ source_version_index (const char *source_version) static const char * get_goodcode_snippet (const char *source_version) { - if (strcmp (source_version, "1.3") == 0) - return "class conftest {}\n"; - if (strcmp (source_version, "1.4") == 0) - return "class conftest { static { assert(true); } }\n"; - if (strcmp (source_version, "1.5") == 0) + if (strcmp (source_version, "1.6") == 0) return "class conftest { T foo() { return null; } }\n"; if (strcmp (source_version, "1.7") == 0) return "class conftest { void foo () { switch (\"A\") {} } }\n"; @@ -176,11 +177,7 @@ get_goodcode_snippet (const char *source_version) static const char * get_failcode_snippet (const char *source_version) { - if (strcmp (source_version, "1.3") == 0) - return "class conftestfail { static { assert(true); } }\n"; - if (strcmp (source_version, "1.4") == 0) - return "class conftestfail { T foo() { return null; } }\n"; - if (strcmp (source_version, "1.5") == 0) + if (strcmp (source_version, "1.6") == 0) return "class conftestfail { void foo () { switch (\"A\") {} } }\n"; if (strcmp (source_version, "1.7") == 0) return "class conftestfail { void foo () { Runnable r = () -> {}; } }\n"; @@ -199,20 +196,20 @@ get_failcode_snippet (const char *source_version) /* ======================= Target version dependent ======================= */ /* Convert a target version to an index. */ -#define TARGET_VERSION_BOUND 11 /* exclusive upper bound */ +#define TARGET_VERSION_BOUND 6 /* exclusive upper bound */ static unsigned int target_version_index (const char *target_version) { if (target_version[0] == '1' && target_version[1] == '.' - && (target_version[2] >= '1' && target_version[2] <= '8') + && (target_version[2] >= '6' && target_version[2] <= '8') && target_version[3] == '\0') - return target_version[2] - '1'; + return target_version[2] - '6'; else if (target_version[0] == '9' && target_version[1] == '\0') - return 8; + return 3; else if (target_version[0] == '1' && (target_version[1] >= '0' && target_version[1] <= '1') && target_version[2] == '\0') - return target_version[1] - '0' + 9; + return target_version[1] - '0' + 4; error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class")); return 0; } @@ -222,16 +219,6 @@ target_version_index (const char *target_version) static int corresponding_classfile_version (const char *target_version) { - if (strcmp (target_version, "1.1") == 0) - return 45; - if (strcmp (target_version, "1.2") == 0) - return 46; - if (strcmp (target_version, "1.3") == 0) - return 47; - if (strcmp (target_version, "1.4") == 0) - return 48; - if (strcmp (target_version, "1.5") == 0) - return 49; if (strcmp (target_version, "1.6") == 0) return 50; if (strcmp (target_version, "1.7") == 0) @@ -248,22 +235,6 @@ corresponding_classfile_version (const char *target_version) return 0; } -/* Return the source version to pass to javac. */ -static const char * -get_source_version_for_javac (const char *source_version, - const char *target_version) -{ - /* The javac option '-source 1.5' has the same meaning as '-source 1.6', - but since Java 9 supports only the latter, prefer the latter if a - target_version >= 1.6 is requested. */ - if (strcmp (source_version, "1.5") == 0 - && !(target_version[0] == '1' && target_version[1] == '.' - && (target_version[2] >= '1' && target_version[2] <= '5') - && target_version[3] == '\0')) - return "1.6"; - return source_version; -} - /* ======================== Compilation subroutines ======================== */ /* Try to compile a set of Java sources with $JAVAC. @@ -479,9 +450,7 @@ get_classfile_version (const char *compiled_file_name) Return a failure indicator (true upon error). */ static bool is_envjavac_usable (const char *javac, - const char *source_version, - const char *source_version_for_javac, - const char *target_version, + const char *source_version, const char *target_version, bool *usablep, bool *source_option_p, bool *target_option_p) { @@ -536,7 +505,7 @@ is_envjavac_usable (const char *javac, /* $JAVAC compiled conftest.java successfully. */ /* Try adding -source option if it is useful. */ char *javac_source = - xasprintf ("%s -source %s", javac, source_version_for_javac); + xasprintf ("%s -source %s", javac, source_version); assume (javac_source != NULL); unlink (compiled_file_name); @@ -589,7 +558,7 @@ is_envjavac_usable (const char *javac, tmpdir->dir_name, false, false, false, true)) /* $JAVAC compiled conftestfail.java successfully, and - "$JAVAC -source $source_version_for_javac" rejects it. + "$JAVAC -source $source_version" rejects it. So the -source option is useful. */ resultp->source_option = true; } @@ -602,125 +571,31 @@ is_envjavac_usable (const char *javac, } else { - /* Try with -target option alone. (Sun javac 1.3.1 has the -target - option but no -source option.) */ - char *javac_target = - xasprintf ("%s -target %s", javac, target_version); - assume (javac_target != NULL); + /* Try with -target and -source options. (All supported javac + versions support both, see the table in javacomp.m4.) */ + char *javac_target_source = + xasprintf ("%s -target %s -source %s", javac, + target_version, source_version); + assume (javac_target_source != NULL); unlink (compiled_file_name); java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target, + if (!compile_using_envjavac (javac_target_source, java_sources, 1, tmpdir->dir_name, false, false, false, true) && stat (compiled_file_name, &statbuf) >= 0 && get_classfile_version (compiled_file_name) <= corresponding_classfile_version (target_version)) { - /* "$JAVAC -target $target_version" compiled conftest.java - successfully. */ - /* Try adding -source option if it is useful. */ - char *javac_target_source = - xasprintf ("%s -source %s", javac_target, source_version_for_javac); - assume (javac_target_source != NULL); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, - failcode)) - { - free (conftest_file_name); - free (javac_target_source); - free (javac_target); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_envjavac (javac_target_source, - java_sources, 1, - tmpdir->dir_name, - false, false, false, - true)) - /* "$JAVAC -target $target_version" compiled - conftestfail.java successfully, and - "$JAVAC -target $target_version -source $source_version_for_javac" - rejects it. So the -source option is useful. */ - resultp->source_option = true; - } - } - } - - free (javac_target_source); - + /* "$JAVAC -target $target_version -source $source_version" + compiled conftest.java successfully. */ + resultp->source_option = true; resultp->target_option = true; resultp->usable = true; } - else - { - /* Maybe this -target option requires a -source option? Try with - -target and -source options. (Supported by Sun javac 1.4 and - higher.) */ - char *javac_target_source = - xasprintf ("%s -source %s", javac_target, source_version_for_javac); - assume (javac_target_source != NULL); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "$JAVAC -target $target_version -source $source_version_for_javac" - compiled conftest.java successfully. */ - resultp->source_option = true; - resultp->target_option = true; - resultp->usable = true; - } - - free (javac_target_source); - } - free (javac_target); + free (javac_target_source); } free (compiled_file_name); @@ -763,9 +638,7 @@ is_javac_present (void) -target option. Return a failure indicator (true upon error). */ static bool -is_javac_usable (const char *source_version, - const char *source_version_for_javac, - const char *target_version, +is_javac_usable (const char *source_version, const char *target_version, bool *usablep, bool *source_option_p, bool *target_option_p) { /* The cache depends on the source_version and target_version. */ @@ -810,7 +683,7 @@ is_javac_usable (const char *source_version, java_sources[0] = conftest_file_name; if (!compile_using_javac (java_sources, 1, - false, source_version_for_javac, + false, source_version, false, target_version, tmpdir->dir_name, false, false, false, true) && stat (compiled_file_name, &statbuf) >= 0 @@ -823,7 +696,7 @@ is_javac_usable (const char *source_version, java_sources[0] = conftest_file_name; if (!compile_using_javac (java_sources, 1, - true, source_version_for_javac, + true, source_version, false, target_version, tmpdir->dir_name, false, false, false, true) && stat (compiled_file_name, &statbuf) >= 0 @@ -856,7 +729,7 @@ is_javac_usable (const char *source_version, java_sources[0] = conftest_file_name; if (!compile_using_javac (java_sources, 1, - false, source_version_for_javac, + false, source_version, false, target_version, tmpdir->dir_name, false, false, false, true) @@ -866,12 +739,12 @@ is_javac_usable (const char *source_version, java_sources[0] = conftest_file_name; if (compile_using_javac (java_sources, 1, - true, source_version_for_javac, + true, source_version, false, target_version, tmpdir->dir_name, false, false, false, true)) /* javac compiled conftestfail.java successfully, and - "javac -source $source_version_for_javac" rejects it. + "javac -source $source_version" rejects it. So the -source option is useful. */ resultp->source_option = true; } @@ -882,13 +755,13 @@ is_javac_usable (const char *source_version, } else { - /* Try with -target option alone. (Sun javac 1.3.1 has the -target - option but no -source option.) */ + /* Try with -target and -source options. (All supported javac + versions support both, see the table in javacomp.m4.) */ unlink (compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_javac (java_sources, 1, - false, source_version_for_javac, + true, source_version, true, target_version, tmpdir->dir_name, false, false, false, true) @@ -896,98 +769,12 @@ is_javac_usable (const char *source_version, && get_classfile_version (compiled_file_name) <= corresponding_classfile_version (target_version)) { - /* "javac -target $target_version" compiled conftest.java - successfully. */ - /* Try adding -source option if it is useful. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - true, source_version_for_javac, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, - failcode)) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - false, source_version_for_javac, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_javac (java_sources, 1, - true, source_version_for_javac, - true, target_version, - tmpdir->dir_name, - false, false, false, true)) - /* "javac -target $target_version" compiled - conftestfail.java successfully, and - "javac -target $target_version -source $source_version_for_javac" - rejects it. So the -source option is useful. */ - resultp->source_option = true; - } - } - } - + /* "javac -target $target_version -source $source_version" + compiled conftest.java successfully. */ + resultp->source_option = true; resultp->target_option = true; resultp->usable = true; } - else - { - /* Maybe this -target option requires a -source option? Try with - -target and -source options. (Supported by Sun javac 1.4 and - higher.) */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - true, source_version_for_javac, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "javac -target $target_version -source $source_version_for_javac" - compiled conftest.java successfully. */ - resultp->source_option = true; - resultp->target_option = true; - resultp->usable = true; - } - } } free (compiled_file_name); @@ -1019,6 +806,19 @@ compile_java_class (const char * const *java_sources, bool err = false; char *old_JAVA_HOME; + /* Map source_version 1.1 ... 1.5 to 1.6. */ + if (source_version[0] == '1' && source_version[1] == '.' + && (source_version[2] >= '1' && source_version[2] <= '5') + && source_version[3] == '\0') + source_version = "1.6"; + + /* Map target_version 1.1 ... 1.5 to 1.6. */ + if (target_version != NULL + && target_version[0] == '1' && target_version[1] == '.' + && (target_version[2] >= '1' && target_version[2] <= '5') + && target_version[3] == '\0') + target_version = "1.6"; + { const char *javac = getenv ("JAVAC"); if (javac != NULL && javac[0] != '\0') @@ -1026,18 +826,12 @@ compile_java_class (const char * const *java_sources, bool usable = false; bool source_option = false; bool target_option = false; - const char *source_version_for_javac; if (target_version == NULL) target_version = default_target_version (); - source_version_for_javac = - get_source_version_for_javac (source_version, target_version); - if (is_envjavac_usable (javac, - source_version, - source_version_for_javac, - target_version, + source_version, target_version, &usable, &source_option, &target_option)) { @@ -1058,7 +852,7 @@ compile_java_class (const char * const *java_sources, xasprintf ("%s%s%s%s%s", javac, source_option ? " -source " : "", - source_option ? source_version_for_javac : "", + source_option ? source_version : "", target_option ? " -target " : "", target_option ? target_version : ""); assume (javac_with_options != NULL); @@ -1091,16 +885,11 @@ compile_java_class (const char * const *java_sources, bool usable = false; bool source_option = false; bool target_option = false; - const char *source_version_for_javac; if (target_version == NULL) target_version = default_target_version (); - source_version_for_javac = - get_source_version_for_javac (source_version, target_version); - - if (is_javac_usable (source_version, source_version_for_javac, - target_version, + if (is_javac_usable (source_version, target_version, &usable, &source_option, &target_option)) { err = true; @@ -1120,7 +909,7 @@ compile_java_class (const char * const *java_sources, verbose); err = compile_using_javac (java_sources, java_sources_count, - source_option, source_version_for_javac, + source_option, source_version, target_option, target_version, directory, optimize, debug, verbose, false); diff --git a/lib/javacomp.h b/lib/javacomp.h index dcc9c37f7a..e6e5d622e6 100644 --- a/lib/javacomp.h +++ b/lib/javacomp.h @@ -23,33 +23,32 @@ classpaths is a list of pathnames to be prepended to the CLASSPATH. source_version can be: support for - 1.3 inner classes - 1.4 assert keyword - 1.5 generic classes and methods - 1.6 (not supported) + 1.6 assert keyword (1.4), generic classes and methods (1.5) 1.7 switch(string) 1.8 lambdas 9 private interface methods 10 type inference for local variables 11 'var' in parameters of lambda expressions + If source-version 1.3 or 1.4 or 1.5 is requested, it gets mapped to 1.6, for + backward compatibility. (Currently the minimum Java and javac version we need + to support is Java 1.6, since that's the default Java version on Solaris 10.) + target_version can be: classfile version: - 1.1 45.3 - 1.2 46.0 - 1.3 47.0 - 1.4 48.0 - 1.5 49.0 1.6 50.0 1.7 51.0 1.8 52.0 9 53.0 10 54.0 11 55.0 + If a target-version below 1.6 is requested, it gets mapped to 1.6, for + backward compatibility. (Currently the minimum Java and javac version we need + to support is Java 1.6, since that's the default Java version on Solaris 10.) target_version can also be given as NULL. In this case, the required target_version is determined from the found JVM (see javaversion.h). Specifying target_version is useful when building a library (.jar) that is useful outside the given package. Passing target_version = NULL is useful when building an application. - It is unreasonable to ask for: + It is unreasonable to ask for a target-version < source-version, such as - target_version < 1.4 with source_version >= 1.4, or - target_version < 1.5 with source_version >= 1.5, or - target_version < 1.6 with source_version >= 1.6, or @@ -57,7 +56,8 @@ - target_version < 1.8 with source_version >= 1.8, or - target_version < 9 with source_version >= 9, or - target_version < 10 with source_version >= 10, or - - target_version < 11 with source_version >= 11, + - target_version < 11 with source_version >= 11, or + - ... because even Sun's/Oracle's javac doesn't support these combinations. It is redundant to ask for a target_version > source_version, since the smaller target_version = source_version will also always work and newer JVMs diff --git a/m4/javacomp.m4 b/m4/javacomp.m4 index d373708d42..e20b309f3a 100644 --- a/m4/javacomp.m4 +++ b/m4/javacomp.m4 @@ -1,4 +1,4 @@ -# javacomp.m4 serial 23 +# javacomp.m4 serial 24 dnl Copyright (C) 2001-2003, 2006-2007, 2009-2023 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -12,25 +12,17 @@ dnl with or without modifications, as long as this notice is preserved. # target-version format. # # source-version can be: support for -# 1.3 inner classes -# 1.4 assert keyword -# 1.5 generic classes and methods -# 1.6 (not supported) +# 1.6 assert keyword (1.4), generic classes and methods (1.5) # 1.7 switch(string) # 1.8 lambdas # 9 private interface methods # 10 type inference for local variables # 11 'var' in parameters of lambda expressions -# Instead of source-version 1.6, use 1.5, since Java 6 did not introduce any -# language changes. See -# https://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html +# If source-version 1.3 or 1.4 or 1.5 is requested, it gets mapped to 1.6, for +# backward compatibility. (Currently the minimum Java and javac version we need +# to support is Java 1.6, since that's the default Java version on Solaris 10.) # # target-version can be: classfile version: -# 1.1 45.3 -# 1.2 46.0 -# 1.3 47.0 -# 1.4 48.0 -# 1.5 49.0 # 1.6 50.0 # 1.7 51.0 # 1.8 52.0 @@ -40,14 +32,13 @@ dnl with or without modifications, as long as this notice is preserved. # The classfile version of a .class file can be determined through the "file" # command. More portably, the classfile major version can be determined through # "od -A n -t d1 -j 7 -N 1 classfile". +# If a target-version below 1.6 is requested, it gets mapped to 1.6, for +# backward compatibility. (Currently the minimum Java and javac version we need +# to support is Java 1.6, since that's the default Java version on Solaris 10.) +# # target-version can also be omitted. In this case, the required target-version # is determined from the found JVM (see macro gt_JAVAEXEC): # target-version for JVM -# 1.1 JDK 1.1 -# 1.2 JDK/JRE 1.2 -# 1.3 JDK/JRE 1.3 -# 1.4 JDK/JRE 1.4 -# 1.5 JDK/JRE 5 # 1.6 JDK/JRE 6 # 1.7 JDK/JRE 7 # 1.8 JDK/JRE 8 @@ -59,7 +50,7 @@ dnl with or without modifications, as long as this notice is preserved. # useful outside the given package. Omitting target-version is useful when # building an application. # -# It is unreasonable to ask for: +# It is unreasonable to ask for a target-version < source-version, such as # - target-version < 1.4 with source-version >= 1.4, or # - target-version < 1.5 with source-version >= 1.5, or # - target_version < 1.6 with source_version >= 1.6, or @@ -67,7 +58,8 @@ dnl with or without modifications, as long as this notice is preserved. # - target_version < 1.8 with source_version >= 1.8, or # - target_version < 9 with source_version >= 9, or # - target_version < 10 with source_version >= 10, or -# - target_version < 11 with source_version >= 11, +# - target_version < 11 with source_version >= 11, or +# - ... # because even Sun's/Oracle's javac doesn't support these combinations. # # It is redundant to ask for a target-version > source-version, since the @@ -86,6 +78,9 @@ AC_DEFUN([gt_JAVACOMP], test -n "$source_version" || { AC_MSG_ERROR([missing source-version argument to gt_@&t@JAVACOMP]) } + case "$source_version" in + 1.1 | 1.2 | 1.3 | 1.4 | 1.5) source_version='1.6' ;; + esac m4_if([$2], [], [if test -n "$HAVE_JAVAEXEC"; then dnl Use $CONF_JAVA to determine the JVM's version. @@ -117,28 +112,33 @@ changequote([,])dnl CLASSPATH=.${CLASSPATH:+$CLASSPATH_SEPARATOR$CLASSPATH} $CONF_JAVA conftestver 2>&AS_MESSAGE_LOG_FD }` case "$target_version" in - 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9 | 10 | 11) ;; + null) + dnl JDK 1.1.X returns null. + target_version=1.1 ;; + esac + case "$target_version" in + 1.1 | 1.2 | 1.3 | 1.4 | 1.5) + AC_MSG_WARN([$CONF_JAVA is too old, cannot compile Java code for this old version any more]) + target_version=1.6 ;; + 1.6 | 1.7 | 1.8 | 9 | 10 | 11) ;; 12 | 13 | 14 | 15 | 16 | 17) dnl Assume that these (not yet released) Java versions will behave dnl like the preceding ones. target_version=11 ;; - null) - dnl JDK 1.1.X returns null. - target_version=1.1 ;; *) AC_MSG_WARN([unknown target-version $target_version, please update gt_@&t@JAVACOMP macro]) - target_version=1.1 ;; + target_version=1.6 ;; esac else - target_version="1.1" + target_version="1.6" fi ], - [target_version=$2]) + [target_version=$2 + case "$target_version" in + 1.1 | 1.2 | 1.3 | 1.4 | 1.5) target_version='1.6' ;; + esac + ]) case "$source_version" in - 1.3) goodcode='class conftest {}' - failcode='class conftestfail { static { assert(true); } }' ;; - 1.4) goodcode='class conftest { static { assert(true); } }' - failcode='class conftestfail { T foo() { return null; } }' ;; - 1.5) goodcode='class conftest { T foo() { return null; } }' + 1.6) goodcode='class conftest { T foo() { return null; } }' failcode='class conftestfail { void foo () { switch ("A") {} } }' ;; 1.7) goodcode='class conftest { void foo () { switch ("A") {} } }' failcode='class conftestfail { void foo () { Runnable r = () -> {}; } }' ;; @@ -153,11 +153,6 @@ changequote([,])dnl *) AC_MSG_ERROR([invalid source-version argument to gt_@&t@JAVACOMP: $source_version]) ;; esac case "$target_version" in - 1.1) cfversion=45 ;; - 1.2) cfversion=46 ;; - 1.3) cfversion=47 ;; - 1.4) cfversion=48 ;; - 1.5) cfversion=49 ;; 1.6) cfversion=50 ;; 1.7) cfversion=51 ;; 1.8) cfversion=52 ;; @@ -185,18 +180,6 @@ changequote([,])dnl dnl dnl The support of Sun/Oracle javac for target-version and source-version: dnl - dnl javac 1.3: -target 1.1 1.2 1.3 default: 1.1 - dnl source always: 1.3 - dnl - dnl javac 1.4: -target 1.1 1.2 1.3 1.4 default: 1.2 - dnl -source 1.3 1.4 default: 1.3 - dnl -target 1.1/1.2/1.3 only possible with -source 1.3 or no -source - dnl - dnl javac 1.5: -target 1.1 1.2 1.3 1.4 1.5 default: 1.5 - dnl -source 1.3 1.4 1.5 default: 1.5 - dnl -target 1.1/1.2/1.3 only possible with -source 1.3 - dnl -target 1.4 only possible with -source 1.3/1.4 - dnl dnl javac 1.6: -target 1.1 1.2 1.3 1.4 1.5 1.6 default: 1.6 dnl -source 1.3 1.4 1.5 1.6 default: 1.5 dnl -target 1.1/1.2/1.3 only possible with -source 1.3 @@ -250,15 +233,6 @@ changequote([,])dnl dnl options). if test -n "$JAVAC"; then dnl Try $JAVAC. - dnl The javac option '-source 1.5' has the same meaning as '-source 1.6', - dnl but since Java 9 supports only the latter, prefer the latter if a - dnl target_version >= 1.6 is requested. - if test "$source_version" = 1.5; then - case "$target_version" in - 1.1 | 1.2 | 1.3 | 1.4 | 1.5) ;; - *) source_version='1.6' ;; - esac - fi rm -f conftest.class if { echo "$as_me:__oline__: $JAVAC -d . conftest.java" >&AS_MESSAGE_LOG_FD $JAVAC -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 @@ -289,51 +263,17 @@ changequote([,])dnl HAVE_JAVACOMP=1 fi else - dnl Try with -target option alone. (Sun javac 1.3.1 has the -target - dnl option but no -source option.) + dnl Try with -target and -source options. (All supported javac + dnl versions support both, see the table above.) rm -f conftest.class - if { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - $JAVAC -target "$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 + if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD + $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 } \ && test -f conftest.class \ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then - dnl Try adding -source option if it is useful. - rm -f conftest.class - rm -f conftestfail.class - if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftest.class \ - && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \ - && { echo "$as_me:__oline__: $JAVAC -target $target_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD - $JAVAC -target "$target_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftestfail.class \ - && ! { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD - $JAVAC -target "$target_version" -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1 - }; then - CONF_JAVAC="$JAVAC -target $target_version -source $source_version" - HAVE_JAVAC_ENVVAR=1 - HAVE_JAVACOMP=1 - else - CONF_JAVAC="$JAVAC -target $target_version" - HAVE_JAVAC_ENVVAR=1 - HAVE_JAVACOMP=1 - fi - else - dnl Maybe this -target option requires a -source option? Try with - dnl -target and -source options. (Supported by Sun javac 1.4 and - dnl higher.) - rm -f conftest.class - if { echo "$as_me:__oline__: $JAVAC -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - $JAVAC -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftest.class \ - && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then - CONF_JAVAC="$JAVAC -target $target_version -source $source_version" - HAVE_JAVAC_ENVVAR=1 - HAVE_JAVACOMP=1 - fi + CONF_JAVAC="$JAVAC -target $target_version -source $source_version" + HAVE_JAVAC_ENVVAR=1 + HAVE_JAVACOMP=1 fi fi fi @@ -350,15 +290,6 @@ changequote([,])dnl if { javac -version >/dev/null 2>/dev/null || test $? -le 2; } \ && ( 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 dnl OK, javac works. - dnl The javac option '-source 1.5' has the same meaning as '-source 1.6', - dnl but since Java 9 supports only the latter, prefer the latter if a - dnl target_version >= 1.6 is requested. - if test "$source_version" = 1.5; then - case "$target_version" in - 1.1 | 1.2 | 1.3 | 1.4 | 1.5) ;; - *) source_version='1.6' ;; - esac - fi dnl Now test whether it supports the desired target-version and dnl source-version. rm -f conftest.class @@ -391,51 +322,17 @@ changequote([,])dnl HAVE_JAVACOMP=1 fi else - dnl Try with -target option alone. (Sun javac 1.3.1 has the -target - dnl option but no -source option.) + dnl Try with -target and -source options. (All supported javac + dnl versions support both, see the table above.) rm -f conftest.class - if { echo "$as_me:__oline__: javac -target $target_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - javac -target "$target_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 + if { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD + javac -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 } \ && test -f conftest.class \ && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then - dnl Try adding -source option if it is useful. - rm -f conftest.class - rm -f conftestfail.class - if { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - javac -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftest.class \ - && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD \ - && { echo "$as_me:__oline__: javac -target $target_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD - javac -target "$target_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftestfail.class \ - && ! { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftestfail.java" >&AS_MESSAGE_LOG_FD - javac -target "$target_version" -source "$source_version" -d . conftestfail.java >&AS_MESSAGE_LOG_FD 2>&1 - }; then - CONF_JAVAC="javac -target $target_version -source $source_version" - HAVE_JAVAC=1 - HAVE_JAVACOMP=1 - else - CONF_JAVAC="javac -target $target_version" - HAVE_JAVAC=1 - HAVE_JAVACOMP=1 - fi - else - dnl Maybe this -target option requires a -source option? Try with - dnl -target and -source options. (Supported by Sun javac 1.4 and - dnl higher.) - rm -f conftest.class - if { echo "$as_me:__oline__: javac -target $target_version -source $source_version -d . conftest.java" >&AS_MESSAGE_LOG_FD - javac -target "$target_version" -source "$source_version" -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1 - } \ - && test -f conftest.class \ - && expr `func_classfile_version conftest.class` '<=' $cfversion >/dev/null 2>&AS_MESSAGE_LOG_FD; then - CONF_JAVAC="javac -target $target_version -source $source_version" - HAVE_JAVAC=1 - HAVE_JAVACOMP=1 - fi + CONF_JAVAC="javac -target $target_version -source $source_version" + HAVE_JAVAC=1 + HAVE_JAVACOMP=1 fi fi fi