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
@@ -668,12 +668,18 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
 
   switch (RTKind) {
   case Driver::OMPRT_OMP:
+    // Automatically find MacPorts' libomp
+    CmdArgs.push_back("-L@@PREFIX@@/lib/libomp");
     CmdArgs.push_back("-lomp");
     break;
   case Driver::OMPRT_GOMP:
+    // Automatically find MacPorts' libomp
+    CmdArgs.push_back("-L@@PREFIX@@/lib/libomp");
     CmdArgs.push_back("-lgomp");
     break;
   case Driver::OMPRT_IOMP5:
+    // Automatically find MacPorts' libomp
+    CmdArgs.push_back("-L@@PREFIX@@/lib/libomp");
     CmdArgs.push_back("-liomp5");
     break;
   case Driver::OMPRT_Unknown:
-- 
2.21.1 (Apple Git-122.3)

