Saturday, April 9, 2022

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

Issue

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?


Solution

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.



Answered By - lostbard
Answer Checked By - Clifford M. (WPSolving Volunteer)