# Description: Next Generation Input Bus for Linux
# URL: https://github.com/ibus/ibus/wiki
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: gnome-common gtk-doc iso-codes libnotify libxkbcommon python3-gobject unicode-cldr unicode-emoji
# Optional: dconf desktop-file-utils gtk4 libappindicator-gtk3  unicode-character-database vala wayland-protocols xorg-setxkbmap
#  xorg-libxcomposite xorg-libxcursor xorg-libxinerama

name=ibus
version=1.5.28
release=1
source=(https://github.com/ibus/ibus/releases/download/$version/$name-$version.tar.gz
  https://raw.githubusercontent.com/ibus/ibus/dd4cc5b028c35f9bb8fa9d3bdc8f26bcdfc43d40/engine/denylist.txt)

build() {
  cd $name-$version

  sed -i 's|$(libibus) $(libibus_emoji_dialog)|$(libibus_emoji_dialog) $(libibus)|' ui/gtk3/Makefile.am
  sed -i "/UCD_DIR=/s/\$with_emoji_annotation_dir/\$with_ucd_dir/" configure.ac
  grep -r -l '#!/usr/bin/python' . | xargs sed -i '1s|python|python3|'

  prt-get isinst dconf && PKGMK_IBUS+=' --enable-dconf' || PKGMK_IBUS+=' --disable-dconf'
  prt-get isinst gtk3 && PKGMK_IBUS+=' --enable-gtk3' || PKGMK_IBUS+=' --disable-gtk3'
  prt-get isinst gtk4 && PKGMK_IBUS+=' --enable-gtk4' || PKGMK_IBUS+=' --disable-gtk4'
  prt-get isinst libappindicator-gtk3 && PKGMK_IBUS+=' --enable-appindicator' || PKGMK_IBUS+=' --disable-appindicator'
  prt-get isinst unicode-emoji && PKGMK_IBUS+=' --enable-emoji-dict' || PKGMK_IBUS+=' --disable-emoji-dict'
  prt-get isinst unicode-character-database && PKGMK_IBUS+=' --enable-unicode-dict' || PKGMK_IBUS+=' --disable-unicode-dict'
  prt-get isinst vala && PKGMK_IBUS+=' --enable-dconf' || PKGMK_IBUS+=' --disable-dconf'
  ls /usr/lib/pkgconfig/gdk-wayland-3.0.pc && PKGMK_IBUS+=' --enable-wayland --enable-ui' || PKGMK_IBUS+=' --disable-wayland --disable-ui'

  NOCONFIGURE=1 ./autogen.sh
  ./configure $PKGMK_IBUS \
    --prefix=/usr \
    --libexecdir=/usr/lib/ibus \
    --sysconfdir=/etc \
    --with-python=python3 \
    --with-ucd-dir=/usr/share/unicode/ \
    --disable-gtk-doc-html \
    --disable-gtk2 \
    --disable-memconf \
    --disable-nls \
    --disable-python2 \
    --disable-schemas-compile \
    --disable-systemd-services
  sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  #mv $SRC/denylist.txt engine/denylist.txt
  make
  make DESTDIR=$PKG install

  rm -r $PKG/usr/share/gtk-doc
}
