使用 automake/Makefile.am 生成 IDL 实体

发布于 2024-09-13 02:47:56 字数 635 浏览 14 评论 0原文

对于那些不熟悉 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-09-20 02:47:56

rq 的答案几乎是正确的,但忽略了一些微妙之处。试试这个:

bin_PROGRAMS = myprogram
myprogram_SOURCES = Foo.c Foo.h FooHelper.h FooHelper.c $(OTHER_SOURCES)
BUILT_SOURCES = Foo.c Foo.h FooHelper.h FooHelper.c
EXTRA_DIST = Foo.idl
MAINTAINERCLEANFILES = Foo.c Foo.h FooHelper.h FooHelper.c

Foo.c: Foo.idl
    $(THE_GENERATE_COMMAND)

Foo.h FooHelper.h FooHelper.c: Foo.c
    @if test -f $@; then \
        touch $@; \
    else \
## Recover from the removal of $@
        rm -rf 
lt;; \
        $(MAKE) $(AM_MAKEFLAGS) 
lt;; \
    fi

Foo.c<“生成”Foo.hFooHelper.hFooHelper.c 的附加规则/code> 确保并行构建不会尝试运行 $(THE_GENERATE_COMMAND) 两次。这是Automake 手册中详细介绍的习惯用法< /a> 这适用于并行构建。这里仍然有一点脆弱:如果用户删除(例如)FooHelper.hFooHelper.c 并启动并行 make,它可能会运行 $ (MAKE) $(AM_MAKEFLAGS) $< 并行多次恢复规则的部分。正如手册所说,只有当用户手动破坏构建树时,这种竞争才会发生,即使这样,也不是 make clean ; make 无法修复。

BUILT_SOURCES 行确保 Foo.cFoo.hFooHelper.hFooHelper。 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:

bin_PROGRAMS = myprogram
myprogram_SOURCES = Foo.c Foo.h FooHelper.h FooHelper.c $(OTHER_SOURCES)
BUILT_SOURCES = Foo.c Foo.h FooHelper.h FooHelper.c
EXTRA_DIST = Foo.idl
MAINTAINERCLEANFILES = Foo.c Foo.h FooHelper.h FooHelper.c

Foo.c: Foo.idl
    $(THE_GENERATE_COMMAND)

Foo.h FooHelper.h FooHelper.c: Foo.c
    @if test -f $@; then \
        touch $@; \
    else \
## Recover from the removal of $@
        rm -rf 
lt;; \
        $(MAKE) $(AM_MAKEFLAGS) 
lt;; \
    fi

The additional rules to "generate" Foo.h, FooHelper.h and FooHelper.c from Foo.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 and FooHelper.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 a make clean; make cannot fix.

The BUILT_SOURCES line ensures that Foo.c, Foo.h, FooHelper.h and FooHelper.c are built before trying to build myprogram (see this section of the Automake manual to see why just adding them to myprog_SOURCES is insufficient). The EXTRA_DIST variable ensures that the .idl file will be captured by make dist (reference).

MAINTAINERCLEANFILES specifies additional files to delete when running make maintainer-clean; this is to comply with the GNU Makefile Standards. See also the variable's description in the Automake manual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文