GNU AutoMake 中的显式中间对象文件
我有一个 C 应用程序,正在将一组手工编码的 Makefile 转换为 GNU AutoMake。它有一个子目录,其中包含接口标头和几个依赖于平台的实现。当前,选择一个实现并将其构建到该目录中具有固定名称的目标文件。然后,使用驱动程序接口的代码链接该目标文件并自动获取正确的驱动程序。
将此系统转换为使用 AutoTools 的最佳方法是什么?我已经让 AutoConf 创建了正确驱动程序实现文件的替换。我只是不知道如何获得一个 AutoMake 目标,我可以将其 EXTRA_*_SOURCES
和 *_LDADD
变量放入其中。我是否需要放弃放在中间目标文件上并将它们放入使用它们的程序目标的列表中?
编辑: 感谢 ptomato 解决了。
由于 Automake 的依赖解析,所有可能的源都必须在 *_SOURCES
和 EXTRA_*_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以构建一个便利的库,并将其静态链接到您的应用程序。最终它和目标文件之间没有什么区别。请参阅 Automake 的此页面手动的。基本上是这样的:
具有固定名称的中间目标文件是
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:
where your intermediate object file with a fixed name is
libdriver.a
, and your application ismyprogram
.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.