~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to scons/scons-local/SCons/Tool/FortranCommon.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""SCons.Tool.FortranCommon
 
2
 
 
3
Stuff for processing Fortran, common to all fortran dialects.
 
4
 
 
5
"""
 
6
 
 
7
#
 
8
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation
 
9
#
 
10
# Permission is hereby granted, free of charge, to any person obtaining
 
11
# a copy of this software and associated documentation files (the
 
12
# "Software"), to deal in the Software without restriction, including
 
13
# without limitation the rights to use, copy, modify, merge, publish,
 
14
# distribute, sublicense, and/or sell copies of the Software, and to
 
15
# permit persons to whom the Software is furnished to do so, subject to
 
16
# the following conditions:
 
17
#
 
18
# The above copyright notice and this permission notice shall be included
 
19
# in all copies or substantial portions of the Software.
 
20
#
 
21
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
 
22
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 
23
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
24
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
25
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
26
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
27
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
28
#
 
29
 
 
30
__revision__ = "src/engine/SCons/Tool/FortranCommon.py  2013/03/03 09:48:35 garyo"
 
31
 
 
32
import re
 
33
import os.path
 
34
 
 
35
import SCons.Action
 
36
import SCons.Defaults
 
37
import SCons.Scanner.Fortran
 
38
import SCons.Tool
 
39
import SCons.Util
 
40
 
 
41
def isfortran(env, source):
 
42
    """Return 1 if any of code in source has fortran files in it, 0
 
43
    otherwise."""
 
44
    try:
 
45
        fsuffixes = env['FORTRANSUFFIXES']
 
46
    except KeyError:
 
47
        # If no FORTRANSUFFIXES, no fortran tool, so there is no need to look
 
48
        # for fortran sources.
 
49
        return 0
 
50
 
 
51
    if not source:
 
52
        # Source might be None for unusual cases like SConf.
 
53
        return 0
 
54
    for s in source:
 
55
        if s.sources:
 
56
            ext = os.path.splitext(str(s.sources[0]))[1]
 
57
            if ext in fsuffixes:
 
58
                return 1
 
59
    return 0
 
60
 
 
61
def _fortranEmitter(target, source, env):
 
62
    node = source[0].rfile()
 
63
    if not node.exists() and not node.is_derived():
 
64
       print "Could not locate " + str(node.name)
 
65
       return ([], [])
 
66
    mod_regex = """(?i)^\s*MODULE\s+(?!PROCEDURE)(\w+)"""
 
67
    cre = re.compile(mod_regex,re.M)
 
68
    # Retrieve all USE'd module names
 
69
    modules = cre.findall(node.get_text_contents())
 
70
    # Remove unique items from the list
 
71
    modules = SCons.Util.unique(modules)
 
72
    # Convert module name to a .mod filename
 
73
    suffix = env.subst('$FORTRANMODSUFFIX', target=target, source=source)
 
74
    moddir = env.subst('$FORTRANMODDIR', target=target, source=source)
 
75
    modules = [x.lower() + suffix for x in modules]
 
76
    for m in modules:
 
77
       target.append(env.fs.File(m, moddir))
 
78
    return (target, source)
 
79
 
 
80
def FortranEmitter(target, source, env):
 
81
    target, source = _fortranEmitter(target, source, env)
 
82
    return SCons.Defaults.StaticObjectEmitter(target, source, env)
 
83
 
 
84
def ShFortranEmitter(target, source, env):
 
85
    target, source = _fortranEmitter(target, source, env)
 
86
    return SCons.Defaults.SharedObjectEmitter(target, source, env)
 
87
 
 
88
def ComputeFortranSuffixes(suffixes, ppsuffixes):
 
89
    """suffixes are fortran source files, and ppsuffixes the ones to be
 
