#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-module-init-tools
VERSION=3.1
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

mkdir -p $PKG
( cd $TMP
rm -rf module-init-tools-$VERSION
tar xjf $CWD/module-init-tools-$VERSION.tar.bz2
cd module-init-tools-$VERSION
find . -perm 664 | xargs chmod 644
chown -R root.root .
./configure --prefix=/ --enable-zlib $TARGET
make -i
make -i install DESTDIR=$PKG
( cd $PKG/bin ; ln -sf $TARGET-lsmod lsmod )
( cd $PKG/sbin ; ln -sf /bin/lsmod . )
( cd $PKG/sbin ; ln -sf $TARGET-depmod depmod )
( cd $PKG/sbin ; ln -sf $TARGET-insmod insmod )
( cd $PKG/sbin ; ln -sf $TARGET-insmod.static insmod.static )
( cd $PKG/sbin ; ln -sf $TARGET-modinfo modinfo )
( cd $PKG/sbin ; ln -sf $TARGET-modprobe modprobe )
( cd $PKG/sbin ; ln -sf $TARGET-rmmod rmmod )
( cd $PKG/sbin ; ln -sf $TARGET-generate-modprobe.conf generate-modprobe.conf )
( gzip -9 $PKG/usr/share/man/man{5,8}/* )
( cd $PKG/usr/share/man/man5 ; ln -sf $TARGET-modprobe.conf.5.gz modprobe.conf.5.gz)
( cd $PKG/usr/share/man/man5 ; ln -sf $TARGET-modules.dep.5.gz modules.dep.5.gz)
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-depmod.8.gz depmod.8.gz )
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-insmod.8.gz insmod.8.gz )
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-lsmod.8.gz lsmod.8.gz )
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-rmmod.8.gz rmmod.8.gz )
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-modprobe.8.gz modprobe.8.gz )
( cd $PKG/usr/share/man/man8 ; ln -sf $TARGET-modinfo.8.gz modinfo.8.gz )
chown -R root.bin $PKG/bin $PKG/sbin
# Strip things:
( 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/etc/cron.hourly
zcat $CWD/kmod.gz > $PKG/etc/cron.hourly/kmod
chmod 755 $PKG/etc/cron.hourly/kmod
touch $PKG/etc/modules.conf.new
touch $PKG/etc/modprobe.conf.new
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cd $PKG
makepkg -l y -c n $TMP/module-init-tools-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/module-init.build.log
