# Maintainer: Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Dan McGee <dan@archlinux.org>

pkgname=irssi
replaces=(irssi-git)
conflicts=(irssi-git)
pkgver=1.4.5
pkgrel=4
pkgdesc="Modular text mode IRC client with Perl scripting"
arch=('i686' 'x86_64')
url="https://irssi.org/"
msys2_repository_url="https://github.com/irssi/irssi"
msys2_references=(
  "cpe: cpe:/a:irssi:irssi"
)
license=('spdx:GPL-2.0-or-later')
depends=('openssl' 'gettext' 'perl' 'ncurses' 'glib2')
makedepends=('gettext-devel' 'glib2-devel' 'openssl-devel' 'perl-devel' 'ncurses-devel' 'elinks' 'autotools' 'gcc')
optdepends=('perl-libwww: for the scriptassist script')
backup=('etc/irssi.conf')
source=("https://github.com/irssi/${pkgname}/releases/download/${pkgver}/${pkgname}-${pkgver}.tar.xz"{,.asc})
sha256sums=('72a951cb0ad622785a8962801f005a3a412736c7e7e3ce152f176287c52fe062'
            'SKIP')
validpgpkeys=('7EE65E3082A5FB06AC7C368D00CCB587DDBEF0E1') # The Irssi project <staff@irssi.org>

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # it hardcodes paths and only supports out-of-tree with the source being one level up
  mkdir build && cd build

  ../configure \
    --build=${CHOST} \
    --sysconfdir=/etc \
    --prefix=/usr \
    --disable-glibtest \
    --with-perl-lib=vendor \
    --with-perl-staticlib

  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}/build"

  echo 'Applying patches to Perl MakeMaker library misname'
  find . -name "Makefile" -type f | while read line; do sed -i 's/\([i|c|I]\)\.dll$/\1.a/' $line; done

  make DESTDIR="${pkgdir}" install
}
