sys-libs/libcxx: Try building with -nodefaultlibs for bootstrap
authorMichał Górny <mgorny@gentoo.org>
Fri, 9 Mar 2018 23:05:14 +0000 (00:05 +0100)
committerMichał Górny <mgorny@gentoo.org>
Fri, 9 Mar 2018 23:11:26 +0000 (00:11 +0100)
Add a hack that appends -nodefaultlibs if the C++ compiler fails to link
software otherwise. This is based on what we do in sys-libs/compiler-rt
already and it should make it possible to bootstrap libc++ on systems
without C++ standard library.

sys-libs/libcxx/libcxx-6.0.0.ebuild
sys-libs/libcxx/libcxx-6.0.9999.ebuild
sys-libs/libcxx/libcxx-9999.ebuild

index 9c9b75e3d7f19cd43f39a2ac303592e056335eb1..0948ab0c6825b57beea549d87ffa7b8c9fb6b25c 100644 (file)
@@ -73,6 +73,11 @@ pkg_setup() {
        fi
 }
 
+test_compiler() {
+       $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \
+               <<<'int main() { return 0; }' &>/dev/null
+}
+
 multilib_src_configure() {
        local cxxabi cxxabi_incs
        if use libcxxabi; then
@@ -109,6 +114,15 @@ multilib_src_configure() {
                fi
        fi
 
+       # bootstrap: cmake is unhappy if compiler can't link to stdlib
+       local nolib_flags=( -nodefaultlibs -lc )
+       if ! test_compiler; then
+               if test_compiler "${nolib_flags[@]}"; then
+                       local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}"
+                       ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}"
+               fi
+       fi
+
        local libdir=$(get_libdir)
        local mycmakeargs=(
                -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib}
index cf76bba5fdfdc5b24e55f87888a4455da4554864..4e687c722c6036cf0ef97f488867368ca02db18c 100644 (file)
@@ -85,6 +85,11 @@ pkg_setup() {
        fi
 }
 
+test_compiler() {
+       $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \
+               <<<'int main() { return 0; }' &>/dev/null
+}
+
 multilib_src_configure() {
        local cxxabi cxxabi_incs
        if use libcxxabi; then
@@ -121,6 +126,15 @@ multilib_src_configure() {
                fi
        fi
 
+       # bootstrap: cmake is unhappy if compiler can't link to stdlib
+       local nolib_flags=( -nodefaultlibs -lc )
+       if ! test_compiler; then
+               if test_compiler "${nolib_flags[@]}"; then
+                       local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}"
+                       ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}"
+               fi
+       fi
+
        local libdir=$(get_libdir)
        local mycmakeargs=(
                -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib}
index 214c61d31f67dd0897e74cd663027109fafffbf4..f304a076c171848f70de09b120140d366102596e 100644 (file)
@@ -84,6 +84,11 @@ pkg_setup() {
        fi
 }
 
+test_compiler() {
+       $(tc-getCXX) ${CXXFLAGS} ${LDFLAGS} "${@}" -o /dev/null -x c++ - \
+               <<<'int main() { return 0; }' &>/dev/null
+}
+
 multilib_src_configure() {
        local cxxabi cxxabi_incs
        if use libcxxabi; then
@@ -120,6 +125,15 @@ multilib_src_configure() {
                fi
        fi
 
+       # bootstrap: cmake is unhappy if compiler can't link to stdlib
+       local nolib_flags=( -nodefaultlibs -lc )
+       if ! test_compiler; then
+               if test_compiler "${nolib_flags[@]}"; then
+                       local -x LDFLAGS="${LDFLAGS} ${nolib_flags[*]}"
+                       ewarn "${CXX} seems to lack runtime, trying with ${nolib_flags[*]}"
+               fi
+       fi
+
        local libdir=$(get_libdir)
        local mycmakeargs=(
                -DLIBCXX_LIBDIR_SUFFIX=${libdir#lib}