3 # Script to create Makefile-style dependencies.
5 # Usage: perl [-s path-separator] [-o obj-ext] mkdep.pl dir... > deps
14 open(FILE
, "< $file\0") or return; # If not openable, assume generated
15 while ( defined($line = <FILE
>) ) {
17 $line =~ s
:/\*.*\*/::g
;
19 if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
22 push(@xdeps, $nf) unless ( defined($deps{$nf}) );
26 $deps{$file} = [@mdeps];
28 foreach $file ( @xdeps ) {
33 # %deps contains direct dependencies. This subroutine resolves
34 # indirect dependencies that result.
40 foreach $dep ( @
{$deps{$file}} ) {
42 foreach $idep ( alldeps
($dep) ) {
51 $sep = '/'; # Default, and works on most systems
52 $obj = 'o'; # Object file extension
54 while ( defined($arg = shift(@ARGV)) ) {
55 if ( $arg =~ /^\-s$/ ) {
57 } elsif ( $arg =~ /^\-o$/ ) {
59 } elsif ( $arg =~ /^-/ ) {
60 die "Unknown option: $arg\n";
66 foreach $dir ( @files ) {
67 opendir(DIR
, $dir) or die "$0: Cannot open directory: $dir";
69 while ( $file = readdir(DIR
) ) {
70 $path = ($dir eq '.') ?
$file : $dir.$sep.$file;
71 if ( $file =~ /\.[Cc]$/ ) {
78 foreach $file ( sort(keys(%deps)) ) {
79 if ( $file =~ /\.[Cc]$/ ) {
80 $ofile = $file; $ofile =~ s/\.[Cc]$/\./; $ofile .= $obj;
81 print $ofile, ': ', $file, ' ';
82 print join(' ', alldeps
($file));