# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
setvar pkgname = 'ircservices'
setvar pkgver = '5.1.24'
setvar pkgrel = '4'
setvar pkgdesc = ""Services for IRC (NickServ, ChanServ, MemoServ)""
setvar url = ""http://www.ircservices.za.net/""
setvar arch = ""all""
setvar license = ""GPL2""
setvar depends = """"
setvar makedepends = ""perl""
setvar install = "$pkgname.pre-install"
setvar pkgusers = ""ircservices""
setvar pkggroups = ""ircservices""
setvar subpackages = ""$pkgname-doc""
setvar source = ""http://achurch.org/services/tarballs/ircservices-$pkgver.tar.gz
		$pkgname.initd""

setvar _builddir = ""$srcdir"/$pkgname-$pkgver"
proc prepare {
	cd $_builddir
	sed -i \
		-e "s/-m 750/-m 755/" \
		-e "s/-m 640/-m 644/" \
		configure
}

proc build {
	cd $_builddir'
	# note: this is not autotools
	RUNGROUP=ircservices' ./configure \
		-cc $CC \
		-cflags $CFLAGS \
		-bindest /usr/bin \
		-datdest /var/lib/ircservices \
		|| return 1

	# build targets one by one as paralell builds breaks
	make config-check && \
		make langstrs.h && \
		make ircservices && \
		make languages && \
		make tools
}

proc package {
	cd $_builddir
#	export INSTALL_PREFIX="$pkgdir"
	make -j1 \
		BINDEST="$pkgdir"/usr/bin \
		DATDEST="$pkgdir"/var/lib/ircservices \
		install || return 1

	install -d "$pkgdir"/usr/share/man/man8
	install docs/ircservices.8 "$pkgdir"/usr/share/man/man8/ircservices.8
	install docs/convert-db.8 \
		"$pkgdir"/usr/share/man/man8/ircservices-convert-db.8

	# try conform to FHS
	cd $pkgdir
	install -d etc/ircservices usr/share/ircservices var/log/ircservices

	mv var/lib/ircservices/convert-db usr/bin/ircservices-convert-db

	mv var/lib/ircservices/example-ircservices.conf \
		etc/ircservices/ircservices.conf
	ln -s /etc/ircservices/ircservices.conf \
		var/lib/ircservices/ircservices.conf

	mv var/lib/ircservices/example-modules.conf \
		etc/ircservices/modules.conf
	ln -s /etc/ircservices/modules.conf var/lib/ircservices/modules.conf

	mv var/lib/ircservices/languages \
		var/lib/ircservices/helpfiles \
		usr/share/ircservices/
	ln -s /usr/share/ircservices/languages var/lib/ircservices/
	ln -s /usr/share/ircservices/helpfiles var/lib/ircservices/

	install -Dm755 "$srcdir"/ircservices.initd \
		etc/init.d/ircservices

	chown ircservices:ircservices var/lib/ircservices \
		var/log/ircservices

	chown root:ircservices etc/ircservices/ircservices.conf \
		etc/ircservices/modules.conf
}

setvar md5sums = ""d4f531537aeed230026cf5560f221ecb  ircservices-5.1.24.tar.gz
b0f4b1f425a9539d5a4e5bc1cb54cc9e  ircservices.initd""
setvar sha256sums = ""63c88b84ddcd12f3636ca9c69987a06e4055156ae3ebe2ff4f22205c66c2a365  ircservices-5.1.24.tar.gz
92697a408b299796af2e652d16a35385281167396bf7dfe3677df1df5cc844ec  ircservices.initd""
setvar sha512sums = ""1c1a0ec6d0e0a11071532e07792a15b1910fe108f09e991ca27e0196cfeec72e057a067fa69396b8647aca4ed8097c857eb8e714d8bee2ca6a0c5e27593fb06d  ircservices-5.1.24.tar.gz
009a60b44deb8e6fd894dbffe25c6c3d6ea9497c6295a3aed5c94e8856b42bfece544c72c6af5214e1f5845964643cc21d3dbdad7baf6af183796a54c9f94f9a  ircservices.initd""