#!/bin/sh
# Build ncurses for Slackware
# by Patrick Volkerding <volkerdi@slackware.com>, 11/2000.
# Updated for ncurses-5.3, 2003-01.
# v5.4, 2004-02.

VERSION=5.4
ARCH=i486
BUILD=2

ncurses_configure() {
./configure \
  --prefix=/usr \
  --with-gpm \
  --disable-termcap \
  --with-normal \
  --with-shared \
  --enable-symlinks \
  --without-debug \
  --without-profile \
  --without-ada \
  --program-prefix="" \
  $WIDEC \
  $ARCH-slackware-linux
}

CWD=`pwd`
PKG=/tmp/package-ncurses
rm -rf $PKG
mkdir -p $PKG
cd /tmp
rm -rf ncurses-$VERSION
tar xzvf $CWD/ncurses-$VERSION.tar.gz
cd ncurses-$VERSION
chown -R root.root .
ncurses_configure
make
# Spamming the partition.  Sorry, but it's about the only way to get a good 'tic'.
make install
# Install the package:
make install DESTDIR=$PKG
# Build/install again with wide character support:
make clean
WIDEC=--enable-widec
ncurses_configure
make
make install
make install DESTDIR=$PKG

# Strip stuff:
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

chown -R root.bin $PKG/usr/bin

# Move the include files from /usr/include into
# /usr/include/ncurses, then make symlinks back
# into /usr/include.
( cd $PKG/usr/include
  rm -rf ncurses
  mkdir ncurses
  mv *.h ncurses
  for file in ncurses/* ; do
    ln -sf $file .
  done
  # This shouldn't clobber the real one:
  rm termcap.h
)

# Move the ncurses libraries into /lib, since they're important:
mkdir -p $PKG/lib
( cd $PKG/usr/lib
  chmod 755 *.so
  chmod 644 *.a
  mv libncurses.so.5* $PKG/lib
  mv libncursesw.so.5* $PKG/lib
  rm -f libncurses.so
  ln -sf /lib/libncurses.so.5 libncurses.so
  rm -f libncursesw.so
  ln -sf /lib/libncursesw.so.5 libncursesw.so
  # Olde obsolete names, just in case
  rm -f libcurses.so
  ln -sf libncurses.so libcurses.so
  rm -f libcursesw.so
  ln -sf libncursesw.so libcursesw.so
)

# Thomas Dickey wrote to ask me why we do this, since --enable-symlinks already
# makes symlinks.  This was about a year ago, 1/2001 or so, and at the time I
# couldn't remember. :)  Well, now I do, so I'll document it here.  It's so that the
# symlinks are all freshly created so my package scanning scripts find all the links.
# If any of them already existed, they might not be picked up.
# [obsolete as of 2004-02 since the build script was rewritten as a SlackBuild ]
#( cd / ; sh $CWD/terminfo.link.sh )

# Set TERMINFO to point to the package:
export TERMINFO=$PKG/usr/share/terminfo

# Fix the xterm entries:
if [ -r /usr/X11R6/lib/X11/etc/xterm.terminfo ]; then
  progs/tic -v /usr/X11R6/lib/X11/etc/xterm.terminfo
else
  echo "WARNING: /usr/X11R6/lib/X11/etc/xterm.terminfo not found"
  sleep 470
fi

# Update screen entry:
progs/tic -v $CWD/screeninfo.src

# Update rxvt entry:
progs/tic -v $CWD/rxvt.terminfo

# Update Eterm entry:
progs/tic -v $CWD/Eterm.ti

unset TERMINFO

# Then, add /usr/doc/ncurses-xxxxx with appropriate files.
mkdir -p $PKG/usr/doc/ncurses-$VERSION
cp -a \
  ANNOUNCE INSTALL MANIFEST NEWS README* TO-DO \
  $PKG/usr/doc/ncurses-$VERSION
mkdir -p $PKG/usr/doc/ncurses-$VERSION/c++
cp -a \
  c++/NEWS c++/PROBLEMS c++/README-first \
  $PKG/usr/doc/ncurses-$VERSION/c++
if [ -r $PKG/usr/man/man1/tack.1 ]; then
  gzip -9 --force $PKG/usr/man/man1/tack.1
fi

# desc file:
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n ../ncurses-$VERSION-$ARCH-$BUILD.tgz