[Top][All Lists]

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

Re: Why is 'make -e' "not recommended practice"?

From: Paul D. Smith
Subject: Re: Why is 'make -e' "not recommended practice"?
Date: Thu, 7 Jul 2005 22:16:12 -0400

%% Greg Chicares <address@hidden> writes:

  gc> | (If the `-e' flag is specified, then values from the environment
  gc> | override assignments in the makefile. See section Summary of Options.
  gc> | But this is not recommended practice.)

  gc> ...but I balk at that because it's "not recommended". (Why not?)

Because who knows what random variables the user might have in his
environment, that would then conflict with and override variables you've
set in your makefile?

Recipe for disaster.  Never use -e (at least, I've never found a use for

  gc> Here's where I'm stuck:

  gc>   Best practice #1: Define CFLAGS in the makefile; include '-g'.

  gc>   Best practice #2: Respect any CFLAGS definition in the environment.

  gc>   Best practice #3: Don't require '-e' ("this is not recommended 

You have a few choices, depending on what you want to do.

One option is to not set CFLAGS at all in your makefiles; use your own
flags variable like _CFLAGS or whatever.  But, keep $(CFLAGS) in your
command lines.  Using this method, any value the user sets in the
environment will be preserved (since it's not overridden by the
makefile).  The problem with this model is that the user has a hard time
changing the flags you set, he can only (easily) add new flags.  What if
he doesn't want -g?

Another option is to test if the user had CFLAGS in her environment,
using the $(origin ...) function, or else just test to see if it's
already set, and if not provide a value:

    ifndef CFLAGS
        CFLAGS = -g

There are two problems with this: first, there is a default value for
CFLAGS provided by make.  You'll need to be sure to pass the -R option
to keep that from being defined.  Second, your makefile is now not
portable anymore: it's GNU make-specific.  Maybe that doesn't matter.

The method used by GNU autoconf, and recommended and widely expected in
the community, is this: set CFLAGS = -g in your makefile.  If the user
wants to override it, they can pass the override value on the command
line, like so:

    make CFLAGS=-O2

remember that command line settings take precedence over values in the
makefile (unless override is specified in the makefile).

GNU autoconf has an additional feature where if you specify CFLAGS when
running configure it will become the default in the makefiles: they can
do that because they create the makefiles.  When you're writing them
from scratch that's much harder to do.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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