+1  A: 

You're definitely on the right track. Autotools can seem very complicated at first, but one of the advantages is that there are thousands of projects out that have already done what you want to do. All you need to do is find them.

Here is a link to a Google code search for AC_ARG_DISABLE. Go nuts.

anthony
gotgenes
+1 for "Autotools can seem very complicated at first"
Chris Lutz
+1  A: 

To prevent the build from attempting to compile in the ctemplate subdirectory, you'll want to do something like:

if CTEMPLATE
SUBDIRS += ctemplate
endif

in Makefile.am

William Pursell
+1  A: 

Here is the solution that I put together after reading through documentation, tutorials, help threads, mailing lists, etc., and just plain trying things until they worked I could explain why they worked.

In configure.ac, I placed the following lines of code

# This adds the option of compiling without using the ctemplate library,
# which has proved troublesome for compilation on some platforms
AC_ARG_ENABLE(ctemplate,
  [ --disable-ctemplate   Disable compilation with ctemplate and HTML output],
  [case "${enableval}" in
     yes | no ) WITH_CTEMPLATE="${enableval}" ;;
     *) AC_MSG_ERROR(bad value ${enableval} for --disable-ctemplate) ;;
   esac],
  [WITH_CTEMPLATE="yes"]
)

dnl Make sure we register this option with Automake, so we know whether to
dnl descend into ctemplate for more configuration or not
AM_CONDITIONAL([WITH_CTEMPLATE], [test "x$WITH_CTEMPLATE" = "xyes"])

# Define CTEMPLATE in config.h if we're going to compile against it
if test "x$WITH_CTEMPLATE" = "xyes"; then
    AC_DEFINE([CTEMPLATE], [], ["build using ctemplate library"])
    AC_MSG_NOTICE([ctemplate will be used, HTML output enabled])
else
    AC_MSG_NOTICE([ctemplate will not be used, HTML output disabled])
fi

In the next step, I changed the Makefile.am at the top level to the following:

if WITH_CTEMPLATE
  MAYBE_CTEMPLATE = ctemplate
endif

SUBDIRS = boost libgsl $(MAYBE_CTEMPLATE) libutil ...

In lower level Makefile.ams, I added

if WITH_CTEMPLATE
    # some change to the configuration
else
    # some other change to the configuration
endif

Finally, I had to make sure that one of the key C++ header files (included by other parts of the code) had the following:

#ifdef HAVE_CONFIG_H
#    include "config.h"
#endif

config.h contains any new definitions one creates with AC_DEFINE, so this file must be included in parts that check whether a macro definition created by this route is defined (or undefined).

This took a lot of time and pushing through frustration on my part; I can only hope documenting this explanation here saves someone else from the same fate.

gotgenes