The notes are from learning of Gnu Make Manual V0.70 for Gun Make version 3.81, which can be referred to http://www.gnu.org/software/make/manual/make.htm
1. Makefile basic syntax
Rule
target ... : prerequisites ...
command
...
...
Usually target is t the object name or executable file name, but it can also be the action name. Make doesn't do anything for the action rule unless you tell it explicitely.
You need to put a tab at the begining of every command line.
By default, the first rule in make file is the DEFAULT GOAL. Only the main goal will be processed.
If the prerequisites files are more recent than target file, or target file doesn't exist, the command needs to be called.
The make process the rules for the files that target depends on firstly.
2. Variables
They are used to simplify the make file.
Definition:
variable = a.o b.o c.o
Usage:
foo.exe:$(variable)
cc -o foo.exe $(variable)
It is necessary to use .PHONY to explicitly indicate a phony rule, which can avoid conflict with file of the same name.
.PHONY:clean
3. Not necessary to write source compile command
By default, make can automatically call source compile command for .o targeted rule, and also consider associated .c file into prerequistes.
e.g.
main.o:main.c main.h
cc -c main.c
equals
main.o:main.h
Gnu Make Learning notes 1
最新推荐文章于 2022-04-01 18:58:50 发布