在它们之间使用 grep 制作多命令食谱?

Make multi-command recipes with grep between them?

我需要 运行 我的对象的多命令配方。但是,如果前一个命令的 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 不能执行下一个命令,而是停止。

I already have the 3 separate make objects (compile, elaborate, simulate). I now need to put all 3 together into one make object so it runs all three when i run 'make run_sim'. How do I do that?

就这样:

.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 introduction, GNU make manual and review the information about GNU make: error handling. Info about phony targets can be found at GNU make: phony targets, Whosebug: What is the purpose of .PHONY target?

Verilog?

我在类似情况下所做的,可能是我自己的novice/electrical工程师错误,是这样的:

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

因为如果 'PASSES' 不存在于 compile.log 中,grep -q 将失败,Make 将突然停止。

你只需让 elaborate 依赖于 compile.summary

如果您正在搜索诸如“*E”或 'Error' 之类的内容,则可以改用 grep -qv 'Error',其中“-v”会在 grep return 找到时出现错误compile.log.

中的字符串

不过,这对用户来说并不是那么友好。在失败的情况下,您只会看到 "Making compile.log" 后跟...什么都没有。

在我的例子中,它实际上是在处理从不 return 0 的程序,因此必须对日志进行 grep 以找出可接受的失败与致命的失败。

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