#! /bin/sh

#
# $Header: /home/gene/src/lisp-script/RCS/make-dist,v 1.1 2004/03/24 06:36:35 gene Exp $
#
# Copyright (C) 2001  Gene Michael Stover.  All rights reserved.
# 
# This library is free software; you can redistribute it
# and/or modify it under the terms of version 2.1 of the GNU
# General Public License as published by the Free
# Software Foundation.
# 
# This library is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
# 
# You should have received a copy of the GNU General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
# 

RC=0

kitname=`cat kitname`
version=`cat version`

if test x$1 = x-h || test x$1 = x--help; then
    cat <<EOF
Usage: make-dist

Creates two distribution files.  One is a gzipped tar file (.tar.gz).
The other, a bzip2'ed, cpio file (.cpio.bz2).  cpio & bzip2 are not as
not as common as tar & gzip, so it is possible the cpio archive will
fail on your system.

Assumes that everything in the directory will become part of the
distribution archive.  The proper way to assure that this is so is
to run "make distclean" before you run make-dist.
EOF
else
    if mkdir ../$kitname-$version; then
        chmod 770 ../$kitname-$version
        if make-manifest |cpio -o -Hnewc |(cd ../$kitname-$version; cpio -id)
        then
            find ../$kitname-$version -type d -exec chmod u+w {} \; -o -exec chmod u+w {} \;
            saved_dir=`pwd`

            cd ..
            find $kitname-$version -print |cpio -o -Hnewc |bzip2 -9 >$kitname-$version.cpio.bz2
            tar cf - $kitname-$version |gzip -9 >$kitname-$version.tar.gz

            cd $saved_dir
        else
            echo error: Can\'t copy the current source tree \(`pwd`\) to the temporary directory \(../$kitname-$version\).
            echo Maybe there\'s a problem with cpio\?  With make-manifest\?
            echo With the permissions on the temporary directory\?
            RC=1
        fi
#        if test 0 -eq $RC
#        then
#            if rm -r ../$kitname-$version
#            then
#                :
#            else
#                echo error: Can\'t remove temporary directory \(../$kitname-$version\).
#                echo In case it matters, the current directory is `pwd`.
#                RC=1
#            fi
#        fi
    else
        echo error: Can\'t create temporary directory, \"../$kitname-$version\".
        RC=1
    fi
fi

exit $RC

# --- end of file ---
