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

mkdir -p $PKG/usr
( cd $TMP
tar xjf $CWD/mc-$VERSION.tar.bz2
cd mc-$VERSION
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
zcat $CWD/mc.cvsfixes.diff.gz | patch -p1
CFLAGS="-O3" ./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --enable-charset \
 --with-gpm-mouse \
 --with-ext2undel \
 --with-x=no \
 --with-vfs \
 --with-mcfs \
 --with-screen=mcslang \
 $TARGET
make
make DESTDIR=$PKG install
# Update PHP syntax file: 
zcat $CWD/php.syntax.gz > $PKG/usr/share/mc/syntax/php.syntax
( 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/profile.d
cat $PKG/usr/share/mc/bin/mc.csh > $PKG/etc/profile.d/mc.csh
cat $PKG/usr/share/mc/bin/mc.sh > $PKG/etc/profile.d/mc.sh
chmod 644 $PKG/etc/profile.d/*
strip $PKG/usr/bin/mc $PKG/usr/lib/mc/cons.saver $PKG/usr/bin/mcmfmt $PKG/usr/sbin/mcserv
chown -R root.bin $PKG/usr/bin $PKG/usr/sbin
( cd $PKG/usr/man
  find . -name "*.?" -type f | xargs gzip -9 )
mkdir -p $PKG/usr/doc/mc-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING FAQ INSTALL INSTALL.FAST MAINTAINERS NEWS README* $PKG/usr/doc/mc-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/mc-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/mc.build.log
