#!/bin/csh -f

# Tests whether the TargetFile is older than any of the sources files.
# echoess 1 if TargetFile does not exist or is older than any of the
# sources files. If a source does not exist, then it echoes 1 and
# exists with 1.
# $Id: UpdateNeeded,v 1.1 2010/04/01 19:21:16 greve Exp $

if($#argv < 2) then
  echo "UpdateNeeded TargetFile SourceFile <SourceFile2 ...> "
  exit 1;
endif

set Target = $argv[1]; shift;
set Sources = ($argv);

if(! -e $Target ) then
  set UpdateNeeded = 1;
  echo $UpdateNeeded
  exit 0
endif

set UpdateNeeded = 0;
foreach Source ($Sources)
  if(! -e $Source ) then
    # If source does not exist, set UpdateNeeded
    # and exit with error
    set UpdateNeeded = 1;
    echo $UpdateNeeded
    exit 1; 
  endif
  # This test looks backwards (ie, testing for ! $status)
  test $Source -nt $Target
  if(! $status) then
    set UpdateNeeded = 1;
    break;
  endif
end

echo $UpdateNeeded

exit 0
