Buffalo
Buffalo

Reputation: 205

Running multiple shell commands in makefile

I would like to run something like:

grep TEXT file.txt

If TEXT exists in file.txt then add a compilation flag. Here is the pseudocode-

if (grep TEXT file.txt == line exists)
     CFLAGS += -DFOO

I would like this to happen in Makefile. I have tried $(shell command) but it did not work so I am a bit confused.

Thanks

Upvotes: 3

Views: 7043

Answers (2)

Taizo Ito
Taizo Ito

Reputation: 424

Please insert a line like the following. So it may work well.

CFLAGS += $(shell /bin/grep -q pattern /path/to/file >/dev/null 2>&1 && echo "-DFOO" || echo "-UFOO")

If the text exists in the file, it evaluates to :

CFLAGS += -DFOO

else if text does NOT exist in the file, it evaluates to :

CFLAGS += -UFOO

Upvotes: 2

Related Questions