# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=unrar
pkgname=('unrar' 'libunrar' 'libunrar-devel')
pkgver=7.1.10
pkgrel=1
arch=('i686' 'x86_64')
url="https://www.rarlab.com/rar_add.htm"
msys2_references=(
  "anitya: 13306"
  "archlinux: unrar"
  "cpe: cpe:/a:rarlab:unrar"
  "gentoo: app-arch/unrar"
)
license=('custom')
depends=('gcc-libs')
makedepends=('make' 'gcc')
source=("https://www.rarlab.com/rar/unrarsrc-${pkgver}.tar.gz"
        'build-dll.patch')
sha256sums=('72a9ccca146174f41876e8b21ab27e973f039c6d10b13aabcb320e7055b9bb98'
            '8c618b85478f5b9bb764c523670d0d60a6b14a382919beadf357120d045313b4')

prepare() {
  cd ${pkgname}
  patch -p1 -i ${srcdir}/build-dll.patch
}

build() {
  cd ${pkgname}
  cp -a ${srcdir}/unrar ${srcdir}/libunrar
  make -C "${srcdir}"/libunrar lib CXXFLAGS="${CXXFLAGS}"
  make CXXFLAGS="${CXXFLAGS}" STRIP="true"
}

package_unrar() {
  pkgdesc="The RAR uncompression program"
  depends=('gcc-libs')
  cd "${srcdir}/${pkgbase}"
  install -Dm755 unrar.exe "${pkgdir}/usr/bin/unrar.exe"
  # install license
  install -Dm644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libunrar() {
  pkgdesc="Library file for applications that use libunrar"
  depends=('gcc-libs')
  cd "${srcdir}/libunrar"
  install -Dm755 msys-unrar.dll "${pkgdir}/usr/bin/msys-unrar.dll"
  # install license
  install -Dm644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libunrar-devel() {
  pkgdesc="Import library and header file for applications that use libunrar"
  depends=('libunrar')
  cd "${srcdir}/libunrar"
  install -Dm644 libunrar.dll.a "${pkgdir}/usr/lib/libunrar.dll.a"
  install -Dm644 libunrar.a "${pkgdir}/usr/lib/libunrar.a"
  install -Dm644 dll.hpp "${pkgdir}/usr/include/unrar/dll.hpp"
}
