0005-llvm-allow-env-override-of-exe-and-libdir-path.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From affcd7f14bca2d9ee95352cd979f66f55901272a Mon Sep 17 00:00:00 2001
  2. From: Martin Kelly <mkelly@xevo.com>
  3. Date: Fri, 19 May 2017 00:22:57 -0700
  4. Subject: [PATCH] llvm: allow env override of exe and libdir path
  5. When using a native llvm-config from inside a sysroot, we need llvm-config to
  6. return the libraries, include directories, etc. from inside the sysroot rather
  7. than from the native sysroot. Thus provide an env override for calling
  8. llvm-config from a target sysroot.
  9. Add YOCTO_ALTERNATE_LIBDIR and YOCTO_ALTERNATE_EXE_PATH env variables
  10. Upstream-Status: Inappropriate [OE-specific]
  11. Signed-off-by: Martin Kelly <mkelly@xevo.com>
  12. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  13. ---
  14. llvm/tools/llvm-config/llvm-config.cpp | 21 +++++++++++++++++++--
  15. 1 file changed, 19 insertions(+), 2 deletions(-)
  16. diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
  17. index 8ed88f33ead4..9e26a2b41409 100644
  18. --- a/llvm/tools/llvm-config/llvm-config.cpp
  19. +++ b/llvm/tools/llvm-config/llvm-config.cpp
  20. @@ -247,6 +247,13 @@ Typical components:\n\
  21. /// Compute the path to the main executable.
  22. std::string GetExecutablePath(const char *Argv0) {
  23. + // Hack for Yocto: we need to override the root path when we are using
  24. + // llvm-config from within a target sysroot.
  25. + const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
  26. + if (Sysroot != nullptr) {
  27. + return Sysroot;
  28. + }
  29. +
  30. // This just needs to be some symbol in the binary; C++ doesn't
  31. // allow taking the address of ::main however.
  32. void *P = (void *)(intptr_t)GetExecutablePath;
  33. @@ -326,7 +333,7 @@ int main(int argc, char **argv) {
  34. // Compute various directory locations based on the derived location
  35. // information.
  36. std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
  37. - ActiveCMakeDir;
  38. + ActiveCMakeDir, BaseLibDir;
  39. std::string ActiveIncludeOption;
  40. if (IsInDevelopmentTree) {
  41. ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
  42. @@ -367,7 +374,17 @@ int main(int argc, char **argv) {
  43. sys::fs::make_absolute(ActivePrefix, Path);
  44. ActiveBinDir = std::string(Path.str());
  45. }
  46. - ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
  47. + // Hack for Yocto: we need to override the lib path when we are using
  48. + // llvm-config from within a target sysroot since LLVM_LIBDIR_SUFFIX
  49. + // maybe different for host llvm vs target e.g. ppc64 Libdir=lib64 but
  50. + // x86_64 Libdir = lib
  51. + const char *YoctoLibDir = std::getenv("YOCTO_ALTERNATE_LIBDIR");
  52. + if (YoctoLibDir != nullptr) {
  53. + BaseLibDir = std::string(YoctoLibDir);
  54. + } else {
  55. + BaseLibDir = std::string("/lib") + LLVM_LIBDIR_SUFFIX;
  56. + }
  57. + ActiveLibDir = ActivePrefix + BaseLibDir;
  58. ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
  59. ActiveIncludeOption = "-I" + ActiveIncludeDir;
  60. }