6

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?

1
  • If the flags don't change, you don't need to re-init them no? Commented Oct 4, 2011 at 17:25

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.