# Automatically generated aport, do not edit!
# Generator: pmbootstrap aportgen gcc-armhf
# Based on: main/gcc (from Alpine)

CTARGET_ARCH=armhf
CTARGET="$(arch_to_hostspec ${CTARGET_ARCH})"
LANG_D=false
LANG_OBJC=false
LANG_JAVA=false
LANG_GO=false
LANG_FORTRAN=false
LANG_ADA=false
options="!strip"

# abuild doesn't try to tries to install "build-base-$CTARGET_ARCH"
# when this variable matches "no*"
BOOTSTRAP="nobuildbase"

# abuild will only cross compile when this variable is set, but it
# needs to find a valid package database in there for dependency
# resolving, so we set it to /.
CBUILDROOT="/"

_cross_configure="--disable-bootstrap --with-sysroot=/usr/$CTARGET"

pkgname=gcc-armhf
pkgver=14.3.0
# i.e. 13.2.1, must match gcc/BASE-VER
_pkgbase="${pkgver%%_git*}"
# date component from snapshots
_pkgsnap="${pkgver##*_git}"
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
[ "$CBUILD" != "$CHOST" ] && _cross="-$CARCH" || _cross=""
[ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target=""

pkgname=gcc-armhf
pkgrel=6
pkgdesc="Stage2 cross-compiler for armhf"
url="https://gcc.gnu.org"
arch="x86_64"
license="GPL-2.0-or-later AND LGPL-2.1-or-later"
_gccrel=$pkgver-r$pkgrel
depends="binutils-armhf mpc1 so:libc.musl-x86_64.so.1 so:libgcc_s.so.1 so:libgmp.so.10 so:libisl.so.23 so:libmpc.so.3 so:libmpfr.so.6 so:libstdc++.so.6 so:libz.so.1"
makedepends_build="gcc g++ bison flex texinfo gawk zip gmp-dev mpfr-dev mpc1-dev zlib-dev"
makedepends_host="linux-headers gmp-dev mpfr-dev mpc1-dev isl-dev zlib-dev musl-dev-armhf binutils-armhf"
subpackages="g++-armhf:gpp libstdc++-dev-armhf:libcxx_dev"
[ "$CHOST" = "$CTARGET" ] && subpackages="gcc-gdb gcc-doc"
replaces="libstdc++ binutils"
options="!strip !tracedeps"

: "${LANG_CXX:=true}"
: "${LANG_D:=true}"
: "${LANG_OBJC:=true}"
: "${LANG_GO:=true}"
: "${LANG_FORTRAN:=true}"
: "${LANG_ADA:=true}"
: "${LANG_JIT:=true}"

_libgomp=true
_libgcc=false
_libatomic=true
_libitm=true

if [ "$CHOST" != "$CTARGET" ]; then
	if [ "$BOOTSTRAP" = nolibc ]; then
		LANG_CXX=false
		LANG_D=false
		LANG_ADA=false
		_libgcc=false
		_builddir="$srcdir/build-cross-pass2"
	else
		_builddir="$srcdir/build-cross-final"
	fi
	LANG_OBJC=false
	LANG_GO=false
	LANG_FORTRAN=false
	LANG_JIT=false
	_libgomp=false
	_libatomic=false
	_libitm=false

	# format-sec: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431
	CPPFLAGS="${CPPFLAGS/-Werror=format-security/}"
	# reset target flags (should be set in crosscreate abuild)
	# fixup flags. seems gcc treats CPPFLAGS as global without
	# _FOR_xxx variants. wrap it in CFLAGS and CXXFLAGS.
	export CFLAGS="$CPPFLAGS -g0 ${CFLAGS/-Werror=format-security/}"
	export CXXFLAGS="$CPPFLAGS -g0 ${CXXFLAGS/-Werror=format-security/}"
	unset CPPFLAGS
	export CFLAGS_FOR_TARGET=" "
	export CXXFLAGS_FOR_TARGET=" "
	export LDFLAGS_FOR_TARGET=" "

	STRIP_FOR_TARGET="$CTARGET-strip"
elif [ "$CBUILD" != "$CHOST" ]; then
	# format-sec: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431
	CPPFLAGS="${CPPFLAGS/-Werror=format-security/}"
	# fixup flags. seems gcc treats CPPFLAGS as global without
	# _FOR_xxx variants. wrap it in CFLAGS and CXXFLAGS.
	export CFLAGS="$CPPFLAGS -g0 ${CFLAGS/-Werror=format-security/}"
	export CXXFLAGS="$CPPFLAGS -g0 ${CXXFLAGS/-Werror=format-security/}"
	unset CPPFLAGS

	# reset flags and cc for build
	export CC_FOR_BUILD="gcc"
	export CXX_FOR_BUILD="g++"
	export CFLAGS_FOR_BUILD=" "
	export CXXFLAGS_FOR_BUILD=" "
	export LDFLAGS_FOR_BUILD=" "
	export CFLAGS_FOR_TARGET=" "
	export CXXFLAGS_FOR_TARGET=" "
	export LDFLAGS_FOR_TARGET=" "

	# Languages that do not need bootstrapping
	LANG_OBJC=false
	LANG_GO=false
	LANG_FORTRAN=false
	LANG_JIT=false

	STRIP_FOR_TARGET=${CROSS_COMPILE}strip
	_builddir="$srcdir/build-cross-native"
else
	STRIP_FOR_TARGET=${CROSS_COMPILE}strip
	_builddir="$srcdir/build"

	# format-sec: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431
	CPPFLAGS="${CPPFLAGS/-Werror=format-security/}"
	# pass -g0 by default to bypass -g, since we don't do debug
	# if -dbg added, the -g is appended and overrides this
	export CFLAGS="$CPPFLAGS -g0 ${CFLAGS/-Werror=format-security/} -O2"
	export CXXFLAGS="$CPPFLAGS -g0 ${CXXFLAGS/-Werror=format-security/} -O2"
	unset CPPFLAGS
	# https://gcc.gnu.org/install/build.html
	export CFLAGS_FOR_TARGET="$CFLAGS"
	export CXXFLAGS_FOR_TARGET="$CXXFLAGS"
	export LDFLAGS_FOR_TARGET="$LDFLAGS"
	export BOOT_CFLAGS="$CFLAGS"
	export BOOT_LDFLAGS="$LDFLAGS"
fi

case "$CTARGET_ARCH" in
# GDC hasn't been ported to PowerPC (LIBDRUNTIME_ONLY=yes)
# See libphobos/configure.tgt in GCC sources for supported targets
# riscv fails with: error: static assert  "unimplemented"
ppc*|riscv64)	LANG_D=false ;;
# GDC does currently not work on 32-bit musl architectures.
# This is a known upstream issue.
# See: https://github.com/dlang/druntime/pull/3383
armhf|armv7|x86)	LANG_D=false ;;
esac

