#!/bin/bash

# cxxlibs.SlackBuild
# by Stuart Winter <mozes@slackware.com> for ARMedSlack
#
# 31-May-2004

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

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

# The basic package framework:
#mkdir -p $PKG/{lib,usr/lib,usr/$ARCH-slackware-linux-gnueabi/lib}
# I don't know why I included the arm-slackware-linux-gnueabi/lib dir!
mkdir -vpm755 $PKG/{lib,usr/lib}

# ARMedslack-11.0 says:
# Because ARMedslack builds with both gcc 3.4 (mainly, where it'll compile
# without *tonnes* of patches) and gcc 3.x, we have to include libraries
# from both packages c++ packages:
# 
# But for 12.0, we don't ship gcc3 anymore.  However, for this 12.0 release we
# will continue to carry the older libstdc++ version because there are some
# ancient packages still; I expect in 12.1 they will be recompiled.
PACKAGES="d/gcc-g++-*.t?z"
#../testing/packages/gcc-3.3.x/gcc-g++-*.tgz"

# Iterate through the list and extract them into the temporary dir:
for i in ${PACKAGES}; do
  echo "Extracting package $PKGSTORE/$i"
  tar xvvf $PKGSTORE/$i 
  echo -n "Please wait - running install script"
  ( bash install/doinst.sh ) > /dev/null 2>&1 # we want the symlinks too
  echo " ... done"
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
  cp -fav libstdc++*.so* $PKG/lib )

# /usr/lib
( cd usr/lib
  cp -fav libstdc++*.so* $PKG/usr/lib
  # That's it at the moment!  There's not a lot in gcc-g++-3.4 to copy.
  # Unless I've broken the gcc-g++-3.4 package.. hmm. Best check that :-)
)

# If there aren't any c++ libraries in /lib, then we can wipe the empty
# /lib directory from the package:
rmdir $PKG/lib

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

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # run makepkg -l y -c n

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