简化其建立多个可执行文件的Andr​​oid.mk文件 [英] Simplifying an Android.mk file which build multiple executables

查看:132
本文介绍了简化其建立多个可执行文件的Andr​​oid.mk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一些硬件测试,为Android。我有一个接一个建立这些可执行文件的Andr​​oid.mk文件,使用的makefile code的每一个块,如下图所示:

I am building some hardware tests for Android. I have an Android.mk file which builds these executables one-by-one, using a block of makefile code for each, as shown below:

##### 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)

正如你所看到的,大多数的code重复每个测试(之间的包括$(CLEAR_VARS)包括$ (CLEAR_VARS))。我想简化,使得我有测试名称的列表和Makefile文件code这是'叫'为每一个部分。我不在乎,如果code必须拆分成另外一个文件。下面是一些Python式的伪code证明什么,我去为:

As you can see, the majority of the code is repeated for each test (between include $(CLEAR_VARS) and include $(CLEAR_VARS)). I would like to simplify this such that I have a list of test names and a section of makefile code which is 'called' for each one. I don't care if that code must be split into another file. Here's some python-esque pseudocode to demonstrate what I am going for:

##### 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文件,这可能吗?怎样才能做到呢?

Is this possible in Android.mk files? How can it be done?

推荐答案

您应该能够做到像

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))))

我们也有类似的建筑在我们的项目中包括多个prebuilt库。

We have similar construction in our project to include multiple prebuilt libraries.

这篇关于简化其建立多个可执行文件的Andr​​oid.mk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