Put system headers at the end of the inclusion path.

Change-Id: I1c3eff1efd2d6c375bcaa1e076f9b85b14c5c6b3
diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index feff06a..d693ba4 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -803,7 +803,8 @@
                               $$(LOCAL_C_INCLUDES:%=-I%) \
                               -I$$(LOCAL_PATH) \
                               $$(LOCAL_CFLAGS) \
-                              $$(NDK_APP_CFLAGS)
+                              $$(NDK_APP_CFLAGS) \
+                              $$($(my)C_INCLUDES:%=-I%) \
 
 $$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK)
 	@mkdir -p $$(dir $$(PRIVATE_OBJ))
@@ -865,6 +866,7 @@
                               $$(NDK_APP_CFLAGS) \
                               $$(NDK_APP_CPPFLAGS) \
                               $$(NDK_APP_CXXFLAGS) \
+                              $$($(my)C_INCLUDES:%=-I%) \
 
 $$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK)
 	@mkdir -p $$(dir $$(PRIVATE_OBJ))
diff --git a/build/toolchains/arm-eabi-4.2.1/setup.mk b/build/toolchains/arm-eabi-4.2.1/setup.mk
index 1b02719..a3e2f2f 100644
--- a/build/toolchains/arm-eabi-4.2.1/setup.mk
+++ b/build/toolchains/arm-eabi-4.2.1/setup.mk
@@ -27,7 +27,6 @@
 TOOLCHAIN_PREFIX := $(HOST_PREBUILT)/$(TOOLCHAIN_NAME)/bin/arm-eabi-
 
 TARGET_CFLAGS.common := \
-    -I$(SYSROOT)/usr/include \
     -march=armv5te -mtune=xscale \
     -msoft-float -fpic \
     -mthumb-interwork \
@@ -38,6 +37,8 @@
     -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ \
     -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ \
 
+TARGET_C_INCLUDES := \
+    $(SYSROOT)/usr/include
 
 TARGET_arm_release_CFLAGS :=  -O2 \
                               -fomit-frame-pointer \
diff --git a/build/toolchains/arm-eabi-4.4.0/setup.mk b/build/toolchains/arm-eabi-4.4.0/setup.mk
index 73bb0fc..d177c88 100644
--- a/build/toolchains/arm-eabi-4.4.0/setup.mk
+++ b/build/toolchains/arm-eabi-4.4.0/setup.mk
@@ -27,7 +27,6 @@
 TOOLCHAIN_PREFIX := $(HOST_PREBUILT)/$(TOOLCHAIN_NAME)/bin/arm-eabi-
 
 TARGET_CFLAGS.common := \
-    -I$(SYSROOT)/usr/include \
     -fpic \
     -mthumb-interwork \
     -ffunction-sections \
@@ -37,6 +36,9 @@
     -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ \
     -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ \
 
+TARGET_C_INCLUDES := \
+    $(SYSROOT)/usr/include
+
 # This is to avoid the dreaded warning compiler message:
 #   note: the mangling of 'va_list' has changed in GCC 4.4
 #
diff --git a/build/toolchains/x86-4.2.1/setup.mk b/build/toolchains/x86-4.2.1/setup.mk
index a2e03e3..0dc37c5 100644
--- a/build/toolchains/x86-4.2.1/setup.mk
+++ b/build/toolchains/x86-4.2.1/setup.mk
@@ -27,13 +27,15 @@
 TOOLCHAIN_PREFIX := $(HOST_PREBUILT)/$(TOOLCHAIN_NAME)/bin/i686-android-linux-gnu-
 
 TARGET_CFLAGS.common := \
-    -I$(SYSROOT)/usr/include \
     -msoft-float -fpic \
     -ffunction-sections \
     -funwind-tables \
     -fstack-protector \
     -fno-short-enums
 
+TARGET_C_INCLUDES := \
+    (SYSROOT)/usr/include
+
 TARGET_x86_release_CFLAGS :=  -O2 \
                               -fomit-frame-pointer \
                               -fstrict-aliasing    \
diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT
index 234b92e..23f7c28 100644
--- a/docs/CHANGES.TXT
+++ b/docs/CHANGES.TXT
@@ -59,6 +59,11 @@
 
 OTHER FIXES & CHANGES:
 
+- The path to system headers is now included last in the compilation command
+  line. This prevents conflicts with source code that define their own headers
+  with similar names (e.g. a custom "err.h" was ignored, because the system
+  <err.h> was used instead).
+
 - Update documentation for 'my-dir' function to explain that, due to the
   way GNU Make works, it really returns the path of the last included
   Makefile (instead of the current one). Also provide examples on how