I have a Android native application which builds for platform x86, armeabi and armeabi-v7a. Now depending upon whether the platform is x86 or arm, I need to run the script accordingly with the corresponding arguments so appropriate third party tool environment variables are set. I tried doing below:
.o.cpp:
ifeq ($(TARGET_ARCH),x86)
$(info $(shell ($(CACHE_LOCAL_PATH_MAIN)/setup_tool.sh x86)))
else
$(info $(shell ($(CACHE_LOCAL_PATH_MAIN)/setup_tool.sh arm)))
endif
But the problem is, when the makefile is parsed, these scripts get run in the initial phase itself 3 times and not before compilation of every platform begins. Is there a way to get this fixed so the script gets run just before the compilation for every platform begins? Thanks.
UPDATED with Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \ <path_to_include_files>
LOCAL_CFLAGS := <cflags included here>
LOCAL_LDLIBS := <ld libs included here>
LOCAL_SRC_FILES := <src files to be compiled>
LOCAL_MODULE := <module_name>
LOCAL_SHARED_LIBRARIES := <shared libs on which we are dependent>
LOCAL_WHOLE_STATIC_LIBRARIES := <static libs>
include $(BUILD_SHARED_LIBRARY)
A simple, but not elegant solution is as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \ <path_to_include_files>
LOCAL_CFLAGS := <cflags included here>
LOCAL_LDLIBS := <ld libs included here>
ifeq ($(TARGET_ARCH),x86)
LOCAL_SRC_FILES := /tmp/dummy.x86.c
else
LOCAL_SRC_FILES := /tmp/dummy.arm.c
$(info $(shell ($(CACHE_LOCAL_PATH_MAIN)/setup_tool.sh arm)))
endif
LOCAL_SRC_FILES += <src files to be compiled>
LOCAL_MODULE := <module_name>
LOCAL_SHARED_LIBRARIES := <shared libs on which we are dependent>
LOCAL_WHOLE_STATIC_LIBRARIES := <static libs>
include $(BUILD_SHARED_LIBRARY)
.PHONY: /tmp/dummy.x86.c /tmp/dummy.arm.c
/tmp/dummy.x86.c:
$(CACHE_LOCAL_PATH_MAIN)/setup_tool.sh x86
@touch $@
/tmp/dummy.arm.c:
$(CACHE_LOCAL_PATH_MAIN)/setup_tool.sh arm
@touch $@
One caveat: this will link the library every time, even if nothing changed. You can set dependencies carefully instead of .PHONY
to improve this.