# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
setvar pkgname = 'znc'
setvar pkgver = '1.6.5'
setvar pkgrel = '2'
setvar pkgdesc = ""An advanced IRC bouncer""
setvar url = ""http://znc.in""
setvar arch = ""all""
setvar license = ""ASL-2.0""
setvar makedepends = ""perl-dev libressl-dev cyrus-sasl-dev python2-dev c-ares-dev swig
	gettext-dev tcl-dev autoconf automake python3-dev""
setvar pkgusers = "$pkgname"
setvar pkggroups = "$pkgusers"
setvar install = ""$pkgname.pre-install""
setvar subpackages = ""$pkgname-dev $pkgname-doc $pkgname-extra $pkgname-modtcl
	$pkgname-modperl $pkgname-modpython""
setvar source = ""http://znc.in/releases/znc-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd""
setvar builddir = ""$srcdir/znc-$pkgver""

proc build {
	cd $builddir

	export CFLAGS="$CFLAGS -D_GNU_SOURCE"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-perl \
		--enable-tcl \
		--enable-python
	make
}

proc package {
	cd $builddir

	make DESTDIR="$pkgdir" install

	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -d -m750 -o $pkgusers -g $pkggroups "$pkgdir"/var/lib/znc
}

proc dev {
	default_dev
	_mv_to_sub usr/bin/znc-buildmod
}

proc extra {
	setvar pkgdesc = ""Extra modules for ZNC""

	_mv_mod \
		autovoice.so \
		block_motd.so \
		clearbufferonmsg.so \
		ctcpflood.so \
		flooddetach.so \
		imapauth.so \
		listsockets.so \
		log.so \
		notify_connect.so \
		send_raw.so \
		shell.so
}

proc modtcl {
	setvar pkgdesc = ""TCL module for ZNC""
	setvar depends = ""znc""

	_mv_mod modtcl.so
	_mv_to_sub usr/share/znc/modtcl
}

proc modperl {
	setvar pkgdesc = ""Perl module for ZNC""
	setvar depends = ""znc""

	_mv_mod modperl modperl.so
}

proc modpython {
	setvar pkgdesc = ""Python modules for ZNC""
	setvar depends = ""znc""

	_mv_mod modpython modpython.so
}

proc _mv_mod {
	local i; for i in "$@" {
		_mv_to_sub usr/lib/znc/$i
	}
}

proc _mv_to_sub {
	local i; for i in "$@" {
		mkdir -p "$subpkgdir"/${i%/*}
		mv "$pkgdir"/$i "$subpkgdir"/$i
	}
}

setvar sha512sums = ""d78603ac86d1fb92cdf591b1eb6d32fa19b0e39414bd69e1300c537051612ae590c43d3b8e4dd598cdff605bf3aa1d3d5d806edd428d15d50f733e1670f3e626  znc-1.6.5.tar.gz
47f9bd00f07861e195333d2cda5b1c7386e2324a1842b890837a7936a94b65b7a269f7fee656a522ec86b58a94bd451a2a3629bd6465578681b8d0733c2c77dc  znc.initd
00360f9b487ed5a9d50c85ce597e65c89cf869cabb893c294d0bc7fcd88f9610ecb63ba6df7af1ba1dd977b6d5b05da625a3ee799a46d381f17ac04b976a1f29  znc.confd""