| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | my $args = @ARGV; |
|---|
| 7 | if ($args==0) { die "Usage: binuptodate.pl target [sources]+\n"; } |
|---|
| 8 | my $target = $ARGV[0]; |
|---|
| 9 | my $arbhome = $ENV{'ARBHOME'}; |
|---|
| 10 | (-d $arbhome) || die "\$arbhome has to contain the name of a directory.\n"; |
|---|
| 11 | my $target_date = -1; |
|---|
| 12 | |
|---|
| 13 | sub filedate($) { |
|---|
| 14 | my $filename = $_[0]; |
|---|
| 15 | my @stat_res = stat($filename); |
|---|
| 16 | return($stat_res[9]); # the files modification date |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | sub ok_if_older($) { |
|---|
| 20 | my $filename = $_[0]; |
|---|
| 21 | |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | sub first_existing(@) { |
|---|
| 25 | my $idx = 0; |
|---|
| 26 | my $count = @_; |
|---|
| 27 | while ($idx<$count) { |
|---|
| 28 | if (-f $_[$idx]) { return($_[$idx]); } |
|---|
| 29 | $idx++; |
|---|
| 30 | } |
|---|
| 31 | return undef; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | sub uptodate() { |
|---|
| 35 | my $stamp = `date +%M:%S.%N`; |
|---|
| 36 | chomp($stamp); |
|---|
| 37 | print STDERR "[$stamp] ------------------------------------------------ Checking $target\n"; |
|---|
| 38 | (-f $target) || die "Target '$target' not found\n"; |
|---|
| 39 | |
|---|
| 40 | my $source_idx = 1; |
|---|
| 41 | $target_date = filedate($target); |
|---|
| 42 | |
|---|
| 43 | while ($source_idx<$args) { |
|---|
| 44 | my $source = $ARGV[$source_idx]; |
|---|
| 45 | |
|---|
| 46 | if ($source =~ /^\-l/) { # handle libs specified with -l |
|---|
| 47 | my $libbase = $'; |
|---|
| 48 | my $fulllib = first_existing(( |
|---|
| 49 | $arbhome.'/lib/lib'.$libbase.'.a', |
|---|
| 50 | $arbhome.'/lib/lib'.$libbase.'.so', |
|---|
| 51 | )); |
|---|
| 52 | |
|---|
| 53 | if (not defined $fulllib) { |
|---|
| 54 | # print STDERR "can't detect where '$source' resides -- ignoring this dependency\n"; |
|---|
| 55 | $source = undef; |
|---|
| 56 | } |
|---|
| 57 | else { |
|---|
| 58 | # print STDERR "fulllib='$fulllib'\n"; |
|---|
| 59 | $source=$fulllib; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | elsif ($source =~ /^\-L/) { |
|---|
| 63 | $source = undef; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | if (defined $source) { |
|---|
| 67 | (-f $source) || die "Source missing: $source\n"; |
|---|
| 68 | my $source_date = filedate($source); |
|---|
| 69 | ($source_date <= $target_date) || die "Changed source: $source (".localtime($source_date).")\n"; |
|---|
| 70 | } |
|---|
| 71 | $source_idx++; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | eval { uptodate(); }; |
|---|
| 77 | if ($@) { |
|---|
| 78 | print STDERR "$@-> rebuilding $target (".localtime($target_date).")\n"; |
|---|
| 79 | exit(1); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | print STDERR "$target is up-to-date.\n"; |
|---|
| 83 | exit(0); |
|---|
| 84 | |
|---|