# Contributor: Chris Leishman <chris@leishman.org>
# Maintainer: Chris Leishman <chris@leishman.org>
pkgname=libcypher-parser
pkgver=0.5.1
pkgrel=0
pkgdesc="Parsing library for the Cypher query language"
url="https://github.com/cleishm/libcypher-parser"
arch="all"
license="Apache-2.0"
depends=""
depends_dev=""
makedepends="$depends_dev automake autoconf libtool check-dev doxygen pkgconfig"
install=""
subpackages="$pkgname-dev $pkgname-doc cypher-lint cypher-lint-doc"
source="https://github.com/cleishm/libcypher-parser/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz"

_builddir="$srcdir"/"$pkgname-$pkgver"
build() {
    cd "$_builddir"
    ./configure \
            --prefix=/usr \
            || return 1
    make || return 1
    make check || return 1
    make doc || return 1
}

package() {
    cd "$_builddir"
    make DESTDIR="$pkgdir" install || return 1
    mkdir -p "$pkgdir"/usr/share/doc/libcypher-parser
    mv doc/html/* "$pkgdir"/usr/share/doc/libcypher-parser/
}

doc() {
    depends="$depends_doc"
    pkgdesc="$pkgdesc (documentation)"
    arch=${arch_doc:-"noarch"}
    install_if="docs $pkgname=$pkgver-r$pkgrel"

    if [ "X$subpkgname" = "Xlibcypher-parser-doc" ]; then
        mkdir -p "$subpkgdir"/usr/share
        mv "$pkgdir"/usr/share/doc "$subpkgdir"/usr/share/
    elif [ "X$subpkgname" = "Xcypher-lint-doc" ]; then
        mkdir -p "$subpkgdir"/usr/share
        mv "$pkgdir"/usr/share/man "$subpkgdir"/usr/share/
        find "$subpkgdir"/usr/share/man/ -type f | xargs gzip -9
    else
        die "Unknown doc package $pkgname"
    fi

    # remove if empty, ignore error (not empty)
    rmdir -f "$pkgdir"/usr/share "$pkgdir"/usr || true 2>/dev/null
    return 0
}

lint() {
    pkgdesc="Lint tool for the Cypher query language"

    mkdir -p "$subpkgdir"/usr
    mv "$pkgdir"/usr/bin "$subpkgdir"/usr/

    # remove if empty, ignore error (not empty)
    rmdir "$pkgdir"/usr/bin "$pkgdir"/usr || true 2>/dev/null
    return 0
}
md5sums="c4c9a3bd9a97f4d97c1ffeb1ff19ebbe  libcypher-parser-0.5.1.tar.gz"
sha256sums="bc9e3234e97b2e7c5829bfe17ed9e2f6a619a2e66144b6db7a6082e697441ead  libcypher-parser-0.5.1.tar.gz"
sha512sums="632d65741332cc81cb42bbf61f53074677d81db27b6a8f2ce9f44fa04f82f16fd13b78c1ed34518124f7e10b77dc87fa3d4f791d19e076c6dc668b89faa82a56  libcypher-parser-0.5.1.tar.gz"
