I need to find the text 'ifeq ($(Param1)' using grep. I try to assign search result to make variable. The problem is that single quotes don't escape text in make so when I try:
GrepResult:= $(shell grep 'ifeq ($$(Param1)' TextFile)
I get:
Makefile:214: *** unterminated call to function `shell': missing `)'. Stop.
The $ can be escaped with $$ but how do I escape parentheses in make? Thanks.
NB: $GrepResult is used in $(error) function, not in a rule command.
The trick is to smuggle the special characters past Make and grep.
GrepResult := ${shell grep 'ifeq (\$$(Param1)' TextFile}
Make turns $$ into $, then grep turns \$ into $. Also note that this assignment uses curly braces "{}", not parentheses "()", so as not to be confused by the results of the match. (There may be a more robust way to handle the string, but never mind.)
When you use the result, use single quotes:
all: @echo '$(GrepResult)'
This too was tested with GNUMake 3.81.
EDIT: This also works with $(error...):
$(error '$(GrepResult)')
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