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

继续翻译

7.3 Conditionals that Test Flags
================================

You can write a conditional that tests `make' command flags such as
`-t' by using the variable `MAKEFLAGS' together with the `findstring'
function (*note Functions for String Substitution and Analysis: Text
Functions.).  This is useful when `touch' is not enough to make a file
appear up to date.

   The `findstring' function determines whether one string appears as a
substring of another.  If you want to test for the `-t' flag, use `t'
as the first string and the value of `MAKEFLAGS' as the other.

   For example, here is how to arrange to use `ranlib -t' to finish
marking an archive file up to date:

     archive.a: ...
     ifneq (,$(findstring t,$(MAKEFLAGS)))
             +touch archive.a
             +ranlib -t archive.a
     else
             ranlib archive.a
     endif

The `+' prefix marks those recipe lines as "recursive" so that they
will be executed despite use of the `-t' flag.  *Note Recursive Use of
`make': Recursion.

7.3 测试标志的条件式
================================

你可以写一个测试 make 命令标志的条件式,如通过使用findstring函数处理变量 MAKEFLAGS 来测试标志 -t (*note Functions for String Substitution and Analysis: Text Functions.)。

findstring 函数决定是否一个字符串作为子串出现在另一个字符串中。如果你想要测试 -t 标志,使用t 作为findstring的第一个参数,MAKEFLAGS 作为另一个参数。

例如,这里有一个如何使用 ranlib -t 来 完成 标记某个库为最新的例子:

archive.a: ...
ifneq (,$(findstring t,$(MAKEFLAGS)))
+touch archive.a
+ranlib -t archive.a
else
ranlib archive.a
endif

+前缀标记那些片段行为递归,因此无论是否使用了-t 标记,它们都将会被执行。*Note Recursive Use of make: Recursion.

后文待续

原文地址:https://www.cnblogs.com/gaojian/p/2716181.html