对包含空格的文件名使用makefile wildcard命令

时间:2012-12-20 00:36:24

标签: makefile

我有一个用于压缩图片的makefile:

src=$(wildcard Photos/*.jpg) $(wildcard Photos/*.JPG)
out=$(subst Photos,Compressed,$(src))

all : $(out)

clean:
    @rmdir -r Compressed

Compressed:
    @mkdir Compressed

Compressed/%.jpg: Photos/%.jpg Compressed
    @echo "Compressing $<"
    @convert "$<" -scale 20% "$@"

Compressed/%.JPG: Photos/%.JPG Compressed
    @echo "Compressing $<"
    @convert "$<" -scale 20% "$@"

但是,当我在其名称中有一个空格的图片时,例如Piper PA-28-236 Dakota.JPG,我收到此错误:

make: *** No rule to make target `Compressed/Piper', needed by `all'.  Stop.

我认为这是wildcard命令中的一个问题,但我不确定要改变它以使其工作。

如何修改我的makefile以允许文件名中的空格?

1 个答案:

答案 0 :(得分:7)

通常在文件名中包含空格对于make来说是个坏主意,但对于您的情况,这可能有效:

src=$(shell find Photos/ -iname '*.JPG' | sed 's/ /\\ /g')

out=$(subst Photos,Compressed,$(src))

all : $(out)

Compressed:
  @mkdir Compressed

Compressed/%: Photos/% Compressed
  @echo "Compressing $<"
  @convert "$<" -scale 20% "$@"
相关问题