From a3de688e12022f605b3d8538ad157f12d7054e37 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sun, 5 May 2019 20:42:06 +0100 Subject: [PATCH] sys-devel/llvm: Add Bash version of llvm-config for cross-compiling This is a poor man's rewrite of llvm-config in Bash, which is needed because llvm-config is normally a native binary and cannot be used when cross-compiling. It supports most of the llvm-config flags and will return largely accurate answers. The main difference is that it doesn't support filtering by component so it will always return all of the LLVM libraries. This would cause overlinking but Gentoo avoids this by default with -Wl,--as-needed. To use this, llvm.eclass should add ${ESYSROOT}/usr/lib/llvm/${SLOT}/bin/cross to the PATH instead of the parent directory but it should only do so when cross-compiling. Tested with LLVM 7 and 8 against Mesa. Package-Manager: Portage-2.3.66, Repoman-2.3.12 Signed-off-by: James Le Cuirot --- sys-devel/llvm/files/7.1.0/gen-llvm-config-sh | 93 +++++++++++++++++++ sys-devel/llvm/llvm-7.1.0.ebuild | 6 ++ sys-devel/llvm/llvm-8.0.0.ebuild | 6 ++ sys-devel/llvm/llvm-8.0.9999.ebuild | 6 ++ sys-devel/llvm/llvm-9999.ebuild | 6 ++ 5 files changed, 117 insertions(+) create mode 100755 sys-devel/llvm/files/7.1.0/gen-llvm-config-sh diff --git a/sys-devel/llvm/files/7.1.0/gen-llvm-config-sh b/sys-devel/llvm/files/7.1.0/gen-llvm-config-sh new file mode 100755 index 000000000000..588ca344a425 --- /dev/null +++ b/sys-devel/llvm/files/7.1.0/gen-llvm-config-sh @@ -0,0 +1,93 @@ +#!/bin/bash -e + +build_var() { + cpp -P -Iinclude -include llvm/Config/config.h -include tools/llvm-config/BuildVariables.inc - <<< "$1" +} + +build_yes_no() { + if [[ $(build_var "$1") = 1 ]]; then + echo YES + else + echo NO + fi +} + +build_on_off() { + if [[ $(build_var "$1") = 1 ]]; then + echo ON + else + echo OFF + fi +} + +: ${CBUILD:-${CHOST}} + +if [[ -n ${CBUILD} ]]; then + CXX=${CBUILD}-c++ +else + CXX=c++ +fi + +TEMP_EXE=$(mktemp) +trap 'rm -f "${TEMP_EXE}"' EXIT + +${CXX} -o "${TEMP_EXE}" -x c++ - < +#include "tools/llvm-config/LibraryDependencies.inc" + +int main(int argc, char** argv) { + unsigned int i, total; + struct AvailableComponent *component; + const char *library; + + total = sizeof(AvailableComponents) / sizeof(AvailableComponents[0]); + + for (i = 0; i < total; i++) { + component = &AvailableComponents[i]; + library = component->Library; + if (library == NULL) library = ""; + if (component->IsInstalled) printf("\t\"%s %s\"\n", component->Name, library); + } + + return 0; +} +EOF + +cat < "${CHOST}"-llvm-config.sh || die } multilib_src_test() { @@ -220,6 +222,7 @@ src_install() { local LLVM_LDPATHS=() multilib-minimal_src_install + dosym "${CHOST}"-llvm-config /usr/lib/llvm/${SLOT}/bin/cross/llvm-config # move wrapped headers back mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT%/*}/include || die @@ -233,6 +236,9 @@ multilib_src_install() { mv "${ED%/}"/usr/lib/llvm/${SLOT%/*}/include "${ED%/}"/usr/include || die LLVM_LDPATHS+=( "${EPREFIX}/usr/lib/llvm/${SLOT%/*}/$(get_libdir)" ) + + exeinto /usr/lib/llvm/${SLOT}/bin/cross + newexe "${CHOST}"-llvm-config{.sh,} } multilib_src_install_all() { diff --git a/sys-devel/llvm/llvm-8.0.0.ebuild b/sys-devel/llvm/llvm-8.0.0.ebuild index 212c6de12274..8ba6284f8bd4 100644 --- a/sys-devel/llvm/llvm-8.0.0.ebuild +++ b/sys-devel/llvm/llvm-8.0.0.ebuild @@ -237,6 +237,8 @@ multilib_src_compile() { pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/MCJIT/MCJITTests pax-mark m "${BUILD_DIR}"/unittests/Support/SupportTests fi + + bash "${FILESDIR}"/7.1.0/gen-llvm-config-sh > "${CHOST}"-llvm-config.sh || die } multilib_src_test() { @@ -256,6 +258,7 @@ src_install() { local LLVM_LDPATHS=() multilib-minimal_src_install + dosym "${CHOST}"-llvm-config /usr/lib/llvm/${SLOT}/bin/cross/llvm-config # move wrapped headers back mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die @@ -269,6 +272,9 @@ multilib_src_install() { mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die LLVM_LDPATHS+=( "${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)" ) + + exeinto /usr/lib/llvm/${SLOT}/bin/cross + newexe "${CHOST}"-llvm-config{.sh,} } multilib_src_install_all() { diff --git a/sys-devel/llvm/llvm-8.0.9999.ebuild b/sys-devel/llvm/llvm-8.0.9999.ebuild index 762eed9364fe..2f73a02d391b 100644 --- a/sys-devel/llvm/llvm-8.0.9999.ebuild +++ b/sys-devel/llvm/llvm-8.0.9999.ebuild @@ -233,6 +233,8 @@ multilib_src_compile() { pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/MCJIT/MCJITTests pax-mark m "${BUILD_DIR}"/unittests/Support/SupportTests fi + + bash "${FILESDIR}"/7.1.0/gen-llvm-config-sh > "${CHOST}"-llvm-config.sh || die } multilib_src_test() { @@ -252,6 +254,7 @@ src_install() { local LLVM_LDPATHS=() multilib-minimal_src_install + dosym "${CHOST}"-llvm-config /usr/lib/llvm/${SLOT}/bin/cross/llvm-config # move wrapped headers back mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die @@ -265,6 +268,9 @@ multilib_src_install() { mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die LLVM_LDPATHS+=( "${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)" ) + + exeinto /usr/lib/llvm/${SLOT}/bin/cross + newexe "${CHOST}"-llvm-config{.sh,} } multilib_src_install_all() { diff --git a/sys-devel/llvm/llvm-9999.ebuild b/sys-devel/llvm/llvm-9999.ebuild index fe059751a9f6..6e79271b0c53 100644 --- a/sys-devel/llvm/llvm-9999.ebuild +++ b/sys-devel/llvm/llvm-9999.ebuild @@ -238,6 +238,8 @@ multilib_src_compile() { pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/MCJIT/MCJITTests pax-mark m "${BUILD_DIR}"/unittests/Support/SupportTests fi + + bash "${FILESDIR}"/7.1.0/gen-llvm-config-sh > "${CHOST}"-llvm-config.sh || die } multilib_src_test() { @@ -257,6 +259,7 @@ src_install() { local LLVM_LDPATHS=() multilib-minimal_src_install + dosym "${CHOST}"-llvm-config /usr/lib/llvm/${SLOT}/bin/cross/llvm-config # move wrapped headers back mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die @@ -270,6 +273,9 @@ multilib_src_install() { mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die LLVM_LDPATHS+=( "${EPREFIX}/usr/lib/llvm/${SLOT}/$(get_libdir)" ) + + exeinto /usr/lib/llvm/${SLOT}/bin/cross + newexe "${CHOST}"-llvm-config{.sh,} } multilib_src_install_all() { -- 2.20.1