This mirrors cmake-*-prefix-dirs.patch

It add EPREFIX to search paths for c/cxx headers.
It also adds EPREFIX/MacOSX.sdk to search paths for c and Frameworks.
Assumes that c++ lib and headers will be installed in the prefix.

Also, a couple of args are populated by inspecting the SDK,
so, default to EPREFIX/MacOSX.sdk when the sysroot is not specified.
(This does NOT set sysroot).

The ebuild adds an extra / at the end of EPREFIX so that it is never
an empty string. 

--- a/clang/lib/Frontend/InitHeaderSearch.cpp	2020-11-30 12:53:42.000000000 -0600
+++ b/clang/lib/Frontend/InitHeaderSearch.cpp	2020-11-30 13:57:52.000000000 -0600
@@ -445,6 +445,9 @@
   // All header search logic is handled in the Driver for Darwin.
   if (triple.isOSDarwin()) {
     if (HSOpts.UseStandardSystemIncludes) {
+      // Add Gentoo Prefix framework dirs first
+      AddPath("@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk/System/Library/Frameworks", System, true);
+      AddPath("@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk/Library/Frameworks", System, true);
       // Add the default framework include paths on Darwin.
       AddPath("/System/Library/Frameworks", System, true);
       AddPath("/Library/Frameworks", System, true);
--- a/clang/lib/Driver/ToolChains/Darwin.cpp	2020-10-07 05:10:48.000000000 -0500
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp	2020-11-30 12:57:15.000000000 -0600
@@ -1737,9 +1737,9 @@
                                          const ArgList &Args,
                                          const Driver &TheDriver) {
   const Arg *A = Args.getLastArg(options::OPT_isysroot);
-  if (!A)
-    return None;
-  StringRef isysroot = A->getValue();
+  //if (!A)
+  //  return None;
+  StringRef isysroot = A ? A->getValue() : "@GENTOO_PORTAGE_EPREFIX@MacOSX.sdk";
   auto SDKInfoOrErr = driver::parseDarwinSDKInfo(VFS, isysroot);
   if (!SDKInfoOrErr) {
     llvm::consumeError(SDKInfoOrErr.takeError());
@@ -1921,13 +1921,14 @@
     return DriverArgs.getLastArgValue(options::OPT_isysroot);
   if (!getDriver().SysRoot.empty())
     return getDriver().SysRoot;
-  return "/";
+  return "@GENTOO_PORTAGE_EPREFIX@";
 }
 
 void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
                                             llvm::opt::ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
 
+  // Sysroot is effectively Gentoo EPREFIX when -isysroot/-sysroot is not defined
   llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
 
   bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc);
@@ -1969,6 +1970,10 @@
     SmallString<128> P(Sysroot);
     llvm::sys::path::append(P, "usr", "include");
-    addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+    addSystemInclude(DriverArgs, CC1Args, P.str());
+    // And add <sysroot>/MacOSX.sdk/usr/include.
+    SmallString<128> Psdk(Sysroot);
+    llvm::sys::path::append(Psdk, "MacOSX.sdk", "usr", "include");
+    addSystemInclude(DriverArgs, CC1Args, Psdk.str());
   }
 }
 
@@ -2017,6 +2022,7 @@
       DriverArgs.hasArg(options::OPT_nostdincxx))
     return;
 
+  // Sysroot is effectively Gentoo EPREFIX when -isysroot/-sysroot is not defined
   llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
 
   switch (GetCXXStdlibType(DriverArgs)) {