Is a generic utility to update files that are derived from other files. The update happens comparing the modification dates of the different files and their relationships, described in a makefile… What a description! Very technic, isn´t it?
Make was one of the first tools I learned when I started in the Linux world, and right now is one of the most used by me, directly or indirectly… I need to recognize that the process of learning make was painful and slow. Full of questions and with the only help of huge manuals really detailed, but also really technical. Now I appreciate those manuals that gets you to the point very fast, but I missed some kind of easy introduction or manual. And this is the purpose of this page! I want to give to the world a little of what I get, and make it easy for the people to understand this tool that is often considered worthless or too expensive to learn in favor of other “easier” solutions that are really not standard. (make is)
I hope this small introduction helps you to avoid the pain and allows you to see what a beautiful tool make is! Let me know in the comments if you like this content and you would like to see more like this.
What is make?
When you type on the command prompt you are doing some kind of task using some kind of logic, isn’t it? Well, make is basically made for that, but without you. So automation is the big why on the equation. But let’s do a proper explanation that will help you to understand many of the more advance concepts we will be looking to in this introduction.
Ok, think you become the make program. Let’s also imagine that make program (in this case you) is being used for preparing food recipes…
Let’s imagine that make is a chef, so… you are a chef.
What do you need in order to prepare a nice tomato soup? Well, you will need tomatoes! That will be your main ingredient isn’t it? You will need some other ingredients indeed, but more important you will need tools: A knife to peel the tomatoes and a blender to make them puree. Do we miss something to do a nice tomato soup? Well, we need a good recipe! The difference between a good soup and a bad soup depends on everything, but the recipe you use determines what you are doing. If you don’t follow a recipe you may do tomato slices or a salad, but not tomato soup.
- Ingredients = files and in general any data source.
- Tools = the tools you require for doing a job: a compiler, a parser, a beutifier, a compressor… Basically any program.
- Recipe = basically that is what a makefile is.
How make works?
Now you know what is make and you have a nice simile you may wonder: how does it actually works? Is just like a bash script? What is the difference? And why a makefile looks so different to any programming language?
Ok, make is an interpreter for makefiles. When you type make on your console the program will look into your current working directory for a file called Makefile (other names may be used, but that is the default). That Makefile will be interpreted by make and applied somehow to your current directory. So make is a kind of language. But is not a script.
Make language is defined by 2 main elements: variables and rules.
Variables are like any other language, you can assign them, modify them and pass them around. But there is only one type of variable in make: string. Everything in make is a string, there are no numbers to control loops or to store numeric data because make does not do any numeric calculation. Thinking the cooking simile: Every recipe lists all the ingredients and quantities, but you don’t need to do calculations with them! Any word of a recipe may be considered a variable: tomatoes, 500g, oil… Even tools may be variables: knife, blender, pan…
Rules are the difference with any other language. Rules defines relationships between files as recipes defines relationships between tools and ingredients: Take the tomatoes and use the blender to get a uniform mix.
It is as easy as that!
To get a zip file take the desired file and run ‘zip’ specifying the file as an argument.
Basic make process
Now, make works reading your variables and rules from your makefile and then it applies just the required changes to the state of the system based on the modification dates of every file. Meaning that if a file that depends on other (say a binary that is built from a source) will not be processed if the first is older than the second. Basically if you modify a source file it related binary will be rebuilt but if you execute make a second time the binary will not be rebuilt.
There are other details about make that affect how makefiles needs to be written, but those aren’t in the scope of this introduction. I plan to write more in detail tutorials about make and other tools in a future, so do not hesitate to subscribe to my page!
Just to finish: my personal experience
I use make in my daily life: Before knowing about other projects I used make to automate the initial provisioning of my development environment and it worked more than fine! Basically I was able to generate all the configuration files and even download and install all the required binaries to get my development up and running in a matter of minutes. Also I used it to build (of course!). But where make has the whole potential is in basically any automatic tasks you may imagine. Anything: Cleaning up files, deploying, provisioning, parsing, generating… There are many other tools for automating some processes in an easy way, but make is so agnostic that I can’t think on any automation task that can’t be run by make under Linux.