blob: 1369bcf78c730a2b14d770b9b81cd3193c9598b0 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 0570fe02c07244a8724c1e6c0437f893c8aa8e93 Mon Sep 17 00:00:00 2001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002From: Martin Kelly <mkelly@xevo.com>
3Date: Fri, 19 May 2017 00:22:57 -0700
4Subject: [PATCH 2/2] llvm: allow env override of exe path
5
6When using a native llvm-config from inside a sysroot, we need llvm-config to
7return the libraries, include directories, etc. from inside the sysroot rather
8than from the native sysroot. Thus provide an env override for calling
9llvm-config from a target sysroot.
10
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080011To let it work in multilib environment, we need to provide a knob to supply
12multilib dirname as well
13
14Upstream-Status: Inappropriate [OE-Specific]
15
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016Signed-off-by: Martin Kelly <mkelly@xevo.com>
17Signed-off-by: Khem Raj <raj.khem@gmail.com>
18---
Brad Bishop19323692019-04-05 15:28:33 -040019 tools/llvm-config/llvm-config.cpp | 35 ++++++++++++++++++++++---------
20 1 file changed, 25 insertions(+), 10 deletions(-)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021
22diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
Brad Bishop19323692019-04-05 15:28:33 -040023index bec89fef98c..91b4d6e4c43 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024--- a/tools/llvm-config/llvm-config.cpp
25+++ b/tools/llvm-config/llvm-config.cpp
Brad Bishop19323692019-04-05 15:28:33 -040026@@ -226,6 +226,13 @@ Typical components:\n\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027
Brad Bishop19323692019-04-05 15:28:33 -040028 /// Compute the path to the main executable.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 std::string GetExecutablePath(const char *Argv0) {
30+ // Hack for Yocto: we need to override the root path when we are using
31+ // llvm-config from within a target sysroot.
32+ const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
33+ if (Sysroot != nullptr) {
34+ return Sysroot;
35+ }
36+
37 // This just needs to be some symbol in the binary; C++ doesn't
38 // allow taking the address of ::main however.
39 void *P = (void *)(intptr_t)GetExecutablePath;
Brad Bishop19323692019-04-05 15:28:33 -040040@@ -284,7 +291,7 @@ int main(int argc, char **argv) {
41 // bin dir).
42 sys::fs::make_absolute(CurrentPath);
43 CurrentExecPrefix =
44- sys::path::parent_path(sys::path::parent_path(CurrentPath)).str();
45+ sys::path::parent_path(sys::path::parent_path(sys::path::parent_path(CurrentPath))).str();
46
47 // Check to see if we are inside a development tree by comparing to possible
48 // locations (prefix style or CMake style).
49@@ -293,7 +300,7 @@ int main(int argc, char **argv) {
50 DevelopmentTreeLayout = CMakeStyle;
51 ActiveObjRoot = LLVM_OBJ_ROOT;
52 } else if (sys::fs::equivalent(CurrentExecPrefix,
53- Twine(LLVM_OBJ_ROOT) + "/bin")) {
54+ Twine(LLVM_OBJ_ROOT) + "/bin/llvm8.0.0")) {
55 IsInDevelopmentTree = true;
56 DevelopmentTreeLayout = CMakeBuildModeStyle;
57 ActiveObjRoot = LLVM_OBJ_ROOT;
58@@ -307,37 +314,45 @@ int main(int argc, char **argv) {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080059 std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
60 ActiveCMakeDir;
61 std::string ActiveIncludeOption;
62+ // Hack for Yocto: we need to override the multilib path when we are using
63+ // llvm-config from within a target sysroot.
64+ std::string Multilibdir = std::getenv("YOCTO_ALTERNATE_MULTILIB_NAME");
65+ if (Multilibdir.empty()) {
Brad Bishop19323692019-04-05 15:28:33 -040066+ Multilibdir = "/lib/llvm8.0.0" LLVM_LIBDIR_SUFFIX;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080067+ }
68+
69 if (IsInDevelopmentTree) {
Brad Bishop19323692019-04-05 15:28:33 -040070- ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
71+ ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include/llvm8.0.0";
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072 ActivePrefix = CurrentExecPrefix;
73
74 // CMake organizes the products differently than a normal prefix style
75 // layout.
76+
77 switch (DevelopmentTreeLayout) {
78 case CMakeStyle:
Brad Bishop19323692019-04-05 15:28:33 -040079- ActiveBinDir = ActiveObjRoot + "/bin";
80- ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
81+ ActiveBinDir = ActiveObjRoot + "/bin/llvm8.0.0";
82+ ActiveLibDir = ActiveObjRoot + "/lib/llvm8.0.0" + LLVM_LIBDIR_SUFFIX;
83 ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
84 break;
85 case CMakeBuildModeStyle:
86 ActivePrefix = ActiveObjRoot;
87- ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
88+ ActiveBinDir = ActiveObjRoot + "/bin/llvm8.0.0/" + build_mode;
89 ActiveLibDir =
90- ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
91+ ActiveObjRoot + "/lib/llvm8.0.0" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
92 ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
93 break;
94 }
95
96 // We need to include files from both the source and object trees.
97 ActiveIncludeOption =
98- ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
99+ ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include/llvm8.0.0");
100 } else {
101 ActivePrefix = CurrentExecPrefix;
102- ActiveIncludeDir = ActivePrefix + "/include";
103+ ActiveIncludeDir = ActivePrefix + "/include/llvm8.0.0";
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800104 SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
105 sys::fs::make_absolute(ActivePrefix, path);
106 ActiveBinDir = path.str();
107- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
108+ ActiveLibDir = ActivePrefix + Multilibdir;
109 ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
110 ActiveIncludeOption = "-I" + ActiveIncludeDir;
111 }
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112--
Brad Bishop19323692019-04-05 15:28:33 -04001132.20.1
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500114