ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Makefile 中的规则

2019-06-13 21:38:19  阅读:227  来源: 互联网

标签:... target prerequisites Makefile makefile TEST 规则 test


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

 

标签:...,target,prerequisites,Makefile,makefile,TEST,规则,test
来源: https://www.cnblogs.com/rivsidn/p/11006748.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有