# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=binutils
_target=avr

pkgbase=mingw-w64-${_target}-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}
pkgver=2.45
pkgrel=1
pkgdesc='GNU Binutils for the AVR target (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:GPL-3.0-or-later AND GPL-2.0-or-later AND LGPL-3.0-or-later AND LGPL-2.0-or-later')
url='https://www.gnu.org/software/binutils/binutils.html'
msys2_references=(
  "cpe: cpe:/a:gnu:binutils"
)
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
depends=("${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz{,.sig}
        "01-avr-size.patch")
sha256sums=('c50c0e7f9cb188980e2cc97e4537626b1672441815587f1eab69d2a1bfbef5d2'
            'SKIP'
            '50b3b7adb33c75697d0d229922ed1963e2589468d021ec797827fbfd70cf931e')
validpgpkeys=('3A24BC1E8FB409FA9F14371813FCEF89DD9E3C4F')

prepare() {
    cd "${srcdir}"/${_realname}-${pkgver}

    # https://github.com/archlinux/svntogit-community/blob/packages/avr-binutils/trunk/avr-size.patch
    patch -p1 -i ../01-avr-size.patch
}

build() {
    mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

    ../${_realname}-${pkgver}/configure \
        --build=${MINGW_CHOST} \
        --prefix=${MINGW_PREFIX} \
        --target=${_target} \
        --libdir=${MINGW_PREFIX}/lib/${_target} \
        --disable-nls \
        --disable-debug \
        --disable-dependency-tracking \
        --disable-werror
    make
}

package() {
    cd "${srcdir}/build-${MSYSTEM}"

    make DESTDIR="$pkgdir" install

    cd "${pkgdir}"${MINGW_PREFIX}

    for info in as bfd binutils ctf-spec gprof ld ldint sframe-spec; do
        mv share/info/${info}.info share/info/${_target}-${info}.info
    done
}
