#!/bin/sh

#
# build-dqs: build DQS on a set of hosts
#
# NOTE: Modify the block of definitions just below.
#       The output from each build will be placed in $DQS/make.log.$host
#         where $host is the name of each host on which the build occurs.
#
# History:
#  -kk6/8/94 11:18am. snarfed some of this from X11R5's xrsh
#

# !!! Modify these definitions to suit yourself !!!
rootdir=${HOME}
# tmpdir should be a directory that's accessible to all the hosts via NFS --
# temporary compilation files shall be put here...
tmpdir=$rootdir/tmp
DQS=$rootdir/DQS

PROGNAME=`basename $0`

if [ $# -lt 1 ]; then
  echo Usage: $PROGNAME Host [Host...]
  echo where: Host is a hostname to build on
  exit 1
fi

# Grab each hostname from the command line
while [ ! "$1" = "" ]
do
  hosts="$hosts $1"
  shift
done

# Some System V hosts have rsh as "restricted shell" and ucb rsh is remsh
if [ -r /usr/bin/remsh ]; then
  rsh=remsh
elif [ -f /usr/bin/rcmd ]; then       # SCO Unix uses "rcmd" instead of rsh
  rsh=rcmd
else
  rsh=rsh
fi

# The redirection inside the innermost quotes is done by csh.  The outer
# redirection is done by whatever shell the user uses on the remote end.
# The inner redirection is necessary for an error log -- the outer 
# redirection is necessary to make sure that the local rsh doesn't hang around.
#
# The outermost < /dev/null is to simulate the -n argument to rsh which 
# we don't want to use for portability reasons.
#
# The three sets of redirections are for the local shell, the login shell
# on the remote host and the csh on the remote host.
#
# We would like the last '>' to be '>&' or equivalent, but that would make this
# code dependent on what flavor of shell the user uses on the remote host
#

echo "Building on machines named: $hosts"

for host in $hosts
do

  $rsh $host " ( cd $DQS; \
                 setenv TMPDIR $tmpdir; \
                 date >>& $DQS/make.log.$host; \
                 make >>& $DQS/make.log.$host; \
                 date >>& $DQS/make.log.$host ) \
                   < /dev/null > /dev/null & " \
    < /dev/null &

done

exit 0
