~ubuntu-branches/ubuntu/utopic/scons/utopic-proposed

« back to all changes in this revision

Viewing changes to engine/SCons/Tool/mingw.py

  • Committer: Bazaar Package Importer
  • Author(s): Mark Brown
  • Date: 2004-08-24 08:57:22 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040824085722-hfk4f0pjbyu0ebxv
Tags: 0.96.1-1
New upstream release.

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 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__ = "/home/scons/scons/branch.0/baseline/src/engine/SCons/Tool/mingw.py 0.96.1.D001 2004/08/23 09:55:29 knight"
 
35
 
 
36
import os
 
37
import os.path
 
38
import string
 
39
 
 
40
import SCons.Tool
 
41
import SCons.Util
 
42
 
 
43
# This is what we search for to find mingw:
 
44
key_program = 'mingw32-gcc'
 
45
 
 
46
def find(env):
 
47
    # First search in the SCons path and then the OS path:
 
48
    return env.WhereIs(key_program) or SCons.Util.WhereIs(key_program)
 
49
 
 
50
def shlib_generator(target, source, env, for_signature):
 
51
    cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS']) 
 
52
 
 
53
    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
 
54
    if dll: cmd.extend(['-o', dll])
 
55
 
 
56
    cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
 
57
 
 
58
    implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
 
59
    if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
 
60
 
 
61
    def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
 
62
    if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
 
63
 
 
64
    return [cmd]
 
65
 
 
66
def shlib_emitter(target, source, env):
 
67
    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
 
68
    no_import_lib = env.get('no_import_lib', 0)
 
69
 
 
70
    if not dll:
 
71
        raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
 
72
    
 
73
    if not no_import_lib and \
 
74
       not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
 
75
 
 
76
        # Append an import library to the list of targets.
 
77
        target.append(env.ReplaceIxes(dll,  
 
78
                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
 
79
                                      'LIBPREFIX', 'LIBSUFFIX'))
 
80
 
 
81
    # Append a def file target if there isn't already a def file target
 
82
    # or a def file source. There is no option to disable def file
 
83
    # target emitting, because I can't figure out why someone would ever
 
84
    # want to turn it off.
 
85
    def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
 
86
    def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
 
87
    if not def_source and not def_target:
 
88
        target.append(env.ReplaceIxes(dll,  
 
89
                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
 
90
                                      'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
 
91
    
 
92
    return (target, source)
 
93
                         
 
94
 
 
95
shlib_action = SCons.Action.CommandGenerator(shlib_generator)
 
96
 
 
97
res_builder = SCons.Builder.Builder(action='$RCCOM', suffix='.o',
 
98
                                    source_scanner=SCons.Defaults.ObjSourceScan)
 
99
SCons.Defaults.ObjSourceScan.add_scanner('.rc', SCons.Defaults.CScan)
 
100
 
 
101
def generate(env):
 
102
    mingw = find(env)
 
103
    if mingw:
 
104
        dir = os.path.dirname(mingw)
 
105
 
 
106
        # The mingw bin directory must be added to the path:
 
107
        path = env['ENV'].get('PATH', [])
 
108
        if not path: 
 
109
            path = []
 
110
        if SCons.Util.is_String(path):
 
111
            path = string.split(path, os.pathsep)
 
112
 
 
113
        env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
 
114
        
 
115
 
 
116
    # Most of mingw is the same as gcc and friends...
 
117
    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
 
118
    for tool in gnu_tools:
 
119
        SCons.Tool.Tool(tool)(env)
 
120
 
 
121
    #... but a few things differ:
 
122
    env['CC'] = 'gcc'
 
123
    env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
 
124
    env['CXX'] = 'g++'
 
125
    env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
 
126
    env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
 
127
    env['SHLINKCOM']   = shlib_action
 
128
    env.Append(SHLIBEMITTER = [shlib_emitter])
 
129
    env['LINK'] = 'g++'
 
130
    env['AS'] = 'as'
 
131
    env['WIN32DEFPREFIX']        = ''
 
132
    env['WIN32DEFSUFFIX']        = '.def'
 
133
    env['SHOBJSUFFIX'] = '.o'
 
134
    env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
 
135
 
 
136
    env['RC'] = 'windres'
 
137
    env['RCFLAGS'] = SCons.Util.CLVar('')
 
138
    env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs)} $)'
 
139
    env['RCINCPREFIX'] = '--include-dir '
 
140
    env['RCINCSUFFIX'] = ''
 
141
    env['RCCOM'] = '$RC $RCINCFLAGS $RCFLAGS -i $SOURCE -o $TARGET'
 
142
    env['BUILDERS']['RES'] = res_builder
 
143
    
 
144
    # Some setting from the platform also have to be overridden:
 
145
    env['OBJSUFFIX'] = '.o'
 
146
    env['LIBPREFIX'] = 'lib'
 
147
    env['LIBSUFFIX'] = '.a'
 
148
 
 
149
def exists(env):
 
150
    return find(env)