How to Write a Makefile – Automating Python Setup, Compilation, and Testing
Introduction
When you want to run a project that has multiple sources, resources, etc., you need to make sure that all of the code is recompiled before the main program is compiled or run.
For example, imagine our software looks something like this:
main_program.source -> uses the libraries `math.source` and `draw.source`
math.source -> uses the libraries `floating_point_calc.source` and `integer_calc.source`
draw.source -> uses the library `opengl.source`
So if we make a change in opengl.source
for example, we need to recompile both draw.source
and main_program.source
because we want our project to be up-to-date on all ends.
This is a very tedious and time-consuming process. And because all good things in the software world come from some engineer being too lazy to type in a few extra commands, Makefile was born.
Makefile uses the
make
utility, and if we’re to be completely accurate, Makefile is just a file that houses the code that themake
utility uses. However, the name Makefile is much more recognizable.
Makefile essentially keeps your project up to date by rebuilding only the necessary parts of your source code whose children
are out of date. It can also automatize compilation, builds and