# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=augeas
pkgver=1.10.1
pkgrel=2
pkgdesc="A configuration editing tool"
url="http://augeas.net"
arch="all"
license="LGPL-2.0-or-later"
makedepends="autoconf automake libxml2-dev readline-dev"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-tests::noarch $pkgname-libs"
source="http://download.augeas.net/augeas-$pkgver.tar.gz
	0001-new-lens-Strongswan.patch
	fix-test.patch
	acf.aug
	awall.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
	make
	make tests
}

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

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/lib/charset.alias
	# Upstream packaging mistake, this should never have been installed
	rm -f "$pkgdir"/usr/bin/dump

	local lens
	for lens in acf awall; do
		install -m 644 "$srcdir"/$lens.aug "$pkgdir"/usr/share/augeas/lenses
	done
}

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/
	mv "$pkgdir"/usr/share/augeas/lenses \
		"$subpkgdir"/usr/share/augeas/
}

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

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

sha512sums="382e8ef6a5bd3d12d7d2e0d2987f39c04ff7df3f07cd68aa732bf266b89d5d59a85be63921a7ff70f9219dbc6bb8547f80528242caa9417e08a008d1721cb1d2  augeas-1.10.1.tar.gz
c4544af27ff60b9198bfba9b753e22caba1a1eba1a7c2c18aaac06242e2fce3a653be6ff3c88c26b27c0331d89f65aa1581c2a859c0c1c47d5a01c0b942c1a79  0001-new-lens-Strongswan.patch
9768878b2f8710436ef1eba7868c22b5eff1d2d549434bf76aced72ebdb4af4f769ea638dedf42ac9b617aaa53d1a767ed6b18868dd0bb3cf72cb3889f6d933a  fix-test.patch
74d728abdf4d3eebdeb3823c1d2588c214fd52734c8855fe3ddbfb6465d31c88d093df356e42effdd3dbdff1a62c52894c7aa840bd6ea8df4995c4f3aa53e919  acf.aug
fe83e70ddeced87fea4c4dbdfb90b7497bc5fd01b6b097f0f49c52894b4dc1d93cf217ae7aa98abeaba0a9f8e8e18a1d426b6c203b318afde9cd5164cbe604b1  awall.aug"
