-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-includes.pl
83 lines (74 loc) · 1.53 KB
/
gen-includes.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
#!/usr/bin/env perl
#
# Public domain.
#
# Scan C header files and generate preprocessed versions of them in the
# specified target directory.
#
my $outdir = '';
sub Scan ($$)
{
my $dir = shift;
my $outdir = shift;
if (! -e $outdir) {
mkdir($outdir, 0755) || die "$outdir: $!";
}
unless (opendir(CWD, $dir)) {
print STDERR "$dir: $!; ignored\n";
return;
}
foreach my $ent (readdir(CWD)) {
my $file = $dir.'/'.$ent;
my $outfile = $outdir.'/'.$ent;
if ($ent =~ /^\./ || -l $outfile || -l $file) {
next;
}
if (-d $ent) {
if (-e $file.'/.generated') { next; }
Scan($file, $outfile);
next;
}
if ($ent =~ /\.h$/) {
my @o = readpipe("perl mk/gen-declspecs.pl '$file'");
if ($? != 0) {
print STDERR "gen-declspecs.pl failed\n";
exit(1);
}
open(OUT, ">$outfile") || die "$outfile: $!";
print OUT @o;
close(OUT);
}
}
closedir(CWD);
}
sub CleanEmptyDirs ($)
{
my $dir = shift;
unless (opendir(CWD, $dir)) {
print STDERR "$dir: $!; ignored\n";
return;
}
foreach my $ent (readdir(CWD)) {
my $subdir = $dir.'/'.$ent;
if ($ent =~ /^\./ || -l $subdir || !-d $subdir) {
next;
}
CleanEmptyDirs($subdir);
rmdir($subdir);
}
closedir(CWD);
}
if (@ARGV < 1) {
print STDERR "Usage: gen-includes.pl [directory]\n";
exit(1);
}
$outdir = $ARGV[0];
if (! -e $outdir) {
my $now = localtime;
mkdir($outdir, 0755) || die "$outdir: $!";
open(STAMP, ">$outdir/.generated") || die "$outdir/.generated: $!";
print STAMP $now,"\n";
close(STAMP);
}
Scan('.', $outdir);
CleanEmptyDirs($outdir);