#!/bin/bash

# kofficei.SlackBuild
# Build KOffice internationalisation packages.
# Heavily based on the original Slackware build scripts for KDEi and koffice
# packages.
# Modified by Stuart Winter <stuart@armedslack.org>
# Please see changelog.txt for revisions to this package's build script history.

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

# The Package version is set in the <port>/build file.
# The KOFFICEVER is set below incase the version of KDE differs from the 
# name of the package version - although I'm not sure why that would be 
# at the moment (but usually it's for a 'dot release' or something).
export KOFFICEVER=1.6.3
export LC_ALL=C

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

# Temporary build locations:
# For this particular set of packages, inside $PKG we create sub directories for each individual
# KOffice package.
#
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

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

# Loop through the sources in the Slackware source tree and build them
# sequentially:
for file in $CWD/*.tar.bz2 ; do
  ( 
   # Determine the package name without the .tar.bz2 suffix:
   THISPKG=$(  basename $file -$KOFFICEVER.tar.bz2 )

   echo "**** Building KOffice internationalisation package: $THISPKG ****"

   # Extract source into temp build area:
   cd $TMPBUILD
   tar jxvvf $file
   cd ${THISPKG}*
   slackhousekeeping

    # Configure:
    ./configure \
       --prefix=/usr \
       --program-prefix="" \
       --program-suffix="" || failconfig

    # Build:
    make -i

    # Install into package:
    mkdir -p $PKG/$THISPKG/install
    make -i install DESTDIR=$PKG/$THISPKG

    # Install package description file:
    install -m644 $CWD/slack-desc/slack-desc.$THISPKG \
                  $PKG/$THISPKG/install/slack-desc

    # Apply generic Slackware packaging policies:
    cd $PKG/$THISPKG
    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
    slackhlinks     # search for any hard links

    # Determine the resulting binary package filename:
    SLACKPACKAGE=$THISPKG-$VERSION-$ARCH-$BUILD.tgz slackmp # run makepkg, substituting the package name from 'arm/build' with $THISPKG
  )
done
