Testing the eval function of GNU make

Viewed 2959

The GNU make manual says that the eval function expands the arguments and then feeds the results of the expansion to make parser. The following is quoted from GNU make manual.

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

I don't quite understand how the make parser process the text fed by eval, so I write following makefile to test.

define myprint
    echo "this is a line"
endef

goal:
    $(eval $(call myprint))
    gcc -o goal test.c

I know that the correct invocation of myprint should be only use the call function: $(call myprint) and delete the 'Tab' character before echo. I write the makefile in this form just to test the eval function.

My expectation: first the eval function expands myprint, which is an echo command preceded by a 'Tab', and the 'Tab' is used to make the expanded text to be a legal recipe. Then the eval feeds the expanded text to maker parser, who will identify the text to be a recipe, and run it. As the command is legal, the makefile should run properly.

However, I meet such an error:

Makefile:6: *** recipe commences before first target.  Stop.

Could somebody explain why make produce such an error?

3 Answers
Related