diff options
author | Paul Smith <psmith@gnu.org> | 1999-09-01 08:04:30 +0000 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 1999-09-01 08:04:30 +0000 |
commit | 82f0c5495afcf82b7cf82cbd69fa2f8f63c6b241 (patch) | |
tree | 073feec66d6452570d4e4802b194ad803a5b1976 /make.texinfo | |
parent | bf7cc546ddd268583b2dfcfb96631b20836e9b7e (diff) | |
download | gunmake-82f0c5495afcf82b7cf82cbd69fa2f8f63c6b241.tar.gz |
* A bugfix on MAKEFLAGS options creation that broke jobserver.
* Put the host info in the --version output.
* Don't croak if the user forces -jN on submakes.
Diffstat (limited to 'make.texinfo')
-rw-r--r-- | make.texinfo | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/make.texinfo b/make.texinfo index 8b6778e..7605994 100644 --- a/make.texinfo +++ b/make.texinfo @@ -2183,6 +2183,56 @@ clean: @end group @end example +Another example of the usefulness of phony targets is in conjunction +with recursive invocations of @code{make}. In this case the makefile +will often contain a variable which lists a number of subdirectories to +be built. One way to handle this is with one rule whose command is a +shell loop over the subdirectories, like this: + +@example +@group +SUBDIRS = foo bar baz + +subdirs: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir; \ + done +@end group +@end example + +There are a few of problems with this method, however. First, any error +detected in a submake is not noted by this rule, so it will continue to +build the rest of the directories even when one fails. This can be +overcome by adding shell commands to note the error and exit, but then +it will do so even if @code{make} is invoked with the @code{-k} option, +which is unfortunate. Second, and perhaps more importantly, you cannot +take advantage of the parallel build capabilities of make using this +method, since there is only one rule. + +By declaring the subdirectories as phony targets (you must do this as +the subdirectory obviously always exists; otherwise it won't be built) +you can remove these problems: + +@example +@group +SUBDIRS = foo bar baz + +.PHONY: subdirs $(SUBDIRS) + +subdirs: $(SUBDIRS) + +$(SUBDIRS): + $(MAKE) -C $@ + +foo: baz +@end group +@end example + +Here we've also declared that the @file{foo} subdirectory cannot be +built until after the @file{baz} subdirectory is complete; this kind of +relationship declaration is particularly important when attempting +parallel builds. + A phony target should not be a prerequisite of a real target file; if it is, its commands are run every time @code{make} goes to update that file. As long as a phony target is never a prerequisite of a real |