# libitm has TEXTRELs in ARM build, so disable for now
case "$CTARGET_ARCH" in
arm*)		_libitm=false ;;
mips*)		_libitm=false ;;
riscv64)	_libitm=false ;;
loongarch64)	_libitm=false ;;
esac

# Internal libffi fails to build on MIPS at the moment, need to
# investigate further.  We disable LANG_GO on mips64 as it requires
# the internal libffi.
case "$CTARGET_ARCH" in
mips*)		LANG_GO=false ;;
loongarch64)	LANG_GO=false ;;
esac

# Fortran uses libquadmath if toolchain has __float128
# currently on x86, x86_64 and ia64
_libquadmath=$LANG_FORTRAN
case "$CTARGET_ARCH" in
x86 | x86_64 | ppc64le) ;;
*)		_libquadmath=false ;;
esac

# libatomic is a dependency for openvswitch
$_libatomic && subpackages="$subpackages libatomic::$CTARGET_ARCH"
$_libgcc && subpackages="$subpackages libgcc::$CTARGET_ARCH"
$_libquadmath && subpackages="$subpackages libquadmath::$CTARGET_ARCH"
if $_libgomp; then
	depends="$depends libgomp=$_gccrel"
	subpackages="$subpackages libgomp::$CTARGET_ARCH"
fi

case "$CTARGET_ARCH" in
riscv64|loongarch64)
LANG_ADA=false;;
esac

_languages=c
if $LANG_CXX; then
	_languages="$_languages,c++"
fi
if $LANG_D; then
	subpackages="$subpackages gcc-gdc$_target:gdc"
	_languages="$_languages,d"
	makedepends_build="$makedepends_build libucontext-dev"
	if [ "$CBUILD" = "$CTARGET" ]; then
		makedepends_build="$makedepends_build gcc-gdc-bootstrap"
		subpackages="$subpackages libgphobos::$CTARGET_ARCH"
	else
		# shared libgphobos is for D programs to link against, so
		# skip building that while cross-compiling the GDC compiler
		makedepends_build="$makedepends_build gcc-gdc gcc-gdc$_cross"
	fi
fi
if $LANG_OBJC; then
	subpackages="$subpackages libobjc::$CTARGET_ARCH gcc-objc$_target:objc"
	_languages="$_languages,objc"
fi
if $LANG_GO; then
	subpackages="$subpackages libgo::$CTARGET_ARCH gcc-go$_target:go"
	_languages="$_languages,go"
fi
if $LANG_FORTRAN; then
	subpackages="$subpackages libgfortran::$CTARGET_ARCH gfortran$_target:gfortran"
	_languages="$_languages,fortran"
fi
if $LANG_ADA; then
	subpackages="$subpackages gcc-gnat$_target:gnat libgnat::$CTARGET_ARCH"
	_languages="$_languages,ada"
	if [ "$CBUILD" = "$CTARGET" ]; then
		makedepends_build="$makedepends_build gcc-gnat-bootstrap"
		subpackages="$subpackages libgnat-static:libgnatstatic:$CTARGET_ARCH"
	else
		makedepends_build="$makedepends_build gcc-gnat gcc-gnat$_cross"
	fi
fi
if $LANG_JIT; then
	subpackages="$subpackages libgccjit:jit libgccjit-dev:jitdev"
fi

