aboutsummaryrefslogtreecommitdiff
path: root/src/depend.pl
blob: b41b8f62cb36d174f8043e078860c1a834601de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w
# $Header$

# Create dependencies for Fortran 90 "use" and "include" statements

$src = $ARGV[0];
$srcfile = $ARGV[1];
$dest = $ARGV[2];
$srcdir = $ARGV[3];
$moddir = $ARGV[4];
$srcsuffix = $ARGV[5];
$modsuffix = $ARGV[6];
@otherdirs = @ARGV[7..$#ARGV];

print "# $src\n";
print "$dest:";

open (FILE, $src);
while (<FILE>) {
  if (/^\s*include\s*['"]([^'"]+)['"]/i) {
    print " $srcdir$1";
  } elsif (/^\s*use\s+(\w+)/i) {
    $found = 0;
    if (! $found) {
      if (-e "$srcdir$1$srcsuffix") {
	$found = 1;
	print " $moddir$1$modsuffix";
      }
    }
    if (! $found) {
      foreach $dir (@otherdirs) {
	if (-e "$dir$1$modsuffix") {
	  $found = 1;
	  print " $dir$1$modsuffix";
	  last;
	}
      }
    }
    if (! $found) {
      die "\nWhile tracing depencencies:\nFortran module $1 (referenced in file $srcfile) not found.\nAborting.\n\n";
    }
  }
}
close (FILE);

print "\n";