Roland Ver. 4.5 Technical Information Seite 97

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 212
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 96
Chapter 8: Functions for Transforming Text 87
produces the result bar’. Although $(lastword text) is the same as $(word
$(words text),text), the lastword function was added for its simplicity and
better performance.
Here is a realistic example of the use of subst and patsubst. Suppose that a makefile
uses the VPATH variable to specify a list of directories that make should search for prerequisite
files (see Section 4.4.1 [VPATH Search Path for All Prerequisites], page 25). This example
shows how to tell the C compiler to search for header files in the same list of directories.
The value of VPATH is a list of directories separated by colons, such as ‘src:../headers’.
First, the subst function is used to change the colons to spaces:
$(subst :, ,$(VPATH))
This produces src ../headers’. Then patsubst is used to turn each directory name
into a -I flag. These can be added to the value of the variable CFLAGS, which is passed
automatically to the C compiler, like this:
override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
The effect is to append the text -Isrc -I../headers to the previously given value of
CFLAGS. The override directive is used so that the new value is assigned even if the
previous value of CFLAGS was specified with a command argument (see
Section 6.7 [The
override Directive], page 68).
8.3 Functions for File Names
Several of the built-in expansion functions relate specifically to taking apart file names or
lists of file names.
Each of the following functions performs a specific transformation on a file name. The
argument of the function is regarded as a series of file names, separated by whitespace.
(Leading and trailing whitespace is ignored.) Each file name in the series is transformed in
the same way and the results are concatenated with single spaces between them.
$(dir names...)
Extracts the directory-part of each file name in names. The directory-part of
the file name is everything up through (and including) the last slash in it. If the
file name contains no slash, the directory part is the string ./’. For example,
$(dir src/foo.c hacks)
produces the result src/ ./’.
$(notdir names...)
Extracts all but the directory-part of each file name in names. If the file name
contains no slash, it is left unchanged. Otherwise, everything through the last
slash is removed from it.
A file name that ends with a slash becomes an empty string. This is unfortunate,
because it means that the result does not always have the same number of
whitespace-separated file names as the argument had; but we do not see any
other valid alternative.
For example,
$(notdir src/foo.c hacks)
produces the result foo.c hacks’.
Seitenansicht 96
1 2 ... 92 93 94 95 96 97 98 99 100 101 102 ... 211 212

Kommentare zu diesen Handbüchern

Keine Kommentare