From 0e86258748b712a9074ebd67e2bf98fe7748c73f Mon Sep 17 00:00:00 2001 From: Mat Cross Date: Fri, 20 Aug 2021 11:55:18 +0100 Subject: [PATCH] Implemented some missing operation for the NAG Fortran Compiler. --- mesonbuild/compilers/detect.py | 12 +++++++++--- mesonbuild/compilers/fortran.py | 20 ++++++++++++++++++-- mesonbuild/linkers/__init__.py | 2 ++ mesonbuild/linkers/linkers.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index cd0f25295..de1845a35 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -34,6 +34,7 @@ from ..linkers import ( C2000Linker, C2000DynamicLinker, DLinker, + NAGDynamicLinker, NvidiaHPC_DynamicLinker, PGIDynamicLinker, PGIStaticLinker, @@ -774,9 +775,14 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C exe_wrap, full_version=full_version, linker=linker) if 'NAG Fortran' in err: - linker = guess_nix_linker(env, - compiler, NAGFortranCompiler, for_machine) - return NAGFortranCompiler( + full_version = err.split('\n', 1)[0] + version = full_version.split()[-1] + cls = NAGFortranCompiler + env.coredata.add_lang_args(cls.language, cls, for_machine, env) + linker = NAGDynamicLinker( + compiler, for_machine, cls.LINKER_PREFIX, [], + version=version) + return cls( compiler, version, for_machine, is_cross, info, exe_wrap, full_version=full_version, linker=linker) diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 00b030841..1a430a7ae 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -494,12 +494,28 @@ class NAGFortranCompiler(FortranCompiler): is_cross, info, exe_wrapper, linker=linker, full_version=full_version) self.id = 'nagfor' + self.warn_args = { + '0': ['-w=all'], + '1': [], + '2': [], + '3': [], + } - def get_warn_args(self, level: str) -> T.List[str]: - return [] + def get_always_args(self) -> T.List[str]: + return self.get_nagfor_quiet(self.version) def get_module_outdir_args(self, path: str) -> T.List[str]: return ['-mdir', path] + @staticmethod + def get_nagfor_quiet(version: str) -> T.List[str]: + return ['-quiet'] if version_compare(version, '>=7100') else [] + + def get_pic_args(self) -> T.List[str]: + return ['-PIC'] + + def get_std_exe_link_args(self) -> T.List[str]: + return self.get_always_args() + def openmp_flags(self) -> T.List[str]: return ['-openmp'] diff --git a/mesonbuild/linkers/__init__.py b/mesonbuild/linkers/__init__.py index 9182fa1a8..2e5217e2b 100644 --- a/mesonbuild/linkers/__init__.py +++ b/mesonbuild/linkers/__init__.py @@ -53,6 +53,7 @@ from .linkers import ( QualcommLLVMDynamicLinker, PGIDynamicLinker, NvidiaHPC_DynamicLinker, + NAGDynamicLinker, VisualStudioLikeLinkerMixin, MSVCDynamicLinker, @@ -110,6 +111,7 @@ __all__ = [ 'QualcommLLVMDynamicLinker', 'PGIDynamicLinker', 'NvidiaHPC_DynamicLinker', + 'NAGDynamicLinker', 'VisualStudioLikeLinkerMixin', 'MSVCDynamicLinker', diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index e84d0a474..58e432400 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -1045,6 +1045,36 @@ class QualcommLLVMDynamicLinker(LLVMDynamicLinker): id = 'ld.qcld' +class NAGDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker): + + """NAG Fortran linker, ld via gcc indirection.""" + + id = 'nag' + + def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str, + rpath_paths: str, build_rpath: str, + install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]: + if not rpath_paths and not install_rpath and not build_rpath: + return ([], set()) + args = [] + origin_placeholder = '$ORIGIN' + processed_rpaths = prepare_rpaths(rpath_paths, build_dir, from_dir) + all_paths = mesonlib.OrderedSet([os.path.join(origin_placeholder, p) for p in processed_rpaths]) + if build_rpath != '': + all_paths.add(build_rpath) + for rp in all_paths: + args.extend(self._apply_prefix('-Wl,-Wl,,-rpath,,' + rp)) + + return (args, set()) + + def get_allow_undefined_args(self) -> T.List[str]: + return [] + + def get_std_shared_lib_args(self) -> T.List[str]: + from ..compilers import NAGFortranCompiler + return NAGFortranCompiler.get_nagfor_quiet(self.version) + ['-Wl,-shared'] + + class PGIDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker): """PGI linker."""