【问题标题】:print horizontal line in Makefile output在 Makefile 输出中打印水平线
【发布时间】:2020-11-24 21:19:41
【问题描述】:

寻找一点 Makefile 糖果;没有什么关键任务。我有这个 Makefile 输出:

$ make
all              The Whole Enchilada
target01         Descript1
target02         Descript2
target03         Descript3
target04         Descript4

由于某种原因,我似乎无法让它在输出中打印出一条水平线;正在寻找这个:

$ make
all              The Whole Enchilada
target01         Descript1
target02         Descript2
------------------------------------------------ make all ends here
target03         Descript3
target04         Descript4

只是一个带有右对齐消息的简单分隔符。

我应该分享一下,这是我的 Makefile 的结尾,它会打印所有目标:

#-----------------------------------------------------------------------------#    
#------------------------   MANAGERIAL OVERHEAD   ----------------------------# 
#-----------------------------------------------------------------------------# 
print-%  : ## Print any variable from the Makefile (e.g. make print-VARIABLE);  
        @echo $* = $($*)                                                        
                                                                                
.PHONY: help                                                                    
                                                                                
help:                                                                           
        @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'
                                                                                
.DEFAULT_GOAL := help                                                           

如果您能在单行 printf 语句中帮助我理解它,则可以加分;出于某种原因,printf 不太适合我。

【问题讨论】:

    标签: makefile output printf


    【解决方案1】:

    您没有提供当前的Makefile,但这看起来并不复杂:

    $ cat Makefile
    all:
            @printf "all\t\tThe Whole Enchilada\n"
            @printf "target01\tDescript1\n"
            @printf "target02\tDescript2\n"
            @printf -- "------------------------------------------------ make all ends here\n"
            @printf "target03\tDescript3\n"
            @printf "target04\tDescript4\n"
    
    
    $ make
    all             The Whole Enchilada
    target01        Descript1
    target02        Descript2
    ------------------------------------------------ make all ends here
    target03        Descript3
    target04        Descript4
    

    唯一的事情是您需要在printf 调用中使用-- 来明确声明选项部分已完成,其余所有都是位置参数,否则printf 将尝试将您的水平线解释为选项。

    【讨论】:

    • 我已经更新了我的原始问题以包含help: 目标;抱歉,我并不清楚。有没有办法让它打印不需要它在all: 目标中?
    • 您能否解释一下您希望何时打印此分隔符?看起来help target 只是打印出了所有目标及其描述,但不清楚何时应该打印分隔符。
    • ^target02.*$ 之后继续使用上面的示例 - 我认为这是表达这一点的方式。
    猜你喜欢
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多