#!/bin/csh
## compiling pvm source programs
## Usage:  pvmlc1/pvmmc1 [-U compiler] [-D hostfile] file.lsp ...
## 8/28/95 Paul Wang

set cmd = $0
if ( $#argv == 0 ) then
     echo "Usage:  $cmd [-U compiler] [-D hostfile] file.lsp ..."
     exit(1)
endif

if ( $cmd:t == pvmlc1 ) then
    set CC = lc
else
    set CC = mc
endif
set distribution = 0
set optdone = 0

while ( ! $optdone )
  switch ($1)
    case -U: ## compiler to use
         set CC = $2
         shift; shift; breaksw
    case -D: ## distribution request
         set distribution = 1
         set hostfile = $2
         shift; shift; breaksw
    default:
         set optdone = 1
  endsw
end

## Compile and distribute
set exdir = $home/pvm3/bin/$PVM_ARCH
## Compile
echo $CC $*
if (! { $CC $* } ) then
					echo "$0: Compilation failed"
					exit(1)
endif

## local disk directory to receive distributed executable
set ldsk = `ls -l $home/pvm3/local_disk_bin`
set ldsk = $ldsk[$#ldsk]
mkdir $ldsk >& /dev/null

foreach file ( $*:gr )
     if ( -f $file.o ) then
        cp $file.o $home/pvm3/local_disk_bin/$file:t.o
## Distribution
        if ($distribution == 1) then
             $UTIL/pvm_distrib -T $PVM_ARCH -H $hostfile $file.o
        endif
        mv $file.o $exdir
     endif
end

