How to dynamically get the current compiler target file name in Android.mk's LOCAL_CFLAGS?

若如初见. 提交于 2019-12-13 02:36:54

问题


I am currently trying to build a native module using Android's NDK. My project consists of several source files (e.g.: FILENAME.c) and for each of them I need to declare a define in their CFLAGS (-DOPERATION_FILENAME).

In order to do that I need to dynamically fetch the name of the current target file of the Android NDK's cross-compiler and use it to for the define value.

I could not find any information about how to do this and the Makefile way (CFLAGS += -DOPERATION_echo $* | sed 's/_$$//') does not apply/work here.

My current Android.mk looks like this:

LOCAL_PATH:=$(call my-dir)

include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_MODULE := libmpn

LOCAL_SRC_FILES := \
<cut>

LOCAL_CFLAGS := \
-std=gnu99 \
-DHAVE_CONFIG_H \
-D__GMP_WITHIN_GMP \
-O2 \
-pedantic \
-fomit-frame-pointer \
-mfloat-abi=softfp \
-DOPERATION_`echo $* | sed 's/_$$//'`

include $(BUILD_SHARED_LIBRARY)

Does anyone know of a working way to get the file name of the current cross-compiler target in Android.mk? Thanks!


回答1:


In the beginning of your Android.mk, add the line that redefines get-src-file-target-cflags, like here:

get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) -DOPERATION_$(basename $1)

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := t.cpp qq.c
LOCAL_MODULE := tm
LOCAL_LDLIBS := -latomic

include $(BUILD_SHARED_LIBRARY)

You can put this line in Application.mk, if you choose.



来源:https://stackoverflow.com/questions/36721648/how-to-dynamically-get-the-current-compiler-target-file-name-in-android-mks-loc

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