-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-dotdepend.pl
executable file
·92 lines (85 loc) · 1.63 KB
/
gen-dotdepend.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
#!/usr/bin/env perl
# Public domain.
# Scan Makefiles for "include .depend" and generate empty ".depend" files,
# such that make can be run prior to an initial "make depend".
#
my %V = ();
sub MakefileIncludesDepend ($$)
{
my $path = shift;
my $cwd = shift;
if (!open(MF, $path)) {
return (0);
}
my @lines = ();
foreach $_ (<MF>) {
chop;
if (/^(.+)\\$/) { # Expansion
$line .= $1;
} else { # New line
if ($line) {
push @lines, $line . $_;
$line = '';
} else {
push @lines, $_;
}
}
}
foreach $_ (@lines) {
if (/^\s*#/) { next; }
if (/^\t/) { next; }
s/\$\{(\w+)\}/$V{$1}/g;
if (/^\s*(\w+)\s*=\s*"(.+)"$/ ||
/^\s*(\w+)\s*=\s*(.+)$/) {
$V{$1} = $2;
} elsif (/^\s*(\w+)\s*\+=\s*"(.+)"$/ ||
/^\s*(\w+)\s*\+=\s*(.+)$/) {
if (exists($V{$1}) && $V{$1} ne '') {
$V{$1} .= ' '.$2;
} else {
$V{$1} = $2;
}
}
if (/^\s*include\s+(.+)$/) {
if ($1 eq '.depend' ||
MakefileIncludesDepend($cwd.'/'.$1, $cwd)) {
return (1);
}
}
}
close(MF);
return (0);
}
sub Scan ($)
{
my $dir = shift;
unless (opendir(CWD, $dir)) {
print STDERR "$dir: opendir: $!; ignoring\n";
return;
}
%V = ();
if (-e $dir.'/Makefile' &&
MakefileIncludesDepend("$dir/Makefile", $dir)) {
if (open(OUT, ">$dir/.depend")) {
close(OUT);
} else {
print STDERR "$dir/.depend: $!; ignoring\n";
}
}
foreach my $ent (readdir(CWD)) {
my $file = $dir.'/'.$ent;
if ($ent =~ /^\./) {
next;
}
if (-d $file) {
Scan($file);
next;
}
}
closedir(CWD);
}
if (@ARGV < 1) {
print STDERR "Usage: gen-dotdepend.pl [directory]\n";
exit(1);
}
Scan($ARGV[0]);