clang-4.0.0-r1.ebuild 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. inherit check-reqs cmake-utils flag-o-matic llvm multilib-minimal \
  9. python-single-r1 toolchain-funcs pax-utils versionator
  10. DESCRIPTION="C language family frontend for LLVM"
  11. HOMEPAGE="http://llvm.org/"
  12. SRC_URI="http://releases.llvm.org/${PV/_//}/cfe-${PV/_/}.src.tar.xz
  13. http://releases.llvm.org/${PV/_//}/clang-tools-extra-${PV/_/}.src.tar.xz
  14. !doc? ( https://dev.gentoo.org/~mgorny/dist/llvm-manpages-${PV}.tar.bz2 )
  15. test? ( http://releases.llvm.org/${PV/_//}/llvm-${PV/_/}.src.tar.xz )"
  16. # Keep in sync with sys-devel/llvm
  17. ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
  18. NVPTX PowerPC RISCV Sparc SystemZ X86 XCore )
  19. ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
  20. LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
  21. LICENSE="UoI-NCSA"
  22. SLOT="$(get_major_version)"
  23. KEYWORDS="~amd64 ~arm64 ~x86"
  24. IUSE="debug default-compiler-rt default-libcxx +doc multitarget
  25. +static-analyzer test xml elibc_musl kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
  26. RDEPEND="
  27. ~sys-devel/llvm-${PV}:${SLOT}=[debug=,${LLVM_TARGET_USEDEPS// /,},${MULTILIB_USEDEP}]
  28. static-analyzer? ( dev-lang/perl:* )
  29. xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
  30. ${PYTHON_DEPS}"
  31. # configparser-3.2 breaks the build (3.3 or none at all are fine)
  32. DEPEND="${RDEPEND}
  33. doc? ( dev-python/sphinx )
  34. test? ( ~dev-python/lit-${PV}[${PYTHON_USEDEP}] )
  35. xml? ( virtual/pkgconfig )
  36. !!<dev-python/configparser-3.3.0.2
  37. ${PYTHON_DEPS}"
  38. RDEPEND="${RDEPEND}
  39. !<sys-devel/llvm-4.0.0_rc:0
  40. !sys-devel/clang:0"
  41. PDEPEND="
  42. ~sys-devel/clang-runtime-${PV}
  43. default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
  44. default-libcxx? ( sys-libs/libcxx )"
  45. REQUIRED_USE="${PYTHON_REQUIRED_USE}
  46. || ( ${ALL_LLVM_TARGETS[*]} )
  47. multitarget? ( ${ALL_LLVM_TARGETS[*]} )"
  48. # We need extra level of indirection for CLANG_RESOURCE_DIR
  49. S=${WORKDIR}/x/y/cfe-${PV/_/}.src
  50. # least intrusive of all
  51. CMAKE_BUILD_TYPE=RelWithDebInfo
  52. # Multilib notes:
  53. # 1. ABI_* flags control ABIs libclang* is built for only.
  54. # 2. clang is always capable of compiling code for all ABIs for enabled
  55. # target. However, you will need appropriate crt* files (installed
  56. # e.g. by sys-devel/gcc and sys-libs/glibc).
  57. # 3. ${CHOST}-clang wrappers are always installed for all ABIs included
  58. # in the current profile (i.e. alike supported by sys-devel/gcc).
  59. #
  60. # Therefore: use sys-devel/clang[${MULTILIB_USEDEP}] only if you need
  61. # multilib clang* libraries (not runtime, not wrappers).
  62. check_space() {
  63. local build_size=650
  64. if use debug; then
  65. ewarn "USE=debug is known to increase the size of package considerably"
  66. ewarn "and cause the tests to fail."
  67. ewarn
  68. (( build_size *= 14 ))
  69. elif is-flagq '-g?(gdb)?([1-9])'; then
  70. ewarn "The C++ compiler -g option is known to increase the size of the package"
  71. ewarn "considerably. If you run out of space, please consider removing it."
  72. ewarn
  73. (( build_size *= 10 ))
  74. fi
  75. # Multiply by number of ABIs :).
  76. local abis=( $(multilib_get_enabled_abis) )
  77. (( build_size *= ${#abis[@]} ))
  78. local CHECKREQS_DISK_BUILD=${build_size}M
  79. check-reqs_pkg_pretend
  80. }
  81. pkg_pretend() {
  82. check_space
  83. }
  84. pkg_setup() {
  85. check_space
  86. LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
  87. python-single-r1_pkg_setup
  88. }
  89. src_unpack() {
  90. # create extra parent dirs for CLANG_RESOURCE_DIR
  91. mkdir -p x/y || die
  92. cd x/y || die
  93. default
  94. mv clang-tools-extra-* "${S}"/tools/extra || die
  95. if use test; then
  96. mv llvm-* "${WORKDIR}"/llvm || die
  97. fi
  98. }
  99. src_prepare() {
  100. # fix finding compiler-rt libs
  101. eapply "${FILESDIR}"/9999/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch
  102. # fix stand-alone doc build
  103. eapply "${FILESDIR}"/9999/0007-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch
  104. # fix value of ATOMIC_*_LOCK_FREE
  105. # (backport, temporary reverted upstream because of FreeBSD issues)
  106. eapply "${FILESDIR}"/4.0.0/0001-Frontend-Correct-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch
  107. cd tools/extra || die
  108. # fix stand-alone test build for extra tools
  109. eapply "${FILESDIR}"/4.0.0/extra/0001-test-Fix-test-dependencies-when-using-installed-tool.patch
  110. eapply "${FILESDIR}"/4.0.0/extra/0002-test-Fix-clang-library-dir-in-LD_LIBRARY_PATH-For-st.patch
  111. cd - >/dev/null || die
  112. # User patches
  113. eapply_user
  114. }
  115. multilib_src_configure() {
  116. local llvm_version=$(llvm-config --version) || die
  117. local clang_version=$(get_version_component_range 1-3 "${llvm_version}")
  118. local mycmakeargs=(
  119. # ensure that the correct llvm-config is used
  120. -DLLVM_CONFIG="$(type -P "${CHOST}-llvm-config")"
  121. -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
  122. # relative to bindir
  123. -DCLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"
  124. -DBUILD_SHARED_LIBS=ON
  125. -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
  126. -DLLVM_BUILD_TESTS=$(usex test)
  127. # these are not propagated reliably, so redefine them
  128. -DLLVM_ENABLE_EH=ON
  129. -DLLVM_ENABLE_RTTI=ON
  130. -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
  131. # libgomp support fails to find headers without explicit -I
  132. # furthermore, it provides only syntax checking
  133. -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
  134. # override default stdlib and rtlib
  135. -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
  136. -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
  137. -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
  138. -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
  139. )
  140. use test && mycmakeargs+=(
  141. -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
  142. -DLIT_COMMAND="${EPREFIX}/usr/bin/lit"
  143. )
  144. if multilib_is_native_abi; then
  145. mycmakeargs+=(
  146. -DLLVM_BUILD_DOCS=$(usex doc)
  147. -DLLVM_ENABLE_SPHINX=$(usex doc)
  148. -DLLVM_ENABLE_DOXYGEN=OFF
  149. # workaround pthread
  150. -DPTHREAD_LIB=-pthread
  151. )
  152. use doc && mycmakeargs+=(
  153. -DCLANG_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/html"
  154. -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/tools-extra"
  155. -DSPHINX_WARNINGS_AS_ERRORS=OFF
  156. )
  157. else
  158. mycmakeargs+=(
  159. -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF
  160. )
  161. fi
  162. if tc-is-cross-compiler; then
  163. [[ -x "/usr/bin/clang-tblgen" ]] \
  164. || die "/usr/bin/clang-tblgen not found or usable"
  165. mycmakeargs+=(
  166. -DCMAKE_CROSSCOMPILING=ON
  167. -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
  168. )
  169. fi
  170. cmake-utils_src_configure
  171. }
  172. multilib_src_compile() {
  173. cmake-utils_src_compile
  174. # provide a symlink for tests
  175. if [[ ! -L ${WORKDIR}/lib/clang ]]; then
  176. mkdir -p "${WORKDIR}"/lib || die
  177. ln -s "${BUILD_DIR}/$(get_libdir)/clang" "${WORKDIR}"/lib/clang || die
  178. fi
  179. }
  180. multilib_src_test() {
  181. # respect TMPDIR!
  182. local -x LIT_PRESERVES_TMP=1
  183. cmake-utils_src_make check-clang
  184. multilib_is_native_abi && cmake-utils_src_make check-clang-tools
  185. }
  186. src_install() {
  187. MULTILIB_WRAPPED_HEADERS=(
  188. /usr/include/clang/Config/config.h
  189. )
  190. multilib-minimal_src_install
  191. # Move runtime headers to /usr/lib/clang, where they belong
  192. mv "${ED%/}"/usr/include/clangrt "${ED%/}"/usr/lib/clang || die
  193. # move (remaining) wrapped headers back
  194. mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die
  195. # Apply CHOST and version suffix to clang tools
  196. # note: we use two version components here (vs 3 in runtime path)
  197. local llvm_version=$(llvm-config --version) || die
  198. local clang_version=$(get_version_component_range 1-2 "${llvm_version}")
  199. local clang_full_version=$(get_version_component_range 1-3 "${llvm_version}")
  200. local clang_tools=( clang clang++ clang-cl clang-cpp )
  201. local abi i
  202. # cmake gives us:
  203. # - clang-X.Y
  204. # - clang -> clang-X.Y
  205. # - clang++, clang-cl, clang-cpp -> clang
  206. # we want to have:
  207. # - clang-X.Y
  208. # - clang++-X.Y, clang-cl-X.Y, clang-cpp-X.Y -> clang-X.Y
  209. # - clang, clang++, clang-cl, clang-cpp -> clang*-X.Y
  210. # also in CHOST variant
  211. for i in "${clang_tools[@]:1}"; do
  212. rm "${ED%/}/usr/lib/llvm/${SLOT}/bin/${i}" || die
  213. dosym "clang-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}-${clang_version}"
  214. dosym "${i}-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}"
  215. done
  216. # now create target symlinks for all supported ABIs
  217. for abi in $(get_all_abis); do
  218. local abi_chost=$(get_abi_CHOST "${abi}")
  219. for i in "${clang_tools[@]}"; do
  220. dosym "${i}-${clang_version}" \
  221. "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}-${clang_version}"
  222. dosym "${abi_chost}-${i}-${clang_version}" \
  223. "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}"
  224. done
  225. done
  226. # Remove unnecessary headers on FreeBSD, bug #417171
  227. if use kernel_FreeBSD; then
  228. rm "${ED}"usr/lib/clang/${clang_full_version}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
  229. fi
  230. }
  231. multilib_src_install() {
  232. cmake-utils_src_install
  233. # move headers to /usr/include for wrapping & ABI mismatch checks
  234. # (also drop the version suffix from runtime headers)
  235. rm -rf "${ED%/}"/usr/include || die
  236. mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die
  237. mv "${ED%/}"/usr/lib/llvm/${SLOT}/$(get_libdir)/clang "${ED%/}"/usr/include/clangrt || die
  238. }
  239. multilib_src_install_all() {
  240. python_fix_shebang "${ED}"
  241. if use static-analyzer; then
  242. python_optimize "${ED}"usr/lib/llvm/${SLOT}/share/scan-view
  243. fi
  244. # install pre-generated manpages
  245. if ! use doc; then
  246. insinto "/usr/lib/llvm/${SLOT}/share/man/man1"
  247. doins "${WORKDIR}/x/y/llvm-manpages-${PV}/clang"/*.1
  248. fi
  249. docompress "/usr/lib/llvm/${SLOT}/share/man"
  250. # match 'html' non-compression
  251. use doc && docompress -x "/usr/share/doc/${PF}/tools-extra"
  252. # +x for some reason; TODO: investigate
  253. use static-analyzer && fperms a-x "/usr/lib/llvm/${SLOT}/share/man/man1/scan-build.1"
  254. }