# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

_pkgname=harfbuzz
pkgname=$_pkgname-static
pkgver=2.7.4
pkgrel=1
pkgdesc="OpenType text shaping engine"
url="https://www.freedesktop.org/wiki/Software/HarfBuzz"
arch=(x86_64)
license=(MIT)
depends=(glib2-static freetype2-static graphite-static)
makedepends=(gobject-introspection ragel git python meson)
checkdepends=(python-fonttools python-setuptools)
options=(!emptydirs !docs staticlibs)
_commit=7236c7e29cef1c2d76c7a284c5081ff4d3aa1127  # tags/2.7.4^0
source=("git+https://github.com/harfbuzz/harfbuzz#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd harfbuzz
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd harfbuzz
}

build() {
  export PKG_CONFIG_PATH=/usr/static/lib/pkgconfig:/usr/lib/pkgconfig
  export PATH=$PWD:$PATH
  printf '#!/usr/bin/bash\nexec /usr/bin/pkg-config --static "$@"\n' > pkg-config
  chmod +x pkg-config
  # disable tools (and related tests)
  echo '' > harfbuzz/util/meson.build
  echo '' > harfbuzz/test/shaping/meson.build
  echo '' > harfbuzz/test/subset/meson.build
  arch-meson harfbuzz build \
    -Dgraphite=enabled \
    -Dcairo=disabled \
    -Dintrospection=disabled \
    -Dfontconfig=disabled \
    -Dicu=disabled \
    -Ddocs=disabled \
    --prefix /usr/static \
    --default-library static
  meson compile -C build
}

check() {
  mkdir -p tmp
  TMPDIR="$PWD/tmp" meson test -C build --print-errorlogs
  rm -r tmp
}

package() {
  DESTDIR="$pkgdir" meson install -C build

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 harfbuzz/COPYING
}
