Android.mk里常见的被调用的方法
我们在阅读Android.mk的时候,我们发现有一些被调用的方法,一般是$(call 方法)这样一个形式调用,比如说我们每个Android.mk文件的开头是设置LOCAL_PATH
LOCAL_PATH:= $(call my-dir)
这里面的my-dir就是一个被调用的方法。
my-dir
my-dir这个方法定义在哪里呢?
find ./ -name "*.mk" | xargs grep "my-dir" --color=auto
# Figure out where we are.
define my-dir
$(strip \
$(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
$(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
$(error my-dir must be called before including any other makefile.) \
, \
$(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
) \
)
endef
这里就是源码了。
all-makefiles-under
某目录下的所有Android.mk文件
源码:
define all-makefiles-under
$(wildcard $(1)/*/Android.mk)
endef
使用$(call all-makefiles-under src)
从代码里我们看到$(1)需要传入一个参数,上面的例子我们传入src,也就是src下的所有Android.mk文件
all-java-files-under
与上面的类似,某目录下的所有的java文件。
当我们去编译的时候,需要指定.java文件,如果一个一个去指定的话会比较麻烦,而且容易出错。
这个时候,调用all-java-files-under即可,某个目录下的所有java文件
define all-java-files-under
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find -L $(1) -name "*.java" -and -not -name ".*") \
)
endef
同理,我们可以改一个AIDL文件的命令来,要不我们AIDL文件也得一个一个手动告诉编译器。但是,AIDL的也是有的:
###########################################################
## Find all files named "I*.aidl" under the named directories,
## which must be relative to $(LOCAL_PATH). The returned list
## is relative to $(LOCAL_PATH).
###########################################################
define all-Iaidl-files-under
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find -L $(1) -name "I*.aidl" -and -not -name ".*") \
)
endef
###########################################################
## Find all of the "I*.aidl" files under $(LOCAL_PATH).
###########################################################
define all-subdir-Iaidl-files
$(call all-Iaidl-files-under,.)
endef
all-subdir-java-files
这个命令其实是调用了上面那个all-java-files-under,只是参数为当前目录
define all-subdir-java-files
$(call all-java-files-under,.)
endef
all-c-files-under和all-subdir-c-files
这些就不再赘述了,同样的道理
###########################################################
## Find all of the c files under the named directories.
## Meant to be used like:
## SRC_FILES := $(call all-c-files-under,src tests)
###########################################################
define all-c-files-under
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find -L $(1) -name "*.c" -and -not -name ".*") \
)
endef
###########################################################
## Find all of the c files from here. Meant to be used like:
## SRC_FILES := $(call all-subdir-c-files)
###########################################################
define all-subdir-c-files
$(call all-c-files-under,.)
endef
其他的话,同学们去看build/core/definitions.mk文件下的内容了。
接下来,同学们可以去看看构建类型