gpt4 book ai didi

makefile - 对带有空格的文件名使用makefile通配符命令

转载 作者:行者123 更新时间:2023-12-03 22:35:57 28 4
gpt4 key购买 nike

我有一个用于压缩图片的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以在文件名中保留空格?

最佳答案

通常,使用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% "$@"

关于makefile - 对带有空格的文件名使用makefile通配符命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13963563/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com