home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # Usage: w4 [options] [files]
-
- # Configuration parameters.
-
- $CPP = "cc -E";
- # $CPP = "cc -P";
- # $CPP = "/lib/cpp";
-
- # Process switches.
-
- while ($ARGV[0] =~ /^-/) {
- $_ = shift;
- if (/^-D(.*)/) {
- $defines .= " -D" . ($1 ? $1 : shift);
- }
- elsif (/^-I(.*)/) {
- $includes .= " -I" . ($1 ? $1 : shift);
- }
- elsif (/^-d(.*)/) {
- $dir = ($1 ? $1 : shift);
- }
- else {
- die "Unrecognized switch: $_\n";
- }
- }
-
- # Do each file on command line.
-
- foreach $file (@ARGV) {
- open(CPP,"$CPP $defines $includes $file|")
- || die "Can't run cpp: $!\n";
-
- # Scan output for line directives.
-
- %seen = ();
- while (<CPP>) {
- next unless /^#/;
- next unless ($filename) = /^# \d.*"(.*)"/;
- $seen{$filename}++;
- }
- close CPP;
-
- # Figure out the corresponding object file name.
-
- ($ofile = $file) =~ s/\.c$/.o/;
- $ofile =~ s#.*/##;
- $ofile = "$dir/$ofile" if $dir;
-
- # Print out the dependencies.
-
- foreach $dep (sort keys(%seen)) {
- print "$ofile: $dep\n";
- }
- print "\n";
- }
-