# Maintainer: Adrian Pop <adrian.pop@liu.se>

_realname=uasm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.53.r668.8f8feb7
pkgrel=1
_commit='8f8feb76a3fec91c5038bb09dfc304df804f5e16'
pkgdesc="UASM is a free MASM-compatible assembler based on JWasm"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('Watcom-1.0')
url="https://github.com/Terraspace/UASM"
depends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-gcc")
source=("UASM"::"git+https://github.com/Terraspace/UASM.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/UASM"
  local _ver=$(sed -ne '/#define\s*_UASM_VERSION_STR_\s*"/ { s/^.*"\(.*\)"\s*$/\1/; p; q }' H/globals.h)
  printf "%s.r%s.%s" ${_ver} "$(git rev-list --count $_commit)" "$(git rev-parse --short $_commit)"
}

prepare() {
  cd ${srcdir}/UASM/
  rm -rf MinGWR
  sed -i -e 's/^extra_c_flags = .*$/& -fcommon/' GccWin.mak
  sed -i 's/s - cv.ps/(uint_8 *)s - cv.ps/;s/s - start/(uint_8*)s - start/' dbgcv.c
}

build() {
  cd ${srcdir}/UASM/
  make -f GccWin.mak
}

package() {
  install -Dm744 ${srcdir}/UASM/MinGWR/hjwasm.exe "${pkgdir}${MINGW_PREFIX}/bin/jwasm.exe"
  install -Dm744 ${srcdir}/UASM/MinGWR/hjwasm.exe "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 ${srcdir}/UASM/License.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
