# $Id: PKGBUILD 145276 2015-10-30 06:59:28Z fyan $
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=pandoc
pkgver=1.15.1.1
pkgrel=2
pkgdesc="Conversion between markup formats"
url="http://pandoc.org"
license=("GPL")
arch=('i686' 'x86_64')
depends=("ghc=7.10.2" "haskell-http" "haskell-juicypixels" "haskell-sha" "haskell-aeson"
         "haskell-base64-bytestring" "haskell-blaze-html" "haskell-blaze-markup"
         "haskell-cmark" "haskell-data-default" "haskell-deepseq-generics" "haskell-mtl"
         "haskell-extensible-exceptions" "haskell-filemanip" "haskell-haddock-library"
         "haskell-highlighting-kate" "haskell-hslua" "haskell-http-client" "haskell-syb"
         "haskell-http-client-tls" "haskell-http-types"  "haskell-text" "haskell-texmath"
         "haskell-network" "haskell-old-time" "haskell-pandoc-types" "haskell-parsec"
         "haskell-random" "haskell-scientific" "haskell-tagsoup" "haskell-temporary"
         "haskell-network-uri" "haskell-unordered-containers" "haskell-zip-archive"
         "haskell-vector" "haskell-xml" "haskell-yaml" "haskell-zlib")
optdepends=('haskell-pandoc-citeproc: for citation rendering with pandoc-citeproc filter')
options=('staticlibs')
source=("http://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
install="${pkgname}.install"
sha256sums=('a70e0af56c294dbb1ba646df24f90b81542d060ec7167f70ff2b873ed7ed6d5e')

build() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    
    runhaskell Setup configure -O --enable-library-profiling --enable-shared \
        --prefix=/usr --docdir="/usr/share/doc/${pkgname}" \
        --libsubdir=\$compiler/site-local/\$pkgid \
            -f-old-locale -fnetwork-uri -fhttps -f-trypandoc -f-embed_data_files
    runhaskell Setup build

    # LC_CTYPE=en_US.UTF-8 is needed since 1.15.1
    # https://github.com/jgm/pandoc/issues/2457#issuecomment-149146107
    LC_CTYPE=en_US.UTF-8 runhaskell Setup haddock --hoogle --html

    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    
    install -D -m744 register.sh   "${pkgdir}/usr/share/haskell/${pkgname}/register.sh"
    install    -m744 unregister.sh "${pkgdir}/usr/share/haskell/${pkgname}/unregister.sh"
    install -d -m755 "${pkgdir}/usr/share/man/man1"
    install -d -m755 "${pkgdir}/usr/share/man/man5"
    install -d -m755 "${pkgdir}/usr/share/doc/ghc/html/libraries"
    ln -s "/usr/share/doc/${pkgname}/html" "${pkgdir}/usr/share/doc/ghc/html/libraries/${pkgname}"
    runhaskell Setup copy --destdir="${pkgdir}"
    install -D -m644 "COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/COPYING"
}
