views:

29

answers:

1

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@
+1  A: 

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.

ptomato
I believe it was originally implemented that way so that the Makefile controlling the driver's build could be in the same directory as the driver code. I'm not sure I agree with that philosophy, but it's not my project so I'll stick with it.
Sam Hanes