Android NDK: How to get compiler architecture in Android.mk dynamically

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I'm trying to configure Android.mk to cross compile native code to support different chipset namely armeabi, mips, and x86. I know I can configure Application.mk in the following way to compile the source code for different chip set:

APP_ABI := all 

This will trigger Android-NDK's build script to compile the source code for all the chipsets. However, I want to dynamically tell Android.mk to look for different static library dependencies compiled with different chip set.

# Get the architecture info ARCH := ????  include $(CLEAR_VARS) LOCAL_MODULE:= mylib LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) include $(PREBUILT_STATIC_LIBRARY) 

Is this possible to do? If so, can anyone advice how to do so?

Update: I tried something like this in Application.mk:

 APP_ABI := armeabi armeabi-v7a mips x64 

with Android.mk:

# Get the architecture info ARCH := $(APP_ABI)  include $(CLEAR_VARS) LOCAL_MODULE:= mylib LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) include $(PREBUILT_STATIC_LIBRARY) 

but it errors with the following:

 The LOCAL_SRC_FILES for a prebuilt static library should only contain one item 

which makes sense. I want to pass APP_ABI := all in Application.mk and be able to dynamically reference it. Any ideas?

回答1:

There is TARGET_ARCH variable that holds the value of the current ABI being built. You can use it the following way:

ifeq ($(TARGET_ARCH),x86)     LOCAL_CFLAGS   := $(COMMON_FLAGS_LIST) else     LOCAL_CFLAGS   := -mfpu=vfp -mfloat-abi=softfp $(COMMON_FLAGS_LIST) endif 

If you specify APP_ABI := armeabi-v7a armeabi mips x86 or APP_ABI := all in your Application.mk you will get each and every separate ABI value.



回答2:

Check TARGET_ARCH_ABI:

ifeq($(TARGET_ARCH_ABI), armeabi-v7a)   # v7a-specific stuff endif 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!