Roland Ver. 4.5 Technical Information Seite 70

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 212
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 69
60 GNU make
could be used to compile a C program prog.c. Since spaces before the variable value are
ignored in variable assignments, the value of foo is precisely c’. (Don’t actually write your
makefiles this way!)
A dollar sign followed by a character other than a dollar sign, open-parenthesis or open-
brace treats that single character as the variable name. Thus, you could reference the
variable x with $x’. However, this practice is strongly discouraged, except in the case of
the automatic variables (see Section 10.5.3 [Automatic Variables], page 120).
6.2 The Two Flavors of Variables
There are two ways that a variable in GNU make can have a value; we call them the two
flavors of variables. The two flavors are distinguished in how they are defined and in what
they do when expanded.
The first flavor of variable is a recursively expanded variable. Variables of this sort are
defined by lines using = (see Section 6.5 [Setting Variables], page 65) or by the define
directive (see Section 6.8 [Defining Multi-Line Variables], page 69). The value you specify is
installed verbatim; if it contains references to other variables, these references are expanded
whenever this variable is substituted (in the course of expanding some other string). When
this happens, it is called recursive expansion.
For example,
foo = $(bar)
bar = $(ugh)
ugh = Huh?
all:;echo $(foo)
will echo Huh?’: $(foo) expands to $(bar) which expands to $(ugh) which finally
expands to Huh?’.
This flavor of variable is the only sort supported by most other versions of make. It has
its advantages and its disadvantages. An advantage (most would say) is that:
CFLAGS = $(include_dirs) -O
include_dirs = -Ifoo -Ibar
will do what was intended: when CFLAGS is expanded in a recipe, it will expand to -Ifoo
-Ibar -O’. A major disadvantage is that you cannot append something on the end of a
variable, as in
CFLAGS = $(CFLAGS) -O
because it will cause an infinite loop in the variable expansion. (Actually make detects the
infinite loop and reports an error.)
Another disadvantage is that any functions (see Chapter 8 [Functions for Transforming
Text], page 83) referenced in the definition will be executed every time the variable is
expanded. This makes make run slower; worse, it causes the wildcard and shell functions
to give unpredictable results because you cannot easily control when they are called, or
even how many times.
To avoid all the problems and inconveniences of recursively expanded variables, there is
another flavor: simply expanded variables.
Seitenansicht 69
1 2 ... 65 66 67 68 69 70 71 72 73 74 75 ... 211 212

Kommentare zu diesen Handbüchern

Keine Kommentare