1

我有一个为 x86、armeabi 和 armeabi-v7a 平台构建的 Android 本机应用程序。现在取决于平台是 x86 还是 arm,我需要使用相应的参数相应地运行脚本,以便设置适当的第三方工具环境变量。我试着在下面做:

.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

但问题是,当解析生成文件时,这些脚本会在初始阶段本身运行 3 次,而不是在每个平台开始编译之前。有没有办法解决这个问题,以便在每个平台的编译开始之前运行脚本?谢谢。

使用 Android.mk 文件更新

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

1 回答 1

1

一个简单但不优雅的解决方案如下:

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 $@

一个警告:这将每次都链接库,即使没有任何改变。您可以仔细设置依赖项,而不是.PHONY对此进行改进。

于 2016-04-12T21:20:07.150 回答