+2025-09-03 Bruno Haible <bruno@clisp.org>
+
+ gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS.
+ Reported by Pádraig Brady in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2025-09/msg00018.html>.
+ * gnulib-tool.sh (func_emit_tests_Makefile_am): Append the
+ warning-protection options to AM_CFLAGS and AM_CXXFLAGS, in addition to
+ initializing CFLAGS and CXXFLAGS.
+ * pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
+ * doc/gnulib-tool.texi (Modified build rules): Document the need to
+ initialize AM_CFLAGS and AM_CXXFLAGS in tests directories.
+ * NEWS: Mention the new requirement.
+
2025-09-03 Bruno Haible <bruno@clisp.org>
gnulib-tool: Improve C++ awareness of 2021-06-10 / 2024-03-06 commit.
Date Modules Changes
+2025-09-03 gnulib-tool If you use --makefile-name with --with-tests, you
+ now need to initialize AM_CFLAGS before the
+ 'include <gnulib-generated-makefile>' statement.
+
2022-07-24 bootstrap To specify a reference directory for the 'gnulib'
submodule, use the environment variable
GNULIB_REFDIR instead of GNULIB_SRCDIR or the
@smallexample
include Makefile.gnulib
@end smallexample
-Before this include, you need to initialize this set of @code{Makefile.am}
-variables:
+Before this include, you need to initialize a set of @code{Makefile.am}
+variables.
+
+For the directory into which @code{gnulib-tool} copies the gnulib source files,
+the set of variables to initialize is:
@itemize @bullet
@item
@code{AUTOMAKE_OPTIONS}
likely want to initialize some of them with non-empty values, in order
to achieve the desired customization.
+For the directory into which @code{gnulib-tool} copies
+the gnulib unit test files
+(when option @samp{--with-tests} is used),
+the set of variables to initialize is:
+@itemize @bullet
+@item
+@code{AM_CFLAGS}
+@item
+@code{AM_CXXFLAGS} (when this directory contains some C++ code)
+@end itemize
+
The other approach, the kitchen-sink module, is more advanced. See
chapter @ref{Extending Gnulib}.
# Enable or disable warnings as suitable for the Gnulib coding style.
cflags_for_gnulib_code=" \$(GL_CFLAG_GNULIB_WARNINGS)"
fi
+ # The primary place to add these options is AM_CFLAGS.
+ echo "AM_CFLAGS += @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code}"
+ if test -n "$uses_cxx"; then
+ echo "AM_CXXFLAGS += @GL_CXXFLAG_ALLOW_WARNINGS@"
+ fi
+ echo
+ # The secondary place to add these options is CFLAGS. This is less reliable,
+ # because the user can invoke e.g. "make CFLAGS=-O2"; see
+ # <https://www.gnu.org/software/automake/manual/html_node/User-Variables.html>
+ # But it is a protection against packages which do AM_CFLAGS += -Werror
+ # after including this generated Makefile (such as GNU grep).
echo "CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@${cflags_for_gnulib_code} @CFLAGS@"
if test -n "$uses_cxx"; then
echo "CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@"
if not for_test:
# Enable or disable warnings as suitable for the Gnulib coding style.
cflags_for_gnulib_code = ' $(GL_CFLAG_GNULIB_WARNINGS)'
+ # The primary place to add these options is AM_CFLAGS.
+ emit += 'AM_CFLAGS += @GL_CFLAG_ALLOW_WARNINGS@%s\n' % (cflags_for_gnulib_code)
+ if uses_cxx:
+ emit += 'AM_CXXFLAGS += @GL_CXXFLAG_ALLOW_WARNINGS@\n'
+ emit += '\n'
+ # The secondary place to add these options is CFLAGS. This is less reliable,
+ # because the user can invoke e.g. "make CFLAGS=-O2"; see
+ # <https://www.gnu.org/software/automake/manual/html_node/User-Variables.html>
+ # But it is a protection against packages which do AM_CFLAGS += -Werror
+ # after including this generated Makefile (such as GNU grep).
emit += 'CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@%s @CFLAGS@\n' % (cflags_for_gnulib_code)
if uses_cxx:
emit += 'CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@\n'