Dear Recipients, bug#79049 has been fixed. The change will be pushed to Savannah shortly. The patch is attached to this e-mail. Thank you for reporting.
-- With Valediction, Kamila Szewczyk (https://iczelia.net)
From 0a6db44b332854c6e6aedddb1cd4387ff986e62f Mon Sep 17 00:00:00 2001 From: Kamila Szewczyk <[email protected]> Date: Mon, 24 Aug 2026 09:28:32 +0200 Subject: [PATCH] dist: fix automake bug #79049. From https://bugs.gnu.org/79049 (Tomas Volf). Resolved the issue where a rule to generate ChangeLog inside a conditional, resulted in the file being always added to am__DIST_COMMON, even when the conditional is false. This lead to a failure to build the tarball, since the ChangeLog file nor the rule to build it exist. While it is admittedly true that automake can not know the This patch fixes the issue by having Automake emit conditional Makefile text via Automake::DisjConditions, resulting in something akin to: @GEN_AUTH_TRUE@am__DIST_COMMON_1 = AUTHORS @GEN_CL_TRUE@am__DIST_COMMON_2 = ChangeLog NEWS am__DIST_COMMON = $(srcdir)/Makefile.in install-sh missing \ $(am__DIST_COMMON_1) $(am__DIST_COMMON_2) A regression test has been added alongside the change. * bin/automake.in: Conditionally emit of Makefile text per the surrounding conditions in the automake file. * doc/automake.texi: Briefly (two sentences) explain this behaviour. * NEWS: Update to mention the patch. * t/autodist-conditional-rule.sh: Add a regression test. * t/list-of-tests.mk: Register the test above. --- NEWS | 7 +++- bin/automake.in | 74 ++++++++++++++++++++++++++++++---- doc/automake.texi | 5 +++ t/autodist-conditional-rule.sh | 57 ++++++++++++++++++++++++++ t/list-of-tests.mk | 1 + 5 files changed, 135 insertions(+), 9 deletions(-) create mode 100755 t/autodist-conditional-rule.sh diff --git a/NEWS b/NEWS index 3a401a373..2beaecb35 100644 --- a/NEWS +++ b/NEWS @@ -28,7 +28,12 @@ New in 1.18.2 (????-??-??): - The manual no longer presents 99 characters as the portable limit for file names in any archive format: it is the limit of the v7 format, whereas ustar, the default since Automake 1.18, stores - longer names. (bug#81557) + longer names. (bug#81557) + + - A file that is not currently present is still a part of the distribution + if a @file{Makefile.am} rule can build it. When that rule is inside + an Automake conditional, the file is distributed only when the + condition is true. (bug#79049) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New in 1.18.1 (2025-06-25): diff --git a/bin/automake.in b/bin/automake.in index 1035dae62..1f0f3b100 100644 --- a/bin/automake.in +++ b/bin/automake.in @@ -552,6 +552,10 @@ my %lang_specific_files; # List of distributed files to be put in DIST_COMMON. my @dist_common; +# List of files to be put in DIST_COMMON only under some conditions, +# as [$DISJCONDITIONS, $FILE] pairs. +my @dist_common_cond; + # This is set when 'handle_dist' has finished. Once this happens, # we should no longer push on dist_common. my $handle_dist_run; @@ -650,6 +654,7 @@ sub initialize_per_input () @dist_targets = (); @dist_common = (); + @dist_common_cond = (); $handle_dist_run = 0; @proglist = (); @@ -3893,20 +3898,29 @@ sub handle_dist () } foreach my $cfile (@toplevelmd_ok, @common_files) { - if (dir_has_case_matching_file ($relative_dir, $cfile) - # The file might be absent, but if it can be built it's ok. - || rule $cfile) + if (dir_has_case_matching_file ($relative_dir, $cfile)) { push_dist_common ($cfile); } + # The file might be absent, but if it can be built it's ok. Only + # put it in the dist tarball it in the conditions where its rule is + # defined, otherwise 'make dist' could require a file that cannot be + # built (bug#79049). + elsif (my $crule = rule $cfile) + { + push_dist_common_cond ($crule->conditions, $cfile); + } elsif (grep { $_ eq $cfile } @toplevelmd_ok) { # Irritatingly, have to repeat the checks, now for .md files; # we want to prefer non-.md, so do this second, and only "elsif". - if (dir_has_case_matching_file ($relative_dir, "$cfile.md") - || rule "$cfile.md") + if (dir_has_case_matching_file ($relative_dir, "$cfile.md")) { push_dist_common ("$cfile.md"); } + elsif (my $mdrule = rule "$cfile.md") + { + push_dist_common_cond ($mdrule->conditions, "$cfile.md"); + } } # Don't use 'elsif' here because a file might meaningfully @@ -3917,11 +3931,14 @@ sub handle_dist () } elsif ($check_aux && grep { $_ eq $cfile } @toplevelmd_ok) { - if (dir_has_case_matching_file ($config_aux_dir, "$cfile.md") - || rule "$cfile.md") + if (dir_has_case_matching_file ($config_aux_dir, "$cfile.md")) { push_dist_common ("$cfile.md"); } + elsif (my $mdrule = rule "$cfile.md") + { + push_dist_common_cond ($mdrule->conditions, "$cfile.md"); + } } } @@ -3947,13 +3964,38 @@ sub handle_dist () @configure_dist_common = (); } + # Files conditionally distributed are gathered into per-condition helper + # variables, so that they do not become prerequisites of 'distdir' in + # the conditions where their rule does not exist (see bug#79049). + my @cond_common; + my %cond_files; + foreach my $pair (@dist_common_cond) + { + my ($conds, $file) = @$pair; + push @{$cond_files{$conds->string}}, $file; + } + my $helper_count = 0; + foreach my $pair (@dist_common_cond) + { + my ($conds) = @$pair; + my $files = delete $cond_files{$conds->string}; + next unless defined $files; + my $helper = 'am__DIST_COMMON_' . ++$helper_count; + foreach my $cond ($conds->conds) + { + define_pretty_variable ($helper, $cond, INTERNAL, + uniq (sort @$files)); + } + push @cond_common, "\$($helper)"; + } + # $(am__DIST_COMMON): files to be distributed automatically. Will be # appended to $(DIST_COMMON) in the generated Makefile. # Use 'sort' so that the expansion of $(DIST_COMMON) in the generated # Makefile is deterministic, in face of m4 and/or perl randomizations # (see automake bug#17908). define_pretty_variable ('am__DIST_COMMON', TRUE, INTERNAL, - uniq (sort @dist_common)); + uniq (sort @dist_common), @cond_common); # Now that we've processed @dist_common, disallow further attempts # to modify it. @@ -7993,6 +8035,22 @@ sub push_dist_common push @dist_common, @_; } +# push_dist_common_cond ($CONDS, @FILES) +# -------------------------------------- +# Like 'push_dist_common', but distribute @FILES only in the conditions +# described by the Automake::DisjConditions $CONDS. +sub push_dist_common_cond +{ + my ($conds, @files) = @_; + prog_error "push_dist_common_cond run after handle_dist" + if $handle_dist_run; + # Short circuit if always true. + return push_dist_common (@files) + if $conds->true; + push @dist_common_cond, [$conds, $_] + foreach @files; +} + ################################################################ diff --git a/doc/automake.texi b/doc/automake.texi index c81b0897f..6bdbd6003 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -8979,6 +8979,11 @@ if they are found either with the plain name, or with extension checked for in that order, so the plain name is preferred. These are: @file{AUTHORS ChangeLog INSTALL NEWS README README-alpha THANKS}. +For both these lists, a file that is not currently present is still +a part of the distribution if a @file{Makefile.am} rule can build +it. When that rule is inside an Automake conditional, the file is +distributed only when the condition is true. + @item A final built-in list of files are those distributed only if other certain conditions hold. For example, diff --git a/t/autodist-conditional-rule.sh b/t/autodist-conditional-rule.sh new file mode 100755 index 000000000..cc5498a9e --- /dev/null +++ b/t/autodist-conditional-rule.sh @@ -0,0 +1,57 @@ +#! /bin/sh +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Regression test for bug#79049: unconditional inclusion of ChangeLog in +# distribution when its rule is guarded by a conditional. + +. test-init.sh + +cat > configure.ac << 'END' +AC_INIT([foobar], [1.0]) +AM_INIT_AUTOMAKE([foreign]) +AM_CONDITIONAL([GEN_CL], [test x"$want_changelog" = xyes]) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +if GEN_CL +ChangeLog: + echo generated > $@ +endif +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +# ChangeLog is only distributed under the condition guarding its rule. +grep '^@GEN_CL_TRUE@am__DIST_COMMON.*= *ChangeLog$' Makefile.in +grep '^am__DIST_COMMON.*ChangeLog' Makefile.in && exit 1 + +# With the condition false, ChangeLog is neither required nor distributed. +./configure +$MAKE dist +$MAKE distdir +test ! -f foo-1.0/ChangeLog + +# With the condition true, ChangeLog is built and distributed. +./configure want_changelog=yes +$MAKE distdir +test -f foo-1.0/ChangeLog +grep generated foo-1.0/ChangeLog + +: diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index e56d257bc..90c2aa256 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -174,6 +174,7 @@ t/asm3.sh \ t/autodist-acconfig-no-subdir.sh \ t/autodist-acconfig.sh \ t/autodist-aclocal-m4.sh \ +t/autodist-conditional-rule.sh \ t/autodist-config-headers.sh \ t/autodist-configure-no-subdir.sh \ t/autodist-no-duplicate.sh \ -- 2.53.0
OpenPGP_0xC868F0B6DE38409D.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature
