#! /bin/sh

#
# $Header: /home/gene/src/critters/RCS/subcp.in,v 4.1 2003/06/02 05:22:41 gene Exp $
#
# Null compiler.  Copies a shell script source file to a
# destination file, making some text symbol substitutions
# and making the result executable.
#

rc=0

if test $# -ne 2
then
    echo subcp: Copy and substitute.
    echo Usage: subcp SRC DST
    exit 2
fi

SRC=$1
DST=$2

date=`date "+%A, %d %B %Y"`
version=`cat version`

prefix=/usr/local
exec_prefix=${prefix}
datadir=${prefix}/share
libdir=${exec_prefix}/lib
infodir=${prefix}/info
includedir=${prefix}/include
mandir=${prefix}/man
man1dir=${mandir}/man1
man2dir=${mandir}/man2
manext=.1
srcdir=.

DSTDIR=`echo $DST |sed -e "s,/[^/]*$,,"`
if test -d $DSTDIR; then
    :                                   # dst dir exists
elif mkdir -p $DSTDIR; then
    :                                   # didn't exist, but created ok
else
    echo error: can\'t create destination directory, \"$DSTDIR\"
    exit 1
fi

if sed -e "s/[@]date[@]/$date/g
           s/[@]version[@]/$version/g
           s,[@]CLISP[@],/usr/local/bin/clisp,g
           s,[@]JAVA[@],@JAVA@,g
           s,[@]JAVAC[@],@JAVAC@,g
           s,[@]JAR[@],@JAR@,g
           s,[@]PERL[@],@PERL@,g
           s,[@]libdir[@],$libdir,g
           s,[@]prefix[@],$prefix,g
	   s,[@]datadir[@],$datadir,g
           s,gene@CyberTiggyr.COM,gmb@CyberTiggyr.COM,g" \
   $SRC >$DST
then
    if chmod 644 $DST; then
        :
    else
        echo subcp: chmod error
        rc=1
    fi
else
    echo subcp: sed error
    rc=1
fi
exit $rc

# --- end of file ---
