# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=dmake
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.12.2.2
pkgrel=2
pkgdesc="Dmake is a make utility similar to GNU make or the Workshop dmake (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
license=('GPL')
url="https://github.com/mohawk2/${_realname}"
pkgver2="$(echo ${_realname} | tr '[:lower:]' '[:upper:]')_$(echo ${pkgver} | sed 's/\./_/g')"
source=("${url}/archive/${pkgver2}.tar.gz"
        '001-detect-mingw.patch'
        '002-disable-shell-environment-variable.patch'
        '003-fix-config-location.patch'
        '004-disable-mkstemp-detection.patch')
sha256sums=('3d412e0afea9d27416c359acb05611ab17f608cafe14ebfdc1410bd4e8e9575c'
            'be97bb773101f2c097d1d3e3bad5dfc05989d1fc2ddfb4f353aba2beee22cc31'
            'b6aacca13803eb0d5276388039889396ea0a9a66b12c5b83aad689e56f774174'
            '21a6b60086e068061d9af1a499bd9134b6eacabbb2f3ad9b071b4657c983428b'
            'b0073f0937e8078a738a787fb512efb437a001c16c31d7f261d1fdee5368b339')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver2}
  patch -p1 -i "${srcdir}"/001-detect-mingw.patch
  patch -p1 -i "${srcdir}"/002-disable-shell-environment-variable.patch
  patch -p1 -i "${srcdir}"/003-fix-config-location.patch
  patch -p1 -i "${srcdir}"/004-disable-mkstemp-detection.patch

  autoreconf -vfi
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}
  ../${_realname}-${pkgver2}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --datarootdir=${MINGW_PREFIX}/etc/dmake \
    --build=${MINGW_CHOST}

  make
}

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