Makefile
:material-circle-edit-outline: 约 68 个字 :fontawesome-solid-code: 19 行代码
The Makefile utility
- Targets
- Good division to components
- Minimum compilation when something is changed
- Easy maintenance of project structure, dependencies and creation
Note that the Makefile mechanism is not limited to C programs
Project structure
Project structure and dependencies can be represented as a DAG (= Directed Acyclic Graph)
e.g
– Program contains 3 files
– main.c., sum.c, sum.h
– sum.h included in both .c files
– Executable should be the file sum
sum: main.o sum.o
gcc –o sum main.o sum.o
main.o: main.c sum.h gcc –c main.c
sum.o: sum.c sum.h gcc –c sum.c
//Equivalent makefiles
//.o depends (by default) on corresponding .c file.
sum: main.o sum.o
gcc –o sum main.o sum.o
main.o: sum.h gcc –c main.c
sum.o: sum.h gcc –c sum.c