#!/bin/bash

# aaa_elflibs.SlackBuild
# by Stuart Winter <stuart@armedslack.org> for the Slackware porting Project.
#
# This is an ugly and will incur timely maintainance.
# I thought about automatically trawling through Slackware's aaa_elflibs
# package but then I'd have to faff with version numbers if ARMedSlack has
# different versions (for what ever reason) to Slackware.
# If you have a ultra sexy way of rewriting this script then please let
# me know! 
# 
# Thinking about it, I probably shouldn't extract everything first then copy the
# libraries - I should probably extract and copy, clean up, rinse and repeat.
# but it works for the moment.
#
# 31-May-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PACKAGE
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete and re-create temporary directories

# The basic package framework:
mkdir -p $PKG/{lib,usr/lib}

# db1 & db2 don't build for ARM so they are excluded but
# they *should* be in this package.
# However, given that I'm not building anything that'll link against them,
# then they don't need to be included in ARMedslack's aaa_elflibs.
#
# I assume that db31 & db4 will be included within Slackware's package soon?
#l/db1-*.tgz
#l/db2-*.tgz
#

PACKAGES="a/bzip2-*.tgz
a/gpm-*.tgz
a/cups-*.tgz
d/gcc-[0-9]*.tgz
l/ncurses-*.tgz
l/libtermcap-*.tgz
l/db3-*.tgz
l/db4-*.tgz
l/expat-*.tgz
l/alsa-lib-*.tgz
l/gdbm-*.tgz
l/glib2-*.tgz
l/gmp-*.tgz
l/libjpeg-*.tgz
l/libpng-*.tgz
l/libtiff-*.tgz
l/libusb-*.tgz
l/ncurses-*.tgz
l/pcre-*.tgz
l/popt-*.tgz
l/readline-*.tgz
l/svgalib-*.tgz
l/slang-*.tgz
l/zlib-*.tgz
n/curl-*.tgz
x/x11-devel-*.tgz
x/x11-[0-9]*.tgz"
# ../testing/packages/gcc-3.3.x/gcc-3*.tgz"

# Iterate through the list and extract them into the temporary dir:
for i in ${PACKAGES}; do
  if [ -s $PKGSTORE/$i ]; then
     echo "Extracting package $PKGSTORE/$i"
     tar zxvvf $PKGSTORE/$i lib usr/lib install
     echo -n "Please wait - running install script"
     ( bash install/doinst.sh ) > /dev/null 2>&1 # we want the symlinks too
     echo " ... done"
   else
     echo "** WARNING: $PKGSTORE/$i not found **"
     sleep 5
 fi
done

# Grab the .sos and symlinks.
# We don't want to copy *everything* out of the packages - only
# a few select things.
# Deal with /lib:
( cd lib

  # a/bzip2:
  cp -af libbz2*.so* $PKG/lib/

  # a/gpm:
  cp -fa libgpm*.so* $PKG/lib

  # l/db*:
  cp -fa libdb*.so* $PKG/lib

  # l/ncurses:
  cp -fa libncurses*.so* $PKG/lib

  # l/libtermcap:
  cp -fa libtermcap*.so* $PKG/lib
)

# /usr/lib
( cd usr/lib

  # a/cups
  cp -fa libcups*.so* $PKG/usr/lib

  # l/alsa-lib:
  cp -fa libasound*.so* $PKG/usr/lib

  # d/gcc #  & testing/packages-gcc-3.3.x: - no because the libgcc names are identical
  cp -fa libgcc_s*.so* $PKG/usr/lib

  # l/expat:
  cp -fa libexpat*.so* $PKG/usr/lib

  # l/libgdbm:
  cp -fa libgdbm*.so* $PKG/usr/lib

  # l/glib2:
  cp -fa libglib*.so* libgmodule*.so* libgobject*.so* libgthread*.so* $PKG/usr/lib

  # l/gmp:
  cp -fa libgmp*.so* libmp*.so* $PKG/usr/lib

  # l/libgr:
  # cp -fa libfbm*.so* libpbm*.so* libpgm*.so* libpnm*.so* libppm*.so* librle*.so* $PKG/usr/lib

  # l/libjpeg:
  cp -fa libjpeg*.so* $PKG/usr/lib

  # l/libpng:
  cp -fa libpng*.so* $PKG/usr/lib

  # l/libtiff:
  cp -fa libtiff*.so* $PKG/usr/lib

  # l/libusb:
  cp -fa libusb*.so* $PKG/usr/lib

  # l/ncurses:
  cp -fa libform*.so* libmenu*.so* libpanel*.so* $PKG/usr/lib

  # l/pcre:
  cp -fa libpcre*.so* $PKG/usr/lib

  # l/popt:
  cp -fa libpopt*.so* $PKG/usr/lib

  # l/readline:
  cp -fa libhistory*.so* libreadline*.so* $PKG/usr/lib

  # l/svgalib:
  cp -fa libvga*.so* $PKG/usr/lib

  # l/slang:
  cp -fa libslang*.so* $PKG/usr/lib

  # l/zlib:
  cp -fa libz*.so* $PKG/usr/lib

  # n/curl:
  cp -fa libcurl*.so* $PKG/usr/lib

  # x/x11-6.7.0: (used to be xfree86-4.3.0)
  cp -fa libfreetype*.so* $PKG/usr/lib
)

# Special hacks:
# For Oracle 10g RAC support.  Yes - you're not going to get Oracle on ARMedslack
# but Slackware has this symlink now, so we'll have it too:
( cd $PKG/lib
  for i in ../usr/lib/libgcc* ; do
        ln -vvfs $i .
  done )

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Slackware policies:
cd $PKG
slackslack      # set all files to root.root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   slackmp # run makepkg
  else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links

echo "Now run a pkgdiff against Slackware's & ARMedslack's package"

