pkgname=freetype
pkgver=2.14.1
pkgdesc="Font rasterization library"
homepage="https://www.freetype.org/"
arch=(x86_64)
license=('FTL OR GPL-2.0-or-later')
depends=(
  bzip2
  glibc
  libpng
  zlib
)
makedepends=(
  gcc
  meson
)
sources=("${pkgname}-${pkgver}.tar.xz")
urls=("https://downloads.sourceforge.net/freetype/${sources[0]}")
md5sums=("78c7d7450fb7d0999ccd029f84094340")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1

  sed -ri "s:.*(AUX_MODULES.*valid):\1:" modules.cfg

  enable_option() {
    sed -i -e "/#define $1/ { s:/\* ::; s: \*/:: }" \
        include/${pkgname}/config/ftoption.h \
        || leaf_error "unable to enable option $1"
  }
  disable_option() {
    sed -i -e "/#define $1/ { s:^:/* :; s:$: */: }" \
        include/${pkgname}/config/ftoption.h \
        || leaf_error "unable to disable option $1"
  }

  enable_option PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
  enable_option FT_CONFIG_OPTION_SUBPIXEL_RENDERING
}

src_build() {
  local meson_args=(
    --prefix=/usr
    --buildtype=release
    -D harfbuzz=dynamic
    -D brotli=disabled
    -D bzip2=enabled
    -D png=enabled
    -D zlib=system
    -D default_library=shared
  )
  meson setup build "${meson_args[@]}"
  meson compile -C build
}

src_install() {
  meson install -C build --destdir="$pkgdir"
}

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