#!/bin/sh
#
# This script builds the expander kit. It is meant to be called from the
# kit's Makefile, not as a standalone element.

location=`basename $PWD`

if [ "$location" != "expander" ]; then
    echo "Must be in 'expander' directory to build expander kit."
else
    invokedBy=`basename $1`
    
    if [ "$invokedBy" != "make" ]; then
        echo "This script should only be invoked by the command 'make kit'"
        exit 1
    fi
    
    shift;        
    KIT=$1; shift
    EXP=$1; shift
    FILES="$*"
    
    #-------------------------------------------------------------------
    # To build proper archive requires parent to be working directory.
    # Number for most recent version of archive is located in ChangeLog.
    #-------------------------------------------------------------------
    cd ..
    version=`grep "^[0-9]" ${EXP}ChangeLog | head -1 | sed -e 's/[ \t].*//'` 
    KIT="${KIT}_${version}" 
    echo "  ... Creating archive ${KIT}.tar"
    
    #-----------------------------------------------------------------
    # Making NEdit expander kit, archive, compress, encode for mail...
    #-----------------------------------------------------------------    
    tar -chf ${EXP}${KIT}.tar ${FILES}
    echo "  ... Compressing into ${KIT}.tar.gz"
    gzip -c  ${EXP}${KIT}.tar > ${EXP}${KIT}.tar.gz
    echo "  ... Encoding into    ${KIT}.uu"
    uuencode ${EXP}${KIT}.tar.gz ${KIT}.tar.gz >${EXP}${KIT}.uu
    echo
fi
