diff --git a/var/spack/repos/builtin/packages/netcdf-fortran/package.py b/var/spack/repos/builtin/packages/netcdf-fortran/package.py index cd6ed11146..1178de8d57 100644 --- a/var/spack/repos/builtin/packages/netcdf-fortran/package.py +++ b/var/spack/repos/builtin/packages/netcdf-fortran/package.py @@ -4,6 +4,9 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) from spack import * +import os +import glob +from shutil import copyfile, Error class NetcdfFortran(AutotoolsPackage): @@ -69,6 +72,14 @@ def flag_handler(self, name, flags): if self.spec.satisfies('%gcc@10:'): # https://github.com/Unidata/netcdf-fortran/issues/212 flags.append('-fallow-argument-mismatch') + elif self.compiler.name == 'cce': + # Cray compiler generates module files with uppercase names by + # default, which is not handled by the makefiles of + # NetCDF-Fortran: + # https://github.com/Unidata/netcdf-fortran/pull/221. + # The following flag forces the compiler to produce module + # files with lowercase names. + flags.append('-ef') elif name == 'ldflags': # We need to specify LDFLAGS to get correct dependency_libs # in libnetcdff.la, so packages that use libtool for linking @@ -129,3 +140,28 @@ def configure_args(self): def check(self): with working_dir(self.build_directory): make('check', parallel=False) + + @run_after('install') + def cray_module_filenames(self): + # Cray compiler searches for module files with uppercase names by + # default and with lowercase names when the '-ef' flag is specified. + # To avoid warning messages when compiler user applications in both + # cases, we create copies of all '*.mod' files in the prefix/include + # with names in upper- and lowercase. + if self.spec.compiler.name != 'cce': + return + + with working_dir(self.spec.prefix.include): + for f in glob.glob('*.mod'): + name, ext = os.path.splitext(f) + try: + # Create a copy with uppercase name: + copyfile(f, name.upper() + ext) + except Error: + # Assume that the exception tells us that the file with + # uppercase name already exists. Try to create a file with + # lowercase name then: + try: + copyfile(f, name.lower() + ext) + except Error: + pass