曲径通幽论坛

标题: filter-out -- 反过滤函数 [打印本页]

作者: beyes    时间: 2010-12-9 18:45
标题: filter-out -- 反过滤函数
格式:
$(filter-out <pattern...>,<text>)
说明:
以 <pattern> 模式过滤 <text> 字符串中的单词,去除符合模式 <pattern> 的单词。返回不符合模式 <pattern> 的字符串。如果 <text> 是 <pattern> 一样或者是其子集,那么返回空。
如:
objs = hello.c world.c are.c you.c ok.c

new = hello.c world.c are.c you.c ok.c add.c
all:
        @echo $(filter-out $(new), $(objs))
运行输出时为空。当 new 改为和 objs 一样时,同样输出为空。当 new 改为hello.c world.c are.c you.c 时,输出 ok.c 。

再做一个实验,如果 new 中包含的字符串比 objs 中的还是少一个 ok.c ,但是字符串的顺序和 ojbs 中的不一样,那结果是不是仍然输出 ok.c 呢?答案是一定的!这一无关顺序的“智能”特性比较重要,像在内核 Makefile 的参数检查中(比较新旧编译选项是否一样)就体现了这一点,如在 script/Kbuild.include 中对arg-check 的定义体现了这一点:
arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
                    $(filter-out $(cmd_$@),   $(cmd_$(1))) )





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2