How to create our own Makefile
Although this blog is not especially oriented to the area of development, but there are several concepts that are convenient to know, whether in the area of systems or development. Knowledge is always useful, and although it is impossible to know everything, there are things which are advisable to know, even if it is heard or passed. One of those concepts which, in my opinion, it is useful to bear in mind, is the creation of our own Makefile. Both to create one in the future and to understand its functioning.
For starters, it is important to know the utility of this file, but for which the best we can do is put ourselves in a hypothetical situation. Generally, when we download a compressed package that we want to install on Linux, what we do is unzip it, enter it and execute the make and make install commands. This is not because the make command installed on the computer does “magic”, but because that command takes the reference of Makefile file that is present in the folder in question, which makes a long and complicated process, is really simple to do, but … What does this file do? What if we did not have the file? The Makefile performs the compilation tasks that normally we should execute by hand, tedious tasks that should be done one by one. In addition, the lack of a Makefile also makes that in the case of sharing the code with another person, it would have to compile every file by file; Task that can be very uncomfortable for anyone.
The best is to understand this with a simple example; imagine that we have these three pieces of code: