#! /bin/csh -fvx
set answ = 'y'
set space = " "
set MACHINE = "sparc"

if ( ! -d tools) then
  mkdir tools
endif
if ( ! -d archi) then
  mkdir archi
endif
if ( ! -d etc) then
  mkdir etc
endif
if ( ! -d etc/example) then
  mkdir etc/example
endif
if ( ! -d cells) then
  mkdir cells
endif
if ( ! -d man) then
  mkdir man 
endif
if ( ! -d doc) then
  mkdir doc 
endif

echo '#! /bin/csh' > INSTALL
echo 'clear' >> INSTALL
echo '' >> INSTALL
echo 'echo "Alliance Installation Shell for sparc"' >> INSTALL
echo '' >> INSTALL
echo 'set TOP=`pwd`' >> INSTALL
echo 'set MACHINE=sparc' >> INSTALL
echo 'DoItAgain:' >> INSTALL

set TOOLLIST="sl"
#set TOOLLIST = "mbk mbkal mbkap mbkedif mbkhilo mbkspice mbkvhdl mbkvti bdd beh behvhdl pat rds rdscif rdsgds genlib genpat desb alc scr asimut lynx lvx ring mbktools mbk2ps s2r versatil proof sl"
  if ( ! -d archi/sparc) then
    mkdir archi/sparc
    foreach sousrep ( lib include bin )
      mkdir archi/sparc/$sousrep
    end 
  endif
        
foreach tool ($TOOLLIST)
  echo -n 'echo -n "Do you wish to install ' >> INSTALL
  echo -n $tool >> INSTALL
  echo ' (y/n) "' >> INSTALL
  echo -n 'set ' >> INSTALL
  echo -n $tool >> INSTALL
  echo 'Install = $< ' >> INSTALL
  if ( -d tools/$tool) then
    /bin/rm -rf tools/$tool
  endif
  if ( ! -d tools/$tool) then
    mkdir tools/$tool 
    foreach f (sce doc etc lib include bin)
      if ( ! -d tools/$tool/$f) then
        mkdir tools/$tool/$f
      endif
    end
  endif
  echo "---------- Copying "$tool" subdirectories ----------"
  echo ""
  echo "  ~"$tool"/labo/sce/*"
  cp -R ~$tool/labo/sce/* tools/$tool/sce 
  echo "  ~"$tool"/labo/man/*"
  cp -R ~$tool/labo/man/* man 
  echo "  ~"$tool"/labo/etc/*"
  cp -R ~$tool/labo/etc/* tools/$tool/etc 
  echo "  ~"$tool"/labo/doc/*"
  cp ~$tool/labo/doc/*.ps tools/$tool/doc
  echo ""
  echo "---------- Done for "$tool" ----------"
  echo "" 
end

#chmod -R 755 *

echo ' echo ""' >> INSTALL

foreach tool ($TOOLLIST)
  echo -n 'if ( $' >> INSTALL
  echo -n $tool >> INSTALL
  echo 'Install == "y" ) then' >> INSTALL
  echo -n '  echo "' >>  INSTALL
  echo -n $tool >> INSTALL
  echo '  will be installed ."' >> INSTALL
  echo 'endif'  >> INSTALL
end
echo 'echo ""' >> INSTALL
echo 'echo -n "Is this correct (y/n) ? "' >> INSTALL
echo 'set answer = $< ' >> INSTALL
echo 'if ( $answer == "n" ) then ' >> INSTALL
echo '  clear' >> INSTALL
echo '  goto DoItAgain'  >> INSTALL
echo 'endif'  >> INSTALL
echo 'echo ""' >> INSTALL
echo ' echo "------------- Installation launched ------------------"' >> INSTALL
foreach tool ($TOOLLIST)
  echo -n 'if ( $' >> INSTALL
  echo -n $tool >> INSTALL
  echo 'Install == "y" ) then' >> INSTALL
  echo -n ' echo  "-------------"' >> INSTALL
  echo -n $tool >> INSTALL
  echo  "-------------" >> INSTALL
  echo -n 'cd tools/' >> INSTALL
  echo -n $tool >> INSTALL
  echo -n '/sce; make MACHINE=sparc ALLIANCE_INCLUDE=' >> INSTALL
  echo -n '$TOP/archi/' >> INSTALL
# echo -n $HOME >>INSTALL
# echo -n "/t1/archi/" >> INSTALL
  echo -n "sparc" >> INSTALL
  echo -n '/include ' >> INSTALL
  echo -n 'ALLIANCE_LIB=' >> INSTALL
  echo -n '$TOP/archi/' >> INSTALL
# echo -n $HOME >>INSTALL
# echo -n "/t1/archi/" >> INSTALL
  echo -n "sparc" >> INSTALL
  echo -n '/lib ' >> INSTALL
  echo -n 'ALLIANCE_ETC=' >> INSTALL
  echo -n '$TOP/etc ' >> INSTALL
# echo -n $HOME >>INSTALL
# echo -n "/t1/etc " >> INSTALL
  echo -n 'ALLIANCE_CELLS=' >> INSTALL
  echo -n '$TOP/cells ' >> INSTALL
# echo -n $HOME >>INSTALL
# echo -n "/t1/cells " >>INSTALL
  echo -n 'distrib ; ' >> INSTALL
  echo 'cd ../../..' >> INSTALL
#  echo -n 'cd tools/' >> INSTALL
#  echo -n $tool >> INSTALL
#  echo '/sce; make clean' >> INSTALL
  echo -n 'mv tools/' >> INSTALL
  echo -n $tool >> INSTALL
  echo '/lib/* archi/sparc/lib' >> INSTALL
  echo 'foreach i (archi/sparc/lib/*.a)' >> INSTALL
  echo '  /bin/ranlib $i' >> INSTALL
  echo 'end' >> INSTALL
  echo -n 'mv tools/' >> INSTALL
  echo -n $tool >> INSTALL
  echo '/bin/* archi/sparc/bin' >> INSTALL
  echo -n 'mv tools/' >> INSTALL
  echo -n $tool >> INSTALL
  echo '/include/* archi/sparc/include' >> INSTALL
  echo -n 'mv tools/' >> INSTALL
  echo -n $tool >> INSTALL
  echo '/etc/* etc' >> INSTALL
  echo ' endif' >> INSTALL
end
