From 4b15c31ae5a7f844d09c2170b2549d4a015f280d Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Wed, 11 Aug 2021 17:57:23 +0800 Subject: [PATCH] GCC: use --enable-host-shared Building 'static GCC' now correctly means to build GCC with static host libraries instead of static target libraries since it runs on host, not target. --- build | 6 ++-- library/config.sh | 5 +-- scripts/binutils.sh | 5 ++- scripts/gcc-11.2.0.sh | 1 + scripts/gcc-post.sh | 72 ++++++++++++++++++------------------------- 5 files changed, 40 insertions(+), 49 deletions(-) diff --git a/build b/build index 9f75e0375..30a181aab 100755 --- a/build +++ b/build @@ -257,7 +257,7 @@ while [[ $# > 0 ]]; do --no-strip) STRIP_ON_INSTALL=no ;; --static-gcc) BOOTSTRAPING=yes - LINK_TYPE_GCC=$LINK_TYPE_STATIC + LINK_TYPE_GCC=$LINK_TYPE_GCC_STATIC GCC_DEPS_LINK_TYPE=$LINK_TYPE_STATIC BUILD_SHARED_GCC=no LINK_TYPE_SUFFIX=static @@ -879,10 +879,8 @@ for rule in ${SUBTARGETS[@]}; do _reverse_arch=$(func_get_reverse_arch $BUILD_ARCHITECTURE) _reverse_bits=$(func_get_reverse_arch_bit $BUILD_ARCHITECTURE) mkdir -p $TESTS_ROOT_DIR/${_reverse_arch} - [[ $BUILD_SHARED_GCC == yes ]] && { - cp -f $( find $PREFIX/$TARGET/lib${_reverse_bits} -type f \( -iname *.dll \) ) \ + cp -f $( find $PREFIX/$TARGET/lib${_reverse_bits} -type f \( -iname *.dll \) ) \ $TESTS_ROOT_DIR/${_reverse_arch}/ - } } for test in "${!PKG_TESTS[@]}"; do func_test $test ${PKG_TESTS[$test]} $TESTS_ROOT_DIR diff --git a/library/config.sh b/library/config.sh index 944682d02..d496608cc 100644 --- a/library/config.sh +++ b/library/config.sh @@ -87,10 +87,11 @@ PROCESSOR_OPTIMIZATION_ARCH_64='nocona' # ************************************************************************** -LINK_TYPE_BOTH="--enable-shared --enable-static" LINK_TYPE_SHARED="--enable-shared --disable-static" LINK_TYPE_STATIC="--enable-static --disable-shared" -LINK_TYPE_GCC=$LINK_TYPE_BOTH +LINK_TYPE_GCC_SHARED="--enable-host-shared" +LINK_TYPE_GCC_STATIC="--disable-host-shared" +LINK_TYPE_GCC=$LINK_TYPE_GCC_SHARED GCC_DEPS_LINK_TYPE=$LINK_TYPE_STATIC ENABLE_LANGUAGES='c,c++,fortran' diff --git a/scripts/binutils.sh b/scripts/binutils.sh index 8ad2bc7d9..56cfae514 100644 --- a/scripts/binutils.sh +++ b/scripts/binutils.sh @@ -99,7 +99,10 @@ PKG_CONFIGURE_FLAGS=( --disable-nls --disable-shared # - $LINK_TYPE_GCC + $( [[ $BUILD_SHARED_GCC == yes ]] \ + && echo "$LINK_TYPE_SHARED" \ + || echo "$LINK_TYPE_STATIC" + ) # CFLAGS="\"$COMMON_CFLAGS\"" CXXFLAGS="\"$COMMON_CXXFLAGS\"" diff --git a/scripts/gcc-11.2.0.sh b/scripts/gcc-11.2.0.sh index 25eb2a9fa..8cc8029a1 100644 --- a/scripts/gcc-11.2.0.sh +++ b/scripts/gcc-11.2.0.sh @@ -74,6 +74,7 @@ PKG_CONFIGURE_FLAGS=( --with-sysroot=$PREFIX #--with-gxx-include-dir=$MINGWPREFIX/$TARGET/include/c++ # + --enable-shared $LINK_TYPE_GCC # $( [[ $USE_MULTILIB == yes ]] \ diff --git a/scripts/gcc-post.sh b/scripts/gcc-post.sh index 4bf17675b..5d35f5c25 100644 --- a/scripts/gcc-post.sh +++ b/scripts/gcc-post.sh @@ -61,11 +61,9 @@ function gcc_post_install { local _gcc_version=$(func_map_gcc_name_to_gcc_version $_GCC_NAME) local _reverse_bits=$(func_get_reverse_arch_bit $BUILD_ARCHITECTURE) - [[ $BUILD_SHARED_GCC == yes ]] && { - # libgcc_s.a - cp -f $PREFIX/lib/gcc/$TARGET/lib/libgcc_s.a $PREFIX/$TARGET/lib/ \ - || die "Cannot copy libgcc_s.a to $PREFIX/$TARGET/lib" - } + # libgcc_s.a + cp -f $PREFIX/lib/gcc/$TARGET/lib/libgcc_s.a $PREFIX/$TARGET/lib/ \ + || die "Cannot copy libgcc_s.a to $PREFIX/$TARGET/lib" func_has_lang objc local is_objc=$? @@ -73,58 +71,48 @@ function gcc_post_install { # libobjc cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/libobjc/.libs/libobjc.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/ \ || die "Cannot copy libobjc.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version" - [[ $BUILD_SHARED_GCC == yes ]] && { - cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/libobjc/.libs/libobjc.dll.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/ \ - || die "Cannot copy libobjc.dll.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version" - } + cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/libobjc/.libs/libobjc.dll.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/ \ + || die "Cannot copy libobjc.dll.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version" # objc headers cp -rf ${SRCS_DIR}/$_GCC_NAME/libobjc/objc $PREFIX/lib/gcc/$TARGET/$_gcc_version/include \ || die "Cannot copy objc headers to $PREFIX/lib/gcc/$TARGET/$_gcc_version/include" } - [[ $BUILD_SHARED_GCC == yes ]] && { - # builded architecture dlls - local _dlls=( $(find $BUILDS_DIR/$_GCC_NAME/$TARGET \ - -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/32 -prune \) \ - -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/64 -prune \) \ - -not \( -path $BUILDS_DIR/$_GCC_NAME/gcc/ada -prune \) \ - -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/libada/adainclude -prune \) \ - -type f -name *.dll) ) - cp -f ${_dlls[@]} $PREFIX/bin/ > /dev/null 2>&1 || die "Cannot copy architecture dlls to $PREFIX/bin/" - cp -f ${_dlls[@]} $PREFIX/$TARGET/lib/ > /dev/null 2>&1 || die "Cannot copy architecture dlls to $PREFIX/lib/" - - [[ $STRIP_ON_INSTALL == yes ]] && { - strip $PREFIX/bin/*.dll || die "Error stripping dlls from $PREFIX/bin" - strip $PREFIX/$TARGET/lib/*.dll || die "Error stripping dlls from $PREFIX/$TARGET/lib" - } + # builded architecture dlls + local _dlls=( $(find $BUILDS_DIR/$_GCC_NAME/$TARGET \ + -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/32 -prune \) \ + -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/64 -prune \) \ + -not \( -path $BUILDS_DIR/$_GCC_NAME/gcc/ada -prune \) \ + -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/libada/adainclude -prune \) \ + -type f -name *.dll) ) + cp -f ${_dlls[@]} $PREFIX/bin/ > /dev/null 2>&1 || die "Cannot copy architecture dlls to $PREFIX/bin/" + cp -f ${_dlls[@]} $PREFIX/$TARGET/lib/ > /dev/null 2>&1 || die "Cannot copy architecture dlls to $PREFIX/lib/" + + [[ $STRIP_ON_INSTALL == yes ]] && { + strip $PREFIX/bin/*.dll || die "Error stripping dlls from $PREFIX/bin" + strip $PREFIX/$TARGET/lib/*.dll || die "Error stripping dlls from $PREFIX/$TARGET/lib" } [[ $USE_MULTILIB == yes ]] && { - [[ $BUILD_SHARED_GCC == yes ]] && { - # libgcc_s.a - cp -f $PREFIX/lib/gcc/$TARGET/lib$_reverse_bits/libgcc_s.a $PREFIX/$TARGET/lib$_reverse_bits/ \ - || die "Cannot copy libgcc_s.a to $PREFIX/$TARGET/lib${_reverse_bits}/" - } + # libgcc_s.a + cp -f $PREFIX/lib/gcc/$TARGET/lib$_reverse_bits/libgcc_s.a $PREFIX/$TARGET/lib$_reverse_bits/ \ + || die "Cannot copy libgcc_s.a to $PREFIX/$TARGET/lib${_reverse_bits}/" [[ $is_objc == 1 ]] && { # libobjc libraries cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits/libobjc/.libs/libobjc.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/$_reverse_bits/ \ || die "Cannot copy libobjc.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version/${_reverse_bits}" - [[ $BUILD_SHARED_GCC == yes ]] && { - cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits/libobjc/.libs/libobjc.dll.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/$_reverse_bits/ \ - || die "Cannot copy libobjc.dll.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version/${_reverse_bits}" - } + cp -f $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits/libobjc/.libs/libobjc.dll.a $PREFIX/lib/gcc/$TARGET/$_gcc_version/$_reverse_bits/ \ + || die "Cannot copy libobjc.dll.a to $PREFIX/lib/gcc/$TARGET/$_gcc_version/${_reverse_bits}" } - [[ $BUILD_SHARED_GCC == yes ]] && { - # Second architecture bit dlls - find $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits \ - -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits/libada/adainclude -prune \) \ - -type f -name *.dll ! -name *winpthread* -print0 \ - | xargs -0 -I{} cp -f {} $PREFIX/$TARGET/lib$_reverse_bits/ || die "Error copying ${_reverse_bits}-bit dlls" + # Second architecture bit dlls + find $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits \ + -not \( -path $BUILDS_DIR/$_GCC_NAME/$TARGET/$_reverse_bits/libada/adainclude -prune \) \ + -type f -name *.dll ! -name *winpthread* -print0 \ + | xargs -0 -I{} cp -f {} $PREFIX/$TARGET/lib$_reverse_bits/ || die "Error copying ${_reverse_bits}-bit dlls" - [[ $STRIP_ON_INSTALL == yes ]] && { - strip $PREFIX/$TARGET/lib$_reverse_bits/*.dll || die "Error stripping ${_reverse_bits}-bit dlls" - } + [[ $STRIP_ON_INSTALL == yes ]] && { + strip $PREFIX/$TARGET/lib$_reverse_bits/*.dll || die "Error stripping ${_reverse_bits}-bit dlls" } }