/[ascend]/trunk/scons/crossmingw.py
ViewVC logotype

Annotation of /trunk/scons/crossmingw.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1420 - (hide annotations) (download) (as text)
Wed Apr 25 11:30:47 2007 UTC (15 years, 7 months ago) by jpye
File MIME type: text/x-python
File size: 6475 byte(s)
Some experimenting with crossmingw cross compiling.
Removed shebangs from files that shouldn't have them.
1 jpye 1420 """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/branch.96/baseline/src/engine/SCons/Tool/mingw.py 0.96.90.D001 2005/02/15 20:11:37 knight"
35    
36     import os
37     import os.path
38     import string
39    
40     import SCons.Action
41     import SCons.Builder
42     import SCons.Tool
43     import SCons.Util
44    
45     # This is what we search for to find mingw:
46     prefixes = SCons.Util.Split("""
47     mingw32-
48     mingw32msvc-
49     i386-mingw32-
50     i486-mingw32-
51     i586-mingw32-
52     i686-mingw32-
53     i386-mingw32msvc-
54     i486-mingw32msvc-
55     i586-mingw32msvc-
56     i686-mingw32msvc-
57     """)
58    
59     def find(env):
60     for prefix in prefixes:
61     # First search in the SCons path and then the OS path:
62     if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
63     return prefix
64    
65     return ''
66    
67     def shlib_generator(target, source, env, for_signature):
68     cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
69    
70     dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
71     if dll: cmd.extend(['-o', dll])
72    
73     cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
74    
75     implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
76     if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
77    
78     def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
79     if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
80    
81     return [cmd]
82    
83     def shlib_emitter(target, source, env):
84     dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
85     no_import_lib = env.get('no_import_lib', 0)
86    
87     if not dll:
88     raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
89    
90     if not no_import_lib and \
91     not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
92    
93     # Append an import library to the list of targets.
94     target.append(env.ReplaceIxes(dll,
95     'SHLIBPREFIX', 'SHLIBSUFFIX',
96     'LIBPREFIX', 'LIBSUFFIX'))
97    
98     # Append a def file target if there isn't already a def file target
99     # or a def file source. There is no option to disable def file
100     # target emitting, because I can't figure out why someone would ever
101     # want to turn it off.
102     def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
103     def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
104     if not def_source and not def_target:
105     target.append(env.ReplaceIxes(dll,
106     'SHLIBPREFIX', 'SHLIBSUFFIX',
107     'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
108    
109     return (target, source)
110    
111    
112     shlib_action = SCons.Action.Action(shlib_generator, generator=1)
113    
114     res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
115    
116     res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
117     source_scanner=SCons.Tool.SourceFileScanner)
118     SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
119    
120     def generate(env):
121     mingw_prefix = find(env)
122    
123     if mingw_prefix:
124     dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
125    
126     # The mingw bin directory must be added to the path:
127     path = env['ENV'].get('PATH', [])
128     if not path:
129     path = []
130     if SCons.Util.is_String(path):
131     path = string.split(path, os.pathsep)
132    
133     env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
134    
135     # Most of mingw is the same as gcc and friends...
136     gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
137     for tool in gnu_tools:
138     SCons.Tool.Tool(tool)(env)
139    
140     #... but a few things differ:
141     env['CC'] = mingw_prefix + 'gcc'
142     env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
143     env['CXX'] = mingw_prefix + 'g++'
144     env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
145     env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
146     env['SHLINKCOM'] = shlib_action
147     env.Append(SHLIBEMITTER = [shlib_emitter])
148     env['LINK'] = mingw_prefix + 'g++'
149     env['AS'] = mingw_prefix + 'as'
150     env['WIN32DEFPREFIX'] = ''
151     env['WIN32DEFSUFFIX'] = '.def'
152     env['SHOBJSUFFIX'] = '.o'
153     env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
154    
155     env['RC'] = mingw_prefix + 'windres'
156     env['RCFLAGS'] = SCons.Util.CLVar('')
157     env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
158     env['BUILDERS']['RES'] = res_builder
159    
160     # Some setting from the platform also have to be overridden:
161     env['OBJPREFIX'] = ''
162     env['OBJSUFFIX'] = '.o'
163     env['LIBPREFIX'] = 'lib'
164     env['LIBSUFFIX'] = '.a'
165     env['SHOBJPREFIX'] = '$OBJPREFIX'
166     env['SHOBJSUFFIX'] = '$OBJSUFFIX'
167     env['PROGPREFIX'] = ''
168     env['PROGSUFFIX'] = '.exe'
169     env['LIBPREFIX'] = ''
170     env['LIBSUFFIX'] = '.lib'
171     env['SHLIBPREFIX'] = ''
172     env['SHLIBSUFFIX'] = '.dll'
173     env['LIBPREFIXES'] = [ '$LIBPREFIX' ]
174     env['LIBSUFFIXES'] = [ '$LIBSUFFIX' ]
175    
176     def exists(env):
177     return find(env)
178    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22