Include a (header-only) library in an autotools project
I want to integrate a header-only C++ library in my Autotools project. Since the library uses Autoconf and Automake, I use AC_CONFIG_SUBDIRS
in configure.ac
and added the library dir to the SUBDIRS =
line in Makefile.am
.
My question is: how do I prevent the header library from being installed by make install
? I'm building a single binary, so my users don't need these he开发者_开发技巧aders.
I'd prefer not to tamper with the library, so I can fetch upgrade by just untarring the new version.
Here is an idea.
Move all the third-party libraries you do not want to see installed into a subdirectory called noinst/
. So for instance if you want to ship your project with something like Boost, unpack it into the directory noinst/boost/
. Use AC_CONFIG_SUBDIRS([noinst/boost])
. Inside noinst/Makefile.am
, do something like this:
SUBDIRS = boost
# Override Automake's installation targets with the command ":" that does nothing.
install:; @:
install-exec:; @:
install-data:; @:
uninstall:; @:
The effect is that whenever some of the recursive "make install*" or "make uninstall" commands are run from the top-level directory, the recursion will stop in noinst/
and not visit its subdirectories. Other recursive commands (like "make", "make clean" or "make dist") will still recurse into the subdirectories.
You could of course override install:
and friends directly into the third-party package, and avoid the extra noinst/
directory. But if you are like me, you don't want to tamper with third-party packages to ease their update.
Also a nice property of the above setup is that if someone goes into noinst/boost/
and decide to run make install
, it will work. It just does not occur by default when they install your package.
just came across a similar problem and found the solution in the automake manual:
noinst_HEADERS would be the right variable to use in a directory containing only headers and no associated library or program
Andreas
Don't use SUBDIRS
then. The following hack may work:
all-local: ${MAKE} -C thatlib all
Of course it would be best if the library remained in its own directory outside of your project, and you just point to it via CFLAGS/LIBS flags.
精彩评论