Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplifying an Android.mk file which build multiple executables

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)

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)

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

like image 975
Adam S Avatar asked Oct 04 '11 17:10

Adam S


1 Answers

You should be able to do something like

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

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

like image 184
Andrey Kamaev Avatar answered Oct 10 '22 21:10

Andrey Kamaev