|
Packit Service |
c5cf8c |
#! /usr/bin/env perl
|
|
Packit Service |
c5cf8c |
# -*- Mode: perl; -*-
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# f77tof90 indir outdir [ Makefile-template [Make-Append] ]
|
|
Packit Service |
c5cf8c |
# For each file in indir/*.[fF], create a corresponding file in outdir
|
|
Packit Service |
c5cf8c |
# with .f90/.F90, and with any include "mpif.h" replaced with use mpi
|
|
Packit Service |
c5cf8c |
# It also changes to the new comment style, because some compilers
|
|
Packit Service |
c5cf8c |
# use the comment style to choose other features of the language
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# We also allow the file name to be modified to help out Windows, since
|
|
Packit Service |
c5cf8c |
# programs in a project need to have distinct names
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
use warnings;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$indir = $ARGV[0];
|
|
Packit Service |
c5cf8c |
$outdir = $ARGV[1];
|
|
Packit Service |
c5cf8c |
$makeTemplate = $ARGV[2];
|
|
Packit Service |
c5cf8c |
$makeAppend = $ARGV[3];
|
|
Packit Service |
c5cf8c |
$convertToFreeForm = 1;
|
|
Packit Service |
c5cf8c |
$convertToNewComments = 1;
|
|
Packit Service |
c5cf8c |
# Including a newline variable allows us to handle Unix and DOS source files
|
|
Packit Service |
c5cf8c |
$newline = "\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
%replaceInclude = ( 'iodisp' => 'integer (kind=MPI_OFFSET_KIND) disp',
|
|
Packit Service |
c5cf8c |
'ioaint' => 'integer (kind=MPI_ADDRESS_KIND) aint',
|
|
Packit Service |
c5cf8c |
'iooffset' => 'integer (kind=MPI_OFFSET_KIND) offset',
|
|
Packit Service |
c5cf8c |
'type1aint' => 'integer (kind=MPI_ADDRESS_KIND) aint',
|
|
Packit Service |
c5cf8c |
'typeaints' => 'integer (kind=MPI_ADDRESS_KIND) aint, aintv(max_asizev)',
|
|
Packit Service |
c5cf8c |
'attr1aints' => 'integer (kind=MPI_ADDRESS_KIND) extrastate, valin, valout, val',
|
|
Packit Service |
c5cf8c |
'attraints' => 'integer (kind=MPI_ADDRESS_KIND) extrastate, valin, valout, val',
|
|
Packit Service |
c5cf8c |
'addsize' => 'integer (kind=MPI_ADDRESS_KIND) asize',
|
|
Packit Service |
c5cf8c |
'add1size' => 'integer (kind=MPI_ADDRESS_KIND) asize',
|
|
Packit Service |
c5cf8c |
);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
%excludePrograms = ();
|
|
Packit Service |
c5cf8c |
$debugReplace = 0;
|
|
Packit Service |
c5cf8c |
$reportSkipped = 1;
|
|
Packit Service |
c5cf8c |
# --------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
# Check the input arguments
|
|
Packit Service |
c5cf8c |
if ($indir eq "" || $outdir eq "") {
|
|
Packit Service |
c5cf8c |
print STDERR "Usage: f77tof90 indir outdir [ makefile-template ]\n";
|
|
Packit Service |
c5cf8c |
exit 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ( ! -d $indir) {
|
|
Packit Service |
c5cf8c |
print STDERR "Input directory $indir does not exist\n";
|
|
Packit Service |
c5cf8c |
exit 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (! -d $outdir) {
|
|
Packit Service |
c5cf8c |
print STDERR "Output directory $outdir does not exist\n";
|
|
Packit Service |
c5cf8c |
exit 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# --------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# --------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
opendir( DIR, "$indir" );
|
|
Packit Service |
c5cf8c |
my @filelist = ();
|
|
Packit Service |
c5cf8c |
while ($file = readdir(DIR)) {
|
|
Packit Service |
c5cf8c |
# Extract the extension
|
|
Packit Service |
c5cf8c |
if ($file =~ /^(.*)\.([^\.]*)$/) {
|
|
Packit Service |
c5cf8c |
$name = $1;
|
|
Packit Service |
c5cf8c |
$ext = $2;
|
|
Packit Service |
c5cf8c |
# Special handling for C files, if any
|
|
Packit Service |
c5cf8c |
if ($ext eq "c") {
|
|
Packit Service |
c5cf8c |
my $name90 = $name;
|
|
Packit Service |
c5cf8c |
# don't transform "ctypesfromc" to "ctypesf90romc"
|
|
Packit Service |
c5cf8c |
if ($name ne "ctypesfromc") {
|
|
Packit Service |
c5cf8c |
$name90 =~ s/f/f90/g;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
&ConvertCFile( "$indir/$file", "$outdir/$name90.c.new" );
|
|
Packit Service |
c5cf8c |
&ReplaceIfDifferent( "$outdir/$name90.c",
|
|
Packit Service |
c5cf8c |
"$outdir/$name90.c.new" );
|
|
Packit Service |
c5cf8c |
next;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Skip if the file isn't a Fortran source file
|
|
Packit Service |
c5cf8c |
if ($ext ne "f" && $ext ne "F") { next; }
|
|
Packit Service |
c5cf8c |
&ConvertToF90( "$indir/$file", "$outdir/${name}90.${ext}90.new" );
|
|
Packit Service |
c5cf8c |
&ReplaceIfDifferent( "$outdir/${name}90.${ext}90",
|
|
Packit Service |
c5cf8c |
"$outdir/${name}90.${ext}90.new" );
|
|
Packit Service |
c5cf8c |
$filelist[$#filelist+1] = $file;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
closedir( DIR );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# &CreateMakefile( "filelist", $outdir );
|
|
Packit Service |
c5cf8c |
if (defined($makeTemplate) && $makeTemplate ne "" &&
|
|
Packit Service |
c5cf8c |
-s "$indir/$makeTemplate") {
|
|
Packit Service |
c5cf8c |
&ConvertMakefile( $indir, $outdir, $makeTemplate );
|
|
Packit Service |
c5cf8c |
if (defined($makeAppend) && -s "$outdir/$makeAppend") {
|
|
Packit Service |
c5cf8c |
# If there is a makeAppend in the output directory, then
|
|
Packit Service |
c5cf8c |
# append that to the generated makefile
|
|
Packit Service |
c5cf8c |
&AppendFile( "$outdir/$makeAppend", "$outdir/$makeTemplate.new" );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
&ReplaceIfDifferent( "$outdir/$makeTemplate",
|
|
Packit Service |
c5cf8c |
"$outdir/$makeTemplate.new" );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# unconditionally update the stamp file to assist the maintainer rebuild
|
|
Packit Service |
c5cf8c |
# rules
|
|
Packit Service |
c5cf8c |
open(STAMP, '>', "$outdir/Makefile.am-stamp");
|
|
Packit Service |
c5cf8c |
print STAMP localtime()."\n";
|
|
Packit Service |
c5cf8c |
close(STAMP);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (-s "$indir/testlist" || -s "$indir/testlist.in") {
|
|
Packit Service |
c5cf8c |
# We allow both testlist.in and testlist as source files;
|
|
Packit Service |
c5cf8c |
# testlist.in gets priority
|
|
Packit Service |
c5cf8c |
my $filename = "testlist";
|
|
Packit Service |
c5cf8c |
if (-s "$indir/testlist.in") {
|
|
Packit Service |
c5cf8c |
$filename = "testlist.in";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
&ConvertTestlist( $indir, $outdir, $filename );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (-s "$outdir/testlist.ap") {
|
|
Packit Service |
c5cf8c |
&AppendFile( "$outdir/testlist.ap", "$outdir/$filename.new" );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
&ReplaceIfDifferent( "$outdir/$filename", "$outdir/$filename.new" );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
exit 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# -----------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sub ConvertToF90 {
|
|
Packit Service |
c5cf8c |
my $infile = $_[0];
|
|
Packit Service |
c5cf8c |
my $outfile = $_[1];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open (INF, "<$infile" ) || die "Could not open $infile\n";
|
|
Packit Service |
c5cf8c |
open (OUTF, ">$outfile" ) || die "Could not open $outfile\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print OUTF "! This file created from $infile with f77tof90\n";
|
|
Packit Service |
c5cf8c |
my $lastLine = "";
|
|
Packit Service |
c5cf8c |
my $firstline = 1;
|
|
Packit Service |
c5cf8c |
while (<INF>) {
|
|
Packit Service |
c5cf8c |
if (/\r/) { $newline = "\r\n"; }
|
|
Packit Service |
c5cf8c |
# Remove any end-of-line characters
|
|
Packit Service |
c5cf8c |
s/[\r\n]*//g;
|
|
Packit Service |
c5cf8c |
# The implicit none must not come before the use mpi statement,
|
|
Packit Service |
c5cf8c |
# but in F77, it must come before the include mpif.h statement.
|
|
Packit Service |
c5cf8c |
# Rather than try and fix this, rely on the F77 versions to
|
|
Packit Service |
c5cf8c |
# catch undeclared variables
|
|
Packit Service |
c5cf8c |
if (/[Ii][Mm][Pp][Ll][Ii][Cc][Ii][Tt]\s+[Nn][Oo][Nn][Ee]/) { next; }
|
|
Packit Service |
c5cf8c |
if (/^(\s*)include\s+[\'\"]mpif\.h/) {
|
|
Packit Service |
c5cf8c |
$_ = "$1use mpi";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Allow the insertion of Fortran 90 only statements, such as
|
|
Packit Service |
c5cf8c |
# interface definitions
|
|
Packit Service |
c5cf8c |
if (/^CF90/) {
|
|
Packit Service |
c5cf8c |
s/^CF90/ /;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Remove lines used only for F77, such as external MPI function declarations
|
|
Packit Service |
c5cf8c |
if (/!\s*F77ONLY\s*$/i) {
|
|
Packit Service |
c5cf8c |
$_ = "";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Since we use interface statements for the error handlers,
|
|
Packit Service |
c5cf8c |
# remove their external declaration
|
|
Packit Service |
c5cf8c |
if (/^\s+external myerrhanfunc/) {
|
|
Packit Service |
c5cf8c |
s/^\s/!/;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($convertToNewComments) {
|
|
Packit Service |
c5cf8c |
s/^C/!/;
|
|
Packit Service |
c5cf8c |
s/^c/!/;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Update the special includes that are used to provide
|
|
Packit Service |
c5cf8c |
# address or offset sized types with ones the use the
|
|
Packit Service |
c5cf8c |
# Fortran90 KIND style
|
|
Packit Service |
c5cf8c |
if (/^(\s*)include\s+[\'\"]([\/\.\w]+)\.h[\"\']/) {
|
|
Packit Service |
c5cf8c |
my $leading = $1;
|
|
Packit Service |
c5cf8c |
my $includename = $2;
|
|
Packit Service |
c5cf8c |
if (defined($replaceInclude{$includename})) {
|
|
Packit Service |
c5cf8c |
$_ = $leading . $replaceInclude{$includename} . "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# We need to handle the special case of the program
|
|
Packit Service |
c5cf8c |
# name in spawn commands
|
|
Packit Service |
c5cf8c |
if (/(.*)\"([\.\/\w]*spawn[^\"]*)\"(.*)/) {
|
|
Packit Service |
c5cf8c |
my $before = $1;
|
|
Packit Service |
c5cf8c |
my $name = $2;
|
|
Packit Service |
c5cf8c |
my $after = $3;
|
|
Packit Service |
c5cf8c |
$_ = $before . "\"" . $name . "90" . "\"" . $after;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# We could also detect continuations in column six and
|
|
Packit Service |
c5cf8c |
# convert to free-form input by holding one line back.
|
|
Packit Service |
c5cf8c |
if ($convertToFreeForm) {
|
|
Packit Service |
c5cf8c |
if (/^ \S(.*)/) {
|
|
Packit Service |
c5cf8c |
$leftover = $1;
|
|
Packit Service |
c5cf8c |
# This line contains a continuation marker
|
|
Packit Service |
c5cf8c |
# Add a continuation marker to the previous line if
|
|
Packit Service |
c5cf8c |
# it doesn't already have one
|
|
Packit Service |
c5cf8c |
if (! ($lastline =~ /\&\s*$/) ) {
|
|
Packit Service |
c5cf8c |
$lastline .= " &";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
$_ = " \&$leftover";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print OUTF "$lastline$newline" if (! $firstline);
|
|
Packit Service |
c5cf8c |
$firstline = 0;
|
|
Packit Service |
c5cf8c |
$lastline = $_;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print OUTF "$lastline$newline";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
close (INF);
|
|
Packit Service |
c5cf8c |
close (OUTF);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# A very simple routine for creating a version of a C file that refers
|
|
Packit Service |
c5cf8c |
# to F90 instead of F77.
|
|
Packit Service |
c5cf8c |
sub ConvertCFile {
|
|
Packit Service |
c5cf8c |
my $infile = $_[0];
|
|
Packit Service |
c5cf8c |
my $outfile = $_[1];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open (INF, "<$infile" ) || die "Could not open $infile\n";
|
|
Packit Service |
c5cf8c |
open (OUTF, ">$outfile" ) || die "Could not open $outfile\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print OUTF "/* This file created from $infile with f77tof90 */\n";
|
|
Packit Service |
c5cf8c |
while (<INF>) {
|
|
Packit Service |
c5cf8c |
if (/\r/) { $newline = "\r\n"; }
|
|
Packit Service |
c5cf8c |
# Remove any end-of-line characters
|
|
Packit Service |
c5cf8c |
s/[\r\n]*//g;
|
|
Packit Service |
c5cf8c |
# replace F77 with F90, mostly for CPP tests, except for name
|
|
Packit Service |
c5cf8c |
# mapping
|
|
Packit Service |
c5cf8c |
if (! /F77_NAME/) {
|
|
Packit Service |
c5cf8c |
s/F77/F90/g;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print OUTF "$_$newline";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
close (INF);
|
|
Packit Service |
c5cf8c |
close (OUTF);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Create a makefile from a template. Replace @EXECS@ with the programs
|
|
Packit Service |
c5cf8c |
# in the filelist.
|
|
Packit Service |
c5cf8c |
# CreateMakefile( "filelist", $outdir )
|
|
Packit Service |
c5cf8c |
sub CreateMakefile {
|
|
Packit Service |
c5cf8c |
my $filelist = $_[0];
|
|
Packit Service |
c5cf8c |
my $outdir = $_[1];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print STDERR "This function is not implemented\n";
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Take an existing makefile and perform the following transformations:
|
|
Packit Service |
c5cf8c |
# .f -> .f90, .F -> .F90
|
|
Packit Service |
c5cf8c |
# Others as necessary
|
|
Packit Service |
c5cf8c |
# ConvertMakefile( indir, outdir, filename )
|
|
Packit Service |
c5cf8c |
# By providing the filename, we can accept Makefile, Makefile.in, Makefile.ap,
|
|
Packit Service |
c5cf8c |
# Makefile.sm, or even nonstandard names such as buildscript.
|
|
Packit Service |
c5cf8c |
sub ConvertMakefile {
|
|
Packit Service |
c5cf8c |
my ($indir, $outdir, $filename) = @_;
|
|
Packit Service |
c5cf8c |
%excludePrograms = ();
|
|
Packit Service |
c5cf8c |
my $saw_maintainercleanfiles = 0;
|
|
Packit Service |
c5cf8c |
my $saw_extra_dist = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open( INF, "<$indir/$filename" ) || die "Cannot open $indir/$filename\n";
|
|
Packit Service |
c5cf8c |
open( OUTF, ">$outdir/$filename.new" ) || die "Cannot open $outdir/$filename.new\n";
|
|
Packit Service |
c5cf8c |
print OUTF "# This $filename generated automatically by f77tof90\n";
|
|
Packit Service |
c5cf8c |
print OUTF "# from $indir/$filename. DO NOT EDIT\n";
|
|
Packit Service |
c5cf8c |
while (<INF>) {
|
|
Packit Service |
c5cf8c |
if (not m/^\s*#/ and m/MAINTAINERCLEANFILES/) {
|
|
Packit Service |
c5cf8c |
$saw_maintainercleanfiles = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (not m/^\s*#/ and m/EXTRA_DIST/) {
|
|
Packit Service |
c5cf8c |
$saw_extra_dist = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# First, check for sources that are not present. These
|
|
Packit Service |
c5cf8c |
# may be derived files (see f77/io for an example). For now,
|
|
Packit Service |
c5cf8c |
# we'll skip these unless they are explicitly expected to not be present
|
|
Packit Service |
c5cf8c |
# (by the presence of a "nodist_" prefix.
|
|
Packit Service |
c5cf8c |
if (/^(nodist_)?(\w+)_SOURCES\s*=\s*(\w+\.f)/) {
|
|
Packit Service |
c5cf8c |
my $nodist = $1;
|
|
Packit Service |
c5cf8c |
my $sourcebase = $2;
|
|
Packit Service |
c5cf8c |
my $sourcename = $3;
|
|
Packit Service |
c5cf8c |
if (not $nodist and ! -s "$indir/$sourcename") {
|
|
Packit Service |
c5cf8c |
print "Skipping source file $indir/$sourcename because it is not present\n" if $reportSkipped;
|
|
Packit Service |
c5cf8c |
$excludePrograms{$sourcebase} = 1;
|
|
Packit Service |
c5cf8c |
next;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Headers like f77/spawn/type1aints.h are not used in the f90 tests.
|
|
Packit Service |
c5cf8c |
# They are instead replaced with appropriate "kind=" type declarations
|
|
Packit Service |
c5cf8c |
# in a different part of this script. So we drop any lines that add
|
|
Packit Service |
c5cf8c |
# dependencies on a header.
|
|
Packit Service |
c5cf8c |
if (m/^\w+f\.\$\(OBJEXT\):.*\.h/) {
|
|
Packit Service |
c5cf8c |
my $chomped = $_;
|
|
Packit Service |
c5cf8c |
chomp $_;
|
|
Packit Service |
c5cf8c |
next;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# convert program names from foof.f to foof90.f90
|
|
Packit Service |
c5cf8c |
s/f_SOURCES/f90_SOURCES/g;
|
|
Packit Service |
c5cf8c |
s/f_DEPENDENCIES/f90_DEPENDENCIES/g;
|
|
Packit Service |
c5cf8c |
if (/f\.f/) {
|
|
Packit Service |
c5cf8c |
s/f\.f/f90.f90/g;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
# Move files to f90
|
|
Packit Service |
c5cf8c |
s/\.f/.f90/g;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
s/mtestf\.o/mtestf90.o/;
|
|
Packit Service |
c5cf8c |
s/\.F/.F90/g;
|
|
Packit Service |
c5cf8c |
s/f77/f90/g;
|
|
Packit Service |
c5cf8c |
s/F77/FC/g;
|
|
Packit Service |
c5cf8c |
# Update any per-program LDADD values
|
|
Packit Service |
c5cf8c |
s/f_LDADD/f90_LDADD/g;
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Handle special cases:
|
|
Packit Service |
c5cf8c |
# Force the c2f2c test to use the f90 compiler
|
|
Packit Service |
c5cf8c |
s/c2f2cf90_SOURCES.*/c2f2cf90_SOURCES = c2f2cf90.f90 c2f902c.c/;
|
|
Packit Service |
c5cf8c |
s/c2f2ciof90_SOURCES.*/c2f2ciof90_SOURCES = c2f2ciof90.f90 c2f902cio.c/;
|
|
Packit Service |
c5cf8c |
# s/c2f2ciof90_LDADD/c2f2cfio90_LDADD/g;
|
|
Packit Service |
c5cf8c |
s/c2f2cwinf90_SOURCES.*/c2f2cwinf90_SOURCES = c2f2cwinf90.f90 c2f902cwin.c/;
|
|
Packit Service |
c5cf8c |
s/c2fmult/c2f90mult/g;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (/EXTRA_PROGRAMS/) {
|
|
Packit Service |
c5cf8c |
s/allocmemf/allocmemf90/; # allocmemf test is special
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Handle the special case of C programs (used for f2c/c2f testing)
|
|
Packit Service |
c5cf8c |
if (/^(\w+)_SOURCES(\s*=\s*)(\w+)\.c\s*$/) {
|
|
Packit Service |
c5cf8c |
my $progname = $1;
|
|
Packit Service |
c5cf8c |
my $spacing = $2;
|
|
Packit Service |
c5cf8c |
my $name = $3;
|
|
Packit Service |
c5cf8c |
if ($name !~ m/ctypesfromc/) {
|
|
Packit Service |
c5cf8c |
$name =~ s/f(?!90)/f90/;
|
|
Packit Service |
c5cf8c |
$progname =~ s/f(?!90)/f90/;
|
|
Packit Service |
c5cf8c |
$_ = "$progname" . "_SOURCES" . $spacing . $name . ".c\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Catch any bare "Xf" tests listed in noinst_PROGRAMS or
|
|
Packit Service |
c5cf8c |
# EXTRA_PROGRAMS. Check for "Xf.f" to avoid substituting any random
|
|
Packit Service |
c5cf8c |
# word that ends in "f". We also cheat a bit and look into the
|
|
Packit Service |
c5cf8c |
# ioharness.defn in the indir directory for valid file names.
|
|
Packit Service |
c5cf8c |
if (not m/^\s*#/) {
|
|
Packit Service |
c5cf8c |
while (m/\b(\w+f)\b/g) {
|
|
Packit Service |
c5cf8c |
my $word = $1;
|
|
Packit Service |
c5cf8c |
next if $word eq "if" or $word eq "rf" or $word eq "endif"; # filter out some noise
|
|
Packit Service |
c5cf8c |
if (-e "$indir/${word}.f" or
|
|
Packit Service |
c5cf8c |
0 == system(qq(grep 'TESTDEFN filename="${word}\\.f"' '$indir/ioharness.defn' >/dev/null 2>&1)))
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
s/\b${word}\b/${word}90/g;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
print "Skipping word '${word}' because file $indir/${word}.f is not present\n" if $reportSkipped;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# f90 makefiles should use the corresponding common automake fragment
|
|
Packit Service |
c5cf8c |
s/Makefile_f77.mtest/Makefile_f90.mtest/g;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Eventually need some way to update directory paths (particularly
|
|
Packit Service |
c5cf8c |
# relative ones) and add F90 compile rules when not present.
|
|
Packit Service |
c5cf8c |
print OUTF $_;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
my $mcf_plus = '';
|
|
Packit Service |
c5cf8c |
if ($saw_maintainercleanfiles) {
|
|
Packit Service |
c5cf8c |
$mcf_plus = '+';
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
my $ed_plus = '';
|
|
Packit Service |
c5cf8c |
if ($saw_extra_dist) {
|
|
Packit Service |
c5cf8c |
$ed_plus = '+';
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
my $testlist_ap = '';
|
|
Packit Service |
c5cf8c |
if (-f "${outdir}/testlist.ap") {
|
|
Packit Service |
c5cf8c |
$testlist_ap = 'testlist.ap';
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
my $makefile_ap = '';
|
|
Packit Service |
c5cf8c |
if (-f "${outdir}/Makefile.ap") {
|
|
Packit Service |
c5cf8c |
$makefile_ap = 'Makefile.ap';
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# append a rule to help remake the f90 Makefile.am if the f77 Makefile.am is
|
|
Packit Service |
c5cf8c |
# updated
|
|
Packit Service |
c5cf8c |
print OUTF <
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if MAINTAINER_MODE
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# f77tof90 only replaces output files if the contents differ, so we must use a
|
|
Packit Service |
c5cf8c |
# separate timestamp file in order avoid constantly trying to remake the f90
|
|
Packit Service |
c5cf8c |
# copy of the Makefile when the f77 copy is updated in a way that does not
|
|
Packit Service |
c5cf8c |
# change its contents
|
|
Packit Service |
c5cf8c |
\$(srcdir)/Makefile.am: \$(srcdir)/Makefile.am-stamp
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
\$(srcdir)/Makefile.am-stamp: \$(top_srcdir)/${indir}/Makefile.am \$(top_srcdir)/maint/f77tof90
|
|
Packit Service |
c5cf8c |
\t( cd \$(top_srcdir) && ./maint/f77tof90 ${indir} ${outdir} Makefile.am Makefile.ap )
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MAINTAINERCLEANFILES ${mcf_plus}= Makefile.am-stamp
|
|
Packit Service |
c5cf8c |
EXTRA_DIST ${ed_plus}= Makefile.am-stamp ${testlist_ap} ${makefile_ap}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
endif MAINTAINER_MODE
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
EOT
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
close( INF );
|
|
Packit Service |
c5cf8c |
close( OUTF );
|
|
Packit Service |
c5cf8c |
# The check on a file change is handled in the routine that calls this
|
|
Packit Service |
c5cf8c |
# because we may append to this file first.
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Append infile to the end of inout file
|
|
Packit Service |
c5cf8c |
#( infile, inoutfile )
|
|
Packit Service |
c5cf8c |
sub AppendFile {
|
|
Packit Service |
c5cf8c |
my $infile = $_[0];
|
|
Packit Service |
c5cf8c |
my $outfile = $_[1];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open( INA, "<$infile" ) || die "Cannot open $infile\n";
|
|
Packit Service |
c5cf8c |
open( OUTA, ">>$outfile" ) || die "Cannot open $outfile\n";
|
|
Packit Service |
c5cf8c |
while (<INA>) {
|
|
Packit Service |
c5cf8c |
print OUTA $_;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
close(INA);
|
|
Packit Service |
c5cf8c |
close(OUTA);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Replace old file with new file only if new file is different
|
|
Packit Service |
c5cf8c |
# Otherwise, remove new filename
|
|
Packit Service |
c5cf8c |
sub ReplaceIfDifferent {
|
|
Packit Service |
c5cf8c |
my ($oldfilename,$newfilename) = @_;
|
|
Packit Service |
c5cf8c |
my $rc = 1;
|
|
Packit Service |
c5cf8c |
if (-s $oldfilename) {
|
|
Packit Service |
c5cf8c |
$rc = system "cmp -s $newfilename $oldfilename";
|
|
Packit Service |
c5cf8c |
$rc >>= 8; # Shift right to get exit status
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($rc != 0) {
|
|
Packit Service |
c5cf8c |
print STDERR "Replacing $oldfilename\n";
|
|
Packit Service |
c5cf8c |
if ($debugReplace && -s $oldfilename) {
|
|
Packit Service |
c5cf8c |
print STDERR "Differences are:";
|
|
Packit Service |
c5cf8c |
system "diff $newfilename $oldfilename";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# The files differ. Replace the old file
|
|
Packit Service |
c5cf8c |
# with the new one
|
|
Packit Service |
c5cf8c |
if (-s $oldfilename) {
|
|
Packit Service |
c5cf8c |
unlink $oldfilename;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
rename $newfilename, $oldfilename ||
|
|
Packit Service |
c5cf8c |
die "Could not replace $oldfilename";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
unlink $newfilename;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Change the names of the tests. Remove any that were skipped from the
|
|
Packit Service |
c5cf8c |
# Makefile. Check for a testlist.in before testlist
|
|
Packit Service |
c5cf8c |
sub ConvertTestlist {
|
|
Packit Service |
c5cf8c |
my ($indir, $outdir, $filename) = @_;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open( INF, "<$indir/$filename" ) || die "Cannot open $indir/$filename\n";
|
|
Packit Service |
c5cf8c |
open( OUTF, ">$outdir/$filename.new" ) || die "Cannot open $outdir/$filename.new\n";
|
|
Packit Service |
c5cf8c |
print OUTF "# This file generated by f77tof90\n";
|
|
Packit Service |
c5cf8c |
while (<INF>) {
|
|
Packit Service |
c5cf8c |
if (/^(\w+)\s/) {
|
|
Packit Service |
c5cf8c |
my $sourcebase = $1;
|
|
Packit Service |
c5cf8c |
if (defined($excludePrograms{$sourcebase})) { next; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (/^(\w+f)\s+(.*)/) {
|
|
Packit Service |
c5cf8c |
$_ = $1 . "90 " . $2 . "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif (/^c2fmult(\w*)\s+(.*)/) {
|
|
Packit Service |
c5cf8c |
# This is a special case for programs that are not Fortran
|
|
Packit Service |
c5cf8c |
# programs but are part of the Fortran tests; principly, these
|
|
Packit Service |
c5cf8c |
# are the tests of MPI handle conversion
|
|
Packit Service |
c5cf8c |
# note the \w* instead of \w+; this allows us to match both
|
|
Packit Service |
c5cf8c |
# c2fmult.c and c2fmultio.c
|
|
Packit Service |
c5cf8c |
$_ = "c2f90mult$1 $2\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif (/^\@ALLOCMEMF\@/) {
|
|
Packit Service |
c5cf8c |
# This is a special case for an optional feature (using
|
|
Packit Service |
c5cf8c |
# Cray-style pointers for MPI_Alloc_mem).
|
|
Packit Service |
c5cf8c |
$_ = "\@ALLOCMEMFC\@\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif (/^(\@\w+\@)(\s*\w+f)\s+(.*)/) {
|
|
Packit Service |
c5cf8c |
# This handles the case where an autoconf variable in the
|
|
Packit Service |
c5cf8c |
# testlist.in file is used to optionally comment out a test
|
|
Packit Service |
c5cf8c |
$_ = $1 . $2 . "90 " . $3 . "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print OUTF $_;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
close INF;
|
|
Packit Service |
c5cf8c |
close OUTF;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
}
|