blob: 1d1408fad1301dee36c911cab5acdd7c4436c60a [file] [log] [blame]
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -03001#!/usr/bin/perl
Mauro Carvalho Chehabecb351f2019-06-20 14:23:10 -03002# SPDX-License-Identifier: GPL-2.0
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -03003
4use strict;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +01005use warnings;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -03006use Pod::Usage;
7use Getopt::Long;
8use File::Find;
9use Fcntl ':mode';
10
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +010011my $help = 0;
12my $man = 0;
13my $debug = 0;
14my $enable_lineno = 0;
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030015my $prefix="Documentation/ABI";
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030016
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +010017#
18# If true, assumes that the description is formatted with ReST
19#
20my $description_is_rst = 0;
21
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030022GetOptions(
23 "debug|d+" => \$debug,
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +010024 "enable-lineno" => \$enable_lineno,
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +010025 "rst-source!" => \$description_is_rst,
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030026 "dir=s" => \$prefix,
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030027 'help|?' => \$help,
28 man => \$man
29) or pod2usage(2);
30
31pod2usage(1) if $help;
32pod2usage(-exitstatus => 0, -verbose => 2) if $man;
33
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030034pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2);
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030035
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030036my ($cmd, $arg) = @ARGV;
37
Mauro Carvalho Chehab7ce7b892019-06-20 14:23:04 -030038pod2usage(2) if ($cmd ne "search" && $cmd ne "rest" && $cmd ne "validate");
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030039pod2usage(2) if ($cmd eq "search" && !$arg);
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030040
41require Data::Dumper if ($debug);
42
43my %data;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +010044my %symbols;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030045
46#
47# Displays an error message, printing file name and line
48#
49sub parse_error($$$$) {
50 my ($file, $ln, $msg, $data) = @_;
51
52 print STDERR "file $file#$ln: $msg at\n\t$data";
53}
54
55#
56# Parse an ABI file, storing its contents at %data
57#
58sub parse_abi {
59 my $file = $File::Find::name;
60
61 my $mode = (stat($file))[2];
62 return if ($mode & S_IFDIR);
63 return if ($file =~ m,/README,);
64
65 my $name = $file;
66 $name =~ s,.*/,,;
67
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -030068 my $nametag = "File $name";
69 $data{$nametag}->{what} = "File $name";
70 $data{$nametag}->{type} = "File";
71 $data{$nametag}->{file} = $name;
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -030072 $data{$nametag}->{filepath} = $file;
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -030073 $data{$nametag}->{is_file} = 1;
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +010074 $data{$nametag}->{line_no} = 1;
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -030075
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030076 my $type = $file;
77 $type =~ s,.*/(.*)/.*,$1,;
78
79 my $what;
80 my $new_what;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +010081 my $tag = "";
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030082 my $ln;
Mauro Carvalho Chehab6619c662019-06-20 14:22:56 -030083 my $xrefs;
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -030084 my $space;
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -030085 my @labels;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +010086 my $label = "";
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030087
88 print STDERR "Opening $file\n" if ($debug > 1);
89 open IN, $file;
90 while(<IN>) {
91 $ln++;
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -030092 if (m/^(\S+)(:\s*)(.*)/i) {
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030093 my $new_tag = lc($1);
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -030094 my $sep = $2;
95 my $content = $3;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030096
Mauro Carvalho Chehab7ce7b892019-06-20 14:23:04 -030097 if (!($new_tag =~ m/(what|where|date|kernelversion|contact|description|users)/)) {
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -030098 if ($tag eq "description") {
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -030099 # New "tag" is actually part of
100 # description. Don't consider it a tag
101 $new_tag = "";
Mauro Carvalho Chehab7d7ea8d2019-06-20 14:23:01 -0300102 } elsif ($tag ne "") {
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300103 parse_error($file, $ln, "tag '$tag' is invalid", $_);
104 }
105 }
106
Mauro Carvalho Chehab2c0700e2019-06-20 14:23:03 -0300107 # Invalid, but it is a common mistake
108 if ($new_tag eq "where") {
109 parse_error($file, $ln, "tag 'Where' is invalid. Should be 'What:' instead", $_);
110 $new_tag = "what";
111 }
112
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300113 if ($new_tag =~ m/what/) {
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300114 $space = "";
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100115 $content =~ s/[,.;]$//;
116
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100117 push @{$symbols{$content}->{file}}, " $file:" . ($ln - 1);
118
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300119 if ($tag =~ m/what/) {
120 $what .= ", " . $content;
121 } else {
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100122 if ($what) {
123 parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
124
125 foreach my $w(split /, /, $what) {
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100126 $symbols{$w}->{xref} = $what;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100127 };
128 }
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300129
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300130 $what = $content;
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300131 $label = $content;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300132 $new_what = 1;
133 }
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300134 push @labels, [($content, $label)];
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300135 $tag = $new_tag;
Mauro Carvalho Chehab6619c662019-06-20 14:22:56 -0300136
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100137 push @{$data{$nametag}->{symbols}}, $content if ($data{$nametag}->{what});
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300138 next;
139 }
140
Mauro Carvalho Chehab7d7ea8d2019-06-20 14:23:01 -0300141 if ($tag ne "" && $new_tag) {
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300142 $tag = $new_tag;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300143
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300144 if ($new_what) {
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100145 @{$data{$what}->{label_list}} = @labels if ($data{$nametag}->{what});
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300146 @labels = ();
147 $label = "";
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300148 $new_what = 0;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300149
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300150 $data{$what}->{type} = $type;
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100151 if (!defined($data{$what}->{file})) {
152 $data{$what}->{file} = $name;
153 $data{$what}->{filepath} = $file;
154 } else {
155 if ($name ne $data{$what}->{file}) {
156 $data{$what}->{file} .= " " . $name;
157 $data{$what}->{filepath} .= " " . $file;
158 }
159 }
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300160 print STDERR "\twhat: $what\n" if ($debug > 1);
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100161 $data{$what}->{line_no} = $ln;
162 } else {
163 $data{$what}->{line_no} = $ln if (!defined($data{$what}->{line_no}));
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300164 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300165
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300166 if (!$what) {
167 parse_error($file, $ln, "'What:' should come first:", $_);
168 next;
169 }
Mauro Carvalho Chehabf82a8a72020-10-30 08:40:23 +0100170 if ($new_tag eq "description") {
171 $sep =~ s,:, ,;
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +0100172 $content = ' ' x length($new_tag) . $sep . $content;
Mauro Carvalho Chehabf82a8a72020-10-30 08:40:23 +0100173 while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
174 if ($content =~ m/^(\s*)(\S.*)$/) {
175 # Preserve initial spaces for the first line
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +0100176 $space = $1;
Mauro Carvalho Chehabf82a8a72020-10-30 08:40:23 +0100177 $content = "$2\n";
178 $data{$what}->{$tag} .= $content;
179 } else {
180 undef($space);
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300181 }
Mauro Carvalho Chehabe9bca892020-10-30 08:40:21 +0100182
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300183 } else {
184 $data{$what}->{$tag} = $content;
185 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300186 next;
187 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300188 }
189
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300190 # Store any contents before tags at the database
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300191 if (!$tag && $data{$nametag}->{what}) {
192 $data{$nametag}->{description} .= $_;
Mauro Carvalho Chehab6619c662019-06-20 14:22:56 -0300193 next;
194 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300195
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300196 if ($tag eq "description") {
Mauro Carvalho Chehabe9bca892020-10-30 08:40:21 +0100197 my $content = $_;
198 while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
Mauro Carvalho Chehabf82a8a72020-10-30 08:40:23 +0100199 if (m/^\s*\n/) {
200 $data{$what}->{$tag} .= "\n";
201 next;
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300202 }
Mauro Carvalho Chehabf82a8a72020-10-30 08:40:23 +0100203
204 if (!defined($space)) {
205 # Preserve initial spaces for the first line
206 if ($content =~ m/^(\s*)(\S.*)$/) {
207 $space = $1;
208 $content = "$2\n";
209 }
210 } else {
211 $space = "" if (!($content =~ s/^($space)//));
212 }
213 $data{$what}->{$tag} .= $content;
214
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300215 next;
216 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300217 if (m/^\s*(.*)/) {
218 $data{$what}->{$tag} .= "\n$1";
219 $data{$what}->{$tag} =~ s/\n+$//;
220 next;
221 }
222
223 # Everything else is error
224 parse_error($file, $ln, "Unexpected line:", $_);
225 }
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100226 $data{$nametag}->{description} =~ s/^\n+// if ($data{$nametag}->{description});
227 if ($what) {
228 parse_error($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description});
229
230 foreach my $w(split /, /,$what) {
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100231 $symbols{$w}->{xref} = $what;
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100232 };
233 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300234 close IN;
235}
236
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100237sub create_labels {
238 my %labels;
239
240 foreach my $what (keys %data) {
241 next if ($data{$what}->{file} eq "File");
242
243 foreach my $p (@{$data{$what}->{label_list}}) {
244 my ($content, $label) = @{$p};
245 $label = "abi_" . $label . " ";
246 $label =~ tr/A-Z/a-z/;
247
248 # Convert special chars to "_"
249 $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g;
250 $label =~ s,_+,_,g;
251 $label =~ s,_$,,;
252
253 # Avoid duplicated labels
254 while (defined($labels{$label})) {
255 my @chars = ("A".."Z", "a".."z");
256 $label .= $chars[rand @chars];
257 }
258 $labels{$label} = 1;
259
260 $data{$what}->{label} = $label;
261
262 # only one label is enough
263 last;
264 }
265 }
266}
267
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300268#
269# Outputs the book on ReST format
270#
Mauro Carvalho Chehab45f96512019-06-20 14:23:00 -0300271
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300272sub output_rest {
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100273 create_labels();
274
Mauro Carvalho Chehab45f96512019-06-20 14:23:00 -0300275 foreach my $what (sort {
276 ($data{$a}->{type} eq "File") cmp ($data{$b}->{type} eq "File") ||
277 $a cmp $b
278 } keys %data) {
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300279 my $type = $data{$what}->{type};
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100280
281 my @file = split / /, $data{$what}->{file};
282 my @filepath = split / /, $data{$what}->{filepath};
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300283
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +0100284 if ($enable_lineno) {
285 printf "#define LINENO %s%s#%s\n\n",
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100286 $prefix, $file[0],
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +0100287 $data{$what}->{line_no};
288 }
289
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300290 my $w = $what;
291 $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g;
292
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100293 if ($type ne "File") {
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100294 printf ".. _%s:\n\n", $data{$what}->{label};
Mauro Carvalho Chehab45f96512019-06-20 14:23:00 -0300295
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100296 my @names = split /, /,$w;
Mauro Carvalho Chehab45f96512019-06-20 14:23:00 -0300297 my $len = 0;
298
299 foreach my $name (@names) {
300 $len = length($name) if (length($name) > $len);
301 }
302
303 print "What:\n\n";
304
305 print "+-" . "-" x $len . "-+\n";
306 foreach my $name (@names) {
307 printf "| %s", $name . " " x ($len - length($name)) . " |\n";
308 print "+-" . "-" x $len . "-+\n";
309 }
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100310
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100311 print "\n";
312 }
313
314 for (my $i = 0; $i < scalar(@filepath); $i++) {
315 my $path = $filepath[$i];
316 my $f = $file[$i];
317
318 $path =~ s,.*/(.*/.*),$1,;;
319 $path =~ s,[/\-],_,g;;
320 my $fileref = "abi_file_".$path;
321
322 if ($type eq "File") {
323 my $bar = $w;
324 $bar =~ s/./-/g;
325
326 print ".. _$fileref:\n\n";
327 print "$w\n$bar\n\n";
328 } else {
329 print "Defined on file :ref:`$f <$fileref>`\n\n";
330 }
Mauro Carvalho Chehab45f96512019-06-20 14:23:00 -0300331 }
332
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100333 my $desc = "";
334 $desc = $data{$what}->{description} if (defined($data{$what}->{description}));
335 $desc =~ s/\s+$/\n/;
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300336
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300337 if (!($desc =~ /^\s*$/)) {
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +0100338 if ($description_is_rst) {
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300339 print "$desc\n\n";
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +0100340 } else {
341 $desc =~ s/^\s+//;
342
343 # Remove title markups from the description, as they won't work
344 $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g;
345
346 if ($desc =~ m/\:\n/ || $desc =~ m/\n[\t ]+/ || $desc =~ m/[\x00-\x08\x0b-\x1f\x7b-\xff]/) {
347 # put everything inside a code block
348 $desc =~ s/\n/\n /g;
349
350 print "::\n\n";
351 print " $desc\n\n";
352 } else {
353 # Escape any special chars from description
354 $desc =~s/([\x00-\x08\x0b-\x1f\x21-\x2a\x2d\x2f\x3c-\x40\x5c\x5e-\x60\x7b-\xff])/\\$1/g;
355 print "$desc\n\n";
356 }
Mauro Carvalho Chehab4e6a6232019-06-20 14:22:57 -0300357 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300358 } else {
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300359 print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file});
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300360 }
Mauro Carvalho Chehab6619c662019-06-20 14:22:56 -0300361
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100362 if ($data{$what}->{symbols}) {
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300363 printf "Has the following ABI:\n\n";
364
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100365 foreach my $content(@{$data{$what}->{symbols}}) {
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100366 my $label = $data{$symbols{$content}->{xref}}->{label};
Mauro Carvalho Chehabd0ebaf52019-06-20 14:22:58 -0300367
368 # Escape special chars from content
369 $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
370
371 print "- :ref:`$content <$label>`\n\n";
372 }
373 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300374 }
375}
376
377#
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300378# Searches for ABI symbols
379#
380sub search_symbols {
381 foreach my $what (sort keys %data) {
382 next if (!($what =~ m/($arg)/));
383
384 my $type = $data{$what}->{type};
385 next if ($type eq "File");
386
387 my $file = $data{$what}->{filepath};
388
389 my $bar = $what;
390 $bar =~ s/./-/g;
391
392 print "\n$what\n$bar\n\n";
393
Mauro Carvalho Chehab234948b2020-10-30 08:40:24 +0100394 my $kernelversion = $data{$what}->{kernelversion} if (defined($data{$what}->{kernelversion}));
395 my $contact = $data{$what}->{contact} if (defined($data{$what}->{contact}));
396 my $users = $data{$what}->{users} if (defined($data{$what}->{users}));
397 my $date = $data{$what}->{date} if (defined($data{$what}->{date}));
398 my $desc = $data{$what}->{description} if (defined($data{$what}->{description}));
399
400 $kernelversion =~ s/^\s+// if ($kernelversion);
401 $contact =~ s/^\s+// if ($contact);
402 if ($users) {
403 $users =~ s/^\s+//;
404 $users =~ s/\n//g;
405 }
406 $date =~ s/^\s+// if ($date);
407 $desc =~ s/^\s+// if ($desc);
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300408
409 printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion);
410 printf "Date:\t\t\t%s\n", $date if ($date);
411 printf "Contact:\t\t%s\n", $contact if ($contact);
412 printf "Users:\t\t\t%s\n", $users if ($users);
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100413 print "Defined on file(s):\t$file\n\n";
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300414 print "Description:\n\n$desc";
415 }
416}
417
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +0100418# Ensure that the prefix will always end with a slash
419# While this is not needed for find, it makes the patch nicer
420# with --enable-lineno
421$prefix =~ s,/?$,/,;
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300422
423#
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300424# Parses all ABI files located at $prefix dir
425#
426find({wanted =>\&parse_abi, no_chdir => 1}, $prefix);
427
428print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug);
429
430#
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300431# Handles the command
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300432#
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100433if ($cmd eq "search") {
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300434 search_symbols;
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100435} else {
436 if ($cmd eq "rest") {
437 output_rest;
438 }
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300439
Mauro Carvalho Chehabc7ba3332020-10-30 08:40:25 +0100440 # Warn about duplicated ABI entries
441 foreach my $what(sort keys %symbols) {
442 my @files = @{$symbols{$what}->{file}};
443
444 next if (scalar(@files) == 1);
445
446 printf STDERR "Warning: $what is defined %d times: @files\n",
447 scalar(@files);
448 }
449}
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300450
451__END__
452
453=head1 NAME
454
455abi_book.pl - parse the Linux ABI files and produce a ReST book.
456
457=head1 SYNOPSIS
458
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +0100459B<abi_book.pl> [--debug] [--enable-lineno] [--man] [--help]
460 [--(no-)rst-source] [--dir=<dir>] <COMAND> [<ARGUMENT>]
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300461
462Where <COMMAND> can be:
463
464=over 8
465
466B<search> [SEARCH_REGEX] - search for [SEARCH_REGEX] inside ABI
467
Mauro Carvalho Chehab7ce7b892019-06-20 14:23:04 -0300468B<rest> - output the ABI in ReST markup language
469
470B<validate> - validate the ABI contents
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300471
472=back
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300473
474=head1 OPTIONS
475
476=over 8
477
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300478=item B<--dir>
479
480Changes the location of the ABI search. By default, it uses
481the Documentation/ABI directory.
482
Mauro Carvalho Chehab11ce90a2020-10-30 08:40:20 +0100483=item B<--rst-source> and B<--no-rst-source>
484
485The input file may be using ReST syntax or not. Those two options allow
486selecting between a rst-compliant source ABI (--rst-source), or a
487plain text that may be violating ReST spec, so it requres some escaping
488logic (--no-rst-source).
489
Mauro Carvalho Chehab61439c42020-10-30 08:40:22 +0100490=item B<--enable-lineno>
491
492Enable output of #define LINENO lines.
493
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300494=item B<--debug>
495
496Put the script in verbose mode, useful for debugging. Can be called multiple
497times, to increase verbosity.
498
499=item B<--help>
500
501Prints a brief help message and exits.
502
503=item B<--man>
504
505Prints the manual page and exits.
506
507=back
508
509=head1 DESCRIPTION
510
Mauro Carvalho Chehab33e3e992019-06-20 14:22:59 -0300511Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI),
512allowing to search for ABI symbols or to produce a ReST book containing
513the Linux ABI documentation.
514
515=head1 EXAMPLES
516
517Search for all stable symbols with the word "usb":
518
519=over 8
520
521$ scripts/get_abi.pl search usb --dir Documentation/ABI/stable
522
523=back
524
525Search for all symbols that match the regex expression "usb.*cap":
526
527=over 8
528
529$ scripts/get_abi.pl search usb.*cap
530
531=back
532
533Output all obsoleted symbols in ReST format
534
535=over 8
536
537$ scripts/get_abi.pl rest --dir Documentation/ABI/obsolete
538
539=back
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300540
541=head1 BUGS
542
Mauro Carvalho Chehab7ce7b892019-06-20 14:23:04 -0300543Report bugs to Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300544
545=head1 COPYRIGHT
546
Mauro Carvalho Chehab7ce7b892019-06-20 14:23:04 -0300547Copyright (c) 2016-2019 by Mauro Carvalho Chehab <mchehab+samsung@kernel.org>.
Mauro Carvalho Chehabbbc249f2019-06-20 14:22:55 -0300548
549License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
550
551This is free software: you are free to change and redistribute it.
552There is NO WARRANTY, to the extent permitted by law.
553
554=cut