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

本文深入探讨了Makefile中filter函数的使用方法及其在处理文件名匹配模式时的作用,同时展示了静态模式规则如何实现特定文件的自动化处理流程。包括通过实例解释如何筛选文件并进行编译或生成操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续翻译

   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。

后文待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值