It's a bit unclear what you want to do, if you need to use old make
implementations or can stick to GNU Make, and if you've read the
documentation.
What I always do is put something like this in the Makefile:
CFLAGS=-W -Wall -pedantic -ansi -g -Os
CXXFLAGS=-W -Wall -pedantic -std=c++14 -g -Os
CPPFLAGS=-Isome/where -Dsomething
With the builtin GNU Make rules, that's enough to compile C and C++
to object code. Note that I split cpp[1] stuff into CPPFLAGS.
If I want to override things and I don't want to edit the Makefile --
and this happens very rarely -- I tend not to use the environment, but
this syntax:
% make CFLAGS=-std=c99 foo.o
Oddly, I cannot find that in the GNU Make manual. Not where it should
be, anyway.
I know there are rules for when GNU Make picks stuff from the
environment, and when it doesn't. Those /are/ documented.
I never could figure out how to use the builtin rules for linking,
so I write that rule explicitly.
Lastly, I actually override the whole .o: .c rule, since I enable
automatic dependency generation with the help of gcc. But that's
orthogonal to the CFLAGS stuff.
There's an example here (the code is mostly C++ but that doesn't
matter):
https://github.com/kjgrahn/gavia
/Jorgen
[1] That's the C preprocessor, not an alternative name for C++.
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/
snipabacken.se> O o .