This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add comment explaining where terrible code comes from
[perl5.git] / Porting / checkcfgvar.pl
1 #!/usr/bin/perl -w
2
3 #
4 # Check that the various config.sh-clones have (at least) all the
5 # same symbols as the top-level config_h.SH so that the (potentially)
6 # needed symbols are not lagging after how Configure thinks the world
7 # is laid out.
8 #
9 # VMS is probably not handled properly here, due to their own
10 # rather elaborate DCL scripting.
11 #
12
13 use strict;
14
15 my $MASTER_CFG = "config_h.SH";
16 my %MASTER_CFG;
17
18 my @CFG = (
19            # This list contains both 5.8.x and 5.9.x files,
20            # we check from MANIFEST whether they are expected to be present.
21            # We can't base our check on $], because that's the version of the
22            # perl that we are running, not the version of the source tree.
23            "Cross/config.sh-arm-linux",
24            "epoc/config.sh",
25            "NetWare/config.wc",
26            "symbian/config.sh",
27            "uconfig.sh",
28            "plan9/config_sh.sample",
29            "vos/config.alpha.def",
30            "vos/config.ga.def",
31            "win32/config.bc",
32            "win32/config.gc",
33            "win32/config.gc64",
34            "win32/config.gc64nox",
35            "win32/config.vc",
36            "win32/config.vc64",
37            "win32/config.ce",
38            "configure.com",
39            "Porting/config.sh",
40           );
41
42 sub read_file {
43     my ($fn, $sub) = @_;
44     if (open(my $fh, $fn)) {
45         local $_;
46         while (<$fh>) {
47             &$sub;
48         }
49     } else {
50         die "$0: Failed to open '$fn' for reading: $!\n";
51     }
52 }
53
54 sub config_h_SH_reader {
55     my $cfg = shift;
56     return sub {
57         while (/[^\\]\$([a-z]\w+)/g) {
58             my $v = $1;
59             next if $v =~ /^(CONFIG_H|CONFIG_SH)$/;
60             $cfg->{$v}++;
61         }
62     }
63 }
64
65 read_file($MASTER_CFG,
66           config_h_SH_reader(\%MASTER_CFG));
67
68 my %MANIFEST;
69
70 read_file("MANIFEST",
71           sub {
72               $MANIFEST{$1}++ if /^(.+?)\t/;
73           });
74
75 my @MASTER_CFG = sort keys %MASTER_CFG;
76
77 sub check_cfg {
78     my ($fn, $cfg) = @_;
79     for my $v (@MASTER_CFG) {
80         print "$fn: missing '$v'\n" unless exists $cfg->{$v};
81     }
82 }
83
84 for my $cfg (@CFG) {
85     unless (exists $MANIFEST{$cfg}) {
86         print STDERR "[skipping not-expected '$cfg']\n";
87         next;
88     }
89     my %cfg;
90     read_file($cfg,
91               sub {
92                   return if /^\#/ || /^\s*$/ || /^\:/;
93                   if ($cfg eq 'configure.com') {
94                       s/(\s*!.*|\s*)$//; # remove trailing comments or whitespace
95                       return if ! /^\$\s+WC "(\w+)='(.*)'"$/;
96                   }
97                   # foo='bar'
98                   # foo=bar
99                   # $foo='bar' # VOS 5.8.x specialty
100                   # $foo=bar   # VOS 5.8.x specialty
101                   if (/^\$?(\w+)='(.*)'$/) {
102                       $cfg{$1}++;
103                   }
104                   elsif (/^\$?(\w+)=(.*)$/) {
105                       $cfg{$1}++;
106                   }
107                   elsif (/^\$\s+WC "(\w+)='(.*)'"$/) {
108                       $cfg{$1}++;
109                   } else {
110                       warn "$cfg:$.:$_";
111                   }
112               });
113     if ($cfg eq 'configure.com') {
114         $cfg{startperl}++; # Cheat.
115     }
116     check_cfg($cfg, \%cfg);
117 }