Makefile基本结构

Makefile 是Make 读入的惟一配置文件,因此本节的内容实际就是讲述Makefile 的编写
规则。在一个Makefile中通常包含如下内容:
· 需要由make工具创建的目标体(target),通常是目标文件或可执行文件;
· 要创建的目标体所依赖的文件(dependency_file);
· 创建每个目标体时需要运行的命令(command)。

它的格式为:
target: dependency_files
command

例如,有两个文件分别为hello.c 和hello.h,创建的目标体为hello.o,执行的命令为gcc
编译指令:gcc –c hello.c,那么,对应的Makefile就可以写为:
#The simplest example
hello.o: hello.c hello.h
gcc –c hello.c –o hello.o
接着就可以使用make了。使用make的格式为:make target,这样make就会自动读入
Makefile(也可以是首字母小写makefile)并执行对应target 的command 语句,并会找到相
应的依赖文件。如下所示:
[root@localhost makefile]# make hello.o
gcc –c hello.c –o hello.o
[root@localhost makefile]# ls
hello.c hello.h hello.o Makefile
可以看到,Makefile执行了“hello.o”对应的命令语句,并生成了“hello.o”目标体。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值