# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Lukas Fleischer <archlinux at cryptocrack dot de>
# Contributor (Arch Linux): Allan McRae <allan@archlinux.org>
# Contributor (Arch Linux): bekks <eduard.warkentin@gmail.com>
# Contributor (Arch Linux): Daniel J Griffiths <ghost1227@archlinux.us>

pkgname=upx
pkgver=5.0.2
pkgrel=1
pkgdesc='Ultimate executable compressor.'
arch=('i686' 'x86_64')
url='https://upx.github.io/'
msys2_repository_url="https://github.com/upx/upx"
msys2_references=(
  "anitya: 13737"
  "cpe: cpe:/a:upx_project:upx"
)
license=('GPL')
depends=('ucl' 'zlib')
makedepends=('ucl-devel' 'zlib-devel' 'gcc' 'cmake' 'ninja')
source=("https://github.com/${pkgname}/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}-src.tar.xz")
sha256sums=('209b219bbcfa58c249ffe6eba3c244e0910fa8be792b5521e4daf938167f05cc')

build() {
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd build-${CARCH}

  local -a extra_config

  if check_option "debug" "y"; then
    extra_config+=(-DCMAKE_BUILD_TYPE=Debug)
  else
    extra_config+=(-DCMAKE_BUILD_TYPE=Release)
  fi

  CPPFLAGS+=" -DUCL_NO_ASM"
  cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    ${extra_config[@]} \
    ../"${pkgname}-${pkgver}-src"

  cmake --build .
}

package() {
  cd build-${CARCH}
  DESTDIR="${pkgdir}" cmake --install .
  install -Dm0644 "${srcdir}/${pkgname}-${pkgver}-src"/LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
