chiark / gitweb /
wip compile
[inn-innduct.git] / support / mkmanifest
1 #! /usr/bin/perl -w
2
3 ##  $Id: mkmanifest 7307 2005-06-11 08:38:15Z eagle $
4 ##
5 ##  Generate a filename-only manifest from an INN tree.
6 ##
7 ##  This script generates a filename-only manifest from an INN tree, excluding
8 ##  certain files according to .cvsignore files and several built-in rules.
9 ##  It is intended to be used to support make check-manifest from the top
10 ##  level of the INN tree.
11
12 require 5.005;
13
14 use strict;
15 use vars qw(%CVSIGNORE @FILES @IGNORE);
16
17 use File::Find qw(find);
18
19 # The following regex patterns match files to be ignored wherever they are
20 # in the tree.  This is intended to handle files that CVS ignores by default
21 # or files that are present in the tree and in CVS but which are not included
22 # in releases.
23 @IGNORE = (qr%(\A|/)\.cvsignore\Z%, qr/\.[ao]\Z/, qr%(\A|/)CVS(/|\Z)%,
24            qr%(\A|/)\.?\#%, qr/\.(old|bak|orig|rej)$/, qr%(\A|/)core\Z%,
25            qr/~$/, qr%(\A|/)\.pure%, qr%(\A|/)\.svn(/|\Z)%);
26
27 # Build a list of all the files ignored by rules in .cvsignore files.  Meant
28 # to be run as the wanted sub of a call to File::Find.  Stuff in .cvsignore
29 # that contains wildcards needs to be lifted into the list of @IGNORE regexes.
30 sub find_cvsignore {
31     return unless $_ eq '.cvsignore';
32     return unless -f;
33     my $file = $_;
34     $file =~ s%^\./%%;
35     my @ignored;
36     my $dir = $File::Find::dir;
37     $dir =~ s%^\./?%%;
38     if ($dir) {
39         $dir .= '/';
40     }
41     open (CVSIGNORE, $_) or die "Cannot open $File::Find::name: $!\n";
42     @ignored = map { $dir . $_ } map { split (' ', $_) } <CVSIGNORE>;
43     close CVSIGNORE;
44     for (@ignored) {
45         if (/\*/) {
46             my $pattern = $_;
47             $pattern =~ s/\./\\./g;
48             $pattern =~ s/\*/.*/g;
49             push (@IGNORE, qr/\A$pattern\Z/);
50         } else {
51             $CVSIGNORE{$_}++;
52         }
53     }
54 }
55
56 # Build a list of all files in the tree that aren't ignored by .cvsignore
57 # files or listed in ignore regexes.
58 sub find_files {
59     return if $_ eq '.';
60     my $name = $File::Find::name;
61     $name =~ s%^./%%;
62     if ($CVSIGNORE{$name}) {
63         $File::Find::prune = 1;
64         return;
65     }
66     for my $pattern (@IGNORE) {
67         return if $name =~ /$pattern/;
68     }
69     push (@FILES, $name);
70 }
71
72 find (\&find_cvsignore, '.');
73 find (\&find_files, '.');
74 print join ("\n", (sort @FILES), '');