Skip to content

Commit 3c7bc4a

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 0403030 commit 3c7bc4a

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
@@ -246,6 +246,13 @@ Typical components:\n\
246246

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

0 commit comments

Comments
 (0)