automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding specific C flags for a SINGLE source file


From: Sander Niemeijer
Subject: Re: adding specific C flags for a SINGLE source file
Date: Mon, 13 Dec 2004 10:43:13 +0100

On vrijdag, dec 10, 2004, at 21:35 Europe/Amsterdam, Alexandre Duret-Lutz wrote:

user_CFLAGS=$CFLAGS
AC_PROG_CC
if test "x$user_CFLAGS" = x; then
  # If the user didn't specify CFLAGS, then CFLAGS contains
  # a subset of -g -O2 selected by AC_PROG_CC.  This is not
  # a user setting, and we want to be able to override this
  # locally in our rules, so put these flags in a separate
  # variable and empty CFLAGS.
  AC_SUBST([DEFAULTFLAGS], [$CFLAGS])
  CFLAGS=
fi

and in Makefile.am use
  foo_CFLAGS = $(DEFAULTFLAGS)
and
  libfoo_a_CFLAGS = $(DEFAULTFLAGS) $(O3)
as appropriate.

($(O3) being the Makefile variable that contains -O3 if the compiler
support it).

Does that sound sensible?

This is indeed a solution I hadn't thought about yet. But unfortunately it has some downsides. If you have a project with a lot of targets (as we have) and only one target needs the $(O3) override, then this approach would force you to create per target CFLAGS entries for all other targets (e.g. 'bar_CFLAGS = $(DEFAULTFLAGS)'). Furthermore, using a 'make CFLAGS=<some flags>' will not work anymore (you will now need to call 'make DEFAULTFLAGS=<some flags>'.

By the way, I totally agree with the argument that the user should always have the last say, which is indeed possible by using a variable for the flags you are appending (in your case the $(O3) and in my case I have called it $(DISOPT_FLAG)).

After some more pondering I think I might know an even cleaner solution to the problem (which would require a change to automake however): How about omitting CFLAGS when target_CFLAGS are provided?

This means one would be able to write:

libfoo_a_CFLAGS = $(AM_CFLAGS) $(CFLAGS) $(O3)

and if libfoo_a_CFLAGS is defined empty no CFLAGS will be used at all.

Of course, introducing this would break backward compatibility. So how about enabling this behavior by using some automake flag in AM_INIT_AUTOMAKE? By default a target_CFLAGS COMPILE target will contain '$(target_CFLAGS) $(CFLAGS)', but if this special automake flag is provided it will only be '$(target_CFLAGS)' (but only when using target specific flags, the '$(AM_CFLAGS) $(CFLAGS)' combination for the default COMPILE rule will _not_ be modified). Does this sound sensible? The implementation effort should at least be quite low as far as I can guess.

Best regards,
Sander







reply via email to

[Prev in Thread] Current Thread [Next in Thread]