Roland Ver. 4.5 Technical Information Seite 79

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 212
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 78
Chapter 6: How to Use Variables 69
6.8 Defining Multi-Line Variables
Another way to set the value of a variable is to use the define directive. This directive
has an unusual syntax which allows newline characters to be included in the value, which
is convenient for defining both canned sequences of commands (see Section 5.8 [Defining
Canned Recipes], page 56), and also sections of makefile syntax to use with eval (see
Section 8.9 [Eval Function], page 93).
The define directive is followed on the same line by the name of the variable being
defined and an (optional) assignment operator, and nothing more. The value to give the
variable appears on the following lines. The end of the value is marked by a line containing
just the word endef. Aside from this difference in syntax, define works just like any other
variable definition. The variable name may contain function and variable references, which
are expanded when the directive is read to find the actual variable name to use.
You may omit the variable assignment operator if you prefer. If omitted, make assumes
it to be = and creates a recursively-expanded variable (see Section 6.2 [The Two Flavors
of Variables], page 60). When using a += operator, the value is appended to the previous
value as with any other append operation: with a single space separating the old and new
values.
You may nest define directives: make will keep track of nested directives and report
an error if they are not all properly closed with endef. Note that lines beginning with
the recipe prefix character are considered part of a recipe, so any define or endef strings
appearing on such a line will not be considered make directives.
define two-lines =
echo foo
echo $(bar)
endef
The value in an ordinary assignment cannot contain a newline; but the newlines that
separate the lines of the value in a define become part of the variable’s value (except for
the final newline which precedes the endef and is not considered part of the value).
When used in a recipe, the previous example is functionally equivalent to this:
two-lines = echo foo; echo $(bar)
since two commands separated by semicolon behave much like two separate shell commands.
However, note that using two separate lines means make will invoke the shell twice, running
an independent sub-shell for each line. See Section 5.3 [Recipe Execution], page 44.
If you want variable definitions made with define to take precedence over command-line
variable definitions, you can use the override directive together with define:
override define two-lines =
foo
$(bar)
endef
See Section 6.7 [The override Directive], page 68.
6.9 Undefining Variables
If you want to clear a variable, setting its value to empty is usually sufficient. Expanding
such a variable will yield the same result (empty string) regardless of whether it was set or
Seitenansicht 78
1 2 ... 74 75 76 77 78 79 80 81 82 83 84 ... 211 212

Kommentare zu diesen Handbüchern

Keine Kommentare