# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=sagemath-doc
pkgver=9.4
pkgrel=1
pkgdesc='HTML documentation for SageMath'
arch=(any)
url='http://www.sagemath.org'
license=(GPL)
depends=(gap-doc python-pplpy)
makedepends=(sagemath python-pyzmq python-docutils python-jupyter_client python-pkgconfig cython python-ipywidgets thebe)
source=(https://github.com/sagemath/sage/archive/$pkgver/sagemath-$pkgver.tar.gz)
sha256sums=('47190f37e679c2483dadc13112595bacb399dfe4c4a0cde18d3627f5b2db0ea5')
options=(!strip) # nothing to strip, save packaging time

prepare() {
  cd sage-$pkgver

  SAGE_ROOT="$PWD" PATH="$PWD/build/bin:$PATH" src/doc/bootstrap
  rm -r src/sage # Use the installed sage, not the one from the source tree
}

build() {
  cd sage-$pkgver/src

  export SAGE_SRC="$PWD" \
         SAGE_DOC="$PWD"/doc \
         MATHJAX_DIR=/usr/share/mathjax2 \
         SAGE_NUM_THREADS=10 \
         LANG=C
  python -m sage_docbuild --no-pdf-links --mathjax all html
}

package() {
  cd sage-$pkgver/src/doc
 
  mkdir -p "$pkgdir"/usr/share/doc/sage
  cp -r common "$pkgdir"/usr/share/doc/sage
  cp -r html "$pkgdir"/usr/share/doc/sage

# Replace duplicated files by symlinks (Gentoo)
  cd "$pkgdir"/usr/share/doc/sage
  mv html/en/_static{,.tmp}
  for _dir in `find -name _static` ; do
    rm -r $_dir
    ln -s /usr/share/doc/sage/html/en/_static $_dir
  done
  mv html/en/_static{.tmp,}
}
