# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Eric Bélanger <eric@archlinux.org>

pkgname=yasm
pkgver=1.3.0
pkgrel=9
pkgdesc="A rewrite of NASM to allow for multiple syntax supported (NASM, TASM, GAS, etc.)"
arch=('x86_64' 'aarch64')
url='https://github.com/yasm/yasm'
license=('BSD-2-Clause OR BSD-3-Clause' 'GPL-2.0-only' 'LGPL-2.1-only' 'Artistic-1.0-Perl')
depends=('glibc')
makedepends=('git' 'python' 'xmlto')
checkdepends=('systemd')
options=('staticlibs')
source=("$pkgname::git+$url#tag=v$pkgver")
sha512sums=('97161e81b91903ddad6bfb26fd4fcaee263b4e71d85b7299aa72572b2d780fe09e69b8a84becedc1b049179080a691055670fa0edebd0a792dd986a0d1d8d703')
b2sums=('f7afb2be3c15d6695142baf2836dfe974e91dac9b00395bfab8504014243f631ced6dca2a058071592cd5beb23588cc1ecbeccd3a4b1da6403b115d36d82b7b1')

prepare() {
  cd "$pkgname"
  # Backport support for .note.gnu.property sections
  # https://github.com/yasm/yasm/pull/148
  git cherry-pick --no-commit 0799f381d513e18f404654047fa1b412084968c8

  # FTBFS due to autotools 2.70+
  # https://github.com/yasm/yasm/pull/178
  git cherry-pick --no-commit 3e74376b5653102a3957f59005969fcdbbe5a89d

  # Ensure package is reproducible
  # https://github.com/yasm/yasm/pull/198
  git cherry-pick --no-commit 61e374f24718975e8175f048e70afaaf0c4771a9

  # FTBFS due to GCC15+
  # https://github.com/yasm/yasm/pull/287
  git cherry-pick --no-commit 64ef740eb262f329e55eebadf2ce276b146d44e9

  # generate version file
  echo "$pkgver" > version

  autoreconf -vfi
}

build() {
  cd "$pkgname"
  CFLAGS+=' -ffat-lto-objects' \
  ./configure --prefix=/usr
  make
}

check() {
  cd "$pkgname"
  # FTBFS due to concurrency issues
  # https://github.com/yasm/yasm/issues/157
  make check -j1
}

package() {
  cd "$pkgname"
  make DESTDIR="${pkgdir}" install

  # licenses
  install -vDm644 \
    -t "$pkgdir/usr/share/licenses/$pkgname" \
    {Artistic,BSD}.txt COPYING GNU_*
}
