Is there any difference in the two ways GREP is invoked in my Makefile? Any reason I should use one or the other? Both seem to produce the same result.
define GREP
$(word 3,$(shell echo "#define FOO 0xfff00100"))
endef
all:
@echo $(GREP)
@echo $(call GREP)
Just add -Dxxx=yy on the command line ( xxx the name of the macro and yy the replacement, or just -Dxxx if there is no value).
To use a macro in a makefile, type $(MacroName) , where MacroName is a defined macro. You can use either braces or parentheses to enclose MacroName . MAKE expands macros at various times depending on where they appear in the makefile: Nested macros are expanded when the outer macro is invoked.
8.8 The call Function The call function is unique in that it can be used to create new parameterized functions. You can write a complex expression as the value of a variable, then use call to expand it with different values. The syntax of the call function is: $(call variable , param , param ,…)
Macro Variables. All macros must start with DEFINE and end with ! ENDDEFINE . These commands identify the beginning and end of a macro definition and are used to separate the macro definition from the rest of the command sequence. Immediately after DEFINE , specify the macro name.
The way you are using it, there is no difference. However, if your GREP macro were a function that took parameters, you would have to use $(call) to pass parameters to it. For example:
define GREP
$(shell grep $1 $2)
endef
FOO:=$(call GREP,abc,words.txt)
This causes $1
to be replaced with "abc", and $2
with "words.txt".
See more in the GNU make manual on user-defined functions here: http://www.gnu.org/software/make/manual/make.html#Call-Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With