Add include path and deal with the case that "-p" flag on path is unspecified.

Change-Id: I592b23ac1e08b62088a9a9e1bfc8109b56929386
diff --git a/slang.cpp b/slang.cpp
index 46b6578..39938fc 100644
--- a/slang.cpp
+++ b/slang.cpp
@@ -1,4 +1,7 @@
 #include "slang.hpp"
+
+#include <stdlib.h>                     /* for getenv */
+
 #include "libslang.h"
 
 #include "llvm/ADT/Twine.h"     /* for class llvm::Twine */
@@ -91,6 +94,35 @@
     return;
 }
 
+void Slang::createPreprocessor() {
+  HeaderSearch* HS = new HeaderSearch(*mFileMgr); /* Default only search header file in current dir */
+
+  mPP.reset(new Preprocessor( *mDiagnostics,
+                              LangOpts,
+                              *mTarget,
+                              *mSourceMgr,
+                              *HS,
+                              NULL,
+                              true /* OwnsHeaderSearch */));
+  /* Initialize the prepocessor */
+  mPragmas.clear();
+  mPP->AddPragmaHandler(NULL, new PragmaRecorder(mPragmas));
+
+  /* Like ApplyHeaderSearchOptions in InitHeaderSearch.cpp */
+  const char*inclDir = getenv("ANDROID_BUILD_TOP");
+
+  printf("%s\n", inclDir);
+  if (inclDir) {
+    std::vector<DirectoryLookup> SearchList;
+    if (const DirectoryEntry *DE = mFileMgr->getDirectory(inclDir, inclDir + strlen(inclDir))) {
+      SearchList.push_back(DirectoryLookup(DE, SrcMgr::C_System, false, false));
+      HS->SetSearchPaths(SearchList, 1, false);
+    }
+  }
+
+  return;
+}
+
 Slang::Slang(const char* Triple, const char* CPU, const char** Features) :
     mOutputType(SlangCompilerOutput_Default),
     mAllowRSPrefix(false)
diff --git a/slang.hpp b/slang.hpp
index 26e823b..7883ebb 100644
--- a/slang.hpp
+++ b/slang.hpp
@@ -85,21 +85,7 @@
 
     /* The preprocessor (source code preprocessor) */
     llvm::OwningPtr<Preprocessor> mPP;
-    inline void createPreprocessor() {
-        HeaderSearch* HeaderInfo = new HeaderSearch(*mFileMgr); /* Default only search header file in current dir */
-        mPP.reset(new Preprocessor( *mDiagnostics,
-                                    LangOpts,
-                                    *mTarget,
-                                    *mSourceMgr,
-                                    *HeaderInfo,
-                                    NULL,
-                                    true /* OwnsHeaderSearch */));
-        /* Initialize the prepocessor */
-        mPragmas.clear();
-        mPP->AddPragmaHandler(NULL, new PragmaRecorder(mPragmas));
-        /* ApplyHeaderSearchOptions */
-        return;
-    }
+    void createPreprocessor();
 
     /* The AST context (the context to hold long-lived AST nodes) */
     llvm::OwningPtr<ASTContext> mASTContext;
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp
index acd93d9..9f4d14c 100644
--- a/slang_rs_reflection.cpp
+++ b/slang_rs_reflection.cpp
@@ -428,7 +428,12 @@
             }
         }
 
-        _path.insert(0, mRSContext->getReflectJavaPathName());
+        std::string prefix = mRSContext->getReflectJavaPathName();
+        if (prefix.empty()) {
+            _path.insert(0, 1, '.');
+        } else {
+            _path.insert(0, mRSContext->getReflectJavaPathName());
+        }
 
         _mkdir(_path);
         C.mOF.open(( _path + "/" + ClassName + ".java" ).c_str());