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

_pkgname=freetype2
pkgname=static-compat-$_pkgname-bootstrap
pkgver=2.12.0
pkgrel=1
pkgdesc="Font rasterization library"
url="https://www.freetype.org/"
arch=(x86_64)
license=(GPL)
# adding harfbuzz for improved OpenType features auto-hinting
# introduces a cycle dep to harfbuzz depending on freetype wanted by upstream
depends=(static-compat-zlib static-compat-bzip2 static-compat-libpng static-compat-brotli)
makedepends=(static-compat-libx11 static-compat-meson)
conflicts=(static-compat-$_pkgname)
provides=(static-compat-$_pkgname)
options=(staticlibs)
source=(https://download-mirror.savannah.gnu.org/releases/freetype/freetype-$pkgver.tar.xz
        0001-Enable-table-validation-modules.patch
        0002-Enable-subpixel-rendering.patch
        0003-Enable-infinality-subpixel-hinting.patch
        0004-Enable-long-PCF-family-names.patch)
sha256sums=('ef5c336aacc1a079ff9262d6308d6c2a066dd4d2a905301c4adda9b354399033'
            '12c869eeba212c74d07d3d7815848b047ecb5282d5463dffb3bb6d219315d4da'
            '2497dcb3650271db9bb7ad4f3379b5b3c6a19f5ca5388dd9ba7d42b5c15c8c4f'
            'caa0bc7d3dfa3b4c6b9beecda6141405dafe540f99a655dc83d1704fa232ac20'
            '8bf978cd1abd73f54c53f7d214c368b1fd8921cd9800d2cc84427c662ffbbdcb')
validpgpkeys=(E30674707856409FF1948010BE6C3AAC63AD8E3F) # Werner Lemberg <wl@gnu.org>

prepare() {
  cd freetype-$pkgver
  patch -Np1 -i ../0001-Enable-table-validation-modules.patch
  patch -Np1 -i ../0002-Enable-subpixel-rendering.patch
  patch -Np1 -i ../0003-Enable-infinality-subpixel-hinting.patch
  patch -Np1 -i ../0004-Enable-long-PCF-family-names.patch

  # meson sucks
  sed -i 's|static: false|static: true|g' meson.build

  # meson sucks a lot
  sed -i 's|ftoption_command.*FT_CONFIG_OPTION_USE_HARFBUZZ.*||g' meson.build
  sed -i 's|ft2_deps.*harfbuzz_dep.*||g' meson.build
}

build() {
  source static-compat-environment
  cd freetype-$pkgver
  static-compat-meson build -D zlib=system -D bzip2=enabled -D png=enabled -D brotli=enabled -Dharfbuzz=disabled
  meson compile -C build
}

check() {
  source static-compat-environment
  cd freetype-$pkgver
  meson test -C build --print-errorlogs
}

package() {
  source static-compat-environment
  cd freetype-$pkgver
  meson install -C build --destdir="$pkgdir"
  rm -rf "${pkgdir}"/usr/static/share/
}

# vim:set ts=2 sw=2 et:
