对带有空格的文件名使用makefile通配符命令 [英] Using makefile wildcard command for file names with spaces
本文介绍了对带有空格的文件名使用makefile通配符命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用于压缩图片的makefile:
I have a makefile that I use to compress pictures:
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
)时,会出现此错误:
However, when I have a picture with a space in its name, for example Piper PA-28-236 Dakota.JPG
, I get this error:
make: *** No rule to make target `Compressed/Piper', needed by `all'. Stop.
我认为这是wildcard
命令中的问题,但是我不确定要使其工作才能进行哪些更改.
I think this is a problem in the wildcard
command, but I'm not sure what to change to get it to work.
如何修改我的makefile以在文件名中保留空格?
推荐答案
在make中,通常在文件名中包含空格是不好的主意,但对于您而言,这可能有效:
Generally having spaces in file names is a bad idea with make, but for your case this may work:
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% "$@"
这篇关于对带有空格的文件名使用makefile通配符命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文