Makefile 中的规则

makefile 规则基本格式

  一条 makefile 规则由以下几部分组成:

target ... : prerequisites ...
  recipe
  ...
  ...

  Please note: you need to put a tab character at the beginning of every recipe line!

 

 

  makefile 没有在命令行中指定执行哪部分时候,第一个 target 会作为最终目标,下边所示的code生成 test_1.o 之后就会结束。

$ cat makefile 
test_1.o : test_1.c gcc -c test_1.c test_2.o : test_2.c gcc -c test_2.c

  下边所示代码中,第一行为生成 test_1.o、 test_2.o 提供规则。也就是说,第一行的 target 不会成为 goal, goal 为 all。

$ cat makefile 
%.o : %.c
    gcc -c -O2 $<

all : test_1.o test_2.o clean: rm *.o

 

makefile 规则隐藏彩蛋

  当最终的goal与prerequisites中某一个文件名相同时,会自动链接生成以该文件名命名的可执行文件。

$ cat Makefile 
TEST_1 := test_1.o

TEST_2 := test_2.o

test_1: $(TEST_1) $(TEST_2)

clean:
    rm *.o

  当一个target 分多次指定 prerequisites 时,多次指定的 prerequisites 都参与 target 的生成。

$ cat Makefile 
test : test_1.o
test : test_2.o

test : test.o

 

makefile 规则中特殊 target(GNU makefile 4.8)

  某些名字作为 target 时有特殊意义。

  • .EXPORT_ALL_VARIABLES  表示将所有的变量传递给下层makefile

 

转载于:https://www.cnblogs.com/rivsidn/p/11006748.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值