1 # Generic Makefile Utilities
6 # Function: streq LHS RHS
8 # Return "true" if LHS == RHS, otherwise "".
10 # LHS == RHS <=> (LHS subst RHS is empty) and (RHS subst LHS is empty)
11 streq
= $(if
$(1),$(if
$(subst $(1),,$(2))$(subst $(2),,$(1)),,true
),$(if
$(2),,true
))
13 # Function: strneq LHS RHS
15 # Return "true" if LHS != RHS, otherwise "".
16 strneq
= $(if
$(call streq
,$(1),$(2)),,true
)
18 # Function: contains list item
20 # Return "true" if 'list' contains the value 'item'.
21 contains
= $(if
$(strip $(foreach i
,$(1),$(if
$(call streq
,$(2),$(i
)),T
,))),true
,)
23 # Function: is_subset a b
24 # Return "true" if 'a' is a subset of 'b'.
25 is_subset
= $(if
$(strip $(set_difference
$(1),$(2))),,true
)
27 # Function: set_difference a b
29 set_difference
= $(foreach i
,$(1),$(if
$(call contains
,$(2),$(i
)),,$(i
)))
31 # Function: Set variable value
33 # Set the given make variable to the given value.
34 Set
= $(eval
$(1) := $(2))
36 # Function: Append variable value
38 # Append the given value to the given make variable.
39 Append
= $(eval
$(1) += $(2))
41 # Function: IsDefined variable
43 # Check whether the given variable is defined.
44 IsDefined
= $(call strneq
,undefined
,$(flavor
$(1)))
46 # Function: IsUndefined variable
48 # Check whether the given variable is undefined.
49 IsUndefined
= $(call streq
,undefined
,$(flavor
$(1)))
51 # Function: VarOrDefault variable default-value
53 # Get the value of the given make variable, or the default-value if the variable
55 VarOrDefault
= $(if
$(call IsDefined
,$(1)),$($(1)),$(2))
57 # Function: CheckValue variable
59 # Print the name, definition, and value of a variable, for testing make
63 # foo = $(call streq,a,a)
64 # $(call CheckValue,foo)
66 # CHECKVALUE: foo: $(call streq,,) - true
67 CheckValue
= $(info CHECKVALUE
: $(1): $(value
$(1)) - $($(1)))
69 # Function: CopyVariable src dst
71 # Copy the value of the variable 'src' to 'dst', taking care to not define 'dst'
72 # if 'src' is undefined. The destination variable must be undefined.
74 $(call AssertValue
,$(call IsUndefined
,$(2)),destination is already defined
)\
75 $(if
$(call IsUndefined
,$(1)),,\
76 $(call Set
,$(2),$($(1))))
78 # Function: Assert value message
80 # Check that a value is true, or give an error including the given message
82 $(error Assertion failed
: $(2)))
84 # Function: AssertEqual variable expected-value
86 # Check that the value of a variable is 'expected-value'.
88 $(if
$(call streq
,$($(1)),$(2)),,\
89 $(error Assertion failed
: $(1): $(value
$(1)) - $($(1)) != $(2)))
91 # Function: CheckCommandLineOverrides list
93 # Check that all command line variables are in the given list. This routine is
94 # useful for validating that users aren't trying to override something which
96 CheckCommandLineOverrides
= \
97 $(foreach arg
,$(MAKEOVERRIDES
),\
98 $(call Set
,varname
,$(firstword $(subst =, ,$(arg
)))) \
99 $(if
$(call contains
,$(1),$(varname
)),,\
100 $(error
"Invalid command line override: $(1) $(varname) (not supported)")))
103 # Clean up make behavior
105 # Cancel all suffix rules. We don't want no stinking suffix rules.
111 # General debugging rule, use 'make print-XXX' to print the definition, value
114 $(error PRINT
: $(value
$*) = "$($*)" (from
$(origin $*)))