manrequest=		#attempt to make a manual for compilers
listrequest=		#list the tar file after creating it
seenlanguage=		#have seen language
host=`cat HOSTNAME`	#use binaries which run on an x
binlist=		#list of front ends (ccom,pcom etc)
targlist=		#list of code gens
sourcelist=		#list of source directories
uucp=			#uucp to this system when done
presson=		#make tape even if there are files missing
wantsource=
wantbin=1
wantunlinked=
tarfile=/dev/rmt8
process=
wantxdev=
wantlibsource=
wantunixlib=
wanttestgen=
testlist=
FILES=			#final list of files to be tarred
CCSRC="ccini.p ccdec.p ccexp.p cclst.p ccpro.p ccscn.p ccsta.p ccerr.c ccmak.p cc.h"
CCOBJS="ccini.o ccdec.o ccexp.o cclst.o ccpro.o ccscn.o ccsta.o ccerr.o"
PASSRC="pasini.p pasdec.p pasexp.p paslst.p paspro.p passcn.p passta.p paserr.c pasmak.p pas.h"
PASOBJS="pasini.o pasdec.o pasexp.o paslst.o paspro.o passcn.o passta.o paserr.o"
FORSRC="forini.p fordec.p forexp.p forlst.p forpro.p forscn.p forsta.p forerr.c formak.p for.h"
FOROBJS="forini.o fordec.o forexp.o forlst.o forpro.o forscn.o forsta.o forerr.o"
INDEPSRC="indeplst.p indep.p indepopt.p indeploop.p indepcod.p indephost.p indeprt.c indepstab.p indepieee.c indepcse.p indepsym.p indeptarg.p indep.h indepcg.h indepddo.h indephost.h indepieee.h indepmac.h indeptarg.h indeptyp.h indeptypes.h nindeptarg.h types.h"
INDEPOBJS="indeplst.o indep.o indepopt.o indeploop.o indepcod.o indephost.o indeprt.o indepstab.o indepieee.o indepcse.o indepsym.o"
C32SRC="c32.p c32a.p c32b.p c32peep.p c32i.p c32p.p c32u.p c32case.p c32stab.p c32ext.h c32types.h typesc32.h"
C32OBJS="c32.o c32a.o c32b.o c32peep.o c32i.o c32p.o c32u.o c32case.o c32stab.o"
C68SRC="c68.p c68a.p c68b.p c68case.p c68i.p c68p.p c68u.p c68eval.p c68stab.p c68expr.p c68inst.p c68float.p c68c.p c68spell.c c68maci.c c68con.h c68deb.h c68ext.h c68mac.h c68stab.h c68types.h typesc68.h c68utarg.h c68vars.h"
C68OBJS="c68.o c68a.o c68b.o c68case.o c68i.o c68p.o c68u.o c68eval.o c68stab.o c68expr.o c68inst.o c68float.o c68c.o c68spell.o c68maci.o"
XCSRC="2c.p 2cpre.p 2cu.p 2ctype.p 2cp.p 2ca.p 2ci.p 2cjunk.p 2cvm.p 2ctick.p 2cext.h 2ctypes.h types2c.h"
XCOBJS="2c.o 2cpre.o 2cu.o 2ctype.o 2cp.o 2ca.o 2ci.o 2cjunk.o 2cvm.o 2ctick.o"
VAXSRC="vax.p vaxa.p vaxb.p vaxpeep.p vaxi.p vaxp.p vaxu.p vaxext.h vaxtypes.h typesvax.h"
VAXOBJS="vax.o vaxa.o vaxb.o vaxpeep.o vaxi.o vaxp.o vaxu.o indeptarg.o"
SRC386="386.p 386a.p 386b.p 386peep.p 386i.p 386p.p 386u.p 386ext.h 386types.h types386.h"
OBJ386S="386.o 386a.o 386b.o 386peep.o 386i.o 386p.o 386u.o indeptarg.o"
FAIRSRC="fair.p faira.p fairb.p fairpeep.p fairi.p fairp.p fairu.p fairext.h fairtypes.h typesfair.h"
FAIROBJS="fair.o faira.o fairb.o fairpeep.o fairi.o fairp.o fairu.o indeptarg.o"
ACPSRC="acp.p acpa.p acpb.p acppeep.p acpi.p acpp.p acpu.p acpopt.p acpext.h acptypes.h typesacp.h"
ACPOBJS="acp.o acpa.o acpb.o acppeep.o acpi.o acpp.o acpu.o acpopt.o indeptarg.o"
if test $1 ; then nop= ; else sh $0 -h ; exit 1 ; fi
while test $1 ; do
    case $1 in 
    -h )    echo "		THIS IS THE MAKETAPE COMMAND"
       echo "Usage: maketape dest language options"
       echo "where:"
       echo "	c 		add C compiler binaries/sources."
       echo "	pas 		add pascal compiler binaries/sources."
       echo "	f77 		add Fortran 77 compiler binaries/sources."
       echo "	68		add 68000 code generator"
       echo "	32		add 32000 code generator"
       echo "	vax		add vax code generator"
       echo "	fair		add Clipper code generator"
       echo "	386		add 386 code generator"
       echo "	acp		add Weitek code generator"
       echo "	2c		add C language code generator"
       echo "	host x		in environment x, default HOSTNAME"
       echo "	source		add compiler sources"
       echo "	nobin		delete linkedbinaries from distribution"
       echo "	presson		press on regardless of files missing"
       echo "	unlinked	add unlinked binaries"
       echo "	file x		create file x rather than tape"
       echo "	plus		allows creation of multiple items on one distribution"
       echo "	testgen		add sources to automatic test generator"
       echo "	fcvs		add sources to Dept. of Commerce Validation Suite"
       echo "	testu		add sources to test programs from the UNIX source"
       echo "	libsource	add sources to Green Hills libraries"
       echo "	unixlib		add sources to UNIX Fortran libraries"
       echo "	xdev		add 68000 cross development library"
       echo "	weiteklib	add Weitek proprietary library sources"
       echo "	list		will list the file after creation. Beware of -"
       echo "	man		will attempt to create manuals"
       echo "	debug		same as running with sh -vx"
       echo "	uucp x		uucp compressed tar file to system x"
       echo "	newenv		describes how to add a new environment, e.g. Sun System V"
       echo "	newtarget	describes how to add a new target, e.g. 80486?"
       echo "	newsource	describes how to add a new front end, e.g. PL/1"
       echo "	-h		gives this message and exits"
       echo
       echo "You must specify at least one language and one code generator"
       echo "By default, a tape will be created, with a vax binary executable"
       echo "on it (if this is running on a VAX)."
       exit 1
    ;;
    newenv )
       echo "Environment Additions"
       echo "You must add a new directory tree in BIN"
       echo "You must add a makefile for BIN/newenv/lib"
       echo "You must add support for -target=<newenv> in COMPILER/compile.c"
       echo "You must add BIN/<newenv>/PROCESSOR to indicate which codegen to use"
       exit 1
    ;;
    newtarget )
       echo "Target Additions"
       echo "You must add a new directory in SOURCE"
       echo "You must modify this file (maketape) to parse new id"
       echo "You must add all .o rules to SOURCE/makefile"
       echo "You must add all .o names to this file(maketape)"
       echo "You must add code generator spec to install.sh"
       echo "You must add support to COMPILER/compile.c"
       echo "You may want to add a new environment"
       exit 1
    ;;
    newsource )
       echo "Front End Additions"
       echo "You must add a new directory in SOURCE"
       echo "You must modify this file (maketape) to parse new id"
       echo "You must add all .o rules to SOURCE/makefile"
       echo "You must add all .o names to this file (maketape)."
       echo "You must add code generator spec to install.sh"
       echo "You must add support to COMPILER/compile.c"
       exit 1
    ;;
    debug )
	set -vx
    ;;
    c ) 
	binlist="$binlist ccom" 
	sourcelist="$sourcelist $CCSRC"
	testlist="$testlist TEST/t.c"
	unlinkedlist="$unlinkedlist $CCOBJS"
	FILES="$FILES TEST/t.c"
	seenlanguage=1
    ;;
    pas ) 
	binlist="$binlist pcom" 
	sourcelist="$sourcelist $PASSRC"
	testlist="$testlist TEST/t.p"
	unlinkedlist="$unlinkedlist $PASOBJS"
	seenlanguage=1
	FILES="$FILES TEST/t.p"
    ;;
    f77 ) 
	binlist="$binlist fcom" 
	sourcelist="$sourcelist $FORSRC"
	testlist="$testlist TEST/t.f"
	unlinkedlist="$unlinkedlist $FOROBJS"
	FILES="$FILES TEST/t.f"
	seenlanguage=1
    ;;
    68 ) 
	targlist="$targlist 68"
	sourcelist="$sourcelist $C68SRC"
	unlinkedlist="$unlinkedlist $C68OBJS"
	seentarget=1
    ;;
    32 ) 
	targlist="$targlist 32"
	sourcelist="$sourcelist $C32SRC"
	unlinkedlist="$unlinkedlist $C32OBJS"
	seentarget=1
    ;;
    vax ) 
	targlist="$targlist vax"
	sourcelist="$sourcelist $VAXSRC"
	unlinkedlist="$unlinkedlist $VAXOBJS"
	seentarget=1
    ;;
    fair ) 
	targlist="$targlist fair"
	sourcelist="$sourcelist $FAIRSRC"
	unlinkedlist="$unlinkedlist $FAIROBJS"
	seentarget=1
    ;;
    386 ) 
	targlist="$targlist 386"
	sourcelist="$sourcelist $SRC386"
	unlinkedlist="$unlinkedlist $OBJ386S"
	seentarget=1
    ;;
    acp ) 
	targlist="$targlist acp"
	sourcelist="$sourcelist $ACPSRC"
	unlinkedlist="$unlinkedlist $ACPOBJS"
	seentarget=1
    ;;
    2c ) 
	targlist="$targlist c"
	sourcelist="$sourcelist $XCSRC"
	unlinkedlist="$unlinkedlist $COBJS"
	seentarget=1
    ;;
    host ) 
	shift
	host=$1
    ;;
    source ) 
	wantsource=1
    ;;
    nobin )
	wantbin=
    ;;
    presson )
	presson=1
    ;;
    unlinked ) 
	wantunlinked=1
    ;;
    file ) 
	shift
	tarfile=$1
    ;;
    uucp ) 
	shift
	uucp=$1
    ;;
    plus ) 
	process=1
    ;;
    testgen ) 
	FILES="$FILES TESTGEN"
    ;;
    fcvs )
	echo "WARNING: THE FORTRAN VALIDATION SUITE IS COPYRIGHT MATERIAL"
	echo "DO NOT SHIP OUTSIDE THE COMPANY"
	FILES="$FILES FCVS"
    ;;
    testu )
	echo "WARNING: THE UNIX VALIDATION SUITE IS COPYRIGHT MATERIAL"
	echo "DO NOT SHIP OUTSIDE THE COMPANY"
	FILES="$FILES TESTU"
    ;;
    libsource ) 
	FILES="$FILES LIB"
    ;;
    unixlib ) 
	FILES="$FILES LIBFUNIX"
    ;;
    xdev ) 
	FILES="$FILES XDEV"
    ;;
    weiteklib ) 
	FILES="$FILES WEITEKLIB"
    ;;
    list ) 
	listrequest=1 
    ;;
    man ) 
	manrequest=1 
    ;;
    *)  echo "maketape: $1 is a bad argument " ; exit 1 ;;
    esac
    shift
    if test $1 ; then fooba=  ; else process=1 ; fi
    if test $process ; then
	process=
	if test $seenlanguage ; then dummy= 
	    else echo NEED LANGUAGE ; exit 1 
	fi
	if test $seentarget ; then dummy= 
	    else echo NEED TARGET ; exit 1 
	fi
	#tar will not append empty directories, it seems,
	#so create .hidden files
	FILES="$FILES BIN/$host/DOC"
	echo > BIN/$host/compiler/.hidden
	FILES="$FILES BIN/$host/compiler/.hidden"
	FILES="$FILES BIN/$host/PROCESSOR"
	echo > BIN/$host/dots/.hidden
	FILES="$FILES BIN/$host/dots/.hidden"
	echo > BIN/$host/lib/.hidden
	FILES="$FILES BIN/$host/lib"
	echo > BIN/$host/unlinked/.hidden
	FILES="$FILES BIN/$host/unlinked/.hidden"
	comlist=
	for x in $targlist ; do 
	    for y in $binlist ; do
		comlist="$comlist $y$x"
		if test -r TEST/$y$x.tst ; then FILES="$FILES TEST/$y$x.tst"; fi
	    done
	    FILES="$FILES README.$x"
	done
	wantbincom=
	maybeoem=
	if test $wantbin ; then
	    for x in $comlist ; do
		FILES="$FILES BIN/$host/compiler/$x"
	    done
	    wantbincom=1
	fi
	if test $wantsource ; then
	    sourcelist="$sourcelist $INDEPSRC"
	    for q in $sourcelist ; do 
		FILES="$FILES SOURCE/$q"
	    done
	    if test -r BIN/$host/PROCESSOR ; then
		hostcomps=`cat BIN/$host/PROCESSOR`
		for q in pcom ccom ; do
		    if test -r BIN/$host/compiler/$q$hostcomps ; then
			FILES="$FILES BIN/$host/compiler/$q$hostcomps"
		    else
			if test -r BIN/$host/compiler/o$q$hostcomps ; then
			    FILES="$FILES BIN/$host/compiler/o$q$hostcomps"
			else
			    echo WARNING NO HOST COMPILER FOUND BIN/$host/compiler/$q$hostcomps
			fi
		    fi
		done
	    else
		echo WARNING BIN/$host/PROCESSOR NOT FOUND, NO HOST COMPILER INCLUDED
	    fi
	    maybeoem=1
	fi
	if test $wantunlinked ; then
	    for x in $unlinkedlist $INDEPOBJS ; do 
		FILES="$FILES BIN/$host/unlinked/$x"
	    done
	    wantbincom=1
	    maybeoem=1
	fi
	FILES="$FILES COMPILER DOC CHANGELOG README install.sh"
	if test $maybeoem ; then 
	    FILES="$FILES maketape SOURCE/makefile SOURCE/makefile.auto SOURCE/makefile.nosrc SOURCE/Xpcom SOURCE/Xccom"
	fi
	if test $wantbincom ; then
	    for x in $targlist ; do
		#should only add libraries if resident;
		#determine this by looking at PROCESSOR field
		if test $x -eq `cat BIN/$host/PROCESSOR` ; then 
		    FILES="$FILES BIN/$host/lib BIN/$host/compiler/gcc BIN/$host/compiler/gf77 BIN/$host/compiler/gpc"
		fi
	    done
	fi
	# AND NOW, RESET ALL VARIABLES IN CASE THERE HAS BEEN A PLUS COMMAND
	wantbin=1
	unlinkedlist=
	manrequest=		#attempt to make a manual for compilers
	seenlanguage=		#have seen language
	host=`cat HOSTNAME`	#use binaries which run on an x
	binlist=		#list of front ends (ccom,pcom etc)
	targlist=		#list of code gens
	sourcelist=		#list of source directories
	wantsource=
	wantbin=1
	wantunlinked=
	process=
	wantxdev=
	wantlibsource=
	wantunixlib=
	wanttestgen=
	testlist=
    fi
done
err=
for file in $FILES ; do 
    if test ! -r $file ; then echo $file NOT READABLE, ERROR ; err=1 ; fi
done
echo "ABOUT TO MAKE A TAPE WITH THE FOLLOWING FILES:"
for file in $FILES ; do
    echo $file
done
if test $err -a ! $presson ; then
    echo FILE WAS MISSING, DISTRIBUTION NOT MADE
    exit 1
else
    if test $uucp ; then
	tar cvf - $FILES | compress > /usr/spool/uucppublic/DI$uucp.Z
	chmod o+r /usr/spool/uucppublic/DI$uucp.Z
	uucp -c /usr/spool/uucppublic/DI$uucp.Z $uucp!/usr/spool/uucppublic
    else
	tar cvf $tarfile $FILES
	if test $listrequest ; then
	    tar tvf $tarfile | pr -f | lpr
	fi
    fi
    echo DISTRIBUTION FINISHED
fi
