2 # SPDX-License-Identifier: GPL-2.0
15 my $prefix="Documentation/features";
18 "debug|d+" => \$debug,
26 pod2usage(1) if $help;
27 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
29 pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2);
31 my ($cmd, $arg) = @ARGV;
33 pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate");
35 require Data::Dumper if ($debug);
41 # Displays an error message, printing file name and line
43 sub parse_error($$$$) {
44 my ($file, $ln, $msg, $data) = @_;
48 print STDERR "Warning: file $file#$ln:\n\t$msg";
51 print STDERR ". Line\n\t\t$data";
58 # Parse a features file, storing its contents at %data
61 my $h_name = "Feature";
62 my $h_kconfig = "Kconfig";
63 my $h_description = "Description";
64 my $h_subsys = "Subsystem";
65 my $h_status = "Status";
66 my $h_arch = "Architecture";
68 my $max_size_name = length($h_name);
69 my $max_size_kconfig = length($h_kconfig);
70 my $max_size_description = length($h_description);
71 my $max_size_subsys = length($h_subsys);
72 my $max_size_status = length($h_status);
73 my $max_size_arch = length($h_arch);
76 my $file = $File::Find::name;
78 my $mode = (stat($file))[2];
79 return if ($mode & S_IFDIR);
80 return if ($file =~ m,($prefix)/arch-support.txt,);
81 return if (!($file =~ m,arch-support.txt$,));
84 $subsys = $2 if ( m,.*($prefix)/([^/]+).*,);
86 if (length($subsys) > $max_size_subsys) {
87 $max_size_subsys = length($subsys);
98 print STDERR "Opening $file\n" if ($debug > 1);
104 if (m/^\#\s+Feature\s+name:\s*(.*\S)/) {
106 if (length($name) > $max_size_name) {
107 $max_size_name = length($name);
111 if (m/^\#\s+Kconfig:\s*(.*\S)/) {
113 if (length($kconfig) > $max_size_kconfig) {
114 $max_size_kconfig = length($kconfig);
118 if (m/^\#\s+description:\s*(.*\S)/) {
120 if (length($description) > $max_size_description) {
121 $max_size_description = length($description);
126 next if (m/^\s*\-+\s*$/);
127 next if (m/^\s*\|\s*arch\s*\|\s*status\s*\|\s*$/);
133 if (m/^\s*\|\s*(\S+):\s*\|\s*(\S+)\s*\|\s*$/) {
137 if (length($status) > $max_size_status) {
138 $max_size_status = length($status);
140 if (length($a) > $max_size_arch) {
141 $max_size_arch = length($a);
144 $status = "---" if ($status =~ m/^\.\.$/);
147 $arch_table{$a} = $status;
151 #Everything else is an error
152 parse_error($file, $ln, "line is invalid", $_);
157 parse_error($file, $ln, "Feature name not found", "");
161 parse_error($file, $ln, "Subsystem not found", "") if (!$subsys);
162 parse_error($file, $ln, "Kconfig not found", "") if (!$kconfig);
163 parse_error($file, $ln, "Description not found", "") if (!$description);
166 parse_error($file, $ln, "Architecture table not found", "");
170 $data{$name}->{where} = $file;
171 $data{$name}->{subsys} = $subsys;
172 $data{$name}->{kconfig} = $kconfig;
173 $data{$name}->{description} = $description;
174 $data{$name}->{comments} = $comments;
175 $data{$name}->{table} = \%arch_table;
179 # Output feature(s) for a given architecture
181 sub output_arch_table {
182 my $title = "Feature status on $arch architecture";
184 print "=" x length($title) . "\n";
186 print "=" x length($title) . "\n\n";
188 print "=" x $max_size_subsys;
190 print "=" x $max_size_name;
192 print "=" x $max_size_kconfig;
194 print "=" x $max_size_status;
196 print "=" x $max_size_description;
198 printf "%-${max_size_subsys}s ", $h_subsys;
199 printf "%-${max_size_name}s ", $h_name;
200 printf "%-${max_size_kconfig}s ", $h_kconfig;
201 printf "%-${max_size_status}s ", $h_status;
202 printf "%-${max_size_description}s\n", $h_description;
203 print "=" x $max_size_subsys;
205 print "=" x $max_size_name;
207 print "=" x $max_size_kconfig;
209 print "=" x $max_size_status;
211 print "=" x $max_size_description;
214 foreach my $name (sort {
215 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
216 ($data{$a}->{name} cmp $data{$b}->{name})
218 next if ($feat && $name ne $feat);
220 my %arch_table = %{$data{$name}->{table}};
221 printf "%-${max_size_subsys}s ", $data{$name}->{subsys};
222 printf "%-${max_size_name}s ", $name;
223 printf "%-${max_size_kconfig}s ", $data{$name}->{kconfig};
224 printf "%-${max_size_status}s ", $arch_table{$arch};
225 printf "%-${max_size_description}s\n", $data{$name}->{description};
228 print "=" x $max_size_subsys;
230 print "=" x $max_size_name;
232 print "=" x $max_size_kconfig;
234 print "=" x $max_size_status;
236 print "=" x $max_size_description;
241 # Output a feature on all architectures
244 my $title = "Feature $feat";
246 print "=" x length($title) . "\n";
248 print "=" x length($title) . "\n\n";
250 print ":Subsystem: $data{$feat}->{subsys} \n" if ($data{$feat}->{subsys});
251 print ":Kconfig: $data{$feat}->{kconfig} \n" if ($data{$feat}->{kconfig});
253 my $desc = $data{$feat}->{description};
254 $desc =~ s/^([a-z])/\U$1/;
256 print "\n$desc.\n\n";
258 my $com = $data{$feat}->{comments};
263 print "--------\n\n";
267 print "=" x $max_size_arch;
269 print "=" x $max_size_status;
272 printf "%-${max_size_arch}s ", $h_arch;
273 printf "%-${max_size_status}s", $h_status . "\n";
275 print "=" x $max_size_arch;
277 print "=" x $max_size_status;
280 my %arch_table = %{$data{$feat}->{table}};
281 foreach my $arch (sort keys %arch_table) {
282 printf "%-${max_size_arch}s ", $arch;
283 printf "%-${max_size_status}s\n", $arch_table{$arch};
286 print "=" x $max_size_arch;
288 print "=" x $max_size_status;
293 # Output all features for all architectures
296 sub matrix_lines($$) {
318 print $fill x $max_size_name;
320 print $fill x $max_size_kconfig;
322 print $fill x $max_size_description;
324 print $ln_marker x $max_size_arch;
326 print $ln_marker x $max_size_status;
331 my $title = "Feature status on all architectures";
333 print "=" x length($title) . "\n";
335 print "=" x length($title) . "\n\n";
338 foreach my $name (sort {
339 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) or
343 if ($cur_subsys ne $data{$name}->{subsys}) {
344 if ($cur_subsys ne "") {
348 $cur_subsys = $data{$name}->{subsys};
350 my $title = "Subsystem: $cur_subsys";
352 print "=" x length($title) . "\n\n";
355 printf "|%-${max_size_name}s", $h_name;
356 printf "|%-${max_size_kconfig}s", $h_kconfig;
357 printf "|%-${max_size_description}s", $h_description;
359 printf "|%-${max_size_arch}s", $h_arch;
360 printf "|%-${max_size_status}s|\n", $h_status;
365 my %arch_table = %{$data{$name}->{table}};
367 foreach my $arch (sort keys %arch_table) {
369 printf "|%-${max_size_name}s", $name;
370 printf "|%-${max_size_kconfig}s", $data{$name}->{kconfig};
371 printf "|%-${max_size_description}s", $data{$name}->{description};
376 printf "|%-${max_size_name}s", "";
377 printf "|%-${max_size_kconfig}s", "";
378 printf "|%-${max_size_description}s", "";
380 printf "|%-${max_size_arch}s", $arch;
381 printf "|%-${max_size_status}s|\n", $arch_table{$arch};
389 # Parses all feature files located at $prefix dir
391 find({wanted =>\&parse_feat, no_chdir => 1}, $prefix);
393 print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug);
396 # Handles the command
398 if ($cmd eq "current") {
399 $arch = qx(uname -m | sed 's/x86_64/x86/' | sed 's/i386/x86/');
403 if ($cmd ne "validate") {
417 get_feat.pl - parse the Linux Feature files and produce a ReST book.
421 B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>]
422 [--arch=<arch>] [--feat=<feature>] <COMAND> [<ARGUMENT>]
424 Where <COMMAND> can be:
428 B<current> - output features for this machine's architecture
430 B<rest> - output features in ReST markup language
432 B<validate> - validate the feature contents
442 Output features for an specific architecture, optionally filtering for
443 a single specific feature.
447 Output features for a single specific architecture.
451 Changes the location of the Feature files. By default, it uses
452 the Documentation/features directory.
456 Put the script in verbose mode, useful for debugging. Can be called multiple
457 times, to increase verbosity.
461 Prints a brief help message and exits.
465 Prints the manual page and exits.
471 Parse the Linux feature files from Documentation/features (by default),
472 optionally producing results at ReST format.
474 It supports output data per architecture, per feature or a
475 feature x arch matrix.
477 When used with B<rest> command, it will use either one of the tree formats:
479 If neither B<--arch> or B<--feature> arguments are used, it will output a
480 matrix with features per architecture.
482 If B<--arch> argument is used, it will output the features availability for
483 a given architecture.
485 If B<--feat> argument is used, it will output the content of the feature
486 file using ReStructured Text markup.
490 Report bugs to Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
494 Copyright (c) 2019 by Mauro Carvalho Chehab <mchehab+samsung@kernel.org>.
496 License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
498 This is free software: you are free to change and redistribute it.
499 There is NO WARRANTY, to the extent permitted by law.