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.)
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With