static bool
compile_using_javac (const char * const *java_sources,
unsigned int java_sources_count,
+ const char *nowarn_option,
bool source_option, const char *source_version,
bool target_option, const char *target_version,
const char *directory,
unsigned int i;
argc =
- 1 + (source_option ? 2 : 0) + (target_option ? 2 : 0) + (optimize ? 1 : 0)
- + (debug ? 1 : 0) + (directory != NULL ? 2 : 0) + java_sources_count;
+ 1 + (nowarn_option != NULL ? 1 : 0) + (source_option ? 2 : 0)
+ + (target_option ? 2 : 0) + (optimize ? 1 : 0) + (debug ? 1 : 0)
+ + (directory != NULL ? 2 : 0) + java_sources_count;
argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "javac";
+ if (nowarn_option != NULL)
+ *argp++ = nowarn_option;
if (source_option)
{
*argp++ = "-source";
}
/* Test whether $JAVAC can be used, and whether it needs a -source and/or
- -target option.
+ -target option, as well as an option to inhibit warnings.
Return a failure indicator (true upon error). */
static bool
is_envjavac_usable (const char *javac,
const char *source_version, const char *target_version,
bool *usablep,
+ char nowarn_option_out[17],
char source_option_out[30], char target_option_out[30])
{
/* The cache depends on the source_version and target_version. */
{
/*bool*/ unsigned int tested : 1;
/*bool*/ unsigned int usable : 1;
+ /*bool*/ unsigned int nowarn_option : 1;
unsigned int source_option : 7;
unsigned int target_option : 7;
};
char *conftest_file_name;
char *compiled_file_name;
const char *java_sources[1];
+ const char *nowarn_option;
struct stat statbuf;
tmpdir = create_temp_dir ("java", NULL, false);
xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL);
register_temp_file (tmpdir, compiled_file_name);
+ /* See the discussion in javacomp.m4. */
+ nowarn_option = " -Xlint:-options";
+ char *javac_nowarn = xasprintf ("%s%s", javac, nowarn_option);
+ assume (javac_nowarn != NULL);
+
java_sources[0] = conftest_file_name;
- if (!compile_using_envjavac (javac,
- java_sources, 1, tmpdir->dir_name,
- false, false, false, true)
- && stat (compiled_file_name, &statbuf) >= 0)
+ if ((!compile_using_envjavac (javac_nowarn,
+ java_sources, 1, tmpdir->dir_name,
+ false, false, false, true)
+ && stat (compiled_file_name, &statbuf) >= 0)
+ || (nowarn_option = "",
+ unlink (compiled_file_name),
+ (!compile_using_envjavac (javac,
+ java_sources, 1, tmpdir->dir_name,
+ false, false, false, true)
+ && stat (compiled_file_name, &statbuf) >= 0)))
{
/* $JAVAC compiled conftest.java successfully. */
int compiler_cfversion =
try_target_version);
char *javac_source_target =
- xasprintf ("%s%s%s", javac, source_option, target_option);
+ xasprintf ("%s%s%s%s", javac, nowarn_option,
+ source_option, target_option);
assume (javac_source_target != NULL);
unlink (compiled_file_name);
and target_version. Perfect. */
free (javac_source_target);
+ resultp->nowarn_option = (nowarn_option[0] != '\0');
resultp->source_option = try_source_version;
resultp->target_option =
(try_target_version == compiler_target_version ? 0 :
try_target_version);
javac_source_target =
- xasprintf ("%s%s%s", javac,
+ xasprintf ("%s%s%s%s", javac, nowarn_option,
source_option, target_option);
assume (javac_source_target != NULL);
nothing. */
free (javac_source_target);
+ resultp->nowarn_option = (nowarn_option[0] != '\0');
resultp->source_option = try_source_version;
resultp->target_option =
(try_target_version == compiler_target_version ? 0 :
cleanup_temp_dir (tmpdir);
+ free (javac_nowarn);
free (compiled_file_name);
free (conftest_file_name);
}
}
*usablep = resultp->usable;
+ if (resultp->nowarn_option)
+ strcpy (nowarn_option_out, " -Xlint:-options");
+ else
+ nowarn_option_out[0] = '\0';
sprintf (source_option_out, " -source %s%d",
resultp->source_option <= 8 ? "1." : "",
resultp->source_option);
}
/* Test whether javac can be used and whether it needs a -source and/or
- -target option.
+ -target option, as well as an option to inhibit warnings.
Return a failure indicator (true upon error). */
static bool
is_javac_usable (const char *source_version, const char *target_version,
bool *usablep,
+ char nowarn_option_out[17],
char source_option_out[20], char target_option_out[20])
{
/* The cache depends on the source_version and target_version. */
{
/*bool*/ unsigned int tested : 1;
/*bool*/ unsigned int usable : 1;
+ /*bool*/ unsigned int nowarn_option : 1;
unsigned int source_option : 7;
unsigned int target_option : 7;
};
char *conftest_file_name;
char *compiled_file_name;
const char *java_sources[1];
+ const char *nowarn_option;
struct stat statbuf;
tmpdir = create_temp_dir ("java", NULL, false);
xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL);
register_temp_file (tmpdir, compiled_file_name);
+ /* See the discussion in javacomp.m4. */
+ nowarn_option = "-Xlint:-options";
+
java_sources[0] = conftest_file_name;
- if (!compile_using_javac (java_sources, 1,
- false, source_version,
- false, target_version,
- tmpdir->dir_name,
- false, false, false, true)
- && stat (compiled_file_name, &statbuf) >= 0)
+ if ((!compile_using_javac (java_sources, 1,
+ nowarn_option,
+ false, source_version,
+ false, target_version,
+ tmpdir->dir_name,
+ false, false, false, true)
+ && stat (compiled_file_name, &statbuf) >= 0)
+ || (nowarn_option = NULL,
+ unlink (compiled_file_name),
+ (!compile_using_javac (java_sources, 1,
+ nowarn_option,
+ false, source_version,
+ false, target_version,
+ tmpdir->dir_name,
+ false, false, false, true)
+ && stat (compiled_file_name, &statbuf) >= 0)))
{
/* javac compiled conftest.java successfully. */
int compiler_cfversion =
java_sources[0] = conftest_file_name;
if (!compile_using_javac (java_sources, 1,
+ nowarn_option,
true,
source_option,
try_target_version != compiler_target_version,
{
/* The compiler directly supports the desired source_version
and target_version. Perfect. */
+ resultp->nowarn_option = (nowarn_option != NULL);
resultp->source_option = try_source_version;
resultp->target_option =
(try_target_version == compiler_target_version ? 0 :
java_sources[0] = conftest_file_name;
if (!compile_using_javac (java_sources, 1,
+ nowarn_option,
true,
source_option,
try_target_version != compiler_target_version,
/* The compiler supports the try_source_version
and try_target_version. It's better than
nothing. */
+ resultp->nowarn_option = (nowarn_option != NULL);
resultp->source_option = try_source_version;
resultp->target_option =
(try_target_version == compiler_target_version ? 0 :
}
*usablep = resultp->usable;
+ if (resultp->nowarn_option)
+ strcpy (nowarn_option_out, "-Xlint:-options");
+ else
+ nowarn_option_out[0] = '\0';
sprintf (source_option_out, "%s%d",
resultp->source_option <= 8 ? "1." : "",
resultp->source_option);
if (javac != NULL && javac[0] != '\0')
{
bool usable = false;
+ char nowarn_option[17];
char source_option[30];
char target_option[30];
if (is_envjavac_usable (javac,
source_version, target_version,
&usable,
+ nowarn_option,
source_option, target_option))
{
err = true;
set_classpath (classpaths, classpaths_count, false, verbose);
javac_with_options =
- xasprintf ("%s%s%s", javac, source_option, target_option);
+ xasprintf ("%s%s%s%s", javac,
+ nowarn_option, source_option, target_option);
assume (javac_with_options != NULL);
err = compile_using_envjavac (javac_with_options,
if (is_javac_present ())
{
bool usable = false;
+ char nowarn_option[17];
char source_option[20];
char target_option[20];
if (is_javac_usable (source_version, target_version,
&usable,
+ nowarn_option,
source_option, target_option))
{
err = true;
verbose);
err = compile_using_javac (java_sources, java_sources_count,
+ nowarn_option[0] != '\0' ? nowarn_option : NULL,
true, source_option,
target_option[0] != '\0', target_option,
directory, optimize, debug, verbose,
-# javacomp.m4 serial 25
+# javacomp.m4 serial 26
dnl Copyright (C) 2001-2003, 2006-2007, 2009-2023 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl javac classfile valid -source and obsolete -source
dnl version default version -target values and -target values
dnl ------- --------------- ----------------- ------------------
- dnl 1.6 50.0 1.3 .. 1.6
- dnl 1.7 51.0 1.3 .. 1.7
+ dnl 1.6 50.0 1.2 .. 1.6
+ dnl 1.7 51.0 1.2 .. 1.7
dnl 1.8 52.0 1.3 .. 1.8 1.3 .. 1.5
dnl 9 53.0 1.6 .. 9 1.6
dnl 10 54.0 1.6 .. 10 1.6
dnl
dnl The -source option value must be <= the -target option value.
dnl The minimal -source and -target option value produces an "is obsolete"
- dnl warning.
+ dnl warning (in javac 1.8 or newer). Additionally, if the -source option
+ dnl value is not the maximal possible one, i.e. not redundant, it produces a
+ dnl "bootstrap class path not set in conjunction with -source ..." warning
+ dnl (in javac 1.7 or newer).
+ dnl
+ dnl To get rid of these warnings, two options are available:
+ dnl * -nowarn. This option is supported since javac 1.6 at least. But
+ dnl it is overkill, because it would also silence warnings about the
+ dnl code being compiled.
+ dnl * -Xlint:-options. This option is supported since javac 1.6 at least.
+ dnl In javac 1.6 it is an undocumented no-op.
+ dnl We use -Xlint:-options and omit it only if we find that the compiler
+ dnl does not support it (which is unlikely).
dnl
dnl Canonicalize source_version and target_version, for easier arithmetic.
case "$source_version" in
dnl options).
if test -n "$JAVAC"; then
dnl Test whether $JAVAC is usable.
- 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
- } \
- && test -f conftest.class; then
+ dnl At the same time, determine which option to use to inhibit warnings;
+ dnl see the discussion above.
+ nowarn_option=' -Xlint:-options'
+ if { rm -f conftest.class \
+ && { echo "$as_me:__oline__: $JAVAC$nowarn_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC$nowarn_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class
+ } || { \
+ nowarn_option=
+ rm -f conftest.class \
+ && { echo "$as_me:__oline__: $JAVAC$nowarn_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC$nowarn_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class
+ }; then
compiler_cfversion=`func_classfile_version conftest.class`
compiler_target_version=`expr $compiler_cfversion - 44`
dnl It is hard to determine the compiler_source_version. This would
else
target_option=' -target '`case "$target_version" in 6|7|8) echo 1. ;; esac`"$target_version"
fi
- if { echo "$as_me:__oline__: $JAVAC$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
- $JAVAC$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ if { echo "$as_me:__oline__: $JAVAC$nowarn_option$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC$nowarn_option$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
} \
&& test -f conftest.class; then
dnl The compiler directly supports the desired source_version and
dnl target_version. Perfect.
- CONF_JAVAC="$JAVAC$source_option$target_option"
+ CONF_JAVAC="$JAVAC$nowarn_option$source_option$target_option"
HAVE_JAVAC_ENVVAR=1
HAVE_JAVACOMP=1
else
else
target_option=' -target '`case "$try_target_version" in 6|7|8) echo 1. ;; esac`"$try_target_version"
fi
- if { echo "$as_me:__oline__: $JAVAC$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
- $JAVAC$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ if { echo "$as_me:__oline__: $JAVAC$nowarn_option$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ $JAVAC$nowarn_option$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
} \
&& test -f conftest.class; then
dnl The compiler supports the try_source_version and
dnl try_target_version. It's better than nothing.
- CONF_JAVAC="$JAVAC$source_option$target_option"
+ CONF_JAVAC="$JAVAC$nowarn_option$source_option$target_option"
HAVE_JAVAC_ENVVAR=1
HAVE_JAVACOMP=1
break
popdef([AC_MSG_CHECKING])dnl
if test -z "$HAVE_JAVACOMP" && test -n "$HAVE_JAVAC_IN_PATH"; then
dnl Test whether javac is usable.
- 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
- } \
- && test -f conftest.class; then
+ dnl At the same time, determine which option to use to inhibit warnings;
+ dnl see the discussion above.
+ nowarn_option=' -Xlint:-options'
+ if { rm -f conftest.class \
+ && { echo "$as_me:__oline__: javac$nowarn_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ javac$nowarn_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class
+ } || { \
+ nowarn_option=
+ rm -f conftest.class \
+ && { echo "$as_me:__oline__: javac$nowarn_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ javac$nowarn_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ } \
+ && test -f conftest.class
+ }; then
compiler_cfversion=`func_classfile_version conftest.class`
compiler_target_version=`expr $compiler_cfversion - 44`
dnl It is hard to determine the compiler_source_version. This would
else
target_option=' -target '`case "$target_version" in 6|7|8) echo 1. ;; esac`"$target_version"
fi
- if { echo "$as_me:__oline__: javac$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
- javac$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ if { echo "$as_me:__oline__: javac$nowarn_option$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ javac$nowarn_option$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
} \
&& test -f conftest.class; then
dnl The compiler directly supports the desired source_version and
dnl target_version. Perfect.
- CONF_JAVAC="javac$source_option$target_option"
+ CONF_JAVAC="javac$nowarn_option$source_option$target_option"
HAVE_JAVAC=1
HAVE_JAVACOMP=1
else
else
target_option=' -target '`case "$try_target_version" in 6|7|8) echo 1. ;; esac`"$try_target_version"
fi
- if { echo "$as_me:__oline__: javac$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
- javac$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
+ if { echo "$as_me:__oline__: javac$nowarn_option$source_option$target_option -d . conftest.java" >&AS_MESSAGE_LOG_FD
+ javac$nowarn_option$source_option$target_option -d . conftest.java >&AS_MESSAGE_LOG_FD 2>&1
} \
&& test -f conftest.class; then
dnl The compiler supports the try_source_version and
dnl try_target_version. It's better than nothing.
- CONF_JAVAC="javac$source_option$target_option"
+ CONF_JAVAC="javac$nowarn_option$source_option$target_option"
HAVE_JAVAC=1
HAVE_JAVACOMP=1
break