-
Notifications
You must be signed in to change notification settings - Fork 3
/
mkfiles.pl
95 lines (78 loc) · 2.08 KB
/
mkfiles.pl
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
#!/usr/bin/perl
############################################################################
#
# Creates make.files - a list of all source files
#
############################################################################
#
# main - top level code
#
if ( @ARGV ) { # parse command line args
print "usage: perl mkfiles.pl\n\n";
exit 1;
}
$tolower = 0;
@files = &find_files(".","\.*",1);
@codefiles = sort grep(/\.(c|cpp|cc|s|h|hpp|icc|ia)$/i,@files);
print STDERR scalar @codefiles . " files found.\n";
if ( -r "make.exclude" ) {
open EXCLUDE, "make.exclude" or
die "make.exclude: $!";
@exclude = <EXCLUDE>;
close EXCLUDE;
for ( @exclude ) {
chop;
$ex{lc $_} = 1;
}
$excluded = 0;
for ( @codefiles ) {
if ( !defined $ex{lc $_} ) {
push @leftfiles, $_;
}
else {
$excluded++;
}
}
*codefiles = *leftfiles;
print STDERR $excluded . " files excluded";
if ( $excluded ne scalar @exclude ) {
print STDERR " (of ".scalar @exclude." files in make.exclude)";
}
print STDERR ".\n";
}
open FILES, ">make.files" or
die("make.files: $!");
print FILES join("\n",sort @codefiles) . "\n";
close FILES;
exit 0;
#
# Finds files.
#
# Examples:
# find_files("/usr","\.cpp$",1) - finds .cpp files in /usr and below
# find_files("/tmp","^#",0) - finds #* files in /tmp
#
sub find_files {
my($dir,$match,$descend) = @_;
my($file,$p,@files);
local(*D);
$dir =~ s=\\=/=g;
($dir eq "") && ($dir = ".");
if ( opendir(D,$dir) ) {
if ( $dir eq "." ) {
$dir = "";
} else {
($dir =~ /\/$/) || ($dir .= "/");
}
foreach $file ( readdir(D) ) {
next if ( $file =~ /^\.\.?$/ );
$p = $dir . $file;
($file =~ /$match/i) && (push @files, ($tolower==0 ? $p : lc($p)));
if ( $descend && -d $p && ! -l $p ) {
push @files, &find_files($p,$match,$descend);
}
}
closedir(D);
}
return @files;
}