pkgname=readline
_patchlevel=004 #prepare for some patches
pkgver=6.0.$_patchlevel
pkgrel=2
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.0.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.0-patches/readline60-$p)
  done
fi
md5sums=('b7f65a48add447693be6e86f04a63019'
         'e5fc955f56d9fa5beb871f3279b8fa8b'
         '85c01ea031ad38a179053c67186bafed'
         '4fad2a4ce987e3101229d0c8dfb0cd80'
         '80967f663864983a889af2eb53aea177'
         'dd5dd5ff7f7229714bf1c2e274ad2ae9')

build() {
  cd ${srcdir}/${pkgname}-6.0
  
  for p in ../readline60-*; 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.0
  
  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:
