2 # SPDX-License-Identifier: GPL-2.0
4 BEGIN { $Pod::Usage
::Formatter
= 'Pod::Text::Termcap'; }
9 use Pod
::Usage
qw(pod2usage);
21 my $enable_lineno = 0;
22 my $show_warnings = 1;
23 my $prefix="Documentation/ABI";
24 my $sysfs_prefix="/sys";
28 my $dbg_what_parsing = 1;
29 my $dbg_what_open = 2;
30 my $dbg_dump_abi_structs = 4;
31 my $dbg_undefined = 8;
33 $Data::Dumper
::Indent
= 1;
34 $Data::Dumper
::Terse
= 1;
37 # If true, assumes that the description is formatted with ReST
39 my $description_is_rst = 1;
43 "enable-lineno" => \
$enable_lineno,
44 "rst-source!" => \
$description_is_rst,
47 "show-hints" => \
$hint,
48 "search-string=s" => \
$search_string,
52 pod2usage
(1) if $help;
53 pod2usage
(-exitstatus
=> 0, -noperldoc
, -verbose
=> 2) if $man;
55 pod2usage
(2) if (scalar @ARGV < 1 || @ARGV > 2);
57 my ($cmd, $arg) = @ARGV;
59 pod2usage
(2) if ($cmd ne "search" && $cmd ne "rest" && $cmd ne "validate" && $cmd ne "undefined");
60 pod2usage
(2) if ($cmd eq "search" && !$arg);
62 require Data
::Dumper
if ($debug & $dbg_dump_abi_structs);
68 # Displays an error message, printing file name and line
70 sub parse_error
($$$$) {
71 my ($file, $ln, $msg, $data) = @_;
73 return if (!$show_warnings);
77 print STDERR
"Warning: file $file#$ln:\n\t$msg";
80 print STDERR
". Line\n\t\t$data";
87 # Parse an ABI file, storing its contents at %data
90 my $file = $File::Find
::name
;
92 my $mode = (stat($file))[2];
93 return if ($mode & S_IFDIR
);
94 return if ($file =~ m
,/README
,);
95 return if ($file =~ m
,/\
.,);
96 return if ($file =~ m
,\
.(rej
|org
|orig
|bak
)$,);
102 $fn =~ s
,.*Documentation
/ABI/,,;
104 my $nametag = "File $fn";
105 $data{$nametag}->{what
} = "File $name";
106 $data{$nametag}->{type
} = "File";
107 $data{$nametag}->{file
} = $name;
108 $data{$nametag}->{filepath
} = $file;
109 $data{$nametag}->{is_file
} = 1;
110 $data{$nametag}->{line_no
} = 1;
113 $type =~ s
,.*/(.*)/.*,$1,;
124 print STDERR
"Opening $file\n" if ($debug & $dbg_what_open);
128 if (m/^(\S+)(:\s*)(.*)/i) {
129 my $new_tag = lc($1);
133 if (!($new_tag =~ m/(what|where|date|kernelversion|contact|description|users)/)) {
134 if ($tag eq "description") {
135 # New "tag" is actually part of
136 # description. Don't consider it a tag
138 } elsif ($tag ne "") {
139 parse_error
($file, $ln, "tag '$tag' is invalid", $_);
143 # Invalid, but it is a common mistake
144 if ($new_tag eq "where") {
145 parse_error
($file, $ln, "tag 'Where' is invalid. Should be 'What:' instead", "");
149 if ($new_tag =~ m/what/) {
151 $content =~ s/[,.;]$//;
153 push @
{$symbols{$content}->{file
}}, " $file:" . ($ln - 1);
155 if ($tag =~ m/what/) {
156 $what .= "\xac" . $content;
159 parse_error
($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description
});
161 foreach my $w(split /\xac/, $what) {
162 $symbols{$w}->{xref
} = $what;
170 push @labels, [($content, $label)];
173 push @
{$data{$nametag}->{symbols
}}, $content if ($data{$nametag}->{what
});
177 if ($tag ne "" && $new_tag) {
181 @
{$data{$what}->{label_list
}} = @labels if ($data{$nametag}->{what
});
186 $data{$what}->{type
} = $type;
187 if (!defined($data{$what}->{file
})) {
188 $data{$what}->{file
} = $name;
189 $data{$what}->{filepath
} = $file;
191 $data{$what}->{description
} .= "\n\n" if (defined($data{$what}->{description
}));
192 if ($name ne $data{$what}->{file
}) {
193 $data{$what}->{file
} .= " " . $name;
194 $data{$what}->{filepath
} .= " " . $file;
197 print STDERR
"\twhat: $what\n" if ($debug & $dbg_what_parsing);
198 $data{$what}->{line_no
} = $ln;
200 $data{$what}->{line_no
} = $ln if (!defined($data{$what}->{line_no
}));
204 parse_error
($file, $ln, "'What:' should come first:", $_);
207 if ($new_tag eq "description") {
209 $content = ' ' x
length($new_tag) . $sep . $content;
210 while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
211 if ($content =~ m/^(\s*)(\S.*)$/) {
212 # Preserve initial spaces for the first line
215 $data{$what}->{$tag} .= $content;
221 $data{$what}->{$tag} = $content;
227 # Store any contents before tags at the database
228 if (!$tag && $data{$nametag}->{what
}) {
229 $data{$nametag}->{description
} .= $_;
233 if ($tag eq "description") {
235 while ($content =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}
237 $data{$what}->{$tag} .= "\n";
241 if (!defined($space)) {
242 # Preserve initial spaces for the first line
243 if ($content =~ m/^(\s*)(\S.*)$/) {
248 $space = "" if (!($content =~ s/^($space)//));
250 $data{$what}->{$tag} .= $content;
255 $data{$what}->{$tag} .= "\n$1";
256 $data{$what}->{$tag} =~ s/\n+$//;
260 # Everything else is error
261 parse_error
($file, $ln, "Unexpected content", $_);
263 $data{$nametag}->{description
} =~ s/^\n+// if ($data{$nametag}->{description
});
265 parse_error
($file, $ln, "What '$what' doesn't have a description", "") if (!$data{$what}->{description
});
267 foreach my $w(split /\xac/,$what) {
268 $symbols{$w}->{xref
} = $what;
277 foreach my $what (keys %data) {
278 next if ($data{$what}->{file
} eq "File");
280 foreach my $p (@
{$data{$what}->{label_list
}}) {
281 my ($content, $label) = @
{$p};
282 $label = "abi_" . $label . " ";
283 $label =~ tr/A-Z/a-z/;
285 # Convert special chars to "_"
286 $label =~s/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xff])/_/g;
290 # Avoid duplicated labels
291 while (defined($labels{$label})) {
292 my @chars = ("A".."Z", "a".."z");
293 $label .= $chars[rand @chars];
297 $data{$what}->{label
} = $label;
299 # only one label is enough
306 # Outputs the book on ReST format
309 # \b doesn't work well with paths. So, we need to define something else:
310 # Boundaries are punct characters, spaces and end-of-line
311 my $start = qr
{(^|\s
|\
() }x
;
312 my $bondary = qr
{ ([,.:;\
)\s
]|\z
) }x
;
313 my $xref_match = qr
{ $start(\
/(sys|config|proc|dev|kvd)\/[^,.:;\
)\s
]+)$bondary }x
;
314 my $symbols = qr
{ ([\x01-\x08\x0e-\x1f\x21-\x2f\x3a-\x40\x7b-\xff]) }x
;
321 foreach my $what (sort {
322 ($data{$a}->{type
} eq "File") cmp ($data{$b}->{type
} eq "File") ||
325 my $type = $data{$what}->{type
};
327 my @file = split / /, $data{$what}->{file
};
328 my @filepath = split / /, $data{$what}->{filepath
};
330 if ($enable_lineno) {
331 printf ".. LINENO %s%s#%s\n\n",
333 $data{$what}->{line_no
};
338 if ($type ne "File") {
339 my $cur_part = $what;
341 if ($what =~ m
#^(\/?(?:[\w\-]+\/?){1,2})#) {
342 $cur_part = "Symbols under $1";
347 if ($cur_part ne "" && $part ne $cur_part) {
351 print "$part\n$bar\n\n";
354 printf ".. _%s:\n\n", $data{$what}->{label
};
356 my @names = split /\xac/,$w;
359 foreach my $name (@names) {
360 $name =~ s/$symbols/\\$1/g;
362 $len = length($name) if (length($name) > $len);
365 print "+-" . "-" x
$len . "-+\n";
366 foreach my $name (@names) {
367 printf "| %s", $name . " " x
($len - length($name)) . " |\n";
368 print "+-" . "-" x
$len . "-+\n";
374 for (my $i = 0; $i < scalar(@filepath); $i++) {
375 my $path = $filepath[$i];
378 $path =~ s
,.*/(.*/.*),$1,;;
379 $path =~ s
,[/\
-],_
,g
;;
380 my $fileref = "abi_file_".$path;
382 if ($type eq "File") {
383 print ".. _$fileref:\n\n";
385 print "Defined on file :ref:`$f <$fileref>`\n\n";
389 if ($type eq "File") {
392 print "$w\n$bar\n\n";
396 $desc = $data{$what}->{description
} if (defined($data{$what}->{description
}));
399 if (!($desc =~ /^\s*$/)) {
400 if ($description_is_rst) {
401 # Remove title markups from the description
402 # Having titles inside ABI files will only work if extra
403 # care would be taken in order to strictly follow the same
404 # level order for each markup.
405 $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g;
407 # Enrich text by creating cross-references
410 my $init_indent = -1;
411 my $literal_indent = -1;
413 open(my $fh, "+<", \
$desc);
414 while (my $d = <$fh>) {
415 my $indent = $d =~ m/^(\s+)/;
416 my $spaces = length($indent);
417 $init_indent = $indent if ($init_indent < 0);
418 if ($literal_indent >= 0) {
419 if ($spaces > $literal_indent) {
423 $literal_indent = -1;
426 if ($d =~ /()::$/ && !($d =~ /^\s*\.\./)) {
427 $literal_indent = $spaces;
431 $d =~ s
,Documentation
/(?!devicetree)(\S+)\.rst,:doc:`/$1`,g;
433 my @matches = $d =~ m,Documentation/ABI/([\w\/\-]+),g;
434 foreach my $f (@matches) {
437 $path =~ s,.*/(.*/.*),$1,;;
438 $path =~ s,[/\-],_,g;;
439 $xref .= " <abi_file_" . $path . ">";
440 $d =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
443 # Seek for cross reference symbols like /sys/...
444 @matches = $d =~ m/$xref_match/g;
446 foreach my $s (@matches) {
447 next if (!($s =~ m,/,));
448 if (defined($data{$s}) && defined($data{$s}->{label})) {
451 $xref =~ s/$symbols/\\$1/g;
452 $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";
454 $d =~ s,$start$s$bondary,$1$xref$2,g;
462 print "$new_desc\n\n";
466 # Remove title markups from the description, as they won't work
467 $desc =~ s/\n[\-\*\=\^\~]+\n/\n\n/g;
469 if ($desc =~ m/\:\n/ || $desc =~ m/\n[\t ]+/ || $desc =~ m/[\x00-\x08\x0b-\x1f\x7b-\xff]/) {
470 # put everything inside a code block
476 # Escape any special chars from description
477 $desc =~s/([\x00-\x08\x0b-\x1f\x21-\x2a\x2d\x2f\x3c-\x40\x5c\x5e-\x60\x7b-\xff])/\\$1/g;
482 print "DESCRIPTION MISSING for $what\n\n" if (!$data{$what}->{is_file});
485 if ($data{$what}->{symbols}) {
486 printf "Has the following ABI:\n\n";
488 foreach my $content(@{$data{$what}->{symbols}}) {
489 my $label = $data{$symbols{$content}->{xref}}->{label};
491 # Escape special chars from content
492 $content =~s/([\x00-\x1f\x21-\x2f\x3a-\x40\x7b-\xff])/\\$1/g;
494 print "- :ref:`$content <$label>`\n\n";
498 if (defined($data{$what}->{users})) {
499 my $users = $data{$what}->{users};
501 $users =~ s/\n/\n\t/g;
502 printf "Users:\n\t%s\n\n", $users if ($users ne "");
509 # Searches for ABI symbols
512 foreach my $what (sort keys %data) {
513 next if (!($what =~ m/($arg)/));
515 my $type = $data{$what}->{type};
516 next if ($type eq "File");
518 my $file = $data{$what}->{filepath};
520 $what =~ s/\xac/, /g;
524 print "\n$what\n$bar\n\n";
526 my $kernelversion = $data{$what}->{kernelversion} if (defined($data{$what}->{kernelversion}));
527 my $contact = $data{$what}->{contact} if (defined($data{$what}->{contact}));
528 my $users = $data{$what}->{users} if (defined($data{$what}->{users}));
529 my $date = $data{$what}->{date} if (defined($data{$what}->{date}));
530 my $desc = $data{$what}->{description} if (defined($data{$what}->{description}));
532 $kernelversion =~ s/^\s+// if ($kernelversion);
533 $contact =~ s/^\s+// if ($contact);
538 $date =~ s/^\s+// if ($date);
539 $desc =~ s/^\s+// if ($desc);
541 printf "Kernel version:\t\t%s\n", $kernelversion if ($kernelversion);
542 printf "Date:\t\t\t%s\n", $date if ($date);
543 printf "Contact:\t\t%s\n", $contact if ($contact);
544 printf "Users:\t\t\t%s\n", $users if ($users);
545 print "Defined on file(s):\t$file\n\n";
546 print "Description:\n\n$desc";
550 # Exclude /sys/kernel/debug and /sys/kernel/tracing from the search path
551 sub dont_parse_special_attributes {
552 if (($File::Find::dir =~ m,^/sys/kernel,)) {
553 return grep {!/(debug|tracing)/ } @_;
556 if (($File::Find::dir =~ m,^/sys/fs,)) {
557 return grep {!/(pstore|bpf|fuse)/ } @_;
573 $dir =~ s,^(.*/).*,$1,;
577 my $file_ref = \%root;
578 foreach my $edge(split "/", $dir) {
580 if (!defined ${$file_ref}{$edge}) {
581 ${$file_ref}{$edge} = { };
583 $file_ref = \%{$$file_ref{$edge}};
584 ${$file_ref}{"__name"} = [ $name ];
587 ${$file_ref}{$file} = {
588 "__name" => [ $name ]
591 return \%{$$file_ref{$file}};
598 # Traverse graph to find the reference
599 my $file_ref = \%root;
600 foreach my $edge(split "/", $file) {
601 $file_ref = \%{$$file_ref{$edge}} || die "Missing node!";
610 push @queue, $file_ref;
614 my $v = shift @queue;
615 my @child = keys(%{$v});
617 foreach my $c(@child) {
618 next if $seen{$$v{$c}};
619 next if ($c eq "__name");
621 if (!defined($$v{$c}{"__name"})) {
622 printf STDERR "Error: Couldn't find a non-empty name on a children of $file/.*: ";
623 print STDERR Dumper(%{$v});
628 my $name = @{$$v{$c}{"__name"}}[0];
629 if ($name =~ s#^$file/#$link/#) {
630 push @{$$v{$c}{"__name"}}, $name;
632 # Add child to the queue and mark as seen
633 push @queue, $$v{$c};
639 my $escape_symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x29\x2b-\x2d\x3a-\x40\x7b-\xfe]) }x;
640 sub parse_existing_sysfs {
641 my $file = $File::Find::name;
643 my $mode = (lstat($file))[2];
644 my $abs_file = abs_path($file);
648 push @tmp, $abs_file if ($abs_file ne $file);
650 foreach my $f(@tmp) {
651 # Ignore cgroup, as this is big and has zero docs under ABI
652 return if ($f =~ m#^/sys/fs/cgroup/#);
654 # Ignore firmware as it is documented elsewhere
655 # Either ACPI or under Documentation/devicetree/bindings/
656 return if ($f =~ m#^/sys/firmware/#);
658 # Ignore some sysfs nodes that aren't actually part of ABI
659 return if ($f =~ m#/sections|notes/#);
661 # Would need to check at
662 # Documentation/admin-guide/kernel-parameters.txt, but this
663 # is not easily parseable.
664 return if ($f =~ m#/parameters/#);
667 if (S_ISLNK($mode)) {
668 $aliases{$file} = $abs_file;
672 return if (S_ISDIR($mode));
674 # Trivial: file is defined exactly the same way at ABI What:
675 return if (defined($data{$file}));
676 return if (defined($data{$abs_file}));
678 push @files, graph_add_file($abs_file, "file");
692 $leave =~ s/[\(\)]//g;
694 # $leave is used to improve search performance at
695 # check_undefined_symbols, as the algorithm there can seek
696 # for a small number of "what". It also allows giving a
697 # hint about a leave with the same name somewhere else.
698 # However, there are a few occurences where the leave is
699 # either a wildcard or a number. Just group such cases
701 if ($leave =~ m/\.\*/ || $leave eq "" || $leave =~ /\\d/) {
712 my $file_ref = shift;
713 my $names_ref = shift;
714 my @names = @{$names_ref};
715 my $file = $names[0];
719 my $leave = get_leave($file);
720 if (!defined($leaf{$leave})) {
723 my @expr = @{$leaf{$leave}->{expr}};
724 die ("\rmissing rules for $leave") if (!defined($leaf{$leave}));
727 $path =~ s,(.*/).*,$1,;
729 if ($search_string) {
730 return if (!($file =~ m#$search_string#));
734 for (my $i = 0; $i < @names; $i++) {
735 if ($found_string && $hint) {
737 print STDERR "--> $names[$i]\n";
739 print STDERR " $names[$i]\n";
742 foreach my $re (@expr) {
743 print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined);
744 if ($names[$i] =~ $re) {
750 if ($leave ne "others") {
751 my @expr = @{$leaf{"others"}->{expr}};
752 for (my $i = 0; $i < @names; $i++) {
753 foreach my $re (@expr) {
754 print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined);
755 if ($names[$i] =~ $re) {
762 push @not_found, $file if (!$search_string || $found_string);
764 if ($hint && (!$search_string || $found_string)) {
765 my $what = $leaf{$leave}->{what};
766 $what =~ s/\xac/\n\t/g;
767 if ($leave ne "others") {
768 print STDERR "\r more likely regexes:\n\t$what\n";
770 print STDERR "\r tested regexes:\n\t$what\n";
775 sub check_undefined_symbols {
776 my $num_files = scalar @files;
778 my $start_time = times;
780 @files = sort @files;
782 my $last_time = $start_time;
784 # When either debug or hint is enabled, there's no sense showing
785 # progress, as the progress will be overriden.
786 if ($hint || ($debug && $dbg_undefined)) {
787 $next_i = $num_files;
791 $is_console = 1 if (-t STDERR);
793 for (my $i = 0; $i < $num_files; $i++) {
794 my $file_ref = $files[$i];
795 my @names = @{$$file_ref{"__name"}};
797 check_file($file_ref, \@names);
799 my $cur_time = times;
801 if ($i == $next_i || $cur_time > $last_time + 1) {
802 my $percent = $i * 100 / $num_files;
804 my $tm = $cur_time - $start_time;
805 my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm));
807 printf STDERR "\33[2K\r", if ($is_console);
808 printf STDERR "%s: processing sysfs files... %i%%: $names[0]", $time, $percent;
809 printf STDERR "\n", if (!$is_console);
812 $next_i = int (($percent + 1) * $num_files / 100);
813 $last_time = $cur_time;
817 my $cur_time = times;
818 my $tm = $cur_time - $start_time;
819 my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm));
821 printf STDERR "\33[2K\r", if ($is_console);
822 printf STDERR "%s: processing sysfs files... done\n", $time;
824 foreach my $file (@not_found) {
825 print "$file not found.\n";
829 sub undefined_symbols {
830 print STDERR "Reading $sysfs_prefix directory contents...";
832 wanted =>\&parse_existing_sysfs,
833 preprocess =>\&dont_parse_special_attributes,
836 print STDERR "done.\n";
838 $leaf{"others"}->{what} = "";
840 print STDERR "Converting ABI What fields into regexes...";
841 foreach my $w (sort keys %data) {
842 foreach my $what (split /\xac/,$w) {
843 next if (!($what =~ m/^$sysfs_prefix/));
845 # Convert what into regular expressions
847 # Escape dot characters
848 $what =~ s/\./\xf6/g;
850 # Temporarily change [0-9]+ type of patterns
851 $what =~ s/\[0\-9\]\+/\xff/g;
853 # Temporarily change [\d+-\d+] type of patterns
854 $what =~ s/\[0\-\d+\]/\xff/g;
855 $what =~ s/\[(\d+)\]/\xf4$1\xf5/g;
857 # Temporarily change [0-9] type of patterns
858 $what =~ s/\[(\d)\-(\d)\]/\xf4$1-$2\xf5/g;
860 # Handle multiple option patterns
861 $what =~ s/[\{\<\[]([\w_]+)(?:[,|]+([\w_]+)){1,}[\}\>\]]/($1|$2)/g;
865 $what =~ s,/\xf6..,/.*,g;
866 $what =~ s/\<[^\>]+\>/.*/g;
867 $what =~ s/\{[^\}]+\}/.*/g;
868 $what =~ s/\[[^\]]+\]/.*/g;
870 $what =~ s/[XYZ]/.*/g;
872 # Recover [0-9] type of patterns
876 # Remove duplicated spaces
879 # Special case: this ABI has a parenthesis on it
880 $what =~ s/sqrt\(x^2\+y^2\+z^2\)/sqrt\(x^2\+y^2\+z^2\)/;
882 # Special case: drop comparition as in:
883 # What: foo = <something>
884 # (this happens on a few IIO definitions)
885 $what =~ s,\s*\=.*$,,;
887 # Escape all other symbols
888 $what =~ s/$escape_symbols/\\$1/g;
889 $what =~ s/\\\\/\\/g;
890 $what =~ s/\\([\[\]\(\)\|])/$1/g;
891 $what =~ s/(\d+)\\(-\d+)/$1$2/g;
893 $what =~ s/\xff/\\d+/g;
895 # Special case: IIO ABI which a parenthesis.
896 $what =~ s/sqrt(.*)/sqrt\(.*\)/;
898 # Simplify regexes with multiple .*
899 $what =~ s#(?:\.\*){2,}##g;
900 # $what =~ s#\.\*/\.\*#.*#g;
902 # Recover dot characters
903 $what =~ s/\xf6/\./g;
905 my $leave = get_leave($what);
908 foreach my $l (split /\|/, $leave) {
909 if (defined($leaf{$l})) {
910 next if ($leaf{$l}->{what} =~ m/\b$what\b/);
911 $leaf{$l}->{what} .= "\xac" . $what;
914 $leaf{$l}->{what} = $what;
918 if ($search_string && $added) {
919 print STDERR "What: $what\n" if ($what =~ m#$search_string#);
925 foreach my $l (sort keys %leaf) {
927 foreach my $w(sort split /\xac/, $leaf{$l}->{what}) {
928 push @expr, qr /^$w$/;
930 $leaf{$l}->{expr} = \@expr;
933 # Take links into account
934 foreach my $link (sort keys %aliases) {
935 my $abs_file = $aliases{$link};
936 graph_add_link($abs_file, $link);
938 print STDERR "done.\n";
940 check_undefined_symbols;
943 # Ensure that the prefix will always end with a slash
944 # While this is not needed for find, it makes the patch nicer
945 # with --enable-lineno
948 if ($cmd eq "undefined" || $cmd eq "search") {
952 # Parses all ABI files located at $prefix dir
954 find({wanted =>\&parse_abi, no_chdir => 1}, $prefix);
956 print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug & $dbg_dump_abi_structs);
959 # Handles the command
961 if ($cmd eq "undefined") {
963 } elsif ($cmd eq "search") {
966 if ($cmd eq "rest") {
970 # Warn about duplicated ABI entries
971 foreach my $what(sort keys %symbols) {
972 my @files = @
{$symbols{$what}->{file
}};
974 next if (scalar(@files) == 1);
976 printf STDERR
"Warning: $what is defined %d times: @files\n",
985 get_abi.pl - parse the Linux ABI files and produce a ReST book.
989 B<get_abi.pl> [--debug <level>] [--enable-lineno] [--man] [--help]
990 [--(no-)rst-source] [--dir=<dir>] [--show-hints]
991 [--search-string <regex>]
992 <COMMAND> [<ARGUMENT>]
994 Where B<COMMAND> can be:
998 B<search> I<SEARCH_REGEX> - search for I<SEARCH_REGEX> inside ABI
1000 B<rest> - output the ABI in ReST markup language
1002 B<validate> - validate the ABI contents
1004 B<undefined> - existing symbols at the system that aren't
1005 defined at Documentation/ABI
1015 Changes the location of the ABI search. By default, it uses
1016 the Documentation/ABI directory.
1018 =item B<--rst-source> and B<--no-rst-source>
1020 The input file may be using ReST syntax or not. Those two options allow
1021 selecting between a rst-compliant source ABI (B<--rst-source>), or a
1022 plain text that may be violating ReST spec, so it requres some escaping
1023 logic (B<--no-rst-source>).
1025 =item B<--enable-lineno>
1027 Enable output of .. LINENO lines.
1029 =item B<--debug> I<debug level>
1031 Print debug information according with the level, which is given by the
1034 - 1: Debug parsing What entries from ABI files;
1035 - 2: Shows what files are opened from ABI files;
1036 - 4: Dump the structs used to store the contents of the ABI files.
1038 =item B<--show-hints>
1040 Show hints about possible definitions for the missing ABI symbols.
1041 Used only when B<undefined>.
1043 =item B<--search-string> I<regex string>
1045 Show only occurences that match a search string.
1046 Used only when B<undefined>.
1050 Prints a brief help message and exits.
1054 Prints the manual page and exits.
1060 Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI),
1061 allowing to search for ABI symbols or to produce a ReST book containing
1062 the Linux ABI documentation.
1066 Search for all stable symbols with the word "usb":
1070 $ scripts/get_abi.pl search usb --dir Documentation/ABI/stable
1074 Search for all symbols that match the regex expression "usb.*cap":
1078 $ scripts/get_abi.pl search usb.*cap
1082 Output all obsoleted symbols in ReST format
1086 $ scripts/get_abi.pl rest --dir Documentation/ABI/obsolete
1092 Report bugs to Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1096 Copyright (c) 2016-2021 by Mauro Carvalho Chehab <mchehab+huawei@kernel.org>.
1098 License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
1100 This is free software: you are free to change and redistribute it.
1101 There is NO WARRANTY, to the extent permitted by law.