# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=7zip
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=23.01
pkgrel=1
pkgdesc="A file archiver with a high compression ratio (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://7-zip.org"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("$url/a/7z${pkgver//./}-src.tar.xz"
        "clang-arm-target-fixes.patch")
sha256sums=('356071007360e5a1824d9904993e8b2480b51b570e8c9faf7c0f58ebe4bf9f74'
            'def6c805a6e0682c60a68d636d49cd996fd991dd32911bcc0262bc840691ef43')

prepare () {
  case ${MSYSTEM} in
    CLANG*)
      sed -i 's/-Werror/ -Wno-missing-exception-spec -Wno-unused-but-set-variable -Wno-unknown-attributes/' */*.mak */*/*.mak
      # This patch can be dropped once we're using Clang 16 or later
      patch -p0 -i "${srcdir}/clang-arm-target-fixes.patch"
      ;;
  esac
}

build() {
  cd "${srcdir}"/

  make -C CPP/7zip/Bundles/Format7zF -f makefile.gcc
  make -C CPP/7zip/UI/Console -f makefile.gcc
  make -C CPP/7zip/Bundles/SFXCon -f makefile.gcc
}

package() {
  cd "${srcdir}"

  install -D -m755 $(find CPP/7zip/Bundles/ -name \*.dll) -t "${pkgdir}"${MINGW_PREFIX}/bin/
  install -D -m755 CPP/7zip/UI/Console/_o/7z.exe "${pkgdir}"${MINGW_PREFIX}/bin/7z.exe
  install -D -m755 CPP/7zip/Bundles/SFXCon/_o/7zCon.exe "${pkgdir}"${MINGW_PREFIX}/lib/7zip/7zCon.sfx

  install -d "${pkgdir}"${MINGW_PREFIX}/share/doc/7zip
  install -D -m644 DOC/* "${pkgdir}"${MINGW_PREFIX}/share/doc/7zip
}
