#!/bin/sh -- # A comment mentioning perl. Indented for bash's sake. eval 'exec perl -S $0 ${1+"$@"}' if 0; chop($Program = `basename $0`); $cmd = "make install"; $debug = 0; $sleep = '1.0'; $Usage = <<"END"; $Program: XXX Usage: $Program Options: Notes: END LOOP: while (@ARGV) { $_ = shift; CASE: { /^-c$/ && ($cmd = shift, last CASE); /^-s$/ && ($sleep = shift, last CASE); /^-d$/ && ($debug = 1, last CASE); /^--$/ && (last LOOP); # -- means end of switches /^-(-.*)$/ && (unshift(@ARGV, $1), last CASE); /^(-h|-help)$/ && ((print $Usage), exit 0, last CASE); if ( /^-(..+)$/ ) { # split bundled switches: local($y, $x) = ($1, ''); foreach $x (reverse(split(//, $y))) { unshift(@ARGV,"-$x") }; last CASE; } /^-/ && ((print "Invalid arg: $_\n$Usage"), exit 1, last CASE); unshift(@ARGV,$_); last LOOP; } } sleep 1; select STDERR; $| = 1; select STDOUT; $| = 1; foreach $file (@ARGV) { next if ! -f $file; $Age{$file} = -M $file; print STDERR "INIT: $file -- $Age{$file}\n"; } while (1) { $doit = 0; foreach $file (keys(%Age)) { $test = -M $file; print STDERR "AGES: $file -- $test -- $Age{$file}\n" if $debug; if ( $test < $Age{$file} ) { $Age{$file} = $test; $doit++; } } print STDERR "\n" if $debug; if ( $doit ) { print STDERR "RUNNING: $cmd at: ", `date`; system($cmd); print STDERR "\n"; } &fsleep($sleep); } exit 0; sub trim_ends { local($x) = @_; $x =~ s/^\s*//; $x =~ s/\s*$//; return $x; } sub basename { # Like basename(1), returns basename of a path. local($x) = @_; $x =~ s,/+$,,; # remove trailing /'s if ( $x =~ m,/([^/]+)$, ) { # check if matches / $x = $1; # grab stuff after the last / } $x = '.' if $x eq ''; # evidently input was null. return $x; } sub dirname { # Like dirname(1), returns dirname of a path. local($x) = @_; $x =~ s,/+$,,; # remove trailing /'s $x =~ s,/+,/,g; # change multiple /'s to single / if ( $x =~ m,/([^/]+)$, ) { # check if matches / $x = $`; # grab stuff before / $x = '/' if $x eq ''; # is root if null. } else { # it was a bare word without / $x = '.'; } $x = '.' if $x eq ''; # never return null string return $x; } sub fsleep { local($time) = @_; select(undef, undef, undef, $time) if $time; }