Make
What is Make?
Stuart Feldman wrote Make at Bell Labs in 1976. The aim was not to rebuild everything. A Makefile keeps a target, a dependency, and a command. The target is the name of the file you get. The dependency is the file that must be ready before that one. The start of a command line must be a tab, not a space. If a space is written, Make stops. The widely used kind on Linux is GNU Make. It puts its own additions on top of old Make. The command itself is another program: a compiler, a script, or a copy.
What is Make used for?
Make is for rebuilding only the part that changed in a large project. It can also tie a small repeated command to one target.
- Rebuilding only the changed file in a C program
- Opening the test by one target name
- Making the cleanup command its own target
- Keeping several steps under one name
What can you do with Make?
With Make you check whether a target is old. If the file has not changed, it does not run the command again. It is not a compiler. You call the compiler inside the line. When the tab or the path is wrong, the build stays quiet or half done. The result has to be read from the Makefile.
Is Make hard to learn?
Writing one target is easy. The difficulty is the tab and the dependency. A space looks like a tab, but Make does not accept it. Not writing the dependency counts an old file as new and skips the command. If the same target is in two places, the last rule runs. If the clock is wrong, Make treats the file as fresh or old.
Advantages and limits
Advantage: the part that did not change is not rebuilt, the rule stays in one file, and the tool is old and widespread. Limit: a tab mistake happens often, and a large Makefile is hard to read. Make is not Cargo and it is not npm. It calls the command you wrote when the time comes.
Basic ideas
A target is the name you want to get. A dependency is the file ready before it. The command is the step itself.
- The target stays on the left of the line
- The command starts with a tab
- A file that did not change is not rebuilt
- make runs the target you name
A short example
This is a short rule that builds one program from two object files. The space in the command line must be a tab.
app: main.o util.o gcc -o app main.o util.o
Common questions
- Is Make a programming language? No. It calls your command if a file is old.
- Are Make and Cargo the same? No. Cargo is for Rust. Make ties the command you wrote to a target.
- Can a command start with a space? No. Traditional Make wants a tab. It does not count a space line as a command.