Home | History | Annotate | Line # | Download | only in libiberty
maint-tool revision 1.1.1.1.8.1
      1          1.1  christos #!/usr/bin/perl
      2          1.1  christos # -*- perl -*-
      3          1.1  christos 
      4          1.1  christos #   Copyright (C) 2001, 2007, 2010
      5          1.1  christos #   Free Software Foundation
      6          1.1  christos #
      7          1.1  christos # This file is part of the libiberty library.
      8          1.1  christos # Libiberty is free software; you can redistribute it and/or
      9          1.1  christos # modify it under the terms of the GNU Library General Public
     10          1.1  christos # License as published by the Free Software Foundation; either
     11          1.1  christos # version 2 of the License, or (at your option) any later version.
     12          1.1  christos #
     13          1.1  christos # Libiberty is distributed in the hope that it will be useful,
     14          1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15          1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16          1.1  christos # Library General Public License for more details.
     17          1.1  christos #
     18          1.1  christos # You should have received a copy of the GNU Library General Public
     19          1.1  christos # License along with libiberty; see the file COPYING.LIB.  If not,
     20          1.1  christos # write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
     21          1.1  christos # Boston, MA 02110-1301, USA.
     22          1.1  christos #
     23          1.1  christos # Originally written by DJ Delorie <dj (at] redhat.com>
     24          1.1  christos 
     25          1.1  christos 
     26          1.1  christos # This is a trivial script which checks the lists of C and O files in
     27          1.1  christos # the Makefile for consistency.
     28          1.1  christos 
     29          1.1  christos $mode = shift;
     30          1.1  christos $srcdir = ".";
     31          1.1  christos 
     32          1.1  christos if ($mode eq "-s") {
     33          1.1  christos     $srcdir = shift;
     34          1.1  christos     $mode = shift;
     35          1.1  christos }
     36          1.1  christos 
     37          1.1  christos &missing() if $mode eq "missing";
     38          1.1  christos &undoc() if $mode eq "undoc";
     39          1.1  christos &deps() if $mode eq "deps";
     40          1.1  christos 
     41          1.1  christos exit 0;
     42          1.1  christos 
     43          1.1  christos format STDOUT =
     44          1.1  christos ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~
     45          1.1  christos $out
     46          1.1  christos         ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
     47          1.1  christos $out
     48          1.1  christos .
     49          1.1  christos 
     50          1.1  christos ######################################################################
     51          1.1  christos 
     52          1.1  christos sub missing {
     53          1.1  christos 
     54          1.1  christos     opendir(S, $srcdir);
     55          1.1  christos     while ($f = readdir S) {
     56          1.1  christos 	$have{$f} = 1;
     57          1.1  christos     }
     58          1.1  christos     closedir(S);
     59          1.1  christos     opendir(S, ".");
     60          1.1  christos     while ($f = readdir S) {
     61          1.1  christos 	$have{$f} = 1;
     62          1.1  christos     }
     63          1.1  christos     closedir(S);
     64          1.1  christos 
     65          1.1  christos     for $a (@ARGV) {
     66          1.1  christos 	$listed{$a} = 1;
     67          1.1  christos 	$have{$a} = 0;
     68          1.1  christos     }
     69          1.1  christos 
     70          1.1  christos     for $f (sort keys %have) {
     71          1.1  christos 	next unless $have{$f};
     72          1.1  christos 	if ($f =~ /\.c$/) {
     73          1.1  christos 	    print "S $f\n";
     74          1.1  christos 	}
     75          1.1  christos     }
     76          1.1  christos     for $f (sort keys %listed) {
     77          1.1  christos 	if ($f =~ /(.*)\.c$/) {
     78          1.1  christos 	    $base = $1;
     79          1.1  christos 	    if (! $listed{"./$base.o"}) {
     80          1.1  christos 		print "O $f\n";
     81          1.1  christos 	    }
     82          1.1  christos 	}
     83          1.1  christos     }
     84          1.1  christos }
     85          1.1  christos 
     86          1.1  christos ######################################################################
     87          1.1  christos 
     88          1.1  christos sub undoc {
     89          1.1  christos 
     90          1.1  christos     opendir(S, $srcdir);
     91          1.1  christos     while ($file = readdir S) {
     92          1.1  christos 	if ($file =~ /\.texi$/) {
     93          1.1  christos 	    open(T, "$srcdir/$file");
     94          1.1  christos 	    while (<T>) {
     95          1.1  christos 		if (/^\@deftype[^\(]* ([^\s\(]+) *\(/) {
     96          1.1  christos 		    $documented{$1} = 1;
     97          1.1  christos 		}
     98          1.1  christos 	    }
     99          1.1  christos 	    close(T);
    100          1.1  christos 	}
    101          1.1  christos 	if ($file =~ /\.c$/) {
    102          1.1  christos 	    open(C, "$srcdir/$file");
    103          1.1  christos 	    while (<C>) {
    104          1.1  christos 		if (/\@undocumented (\S+)/) {
    105          1.1  christos 		    $documented{$1} = 1;
    106          1.1  christos 		}
    107          1.1  christos 		if (/^static /) {
    108          1.1  christos 		    if (! /[\(;]/) {
    109          1.1  christos 			s/[\r\n]+$/ /;
    110          1.1  christos 			$_ .= <C>;
    111          1.1  christos 		    }
    112          1.1  christos 		    while ($_ =~ /\([^\)]*$/) {
    113          1.1  christos 			s/[\r\n]+$/ /;
    114          1.1  christos 			$_ .= <C>;
    115          1.1  christos 		    }
    116          1.1  christos 		}
    117          1.1  christos 		s/ VPARAMS([ \(])/$1/;
    118          1.1  christos 		s/PREFIX\(([^\)]*)\)/byte_$1/;
    119          1.1  christos 		if (/^static [^\(]* ([^\s\(]+) *\(.*\)$/) {
    120          1.1  christos 		    $documented{$1} = 1;
    121          1.1  christos 		}
    122          1.1  christos 	    }
    123          1.1  christos 	}
    124          1.1  christos     }
    125          1.1  christos     closedir(D);
    126          1.1  christos 
    127          1.1  christos     # $out = join(' ', sort keys %documented);
    128          1.1  christos     # write;
    129          1.1  christos     # print "\n";
    130          1.1  christos 
    131          1.1  christos     system "etags $srcdir/*.c $srcdir/../include/*.h";
    132          1.1  christos     open(TAGS, "TAGS");
    133          1.1  christos     while (<TAGS>) {
    134          1.1  christos 	s/[\r\n]+$//;
    135          1.1  christos 	if (/^\014$/) {
    136          1.1  christos 	    $filename = <TAGS>;
    137          1.1  christos 	    $filename =~ s/[\r\n]+$//;
    138          1.1  christos 	    $filename =~ s/,\d+$//;
    139          1.1  christos 	    $filename =~ s@.*[/\\]@@;
    140          1.1  christos 	    next;
    141          1.1  christos 	}
    142          1.1  christos 	if ($filename =~ /\.c$/ ) {
    143          1.1  christos 	    next unless /^[_a-zA-Z]/;
    144          1.1  christos 	} else {
    145          1.1  christos 	    next unless /^\# *define/;
    146          1.1  christos 	    s/\# *define *//;
    147          1.1  christos 	}
    148          1.1  christos 
    149          1.1  christos 	s/ VPARAMS//;
    150          1.1  christos 	s/ *\177.*//;
    151          1.1  christos 	s/,$//;
    152          1.1  christos 	s/DEFUN\(//;
    153          1.1  christos 	s/\(//;
    154          1.1  christos 
    155          1.1  christos 	next if /^static /;
    156          1.1  christos 	next if /\s/;
    157          1.1  christos 	next if /^_/;
    158          1.1  christos 	next if $documented{$_};
    159          1.1  christos 	next if /_H_?$/;
    160          1.1  christos 
    161          1.1  christos 	if ($seen_in{$_} ne $filename) {
    162          1.1  christos 	    $saw{$_} ++;
    163          1.1  christos 	}
    164          1.1  christos 	$seen_in{$_} = $filename;
    165          1.1  christos     }
    166          1.1  christos 
    167          1.1  christos     for $k (keys %saw) {
    168          1.1  christos 	delete $saw{$k} if $saw{$k} > 1;
    169          1.1  christos     }
    170          1.1  christos 
    171          1.1  christos     for $k (sort keys %saw) {
    172          1.1  christos 	$fromfile{$seen_in{$k}} .= " " if $fromfile{$seen_in{$k}};
    173          1.1  christos 	$fromfile{$seen_in{$k}} .= $k;
    174          1.1  christos     }
    175          1.1  christos 
    176          1.1  christos     for $f (sort keys %fromfile) {
    177          1.1  christos 	$out = "$f: $fromfile{$f}";
    178          1.1  christos 	write;
    179          1.1  christos     }
    180          1.1  christos }
    181          1.1  christos 
    182          1.1  christos ######################################################################
    183          1.1  christos 
    184          1.1  christos sub deps_for {
    185          1.1  christos     my($f) = @_;
    186          1.1  christos     my(%d);
    187          1.1  christos     open(F, $f);
    188          1.1  christos     %d = ();
    189          1.1  christos     while (<F>) {
    190          1.1  christos 	if (/^#\s*include\s+["<](.*)[">]/) {
    191          1.1  christos 	    $d{$1} = 1;
    192          1.1  christos 	}
    193          1.1  christos     }
    194          1.1  christos     close(F);
    195          1.1  christos     return keys %d;
    196          1.1  christos }
    197          1.1  christos 
    198          1.1  christos sub canonicalize {
    199          1.1  christos     my ($p) = @_;
    200          1.1  christos     0 while $p =~ s@/\./@/@g;
    201          1.1  christos     0 while $p =~ s@^\./@@g;
    202          1.1  christos     0 while $p =~ s@/[^/]+/\.\./@/@g;
    203          1.1  christos     return $p;
    204          1.1  christos }
    205          1.1  christos 
    206          1.1  christos sub locals_first {
    207          1.1  christos     my ($a,$b) = @_;
    208          1.1  christos     return -1 if $a eq "config.h";
    209          1.1  christos     return  1 if $b eq "config.h";
    210          1.1  christos     return $a cmp $b;
    211          1.1  christos }
    212          1.1  christos 
    213          1.1  christos sub deps {
    214          1.1  christos 
    215          1.1  christos     $crule  = "\tif [ x\"\$(PICFLAG)\" != x ]; then \\\n";
    216          1.1  christos     $crule .= "\t  \$(COMPILE.c) \$(PICFLAG) \$< -o pic/\$@; \\\n";
    217          1.1  christos     $crule .= "\telse true; fi\n";
    218          1.1  christos     $crule .= "\t\$(COMPILE.c) \$< \$(OUTPUT_OPTION)\n";
    219          1.1  christos     $crule .= "\n";
    220          1.1  christos 
    221          1.1  christos     $incdir = shift @ARGV;
    222          1.1  christos 
    223          1.1  christos     opendir(INC, $incdir);
    224          1.1  christos     while ($f = readdir INC) {
    225  1.1.1.1.8.1       tls 	next unless $f =~ /\.h$/ || $f =~ /\.def$/;
    226          1.1  christos 	$mine{$f} = "\$(INCDIR)/$f";
    227          1.1  christos 	$deps{$f} = join(' ', &deps_for("$incdir/$f"));
    228          1.1  christos     }
    229          1.1  christos     $mine{'config.h'} = "config.h";
    230          1.1  christos 
    231          1.1  christos     opendir(INC, $srcdir);
    232          1.1  christos     while ($f = readdir INC) {
    233          1.1  christos 	next unless $f =~ /\.h$/;
    234          1.1  christos 	$mine{$f} = "\$(srcdir)/$f";
    235          1.1  christos 	$deps{$f} = join(' ', &deps_for("$srcdir/$f"));
    236          1.1  christos     }
    237          1.1  christos     $mine{'config.h'} = "config.h";
    238          1.1  christos 
    239          1.1  christos     open(IN, "$srcdir/Makefile.in");
    240          1.1  christos     open(OUT, ">$srcdir/Makefile.tmp");
    241          1.1  christos     while (<IN>) {
    242          1.1  christos 	last if /remainder of this file/;
    243          1.1  christos 	print OUT;
    244          1.1  christos     }
    245          1.1  christos     print OUT "# The dependencies in the remainder of this file are automatically\n";
    246          1.1  christos     print OUT "# generated by \"make maint-deps\".  Manual edits will be lost.\n\n";
    247          1.1  christos 
    248          1.1  christos     opendir(S, $srcdir);
    249          1.1  christos     for $f (sort readdir S) {
    250          1.1  christos 	if ($f =~ /\.c$/) {
    251          1.1  christos 
    252          1.1  christos 	    %scanned = ();
    253          1.1  christos 	    @pending = &deps_for("$srcdir/$f");
    254          1.1  christos 	    while (@pending) {
    255          1.1  christos 		@tmp = @pending;
    256          1.1  christos 		@pending = ();
    257          1.1  christos 		for $p (@tmp) {
    258          1.1  christos 		    next unless $mine{$p};
    259          1.1  christos 		    if (!$scanned{$p}) {
    260          1.1  christos 			push(@pending, split(' ', $deps{$p}));
    261          1.1  christos 			$scanned{$p} = 1;
    262          1.1  christos 		    }
    263          1.1  christos 		}
    264          1.1  christos 	    }
    265          1.1  christos 	    @deps = sort { &locals_first($a,$b) } keys %scanned;
    266          1.1  christos 	    $obj = $f;
    267          1.1  christos 	    $obj =~ s/\.c$/.\$(objext)/;
    268          1.1  christos 	    $obj = "./$obj:";
    269          1.1  christos 	    if ($#deps >= 0) {
    270          1.1  christos 		print OUT "$obj \$(srcdir)/$f";
    271          1.1  christos 		$len = length("$obj $f");
    272          1.1  christos 		for $dt (@deps) {
    273          1.1  christos 		    $d = $mine{$dt};
    274          1.1  christos 		    if ($len + length($d) > 70) {
    275          1.1  christos 			printf OUT " \\\n\t$d";
    276          1.1  christos 			$len = 8 + length($d);
    277          1.1  christos 		    } else {
    278          1.1  christos 			print OUT " $d";
    279          1.1  christos 			$len += length($d) + 1;
    280          1.1  christos 		    }
    281          1.1  christos 		}
    282          1.1  christos 		print OUT "\n";
    283          1.1  christos 	    } else {
    284          1.1  christos 		print OUT "$obj \$(srcdir)/$f\n";
    285          1.1  christos 	    }
    286          1.1  christos 	    $c = $crule;
    287          1.1  christos 	    $c =~ s@\$\<@\$\(srcdir\)\/$f@g;
    288          1.1  christos 	    print OUT $c;
    289          1.1  christos 	}
    290          1.1  christos     }
    291          1.1  christos     closedir(S);
    292          1.1  christos     close(IN);
    293          1.1  christos     close(OUT);
    294          1.1  christos 
    295          1.1  christos     rename("$srcdir/Makefile.tmp", "$srcdir/Makefile.in");
    296          1.1  christos }
    297