On Wed, Nov 17, 2010 at 01:34:21PM +0000, Tony Houghton wrote: > How should one add --as-needed linker flags to an autotools-based > package? I ended up adding CFLAGS=-Wl,--as-needed to my > dh_auto_configure parameters but is it OK to just overwrite CFLAGS like > that, or should I add it to any existing CFLAGS? > > BTW, at first I tried LDFLAGS=--as-needed but automake/libtools passed > it to gcc without -Wl, which I thought wasn't very clever. I then used > CFLAGS because the -Wl makes it a gcc option, but OTOH it is explicitly > a linker option (according to the man page) so perhaps I should stick > with LDFLAGS after all? Check the rule in your generated Makefile.in (example): LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ You can see LDFLAGS is used, but --as-needed (and --no-as-needed) are /positional/ parameters. So you need --as-needed immediately before $(AM_LDFLAGS), which is why you see it working when added to $(CFLAGS). I would just add it to the front of AM_LDFLAGS. BTW, it's worth considering whether or not you actually need to use --as-needed, or if there are better ways of removing unwanted libraries (such as not linking them in in the first place). Regards, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.
Attachment:
signature.asc
Description: Digital signature