Automake:依赖于构建结果
我使用 automake 和 autoconf。
在子目录 src/ 中,Makefile.am 包含
bin_PROGRAMS = hello
hello_SOURCES = hello.c
在构建 hello 之后,我想在二进制文件上运行一个工具(系统上安装的一些分析器/优化器)来修改它(例如 strip)或生成统计信息(例如 dwarves、pahole ... )。为此,顶层目录中的 Makefile.am 包含
tool:
tool src/hello
When build hello with make 并执行 make 工具,一切正常。当用户运行 make 工具而不构建二进制文件时,会出现此问题。如何强制构建 bin_PROGRAMS (可能是一个列表)或仅构建 hello 二进制文件作为目标工具的依赖项?
既不
tool: bin_PROGRAMS
tool src/hello
工作也不
tool: src/hello
tool src/hello
工作。
I use automake and autoconf.
In the subdirectory src/ the Makefile.am contains
bin_PROGRAMS = hello
hello_SOURCES = hello.c
After building hello I want to run a tool (some analyzer/optimizer installed on the system) on the binary to modify it (e.g. strip) or generate statistics (e.g. dwarves, pahole ...). For this purpose the Makefile.am in the top-level-directory contains
tool:
tool src/hello
When building hello with make and executing make tool everything is fine. The problem occurs when the user runs make tool without building the binary. How can I enforce building the bin_PROGRAMS (which may be a list) or just the hello binary as dependency of the target tool?
Neither
tool: bin_PROGRAMS
tool src/hello
nor
tool: src/hello
tool src/hello
work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
名为“tool”的 Makefile 目标应该创建一个名为“tool”的文件。由于“工具”已经存在,Make 假设它不需要再次运行该命令(我正在简化,但只是一点点)。
像这样的构造应该可以工作:
另外,一般来说,我相信您不能使用
bin_PROGRAMS
或任何其他 Automake 变量(用=
分配)作为依赖,但我可能是错的。A Makefile target named 'tool' is supposed to create a file named 'tool'. Since 'tool' already exists, Make assumes that it does not need to run the command again (I'm simplifying, but only a little).
A construct like this should work:
Also, in general I believe you cannot use
bin_PROGRAMS
or any other Automake variable (assigned with=
) as a dependency, but I could be wrong.你想要:
但是你会遇到与显式指定 src/hello 相同的问题。 (也就是说,顶层 Makefile 不知道如何在 src 中构建 hello。)您可能最好执行以下操作:
在顶层并将实际规则放入 src/Makefile.am,您可以在其中列出的依赖性。但这也是一个非常糟糕的主意。也许最好的办法是使用全本地规则并放入类似以下内容:
在 src/Makefile.am 中。这将确保每当您运行不带参数的 make 时该工具都会运行,但在重建 hello 时它不会更新输出。如果这是可以接受的,那么这是一个合理的解决方案。另一种选择是:
在 src/Makefile.am 中,并在 src/Makefile.am 的 noinst_DATA 中列出工具输出。
You want:
But you'll have the same problem as if you specify src/hello explicitly. (Namely, the top level Makefile doesn't know how to build hello in src.) You'd probably be better off doing something like:
in the top level and put the actual rule in src/Makefile.am, where you can list the dependency. But that's a pretty bad idea, too. Probably the best thing to do is use an all-local rule and put something like:
in src/Makefile.am. This will ensure that tool is run whenever you run make with no arguments, but it will not update the output when hello is rebuilt. If that is acceptable, then this is a reasonable solution. Another option is to do:
in src/Makefile.am and list tool-output in noinst_DATA in src/Makefile.am.