summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/fortran.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-08-18 20:39:47 +0300
committerGitHub <noreply@github.com>2018-08-18 20:39:47 +0300
commitd83f77109a7ac22da53acfad8f7ff078d929cd9d (patch)
treeba2dc20e3a91379008d6c7c841a4f503d50b5bd8 /mesonbuild/compilers/fortran.py
parent8277d94e24d4382d49289c07ef20ea78d95443e1 (diff)
downloadmeson-d83f77109a7ac22da53acfad8f7ff078d929cd9d.tar.gz
Convert buildtype to optimization and debug options (#3489)
Diffstat (limited to 'mesonbuild/compilers/fortran.py')
-rw-r--r--mesonbuild/compilers/fortran.py57
1 files changed, 50 insertions, 7 deletions
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index d6e41e3bd..5648a6f46 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -15,12 +15,20 @@
from .c import CCompiler
from .compilers import (
ICC_STANDARD,
+ apple_buildtype_linker_args,
+ gnulike_buildtype_args,
+ gnulike_buildtype_linker_args,
+ gnu_optimization_args,
+ clike_debug_args,
Compiler,
GnuCompiler,
ElbrusCompiler,
IntelCompiler,
)
+from mesonbuild.mesonlib import EnvironmentException, is_osx
+import subprocess, os
+
class FortranCompiler(Compiler):
library_dirs_cache = CCompiler.library_dirs_cache
program_dirs_cache = CCompiler.library_dirs_cache
@@ -61,6 +69,48 @@ class FortranCompiler(Compiler):
def get_soname_args(self, *args):
return CCompiler.get_soname_args(self, *args)
+ def sanity_check(self, work_dir, environment):
+ source_name = os.path.join(work_dir, 'sanitycheckf.f90')
+ binary_name = os.path.join(work_dir, 'sanitycheckf')
+ with open(source_name, 'w') as ofile:
+ ofile.write('''program prog
+ print *, "Fortran compilation is working."
+end program prog
+''')
+ extra_flags = self.get_cross_extra_flags(environment, link=True)
+ pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
+ pc.wait()
+ if pc.returncode != 0:
+ raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
+ if self.is_cross:
+ if self.exe_wrapper is None:
+ # Can't check if the binaries run so we have to assume they do
+ return
+ cmdlist = self.exe_wrapper + [binary_name]
+ else:
+ cmdlist = [binary_name]
+ pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ pe.wait()
+ if pe.returncode != 0:
+ raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string())
+
+ def get_std_warn_args(self, level):
+ return FortranCompiler.std_warn_args
+
+ def get_buildtype_args(self, buildtype):
+ return gnulike_buildtype_args[buildtype]
+
+ def get_optimization_args(self, optimization_level):
+ return gnu_optimization_args[optimization_level]
+
+ def get_debug_args(self, is_debug):
+ return clike_debug_args[is_debug]
+
+ def get_buildtype_linker_args(self, buildtype):
+ if is_osx():
+ return apple_buildtype_linker_args[buildtype]
+ return gnulike_buildtype_linker_args[buildtype]
+
def split_shlib_to_parts(self, fname):
return CCompiler.split_shlib_to_parts(self, fname)
@@ -151,13 +201,6 @@ class FortranCompiler(Compiler):
def gen_import_library_args(self, implibname):
return CCompiler.gen_import_library_args(self, implibname)
- def sanity_check(self, work_dir, environment):
- code = '''program main
- integer :: ret = 0
- call exit(ret)
- end program main'''
- return CCompiler.sanity_check_impl(self, work_dir, environment, 'sanitycheckf.f90', code)
-
def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'):
return CCompiler._get_compiler_check_args(self, env, extra_args, dependencies, mode='compile')