2025-04-14 11:54:47 +00:00

317 lines
11 KiB
Plaintext

# --- T2-COPYRIGHT-BEGIN ---
# t2/package/*/gcc/gcc.conf
# Copyright (C) 2004 - 2025 The T2 SDE Project
# SPDX-License-Identifier: GPL-2.0
# --- T2-COPYRIGHT-END ---
# TODO: fix eval_config_command to properly evaluate the spaces!
[ $arch != avr32 ] && var_append confopt ' ' '--with-pkgversion=T2\\ SDE'
[ $arch = ia64 -o $arch = nios2 ] && var_append confopt ' ' '--enable-obsolete'
languages="c,c++"
if [ $stagelevel -le 1 ]; then
var_append confopt " " '--program-prefix=${arch_target}-'
toolsroot="${sysroot}/TOOLCHAIN/cross"
export LDFLAGS="-Wl,-rpath,${toolsroot}/lib"
var_append patchfiles " " "$confdir/gxx_include.diff"
if atstage toolchain; then
var_append confopt " " "--with-sysroot=$sysroot"
var_append confopt " " "--disable-shared"
var_append confopt " " "--disable-libatomic --disable-libstdc++-v3 --disable-libsanitizer"
var_append confopt " " "--disable-libssp --disable-libgomp --disable-cet"
var_append confopt " " "--disable-target-libiberty --disable-vtable-verify"
var_append confopt " " "--disable-libitm --disable-libcilkrts"
var_append confopt " " "--disable-libquadmath --disable-decimal-float"
elif [ $stagelevel = 1 ]; then
if [ "$SDECFG_LIBC" = "uclibc" ]; then
configscript="../libstdc++-v3/configure"
else
CC="cc" CXX="c++" CPP="cpp" OBJDUMP="objdump"
AS="as" STRIP="strip" OBJCOPY="objcopy"
LD="ld" AR="ar" RANLIB="ranlib" NM="nm"
var_remove_regex confopt ' ' '--prefix=.*'
var_remove_regex confopt ' ' '--bindir=.*'
var_remove_regex confopt ' ' '--libdir=.*'
var_remove_regex confopt ' ' '--includedir=.*'
var_insert confopt ' ' "--libexecdir=$toolsroot/$prefix/libexec"
var_insert confopt ' ' "--libdir=$toolsroot/$prefix/lib"
var_insert confopt ' ' "--bindir=$toolsroot/$prefix/bin"
var_insert confopt ' ' "--prefix=$toolsroot/$prefix"
var_remove_regex confopt ' ' '--datadir=.*'
var_remove_regex confopt ' ' '--infodir=.*'
var_remove_regex confopt ' ' '--mandir=.*'
var_remove_regex confopt ' ' '--sbindir=.*'
var_remove_regex confopt ' ' '--localstatedir=.*'
var_remove_regex confopt ' ' '--sysconfdir=.*'
var_remove_regex confopt ' ' '--host=.*'
var_append confopt ' ' "--host=\$arch_build"
var_remove_regex makeopt ' ' 'prefix=.*'
var_remove_regex makeinstopt ' ' 'prefix=.*'
var_remove_regex makeinstopt ' ' 'DESTDIR=.*'
var_remove_regex makeinstopt ' ' 'docdir=.*'
# override to install headers into the actual sysroot
var_append confopt ' ' "--with-gxx-include-dir=$root$includedir/c++/$ver"
var_append confopt ' ' "--with-toolexeclibdir=$root$libdir"
fi
fi
# we need to help configure pick up our native libraries in the toolchain dir
var_append confopt ' ' '--with-mpfr=$toolsroot --with-mpfr-lib=$toolsroot/lib'
var_append confopt ' ' '--with-ppl=$toolsroot --with-cloog=$toolsroot --with-gmp=$toolsroot'
var_append confopt ' ' '--disable-libsanitizer'
pkginstalled isl && var_append confopt ' ' '--with-isl=$toolsroot'
unset toolsroot
fi
if ! atstage toolchain; then
[ $stagelevel = 2 ] &&
confopt="${confopt/--with-sysroot/--with-libtool-sysroot}"
# shared, or not shared?
if [ "$diet_dynamic_static" == "static" ]; then
var_append confopt " " "--disable-shared"
else
var_append confopt " " "--enable-shared"
fi
var_append confopt " " "--with-gnu-as --with-gnu-ld --enable-threads=posix"
# Ada support is implemented in Ada, so GNAT has to be present
[ "$SDECFG_PKG_GCC_GNAT" = 1 ] && case "$arch" in
alpha|arc|microblaze|loongarch*|mips64|nios2|riscv)
: ;;
*)
var_append languages ',' "ada" ;;
esac
# unsupported / not broken, arch / languages:
case "$arch" in
loongarch)
: ;;
arc|riscv)
var_append languages ',' 'fortran' ;;
hppa*|loongarch64|mips64|microblaze|nios2|sparc*)
# sparc64 ICE in go
var_append languages ',' 'objc,fortran' ;;
*)
[ "$SDECFG_PKG_GCC_GO" = 1 ] && var_append languages ',' 'go'
var_append languages ',' "objc,fortran" ;;
esac
if [ "$SDECFG_LIBC" != "glibc" ]; then
var_remove languages ',' 'ada'
var_append confopt ' ' '--enable-clocale=generic'
fi
fi
# not relied on by T2, but for the actual system user to get the same
case "$arch" in
avr32|blackfin|cris|ia64) ;;
*)
for x in $GCC_WRAPPER_INSERT $GCC_WRAPPER_APPEND; do
case "$x" in
-march=*) var_append confopt " " "${x/-m/--with-}" ;;
-mcpu=*) var_append confopt " " "${x/-m/--with-}" ;;
-mtune=*) var_append confopt " " "${x/-m/--with-}" ;;
esac
done
esac
# at least the fortran parts get unresolved errors when we remove -Werror???
var_remove GCC_WRAPPER_REMOVE " " "-Werror"
# emmintrin.h: error: cast discards 'const' qualifier from pointer target type [-Werror=cast-qual]
var_append GCC_WRAPPER_REMOVE ' ' '*/libgo/*?-Werror:'
# create and set up cmd_wrapper for xgcc
setup_xgcc_wrapper() {
mkdir gcc; pushd gcc
cat <<-EOF > xgcc-wrapper
#!/bin/bash
# place the xgcc in the path
export PATH="$PWD:\$PATH"
[ "\$GCC_WRAPPER_DEBUG" = 1 ] && export CMD_WRAPPER_DEBUG=1
mycmd=\$1
if [ "\${mycmd%gcj}" != "\$mycmd" ]; then
export CMD_WRAPPER_OTHERS="\$GCJ_WRAPPER_OTHERS"
export CMD_WRAPPER_INSERT="\$GCJ_WRAPPER_INSERT"
export CMD_WRAPPER_REMOVE="\$GCJ_WRAPPER_REMOVE"
export CMD_WRAPPER_APPEND="\$GCJ_WRAPPER_APPEND"
export CMD_WRAPPER_FILTER="\$GCJ_WRAPPER_FILTER"
elif [ "\${mycmd%gfortran}" != "\$mycmd" ]; then
export CMD_WRAPPER_OTHERS="\$F95_WRAPPER_OTHERS"
export CMD_WRAPPER_INSERT="\$F95_WRAPPER_INSERT"
export CMD_WRAPPER_REMOVE="\$F95_WRAPPER_REMOVE"
export CMD_WRAPPER_APPEND="\$F95_WRAPPER_APPEND"
export CMD_WRAPPER_FILTER="\$F95_WRAPPER_FILTER"
elif [ "\${mycmd%g++}" != "\$mycmd" ]; then
export CMD_WRAPPER_OTHERS="\$CXX_WRAPPER_OTHERS:\$GCC_WRAPPER_OTHERS"
export CMD_WRAPPER_INSERT="\$CXX_WRAPPER_INSERT \$GCC_WRAPPER_INSERT"
export CMD_WRAPPER_REMOVE="\$CXX_WRAPPER_REMOVE \$GCC_WRAPPER_REMOVE"
export CMD_WRAPPER_APPEND="\$CXX_WRAPPER_APPEND \$GCC_WRAPPER_APPEND"
export CMD_WRAPPER_FILTER="\$CXX_WRAPPER_FILTER|\$GCC_WRAPPER_FILTER"
else
export CMD_WRAPPER_OTHERS="\$CC_WRAPPER_OTHERS:\$GCC_WRAPPER_OTHERS"
export CMD_WRAPPER_INSERT="\$CC_WRAPPER_INSERT \$GCC_WRAPPER_INSERT"
export CMD_WRAPPER_REMOVE="\$CC_WRAPPER_REMOVE \$GCC_WRAPPER_REMOVE"
export CMD_WRAPPER_APPEND="\$CC_WRAPPER_APPEND \$GCC_WRAPPER_APPEND"
export CMD_WRAPPER_FILTER="\$CC_WRAPPER_FILTER|\$GCC_WRAPPER_FILTER"
fi
exec cmd_wrapper "\$@"
EOF
chmod 0755 xgcc-wrapper
export STAGE_CC_WRAPPER=$PWD/xgcc-wrapper
popd
}
# historically we did not had to explicitly specifiy the target for "Canadian
# crossbuild", since gcc-4.3 we have to:
var_append confopt ' ' '--target=${arch_target}'
# See http://gcc.gnu.org/gcc-3.2/c++-abi.html
# and http://www.codesourcery.com/cxx-abi/.
var_append confopt ' ' "--enable-__cxa_atexit"
# we might build a SVN or prereleases, disable checking
var_append confopt ' ' '--disable-checking'
# we build a cross compiler in stage0 and later use known good GCCs, no bstrap
var_append confopt ' ' '--disable-bootstrap'
# not really useful and just blows up the binary package
var_append confopt ' ' '--disable-libstdcxx-pch'
# multilib is usually enabled by default, so do not fore re-enable it here, see GCC Bug 43328
if [ "$SDECFG_MULTILIB" != 1 ]; then
var_append confopt ' ' "--disable-multilib"
fi
if [ -n "$SDECFG_MULTILIBLIST" ]; then
# pass multilib-list even when disabled, e.g. for superh
var_append confopt ' ' "--with-multilib-list=$SDECFG_MULTILIBLIST"
fi
if [ "$SDECFG_LTO" == 1 ] && ! hasflag NO-LTO; then
var_append GCC_WRAPPER_INSERT " " "-DIN_GCC_FRONTEND?-flto=${SDECFG_PARALLEL:-auto}"
var_append GCC_WRAPPER_INSERT " " "-DIN_GCC_FRONTEND?-fwhole-program"
fi
# only left for uclibc libatomic
gcc_build_module() {
for x; do
mkdir x-$x; cd x-$x
configscript="../../$x/configure"
eval_config_command $(eval echo $confopt)
eval $MAKE $makeopt
eval $MAKE $makeinstopt
cd ..
configscript=../configure
done
}
if atstage cross; then
# canadian cross also needs to know the build root to find headers, e.g. for fixincludes
var_append confopt ' ' '--with-build-sysroot=$root'
# make sure we use gcc itself, not clang
[ "$SDECFG_DEFAULT_CC" != gcc -o "$SDECFG_DEFAULT_CXX" != gcc ] &&
export CC_FOR_TARGET=$arch_target-gcc \
GCC_FOR_TARGET=$arch_target-gcc \
CXX_FOR_TARGET=$arch_target-g++
if [ "$SDECFG_KERNEL" = mingw ]; then
configscript="../libstdc++-v3/configure"
fi
fi
gcc_premake() {
# create and set up the xgcc cmd_wrapper
setup_xgcc_wrapper
# install binutils bfd lto plugin
local gcc_ver=$(< ../gcc/BASE-VER)
mkdir -pv $root$libdir/bfd-plugins/
ln -sfv ../../libexec/gcc/$arch_target/$gcc_ver/liblto_plugin.so \
$root$libdir/bfd-plugins/
}
hook_add premake 5 "gcc_premake"
gcc_postmake() {
# force a tools rebuild
rm -fv $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
# create various symlinks for cc, c++, cpp and f77
if atstage toolchain; then
for x in $([ "$SDECFG_DEFAULT_CC" = gcc ] && echo cc
[ "$SDECFG_DEFAULT_CXX" = gcc ] && echo c++
[ "$SDECFG_DEFAULT_KCC" = gcc ] && echo kcc); do
[ $x != c++ ] &&
ln -svf ${arch_target}-gcc $root/$prefix/bin/${arch_target}-$x ||
ln -svf ${arch_target}-g++ $root/$prefix/bin/${arch_target}-$x
done
if [ "$SDECFG_DEFAULT_CXX" = clang ]; then
# compat symlink for clang++
ln -svf $sysroot/usr/include/c++/$ver/ \
$sysroot/TOOLCHAIN/cross/lib/gcc/$arch_target/$ver/include/c++
fi
return
fi
for x in $([ "$SDECFG_DEFAULT_CC" = gcc ] && echo cc
[ "$SDECFG_DEFAULT_CXX" = gcc ] && echo c++
[ "$SDECFG_DEFAULT_KCC" = gcc ] && echo kcc); do
[ $x != c++ ] && ln -sfv gcc $root$bindir/$x || ln -sfv g++ $root$bindir/$x
done
[ "$SDECFG_DEFAULT_CC" = gcc ] && ln -sfv ..$bindir/cpp $root/lib/cpp
if [ -f $root$bindir/gfortran ]; then
ln -sfv gfortran $root$bindir/f77
fi
}
hook_add postmake 5 "gcc_postmake"
if [ "$SDECFG_LIBC" != "glibc" ]; then
var_append confopt " " "--disable-libsanitizer"
var_remove languages ',' "go"
fi
[ "$arch" = "arm" -a "$SDECFG_SOFTFLOAT" != 1 ] && var_append confopt ' ' '--with-float=hard'
[ "$SDECFG_ARM_ENDIANESS" = 'eb' ] && var_remove languages ',' "go"
[ "$arch" = "mips64" ] && var_append confopt ' ' '--disable-libsanitizer'
[ "$SDECFG_POWERPC64_ELF_ABI" = elfv2 ] && var_append confopt ' ' '--with-abi=elfv2'
[ $arch_sizeof_char_p -gt 4 ] && var_append patchfiles " " "$confdir/tune-inline.diff"
# 32-bit default 64-bit biarch configuration
if [ "$SDECFG_POWERPC64_32" = 1 -o "$SDECFG_SPARC64_32BIT" = 1 ]; then
[ $arch = "powerpc64" ] && var_append confopt " " "--with-cpu=default32"
var_append patchfiles " " "$confdir/m32-default.diff"
var_remove languages ',' "fortran" # why?
var_remove languages ',' "go"
var_remove languages ',' "ada"
gcc_default_m32() {
echo "Running $makeopt all-host"
eval $MAKE $makeopt all-host
var_append GCC_WRAPPER_INSERT " " "-m32?:-m64"
}
# simulate -m64 default thru our wrapper for the target multilibs
hook_add premake 7 "gcc_default_m32"
fi
var_insert confopt ' ' '--enable-languages=$languages'