This is a basic overview of some make
concepts including some examples. For
the most part I didn't use code/compile examples, just simple examples of
commands with a single code example at the end.
These examples were put together with:
- Ubuntu 20.04
- GCC v9.3.0
- GNU Make v 4.2.1
The GNU make docs have detailed documentation and examples. I would also recommend (no affiliation) what I think is a very well organized and written tutorial that explains core concepts in detail with examples: Learn Makefiles by Chase Lambert.
Each example directory will have its own README with some details, but roughly the examples are:
Very simple example showing basic structure of targets and dependencies.
This example is similar in behaviour to the basic example but it makes use of some variables to make the rules more manageable for updates or long lists.
This example similarly builds some text files, but makes use of different types of variable assignments, wildcards, and dependencies.
This example just goes through some common built-in functions and a simple user-defined function as an example.
Example of including multiple Makefiles to create a modular build system.
This is a simple hello_world C/C++ project to show a more real-world example of Makefile usage. The Makefile is more complex than necessary for the scale of the project but hopefully it will highlight some good practices.