It's an Automake limitation, it doesn't care about the condition when choosing the linker.
One work-around is to conditionally rewrite the _LINK command, as suggested in this mailing list post:
if USE_CXX
cxx_sources = ...
else
cxx_sources =
libSDLU_la_LINK = $(LINK) $(libSDLU_la_CFLAGS) $(libSDLU_la_LDFLAGS)
endif
Another way (suggested in the same discussion) is to put the C++ sources in a utility library that is built and added conditionally, then added to the main library:
if CXX
noinst_LTLIBRARIES = libSDLUxx.la
libSDLUxx_la_SOURCES = src/cxx/SDLU_CButton.cxx \
src/cxx/SDLU_CIniHandler.cxx \
src/cxx/SDLU_CRenderer.cxx \
src/cxx/SDLU_CSprite.cxx \
src/cxx/SDLU_CTexture.cxx \
src/cxx/SDLU_CWindow.cxx
libSDLU_la_LIBADD = libSDLUxx.la
endif
Some unrelated notes
Do not put generated files (
Makefile.in
,configure
, etc) into source control.Add a
bootstrap
script that invokes the autotools to generate things.Prefer pkg-config (i.e.
PKG_CHECK_MODULES(SDL2, sdl2)
) over hand-crafted autoconf macros (i.e.AM_PATH_SDL2
);Do not install autoheaders (i.e.
SDLU_config.h.in
). It makes your library incompatible with every autoconf-based software, as you are re-definingPACKAGE
,VERSION
, and all library-detection macros. See my answer in this question for examples on how to do it.I would have the C++ API built and installed as an independent, optional library; drop the sdlu-config script altogether, then write
sdluxx.pc
that requiressdlu
. Do not bother checking if the C++ compiler works, if the user passed--enable-cxx
he knows what he's doing; I prefer to have the build fail than silently have an incomplete library.