Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I invoke a GNU make macro created using define?

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)
like image 313
sigjuice Avatar asked Jul 23 '09 01:07

sigjuice


People also ask

How do I set #define in makefile?

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).

How do I enable macros in makefile?

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.

How do you call a function in makefile?

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 ,…)

Which command is used to define a macro variable?

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.


1 Answers

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

like image 190
Eric Melski Avatar answered Oct 29 '22 12:10

Eric Melski