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

CTARGET_ARCH=armv7
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-armv7
pkgver=13.1.1_git20230708
# i.e. 13.1.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-armv7
pkgrel=0
pkgdesc="Stage2 cross-compiler for armv7"
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-armv7 mpc1"
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-armv7 binutils-armv7"
subpackages="g++-armv7:gpp libstdc++-dev-armv7:libcxx_dev"
[ "$CHOST" = "$CTARGET" ] && subpackages="gcc-gdb gcc-doc$_target"
replaces="libstdc++ binutils"

: "${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_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_D=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_D=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_CXXFLAGS="$CXXFLAGS"
	export BOOT_LDFLAGS="$LDFLAGS"
fi

case "$CARCH" in
# GDC hasn't been ported to PowerPC
# See libphobos/configure.tgt in GCC sources for supported targets
# riscv fails with: error: static assert  "unimplemented"
ppc64le|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 ;;
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 ;;
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=$LANG_FORTRAN ;;
*)		_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 "$CARCH" in
riscv64)
LANG_ADA=false;;
esac

_languages=c
if $LANG_CXX; then
	_languages="$_languages,c++"
fi
if $LANG_D; then
	subpackages="$subpackages libgphobos::$CTARGET_ARCH gcc-gdc$_target:gdc"
	_languages="$_languages,d"
	makedepends_build="$makedepends_build libucontext-dev gcc-gdc-bootstrap"
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"
	_languages="$_languages,ada"
	if [ "$CBUILD" = "$CTARGET" ]; then
		makedepends_build="$makedepends_build gcc-gnat-bootstrap"
		subpackages="$subpackages libgnat-static:libgnatstatic:$CTARGET_ARCH libgnat::$CTARGET_ARCH"
	else
		subpackages="$subpackages libgnat::$CTARGET_ARCH"
		makedepends_build="$makedepends_build gcc-gnat gcc-gnat$_cross"
	fi
fi
if $LANG_JIT; then
	subpackages="$subpackages libgccjit:jit libgccjit-dev:jitdev"
fi
makedepends="$makedepends_build $makedepends_host"

# when using upstream releases, use this URI template
# https://gcc.gnu.org/pub/gcc/releases/gcc-${_pkgbase:-$pkgver}/gcc-${_pkgbase:-$pkgver}.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
	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
	"

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

prepare() {
	cd "$_gccdir"

	_err=
	for i in $source; do
		case "$i" in
		*.patch)
			msg "Applying $i"
			patch -p1 -i "$srcdir"/$i || _err="$_err $i"
			;;
		esac
	done

	if [ -n "$_err" ]; then
		error "The following patches failed:"
		for i in $_err; do
			echo "  $i"
		done
		return 1
	fi

	echo ${_pkgbase:-$pkgver} > gcc/BASE-VER
}

