关于makefile

来源:互联网 发布:免费网络加速软件 编辑:程序博客网 时间:2024/05/28 15:08
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是个伪目标,是所有目标的目标,其功能是编译所有的目标。

1
2
.PHONY:all
all:prog1 prog2 prog3 prog4


要编译prog1 prog2 prog3 prog4 四个目标,我们可以使用 make all 命令来编译所有的目标。
也可以 make prog3单独编译 prog3 目标。

 

$@ 表示目标

$< 表示第一个依赖

 

如果有第二个依赖,第二个依赖可以写成:

 $(word 2, $^) ,其意思是:取所有依赖中的第二个。

$^ 表示所有的依赖

$(word n,text) 函数用来提取 text 中的第 n 个词

 

以上源自:http://bbs.csdn.net/topics/300199783

0 0
原创粉丝点击