90
    pre-processed. Both should be sequences, not strings."""
 
91
    assert len(suffixes) > 0
 
92
    s = suffixes[0]
 
93
    sup = s.upper()
 
94
    upper_suffixes = [_.upper() for _ in suffixes]
 
95
    if SCons.Util.case_sensitive_suffixes(s, sup):
 
96
        ppsuffixes.extend(upper_suffixes)
 
97
    else:
 
98
        suffixes.extend(upper_suffixes)
 
99
 
 
100
def CreateDialectActions(dialect):
 
101
    """Create dialect specific actions."""
 
102
    CompAction = SCons.Action.Action('$%sCOM ' % dialect, '$%sCOMSTR' % dialect)
 
103
    CompPPAction = SCons.Action.Action('$%sPPCOM ' % dialect, '$%sPPCOMSTR' % dialect)
 
104
    ShCompAction = SCons.Action.Action('$SH%sCOM ' % dialect, '$SH%sCOMSTR' % dialect)
 
105
    ShCompPPAction = SCons.Action.Action('$SH%sPPCOM ' % dialect, '$SH%sPPCOMSTR' % dialect)
 
106
 
 
107
    return CompAction, CompPPAction, ShCompAction, ShCompPPAction
 
108
 
 
109
def DialectAddToEnv(env, dialect, suffixes, ppsuffixes, support_module = 0):
 
110
    """Add dialect specific construction variables."""
 
111
    ComputeFortranSuffixes(suffixes, ppsuffixes)
 
112
 
 
113
    fscan = SCons.Scanner.Fortran.FortranScan("%sPATH" % dialect)
 
114
 
 
115
    for suffix in suffixes + ppsuffixes:
 
116
        SCons.Tool.SourceFileScanner.add_scanner(suffix, fscan)
 
117
 
 
118
    env.AppendUnique(FORTRANSUFFIXES = suffixes + ppsuffixes)
 
119
 
 
120
    compaction, compppaction, shcompaction, shcompppaction = \
 
121
            CreateDialectActions(dialect)
 
122
 
 
123
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
 
124
 
 
125
    for suffix in suffixes:
 
126
        static_obj.add_action(suffix, compaction)
 
127
        shared_obj.add_action(suffix, shcompaction)
 
128
        static_obj.add_emitter(suffix, FortranEmitter)
 
129
        shared_obj.add_emitter(suffix, ShFortranEmitter)
 
130
 
 
131
    for suffix in ppsuffixes:
 
132
        static_obj.add_action(suffix, compppaction)
 
133
        shared_obj.add_action(suffix, shcompppaction)
 
134
        static_obj.add_emitter(suffix, FortranEmitter)
 
135
        shared_obj.add_emitter(suffix, ShFortranEmitter)
 
136
 
 
137
    if '%sFLAGS' % dialect not in env:
 
138
        env['%sFLAGS' % dialect] = SCons.Util.CLVar('')
 
139
 
 
140
    if 'SH%sFLAGS' % dialect not in env:
 
141
        env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
 
142
 
 
143
    # If a tool does not define fortran prefix/suffix for include path, use C ones
 
144
    if 'INC%sPREFIX' % dialect not in env:
 
145
        env['INC%sPREFIX' % dialect] = '$INCPREFIX'
 
146
 
 
147
    if 'INC%sSUFFIX' % dialect not in env:
 
148
        env['INC%sSUFFIX' % dialect] = '$INCSUFFIX'
 
149
 
 
150
    env['_%sINCFLAGS' % dialect] = '$( ${_concat(INC%sPREFIX, %sPATH, INC%sSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' % (dialect, dialect, dialect)
 
151
 
 
152
    if support_module == 1:
 
153
        env['%sCOM' % dialect]     = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
 
154
        env['%sPPCOM' % dialect]   = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
 
155
        env['SH%sCOM' % dialect]    = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
 
156
        env['SH%sPPCOM' % dialect]  = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
 
157
    else:
 
158
        env['%sCOM' % dialect]     = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
 
159
        env['%sPPCOM' % dialect]   = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
 
160
        env['SH%sCOM' % dialect]    = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
 
161
        env['SH%sPPCOM' % dialect]  = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
 
162
 
 
163
def add_fortran_to_env(env):
 
164
    """Add Builders and construction variables for Fortran to an Environment."""
 
165
    try:
 
166
        FortranSuffixes = env['FORTRANFILESUFFIXES']
 
167
    except KeyError:
 
168
        FortranSuffixes = ['.f', '.for', '.ftn']
 
169
 
 
170
    #print "Adding %s to fortran suffixes" % FortranSuffixes
 
171
    try:
 
172
        FortranPPSuffixes = env['FORTRANPPFILESUFFIXES']
 
173
    except KeyError:
 
174
        FortranPPSuffixes = ['.fpp', '.FPP']
 
175
 
 
176
    DialectAddToEnv(env, "FORTRAN", FortranSuffixes,
 
177
                    FortranPPSuffixes, support_module = 1)
 
178
 
 
179
    env['FORTRANMODPREFIX'] = ''     # like $LIBPREFIX
 
180
    env['FORTRANMODSUFFIX'] = '.mod' # like $LIBSUFFIX
 
181
 
 
182
    env['FORTRANMODDIR'] = ''          # where the compiler should place .mod files
 
183
    env['FORTRANMODDIRPREFIX'] = ''    # some prefix to $FORTRANMODDIR - similar to $INCPREFIX
 
184
    env['FORTRANMODDIRSUFFIX'] = ''    # some suffix to $FORTRANMODDIR - similar to $INCSUFFIX
 
185
    env['_FORTRANMODFLAG'] = '$( ${_concat(FORTRANMODDIRPREFIX, FORTRANMODDIR, FORTRANMODDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
 
186
 
 
187
def add_f77_to_env(env):
 
188
    """Add Builders and construction variables for f77 to an Environment."""
 
189
    try:
 
190
        F77Suffixes = env['F77FILESUFFIXES']
 
191
    except KeyError:
 
192
        F77Suffixes = ['.f77']
 
193
 
 
194
    #print "Adding %s to f77 suffixes" % F77Suffixes
 
195
    try:
 
196
        F77PPSuffixes = env['F77PPFILESUFFIXES']
 
197
    except KeyError:
 
198
        F77PPSuffixes = []
 
199
 
 
200
    DialectAddToEnv(env, "F77", F77Suffixes, F77PPSuffixes)
 
201
 
 
202
def add_f90_to_env(env):
 
203
    """Add Builders and construction variables for f90 to an Environment."""
 
204
    try:
 
205
        F90Suffixes = env['F90FILESUFFIXES']
 
206
    except KeyError:
 
207
        F90Suffixes = ['.f90']
 
208
 
 
209
    #print "Adding %s to f90 suffixes" % F90Suffixes
 
210
    try:
 
211
        F90PPSuffixes = env['F90PPFILESUFFIXES']
 
212
    except KeyError:
 
213
        F90PPSuffixes = []
 
214
 
 
215
    DialectAddToEnv(env, "F90", F90Suffixes, F90PPSuffixes,
 
216
                    support_module = 1)
 
217
 
 
218
def add_f95_to_env(env):
 
219
    """Add Builders and construction variables for f95 to an Environment."""
 
220
    try:
 
221
        F95Suffixes = env['F95FILESUFFIXES']
 
222
    except KeyError:
 
223
        F95Suffixes = ['.f95']
 
224
 
 
225
    #print "Adding %s to f95 suffixes" % F95Suffixes
 
226
    try:
 
227
        F95PPSuffixes = env['F95PPFILESUFFIXES']
 
228
    except KeyError:
 
229
        F95PPSuffixes = []
 
230
 
 
231
    DialectAddToEnv(env, "F95", F95Suffixes, F95PPSuffixes,
 
232
                    support_module = 1)
 
233
 
 
234
def add_f03_to_env(env):
 
235
    """Add Builders and construction variables for f03 to an Environment."""
 
236
    try:
 
237
        F03Suffixes = env['F03FILESUFFIXES']
 
238
    except KeyError:
 
239
        F03Suffixes = ['.f03']
 
240
 
 
241
    #print "Adding %s to f95 suffixes" % F95Suffixes
 
242
    try:
 
243
        F03PPSuffixes = env['F03PPFILESUFFIXES']
 
244
    except KeyError:
 
245
        F03PPSuffixes = []
 
246
 
 
247
    DialectAddToEnv(env, "F03", F03Suffixes, F03PPSuffixes,
 
248
                    support_module = 1)
 
249
 
 
250
def add_all_to_env(env):
 
251
    """Add builders and construction variables for all supported fortran
 
252
    dialects."""
 
253
    add_fortran_to_env(env)
 
254
    add_f77_to_env(env)
 
255
    add_f90_to_env(env)
 
256
    add_f95_to_env(env)
 
257
    add_f03_to_env(env)
 
258
 
 
259
# Local Variables:
 
260
# tab-width:4
 
261
# indent-tabs-mode:nil
 
262
# End:
 
263
# vim: set expandtab tabstop=4 shiftwidth=4: