Roland Ver. 4.5 Technical Information Seite 69

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 212
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 68
Chapter 6: How to Use Variables 59
6 How to Use Variables
A variable is a name defined in a makefile to represent a string of text, called the variable’s
value. These values are substituted by explicit request into targets, prerequisites, recipes,
and other parts of the makefile. (In some other versions of make, variables are called macros.)
Variables and functions in all parts of a makefile are expanded when read, except for
in recipes, the right-hand sides of variable definitions using =’, and the bodies of variable
definitions using the define directive.
Variables can represent lists of file names, options to pass to compilers, programs to run,
directories to look in for source files, directories to write output in, or anything else you can
imagine.
A variable name may be any sequence of characters not containing ‘:’, #’, =’, or white-
space. However, variable names containing characters other than letters, numbers, and
underscores should be considered carefully, as in some shells they cannot be passed through
the environment to a sub-make (see Section 5.7.2 [Communicating Variables to a Sub-make],
page 52). Variable names beginning with . and an uppercase letter may be given special
meaning in future versions of make.
Variable names are case-sensitive. The names foo’, FOO’, and ‘Foo all refer to different
variables.
It is traditional to use upper case letters in variable names, but we recommend using lower
case letters for variable names that serve internal purposes in the makefile, and reserving
upper case for parameters that control implicit rules or for parameters that the user should
override with command options (see Section 9.5 [Overriding Variables], page 103).
A few variables have names that are a single punctuation character or just a few char-
acters. These are the automatic variables, and they have particular specialized uses. See
Section 10.5.3 [Automatic Variables], page 120.
6.1 Basics of Variable References
To substitute a variable’s value, write a dollar sign followed by the name of the variable in
parentheses or braces: either $(foo) or ${foo} is a valid reference to the variable foo.
This special significance of $ is why you must write ‘$$’ to have the effect of a single dollar
sign in a file name or recipe.
Variable references can be used in any context: targets, prerequisites, recipes, most
directives, and new variable values. Here is an example of a common case, where a variable
holds the names of all the object files in a program:
objects = program.o foo.o utils.o
program : $(objects)
cc -o program $(objects)
$(objects) : defs.h
Variable references work by strict textual substitution. Thus, the rule
foo = c
prog.o : prog.$(foo)
$(foo)$(foo) -$(foo) prog.$(foo)
Seitenansicht 68
1 2 ... 64 65 66 67 68 69 70 71 72 73 74 ... 211 212

Kommentare zu diesen Handbüchern

Keine Kommentare