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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 8f8e25be1822d93341b0e32ba42d22c8c54016d4 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 | 25 +++++++++++++++++++------
  15. 1 file changed, 19 insertions(+), 6 deletions(-)
  16. diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
  17. index b1d795a0a349..dbeddeb2152e 100644
  18. --- a/llvm/tools/llvm-config/llvm-config.cpp
  19. +++ b/llvm/tools/llvm-config/llvm-config.cpp
  20. @@ -246,6 +246,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. @@ -325,7 +332,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. @@ -366,12 +373,18 @@ 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. - {
  48. - SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
  49. - sys::fs::make_absolute(ActivePrefix, Path);
  50. - ActiveCMakeDir = std::string(Path.str());
  51. + // Hack for Yocto: we need to override the lib path when we are using
  52. + // llvm-config from within a target sysroot since LLVM_LIBDIR_SUFFIX
  53. + // maybe different for host llvm vs target e.g. ppc64 Libdir=lib64 but
  54. + // x86_64 Libdir = lib
  55. + const char *YoctoLibDir = std::getenv("YOCTO_ALTERNATE_LIBDIR");
  56. + if (YoctoLibDir != nullptr) {
  57. + BaseLibDir = std::string(YoctoLibDir);
  58. + } else {
  59. + BaseLibDir = std::string("/lib") + LLVM_LIBDIR_SUFFIX;
  60. }
  61. + ActiveLibDir = ActivePrefix + BaseLibDir;
  62. + ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
  63. ActiveIncludeOption = "-I" + ActiveIncludeDir;
  64. }