# Maintainer: Jeremy Drake <github@jdrake.com>

pkgname=cygutils
# it sucks, but upstream adds features in packaging patches, so treat
# their -4 as a .4 so we can have our own pkgrel
pkgver=1.4.17.4
_realpkgver=${pkgver%.*}
pkgrel=1
pkgdesc="${pkgname} is a collection of simple utilities"
arch=('i686' 'x86_64')
url="https://cygwin.org/"
license=('spdx:GPL-3.0-or-later')
depends=('gcc-libs' 'popt' 'libiconv' 'libintl')
makedepends=('gcc'
             'gettext-devel'
             'git'
             'libiconv-devel'
             'autotools'
             'popt-devel')
conflicts=('winln')
replaces=('winln')
provides=('winln')
_commit='a804501b8c33c55a45a87b6e505b4e5db41e4f2f'
source=("${pkgname}-${_realpkgver}::git+https://sourceware.org/git/cygwin-apps/${pkgname}.git#commit=${_commit}"
        "cygutils-1.4.17-4.src.patch"
        "lssparse-support-check.patch")
sha256sums=('35ad70ebebd40cafc1bf7a87d308ad658e48f65462bf641241d75f95edd50abd'
            '07d8184f5ed63c085450f9e27ca4a7d2e86d9ef7a6a23a2da20fe120f163668b'
            '6170756c292a606fcf1876a2bd57ecb72262e4c1062132874be623d8de9233af')

prepare(){
  cd ${pkgname}-${_realpkgver}

  patch -Nbp1 -i "${srcdir}/cygutils-1.4.17-4.src.patch"
  patch -Nbp1 -i "${srcdir}/lssparse-support-check.patch"

  autoreconf -fi
}

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

  CXXFLAGS+=" -std=gnu++14"

  export MSYSTEM=CYGWIN
  ../${pkgname}-${_realpkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}

  make
}

package() {
  cd "${srcdir}/build-${CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${pkgname}-${_realpkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