# when using upstream releases, use this URI template
# https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz
#
# right now, we are using a git snapshot. snapshots are taken from gcc.gnu.org/pub/gcc/snapshots.
# However, since they are periodically deleted from the GCC mirrors the utilized snapshots are
# mirrored on dev.alpinelinux.org. Please ensure that the snapshot Git commit (as stated in the
# README) matches the base commit on the version-specific branch in the Git repository below.
#
# PLEASE submit all patches to gcc to https://gitlab.alpinelinux.org/kaniini/alpine-gcc-patches,
# so that they can be properly tracked and easily rebased if needed.
#source="https://dev.alpinelinux.org/archive/gcc/${_pkgbase%%.*}-$_pkgsnap/gcc-${_pkgbase%%.*}-$_pkgsnap.tar.xz
source="https://gcc.gnu.org/pub/gcc/releases/gcc-$_pkgbase/gcc-$_pkgbase.tar.xz
	0001-posix_memalign.patch
	0002-gcc-poison-system-directories.patch
	0003-specs-turn-on-Wl-z-now-by-default.patch
	0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch
	0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
	0006-Enable-Wformat-and-Wformat-security-by-default.patch
	0007-Enable-Wtrampolines-by-default.patch
	0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
	0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
	0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
	0011-libiberty-copy-PIC-objects-during-build-process.patch
	0012-libgcc_s.patch
	0013-nopie.patch
	0014-ada-fix-shared-linking.patch
	0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
	0016-add-fortify-headers-paths.patch
	0017-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
	0018-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
	0019-aarch64-disable-multilib-support.patch
	0020-s390x-disable-multilib-support.patch
	0021-ppc64-le-disable-multilib-support.patch
	0022-x86_64-disable-multilib-support.patch
	0023-riscv-disable-multilib-support.patch
	0024-always-build-libgcc_eh.a.patch
	0025-ada-libgnarl-compatibility-for-musl.patch
	0026-ada-musl-support-fixes.patch
	0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
	0028-configure-fix-detection-of-atomic-builtins-in-libato.patch
	0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch
	0030-gdc-unconditionally-link-libgphobos-against-libucont.patch
	0031-druntime-link-against-libucontext-on-all-platforms.patch
	0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch
	0033-libphobos-do-not-use-LFS64-symbols.patch
	0034-libgo-fix-lfs64-use.patch
	0035-loongarch-disable-multilib-support.patch
	0036-libphobos-add-riscv64-and-loongarch64-support.patch
	0037-static-pie.patch
	0038-except-Don-t-use-the-cached-value-of-the-gcc_except_.patch
	"

# secfixes:
#   13.2.1_git20231014-r0:
#     - CVE-2023-4039

# we build out-of-tree
#builddir="$srcdir"/gcc-${_pkgbase%%.*}-$_pkgsnap
builddir="$srcdir"/gcc-$_pkgbase
_gcclibdir="usr/lib/gcc/$CTARGET/$_pkgbase"
_gcclibexec="usr/libexec/gcc/$CTARGET/$_pkgbase"

prepare() {
	default_prepare
	echo $_pkgbase > gcc/BASE-VER
}

