#!/bin/bash

softversion='2.3.1'
packageversion='2vl5.9'
softname='xdialog'

arch='i586'
cpu='i686'

buildir=$(pwd)

srcpkg="$buildir/Xdialog-$softversion.tar.bz2"
src="$buildir/Xdialog-$softversion"

package="$softname-$softversion-$arch-$packageversion"

dest="/tmp/$package"


cd $buildir
rm -rf $src
tar -xvf $srcpkg
rm -f $dest.tgz
rm -rf $dest
mkdir -p $dest
chown -R root:root .
export CFLAGS="-O2 -march=$arch -mtune=$cpu"

cd $src
patch -p1 < ../xdialog-2.3.1-gtk2.patch
./configure --prefix=/usr --sysconfdir=/etc --with-gtk2
make DESTDIR=$dest
make install DESTDIR=$dest

mkdir -p $dest/usr/doc/$softname-$softversion
cp -a  \
  ABOUT-NLS AUTHORS BUGS COPYING ChangeLog INSTALL doc\
  $dest/usr/doc/$softname-$softversion



( cd $dest
  find . | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
)

gzip -9 $dest/usr/man/man?/*

# redundant
rm -rf $dest/usr/share/doc

# Description file
mkdir -p $dest/install

cat << "EODESC" > $dest/install/slack-desc
xdialog: Xdialog is a bash GTK GUI binding
xdialog:
xdialog: Xdialog is a GTK version of the "dialog" ncurses GUI binding.
xdialog: It allows any bash program to display GTK widgets.
xdialog: (e.g. with the treeview, the file selector, the edit box, the range
xdialog: box, the help button/box). Because Xdialog uses GTK, it will  also
xdialog: match your desktop theme.
xdialog:
xdialog:
xdialog:
xdialog:
EODESC

mkdir -p $dest/usr/src/$softname-$softversion
cp $buildir/build-$softname.sh $dest/usr/src/$softname-$softversion
cp $buildir/xdialog-2.3.1-gtk2.patch $dest/usr/src/$softname-$softversion

cd $dest
makepkg -l y -c n $dest.tlz

# cleanup

rm -rf $dest
rm -rf $src



