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

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf fvwm-$VERSION
tar xjf $CWD/fvwm-$VERSION.tar.bz2
cd fvwm-$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/X11R6 \
  --sysconfdir=/etc/X11/fvwm2 \
  --enable-extras \
  $TARGET
make
make install DESTDIR=$PKG
gzip -9 $PKG/usr/X11R6/man/man1/*
chown -R root.bin $PKG/usr/X11R6/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/fvwm-$VERSION
cp -a AUTHORS COPYING INSTALL INSTALL.fvwm README docs sample.fvwmrc $PKG/usr/doc/fvwm-$VERSION
rm -f \
  $PKG/usr/doc/fvwm-$VERSION/docs/ChangeLog \
  $PKG/usr/doc/fvwm-$VERSION/docs/NEWS \
  $PKG/usr/doc/fvwm-$VERSION/docs/Makefile* \
  $PKG/usr/doc/fvwm-$VERSION/sample.fvwmrc/Makefile*
mkdir -p $PKG/usr/X11R6/include/X11/pixmaps
# Add all the old icons that have fallen through the cracks:
( cd $PKG ; tar xzf $CWD/ancient-icons.tar.gz )
mkdir -p $PKG/etc/X11/xinit
zcat $CWD/xinitrc.fvwm2.gz > $PKG/etc/X11/xinit/xinitrc.fvwm2
chmod 755 $PKG/etc/X11/xinit/xinitrc.fvwm2
mkdir -p $PKG/etc/X11/fvwm2
zcat $CWD/system.fvwm2rc.gz > $PKG/etc/X11/fvwm2/system.fvwm2rc.new
mkdir -p $PKG/usr/X11R6/lib/X11
( cd $PKG/usr/X11R6/lib/X11 && ln -sf ../../../../etc/X11/fvwm2 fvwm2 )
( cd $PKG/usr/X11R6/man/man1 ; rm -rf fvwm-root.1 )
( cd $PKG/usr/X11R6/man/man1 ; ln -sf xpmroot.1.gz fvwm-root.1.gz )
mkdir -p $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/fvwm-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/fvwm.build.log
