Linux 下:
BuildUtility.mk
###########################################################
## Debugging; prints a variable list to stdout
###########################################################
# $(1): variable name list, not variable values
define print-vars-ex
$(foreach var,$(1), \
$(info $(var):) \
$(foreach word,$($(var)), \
$(info $(space)$(space)$(word)) \
) \
)
endef
###########################################################
## Evaluates to true if the string contains the word true,
## and empty otherwise
## $(1): a var to test
###########################################################
define true-or-empty-ex
$(filter true, $(1))
endef
###########################################################
## Find all of the c files under the named directories.
## Meant to be used like:
## SRC_FILES := $(call all-c-files-under-ex,src tests)
###########################################################
define all-c-files-under-ex
$(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-ex)
###########################################################
define all-subdir-c-files-ex
$(call all-c-files-under-ex,.)
endef
###########################################################
## Find all of the cpp files under the named directories.
## Meant to be used like:
## SRC_FILES := $(call all-cpp-files-under-ex,src tests)
###########################################################
define all-cpp-files-under-ex
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find -L $(1) -name "*.cpp" -and -not -name ".*") \
)
endef
###########################################################
## Find all of the cpp files from here. Meant to be used like:
## SRC_FILES := $(call all-subdir-cpp-files)
###########################################################
define all-subdir-cpp-files-ex
$(call all-cpp-files-under-ex,.)
endef
###########################################################
## Find all of the java files under the named directories.
## Meant to be used like:
## SRC_FILES := $(call all-java-files-under-ex,src tests)
###########################################################
define all-java-files-under-ex
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find -L $(1) -name "*.java" -and -not -name ".*") \
)
endef
###########################################################
## Find all of the java files from here. Meant to be used like:
## SRC_FILES := $(call all-subdir-java-files-ex)
###########################################################
define all-subdir-java-files-ex
$(call all-java-files-under-ex,.)
endef
在 Android.mk 中,加入这句(BuildUtility.mk 放在Android.mk同目录下)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/BuildUtility.mk
Windows 下:
在 Android.mk 中,加入
ALL_CPP_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
ALL_CPP_LIST += $(wildcard $(LOCAL_PATH)/src/*.cpp)
LOCAL_SRC_FILES := $(ALL_CPP_LIST:$(LOCAL_PATH)/%=%)
Windows 中没有完全实现自己包含 *.cpp 要自己加目录,如上面的 "src"。