我希望能够从文件列表中读取makefile的先决条件。
文件列表如下所示:
/projects/abc/a.v
/projects/abc/b.v
/projects/abc/c.v
,文件列表名为source.flist
这个文件列表很长,我想简单地使用这个文件列表作为makefile中某个目标的先决条件。
有人可以告诉我如何实现这一目标。
PS:我在初学者级别w.r.t.生成文件由于 森迪普•
答案 0 :(得分:1)
我会通过在另一个步骤中将您的文件列表转换为生成文件来完成此操作:
# Makefileall:
all: depsfromfile.out
depsfromfile.mk:
(echo "depsfromfile:"; cat depsfromfile )| sed -e '/^#/d' -e 's/$/ \\/' -e '$s/ \\//' > depsfromfile.mk # there is a \t at the beginnging of this line!
-include depsfromfile.mk
depsfromfile.out: depsfromfile
@touch depsfromfile depsfromfile.out
depsfromfile:
cat $^ > $@.out
@touch depsfromfile
使用文件列表depsfromfile
# depsfromfile
a
b
c
Makefile从depsfromfile
文件自动生成其依赖项。测试目标使用depsfromfile
来生成输出。
自动生成depsfromfile:
并包含在Makefile中的depsfromfile.mk
目标包含依赖项。
只有在depsfromfile的依赖关系发生更改时才会重新生成depsfromfile.out
目标。
现在你可以
# echo "test a" > a
# echo "test b" > b
# echo "test c" > c
# make
cat a b c > depsfromfile.out
# make
make: Nothing to be done for 'all'.