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

pkgbase=unrar
pkgname=('unrar' 'libunrar')
pkgver=5.2.2
pkgrel=1
arch=('i686' 'x86_64')
groups=('base-devel')
url="http://www.rarlab.com/rar_add.htm"
license=('custom')
options=('staticlibs' '!makeflags')
depends=('gcc-libs')
source=("http://www.rarlab.com/rar/unrarsrc-${pkgver}.tar.gz"
        'build-dll.patch')
md5sums=('69ef5af8442cbb7dfdebe298bfb9c61a'
         '3f1c51c2ae7e0bd1ea02aaf904d61bd0')

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

  #autoreconf -fi
}

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 and header file for applications that use libunrar"
  depends=('gcc-libs')
  cd "${srcdir}/libunrar"
  install -Dm755 libunrar.dll.a "${pkgdir}/usr/lib/libunrar.dll.a"
  install -Dm755 libunrar.dll "${pkgdir}/usr/bin/libunrar.dll.a"
  install -Dm644 dll.hpp "${pkgdir}/usr/include/unrar/dll.hpp"
  # install license
  install -Dm644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

