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

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

pkgname=gcc-aarch64
pkgrel=1
pkgdesc="Stage2 cross-compiler for aarch64"
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-aarch64 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-aarch64 binutils-aarch64"
subpackages="g++-aarch64: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-There-are-more-than-one-st_-a-m-c-tim-fields-in-stru.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-Use-generic-errstr.go-implementation-on-musl.patch
	0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
	0041-configure-fix-detection-of-atomic-builtins-in-libato.patch
	0042-stddef.h-add-support-for-musl-typedef-macro-guards.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="
2a682823f9b114c4288a3428dc658ce21679f48a5b901d4792fc4ea09f75e9c9516f8cdc7c70697e1be335d925f99eac01eaf20c117cd5ee685181d37fcc7290  gcc-11.2.1_git20211125.tar.xz
14ef1a0b284c85859f4db03cb0750c4dcadb8821dd0ec1b04e6872ffd2fa55ae125a99fee986a160bce9448226d08daf05e1a7feda5220e746aaa5f338d78d69  0001-posix_memalign.patch
950b04c8bf96810dfe4bd4c2ea5218dfacfae0f0b1be9e64cbb1f09bbf67d29565b59094aa4d5cca095355db8cce99c80c99f0463ef296a96faf6b13e38230e0  0002-gcc-poison-system-directories.patch
1d9c1b028b07644da9182288a26762f294d1ef25804c0227bfd3419a2a8ba579bec7590aaac9a241242bb14e3e371eff81ad26a07d0183be821af59bd6abe4d4  0003-Turn-on-Wl-z-relro-z-now-by-default.patch
5a705aa5ffdc5ab3fb417ddb494486156db4af3b7f9a1d29e1b3ac2e7095f924b2a3f73a73b4d7d20f6ba3c77b062f1b47e7b46c0a8e1992f349abe3cf7f6542  0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch
87573db27fd83fe9d7c40cefb5bd264e36500280ab2dd39c1763f87f4cfaef3e0d3115f4aadd3b3d65c93a13db17df469e038931335685dfad4adf6b48e96c66  0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
4055d8b934c8a017bbba74b224c8da105668ea16fc9f244b0dacc9511a89088701b491daec09d95041f640b7f0e994feb17a0803d389818f104578bfaf433623  0006-Enable-Wformat-and-Wformat-security-by-default.patch
0ffb348414468ea166d5875e0f20f77a813473a6823e26189b010eebb835c91e14b04f360b139fffbc50b30622476a625a5f567d26b6c18ddcbfc88e6d28e54f  0007-Enable-Wtrampolines-by-default.patch
799117fc233f3172457024a71d4d964c6a367b7ae7246e208ba16192a533bdf484dc72b79eb7ee3629c0eb7fe202d32658a64219c03c9098120c899d9f832309  0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch
eb47d678ff9a14ad54833b1fdc2d04976e31db741cdf9ac6b213d56df3df3ea61514bdfa5bbe2577b82135517e184de53028663b7aad565613e90c0bafd6513f  0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch
e3d2241e3bb8e67bece8a322cdc707542586f7a1b5da9412eb38dbfa40508e618b8827e3574b21c86b9d263e8ed31941d8885618707c1947d07f86d18d34a9a8  0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch
e8976a1f1618e94d519852dee346bb787589637905451a6f02b4f8a1ffc5a6fa797a697b8c0964a72830aad32ba412986d45e9f88ae86e3d7c8007d3b1400692  0011-libiberty-copy-PIC-objects-during-build-process.patch
2cc03796789b6680f43533d41a1966283b6e913b19080a00c4ec6653614f1af66754db7ffca05103bb398e389316c9fca525d2fe00965e1105b210d1d940d507  0012-libitm-disable-FORTIFY.patch
8fe44a88f66f1d282c5c6db80642ac8ef52f89ccc8287f73eecd1c8d78ee3e5ac890065d173fc3ff00172b8b3984ca484debbf84b9ba649dc5939afdfc4a220a  0013-libgcc_s.patch
1323a512d063f9a0679c68c9856ede8a6d48ae0c9c52ef14e63d34e6a2b6486fa02301d75554b2d623a369967c71ca35e7c93530c093f334f0cf666c7d1b4911  0014-nopie.patch
1fb9fb420335d5e87245eb781960bc876a1d60bc69af2a8febad8ddd23cc064e28227a7b9f8389b4f2bb0211259102feaa6e2a7f64457fac06d60a59fdc1c2bb  0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch
226e68c4561524ece4340107736f5f7f5a31fb725373a5ad472147f443a5fc037d0e0d93562c3e6d333ed43ceef7a2c6a2adad1ad10a464235d168a2dd4ed65e  0016-dlang-update-zlib-binding.patch
9615d8844f4ffaab6dc61ad452ec9502acfe41029f2225b4b9fa10b034659447fb92b037918d52c615cae30acbb778b8a3d2197c705c90698221ae9e7bb30a32  0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch
3008df8b4e4f582ced4976e640cb3329904bdefe9d454b13c8e61f3393fee21ec4e49cefc90e6049f85bacced500886681520b46b5063c948b7f5506c050b8cc  0018-ada-fix-shared-linking.patch
3df7c1285a370e9741f649b26e31074177826b11da5172e5571c982ff1127ba83c6baf6b0666433ab7cd937217550ed2f083460d8ef8ed62531a98e63cbcc4c9  0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch
5235fbd6bb39c98f9ef702112d5bda05dcba03e897106ef864be606568e0c51e2fb5cadc5df93d162ceb8bf38a544adf9487ddd995ed0b936e86e3fbbc10512e  0020-add-fortify-headers-paths.patch
9405ea49a6832ae7e2c81c00a9c0c7eeb03b2b4cb887ff2f6352b0f0a5de2c002208a12a6a61ec0e287b114c30090197e867be1a5ed8f462e6f74a63b87fd6f5  0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch
aa46e49551ff84654166927f62fc81a118dcec1934cf0a95bdbcfe0ed08fac21d6c4b123965d9e718936411e2935c6cd6b60dbba2853c01169fea8d0fa401464  0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch
62a743dea9f0b644876138f5d336726a32ad62ad1b49c308daf3a11c7122cef292e93fe580fc71aa1ec9c73bb234e485a3d447135f2d169b98af1900d304368e  0023-Pure-64-bit-MIPS.patch
6959cf80dcceeee5d89eff1337bdf35d7a1d42fe3861a56bebd10ccfba1e5046837b63923a2f1b23109c8494d39a18a400f08342686271d539964ad85c83d2f1  0024-use-pure-64-bit-configuration-where-appropriate.patch
1f160b42a88f1d6cdf2cf140323d5fb96233f82b5fbeb8efdb861820b25c1b0354e55202655bfb5f571e21fdb18e66a532b7278a014aab828e03b04e9345fe19  0025-always-build-libgcc_eh.a.patch
fec758a6cbee1d468b966b90e35fe83742b2ebb2cc873634115ab4db599bd84a8c00f687ff18a2f37360126a75f4b8d85d9de3127d44b9076d931479cdd65ab1  0026-ada-libgnarl-compatibility-for-musl.patch
e49720b5d78fca91bdc0dbc431b70e9e75bbd6a95ba2e856dce6764dd9759fc830bb445ce8aa8fc9aa6ace80c474e9c2a947c6b23a1178b2cb6bd8780447350a  0027-ada-musl-support-fixes.patch
199b87e0844c361fc176755cd5846ea48f4a18382609633d0f4d1fb3e11a41ad93168f9b4f44ed993dca977354c0072637779658941cebe6adebfea28b28531c  0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch
17642cb9f179007b898f62cb4d6c9b436876cf667606c8003e02a782f09d29e17a301225efb94102094cc7f2b3efb413dd5ea2581e7e421e2b814f29f1b7e776  0029-gcc-go-Don-t-include-sys-user.h.patch
08268c1ec6b6f0097ea15230f45f2a7231b8c5f9e6f90fcb102f86fe8e83c81a1755482a88415ab11a3de62e82769e4f0e3e029b812e477fcb6ddccb5f086734  0030-gcc-go-Fix-ucontext_t-on-PPC64.patch
1345b99c20a9f7335c8af5e619c769f0555e46c18ba0f084d2655bce1581d11353f278dd9c94874edaceed1bf9d11a4a720b5263197c0cc9ce288f664e26eb01  0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch
ff8fb2cd67dd4723b271c2d1b6bca80e062d2fe31fe9f71aa1b83bab1c131decff4b4ddf8da9ce188cd28eee0fa1cf04d8ffc863033c5ce0096a6dd7b748e3b5  0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch
ce677dad505e56c67c79f7836888b6c28feaa4172d41c8c7573b931e6baff56ca0e5b9e6902b576d784735c5d278bc8a23e08a83597e3f41d11be9e14cf1dc59  0033-There-are-more-than-one-st_-a-m-c-tim-fields-in-stru.patch
19743886041ed1fc8e3afebc48b5c196c032f4bd8d20a8deb99ba83ec7ffb3a5e18f1686a705a0578ce120f702493e444c599c9228f2b466abbcb8820f313d7a  0034-gcc-go-signal-34-is-special-on-musl-libc.patch
150dba551824d99a3b58ea531c939237ce3aa642d04e5a2f774fe96bb27f1aa498d2b95d74369dd893da6142f9a8e5fe8966c72f38e21fc14ff614f90e7374ce  0035-gcc-go-Prefer-_off_t-over-_off64_t.patch
2e09c90e5b9ba295949d5a9986ca4e13774981fb918d35098ab560139d34703b15924767bb54ffadf38b061b2b395c50f53c367c96959e5e9d1e7c65224171f4  0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch
01b3010bdfcec65d68f851ed425fa22c744e6744aaf4b0fe7699c7a678e970e11bc7b907188fbacababacadf520b515883944480e91262259e0a03a0966d7540  0037-gcc-go-link-to-libucontext.patch
f7eefa7ae1f31fc7bc1721578d4c1642f2ef5feda37dec03264dde53717474437722ee646ab9a837d888eedbee4ea3c407f20cc4c7cb36d34a81e56b3ea02c79  0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch
83deca7a68c6e1ce934f79b5d1e1a4b8b8a25c7bc24c3ef934307c232e168d9b17048a00a040fe81ac0cf6d4a23beefb292369c35d9896dab440dda228c90b0a  0039-Use-generic-errstr.go-implementation-on-musl.patch
4074c62c2ee0ed555f01bf0cc69e32ef275bc3ac74de1d428ba1a2ac59fae973fe6f9aab8b3796df4bda7ab7cf220e5e1cbfdf103f41e4cbea175067a947d08f  0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch
1fe1b1e9ec288f65cd0d80a74b0a060b29c40e501f666b01e2825b61949be4568aeaf7cf473142889a7fd5e011b096837a651582d64fce67500fcb2ba39e16ce  0041-configure-fix-detection-of-atomic-builtins-in-libato.patch
0a66c5a567e15dafac0bcad5c9dd5e98c44c74cbe539340ad28cbf6d26b994bab46b355f3a3a57b830f802145cfd826ad8d87359ebc5d6a20ef41e968904c7dc  0042-stddef.h-add-support-for-musl-typedef-macro-guards.patch
"
