SUMMARY="A very advanced and programmable command interpreter (shell) for UNIX"
DESCRIPTION="Zsh is a shell designed for interactive use, although it \
is also a powerful scripting language. Many of the useful features of \
bash, ksh, and tcsh were incorporated into zsh; plenty original features \
were added."
HOMEPAGE="https://www.zsh.org/"
COPYRIGHT="1992-2020 The Zsh Development Group"
LICENSE="ZSH
	GNU GPL v2"
REVISION="1"
SOURCE_URI="https://downloads.sf.net/zsh/zsh-$portVersion.tar.xz"
CHECKSUM_SHA256="dcc4b54cc5565670a65581760261c163d720991f0d06486da61f8d839b52de27"
SOURCE_URI_2="https://downloads.sf.net/zsh/zsh-$portVersion-doc.tar.xz"
CHECKSUM_SHA256_2="9b4e939593cb5a76564d2be2e2bfbb6242509c0c56fd9ba52f5dba6cf06fdcc4"
PATCHES="zsh-$portVersion.patchset"
ADDITIONAL_FILES="
	zprofile
	zshenv
	"

ARCHITECTURES="all ?x86"

GLOBAL_WRITABLE_FILES="
	settings/zsh directory keep-old
	settings/zsh/zlogin
	settings/zsh/zlogout
	settings/zsh/zprofile keep-old
	settings/zsh/zshenv keep-old
	settings/zsh/zshrc
	"
USER_SETTINGS_FILES="
	settings/zsh directory
	settings/zsh/.zlogin
	settings/zsh/.zlogout
	settings/zsh/.zprofile
	settings/zsh/.zshenv
	settings/zsh/.zshrc
	"

PROVIDES="
	zsh = $portVersion compat >= 5
	cmd:zsh = $portVersion compat >= 5
	cmd:zsh_$portVersion = $portVersion compat >= 5
	"
REQUIRES="
	haiku
	lib:libgdbm
	lib:libiconv
	lib:libncursesw
	lib:libpcre
	"

PROVIDES_doc="
	zsh_doc = $portVersion
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libgdbm
	devel:libiconv
	devel:libncursesw
	devel:libpcre
	"
BUILD_PREREQUIRES="
	cmd:autoreconf
	cmd:awk
	cmd:col
	cmd:find
	cmd:gcc
	cmd:grep
	cmd:make
	cmd:man
	cmd:nroff
	cmd:sed
	cmd:texi2any
	cmd:texi2dvi
	cmd:texi2html
	cmd:texi2pdf
	"

BUILD()
{
	cp -rut . "$sourceDir2/zsh-$portVersion"/*

	export LIBS="-Wl,--as-needed -lnetwork -lbsd"
	export CPPFLAGS="-D_BSD_SOURCE"

	autoreconf -vfi

	runConfigure ./configure \
		--htmldir="$developDocDir/html" \
		--enable-etcdir="$sysconfDir/zsh" \
		--enable-zlogin="$sysconfDir/zsh/zlogin" \
		--enable-zlogout="$sysconfDir/zsh/zlogout" \
		--enable-zprofile="$sysconfDir/zsh/zprofile" \
		--enable-zshenv="$sysconfDir/zsh/zshenv" \
		--enable-zshrc="$sysconfDir/zsh/zshrc" \
		--enable-multibyte \
		--enable-function-subdirs \
		--enable-pcre \
		--enable-dynamic \
		--enable-cap \
		--enable-unicode9 \
		--enable-maildir-support \
		--with-tcsetpgrp \
		--enable-zsh-secure-free

	make $jobArgs
}

INSTALL()
{
	make install

	install -d -m 755 "$settingsDir/zsh"

	# Source /etc/profile on startup, which contains important settings
	# Keep dots in B_USER_SETTINGS_DIRECTORY, if the user hasn't got any
	# dots in their home directory
	install -m 644 \
		"$portDir"/additional-files/zprofile \
		"$portDir"/additional-files/zshenv \
		"$settingsDir"/zsh

	make install.html
	install -t "$developDocDir" -m 644 Doc/*.pdf
	packageEntries doc "$developDir"
}

TEST()
{
	mkdir -p "$sourceDir/fakehome"

	HOME="$sourceDir/fakehome" make check
}
