Reputation: 205
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
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
Reputation: 1289
Try this, maybe it helps
http://docstore.mik.ua/orelly/linux/run/ch13_02.htm#x-100-3-prog-make-command
Upvotes: -1