source: tags/ms_ra2q56/SOURCE_TOOLS/binuptodate.pl

Last change on this file was 17618, checked in by westram, 6 years ago
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my $args = @ARGV;
7if ($args==0) { die "Usage: binuptodate.pl target [sources]+\n"; }
8my $target = $ARGV[0];
9my $arbhome = $ENV{'ARBHOME'};
10(-d $arbhome) || die "\$arbhome has to contain the name of a directory.\n";
11my $target_date = -1;
12
13sub filedate($) {
14  my $filename = $_[0];
15  my @stat_res = stat($filename);
16  return($stat_res[9]); # the files modification date
17}
18
19sub ok_if_older($) {
20  my $filename = $_[0];
21
22}
23
24sub 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
34sub 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
76eval { uptodate(); };
77if ($@) {
78  print STDERR "$@-> rebuilding $target (".localtime($target_date).")\n";
79  exit(1);
80}
81
82print STDERR "$target is up-to-date.\n";
83exit(0);
84
Note: See TracBrowser for help on using the repository browser.