# Description: A fast, lightweight and minimalistic Wayland terminal emulator
# URL: https://codeberg.org/dnkl/foot
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: fcft foot-terminfo libxkbcommon
# Optional: utf8proc

name=foot
version=1.14.0
release=1
source=(https://codeberg.org/dnkl/foot/archive/$version.tar.gz)

build() {
  prt-get isinst utf8proc && PKGMK_FOOT+=' -D grapheme-clustering=enabled'

  # doing the lto dance
  export CFLAGS='-march=x86-64 -O3 -Wno-missing-profile -Wno-error'
  meson setup $name build $PKGMK_FOOT \
    --prefix=/usr \
    --buildtype=release \
    -D b_lto=true \
    -D b_pgo=generate \
    --wrap-mode=nodownload \
    -D terminfo=disabled

  find -name "*.gcda" -delete
  meson compile -C build
  local script_options="--scroll --scroll-region --colors-regular --colors-bright --colors-256 --colors-rgb --attr-bold --attr-italic --attr-underline --sixel"

  tmp_file=$(mktemp)
  if [[ -v WAYLAND_DISPLAY ]]; then
    local tmp_file=$(mktemp)
    export LC_ALL=en_US.UTF-8
    build/footclient --version
    build/foot \
      --config /dev/null \
      --term=xterm \
      sh -c "sleep 2 && $SRC/$name/scripts/generate-alt-random-writes.py ${script_options} ${tmp_file} && cat ${tmp_file}" | true
  else
    build/footclient --version
    build/foot --version
    $SRC/$name/scripts/generate-alt-random-writes.py \
      --rows=67 \
      --cols=135 \
      $script_options \
      $tmp_file
    build/pgo $tmp_file $tmp_file $tmp_file
  fi
  rm $tmp_file
  meson configure -D b_pgo=use build
  meson compile -C build
  DESTDIR=$PKG meson install -C build

  rm -r $PKG/usr/share/{doc,fish}
  prt-get isinst bash-completion || rm -r $PKG/usr/share/bash-completion
  prt-get isinst zsh || rm -r $PKG/usr/share/zsh
}
