make: Target-specific
1
1 6.11 Target-specific Variable Values
1 ====================================
1
1 Variable values in 'make' are usually global; that is, they are the same
1 regardless of where they are evaluated (unless they're reset, of
11 course). One exception to that is automatic variables (⇒Automatic
Variables).
1
1 The other exception is "target-specific variable values". This
1 feature allows you to define different values for the same variable,
1 based on the target that 'make' is currently building. As with
1 automatic variables, these values are only available within the context
1 of a target's recipe (and in other target-specific assignments).
1
1 Set a target-specific variable value like this:
1
1 TARGET ... : VARIABLE-ASSIGNMENT
1
1 Target-specific variable assignments can be prefixed with any or all
1 of the special keywords 'export', 'override', or 'private'; these apply
1 their normal behavior to this instance of the variable only.
1
1 Multiple TARGET values create a target-specific variable value for
1 each member of the target list individually.
1
1 The VARIABLE-ASSIGNMENT can be any valid form of assignment;
1 recursive ('='), simple (':=' or '::='), appending ('+='), or
1 conditional ('?='). All variables that appear within the
1 VARIABLE-ASSIGNMENT are evaluated within the context of the target:
1 thus, any previously-defined target-specific variable values will be in
1 effect. Note that this variable is actually distinct from any "global"
1 value: the two variables do not have to have the same flavor (recursive
1 vs. simple).
1
1 Target-specific variables have the same priority as any other
1 makefile variable. Variables provided on the command line (and in the
1 environment if the '-e' option is in force) will take precedence.
1 Specifying the 'override' directive will allow the target-specific
1 variable value to be preferred.
1
1 There is one more special feature of target-specific variables: when
1 you define a target-specific variable that variable value is also in
1 effect for all prerequisites of this target, and all their
1 prerequisites, etc. (unless those prerequisites override that variable
1 with their own target-specific variable value). So, for example, a
1 statement like this:
1
1 prog : CFLAGS = -g
1 prog : prog.o foo.o bar.o
1
1 will set 'CFLAGS' to '-g' in the recipe for 'prog', but it will also set
1 'CFLAGS' to '-g' in the recipes that create 'prog.o', 'foo.o', and
1 'bar.o', and any recipes which create their prerequisites.
1
1 Be aware that a given prerequisite will only be built once per
1 invocation of make, at most. If the same file is a prerequisite of
1 multiple targets, and each of those targets has a different value for
1 the same target-specific variable, then the first target to be built
1 will cause that prerequisite to be built and the prerequisite will
1 inherit the target-specific value from the first target. It will ignore
1 the target-specific values from any other targets.
1