#!/bin/sh

if [ $# -le 0 ]  ; then echo usage: Provide a machine name as arg ; exit 1 ; fi

if [ -f h/$1.defs ] ; then echo using $1.defs ;
  else echo h/$1.defs does not exist
  echo Build one or use one of `ls h/*.defs`
  exit 1
fi

echo $1 > machine


if [ $# -ge 2 ] ; then
   if [ -f $2/c/print.d ] ; then true ; else echo $2 is not the main kcl direct\
ory ; fi ;fi



make -f Smakefile merge


  echo "@s[# begin makedefs" > tmpxx
  echo "@s,# end makedefs" >> tmpxx
  echo "@s|# begin makedefs" >> tmpxx
  rm -f makedefs
  echo "AKCLDIR=`pwd`" > makedefs
  echo "SHELL=/bin/sh" >> makedefs
  echo "MACHINE=$1"  >> makedefs
  cat h/$1.defs >> makedefs 
  if  [ -f $2/c/print.d ] ; then echo MAINDIR = $2 >> makedefs ; fi
  cat makedefs >> tmpxx	
  echo "# end makedefs" >> tmpxx
  echo "@s]" >> tmpxx
  echo inserting h/$1.defs in ..
  for v in  Smakefile mp/makefile V/makefile V/o/makefile V/lsp/makefile V/unixport/makefile  V/cmpnew/makefile  unixport/make_kcn ;
  do
  echo -n " $v,"
 ./merge $v tmpxx tmp1
  mv tmp1 $v
  done

rm -f Vmakefile

rm -f tmpxx

echo ""

# Copy the config.h over.


./xbin/move-if-changed h/$1.h h/config.h


# fix the cmpinclude.h

if fgrep "Begin for cmpinclud" h/$1.h > /dev/null ;
then
./xbin/file-sub h/$1.h V/h/cmpinclude.h "Begin for cmpinclud" "End for cmpinclud"
else
echo "/* Begin for cmpinclude */" >tmp.h
echo "/* End for cmpinclude */" >>tmp.h
./xbin/file-sub tmp.h V/h/cmpinclude.h "Begin for cmpinclud" "End for cmpinclud"
rm -f tmp.h
fi
./xbin/move-if-changed tmpx V/h/cmpinclude.h
rm -f tmpx




if [ -f xbin/$1-fix ] ; then xbin/$1-fix ; fi


