by exDM69 · 11y ago · 0 comments
A good Makefile should have any rules for building object files if you're using a language like C or C++, which Make has built-in rules for. If using another language, adding a few generic rules should be enough.
Here's a Makefile template I've been using for some time. It may look complicated initially but only the first 70 or so lines are the actual beef. The rest of the Makefile is helpful rules for tooling (tags, cscope, coverage, profile) but that doesn't work too well at the moment. It also supports out-of-source-tree builds (using vpath to locate source files, object files and other outputs go under $PWD, vpath is does not work for object files).
# Disable built in suffix rules
.SUFFIXES:
# Disable builtin pattern rules
MAKEFLAGS+=-rYes they can be a bit limiting, but even if you do not want to use built-in rules it's still a good idea to use generic rules using wildcards.
This is what lots of "Makefile tutorials" get wrong, they start by writing rules to build individual object files and targets.
Even if you want to write your own build rules, you should not need more than a few good rules for building and linking your object files.