manpagez: man pages & more
info automake
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1.3.1 Conditional compilation using _LDADD substitutions

Automake must know all the source files that could possibly go into a program, even if not all the files are built in every circumstance. Any files that are only conditionally built should be listed in the appropriate EXTRA_ variable. For instance, if ‘hello-linux.c’ or ‘hello-generic.c’ were conditionally included in hello, the ‘Makefile.am’ would contain:

 
bin_PROGRAMS = hello
hello_SOURCES = hello-common.c
EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
hello_LDADD = $(HELLO_SYSTEM)
hello_DEPENDENCIES = $(HELLO_SYSTEM)

You can then setup the ‘$(HELLO_SYSTEM)’ substitution from ‘configure.ac’:

 
…
case $host in
  *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
  *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
esac
AC_SUBST([HELLO_SYSTEM])
…

In this case, the variable HELLO_SYSTEM should be replaced by either ‘hello-linux.o’ or ‘hello-generic.o’, and added to both hello_DEPENDENCIES and hello_LDADD in order to be built and linked in.


© manpagez.com 2000-2025
Individual documents may contain additional copyright information.