GNU中的递归通配符使? [英] Recursive wildcards in GNU make?
问题描述
自从我使用make
已经有一段时间了,所以请忍受...
我有一个目录flac
,其中包含.FLAC文件.我有一个对应的目录,包含MP3文件的mp3
.如果FLAC文件比相应的MP3文件新(或相应的MP3文件不存在),那么我想运行一堆命令将FLAC文件转换为MP3文件,并在其中复制标签.>
启动器:我需要递归搜索flac
目录,并在mp3
目录中创建相应的子目录.目录和文件的名称中可以包含空格,并以UTF-8命名.
我想用make
来驱动它.
我会尝试以下方法
FLAC_FILES = $(shell find flac/ -type f -name '*.flac')
MP3_FILES = $(patsubst flac/%.flac, mp3/%.mp3, $(FLAC_FILES))
.PHONY: all
all: $(MP3_FILES)
mp3/%.mp3: flac/%.flac
@mkdir -p "$(@D)"
@echo convert "$<" to "$@"
针对make
初学者的一些快速笔记:
- 命令前面的
@
阻止make
在实际运行命令之前打印命令. -
$(@D)
是目标文件名($@
)的目录部分 - 确保其中带有shell命令的行以制表符开头,而不以空格开头.
即使这可以处理所有UTF-8字符和内容,它也会在文件或目录名称中的空格处失败,因为make
使用空格分隔makefile中的内容,并且我不知道解决方法那.恐怕只剩下一个shell脚本了:-/
It's been a while since I've used make
, so bear with me...
I've got a directory, flac
, containing .FLAC files. I've got a corresponding directory, mp3
containing MP3 files. If a FLAC file is newer than the corresponding MP3 file (or the corresponding MP3 file doesn't exist), then I want to run a bunch of commands to convert the FLAC file to an MP3 file, and copy the tags across.
The kicker: I need to search the flac
directory recursively, and create corresponding subdirectories in the mp3
directory. The directories and files can have spaces in the names, and are named in UTF-8.
And I want to use make
to drive this.
I would try something along these lines
FLAC_FILES = $(shell find flac/ -type f -name '*.flac')
MP3_FILES = $(patsubst flac/%.flac, mp3/%.mp3, $(FLAC_FILES))
.PHONY: all
all: $(MP3_FILES)
mp3/%.mp3: flac/%.flac
@mkdir -p "$(@D)"
@echo convert "$<" to "$@"
A couple of quick notes for make
beginners:
- The
@
in front of the commands preventsmake
from printing the command before actually running it. $(@D)
is the directory part of the target file name ($@
)- Make sure that the lines with shell commands in them start with a tab, not with spaces.
Even if this should handle all UTF-8 characters and stuff, it will fail at spaces in file or directory names, as make
uses spaces to separate stuff in the makefiles and I am not aware of a way to work around that. So that leaves you with just a shell script, I am afraid :-/
这篇关于GNU中的递归通配符使?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!