Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想运行类似的东西:
grep TEXT file.txt
如果 file.txt 中存在 TEXT,则添加编译标志。这是伪代码-
if (grep TEXT file.txt == line exists) CFLAGS += -DFOO
我希望这发生在 Makefile 中。我试过 $(shell command) 但它没有用,所以我有点困惑。
谢谢
请插入如下一行。所以它可能运作良好。
CFLAGS += $(shell /bin/grep -q pattern /path/to/file >/dev/null 2>&1 && echo "-DFOO" || echo "-UFOO")
如果文件中存在文本,则计算结果为:
CFLAGS += -DFOO
否则,如果文件中不存在文本,则计算结果为:
CFLAGS += -UFOO
试试这个,也许有帮助
http://docstore.mik.ua/orelly/linux/run/ch13_02.htm#x-100-3-prog-make-command