Hug*_*lpz 1 bash makefile gnu-make
直接粘贴到我的shell中,下面尝试3个正则表达式中的每一个并且工作(参见*.{jpg,png,gis.tif}):
for file in ./output/India/*.{jpg,png,gis.tif}; do echo $file; openssl base64 -in $file -out ./output/India/`basename $file`.b64; done;
Run Code Online (Sandbox Code Playgroud)
作为makefile进程,它失败并返回:
task:
for file in ./output/India/*.{png,jpg,gis.tif} ; \
do echo $$file ; openssl base64 -in $$file -out ./output/India/`basename $$file`.b64; \
done
Run Code Online (Sandbox Code Playgroud)
并返回:
47910543179104:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('./output/India/*.{png,jpg,gis.tif}','r')
Run Code Online (Sandbox Code Playgroud)
为什么当Bash在makefile中时这个表达式不起作用?
我被提示给出一个草图,说明制造如何为你做繁重的工作.
所以,你想所有的源文件转换(.jpg,.png,.gis.tif)在output/India/为他们的base64编码的等价物.草图:
.PHONY: all
all: # default target
dir := output/India/
exts := jpg png gis.tif
wildcards := $(addprefix ${dir}*.,${exts})
sources := $(wildcard ${wildcards})
targets := $(addsuffix .b64,${sources})
${targets}: %.b64: %
openssl base64 -in $< -out $@
all: ${targets}
all: ; : $@ Success
Run Code Online (Sandbox Code Playgroud)
这比它需要的更冗长,通常我反对使用$(wildcard …).那好吧.
那么我们在shell版本上有什么优势呢?
make -j5将同时进行5次转换.好的,如果你有四个CPU未完成的BTW.抱歉.