aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-core/llvm/files/0001-llvm-config-allow-overriding-libdir-through-cmdline.patch
blob: 26bf42e51f81993b7866c0eb6d1da2cf91b72ed0 (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
From 87b01c9e5cecd30f9cde1f717e1ae7094e1f62c1 Mon Sep 17 00:00:00 2001
From: Awais Belal <awais_belal@mentor.com>
Date: Wed, 13 Dec 2017 14:15:24 +0500
Subject: [PATCH] llvm-config: allow overriding libdir through cmdline

This is handy in cases such as the OE environment
where llvm-config is used through the llvm-native
package so the libdir it reports can be different
what is required for the target sysroot and so if
the baselib is different for target and host the
llvm-config --libs command will fail complaining
about not finding required libraries. This scenario
can be reproduced through an LLVM enabled mesa build
where host and target have different baselib. So
after the patch the mesa build should pass the whole
target libdir to the llvm-config command to use.

Signed-off-by: Awais Belal <awais_belal@mentor.com>
---
 tools/llvm-config/llvm-config.cpp | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index 08b096afb05..8233d16dda0 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -301,6 +301,18 @@ int main(int argc, char **argv) {
     DevelopmentTreeLayout = CMakeStyle; // Initialized to avoid warnings.
   }
 
+  // Check if we were given a special libdir to use
+  // if so disregard all other libdir settings
+  std::string TargetLibDir;
+  for (int i = 1; i != argc; ++i) {
+    if (strcmp(argv[i],"--tgtlibdir") == 0) {
+      if (argc > i+1) {
+        TargetLibDir.assign(argv[i+1]);
+        break;
+      }
+    }
+  }
+
   // Compute various directory locations based on the derived location
   // information.
   std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
@@ -315,13 +327,19 @@ int main(int argc, char **argv) {
     switch (DevelopmentTreeLayout) {
     case CMakeStyle:
       ActiveBinDir = ActiveObjRoot + "/bin";
-      ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
+      if (!TargetLibDir.empty())
+        ActiveLibDir = TargetLibDir;
+      else
+        ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
       ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
       break;
     case CMakeBuildModeStyle:
       ActivePrefix = ActiveObjRoot;
       ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
-      ActiveLibDir =
+      if (!TargetLibDir.empty())
+        ActiveLibDir = TargetLibDir;
+      else
+        ActiveLibDir =
           ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
       ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
       break;
@@ -336,7 +354,10 @@ int main(int argc, char **argv) {
     SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
     sys::fs::make_absolute(ActivePrefix, path);
     ActiveBinDir = path.str();
-    ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
+    if (!TargetLibDir.empty())
+      ActiveLibDir = TargetLibDir;
+    else
+      ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
     ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
     ActiveIncludeOption = "-I" + ActiveIncludeDir;
   }
@@ -468,7 +489,7 @@ int main(int argc, char **argv) {
   };
 
   raw_ostream &OS = outs();
-  for (int i = 1; i != argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
     StringRef Arg = argv[i];
 
     if (Arg.startswith("-")) {
@@ -567,6 +588,9 @@ int main(int argc, char **argv) {
         LinkMode = LinkModeShared;
       } else if (Arg == "--link-static") {
         LinkMode = LinkModeStatic;
+      } else if (Arg == "--tgtlibdir") {
+        ++i;
+        continue;
       } else {
         usage();
       }
-- 
2.11.1