# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: dorphell <dorphell@gmx.net>

pkgbase=unrar
pkgname=(unrar libunrar)
pkgver=6.2.6
pkgrel=1
epoch=1
arch=(x86_64)
url='https://www.rarlab.com/rar_add.htm'
license=(custom)
source=(https://www.rarlab.com/rar/unrarsrc-$pkgver.tar.gz)
sha256sums=('0c2d4cbc8b34d0e3bec7b474e0f52bbcc6c4320ec089b4141223ee355f63c318')

prepare() {
  sed -e '/CXXFLAGS=/d' -e '/LDFLAGS=/d' -i unrar/makefile # Use system build flags
}

build() {
  cp -a unrar libunrar
  export LDFLAGS+=' -pthread'
  make -C libunrar lib
  make -C unrar -j1
}

package_unrar() {
  pkgdesc='The RAR uncompression program'
  depends=(gcc-libs)
  cd unrar
  install -Dm755 unrar -t "$pkgdir"/usr/bin/
  # 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 libunrar
  install -Dm755 libunrar.so -t "$pkgdir"/usr/lib/
  install -Dm644 dll.hpp -t "$pkgdir"/usr/include/unrar/
  # install license
  install -Dm644 license.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