build() {
	local _arch_configure=
	local _libc_configure=
	local _bootstrap_configure=
	local _symvers=
	local _jit_configure=

	cd "$_gccdir"

	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";;
	esac

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

	case "$CTARGET_LIBC" in
	musl)
		# musl does not support libsanitizer
		# alpine musl provides libssp_nonshared.a, so we don't need libssp either
		_libc_configure="--disable-libssp --disable-libsanitizer"
		_symvers="--disable-symvers"
		export libat_cv_have_ifunc=no
		;;
	esac


	case "$BOOTSTRAP" in
	nolibc)	_bootstrap_configure="--with-newlib --disable-shared --enable-threads=no" ;;
	*)	_bootstrap_configure="--enable-shared --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 "  CTARGET_LIBC=$CTARGET_LIBC"
	echo "  languages=$_languages"
	echo "  arch_configure=$_arch_configure"
	echo "  libc_configure=$_libc_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
		$_symvers
		--enable-__cxa_atexit
		--enable-default-pie
		--enable-default-ssp
		--enable-languages=$_languages
		--enable-link-serialization=2
		--enable-linker-build-id
		$_arch_configure
		$_libc_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"
	"$_gccdir"/configure $gccconfiguration \
		--with-pkgversion="$version"

	msg "building gcc"
	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
		"$_gccdir"/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

	ln -s gcc "$pkgdir"/usr/bin/cc

	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
		for i in $(find "$pkgdir"/$_gcclibdir/adalib/ -type f -maxdepth 1 -name "libgna*.so"); do
			mv "$i" "$pkgdir"/usr/lib/
			ln -s ../../../../${i##*/} $i
		done
		if [ "$CHOST" = "$CTARGET" ]; then
			for i in $(find "$pkgdir"/$_gcclibdir/adalib/ -type f -maxdepth 1 -name "libgna*.a"); do
				mv "$i" "$pkgdir"/usr/lib/
				ln -s ../../../../${i##*/} $i
			done
		fi
	fi

	if [ "$CHOST" != "$CTARGET" ]; then
		# cross-gcc: remove any files that would conflict with the
		# native gcc package
		rm -rf "$pkgdir"/usr/bin/cc "$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"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libatomic.so.* "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libstdc++.so.* "$subpkgdir"/usr/lib/
}

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++=$_gccrel libstdc++-dev$_target=$_gccrel gcc$_target=$_gccrel libc-dev"
	mkdir -p "$subpkgdir/$_gcclibexec" \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/${_target:+$CTARGET/}include \
		"$subpkgdir"/usr/${_target:+$CTARGET/}lib \

	mv "$pkgdir/$_gcclibexec/cc1plus" "$subpkgdir/$_gcclibexec/"

	mv "$pkgdir"/usr/bin/*++ "$subpkgdir"/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=
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libobjc.so.* "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir/$_gcclibexec" \
		"$subpkgdir"/$_gcclibdir/include \
		"$subpkgdir"/usr/lib
	mv "$pkgdir/$_gcclibexec/cc1obj" "$subpkgdir/$_gcclibexec/"
	mv "$pkgdir"/$_gcclibdir/include/objc "$subpkgdir"/$_gcclibdir/include/
	mv "$pkgdir"/usr/lib/libobjc.so "$pkgdir"/usr/lib/libobjc.a \
		"$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libgcc_s.so.* "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/${_target:+$CTARGET/}lib/libgomp.so.* "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgdruntime.so.* "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgphobos.so.*  "$subpkgdir"/usr/lib/
}

gdc() {
	pkgdesc="GCC-based D language compiler"
	depends="gcc=$_gccrel libgphobos=$_gccrel musl-dev"
	depends="$depends libucontext-dev"
	provides="gcc-gdc-bootstrap=$_gccrel"

	mkdir -p "$subpkgdir/$_gcclibexec" \
		"$subpkgdir"/$_gcclibdir/include/d/ \
		"$subpkgdir"/usr/lib \
		"$subpkgdir"/usr/bin
	# 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
	mv "$pkgdir/$_gcclibexec/d21" "$subpkgdir/$_gcclibexec/"
	mv "$pkgdir"/$_gcclibdir/include/d/* "$subpkgdir"/$_gcclibdir/include/d/
	mv "$pkgdir"/usr/lib/libgdruntime.a "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgdruntime.so "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgphobos.a "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgphobos.so "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgphobos.spec "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/bin/$CTARGET-gdc "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/gdc "$subpkgdir"/usr/bin/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgo.so.* "$subpkgdir"/usr/lib/
}

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

	# See https://lists.alpinelinux.org/~alpine/devel/%3C33KG0XO61I4IL.2Z7RTAZ5J3SY6%408pit.net%3E
	provides="go-bootstrap"
	provider_priority=1 # lowest, see community/go

	mkdir -p "$subpkgdir"/$_gcclibexec \
		"$subpkgdir"/usr/lib \
		"$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/lib/go "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/bin/*gccgo "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/*go "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/*gofmt "$subpkgdir"/usr/bin
	mv "$pkgdir"/$_gcclibexec/go1 "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/$_gcclibexec/cgo "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/$_gcclibexec/buildid "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/$_gcclibexec/test2json "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/$_gcclibexec/vet "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/usr/lib/libgo.a \
		"$pkgdir"/usr/lib/libgo.so \
		"$pkgdir"/usr/lib/libgobegin.a \
		"$pkgdir"/usr/lib/libgolibbegin.a \
		"$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgfortran.so.* "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libquadmath.so.* "$subpkgdir"/usr/lib/
}

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

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

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgna*.so "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgna*.a "$subpkgdir"/usr/lib/
}

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

	mkdir -p "$subpkgdir"/$_gcclibexec \
		"$subpkgdir"/$_gcclibdir \
		"$subpkgdir"/usr/bin
	mv "$pkgdir"/$_gcclibexec/*gnat* "$subpkgdir"/$_gcclibexec/
	mv "$pkgdir"/$_gcclibdir/*ada* "$subpkgdir"/$_gcclibdir/
	mv "$pkgdir"/usr/bin/*gnat* "$subpkgdir"/usr/bin/
}

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

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

sha512sums="
ca703acdf2c32ad7cf28d159a3306dca4032771d701074d618d08a3b8684b72f6c28d62f1e3263e4cc0064c960bc30373877c3f89fa6f35dddd8794f66ab53dc  gcc-13-20230708.tar.xz
5738a25e510d47058ea7acf44f47292c365f74f60f75d600c3bdf79022a78e3c14c87648e23d3f44612833123ba1ae6776c8a6ea4371bf8c2cf31ea8296a0278  0001-posix_memalign.patch
35cba990b41ba8fd2544404a0330ceddfbc7b63475f4ebb515552d5ec494d0099f0585240a36099431ae6dcaf9bd7674ca0224f0dd4310cd3597aabadedd1d07  0002-gcc-poison-system-directories.patch
fa3b349be7e7f49c1d2192a84d6fc6b9f9b750381607711950d3ad5c867c677dac65dc2274fa4227aa6909d6b5e0fcc59b137254202035e930a2c6a0ba494e2f  0003-specs-turn-on-Wl-z-now-by-default.patch
495b08b8b25f25f616fd68d205c23232d8307a35dae81f5d37e248ec704734e40618d5e3855f1cedeaa615b1d03e5a34089695faca9798d51a367a0e3bc59b78  0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch
ee10b0b91e7b0a91a47b6708dd8a41c8f08a89f87a3eed57aed2ea3df5b7109a2a33741651a294a10f056c736beeb0be0fb6004c0517e8687a80bc33be50d8c9  0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
87dca73e398acf396ade55b8cd533d3e90889444c27069df9840a57d524d8f045781b4a38f9e0e52595a510049a0832a5067f6f0200df00fc51501316fa7c61b  0006-Enable-Wformat-and-Wformat-security-by-default.patch
5eca632dbb3f709ee92ba89e062642cfcf854aa31426b8eca859432773bff4bffd35fa6a7418a760bed89a30a1f64e1de87b0353e9d332d8abc72c14e236e1ed  0007-Enable-Wtrampolines-by-default.patch
d46546536564f76abcda3a54b0c159175aca7044542fdcdf1f08c46bfabff452e2ba7d535e9e5b04c9c595c3f865bf80bdece8aee4a0bc24baea4f2c94fcf0bb  0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
00ce50efdeb9a31cbd9ca2d2fa22cd27b1d972e96c01948bd9ae95aff7275e6bc894196ff871107c5feadb6cb832119127240f4539fda35d4326955babf5f510  0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
46a228b875f835fd1c2cae479f5e931cd2afc4124690ebb935ea49a3fc4ed46b69d4c76e18a1d7632283690e9d51fbcb90f478fc0b87d532dc095fcf067de7e6  0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
b2c5e2af8f6f50da5795de7fb94309149eb63b1dcc31d72147975702b751e7af0f89adbde7e359416a4ad7749c3d251e6c2b8b57c9a24c77e15c9ce4730d5e4a  0011-libiberty-copy-PIC-objects-during-build-process.patch
8c60c72a123d984452b57bc6a7d3dea3ab092e963d459d8a69a27384c8cf2d7e0e718d1dda2957b62cb2d0353dd851e57c3d1791f90adf6a32393b64846677d9  0012-libgcc_s.patch
082a1dcca42899fc7c70616f0b73fc640fbaae8c4f08c960c71bd9f2cda57bf34a662f1f6327a6eb7e026ebe3414ee71303c3354687ad6c14068fdf37025f2e5  0013-nopie.patch
ced25410c21b0bac351ef4a6c2d381f4e0a1c0f4043899bbed2f10ad5f5c39ec6ff4cde07c62d486643a89421c28266798234c318a09a029bc1a79d6adee1c0e  0014-ada-fix-shared-linking.patch
f245428f57f1d59e353b3c1d745c7cb3987689d8ef3cb38e113f69750dca08ed76681ed72b2d5ee659d0d6c33179c4b12eb1d509c0baf185cc8c8549e0c09f8f  0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
4fd357f4f24899f742e19680db543647dea556e3144744ac990474ee01f32d28e1724f6f56dac4ba2ce2491aae88ffea16b6f7c33b74132deb2f932d550f119a  0016-add-fortify-headers-paths.patch
dd028aeb2e8a32157a419f4450fa70a96522ce2de88febfac374d11f1340660584c7547eaa287715f585289aa313b17918a52b64bc758778833f387c0e3c3506  0017-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
47eb31a354177f4abd699e6bcb29ba688eeb51511b27969a88e25a0153108023ceb3d821fe3ffca0491dafec5341a3186b813519b9d043450eeec990bfc7d7d4  0018-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
b77e98c45d28e42ec9f9842b5aab3fd69b8696ea69376a049e7792bd5cef98c730ab5a458406084fb7be2f3c361962c407b72dde3dd27857f55433f3fc749b3c  0019-aarch64-disable-multilib-support.patch
79b3a8ea1fe452a2f8fdf2b15b75754ed00f2993120596e7870622d4d608edf8c3ddc31181dafa40815fdfe277a10d539830484f09a57c3b0ee5677785224e04  0020-s390x-disable-multilib-support.patch
d250d791dd9d5190eee9fc54326830b0e19d9986e801d0576199808c6e211f5137ce71b92e0dbfb1ab910c22311b4b48dbbd63fa9390c2e2491dce80062e5f51  0021-ppc64-le-disable-multilib-support.patch
51206e8132e93bb79f891f0f69461982435fa4212b1bf91c75b9bb9ee7fd25106d53fad21470f4706b5d258fbe1715ef7524d6c2bb94813b7d4a48d949a176f7  0022-x86_64-disable-multilib-support.patch
b774c6a750077a546d1cef0b31812d5d68cf64a8abdd47a30180fb6f3a848941e7986f4a587da9a6ab034e5083068723620319e3f821f0db3ff66dc4c33faf06  0023-riscv-disable-multilib-support.patch
1b6ed17c5798d8fd80826188c35232d0f90843d6cba060ea784fdfa5b5cb2490ac4507ce9802f7f6f50ccb7fe5db34cd6860c256e9da311710c95b1d4870fc1c  0024-always-build-libgcc_eh.a.patch
4b9f4446254720e692478fb016798b44c6ebc021816dff49fe32b6eac4f4da091c47adf46f040df603ee74f4986a832257eaad4d3c594b6d50a23e447c755586  0025-ada-libgnarl-compatibility-for-musl.patch
fbc903ca64f8a17ea8ffce4cb882dd53713dee3b24b729ab81741a8133802b9c95619596829706fcfe26350a33e8558dc9b9edf92802170041c3f4f831b2ff2c  0026-ada-musl-support-fixes.patch
8d3f37bd75a9fea17c277b380aa943ad44989c65e6aabbf09f9c3f35acb1f048dbe361bc788b6ef2133dee3b9f646c56637811fe33171a50a2a024fe9d78e6ef  0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
04a07053c82842f1ec5ec58723c0801659f8174318e32d1e966411422bfa9665f259ba9025d030e0e298608d6eeff423cbe5ed9981717d691a49de8806ead7aa  0028-configure-fix-detection-of-atomic-builtins-in-libato.patch
3398fcb9273e5d76006b2c2c0215cf9ead757faa4751f7a55cf7bc687894ac38da47e76700860ea3c7f8feb18361e4ce8ce6b16a365fdfe4c61032bd53da56e7  0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch
ac86593db92aca836a91dd7ad3060e6c1d92b1b7c685a6fa1b51281f76b091fb07058d8d53f16f7df18eb148fde0526723c6cf6fc4c38471399dc7fde8892307  0030-gdc-unconditionally-link-libgphobos-against-libucont.patch
e2f8901bf30494563373a24cb632a251056cb99dbb9cce789817f12016da323f702d981ce4ba9d7d52eefc33f257568509d391776fd022b012e589b43857c696  0031-druntime-link-against-libucontext-on-all-platforms.patch
434d3739d7e6ecc5017c29711c3a7c207e7c673d2a535607dea78a5a5d265d8efb74b7f726c18efc13e9c80c29385ce1b4e3b53c7d1c9d55bb1b8a217425f3ea  0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch
8a56a2a1d1c60894ab429ecc8fa3ddbfdd6c7e3cc9f764b4f260695a2cd54442668e9b4c7ba62d833e5dbc05548586aefc344caf9ea87cdf6de60ce3c30f9da9  0033-libphobos-do-not-use-LFS64-symbols.patch
"