Richard Levitte - VMS Whacker wrote:
> rsalz> Or, since perl is already required, include a quick perl script that does
> rsalz> 70% of the job.
>
> Hmm, that could possibly be done... Do you have something ready?
Attached. Hope it's useful.
/r$
#! /usr/bin/env perl --
## Rough tool to write Makefile dependencies by scanning source.
## Not an error if a file isn't found.
## Rich $alz, [EMAIL PROTECTED] Public domain.
%found = {};
@searchdirs = ('.', '/usr/include');
$verbose = 0;
sub
doline()
{
local ( $file, $header, $angles ) = ( shift, shift, shift );
local ( $full ) = $found{$header};
local ( $dir );
if ( defined $full ) {
print "$file: $full\n";
return;
}
checkdir: foreach $dir ( @searchdirs ) {
if ( $angles == 1 ) {
$angles = 0;
next checkdir;
}
if ( -f "$dir/$header" ) {
$found{$header} = "$dir/$header";
print "$file: $dir/$header\n";
return;
}
}
# Not found, print a comment
print "# $file: $header\n";
}
$dashdash = 0;
$nosysincs = 0;
argloop: foreach $arg ( @ARGV ) {
if ( ! $dashdash ) {
if ( $arg eq '-nosysincludes' ) {
$nosysincs = 1;
next argloop;
}
if ( $arg =~ /^-I(.*)/ ) {
push(@searchdirs, $1);
next argloop;
}
if ( $arg =~ /^-[DU]/ ) {
# XXX could parse those options.
next argloop;
}
if ( $arg eq '--' ) {
$dashdash++;
next argloop;
}
if ( $arg =~ /^-/ ) {
die "Unknown flag $_";
}
}
if ( !open(FH, $arg) ) {
warn "Can' open $arg ($!), skipping.";
next argloop;
}
# Look for #include lines in the file.
fline: while ( $line = <FH> ) {
chop($line);
if ( $line =~ /#\s*include\s+"([^"]+)"/ ) {
&doline($arg, $1, 0);
}
elsif ( ! $nosysincs && $line =~ /#\s*include\s+<([^>]+)>/ ) {
&doline($arg, $1, 1);
}
}
close(FH);
}