Makefile 使用文件列表创建先决条件

Makefile 使用文件列表创建先决条件,makefile,Makefile,我希望能够从文件列表中读取makefile的先决条件 文件列表如下所示: /projects/abc/a.v /projects/abc/b.v /projects/abc/c.v 文件列表名为source.flist 这个文件列表相当长,我只想将这个文件列表作为makefile中一个目标的先决条件 有人能告诉我如何做到这一点吗 附言:我是一个初学者水平的w.r.t.makefiles 谢谢 Sundeep我会在另一个步骤中将您的文件列表转换为makefile: # Makefileall:

我希望能够从文件列表中读取makefile的先决条件

文件列表如下所示:

/projects/abc/a.v
/projects/abc/b.v
/projects/abc/c.v
文件列表名为source.flist

这个文件列表相当长,我只想将这个文件列表作为makefile中一个目标的先决条件

有人能告诉我如何做到这一点吗

附言:我是一个初学者水平的w.r.t.makefiles

谢谢
Sundeep

我会在另一个步骤中将您的文件列表转换为makefile:

# 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.mk中并包含在Makefile中的
depsfromfile:
目标包含依赖项

只有当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'.

这很简单,但为什么有必要呢?将已知先决条件的列表(无论多么长)放入一个文件中,然后将其读入
make
,这只会比将列表放入makefile开始时更加复杂和脆弱。我还没有尝试过任何方法。我不知道在哪里可以放置env变量的定义,该变量将是文件列表。我们的文件列表是自动生成的,我希望在任何地方都使用此自动生成的文件列表以避免重复错误。我是堆栈溢出新手,因此如果我没有遵循某些ETTIQUETES,请原谅(并教育我)