Commit | Line | Data |
---|---|---|
acad74ad | 1 | #!/usr/bin/perl |
522c08cc | 2 | |
522c08cc RGS |
3 | # Check that the various config.sh-clones have (at least) all the |
4 | # same symbols as the top-level config_h.SH so that the (potentially) | |
5 | # needed symbols are not lagging after how Configure thinks the world | |
6 | # is laid out. | |
7 | # | |
a0e39d89 AT |
8 | # VMS is probably not handled properly here, due to their own |
9 | # rather elaborate DCL scripting. | |
522c08cc RGS |
10 | # |
11 | ||
12 | use strict; | |
acad74ad | 13 | use warnings; |
4ccedf19 | 14 | use autodie; |
acad74ad MB |
15 | |
16 | sub usage | |
17 | { | |
18 | my $err = shift and select STDERR; | |
818a19bd | 19 | print "usage: $0 [--list] [--regen] [--default=value]\n"; |
acad74ad MB |
20 | exit $err; |
21 | } # usage | |
22 | ||
23 | use Getopt::Long; | |
24 | my $opt_l = 0; | |
7ee20c71 | 25 | my $opt_r = 0; |
818a19bd | 26 | my $default; |
6692294e NC |
27 | my $tap = 0; |
28 | my $test; | |
acad74ad MB |
29 | GetOptions ( |
30 | "help|?" => sub { usage (0); }, | |
31 | "l|list!" => \$opt_l, | |
7ee20c71 | 32 | "regen" => \$opt_r, |
818a19bd | 33 | "default=s" => \$default, |
6692294e | 34 | "tap" => \$tap, |
acad74ad | 35 | ) or usage (1); |
522c08cc | 36 | |
7ee20c71 NC |
37 | require 'regen/regen_lib.pl' if $opt_r; |
38 | ||
522c08cc | 39 | my $MASTER_CFG = "config_h.SH"; |
7ee20c71 NC |
40 | # Inclusive bounds on the main part of the file, $section == 1 below: |
41 | my $first = qr/^Author=/; | |
42 | my $last = qr/^zip=/; | |
522c08cc RGS |
43 | |
44 | my @CFG = ( | |
522c08cc | 45 | # we check from MANIFEST whether they are expected to be present. |
bb0fc361 NC |
46 | # We can't base our check on $], because that's the version of the |
47 | # perl that we are running, not the version of the source tree. | |
522c08cc RGS |
48 | "Cross/config.sh-arm-linux", |
49 | "epoc/config.sh", | |
50 | "NetWare/config.wc", | |
51 | "symbian/config.sh", | |
52 | "uconfig.sh", | |
fc09a9a0 | 53 | "uconfig64.sh", |
522c08cc | 54 | "plan9/config_sh.sample", |
522c08cc | 55 | "win32/config.gc", |
e89c2dd0 CJ |
56 | "win32/config.gc64", |
57 | "win32/config.gc64nox", | |
522c08cc | 58 | "win32/config.vc", |
6ab0e26e | 59 | "win32/config.vc64", |
26d21fa1 | 60 | "win32/config.ce", |
a0e39d89 | 61 | "configure.com", |
d73cfe96 | 62 | "Porting/config.sh", |
522c08cc RGS |
63 | ); |
64 | ||
2dcb77c2 | 65 | my @MASTER_CFG; |
4ccedf19 | 66 | { |
2dcb77c2 | 67 | my %seen; |
4ccedf19 NC |
68 | open my $fh, '<', $MASTER_CFG; |
69 | while (<$fh>) { | |
2eacba2f | 70 | while (/[^\\]\$([a-z]\w+)/g) { |
522c08cc RGS |
71 | my $v = $1; |
72 | next if $v =~ /^(CONFIG_H|CONFIG_SH)$/; | |
2dcb77c2 | 73 | $seen{$v}++; |
522c08cc RGS |
74 | } |
75 | } | |
4ccedf19 | 76 | close $fh; |
2dcb77c2 | 77 | @MASTER_CFG = sort keys %seen; |
522c08cc RGS |
78 | } |
79 | ||
522c08cc RGS |
80 | my %MANIFEST; |
81 | ||
4ccedf19 NC |
82 | { |
83 | open my $fh, '<', 'MANIFEST'; | |
84 | while (<$fh>) { | |
85 | $MANIFEST{$1}++ if /^(.+?)\t/; | |
86 | } | |
87 | close $fh; | |
88 | } | |
522c08cc | 89 | |
6692294e NC |
90 | printf "1..%d\n", 2 * @CFG if $tap; |
91 | ||
68cf6151 | 92 | for my $cfg (sort @CFG) { |
522c08cc | 93 | unless (exists $MANIFEST{$cfg}) { |
a76803d0 | 94 | print STDERR "[skipping not-expected '$cfg']\n"; |
522c08cc RGS |
95 | next; |
96 | } | |
97 | my %cfg; | |
7ee20c71 NC |
98 | my $section = 0; |
99 | my @lines; | |
4ccedf19 NC |
100 | |
101 | open my $fh, '<', $cfg; | |
f4ca0be2 NC |
102 | |
103 | if ($cfg eq 'configure.com') { | |
104 | ++$cfg{startperl}; # Cheat. | |
105 | ||
106 | while (<$fh>) { | |
107 | next if /^\#/ || /^\s*$/ || /^\:/; | |
4ccedf19 | 108 | s/(\s*!.*|\s*)$//; # remove trailing comments or whitespace |
f4ca0be2 | 109 | ++$cfg{$1} if /^\$\s+WC "(\w+)='(?:.*)'"$/; |
4ccedf19 | 110 | } |
f4ca0be2 NC |
111 | } else { |
112 | while (<$fh>) { | |
7ee20c71 NC |
113 | if ($_ =~ $first) { |
114 | die "$cfg:$.:section=$section:$_" unless $section == 0; | |
115 | $section = 1; | |
116 | } | |
117 | push @{$lines[$section]}, $_; | |
f4ca0be2 | 118 | next if /^\#/ || /^\s*$/ || /^\:/; |
7ee20c71 NC |
119 | if ($_ =~ $last) { |
120 | die "$cfg:$.:section=$section:$_" unless $section == 1; | |
121 | $section = 2; | |
122 | } | |
f4ca0be2 NC |
123 | # foo='bar' |
124 | # foo=bar | |
58f1e530 NC |
125 | # (optionally with a trailing comment) |
126 | if (/^(\w+)=(?:'.*'|[^'].*)(?: #.*)?$/) { | |
f4ca0be2 NC |
127 | ++$cfg{$1}; |
128 | } else { | |
129 | warn "$cfg:$.:$_"; | |
130 | } | |
4ccedf19 NC |
131 | } |
132 | } | |
133 | close $fh; | |
134 | ||
6692294e | 135 | ++$test; |
e1bac119 | 136 | my $missing; |
6692294e NC |
137 | if ($cfg eq 'configure.com') { |
138 | print "ok $test # skip $cfg doesn't need to be sorted\n" | |
139 | if $tap; | |
140 | } elsif (join("", @{$lines[1]}) eq join("", sort @{$lines[1]})) { | |
141 | print "ok $test - $cfg sorted\n" | |
142 | if $tap; | |
143 | } elsif ($tap) { | |
144 | print "not ok $test - $cfg is not sorted\n"; | |
e1bac119 NC |
145 | } elsif ($opt_r || $opt_l) { |
146 | # A reference to an empty array is true, hence this flags the | |
147 | # file for later attention by --regen and --list, even if | |
148 | # nothing is missing. Actual sort and output are done later. | |
149 | $missing = []; | |
150 | } else { | |
151 | print "$cfg: unsorted\n" | |
7ee20c71 | 152 | } |
e1bac119 | 153 | |
1750d3ff | 154 | for my $v (@MASTER_CFG) { |
e1bac119 NC |
155 | # This only creates a reference in $missing if something is missing: |
156 | push @$missing, $v unless exists $cfg{$v}; | |
1750d3ff | 157 | } |
e1bac119 | 158 | |
6692294e | 159 | ++$test; |
e1bac119 | 160 | if ($missing) { |
6692294e NC |
161 | if ($tap) { |
162 | print "not ok $test - $cfg missing keys @$missing\n"; | |
163 | } elsif ($opt_l) { | |
e1bac119 NC |
164 | # print the name once, however many problems |
165 | print "$cfg\n"; | |
166 | } elsif ($opt_r && $cfg ne 'configure.com') { | |
167 | if (defined $default) { | |
168 | push @{$lines[1]}, map {"$_='$default'\n"} @$missing; | |
169 | } else { | |
170 | print "$cfg: missing '$_', use --default to add it\n" | |
171 | foreach @$missing; | |
172 | } | |
173 | ||
174 | @{$lines[1]} = sort @{$lines[1]}; | |
175 | my $fh = open_new($cfg); | |
176 | print $fh @{$_} foreach @lines; | |
177 | close_and_rename($fh); | |
178 | } else { | |
179 | print "$cfg: missing '$_'\n" foreach @$missing; | |
180 | } | |
6692294e NC |
181 | } elsif ($tap) { |
182 | print "ok $test - $cfg has no missing keys\n"; | |
7ee20c71 | 183 | } |
522c08cc | 184 | } |