Configuring conditional building
From SIPfoundry sipXecs IP PBX, The Open Source SIP PBX for Linux - Calivia
You can make part of the build conditional on whether or not the developer selected it when running 'configure' and on whether or not 'configure' found all the prerequistes needed for it.
An example of how to do this is the conditional support for building doxygen documentation, which is controlled both by the configure options --{enable|disable}-doxygen and by whether or not the program 'doxygen' is installed.
See the ENABLE_DOXYGEN macro in config/general.am; it tests for a global --enable-doc switch and another executable by requiring that two other macros be run first. It then checks for the prerequisite (in this case by using AC_PATH_PROG to find an executable on the users PATH) and then some other tests for particular features; the executable is not found, it prints a warning and resets the 'enable_doxygen' flag to false (note that the variable 'enable_doxygen' is made available to subsequent decisions by using AC_SUBST at the end of the macro).
This could also have used a '--with-doxygen' argument created by using AC_ARG_WITH to specify a path to search for the executable (there are a number of uses of that macro in general.ac).
To use the resulting enable_doxygen value in building the component, the macros must be invoked from the 'configure.ac' (see sipXportLib/configure.ac) in the top level component directory:
ENABLE_DOC
ENABLE_DOXYGEN
and then the conditional make flags established based on the values set by those macros:
AM_CONDITIONAL(DOC, test x$enable_doc = xyes)
AM_CONDITIONAL(GENERATE_DOXYGEN, test x$enable_doxygen = xyes)
in the Makefile.am, the conditional make flags are used to change the targets of the makefile; in this example, the common file config/conditional_doc.am is included in the .../doc/Makefile.am of many components:
if DOC
# go into the doc subdirectory and build all the documents there
doc_SUBDIRS=doc
else
# do not build the doc subdirectory, but install the empty directories
doc_SUBDIRS=
INSTALL_DOC_TARGETS=$(DESTDIR)@SIPX_DOCDIR@/@PACKAGE@
endif # DOC
$(DESTDIR)@SIPX_DOCDIR@:
@INSTALL@ -d $@
$(DESTDIR)@SIPX_DOCDIR@/@PACKAGE@: $(DESTDIR)@SIPX_DOCDIR@
@INSTALL@ -d $@
install-data-hook: $(INSTALL_DOC_TARGETS)
note that the actual rules to build the targets are outside the conditional section - the conditional section controls whether or not they are used, not whether or not they are defined (doing it the other way often leads to automake errors).
