使用 automake/Makefile.am 生成 IDL 实体
对于那些不熟悉 IDL(接口描述语言)的人来说,它抽象了跨平台(java、c、c++ 等)使用的数据描述。我的项目具有从 Foo.idl 生成的依赖项 Foo.c、Foo.h、FooHelper.c 和 FooHelper.h。当 Foo.idl 更改时,如何运行任意命令,但在构建过程中仍包含 Foo.c、FooHelper.c?
我当前尝试向 Makefile.am 添加一条规则——希望将该规则复制到生成的 Makefile 中。
我尝试过:
Foo.idl : Foo.idl
${the_generate_command}
然后将 Foo.idl 添加到 my_program_SOURCES 但在构建时它不会运行 the_generate_command 。
我已成功从 IDL 生成,
Foo.c Foo.h FooHelper.h FooHelper.c : Foo.idl
${the_generate_command}
但它不会将 Foo.c、FooHelper.c 添加到编译过程中,因此它们从未构建,只是由 the_generate_command 生成!
所有代码(包括 idl)都位于 $PROJECT_DIR/src 中。
For those unfamiliar with IDL (interface description language), it abstracts data description for use across platforms (java, c, c++, etc). My project has dependencies Foo.c, Foo.h, FooHelper.c, and FooHelper.h which are generated from Foo.idl. How do I run an arbitrary command when Foo.idl changes, but still include Foo.c, FooHelper.c, in the build process?
My current attempts add a rule to the Makefile.am -- the hope is that the rule is copied over to the generated Makefile.
I have tried:
Foo.idl : Foo.idl
${the_generate_command}
and then added Foo.idl to my_program_SOURCES but it doesn't run the_generate_command when building.
I have had success generating from the IDL with
Foo.c Foo.h FooHelper.h FooHelper.c : Foo.idl
${the_generate_command}
But it won't add Foo.c, FooHelper.c to the compile process, so they're never built, just generated by the_generate_command!
All the code (including the idl) is in $PROJECT_DIR/src.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rq 的答案几乎是正确的,但忽略了一些微妙之处。试试这个:
从
Foo.c<“生成”
Foo.h
、FooHelper.h
和FooHelper.c
的附加规则/code> 确保并行构建不会尝试运行$(THE_GENERATE_COMMAND)
两次。这是Automake 手册中详细介绍的习惯用法< /a> 这适用于并行构建。这里仍然有一点脆弱:如果用户删除(例如)FooHelper.h
和FooHelper.c
并启动并行 make,它可能会运行$ (MAKE) $(AM_MAKEFLAGS) $<
并行多次恢复规则的部分。正如手册所说,只有当用户手动破坏构建树时,这种竞争才会发生,即使这样,也不是 make clean ; make 无法修复。BUILT_SOURCES
行确保Foo.c
、Foo.h
、FooHelper.h
和FooHelper。 c
在尝试构建myprogram
之前构建(请参阅Automake 手册的这一部分,了解为什么仅将它们添加到myprog_SOURCES
是不够的)。EXTRA_DIST
变量确保.idl
文件将被make dist
捕获 (参考)。MAINTAINERCLEANFILES
指定运行makemaintainer-clean
时要删除的其他文件;这是为了遵守 GNU Makefile 标准< /a>.另请参阅Automake 手册< /a>.rq's answer is almost correct, but misses a couple of subtleties. Try this:
The additional rules to "generate"
Foo.h
,FooHelper.h
andFooHelper.c
fromFoo.c
ensure that parallel builds won't try and run$(THE_GENERATE_COMMAND)
twice. It is an idiom detailed in the Automake manual which will work for parallel builds. There is still a little fragility here: if the user removes (say)FooHelper.h
andFooHelper.c
and starts a parallel make, it may run the$(MAKE) $(AM_MAKEFLAGS) $<
recovery part of the rule multiple times in parallel. As the manual says, this race can only going to happen if the user manually mutilates the build tree, and even then it's nothing amake clean; make
cannot fix.The
BUILT_SOURCES
line ensures thatFoo.c
,Foo.h
,FooHelper.h
andFooHelper.c
are built before trying to buildmyprogram
(see this section of the Automake manual to see why just adding them tomyprog_SOURCES
is insufficient). TheEXTRA_DIST
variable ensures that the.idl
file will be captured bymake dist
(reference).MAINTAINERCLEANFILES
specifies additional files to delete when runningmake maintainer-clean
; this is to comply with the GNU Makefile Standards. See also the variable's description in the Automake manual.