andigor
andigor

Reputation: 732

Strange behaviour of gnu make

I have a simple Makefile (just for testing)

define my_macro
var_$(1) := $(1)
$(warning $(var_$(1)))      
$(warning $(var_some_value))
endef

$(eval $(call my_macro,some_value))
$(warning $(var_some_value))

Gnu make (v 3.80) produces:

Makefile:8:
Makefile:8:
Makefile:10: some_value

Why first and even second warnings don't print anything ?

Upvotes: 1

Views: 29

Answers (1)

Jonathan Wakely
Jonathan Wakely

Reputation: 171263

As the manual says, The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.

That means the eval gets expanded to this by substituting some_value for $(1) in the macro:

var_some_value := some_value
$(warning $(var_some_value))
$(warning $(var_some_value))

then the variable $(var_some_value) gets expanded, but at this point the result of the macro expansion has not been evaluated as makefile syntax yet, so the variable has not been set. That means it expands to:

var_some_value := some_value
$(warning )
$(warning )

Then finally that expanded text is processed as makefile syntax, so the variable gets defined, then the empty warnings get printed.

Upvotes: 1

Related Questions