# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
# Maintainer    : YianIris <yianiris At disroot Dot org>
#----------------
# Obarun PkgSrc : https://git.obarun.org/pkg/obextra/brltty
#-----------------------------------------------------------
# DESCRIPTION ]

pkgname=brltty
pkgver=6.4
pkgrel=9
pkgdesc="Braille display driver for Linux/Unix"
url='https://brltty.app'

track="archive"
target="$pkgname-$pkgver"
source=(
    "https://brltty.app/${track}/${target}.tar.bz2"
    brltty-6.4-x11_autostart.patch
    brltty.sysusers
    brltty.tmpfiles
)

#----------------------
# BUILD CONFIGURATION ]

makedepends=(
    'alsa-lib'
    'at-spi2-atk'
    'at-spi2-core'
    'atk'
    'cython'
    'dbus'
    'espeak-ng'
    'expat'
    'festival'
    'glib2'
    'gpm'
    'icu'
    'java-environment'
    'libxaw'
    'ncurses'
    'ocaml-ctypes'
    'ocaml-findlib'
    'speech-dispatcher'
    'strip-nondeterminism'
    'tcl'
)   ## 'dracut'

#------------------------
# INSTALL CONFIGURATION ]

depends=(
    'bluez-libs'
    'gcc-libs'
    'glibc'
    'liblouis'
    'libspeechd'
    'pcre2'
    'polkit'
)

optdepends=(
    'at-spi2-core: X11/GNOME Apps accessibility'
    'atk: ATK bridge for X11/GNOME accessibility'
    'espeak-ng: espeak-ng driver'
    'java-runtime: Java support'
    'libxaw: X11 support'
    'libxt: X11 support'
    'libx11: for xbrlapi'
    'libxfixes: for xbrlapi'
    'libxtst: for xbrlapi'
    'ocaml: OCaml support'
    'python: Python support'
    'speech-dispatcher: speech-dispatcher driver'
    'tcl: tcl support'
)   # 'dracut: initramfs support'

backup=(
    'etc/brltty.conf'
    'etc/X11/xinit/xinitrc.d/90xbrlapi'
)

provides=(
    'libbrlapi.so'
)

options=(
    '!emptydirs'
)

install=brltty.install

#--------------------
# BUILD PREPARATION ]

prepare() {
    cd $pkgname-$pkgver
    patch -Np1 -i ../brltty-6.4-x11_autostart.patch
    ./autogen
}

#----------------------
# BUILD CONFIGURATION ]

_flags=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --mandir=/usr/share/man
    --with-scripts-directory=/usr/lib/brltty
    --with-tables-directory=/usr/share/brltty
    --with-writable-directory=/run/brltty
    --with-flite-voice=cmu_us_kal16
    --disable-stripping
    --enable-gpm
)

#--------
# BUILD ]

build() {
    cd $pkgname-$pkgver

    ./configure "${_flags[@]}"
    make

    ## make brlapi.jar deterministic
    find . -type f -iname "*.jar" -exec strip-nondeterminism {} \;
}

#----------
# PACKAGE ]

package() {
    depends+=(
        'libasound.so'
        'libdbus-1.so'
        'libexpat.so'
        'libgio-2.0.so'
        'libglib-2.0.so'
        'libgobject-2.0.so'
        'libicuuc.so'
        'libgpm.so'
        'libncursesw.so'
    )

    cd $pkgname-$pkgver

    make INSTALL_ROOT="$pkgdir" install
    make INSTALL_ROOT="$pkgdir" install-udev
    make INSTALL_ROOT="$pkgdir" install-polkit
    #make INSTALL_ROOT="$pkgdir" install-dracut

    install -vDm 644 "Documents/$pkgname.conf" -t "$pkgdir/etc/"
    install -vDm 644 "../$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
    install -vDm 644 "../$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"

    ## fix directory permission and ownership
    install -vdm 700 -o 102 -g 102 "$pkgdir/usr/share/polkit-1/rules.d"
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(LGPL2.1)

sha512sums=('')