Variables

Table of Contents

Pass additional variables from command line howto

make target FOO=bar

An argument that contains = specifies the value of a variable: v=x sets the value of the variable v to x. If you specify a value in this way, all ordinary assignments of the same variable in the makefile are ignored; we say they have been overridden by the command line argument.

Automatic Variables($@, $<, etc…) reference

$@ The name of the target
$% The target member name (archive)
$< The name of the first prerequisite
$? The names of all the prerequisites that are newer than the target
$^ The names of all the prerequisites(deduplicated)
$+ The names of all the prerequisites
$| The names of all the order-only prerequisites
$* The stem with which an implicit rule matches

Tweak variables for a specific rule howto

%.o: %.c
    $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

%.o: CFLAGS := -g
lib/%.o: CFLAGS := -fPIC -g

all: foo.o lib/bar.o