我正在为Android构建一些硬件测试。我有一个Android.mk文件,逐个构建这些可执行文件,每个文件使用一块makefile代码,如下所示:
##### shared #####
LOCAL_PATH := $(my-dir)
##### test_number_one #####
test_name := test_number_one
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
##### test_number_two #####
test_name := test_number_two
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
如您所见,每次测试都会重复大部分代码(include $(CLEAR_VARS)
和include $(CLEAR_VARS)
之间)。我想简化这一点,以便我有一个测试名称列表和一段makefile代码,每个代码都被“调用”。我不在乎该代码是否必须拆分成另一个文件。这里有一些python-esque伪代码来演示我的目标:
##### shared #####
LOCAL_PATH := $(my-dir)
##### test_number_one #####
test_names := test_number_one test_numer_two
for each item in test_names:
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(item)
LOCAL_SRC_FILES := tests/$(item)/$(item).c
include $(BUILD_EXECUTABLE)
这可以在Android.mk文件中使用吗?怎么办呢?
答案 0 :(得分:8)
您应该可以执行类似
的操作define my_add_executable
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $1
LOCAL_SRC_FILES := tests/$1/$1.c
include $(BUILD_EXECUTABLE)
endef
test_names := test_number_one test_numer_two
$(foreach item,$(test_names),$(eval $(call my_add_executable,$(item))))
我们的项目中有类似的构造,包括多个预建库。