pkgname=readline
_patchlevel=001 #prepare for some patches
pkgver=6.2.$_patchlevel
pkgrel=1
pkgdesc="GNU readline library"
arch=('i686' 'x86_64')
url="http://tiswww.case.edu/php/chet/readline/rltop.html"
license=('GPL')
groups=('base')
depends=('glibc' 'ncurses')
backup=("etc/inputrc")
source=("http://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz"
        'inputrc')
if [ $_patchlevel -gt 00 ]; then
  for p in $(seq -w 01 $_patchlevel); do
    source=(${source[@]} http://ftp.gnu.org/gnu/readline/readline-6.2-patches/readline62-$p)
  done
fi
md5sums=('67948acb2ca081f23359d0256e9a271c'
         'e5fc955f56d9fa5beb871f3279b8fa8b'
         '83287d52a482f790dfb30ec0a8746669') 

build() {
  cd ${srcdir}/${pkgname}-6.2
  
  for p in ../readline62-*; do
    [ -e "$p" ] || continue
    msg "applying patch ${p}"
    patch -Np0 -i ${p} || return 1
  done
  
  # Remove RPATH from shared objects (FS#14366)
  sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf || return 1
  
  # build with -fPIC for x86_64 (FS#15634)
  [ $CARCH == "x86_64" ] && CFLAGS="$CFLAGS -fPIC"
  
  ./configure \
    --prefix=/usr \
    --libdir=/lib \
    --mandir=/usr/share/man \
    --infodir=/usr/share/info || return 1
  
  make SHLIB_LIBS=-lncurses || return 1
}

package() {
  cd ${srcdir}/${pkgname}-6.2
  
  make DESTDIR=${pkgdir} install || return 1
  
  mkdir -p ${pkgdir}/etc || return 1
  install -m644 ../inputrc ${pkgdir}/etc/inputrc || return 1
  #FHS recommends only shared libs in /lib
  mkdir -p $pkgdir/usr/lib || return 1
  mv $pkgdir/lib/*.a $pkgdir/usr/lib || return 1
  
  # to make the linker find the shared lib and fix compile issues
  cd ${pkgdir}/usr/lib || return 1
  ln -sv /lib/libreadline.so . || return 1
  ln -sv /lib/libhistory.so . || return 1
  
  rm -f ${pkgdir}/usr/share/info/dir || return 1
}

# vim:set ts=2 sw=2 et:
