开发者

Explicit Intermediate Object Files in GNU AutoMake

开发者 https://www.devze.com 2023-01-05 06:30 出处:网络
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. Curre

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 di开发者_开发知识库rectory. 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@


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号