build() {
	local _arch_configure=
	local _bootstrap_configure=
	local _jit_configure=
	local _sanitizer_configure=

	case "$CTARGET" in
	aarch64-*-*-*)		_arch_configure="--with-arch=armv8-a --with-abi=lp64";;
	armv5-*-*-*eabi)	_arch_configure="--with-arch=armv5te --with-tune=arm926ej-s --with-float=soft --with-abi=aapcs-linux";;
	armv6-*-*-*eabihf)	_arch_configure="--with-arch=armv6kz --with-tune=arm1176jzf-s --with-fpu=vfpv2 --with-float=hard --with-abi=aapcs-linux";;
	armv7-*-*-*eabihf)	_arch_configure="--with-arch=armv7-a --with-tune=generic-armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-abi=aapcs-linux --with-mode=thumb";;
	mips-*-*-*)		_arch_configure="--with-arch=mips32 --with-mips-plt --with-float=soft --with-abi=32";;
	mips64-*-*-*)		_arch_configure="--with-arch=mips3 --with-tune=mips64 --with-mips-plt --with-float=soft --with-abi=64";;
	mips64el-*-*-*)		_arch_configure="--with-arch=mips3 --with-tune=mips64 --with-mips-plt --with-float=soft --with-abi=64";;
	mipsel-*-*-*)		_arch_configure="--with-arch=mips32 --with-mips-plt --with-float=soft --with-abi=32";;
	powerpc-*-*-*)		_arch_configure="--enable-secureplt --enable-decimal-float=no";;
	powerpc64*-*-*-*)	_arch_configure="--with-abi=elfv2 --enable-secureplt --enable-decimal-float=no --enable-targets=powerpcle-linux";;
	i486-*-*-*)		_arch_configure="--with-arch=i486 --with-tune=generic --enable-cld";;
	i586-*-*-*)		_arch_configure="--with-arch=pentium-m --with-fpmath=sse --with-tune=generic --enable-cld";;
	s390x-*-*-*)		_arch_configure="--with-arch=z196 --with-tune=zEC12 --with-zarch --with-long-double-128 --enable-decimal-float";;
	riscv64-*-*-*)		_arch_configure="--with-arch=rv64gc --with-abi=lp64d --enable-autolink-libatomic";;
	loongarch64-*-*-*)	_arch_configure="--with-arch=la64v1.0 --with-abi=lp64d";;
	esac

	case "$CTARGET_ARCH" in
	*)	_sanitizer_configure="--disable-libsanitizer" ;;
	esac

	case "$CTARGET_ARCH" in
	mips*)	_hash_style_configure="--with-linker-hash-style=sysv" ;;
	*)	_hash_style_configure="--with-linker-hash-style=gnu" ;;
	esac

	export libat_cv_have_ifunc=no


	case "$BOOTSTRAP" in
	nolibc)	_bootstrap_configure="--with-newlib --disable-shared --enable-threads=no" ;;
	*)
		# cross-bootstrap GDC with a static libphobos: due to GCC's
		# ./configure not having a --disable-shared=libphobos option,
		# we have to use --enable-shared with everything else instead.
		if $LANG_D && [ "$CBUILD" != "$CTARGET" ]; then
			_bootstrap_configure="--enable-shared=libgcc,libstdc++,libffi,zlib,boehm-gc,ada,libada,libgo,libobjc,libatomic,libgomp,libitm,libgfortran,libquadmath"
		else
			_bootstrap_configure="--enable-shared"
		fi
		_bootstrap_configure="$_bootstrap_configure --enable-threads --enable-tls"
		;;
	esac

	$_libgomp	|| _bootstrap_configure="$_bootstrap_configure --disable-libgomp"
	$_libatomic	|| _bootstrap_configure="$_bootstrap_configure --disable-libatomic"
	$_libitm	|| _bootstrap_configure="$_bootstrap_configure --disable-libitm"
	$_libquadmath	|| _arch_configure="$_arch_configure --disable-libquadmath"

	msg "Building the following:"
	echo ""
	echo "  CBUILD=$CBUILD"
	echo "  CHOST=$CHOST"
	echo "  CTARGET=$CTARGET"
	echo "  CTARGET_ARCH=$CTARGET_ARCH"
	echo "  languages=$_languages"
	echo "  arch_configure=$_arch_configure"
	echo "  cross_configure=$_cross_configure"
	echo "  bootstrap_configure=$_bootstrap_configure"
	echo "  hash_style_configure=$_hash_style_configure"
	echo ""

	local version="Alpine $pkgver"
	local gccconfiguration="
		--prefix=/usr
		--mandir=/usr/share/man
		--infodir=/usr/share/info
		--build=$CBUILD
		--host=$CHOST
		--target=$CTARGET
		--enable-checking=release
		--disable-cet
		--disable-fixed-point
		--disable-libstdcxx-pch
		--disable-multilib
		--disable-nls
		--disable-werror
		--disable-symvers
		--enable-__cxa_atexit
		--enable-default-pie
		--enable-default-ssp
		--enable-languages=$_languages
		--enable-link-serialization=2
		--enable-linker-build-id
		$_arch_configure
		--disable-libssp
		$_sanitizer_configure
		$_cross_configure
		$_bootstrap_configure
		--with-bugurl=https://gitlab.alpinelinux.org/alpine/aports/-/issues
		--with-system-zlib
		$_hash_style_configure
		"

	mkdir -p "$_builddir"
	cd "$_builddir"
	"$builddir"/configure $gccconfiguration \
		--with-pkgversion="$version"

	msg "building gcc"
	if $LANG_D && [ "$CBUILD" != "$CTARGET" ]; then
		# cross-compiling libphobos with parallel make fails
		make all-target-libphobos
	fi
	make

	# we build gccjit separate to not build all of gcc with --enable-host-shared
	# as doing so slows it down a few %, so for some quick if's here we gain
	# free performance
	if $LANG_JIT; then
		mkdir -p "$_builddir"/libgccjit-build
		cd "$_builddir"/libgccjit-build
		"$builddir"/configure $gccconfiguration \
			--disable-bootstrap \
			--enable-host-shared \
			--enable-languages=jit \
			--with-pkgversion="$version"

		msg "building libgccjit"
		make all-gcc
	fi
}

