makefile

***本文是参考   linux内核完全注释.pdf  写的***

简单的makefile文件包含一些规则,规则形式如下

目标(target).. :  先决条件(prerequisites)...

\t  命令(command)

\t ...

注: 命令必须以tab键开始.

1. 自动变量: 在命令行上根据具体情况能被自动替换的变量,在命令执行前被替换。

例如: '$^' 的值表示规则的所有先决条件,包括他们所处的目录的名称;‘$<’表示规则的第一个先决条件;'$@'表示目标对象

例如:

foo.o : foo.c defs.h hack.h
    cc -c $(CFLAGS) $< -o $@
$<将被替换成foo.c , $@将被替换成foo.o


2. as86, ld86简介

汇编编译工具(as86)和链接工具(ld86)

例子:  

// @filename hello.c
// for makefile and as ld
int main()
{
    printf("hello\n");
    return 0;
}
// @filename Makefile
// for make
hello: hello.c
    gcc -o $@ -Wall -Werror $< -g
执行

#make; ./hello                             // 输出hello

gcc -S hello.c            // 生成hello.s

as hello.s -o hello.o

ld -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o -lc hello.o -o hello

./hello     //  输出hello



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值