❦ 29 septembre 2013 22:27 CEST, Vincent Bernat <ber...@luffy.cx> :

> LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
>         $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
>         $(AM_LDFLAGS) $(LDFLAGS) -o $@
> haproxy: ...
>       $(AM_V_CCLD)$(LINK) $(haproxy_OBJECTS) $(haproxy_LDADD) $(LIBS)
>
> So, the ordering would be as expected.

I was unclear. What I mean is that the expectation of an autoconf build
system (and therefore, the expectation of most users since it is the
most widespread build system) is that the linker will use the following
flags in the following order:

 - maintainer-specified CFLAGS (AM_CFLAGS)
 - user-specified CFLAGS (CFLAGS)

The expectation for CFLAGS is that the user can override any flag set by
AM_CFLAGS.

 - maintainer-specified LDFLAGS (AM_LDFLAGS)
 - user-specified LDFLAGS (LDFLAGS)

Same thing as for CFLAGS. This holds because LDFLAGS should not contain
either `-l` or `-L` options. It's for stuff like `-Wl,--as-needed`. Of
course, for special cases, LDFLAGS can have any flag that is deemed
necessary, like `-L/some/special/path` or `-lmyalternateallocator`. But
not AM_LDFLAGS.

 - any object (OBJECTS)
 - object-specific libraries (LDADD/LIBADD)
 - project-specific libraries (LIBS)

LDADD/LIBADD/LIBS are a combination of `-l`, `-L` or `.a`. No need to
have three variables like here (there are 3 variables just because how
stuff from automake are merged together).

HAProxy's Makefile is almost "correct" with respect to those
expectations. LDADD/LIBADD/LIBS is OPTIONS_LDFLAGS, AM_LDFLAGS is
LDFLAGS + TARGET_LDFLAGS and you just need to rename LDFLAGS to
HA_LDFLAGS and let the user specify LDFLAGS if she wants to. Same for
CFLAGS. LDFLAGS default is usually empty. CFLAGS default is usually -O2
-g.

Distributions will take advantage of this as well. In Debian, currently,
we override CFLAGS and LDFLAGS (so, we don't get the optimisation stuff)
to use our defaults because we want to use hardening flags (and I
suppose we didn't notice that we were overriding some flags, like
-fno-strict-aliasing).
-- 
Write and test a big program in small pieces.
            - The Elements of Programming Style (Kernighan & Plauger)

Reply via email to