生成文件是否可以从变量中获取规则的依赖项并插入到配方中



具体来说,我正在考虑一个"干净"的规则来删除剩余的文件。

files=file1 file2
clean:
    rm -f $(files)
file1: file1dependancy.o

我怎样才能自动rm -f file1dependancy.o清洁,甚至可能吗?

通常,生成文件的结构如下所示:

RM_F  = rm -f
FILES = file1 file2
all:   ${FILES}
FILE1.o = file1dependency.o
file1: ${FILE1.o}
    ...build command mentioning ${FILE1.o}...
FILE2.o = file2.dependency.o
file2: ${FILE2.o}
    ...build command mentioning ${FILE2.o}...
clean:
    ${RM_F} ${FILE1.o} ${FILE2.o} ${FILES|

根据你的make版本,可能会有一个宏用于"所有依赖项";不过它不是POSIX make

最新更新