GNU make manual 翻译( 一百一十九)

继续翻译

   Each target specified must match the target pattern; a warning is
issued for each target that does not.  If you have a list of files,
only some of which will match the pattern, you can use the `filter'
function to remove nonmatching file names (*note Functions for String
Substitution and Analysis: Text Functions.):

     files = foo.elc bar.o lose.o

     $(filter %.o,$(files)): %.o: %.c
             $(CC) -c $(CFLAGS) $< -o $@
     $(filter %.elc,$(files)): %.elc: %.el
             emacs -f batch-byte-compile $<

In this example the result of `$(filter %.o,$(files))' is `bar.o
lose.o', and the first static pattern rule causes each of these object
files to be updated by compiling the corresponding C source file.  The
result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
from `foo.el'.

   Another example shows how to use `$*' in static pattern rules: 

     bigoutput littleoutput : %output : text.g
             generate text.g -$* > $@

When the `generate' command is run, `$*' will expand to the stem,
either `big' or `little'.

每一个指定的目的必须匹配目的模式;不匹配的目的会生成一个警告。如果你有一列文件,只有一部分将要匹配模式,你可以使用 filter 函数来移出不匹配的文件名(*note Functions for String Substitution and Analysis: Text Functions.):

files = foo.elc bar.o lose.o

$(filter %.o,$(files)): %.o: %.c
  $(CC) -c $(CFLAGS) $< -o $@


$(filter %.elc,$(files)): %.elc: %.el
  emacs -f batch-byte-compile $<

在这个例子中,$(filter %.o,$(files)) 保留下来的结果是 bar.o 和 lose.o, 第一个静态模式规则使得通过编译相应的C 源文件,生成目标文件。$(filter %.elc,$(files)) 保留下来的结果是foo.elc, 因此此foo.el 文件被生成。

另外一个例子显示了如何在静态模式规则中适用 $*:

bigoutput littleoutput : %output : text.g
generate text.g -$* > $@

当 generate 命令运行的时候, $* 将会展开为枝干,或者是big 或者是 little。

后文待续

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