Windows: Check exported symbols
[heimdal.git] / cf / w32-check-exported-symbols.pl
blobcfe014ff2ef234a40cd573a364dc9530fb54a1f2
1 use Getopt::Long;
2 use Pod::Usage;
3 use feature "switch";
5 my $def_name = '';
6 my $vs_name = '';
7 my $show_help = 0;
9 my %syms;
11 my $def_only = 0;
12 my $vs_only = 0;
14 GetOptions ("def=s" => \$def_name,
15 "vs=s" => \$vs_name,
16 "help|?" => \$show_help) or pod2usage( -exitval => 2,
17 -verbose => 3 );
18 pod2usage( -exitval => 1,
19 -verbose => 3 ) if $show_help or !$def_name or !$vs_name;
21 open (my $def, '<', $def_name) or die $!;
22 open (my $vs, '<', $vs_name) or die $!;
24 # First go through the version-script
26 my $global = 0;
28 while(<$vs>)
30 next unless m/^([^#]+)/;
32 @a = split(/\s+|({|})/,$1);
34 for $f (@a) {
35 given ($f) {
36 when (/global\:/) { $global = 1; }
37 when (/{|}|.*\:/) { $global = 0; }
38 when (/(.*)\;/ and $global == 1) {
39 $syms{$1} = 1;
45 while(<$def>)
47 next if m/^#/;
48 next unless m/^;!([^;]+)/ or m/^([^;]+);?(!?)/;
50 @a = split(/\s+/, $1);
52 for $f (@a) {
53 next if $f =~ /EXPORTS/ or $f =~ /DATA/ or not $f;
55 if (not exists $syms{$f} and not $2) {
56 print "$f: Only in DEF\n";
57 ++$def_only;
59 delete $syms{$f};
63 #while (($k,$v) = each %syms) {
64 for $k (sort keys %syms) {
65 print "$k: Only in VS\n";
66 ++$vs_only;
69 close($def);
70 close($vs);
72 if ($def_only or $vs_only) {
73 print "\nMismatches found.\n";
74 exit(1);
77 __END__
79 =head1 NAME
81 w32-sync-exported-symbols.pl - Synchronize Windows .def with version-script
83 =head1 SYNOPSIS
85 w32-sync-exported-symbols.pl {options}
87 Options:
88 --def Name of .def file
89 --vs Name of version-script file
91 =head1 DESCRIPTION
93 Verifies that all the symbols exported by the version-script is also
94 accounted for in the .def file. Also checks that no extra symbols are
95 exported by the .def file unless they are marked as safe.
97 =cut