#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-lesstif
VERSION=0.95.2
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf lesstif-$VERSION
tar xf $CWD/lesstif-$VERSION.tar.gz
cd lesstif-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --enable-shared \
 --enable-static \
 --enable-build-Xlt \
 --enable-build-Xbae \
 --enable-xbae-24bit \
 --enable-build-21 \
 --enable-xbae-row-heights \
 --disable-debug \
 --enable-production \
 --build=$TARGET
make || exit 1
make install DESTDIR=$PKG || exit 1
chown -R root.bin $PKG/usr/bin

( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

mkdir -p $PKG/usr/doc
( cd $PKG/usr ; mv LessTif ../usr/doc/lesstif-$VERSION )

# Move LessTif's Imake files into place:
mkdir -p $PKG/usr/lib/X11
mv $PKG/usr/lib/LessTif/config $PKG/usr/lib/X11
rm -rf $PKG/usr/lib/LessTif

mkdir -p $PKG/etc/X11                                                                                                                                                                                                                       
mv $PKG/usr/lib/X11/app-defaults $PKG/etc/X11                                                                                                                                                                                               
mv $PKG/usr/lib/X11/mwm $PKG/etc/X11                                                                                                                                                                                                        
( cd $PKG/usr/lib/X11 ; ln -sf ../../../etc/X11/mwm . )                                                                                                                                                                                     

gzip -9 $PKG/usr/man/man?/*.?

mkdir $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n $TMP/lesstif-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/lesstif.build.log
