makefile:运行目标时忽略依赖项

时间:2018-05-31 21:32:02

标签: makefile gnu-make

我在Makefile中有这个设置。

action1:
  does something

action2: action1
  does something else

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

2 个答案:

答案 0 :(得分:2)

你可以这样做:

".profile"

现在,如果你运行ACTION1 = action1 action1: does something action2: $(ACTION1) does something else ,那么两者都将被构建。如果您运行make,那么该变量将为空,make ACTION1=将不依赖于action2。当然你可以随意调用那个变量。

答案 1 :(得分: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.