commit:     b5eb2ede092b2d059d6e1d7799c4adfbc4b19978
Author:     Chloe Kudryavtsev <chloe.kudryavtsev <AT> gmail <DOT> com>
AuthorDate: Sat Sep 19 07:32:17 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Sep 21 08:49:33 2015 +0000
URL:        https://gitweb.gentoo.org/proj/musl.git/commit/?id=b5eb2ede

Fix LibC++ Under Musl

- Musl does not define locale-specific versions of functions (*_l)
- This may be because musl only supports UTF-8 at the moment
- This patch creates macros that redirect the *_l functions used to
  their non-localized variants.
- Also, remove checks against GLIBC's version (EMSCRIPTEN) and
  __GLIBC_PREREQ (based on vvavrychuk's 3.4.2 patch).

TODO: think about other LIBCs that might have confusing breakages due to
last change.

 sys-libs/libcxx/Manifest                           |   6 +
 sys-libs/libcxx/files/Makefile                     |  38 +++++
 .../files/libcxx-3.7.0-musl-compatibility.patch    |  70 ++++++++
 sys-libs/libcxx/files/prepare_snapshot.sh          |  16 ++
 sys-libs/libcxx/libcxx-3.7.0-r99.ebuild            | 176 +++++++++++++++++++++
 sys-libs/libcxx/metadata.xml                       |  15 ++
 6 files changed, 321 insertions(+)

diff --git a/sys-libs/libcxx/Manifest b/sys-libs/libcxx/Manifest
new file mode 100644
index 0000000..5ddeeee
--- /dev/null
+++ b/sys-libs/libcxx/Manifest
@@ -0,0 +1,6 @@
+AUX Makefile 874 SHA256 
ba99d3b7b98ed88a64f8370ba2d90e245f8e5ea9bfe302382ef8eeded0ec00b4 SHA512 
96eef2e897075bc7d9fc799ce6c54f6a33ee917efd5666376ac578cb16e15d965205630dbd076f92a3a7091d58ecc235e37bc327c211bf3594244981f089135f
 WHIRLPOOL 
0680b69fdc46c0d6fac01fc2fa0b93ff62d167a03b3ce1cc80fbe57ff04356f5ab4e71f0daec517e629697d5e34f295b66e8263f7506eaa347a500b27442933d
+AUX libcxx-3.7.0-musl-compatibility.patch 2673 SHA256 
9671760510032749208f4eacc3b1cea1757f1e7485d6449e23b2d3b69a75f62d SHA512 
f42d465880087c67f782d004729b2a75574afb752961339d7501a3d4767964b5476a071d02fb610894ff4a24631ad60ac335434abe5a0643b41dcdb70ac8638e
 WHIRLPOOL 
4da05e7820e6e813ef029efb9a8fc136d2f5c669809cc609d9e29cb56e9e8990678797a23110dec4b4e765180aa064587e04dd090aafda1eb8b8a751e935f701
+AUX prepare_snapshot.sh 427 SHA256 
9ebf22257a2e296dee41a56b0a721cd1ba459c620009ca8422ba812515ff726f SHA512 
ebac2a467f8b1dfb68f1dc46a35f8294d1cf74b70be2a008217fa13b3366ddf4a9f2ebbe611cd63824f42305c5c0304aac2f46386b2956c9e07d82d5d984b435
 WHIRLPOOL 
232a60d6a22f50c424ec9cf6f325bbb4e8e96815ba9dffdad0a5b1b872b19d20126d316ced71956978eb5ce098f72584d21104c14e232330b3893a73e4c3c358
+DIST libcxx-3.7.0.src.tar.xz 994580 SHA256 
c18f3c8333cd7e678c1424a57fe5e25efe740ca7caf62ac67152b4723f3ad08e SHA512 
e71d04efa0fafab129a97ca6f4fd7b5f185258de7455c7a25d0964f459bc6068c69c5d67199f6d7cd3541bdce630106cbaf3b7099e4737dddbdd57c77a3fe054
 WHIRLPOOL 
26672e3f6e0772504e7ee174c37e5fc20079c730ac8bd0d2563d5415ca9589360aa3be42a8aac15eb5a63c69227bd4911aa822b158b9a35e3d74ec0d71bb1300
+EBUILD libcxx-3.7.0-r99.ebuild 5444 SHA256 
caf6ad314fdbdf86e9290bbcbb1b7619b215afbcee279d3dac9b67278aae36da SHA512 
d17bc205320ec01c3546e99289d9923c1dc65214c49762f6fa41d498727c5e5cd658fe665c87b657ad41bc2c07640cd1b7fa907d6a30d9fa87e8d3fd61bbc703
 WHIRLPOOL 
0825e0cd24aebcfbe2bb23e5c1b3aba04fd65ea0a966b72c186f2ef736328b2a129eb7087e234d2ea88ddc30ab397630002a63bb898c0d76e67f16a19b58c714
+MISC metadata.xml 558 SHA256 
c9fe7077a8c7f767d7cdbe154d85dd344fb86ea246b16613242c70a40f3e1ef2 SHA512 
3f324c4959a7c9f2613b29928957fd010b35c6e9c1601f0296e7e8b7c8d59a3c27c5c04fef87ac825f2f7bb07553bc617c4405e1e22847dc8db3e7a1ebb21f50
 WHIRLPOOL 
3ade5e3852afcd533c89ce0aeead55101f23d1b31825718bfccd60fac485961df617c93962be4c60333a21335dcd6bb5630c8002fe06f456c4e177c14d434455

diff --git a/sys-libs/libcxx/files/Makefile b/sys-libs/libcxx/files/Makefile
new file mode 100644
index 0000000..029e729
--- /dev/null
+++ b/sys-libs/libcxx/files/Makefile
@@ -0,0 +1,38 @@
+CXXFLAGS+=-std=c++11 -fstrict-aliasing -Wall -Wextra -Wshadow -Wconversion \
+         -Wpadded -Wstrict-aliasing=2 -Wstrict-overflow=4
+
+SRCDIR=..
+LIB=libc++
+STATIC=libc++.a
+MAJOR=1
+MINOR=0
+SHEXT?=.so
+SHLIB=$(LIB)$(SHEXT).$(MAJOR).$(MINOR)
+SONAME=$(LIB)$(SHEXT).$(MAJOR)
+
+SRC=$(wildcard $(SRCDIR)/src/*.cpp)
+OBJ=$(SRC:$(SRCDIR)/src/%.cpp=%.o)
+SOBJ=$(SRC:$(SRCDIR)/src/%.cpp=%.So)
+
+
+%.So: $(SRCDIR)/src/%.cpp
+       $(CXX) -I$(SRCDIR)/include $(CPPFLAGS) $(CXXFLAGS) -fPIC -nostdinc++ -c 
$< -o $@
+
+%.o: $(SRCDIR)/src/%.cpp
+       $(CXX) -I$(SRCDIR)/include $(CPPFLAGS) $(CXXFLAGS) -nostdinc++ -c $< -o 
$@
+
+$(STATIC): $(OBJ)
+       $(AR) cr $@ $^
+
+static: $(STATIC)
+
+$(SHLIB): $(SOBJ)
+       $(CXX) -fPIC -nodefaultlibs $(CXXFLAGS) $(LDFLAGS) -shared 
-Wl,-soname,$(SONAME) -o $@ $^ $(LIBS)
+
+$(SONAME): $(SHLIB)
+       ln -s $< $@
+
+$(LIB)$(SHEXT): $(SONAME)
+       ln -s $< $@
+
+shared: $(SHLIB) $(SONAME) $(LIB)$(SHEXT)

diff --git a/sys-libs/libcxx/files/libcxx-3.7.0-musl-compatibility.patch 
b/sys-libs/libcxx/files/libcxx-3.7.0-musl-compatibility.patch
new file mode 100644
index 0000000..5e223bf
--- /dev/null
+++ b/sys-libs/libcxx/files/libcxx-3.7.0-musl-compatibility.patch
@@ -0,0 +1,70 @@
+diff -Naur libcxx-3.7.0.src.orig/include/__config 
libcxx-3.7.0.src/include/__config
+--- libcxx-3.7.0.src.orig/include/__config     2015-07-17 00:58:59.000000000 
+0000
++++ libcxx-3.7.0.src/include/__config  2015-09-19 07:56:55.295497669 +0000
+@@ -355,14 +355,10 @@
+ #define _LIBCPP_HAS_QUICK_EXIT
+ #elif defined(__linux__)
+ #include <features.h>
+-#if __GLIBC_PREREQ(2, 15)
+ #define _LIBCPP_HAS_QUICK_EXIT
+-#endif
+-#if __GLIBC_PREREQ(2, 17)
+ #define _LIBCPP_HAS_C11_FEATURES
+ #endif
+ #endif
+-#endif
+ 
+ #if (__has_feature(cxx_noexcept))
+ #  define _NOEXCEPT noexcept
+diff -Naur libcxx-3.7.0.src.orig/include/locale libcxx-3.7.0.src/include/locale
+--- libcxx-3.7.0.src.orig/include/locale       2015-09-19 08:02:51.101497669 
+0000
++++ libcxx-3.7.0.src/include/locale    2015-09-19 07:24:18.635497669 +0000
+@@ -11,6 +11,15 @@
+ #ifndef _LIBCPP_LOCALE
+ #define _LIBCPP_LOCALE
+ 
++// musl doesn't define _l (with locale) variants of functions, as it only 
supports UTF-8.
++// we can simply make macros that will call the non-localated ones if we're 
using musl, or rather not-using something that has the _l ones.
++// couldn't find anything glibc #defines when it creates strtoull_l (that it 
doesn't undefine a few lines later), so let's test against glibc and 
glibc-likes.
++// almost all glibc-likes define __GNU_LIBRARY__ for compatibility
++#ifndef __GNU_LIBRARY__
++#define strtoull_l(A, B, C, LOC) strtoull(A,B,C)
++#define strtoll_l(A, B, C, LOC) strtoll(A,B,C)
++#endif
++
+ /*
+     locale synopsis
+ 
+diff -Naur libcxx-3.7.0.src.orig/src/locale.cpp libcxx-3.7.0.src/src/locale.cpp
+--- libcxx-3.7.0.src.orig/src/locale.cpp       2015-07-06 15:39:36.000000000 
+0000
++++ libcxx-3.7.0.src/src/locale.cpp    2015-09-19 07:59:59.979497669 +0000
+@@ -1012,11 +1012,10 @@
+     return low;
+ }
+ 
+-#ifdef __EMSCRIPTEN__
++// we want this either way
+ extern "C" const unsigned short ** __ctype_b_loc();
+ extern "C" const int ** __ctype_tolower_loc();
+ extern "C" const int ** __ctype_toupper_loc();
+-#endif
+ 
+ #ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+ const ctype<char>::mask*
+@@ -1122,12 +1121,10 @@
+ #elif defined(_AIX)
+     return (const unsigned int *)__lc_ctype_ptr->obj->mask;
+ #else
+-    // Platform not supported: abort so the person doing the port knows what 
to
+-    // fix
+-# warning  ctype<char>::classic_table() is not implemented
+-    printf("ctype<char>::classic_table() is not implemented\n");
+-    abort();
+-    return NULL;
++// not sure any other libc like this exists, but there is no way to 
differentiate musl as of right now
++// to be fair, with the change above, this should always work
++// also, #warning is a gcc extension
++    return (const unsigned long *)*__ctype_b_loc();
+ #endif
+ }
+ #endif

diff --git a/sys-libs/libcxx/files/prepare_snapshot.sh 
b/sys-libs/libcxx/files/prepare_snapshot.sh
new file mode 100755
index 0000000..3de5a97
--- /dev/null
+++ b/sys-libs/libcxx/files/prepare_snapshot.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+VERSION=$(date +%Y%m%d)
+BASE_VERSION="0.0"
+PACKAGE="libcxx-${BASE_VERSION}_p${VERSION}"
+
+svn co http://llvm.org/svn/llvm-project/libcxx/trunk ${PACKAGE}
+
+find "${PACKAGE}" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
+find "${PACKAGE}" -type d -name '.git' -prune -print0 | xargs -0 rm -rf
+
+tar cJf ${PACKAGE}.tar.xz ${PACKAGE}
+rm -rf ${PACKAGE}/
+
+echo "Tarball: \"${PACKAGE}.tar.xz\""
+
+echo "** all done **"

diff --git a/sys-libs/libcxx/libcxx-3.7.0-r99.ebuild 
b/sys-libs/libcxx/libcxx-3.7.0-r99.ebuild
new file mode 100644
index 0000000..a557266
--- /dev/null
+++ b/sys-libs/libcxx/libcxx-3.7.0-r99.ebuild
@@ -0,0 +1,176 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=5
+
+ESVN_REPO_URI="http://llvm.org/svn/llvm-project/libcxx/trunk";
+
+[ "${PV%9999}" != "${PV}" ] && SCM="subversion" || SCM=""
+
+inherit ${SCM} flag-o-matic toolchain-funcs multilib multilib-minimal
+
+DESCRIPTION="New implementation of the C++ standard library, targeting C++11"
+HOMEPAGE="http://libcxx.llvm.org/";
+if [ "${PV%9999}" = "${PV}" ] ; then
+       SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz";
+       S="${WORKDIR}/${P}.src"
+else
+       SRC_URI=""
+fi
+
+LICENSE="|| ( UoI-NCSA MIT )"
+SLOT="0"
+if [ "${PV%9999}" = "${PV}" ] ; then
+       KEYWORDS="~amd64 ~mips ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux 
~x86-linux"
+else
+       KEYWORDS=""
+fi
+IUSE="elibc_glibc +libcxxrt +static-libs test"
+
+RDEPEND="libcxxrt? ( 
>=sys-libs/libcxxrt-0.0_p20130725[static-libs?,${MULTILIB_USEDEP}] )
+       !libcxxrt? ( >=sys-devel/gcc-4.7:=[cxx] )"
+DEPEND="${RDEPEND}
+       test? ( sys-devel/clang )
+       app-arch/xz-utils"
+
+DOCS=( CREDITS.TXT )
+
+pkg_setup() {
+       if ! use libcxxrt ; then
+               ewarn "You have disabled USE=libcxxrt. This will build ${PN} 
against"
+               ewarn "libsupc++. Please note that this is not well supported."
+               ewarn "In particular, static linking will not work."
+       fi
+       if [[ $(gcc-version) < 4.7 ]] && [[ $(tc-getCXX) != *clang++* ]] ; then
+               eerror "${PN} needs to be built with clang++ or gcc-4.7 or 
later."
+               eerror "Please use gcc-config to switch to gcc-4.7 or later 
version."
+               die
+       fi
+}
+
+src_prepare() {
+       cp -f "${FILESDIR}/Makefile" lib/ || die
+       multilib_copy_sources
+}
+
+src_unpack() {
+       unpack ${A}
+       cd ${S}
+       epatch "${FILESDIR}/${PN}-3.7.0-musl-compatibility.patch"
+}
+
+src_configure() {
+       export LIBS="-lpthread -lrt -lc -lgcc_s"
+       if use libcxxrt ; then
+               append-cppflags -DLIBCXXRT "-I${EPREFIX}/usr/include/libcxxrt/"
+               LIBS="-lcxxrt ${LIBS}"
+               cp "${EPREFIX}/usr/include/libcxxrt/"*.h "${S}/include"
+       else
+               # Very hackish, see $HOMEPAGE
+               # If someone has a clever idea, please share it!
+               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' ' ')"
+               local libcxx_gcc_dirs="$(echo | ${CHOST}-g++ -Wp,-v -x c++ - 
-fsyntax-only 2>&1 | grep -C 2 '#include.*<...>' | tail -n 2 | tr '\n' ' ')"
+               append-cppflags -D__GLIBCXX__ ${includes}
+               LIBS="-lsupc++ ${LIBS}"
+               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"
+               for i in ${libsupcxx_includes} ; do
+                       local found=""
+                       [ -d "${S}/include/$(dirname ${i})/" ] || mkdir -p 
"${S}/include/$(dirname ${i})"
+                       for j in ${libcxx_gcc_dirs} ; do
+                               if [ -f "${j}/${i}" ] ; then
+                                       cp "${j}/${i}" "${S}/include/$(dirname 
${i})/" || die
+                                       found=yes
+                               fi
+                       done
+                       [ -n "${found}" ] || die "Header not found: ${i}"
+               done
+       fi
+
+       tc-export AR CC CXX
+
+       append-ldflags "-Wl,-z,defs" # make sure we are not underlinked
+}
+
+multilib_src_compile() {
+       cd "${BUILD_DIR}/lib" || die
+       emake shared
+       use static-libs && emake static
+}
+
+# Tests fail for now, if anybody is able to fix them, help is very welcome.
+multilib_src_test() {
+       cd "${BUILD_DIR}/test"
+       LD_LIBRARY_PATH="${BUILD_DIR}/lib:${LD_LIBRARY_PATH}" \
+               CC="clang++ $(get_abi_CFLAGS) ${CXXFLAGS}" \
+               HEADER_INCLUDE="-I${BUILD_DIR}/include" \
+               SOURCE_LIB="-L${BUILD_DIR}/lib" \
+               LIBS="-lm $(usex libcxxrt -lcxxrt "")" \
+               ./testit || die
+       # TODO: fix link against libsupc++
+}
+
+# Usage: deps
+gen_ldscript() {
+       local output_format
+       output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | 
sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p')
+       [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( 
${output_format} )"
+
+       cat <<-END_LDSCRIPT
+/* GNU ld script
+   Include missing dependencies
+*/
+${output_format}
+GROUP ( $@ )
+END_LDSCRIPT
+}
+
+gen_static_ldscript() {
+       if use libcxxrt ; then
+               # Move it first.
+               mv "${ED}/usr/$(get_libdir)/libc++.a" 
"${ED}/usr/$(get_libdir)/libc++_static.a" || die
+
+               # Generate libc++.a ldscript for inclusion of its dependencies 
so that
+               # clang++ -stdlib=libc++ -static works out of the box.
+               local deps="${EPREFIX}/usr/$(get_libdir)/libc++_static.a 
${EPREFIX}/usr/$(get_libdir)/libcxxrt.a"
+               # On Linux/glibc it does not link without libpthread or libdl. 
It is
+               # fine on FreeBSD.
+               use elibc_glibc && deps="${deps} 
${EPREFIX}/usr/$(get_libdir)/libpthread.a ${EPREFIX}/usr/$(get_libdir)/libdl.a"
+
+               gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.a"
+       fi
+       # TODO: Generate a libc++.a ldscript when building against libsupc++
+}
+
+gen_shared_ldscript() {
+       if use libcxxrt ; then
+               mv "${ED}/usr/$(get_libdir)/libc++.so" 
"${ED}/usr/$(get_libdir)/libc++_shared.so" || die
+               local deps="${EPREFIX}/usr/$(get_libdir)/libc++_shared.so 
${EPREFIX}/usr/$(get_libdir)/libcxxrt.so"
+               gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.so"
+       fi
+       # TODO: Generate the linker script for other confiurations too.
+}
+
+multilib_src_install() {
+       cd "${BUILD_DIR}/lib"
+       if use static-libs ; then
+               dolib.a libc++.a
+               gen_static_ldscript
+       fi
+       dolib.so libc++.so*
+       gen_shared_ldscript
+}
+
+multilib_src_install_all() {
+       einstalldocs
+       insinto /usr/include/c++/v1
+       doins -r include/*
+}
+
+pkg_postinst() {
+       elog "This package (${PN}) is mainly intended as a replacement for the 
C++"
+       elog "standard library when using clang."
+       elog "To use it, instead of libstdc++, use:"
+       elog "    clang++ -stdlib=libc++"
+       elog "to compile your C++ programs."
+}

diff --git a/sys-libs/libcxx/metadata.xml b/sys-libs/libcxx/metadata.xml
new file mode 100644
index 0000000..578f810
--- /dev/null
+++ b/sys-libs/libcxx/metadata.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+  <herd>bsd</herd>
+  <!-- BSD is here because the plan is to have libc++ as the standard C++
+          library with clang. A llvm herd would make a lot of sense here too 
-->
+  <maintainer>
+    <email>[email protected]</email>
+    <name>Alexis Ballier</name>
+  </maintainer>
+  <use>
+         <flag name="libcxxrt">Build on top of <pkg>sys-libs/libcxxrt</pkg> 
instead of gcc's libsupc++ (avoids depending on gcc).</flag>
+  </use>
+</pkgmetadata>
+

Reply via email to