【问题标题】:Unable to execute all prerequisites for a target in makefile无法为 makefile 中的目标执行所有先决条件
【发布时间】:2019-06-28 05:44:38
【问题描述】:

我一直在尝试执行 makefile 中特定目标的所有先决条件。但只要先决条件是具有单个/多个信息值的目标,我发现其他先决条件没有执行(在基于“信息”的目标之后)

我尝试将先决条件中的值中的信息数量减少到只有 1。在这种情况下,我也找不到其他要执行的先决条件。 因此,我的问题是了解如何执行基于单行/多行信息的先决条件并继续执行其他先决条件。

# Define new line and separator
.PHONY:newline
newline:
    @echo 

.PHONY:separator
separator:
    $(info -------------------------------)

# Print the project details
.PHONY:project
project:
    $(info Project Details)
    $(info Author  : xyz)

# Help menu 
.PHONY:help
help: newline separator project separator newline 



Expected outcome 
$ make help

-------------------------------
Project Details
Author  : xyz
-------------------------------

Outcome received

$ make help

-------------------------------
Project Details
Author  : xyz

【问题讨论】:

    标签: makefile gnu-make gnu


    【解决方案1】:

    在 make 中,任何目标的配方在每个构建中最多执行一次。所以不要这样做,这是非常非常错误的。

    另外,$(info ...) 是一个文本替换,它在同一配方中的任何外部命令之前执行,因此将它与 echo 混合通常是一个坏主意。

    如果您想避免重复长虚线,您可以随时使用变量来做到这一点:

    sep := --------------------
    define nl :=
    
    
    endef
    
    ...
    
    help:
        $(info $(nl)$(sep))
        $(info Project details)
        ...
        $(info $(sep)$(nl))
    

    【讨论】:

    • 此外,尽管 GNU make 在串行模式下运行时会按顺序处理先决条件,但 make 规范实际上并不要求这样做,也不应依赖它。在需要管理目标构建顺序的地方,应该通过目标/先决条件关系来完成。除其他外,这将确保具有并行 make 的可接受的构建顺序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 2010-11-23
    • 2020-07-04
    • 2023-03-23
    相关资源
    最近更新 更多