-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen-includelinks.pl
79 lines (70 loc) · 1.48 KB
/
gen-includelinks.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
#!/usr/bin/env perl
#
# Public domain.
#
# Create shadow directories of symbolic links to include files in the
# source directory (i.e., for ./configure --include=link).
#
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$/) {
unless (symlink($srcdir.'/'.$file, $outfile)) {
print STDERR "$file to $outfile: $!\n";
}
}
}
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 < 2) {
print STDERR "Usage: gen-includelinks.pl [source-dir] [target-dir]\n";
exit(1);
}
$srcdir = $ARGV[0];
$outdir = $ARGV[1];
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);