CFLAGS, LDFLAGS and LDLIBS are set by a distro build. They specify system-wide settings that the distro wants. Anything from special ways of linking the program, to tuning optimization for a particular CPU and whatnot.
The more your Makefile sticks to standards, the less they have to do.
Make sure you support "make DESTDIR=<directory>" to install into a temporary directory of the caller's choice. E.g. if your prefix (another thing to support) is /usr/bin then "make DESTDIR=tmp-dir" installs into tmp-dir/usr/bin. The software is configured to run in /usr/bin though and won't necessarily execute properly out of there; that tmp-dir is just for packaging.
However you do compiler selection, make sure that the default is to use $(CC).
Regarding the OUR_CFLAGS thing in my above post: the reason some Makefiles clobber CFLAGS is that they can then use built-in recipes. The built-in recipe for compiling a .c to a .o only knows about CC and CFLAGS. It's worth it to replace the built-in recipes with your own though in order not to disturb the standard variables.
A long time ago I put together my own little summary of applied GNU'ish conventions. See https://25thandClement.com/~william/cuda/Makefile.md.html Notably I specified LIBS instead of LDLIBS. These days I use LDLIBS. I forget why I listed LIBS, but there is some ambiguity and consistency across GNU tools. For example, pkg-config sort of ignored or simplified some older conventions (e.g. dropping CPPFLAGS and making CFLAGS do double duty) which IME wasn't for the better, at least if applied outside the domain of what pkg-config is used for.
Why use these conventions? Because such variables and their semantics will be useful for package maintainers, who won't need to spend as much time learning some bespoke convention and who often have templates for working with GNU-like builds, even when autotools aren't being used. Because they reflect decades of experience in how to write builds that in 80% of odd circumstances (including development, non-production environments) can be controlled without modifying the build rules directly. Relatedly, they're often the minimum necessary abstraction for cross-compiling (though alone not always sufficient).
On the compiler command line, you just want -iquote include; -iquote $(INC_DIR) doesn't help anything.
If someone renames or moves directories in the future, they can search and replace the Makefile.
Variables hide things. If I see $(INC_DIR), is that something external? I have to look it up.
By default I assume that a variable exists for a reason, which is that something is being made configurable. Usually, configurable things are uncertainties that are external: where other stuff is, and what not.
The article further recommends nonstandard practices.
- LFLAGS: what is that? The standard variables are LDFLAGS and LDLIBS. LDFLAGS are options for linking, and LDLIBS are just the libraries like -lwhatever. They are separated because they go into different parts of the command line. For Pete's sake, do not invent your own variables. Learn the standards. Distro maintainers will thank you when your program is packaged.
- Believe it it or not, but you must should not touch CFLAGS. CFLAGS belongs to the user who is invoking your Makefile. Put any required options or debug options and whatnot into a different variable. Combine that with CFLAGS. The same goes for the aforementioned LDFLAGS and LDLIBS.
Let's look at this:
This does not always do what the author thinks. It looks like it wants to add some options to CFLAGS, if CFLAGS is already defined. But this is not what GNU Make will do if CFLAGS is coming from the command line: then the := assignment will be entirely suppressed. That -O2 will be the CFLAGS. The combination will happen if CFLAGS is coming from the environment.Thus if you have essential code generation options that your program needs, the above pattern will break in some situations. Don't use CFLAGS as the container where you accumulate all your options. Assemble the options in your own variable, where you interpolate CFLAGS: