With this simple makefile file column
# 生成可执行文件main
main:main.o
cc -o main main.o
# 生成main.o对象文件
main.o:main.c
cc -c main.c
# 清除指令,删除执行过程中生成的文件
# 伪目标
.PHONY:clean
clean:
rm main main.o
Rule format
target...:prerequisites...
<tab> command
- target: target
- prerequisites: dependent files
- command: Command
1. explore the role of target and prerequisite of
- carried out
make main.o
- Run Log
cc -c main.c
- Main.o generated file
- Run Log
- Executed again
make mian.o
- Run Log
'main.o' is up to date
, it is up to date of the
- Run Log
- After modifying the file main.c
- Run Log
cc -c main.c
- Main.o generated file
- Run Log
- Modify the makefile to
main.o:
cc -c main.c
- carried out
make mian.o
- Run Log
cc -c main.c
- Main.o generated file
- Run Log
- carried out
make mian.o
- Run Log
cc -c main.c
- Main.o generated file
6. Modify the makefile to
- Run Log
main:main.c
cc -c main.c
- 4,5 conclusions and results of the same
in conclusion
- When the target is the name of the target file is generated, the target will Makefile file name corresponding to the file dependent, and last modification time comparison, determines whether to execute the command to generate a new file, to avoid repeatedly performing
- Not set dependency file name is not a target or destination file name does not affect the target instruction execution
2. The problem of pseudo target
Some say pseudo target on the blog do not generate the target file is used
to clean the column above target
- There are
.PHONY:clean
time code executionmake clean
- Delete command is executed, the file does not generate clean
- Deleted
.PHONY:clean
after the code, execute commands, and no clean files
in conclusion
- Pseudotarget no effect
- When the target file name itself does not produce, not a destination file name, the name only serve as a method of action
3. With regard to obscure rule
- Delete the code
main.o:main.c
cc -c main.c
- Execution make
- Journal
cc -c -o main.o main.c
- Journal
cc -o run main.o
- Journal
Conclusion
C compilation process, when there are .o file depends on if there is no explicit rule generates .o file, makefile will auto-complete command generating .o
ps: If you have questions and would like to welcome the king of mutual encouragement exchange
Reproduced in: https: //www.jianshu.com/p/e521f09d1b28