【问题标题】:makefile: ignore dependency when running targetmakefile:运行目标时忽略依赖关系
【发布时间】:2019-12-11 19:16:11
【问题描述】:

我的 Makefile 中有这个设置。

action1:
  does something

action2: action1
  does something else

我想保留我的配置以防我想使用action1 作为action2 的依赖项,但有时我想在运行make action2 时忽略action1(例如,我想运行@987654325 @ 而不必包括 action1)。我可以设置某种标志来传递以在运行目标时忽略依赖关系吗?我该怎么做?

【问题讨论】:

  • 你可以有action3:,它没有先决条件,也可以有does something else。
  • @Beta 我不希望它重复:(
  • 我想我可以使用一个函数来摆脱重复性,但最好有某种标志

标签: makefile gnu-make


【解决方案1】:

make -o <name of dependency> 允许您忽略依赖项及其所有含义。从手册页:

-o file, --old-file=file, --assume-old=file
     Do not  remake the file file  even if it is  older than
     its dependencies, and do not remake anything on account
     of changes in file.  Essentially the file is treated as
    very old and its rules are ignored.

【讨论】:

    【解决方案2】:

    你可以这样做:

    ACTION1 = action1
    
    action1:
            does something
    
    action2: $(ACTION1)
            does something else
    

    现在,如果您运行 make,那么两者都将被构建。如果您运行make ACTION1=,那么该变量将为空并且action2 将不依赖于action1。当然,您可以随意调用该变量。

    【讨论】:

    • 这里更喜欢使用:= 而不是=。
    • 耸耸肩当然。在这种情况下真的没有任何区别。
    猜你喜欢
    • 1970-01-01
    • 2016-06-22
    • 2022-10-23
    • 2023-04-02
    • 1970-01-01
    • 2014-01-23
    • 2020-11-17
    • 2013-10-22
    • 1970-01-01
    相关资源
    最近更新 更多