【发布时间】:2020-08-13 12:42:34
【问题描述】:
我有一个复杂的脚本c.sh 来测试机器make 运行的环境的某些部分。它应该使用bash 运行。它会打印一些有用的信息以供stdout 和stderr 使用。如果满足某些特殊条件,则c.sh 存在,退出代码为 1,否则为 0。如果出现问题,可能会出现其他退出代码。根据退出代码,我想执行不同的配方。
all:
# test using c.sh
everything-OK: # prerequisites
# *recurse* on this if c.sh exits with zero
# e.g. "$(MAKE) everything-OK" in all if ...
something-went-wrong: # prerequisites
# *recurse* on this if c.sh exists with anything else
我找到了this 有用的答案,但它并没有太大帮助。由于我似乎无法使递归工作或 if 开关取决于退出代码。使用 $(.SHELLSTATUS) 起初看起来很有希望,但该解决方案不会立即从脚本重定向 stdout。
另一种解决方案可能如下所示:
EVERYTHING_OK = 0 # 0: false, 1: true
all:
# test using c.sh
# set EVERYTHING_OK depending on exit code
$(MAKE) second-stage
ifeq (1,EVERYTHING_OK)
second-stage: # prerequisites
# ...
else
second-stage: # prerequisites
# ...
endif
(我更喜欢这个,因为我可以将 if 条件放在宏中)
【问题讨论】: