Using macros in a description file
After defining a macro in a description file, use the macro in description file commands by putting a $ (dollar sign) before the name of the macro.
If the macro name is longer than one character, put ( ) (parentheses) or { } (braces) around the macro name. The following are examples of using macros:
$(CFLAGS)
$2
$(xy)
$Z
$(Z)The last two examples in the previous list have the same effect.
The following fragment shows how to define and use some macros:
# OBJECTS is the 3 files x.o, y.o and
# z.o (previously compiled)
OBJECTS = x.o y.o z.o
# LIBES is the standard library
LIBES = -lc
# prog depends on x.o y.o and z.o
prog: $(OBJECTS)
# Link and load the 3 files with
# the standard library to make prog
cc $(OBJECTS) $(LIBES) -o progThe make command that uses this description file links and loads the three object files (x.o, y.o, and z.o) with the libc.a library.
A macro definition entered on the command line overrides any duplicate macro definitions in the description file. Therefore, the following command loads the files with the lex (-11) library:
make "LIBES= -ll"Note: When macros contain blanks and you enter them, on the command line, put " " (double quotation marks) around the macro. Without the double quotation marks, the shell interprets the blanks as parameter separators and not as part of the macro.
The make command handles up to 10 levels of nested macro expansion. Based on the definitions in the following example, the expression $($(macro2)) would evaluate to value1:
macro1=value1 macro2=macro1The evaluation of a macro occurs each time the macro is referenced. It is not evaluated when it is defined. If a macro is defined but never used, it will never be evaluated. This is especially important if the macro is assigned values that will be interpreted by the shell, particularly if the value might change. A variable declaration such as:
OBJS = 'ls *.o'could change in value if referenced at different times during the process of building or removing object files. It does not hold the value of the ls command at the time the OBJS macro is defined.