libcxx-8.0.1.ebuild (6539B)
1 # Copyright 1999-2020 Gentoo Authors 2 # Distributed under the terms of the GNU General Public License v2 3 4 EAPI=7 5 6 # Ninja provides better scalability and cleaner verbose output, and is used 7 # throughout all LLVM projects. 8 : ${CMAKE_MAKEFILE_GENERATOR:=ninja} 9 # (needed due to CMAKE_BUILD_TYPE != Gentoo) 10 CMAKE_MIN_VERSION=3.7.0-r1 11 PYTHON_COMPAT=( python2_7 ) 12 13 inherit cmake-multilib llvm multiprocessing python-any-r1 \ 14 toolchain-funcs 15 16 MY_P=${P}.src 17 DESCRIPTION="New implementation of the C++ standard library, targeting C++11" 18 HOMEPAGE="https://libcxx.llvm.org/" 19 SRC_URI="https://github.com/llvm/llvm-project/releases/download/llvmorg-${PV}/${MY_P}.tar.xz" 20 21 LICENSE="|| ( UoI-NCSA MIT )" 22 SLOT="0" 23 KEYWORDS="amd64 arm arm64 x86" 24 IUSE="elibc_glibc elibc_musl +libcxxabi libcxxrt +libunwind +static-libs test" 25 REQUIRED_USE="libunwind? ( || ( libcxxabi libcxxrt ) ) 26 ?? ( libcxxabi libcxxrt )" 27 RESTRICT="!test? ( test )" 28 29 RDEPEND=" 30 libcxxabi? ( ~sys-libs/libcxxabi-${PV}[libunwind=,static-libs?,${MULTILIB_USEDEP}] ) 31 libcxxrt? ( sys-libs/libcxxrt[libunwind=,static-libs?,${MULTILIB_USEDEP}] ) 32 !libcxxabi? ( !libcxxrt? ( >=sys-devel/gcc-4.7:=[cxx] ) )" 33 # llvm-6 for new lit options 34 # clang-3.9.0 installs necessary target symlinks unconditionally 35 # which removes the need for MULTILIB_USEDEP 36 DEPEND="${RDEPEND} 37 test? ( >=sys-devel/clang-3.9.0 38 $(python_gen_any_dep 'dev-python/lit[${PYTHON_USEDEP}]') ) 39 app-arch/xz-utils 40 >=sys-devel/llvm-6" 41 42 S=${WORKDIR}/${MY_P} 43 44 DOCS=( CREDITS.TXT ) 45 46 PATCHES=( 47 # Add link flag "-Wl,-z,defs" to avoid underlinking; this is needed in a 48 # out-of-tree build. 49 "${FILESDIR}/${PN}-3.9-cmake-link-flags.patch" 50 ) 51 52 # least intrusive of all 53 CMAKE_BUILD_TYPE=RelWithDebInfo 54 55 python_check_deps() { 56 has_version "dev-python/lit[${PYTHON_USEDEP}]" 57 } 58 59 pkg_setup() { 60 llvm_pkg_setup 61 use test && python-any-r1_pkg_setup 62 63 if ! use libcxxabi && ! use libcxxrt && ! tc-is-gcc ; then 64 eerror "To build ${PN} against libsupc++, you have to use gcc. Other" 65 eerror "compilers are not supported. Please set CC=gcc and CXX=g++" 66 eerror "and try again." 67 die 68 fi 69 } 70 71 test_compiler() { 72 $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \ 73 <<<'int main() { return 0; }' &>/dev/null 74 } 75 76 src_configure() { 77 # note: we need to do this before multilib kicks in since it will 78 # alter the CHOST 79 local cxxabi cxxabi_incs 80 if use libcxxabi; then 81 cxxabi=libcxxabi 82 cxxabi_incs="${EPREFIX}/usr/include/libcxxabi" 83 elif use libcxxrt; then 84 cxxabi=libcxxrt 85 cxxabi_incs="${EPREFIX}/usr/include/libcxxrt" 86 else 87 local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)" 88 cxxabi=libsupc++ 89 cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}" 90 fi 91 92 multilib-minimal_src_configure 93 } 94 95 multilib_src_configure() { 96 # we want -lgcc_s for unwinder, and for compiler runtime when using 97 # gcc, clang with gcc runtime (or any unknown compiler) 98 local extra_libs=() want_gcc_s=ON 99 if use libunwind; then 100 # work-around missing -lunwind upstream 101 extra_libs+=( -lunwind ) 102 # if we're using libunwind and clang with compiler-rt, we want 103 # to link to compiler-rt instead of -lgcc_s 104 if tc-is-clang; then 105 local compiler_rt=$($(tc-getCC) ${CFLAGS} ${CPPFLAGS} \ 106 ${LDFLAGS} -print-libgcc-file-name) 107 if [[ ${compiler_rt} == *libclang_rt* ]]; then 108 want_gcc_s=OFF 109 extra_libs+=( "${compiler_rt}" ) 110 fi 111 fi 112 fi 113 114 # bootstrap: cmake is unhappy if compiler can't link to stdlib 115 local nolib_flags=( -nodefaultlibs -lc ) 116 if ! test_compiler; then 117 if test_compiler "${nolib_flags[@]}"; then 118 local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}" 119 ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}" 120 fi 121 fi 122 123 local libdir=$(get_libdir) 124 local mycmakeargs=( 125 -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib} 126 -DLIBCXX_ENABLE_SHARED=ON 127 -DLIBCXX_ENABLE_STATIC=$(usex static-libs) 128 -DLIBCXX_CXX_ABI=${cxxabi} 129 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi_incs} 130 # we're using our own mechanism for generating linker scripts 131 -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF 132 -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl) 133 -DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s} 134 -DLIBCXX_INCLUDE_TESTS=$(usex test) 135 -DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}" 136 ) 137 138 if use test; then 139 local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null) 140 local jobs=${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")} 141 142 [[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests" 143 144 mycmakeargs+=( 145 -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit" 146 -DLLVM_LIT_ARGS="-vv;-j;${jobs};--param=cxx_under_test=${clang_path}" 147 ) 148 fi 149 cmake-utils_src_configure 150 } 151 152 multilib_src_test() { 153 cmake-utils_src_make check-libcxx 154 } 155 156 # Usage: deps 157 gen_ldscript() { 158 local output_format 159 output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p') 160 [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )" 161 162 cat <<-END_LDSCRIPT 163 /* GNU ld script 164 Include missing dependencies 165 */ 166 ${output_format} 167 GROUP ( $@ ) 168 END_LDSCRIPT 169 } 170 171 gen_static_ldscript() { 172 local libdir=$(get_libdir) 173 local cxxabi_lib=$(usex libcxxabi "libc++abi.a" "$(usex libcxxrt "libcxxrt.a" "libsupc++.a")") 174 175 # Move it first. 176 mv "${ED}/usr/${libdir}/libc++.a" "${ED}/usr/${libdir}/libc++_static.a" || die 177 # Generate libc++.a ldscript for inclusion of its dependencies so that 178 # clang++ -stdlib=libc++ -static works out of the box. 179 local deps="libc++_static.a ${cxxabi_lib} $(usex libunwind libunwind.a libgcc_eh.a)" 180 # On Linux/glibc it does not link without libpthread or libdl. It is 181 # fine on FreeBSD. 182 use elibc_glibc && deps+=" libpthread.a libdl.a" 183 184 gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.a" || die 185 } 186 187 gen_shared_ldscript() { 188 local libdir=$(get_libdir) 189 # libsupc++ doesn't have a shared version 190 local cxxabi_lib=$(usex libcxxabi "libc++abi.so" "$(usex libcxxrt "libcxxrt.so" "libsupc++.a")") 191 192 mv "${ED}/usr/${libdir}/libc++.so" "${ED}/usr/${libdir}/libc++_shared.so" || die 193 local deps="libc++_shared.so ${cxxabi_lib} $(usex libunwind libunwind.so libgcc_s.so)" 194 195 gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.so" || die 196 } 197 198 multilib_src_install() { 199 cmake-utils_src_install 200 gen_shared_ldscript 201 use static-libs && gen_static_ldscript 202 } 203 204 pkg_postinst() { 205 elog "This package (${PN}) is mainly intended as a replacement for the C++" 206 elog "standard library when using clang." 207 elog "To use it, instead of libstdc++, use:" 208 elog " clang++ -stdlib=libc++" 209 elog "to compile your C++ programs." 210 }