package() {
	cd "$_builddir"
	make -j1 DESTDIR="$pkgdir" install

	[ "$CHOST" = "$CTARGET" ] && ln -s gcc "$pkgdir"/usr/bin/cc
	ln -s ${CTARGET}-gcc "$pkgdir"/usr/bin/${CTARGET}-cc

	# symlink to vendor-less target triple for
	# supporting clang --target's fallback match
	# ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/16828
	ln -s "$CTARGET" "$pkgdir/usr/lib/gcc/${CTARGET%%-*}-${CTARGET#*-*-}"

	if $LANG_JIT; then
		make -C "$_builddir"/libgccjit-build/gcc DESTDIR="$pkgdir" jit.install-common
	fi

	# we dont support gcj -static
	# and saving 35MB is not bad.
	find "$pkgdir" \( -name libgtkpeer.a \
		-o -name libgjsmalsa.a \
		-o -name libgij.a \) \
		-delete

	# strip debug info from some static libs
	find "$pkgdir" \( -name libgfortran.a -o -name libobjc.a -o -name libgomp.a \
		-o -name libgphobos.a -o -name libgdruntime.a \
		-o -name libgcc.a -o -name libgcov.a -o -name libquadmath.a \
		-o -name libitm.a -o -name libgo.a -o -name libcaf\*.a \
		-o -name libatomic.a -o -name libasan.a -o -name libtsan.a \) \
		-a -type f \
		-exec $STRIP_FOR_TARGET -g {} +

	if $_libgomp; then
		mv "$pkgdir"/usr/lib/libgomp.spec "$pkgdir"/$_gcclibdir
	fi
	if $_libitm; then
		mv "$pkgdir"/usr/lib/libitm.spec "$pkgdir"/$_gcclibdir
	fi

	# remove ffi
	rm -f "$pkgdir"/usr/lib/libffi* "$pkgdir"/usr/share/man/man3/ffi*
	find "$pkgdir" -name 'ffi*.h' -delete

	local gdblib=${_target:+$CTARGET/}lib
	if [ -d "$pkgdir"/usr/$gdblib/ ]; then
		for i in $(find "$pkgdir"/usr/$gdblib/ -type f -maxdepth 1 -name "*-gdb.py"); do
			mkdir -p "$pkgdir"/usr/share/gdb/python/auto-load/usr/$gdblib
			mv "$i" "$pkgdir"/usr/share/gdb/python/auto-load/usr/$gdblib/
		done
	fi

	# move ada runtime libs
	if $LANG_ADA; then
		local libgnat_static=
		[ "$CHOST" = "$CTARGET" ] && libgnat_static="libgna*.a"
		for i in $(find "$pkgdir"/$_gcclibdir/adalib/ -type f -maxdepth 1 \( -name "libgna*.so" -o -name "$libgnat_static" \) ); do
			mv "$i" "$pkgdir"/usr/lib/
			ln -s ../../../../${i##*/} $i
		done
	fi

	if [ "$CHOST" != "$CTARGET" ]; then
		# cross-gcc: remove any files that would conflict with the
		# native gcc package
		rm -rf "$pkgdir"/usr/include "${pkgdir:?}"/usr/share
		# libcc1 does not depend on target, don't ship it
		rm -rf "$pkgdir"/usr/lib/libcc1.so*


		# fixup gcc library symlinks to be linker scripts so
		# linker finds the libs from relocated sysroot
		for so in "$pkgdir"/usr/"$CTARGET"/lib/*.so; do
			if [ -h "$so" ]; then
				local _real=$(basename "$(readlink "$so")")
				rm -f "$so"
				echo "GROUP ($_real)" > "$so"
			fi
		done
	else
		# add c89/c99 wrapper scripts
		cat >"$pkgdir"/usr/bin/c89 <<'EOF'
#!/bin/sh
_flavor="-std=c89"
for opt; do
	case "$opt" in
	-ansi|-std=c89|-std=iso9899:1990) _flavor="";;
	-std=*) echo "$(basename $0) called with non ANSI/ISO C option $opt" >&2
		exit 1;;
	esac
done
exec gcc $_flavor ${1+"$@"}
EOF
		cat >"$pkgdir"/usr/bin/c99 <<'EOF'
#!/bin/sh
_flavor="-std=c99"
for opt; do
	case "$opt" in
	-std=c99|-std=iso9899:1999) _flavor="";;
	-std=*) echo "$(basename $0) called with non ISO C99 option $opt" >&2
		exit 1;;
	esac
done
exec gcc $_flavor ${1+"$@"}
EOF
		chmod 755 "$pkgdir"/usr/bin/c?9

		# install lto plugin so regular binutils may use it
		mkdir -p "$pkgdir"/usr/lib/bfd-plugins
		ln -s /$_gcclibexec/liblto_plugin.so "$pkgdir/usr/lib/bfd-plugins/"
	fi
}

libatomic() {
	pkgdesc="GCC Atomic library"
	depends=
	replaces="gcc"

	amove usr/lib/libatomic.so.*
}

libcxx() {
	pkgdesc="GNU C++ standard runtime library"
	depends=

	if [ "$CHOST" = "$CTARGET" ]; then
		# verify that we are using clock_gettime rather than doing direct syscalls
		# so we dont break 32 bit arches due to time64.
		nm -D "$pkgdir"/usr/lib/libstdc++.so.* | grep clock_gettime
	fi

	amove usr/lib/libstdc++.so.*
}

libcxx_dev() {
	pkgdesc="GNU C++ standard runtime library (development files)"
	depends=
	replaces="g++"

	amove usr/${_target:+$CTARGET/}lib/libstdc++.a \
		usr/${_target:+$CTARGET/}lib/libstdc++exp.a \
		usr/${_target:+$CTARGET/}lib/libstdc++.so \
		usr/${_target:+$CTARGET/}lib/libstdc++fs.a \
		usr/${_target:+$CTARGET/}lib/libsupc++.a \
		usr/${_target:+$CTARGET/}include/c++
}

gpp() {
	pkgdesc="GNU C++ standard library and compiler"
	depends="libstdc++-dev$_target=$_gccrel gcc$_target=$_gccrel musl-dev"
	[ "$CHOST" = "$CTARGET" ] && depends="$depends libstdc++=$_gccrel"

	depends="$depends so:libc.musl-x86_64.so.1 so:libgmp.so.10 so:libisl.so.23 so:libmpc.so.3 so:libmpfr.so.6 so:libz.so.1"

	amove $_gcclibexec/cc1plus
	amove usr/bin/*++
}

jit() {
	pkgdesc="GCC JIT Library"
	depends=
	amove usr/lib/libgccjit.so*
}

jitdev() {
	pkgdesc="GCC JIT Library (development files)"
	depends="libgccjit"
	amove usr/include/libgccjit*.h
}

libobjc() {
	pkgdesc="GNU Objective-C runtime"
	replaces="objc"
	depends=

	amove usr/lib/libobjc.so.*
}

objc() {
	pkgdesc="GNU Objective-C"
	replaces="gcc"
	depends="musl-dev gcc=$_gccrel libobjc=$_gccrel"

	amove $_gcclibexec/cc1obj
	amove $_gcclibdir/include/objc
	amove usr/lib/libobjc.so
	amove usr/lib/libobjc.a
}

libgcc() {
	pkgdesc="GNU C compiler runtime libraries"
	depends=

	amove usr/lib/libgcc_s.so.*
}

libgomp() {
	pkgdesc="GCC shared-memory parallel programming API library"
	depends=
	replaces="gcc"

	amove usr/lib/libgomp.so.*
}

libgphobos() {
	pkgdesc="D programming language standard library for GCC"
	depends=

	amove usr/lib/libgdruntime.so.*
	amove usr/lib/libgphobos.so.*
}

gdc() {
	pkgdesc="GCC-based D language compiler"
	depends="gcc$_target=$_gccrel musl-dev libucontext-dev"
	[ "$CBUILD" = "$CTARGET" ] && depends="$depends libgphobos=$_gccrel"
	[ "$CHOST" = "$CTARGET" ] && provides="gcc-gdc-bootstrap=$_gccrel"

	# Copy: The installed '.d' files, the static lib, the binary itself
	# The shared libs are part of 'libgphobos' so one can run program
	# without installing the compiler
	amove $_gcclibexec/d21
	amove $_gcclibdir/include/d
	if [ "$CBUILD" = "$CTARGET" ]; then
		amove usr/lib/libgdruntime.so
		amove usr/lib/libgphobos.so
	fi
	amove usr/${_target:+$CTARGET/}lib/libgdruntime.a
	amove usr/${_target:+$CTARGET/}lib/libgphobos.a
	amove usr/${_target:+$CTARGET/}lib/libgphobos.spec
	amove usr/bin/*gdc
}

libgo() {
	pkgdesc="Go runtime library for GCC"
	depends=

	amove usr/lib/libgo.so.*
}

go() {
	pkgdesc="GCC Go frontend (intended for bootstrapping community/go)"
	depends="gcc=$_gccrel libgo=$_gccrel !go"

	amove usr/lib/go
	amove usr/bin/*go
	amove usr/bin/*gofmt
	amove $_gcclibexec/go1
	amove $_gcclibexec/cgo
	amove $_gcclibexec/buildid
	amove $_gcclibexec/test2json
	amove $_gcclibexec/vet
	amove usr/lib/libgo.a
	amove usr/lib/libgo.so
	amove usr/lib/libgobegin.a
	amove usr/lib/libgolibbegin.a
}

libgfortran() {
	pkgdesc="Fortran runtime library for GCC"
	depends=

	amove usr/lib/libgfortran.so.*
}

libquadmath() {
	replaces="gcc"
	pkgdesc="128-bit math library for GCC"
	depends=

	amove usr/lib/libquadmath.so.*
}

gfortran() {
	pkgdesc="GNU Fortran Compiler"
	depends="gcc=$_gccrel libgfortran=$_gccrel"
	$_libquadmath && depends="$depends libquadmath=$_gccrel"
	replaces="gcc"

	amove usr/bin/*gfortran
	amove usr/lib/libgfortran.a
	amove usr/lib/libgfortran.so
	if $_libquadmath; then
		amove usr/lib/libquadmath.a
		amove usr/lib/libquadmath.so
	fi
	amove $_gcclibdir/finclude
	amove $_gcclibexec/f951
	mv -v "$pkgdir"/usr/lib/libgfortran.spec "$subpkgdir"/$_gcclibdir/
}

libgnat() {
	pkgdesc="GNU Ada runtime shared libraries"
	depends=

	amove usr/lib/libgna*.so
}

libgnatstatic() {
	pkgdesc="GNU Ada static libraries"
	depends=

	amove usr/lib/libgna*.a
}

gnat() {
	pkgdesc="Ada support for GCC"
	depends="gcc=$_gccrel"
	provides="$pkgname-gnat-bootstrap=$_gccrel"
	[ "$CHOST" = "$CTARGET" ] && depends="$depends libgnat=$_gccrel"

	amove $_gcclibexec/*gnat*
	amove $_gcclibdir/*ada*
	amove usr/bin/*gnat*
}

gdb() {
	pkgdesc="$pkgdesc (gdb printers)"
	install_if="$pkgname=$pkgver-r$pkgrel gdb"

	amove \
		usr/share/gdb/python/ \
		usr/share/gcc-*/python/
}

sha512sums="
cb4e3259640721bbd275c723fe4df53d12f9b1673afb3db274c22c6aa457865dccf2d6ea20b4fd4c591f6152e6d4b87516c402015900f06ce9d43af66d3b7a93  gcc-14.3.0.tar.xz
1ecffba1b07d60e1b4422302b032bbea918b674c8e12b30aa6965b544d700ce86b61e9f7b8d402c6caf59257f491a394dd0912f0948565d6eae9335ee54f3b35  0001-posix_memalign.patch
6dd1eecbc050e30e5a0493969a0e80507d971f4ca87c06466f725fa50c9106e18aef86453fc8a80cd277438b6e79695a99cdaf2eaeb2f1add7e28f7cffd0cd2f  0002-gcc-poison-system-directories.patch
b6903b60b01187bfebc961e74d01ff5d8dc2852747663dff2b4a4f66df4b5aa412347fe92926cce1821fdd0c59d088404acbbced4b464aba9664d599a9e1bbce  0003-specs-turn-on-Wl-z-now-by-default.patch
d41a519ea5014e9ab49f017d3793e2a0a82429c2b7ded2776f2df7a2d0ac02aa294e7dbe74e027fe7c844c87525d483e0eda3846cf16340eb02e934389cfd838  0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch
e34d7bb51c4c413b1a10bafcdfd5729fb5980b0288277ef44ed4779700d443d2fd22129b3b22d401def140851263e803160d2f3ed8825b0bf4f3fb8606db77bd  0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
83665b6adb0b8080245b253abe3344ee5106ac2bc248aad9bef713b22b644a268d75c75fbab7554e0543836903a89bc4f0bec4b6d6d4e3d5ba355dddbc5ba190  0006-Enable-Wformat-and-Wformat-security-by-default.patch
ca5757a32f02bb24bc5b42bb03dca49fb9f9e6f34776343f1c5580efd2bcacf8c5b59f4b61652fa3ea1506eb14bcd390f5fda7b4cbfd32f7d1a750d14add4739  0007-Enable-Wtrampolines-by-default.patch
e476da4c2f29a941b7f4f1dfc9a37ba82b439badc47fc3fb72630ec5620f64849bdb66d339e0182674a0ee898a75564ffaf702986b770bfd793e7fbdcaa9f21b  0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
93d03afd83dee5f7129c36a7b81fa8fd323476507e2f53a4fbe40a026037e7dfafa23591145d7af5848d9a322d212497947a0f58ef828734552e6a6dabd00cfa  0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
da9eaf2f0ddbec5ee14dc26053936587e6c76fbf16846db804a18cf4d318579426ebcc566aed02daf8e34f60c08b61f5d3959305886dca9bbcdc84db057258d9  0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
35b9aafe7eee8138cb7aad7164a8f77c15ccdce26843cee78b5871ef91d76cad22ed0871b20f51c4b89b71afd9cfe4ba4227086e158c466558513708fe7d2a1a  0011-libiberty-copy-PIC-objects-during-build-process.patch
b40b6cbc3725ae88c506bc39a8ba10cfcdcc208fa26d667393bbb80e24346da2ccfac3ff914bb9fc4c374f022fa7f913e6873b9a66a96b79a1ac84959c9d5348  0012-libgcc_s.patch
6cc2c00b15d259289fa9831b60b58f8afdf09858410bd08ab3d839a45c6f3fb9e8e214dab851d105c61df7965f1c10255c84b5b6301630a390b27b8929a25e1e  0013-nopie.patch
0b50ad15115192699efa9fda3d4fb1c2fa95da06d7880ba34615b40c19a8256e1fe364da39f5c70dc22fbccf21db2de5900932afef68948722eeb25e435262f8  0014-ada-fix-shared-linking.patch
7640e71cd957066e2e07ffcec1f8540cd6b1bdaf976c980693bf6f5d3afaf51ca7e41c62f92cb13c86c2dea9eb9cd799b2e3ea77d74926e82bf1e12bb7a4d64e  0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
7f0bc42b93a389b614054e700b851abfbc53db391aa10cbdf6990d41396b293af78980bb39f1cf0967184d3fbf3d46ac7c7f096717b8f193ea34cbf7f37d7e91  0016-add-fortify-headers-paths.patch
8a8c9dc96f300f660f1a643c800352383f32db258dfcfa88a44159a38bb81a7298089a5dcb23906002c85cafc806caf6f3db0e1cb26fcac6192ae1e41d9ada3a  0017-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
6c1cbfcf9e6f54b2173af39bbbfd97e7c18ae32a690fb4c6b1e35fa183992ea0f8046d479be57b6ac7d798bf2a6dade4f9ea3e3a839dc6fb8d47203de9c89e25  0018-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
2213e07bab6f5d8d3d39c732f5385f46cc8f0c84e35054139fdaf13051252d7bf11f647f54aa8456b532166b008fff0656d8f41278e34ba868dd6fe427427a3a  0019-aarch64-disable-multilib-support.patch
a9567947471c3ba8a547a79c55e183974554bf823d9a97a165c966d7b3caad8789980e096e3b78452ece5de062bd9bb006af464bbf0c5a35b689eac3ee21e5c5  0020-s390x-disable-multilib-support.patch
f382eb5f7c2c60c5a23fac587c9629a3059d7be0898e97a1feaf9b9cbe1ef4693cc1177eb29333e8b7944fa17487478e73958be45d5782ccb9ef501961fb9a96  0021-ppc64-le-disable-multilib-support.patch
44ab86feb8e41e7c2b2e27accdf46194c9b80ee6a39543303dc04824f669d9fad182aabd40c9c7f6c265cf9bb71be830c257be115dc9d701d54eca3aa9ef174e  0022-x86_64-disable-multilib-support.patch
0ef65a344975b641343767e289578ba5b0fd381c7177ebe4558cb67d8b41e33e3b825478fa46852f1f40ec9119ff908cf75ee36307266aea13f39460e080b0b6  0023-riscv-disable-multilib-support.patch
55438233a217dc1ee58990413b8782b9bd560a1532c1e6c860f377072ed1bdf75d5dc2458ed33194040ec5427c30df3fa68948dcd26de90e3803d3f7b784becd  0024-always-build-libgcc_eh.a.patch
8fdbe0c8bf4ca60f458a33e59027de03d15ac91933fe46d8ca62119346d20b9bc2447c0bf22bceb63d0cf8613ab61512d9197f4e6c2224af473b63ef9f254295  0025-ada-libgnarl-compatibility-for-musl.patch
02e8358b8855fb49bbb2b3ef293cff67441c5fdf1f2fee4dcec86ef1fd4f701e899ea9c7e072d888b0f1e674d7874d3085138f3deb9845d1f2e35d4a1fe3f5ab  0026-ada-musl-support-fixes.patch
8eff7679140f9e39f1a0ac2e4a6cc7e131efa3d5a669696dd28300eb5d75ef3be62f10c1b91d8f8c8ba2cba1ff9cf121228b6fcd3adafa28389ac63698e7d5a7  0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
720a4001f9a1fa4122e456077ecff8d3eb8af7c83d0a81f9da6a6cca05b23664206a82a349e34482c48bfe40e99aa5f21567613d0913f6a24f282bc84a994496  0028-configure-fix-detection-of-atomic-builtins-in-libato.patch
2044c23b23726965c0a6fd39f616cc464badd650947cb40495eeabd906a3af629878c1d28b403b8eb46b30a1a0ba39083023290d62f0c99ccf070063226e3f8f  0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch
458c9b121e00cec4d0dbe1d18c5e5332342eb0a3429129e5a9d9ace3247c31d85571ad9f47046c4ed3bc62e5d8a4297f48744a30424a19acbdd9aa484e3ee715  0030-gdc-unconditionally-link-libgphobos-against-libucont.patch
099103f4b0b4612ff4bd2e8721cf1593415b636bff74d4feba304bb610ced6f4951cb3ab89088111e58029a2f9bf4a5dcc91e2b2afe4dd9813d2fa6b0999a5a2  0031-druntime-link-against-libucontext-on-all-platforms.patch
21ff4d55eec48ad4a9db0cd359e760cff548f7f6b1a67759a2e87fc7e16a262d82d2f980d309a3ce5e14097665beeb5516a5f2d98869a5d28345e685c6fe689d  0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch
c474f34e6f9a4239d486a65141a133dbe8ce91427d502a57a9fd6eb403478a2b5715ba74f24c1cc0761e16eec77ba2c1ca921fb7d7bc1e040fc3703fc9559e75  0033-libphobos-do-not-use-LFS64-symbols.patch
c4482ffc36e7894b2140800159f4cbc9a3e9011e43a69b69f4fa92d5a11e2ee645c7e21df4423dd1e0636e8890849a5719647bfbdf84f951d638f8f488cb718c  0034-libgo-fix-lfs64-use.patch
65df1d489e8d07a811f39e27fd29e3b2b4164fbc2c5fdc16a5142886d94a96e3fb28ccf4f20dd297ba6540ef8ea1ac3eb65a4279494639bf2f0f8376a3896cc3  0035-loongarch-disable-multilib-support.patch
06f64544fd8bc4b6c8b06410c5198aa8fb4e82c232afc0cad83b2c69ac5d39399968206defa78297222700cd18e7fd7e8244afa76d343406a01f657c86306453  0036-libphobos-add-riscv64-and-loongarch64-support.patch
8249ce989c1a76bcb5bbb1123ef88d88f220b709fe6ac804f18c905a7b31c4e68ef6f5cc2236f446feed89fa773a3aed996a6aba7618e73a000d73cb0b0753f6  0037-static-pie.patch
90b6148d47f39caf1b70416abf2a09f4ce048491f784f56bd659dbf99e2c9f6a44b244827f23977494ab4e42640c49c1dc79f43a4d69c2b31c4b1e25d54d8142  0038-except-Don-t-use-the-cached-value-of-the-gcc_except_.patch
"
