[Dart-dev] [6377] DART/trunk: make the mkmf perl script generate a makefile target that

nancy at ucar.edu nancy at ucar.edu
Fri Aug 2 11:59:24 MDT 2013


Revision: 6377
Author:   nancy
Date:     2013-08-02 11:59:24 -0600 (Fri, 02 Aug 2013)
Log Message:
-----------
make the mkmf perl script generate a makefile target that
will silently check the status of the mpi source files
and alter them if they are configured for a different compiler.

fixsystem now takes a single argument: the name of the compiler
command, such as 'ifort', 'gfortran', 'pgf90', 'xlf90', etc.
it will ensure the source is compatible for that compiler.
for now for backwards compatibility this script can still be
called without any arguments; but this will eventually be
deprecated and the compiler name will have to be supplied
as an argument.

remove mention of fixsystem from the top level README.

Modified Paths:
--------------
    DART/trunk/README
    DART/trunk/mkmf/mkmf
    DART/trunk/mpi_utilities/fixsystem

-------------- next part --------------
Modified: DART/trunk/README
===================================================================
--- DART/trunk/README	2013-08-02 16:48:18 UTC (rev 6376)
+++ DART/trunk/README	2013-08-02 17:59:24 UTC (rev 6377)
@@ -54,9 +54,6 @@
 *This NetCDF library must have been compiled with the same compiler
 that you use to compile DART, and must include the F90 interfaces.*
 
-If you are using gfortran, go into the 'mpi_utilities' directory and run
-the './fixsystem' shell script.
-
 Go into 'models/lorenz_63/work' and run './quickbuild.csh'.
 
 If it compiles, hooray.  Run './perfect_model_obs' and then './filter'.
@@ -68,7 +65,7 @@
 
 If you are planning to run one of the larger models and want to
 test the MPI version of DART, run './quickbuild.csh -mpi'.  It will
-recompile the Lorenz 63 model without MPI and then try to build
+first compile the Lorenz 63 model without MPI and then try to build
 filter with MPI.  *The 'mpif90' command you use must have been built
 with the same version of the compiler as you are using.*
 

Modified: DART/trunk/mkmf/mkmf
===================================================================
--- DART/trunk/mkmf/mkmf	2013-08-02 16:48:18 UTC (rev 6376)
+++ DART/trunk/mkmf/mkmf	2013-08-02 17:59:24 UTC (rev 6377)
@@ -137,7 +137,13 @@
 }
 print MAKEFILE "\nOTHERFLAGS = $opt_o" if $opt_o;
 print MAKEFILE "\n.DEFAULT:\n\t-touch \$@\n";
-print MAKEFILE "all: $opt_p\n"; # first target should be program, so you can type just 'make'
+#change for running 'fixsystem' automatically.  nsc 02aug2013
+#the original target for all: was simply $opt_p
+#the at sign prevents the command from being echoed to the terminal.
+print MAKEFILE "all: fixsys $opt_p\n"; # first target should be program, so you can type just 'make'
+print MAKEFILE "fixsys: \n";
+print MAKEFILE "\t@ (cd ${opt_a}mpi_utilities\; ./fixsystem \$(FC) )\n" ;
+#end change nsc 02aug2013
 
 #if cppdefs flag is present, look for changes in cppdefs
 my %chgdefs;

Modified: DART/trunk/mpi_utilities/fixsystem
===================================================================
--- DART/trunk/mpi_utilities/fixsystem	2013-08-02 16:48:18 UTC (rev 6376)
+++ DART/trunk/mpi_utilities/fixsystem	2013-08-02 17:59:24 UTC (rev 6377)
@@ -6,39 +6,41 @@
 #
 # $Id$
 
-# usage: fixsystem [ -gfortran | -not_gfortran ]
+# usage: fixsystem [ your_fortran_command_name | -help  ]
+#         (e.g. ifort, pgf90, gfortran, g95, xlf90, etc)
 #
-# in two DART source code files in this directory we depend on using 
-# the system() function to run a shell script and wait for the shell 
-# exit code, e.g.:  rc = system("/bin/date")
+# this script updates the mpi source files for any compiler-dependent
+# changes needed before building.
+# 
+# at the moment the only compiler-dependent code is the declaration
+# of the "system()" function in a fortran interface block.
+# the code uses this function to run a shell script or command and 
+# wait for the command exit code, e.g.:  rc = system("/bin/date")
 #
 # for all compilers, except gfortran, an interface block is required
 # to define the integer return from the system function.  however
 # the gfortran compiler gives an error if this block is defined.
-# this script tries to comment in and out this interface block by
+# this script enables and disables this interface block by
 # looking for a pair of specially formatted comment lines and
 # commenting in (or out) all the lines between those comment 
 # delimiter lines.
 #
 # the original usage of this script was without any arguments. 
