We mentioned pseudo targets, variables, and functions last time.
Let's talk about pseudo targets and variables first: there are not many functions, but they are flexible to use. In other words, they are too complicated to be discussed later.
Let's take a look at an example:
Objs = Main. o. o B. omain: $ (objs) CC-O main $ (objs) Main. o: Main. ha. o:. HB. o: B. h. Phony: cleanclean: Rm-F Main $ (objs)
A pseudo target is a keyword. starting with phony, it indicates that clean is a target. Because we do not generate a clean file, the pseudo target is not a file but a tag, since the target and executable files are generated during compilation, you should be able to delete them all (make clean) for re-compilation,
Objs = Main. o a. o B. O. Phiny: allall: MainMain: $ (objs) CC-O main $ (objs) Main. O: Main. Ha. O: A. HB. O: B. H. Phony: cleanclean: Rm-F Main $ (objs)
If makefile is written in this way, you can use make all to compile all make clean to delete the middleware and generated executable files, this is also the general rule for writing makefile. Of course, there can be more pseudo targets based on project requirements.
Use of Variables
In makefile, the variable is a string where the text is used and is automatically expanded as is. In the above example, the objs variable is used. After the variable is expanded, it is main. o a. o B. O.
$ Is used when the variable is used. It is best to add () or {} $ (objs) before the variable. To represent the true $ character, $ is used,
Foo = $ (phello) phello = $ (Hello) Hello = helloall: Echo $ (FOO)
Make all will print out hello, so it seems that the declaration of variables does not need a certain order, but it looks very difficult. You have to reference Foo to phello and phello defines it under Foo, in this way, if a definition is referenced across N multiple rows, it will not seem so easy.
To avoid the above problems, make uses another variable definition method so that the previous variables cannot use the subsequent variables.
X: = Main. Cy: = $ (x) A. cz: = $ (y) B. C
The value of Z is main. c a. c B. C.
In this case:
Z: = $ (y) B. Cy: = $ (x) A. CX: = Main. c
Then, the value of Z is B. C. Because y is not defined in Z, Y is null by default.
The above is a simple example to look at a layer with makelevel (this refers to when make is nested)
ifeq ($ (makelevel), 0) cur_dir: = $ (shell PWD) whoami :=$ (shell whoami) host_type :=$ (Shell Arch) endif
Foo? = Bar is equivalent to ifeq ($ (origin Foo), undefined) Foo = barendif
? = Indicates that there is no definition in this variable to assign values to the variable, this statement is invalid if the variable has been defined
append variable value
objs = Main. o. o B. oobjs + = C. after oobjs is expanded, it is main. o. o B. o C. O