Makefile依赖项中的空格

时间:2014-11-06 20:49:40

标签: makefile

我有一个GNU Make规则,它取决于两个带空格的文件。我不想硬编码名称,所以我想逃避包含空格的名称。

GS := gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite  
DEPENDENCIES := File\ 1.pdf File\ 2.pdf

Final.pdf: $(DEPENDENCIES)
    # $@ corresponds to "Final.pdf", and $^ is an automatic variable
    # that expands to "File" "1.pdf" "File" "2.pdf", however, I would like
    # it to be "File 1.pdf" and "File 2.pdf"
    # Ghostscript complains that "File" cannot be found, "2.pdf"... etc.
    $(GS) -sOutputFile="$@" $^

    # Now, the variable expands to "File 1.pdf File 2.pdf", which does
    # not yield the intended result either.
    $(GS) -sOutputFile="$@" "$^"

    # Ultimate goal is to get make to run the following command:
    #   $(GS) -sOutputFile="Final.pdf" "File 1.pdf" "File 2.pdf"

有没有办法使用普通的Make来逃避它,或者我是否必须求助于为我(或其他构建系统)生成Makefile的外部工具? (例如autotools或scons)

可移植性不是必需的,但它是一个不错的选择。

1 个答案:

答案 0 :(得分:2)

您不能将自动变量用作$^$<,因为它们不会保留文件名中的空格。不过,您可以使用包含转义空格的$(DEPENDENCIES)

GS := gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite  
DEPENDENCIES := File\ 1.pdf File\ 2.pdf

Final.pdf: $(DEPENDENCIES)
    $(GS) -sOutputFile="$@" $(DEPENDENCIES)

使用GNU Make 3.81

进行检查