Echo '$(VAR)' to a file

2019-03-02 04:50发布

问题:

I have the following problem with a line from a Makefile:

echo 'include $(BASE)/Makefile.base' > file

If I write this directly into the console it literally prints 'include $(BASE)/Makefile.base' into the file, but when using it within a Makefile $(BASE) always gets replaced with a blank and i want it to literally write that to the file. I tried to write several ways but can't seem the find the right way...

回答1:

echo 'include $$(BASE)/Makefile.base' > file

The macro named $ (invoked using $$) expands to $. You frequently need to use $$ in segments of a makefile that will become shell script, because make expands $L, $(NAME) and ${NAME} (where L is a single-letter) automatically (to an empty string if the macro isn't set to anything else).



标签: makefile echo