#!/bin/sh
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-pkgconfig
rm -rf $PKG
mkdir -p $PKG/usr

VERSION=0.93.94
ARCH=${ARCH:-i486}
BUILD=1

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "alpha" ]; then
  SLKCFLAGS="-O2 -mcpu=ev4"
fi

cd $TMP
tar xjvf $CWD/lesstif-$VERSION.tar.bz2
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 {} \;

CFLAGS=$SLKCFLAGS \
./configure --enable-shared \
            --enable-static \
            --enable-build-21 \
            --enable-build-Xlt \
            --enable-build-Xbae \
            --enable-xbae-24bit \
            --enable-xbae-row-heights \
            --disable-debug \
            --enable-production \
            --prefix=/usr/X11R6 \
            $ARCH-slackware-linux
make
# I'm taking these out to see if anyone cares
#            --enable-build-12
#            --enable-build-20
# rm -rf /etc/X11/mwm /usr/X11R6/lib/X11/mwm
# I know this is destructive, but that's the way the cookie crumbles:
# rm -f /usr/X11R6/lib/X11/config/host.def
make install DESTDIR=$PKG
( cd $PKG/usr/doc ; rm -rf lesstif-$VERSION ; ln -sf /usr/X11R6/LessTif lesstif-$VERSION )
mkdir -p $PKG/usr/X11R6/lib/X11/config
cp -a $PKG/usr/X11R6/lib/LessTif/config/* $PKG/usr/X11R6/lib/X11/config
( cd $PKG/usr/X11R6/lib/X11/config ; mv host.def host.def-lesstif )
( cd $PKG/usr/X11R6/lib/X11 ; cp -a mwm $PKG/etc/X11 ; rm -rf mwm ; ln -sf ../../../../etc/X11/mwm . )
# Look out for this one, too:
rm -rf $PKG/install
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 ../lesstif-$VERSION-$ARCH-$BUILD.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  cd $CWD
  rm -rf $TMP/lesstif-$VERSION
  rm -rf $PKG
fi

