我有一个用于压缩图片的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以允许文件名中的空格?
答案 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% "$@"