abinfo "Building Calibre runtime ..."
LANG='en_US.UTF-8' python3 setup.py build

abinfo "Unbundle Libreation Fonts ..."
LANG='en_US.UTF-8' python3 setup.py liberation_fonts \
    --system-liberation_fonts \
    --path-to-liberation_fonts /usr/share/fonts/TTF

# TODO: MathJax 3
#abinfo "Unbundle MathJax ..."
#LANG='en_US.UTF-8' python3 setup.py mathjax \
#   --system-mathjax --path-to-mathjax /usr/share/mathjax

abinfo "Building Calibre GUI ..."
LANG='en_US.UTF-8' python3 setup.py gui

abinfo "Creating data directories ..."
install -dv \
    "$PKGDIR"/usr/share/zsh/site-functions \
    "$PKGDIR"/usr/share/{applications,desktop-directories,icons/hicolor}

abinfo "Installing MIME data ..."
install -Dvm644 "$SRCDIR"/resources/calibre-mimetypes.xml \
    "$PKGDIR"/usr/share/mime/packages/calibre-mimetypes.xml

abinfo "Installing Calibre ..."
LANG='en_US.UTF-8' XDG_DATA_DIRS="$PKGDIR"/usr/share python3 setup.py install \
    --root="$PKGDIR"/usr \
    --staging-root="$PKGDIR"/usr \
    --prefix=/usr

abinfo "Compiling bytecode for Calibre ..."
python3 -m compileall "$PKGDIR"/usr/lib/calibre/ || true
python3 -O -m compileall "$PKGDIR"/usr/lib/calibre/ || true
