Makefile 的规则格式是这样的
1
2
3
4
|
target ... : prerequisites ...
command
...
...
|
比如 lz 要把一个 hello.cpp 文件编译成 hello
1
2
3
4
5
6
7
|
all : hello another
hello : hello.cpp
g++ -o $@ $<
another : another.cpp
g++ -o $@ $<
|
直接 make 或 make all 的话会执行 hello.cpp 和 another.cpp 的编译命令
后面不加参数的话,会把第一个目标作为默认的
make hello 的话只编译 hello.cpp
make another 的话只编译 another.cpp
all : p1 p2 p3
.PHONY : all
这样在编译以后,不会生成all文件,但是p1,p2,p3都会生成。