Hello Hugh, * Hugh Dickinson wrote on Wed, Sep 22, 2010 at 04:50:33PM CEST: > I am trying to convert an existing software package to build using the > GNU autotools. The source code contains several files with .c and .cc > which are designed to be compiled both as C and C++ regardless of > their suffix (i.e. they contain conditionally compiled code #ifdef > _cplusplus preprocessor directives). Unfortunately it seems like > automake hard-codes the libtool "--tag" value directly into the > Makefile.in based on the file suffix.
Indeed, automake assumes .c files are for the C compiler, and C++ files are for the C++ compiler. It is probably not worth trying to fight this, as you will run into more issues later with libtool. There are a couple of hacks I can think of to get up to speed without creating full-fledged copies of each file: 1) For each foo.c file, create a foo.cc file consisting of #include "foo.c" You can even do this automatically from a make rule *if* you always go from .c to .cc, or always the other way, but never have to go both ways within a single Makefile.am. Example: bin_PROGRAMS = cee ceepp cee_SOURCES = foo.c bar.c nodist_ceepp_SOURCES = $(cee_SOURCES:.c=.cc) CLEANFILES = $(nodist_ceepp_SOURCES) .c.cc: source=`echo $< | sed 's,.*/,,'`; \ echo '#include "'$$source.c'"' > $@ 2) Alternatively, use symlinks if possible. Same as above, only .c.cc: rm -f $@ $(LN_S) $< $@ (be sure to still use nodist_*, otherwise you run into portability issues both for symlinks on w32, and for VPATH target issues on other systems with GNU make). Be sure AC_PROG_LN_S is in configure.ac. If your sources files have nontrivial dirname components, this rule needs to be quite a bit more elaborate, though. 3) If you really must compile .c files with $(CXX) or .cc with $(CC) then report back. I probably eventually need to look into this anyway for the GCC source tree, but it's more tricky than it looks at first. Hope that helps. Cheers, Ralf