# Maintainer: Paul Moore <p.f.moore@gmail.com>

_realname=file
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.46
pkgrel=1
pkgdesc='Determine the type of a file from its contents (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.darwinsys.com/file/'
msys2_repository_url="https://github.com/file/file"
msys2_references=(
  "cpe: cpe:/a:file_project:file"
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-libsystre")
         # file couldn't use those compression libraries
         # because It requires fork function.
         # see: https://github.com/file/file/blob/FILE5_46/src/compress.c#L229
         #"${MINGW_PACKAGE_PREFIX}-bzip2"
         #"${MINGW_PACKAGE_PREFIX}-xz"
         #"${MINGW_PACKAGE_PREFIX}-zlib"
         #"${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://astron.com/pub/file/${_realname}-${pkgver}.tar.gz")
sha256sums=('c9cc77c7c560c543135edc555af609d5619dbef011997e988ce40a3d75d86088')

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

  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

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

  CFLAGS+=" -Wno-incompatible-pointer-types" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static \
    --disable-libseccomp

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make -C tests check
}

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

  # Licenses
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
