#!/bin/bash
#
# source: http://gtkspell.sourceforge.net/download/gtkspell-2.0.16.tar.gz
#
# maintainer: (package seek a maintainer)
#

soft="gtkspell"
softversion="2.0.16"
arch="i486"
cpu="i686"
packageversion="64.1"

buildir=$(pwd)
srcpkg="$buildir/$soft-$softversion.tar.gz"
src="$buildir/$soft-$softversion"
package="$soft-$softversion-$arch-$packageversion"
dest="$buildir/$package"

# -----------------Extract sources and get ready to build

cd $buildir
rm -rf $src
tar -xvzf $srcpkg
rm -f $dest.tgz
rm -rf $dest

cd $src
chown -R root:root .
find . \
 \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \;
export CFLAGS="-O2 -march=$arch -mtune=$cpu"
export CXXFLAGS="-O2 -march=$arch -mtune=$cpu"
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --mandir=/usr/man

make -j2
make install DESTDIR=$dest

find $dest | xargs file | grep -e "shared object" -e "executable" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

# Documentation

mkdir -p $dest/usr/doc/$soft-$softversion
cp -a \
  AUTHORS ChangeLog COPYING INSTALL README \
  $dest/usr/doc/$soft-$softversion

# Description file

mkdir -p $dest/install
cat << "EODESC" > $dest/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

        |-----handy-ruler------------------------------------------------------|
gtkspell: gtkspell - GtkSpell provides word-processor-styl
gtkspell:
gtkspell: tkSpell provides word-processor-style highlighting and replacement of
gtkspell: misspelled words in a GtkTextView widget. Right-clicking a misspelled
gtkspell: word pops up a menu of suggested replacements.
gtkspell: 
gtkspell: 
gtkspell: 
gtkspell: 
gtkspell: 
gtkspell:
EODESC

mkdir -p $dest/usr/src/$soft-$softversion
cp $buildir/build-$soft.sh $dest/usr/src/$soft-$softversion

# Packaging

cd $dest
makepkg -l y -c n $dest.txz
makepkg -l y -c n $dest.tgz
cd $buildir
md5sum $package.txz > $package.md5
