Roland Ver. 4.5 Technical Information Seite 39

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 212
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 38
Chapter 4: Writing Rules 29
a pattern string. When a prerequisite like -lname is seen, make will replace the percent
in each pattern in the list with name and perform the above directory searches using each
library file name.
The default value for .LIBPATTERNS is lib%.so lib%.a’, which provides the default
behavior described above.
You can turn off link library expansion completely by setting this variable to an empty
value.
4.5 Phony Targets
A phony target is one that is not really the name of a file; rather it is just a name for a
recipe to be executed when you make an explicit request. There are two reasons to use a
phony target: to avoid a conflict with a file of the same name, and to improve performance.
If you write a rule whose recipe will not create the target file, the recipe will be executed
every time the target comes up for remaking. Here is an example:
clean:
rm *.o temp
Because the rm command does not create a file named clean, probably no such file will
ever exist. Therefore, the rm command will be executed every time you say make clean’.
In this example, the clean target will not work properly if a file named clean is ever
created in this directory. Since it has no prerequisites, clean would always be considered
up to date and its recipe would not be executed. To avoid this problem you can explicitly
declare the target to be phony by making it a prerequisite of the special target .PHONY (see
Section 4.8 [Special Built-in Target Names], page 32) as follows:
.PHONY: clean
clean:
rm *.o temp
Once this is done, make clean will run the recipe regardless of whether there is a file
named clean.
Phony targets are also useful in conjunction with recursive invocations of make (see
Section 5.7 [Recursive Use of make], page 50). In this situation the makefile will often
contain a variable which lists a number of sub-directories to be built. A simplistic way to
handle this is to define one rule with a recipe that loops over the sub-directories, like this:
SUBDIRS = foo bar baz
subdirs:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done
There are problems with this method, however. First, any error detected in a sub-make
is ignored 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 make is invoked with the -k option, which is unfortunate. Second, and
perhaps more importantly, you cannot take advantage of make’s ability to build targets in
parallel (see Section 5.4 [Parallel Execution], page 47), since there is only one rule.
Seitenansicht 38
1 2 ... 34 35 36 37 38 39 40 41 42 43 44 ... 211 212

Kommentare zu diesen Handbüchern

Keine Kommentare