Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / SCons / Tool / gfortran.py
blobf438b91717c7aff15f3f1e261d51dc59628016eb
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """
25 Tool-specific initialization for gfortran, the GNU Fortran compiler.
27 There normally shouldn't be any need to import this module directly.
28 It will usually be imported through the generic SCons.Tool.Tool()
29 selection method.
30 """
32 from SCons.Util import CLVar
33 from SCons.Tool.FortranCommon import add_all_to_env, add_fortran_to_env
35 compilers = ['gfortran']
38 def generate(env) -> None:
39 """Add Builders and construction variables for gfortran."""
41 add_all_to_env(env)
42 add_fortran_to_env(env)
44 compiler = env.Detect(compilers) or 'gfortran'
46 # fill in other dialects (FORTRAN dialect set by fortran.generate(),
47 # but don't overwrite if they have been set manually.
48 for dialect in ['FORTRAN', 'F77', 'F90', 'F95', 'F03', 'F08']:
49 if dialect not in env:
50 env[f'{dialect}'] = compiler
51 if f'SH{dialect}' not in env:
52 env[f'SH{dialect}'] = f'${dialect}'
54 # The fortran module always sets the shlib FLAGS, but does not
55 # include -fPIC, which is needed for the GNU tools. Rewrite if needed.
56 if env['PLATFORM'] not in ['cygwin', 'win32']:
57 env[f'SH{dialect}FLAGS'] = CLVar(f'${dialect}FLAGS -fPIC')
58 env[f'INC{dialect}PREFIX'] = "-I"
59 env[f'INC{dialect}SUFFIX'] = ""
61 env['FORTRANMODDIRPREFIX'] = "-J"
64 def exists(env):
65 return env.Detect('gfortran')
67 # Local Variables:
68 # tab-width:4
69 # indent-tabs-mode:nil
70 # End:
71 # vim: set expandtab tabstop=4 shiftwidth=4: