# Maintainer: Aura Kelloniemi <kaura.dev@sange.fi>

pkgname=brltty-aurum
pkgver=6.1.r442.g4be6f8cf1
pkgrel=1
pkgdesc="Braille display driver for Linux/Unix (development version)"
arch=('x86_64')
url="https://brltty.app"
license=('LGPL2.1')
depends=('alsa-lib' 'expat' 'icu' 'liblouis' 'pcre2' 'systemd')
makedepends=('autoconf' 'automake' 'at-spi2-core' 'bluez-libs' 'cython' 'dbus'
             'doxygen' 'espeak-ng' 'glib2' 'groff' 'libxaw' 'libxtst'
             'ncurses' 'linuxdoc-tools' 'pkg-config' 'polkit'
             'speech-dispatcher' 'xorgproto')
optdepends=('at-spi2-core: X11/GNOME Apps accessibility'
            'atk: ATK bridge for X11/GNOME accessibility'
            'bluez-libs: bluetooth support'
            'espeak-ng: espeak-ng driver'
            'libxaw: X11 support'
            'polkit: PolicyKit support'
            'python: Python support'
            'speech-dispatcher: speech-dispatcher driver')
conflicts=('brltty')
provides=('brltty')
backup=(etc/brltty.conf)
options=('!emptydirs')
install=brltty.install
source=(${pkgname}::'git+https://github.com/brltty/brltty.git'
        "brltty.install"
        "brltty.tmpfiles")

sha256sums=('SKIP'
            'd6d69f812b04934debe8865e7d35ac4e0000361b00eab7314e588a56be57c0ae'
            '393e2d4007e9da43d3a5756aafa473b83acde788b1a5f4f706526fc8c6003cd2')

pkgver() {
    cd "${srcdir}/${pkgname}"
    # cutting off 'BRLTTY.' prefix that presents in the git tag
    git describe --long | sed 's/^BRLTTY.//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
    cd "${srcdir}/${pkgname}"
    ./autogen --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
            --mandir=/usr/share/man \
            --with-tables-directory=/usr/share/brltty \
            --with-screen-driver=lx \
            --disable-gpm \
            --disable-tcl-bindings \
            --disable-java-bindings \
            --disable-lisp-bindings \
            --disable-ocaml-bindings \
            --without-espeak --without-theta --without-swift \
            --with-rgx-package=libpcre2-32 \
            --with-curses=ncursesw \
            --without-midi-package --without-fm-package \
            --disable-stripping

    # Fix ncursesw header include
    sed --in-place -e 's|^\(#include \)<ncursesw/ncurses\.h>|\1<ncurses.h>|' \
        Headers/get_curses.h

    # Reduce display update rate
    sed --in-place -e 's|^\(#define UPDATE_SCHEDULE_DELAY \)15|\1 50|' \
        Programs/parameters.h

    make 
    make -C "Documents/"
}

package() {
    cd "${srcdir}/${pkgname}"
    make INSTALL_ROOT="${pkgdir}" install
    install -vDm 644 "Documents/brltty.conf" -t "${pkgdir}/etc/"
    install -vDm 644 "../brltty.tmpfiles" \
        "${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"

    make -C "Autostart/Systemd/" INSTALL_ROOT="$pkgdir" install
    make -C "Autostart/Udev/" INSTALL_ROOT="$pkgdir" install
}
