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 12:43:33 +0100

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).

I just noticed something else I don't like about this approach. If you do it this way a user will never be able to change CFLAGS and still be able to only provide specific optimization flags for libfoo. For example, it won't be possible to have CFLAGS='-g -O0' but still have libfoo compiled with e.g. '-O2'.

Although I agree that users should always be able to have the last say, I do not think that a user provided CFLAGS setting should override _all_. If it were possible to have '$(CFLAGS) $(O3)' for libfoo (which is not the case in the code example above), then a user would still be able to have the last say if the O3 variable was an AC_ARG_VAR. He would be able to change the globally default flags by providing his own CFLAGS, but in addition would also still be able to tune the optimization of _just_ libfoo by supplying his own values for O3.

With the example above, a user can only tune both global CFLAGS _and_ libfoo optimization flags if he used a 'make DEFAULTFLAGS=... O3=...', which is in my opinion not an ideal approach (it would defeat the purpose of having a CFLAGS variable).

Best regards,
Sander





reply via email to

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