代码之家  ›  专栏  ›  技术社区  ›  thetango

Makefile:多次执行目标

  •  1
  • thetango  · 技术社区  · 5 月前

    这个答案有点相关,但并没有真正回答我的问题: How do you force a makefile to rebuild a target?

    我在Makefile中定义了以下目标:

    dist-3:
            @echo "calling dist-3"
    
    dist-2: dist-3
            @echo "calling dist-2"
    
    dist-1: dist-2 dist-3
            @echo "calling dist-1"
    

    “make dist-1”的输出为:

    calling dist-3
    calling dist-2
    calling dist-1
    

    但我希望dist-3被执行多次。我试着将dist-3声明为。PHONY尝试使用FORCE选项,但似乎都不起作用。

    有没有一种方法可以多次执行dist-3?

    1 回复  |  直到 5 月前
        1
  •  3
  •   Ngenator    5 月前

    您可以通过递归调用来实现这一点 make 使用 MAKE 目标配方中的变量。由于这些目标没有引用文件,您应该将它们声明为 .PHONY 。我还添加了一个 MAKEFLAGS 变量用于使目录开关输出静音,以便结果与问题的输出相匹配。

    Makefile

    MAKEFLAGS = s
    
    .PHONY: dist-3
    dist-3:
        @echo "calling dist-3"
    
    .PHONY: dist-2
    dist-2:
        @$(MAKE) dist-3
        @echo "calling dist-2"
    
    .PHONY: dist-1
    dist-1:
        @$(MAKE) dist-2 dist-3
        @echo "calling dist-1"
    
    $ make dist-1
    calling dist-3
    calling dist-2
    calling dist-3
    calling dist-1