SUMMARY="The GNU Readline library"
DESCRIPTION="The GNU Readline library provides a set of functions for use by \
applications that allow users to edit command lines as they are typed in. \
Both Emacs and vi editing modes are available. The Readline library includes \
additional functions to maintain a list of previously-entered command lines, \
to recall and perhaps reedit those lines, and perform csh-like history \
expansion on previous commands.

The history facilites are also placed into a separate library, the History \
library, as part of the build process. The History library may be used without \
Readline in applications which desire its capabilities."
HOMEPAGE="http://tiswww.case.edu/php/chet/readline/rltop.html"
COPYRIGHT="1989-2019 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="ftp://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz"
SOURCE_DIR="readline-8.1"
for i in {001..002}; do
	eval "SOURCE_URI_$i=\"https://ftp.gnu.org/gnu/readline/readline-8.1-patches/readline81-$i#noarchive\""
done
CHECKSUM_SHA256="f8ceb4ee131e3232226a17f51b164afc46cd0b9e6cef344be87c65962cb82b02"
CHECKSUM_SHA256_001="682a465a68633650565c43d59f0b8cdf149c13a874682d3c20cb4af6709b9144"
CHECKSUM_SHA256_002="e55be055a68cb0719b0ccb5edc9a74edcc1d1f689e8a501525b3bc5ebad325dc"
PATCHES="readline-8.1.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

PROVIDES="
	readline$secondaryArchSuffix = $portVersion
	lib:libhistory$secondaryArchSuffix = 8.1 compat >= 8
	lib:libreadline$secondaryArchSuffix = 8.1 compat >= 8
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	"

PROVIDES_devel="
	readline${secondaryArchSuffix}_devel = $portVersion
	devel:libhistory$secondaryArchSuffix = 8.1 compat >= 8
	devel:libreadline$secondaryArchSuffix = 8.1 compat >= 8
	"
REQUIRES_devel="
	readline$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libncurses$secondaryArchSuffix >= 6
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage readline$secondaryArchSuffix \
	$libDir/libhistory.so.8.1 \
	$libDir/libreadline.so.8.1

PATCH()
{
	for i in {001..002}; do
		echo "Applying patch $i..."
		sed -e "s/\.\.\/readline-8.1\///" ../../sources-$i/readline81-$i | patch -p0
	done
}

BUILD()
{
	libtoolize --force --copy --install
	aclocal
	autoconf
	runConfigure ./configure \
		--with-curses
	make $jobArgs SHLIB_LIBS=-lncurses
}

INSTALL()
{
	make install

	rm $libDir/lib*.a

	mkdir -p $libDir/pkgconfig
	cp $sourceDir/readline.pc $libDir/pkgconfig/

	prepareInstalledDevelLibs libhistory libreadline
	rmdir $binDir
	fixPkgconfig

	# devel package
	packageEntries devel \
		$dataDir \
		$developDir \
		$documentationDir
}
