2014-11-06 98 views
0

我有一个GNU Make规则,它依赖于带有空格的两个文件。我不想对这些名称进行硬编码,所以我想跳过包含空格的名称。Makefile依赖关系中的空间

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

Final.pdf: $(DEPENDENCIES) 
    # [email protected] 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="[email protected]" $^ 

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

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

有没有办法使用普通做出摆脱它,还是我不得不求助于外部工具,将产生Makefile中,我(或其他编译系统)? (例如autotools或scons)

可移植性不是必需条件,但是很好。

+0

让单位出无法在命名空间处理文件。你无法得到这个工作。 – 2014-11-06 20:59:59

+0

使用在调用make之前将文件重命名的实用程序。我使用[这个快速入侵](http://www.win.tue.nl/~rp/bin/unixifn)。 – reinierpost 2014-11-07 08:11:49

+1

请注意,autotools(特别是automake)只是生成makefile,所以这对此没有帮助。你必须切换到一个完全不同的构建系统,如scons等。 – MadScientist 2014-11-07 13:17:55

回答

1

您不能使用自动变量作为$^$<,因为它们不保留文件名中的空格。不过你可以使用$(DEPENDENCIES),其中包含逃脱空间:

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

Final.pdf: $(DEPENDENCIES) 
    $(GS) -sOutputFile="[email protected]" $(DEPENDENCIES) 

经过与GNU使3.81