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

« back to all changes in this revision

Viewing changes to scons/scons-local/SCons/Tool/mingw.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.gcc
 
2
 
 
3
Tool-specific initialization for MinGW (http://www.mingw.org/)
 
4
 
 
5
There normally shouldn't be any need to import this module directly.
 
6
It will usually be imported through the generic SCons.Tool.Tool()
 
7
selection method.
 
8
 
 
9
"""
 
10
 
 
11
#
 
12
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation
 
13
#
 
14
# Permission is hereby granted, free of charge, to any person obtaining
 
15
# a copy of this software and associated documentation files (the
 
16
# "Software"), to deal in the Software without restriction, including
 
17
# without limitation the rights to use, copy, modify, merge, publish,
 
18
# distribute, sublicense, and/or sell copies of the Software, and to
 
19
# permit persons to whom the Software is furnished to do so, subject to
 
20
# the following conditions:
 
21
#
 
22
# The above copyright notice and this permission notice shall be included
 
23
# in all copies or substantial portions of the Software.
 
24
#
 
25
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
 
26
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 
27
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
28
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
29
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
30
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
31
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
32
#
 
33
 
 
34
__revision__ = "src/engine/SCons/Tool/mingw.py  2013/03/03 09:48:35 garyo"
 
35
 
 
36
import os
 
37
import os.path
 
38
 
 
39
import SCons.Action
 
40
import SCons.Builder
 
41
import SCons.Defaults
 
42
import SCons.Tool
 
43
import SCons.Util
 
44
 
 
45
# This is what we search for to find mingw:
 
46
key_program = 'mingw32-gcc'
 
47
 
 
48
def find(env):
 
49
    # First search in the SCons path
 
50
    path=env.WhereIs(key_program)
 
51
    if (path):
 
52
        return path
 
53
    # then the OS path:
 
54
    path=SCons.Util.WhereIs(key_program)
 
55
    if (path):
 
56
        return path
 
57
 
 
58
    # If that doesn't work try default location for mingw
 
59
    save_path=env['ENV']['PATH']
 
60
    env.AppendENVPath('PATH',r'c:\MinGW\bin')
 
61
    path =env.WhereIs(key_program)
 
62
    if not path:
 
63
        env['ENV']['PATH']=save_path
 
64
    return path
 
65
 
 
66
def shlib_generator(target, source, env, for_signature):
 
67
    cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS']) 
 
68
 
 
69
    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
 
70
    if dll: cmd.extend(['-o', dll])
 
71
 
 
72
    cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
 
73
 
 
74
    implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
 
75
    if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
 
76
 
 
77
    def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
 
78
    insert_def = env.subst("$WINDOWS_INSERT_DEF")
 
79
    if not insert_def in ['', '0', 0] and def_target: \
 
80
        cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
 
81
 
 
82
    return [cmd]
 
83
 
 
84
def shlib_emitter(target, source, env):
 
85
    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
 
86
    no_import_lib = env.get('no_import_lib', 0)
 
87
 
 
88
    if not dll:
 
89
        raise SCons.Errors.UserError("A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX"))
 
90
    
 
91
    if not no_import_lib and \
 
92
       not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
 
93
 
 
94
        # Create list of target libraries as strings
 
95
        targetStrings=env.ReplaceIxes(dll,  
 
96
                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
 
97
                                      'LIBPREFIX', 'LIBSUFFIX')
 
98
        
 
99
        # Now add file nodes to target list
 
100
        target.append(env.fs.File(targetStrings))
 
101
 
 
102
    # Append a def file target if there isn't already a def file target
 
103
    # or a def file source or the user has explicitly asked for the target
 
104
    # to be emitted.
 
105
    def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
 
106
    def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
 
107
    skip_def_insert = env.subst("$WINDOWS_INSERT_DEF") in ['', '0', 0]
 
108
    if not def_source and not def_target and not skip_def_insert:
 
109
        # Create list of target libraries and def files as strings
 
110
        targetStrings=env.ReplaceIxes(dll,  
 
111
                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
 
112
                                      'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
 
113
        
 
114
        # Now add file nodes to target list
 
115
        target.append(env.fs.File(targetStrings))
 
116
 
 
117
    return (target, source)
 
118
                         
 
119
 
 
120
shlib_action = SCons.Action.Action(shlib_generator, generator=1)
 
121
 
 
122
res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
 
123
 
 
124
res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
 
125
                                    source_scanner=SCons.Tool.SourceFileScanner)
 
126
SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
 
127
 
 
128
def generate(env):
 
129
    mingw = find(env)
 
130
    if mingw:
 
131
        dir = os.path.dirname(mingw)
 
132
        env.PrependENVPath('PATH', dir )
 
133
        
 
134
 
 
135
    # Most of mingw is the same as gcc and friends...
 
136
    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'gfortran', 'm4']
 
137
    for tool in gnu_tools:
 
138
        SCons.Tool.Tool(tool)(env)
 
139
 
 
140
    #... but a few things differ:
 
141
    env['CC'] = 'gcc'
 
142
    env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
 
143
    env['CXX'] = 'g++'
 
144
    env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
 
145
    env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
 
146
    env['SHLINKCOM']   = shlib_action
 
147
    env['LDMODULECOM'] = shlib_action
 
148
    env.Append(SHLIBEMITTER = [shlib_emitter])
 
149
    env['AS'] = 'as'
 
150
 
 
151
    env['WIN32DEFPREFIX']        = ''
 
152
    env['WIN32DEFSUFFIX']        = '.def'
 
153
    env['WINDOWSDEFPREFIX']      = '${WIN32DEFPREFIX}'
 
154
    env['WINDOWSDEFSUFFIX']      = '${WIN32DEFSUFFIX}'
 
155
 
 
156
    env['SHOBJSUFFIX'] = '.o'
 
157
    env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
 
158
 
 
159
    env['RC'] = 'windres'
 
160
    env['RCFLAGS'] = SCons.Util.CLVar('')
 
161
    env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
 
162
    env['RCINCPREFIX'] = '--include-dir '
 
163
    env['RCINCSUFFIX'] = ''
 
164
    env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
 
165
    env['BUILDERS']['RES'] = res_builder
 
166
    
 
167
    # Some setting from the platform also have to be overridden:
 
168
    env['OBJSUFFIX'] = '.o'
 
169
    env['LIBPREFIX'] = 'lib'
 
170
    env['LIBSUFFIX'] = '.a'
 
171
    env['PROGSUFFIX'] = '.exe'
 
172
 
 
173
def exists(env):
 
174
    return find(env)
 
175
 
 
176
# Local Variables:
 
177
# tab-width:4
 
178
# indent-tabs-mode:nil
 
179
# End:
 
180
# vim: set expandtab tabstop=4 shiftwidth=4: