# 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 !tracedeps"

# 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
_pkgbase=10.3.1
pkgver=10.3.1_git20210625
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
[ "$CBUILD" != "$CHOST" ] && _cross="-$CARCH" || _cross=""
[ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target=""

pkgname=gcc-armhf
pkgrel=0
pkgdesc="Stage2 cross-compiler for armhf"
url="https://gcc.gnu.org"
arch="x86_64"
license="GPL-2.0-or-later LGPL-2.1-or-later"
_gccrel=$pkgver-r$pkgrel
depends="isl binutils-armhf mpc1"
makedepends_build="gcc g++ paxmark 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"
[ "$CHOST" = "$CTARGET" ] && subpackages="gcc-doc$_target"
replaces="libstdc++ binutils"

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

_libgomp=true
_libgcc=true
_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
	_libgomp=false
	_libatomic=false
	_libitm=false

	# 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 $CFLAGS"
	export CXXFLAGS="$CPPFLAGS $CXXFLAGS"
	unset CPPFLAGS
	export CFLAGS_FOR_TARGET=" "
	export CXXFLAGS_FOR_TARGET=" "
	export LDFLAGS_FOR_TARGET=" "

	STRIP_FOR_TARGET="$CTARGET-strip"
elif [ "$CBUILD" != "$CHOST" ]; then
	# fixup flags. seems gcc treats CPPFLAGS as global without
	# _FOR_xxx variants. wrap it in CFLAGS and CXXFLAGS.
	export CFLAGS="$CPPFLAGS $CFLAGS"
	export CXXFLAGS="$CPPFLAGS $CXXFLAGS"
	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

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

# GDC hasn't been ported to PowerPC
# See libphobos/configure.tgt in GCC sources for supported targets
# riscv fails with: error: static assert  "unimplemented"
case "$CARCH" in
ppc64le|riscv64)	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)	_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"
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 libgnat-static:libgnatstatic:$CTARGET_ARCH libgnat::$CTARGET_ARCH gcc-gnat$_target:gnat"
	_languages="$_languages,ada"
	[ "$CBUILD" = "$CTARGET" ] && makedepends_build="$makedepends_build gcc-gnat-bootstrap"
	[ "$CBUILD" != "$CTARGET" ] && makedepends_build="$makedepends_build gcc-gnat gcc-gnat$_cross"
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.
#
# 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/~nenolod/gcc-${pkgver}.tar.xz
	0001-posix_memalign.patch
	0002-gcc-poison-system-directories.patch
	0003-Turn-on-Wl-z-relro-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-libitm-disable-FORTIFY.patch
	0013-libgcc_s.patch
	0014-nopie.patch
	0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch
	0016-dlang-update-zlib-binding.patch
	0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch
	0018-ada-fix-shared-linking.patch
	0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
	0020-add-fortify-headers-paths.patch
	0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
	0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
	0023-Pure-64-bit-MIPS.patch
	0024-use-pure-64-bit-configuration-where-appropriate.patch
	0025-always-build-libgcc_eh.a.patch
	0026-ada-libgnarl-compatibility-for-musl.patch
	0027-ada-musl-support-fixes.patch
	0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch
	0029-gcc-go-Don-t-include-sys-user.h.patch
	0030-gcc-go-Fix-ucontext_t-on-PPC64.patch
	0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch
	0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch
	0033-gcc-go-Fix-st_-a-m-c-tim-fields-in-generated-sysinfo.patch
	0034-gcc-go-signal-34-is-special-on-musl-libc.patch
	0035-gcc-go-Prefer-_off_t-over-_off64_t.patch
	0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch
	0037-gcc-go-link-to-libucontext.patch
	0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch
	0039-CRuntime_Musl-Support-v1.2.0-for-32-bits.patch
	0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
	0041-Use-generic-errstr.go-implementation-on-musl.patch
	"

# we build out-of-tree
_gccdir="$srcdir"/gcc-$pkgver
_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=

	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=armv6zk --with-tune=arm1176jzf-s --with-fpu=vfp --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=i586 --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 mudflap, or libsanitizer
		# libmpx uses secure_getenv and struct _libc_fpstate not present in musl
		# alpine musl provides libssp_nonshared.a, so we don't need libssp either
		_libc_configure="--disable-libssp --disable-libmpx --disable-libmudflap --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 ""

	export CFLAGS="$CFLAGS -O2"

	mkdir -p "$_builddir"
	cd "$_builddir"
	"$_gccdir"/configure --prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--build=${CBUILD} \
		--host=${CHOST} \
		--target=${CTARGET} \
		--with-pkgversion="Alpine $pkgver" \
		--enable-checking=release \
		--disable-fixed-point \
		--disable-libstdcxx-pch \
		--disable-multilib \
		--disable-nls \
		--disable-werror \
		$_symvers \
		--enable-__cxa_atexit \
		--enable-default-pie \
		--enable-default-ssp \
		--enable-cloog-backend \
		--enable-languages=$_languages \
		$_arch_configure \
		$_libc_configure \
		$_cross_configure \
		$_bootstrap_configure \
		--with-system-zlib \
		$_hash_style_configure
	make
}

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

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

	# 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 libmudflap.a -o -name libmudflapth.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
		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

	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/
}

gpp() {
	pkgdesc="GNU C++ standard library and compiler"
	depends="libstdc++=$_gccrel gcc=$_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/${_target:+$CTARGET/}lib/*++* "$subpkgdir"/usr/${_target:+$CTARGET/}lib/
	mv "$pkgdir"/usr/${_target:+$CTARGET/}include/c++ "$subpkgdir"/usr/${_target:+$CTARGET/}include/
	mv "$pkgdir"/usr/bin/*++ "$subpkgdir"/usr/bin/
}

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"

	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/libgphobos.a "$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="Go support for GCC"
	depends="gcc=$_gccrel libgo=$_gccrel !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"
	[ "$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/
}

sha512sums="
e3381e4511fff63f388b0898669f83eae82334c7833dac3a0d4e3a3241d4154400681b7c934253b2e773922cb91b33d586888ff6c1e00c8be96bf708c9247178  gcc-10.3.1_git20210625.tar.xz
1d5788a2bede9ecdf2597a836fecaadd78ce4f5742838edbf5ef1091bc6fa73d2e43d862a5ccdcb45d404c49fc943a8110ba470608b2b4da165dbdcae00818ca  0001-posix_memalign.patch
997b75b108cb95c47eecce8aabb60490bd07d4a0c4bd90d449dcef9f85319ab529fbb19b381fa984e7c73232cbe4e33d0e45a1677ff620dbaa14590518f4ce4b  0002-gcc-poison-system-directories.patch
01623bd69b69bb4690511e0c8b00afddf816eb0040647de7140a588b75cd5ca8f4a087a52793092a8d8e9a95fee546562bc2ebf80141dafc9754ec3a0bde2cd1  0003-Turn-on-Wl-z-relro-z-now-by-default.patch
bbf01f6f857d981d6d82859268c1c7392e277b3943332f47650ff758b791c5711b9d7cfe1c11ed2770dda77a42105433f0da9e974638aad1e263b29c0ee2cbf2  0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch
b9e03d6f18861269d356a686438b848fa294cc1c9ac6ad972b89c64e92cb99a25cf8a0513344d18ee41698825b5d8ea9a23cac6f96c933e03f8e20afdd285516  0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
d9389c82d7075debade8d1b43ab6bd4a087a8bcdc6d1a812923ca80eefe6e45498e552b7a088780e74fd08d679cb83cf94973157ed78d78090594ca4c41eb816  0006-Enable-Wformat-and-Wformat-security-by-default.patch
2a9727a9b6ec7dd05ade8be3e686d82b5702ab9b6185812f72afce627179b8438505b37b5dd3705a751ba600a5a246de69e23e81bf09faeb7680496f2e5803ab  0007-Enable-Wtrampolines-by-default.patch
c8828ef94d4be1ee8979f41ad2fb5d956fd17e7509c0d3df6f88e75d6faf253b9bea8eaa2cf00ee925e0fafabb4823fbfc125d018dd1b19911ee982a3d073002  0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
c150051ffb049ffd6a92b85265dbd9d763044468259220332f196f234031dcbada00bf9fea4be77bac712c0fd554d58ba5bdaa61e437f4678edeb7bdc30bf0db  0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
68d59c2f2714ab41a90e3ea512187f3da8d5d7bd05d07c1fafb2d78681ec772698a5ff4303e98302230a69a3fc1f56bb5d32d58d1ae95dd33e20850d9e02dd79  0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
5059d3207f4abbab13b7b4aa1a9aa40b3fe519dd4a378e049553c13582787faada4f9e79cfee51e291c5ad88947d763217b15356730fecb8eebdde6fd4f285c1  0011-libiberty-copy-PIC-objects-during-build-process.patch
18d6d84b08f4949f510c5c3899451fba08a68e0b1fde381a7df6d117e7493e9093839e660a1293ae4f1a5194b3200b65e89dbb61d6f60e09b292f4452e9f1411  0012-libitm-disable-FORTIFY.patch
55165e4955ce7a881b80701a543d61253252011c21dfc86ab7fa8a49a105b708d2452b588bc631423cdb5dd0f454d877283635a40485684762ec2ad3a103c911  0013-libgcc_s.patch
2e7af3e31f46a44cedeed949730a3c10f573b0d5071e3d6606444a40c9d1ebc5331d46d5e9955473d12bc84de118e3a84c15d0f70019e3a71c671d016dd7203c  0014-nopie.patch
ae86e9dba038e1fcf536bf35fbb0b7f0f113cc5ced4d4507d3c4b8a9f1b59a7e039b4162df7dedf19730ffa7c4e546aa5704c160879cda005123b45a505c0993  0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch
f4002aecd5a53547479c2869c0cf9b7b281d9c1f96f41c6959e81fc3af590a00530389647c0acc2e6f0df2f8bb4d185c9cdcd740487b124e0676b74cc9a3e6be  0016-dlang-update-zlib-binding.patch
d280ac5c6675c063ca671e267c8789181e4b13de65c4248bdac702e0c1daa40089df277858f8740d8e182ee7773ac0518777e1625f20dcb96dbf3d9975ddd571  0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch
53ae0411ae86da64953b0e26bce171a222205697644428248cb2becd394e463a40496d4d06af587bfedcbeb8b323ecae4284d5f91a7c7b30b9053adad0b78a86  0018-ada-fix-shared-linking.patch
37cf7167c1e7e387abaf91acc46d0c751d07f4d427a937d0efac3a479dd5f6a88f632c183462fb1ff4e0145474228960a98721f711c2176c9425a5f33649634d  0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
48e38d2d86843bbfaffc51288bb33d25478d32ab9832684da4066a487a92a6ef24ad6381feac2fb8a7905c5f3000709c3b10cf37f9be70685e1f9c70c63c4363  0020-add-fortify-headers-paths.patch
fcee4fb2d8317490144404b6d6c632607e57a01591b69cb90d9119fc7b5446b59027e403cd65e6bf18dccee127dc5fda96c5a7b43adc14671b85ecd4303da2dd  0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
cedd53c2dd61c4ead859242ecbdac4ac674424ad68eda3326741187d187ff90d6b6e3e88f9b65ceb2e97d914eb38ae62670ac4b08cbaa3728129739fa8fa7f27  0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
fc7684b25163a43a2d97df0614b2d1c8da81a5a80169cbe853aefd442d8413d5d0717772bad1c87ca6e8eff6e26f8aa5f340cebf635ef44192227227e167f08c  0023-Pure-64-bit-MIPS.patch
cdd42fe4a48cee11a23086aaaf9f9c8b55de69987cee88a39a3316878e064066511b5e9e9b98267a27af5042c1fdfcfaadeb5a3ac81fab4102c9b9e261b17410  0024-use-pure-64-bit-configuration-where-appropriate.patch
79f1ab0e29bd3fc7e72d8c59cd380a2b50b6e4b872d5101d4f1ed1ac00368716e3b12b2d54bcbfa60a89104418811034c5a560ffb1de5712bbe590f16f74d2b5  0025-always-build-libgcc_eh.a.patch
073eda8d12299723b2f4d190cfcbe467b529936d580240b1180d0c37286c9b5ab26d8aa99f8b59ce2e195ac46da708d84ad8b9a2f0946398b91448b590e9cae4  0026-ada-libgnarl-compatibility-for-musl.patch
3cb3f153f67d10171b3bc9cb8f7acafb611f2f221dec2a6129cab63f9cb97bd3b9c0e512e9d70f985cc139859d64b266fe71504eb0ca2ce5ab59ca82445e4b14  0027-ada-musl-support-fixes.patch
e8d8e7b2f39d706c7aed4b9e6b5f166482e317b2b68e9250880cd864932e0e69d9b595eaa9e10e573f88207697489cf89aa968d2e0a9aa3d92c44717c9f6e9f8  0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch
674a0599e9e0f450bbb924513a4a6ee1dfde0848d47110ce1415782b6f848335197bb86798063aae5626d01ee892c993762dec83c729052c536d97d6b86999f0  0029-gcc-go-Don-t-include-sys-user.h.patch
8714dde37beda68d901ad6c50c208c3fd3dab81951898535a964348c6b45bd2896b1386302061fedeccf29228ba9d5e788657e550d3680c6562c024b6b135ea3  0030-gcc-go-Fix-ucontext_t-on-PPC64.patch
e5c9bc4825f5adefe1eeee80dc24a05cc6224b20c5a4e36e1d3b74255ab1d2b1dda0f90915a208ce7d09a22853e1782aedb3c57729a4e650eb13a2c1f9bc0482  0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch
578d2adbdf036a1764143340fb63055b0f23cdfc75c79a91813194c0dd346900d36c5db334ea341ea29c51dd62e94618ce49db422603284bb565260d0ee2d4c6  0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch
3e06a22fcda856bdde6d77d2ef11b0a60b5a99b3c8dc4a7919a4c4f3fc01b86f94f141b58df8129d739f9cc1b116ebf8b4e6d82d58e6c5c38eccb677c5f4c0aa  0033-gcc-go-Fix-st_-a-m-c-tim-fields-in-generated-sysinfo.patch
5c4edc35d40b759d08dc3b536be5a20be727e5a37ea2755f0416de932d2c641661d4e197f24c3128f9fe79daa08f80528d925676920ff03ca0f8127ff13a9ea6  0034-gcc-go-signal-34-is-special-on-musl-libc.patch
41ccc997352859f0c023c4b49f8a8f3d505727163db8ba9795d26c0ba89a004b232ea685da7cd6f210272641e107a09c398578ae3e0e6e065982912555f0d2bb  0035-gcc-go-Prefer-_off_t-over-_off64_t.patch
c70b599de8698ea2b6ed865f5ca503a55ce1590c4d30af5af4c36d4fce1d42f19d347f44d6e62fbe84bebeeaac9c90d74bb9e17e2b7bc66d8e8988e98f81cac3  0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch
19ccab17f5ba7c02643a1ea85f3690554d3142e3bdd7a68d663a74381336f74007d1ef053fe4e78acc3154ee6f59606de5fbe54dac9efa72291ace76902b2856  0037-gcc-go-link-to-libucontext.patch
b92ea62f8ffc7471dabbc8a6f770fc141702d4900f6eb4808a8b0c46042434617185366d93b491220e4f079827239b3849d078acd4389a360f6ef7fddf2ab249  0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch
1f54ea2ed780964da3238bd98b63719d68585ac97bd312211797dabec3fc7c54b60af9f7ffc490355c898ed42c0a2745e6486bfc0577b9adee88ee1fb35bf2d1  0039-CRuntime_Musl-Support-v1.2.0-for-32-bits.patch
7e02eaf9e0261a2942cbc4db626cc6d67955bdfdc9036d505f1e3a4b3fa03993de403b58173137ca98db3365df28db234bf70ae76a74a463c39887a40780c2a7  0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
99ecfd0beeb8dfcd95ef84b3ad8fb43402edb87ac6b0591c7a8bd986b9e163e1b8ce2c5773ee3cbf1264dc40912b7312f450e6dde4ab8a6cf28b02541de7ce84  0041-Use-generic-errstr.go-implementation-on-musl.patch
"
