I am compiling packages and I see that oftentimes Makefile authors write set CFLAGS in the makefile, with such and such options. I, on the other hand, would like to try out some compiler optimizations and would like to propagate the compiler switches to make with as little trouble as possible. Not always is this doable though. For instance when a makefile specifies CFLAGS and I want all C compiler invocations to use -fomit-frame-pointer, short of having to explicitly write something like CFLAGS=-fomit-frame-pointer make
, what are my options that are not hackish. From what I can see there is the above, then there is the same but different make "CFLAGS=-fomit-frame-pointer"
and I can also do what I consider to be the best solution and the reason for this question:
export CFLAGS=-fomit-frame-pointer
make -e
I consider this the best one, because frankly even thought potentially dangerous flag, I don't debug software that much, and when I need to I can recompile a particular piece on demand, with debugging info and all. Otherwise I like to work with release software without debugging bells and whistles at all, especially if the package is not authored by me. So I guess what I ask here specifically is: why make does not automatically prefer environment variables to makefile's own? After all environment knows best what is what, and in case make author really needs to have something their way there is the 'override' syntax, right?
Make will override the variables if you put them on the make command line.
Try this:
make CFLAGS=-fomit-frame-pointer
One word of warning. Most Makefiles don't expect their variables to be overridden. That means that if the Makefile uses CFLAGS to specify -I for include files, -O2 for optimization, or other flags, you must add them to your CFLAGS override or the make will probably fail.
That is arguable: "After all environment knows best what is what"
It's like saying "mother knows best" to an all-grown up child and stopping them from going to study law because you wanted to see what kind of plumber they'd be. It's their life. Let go and let them make their choice for themselves.
Oh wait, you were asking about environment and make. Right.
Well, make is a new process that starts after you've modified your environment and in the general case, the environment does not know what the make goals are and how it works. So, whatever make explicitly sets should trump whatever might happen to be in the environment.
Update: There's an argument I missed originally in my answer - predictability. The only requirement should be the presence of standardized set of tools (same version of GCC, same libs), and given that a properly written make file should always produce the same result, no matter what the environment is, or what other tools are present.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With