pkgname=libzip
pkgver=1.11.4
pkgdesc="C library for reading, creating, and modifying zip archives"
homepage="https://libzip.org"
license=('BSD')
arch=('x86_64')
depends=('zlib' 'bzip2' 'zstd' 'openssl')
makedepends=('cmake')
_patches=("libzip-1.11.4-mbedtls-3.patch")
_patch_sums=("4fda522afd4a6b37ed08dbfc47baedb3")
sources=("${pkgname}-${pkgver}.tar.xz"
  ${_patches[@]}
)
urls=("https://www.nih.at/libzip/${sources[0]}"
  ${_patches[@]}
)
md5sums=("5b53072471ef2ef03505fc6ac06f5835"
  ${_patch_sums[@]}
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  for _patch in ${_patches[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done
}

src_build() {
  local cmake_args=(
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_LIBDIR=lib
    -Wno-dev
    -DBUILD_DOC=ON
    -DBUILD_OSSFUZZ=OFF
    -DBUILD_EXAMPLES=OFF # nothing is installed
    -DENABLE_COMMONCRYPTO=OFF # not in tree
    -DENABLE_BZIP2=ON
    -DENABLE_LZMA=OFF
    -DENABLE_ZSTD=ON
    -DBUILD_REGRESS=OFF
    -DBUILD_TOOLS=OFF
    -DENABLE_GNUTLS=OFF
    -DENABLE_MBEDTLS=OFF
    -DENABLE_OPENSSL=ON
  )
  cmake -B build "${cmake_args[@]}"
  cmake --build build
}

src_install() {
  DESTDIR="${pkgdir}" cmake --install build
  install -vDm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}

# vim:ft=sh syn=sh et sw=2:
