#!/bin/sh
if ( test -f $1/gs.c ) then
	for sub in dll gnu
	do
		echo Writing $1${sub}.tar.gz....
		cd $1
		rm -f $1
		ln -s ${sub} $1
		tar -chvf - $1/* | gzip -c > ../$1${sub}.tar.gz
		rm -f $1
		cd ..
		echo Wrote $1${sub}.tar.gz.
	done
	echo Writing $1.tar.gz....
	cd $1
	./tar_cat
	rm -f arch.h gconfig.h j*.h lib*.tr obj.tr q* t.* _temp_*
	echo quit >quit.ps
	cd ..
	ctf -u $1/*.bat $1/*.cmd
	tar -cvf - $1/*.1 $1/g*.asm $1/i*.asm $1/*.bat \
$1/ansi2knr.c $1/echogs.c \
$1/g*.c $1/i*.c $1/s*.c $1/z*.c $1/*.cfg $1/*.cmd $1/dw*.cpp \
$1/*.doc $1/*.h $1/*.icx $1/*.lis $1/*.mak $1/*.ppd $1/*.ps \
$1/gs*.def $1/gs*.rc $1/*.sh $1/*.tcl $1/tar_cat \
$1/Fontmap $1/Fontmap.ATB $1/Fontmap.ATM $1/Fontmap.OS2 $1/Fontmap.OSF1 \
$1/Fontmap.Solaris $1/Fontmap.Ultrix $1/Fontmap.URW $1/Fontmap.VMS \
$1/COPYING $1/NEWS $1/PUBLIC $1/README \
$1/ccgs \
$1/bdftops $1/font2c $1/gsbj $1/gsdj $1/gslp $1/gslj $1/gsnd \
$1/pdf2ps $1/printafm $1/ps2ascii $1/ps2epsi $1/wftopfa \
| gzip -c > $1.tar.gz
	echo Wrote $1.tar.gz.
	if ( test -f $1/gs386.exe ) then
		echo Writing $1pc.tar.gz....
		cp dos4gw.exe $1
		cp *.dll $1
		cd $1
		chmod u+w dos4gw.exe *.dll
		for f in *.bat
		do
			ctf -d ${f} -o `basename ${f} .bat`.BAT
		done
		for f in *.cmd
		do
			ctf -d ${f} -o `basename ${f} .cmd`.CMD
		done
		for f in *.doc
		do
			ctf -d ${f} -o `basename ${f} .doc`.DOC
		done
		for f in *.ps
		do
			ctf -d ${f} -o `basename ${f} .ps`.PS
		done
		ctf -d Fontmap -o FONTMAP
		ctf -d Fontmap.ATB -o FONTMAP.ATB
		ctf -d Fontmap.ATM -o FONTMAP.ATM
		ctf -d Fontmap.OS2 -o FONTMAP.OS2
		ctf -d Fontmap.URW -o FONTMAP.URW
		ctf -d COPYING -o COPYING.
		ctf -d NEWS -o NEWS.
		ctf -d PUBLIC -o PUBLIC.
		ctf -d README -o README.
		cd ..
# Some combination of tar and gzip is broken: doing this with a pipe
# winds up writing to the original stdout, not to the tar file.
# Do it in separate steps instead.
		tar -cvf $1pc.tar \
$1/gs*.exe $1/dos4gw.exe $1/*.dll $1/*.ico $1/*.res \
$1/*.BAT $1/*.CMD $1/*.DOC $1/*.PS \
$1/FONTMAP $1/FONTMAP.ATB $1/FONTMAP.ATM $1/FONTMAP.OS2 $1/FONTMAP.URW \
$1/COPYING. $1/NEWS. $1/PUBLIC. $1/README.
		rm -f $1pc.tar.gz
		gzip $1pc.tar
		cd $1
		rm dos4gw.exe *.dll
		rm *.BAT *.CMD *.DOC *.PS
		rm FONTMAP FONTMAP.ATB FONTMAP.ATM FONTMAP.OS2 FONTMAP.URW
		rm COPYING. NEWS. PUBLIC. README.
		cd ..
		echo Wrote $1pc.tar.gz.
	fi
else
	echo The Ghostscript files must be in the directory ./$1.
fi
