# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

pkgname=which
pkgver=2.21
pkgrel=2
pkgdesc="A utility to show the full path of commands"
arch=('i686' 'x86_64')
url="https://savannah.gnu.org/projects/which/"
license=('GPL3')
source=("https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz"
        am-1.14.all.patch
        msys2-allow-windows-mixed-absolute-paths.patch)
depends=('sh')
install=which.install
#options=('debug' '!strip')
sha256sums=('f4a245b94124b377d8b49646bf421f9155d36aa7614b6ebf83705d3ffc76eaad'
            'c4957d7730d84cd656dfde2086e81c75447d27d78f03f559a5d465774caf1ce3'
            '3dcec525a2760c2caebc4d19f217916801c3911988fb601755dbbee14d2a07e8')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/am-1.14.all.patch
  patch -p1 -i ${srcdir}/msys2-allow-windows-mixed-absolute-paths.patch
}

build() {
  [[ -d ${srcdir}/build-${CHOST} ]] && rm -rf ${srcdir}/build-${CHOST}
  mkdir ${srcdir}/build-${CHOST} && cd ${srcdir}/build-${CHOST}

  ../${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}

  make
}

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