]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/my_distutils.py
4 from distutils
.msvccompiler
import MSVCCompiler
6 from distutils
.errors
import \
7 DistutilsExecError
, DistutilsPlatformError
, \
8 CompileError
, LibError
, LinkError
9 from distutils
.ccompiler
import \
10 CCompiler
, gen_preprocess_options
, gen_lib_options
12 #----------------------------------------------------------------------
14 class MyMSVCCompiler(MSVCCompiler
):
16 ##------------------------------------------------------------
17 ## Override the entire compile method just to add flags to the
18 ## RC command. There should be an easier way to do this from
19 ## distutils directly or in a derived class...
20 ##------------------------------------------------------------
31 (output_dir
, macros
, include_dirs
) = \
32 self
._fix
_compile
_args
(output_dir
, macros
, include_dirs
)
33 (objects
, skip_sources
) = self
._prep
_compile
(sources
, output_dir
)
35 if extra_postargs
is None:
38 pp_opts
= gen_preprocess_options (macros
, include_dirs
)
39 compile_opts
= extra_preargs
or []
40 compile_opts
.append ('/c')
42 compile_opts
.extend (self
.compile_options_debug
)
44 compile_opts
.extend (self
.compile_options
)
46 for i
in range (len (sources
)):
47 src
= sources
[i
] ; obj
= objects
[i
]
48 ext
= (os
.path
.splitext (src
))[1]
51 self
.announce ("skipping %s (%s up-to-date)" % (src
, obj
))
53 self
.mkpath (os
.path
.dirname (obj
))
55 if ext
in self
._c
_extensions
:
56 input_opt
= "/Tc" + os
.path
.abspath(src
)
57 elif ext
in self
._cpp
_extensions
:
58 input_opt
= "/Tp" + os
.path
.abspath(src
)
59 elif ext
in self
._rc
_extensions
:
60 # compile .RC to .RES file
62 output_opt
= "/fo" + obj
64 self
.spawn ([self
.rc
] + pp_opts
+ ### RPD changed this line only
65 [output_opt
] + [input_opt
])
66 except DistutilsExecError
, msg
:
67 raise CompileError
, msg
69 elif ext
in self
._mc
_extensions
:
71 # Compile .MC to .RC file to .RES file.
72 # * '-h dir' specifies the directory for the
73 # generated include file
74 # * '-r dir' specifies the target directory of the
75 # generated RC file and the binary message resource
78 # For now (since there are no options to change this),
79 # we use the source-directory for the include file and
80 # the build directory for the RC file and message
81 # resources. This works at least for win32all.
83 h_dir
= os
.path
.dirname (src
)
84 rc_dir
= os
.path
.dirname (obj
)
86 # first compile .MC to .RC and .H file
87 self
.spawn ([self
.mc
] +
88 ['-h', h_dir
, '-r', rc_dir
] + [src
])
89 base
, _
= os
.path
.splitext (os
.path
.basename (src
))
90 rc_file
= os
.path
.join (rc_dir
, base
+ '.rc')
91 # then compile .RC to .RES file
92 self
.spawn ([self
.rc
] +
93 ["/fo" + obj
] + [rc_file
])
95 except DistutilsExecError
, msg
:
96 raise CompileError
, msg
99 # how to handle this file?
101 "Don't know how to compile %s to %s" % \
104 output_opt
= "/Fo" + obj
106 self
.spawn ([self
.cc
] + compile_opts
+ pp_opts
+
107 [input_opt
, output_opt
] +
109 except DistutilsExecError
, msg
:
110 raise CompileError
, msg
118 ##------------------------------------------------------------
119 ## Now override the link() method to change where the import
120 ## library is placed. Hopefully distutils will be updated
121 ## someday to make this configurable...
122 ##------------------------------------------------------------
131 runtime_library_dirs
=None,
138 (objects
, output_dir
) = self
._fix
_object
_args
(objects
, output_dir
)
139 (libraries
, library_dirs
, runtime_library_dirs
) = \
140 self
._fix
_lib
_args
(libraries
, library_dirs
, runtime_library_dirs
)
142 if runtime_library_dirs
:
143 self
.warn ("I don't know what to do with 'runtime_library_dirs': "
144 + str (runtime_library_dirs
))
146 lib_opts
= gen_lib_options (self
,
147 library_dirs
, runtime_library_dirs
,
149 if output_dir
is not None:
150 output_filename
= os
.path
.join (output_dir
, output_filename
)
152 if self
._need
_link
(objects
, output_filename
):
154 if target_desc
== CCompiler
.EXECUTABLE
:
156 ldflags
= self
.ldflags_shared_debug
[1:]
158 ldflags
= self
.ldflags_shared
[1:]
161 ldflags
= self
.ldflags_shared_debug
163 ldflags
= self
.ldflags_shared
166 for sym
in (export_symbols
or []):
167 export_opts
.append("/EXPORT:" + sym
)
169 ld_args
= (ldflags
+ lib_opts
+ export_opts
+
170 objects
+ ['/OUT:' + output_filename
])
172 # The MSVC linker generates .lib and .exp files, which cannot be
173 # suppressed by any linker switches. The .lib files may even be
174 # needed! Make sure they are generated in the temporary build
175 # directory. Since they have different names for debug and release
176 # builds, they can go into the same directory.
177 if export_symbols
is not None:
178 (dll_name
, dll_ext
) = os
.path
.splitext(
179 os
.path
.basename(output_filename
))
182 ##implib_file = os.path.join(
183 ## os.path.dirname(objects[0]),
184 ## self.library_filename(dll_name))
187 implib_file
= os
.path
.join('build', 'ilib',
188 self
.library_filename(dll_name
))
189 self
.mkpath(os
.path
.dirname(implib_file
))
191 ld_args
.append ('/IMPLIB:' + implib_file
)
194 ld_args
[:0] = extra_preargs
196 ld_args
.extend(extra_postargs
)
198 self
.mkpath (os
.path
.dirname (output_filename
))
200 self
.spawn ([self
.linker
] + ld_args
)
201 except DistutilsExecError
, msg
:
205 self
.announce ("skipping %s (up-to-date)" % output_filename
)
211 #----------------------------------------------------------------------
212 # Hack this module and class into the distutils...
214 from distutils
import ccompiler
216 ccompiler
.default_compiler
['nt'] = 'my_msvc'
217 ccompiler
.compiler_class
['my_msvc'] = ('my_distutils',
219 'My MSVC derived class')
222 # make it look like it is part of the package...
224 sys
.modules
['distutils.my_distutils'] = my_distutils
229 #----------------------------------------------------------------------
230 # Run SWIG the way I want it done
232 def run_swig(files
, dir, gendir
, package
, USE_SWIG
, force
, swig_args
, swig_deps
=[]):
233 from distutils
.file_util
import copy_file
234 from distutils
.dep_util
import newer
235 from distutils
.spawn
import spawn
240 basefile
= os
.path
.splitext(file)[0]
241 i_file
= os
.path
.join(dir, file)
242 py_file
= os
.path
.join(dir, gendir
, basefile
+'.py')
243 cpp_file
= os
.path
.join(dir, gendir
, basefile
+'.cpp')
245 sources
.append(cpp_file
)
248 for dep
in swig_deps
:
249 if newer(dep
, py_file
) or newer(dep
, cpp_file
):
253 if force
or newer(i_file
, py_file
) or newer(i_file
, cpp_file
):
254 # we need forward slashes here even on win32
255 cpp_file
= string
.join(string
.split(cpp_file
, '\\'), '/')
256 i_file
= string
.join(string
.split(i_file
, '\\'), '/')
258 cmd
= ['swig'] + swig_args
+ ['-I'+dir, '-c', '-o', cpp_file
, i_file
]
259 spawn(cmd
, verbose
=1)
261 # copy the generated python file to the package directory
262 copy_file(py_file
, package
, update
=not force
, verbose
=0)
269 #----------------------------------------------------------------------
270 # Update local copies of wxWindows contrib files
273 def contrib_copy_tree(src
, dest
, verbose
=0):
274 from distutils
.dir_util
import mkpath
, copy_tree
276 mkpath(dest
, verbose
=verbose
)
277 copy_tree(src
, dest
, update
=1, verbose
=verbose
)