1#!perl 2# $Id: makedepend.pl,v 1.2 2004/09/30 07:34:13 jlinoff Exp $ 3# 4# Walk over the source files and generate the local dependencies. 5# 6use strict; 7 8my %depends = (); 9 10&Main; 11 12# ================================================ 13# MAIN 14# ================================================ 15sub Main 16 { 17 my @files = (); 18 while ( $#ARGV >= 0 ) { 19 my $arg = shift @ARGV; 20 push @files,$arg; 21 } 22 my $file; 23 24 # ================================================ 25 # Print the objs target. 26 # ================================================ 27 print "OBJS ="; 28 foreach $file ( @files ) { 29 my $obj = $file; 30 $obj =~ s/\.cc$/\.\${OBJ_EXT}/; 31 print " \\\n\t\${BIN_DIR}/$obj"; 32 } 33 print "\n"; 34 print "\n"; 35 36 # ================================================ 37 # Print the dependencies. 38 # ================================================ 39 foreach $file ( @files ) { 40 %depends = (); 41 &process_file( $file ); 42 my $obj = $file; 43 $obj =~ s/\.cc$/\.\${OBJ_EXT}/; 44 print "\${BIN_DIR}/${obj} : $file"; 45 my $key; 46 foreach $key ( sort keys %depends ) { 47 print " \\\n\t$key"; 48 } 49 print "\n"; 50 print "\t\@echo \"================================================\"\n"; 51 print "\t\@echo \"Compiling \$\@\"\n"; 52 print "\t\${CXX} \${CXX_FLAGS} \${CXX_OUT}\$\@ ${file}\n"; 53 print "\n"; 54 } 55 } 56sub process_file 57 { 58 my $file = shift; 59 my @includes = (); 60 open FP,"$file" || die "ERROR: !*"; 61 while( <FP> ) { 62 if( /^\s*\#\s*include\s+\"([^\"]+)/ ) { 63 push @includes,$1; 64 } 65 } 66 close FP; 67 my $include; 68 foreach $include ( @includes ) { 69 if( ! defined $depends{$include} ) { 70 $depends{$include} = 1; 71 &process_file($include); 72 } 73 } 74 } 75