Gentoo Archives: gentoo-commits

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