18

我有一个用于压缩图片的生成文件:

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 以允许文件名中有空格?

4

1 回答 1

11

通常在文件名中有空格对于 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% "$@"
于 2012-12-20T01:15:49.547 回答