Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(shell) function in GNU makefile results in 'unterminated call to function shell: missing )'

Tags:

grep

gnu-make

Description:

I have the following snippet within my GNU makefile:

test:=$(shell grep '#pragma' test_types.h)
$(info test:$(test))

The above results in the following error message:

*** unterminated call to function 'shell': missing ')'. STOP

However if I remove the '#' from the snippet above:

test:=$(shell grep 'pragma' test_types.h)
$(info test:$(test))

The output is:

test: #pragma pack(push, 1) #pragma pack(pop)

If I run the following directly from the command line: grep '#pragma' test_types.h. The output is again:

#pragma pack(push, 1) #pragma pack(pop)

Question:

What is causing the shell function behaviour when combining grep with a search for # within a GNU makefile?

like image 735
Bruno Hendrickx Avatar asked Jun 14 '26 18:06

Bruno Hendrickx


1 Answers

It is interpreting the # as the start of a comment, so the rest of the line is no longer seen.

Escape the character as \# instead and it will work.

like image 168
lostbard Avatar answered Jun 18 '26 01:06

lostbard