# Description: Outline and bitmap font editor
# URL: https://fontforge.github.io/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: giflib gtk3 libspiro libuninameslist libwebp potrace woff2

name=fontforge
version=20230101
release=2
source=(https://github.com/$name/$name/releases/download/$version/$name-$version.tar.xz
  fontforge-20230101-workaround-broken-translations.patch)

build() {
  if [ -e '/usr/lib/ccache' ]; then
    PKGMK_FONTFORGE+=' -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER_LAUNCHER=ccache'
    PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')
  fi

  patch -Np1 -d $name-$version -i $SRC/fontforge-20230101-workaround-broken-translations.patch

  cmake -S $name-$version -B build -G Ninja $PKGMK_FONTFORGE \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
    -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
    -D ENABLE_MAINTAINER_TOOLS=TRUE \
    -D ENABLE_FONTFORGE_EXTRAS=TRUE \
    -D UNIX=TRUE \
    -D ENABLE_DOCS=FALSE \
    -Wno-dev

  sed -i 's!-R/usr/lib!!g' build/build.ninja

  cmake --build build
  DESTDIR=$PKG cmake --install build

  rm -r $PKG/usr/share/locale
}
