title: Controlling compiler flags in the Android NDK?
body: <p>I know I can use <code>LOCAL_CFLAGS</code> to pass arguments to the compiler. However, <code>ndk-build</code> is inserting options after my <code>LOCAL_CFLAGS</code>, and therefore they take precedence. For example, I want to specify <code>-Ofast</code>, but <code>ndk-build</code> adds <code>-O2</code> after my own flags, and since only the last option is the one that has any effect, I'm unable to test my code with certain optimization flags set.</p>
  
  <p>Is there any way to either force my <code>LOCAL_CFLAGS</code> to be the last options on the build command, or to disable <code>ndk-build</code> from using certain flags?</p>
  
  <p>For example, my <code>LOCAL_CFLAGS</code> is set to:</p>
  
  <pre><code>-Wall -Wno-psabi -Ofast -D CP_USE_DOUBLES=0 -D USE_CHIPMUNK
  </code></pre>
  
  <p>And the call to <code>g++</code> that <code>ndk-build</code> makes is:</p>
  
  <blockquote>
    <p><code>/Library/Android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/native-activity/Main.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Ijni -Ijni/Chipmunk/include/chipmunk -I/Library/Android/android-ndk-r8b/sources/android/native_app_glue -I/Library/Android/android-ndk-r8b/sources/cxx-stl/stlport/stlport -I/Library/Android/android-ndk-r8b/sources/cxx-stl//gabi++/include -Ijni -DANDROID -Wall -Wno-psabi -Ofast -D CP_USE_DOUBLES=0 -D USE_CHIPMUNK -Wa,--noexecstack  -frtti  -O2 -DNDEBUG -g   -I/Library/Android/android-ndk-r8b/platforms/android-9/arch-arm/usr/include -c  jni/Main.cpp -o ./obj/local/armeabi-v7a/objs/native-activity/Main.o</code></p>
  </blockquote>
  
  <p>There's a lot in there, but specifically notice that it first specifies <code>-Os</code>, then there's my <code>-Ofast</code>, and then after that there's <code>-O2</code>. Why it specifies <code>-Os</code> if it's going to later say <code>-O2</code>, I don't know, but I'm frustrated my <code>-Ofast</code> is being overridden.</p>