#!/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"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

#pkgbase=zsh
#pkgname=('zsh' 'zsh-doc')
pkgname=zsh
pkgver=5.9
pkgrel=03
arch=('x86_64')
url='https://www.zsh.org/'
makedepends=(pcre libcap gdbm yodl)
source=("https://www.zsh.org/pub/zsh-${pkgver}"{,-doc}".tar.xz"{,.asc}
        '0001-50629-do-not-use-egrep-in-tests.patch'
        'zprofile')
prepare() {
	cd "${srcdir}/${pkgbase}-${pkgver}"

	# 50629: do not use egrep in tests
	patch -Np1 < ../0001-50629-do-not-use-egrep-in-tests.patch

	# Set correct keymap path
	sed -i 's#/usr/share/keymaps#/usr/share/kbd/keymaps#g' Completion/Unix/Command/_loadkeys

	# Fix usb.ids path
	sed -i 's#/usr/share/misc/usb.ids#/usr/share/hwdata/usb.ids#g' Completion/Linux/Command/_lsusb

	# Remove unneeded and conflicting completion scripts
	for _fpath in AIX BSD Cygwin Darwin Debian Mandriva openSUSE Redhat Solaris; do
		rm -rf Completion/$_fpath
		sed "s#\s*Completion/$_fpath/\*/\*##g" -i Src/Zle/complete.mdd
	done
	rm Completion/Linux/Command/_pkgtool

	# force generation of documentation with correct paths
	rm Doc/version.yo
}

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

	./configure --prefix=/usr \
		--docdir=/usr/share/doc/zsh \
		--htmldir=/usr/share/doc/zsh/html \
		--enable-etcdir=/etc/zsh \
		--enable-zshenv=/etc/zsh/zshenv \
		--enable-zlogin=/etc/zsh/zlogin \
		--enable-zlogout=/etc/zsh/zlogout \
		--enable-zprofile=/etc/zsh/zprofile \
		--enable-zshrc=/etc/zsh/zshrc \
		--enable-maildir-support \
		--with-term-lib='ncursesw' \
		--enable-multibyte \
		--enable-function-subdirs \
		--enable-fndir=/usr/share/zsh/functions \
		--enable-scriptdir=/usr/share/zsh/scripts \
		--with-tcsetpgrp \
		--enable-pcre \
		--enable-cap \
		--enable-gdbm \
		--enable-zsh-secure-free
	make
}

#check() {
#	cd "${srcdir}/${pkgbase}-${pkgver}"
#	HOME="${srcdir}" make check
#}

package_zsh() {
	pkgdesc='A very advanced and programmable command interpreter (shell) for UNIX'
	groups=( jobbot )
	depends=('pcre' 'libcap' 'gdbm')
	backup=('etc/zsh/zprofile')
	install=zsh.install

	cd "${srcdir}/${pkgbase}-${pkgver}"
	make DESTDIR="${pkgdir}/" install
	install -D -m644 "${srcdir}/zprofile" "${pkgdir}/etc/zsh/zprofile"
	install -D -m644 LICENCE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

#package_zsh-doc() {
#	pkgdesc='Info, HTML and PDF format of the ZSH documentation'
#
#	cd "${srcdir}/${pkgbase}-${pkgver}"
#	make DESTDIR="${pkgdir}/" install.info install.html
#	install -D -m644 Doc/zsh.pdf "${pkgdir}/usr/share/doc/zsh/zsh.pdf"
#	install -D -m644 LICENCE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
#}

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

license=('custom')

validpgpkeys=('F7B2754C7DE2830914661F0EA71D9A9D4BDB27B3'
              'E96646BE08C0AF0AA0F90788A5FEEE3AC7937444'
              '7CA7ECAAF06216B90F894146ACF8146CAE8CBBC4')

sha256sums=(9b8d1ecedd5b5e81fbf1918e876752a7dd948e05c1a0dba10ab863842d45acd5  # zsh-5.9.tar.xz
	026e0e0bcaf389a60167694eec41fb7840bb4bf196af25b3365ba7eef51e763b  # zsh-5.9.tar.xz.asc
	6f7c091249575e68c177c5e8d5c3e9705660d0d3ca1647aea365fd00a0bd3e8a  # zsh-5.9-doc.tar.xz
	2fda22062a9dcbcb5e76a5b4b5a0f7b8d7e4cd08707b05f11d3b99e721a982b5  # zsh-5.9-doc.tar.xz.asc
	bcce55ff5a81a321c501b7749a7d3e2031004c0ab999d80c35eeb4b9ce7efdf0  # 0001-50629-do-not-use-egrep-in-tests.patch
	230832038c3b8f67fdb1b284ac5f68d709cdb7f1bc752b0e60657b9b9d091045) # zprofile

##  6fdd808ed14d8717289a8948c3d17ec4c5b7b0ac169d282341a9cc841136ec37  zsh-5.9-03-x86_64.pkg.tar.lz

