# Template build file for 'readline'.
pkgname=readline
_dist_ver=6.1
_patch_ver=001
version=${_dist_ver}.${_patch_ver}
revision=2
wrksrc=${pkgname}-${_dist_ver}
distfiles="http://ftp.gnu.org/gnu/readline/${pkgname}-${_dist_ver}.tar.gz"
build_style=gnu_configure
configure_args="--with-curses --enable-multibyte"
make_build_args="SHLIB_LIBS=-lncurses"
short_desc="The GNU Readline Library"
maintainer="Juan RP <xtraeme@gmail.com>"
checksum=f0caf608c06ccd6d56b3bee1843458d509c53f9b53dffffe07cc11d8f03fa969
long_desc="
 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."

subpackages="$pkgname-devel"
Add_dependency run	glibc
Add_dependency run	ncurses-libs
Add_dependency build	ncurses-devel
Add_dependency build	texinfo

pre_configure()
{
	local url="http://ftp.gnu.org/gnu/$pkgname/$pkgname-6.1-patches"

	if [ "${_patch_ver}" -gt 000 ]; then
		for p in $(seq -w 001 ${_patch_ver}); do
			cd ${XBPS_SRCDISTDIR} || return 1
			[ -f ${XBPS_SRCDISTDIR}/readline61-${p} ] && continue
			$XBPS_FETCH_CMD ${url}/readline61-$p
		done
	fi
	cd ${wrksrc}
	for p in $(seq -w 001 ${_patch_ver}); do
		patch -s -Np0 -i ${XBPS_SRCDISTDIR}/readline61-${p} && \
			msg_normal "Applying patch readline61-$p."
	done
	sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf
}

post_install()
{
	# Move shared libs to /.
	mkdir -p ${DESTDIR}/lib
	mv ${DESTDIR}/usr/lib/lib*.so.* ${DESTDIR}/lib
	chmod 755 ${DESTDIR}/lib/*.so*
	rm -f ${DESTDIR}/usr/lib/*.so
	for f in history readline; do
		cd ${DESTDIR}/usr/lib && \
                	ln -s ../../lib/lib${f}.so.6 lib${f}.so
	done
}