#! /bin/csh
set V = csv`echo '(printf "~a\n" #%\#scheme-version)' | scheme -q`
set S = `pwd`
set S = swl/$S:t

# requirements:
#   built and tested on vortex
#   sync'd chez scheme release on vortex, beast-fb, vortex-ob, beastie, garbo, and schmac
#   sync'd swl files on vortex, beast-fb, vortex-ob, beastie, garbo, and schmac

if ($#argv == 0) then
#  echo | $0 i3le >&! /tmp/$0.i3le &
  echo | $0 i3fb >&! /tmp/$0.i3fb &
  echo | $0 i3ob >&! /tmp/$0.i3ob &
  echo | $0 i3osx >&! /tmp/$0.i3osx &
  echo | $0 sps2 >&! /tmp/$0.sps2 &
  echo | $0 ppcosx >&! /tmp/$0.ppcosx &
  wait
  exit
endif

# makeall -checkin
if ("$argv" == "-checkin") then
  echo 'rback -u from schmac to vortex'
  ssh schmac "(cd $S; rback -i -u vortex .)"
  echo 'rback -u from garbo to vortex'
  ssh garbo "(cd $S; rback -i -u vortex .)"
  echo 'rback -u from beast-fb to vortex'
  ssh beast-fb "(cd $S; rback -i -u vortex .)"
  echo 'rback -u from vortex-ob to vortex'
  ssh vortex-ob "(cd $S; rback -i -u vortex .)"
  echo 'rback -u from beastie to vortex'
  ssh beastie "(cd $S; rback -i -u vortex .)"
  chgrp -R chez .
  exec $0 -sync
endif

# makeall -sync
if ("$argv" == "-sync") then
  echo 'rback --delete from vortex to beastie'
  rback -i --delete beastie .
  echo 'rback --delete from vortex to beast-fb'
  rback -i --delete beast-fb .
  echo 'rback --delete from vortex to vortex-ob'
  rback -i --delete vortex-ob .
  echo 'rback --delete from vortex to garbo'
  rback -i --delete garbo .
  echo 'rback --delete from vortex to schmac'
  rback -i --delete schmac .
  exit
endif

foreach m ($*)
  set fail = 1
  switch ($m)
    case i3le:
      make Scheme='vscheme csv7.4' || got skip
      make clean Scheme='vscheme csv7.4' || got skip
      set fail = 0
      breaksw
    case i3fb:
      ssh beast-fb "(cd $S; make Scheme='vscheme csv7.4')" || goto skip
      ssh beast-fb "(cd $S; make clean Scheme='vscheme csv7.4')" || goto skip
      set fail = 0
      breaksw
    case i3ob:
      ssh vortex-ob "(cd $S; make Scheme='vscheme csv7.4')" || goto skip
      ssh vortex-ob "(cd $S; make clean Scheme='vscheme csv7.4')" || goto skip
      set fail = 0
      breaksw
    case i3osx:
      ssh beastie "(cd $S; make Scheme='vscheme csv7.4')" || goto skip
      ssh beastie "(cd $S; make clean Scheme='vscheme csv7.4')" || goto skip
      set fail = 0
      breaksw
    case sps2:
      ssh school "(cd $S; make Scheme='vscheme csv7.4')" || goto skip
      ssh school "(cd $S; make clean Scheme='vscheme csv7.4')" || goto skip
      set fail = 0
      breaksw
    case ppcosx:
      ssh schmac "(cd $S; make Scheme='vscheme csv7.4')" || goto skip
      ssh schmac "(cd $S; make clean Scheme='vscheme csv7.4')" || goto skip
      set fail = 0
      breaksw
    default:
      echo "unrecognized machine type $m"
      exit 1
  endsw
 skip:
  if ($fail) echo "ABORTING $m"
end
