makefile1

 

#include "stdio.h"

int main()
{
	printf("LINE: %d\n", __LINE__);
	
	return 0;
}

 

#第一个makefile脚本
#(命令开头是一个Tab不然报错:*** missing separator.  Stop.)
#没有逗号,加逗号不打印$(info,"begin compile")
#首先执行没有缩进的行
A = 1000
B = "BBB"
$(info		A = $(A))
$(info		B: $(B))
$(info		PWD: $(PWD))
$(info		"begin compile")
$(warning	"begin compile")


#在make时没有指定编译哪个,会默认编译默认目标。
#一般Makefile中第一个定义的目标就是默认目标
#因此把最终要生成的目标(hello)写在最前面
#这里 make <==> make hello
#若仅仅生成hello.o,不生成hello可执行文件,make hello.o
#若仅仅清理之前的编译内容, make clean

hello:		hello.o   
	cc   hello.o   -o hello
	$(warning	"linking")
	
hello.o:	hello.c
	gcc -c hello.c -o hello.o
	$(warning	"compiling")
	

	
$(warning	"begin compile")

clean:
	rm -rf hello.o hello
	$(info	"!!!! clean !!!!")

$(warning	"begin compile")

 

 

zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ reset
                                                                        
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
makefile:22: "linking"
cc   hello.o   -o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello  hello.c  hello.o  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make clean
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
"!!!! clean !!!!"
rm -rf hello.o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make hello
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
makefile:22: "linking"
cc   hello.o   -o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello  hello.c  hello.o  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make clean
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
"!!!! clean !!!!"
rm -rf hello.o hello
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ make hello.o
A = 1000
B: "BBB"
PWD: /home/zhenglf/Documents/TEST/makefile/print_echo
"begin compile"
makefile:11: "begin compile"
makefile:31: "begin compile"
makefile:37: "begin compile"
makefile:26: "compiling"
gcc -c hello.c -o hello.o
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ ls
hello.c  hello.o  makefile
zhenglf@hwlnx01:~/Documents/TEST/makefile/print_echo$ 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值