【问题标题】:How to abort makefile without error message如何在没有错误消息的情况下中止makefile
【发布时间】:2016-04-27 21:18:15
【问题描述】:

如果当前目标满足特定条件,我如何中止 makefile 继续其他目标。

例如:

Step01:
    @# Do something

Step02: Step01_Output
    @# Check that Step01_output meet certain condition, otherwise, abort

Step03: Step02
    @# Do somethings (of course if did not abort in Step02)

# And so on

我尝试使用状态为 0 的“退出” ==> 但它仍然继续! 我尝试使用“exit 1”或其他存在状态==>它中止,但在输出时给出错误消息。 我想中止,但在 make 调用 shell 时仍然没有给出错误消息。 我还尝试从 Step02 设置 env 变量并围绕 Step03 并在 if 之后检查如下:

ifneq ($(ToAbort),1) 
Step03:
...
StepN

endif

不幸的是,make 似乎连条件都没有看,或者变量值没有在目标之间传递。

有什么想法吗?可能是通过添加额外的目标吗?

【问题讨论】:

  • 请提供一个真实的例子而不是伪代码,这可能是XY problem

标签: makefile gnu-make abort


【解决方案1】:

我认为只有在创建所有目标或出现任何错误时才会退出。 顺便说一句,命令在子 shell 中运行,因此使用`exit' 不会导致 make 退出。

【讨论】:

    【解决方案2】:

    不确定您对此的想法是否正确。 将工作的剔除留给 make

    然而, 你可以用少量的 shell 和递归的 make 来表达你的要求(对不起)。 你想表达“如果a完成有/没有错误,那么我们就完成了,否则继续b。”

    Step01:
        command1
        command2
        command3 && ${MAKE} Step02
        command4
    
    Step02:
        cmd5
        cmd6 && ${MAKE} Step03
    
    ⋮
    

    注意那些 & 符号。 if command3; then ${MAKE} Step02; fi 不会做你想做的事。 如果 make 失败, 您不想继续进入 command4

    附:如果它们不是真实文件,请不要忘记将这些步骤标记为 PHONY。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 2023-04-06
      • 2019-06-13
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      相关资源
      最近更新 更多