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

pkgname="msys2-w32api-headers"
pkgver=11.0.1.r0.gc3e587c06
pkgrel=3
pkgdesc="Win32 API headers for MSYS2 32bit toolchain"
arch=('i686' 'x86_64')
url="https://mingw-w64.sourceforge.io/"
license=('custom')
depends=()
makedepends=('git' 'mingw-w64-cross-gcc' 'autotools')
options=('staticlibs' '!buildflags')
_commit='c3e587c067a00a561899d49d3e63a659e38802ec'
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=('SKIP'
            '189dd0f614caae1428e1d3a06bc3ac436d26afd9cbdbd1a7ce58b1ee6478ff3f')
msys2_references=(
  'cygwin: w32api-runtime'
)

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
}
