|
The Guava Toolsdepgenfilt.pl |
This script reads a file containing dependency information, as generated by gcc or hss2html with the -M and -MG options.
The -MG option tells the dependency program to assume that any missing files will be generated by a make rule. These files are added to the dependency output, but it is assumed that the generated file will be in the current directory, which is often not the case.
This Perl script searches for files with certain extensions, which are assumed to be generated files. If (and only if) these files do not have a path name, one is added. Lists of extensions and directory names are supplied as arguments to the script.
Examples:
$ echo "file.o: src/file.c file.i src/file.i" | depgenfilt.pl i xyz file.o: src/file.c xyz/file.i src/file.i |
$ echo "file.o: src/file.c file.i file.j" | depgenfilt.pl "i j" "xyz pqr" file.o: src/file.c xyz/file.i pqr/file.j |
#!/usr/bin/perl -w
# depgenfilt.pl
#
# Steve Morphet - September 1999.
#
# Program to add pathnames to pathless entries in a dependency makefile.
# The first argument is a list of filename extensions, without dots.
# The second argument is a list of directories to be added, corresponding
# to the extensions in the first argument.
#
# Used to correct the output from gcc -M -MG, where generated files are
# assumed to be in the local directory.
#
# @el - extension list
# @dl - directory list
# $x - filename from input
# $i - iterator for @el
# $m - set when extension match found.
#
# example:
# echo "file.o: src/file.c file.i src/file.i" | depgenfilt.pl i xyz
# outputs:
# file.o: src/file.c xyz/file.i src/file.i
#
@el = split(" ",$ARGV[0]); shift; # Get extensions and paths
@dl = split(" ",$ARGV[0]); shift;
while(<>) { # For each line in input
foreach $x (split(" ",$_)){ # For each filename in line
for( $i = 0, $m = 0; ($i <= $#el) && ($m==0); $i++ ) {
# For each ext,until match found.
if(($x =~ /(.*)\.$el[$i]$/) && # If name has right extension
($x !~ /\// ) ) { # but doesn't have any path
print "$dl[$i]/$x "; # Add appropriate path.
$m = 1;
}
}
if(!$m ) { # If no match found in ext list
print "$x "; # Add nothing.
}
}
print "\n";
}
|