From 600a473dc06a2527981b2e9ecc91a69774cd04f6 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Sat, 3 Sep 2016 19:28:24 +0800 Subject: sys-libs/libcxx: update live ebuild to use cmake Notable changes: - gcc is now required to build libcxx against libsupc++ - keyword ~mips is dropped to be compatible with clang/llvm --- .../libcxx/files/libcxx-3.9-cmake-link-flags.patch | 23 +++ sys-libs/libcxx/libcxx-9999.ebuild | 216 +++++++++++---------- 2 files changed, 139 insertions(+), 100 deletions(-) create mode 100644 sys-libs/libcxx/files/libcxx-3.9-cmake-link-flags.patch (limited to 'sys-libs') diff --git a/sys-libs/libcxx/files/libcxx-3.9-cmake-link-flags.patch b/sys-libs/libcxx/files/libcxx-3.9-cmake-link-flags.patch new file mode 100644 index 000000000000..bef5bc187547 --- /dev/null +++ b/sys-libs/libcxx/files/libcxx-3.9-cmake-link-flags.patch @@ -0,0 +1,23 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d618e83..0e76525 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -293,6 +293,18 @@ remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG + # so they don't get transformed into -Wno and -errors respectivly. + remove_flags(-Wno-pedantic -pedantic-errors -pedantic) + ++# FIXME: this is cribbed from HandleLLVMOptions.cmake. ++if(LIBCXX_STANDALONE_BUILD) ++ # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO ++ # build might work on ELF but fail on MachO/COFF. ++ if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR ++ ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ++ ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND ++ NOT LLVM_USE_SANITIZER) ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") ++ endif() ++endif() ++ + # Required flags ============================================================== + add_compile_flags_if_supported(-std=c++11) + if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) diff --git a/sys-libs/libcxx/libcxx-9999.ebuild b/sys-libs/libcxx/libcxx-9999.ebuild index 06a6211b8564..dc867aa6bd42 100644 --- a/sys-libs/libcxx/libcxx-9999.ebuild +++ b/sys-libs/libcxx/libcxx-9999.ebuild @@ -2,108 +2,134 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -EAPI=5 +EAPI=6 -ESVN_REPO_URI="http://llvm.org/svn/llvm-project/libcxx/trunk" +# Ninja provides better scalability and cleaner verbose output, and is used +# throughout all LLVM projects. +: ${CMAKE_MAKEFILE_GENERATOR:=ninja} +EGIT_REPO_URI="http://llvm.org/git/libcxx.git + https://github.com/llvm-mirror/libcxx.git" +CMAKE_MIN_VERSION=3.4.3 +PYTHON_COMPAT=( python2_7 ) -[ "${PV%9999}" != "${PV}" ] && SCM="subversion" || SCM="" +[[ ${PV} == 9999 ]] && SCM="git-r3" || SCM="" -inherit ${SCM} flag-o-matic toolchain-funcs multilib multilib-minimal +inherit ${SCM} cmake-multilib python-any-r1 toolchain-funcs 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" +if [[ ${PV} != 9999 ]] ; then + SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz + test? ( http://llvm.org/releases/${PV}/llvm-${PV}.src.tar.xz )" S="${WORKDIR}/${P}.src" + LLVM_S="${WORKDIR}/llvm-${PV}.src" else SRC_URI="" + LLVM_S="${WORKDIR}/llvm" fi LICENSE="|| ( UoI-NCSA MIT )" SLOT="0" -if [ "${PV%9999}" = "${PV}" ] ; then - KEYWORDS="~amd64 ~mips ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux" +if [[ ${PV} != 9999 ]] ; then + KEYWORDS="~amd64 ~x86 ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux" else KEYWORDS="" fi IUSE="elibc_glibc elibc_musl +libcxxrt libunwind +static-libs test" REQUIRED_USE="libunwind? ( libcxxrt )" -RDEPEND="libcxxrt? ( >=sys-libs/libcxxrt-0.0_p20130725[libunwind?,static-libs?,${MULTILIB_USEDEP}] ) +RDEPEND="libcxxrt? ( sys-libs/libcxxrt[libunwind=,static-libs?,${MULTILIB_USEDEP}] ) !libcxxrt? ( >=sys-devel/gcc-4.7:=[cxx] )" +# llvm-3.9.0 needed because its cmake files installation path changed, which is +# needed by libcxx DEPEND="${RDEPEND} - test? ( sys-devel/clang ) - app-arch/xz-utils" + test? ( sys-devel/clang[${MULTILIB_USEDEP}] + ${PYTHON_DEPS} ) + app-arch/xz-utils + >=sys-devel/llvm-3.9.0[${MULTILIB_USEDEP}]" DOCS=( CREDITS.TXT ) +PATCHES=( + # Add link flag "-Wl,-z,defs" to avoid underlinking; this is needed in a + # out-of-tree build. + "${FILESDIR}/${PN}-3.9-cmake-link-flags.patch" +) + 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." + use test && python_setup + + if ! use libcxxrt && ! tc-is-gcc ; then + eerror "To build ${PN} against libsupc++, you have to use gcc. Other" + eerror "compilers are not supported. Please set CC=gcc and CXX=g++" + eerror "and try again." + die 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." + if tc-is-gcc && [[ $(gcc-version) < 4.7 ]] ; then + eerror "${PN} needs to be built with gcc-4.7 or later (or other" + eerror "conformant compilers). Please use gcc-config to switch to" + eerror "gcc-4.7 or later version." die fi } -src_prepare() { - cp -f "${FILESDIR}/Makefile" lib/ || die - use elibc_musl && epatch "${FILESDIR}/${P}-musl-support.patch" - multilib_copy_sources -} +src_unpack() { + [[ ${PV} != 9999 ]] && default && return -src_configure() { - export LIBS="-lpthread -lrt -lc -l$(usex libunwind unwind gcc_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 + if use test; then + # needed for tests + git-r3_fetch "http://llvm.org/git/llvm.git + https://github.com/llvm-mirror/llvm.git" fi + git-r3_fetch - tc-export AR CC CXX - - append-ldflags "-Wl,-z,defs" # make sure we are not underlinked + if use test; then + git-r3_checkout http://llvm.org/git/llvm.git \ + "${WORKDIR}"/llvm + fi + git-r3_checkout } -multilib_src_compile() { - cd "${BUILD_DIR}/lib" || die - emake shared - use static-libs && emake static +multilib_src_configure() { + local cxxabi cxxabi_incs + if use libcxxrt; then + cxxabi=libcxxrt + cxxabi_incs="${EPREFIX}/usr/include/libcxxrt" + else + local gcc_inc="${EPREFIX}/usr/lib/gcc/${CHOST}/$(gcc-fullversion)/include/g++-v$(gcc-major-version)" + cxxabi=libsupc++ + cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}" + fi + + local libdir=$(get_libdir) + local mycmakeargs=( + -DLLVM_LIBDIR_SUFFIX=${libdir#lib} + -DLIBCXX_ENABLE_SHARED=ON + -DLIBCXX_ENABLE_STATIC=$(usex static-libs) + -DLIBCXX_CXX_ABI=${cxxabi} + -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi_incs} + # we're using our own mechanism for generating linker scripts + -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF + -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl) + -DLIBCXX_HAS_GCC_S_LIB=$(usex !libunwind) + -DLIBCXX_INCLUDE_TESTS=$(usex test) + -DCMAKE_SHARED_LINKER_FLAGS=$(usex libunwind "-lunwind" "") + ) + if use test; then + mycmakeargs+=( + -DLLVM_MAIN_SRC_DIR=${LLVM_S} + ) + fi + cmake-utils_src_configure } -# 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++ + local clang_path=$(type -P "${CHOST:+${CHOST}-}clang" 2>/dev/null) + + [[ -n ${clang_path} ]] || die "Unable to find ${CHOST}-clang for tests" + sed -i -e "/cxx_under_test/s^\".*\"^\"${clang_path}\"^" test/lit.site.cfg || die + + cmake-utils_src_make check-libcxx } # Usage: deps @@ -122,49 +148,39 @@ 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" - - # unlike libgcc_s, libunwind is not implicitly linked - use libunwind && deps="${deps} ${EPREFIX}/usr/$(get_libdir)/libunwind.a" - - gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.a" - fi - # TODO: Generate a libc++.a ldscript when building against libsupc++ + local libdir=$(get_libdir) + local cxxabi_lib=$(usex libcxxrt "libcxxrt.a" "libsupc++.a") + + # Move it first. + mv "${ED}/usr/${libdir}/libc++.a" "${ED}/usr/${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="libc++_static.a ${cxxabi_lib}" + # On Linux/glibc it does not link without libpthread or libdl. It is + # fine on FreeBSD. + use elibc_glibc && deps+=" libpthread.a libdl.a" + # unlike libgcc_s, libunwind is not implicitly linked + use libunwind && deps+=" libunwind.a" + + gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.a" || die } 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" - use libunwind && deps="${deps} ${EPREFIX}/usr/$(get_libdir)/libunwind.so" - gen_ldscript "${deps}" > "${ED}/usr/$(get_libdir)/libc++.so" - fi - # TODO: Generate the linker script for other configurations too. + local libdir=$(get_libdir) + # libsupc++ doesn't have a shared version + local cxxabi_lib=$(usex libcxxrt "libcxxrt.so" "libsupc++.a") + + mv "${ED}/usr/${libdir}/libc++.so" "${ED}/usr/${libdir}/libc++_shared.so" || die + local deps="libc++_shared.so ${cxxabi_lib}" + use libunwind && deps+=" libunwind.so" + + gen_ldscript "${deps}" > "${ED}/usr/${libdir}/libc++.so" || die } multilib_src_install() { - cd "${BUILD_DIR}/lib" - if use static-libs ; then - dolib.a libc++.a - gen_static_ldscript - fi - dolib.so libc++.so* + cmake-utils_src_install gen_shared_ldscript -} - -multilib_src_install_all() { - einstalldocs - insinto /usr/include/c++/v1 - doins -r include/* + use static-libs && gen_static_ldscript } pkg_postinst() { -- cgit v1.2.3-65-gdbad