libcxx-4.0.0.ebuild 6.2 KB

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