#!/bin/bash

# gnome-icon-theme.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <mozes@slackware.com>
# Please see changelog.txt for revisions to this package's build script history.

# Record toolchain & other info for the build log:
slackbuildinfo

# 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 & re-create temporary directories then cd into $TMPBUILD

SYMVERS=3.8.3  # gnome-icon-theme-symbolic version
EXTRAVERS=3.6.2 # gnome-icon-theme-extras version

# Determine the CFLAGS for the known architectures:
case $ARCH in
   arm)     export SLKCFLAGS="-O2 -march=armv5te"
            export LIBDIRSUFFIX="" ;;
   *)       export SLKCFLAGS="-O2" ;;
esac 

for ICONPKG in gnome-icon-theme-$VERSION gnome-icon-theme-symbolic-$SYMVERS gnome-icon-theme-extras-$EXTRAVERS ; do
  tar xvf $CWD/$ICONPKG.tar.?z* || exit 1
  cd $ICONPKG || exit 1
  slackhousekeeping

  if [ $ICONPKG = gnome-icon-theme-symbolic-$SYMVERS ]; then
    zcat $CWD/fix_gits_configure.diff.gz | patch -p1 || exit 1
  fi

  # Configure:
  ./configure \
    --prefix=/usr \
    --libdir=/usr/lib${LIBDIRSUFFIX} \
    --sysconfdir=/etc \
    --enable-icon-mapping \
    --localstatedir=/var/lib || exit 1

  # Build:
  make $NUMJOBS || make || exit 1

  # Install into package:
  make install DESTDIR=$PKG || exit 1

  # Add documentation:
  mkdir -p $PKG/usr/doc/$ICONPKG
  cp -a \
    AUTHORS COPYING* NEWS README* TODO \
    $PKG/usr/doc/$ICONPKG
  if [ -r ChangeLog ]; then
    cat ChangeLog | head -n 1000 > $PKG/usr/doc/$ICONPKG/ChangeLog
    touch -r ChangeLog $PKG/usr/doc/$ICONPKG/ChangeLog
  fi
  cd ..
done

# It's a bad idea to ship these in the packages.  If they aren't kept
# updated, there will be missing icons.  Let the user create them if
# they care to.
find $PKG -name icon-theme.cache -exec rm "{}" \;

# 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
