我有一个自动工具项目。在其目录之一中,我想在 make 过程完成后运行一个脚本。换句话说,我希望有一个选项可以选择最后执行的“虚假”目标。或者,我可以使用专用的 m4 宏(我只知道是哪个......)。 有什么想法吗?
谢谢
最佳答案
我假设通过“autotools”,您正在使用 Automake 以及 Autoconf。我可以看到两种方法。
您可以在 Makefile.am 中创建 -hook
规则。但是,这只能针对某些默认目标完成:install-data
、install-exec
、uninstall
、dist
> 和 distcheck
。因此,要制定一个在 install-exec
之后立即运行的规则,请将其命名为 install-exec-hook
。然后只需运行该规则的配方中的脚本即可。
但是,根据您问题的措辞,您似乎想在构建后运行脚本。如果是这种情况,您可以使用 all-local
目标自定义 all
目标,然后运行该目标配方中的脚本。请注意,根据 Automake 文档,
With the '-local' targets, there is no particular guarantee of execution order; typically, they are run early, but with parallel make, there is no way to be sure of that.
但是,由于 all
目标是虚假的,因此在构建所有内容之前它不应该运行。不过,如果你可以在安装后运行脚本,我会推荐这种方式,因为执行顺序是有保证的。
关于makefile - 如何在自动工具中强制最终目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17726683/