Any non trivial C++ or C program requires some kind of build system. There
are many of them available: cmake, waf, scons, and many others. You can even
roll your own. Problem is that you need to learn the “language” of that build
system, its rules, conventions and so one. But clearly, you usally don’t want
to spend that much time on that task in the beginning of your project and you
would like focus on your software first. On the other hand getting a properly
working and correct build system is necessary as I already said for any non
trivial system. In this post I present a simple Makefile. You can use it
almost as is when you start coding you C or C++ program. The most important
feature is that it
automatically generates the dependencies between your
source files. So why make (or gmake actually) and not any other build tool?
Make is huge and is not simple at all. Well, it is widely used (Android build
system is entirely build on Makefiles for example) and widely available even
on Windows. You can of course read a “tutorial” on make but most of the time
those tutorials on scratch the surface of the art of creating a correct
Makefile. Ok now here is the Makefile: Please read the inline comments to
understand how it structured.
I am not a make guru, so please post a comment if you have a suggestion or if you see something wrong
with this Makefile.