博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GNU make manual 翻译( 一百四十二)
阅读量:6997 次
发布时间:2019-06-27

本文共 2344 字,大约阅读时间需要 7 分钟。

继续翻译

5.7 Recursive Use of `make'===========================Recursive use of `make' means using `make' as a command in a makefile.This technique is useful when you want separate makefiles for varioussubsystems that compose a larger system.  For example, suppose you havea subdirectory `subdir' which has its own makefile, and you would likethe containing directory's makefile to run `make' on the subdirectory.You can do it by writing this:     subsystem:             cd subdir && $(MAKE)or, equivalently, this (*note Summary of Options: Options Summary.):     subsystem:             $(MAKE) -C subdir      You can write recursive `make' commands just by copying this example,but there are many things to know about how they work and why, and abouthow the sub-`make' relates to the top-level `make'.  You may also findit useful to declare targets that invoke recursive `make' commands as`.PHONY' (for more discussion on when this is useful, see *note PhonyTargets::).   For your convenience, when GNU `make' starts (after it has processedany `-C' options) it sets the variable `CURDIR' to the pathname of thecurrent working directory.  This value is never touched by `make'again: in particular note that if you include files from otherdirectories the value of `CURDIR' does not change.  The value has thesame precedence it would have if it were set in the makefile (bydefault, an environment variable `CURDIR' will not override thisvalue).  Note that setting this variable has no impact on the operationof `make' (it does not cause `make' to change its working directory,for example).

5.7 make 的递归使用

===========================

递归是使用 make 意味着在 makefile中把make 当作命令使用。这个技术在你想要一个大系统的每个子系统都有一个单独的makefile时候有用。例如,设想你有一个子目录 subdir ,有自己的makefile, 并且你想要包含此makefile的目录上的makefile来运行,你可以这样写:

subsystem:

cd subdir && $(MAKE)

或者,等价地,这样写(*note Summary of Options: Options Summary.):

subsystem:

$(MAKE) -C subdir
你可以用拷贝这个例子的方式来写自己的递归make 命令,但是也有很多如它们如何工作和为何如此工作以及子make如何和顶级make关联的东西需要知道。你也可以发现,声明激活递归式make指令为.PHONY很有用(若要参考更多相关信息,参见 *note Phony Targets::)。

为了方便起见,当 GNU make 启动(当它处理了任何的 -C 选项),它设置了变量 CURDIR 到当前工作目录。make 不会再改变其值:特别是请注意,如果你从其他目录包含了文件,CURDIR 的值是不会改变的。如果是设置在makefile,优先级别也是一样。

 (缺省地,环境变量 CURDIR 无法覆盖此值)

请注意设置这个值对make 的操作没有影响(它不会导致make 改变当前工作目录)。

后文待续

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/01/2709685.html,如需转载请自行联系原作者

你可能感兴趣的文章
人民币对美元汇率中间价报6.7343元 上调13个基点
查看>>
「每天一道面试题」Hibernate中SessionFactory是否线程安全?
查看>>
韩媒:美驻韩大使要求韩大幅上调防卫费分担额
查看>>
客运压力大 北京地铁4号线、大兴线工作日早高峰将限流
查看>>
中关村硬科技孵化器首次合作建科技成果转化创新平台
查看>>
广州外援斯贝茨被CBA公司停赛4场 罚款10万元
查看>>
福利!给所有需要找工作的小伙伴分享让我印象深刻的的开发面试题(第二部分),朋友们收好哦...
查看>>
React 折腾记 - (5) 记录用React开发项目过程遇到的问题(Webpack4/React16/antd等)
查看>>
Angular 6 + 折腾记 :(11) 写一个挺不靠谱的多少秒/分/时/天前的管道
查看>>
C++ 高性能服务器网络框架设计细节
查看>>
那一定都是你的错!- 一次FastDFS并发问题的排查经历
查看>>
redis限制请求频率及资源隔离
查看>>
详解Condition的await和signal等待/通知机制
查看>>
1206 - 长假之旅,即将开启
查看>>
Flutter 布局(一)- Container详解
查看>>
Log最佳实践
查看>>
App瘦身最佳实践
查看>>
图解 HTTP 的缓存机制 | 实用 HTTP
查看>>
30 天精通 RxJS(26):简易实例 Observable(一)
查看>>
Java和Docker限制的那些事儿
查看>>