# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=heirloom-doctools
pkgver=191015
pkgrel=4
pkgdesc="The Heirloom Documentation Tools"
url="http://n-t-roff.github.io/heirloom/doctools.html"
arch="all"
license="CDDL"
# TODO: Switch to bison <https://github.com/n-t-roff/heirloom-doctools/issues/85>
makedepends="flex byacc"
subpackages="$pkgname-doc"
install="$pkgname.post-upgrade $pkgname.post-install"
source="heirloom-doctools-$pkgver.tar.gz::https://github.com/n-t-roff/heirloom-doctools/archive/$pkgver.tar.gz
	heirloom-doctools.sh.disabled
	README.alpine"

_makeargs="
	CC="${CC:-gcc}" \
	CCC="${CCX:-g++}" \
	EUC=-DEUC \
	STRIP=true \
	RANLIB=ranlib \
	INSTALL=install \
	BINDIR=/usr/lib/$pkgname/bin \
	MANDIR=/usr/share/man \
	LIBDIR=/usr/lib/$pkgname \
	REFDIR=/usr/lib/$pkgname/reftools \
	MACDIR=/usr/share/$pkgname/tmac \
	FNTDIR=/usr/share/$pkgname/font \
	TABDIR=/usr/share/$pkgname/nterm \
	HYPDIR=/usr/share/$pkgname/hyphen \
	PUBDIR=/usr/share/$pkgname/pub \
	PSTDIR=/usr/share/$pkgname/font/devpost/postscript
"

build() {
	# Unfortunately parallel build isn't supported.
	CFLAGS="$CFLAGS -fcommon" make -j1 $_makeargs -C "$builddir"
}

package() {
	# Unfortunately parallel install isn't supported.
	make -j1 ROOT="$pkgdir" $_makeargs \
		-C "$builddir" install

	install -Dm644 "$srcdir"/README.alpine \
		"$pkgdir"/usr/share/doc/$pkgname/README.alpine
	install -Dm644 "$srcdir"/heirloom-doctools.sh.disabled \
		"$pkgdir"/etc/profile.d/heirloom-doctools.sh.disabled
}

doc() {
	default_doc

	# Move man pages to a different location to avoid
	# conflicts with other -doc packages. See also:
	# the non-standard BINDIR above.
	mkdir -p "$subpkgdir"/usr/lib/$pkgname
	mv "$subpkgdir"/usr/share/man \
		"$subpkgdir"/usr/lib/$pkgname/man
}

sha512sums="
60fd531c29edc7ecee479b69111effa30555c6ba93de3aa4c9f3f06d50a504848eaf800f8fd39865f83d6ed73c03b14e1a416bf942ba82f8a4211344002ad179  heirloom-doctools-191015.tar.gz
a6509b3efcf4aea77b41eb7d02796699d84524b7d38dbc29e96c45fb25197099e56671d10364ea45d09194e9a73197c35d4f53cddb43e6c7c3eb1afd4138d255  heirloom-doctools.sh.disabled
70ea25556c43556cb183c7d5d5119ab25a58440b3ea320aff32028a62f36a02e4ef4bc18d37c937b52deae4ec9f0e2d5709a3fedba4bf612c4c795e919e1316b  README.alpine
"
