之前没怎么好好看过 Android build系统中的mk,找个命令包开刀和大家分享一下吧
include-path-for
define include-path-for #定义命令包, n 由调用者传递进来, 这个在 build/core/pathmap.mk
$(foreach n,$(1),$(patsubst $(n):%,%,$(filter $(n):%,$(pathmap_INCL))))
endef
// pathmap_INCL 在 build/core/pathmap.mk 文件中有定义,最后使用的时候可以看到
【函数内实现的解析】
foreach 遍历, patsubst 字符串替换, filter 过滤函数
【函数调用】
这里以external\dbus\bus 下的Android.mk 调用为例:
...
LOCAL_C_INCLUDES:= \
$(call include-path-for, dbus)
...
调用命令包 include-path-for ,只有一个入参是 dbus
1. foreach
入参 dbus 替换 $(1), 那么根据 foreach 的语法,就是把字符串 dbus 保持到 n 中