Sometimes it is necessary to add compiler or linker flags for particular make targets, or add libraries to a link. This is described in the automake manual, in the section Program and Library Variables. This is a powerful mechanism, but there is a gotcha.
For each of the variables CFLAGS
,
LDFLAGS
and so on, automake maintains a
parallel variable AM_CFLAGS
or
AM_LDFLAGS
, the contents
of which are managed by automake and autoconf, so that the
unprefixed variables are free to be overridden by the user
(see section Variables reserved
for the user of the automake manual; to be clear,
`user' in this context means the person building the
distributed software, as opposed to the maintainer, or
whoever is creating the distribution). If automake
sees one of the above per-target variables, however, it
carefully uses this instead of the AM_
variable, not in addition to it. This replacement is
sensible, since if this were not the case then there would
be no way to remove a problematic flag from an
AM_
variable, but it is not the behaviour you
might guess at first, and so can come as rather a surprise.
Given that you want to add to these flags rather than
replace them, you do so with the idiom:
libxxx_la_FCFLAGS = $(AM_FCFLAGS) -my-magic-flag
An alternative to setting per-target flags like this is to
set one or more of the AM_*FLAGS
variables
directly. These variables
are `yours' as the author of the Makefile.am
and configure.ac
files -- the automake system
ensures that the variables are included in the correct
places in compile and link commands, but neither it nor
autoconf set these flags. See the FAQ on `Flag Variables
Ordering' in the automake
manual for some further discussion.
There is another set of similar variables, named
STAR_*FLAGS
, which are maintained by
starconf
and the STAR_*
macros in
configure.ac
, and which are the means by which
those macros pass their discovered magic on to the Makefile.
You shouldn't need to know that, and you should not need to
adjust these variables at all, but if for some occult reason
you need to refer to the complete set of flags used to
compile and link programs, you will need to include these
flags also. In general, Makefile variables such as
$(COMPILE)
and $(FCCOMPILE)
are
most suitable for any by-hand compilations you need to do,
and they already have all the extra flags you need, in the
right order..