#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer		: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=vi
pkgver=070224
pkgrel=06
epoch=1
pkgdesc="The original ex/vi text editor"
arch=('x86_64')
url="https://ex-vi.sourceforge.net/"
depends=('ncurses')
optdepends=('s-nail: used by the preserve command for notification')
source=(https://sources.archlinux.org/other/$pkgname/ex-$pkgver.tar.xz{,.sig}
        fix-tubesize-short-overflow.patch
        format-security.patch
        linenum.patch
        navkeys.patch
        preserve-dir.patch)

prepare() {
  cd ex-$pkgver

CFLAGS=${CFLAGS/-Werror=format-security/}  #  https://bugs.archlinux.org/task/70701
CXXFLAGS=${CXXFLAGS/-Werror=format-security/}

  patch -Np1 -i ../fix-tubesize-short-overflow.patch

  # https://bugs.archlinux.org/task/76121
  patch -Np1 -i ../format-security.patch

  # https://bugs.archlinux.org/task/70770
  patch -Np1 -i ../linenum.patch

  patch -Np1 -i ../navkeys.patch

  # https://bugs.archlinux.org/task/20653
  patch -Np1 -i ../preserve-dir.patch
}

build() {
  cd ex-$pkgver

  make PREFIX=/usr LIBEXECDIR=/usr/lib/ex PRESERVEDIR=/var/lib/ex \
    TERMLIB=ncurses FEATURES="-DCHDIR -DFASTTAG -DUCVISUAL -DMB -DBIT8"
}

package() {
  cd ex-$pkgver

  make PREFIX=/usr LIBEXECDIR=/usr/lib/ex PRESERVEDIR=/var/lib/ex \
    INSTALL=/usr/bin/install DESTDIR="$pkgdir" install
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

#---- license gpg-key sha256sums ----

license=('custom:ex')

validpgpkeys=('86CFFCA918CF3AF47147588051E8B148A9999C34')

sha256sums=(c3e52dd44edd1f6bf0b52207f717c56149dc50aac0d131fff3851d589727f52f # ex-070224.tar.xz
	f45f9b452e065a7f8c271197fa5194b0e9389adf0a8955518dd9a213cef43f8b # ex-070224.tar.xz.sig
	42167fabebe30a13d594346b1d254db82090ba41742a9f35b8895d37092053f0 # fix-tubesize-short-overflow.patch
	ec50373ab48a9b327c5d02b10406bc3d04310d692de6c17098a59b1afeb08e03 # format-security.patch
	4539f46cd839475c168a9c463f041354463e90e810b973a10c499c2727b008e7 # linenum.patch
	0e9e2d381f1d8cb86daae68462b3849825b003c08007725c0db9939d3d5bf58d # navkeys.patch
	f0ef9ed2ccea98bf47b08dd3faa2abb911b4e6c0579f5294e9d0e8742282ff65) #  preserve-dir.patch


