From 3787f0c64c98f86b6c5b799cdf942d762d760f2c Mon Sep 17 00:00:00 2001 From: Stephen Sachs Date: Thu, 7 Jul 2022 17:04:51 +0200 Subject: mpas-model: Overwrite compiler args in Makefile (#31431) Use 8 byte reals only when `precision=double` is set The pre-defined compilation targets do not follow the usual behavior of Makefiles. Compiler flags are set as strings (not Makefile variables) and as such are not able to be overridden by environment variables. This patch changes the behavior to the expected behavior of a Makefile such that `fflags` etc have the desired effect. Co-authored-by: Stephen Sachs --- .../repos/builtin/packages/mpas-model/package.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/var/spack/repos/builtin/packages/mpas-model/package.py b/var/spack/repos/builtin/packages/mpas-model/package.py index 92ac98c3ca..92314413c2 100644 --- a/var/spack/repos/builtin/packages/mpas-model/package.py +++ b/var/spack/repos/builtin/packages/mpas-model/package.py @@ -5,6 +5,7 @@ import os from spack.package import * +from spack.util.executable import Executable class MpasModel(MakefilePackage): @@ -58,6 +59,21 @@ class MpasModel(MakefilePackage): git='https://github.com/MPAS-Dev/MPAS-Data.git', tag='v7.0') + def patch_makefile(self, action, targets): + """Patch predefined flags in Makefile. + MPAS Makefile uses strings rather Makefile variables for its compiler flags. + This patch substitutes the strings with flags set in `target:`.""" + + # Target `all:` does not contain any strings with compiler flags + if action == "all": + return + + sed = Executable('sed') + for target in targets: + key = target.split('=')[0] + sed("-i", "-e", "/^" + action + ":.*$/,/^$/s?" + key + ".*\\\" \\\\?" + + target + "\\\" \\\\?1", "Makefile") + def target(self, model, action): spec = self.spec satisfies = spec.satisfies @@ -80,10 +96,12 @@ class MpasModel(MakefilePackage): ]) elif satisfies('%intel'): fflags.extend([ - '-r8', '-convert big_endian', '-FR', ]) + if satisfies('precision=double'): + fflags.extend(['-r8']) + cppflags.append('-DUNDERSCORE') targets = [ 'FC_PARALLEL={0}'.format(spec['mpi'].mpifc), @@ -121,6 +139,7 @@ class MpasModel(MakefilePackage): 'CORE={0}'.format(model), action ]) + self.patch_makefile(action, targets) return targets def build(self, spec, prefix): -- cgit v1.2.3-70-g09d2