Dmitry K
Dmitry K

Reputation: 95

Makefile shell grep

$(BUILDDIR)/%.check: $(SRCDIR)/%.c
        $(eval pragma := $(shell grep "pragma" $< ))
        @echo $<: $(pragma)

$(pragma) variable is always a null string, even for files containing #pragma

What's wrong?

Upvotes: 0

Views: 1460

Answers (1)

Beta
Beta

Reputation: 99104

There are several things wrong.

1) You are putting Make syntax into a command, which should be in the shell syntax.

2) You are attempting to set a variable in one command and use it in another (which won't work because each command runs in its own subshell).

3) You have attempted a complex command without testing its simpler components (which would have told you that something was wrong).

If all you want to do is display the #pragma lines, this will do it:

$(BUILDDIR)/%.check: $(SRCDIR)/%.c
    @echo $<: `grep "pragma" $<`

If you want to do something more complex with the lines, tell us what it is and we'll see if we can help.

Upvotes: 1

Related Questions