compiler-rt-9999.ebuild 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
  5. # (needed due to CMAKE_BUILD_TYPE != Gentoo)
  6. CMAKE_MIN_VERSION=3.7.0-r1
  7. PYTHON_COMPAT=( python2_7 )
  8. # TODO: fix unnecessary dep on Python upstream
  9. inherit cmake-utils flag-o-matic git-r3 llvm python-any-r1 toolchain-funcs
  10. DESCRIPTION="Compiler runtime library for clang (built-in part)"
  11. HOMEPAGE="http://llvm.org/"
  12. SRC_URI=""
  13. EGIT_REPO_URI="http://llvm.org/git/compiler-rt.git
  14. https://github.com/llvm-mirror/compiler-rt.git"
  15. LICENSE="|| ( UoI-NCSA MIT )"
  16. # Note: this needs to be updated to match version of clang-9999
  17. SLOT="5.0.0"
  18. KEYWORDS=""
  19. IUSE="+clang test"
  20. LLVM_SLOT=${SLOT%%.*}
  21. # llvm-4 needed for --cmakedir
  22. DEPEND="
  23. >=sys-devel/llvm-4
  24. clang? ( sys-devel/clang )
  25. test? ( =sys-devel/clang-${PV%_*}*:${LLVM_SLOT} )
  26. ${PYTHON_DEPS}"
  27. # least intrusive of all
  28. CMAKE_BUILD_TYPE=RelWithDebInfo
  29. pkg_setup() {
  30. llvm_pkg_setup
  31. python-any-r1_pkg_setup
  32. }
  33. test_compiler() {
  34. $(tc-getCC) ${CFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c - \
  35. <<<'int main() { return 0; }' &>/dev/null
  36. }
  37. src_configure() {
  38. # pre-set since we need to pass it to cmake
  39. BUILD_DIR=${WORKDIR}/${P}_build
  40. if use clang; then
  41. local -x CC=${CHOST}-clang
  42. local -x CXX=${CHOST}-clang++
  43. # ensure we can use clang before installing compiler-rt
  44. local -x LDFLAGS="${LDFLAGS} -nodefaultlibs -lc"
  45. strip-unsupported-flags
  46. elif ! test_compiler; then
  47. local extra_flags=( -nodefaultlibs -lc )
  48. if test_compiler "${extra_flags[@]}"; then
  49. local -x LDFLAGS="${LDFLAGS} ${extra_flags[*]}"
  50. ewarn "${CC} seems to lack runtime, trying with ${extra_flags[*]}"
  51. fi
  52. fi
  53. local mycmakeargs=(
  54. -DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${SLOT}"
  55. # use a build dir structure consistent with install
  56. # this makes it possible to easily deploy test-friendly clang
  57. -DCOMPILER_RT_OUTPUT_DIR="${BUILD_DIR}/lib/clang/${SLOT}"
  58. # currently lit covers only sanitizer tests
  59. -DCOMPILER_RT_INCLUDE_TESTS=OFF
  60. -DCOMPILER_RT_BUILD_SANITIZERS=OFF
  61. -DCOMPILER_RT_BUILD_XRAY=OFF
  62. )
  63. cmake-utils_src_configure
  64. }
  65. src_test() {
  66. # prepare a test compiler
  67. # copy clang over since resource_dir is located relatively to binary
  68. # therefore, we can put our new libraries in it
  69. mkdir -p "${BUILD_DIR}"/lib/{llvm/${LLVM_SLOT}{/bin,$(get_libdir)},clang/${SLOT}/include} || die
  70. cp "${EPREFIX}"/usr/lib/llvm/${LLVM_SLOT}/bin/clang{,++} \
  71. "${BUILD_DIR}"/lib/llvm/${LLVM_SLOT}/bin/ || die
  72. cp "${EPREFIX}/usr/lib/clang/${SLOT}/include"/*.h \
  73. "${BUILD_DIR}/lib/clang/${SLOT}/include/" || die
  74. # builtins are not converted to lit yet, so run them manually
  75. local tests=() f
  76. cd "${S}"/test/builtins/Unit || die
  77. while read -r -d '' f; do
  78. # ppc subdir is unmaintained and lacks proper guards
  79. # (and ppc builtins do not seem to be used anyway)
  80. [[ ${f} == ./ppc/* ]] && continue
  81. # these are special
  82. [[ ${f} == ./cpu_model_test.c ]] && continue
  83. [[ ${f} == ./gcc_personality_test.c ]] && continue
  84. # unsupported
  85. [[ ${f} == ./trampoline_setup_test.c ]] && continue
  86. tests+=( "${f%.c}" )
  87. done < <(find -name '*.c' -print0)
  88. {
  89. echo "check: ${tests[*]/#/check-}" &&
  90. echo ".PHONY: check ${tests[*]/#/check-}" &&
  91. for f in "${tests[@]}"; do
  92. echo "check-${f}: ${f}" &&
  93. echo " ${f}"
  94. done
  95. } > Makefile || die
  96. local ABI
  97. for ABI in $(get_all_abis); do
  98. # not supported at all at the moment
  99. [[ ${ABI} == x32 ]] && continue
  100. rm -f "${tests[@]}" || die
  101. einfo "Running tests for ABI=${ABI}"
  102. # use -k to run all tests even if some fail
  103. emake -k \
  104. CC="${BUILD_DIR}/lib/llvm/${LLVM_SLOT}/bin/clang" \
  105. CFLAGS="$(get_abi_CFLAGS)" \
  106. CPPFLAGS='-I../../../lib/builtins' \
  107. LDFLAGS='-rtlib=compiler-rt' \
  108. LDLIBS='-lm'
  109. done
  110. }
  111. src_install() {
  112. cmake-utils_src_install
  113. # includes are mistakenly installed for all sanitizers and xray
  114. rm -rf "${ED}"usr/lib/clang/*/include || die
  115. }