libcxx-9999.ebuild 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. # Ninja provides better scalability and cleaner verbose output, and is used
  5. # throughout all LLVM projects.
  6. : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
  7. # (needed due to CMAKE_BUILD_TYPE != Gentoo)
  8. CMAKE_MIN_VERSION=3.7.0-r1
  9. EGIT_REPO_URI="http://llvm.org/git/libcxx.git
  10. https://github.com/llvm-mirror/libcxx.git"
  11. PYTHON_COMPAT=( python2_7 )
  12. [[ ${PV} == 9999 ]] && SCM="git-r3" || SCM=""
  13. inherit ${SCM} cmake-multilib llvm python-any-r1 toolchain-funcs
  14. DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
  15. HOMEPAGE="http://libcxx.llvm.org/"
  16. if [[ ${PV} != 9999 ]] ; then
  17. SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz"
  18. S="${WORKDIR}/${P}.src"
  19. else
  20. SRC_URI=""
  21. fi
  22. LICENSE="|| ( UoI-NCSA MIT )"
  23. SLOT="0"
  24. if [[ ${PV} != 9999 ]] ; then
  25. KEYWORDS="~amd64 ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux"
  26. else
  27. KEYWORDS=""
  28. fi
  29. IUSE="elibc_glibc elibc_musl +libcxxabi libcxxrt +libunwind +static-libs test"
  30. REQUIRED_USE="libunwind? ( || ( libcxxabi libcxxrt ) )
  31. ?? ( libcxxabi libcxxrt )"
  32. RDEPEND="
  33. libcxxabi? ( ~sys-libs/libcxxabi-${PV}[libunwind=,static-libs?,${MULTILIB_USEDEP}] )
  34. libcxxrt? ( sys-libs/libcxxrt[libunwind=,static-libs?,${MULTILIB_USEDEP}] )
  35. !libcxxabi? ( !libcxxrt? ( >=sys-devel/gcc-4.7:=[cxx] ) )"
  36. # LLVM 4 required for llvm-config --cmakedir
  37. # clang-3.9.0 installs necessary target symlinks unconditionally
  38. # which removes the need for MULTILIB_USEDEP
  39. DEPEND="${RDEPEND}
  40. test? ( >=sys-devel/clang-3.9.0
  41. $(python_gen_any_dep 'dev-python/lit[${PYTHON_USEDEP}]') )
  42. app-arch/xz-utils
  43. >=sys-devel/llvm-4"
  44. DOCS=( CREDITS.TXT )
  45. PATCHES=(
  46. # Add link flag "-Wl,-z,defs" to avoid underlinking; this is needed in a
  47. # out-of-tree build.
  48. "${FILESDIR}/${PN}-3.9-cmake-link-flags.patch"
  49. )
  50. # least intrusive of all
  51. CMAKE_BUILD_TYPE=RelWithDebInfo
  52. python_check_deps() {
  53. has_version "dev-python/lit[${PYTHON_USEDEP}]"
  54. }
  55. pkg_setup() {
  56. llvm_pkg_setup
  57. use test && python-any-r1_pkg_setup
  58. if ! use libcxxabi && ! use libcxxrt && ! tc-is-gcc ; then
  59. eerror "To build ${PN} against libsupc++, you have to use gcc. Other"
  60. eerror "compilers are not supported. Please set CC=gcc and CXX=g++"
  61. eerror "and try again."
  62. die
  63. fi
  64. if tc-is-gcc && [[ $(gcc-version) < 4.7 ]] ; then
  65. eerror "${PN} needs to be built with gcc-4.7 or later (or other"
  66. eerror "conformant compilers). Please use gcc-config to switch to"
  67. eerror "gcc-4.7 or later version."
  68. die
  69. fi
  70. }
  71. multilib_src_configure() {
  72. local cxxabi cxxabi_incs
  73. if use libcxxabi; then
  74. cxxabi=libcxxabi
  75. cxxabi_incs="${EPREFIX}/usr/include/libcxxabi"
  76. elif use libcxxrt; then
  77. cxxabi=libcxxrt
  78. cxxabi_incs="${EPREFIX}/usr/include/libcxxrt"
  79. else
  80. local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)"
  81. cxxabi=libsupc++
  82. cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}"
  83. fi
  84. # we want -lgcc_s for unwinder, and for compiler runtime when using
  85. # gcc, clang with gcc runtime (or any unknown compiler)
  86. local extra_libs=() want_gcc_s=ON
  87. if use libunwind; then
  88. # work-around missing -lunwind upstream
  89. extra_libs+=( -lunwind )
  90. # if we're using libunwind and clang with compiler-rt, we want
  91. # to link to compiler-rt instead of -lgcc_s
  92. if tc-is-clang; then
  93. # get the full library list out of 'pretend mode'
  94. # and grep it for libclang_rt references
  95. local args=( $($(tc-getCC) -### -x c - 2>&1 | tail -n 1) )
  96. local i
  97. for i in "${args[@]}"; do
  98. if [[ ${i} == *libclang_rt* ]]; then
  99. want_gcc_s=OFF
  100. extra_libs+=( "${i}" )
  101. fi
  102. done
  103. fi
  104. fi
  105. local libdir=$(get_libdir)
  106. local mycmakeargs=(
  107. -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib}
  108. -DLIBCXX_ENABLE_SHARED=ON
  109. -DLIBCXX_ENABLE_STATIC=$(usex static-libs)
  110. -DLIBCXX_CXX_ABI=${cxxabi}
  111. -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi_incs}
  112. # we're using our own mechanism for generating linker scripts
  113. -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF
  114. -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl)
  115. -DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s}
  116. -DLIBCXX_INCLUDE_TESTS=$(usex test)
  117. -DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}"
  118. )
  119. if use test; then
  120. mycmakeargs+=(
  121. # this can be any directory, it just needs to exist...
  122. # FIXME: remove this once https://reviews.llvm.org/D25093 is merged
  123. -DLLVM_MAIN_SRC_DIR="${T}"
  124. -DLIT_COMMAND="${EPREFIX}"/usr/bin/lit
  125. )
  126. fi
  127. cmake-utils_src_configure
  128. }
  129. multilib_src_test() {
  130. local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null)
  131. [[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests"
  132. sed -i -e "/cxx_under_test/s^\".*\"^\"${clang_path}\"^" test/lit.site.cfg || die
  133. cmake-utils_src_make check-libcxx
  134. }
  135. # Usage: deps
  136. gen_ldscript() {
  137. local output_format
  138. output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
  139. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
  140. cat <<-END_LDSCRIPT
  141. /* GNU ld script
  142. Include missing dependencies
  143. */
  144. ${output_format}
  145. GROUP ( $@ )
  146. END_LDSCRIPT
  147. }
  148. gen_static_ldscript() {
  149. local libdir=$(get_libdir)
  150. local cxxabi_lib=$(usex libcxxabi "libc++abi.a" "$(usex libcxxrt "libcxxrt.a" "libsupc++.a")")
  151. # Move it first.
  152. mv "${ED}/usr/${libdir}/libc++.a" "${ED}/usr/${libdir}/libc++_static.a" || die
  153. # Generate libc++.a ldscript for inclusion of its dependencies so that
  154. # clang++ -stdlib=libc++ -static works out of the box.
  155. local deps="libc++_static.a ${cxxabi_lib} $(usex libunwind libunwind.a libgcc_eh.a)"
  156. # On Linux/glibc it does not link without libpthread or libdl. It is
  157. # fine on FreeBSD.
  158. use elibc_glibc && deps+=" libpthread.a libdl.a"
  159. gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.a" || die
  160. }
  161. gen_shared_ldscript() {
  162. local libdir=$(get_libdir)
  163. # libsupc++ doesn't have a shared version
  164. local cxxabi_lib=$(usex libcxxabi "libc++abi.so" "$(usex libcxxrt "libcxxrt.so" "libsupc++.a")")
  165. mv "${ED}/usr/${libdir}/libc++.so" "${ED}/usr/${libdir}/libc++_shared.so" || die
  166. local deps="libc++_shared.so ${cxxabi_lib} $(usex libunwind libunwind.so libgcc_s.so)"
  167. gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.so" || die
  168. }
  169. multilib_src_install() {
  170. cmake-utils_src_install
  171. gen_shared_ldscript
  172. use static-libs && gen_static_ldscript
  173. }
  174. pkg_postinst() {
  175. elog "This package (${PN}) is mainly intended as a replacement for the C++"
  176. elog "standard library when using clang."
  177. elog "To use it, instead of libstdc++, use:"
  178. elog " clang++ -stdlib=libc++"
  179. elog "to compile your C++ programs."
  180. }