Add LOCAL_C_INCLUDES to the source directory search path for ndk-gdb.

Also fix clean parallel builds of debuggable applications.

Change-Id: I5a22b4b7b6104cf46780f275b713230f444f3493
diff --git a/build/core/build-module.mk b/build/core/build-module.mk
index fca1371..a72fc21 100644
--- a/build/core/build-module.mk
+++ b/build/core/build-module.mk
@@ -49,8 +49,5 @@
 	$(hide) rm -rf $(PRIVATE_CLEAN_FILES)
 
 ifeq ($(NDK_APP_DEBUGGABLE),true)
-$(NDK_APP_GDBSETUP):: PRIVATE_DIR := $(LOCAL_PATH)
-$(NDK_APP_GDBSETUP)::
-	@echo "Gdbsetup       : + source directory $(PRIVATE_DIR)"
-	$(hide) echo "directory $(PRIVATE_DIR)" >> $(PRIVATE_DST)
+$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS += $(LOCAL_C_INCLUDES) $(LOCAL_PATH)
 endif
diff --git a/build/core/setup-toolchain.mk b/build/core/setup-toolchain.mk
index 88650d8..1f6e29e 100644
--- a/build/core/setup-toolchain.mk
+++ b/build/core/setup-toolchain.mk
@@ -79,6 +79,8 @@
 # compute NDK_APP_DST_DIR as the destination directory for the generated files
 NDK_APP_DST_DIR := $(NDK_APP_PROJECT_PATH)/libs/$(TARGET_ARCH_ABI)
 
+clean-installed-binaries::
+
 # Ensure that for debuggable applications, gdbserver will be copied to
 # the proper location
 ifeq ($(NDK_APP_DEBUGGABLE),true)
@@ -100,19 +102,19 @@
 NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup
 installed_modules: $(NDK_APP_GDBSETUP)
 
-$(NDK_APP_GDBSETUP)::
+$(NDK_APP_GDBSETUP): PRIVATE_DST := $(NDK_APP_GDBSETUP)
+$(NDK_APP_GDBSETUP): PRIVATE_SOLIB_PATH := $(TARGET_OUT)
+$(NDK_APP_GDBSETUP): PRIVATE_SRC_DIRS := $(SYSROOT)/usr/include
+
+$(NDK_APP_GDBSETUP):
 	@ echo "Gdbsetup       : $(PRIVATE_DST)"
 	$(hide) echo "set solib-search-path $(PRIVATE_SOLIB_PATH)" > $(PRIVATE_DST)
-	$(hide) echo "directory $(SYSROOT)/usr/include" >> $(PRIVATE_DST)
+	$(hide) echo "directory $(call uniq,$(PRIVATE_SRC_DIRS))" >> $(PRIVATE_DST)
 
-$(NDK_APP_GDBSETUP):: PRIVATE_DST := $(NDK_APP_GDBSETUP)
-$(NDK_APP_GDBSETUP):: PRIVATE_SOLIB_PATH := $(TARGET_OUT)
-$(NDK_APP_GDBSETUP):: PRIVATE_SRC_DIRS := $(SYSROOT)/usr/include
-
+# This prevents parallel execution to clear gdb.setup after it has been written to
+$(NDK_APP_GDBSETUP): clean-installed-binaries
 endif
 
-clean-installed-binaries::
-
 # free the dictionary of LOCAL_MODULE definitions
 $(call modules-clear)
 
diff --git a/docs/ANDROID-MK.TXT b/docs/ANDROID-MK.TXT
index f2dc180..fd162dc 100644
--- a/docs/ANDROID-MK.TXT
+++ b/docs/ANDROID-MK.TXT
@@ -443,6 +443,9 @@
     These are placed before any corresponding inclusion flag in
     LOCAL_CFLAGS / LOCAL_CPPFLAGS
 
+    The LOCAL_C_INCLUDES path are also used automatically when
+    launching native debugging with ndk-gdb.
+
 
 LOCAL_CFLAGS
     An optional set of compiler flags that will be passed when building
@@ -462,6 +465,12 @@
           match the full Android build system behaviour. (You can use
           LOCAL_CPPFLAGS to specify flags for C++ sources only now).
 
+    It is possible to specify additional include paths with
+    LOCAL_CFLAGS += -I<path>, however, it is better to use LOCAL_C_INCLUDES
+    for this, since the paths will then also be used during native
+    debugging with ndk-gdb.
+
+
 LOCAL_CXXFLAGS
     An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete
     as it may disappear in future releases of the NDK.
diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT
index af53258..5f27587 100644
--- a/docs/CHANGES.TXT
+++ b/docs/CHANGES.TXT
@@ -49,6 +49,14 @@
 
   See docs/IMPORT-MODULE.TXT for details.
 
+- Add the content of LOCAL_C_INCLUDES to gdb.setup to make native debugging
+  easier. Also fixes an issue that prevented clean parallel builds of debuggable
+  applications to work correctly. This fixes an error message that said:
+
+      /bin/sh: <project>/libs/armeabi/gdb.setup: No such file or directory
+
+  When doing a "ndk-build -j<number>", with <number> bigger than 1.
+
 OTHER FIXES & CHANGES:
 
 - Update documentation for 'my-dir' function to explain that, due to the