From: Bruno Haible Date: Wed, 3 Sep 2025 22:15:19 +0000 (+0200) Subject: gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fd6098f510255c0b9134088b1526a50fef90edd;p=thirdparty%2Fgnulib.git gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS. Reported by Pádraig Brady in . * 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. --- diff --git a/ChangeLog b/ChangeLog index 7d7c44aea5..956c4ab407 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2025-09-03 Bruno Haible + + gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS. + Reported by Pádraig Brady in + . + * 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 gnulib-tool: Improve C++ awareness of 2021-06-10 / 2024-03-06 commit. diff --git a/NEWS b/NEWS index 664007395d..de89ddb78c 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ Important general notes 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 ' 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 diff --git a/doc/gnulib-tool.texi b/doc/gnulib-tool.texi index 2ee6fd83de..e9ee83703c 100644 --- a/doc/gnulib-tool.texi +++ b/doc/gnulib-tool.texi @@ -747,8 +747,11 @@ through a line such as @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} @@ -789,6 +792,17 @@ The other variables can be initialized to empty. However, you will most 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}. diff --git a/gnulib-tool.sh b/gnulib-tool.sh index e3a9b92de6..2e9e70036c 100755 --- a/gnulib-tool.sh +++ b/gnulib-tool.sh @@ -4459,6 +4459,17 @@ func_emit_tests_Makefile_am () # 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 + # + # 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@" diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 9d02210518..4abbacb710 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -1242,6 +1242,16 @@ AC_DEFUN([%V1%_LIBSOURCES], [ 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 + # + # 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'