#!/bin/sh

VERSION=4.6.0
ARCH=i386
BUILD=1

PKG=/tmp/package-mc
rm -rf $PKG
mkdir -p $PKG/usr
CWD=`pwd` 
cd /tmp
tar xjvf $CWD/mc-$VERSION.tar.bz2
cd mc-$VERSION
chown -R root.root .
#find . -perm 666 | xargs chmod 644
find . -perm 664 | xargs chmod 644
find . -perm 777 | xargs chmod 755
find . -perm 775 | xargs chmod 755
# This is obsolete:
# ( cd vfs/samba ; zcat $CWD/samba.codepages.diff.gz | patch -p0 )
# To enable samba, I believe these are the options to use:
# --with-samba \
# --with-configdir=/etc/samba \
# --with-codepagedir=/etc/codepages \
#
# Using --with-included-slang seems to be the magic incantation that builds
# a clean, small mc like days of yore
CFLAGS="-O2 -march=i386 -mcpu=i686" ./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --enable-charset \
 --with-gpm-mouse \
 --with-ext2undel \
 --with-x=no \
 --with-vfs \
 --with-screen=mcslang \
 i386-slackware-linux
# Removed due to bug reports.  Does anyone use this feature?
# Will it be missed?  complain to: volkerdi@slackware.com
#	    --with-samba
make
make DESTDIR=$PKG install
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 755 $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

# Build package:
cd $PKG
makepkg -l y -c n ../mc-$VERSION-$ARCH-$BUILD.tgz