Makefile:如何找出其他规则中不再使用的依赖项
我有一个有点复杂的 Makefile,它运行 perl 脚本和其他工具并生成大约 1000 个文件。我想在生成所有文件后编辑/修改其中一些生成的文件。所以我想我可以简单地添加一个新规则来这样做:
(phony new rule): $LIST_OF_FILES_TO_EDIT
file_modifier ...
但是,这里的重点是我想要编辑的一些生成的文件($LIST_OF_FILES_TO_EDIT
)在同一个中使用make 过程生成一长串文件。因此,我必须等待确保 make 过程中不再需要这些文件,然后才能继续编辑它们。但我不知道该怎么做。更不用说,借助$LIST_OF_FILES_TO_EDIT
很难找出生成了哪些文件。
如果可以在 Makefile 中提及该规则只能作为最后一条规则运行,那么我的问题就可以解决。但据我所知这是不可能的。那么有人有想法吗?
一些要点:
要编辑的文件列表 ($LIST_OF_FILES_TO_EDIT) 是动态确定的(在 make 过程之前未知)
我不确定我是否为这个问题选择了一个好的标题。 :)
I have a somewhat complicated Makefile which runs perl scripts and other tools and generates some 1000 files. I would like to edit/modify some of those generated files after all files are generated. So I thought I can simply add a new rule to do so like this:
(phony new rule): $LIST_OF_FILES_TO_EDIT
file_modifier ...
however, the point here is some of those generated files which I'd like to edit ($LIST_OF_FILES_TO_EDIT
) are used in the same make process to generate a long list of files. So I have to wait to make sure those files are no longer needed in the make process before I can go ahead and edit them. But I don't know how to do that. Not to mention that it is really hard to find out what files are generated by the help of $LIST_OF_FILES_TO_EDIT
.
If it was possible to mention in the Makefile that this rule should be only run as the last rule, then my problem would be solved. but as far as I know this is not possible. So anyone has an idea?
Some points:
List of files to edit ($LIST_OF_FILES_TO_EDIT) is determined dynamically (not known before make process)
I am not sure I have picked a good title for this question. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 如果你要像这样修改文件,你可能需要给目标指定不同的名称,例如 foo_unmodified 和 foo_modified ,以便 Make 的依赖处理会处理这个的。
2) 如果您的虚假新规则是您在命令行上调用的规则(“make phonyNewRule”),则 Make 将在执行
file_modifier
命令之前构建它将构建的任何其他规则。如果你想构建不在该列表中的目标,你可以这样做:3) 如果你的依赖设置正确,你可以找出哪些目标依赖于 $(LIST_OF_FILES_TO_EDIT),但它不是很整洁。您只需
touch
其中一个文件,运行make
,查看它构建了哪些目标,然后对所有文件重复此操作。您可以通过使用 Make 参数来节省一些时间:“make -n -W foo1 -W foo2 -W foo3 ... -W foo99 all”。这将打印 Make 将运行的命令——我不知道有什么方法让它告诉你它将重建哪些目标。1) If you're going to modify the files like that, it might behoove you to give the targets different names, like
foo_unmodified
andfoo_modified
, so that the Make's dependency handling will take care of this.2) If your phony new rule is the one you invoke on the command line ("make phonyNewRule"), then Make will build whatever else it's going to build before executing the
file_modifier
command. If you want to build targets not on that list, you could do it this way:3) If your dependencies are set up correctly, you can find out which targets depend on $(LIST_OF_FILES_TO_EDIT), but it's not very tidy. You could just
touch
one of the files, runmake
, see which targets it built, repeat for all files. You could save a little time by using Make arguments: "make -n -W foo1 -W foo2 -W foo3 ... -W foo99 all". This will print the commands Make would run-- I don't know of any way to get it to tell you which targets it would rebuild.