# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=augeas
pkgver=1.9.0
pkgrel=3
pkgdesc="A configuration editing tool"
url="http://augeas.net"
arch="all"
license="LGPL-2.0-or-later"
depends=""
makedepends="readline-dev libxml2-dev"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-tests::noarch $pkgname-libs"
source="http://download.augeas.net/augeas-$pkgver.tar.gz
	fix-test.patch
	acf.aug"
builddir="$srcdir/$pkgname-$pkgver"
options="!checkroot"

build() {
	cd "$builddir"

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-static \
		--enable-shared \
		--disable-gnulib-tests \
		|| return 1
	make || return 1
	make tests || return 1
}

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install || return 1
	rm -rf "$pkgdir"/usr/lib/charset.alias || return 1
	# Upstream packaging mistake, this should never have been installed
	rm -f "$pkgdir"/usr/bin/dump || return 1
	install -m 644 "$srcdir"/acf.aug "$pkgdir"/usr/share/augeas/lenses
}

tests() {
	pkgdesc="Tests for Augeas lenses"

	mkdir -p "$subpkgdir"/usr/share/augeas/lenses/dist/
	mv "$pkgdir"/usr/share/augeas/lenses/dist/tests \
		"$subpkgdir"/usr/share/augeas/lenses/dist/
}

libs() {
	pkgdesc="Libraries for augeas"
	replaces="augeas"

	mkdir -p "$subpkgdir"/usr/ "$subpkgdir"/usr/share/augeas/
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/ || return 1
	mv "$pkgdir"/usr/share/augeas/lenses \
		"$subpkgdir"/usr/share/augeas/ || return 1
}

static() {
	pkgdesc="Static libraries for Augeas"

	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib/ || return 1
}

check() {
	cd "$builddir"
	make check
}

sha512sums="340aed78ac2df455770735b41f3c10a1cbe40f160e236a735d4580edf5b635afeaf7ddadc10e759e9197c4b233e98b3b6b94a3c2f072aa765c104d64371ce171  augeas-1.9.0.tar.gz
9768878b2f8710436ef1eba7868c22b5eff1d2d549434bf76aced72ebdb4af4f769ea638dedf42ac9b617aaa53d1a767ed6b18868dd0bb3cf72cb3889f6d933a  fix-test.patch
74d728abdf4d3eebdeb3823c1d2588c214fd52734c8855fe3ddbfb6465d31c88d093df356e42effdd3dbdff1a62c52894c7aa840bd6ea8df4995c4f3aa53e919  acf.aug"
