From: Michael Pratt Date: Tue, 8 Oct 2024 10:55:47 +0000 (-0400) Subject: tools/automake: control all cleaning with clean variables X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d2bfe50d32bcaa53a1dd5012653661b29233dcc;p=thirdparty%2Fopenwrt.git tools/automake: control all cleaning with clean variables Automake previously makes rules for the target maintainer-clean to remove both the contents of MAINTAINERCLEANFILES and BUILT_SOURCES. In order to have finer control over what is removed, let there only be a rule for deleting MAINTAINERCLEANFILES, and set MAINTAINERCLEANFILES to a default value of BUILT_SOURCES if only conditional or missing, and append BUILT_SOURCES if user-defined. In order to maintain conditional values for MAINTAINERCLEANFILES while keeping a default value, change the behavior of automake to output unconditional definitions before conditions. Signed-off-by: Michael Pratt Link: https://github.com/openwrt/openwrt/pull/16522 Signed-off-by: Robert Marko --- diff --git a/tools/automake/patches/300-output-TRUE-cond-first.patch b/tools/automake/patches/300-output-TRUE-cond-first.patch new file mode 100644 index 00000000000..1bfc0203dd6 --- /dev/null +++ b/tools/automake/patches/300-output-TRUE-cond-first.patch @@ -0,0 +1,34 @@ +--- a/lib/Automake/Variable.pm ++++ b/lib/Automake/Variable.pm +@@ -1259,8 +1259,15 @@ sub output_variables () + foreach my $var (@vars) + { + my $v = rvar $var; ++ # Output unconditional definitions before conditional ones. ++ if ($v->def (TRUE)) { ++ $res .= $v->output (TRUE) ++ if $v->rdef (TRUE)->owner == VAR_AUTOMAKE; ++ } + foreach my $cond ($v->conditions->conds) + { ++ # TRUE is handled already. ++ next if $cond->string eq "TRUE"; + $res .= $v->output ($cond) + if $v->rdef ($cond)->owner == VAR_AUTOMAKE; + } +@@ -1270,8 +1277,15 @@ sub output_variables () + foreach my $var (@vars) + { + my $v = rvar $var; ++ # Output unconditional definitions before conditional ones. ++ if ($v->def (TRUE)) { ++ $res .= $v->output (TRUE) ++ if $v->rdef (TRUE)->owner != VAR_AUTOMAKE; ++ } + foreach my $cond ($v->conditions->conds) + { ++ # TRUE is handled already. ++ next if $cond->string eq "TRUE"; + $res .= $v->output ($cond) + if $v->rdef ($cond)->owner != VAR_AUTOMAKE; + } diff --git a/tools/automake/patches/310-maintainer-clean-built_sources.patch b/tools/automake/patches/310-maintainer-clean-built_sources.patch new file mode 100644 index 00000000000..5737a650238 --- /dev/null +++ b/tools/automake/patches/310-maintainer-clean-built_sources.patch @@ -0,0 +1,49 @@ +--- a/bin/automake.in ++++ b/bin/automake.in +@@ -4745,12 +4745,42 @@ sub handle_clean + if var ('CLEANFILES'); + $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN + if var ('DISTCLEANFILES'); +- $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN +- if var ('MAINTAINERCLEANFILES'); + + # Built sources are automatically removed by maintainer-clean. +- $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN +- if var ('BUILT_SOURCES'); ++ # For each defined condition of the maintainer-clean variable, append built sources ++ # and create an unconditional definition with built sources if not already defined. ++ # Then, for each definition of built sources without maintainer-clean defined, define it. ++ # Otherwise, if the variable is not user-defined, define it with built sources. ++ my $mcleanvar = var ('MAINTAINERCLEANFILES'); ++ if ($mcleanvar) { ++ foreach my $rcond ($mcleanvar->conditions->conds) ++ { ++ if (! grep { $_ eq '$(BUILT_SOURCES)' } $mcleanvar->value_as_list ($rcond)) { ++ Automake::Variable::define ($mcleanvar->name, VAR_MAKEFILE, '+', $rcond, ++ '$(BUILT_SOURCES)', '', INTERNAL, VAR_ASIS) ++ if vardef ('BUILT_SOURCES', $rcond); ++ } ++ } ++ my $bsources = var ('BUILT_SOURCES'); ++ if ($bsources) { ++ foreach my $rcond ($bsources->conditions->conds) ++ { ++ Automake::Variable::define ($mcleanvar->name, VAR_MAKEFILE, '', $rcond, ++ '$(BUILT_SOURCES)', '', INTERNAL, VAR_ASIS) ++ if ! vardef ($mcleanvar, $rcond); ++ } ++ if (! vardef ($mcleanvar, TRUE)) { ++ Automake::Variable::define ($mcleanvar->name, VAR_MAKEFILE, '', TRUE, ++ '$(BUILT_SOURCES)', '', INTERNAL, VAR_ASIS); ++ } ++ } ++ } else { ++ Automake::Variable::define ('MAINTAINERCLEANFILES', VAR_MAKEFILE, '', TRUE, ++ '$(BUILT_SOURCES)', '', INTERNAL, VAR_ASIS) ++ if var ('BUILT_SOURCES'); ++ } ++ $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN ++ if var ('MAINTAINERCLEANFILES'); + + # Compute a list of "rm"s to run for each target. + my %rms = (MOSTLY_CLEAN, [],