3 |
3 |
|
4 |
4 |
EAPI=8
|
5 |
5 |
|
6 |
|
PYTHON_COMPAT=( python3_{9..10} )
|
7 |
|
inherit cmake-multilib llvm llvm.org python-any-r1 toolchain-funcs
|
|
6 |
PYTHON_COMPAT=( python3_{9..11} )
|
|
7 |
inherit cmake-multilib flag-o-matic llvm llvm.org python-any-r1 \
|
|
8 |
toolchain-funcs
|
8 |
9 |
|
9 |
10 |
DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
|
10 |
11 |
HOMEPAGE="https://libcxx.llvm.org/"
|
... | ... | |
12 |
13 |
LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
|
13 |
14 |
SLOT="0"
|
14 |
15 |
KEYWORDS="amd64 arm arm64 ~riscv sparc x86 ~x64-macos"
|
15 |
|
IUSE="+libcxxabi +libunwind +static-libs test"
|
|
16 |
IUSE="+clang +libcxxabi +static-libs test"
|
|
17 |
REQUIRED_USE="test? ( clang )"
|
16 |
18 |
RESTRICT="!test? ( test )"
|
17 |
|
REQUIRED_USE="libunwind? ( libcxxabi )"
|
18 |
19 |
|
19 |
20 |
RDEPEND="
|
20 |
21 |
libcxxabi? (
|
21 |
|
~sys-libs/libcxxabi-${PV}[libunwind=,static-libs?,${MULTILIB_USEDEP}]
|
|
22 |
~sys-libs/libcxxabi-${PV}[static-libs?,${MULTILIB_USEDEP}]
|
22 |
23 |
)
|
23 |
24 |
!libcxxabi? ( >=sys-devel/gcc-4.7:=[cxx] )
|
24 |
25 |
"
|
25 |
|
# llvm-6 for new lit options
|
26 |
|
# clang-3.9.0 installs necessary target symlinks unconditionally
|
27 |
|
# which removes the need for MULTILIB_USEDEP
|
28 |
26 |
DEPEND="
|
29 |
27 |
${RDEPEND}
|
30 |
|
>=sys-devel/llvm-6
|
|
28 |
sys-devel/llvm:${LLVM_MAJOR}
|
31 |
29 |
"
|
32 |
30 |
BDEPEND="
|
|
31 |
clang? (
|
|
32 |
sys-devel/clang:${LLVM_MAJOR}
|
|
33 |
)
|
33 |
34 |
!test? (
|
34 |
35 |
${PYTHON_DEPS}
|
35 |
36 |
)
|
36 |
37 |
test? (
|
37 |
38 |
>=dev-util/cmake-3.16
|
38 |
|
>=sys-devel/clang-3.9.0
|
39 |
39 |
sys-devel/gdb[python]
|
40 |
40 |
$(python_gen_any_dep 'dev-python/lit[${PYTHON_USEDEP}]')
|
41 |
41 |
)
|
42 |
42 |
"
|
43 |
43 |
|
44 |
44 |
LLVM_COMPONENTS=( runtimes libcxx{,abi} llvm/{cmake,utils/llvm-lit} cmake )
|
45 |
|
LLVM_PATCHSET=${PV}-r2
|
46 |
45 |
llvm.org_set_globals
|
47 |
46 |
|
48 |
47 |
python_check_deps() {
|
... | ... | |
55 |
54 |
# bootstrap-prefix to set the appropriate path vars to LLVM instead
|
56 |
55 |
# of using llvm_pkg_setup.
|
57 |
56 |
if [[ ${CHOST} != *-darwin* ]] || has_version sys-devel/llvm; then
|
58 |
|
llvm_pkg_setup
|
|
57 |
LLVM_MAX_SLOT=${LLVM_MAJOR} llvm_pkg_setup
|
59 |
58 |
fi
|
60 |
59 |
python-any-r1_pkg_setup
|
61 |
60 |
|
... | ... | |
78 |
77 |
local cxxabi cxxabi_incs
|
79 |
78 |
if use libcxxabi; then
|
80 |
79 |
cxxabi=system-libcxxabi
|
81 |
|
cxxabi_incs="${EPREFIX}/usr/include/libcxxabi"
|
|
80 |
cxxabi_incs="${EPREFIX}/usr/include/c++/v1"
|
82 |
81 |
else
|
83 |
82 |
local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)"
|
84 |
83 |
cxxabi=libsupc++
|
... | ... | |
89 |
88 |
}
|
90 |
89 |
|
91 |
90 |
multilib_src_configure() {
|
92 |
|
# we want -lgcc_s for unwinder, and for compiler runtime when using
|
93 |
|
# gcc, clang with gcc runtime (or any unknown compiler)
|
94 |
|
local extra_libs=() want_gcc_s=ON want_compiler_rt=OFF
|
95 |
|
if use libunwind; then
|
96 |
|
# work-around missing -lunwind upstream
|
97 |
|
extra_libs+=( -lunwind )
|
98 |
|
# if we're using libunwind and clang with compiler-rt, we want
|
99 |
|
# to link to compiler-rt instead of -lgcc_s
|
100 |
|
if tc-is-clang; then
|
101 |
|
local compiler_rt=$($(tc-getCC) ${CFLAGS} ${CPPFLAGS} \
|
102 |
|
${LDFLAGS} -print-libgcc-file-name)
|
103 |
|
if [[ ${compiler_rt} == *libclang_rt* ]]; then
|
104 |
|
want_gcc_s=OFF
|
105 |
|
want_compiler_rt=ON
|
106 |
|
extra_libs+=( "${compiler_rt}" )
|
107 |
|
fi
|
108 |
|
fi
|
109 |
|
elif [[ ${CHOST} == *-darwin* ]] && tc-is-clang; then
|
110 |
|
# clang-based darwin prefix disables libunwind useflag during
|
111 |
|
# bootstrap, because libunwind is not in the prefix yet.
|
112 |
|
# override the default, though, because clang based libcxx
|
113 |
|
# should never use gcc_s on Darwin.
|
114 |
|
want_gcc_s=OFF
|
115 |
|
# compiler_rt is not available in EPREFIX during bootstrap,
|
116 |
|
# so we cannot link to it yet anyway, so keep the defaults
|
117 |
|
# of want_compiler_rt=OFF and extra_libs=()
|
|
91 |
if use clang; then
|
|
92 |
local -x CC=${CHOST}-clang
|
|
93 |
local -x CXX=${CHOST}-clang++
|
|
94 |
strip-unsupported-flags
|
118 |
95 |
fi
|
119 |
96 |
|
|
97 |
# link to compiler-rt
|
|
98 |
local use_compiler_rt=OFF
|
|
99 |
[[ $(tc-get-c-rtlib) == compiler-rt ]] && use_compiler_rt=ON
|
|
100 |
|
120 |
101 |
# bootstrap: cmake is unhappy if compiler can't link to stdlib
|
121 |
102 |
local nolib_flags=( -nodefaultlibs -lc )
|
122 |
103 |
if ! test_compiler; then
|
... | ... | |
128 |
109 |
|
129 |
110 |
local libdir=$(get_libdir)
|
130 |
111 |
local mycmakeargs=(
|
|
112 |
-DCMAKE_CXX_COMPILER_TARGET="${CHOST}"
|
131 |
113 |
-DPython3_EXECUTABLE="${PYTHON}"
|
132 |
114 |
-DLLVM_ENABLE_RUNTIMES=libcxx
|
133 |
115 |
-DLLVM_INCLUDE_TESTS=OFF
|
... | ... | |
140 |
122 |
# we're using our own mechanism for generating linker scripts
|
141 |
123 |
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF
|
142 |
124 |
-DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl)
|
143 |
|
-DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s}
|
144 |
125 |
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
|
145 |
126 |
-DLIBCXX_INCLUDE_TESTS=$(usex test)
|
146 |
|
-DLIBCXX_USE_COMPILER_RT=${want_compiler_rt}
|
147 |
|
-DLIBCXX_HAS_ATOMIC_LIB=${want_gcc_s}
|
148 |
|
-DLIBCXX_TARGET_TRIPLE="${CHOST}"
|
149 |
|
-DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}"
|
|
127 |
-DLIBCXX_USE_COMPILER_RT=${use_compiler_rt}
|
150 |
128 |
)
|
151 |
129 |
|
152 |
130 |
if use test; then
|
153 |
|
local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null)
|
154 |
|
[[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests"
|
155 |
|
|
156 |
131 |
mycmakeargs+=(
|
157 |
132 |
-DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
|
158 |
|
-DLLVM_LIT_ARGS="$(get_lit_flags);--param=cxx_under_test=${clang_path}"
|
159 |
|
-DLIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABI=ON
|
|
133 |
-DLLVM_LIT_ARGS="$(get_lit_flags)"
|
160 |
134 |
-DPython3_EXECUTABLE="${PYTHON}"
|
161 |
135 |
)
|
162 |
136 |
fi
|
163 |
137 |
cmake_src_configure
|
164 |
138 |
}
|
165 |
139 |
|
|
140 |
multilib_src_compile() {
|
|
141 |
cmake_src_compile
|
|
142 |
if [[ ${CHOST} != *-darwin* ]] ; then
|
|
143 |
gen_shared_ldscript
|
|
144 |
use static-libs && gen_static_ldscript
|
|
145 |
fi
|
|
146 |
}
|
|
147 |
|
166 |
148 |
multilib_src_test() {
|
167 |
149 |
local -x LIT_PRESERVES_TMP=1
|
168 |
150 |
cmake_build check-cxx
|
169 |
151 |
}
|
170 |
152 |
|
|
153 |
multilib_src_install() {
|
|
154 |
cmake_src_install
|
|
155 |
# since we've replaced libc++.{a,so} with ldscripts, now we have to
|
|
156 |
# install the extra symlinks
|
|
157 |
if [[ ${CHOST} != *-darwin* ]] ; then
|
|
158 |
dolib.so lib/libc++_shared.so
|
|
159 |
use static-libs && dolib.a lib/libc++_static.a
|
|
160 |
fi
|
|
161 |
}
|
|
162 |
|
171 |
163 |
# Usage: deps
|
172 |
164 |
gen_ldscript() {
|
173 |
165 |
local output_format
|
... | ... | |
184 |
176 |
}
|
185 |
177 |
|
186 |
178 |
gen_static_ldscript() {
|
187 |
|
local libdir=$(get_libdir)
|
188 |
|
local cxxabi_lib=$(usex libcxxabi "libc++abi.a" "libsupc++.a")
|
189 |
|
|
190 |
179 |
# Move it first.
|
191 |
|
mv "${ED}/usr/${libdir}/libc++.a" "${ED}/usr/${libdir}/libc++_static.a" || die
|
|
180 |
mv lib/libc++{,_static}.a || die
|
192 |
181 |
# Generate libc++.a ldscript for inclusion of its dependencies so that
|
193 |
182 |
# clang++ -stdlib=libc++ -static works out of the box.
|
194 |
|
local deps="libc++_static.a ${cxxabi_lib} $(usex libunwind libunwind.a libgcc_eh.a)"
|
|
183 |
local deps=(
|
|
184 |
libc++_static.a
|
|
185 |
$(usex libcxxabi libc++abi.a libsupc++.a)
|
|
186 |
)
|
195 |
187 |
# On Linux/glibc it does not link without libpthread or libdl. It is
|
196 |
188 |
# fine on FreeBSD.
|
197 |
|
use elibc_glibc && deps+=" libpthread.a libdl.a"
|
|
189 |
use elibc_glibc && deps+=( libpthread.a libdl.a )
|
198 |
190 |
|
199 |
|
gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.a" || die
|
|
191 |
gen_ldscript "${deps[*]}" > lib/libc++.a || die
|
200 |
192 |
}
|
201 |
193 |
|
202 |
194 |
gen_shared_ldscript() {
|
203 |
|
local libdir=$(get_libdir)
|
204 |
|
# libsupc++ doesn't have a shared version
|
205 |
|
local cxxabi_lib=$(usex libcxxabi "libc++abi.so" "libsupc++.a")
|
206 |
|
|
207 |
|
mv "${ED}/usr/${libdir}/libc++.so" "${ED}/usr/${libdir}/libc++_shared.so" || die
|
208 |
|
local deps="libc++_shared.so ${cxxabi_lib} $(usex libunwind libunwind.so libgcc_s.so)"
|
209 |
|
|
210 |
|
gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.so" || die
|
211 |
|
}
|
212 |
|
|
213 |
|
multilib_src_install() {
|
214 |
|
cmake_src_install
|
215 |
|
if [[ ${CHOST} != *-darwin* ]] ; then
|
216 |
|
gen_shared_ldscript
|
217 |
|
use static-libs && gen_static_ldscript
|
218 |
|
fi
|
219 |
|
}
|
|
195 |
# Move it first.
|
|
196 |
mv lib/libc++{,_shared}.so || die
|
|
197 |
local deps=(
|
|
198 |
libc++_shared.so
|
|
199 |
# libsupc++ doesn't have a shared version
|
|
200 |
$(usex libcxxabi libc++abi.so libsupc++.a)
|
|
201 |
)
|
220 |
202 |
|
221 |
|
pkg_postinst() {
|
222 |
|
elog "This package (${PN}) is mainly intended as a replacement for the C++"
|
223 |
|
elog "standard library when using clang."
|
224 |
|
elog "To use it, instead of libstdc++, use:"
|
225 |
|
elog " clang++ -stdlib=libc++"
|
226 |
|
elog "to compile your C++ programs."
|
|
203 |
gen_ldscript "${deps[*]}" > lib/libc++.so || die
|
227 |
204 |
}
|