一个棘手的 GNU make 问题
下面是我希望 makefile 执行的一些伪代码:
if (A doesn't exist) or (B is newer than A):
rm -rf A
create an empty A
parallel_for X in (a large set of files):
if (X is newer than A):
update A using the contents of X
在上面的伪代码中,A
是一个 SQLite 数据库,B
是一个 C 头文件,并且中的每个文件“大文件集”是一个 C 源文件。
基本上,如果我只修改其中一个C源文件,我只是希望数据库能够快速更新,而不是从头开始重建整个数据库。
这种类型的问题可以直接在 GNU make 中解决吗,还是我必须求助于使用脚本?
提前致谢!
Here's some pseudocode for what I want my makefile to do:
if (A doesn't exist) or (B is newer than A):
rm -rf A
create an empty A
parallel_for X in (a large set of files):
if (X is newer than A):
update A using the contents of X
In the above pseudocode, A
is an SQLite database, B
is a C header file, and each of the files in the "large set of files" is a C source file.
Basically, if I only modify one of the C source files, I just want the database to be quickly updated rather than rebuilding the entire database from scratch.
Is this type of problem solvable directly in GNU make, or am I going to have to resort to using a script?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该可以工作:
$?
扩展到比 A 更新的$(all_X)
子集(请参阅“自动变量 部分的 GNU Make 手册了解更多详细信息)。必须针对所有后续参数更新其第一个参数;它只会被调用一次。 href="http://www.gnu.org/software/make/manual/html_node/Double_002dColon.html" rel="noreferrer">双冒号 告诉 Make 运行更新 A 的命令是不同的它相对于 B 来说已经过时了,而对于 Xes 来说已经过时了,我不确定如果两者都已过时,这两组命令是否都会运行;运行时,
A::B
规则将首先运行。Something like this ought to work:
$?
expands to the subset of$(all_X)
that are newer than A (see the "Automatic Variables section of the GNU Make manual for more details). Therefore,update_A_from_Xes
must update its first argument with respect to all of the subsequent arguments; it will only be invoked once.The double colons tell Make that the commands to run to update A are different when it's out of date with respect to B than when it's out of date with respect to the Xes. I am not sure whether both sets of commands will get run in the case that it is out of date with respect to both; if they do both get run, the
A:: B
rules will get run first.