📄 sfmakedepend
字号:
#!/usr/bin/perl -w## Fortran 90/77 dependency checker, 2002 version.## $Id: sfmakedepend,v 1.1 2005/06/21 23:14:23 volov Exp $## use 5.6.0;use strict;use File::Basename;use Getopt::Long;use Pod::Usage;use Getopt::Long;use File::Copy;my ($opt_help, $opt_man, $opt_file, @incdirs, @srcdirs, $opt_modext, $opt_case, $compiler, $opt_depend, $drop_circ);our ($cpp, $add_ext, $mod_dir, $libdeps);our $obj_ext = 'o';our $ext = 'f';# Parse the arguments, do the right thing for --help, --man.Getopt::Long::Configure( "bundling" );GetOptions("help" => \$opt_help, "man" => \$opt_man, "file=s" => \$opt_file, "I=s@" => \@incdirs, "srcdir=s@" => \@incdirs, "moddir=s" => \$mod_dir, "fext=s" => \$ext, "objext=s" => \$obj_ext, "modext=s" => \$opt_modext, "addext=s" => \$add_ext, "case=s" => \$opt_case, "compiler=s" => \$compiler, "depend=s" => \$opt_depend, "cpp" => \$cpp, "libdeps" => \$libdeps, "drop" => \$drop_circ) or pod2usage("Try '$0 --help' for more information");pod2usage(-verbose => 1) if $opt_help;pod2usage(-verbose => 2) if $opt_man;our @suffixes = qw( .c .C .cc .cxx .cpp .f .F .f90 .F90 .f95 .F95 .for);our @mod_files = ();my $mf = 'Makefile';if ($opt_file) { $mf = $opt_file;} elsif (-f "makefile") { $mf = 'makefile';}if ( !(-f $mf)) { system "touch $mf";}# extension used for compiler's private module informationour $mod_ext = "mod";our $depend = "obj";our $case = "lower";our $obj_dep_flag;my $ll = 79; # maximum line length in Makefilemy $cray;my $parasoft;# Hernan hack my $nothing = "\n";# Check the compiler first, then override the compiler-specific defaultsif ($compiler) { if ($compiler eq "crayold") { $cray = 1; $case = "lower"; $depend = "obj"; $obj_dep_flag = "-p"; } elsif ($compiler eq "cray") { $case = "upper"; } elsif ($compiler eq "parasoft") { $parasoft = 1; $case = "lower"; $depend = "obj"; $obj_dep_flag = "-module"; } elsif ($compiler eq "sgiold") { $mod_ext = "kmo"; $case = "upper"; } elsif ($compiler eq "sgi" or $compiler eq "hp" or $compiler eq "absoft") { $case = "upper"; } elsif ($compiler eq "nag" or $compiler eq "ibm" or $compiler eq "sun") { $case = "lower"; } else { warn "Unknown compiler: $compiler\n"; }}$depend = $opt_depend if defined($opt_depend);if ($depend eq "obj") { $drop_circ = 1;}$case = $opt_case if defined($opt_case);# extension used for compiler's private module informationif ($opt_modext) { $mod_ext = $opt_modext;}# need to add some more dependencies so the .f file gets createdour $need_f;if ($cpp and $depend eq "obj") { $need_f = 1;}my $mystring = '# DO NOT DELETE THIS LINE - used by make depend';# Search for the includes in all the filesmy $file;my %sources;foreach $file (@ARGV) { my $filesrc = findsrc($file); $sources{$file} = new Source_File($file, $filesrc); $sources{$file}->find_includes();}# Create new Makefile with new dependencies.if ($mf ne "-") { copy( "$mf", "$mf.old"); open(MFILE, "$mf.old") || die "can't read Makefile $mf.old: $!\n"; open(NMFILE, "> $mf") || die "can't write $mf: $!\n"; select(NMFILE); while (<MFILE>) { if (!/$mystring/) { print; } else { last; } } print $mystring, "\n";}# Now print out include and use dependencies in sorted order.my $target;foreach $target (sort keys(%sources)) { $sources{$target}->print();# Hernan hack print $nothing;}# print out module dependenciesif ( !( $cray || $parasoft) ) { my $modname; foreach $modname (sort keys(%main::mod_files)) { my ($name, $path, $suffix) = fileparse( $sources{$main::mod_files{$modname}}->{'filepath'}, @suffixes); my $object = $path . $name . "." . $obj_ext; if (!( $drop_circ && lc($modname) eq lc($name)) ) { $object =~ s#^\./##; print "$modname.$mod_ext: $object\n"; } }}## End of main#sub findfile {# Let's see if we can find the included file. Look in current# directory first, then in directories from -I arguments. my $file = shift; my ($found, $i, $filepath); $found = 0; if ( -f $file ) { $found = 1; $file =~ s#^\./##; # convert ./foo.h to foo.h return $file; } foreach $i (0 .. $#incdirs) { $filepath = $incdirs[$i]."/".$file; if ( -f $filepath ) { $found = 1; $filepath =~ s#^\./##; # convert ./foo.h to foo.h return $filepath; } } if ( ! $found ) { $filepath = ""; } $filepath;}#-----------------------------------------------------------------------sub findsrc {# Let's see if we can find the source-file. Look in current# directory first, then in directories from --srcdir arguments. my $src = shift; my($found, $i, $srcpath); $found = 0; if ( -f $src ) { $found = 1; $src =~ s#^\./##; # convert ./foo.h to foo.h return $src; } foreach $i (0 .. $#srcdirs) { $srcpath = $srcdirs[$i]."/".$src; if ( -f $srcpath ) { $found = 1; $srcpath =~ s#^\./##; # convert ./foo.h to foo.h return $srcpath; } } if ( ! $found ) { $srcpath = ""; } $srcpath;}#################################################################package Source_File;# hash containing names of included filesmy %inc_files = ();# Constructorsub new { my $type = shift; my $filename = shift; my $path = shift; my $self = {}; $self->{'Source_File'} = $filename; $self->{'filepath'} = $path; $self->{'includes'} = {}; $self->{'uses'} = {}; $self->{'modules'} = {}; bless $self;}sub find_includes { my $self = shift; my $file = $self->{'filepath'}; my($after, $filepath, $ref, $included, $use, $modname); local(*FILE); local($_); if (-f $file) { open(FILE, $file) || warn "Can't open $file: $!\n"; } else { return; } while (<FILE>) { $included = ""; $use = ""; # look for Fortran style includes if (/^\s*include\s*['"]([^"']*)["']/i) { $included = $1; $after = $'; # C preprocessor style includes } elsif (/^#\s*include\s*["<]([^">]*)[">]/) { $included = $1; $after = $'; # Fortran 90 "use" } elsif (/^\s*use\s+(\w+)/i) { $use = $1;# Change the case as needed - compiler dependent. if ($main::case eq "upper") { $use = uc($use); } elsif ($main::case eq "lower") { $use = lc($use); } $self->{'uses'}{$use} = 1; # Fortran 90 module } elsif (/^\s*module\s+(\w+)/i) { $modname = $1; if ($main::case eq "upper") { $modname = uc($modname); } elsif ($main::case eq "lower") { $modname = lc($modname); } # Skip "module procedure" in interface blocks next if (lc($modname) eq "procedure"); $main::mod_files{$modname} = $file; $self->{'modules'}{$modname} = 1; } if ($included) { # See if we've already searched this file if ( $inc_files{$included} ) { $filepath = $inc_files{$included}{'filepath'}; } else { $filepath = main::findfile($included); $ref = new Source_File($included, $filepath); $inc_files{$included} = $ref;# Search included file for includes $ref->find_includes(); } if ( $filepath ) { $self->{'includes'}{$included} = 1; } else { if ($after !~ /bogus/i) { warn "Can't find file: $included\n"; } } } } close FILE;}sub print_includes { my $self = shift; my $target = shift; my $len_sum = shift; my $file; foreach $file (keys %{$self->{'includes'}}) { my $ref = $inc_files{$file}; my $len = length($ref->{'filepath'}) + 1; if (($len_sum + $len > $ll) && (length($target) + 1 < $len_sum)) { print "\n$target:"; $len_sum = length($target) + 1; } print " " . $ref->{'filepath'}; $len_sum += $len; $len_sum = $ref->print_includes($target, $len_sum); } $len_sum;}# return list of modules used by included filessub inc_mods { my $self = shift; my($file, $ref, $mod, @sub_list); my @list = (); foreach $mod (keys %{$self->{'uses'}}) { push(@list, $mod); } foreach $file (keys %{$self->{'includes'}}) { $ref = $inc_files{$file}; @sub_list = $ref->inc_mods(); @list = (@list, @sub_list); } @list;}# filenames containing the modules used by file and all its includessub find_mods { my $self = shift; my($modname, $file); my @module_files = (); my @mod_list = ();# find modules used by include files if (%{$self->{'includes'}}) { foreach $file (keys %{$self->{'includes'}}) { my $ref = $inc_files{$file};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -