automake: Linking

1 
1 8.1.2 Linking the program
1 -------------------------
1 
1 If you need to link against libraries that are not found by ‘configure’,
1 you can use ‘LDADD’ to do so.  This variable is used to specify
1 additional objects or libraries to link with; it is inappropriate for
1 specifying specific linker flags, you should use ‘AM_LDFLAGS’ for this
1 purpose.
1 
1    Sometimes, multiple programs are built in one directory but do not
1 share the same link-time requirements.  In this case, you can use the
1 ‘PROG_LDADD’ variable (where PROG is the name of the program as it
1 appears in some ‘_PROGRAMS’ variable, and usually written in lowercase)
1 to override ‘LDADD’.  If this variable exists for a given program, then
1 that program is not linked using ‘LDADD’.
1 
1    For instance, in GNU cpio, ‘pax’, ‘cpio’ and ‘mt’ are linked against
1 the library ‘libcpio.a’.  However, ‘rmt’ is built in the same directory,
1 and has no such link requirement.  Also, ‘mt’ and ‘rmt’ are only built
1 on certain architectures.  Here is what cpio’s ‘src/Makefile.am’ looks
1 like (abridged):
1 
1      bin_PROGRAMS = cpio pax $(MT)
1      libexec_PROGRAMS = $(RMT)
1      EXTRA_PROGRAMS = mt rmt
1 
1      LDADD = ../lib/libcpio.a $(INTLLIBS)
1      rmt_LDADD =
1 
1      cpio_SOURCES = ...
1      pax_SOURCES = ...
1      mt_SOURCES = ...
1      rmt_SOURCES = ...
1 
1    ‘PROG_LDADD’ is inappropriate for passing program-specific linker
1 flags (except for ‘-l’, ‘-L’, ‘-dlopen’ and ‘-dlpreopen’).  So, use the
1 ‘PROG_LDFLAGS’ variable for this purpose.
1 
1    It is also occasionally useful to have a program depend on some other
1 target that is not actually part of that program.  This can be done
1 using either the ‘PROG_DEPENDENCIES’ or the ‘EXTRA_PROG_DEPENDENCIES’
1 variable.  Each program depends on the contents both variables, but no
1 further interpretation is done.
1 
1    Since these dependencies are associated to the link rule used to
1 create the programs they should normally list files used by the link
1 command.  That is ‘*.$(OBJEXT)’, ‘*.a’, or ‘*.la’ files.  In rare cases
1 you may need to add other kinds of files such as linker scripts, but
1 _listing a source file in ‘_DEPENDENCIES’ is wrong_.  If some source
1 file needs to be built before all the components of a program are built,
1 consider using the ‘BUILT_SOURCES’ variable instead (⇒Sources).
1 
1    If ‘PROG_DEPENDENCIES’ is not supplied, it is computed by Automake.
1 The automatically-assigned value is the contents of ‘PROG_LDADD’, with
1 most configure substitutions, ‘-l’, ‘-L’, ‘-dlopen’ and ‘-dlpreopen’
1 options removed.  The configure substitutions that are left in are only
1 ‘$(LIBOBJS)’ and ‘$(ALLOCA)’; these are left because it is known that
1 they will not cause an invalid value for ‘PROG_DEPENDENCIES’ to be
1 generated.
1 
1    ⇒Conditional Sources shows a situation where ‘_DEPENDENCIES’
1 may be used.
1 
1    The ‘EXTRA_PROG_DEPENDENCIES’ may be useful for cases where you
1 merely want to augment the ‘automake’-generated ‘PROG_DEPENDENCIES’
1 rather than replacing it.
1 
1    We recommend that you avoid using ‘-l’ options in ‘LDADD’ or
1 ‘PROG_LDADD’ when referring to libraries built by your package.
1 Instead, write the file name of the library explicitly as in the above
1 ‘cpio’ example.  Use ‘-l’ only to list third-party libraries.  If you
1 follow this rule, the default value of ‘PROG_DEPENDENCIES’ will list all
1 your local libraries and omit the other ones.
1