This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Regen Configure, Glossary, et alia.
[perl5.git] / Porting / manicheck
1 #!/usr/bin/perl -ws
2
3 #
4 # manicheck - check files against the MANIFEST
5 #
6 # Without options prints out (possibly) two lines:
7 #
8 # extra: a b c
9 # missing: d
10 #
11 # With option -x prints out only the missing files (and without the "extra: ")
12 # With option -m prints out only the extra files (and without the "missing: ")
13 #
14
15 BEGIN {
16   $SIG{__WARN__} = sub {
17     help() if $_[0] =~ /"main::\w" used only once: possible typo at /;
18   };
19 }
20
21 use strict;
22
23 sub help {
24   die <<EOF;
25 $0: Usage: $0 [-x|-m|-h]
26 -x show only the extra files
27 -m show only the missing files
28 -h show only this help
29 EOF
30 }
31
32 use vars qw($x $m $h);
33
34 help() if $h;
35
36 open(MANIFEST, "MANIFEST") or die "MANIFEST: $!";
37
38 my %mani;
39 my %mand = qw(. 1);
40 use File::Basename qw(dirname);
41
42 while (<MANIFEST>) {
43   if (/^(\S+)\t+(.+)$/) {
44     $mani{$1}++;
45     my $d = dirname($1);
46     while($d ne '.') {
47         $mand{$d}++;
48         $d = dirname($d);
49     }
50   } else {
51     warn "MANIFEST:$.:$_";
52   }
53 }
54
55 close(MANIFEST);
56
57 my %find;
58 use File::Find;
59 find(sub {
60        my $n = $File::Find::name;
61        $n =~ s:^\./::;
62        $find{$n}++;
63      }, '.' );
64
65 my @xtra;
66 my @miss;
67
68 for (sort keys %find) {
69   push @xtra, $_ unless $mani{$_} || $mand{$_};
70 }
71
72 for (sort keys %mani) {
73   push @miss, $_ unless $find{$_};
74 }
75
76 printf("%s@xtra\n", $x || $m ? "" : "extra: ")   if @xtra && !$m;
77 printf("%s@miss\n", $x || $m ? "" : "missing: ") if @miss && !$x;
78
79 exit 0;
80