4.1. Makefile Basics
- A makefile is built out of a set of targets which we want to build and intermediate targets used in the build process.
- In a makefile, the target is followed by a colon (:), which is then followed by a list of its dependent targets or files (commonly referred to as dependencies).
- Afterwards in a new line, there should be a tab character (and not any other whitespace before or afterwards), followed by the command used to generate the target from the dependencies.
Example
foo: foo.o helper.o gcc -Wall foo.o helper.o -o foo bar: bar.o helper.o gcc -Wall bar.o helper.o -o bar bar.o: bar.c gcc bar.c -c -o bar foo.o: foo.c foo.h gcc -ansi -Wall -c foo.c -o foo.o
- To run make one types: make [target_name]
- If no target is specified the first target in the makefile is used.