# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Maintainer: Alad Wenter <alad@mailbox.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Larry Hajali <larryhaja [at] gmail [dot] com>

pkgname=sigil
pkgver=1.7.0
pkgrel=1
pkgdesc="multi-platform EPUB2/EPUB3 ebook editor"
arch=('x86_64')
url="https://sigil-ebook.com/"
license=('GPL3')
depends=('hicolor-icon-theme' 'hunspell' 'mathjax2' 'minizip' 'python-css-parser'
         'python-dulwich' 'python-lxml' 'qt5-svg' 'qt5-webengine')
makedepends=('qt5-tools' 'cmake')
optdepends=('hunspell-en_US: for English dictionary support'
            'hyphen-en: for English hyphenation support in plugins'
            'pageedit: external editor to replace BookView'
            'python-html5lib: recommended for plugins'
            'python-chardet: recommended for plugins'
            'python-cssselect: recommended for plugins'
            'python-pillow: recommended for plugins'
            'python-regex: recommended for plugins'
            'python-pyqt5: recommended for plugins'
            'python-pyqt5-webengine: recommended for plugins'
            'tk: recommended for plugins')
source=("Sigil-${pkgver}.tar.gz::https://github.com/Sigil-Ebook/Sigil/archive/${pkgver}.tar.gz"
        "https://github.com/Sigil-Ebook/Sigil/releases/download/${pkgver}/Sigil-${pkgver}.tar.gz.sig")
sha256sums=('f8ea3c11a33bb54de3de1b401fb7ec8d440a5a63277c4d7ed32a29ba629eac66'
            'SKIP')
b2sums=('29f7c682925d1e1bbff082e96b747ce32df82d78406ccd984b4f8de1f01944c35aa86587ce47a18687d5fe281b8cb656085b52d3a1e72ed17862501121d9d134'
        'SKIP')
validpgpkeys=('B5A56206AB0FBC1A24EFAB8AA166D29A8FCDAC63') # Doug Massay <douglaslmassay@gmail.com>

build() {
    mkdir -p "${srcdir}"/Sigil-${pkgver}/build
    cd "${srcdir}"/Sigil-${pkgver}/build

    cmake -G "Unix Makefiles" \
        -DUSE_SYSTEM_LIBS=1 \
        -DSYSTEM_LIBS_REQUIRED=1 \
        -DINSTALL_BUNDLED_DICTS=0 \
        -DINSTALL_HICOLOR_ICONS=1 \
        -DDISABLE_UPDATE_CHECK=1 \
        -DMATHJAX_DIR=/usr/share/mathjax2 \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DCMAKE_C_FLAGS:STRING="${CFLAGS}" \
        -DCMAKE_CXX_FLAGS:STRING="${CXXFLAGS}" \
        -DCMAKE_SKIP_RPATH=ON ..

    make
}

package() {
    cd "${srcdir}"/Sigil-${pkgver}/build

    make install DESTDIR="${pkgdir}"

    # Compile python bytecode
    python -m compileall "${pkgdir}"/usr/share/sigil/{plugin_launchers/python/,python3lib}
    python -O -m compileall "${pkgdir}"/usr/share/sigil/{plugin_launchers/python/,python3lib}
}
