summaryrefslogtreecommitdiff
path: root/Porting/checkcfgvar.pl
blob: b7022dc22f7f3268533265c5ef86d31c76968ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl

# Check that the various config.sh-clones have (at least) all the
# same symbols as the top-level config_h.SH so that the (potentially)
# needed symbols are not lagging after how Configure thinks the world
# is laid out.
#
# VMS is probably not handled properly here, due to their own
# rather elaborate DCL scripting.
#

use strict;
use warnings;

sub usage
{
    my $err = shift and select STDERR;
    print "usage: $0 [--list]\n";
    exit $err;
    } # usage

use Getopt::Long;
my $opt_l = 0;
GetOptions (
    "help|?"	=> sub { usage (0); },
    "l|list!"	=> \$opt_l,
    ) or usage (1);

my $MASTER_CFG = "config_h.SH";
my %MASTER_CFG;

my %lst;
my @CFG = (
	   # we check from MANIFEST whether they are expected to be present.
	   # We can't base our check on $], because that's the version of the
	   # perl that we are running, not the version of the source tree.
	   "Cross/config.sh-arm-linux",
	   "epoc/config.sh",
	   "NetWare/config.wc",
	   "symbian/config.sh",
	   "uconfig.sh",
	   "uconfig64.sh",
	   "plan9/config_sh.sample",
	   "win32/config.bc",
	   "win32/config.gc",
	   "win32/config.gc64",
	   "win32/config.gc64nox",
	   "win32/config.vc",
	   "win32/config.vc64",
	   "win32/config.ce",
	   "configure.com",
	   "Porting/config.sh",
	  );

sub read_file {
    my ($fn, $sub) = @_;
    if (open(my $fh, $fn)) {
	local $_;
	while (<$fh>) {
	    &$sub;
	}
    } else {
	die "$0: Failed to open '$fn' for reading: $!\n";
    }
}

sub config_h_SH_reader {
    my $cfg = shift;
    return sub {
	while (/[^\\]\$([a-z]\w+)/g) {
	    my $v = $1;
	    next if $v =~ /^(CONFIG_H|CONFIG_SH)$/;
	    $cfg->{$v}++;
	}
    }
}

read_file($MASTER_CFG,
	  config_h_SH_reader(\%MASTER_CFG));

my %MANIFEST;

read_file("MANIFEST",
	  sub {
	      $MANIFEST{$1}++ if /^(.+?)\t/;
	  });

my @MASTER_CFG = sort keys %MASTER_CFG;

for my $cfg (@CFG) {
    unless (exists $MANIFEST{$cfg}) {
	print STDERR "[skipping not-expected '$cfg']\n";
	next;
    }
    my %cfg;
    read_file($cfg,
	      sub {
		  return if /^\#/ || /^\s*$/ || /^\:/;
		  if ($cfg eq 'configure.com') {
		      s/(\s*!.*|\s*)$//; # remove trailing comments or whitespace
		      return if ! /^\$\s+WC "(\w+)='(.*)'"$/;
		  }
		  # foo='bar'
		  # foo=bar
		  if (/^(\w+)='(.*)'$/) {
		      $cfg{$1}++;
		  }
		  elsif (/^(\w+)=(.*)$/) {
		      $cfg{$1}++;
		  }
		  elsif (/^\$\s+WC "(\w+)='(.*)'"$/) {
		      $cfg{$1}++;
		  } else {
		      warn "$cfg:$.:$_";
		  }
	      });
    if ($cfg eq 'configure.com') {
	$cfg{startperl}++; # Cheat.
    }

    for my $v (@MASTER_CFG) {
	exists $cfg{$v} and next;
	if ($opt_l) {
	    $lst{$cfg}{$v}++;
	}
	else {
	    print "$cfg: missing '$v'\n";
	}
    }
}

$opt_l and print "$_\n" for sort keys %lst;