如何在Android.mk的LOCAL_CFLAGS中动态获取当前的编译器目标文件名? [英] How to dynamically get the current compiler target file name in Android.mk's LOCAL_CFLAGS?

查看:427
本文介绍了如何在Android.mk的LOCAL_CFLAGS中动态获取当前的编译器目标文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Android的NDK构建本机模块.我的项目包含几个源文件(例如: FILENAME .c),对于每个源文件,我都需要在其CFLAGS中声明一个定义( -DOPERATION_FILENAME ).

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

为此,我需要动态获取Android NDK交叉编译器的当前目标文件的名称,并将其用于定义值.

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.

我找不到有关如何执行此操作的任何信息,并且Makefile方式( CFLAGS + = -DOPERATION_ echo $* | sed 's/_$$//' )在这里不适用/不起作用.

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.

我当前的Android.mk如下所示:

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)

有人知道在Android.mk中获取当前交叉编译器目标文件名的有效方法吗?谢谢!

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

推荐答案

Android.mk 的开头,添加重新定义 get-src-file-target-cflags的行,例如此处:

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)

如果愿意,可以将此行放在 Application.mk 中.

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

这篇关于如何在Android.mk的LOCAL_CFLAGS中动态获取当前的编译器目标文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