Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | From 0570fe02c07244a8724c1e6c0437f893c8aa8e93 Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Martin Kelly <mkelly@xevo.com> |
| 3 | Date: Fri, 19 May 2017 00:22:57 -0700 |
| 4 | Subject: [PATCH 2/2] llvm: allow env override of exe path |
| 5 | |
| 6 | When using a native llvm-config from inside a sysroot, we need llvm-config to |
| 7 | return the libraries, include directories, etc. from inside the sysroot rather |
| 8 | than from the native sysroot. Thus provide an env override for calling |
| 9 | llvm-config from a target sysroot. |
| 10 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 11 | To let it work in multilib environment, we need to provide a knob to supply |
| 12 | multilib dirname as well |
| 13 | |
| 14 | Upstream-Status: Inappropriate [OE-Specific] |
| 15 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | Signed-off-by: Martin Kelly <mkelly@xevo.com> |
| 17 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 18 | --- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 19 | tools/llvm-config/llvm-config.cpp | 35 ++++++++++++++++++++++--------- |
| 20 | 1 file changed, 25 insertions(+), 10 deletions(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | |
| 22 | diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 23 | index bec89fef98c..91b4d6e4c43 100644 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 24 | --- a/tools/llvm-config/llvm-config.cpp |
| 25 | +++ b/tools/llvm-config/llvm-config.cpp |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 26 | @@ -226,6 +226,13 @@ Typical components:\n\ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 27 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 28 | /// Compute the path to the main executable. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 40 | @@ -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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 59 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 66 | + Multilibdir = "/lib/llvm8.0.0" LLVM_LIBDIR_SUFFIX; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 67 | + } |
| 68 | + |
| 69 | if (IsInDevelopmentTree) { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 70 | - ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include"; |
| 71 | + ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include/llvm8.0.0"; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 72 | ActivePrefix = CurrentExecPrefix; |
| 73 | |
| 74 | // CMake organizes the products differently than a normal prefix style |
| 75 | // layout. |
| 76 | + |
| 77 | switch (DevelopmentTreeLayout) { |
| 78 | case CMakeStyle: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 79 | - 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 104 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 112 | -- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 113 | 2.20.1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 114 | |