#! /bin/csh -f
# Last edited on 2004-01-04 23:41:09 by stolfi

set usage = "$0 DERIVED SOURCE..."

# Returns "1" if DERIVED is absent, unreadable,
# or older than any of the SOURCES.  Returns "0" otherwise.

if ( $#argv < 1 ) then
  echo "usage: ${usage}"; exit 1
endif

set derived = "$1"; shift

foreach d ( /usr/bin  /bin )
  if ( -x $d/test ) set gnutest = "$d/test"
  if ( -x $d/echo ) set gnuecho = "$d/echo"
end

if ( -r ${derived} ) then
  set res = "0"
  while ( $#argv > 0 )
    set source = "$1"; shift;
    if ( -r ${source} ) then
      if ( { ${gnutest} ${source} -nt ${derived} } ) set res = "1"
    else
      echo "${source} unreadable (needed for ${derived})" > "/dev/stderr"
      exit 1
    endif
  end
else
  set res = "1"
endif
${gnuecho} -n ${res}

