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