Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Per-file CPPFLAGS in Android.mk

I'm working on an Android.mk file in which, for a single module, one of the files needs different CPPFLAGS; namely, it needs -frtti enabled, while others need the Android default of -fno-rtti.

The obvious solution was target-specific variables, but oddly they do not seem to affect compilation, even with some fiddling to ensure the values should be fixed at the right time.

Here's an extract from my Android.mk (names changed to protect me):

LOCAL_MODULE := foo_bar

LOCAL_SRC_FILES := \
    foo_bar.cpp \
    foo_baz.cpp

my_intermediates:= $(local-intermediates-dir)/foo_baz.o
$(my_intermediates): LOCAL_CPPFLAGS := -frtti

I have tried simply doing foo_baz.o: in lieu of $(my_intermediates), and have tried substituting += for := to no change.

So, is there an Android-specific way to override CPPFLAGS (or CFLAGS) for a specific source file?

(In this case I'm using the Eclair Android sources, though it may apply to the NDK; see my answer, below.)

like image 715
Arthur Shipkowski Avatar asked Sep 16 '11 16:09

Arthur Shipkowski


People also ask

What is Android.mk file in Android?

The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.

What is Makefile mk?

The . mk extension is a more or less standard extension for make files that have other names than the defaults. It is a reasonable extension if you want humans to quickly understand what these files are: convert.mk is more informative than foobar .

What is Ndk_project_path?

NDK_PROJECT_PATH - the location of your project NDK_APPLICATION_MK - the path of the Application.mk file APP_BUILD_SCRIPT - the path to the Android.mk file. These are needed to override the default values of the build script, which expects things to be in the jni folder.


1 Answers

As is usual, having asked the question after spending a lot of time on it, I have found the answer in short order. I need to use PRIVATE_CPPFLAGS instead of LOCAL_CPPFLAGS.

However, this only appears to be the case for the Android source distribution (at least Eclair) and NDK r6b. If I was using NDK r6, this probably would have worked as it stands.

like image 100
Arthur Shipkowski Avatar answered Oct 04 '22 20:10

Arthur Shipkowski