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