source: branches/port5/SOURCE_TOOLS/fix_depends.pl

Last change on this file was 5470, checked in by westram, 17 years ago
  • Makefile: - exclude .svn while cleaning
  • SOURCE_TOOLS/find_newest_source.pl: - ignore .svn dirs
  • SOURCE_TOOLS/fix_depends.pl: - comment
  • SOURCE_TOOLS/grepx.pl: - updated from other location
  • SOURCE_TOOLS/prep_old_arb_versions: - obsolete (was cvs specific)
  • SOURCE_TOOLS/tabBrake.pl: - ignore .svn subdirs
  • WINDOW/AW_status.cxx: - comment
  • util/arb_compress: - excludes .svn
  • util/arb_srclst: - obsolete (arb_srclst.pl is used)
  • util/arb_srclst.pl: - added MAKEBIN and LIBLINK (empty directories no longer in repository)
    • read .svn/entries if present
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1#!/usr/bin/perl -w
2#
3# This script parses and fixes dependency lines in Makefiles:
4# 1. Searches for a line containing '# DO NOT DELETE'
5# 2. Lines after that point are modified like follows:
6#    a. hardcoded directory path to $ARBHOME (environment variable)
7#       is replaced by '$(ARBHOME)'
8#    b. split lines with multiple dependencies
9#    c. sort lines
10#
11# Goal of this script is to unify the result of 'make depends'
12# to avoid CVS/SVN changes caused by formatting.
13
14my $arbhome = qr/$ENV{ARBHOME}/;
15my $makedependlineseen = 0;
16my @depends;
17
18if (0) {
19  foreach (<>) {
20    print "ALL: $_";
21  }
22
23  die "done";
24}
25
26sub fix_name($) {
27  my ($name) = @_;
28  $name =~ s/^$arbhome/\$\(ARBHOME\)/ig; # translate $ARBHOME
29  $name =~ s/^.\///ig; # remove './' at start
30 
31  # ensure there's a / behind '$(ARBHOME)'
32  if ($name =~ /\$\(ARBHOME\)[^\/]/) {
33    $name =~ s/\$\(ARBHOME\)/\$\(ARBHOME\)\//ig;
34  }
35
36  $name;
37}
38
39# read input stream
40foreach (<>) {
41  if ($makedependlineseen==0) { # simply forward lines before 'DO NOT DELETE'
42    print "$_";
43    if (/^\# DO NOT DELETE/) { $makedependlineseen = 1; }
44  }
45  else { # put lines behind into '@depends'
46    chomp;
47    if (/^ *[\/\$a-z]/i) {
48      if (/^([^:]*): *(.*)$/) {
49        my $file       = $1;
50        my $depends_on = $2;
51        $file = fix_name($file);
52
53        while ($depends_on =~ / /) { # split lines with multiple dependencies
54          my $name = $`;
55          my $rest = $';
56          $name = fix_name($name);
57          push @depends, "$file: $name";
58          $depends_on = $rest;
59        }
60        $depends_on = fix_name($depends_on);
61        $_ = "$file: $depends_on";
62      }
63      push @depends,$_;
64    }
65  }
66}
67
68print "\n# Do not add dependencies manually - use 'make depend' in \$ARBHOME\n";
69print "# For formatting issues see SOURCE_TOOLS/fix_depends.pl\n";
70
71# sort dependency lines
72
73sub beautiful($$) {
74  # sorts files alphabethically (ign. case)
75  # sorts local dependencies first (for each file)
76  my ($a,$b) = @_;
77  my ($ap,$bp) = ('','');
78  ($a,$b) = (lc($a),lc($b));
79
80  if ($a =~ /^[^:]*:/) { $ap = $&; }
81  if ($b =~ /^[^:]*:/) { $bp = $&; }
82
83  my $res = $ap cmp $bp;
84
85  if ($res == 0) {
86    if ($a =~ /\$/) {
87      if ($b =~ /\$/) { $a cmp $b; }
88      else { 1; }
89    }
90    else {
91      if ($b =~ /\$/) { -1; }
92      else { $a cmp $b; }
93    }
94  }
95  else {
96    $res;
97  }
98}
99
100@depends = sort beautiful @depends;
101
102# print dependency lines
103
104my $prefix = '';
105foreach (@depends) {
106  my $tprefix = '';
107  if (/^([^:]*):/) { $tprefix = $1; }
108  if ($tprefix ne $prefix) {
109    print "\n"; # empty line between different files
110    $prefix = $tprefix;
111  }
112  print "$_\n";
113}
Note: See TracBrowser for help on using the repository browser.