# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=openjpeg2
pkgver=%version%
pkgrel=%release%
pkgdesc="An open source JPEG 2000 codec, version ${pkgver}"
arch=(x86_64)
license=('BSD-2-Clause' 'MIT')
url="https://github.com/uclouvain/openjpeg"
makedepends=('cmake' 'doxygen' 'graphviz')
depends=('libpng' 'libtiff' 'lcms2' 'glibc')
source=("$pkgname-$pkgver.tar.gz::https://github.com/uclouvain/openjpeg/archive/v$pkgver.tar.gz")
sha256sums=('90e3896fed910c376aaf79cdd98bdfdaf98c6472efd8e1debf0a854938cbda6a')

prepare() {
  # Remove all third party libraries just to be sure
  find openjpeg-"${pkgver}"/thirdparty/ -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
}

build() {
  cmake -B build -S openjpeg-"${pkgver}" \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=OFF \
    -DBUILD_DOC=on

  VERBOSE=1 cmake --build build
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm 644 "${srcdir}"/openjpeg-"${pkgver}"/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/  
}
