SUMMARY="New curses library"
DESCRIPTION="The Ncurses (new curses) library is a free software emulation of \
curses in System V Release 4.0, and more. It uses Terminfo format, supports \
pads and color and multiple highlights and forms characters and function-key \
mapping, and has all the other SYSV-curses enhancements over BSD Curses.
The ncurses code was developed under GNU/Linux. It has been in use for some \
time with OpenBSD as the system curses library, and on FreeBSD and NetBSD as \
an external package. It should port easily to any ANSI/POSIX-conforming UNIX. \
It has even been ported to OS/2 Warp!
This packages provides ncurses 5 ABI ocmpatibility and should not be used for \
new software."
HOMEPAGE="https://www.gnu.org/software/ncurses/ncurses.html"
COPYRIGHT="1998-2018 Free Software Foundation, Inc."
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://ftpmirror.gnu.org/ncurses/ncurses-$portVersion.tar.gz
	https://ftp.gnu.org/gnu/ncurses/ncurses-$portVersion.tar.gz"
CHECKSUM_SHA256="30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d"
SOURCE_DIR="ncurses-$portVersion"
PATCHES="ncurses-$portVersion.patchset"

ARCHITECTURES=""
SECONDARY_ARCHITECTURES="x86"

libVersion="5.9.0"
libVersionCompat="$libVersion compat >= 5"

PROVIDES="
	ncurses5$secondaryArchSuffix = $portVersion
	lib:libformw$secondaryArchSuffix = $libVersionCompat
	lib:libmenuw$secondaryArchSuffix = $libVersionCompat
	lib:libncursesw$secondaryArchSuffix = $libVersionCompat
	lib:libncurses++w$secondaryArchSuffix = $libVersionCompat
	lib:libpanelw$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:libtool$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

doBuild()
{
	if [ $# -lt 1 ]; then
		echo >&2 "Usage: doBuild <targetDir> [ <configureFlags> ... ]"
		exit 1
	fi

	targetDir=$(pwd)/$1
	shift 1

	# Parse additional arguments. "--libs-only" means we only want the
	# libraries, nothing else. "--without-progs" means no programs and no
	# terminfo DB (requires tic).
	local noData
	local libsOnly
	local configureArgs
	local arg
	for arg in $@; do
		case "$arg" in
			--libs-only)
				noData=1
				libsOnly=1
				arg="--without-progs"
				;;
			--without-progs)
				noData=1
				;;
		esac
		configureArgs="$configureArgs $arg"
	done

	runConfigure \
		--omit-dirs "dataRootDir docDir" ./configure \
		--with-libtool --with-abi-version=5 --with-rel-version=5.9 \
		--enable-termcap --without-tests \
		--enable-hard-tabs \
		--disable-pc-files \
		$configureArgs
	make $jobArgs

	if [ -z "$noData" ]; then
		# We need LIBRARY_PATH to include the library installation directory,
		# since the installation process for the terminfo database will run tic
		# and the built-in rpath doesn't consider the DESTDIR we're using.
		LIBRARY_PATH="$targetDir/$prefix/lib:$LIBRARY_PATH" \
		make install DESTDIR=$targetDir
	else
		make install.libs DESTDIR=$targetDir
		if [ -z "$libsOnly" ]; then
			make install.includes DESTDIR=$targetDir
			make install.man DESTDIR=$targetDir
		fi
	fi
}

BUILD()
{
	doBuild build-widec --enable-widec --libs-only
}

INSTALL()
{
	cp -ra build-widec/$prefix/. $prefix

	# prepare develop/lib
	prepareInstalledDevelLibs \
		libformw libmenuw libncursesw libncurses++w libpanelw

	# library-only package, remove all other files
	rm -r $binDir $developDir
}
