aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-core/llvm/llvm/0002-llvm-allow-env-override-of-exe-path.patch
blob: 774947ae22cda1ac5d811dc6e5152e9ecf608af5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
From 0570fe02c07244a8724c1e6c0437f893c8aa8e93 Mon Sep 17 00:00:00 2001
From: Martin Kelly <mkelly@xevo.com>
Date: Fri, 19 May 2017 00:22:57 -0700
Subject: [PATCH 2/2] llvm: allow env override of exe path

When using a native llvm-config from inside a sysroot, we need llvm-config to
return the libraries, include directories, etc. from inside the sysroot rather
than from the native sysroot. Thus provide an env override for calling
llvm-config from a target sysroot.

To let it work in multilib environment, we need to provide a knob to supply
multilib dirname as well

Upstream-Status: Inappropriate [OE-Specific]

Signed-off-by: Martin Kelly <mkelly@xevo.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Arsalan H. Awan <Arsalan_Awan@mentor.com>
---
 tools/llvm-config/llvm-config.cpp | 35 ++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index bec89fef98c..91b4d6e4c43 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -226,6 +226,13 @@ Typical components:\n\
 
 /// Compute the path to the main executable.
 std::string GetExecutablePath(const char *Argv0) {
+  // Hack for Yocto: we need to override the root path when we are using
+  // llvm-config from within a target sysroot.
+  const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
+  if (Sysroot != nullptr) {
+    return Sysroot;
+  }
+
   // This just needs to be some symbol in the binary; C++ doesn't
   // allow taking the address of ::main however.
   void *P = (void *)(intptr_t)GetExecutablePath;
@@ -284,7 +291,7 @@ int main(int argc, char **argv) {
   // bin dir).
   sys::fs::make_absolute(CurrentPath);
   CurrentExecPrefix =
-      sys::path::parent_path(sys::path::parent_path(CurrentPath)).str();
+      sys::path::parent_path(sys::path::parent_path(sys::path::parent_path(CurrentPath))).str();
 
   // Check to see if we are inside a development tree by comparing to possible
   // locations (prefix style or CMake style).
@@ -293,7 +300,7 @@ int main(int argc, char **argv) {
     DevelopmentTreeLayout = CMakeStyle;
     ActiveObjRoot = LLVM_OBJ_ROOT;
   } else if (sys::fs::equivalent(CurrentExecPrefix,
-                                 Twine(LLVM_OBJ_ROOT) + "/bin")) {
+                                 Twine(LLVM_OBJ_ROOT) + "/bin/llvm9.0.0")) {
     IsInDevelopmentTree = true;
     DevelopmentTreeLayout = CMakeBuildModeStyle;
     ActiveObjRoot = LLVM_OBJ_ROOT;
@@ -307,37 +314,45 @@ int main(int argc, char **argv) {
   std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
               ActiveCMakeDir;
   std::string ActiveIncludeOption;
+  // Hack for Yocto: we need to override the multilib path when we are using
+  // llvm-config from within a target sysroot.
+  std::string Multilibdir = std::getenv("YOCTO_ALTERNATE_MULTILIB_NAME");
+  if (Multilibdir.empty()) {
+    Multilibdir = "/lib/llvm9.0.0" LLVM_LIBDIR_SUFFIX;
+  }
+
   if (IsInDevelopmentTree) {
-    ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
+    ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include/llvm9.0.0";
     ActivePrefix = CurrentExecPrefix;
 
     // CMake organizes the products differently than a normal prefix style
     // layout.
+
     switch (DevelopmentTreeLayout) {
     case CMakeStyle:
-      ActiveBinDir = ActiveObjRoot + "/bin";
-      ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
+      ActiveBinDir = ActiveObjRoot + "/bin/llvm9.0.0";
+      ActiveLibDir = ActiveObjRoot + "/lib/llvm9.0.0" + LLVM_LIBDIR_SUFFIX;
       ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
       break;
     case CMakeBuildModeStyle:
       ActivePrefix = ActiveObjRoot;
-      ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
+      ActiveBinDir = ActiveObjRoot + "/bin/llvm9.0.0/" + build_mode;
       ActiveLibDir =
-          ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
+          ActiveObjRoot + "/lib/llvm9.0.0" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
       ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
       break;
     }
 
     // We need to include files from both the source and object trees.
     ActiveIncludeOption =
-        ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
+        ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include/llvm9.0.0");
   } else {
     ActivePrefix = CurrentExecPrefix;
-    ActiveIncludeDir = ActivePrefix + "/include";
+    ActiveIncludeDir = ActivePrefix + "/include/llvm9.0.0";
     SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
     sys::fs::make_absolute(ActivePrefix, path);
     ActiveBinDir = path.str();
-    ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
+    ActiveLibDir = ActivePrefix + Multilibdir;
     ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
     ActiveIncludeOption = "-I" + ActiveIncludeDir;
   }
-- 
2.20.1