-# it swapped the state of the comment block; if it was commented out
-# it removed the comment characters, or if the code was enabled
-# it added comment chars.  it still has this backwards-compatible
-# behavior but now it also takes a single optional argument
-# which must be one of:  -gfortran   or -not_gfortran
-# it ensures the interface block is in the correct configuration
-# for the given compiler.
+# the backwards compatibility remains for now, but is deprecated.
+# usage now is to give it a single argument - the name that the
+# fortran compiler is invoked with, e.g. ifort, xlf90, pgf90, etc.
+# it will ensure that any required changes to the source will be
+# made here before compilation.
 
+
 for f in mpi_utilities_mod.f90 null_mpi_utilities_mod.f90
 do
 
   # figure out what state the source file is in before we start
   export bline=`fgrep SYSTEM_BLOCK_EDIT ${f} | grep START | head -n 1`
   if [[ "`echo $bline | grep COMMENTED_OUT`" != ""  ]]; then
-    #echo Is no interface block for system in ${f}
     export before=out
   elif [[ "`echo $bline | grep COMMENTED_IN`" != ""  ]]; then
-    #echo Interface block is present in ${f}
     export before=in
   else
     echo ${f} not found, or does not have the right comment string to
@@ -49,32 +51,43 @@
   fi
 
   if [[ $# == 0 ]]; then
-    # no args given, swap to the other configuration
+    # no args given, swap to the other configuration.  deprecated
+    # and eventually a single argument will become required.
     if [[ $before == out ]]; then
       export todo=in
+      export compiler=non-gfortran
     elif [[ $before == in ]]; then
       export todo=out
+      export compiler=gfortran
     else
       echo Internal error; should not happen.  Contact DART support.
       exit 1
     fi
 
   elif [[ $# == 1 ]]; then
-    # single arg: must be either -gfortran or -not_gfortran
-    if [[ "$1" == -gfortran ]]; then
+    # single arg: the name of your fortran compiler command
+    if [[ "$1" == help || "$1" == -help || "$1" == --help ]]; then
+      echo "usage: $0 [ your_fortran_command_name | -help  ]"
+      echo "  e.g. $0 gfortran"
+      echo "  or   $0 ifort "
+      echo "  or   $0 pgf90 "
+      echo "  etc."
+      exit 1
+    elif [[ "$1" == gfortran ]]; then
       export todo=out
-    elif [[ "$1" == -not_gfortran ]]; then
+    else
       export todo=in
-    else
-      echo unrecognized argument \"$1\" given to $0
-      echo valid args are either \"-gfortran\" or \"-not_gfortran\"
-      exit 1
     fi
+    export compiler=$1
 
   else
     # too many arguments, give an error message and exit
     echo invalid usage, more than 1 argument given to $0
-    echo only one of either \"-gfortran\" or \"-not_gfortran\" can be specified
+    echo "usage: $0 [ your_fortran_command_name | -help  ]"
+    echo "  e.g. $0 gfortran"
+    echo "  or   $0 ifort "
+    echo "  or   $0 pgf90 "
+    echo "  etc."
     exit 1
   fi
   
@@ -89,18 +102,19 @@
     cp -p ${f} ${f}.orig
   fi
   
+  # say what compiler we are doing this for, and move the existing
+  # code into a temporary file so the sed command does not overwrite it.
+  echo Setting for $compiler compiler in ${f}
+  mv ${f} tempfile
+
   # removing comment chars, enabling interface block code
   if [[ $todo == in ]]; then
-   echo Setting for a non-gfortran compiler in ${f}
-   mv ${f} tempfile
    sed -e '/SYSTEM_BLOCK_EDIT START COMMENTED_OUT/,/SYSTEM_BLOCK_EDIT END COMMENTED_OUT/s/^!//' \
        -e '/\(SYSTEM_BLOCK_EDIT [A-Z][A-Z]*\) COMMENTED_OUT/s//\1 COMMENTED_IN/' tempfile > ${f}
   fi
   
   # adding comment chars, disabling interface block code
   if [[ $todo == out ]]; then
-   echo Setting for gfortran compiler in ${f}
-   mv ${f} tempfile
    sed -e '/SYSTEM_BLOCK_EDIT START COMMENTED_IN/,/SYSTEM_BLOCK_EDIT END COMMENTED_IN/s/^/!/' \
        -e '/\(SYSTEM_BLOCK_EDIT [A-Z][A-Z]*\) COMMENTED_IN/s//\1 COMMENTED_OUT/' tempfile > ${f}
   fi


More information about the Dart-dev mailing list