This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add Porting/checkcfgvar.pl by Jarkko
[perl5.git] / Porting / checkcfgvar.pl
CommitLineData
522c08cc
RGS
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 not handled here, due to their own rather elaborate DCL scripting.
10#
11
12use strict;
13
14my $MASTER_CFG = "config_h.SH";
15my %MASTER_CFG;
16
17my @CFG = (
18 # This list contains both 5.8.x and 5.9.x files,
19 # we check from MANIFEST whether they are expected to be present.
20 "Cross/config.sh-arm-linux",
21 "epoc/config.sh",
22 "NetWare/config.wc",
23 "symbian/config.sh",
24 "uconfig.sh",
25 "plan9/config_sh.sample",
26 "vos/config.alpha.def",
27 "vos/config.ga.def",
28 "win32/config.bc",
29 "win32/config.gc",
30 "win32/config.vc",
31 "wince/config.ce",
32 );
33
34sub read_file {
35 my ($fn, $sub) = @_;
36 if (open(my $fh, $fn)) {
37 local $_;
38 while (<$fh>) {
39 &$sub;
40 }
41 } else {
42 die "$0: Failed to open '$fn' for reading: $!\n";
43 }
44}
45
46sub config_h_SH_reader {
47 my $cfg = shift;
48 return sub {
49 return if 1../^echo \"Extracting \$CONFIG_H/;
50 while (/[^\\]\$(\w+)/g) {
51 my $v = $1;
52 next if $v =~ /^(CONFIG_H|CONFIG_SH)$/;
53 $cfg->{$v}++;
54 }
55 }
56}
57
58read_file($MASTER_CFG,
59 config_h_SH_reader(\%MASTER_CFG));
60
61my %MANIFEST;
62
63read_file("MANIFEST",
64 sub {
65 $MANIFEST{$1}++ if /^(.+?)\t/;
66 });
67
68my @MASTER_CFG = sort keys %MASTER_CFG;
69
70sub check_cfg {
71 my ($fn, $cfg) = @_;
72 for my $v (@MASTER_CFG) {
73 print "$fn: missing '$v'\n" unless exists $cfg->{$v};
74 }
75}
76
77for my $cfg (@CFG) {
78 unless (exists $MANIFEST{$cfg}) {
79 print "[skipping not-expected '$cfg']\n";
80 next;
81 }
82 my %cfg;
83 read_file($cfg,
84 sub {
85 return if /^\#/ || /^\s*$/;
86 # foo='bar'
87 # foo=bar
88 # $foo='bar' # VOS 5.8.x specialty
89 # $foo=bar # VOS 5.8.x specialty
90 if (/^\$?(\w+)='(.*)'$/) {
91 $cfg{$1}++;
92 }
93 elsif (/^\$?(\w+)=(.*)$/) {
94 $cfg{$1}++;
95 } else {
96 warn "$cfg:$.:$_";
97 }
98 });
99 check_cfg($cfg, \%cfg);
100}