# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=nano
pkgver=5.8
pkgrel=1
pkgdesc="Pico editor clone with enhancements"
arch=('i686' 'x86_64')
license=('GPL')
url="https://www.nano-editor.org"
groups=('editors')
depends=('file' 'libintl' 'ncurses' 'sh')
makedepends=('make'
             'automake-wrapper'
             'ncurses-devel'
             'libiconv-devel'
             'gettext-devel')
backup=('etc/nanorc')
install=nano.install
source=(https://www.nano-editor.org/dist/v5/${pkgname}-${pkgver}.tar.xz{,.asc}
        2.2.4-wchar.patch
        nano-2.3.4-fix-ncurses-location.patch
        nano-2.8.0-msys2.patch)
sha256sums=('e43b63db2f78336e2aa123e8d015dbabc1720a15361714bfd4b1bb4e5e87768c'
            'SKIP'
            '021d6bba4d45068b6d24aefdaed5044675f05b01430b68d27721f90d5ea6f5d3'
            '62b0e50470254ed09e55c068b29b72fe784d0552f97fbc5a15b6ee791c9cbd72'
            'c3b66174c936ca5452dbb1cd31f09d9feeeb965bb7683a35e006900ad7d71667')
validpgpkeys=('8DA6FE7BFA7A418AB3CB2354BCB356DF91009FA7' # "Chris Allegretta <chrisa@asty.org>"
              'A7F6A64A67DA09EF92782DD79DF4862AF1175C5B' # "Benno Schulenberg <bensberg@justemail.net>"
              'BFD009061E535052AD0DF2150D28D4D2A0ACE884' # "Benno Schulenberg <bensberg@telfort.nl>"
)

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  msg2 "2.2.4-wchar.patch"
  patch -p2 -i ${srcdir}/2.2.4-wchar.patch
  msg2 "nano-2.3.4-fix-ncurses-location.patch"
  patch -p1 -i ${srcdir}/nano-2.3.4-fix-ncurses-location.patch
  msg2 "nano-2.8.0-msys2.patch"
  patch -p1 -i ${srcdir}/nano-2.8.0-msys2.patch

  autoreconf -fiv
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --enable-color \
    --enable-nanorc \
    --enable-utf8 \
    CFLAGS="${CFLAGS} -I/usr/include/ncursesw" \
    CPPFLAGS="${CPPFLAGS} -I/usr/include/ncursesw"

  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
  install -DTm644 ${srcdir}/${pkgname}-${pkgver}/doc/sample.nanorc ${pkgdir}/etc/nanorc
}
