build/core/pathmap.mk 文件定义了一个列表pathmap_INCL,列表中每项是"短名:路径"对。宏函数include-path-for将会使用这个列表,来通过短名获取相对于的路径,如:$(call include-path-for,短名) ## A mapping from shorthand names to include directories.# "短名: 路径"对列表pathmap_INCLpathmap_INCL := bluedroid:system/bluetooth/bluedroid/include bluez-libs:external/bluez/libs/include bluez-utils:external/bluez/utils bootloader:bootable/bootloader/legacy/include corecg:external/skia/include/core dbus:external/dbus frameworks-base:frameworks/base/include graphics:external/skia/include/core libc:bionic/libc/include libdrm1:frameworks/base/media/libdrm/mobile1/include libdrm2:frameworks/base/media/libdrm/mobile2/include libhardware:hardware/libhardware/include libhardware_legacy:hardware/libhardware_legacy/include libhost:build/libs/host/include libm:bionic/libm/include libnativehelper:dalvik/libnativehelper/include libpagemap:system/extras/libpagemap/include libril:hardware/ril/include libstdc++:bionic/libstdc++/include libthread_db:bionic/libthread_db/include mkbootimg:system/core/mkbootimg recovery:bootable/recovery system-core:system/core/include ## Returns the path to the requested module"s include directory,# relative to the root of the source tree. Does not handle external# modules.## $(1): a list of modules (or other named entities) to find the includes for#define include-path-for$(foreach n,$(1),$(patsubst $(n):%,%,$(filter $(n):%,$(pathmap_INCL))))endef 上面的宏函数include-path-for使用了3个make内嵌函数:foreach,patsubst,filter。 foreach:它是一个循环函数,类似于Linux的shell中的for语句,语法格式如下:$(foreach VAR, LIST, TEXT)include-path-for宏函数中:VAR = n (是一个临时变量,只在foreach函数上下文中有效)LIST = $(1) ( 是call include-path-for 时传递进来的参数,可以使很多空格隔开的字符串)TEXT = $(patsubst $(n):%,%,$(filter $(n):%,$(pathmap_INCL))) (是每次循环时执行的表达式)foreach函数和c语言中的如下格式的for循环类似:for( int n, int i=0 ; i < number(LIST); i++){n = LIST第一个字符串;执行TEXT(引用n)表达式;LIST丢掉第一个字符串} filter:过滤函数,$(filter PATTERN…,TEXT)过滤掉字串“TEXT”中所有不符合模式“PATTERN”的单词,保留所有符合此模式的单词。可以使用多个模式。模式中一般需要包含模式字符“%”。存在多个模式时,模式表达式之间使用空格分割。sources := foo.c bar.c baz.s ugh.hfoo: $(sources)cc $(filter %.c %.s,$(sources)) -o foo返回值为“foo.c bar.c baz.s”。$(filter $(n):%,$(pathmap_INCL)), 滤除掉pathmap_INCL列表中不属于以:隔开的字符串模式的字符串。