summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Sachs <stephenmsachs@gmail.com>2022-07-07 17:04:51 +0200
committerGitHub <noreply@github.com>2022-07-07 17:04:51 +0200
commit3787f0c64c98f86b6c5b799cdf942d762d760f2c (patch)
tree18c2f778f0c76e43c52033f16bc548bb81cf7108
parentbe65e4471e6e5d70972d9fd7a51ad0ac052360d5 (diff)
downloadspack-3787f0c64c98f86b6c5b799cdf942d762d760f2c.tar.gz
spack-3787f0c64c98f86b6c5b799cdf942d762d760f2c.tar.bz2
spack-3787f0c64c98f86b6c5b799cdf942d762d760f2c.tar.xz
spack-3787f0c64c98f86b6c5b799cdf942d762d760f2c.zip
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 <stesachs@amazon.com>
-rw-r--r--var/spack/repos/builtin/packages/mpas-model/package.py21
1 files changed, 20 insertions, 1 deletions
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):