This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Faster feature checks
[perl5.git] / Porting / checkcfguse.pl
CommitLineData
95318fb6
JH
1#!/usr/bin/perl -w
2
3#
4# checkcfguse.pl
5#
6# (1) finds all the Configure/config symbols
7#
8# (2) greps for their use in the core files and shows which ones.
9#
10
11use strict;
12use warnings;
13
14my %SYM;
15
16my @PAT =
17 (
18 [
19 # The format is:
20 # (1) aref of filename glob patterns
21 # (2) aref of qr patterns, the submatch $1 is the symbol name
22 [
23 "config_h.SH",
24 ],
25 [
26 qr/^#\$(\w+)\s+(\w+)/,
27 ],
28 ],
29 [
30 [
31 "NetWare/config_H.??",
32 "Porting/config.sh",
33 "plan9/config_h.sample",
34 "win32/config_H.??",
35 ],
36 qr{^(?:\Q/*\E)?#(?:define|undef)\s+(\w+)},
37 ],
38 [
39 [
40 "configure.com",
41 ],
42 qr{^(\w+)="(?:define|undef)"},
43 ],
44 );
45
46{
47 print STDERR "$0: Looking for symbols...\n";
48 for my $pat (@PAT) {
49 for my $fn (map { glob($_) } @{ $pat->[0] }) {
1ae6ead9 50 if (open(my $fh, '<', $fn)) {
95318fb6
JH
51 while (<$fh>) {
52 for my $p (@$pat) {
53 for my $sym (/$p/g) {
54 $SYM{$sym}{$fn}++;
55 }
56 }
57 }
58 }
59 }
60 }
61}
62
63printf(STDERR "$0: Found %d symbols\n", scalar keys %SYM);
64
65print STDERR "$0: Looking for their uses...\n";
66
67# Much too noisy grepping.
68delete $SYM{'_'};
69delete $SYM{'const'};
70
71my $SYM = join("|", sort { length($b) <=> length($a) || $a cmp $b } keys %SYM);
72
1ae6ead9 73open(my $mani, '<', "MANIFEST") or die "$0: Failed to open MANIFEST\n";
95318fb6
JH
74
75my %found;
76while (<$mani>) {
77 if (/^(\S+)\s+/) {
78 my $fn = $1;
79 # Skip matches from the config files themselves,
80 # from metaconfig generated files that refer to
81 # the config symbols, and from pods.
82 next if $fn =~ m{^(?:config_h.SH|Configure|configure\.com|Porting/(?:config|Glossary)|(?:NetWare|plan9|win32)/(?:config|(?:GNU)?[Mm]akefile)|uconfig)|\.pod$};
1ae6ead9 83 open my $fh, '<', $fn or die qq[$0: Failed to open $fn: $!];
95318fb6
JH
84 while (<$fh>) {
85 while (/\b($SYM)\b/go) {
86 $found{$1}{$fn}++;
87 }
88 }
89 }
90}
91
92for my $sym (sort keys %SYM) {
93 if (exists $found{$sym}) {
94 my @found = keys %{$found{$sym}};
95 print "$sym\t", join(" ", sort @found), "\n";
96 } else {
97 print "$sym\n";
98 }
99}