summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-06-24 14:48:30 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2013-06-24 14:48:30 +0000
commit842c0eb1622a6dddafcf4fc3d36c0e14a01539c1 (patch)
tree7ec48674365e1f655adb2586e8000dedc19400e7
parent13a2131d39b29213f4088b0721f8ae7acc84c187 (diff)
Take subdirectories into account when determining Fortran dependencies
I have also rewritten and partly redesigned some other features, correcting some unrelated errors in the course, and simplifying the code a bit. I have also added some comments. git-svn-id: http://svn.cactuscode.org/flesh/trunk@5029 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rwxr-xr-xlib/sbin/f_depend_modules.pl260
1 files changed, 122 insertions, 138 deletions
diff --git a/lib/sbin/f_depend_modules.pl b/lib/sbin/f_depend_modules.pl
index 2666573d..1dbaad21 100755
--- a/lib/sbin/f_depend_modules.pl
+++ b/lib/sbin/f_depend_modules.pl
@@ -7,7 +7,6 @@
# @desc
# Create dependencies for Fortran 90 "use" and "include" statements
# @enddesc
-# @version $Header$
# @@*/
@@ -26,156 +25,141 @@ print "$dest:";
my %modules;
my $line = 0;
-while (<STDIN>)
-{
- ++ $line;
- if (/^\s*#\s*(\d+)/)
- {
- # line number directive from C preprocessor
- $line = $1 - 1;
- }
- elsif (/^\s*include\s*['"]([^'"]+)['"]/i)
- {
- # include statement
- my $name = $1;
- my $found = 0;
- if (! $found)
- {
- # reference to an include file in this thorn?
- my $dirhdl;
- if( opendir( DIRHDL, "$srcdir" ) )
- {
- file: while( defined( my $filename = readdir( DIRHDL ) ) )
- {
- if( $filename eq "$name" )
- {
- $found = 1;
- print " \\\n $filename";
- last file;
- }
- }
- closedir DIRHDL;
- }
+while (<STDIN>) {
+ ++$line;
+ if (/^\s*#\s*(\d+)/) {
+ # Line number directive from C preprocessor
+ $line = $1 - 1;
}
- if (! $found)
- {
- # reference to an include file in another thorn?
- dir: foreach my $dir (@otherdirs)
- {
- # note: we could also use the SUBDIRS from the make.code.defn here
- foreach my $subdir (".", "include")
- {
- if( opendir( DIRHDL, "$dir/$subdir" ) )
- {
- while( defined( my $filename = readdir( DIRHDL ) ) )
- {
- if( $filename eq "$name" )
- {
- $found = 1;
- print " \\\n $dir/$subdir/$filename";
- last dir;
- }
+ elsif (/^\s*include\s*['"]([^'"]+)['"]/i) {
+ # Include statement
+ my $name = $1;
+ my $found = 0;
+ if (!$found) {
+ # Reference to an include file in this thorn?
+ my @subdirs = (".", "include");
+ LOOP: foreach my $subdir (@subdirs) {
+ # Note: We don't use -f directly since this will match
+ # the wrong case on case-insensitive file systems
+ my @filenames;
+ if (opendir DIR, "$srcdir/$subdir") {
+ @filenames = readdir DIR;
+ closedir DIR;
+ }
+ if (grep { $_ eq $name } @filenames) {
+ $found = 1;
+ print " \\\n $subdir/$name";
+ last LOOP;
+ }
+ }
+ }
+ if (!$found) {
+ # Reference to an include file in another thorn?
+ LOOP: foreach my $otherdir (@otherdirs) {
+ # Note: We could also use SUBDIRS from make.code.defn
+ # here.
+ # Note: This looks into the build directories, and
+ # include files won't be there.
+ my @subdirs = (".");
+ foreach my $subdir (@subdirs) {
+ my @filenames;
+ if (opendir DIR, "$otherdir/$subdir") {
+ @filenames = readdir DIR;
+ closedir DIR;
+ }
+ if (grep { $_ eq $name } @filenames) {
+ $found = 1;
+ print " \\\n $otherdir/$subdir/$name";
+ last LOOP;
+ }
+ }
+ }
+ }
+ if (!$found) {
+ print STDERR "$srcfile:$line: Warning: While tracing include dependencies: Include file \"$name\" not found\n";
+ if (@otherdirs) {
+ print STDERR " Searched in thorn directory and in [" . join(', ', @otherdirs) . "]\n";
+ }
+ else {
+ print STDERR " Searched in thorn directory only.\n";
}
- closedir DIRHDL;
- }
}
- }
- }
- if (! $found)
- {
- print STDERR "$srcfile:$line: Warning: While tracing include dependencies: Include file \"$name\" not found\n";
- if (@otherdirs)
- {
- print STDERR " Searched in thorn directory and in [" . join(', ', @otherdirs) . "]\n";
- }
- else
- {
- print STDERR " Searched in thorn directory only.\n";
- }
}
- }
- elsif (/^\s*module\s+(\w+)/i)
- {
- # begin of a module
- my $name = $1;
- $modules{$name} = 1;
- }
- elsif (/^\s*use\s+(\w+)/i)
- {
- # use statement
- my $name = $1;
- my $found = 0;
- if (! $found)
- {
- # reference to a module in this file?
- if ($modules{$name})
- {
- $found = 1;
- }
+ elsif (/^\s*module\s+(\w+)/i) {
+ # Begin of a module
+ my $name = $1;
+ $modules{"\L$name"} = 1;
}
- if (! $found)
- {
- # reference to a module in this thorn?
- my $dirhdl;
- if( opendir( DIRHDL, "$srcdir" ) )
- {
- file: while( defined( my $filename = readdir( DIRHDL ) ) )
- {
- foreach my $suffix (@suffixes)
- {
- if( $filename eq "$name$suffix" )
- {
- $found = 1;
- print " \\\n $filename.o";
- last file;
+ elsif (/^\s*use\s+(\w+)/i) {
+ # Use statement
+ my $name = $1;
+ my $found = 0;
+ if (!$found) {
+ # Reference to a module in this file?
+ if ($modules{"\L$name"}) {
+ $found = 1;
}
- }
}
- closedir DIRHDL;
- }
- }
- if (! $found)
- {
- # reference to a module in another thorn?
- dir: foreach my $dir (@otherdirs)
- {
- # note: we could also use the SUBDIRS from the make.code.defn here
- foreach my $subdir (".", "include")
- {
- if( opendir( DIRHDL, "$dir/$subdir" ) )
- {
- while( defined( my $filename = readdir( DIRHDL ) ) )
- {
- foreach my $suffix (@suffixes)
- {
- if( $filename eq "$name$suffix.o" )
- {
- $found = 1;
- print " \\\n $dir/$subdir/$filename";
- last dir;
+ if (!$found) {
+ # Reference to a module in this thorn?
+ # Look in the source directory, matching the source file
+ my @subdirs = `cd '$srcdir'; find . -type d`;
+ chomp @subdirs;
+ LOOP: foreach my $subdir (@subdirs) {
+ my @filenames;
+ if (opendir DIR, "$srcdir/$subdir") {
+ @filenames = readdir DIR;
+ closedir DIR;
+ }
+ foreach my $suffix (@suffixes) {
+ foreach my $filename (@filenames) {
+ if ("\L$filename" eq "\L$name$suffix") {
+ $found = 1;
+ print " \\\n $subdir/$filename.o";
+ last LOOP;
+ }
+ }
}
- }
}
- closedir DIRHDL;
- }
}
- }
- }
- if (! $found)
- {
- if ("\L$name" ne "omp_lib") {
- print STDERR "$srcfile:$line: Warning: While tracing module dependencies: Source file for module \"$name\" not found\n";
- if (@otherdirs)
- {
- print STDERR " Searched in thorn directory and in [" . join(', ', @otherdirs) . "]\n";
+ if (!$found) {
+ # Reference to a module in another thorn?
+ # Look in the build directory, matching the object file
+ LOOP: foreach my $otherdir (@otherdirs) {
+ # note: we could also use SUBDIRS from make.code.defn
+ # here
+ my @subdirs = `cd '$otherdir'; find . -type d`;
+ chomp @subdirs;
+ foreach my $subdir (@subdirs) {
+ my @filenames;
+ if (opendir DIR, "$otherdir/$subdir") {
+ @filenames = readdir DIR;
+ closedir DIR;
+ }
+ foreach my $suffix (@suffixes) {
+ foreach my $filename (@filenames) {
+ if ("\L$filename" eq "\L$name$suffix.o") {
+ $found = 1;
+ print " \\\n $otherdir/$subdir/$filename";
+ last LOOP;
+ }
+ }
+ }
+ }
+ }
}
- else
- {
- print STDERR " Searched in thorn directory only.\n";
+ if (!$found) {
+ if ("\L$name" ne "omp_lib") {
+ print STDERR "$srcfile:$line: Warning: While tracing module dependencies: Source file for module \"$name\" not found\n";
+ if (@otherdirs) {
+ print STDERR " Searched in thorn directory and in [" . join(', ', @otherdirs) . "]\n";
+ }
+ else {
+ print STDERR " Searched in thorn directory only.\n";
+ }
+ }
}
- }
}
- }
}
print "\n";