Bump for 3.6-28
[LibreOffice.git] / solenv / bin / concat-deps.pl
blob935a50c68daa03833dfb42bf7f452169a22c3d8c
1 #! /usr/bin/env perl
3 # reads a list of dependency files from a file, opens and
4 # concatenates them, while eliding duplicate nop rules.
5 use File::Spec;
7 sub read_depfiles($)
9 my $name = shift;
10 my $depfh;
11 my @files;
12 open ($depfh, $name) || die "Can't open list of dependencies: $name: $!";
13 while (<$depfh>) {
14 push @files, split(/\s+/, $_);
16 close ($depfh);
18 # print STDERR "dep files: " . join ("'", @files) . "\n";
19 return @files;
22 my @depfiles = read_depfiles (shift @ARGV);
24 my %rules;
25 print "# concatenated, reduced dependencies generated by solenv/bin/concat-deps.pl\n";
26 print "# generated with \$(SRCDIR) = $ENV{SRCDIR}\n";
28 sub canonicalize_path($)
30 my $line = shift;
31 $line =~ /^(\s*)([^\s\n:]*)(.*\n?)$/;
32 my $pre = $1;
33 my $path = $2;
34 my $post =$3;
35 if (length($path) > 0 && index($path,$ENV{SRCDIR}) == 0) {
36 $path = File::Spec->rel2abs($2);
37 $path = "\$(SRCDIR)" . substr($path, length($ENV{SRCDIR}));
39 #print "## $pre$path$post";
40 return "$pre$path$post";
43 for my $fname (@depfiles) {
44 my $fileh;
46 next if ($fname eq '');
47 open ($fileh, $fname) || die "Can't open $fname: $!\n";
49 my $last = '';
50 while (<$fileh>) {
51 my $line = canonicalize_path($_);
52 # print "# $line";
53 if ($line eq "\n") {
54 if ($last =~ /^(.*):\s*$/) {
55 if (defined $rules{$1}) {
56 $last = '';
57 next;
59 $rules{$1} = 1;
62 print $last;
63 $last = $line;
65 print "$last\n"; # in case of missing newline
67 close ($fileh);