libcxx-3.8.1.ebuild 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. ESVN_REPO_URI="http://llvm.org/svn/llvm-project/libcxx/trunk"
  5. [ "${PV%9999}" != "${PV}" ] && SCM="subversion" || SCM=""
  6. inherit ${SCM} flag-o-matic toolchain-funcs multilib multilib-minimal
  7. DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
  8. HOMEPAGE="http://libcxx.llvm.org/"
  9. if [ "${PV%9999}" = "${PV}" ] ; then
  10. SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz"
  11. S="${WORKDIR}/${P}.src"
  12. else
  13. SRC_URI=""
  14. fi
  15. LICENSE="|| ( UoI-NCSA MIT )"
  16. SLOT="0"
  17. if [ "${PV%9999}" = "${PV}" ] ; then
  18. KEYWORDS="~amd64 ~mips ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux"
  19. else
  20. KEYWORDS=""
  21. fi
  22. IUSE="elibc_glibc elibc_musl +libcxxrt libunwind +static-libs test"
  23. REQUIRED_USE="libunwind? ( libcxxrt )"
  24. RDEPEND="libcxxrt? ( >=sys-libs/libcxxrt-0.0_p20130725[libunwind=,static-libs?,${MULTILIB_USEDEP}] )
  25. !libcxxrt? ( >=sys-devel/gcc-4.7:=[cxx] )"
  26. DEPEND="${RDEPEND}
  27. test? ( sys-devel/clang )
  28. app-arch/xz-utils"
  29. DOCS=( CREDITS.TXT )
  30. pkg_setup() {
  31. if ! use libcxxrt ; then
  32. ewarn "You have disabled USE=libcxxrt. This will build ${PN} against"
  33. ewarn "libsupc++. Please note that this is not well supported."
  34. ewarn "In particular, static linking will not work."
  35. fi
  36. if tc-is-gcc && [[ $(gcc-version) < 4.7 ]] ; then
  37. eerror "${PN} needs to be built with gcc-4.7 or later (or other"
  38. eerror "conformant compilers). Please use gcc-config to switch to"
  39. eerror "gcc-4.7 or later version."
  40. die
  41. fi
  42. }
  43. src_prepare() {
  44. cp -f "${FILESDIR}/Makefile" lib/ || die
  45. use elibc_musl && epatch "${FILESDIR}/${P}-musl-support.patch"
  46. multilib_copy_sources
  47. }
  48. src_configure() {
  49. export LIBS="-lpthread -lrt -lc -l$(usex libunwind unwind gcc_s)"
  50. if use libcxxrt ; then
  51. append-cppflags -DLIBCXXRT "-I${EPREFIX}/usr/include/libcxxrt/"
  52. LIBS="-lcxxrt ${LIBS}"
  53. cp "${EPREFIX}/usr/include/libcxxrt/"*.h "${S}/include"
  54. else
  55. # Very hackish, see $HOMEPAGE
  56. # If someone has a clever idea, please share it!
  57. local includes="$(echo | ${CHOST}-g++ -Wp,-v -x c++ - -fsyntax-only 2>&1 | grep -C 2 '#include.*<...>' | tail -n 2 | sed -e 's/^ /-I/' | tr '\n' ' ')"
  58. local libcxx_gcc_dirs="$(echo | ${CHOST}-g++ -Wp,-v -x c++ - -fsyntax-only 2>&1 | grep -C 2 '#include.*<...>' | tail -n 2 | tr '\n' ' ')"
  59. append-cppflags -D__GLIBCXX__ ${includes}
  60. LIBS="-lsupc++ ${LIBS}"
  61. local libsupcxx_includes="cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h bits/cxxabi_tweaks.h bits/cxxabi_forced.h"
  62. for i in ${libsupcxx_includes} ; do
  63. local found=""
  64. [ -d "${S}/include/$(dirname ${i})/" ] || mkdir -p "${S}/include/$(dirname ${i})"
  65. for j in ${libcxx_gcc_dirs} ; do
  66. if [ -f "${j}/${i}" ] ; then
  67. cp "${j}/${i}" "${S}/include/$(dirname ${i})/" || die
  68. found=yes
  69. fi
  70. done
  71. [ -n "${found}" ] || die "Header not found: ${i}"
  72. done
  73. fi
  74. tc-export AR CC CXX
  75. append-ldflags "-Wl,-z,defs" # make sure we are not underlinked
  76. }
  77. multilib_src_compile() {
  78. cd "${BUILD_DIR}/lib" || die
  79. emake shared
  80. use static-libs && emake static
  81. }
  82. # Tests fail for now, if anybody is able to fix them, help is very welcome.
  83. multilib_src_test() {
  84. cd "${BUILD_DIR}/test"
  85. LD_LIBRARY_PATH="${BUILD_DIR}/lib:${LD_LIBRARY_PATH}" \
  86. CC="clang++ $(get_abi_CFLAGS) ${CXXFLAGS}" \
  87. HEADER_INCLUDE="-I${BUILD_DIR}/include" \
  88. SOURCE_LIB="-L${BUILD_DIR}/lib" \
  89. LIBS="-lm $(usex libcxxrt -lcxxrt "")" \
  90. ./testit || die
  91. # TODO: fix link against libsupc++
  92. }
  93. # Usage: deps
  94. gen_ldscript() {
  95. local output_format
  96. output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
  97. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )"
  98. cat <<-END_LDSCRIPT
  99. /* GNU ld script
  100. Include missing dependencies
  101. */
  102. ${output_format}
  103. GROUP ( $@ )
  104. END_LDSCRIPT
  105. }
  106. gen_static_ldscript() {
  107. if use libcxxrt ; then
  108. # Move it first.
  109. mv "${ED}/usr/$(get_libdir)/libc++.a" "${ED}/usr/$(get_libdir)/libc++_static.a" || die
  110. # Generate libc++.a ldscript for inclusion of its dependencies so that
  111. # clang++ -stdlib=libc++ -static works out of the box.
  112. local deps="${EPREFIX}/usr/$(get_libdir)/libc++_static.a ${EPREFIX}/usr/$(get_libdir)/libcxxrt.a"
  113. # On Linux/glibc it does not link without libpthread or libdl. It is
  114. # fine on FreeBSD.
  115. use elibc_glibc && deps="${deps} ${EPREFIX}/usr/$(get_libdir)/libpthread.a ${EPREFIX}/usr/$(get_libdir)/libdl.a"
  116. # unlike libgcc_s, libunwind is not implicitly linked
  117. use libunwind && deps="${deps} ${EPREFIX}/usr/$(get_libdir)/libunwind.a"
  118. gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.a"
  119. fi
  120. # TODO: Generate a libc++.a ldscript when building against libsupc++
  121. }
  122. gen_shared_ldscript() {
  123. if use libcxxrt ; then
  124. mv "${ED}/usr/$(get_libdir)/libc++.so" "${ED}/usr/$(get_libdir)/libc++_shared.so" || die
  125. local deps="${EPREFIX}/usr/$(get_libdir)/libc++_shared.so ${EPREFIX}/usr/$(get_libdir)/libcxxrt.so"
  126. use libunwind && deps="${deps} ${EPREFIX}/usr/$(get_libdir)/libunwind.so"
  127. gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.so"
  128. fi
  129. # TODO: Generate the linker script for other configurations too.
  130. }
  131. multilib_src_install() {
  132. cd "${BUILD_DIR}/lib"
  133. if use static-libs ; then
  134. dolib.a libc++.a
  135. gen_static_ldscript
  136. fi
  137. dolib.so libc++.so*
  138. gen_shared_ldscript
  139. }
  140. multilib_src_install_all() {
  141. einstalldocs
  142. insinto /usr/include/c++/v1
  143. doins -r include/*
  144. }
  145. pkg_postinst() {
  146. elog "This package (${PN}) is mainly intended as a replacement for the C++"
  147. elog "standard library when using clang."
  148. elog "To use it, instead of libstdc++, use:"
  149. elog " clang++ -stdlib=libc++"
  150. elog "to compile your C++ programs."
  151. }