From e27d02d4c95a48cfa3aa9f7c0f3d6dd4f45e4f22 Mon Sep 17 00:00:00 2001
Date: Sun, 16 May 2021 13:07:20 -0700
Subject: [PATCH 01/24] MacPorts-only: clang use MP omp locations

look in ${prefix}/lib/libomp for omp libraries
* this patch requires post-patch reinplace
---
 clang/lib/Driver/ToolChains/Clang.cpp      | 2 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 1976b48e0f6a..981f35e36a0e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5463,6 +5463,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     case Driver::OMPRT_OMP:
     case Driver::OMPRT_IOMP5:
       // Clang can generate useful OpenMP code for these two runtime libraries.
+      // Automatically find MacPorts' omp.h
+      CmdArgs.push_back("-I@@PREFIX@@/include/libomp");
       CmdArgs.push_back("-fopenmp");
 
       // If no option regarding the use of TLS in OpenMP codegeneration is
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index bcaea71dca94..a88833055be7 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -652,25 +652,17 @@
 
   if (Args.hasFlag(options::OPT_fopenmp_implicit_rpath,
                    options::OPT_fno_openmp_implicit_rpath, true)) {
-    // Default to clang lib / lib64 folder, i.e. the same location as device
-    // runtime
-    SmallString<256> DefaultLibPath =
-        llvm::sys::path::parent_path(TC.getDriver().Dir);
-    llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
+    // MacPorts's runtime
     CmdArgs.push_back("-rpath");
-    CmdArgs.push_back(Args.MakeArgString(DefaultLibPath));
+    CmdArgs.push_back("@@PREFIX@@/lib/libomp");
   }
 }
 
 void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,
                                         const ArgList &Args,
                                         ArgStringList &CmdArgs) {
-  // Default to clang lib / lib64 folder, i.e. the same location as device
-  // runtime.
-  SmallString<256> DefaultLibPath =
-      llvm::sys::path::parent_path(TC.getDriver().Dir);
-  llvm::sys::path::append(DefaultLibPath, Twine("lib") + CLANG_LIBDIR_SUFFIX);
-  CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+  // Automatically find MacPorts's libomp
+  CmdArgs.push_back("-L@@PREFIX@@/lib/libomp");
 }
 
 void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
