forked from z80playground/cpm-fat
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gendep
executable file
·62 lines (45 loc) · 1.13 KB
/
gendep
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
#!/usr/bin/perl -w
#
# This is a utility script which is invoked by Make to handle
# dependencies.
#
# Dependencies we've discovered.
my %discovered;
# Read the given file, and look for file-inclusion. If we found
# a file that is included scan that too.
sub include_search {
# File we're examining
my ( $file ) = ( @_ );
# New inclusions we fond.
my @new;
# Open
open( my $handle, "<", $file) or die "Failed to open $file - $!";
# Read line by line
foreach my $line ( <$handle> ) {
# Is this an include line?
if ( $line =~ /^include "([^"]+)"/ ) {
# save it away.
$discovered{$1} += 1;
# And record that this was newly discovered.
push(@new, $1 );
}
}
close( $handle );
# For any newly discovered includes, scan them too
foreach my $name ( @new ) {
include_search($name);
}
}
#
# Did we get an argument? If so process it.
#
my $file = shift;
if ( defined( $file ) ) {
include_search( $file );
}
# Show results
foreach my $file ( sort keys %discovered ) {
print $file . "\n";
}
# All done
exit 0;