# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=irssi
pkgver=1.4.5
pkgrel=3
pkgdesc="Modular textUI IRC client with IPv6 support"
url="https://irssi.org/"
arch="all"
license="GPL-2.0-or-later WITH OpenSSL-Exception"
makedepends="
	glib-dev
	libotr-dev
	meson
	ncurses-dev
	openssl-dev>3
	perl-dev
	utf8proc-dev
	"
subpackages="$pkgname-doc $pkgname-dev $pkgname-proxy $pkgname-perl $pkgname-otr"
source="https://github.com/irssi/irssi/releases/download/$pkgver/irssi-$pkgver.tar.xz
	$pkgname-$pkgver-perl-again.patch::https://github.com/irssi/irssi/releases/download/$pkgver/perl-again.patch
	"

# secfixes:
#   1.2.2-r0:
#     - CVE-2019-15717
#   1.2.1-r0:
#     - CVE-2019-13045
#   1.1.2-r0:
#     - CVE-2019-5882
#   1.0.3-r0:
#     - CVE-2017-9468
#     - CVE-2017-9469
#   1.0.4-r0:
#     - CVE-2017-10965
#     - CVE-2017-10966
#   1.0.5-r0:
#     - CVE-2017-15721
#     - CVE-2017-15722
#     - CVE-2017-15723
#     - CVE-2017-15227
#     - CVE-2017-15228
#   1.0.6-r0:
#     - CVE-2018-5205
#     - CVE-2018-5206
#     - CVE-2018-5207
#     - CVE-2018-5208
#   1.1.1-r0:
#     - CVE-2018-7050
#     - CVE-2018-7051
#     - CVE-2018-7052
#     - CVE-2018-7053
#     - CVE-2018-7054

build() {
	abuild-meson \
		-Db_lto=true \
		-Dwith-perl=yes \
		-Dwith-perl-lib=vendor \
		-Dwith-proxy=yes \
		-Dwith-otr=yes \
		-Denable-true-color=yes \
		. output
	meson compile -C output
}

check() {
	meson test --print-errorlogs --no-rebuild -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	find "$pkgdir" -name perllocal.pod -delete
}

perl() {
	depends="$pkgname=$pkgver-r$pkgrel perl"
	pkgdesc="Irssi perl support and scripts"
	amove usr/share/irssi/scripts
	amove usr/lib/irssi/modules/libfe_perl.*
	amove usr/lib/irssi/modules/libperl_core.*
	amove usr/lib/perl5
}

proxy() {
	depends="$pkgname=$pkgver-r$pkgrel"
	pkgdesc="Irssi module for enabling bouncer-like functionality"
	amove usr/lib/irssi/modules/libirc_proxy.*
}

otr() {
	depends="$pkgname=$pkgver-r$pkgrel"
	pkgdesc="Irssi module for enabling OTR functionality"
	amove usr/lib/irssi/modules/libotr_core.*
	amove usr/share/irssi/help/otr
}

sha512sums="
5d80107ad625feb6d2b3ac807f517c5cfeae58986d3fbfe53ea82f2dee70396f5092abdc6ef137c5651e4515e081591079b37f0e428f69990db493cfe14e4f36  irssi-1.4.5.tar.xz
026869a1dddb5896638623677fa5e3f9d69b890d843f71424beb22e147ddde6645f330607f34b78e5ab2f162cde721b60e52c7d070ae856f985f94d02d2e08e1  irssi-1.4.5-perl-again.patch
"
