Skip to content

Commit ca24a7a

Browse files
Martin Kellykraj
authored andcommitted
llvm: allow env override of exe and libdir path
When using a native llvm-config from inside a sysroot, we need llvm-config to return the libraries, include directories, etc. from inside the sysroot rather than from the native sysroot. Thus provide an env override for calling llvm-config from a target sysroot. Add YOCTO_ALTERNATE_LIBDIR and YOCTO_ALTERNATE_EXE_PATH env variables Upstream-Status: Inappropriate [OE-specific] Signed-off-by: Martin Kelly <mkelly@xevo.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
1 parent 85e498a commit ca24a7a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

llvm/tools/llvm-config/llvm-config.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ Typical components:\n\
245245

246246
/// Compute the path to the main executable.
247247
std::string GetExecutablePath(const char *Argv0) {
248+
// Hack for Yocto: we need to override the root path when we are using
249+
// llvm-config from within a target sysroot.
250+
const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH");
251+
if (Sysroot != nullptr) {
252+
return Sysroot;
253+
}
254+
248255
// This just needs to be some symbol in the binary; C++ doesn't
249256
// allow taking the address of ::main however.
250257
void *P = (void *)(intptr_t)GetExecutablePath;
@@ -324,7 +331,7 @@ int main(int argc, char **argv) {
324331
// Compute various directory locations based on the derived location
325332
// information.
326333
std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
327-
ActiveCMakeDir;
334+
ActiveCMakeDir, BaseLibDir;
328335
std::string ActiveIncludeOption;
329336
if (IsInDevelopmentTree) {
330337
ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
@@ -365,12 +372,18 @@ int main(int argc, char **argv) {
365372
sys::fs::make_absolute(ActivePrefix, Path);
366373
ActiveBinDir = std::string(Path);
367374
}
368-
ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
369-
{
370-
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
371-
sys::fs::make_absolute(ActivePrefix, Path);
372-
ActiveCMakeDir = std::string(Path);
375+
// Hack for Yocto: we need to override the lib path when we are using
376+
// llvm-config from within a target sysroot since LLVM_LIBDIR_SUFFIX
377+
// maybe different for host llvm vs target e.g. ppc64 Libdir=lib64 but
378+
// x86_64 Libdir = lib
379+
const char *YoctoLibDir = std::getenv("YOCTO_ALTERNATE_LIBDIR");
380+
if (YoctoLibDir != nullptr) {
381+
BaseLibDir = std::string(YoctoLibDir);
382+
} else {
383+
BaseLibDir = std::string("/lib") + LLVM_LIBDIR_SUFFIX;
373384
}
385+
ActiveLibDir = ActivePrefix + BaseLibDir;
386+
ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
374387
ActiveIncludeOption = "-I" + ActiveIncludeDir;
375388
}
376389

0 commit comments

Comments
 (0)