代码之家  ›  专栏  ›  技术社区  ›  Scott Deerwester

如何在Makefile中连接字符串?

  •  1
  • Scott Deerwester  · 技术社区  · 7 年前

    我有一个运行pandoc的Makefile。我要打开扩展列表:

    PANDOC_EXTENSIONS = \
            multiline_tables \
            some_other_extension
    

    变成一个字符串,看起来像:

    PANDOC_EXTENSION_LIST = +multiline_tables+some_other_extension
    

    它将作为命令行选项传递给pandoc,如下所示:

    pandoc --from$(PANDOC_EXTENSION_LIST) ...
    

    这在几乎任何编程语言中都是微不足道的,但我不知道如何使用patsubst或subst函数来实现这一点,因为make实际上没有列表。有什么想法吗?

    2 回复  |  直到 7 年前
        1
  •  3
  •   Mike Kinghan Luchian Grigore    7 年前

    在这里:

    生成文件

    PANDOC_EXTENSIONS = \
            multiline_tables \
            some_other_extension
    
    
    $(foreach word,$(PANDOC_EXTENSIONS),$(eval PANDOC_EXTENSION_LIST := $(PANDOC_EXTENSION_LIST)+$(word)))
    
    .PHONY: all
    
    all:
        echo $(PANDOC_EXTENSION_LIST)
    

    运行方式如下:

    $ make
    echo +multiline_tables+some_other_extension
    +multiline_tables+some_other_extension
    

        2
  •  1
  •   Community Mohan Dere    5 年前

    基于中的示例 documentation

    empty:=
    space:=$(empty) $(empty)
    PANDOC_EXTENSIONS = \
            multiline_tables \
            some_other_extension
    
    all:
        @echo +$(subst ${space},+,${PANDOC_EXTENSIONS})
    

    结果是:

    $ gmake                                                                                                    
    +multiline_tables+some_other_extension