GNU AutoMake 中的显式中间对象文件

发布于 2024-09-07 11:29:23 字数 827 浏览 9 评论 0原文

我有一个 C 应用程序,正在将一组手工编码的 Makefile 转换为 GNU AutoMake。它有一个子目录,其中包含接口标头和几个依赖于平台的实现。当前,选择一个实现并将其构建到该目录中具有固定名称的目标文件。然后,使用驱动程序接口的代码链接该目标文件并自动获取正确的驱动程序。

将此系统转换为使用 AutoTools 的最佳方法是什么?我已经让 AutoConf 创建了正确驱动程序实现文件的替换。我只是不知道如何获得一个 AutoMake 目标,我可以将其 EXTRA_*_SOURCES*_LDADD 变量放入其中。我是否需要放弃放在中间目标文件上并将它们放入使用它们的程序目标的列表中?

编辑: 感谢 ptomato 解决了。

由于 Automake 的依赖解析,所有可能的源都必须在 *_SOURCESEXTRA_*_SOURCES 中命名,如 手册的条件源部分。因此,图书馆节实际上是:

noinst_LIBRARIES = libdriver.a
libdriver_a_SOURCES = driver.h
EXTRA_libdriver_a_SOURCES = driver-linux.c driver-windows.c driver-osx.c
libdriver_a_LIBADD = @DRIVERIMPL@

I have a C application I'm converting from a set of hand coded Makefiles to GNU AutoMake. It has a subdirectory that contains an interface header and several platform-dependent implementations. Currently an implementation is selected and built to an object file with a fixed name in that directory. The code that uses the driver interface then links against that object file and automagically gets the right driver.

What's the best way to convert this system to use AutoTools? I already have AutoConf creating a substitution for the correct driver implementation file. I just can't figure out how to get an AutoMake target whose EXTRA_*_SOURCES and *_LDADD variables I can put the implementation files in. Do I just need to give up on the intermediate object file and put them in the list for the program target that uses them?

EDIT: Solved thanks to ptomato.

Because of Automake's dependency resolution all possible sources must be named in *_SOURCES and EXTRA_*_SOURCES, as explained in the Conditional Sources section of the manual. Therefore, the library stanza is actually:

noinst_LIBRARIES = libdriver.a
libdriver_a_SOURCES = driver.h
EXTRA_libdriver_a_SOURCES = driver-linux.c driver-windows.c driver-osx.c
libdriver_a_LIBADD = @DRIVERIMPL@

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

禾厶谷欠 2024-09-14 11:29:23

您可以构建一个便利的库,并将其静态链接到您的应用程序。最终它和目标文件之间没有什么区别。请参阅 Automake 的此页面手动的。基本上是这样的:

noinst_LIBRARIES = libdriver.a
libdriver_a_SOURCES = @CORRECT_IMPLEMENTATION_FILE@
myprogram_LDADD = libdriver.a

具有固定名称的中间目标文件是 libdriver.a,您的应用程序是 myprogram

然而,这对我来说似乎不必要地复杂。我不认为您有任何理由不应该按照您的建议放弃中间目标文件并将实现文件放入使用它们的程序目标中。

You could build a convenience library, and link it statically to your application. There's ultimately very little difference between that and an object file. See this page of the Automake manual. Basically it goes like this:

noinst_LIBRARIES = libdriver.a
libdriver_a_SOURCES = @CORRECT_IMPLEMENTATION_FILE@
myprogram_LDADD = libdriver.a

where your intermediate object file with a fixed name is libdriver.a, and your application is myprogram.

However, this seems unnecessarily complicated to me. I don't see any reason why you shouldn't, as you suggest, give up on the intermediate object file and put the implementation files in the program target that uses them.

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