libcxx-3.9.0.ebuild 6.6 KB

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