# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>
# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=coreutils
pkgbase=mingw-w64-uutils-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-uutils-${_realname}")
pkgver=0.4.0
pkgrel=1
pkgdesc="Cross-platform Rust rewrite of the GNU coreutils (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/uutils/coreutils'
msys2_references=(
  'archlinux: uutils-coreutils'
  'purl: pkg:cargo/coreutils'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-oniguruma" "${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://github.com/uutils/coreutils/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('5f0c3f97b807e72edccc844c6a685ec9862199f16a665df07de5b1d20ec21233')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

# spliting build() sometimes cause building twice at make build
package() {
  cd "${_realname}-${pkgver}"

  export RUSTONIG_DYNAMIC_LIBONIG=1
  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  make -O install \
    DESTDIR="${pkgdir}" \
    PREFIX="${MINGW_PREFIX}" \
    PROG_PREFIX=uu- \
    PROFILE=release \
    MULTICALL=y \
    LN="ln -vf"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/uutils-${_realname}/LICENSE"
}
