且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GNU make manual 翻译( 一百七十四)

更新时间:2022-09-15 22:17:58

继续翻译

GNU make manual 翻译( 一百七十四)
6.14 Other Special Variables
============================

GNU `make' supports some variables that have special properties.

`MAKEFILE_LIST'
     Contains the name of each makefile that is parsed by `make', in
     the order in which it was parsed.  The name is appended just
     before `make' begins to parse the makefile.  Thus, if the first
     thing a makefile does is examine the last word in this variable, it
     will be the name of the current makefile.  Once the current
     makefile has used `include', however, the last word will be the
     just-included makefile.

     If a makefile named `Makefile' has this content:

          name1 := $(lastword $(MAKEFILE_LIST))

          include inc.mk

          name2 := $(lastword $(MAKEFILE_LIST))

          all:
                  @echo name1 = $(name1)
                  @echo name2 = $(name2)

     then you would expect to see this output:

          name1 = Makefile
          name2 = inc.mk
GNU make manual 翻译( 一百七十四)

6.14 其他的特殊变量
============================

GNU make 支持某些拥有特殊属性的变量

`MAKEFILE_LIST'

包含被make 解析的每一个makefile的名字,按照其被解析的顺序来罗列。在make 开始解析makefile之前,makefile的名字被追加近来。因此如果一个makefile所作的第一件事情是检查此变量中的最后一个单词,那么它将是当前的makefile。当当前的makefile使用了 include,那么最后一个单词将会是被包含的makefile的名字。

如果一个名为`Makefile' 的makefile包含了如下的内容:

name1 := $(lastword $(MAKEFILE_LIST))

include inc.mk

name2 := $(lastword $(MAKEFILE_LIST))

all:
@echo name1 = $(name1)
@echo name2 = $(name2)

那么,你将要看到如下的输出:

name1 = Makefile
name2 = inc.mk

 

后文待续





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