]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import sys, os, string | |
3 | ||
4 | from distutils.msvccompiler import MSVCCompiler | |
5 | ||
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 | |
11 | ||
12 | #---------------------------------------------------------------------- | |
13 | ||
14 | class MyMSVCCompiler(MSVCCompiler): | |
15 | ||
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 | ##------------------------------------------------------------ | |
21 | ||
22 | def compile (self, | |
23 | sources, | |
24 | output_dir=None, | |
25 | macros=None, | |
26 | include_dirs=None, | |
27 | debug=0, | |
28 | extra_preargs=None, | |
29 | extra_postargs=None): | |
30 | ||
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) | |
34 | ||
35 | if extra_postargs is None: | |
36 | extra_postargs = [] | |
37 | ||
38 | pp_opts = gen_preprocess_options (macros, include_dirs) | |
39 | compile_opts = extra_preargs or [] | |
40 | compile_opts.append ('/c') | |
41 | if debug: | |
42 | compile_opts.extend (self.compile_options_debug) | |
43 | else: | |
44 | compile_opts.extend (self.compile_options) | |
45 | ||
46 | for i in range (len (sources)): | |
47 | src = sources[i] ; obj = objects[i] | |
48 | ext = (os.path.splitext (src))[1] | |
49 | ||
50 | if skip_sources[src]: | |
51 | self.announce ("skipping %s (%s up-to-date)" % (src, obj)) | |
52 | else: | |
53 | self.mkpath (os.path.dirname (obj)) | |
54 | ||
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 | |
61 | input_opt = src | |
62 | output_opt = "/fo" + obj | |
63 | try: | |
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 | |
68 | continue | |
69 | elif ext in self._mc_extensions: | |
70 | ||
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 | |
76 | # it includes | |
77 | # | |
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. | |
82 | ||
83 | h_dir = os.path.dirname (src) | |
84 | rc_dir = os.path.dirname (obj) | |
85 | try: | |
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]) | |
94 | ||
95 | except DistutilsExecError, msg: | |
96 | raise CompileError, msg | |
97 | continue | |
98 | else: | |
99 | # how to handle this file? | |
100 | raise CompileError ( | |
101 | "Don't know how to compile %s to %s" % \ | |
102 | (src, obj)) | |
103 | ||
104 | output_opt = "/Fo" + obj | |
105 | try: | |
106 | self.spawn ([self.cc] + compile_opts + pp_opts + | |
107 | [input_opt, output_opt] + | |
108 | extra_postargs) | |
109 | except DistutilsExecError, msg: | |
110 | raise CompileError, msg | |
111 | ||
112 | return objects | |
113 | ||
114 | # compile () | |
115 | ||
116 | ||
117 | ||
118 | ||
119 | ||
120 | #---------------------------------------------------------------------- | |
121 | # Hack this module and class into the distutils... | |
122 | ||
123 | from distutils import ccompiler | |
124 | ||
125 | ccompiler.default_compiler['nt'] = 'my_msvc' | |
126 | ccompiler.compiler_class['my_msvc'] = ('my_distutils', | |
127 | 'MyMSVCCompiler', | |
128 | 'My MSVC derived class') | |
129 | ||
130 | ||
131 | # make it look like it is part of the package... | |
132 | import my_distutils | |
133 | sys.modules['distutils.my_distutils'] = my_distutils | |
134 | ||
135 | ||
136 | ||
137 | ||
138 | #---------------------------------------------------------------------- | |
139 | # Run SWIG the way I want it done | |
140 | ||
141 | def run_swig(files, dir, gendir, package, USE_SWIG, force, swig_args, swig_deps=[]): | |
142 | from distutils.file_util import copy_file | |
143 | from distutils.dep_util import newer | |
144 | from distutils.spawn import spawn | |
145 | ||
146 | sources = [] | |
147 | ||
148 | for file in files: | |
149 | basefile = os.path.splitext(file)[0] | |
150 | i_file = os.path.join(dir, file) | |
151 | py_file = os.path.join(dir, gendir, basefile+'.py') | |
152 | cpp_file = os.path.join(dir, gendir, basefile+'.cpp') | |
153 | ||
154 | sources.append(cpp_file) | |
155 | ||
156 | if USE_SWIG: | |
157 | for dep in swig_deps: | |
158 | if newer(dep, py_file) or newer(dep, cpp_file): | |
159 | force = 1 | |
160 | break | |
161 | ||
162 | if force or newer(i_file, py_file) or newer(i_file, cpp_file): | |
163 | # we need forward slashes here even on win32 | |
164 | cpp_file = string.join(string.split(cpp_file, '\\'), '/') | |
165 | i_file = string.join(string.split(i_file, '\\'), '/') | |
166 | ||
167 | cmd = ['swig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file] | |
168 | spawn(cmd, verbose=1) | |
169 | ||
170 | # copy the generated python file to the package directory | |
171 | copy_file(py_file, package, update=not force, verbose=0) | |
172 | ||
173 | ||
174 | return sources | |
175 | ||
176 | ||
177 | ||
178 | #---------------------------------------------------------------------- | |
179 | # Update local copies of wxWindows contrib files | |
180 | ||
181 | ||
182 | def contrib_copy_tree(src, dest, verbose=0): | |
183 | from distutils.dir_util import mkpath, copy_tree | |
184 | ||
185 | mkpath(dest, verbose=verbose) | |
186 | copy_tree(src, dest, update=1, verbose=verbose) | |
187 |