makefile语法

target ... : prerequisites ...
	command
	...
	...

#e.g.
cc = gcc
prom = calc
deps = calc.h
obj = main.o getch.o getop.o stack.o
$(prom): $(obj)
    $(cc) -o $(prom) \
	$(obj)

main.o: main.c $(deps)
    $(cc) -c main.c

...
clean:
    #rm -rf /*	#hhh

\ : 换行符
target: 一个object file(目标文件),也可以是一个执行文件,被认为是这条语句所要处理的对象。
prerequisites: 依赖关系表,要生成那个target所需要的文件或是目标。这些文件只要有一个发生了变化,就会触发该语句的command。
command: make需要执行的命令。(任意的shell命令)

在第二行的command命令之前必须要有一个tab缩进。语法规定Makefile中的任何命令之前都必须要有一个tab缩进,否则make就会报错。

make 会比较targets文件和prerequisites文件的修改日期,如果prerequisites文件的日期要比targets文件的日期要新,或者target不存在的话,那么,make就会先执行后续定义的命令。
而对于clean,没有被第一个目标文件直接或间接关联(无prerequisites),那么它后面所定义的命令将不会被自动执行

# e.g
HttpServer: HttpServer.o Socket.o EventLoopThreadPool.o EventLoopThread.o
	g++ -std=c++11 -pthread -o HttpServer HttpServer.o Socket.o EventLoopThreadPool.o EventLoopThread.o

HttpServer.o: HttpServer.cpp Socket.h EventLoopThreadPool.h EventLoopThread.h EventLoop.h
	g++ -std=c++11 -c -pthread HttpServer.cpp EventLoopThreadPool.cpp EventLoopThread.cpp EventLoop.cpp

Socket.o: Socket.cpp Socket.h 
	g++ -std=c++11 -c -pthread Socket.cpp

EventLoopThreadPool.o: EventLoopThreadPool.cpp EventLoopThread.h 
	g++ -std=c++11 -c -pthread EventLoopThreadPool.cpp EventLoopThread.cpp

EventLoopThread.o: EventLoopThread.cpp EventLoopThread.h EventLoop.h Thread.h 
	g++ -std=c++11 -c -pthread EventLoopThread.cpp EventLoop.cpp Thread.cpp

clean:
	rm *.o HttpServer

https://blog.csdn.net/weixin_38391755/article/details/80380786

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值