#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-automake

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_automake.tar.gz

# Find the size of a file:
filesize() {
 SIZE=`ls -l -d -G $1 | cut -b23-32`
 echo -n $SIZE
}

echo "+==============+"
echo "| automake-1.4 |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/automake-1.4.tar.gz
cd automake-1.4
./configure --prefix=/usr
make
for file in automake aclocal ; do
  cat $file > $PKG/usr/bin/$file
done
for n in *.info* ; do
  gzip -9c $n > $PKG/usr/info/$n.gz
done
for file in COPYING INSTALL texinfo.tex ansi2knr.c ansi2knr.1 clean-hdr.am \
clean-kr.am clean.am comp-vars.am compile.am data-clean.am data.am \
dejagnu.am depend.am depend2.am dist-vars.am footer.am header-vars.am \
header.am java-clean.am java.am kr-extra.am library.am libs-clean.am \
libs.am libtool.am lisp-clean.am lisp.am ltlib-clean.am ltlib.am \
ltlibrary.am mans-vars.am mans.am multilib.am program.am progs-clean.am \
progs.am remake-hdr.am remake.am scripts.am subdirs.am tags-clean.am \
tags.am texi-vers.am texinfos.am config.guess config.sub install-sh \
mdate-sh missing mkinstalldirs elisp-comp ylwrap acinstall ; do
  cp -a $file $PKG/usr/share/automake
  chown root.root $PKG/usr/share/automake/$file
done
for file in m4/*.m4 ; do
  cat $file > $PKG/usr/share/aclocal/`basename $file`
done
mkdir -p $PKG/usr/doc/automake-1.4
cp -a AUTHORS COPYING INSTALL NEWS README THANKS \
    TODO $PKG/usr/doc/automake-1.4
chown root.root $PKG/usr/doc/automake-1.4/*

# Build the package:
cd $PKG
tar czvf $TMP/automake.tgz .

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

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