[Top][All Lists]

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

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

From: Greg Chicares
Subject: Why is 'make -e' "not recommended practice"?
Date: Thu, 07 Jul 2005 21:35:07 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Please help me figure out how to implement the least astonishing behavior
for my makefiles (simplified listings below). I'd like to follow all the
best practices in the manual, but I'm running into an apparent conflict.
| by setting the variable CFLAGS in your environment, you can cause all C
| compilations in most makefiles to use the compiler switches you prefer.

I'd like to have that unastonishing behavior...but:
| (But this is not totally reliable; some makefiles set CFLAGS explicitly
| and therefore are not affected by the value in the environment.)

This is where my confusion begins. Instead of "not totally reliable",
I think that's not at all safe to rely on, because the manual elsewhere
*advocates* setting CFLAGS explicitly:
| Take this common example:
|   CFLAGS = $(includes) -O
| The makefile probably specifies the usual value for CFLAGS, like this:
|   CFLAGS=-g
|   CFLAGS = -g
| Do include the `-g' option in CFLAGS, because that is not required
| for proper compilation.

But if I take that as a best practice and follow it, then CFLAGS isn't
affected by a value in the environment. OK, there's a flag for that:
| (If the `-e' flag is specified, then values from the environment
| override assignments in the makefile. See section Summary of Options.
| But this is not recommended practice.)

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

Here's where I'm stuck:

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

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

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

I can follow any two, but don't see how to follow all three at once
without making the makefiles distinctly less simple than they
otherwise could be.

Here's a testcase with two very simplified makefiles:

### file 'make_0' begins ###
.PHONY: all_0
        @$(MAKE) --no-print-directory --file=make_1
### file 'make_0' ends ###

### file 'make_1' begins ###

.PHONY: all_1
        @echo CFLAGS = '$(CFLAGS)'
### file 'make_1' ends ###

These invocations work as expected:

  C:/tmp[0]$make -f make_0
  CFLAGS = -g

  C:/tmp[0]$make CFLAGS="set_on_command_line" -f make_0
  CFLAGS = set_on_command_line

I'm working with someone who wants to do this:

  C:/tmp[0]$export CFLAGS="set_in_environment"
  C:/tmp[0]$make -f make_0
  CFLAGS = -g

I understand why that example works that way, but my friend wants his
environment setting to prevail, without requiring 'make -e': he thinks
any other behavior is astonishing. OTOH, I think that's his best option.
Am I being horrid if I require 'make -e'?

I could rewrite the makefiles to satisfy his wish and follow the three
best practices above, by
 - moving the definition of CFLAGS into the top-level make,
 - making that definition use '?=' instead of '=', and
 - passing that definition explicitly to the submakefile
but that makes them less simple and comprehensible--even for the highly
simplified testcase here, and much more so for my real makefiles.

Am I missing some obvious solution?

reply via email to

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