使用Grep制作多命令配方?

问题描述 投票:2回答:2

我需要为我的对象运行多命令配方。但是,如果先前命令的grep导致找到特定的字符串,则不得运行后续命令。我该怎么写?

run_sim:
    $(MAKE) compile; \
    (Here I need grep of results of log of compile command) && $(MAKE) elaborate; \
    (Here I need grep of results of log of elaborate command) && $(MAKE) simulate;

如果grep返回找到的字符串,那么make一定不要执行下一个命令,而要停止。

shell grep gnu-make
2个回答
0
投票

我已经有3个独立的make对象(编译,精心制作,模拟)。现在,我需要将所有3个对象放到一个make对象中,这样当我运行'make run_sim'时,它将同时运行所有3个对象。我怎么做?

就这样:

.PHONY: run_sim
run_sim:
    $(MAKE) compile
    $(MAKE) elaborate
    $(MAKE) simulate

但是创建适当的依赖关系树会更好:

.PHONY: compile
compile: output.out ;

output.out: something.c
     gcc something.c -o output.out

.PHONY: elaborate
elaborate: compile
    do_the_elaboration


.PHONY: simulate
simulate: compile
    do_the_simulation

.PHONY: run_sim
run_sim: compile elaborate simulate ;

查看GNU make introductionGNU make manual并查看有关GNU make: error handling的信息是明智的。有关伪造目标的信息可以在GNU make: phony targetsstackoverflow: What is the purpose of .PHONY target?

中找到

0
投票

Verilog?

我在类似情况下所做的事情可能是我自己的使新手/电气工程师犯错,这是:

compile.summary: compile.log
    @echo Making $@
    @grep -q PASSES $<
    @echo Compile PASSES > $@

因为如果compile.log中不存在'PASSES',grep -q将会失败,因此Make会停止运行。

您仅使elaborate依赖于compile.summary

如果搜索的是'* E'或'Error'之类的东西,可以改用grep -qv 'Error',其中'-v'如果grep在compile.log中找到字符串,则grep将返回错误。

不过,这还不全是用户友好的。在失败的情况下,您将仅看到“制作compile.log”,后跟...什么都没有。

就我而言,它实际上是在处理永不返回0的程序,因此必须对日志进行grep处理,以确保可接受的失败与致命的失败。

随着另一个答案的到来,以实际文件为目标来管理依赖关系要容易得多。 PHONY编译目标可能意味着您在进行详细说明时总是重新编译...,因为它没有文件+时间戳来知道上次编译与输入的新鲜度。最好让compile.log作为详细说明所依赖的实际文件。

© www.soinside.com 2019 - 2024. All rights reserved.