[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: machinery to add files to *clean-generic
From: |
Alexandre Duret-Lutz |
Subject: |
FYI: machinery to add files to *clean-generic |
Date: |
24 Aug 2002 22:32:53 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
For PR/343 (building Texinfo files in subdirectories) I need to use
the &require_build_directory function. This functions creates a rule
to build a directory and its associated .dirstamp, and add .dirstamp
to %compile_clean_files so it gets automatically deleted.
This sucks, because .dirstamp then gets cleaned by
distclean-compile, a rule which is emitted only if the current
directory contains something to compile (not something frequent
in a doc/ directory).
Obvisously &require_build_directory shouldn't register .dirstamp
for distclean-compile; using distclean-generic would be more useful.
(Or distclean-dirstamp, but why invent new targets?)
However there no easy way for &require_build_directory to add
something to distclean-generic. The choice is limited to
@maintainer_clean_files or %compile_clean_files.
I'm installing the following patch which add support for
%clean_files. This works like %compile_clean_files, but keys
are erased by the *clean-generic targets. This also supersedes
@maintainer_clean_files. Of course, as far PR/343 is concerned
the most important change is that &require_build_directory now
uses %clean_files instead of %compile_clean_files.
There is something I was tempted to do but I didn't dared to.
It's to remove %compile_clean_files entirely and use
%clean_files instead. This means merging the *clean-compile
targets into the *clean-generic targets. I guess the same can
be done with other targets like distclean-hdr. Internally this
will simplify things, since we'll have a single mecanism to
clean files; however this will remove targets that people might
be dependent upon (is there really people using targets like
mostlyclean-compile?).
What do you think?
2002-08-24 Alexandre Duret-Lutz <address@hidden>
* automake.in (CLEAN, MAINTAINER_CLEAN): New constants.
(maintainer_clean_files): Replace by ...
(clean_files): ... this new variable.
(initialize_per_input, lang_yacc_target_hook,
lang_lex_target_hook): Use %clean_files instead of
@maintainer_clean_files.
(handle_clean): Rewrite, using %clean_files.
(require_build_directory_maybe): Use %clean_files instead
of %compile_clean_files. This allows using
&require_build_directory_maybe for non-compiling targets.
* lib/am/clean.am (mostlyclean-generic, clean-generic,
distclean-generic, maintainer-clean-generic): Rewrite using
%MOSTLYCLEAN_RMS%, %CLEAN_RMS%, %DISTCLEAN_RMS%, and
%MAINTAINER_CLEAN_RMS%.
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1342
diff -u -r1.1342 automake.in
--- automake.in 23 Aug 2002 13:32:55 -0000 1.1342
+++ automake.in 24 Aug 2002 19:58:49 -0000
@@ -193,11 +193,11 @@
use constant AC_CANONICAL_HOST => 1;
use constant AC_CANONICAL_SYSTEM => 2;
-# Values indicating when something should be cleaned. Right now we
-# only need to handle `mostly'- and `dist'-clean; add more as
-# required.
-use constant MOSTLY_CLEAN => 0;
-use constant DIST_CLEAN => 1;
+# Values indicating when something should be cleaned.
+use constant MOSTLY_CLEAN => 0;
+use constant CLEAN => 1;
+use constant DIST_CLEAN => 2;
+use constant MAINTAINER_CLEAN => 3;
# Libtool files.
my @libtool_files = qw(ltmain.sh config.guess config.sub);
@@ -550,8 +550,9 @@
# only when keys exists in %DEPENDENCIES.
my %actions;
-# A list of files deleted by `maintainer-clean'.
-my @maintainer_clean_files;
+# Keys in this hash table are files to delete. The associated
+# value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
+my %clean_files;
# Keys in this hash table are object files or other files in
# subdirectories which need to be removed. This only holds files
@@ -777,7 +778,7 @@
);
%actions = ();
- @maintainer_clean_files = ();
+ %clean_files = ();
@sources = ();
@dist_sources = ();
@@ -4714,30 +4715,46 @@
# Handle all 'clean' targets.
sub handle_clean
{
- my %transform;
-
- # Don't include `MAINTAINER'; it is handled specially below.
- foreach my $name ('MOSTLY', '', 'DIST')
- {
- $transform{"${name}CLEAN"} = variable_defined ("${name}CLEANFILES");
- }
-
- # Built sources are automatically removed by maintainer-clean.
- push (@maintainer_clean_files, '$(BUILT_SOURCES)')
- if variable_defined ('BUILT_SOURCES');
- push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
- if variable_defined ('MAINTAINERCLEANFILES');
-
- $output_rules .= &file_contents ('clean',
- (%transform,
- 'MCFILES'
- # Join with no space to avoid
- # spurious `test -z' success at
- # runtime.
- => join ('', @maintainer_clean_files),
- 'MFILES'
- # A space is required in the join here.
- => "@maintainer_clean_files"));
+ # Clean the files listed in user variables if they exist.
+ $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
+ if variable_defined ('MOSTLYCLEANFILES');
+ $clean_files{'$(CLEANFILES)'} = CLEAN
+ if variable_defined ('CLEANFILES');
+ $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
+ if variable_defined ('DISTCLEANFILES');
+ $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
+ if variable_defined ('MAINTAINERCLEANFILES');
+
+ # Built sources are automatically removed by maintainer-clean.
+ $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
+ if variable_defined ('BUILT_SOURCES');
+
+ # Compute a list of "rm"s to run for each target.
+ my %rms = (MOSTLY_CLEAN, [],
+ CLEAN, [],
+ DIST_CLEAN, [],
+ MAINTAINER_CLEAN, []);
+
+ foreach my $file (keys %clean_files)
+ {
+ my $when = $clean_files{$file};
+ prog_error 'invalid entry in %clean_files'
+ unless exists $rms{$when};
+
+ my $rm = "rm -f $file";
+ # If file is a variable, make sure when don't call `rm -f' without args.
+ $rm ="test -z \"$file\" || $rm"
+ if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
+
+ push @{$rms{$when}}, "\t-$rm\n";
+ }
+
+ $output_rules .= &file_contents
+ ('clean',
+ MOSTLYCLEAN_RMS => join ('', @{$rms{&MOSTLY_CLEAN}}),
+ CLEAN_RMS => join ('', @{$rms{&CLEAN}}),
+ DISTCLEAN_RMS => join ('', @{$rms{&DIST_CLEAN}}),
+ MAINTAINER_CLEAN_RMS => join ('', @{$rms{&MAINTAINER_CLEAN}}));
}
@@ -5497,11 +5514,11 @@
# statically, and the GNU rules say that yacc/lex output files
# should be removed by maintainer-clean. So that's what we
# do.
- push (@maintainer_clean_files, $header);
+ $clean_files{$header} = MAINTAINER_CLEAN;
}
# Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
# See the comment above for $HEADER.
- push (@maintainer_clean_files, $output);
+ $clean_files{$output} = MAINTAINER_CLEAN;
}
# This is a lex helper which is called whenever we have decided to
@@ -5514,7 +5531,7 @@
# shouldn't be touched. However, we can't determine this
# statically, and the GNU rules say that yacc/lex output files
# should be removed by maintainer-clean. So that's what we do.
- push (@maintainer_clean_files, $output);
+ $clean_files{$output} = MAINTAINER_CLEAN;
}
# This is a helper for both lex and yacc.
@@ -8613,7 +8630,7 @@
$directory_map{$directory} = 1;
# Directory must be removed by `make distclean'.
- $compile_clean_files{$dirstamp} = DIST_CLEAN;
+ $clean_files{$dirstamp} = DIST_CLEAN;
$output_rules .= ("$dirstamp:\n"
. "address@hidden(mkinstalldirs) $directory\n"
Index: lib/am/clean.am
===================================================================
RCS file: /cvs/automake/automake/lib/am/clean.am,v
retrieving revision 1.41
diff -u -r1.41 clean.am
--- lib/am/clean.am 6 May 2002 19:10:40 -0000 1.41
+++ lib/am/clean.am 24 Aug 2002 19:58:51 -0000
@@ -21,16 +21,16 @@
## return an error if there are no arguments other than "-f".
mostlyclean-am: mostlyclean-generic
mostlyclean-generic:
-?MOSTLYCLEAN? -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
+%MOSTLYCLEAN_RMS%
clean-am: clean-generic mostlyclean-am
clean-generic:
-?CLEAN? -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+%CLEAN_RMS%
distclean-am: distclean-generic clean-am
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-?DISTCLEAN? -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+%DISTCLEAN_RMS%
maintainer-clean-am: maintainer-clean-generic distclean-am
maintainer-clean-generic:
@@ -38,7 +38,7 @@
## the dependencies?
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
-?MFILES? -test -z "%MCFILES%" || rm -f %MFILES%
+%MAINTAINER_CLEAN_RMS%
.PHONY: clean mostlyclean distclean maintainer-clean \
clean-generic mostlyclean-generic distclean-generic maintainer-clean-generic
--
Alexandre Duret-Lutz
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: machinery to add files to *clean-generic,
Alexandre Duret-Lutz <=