# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname="msys2-w32api-headers"
pkgver=12.0.0.r0.g819a6ec2e
pkgrel=2
pkgdesc="Win32 API headers for MSYS2 32bit toolchain"
arch=('i686' 'x86_64')
url="https://mingw-w64.sourceforge.io/"
license=('custom')
depends=()
makedepends=('git' 'autotools')
if [[ "${CARCH}" == 'i686' ]]; then
  makedepends+=('mingw-w64-cross-mingw32-gcc')
else
  makedepends+=('mingw-w64-cross-mingw64-gcc')
fi
options=('staticlibs' '!buildflags')
_commit='819a6ec2ea87c19814b287e21d65e0dc7f05abba'
source=("mingw-w64"::"git+https://git.code.sf.net/p/mingw-w64/mingw-w64#commit=$_commit"
        "0001-Work-around-Warray-bounds-warning-for-__readfsdword-.patch")
sha256sums=('41878f44fe3b6c347fc99ab8a90d384f61bd3ae25cfb2a62a7e24d4f0d14f720'
            '189dd0f614caae1428e1d3a06bc3ac436d26afd9cbdbd1a7ce58b1ee6478ff3f')
msys2_references=(
  'cygwin: w32api-runtime'
  'cpe: cpe:/a:mingw-w64:mingw-w64'
)

pkgver() {
  cd "${srcdir}/mingw-w64"
  git describe --long ${_commit} | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'
}

prepare() {
  cd ${srcdir}/mingw-w64

  patch -Np1 -i "${srcdir}"/0001-Work-around-Warray-bounds-warning-for-__readfsdword-.patch
}

build() {
  cd ${srcdir}/mingw-w64/mingw-w64-headers

  unset CC CXX

  ./configure \
     --build=${CHOST} \
     --host=${CARCH}-w64-mingw32 \
     --prefix=/usr \
     --enable-sdk=all \
     --enable-w32api \
     --with-default-win32-winnt=0x601

  make
}

package() {
  cd ${srcdir}/mingw-w64/mingw-w64-headers

  make DESTDIR=${pkgdir} install
}
