#!/bin/sh

# the KCL_DISTRIB directory and the NEWKCL directory, and 

# script for creating a copy of the distribution kcl.
# Directories in which no changes are to be made, are linked
# directly. Otherwise a new directory is created linking
# the individual files.  If there are args they are

KCL_DISTRIB=$1
NEWKCL=$2
export SYMB
SYMB=$3


#  if [ $# -ne 2 ] ; then echo usage distrib new ; exit 1 ; fi
if [ ! -f $1/c/print.d  ] || [ -f $1/Smakefile ] ; then echo $1 is not the kcl distrib directory ;	exit 1 ; fi

if  [ ! -f Smakefile ] ; then echo $2 is not the new directory ; exit 1 ; fi






echo "Making links $NEWKCL --> $KCL_DISTRIB"
echo Using for the new kcl directory :NEWKCL = ${NEWKCL}
echo Assuming the KCL_DISTRIB is KCL_DISTRIB = ${KCL_DISTRIB}

cd $KCL_DISTRIB

for v in * ; do
  if [ -f $v ] ; then  if [ -f ${NEWKCL}/$v ] ; then rm -f ${NEWKCL}/$v ;fi;
	ln ${SYMB} ${KCL_DISTRIB}/$v ${NEWKCL}/$v ; fi;
  if [ -d $v ] ;
	then if [ ! -d ${NEWKCL}/$v ] ; then mkdir ${NEWKCL}/$v;
            fi;
          for w in $v/*	 ; do
           if [ -f $w ] ; then if [ -f ${NEWKCL}/$w ] ; then rm -f ${NEWKCL}/$w ;
                                fi;
	                 ln ${SYMB} ${KCL_DISTRIB}/$w ${NEWKCL}/$w ;
	   fi; done;
 fi;
done

# fix up two pathnames that some systems truncate [hp under hp-ux]
if [ -f cmpnew/cmpspecial.dat ] ; then mv cmpnew/cmpspecial.dat cmpnew/cmpspecial.data ;fi
if [ -f lsp/evalmacros.dat ] ; then mv lsp/evalmacros.dat lsp/evalmacros.data ;fi

cd ${NEWKCL}/lsp
for v in `cat ../unixport/lspboots` ;
   do rm -f $v.c $v.h $v.data ;
   ln ${SYMB} ../lsp/dummy.c $v.c	
   echo > $v.data
done
cd ${NEWKCL}/cmpnew
for v in `cat ../unixport/cmpboots` ;
   do rm -f $v.c $v.h $v.data ;
   ln ${SYMB} ../lsp/dummy.c $v.c	
   echo > $v.data
done

 
	




            
	   
  






