source: trunk/SOURCE_TOOLS/gen_dep.pl

Last change on this file was 18914, checked in by westram, 3 years ago
  • fix error handling for piped commands in perl
    • when forking piped commands
      • use error message ($!) instead of exitcode ($?).
      • use message 'failed to fork'.
    • when closing piped commands
      • show IPC errors and exitcode of command.
  • Property svn:executable set to *
File size: 921 bytes
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6sub get_depends($) {
7  my ($lib) = @_;
8  my @depends = ();
9
10  my $cmd = './needed_libs.pl -D -U -n '.$lib;
11  # print "cmd=$cmd\n";
12
13  open(DEPENDS,$cmd.'|') || die "failed to fork '$cmd' (Reason: $!)";
14  foreach (<DEPENDS>) {
15    chomp;
16    my @d = split(/ /,$_);
17    foreach (@d) { push @depends, $_; }
18  }
19  close(DEPENDS) || die "failed to execute '$cmd' (Reason: $! exitcode=$?)";
20
21  return @depends;
22}
23
24sub main() {
25  my $args = scalar(@ARGV);
26  if ($args!=1) {
27    die "Usage: gen_dep.pl suffix\nFilter to create dep.*-files\n";
28  }
29
30  my $suffix = shift @ARGV;
31  foreach my $lib (<>) {
32    chomp($lib);
33
34    my @depends_on = get_depends($lib);
35
36    my $base = $lib;
37    $base =~ s/\.(a|o|so)$//;
38    if ($base =~ /^lib\/lib/) { $base = $'.'/'.$'; }
39
40    print "$base.$suffix:";
41    foreach (@depends_on) {
42      print " $_.$suffix";
43    }
44    print "\n";
45  }
46}
47main();
48
Note: See TracBrowser for help on using the repository browser.