]>
Commit | Line | Data |
---|---|---|
5c3a94a6 RD |
1 | #!/usr/bin/env python |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: build.py | |
4 | # Purpose: This script is used to build wxPython. It reads a build | |
5 | # configuration file in the requested project directory and | |
6 | # based on the contents of the file can build Makefiles for | |
7 | # unix or win32, and can execute make with various options | |
8 | # potentially automating the entire build/install/clean process | |
9 | # from a single command. | |
10 | # | |
11 | # Author: Robin Dunn | |
12 | # | |
13 | # Created: 18-Aug-1999 | |
14 | # RCS-ID: $Id$ | |
15 | # Copyright: (c) 1999 by Total Control Software | |
16 | # Licence: wxWindows license | |
17 | #---------------------------------------------------------------------------- | |
18 | """ | |
19 | build.py | |
20 | ||
21 | This script is used to build wxPython. It reads a build configuration | |
22 | file in the requested project directory and based on the contents of | |
23 | the file can build Makefiles for unix or win32, and can execute make | |
24 | with various options potentially automating the entire | |
25 | build/install/clean process from a single command. | |
26 | ||
27 | The default action is to build the Makefile and exit. | |
28 | ||
29 | Options | |
30 | -C dir CD to dir before doing anything | |
31 | -B file Use file as the build configuration (default ./build.cfg) | |
32 | -M file Use file as the name of the makefile to create | |
33 | (default Makefile) | |
34 | ||
35 | -b Build the module (runs make) | |
36 | -i Install the module (runs make install) | |
37 | -c Cleanup (runs make clean) | |
38 | -u Uninstall (runs make uninstall) | |
39 | ||
40 | -h Show help and exit | |
41 | ||
42 | ||
43 | Configuration Files | |
44 | ||
45 | The build configuration file lists targets, source files and options | |
46 | for the the build process. The contents of the build.cfg are used to | |
47 | dynamically generate the Makefile. | |
48 | ||
49 | To prevent you from getting screwed when the default build.cfg is | |
50 | updated, you can override the values in build.cfg by putting your | |
51 | custom definitions in a file named build.local. You can also place a | |
52 | build.local file in the parent directory, or even in the grandparent | |
53 | directory for project-wide overrides. Finally, command-line arguments | |
54 | of the form NAME=VALUE can also be used to override simple configuration | |
55 | values. The order of evaluation is: | |
56 | ||
57 | 0. comman-line flags (-M, -b, etc.) | |
58 | 1. ./build.cfg | |
59 | 2. ../../build.local (if present) | |
60 | 3. ../build.local (if present) | |
61 | 4. ./build.local (if present) | |
62 | 5. command-line NAME=VALUEs | |
63 | ||
64 | The config files are actually just Python files that get exec'ed in a | |
65 | separate namespace which is then used later as a configuration object. | |
66 | This keeps the build script simple in that it doesn't have to parse | |
67 | anything, and the config files can be much more than just names and | |
68 | values as pretty much any python code can be executed. The global | |
69 | variables set in the config namespace are what are used later as | |
70 | configuation values. | |
71 | ||
72 | ||
73 | Configuration Options | |
74 | ||
75 | The following variables can be set in the config files. Only a few are | |
76 | required, the rest will either have suitable defaults or will be | |
77 | calculated from your current Python runtime environment. | |
78 | ||
79 | MODULE The name of the extension module to produce | |
80 | SWIGFILES A list of files that should be run through SWIG | |
81 | SWIGFLAGS Flags for SWIG | |
82 | SOURCES Other C/C++ sources that should be part of the module | |
83 | PYFILES Other Python files that should be installed with the module | |
84 | CFLAGS Flags to be used by the compiler | |
85 | LFLAGS Flags to be used at the link step | |
86 | LIBS Libraries to be linked with | |
87 | ||
88 | OTHERCFLAGS Extra flags to append to CFLAGS | |
89 | OTHERLFLAGS Extra flags to append to LFLAGS | |
90 | OTHERSWIGFLAGS Extra flags to append to SWIGFLAGS | |
91 | OTHERLIBS Other libraries to be linked with, in addition to LIBS | |
92 | OTHERTARGETS Other targets to be placed on the default rule line | |
93 | OTHERINSTALLTARGETS | |
94 | Other targets to be placed on the install rule line | |
f6bcfd97 | 95 | OTHERDEFS Text to place near the begining of the Makefile |
5c3a94a6 RD |
96 | OTHERRULES This text is placed at the end of the makefile and |
97 | will typically be used for adding rules and such | |
98 | DEFAULTRULE Text to be used for the default rule in the makefile | |
99 | ||
100 | TARGETDIR Destination for the install step | |
101 | ||
102 | MAKE The make program to use | |
103 | MAKEFILE The name of the makefile | |
104 | ||
105 | runBuild Setting this to 1 is eqivalent to the -b flag | |
106 | runInstall Setting this to 1 is eqivalent to the -i flag | |
107 | runClean Setting this to 1 is eqivalent to the -c flag | |
108 | runUninstall Setting this to 1 is eqivalent to the -u flag | |
109 | ||
110 | PYVERSION Version number of Python used in pathnames | |
111 | PYPREFIX The root of the Python install | |
112 | EXECPREFIX The root of the Python install for binary files | |
113 | PYTHONLIB The Python link library | |
114 | ||
115 | """ | |
116 | ||
117 | import sys, os, string, getopt | |
118 | ||
119 | #---------------------------------------------------------------------------- | |
120 | # This is really the wxPython version number, and will be placed in the | |
121 | # Makefiles for use with the distribution related targets. | |
122 | ||
3ca6a5f0 BP |
123 | major_version = '2.2' |
124 | build_version = '0' | |
f6bcfd97 BP |
125 | |
126 | __version__ = major_version + '.' + build_version | |
5c3a94a6 RD |
127 | |
128 | #---------------------------------------------------------------------------- | |
129 | ||
130 | def main(args): | |
131 | try: | |
132 | opts, args = getopt.getopt(args[1:], 'C:B:M:bicu') | |
133 | except getopt.error: | |
134 | usage() | |
135 | sys.exit(1) | |
136 | ||
137 | if not os.environ.has_key('WXWIN'): | |
138 | print "WARNING: WXWIN is not set in the environment. WXDIR may not\n"\ | |
139 | " be set properly in the makefile, you will have to \n"\ | |
140 | " set the environment variable or override in build.local." | |
141 | ||
142 | bldCfg = 'build.cfg' | |
143 | bldCfgLocal = 'build.local' | |
144 | MAKEFILE = 'Makefile' | |
145 | runBuild = 0 | |
146 | runInstall = 0 | |
147 | runClean = 0 | |
148 | runUninstall = 0 | |
149 | ||
150 | for flag, value in opts: | |
151 | if flag == '-C': os.chdir(value) | |
152 | elif flag == '-B': bldCfgFile = value | |
153 | elif flag == '-M': makefile = value | |
154 | elif flag == '-b': runBuild = 1 | |
155 | elif flag == '-c': runClean = 1 | |
156 | elif flag == '-i': runInstall = 1 | |
157 | elif flag == '-u': runUninstall = 1 | |
158 | ||
159 | elif flag == '-h': usage(); sys.exit(1) | |
160 | else: usage(); sys.exit(1) | |
161 | ||
162 | config = BuildConfig(bldCfg = bldCfg, | |
163 | bldCfgLocal = bldCfgLocal, | |
164 | MAKEFILE = MAKEFILE, | |
165 | runBuild = runBuild, | |
166 | runInstall = runInstall, | |
167 | runClean = runClean, | |
168 | runUninstall = runUninstall) | |
169 | ||
2f90df85 | 170 | err = 0 |
5c3a94a6 RD |
171 | if config.readConfigFiles(args): |
172 | config.doFixups() | |
173 | config.makeMakefile() | |
5c3a94a6 RD |
174 | |
175 | if config.runBuild: | |
176 | cmd = "%s -f %s" % (config.MAKE, config.MAKEFILE) | |
177 | print "Running:", cmd | |
178 | err = os.system(cmd) | |
179 | ||
180 | if not err and config.runInstall: | |
181 | cmd = "%s -f %s install" % (config.MAKE, config.MAKEFILE) | |
182 | print "Running:", cmd | |
183 | err = os.system(cmd) | |
184 | ||
185 | ||
186 | if not err and config.runClean: | |
187 | cmd = "%s -f %s clean" % (config.MAKE, config.MAKEFILE) | |
188 | print "Running:", cmd | |
189 | err = os.system(cmd) | |
190 | ||
191 | if not err and config.runUninstall: | |
192 | cmd = "%s -f %s uninstall" % (config.MAKE, config.MAKEFILE) | |
193 | print "Running:", cmd | |
194 | err = os.system(cmd) | |
195 | ||
6f82295e | 196 | return err/256 |
5c3a94a6 RD |
197 | |
198 | ||
199 | #---------------------------------------------------------------------------- | |
200 | ||
201 | def usage(): | |
202 | print __doc__ | |
203 | ||
204 | #---------------------------------------------------------------------------- | |
205 | ||
206 | def swapslash(st): | |
207 | if sys.platform != 'win32': | |
208 | st = string.join(string.split(st, '\\'), '/') | |
209 | return st | |
210 | ||
211 | #---------------------------------------------------------------------------- | |
212 | ||
213 | def splitlines(st): | |
214 | return string.join(string.split(string.strip(st), ' '), ' \\\n\t') | |
215 | ||
216 | #---------------------------------------------------------------------------- | |
217 | ||
218 | class BuildConfig: | |
219 | def __init__(self, **kw): | |
220 | self.__dict__.update(kw) | |
221 | self.setDefaults() | |
222 | ||
223 | #------------------------------------------------------------ | |
224 | def setDefaults(self): | |
f6bcfd97 BP |
225 | base = os.path.split(sys.argv[0])[0] |
226 | base = os.path.join(base, '..') | |
227 | self.WXPYDIR = os.path.abspath(base) | |
5c3a94a6 | 228 | self.VERSION = __version__ |
f6bcfd97 BP |
229 | self.MAJVER = major_version |
230 | self.BLDVER = build_version | |
5c3a94a6 RD |
231 | self.MODULE = '' |
232 | self.SWIGFILES = [] | |
efc5f224 | 233 | self.SWIGFLAGS = '-c++ -shadow -python -keyword -dnone -I$(WXPSRCDIR)' |
5c3a94a6 RD |
234 | self.SOURCES = [] |
235 | self.PYFILES = [] | |
236 | self.LFLAGS = '' | |
237 | self.OTHERCFLAGS = '' | |
238 | self.OTHERLFLAGS = '' | |
239 | self.OTHERSWIGFLAGS = '' | |
240 | self.OTHERLIBS = '' | |
241 | self.OTHERTARGETS = '' | |
242 | self.OTHERINSTALLTARGETS = '' | |
efc5f224 | 243 | self.OTHERUNINSTALLTARGETS = '' |
5c3a94a6 | 244 | self.OTHERRULES = '' |
f6bcfd97 | 245 | self.DEFAULTRULE = 'default: $(GENCODEDIR) $(TARGET) $(BUILDDIR)/$(TARGET) bldpycfiles' |
5c3a94a6 RD |
246 | self.PYVERSION = sys.version[:3] |
247 | self.PYPREFIX = sys.prefix | |
248 | self.EXECPREFIX = sys.exec_prefix | |
249 | self.WXDIR = '$(WXWIN)' | |
250 | self.FINAL = '0' | |
251 | self.WXP_USE_THREAD = '1' | |
252 | self.WXUSINGDLL = '1' | |
253 | self.OTHERDEP = '' | |
f6bcfd97 | 254 | self.WXPSRCDIR = '$(WXPYDIR)/src' |
922dc976 RD |
255 | self.SWIGDEPS = '' |
256 | self.OTHERDEPS = '' | |
f6bcfd97 | 257 | self.OTHERDEFS = '' |
5c3a94a6 RD |
258 | |
259 | ||
260 | if sys.platform == 'win32': | |
261 | self.MAKE = 'nmake' | |
262 | self.PYTHONLIB = '$(PYPREFIX)\\libs\\python15.lib' | |
263 | self.TARGETDIR = '$(PYPREFIX)\\wxPython' | |
264 | self.LIBS = '$(PYTHONLIB) $(WXPSRCDIR)\wxc.lib' | |
265 | self.GENCODEDIR = 'msw' | |
266 | self.SWIGTOOLKITFLAG = '-D__WXMSW__' | |
267 | self.OBJEXT = '.obj' | |
268 | self.TARGET = '$(MODULE).pyd' | |
269 | self.CFLAGS = '-I$(PYPREFIX)\include -I$(WXPSRCDIR) -I. /Fp$(MODULE).pch /YXhelpers.h -DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) ' | |
270 | self.LFLAGS = '$(DEBUGLFLAGS) /DLL /subsystem:windows,3.50 /machine:I386 /nologo' | |
271 | self.RESFILE = '' | |
272 | self.RESRULE = '' | |
273 | self.OVERRIDEFLAGS = '/GX-' | |
b164fb38 RD |
274 | self.RMCMD = '-erase ' |
275 | self.WXPSRCDIR = os.path.normpath(self.WXPSRCDIR) | |
f0261a72 | 276 | self.CRTFLAG = '' |
b164fb38 | 277 | |
5c3a94a6 RD |
278 | |
279 | else: | |
280 | self.MAKE = 'make' | |
281 | self.PYLIB = '$(EXECPREFIX)/lib/python$(PYVERSION)' | |
282 | self.LIBPL = '$(PYLIB)/config' | |
283 | self.PYTHONLIB = '$(LIBPL)/libpython$(PYVERSION).a' | |
284 | self.TARGETDIR = '$(EXECPREFIX)/lib/python$(PYVERSION)/site-packages/wxPython' | |
285 | self.TARGET = '$(MODULE)module$(SO)' | |
286 | self.OBJEXT = '.o' | |
287 | self.HELPERLIB = 'wxPyHelpers' | |
f6bcfd97 | 288 | self.HELPERLIBDIR = '$(EXECPREFIX)/lib' |
5c3a94a6 | 289 | self.CFLAGS = '-DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) -I. '\ |
266839ee | 290 | '`$(WXCONFIG) --cflags` -I$(PYINCLUDE) -I$(EXECINCLUDE) '\ |
5c3a94a6 | 291 | '-I$(WXPSRCDIR)' |
266839ee | 292 | self.LFLAGS = '-L$(WXPSRCDIR) `$(WXCONFIG) --libs`' |
b164fb38 | 293 | self.RMCMD = '-rm -f ' |
352f281a | 294 | self.WXCONFIG = 'wx-config' |
f6bcfd97 | 295 | self.USE_SONAME = '1' |
5c3a94a6 RD |
296 | |
297 | # **** What to do when I start supporting Motif, etc.??? | |
298 | self.GENCODEDIR = 'gtk' | |
299 | self.SWIGTOOLKITFLAG = '-D__WXGTK__' | |
300 | ||
301 | # Extract a few things from Python's Makefile... | |
302 | try: | |
303 | filename = os.path.join(self.EXECPREFIX, | |
304 | 'lib/python'+self.PYVERSION, | |
305 | 'config/Makefile') | |
306 | mfText = string.split(open(filename, 'r').read(), '\n') | |
307 | except IOError: | |
308 | raise SystemExit, "Python development files not found" | |
309 | ||
310 | self.CCC = self.findMFValue(mfText, 'CCC') | |
311 | self.CC = self.findMFValue(mfText, 'CC') | |
312 | self.OPT = self.findMFValue(mfText, 'OPT') | |
313 | self.SO = self.findMFValue(mfText, 'SO') | |
314 | self.LDSHARED = self.findMFValue(mfText, 'LDSHARED') | |
315 | self.CCSHARED = self.findMFValue(mfText, 'CCSHARED') | |
316 | #self.LINKFORSHARED = self.findMFValue(mfText, 'LINKFORSHARED') | |
317 | #self. = self.findMFValue(mfText, '') | |
318 | #self. = self.findMFValue(mfText, '') | |
319 | ||
320 | ||
321 | # The majority of cases will require LDSHARED to be | |
322 | # modified to use the C++ driver instead of the C driver | |
323 | # for linking. We'll try to do it here and if we goof up | |
324 | # then the user can correct it in their build.local file. | |
325 | self.LDSHARED = string.join(['$(CCC)'] + | |
326 | string.split(self.LDSHARED, ' ')[1:], | |
327 | ' ') | |
328 | ||
329 | ||
330 | #------------------------------------------------------------ | |
331 | def doFixups(self): | |
332 | # This is called after the config files have been evaluated | |
333 | # so we can do some sanity checking... | |
334 | if sys.platform != 'win32': | |
335 | if not self.CCC: | |
352f281a | 336 | self.CCC = os.popen('%(WXCONFIG)s --cxx' % self.__dict__, 'r').read()[:-1] |
8e425133 RD |
337 | if not self.CCC: |
338 | print "Warning: C++ compiler not specified (CCC). Assuming c++" | |
339 | self.CCC = 'c++' | |
340 | if not self.CC: | |
352f281a | 341 | self.CCC = os.popen('%(WXCONFIG)s --cc' % self.__dict__, 'r').read()[:-1] |
8e425133 RD |
342 | if not self.CC: |
343 | print "Warning: C compiler not specified (CC). Assuming cc" | |
344 | self.CC = 'cc' | |
5c3a94a6 RD |
345 | |
346 | #------------------------------------------------------------ | |
347 | def findMFValue(self, mfText, st): | |
348 | # Find line begining with st= and return the value | |
349 | # Regex would probably be to cooler way to do this, but | |
350 | # I think this is the most understandable. | |
351 | for line in mfText: | |
352 | if string.find(line, st+'=') == 0: | |
353 | st = string.strip(line[len(st)+1:]) | |
354 | return st | |
355 | return None | |
356 | ||
357 | #------------------------------------------------------------ | |
358 | def makeMakefile(self): | |
359 | ||
360 | # make a list of object file names | |
361 | objects = "" | |
362 | for name in self.SWIGFILES: | |
363 | objects = objects + os.path.splitext(name)[0] + self.OBJEXT + ' ' | |
364 | for name in self.SOURCES: | |
365 | obj = os.path.basename(name) | |
366 | objects = objects + os.path.splitext(obj)[0] + self.OBJEXT + ' ' | |
367 | self.OBJECTS = splitlines(objects) | |
368 | ||
369 | ||
370 | # now build the text for the dependencies | |
371 | depends = "" | |
372 | for name in self.SWIGFILES: | |
922dc976 RD |
373 | rootname = os.path.splitext(name)[0] |
374 | text = '$(GENCODEDIR)/%s.cpp $(GENCODEDIR)/%s.py : %s.i %s\n' \ | |
f6bcfd97 BP |
375 | '$(TARGETDIR)\\%s.py : $(GENCODEDIR)\\%s.py\n' \ |
376 | '$(BUILDDIR)\\%s.py : $(GENCODEDIR)\\%s.py\n' % \ | |
377 | (rootname, rootname, rootname, self.SWIGDEPS, | |
378 | rootname, rootname, rootname, rootname) | |
5c3a94a6 | 379 | depends = depends + text |
922dc976 RD |
380 | if self.OTHERDEPS: |
381 | text = '%s%s : %s\n' % \ | |
382 | (os.path.splitext(name)[0], self.OBJEXT, self.OTHERDEPS) | |
383 | depends = depends + text | |
5c3a94a6 RD |
384 | for name in self.PYFILES: |
385 | text = '$(TARGETDIR)\\%s.py : %s.py\n' % \ | |
386 | tuple([os.path.splitext(name)[0]] * 2) | |
387 | depends = depends + text | |
922dc976 RD |
388 | if self.OTHERDEPS: |
389 | for name in self.SOURCES: | |
390 | name = os.path.basename(name) | |
391 | text = '%s%s : %s\n' % \ | |
392 | (os.path.splitext(name)[0], self.OBJEXT, self.OTHERDEPS) | |
393 | depends = depends + text | |
394 | ||
5c3a94a6 RD |
395 | self.DEPENDS = swapslash(depends) |
396 | ||
397 | ||
398 | # and the list of .py files | |
399 | pymodules = "" | |
f6bcfd97 | 400 | bldpymodules = "" |
5c3a94a6 RD |
401 | for name in self.SWIGFILES: |
402 | pymodules = pymodules + '$(TARGETDIR)\\%s.py ' % os.path.splitext(name)[0] | |
f6bcfd97 | 403 | bldpymodules = bldpymodules + '$(BUILDDIR)\\%s.py ' % os.path.splitext(name)[0] |
5c3a94a6 RD |
404 | for name in self.PYFILES: |
405 | pymodules = pymodules + '$(TARGETDIR)\\%s.py ' % os.path.splitext(name)[0] | |
f6bcfd97 | 406 | bldpymodules = bldpymodules + '$(BUILDDIR)\\%s.py ' % os.path.splitext(name)[0] |
5c3a94a6 | 407 | self.PYMODULES = splitlines(swapslash(pymodules)) |
f6bcfd97 | 408 | self.BLDPYMODULES = splitlines(swapslash(bldpymodules)) |
5c3a94a6 RD |
409 | |
410 | ||
f6bcfd97 | 411 | # now make a list of the python files that would need cleaned up |
b164fb38 RD |
412 | pycleanup = "" |
413 | for name in self.SWIGFILES: | |
414 | pycleanup = pycleanup + self.makeCleanupList(name) | |
415 | for name in self.PYFILES: | |
416 | pycleanup = pycleanup + self.makeCleanupList(name) | |
417 | self.PYCLEANUP = swapslash(pycleanup) | |
418 | ||
5c3a94a6 | 419 | |
f6bcfd97 BP |
420 | # now make a list of the python files that would need uninstalled |
421 | pyUninstall = "" | |
422 | for name in self.SWIGFILES: | |
423 | pyUninstall = pyUninstall + self.makeUninstallList(name) | |
424 | for name in self.PYFILES: | |
425 | pyUninstall = pyUninstall + self.makeUninstallList(name) | |
426 | self.PYUNINSTALL = swapslash(pyUninstall) | |
427 | ||
428 | ||
5c3a94a6 RD |
429 | # finally, build the makefile |
430 | if sys.platform == 'win32': | |
431 | if self.RESFILE: | |
432 | self.RESFILE = '$(MODULE).res' | |
433 | self.RESRULE = '$(MODULE).res : $(MODULE).rc $(WXDIR)\\include\\wx\\msw\\wx.rc\n\t'\ | |
434 | '$(rc) -r /i$(WXDIR)\\include -fo$@ $(MODULE).rc' | |
435 | text = win32Template % self.__dict__ | |
436 | else: | |
437 | text = unixTemplate % self.__dict__ | |
438 | f = open(self.MAKEFILE, 'w') | |
439 | f.write(text) | |
440 | f.close() | |
441 | ||
442 | print "Makefile created: ", self.MAKEFILE | |
443 | ||
444 | ||
b164fb38 RD |
445 | |
446 | #------------------------------------------------------------ | |
f6bcfd97 | 447 | def makeUninstallList(self, name): |
b164fb38 RD |
448 | st = "" |
449 | st = st + '\t%s$(TARGETDIR)\\%s.py\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
450 | st = st + '\t%s$(TARGETDIR)\\%s.pyc\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
451 | st = st + '\t%s$(TARGETDIR)\\%s.pyo\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
452 | return st | |
453 | ||
454 | ||
f6bcfd97 BP |
455 | #------------------------------------------------------------ |
456 | def makeCleanupList(self, name): | |
457 | st = "" | |
458 | st = st + '\t%s$(BUILDDIR)\\%s.py\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
459 | st = st + '\t%s$(BUILDDIR)\\%s.pyc\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
460 | st = st + '\t%s$(BUILDDIR)\\%s.pyo\n' % (self.RMCMD, os.path.splitext(name)[0]) | |
461 | return st | |
462 | ||
463 | ||
5c3a94a6 RD |
464 | #------------------------------------------------------------ |
465 | def readConfigFiles(self, args): | |
466 | return self.processFile(self.bldCfg, 1) and \ | |
467 | self.processFile(os.path.join('../..', self.bldCfgLocal)) and \ | |
468 | self.processFile(os.path.join('..', self.bldCfgLocal)) and \ | |
469 | self.processFile(os.path.join('.', self.bldCfgLocal)) and \ | |
470 | self.processArgs(args) | |
471 | ||
472 | #------------------------------------------------------------ | |
473 | def processFile(self, filename, required=0): | |
474 | try: | |
475 | text = open(filename, 'r').read() | |
476 | except IOError: | |
477 | if required: | |
478 | print "Unable to open %s" % filename | |
479 | return 0 | |
480 | else: | |
481 | return 1 | |
482 | ||
483 | try: | |
484 | exec(text, self.__dict__) | |
485 | except: | |
486 | print "Error evaluating %s" % filename | |
487 | import traceback | |
488 | traceback.print_exc() | |
489 | return 0 | |
490 | return 1 | |
491 | ||
492 | ||
493 | #------------------------------------------------------------ | |
494 | def processArgs(self, args): | |
495 | try: | |
496 | for st in args: | |
497 | pair = string.split(st, '=') | |
498 | name = pair[0] | |
6f82295e | 499 | value = string.join(pair[1:], '=') |
5c3a94a6 RD |
500 | self.__dict__[name] = value |
501 | except: | |
502 | print "Error parsing command-line: %s" % st | |
503 | return 0 | |
504 | ||
505 | return 1 | |
506 | ||
507 | ||
508 | #------------------------------------------------------------ | |
509 | ||
510 | ||
511 | ||
512 | ||
513 | ||
b164fb38 | 514 | #---------------------------------------------------------------------------- |
5c3a94a6 RD |
515 | #---------------------------------------------------------------------------- |
516 | #---------------------------------------------------------------------------- | |
517 | ||
518 | win32Template = ''' | |
519 | #---------------------------------------------------------------------- | |
520 | # This makefile was autogenerated from build.py. Your changes will be | |
521 | # lost if the generator is run again. You have been warned. | |
522 | #---------------------------------------------------------------------- | |
523 | ||
524 | WXDIR = %(WXDIR)s | |
525 | VERSION = %(VERSION)s | |
f6bcfd97 BP |
526 | MAJVER = %(MAJVER)s |
527 | BLDVER = %(BLDVER)s | |
5c3a94a6 RD |
528 | MODULE = %(MODULE)s |
529 | SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s | |
efc5f224 RD |
530 | CFLAGS = %(CFLAGS)s |
531 | LFLAGS = %(LFLAGS)s | |
5c3a94a6 RD |
532 | PYVERSION = %(PYVERSION)s |
533 | PYPREFIX = %(PYPREFIX)s | |
534 | EXECPREFIX = %(EXECPREFIX)s | |
535 | PYTHONLIB = %(PYTHONLIB)s | |
536 | FINAL = %(FINAL)s | |
537 | WXP_USE_THREAD = %(WXP_USE_THREAD)s | |
538 | WXUSINGDLL = %(WXUSINGDLL)s | |
539 | GENCODEDIR = %(GENCODEDIR)s | |
540 | RESFILE = %(RESFILE)s | |
541 | WXPSRCDIR = %(WXPSRCDIR)s | |
f6bcfd97 | 542 | %(OTHERDEFS)s |
5c3a94a6 | 543 | |
f6bcfd97 BP |
544 | WXPYDIR = %(WXPYDIR)s |
545 | BUILDDIR = $(WXPYDIR)\\wxPython | |
5c3a94a6 RD |
546 | TARGETDIR = %(TARGETDIR)s |
547 | ||
548 | OBJECTS = %(OBJECTS)s | |
549 | PYMODULES = %(PYMODULES)s | |
f6bcfd97 | 550 | BLDPYMODULES = %(BLDPYMODULES)s |
5c3a94a6 RD |
551 | TARGET = %(TARGET)s |
552 | ||
553 | ||
554 | ||
555 | ||
556 | !if "$(FINAL)" == "0" | |
557 | DEBUGLFLAGS = /DEBUG /INCREMENTAL:YES | |
558 | !else | |
559 | DEBUGLFLAGS = /INCREMENTAL:NO | |
560 | !endif | |
561 | !if "$(WXP_USE_THREAD)" == "1" | |
562 | THREAD=-DWXP_USE_THREAD=1 | |
563 | !endif | |
564 | ||
565 | ||
566 | ||
567 | ||
568 | NOPCH=1 | |
efc5f224 RD |
569 | OVERRIDEFLAGS=%(OVERRIDEFLAGS)s |
570 | EXTRAFLAGS = $(CFLAGS) %(OTHERCFLAGS)s | |
5c3a94a6 RD |
571 | |
572 | LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s | |
573 | EXTRALIBS = %(LIBS)s %(OTHERLIBS)s | |
574 | ||
f0261a72 RD |
575 | CRTFLAG=%(CRTFLAG)s |
576 | ||
5c3a94a6 RD |
577 | #---------------------------------------------------------------------- |
578 | ||
579 | !include $(WXDIR)\\src\\makevc.env | |
580 | ||
581 | #---------------------------------------------------------------------- | |
582 | ||
583 | %(DEFAULTRULE)s %(OTHERTARGETS)s | |
584 | ||
585 | ||
586 | ||
f6bcfd97 | 587 | install: default $(TARGETDIR) $(TARGETDIR)\\$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s |
5c3a94a6 RD |
588 | |
589 | clean: | |
590 | -erase *.obj | |
591 | -erase *.exe | |
592 | -erase *.res | |
593 | -erase *.map | |
594 | -erase *.sbr | |
595 | -erase *.pdb | |
596 | -erase *.pch | |
597 | -erase $(MODULE).exp | |
598 | -erase $(MODULE).lib | |
599 | -erase $(MODULE).ilk | |
600 | -erase $(TARGET) | |
f6bcfd97 BP |
601 | -erase $(BUILDDIR)\$(TARGET) |
602 | %(PYCLEANUP)s | |
5c3a94a6 RD |
603 | |
604 | ||
efc5f224 | 605 | uninstall: %(OTHERUNINSTALLTARGETS)s |
5c3a94a6 | 606 | -erase $(TARGETDIR)\\$(TARGET) |
f6bcfd97 | 607 | %(PYUNINSTALL)s |
b164fb38 | 608 | |
5c3a94a6 RD |
609 | |
610 | #---------------------------------------------------------------------- | |
611 | # implicit rule for compiling .cpp and .c files | |
612 | {}.cpp{}.obj: | |
613 | $(cc) @<< | |
614 | $(CPPFLAGS) /c /Tp $< | |
615 | << | |
616 | ||
617 | {$(GENCODEDIR)}.cpp{}.obj: | |
618 | $(cc) @<< | |
619 | $(CPPFLAGS) /c /Tp $< | |
620 | << | |
621 | ||
622 | {}.c{}.obj: | |
623 | $(cc) @<< | |
624 | $(CPPFLAGS) /c $< | |
625 | << | |
626 | ||
627 | .SUFFIXES : .i .py | |
628 | ||
629 | # Implicit rules to run SWIG | |
630 | {}.i{$(GENCODEDIR)}.cpp: | |
631 | swig $(SWIGFLAGS) -c -o $@ $< | |
632 | ||
633 | {}.i{$(GENCODEDIR)}.py: | |
634 | swig $(SWIGFLAGS) -c -o $(GENCODEDIR)\\tmp_wrap.cpp $< | |
635 | -erase $(GENCODEDIR)\\tmp_wrap.cpp | |
636 | ||
637 | ||
638 | {$(GENCODEDIR)}.py{$(TARGETDIR)}.py: | |
639 | copy $< $@ | |
640 | ||
641 | {}.py{$(TARGETDIR)}.py: | |
642 | copy $< $@ | |
643 | ||
f6bcfd97 BP |
644 | |
645 | {$(GENCODEDIR)}.py{$(BUILDDIR)}.py: | |
646 | copy $< $@ | |
647 | ||
648 | {}.py{$(BUILDDIR)}.py: | |
649 | copy $< $@ | |
650 | ||
5c3a94a6 RD |
651 | #---------------------------------------------------------------------- |
652 | ||
653 | $(TARGET) : $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(RESFILE) | |
654 | $(link) @<< | |
655 | /out:$@ | |
eec92d76 | 656 | $(LFLAGS) /export:init$(MODULE) /implib:./$(MODULE).lib |
5c3a94a6 RD |
657 | $(DUMMYOBJ) $(OBJECTS) $(RESFILE) |
658 | $(LIBS) | |
659 | << | |
660 | ||
661 | ||
662 | %(RESRULE)s | |
663 | ||
664 | ||
665 | $(TARGETDIR)\\$(TARGET) : $(TARGET) | |
666 | copy $(TARGET) $@ | |
667 | ||
f6bcfd97 BP |
668 | $(BUILDDIR)\\$(TARGET) : $(TARGET) |
669 | copy $(TARGET) $@ | |
670 | ||
5c3a94a6 RD |
671 | |
672 | pycfiles : $(PYMODULES) | |
673 | $(EXECPREFIX)\\python $(PYPREFIX)\\Lib\\compileall.py -l $(TARGETDIR) | |
674 | $(EXECPREFIX)\\python -O $(PYPREFIX)\Lib\\compileall.py -l $(TARGETDIR) | |
675 | ||
f6bcfd97 BP |
676 | bldpycfiles : $(BLDPYMODULES) |
677 | ||
5c3a94a6 RD |
678 | |
679 | $(TARGETDIR) : | |
680 | mkdir $(TARGETDIR) | |
681 | ||
682 | $(GENCODEDIR): | |
683 | mkdir $(GENCODEDIR) | |
684 | ||
685 | #---------------------------------------------------------------------- | |
686 | ||
687 | %(DEPENDS)s | |
688 | ||
689 | #---------------------------------------------------------------------- | |
690 | ||
efc5f224 RD |
691 | showflags: |
692 | @echo CPPFLAGS: | |
693 | @echo $(CPPFLAGS) | |
694 | @echo LFLAGS: | |
695 | @echo $(LFLAGS) | |
f6bcfd97 BP |
696 | @echo BUILDDIR: |
697 | @echo $(BUILDDIR) | |
efc5f224 | 698 | |
5c3a94a6 RD |
699 | |
700 | %(OTHERRULES)s | |
701 | ''' | |
702 | ||
703 | #---------------------------------------------------------------------------- | |
704 | #---------------------------------------------------------------------------- | |
705 | #---------------------------------------------------------------------------- | |
706 | ||
707 | unixTemplate = ''' | |
708 | #---------------------------------------------------------------------- | |
709 | # This makefile was autogenerated from build.py. Your changes will be | |
710 | # lost if the generator is run again. You have been warned. | |
711 | #---------------------------------------------------------------------- | |
712 | ||
5c3a94a6 RD |
713 | WXDIR = %(WXDIR)s |
714 | VERSION = %(VERSION)s | |
f6bcfd97 BP |
715 | MAJVER = %(MAJVER)s |
716 | BLDVER = %(BLDVER)s | |
5c3a94a6 RD |
717 | MODULE = %(MODULE)s |
718 | SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s | |
efc5f224 | 719 | CFLAGS = %(CFLAGS)s $(OPT) %(OTHERCFLAGS)s |
5c3a94a6 | 720 | LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s |
f6bcfd97 | 721 | |
5c3a94a6 RD |
722 | PYVERSION = %(PYVERSION)s |
723 | PYPREFIX = %(PYPREFIX)s | |
724 | EXECPREFIX = %(EXECPREFIX)s | |
725 | PYINCLUDE = $(PYPREFIX)/include/python$(PYVERSION) | |
726 | EXECINCLUDE = $(EXECPREFIX)/include/python$(PYVERSION) | |
727 | PYLIB = %(PYLIB)s | |
728 | LIBPL = %(LIBPL)s | |
729 | PYTHONLIB = %(PYTHONLIB)s | |
730 | FINAL = %(FINAL)s | |
731 | WXP_USE_THREAD = %(WXP_USE_THREAD)s | |
732 | GENCODEDIR = %(GENCODEDIR)s | |
733 | WXPSRCDIR = %(WXPSRCDIR)s | |
734 | HELPERLIB = %(HELPERLIB)s | |
735 | HELPERLIBDIR = %(HELPERLIBDIR)s | |
352f281a | 736 | WXCONFIG=%(WXCONFIG)s |
f6bcfd97 BP |
737 | |
738 | WXPYDIR = %(WXPYDIR)s | |
739 | BUILDDIR = $(WXPYDIR)/wxPython | |
5c3a94a6 | 740 | TARGETDIR = %(TARGETDIR)s |
f6bcfd97 | 741 | %(OTHERDEFS)s |
5c3a94a6 RD |
742 | |
743 | ||
744 | CCC = %(CCC)s | |
745 | CC = %(CC)s | |
746 | OPT = %(OPT)s | |
747 | SO = %(SO)s | |
748 | LDSHARED = %(LDSHARED)s | |
749 | CCSHARED = %(CCSHARED)s | |
750 | ||
751 | ||
752 | OBJECTS = %(OBJECTS)s | |
753 | PYMODULES = %(PYMODULES)s | |
f6bcfd97 | 754 | BLDPYMODULES = %(BLDPYMODULES)s |
5c3a94a6 RD |
755 | TARGET = %(TARGET)s |
756 | ||
757 | ||
758 | ifeq ($(WXP_USE_THREAD), 1) | |
759 | THREAD=-DWXP_USE_THREAD | |
760 | endif | |
761 | ||
f6bcfd97 BP |
762 | USE_SONAME = %(USE_SONAME)s |
763 | ifeq ($(USE_SONAME), 1) | |
764 | LIBS = -l$(HELPERLIB) %(OTHERLIBS)s | |
765 | else | |
766 | LIBS = $(WXPSRCDIR)/lib$(HELPERLIB)$(SO) %(OTHERLIBS)s | |
767 | endif | |
768 | ||
5c3a94a6 RD |
769 | #---------------------------------------------------------------------- |
770 | ||
771 | %(DEFAULTRULE)s %(OTHERTARGETS)s | |
772 | ||
f6bcfd97 | 773 | install: default $(TARGETDIR) $(TARGETDIR)/$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s |
5c3a94a6 RD |
774 | |
775 | clean: | |
f6bcfd97 | 776 | -rm -f *.o *$(SO) *$(SO).* *~ |
5c3a94a6 | 777 | -rm -f $(TARGET) |
f6bcfd97 BP |
778 | -rm -f $(BUILDDIR)/$(TARGET) |
779 | %(PYCLEANUP)s | |
5c3a94a6 | 780 | |
efc5f224 | 781 | uninstall: %(OTHERUNINSTALLTARGETS)s |
5c3a94a6 | 782 | -rm -f $(TARGETDIR)/$(TARGET) |
f6bcfd97 | 783 | %(PYUNINSTALL)s |
5c3a94a6 RD |
784 | |
785 | ||
786 | #---------------------------------------------------------------------- | |
787 | ||
788 | %%.o : %%.cpp | |
789 | $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $< | |
790 | ||
791 | %%.o : $(GENCODEDIR)/%%.cpp | |
792 | $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $< | |
793 | ||
794 | %%.o : %%.c | |
795 | $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $< | |
796 | ||
797 | %%.o : $(GENCODEDIR)/%%.c | |
798 | $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $< | |
799 | ||
46c3e3d9 | 800 | ifndef NOSWIG |
5c3a94a6 RD |
801 | $(GENCODEDIR)/%%.cpp : %%.i |
802 | swig $(SWIGFLAGS) -c -o $@ $< | |
803 | ||
804 | $(GENCODEDIR)/%%.py : %%.i | |
805 | swig $(SWIGFLAGS) -c -o $(GENCODEDIR)/tmp_wrap.cpp $< | |
806 | rm $(GENCODEDIR)/tmp_wrap.cpp | |
46c3e3d9 RD |
807 | endif |
808 | ||
5c3a94a6 RD |
809 | |
810 | $(TARGETDIR)/%% : %% | |
811 | cp -f $< $@ | |
812 | ||
813 | $(TARGETDIR)/%% : $(GENCODEDIR)/%% | |
814 | cp -f $< $@ | |
815 | ||
f6bcfd97 BP |
816 | $(BUILDDIR)/%% : %% |
817 | cp -f $< $@ | |
818 | ||
819 | $(BUILDDIR)/%% : $(GENCODEDIR)/%% | |
820 | cp -f $< $@ | |
821 | ||
5c3a94a6 RD |
822 | #---------------------------------------------------------------------- |
823 | ||
824 | %(DEPENDS)s | |
825 | ||
826 | #---------------------------------------------------------------------- | |
827 | ||
828 | $(TARGET) : $(OBJECTS) | |
829 | $(LDSHARED) $(OBJECTS) $(LFLAGS) $(LIBS) $(OTHERLIBS) -o $(TARGET) | |
830 | ||
831 | ||
5c3a94a6 RD |
832 | pycfiles : $(PYMODULES) |
833 | $(EXECPREFIX)/bin/python $(PYLIB)/compileall.py -l $(TARGETDIR) | |
834 | $(EXECPREFIX)/bin/python -O $(PYLIB)/compileall.py -l $(TARGETDIR) | |
835 | ||
f6bcfd97 BP |
836 | bldpycfiles : $(BLDPYMODULES) |
837 | ||
5c3a94a6 RD |
838 | |
839 | $(TARGETDIR) : | |
305b8c10 | 840 | mkdir -p $(TARGETDIR) |
5c3a94a6 RD |
841 | |
842 | $(GENCODEDIR): | |
843 | mkdir $(GENCODEDIR) | |
844 | ||
845 | #---------------------------------------------------------------------- | |
846 | ||
847 | ||
848 | %(OTHERRULES)s | |
849 | ||
850 | ||
5c3a94a6 RD |
851 | ''' |
852 | ||
853 | ||
854 | #---------------------------------------------------------------------------- | |
855 | ||
856 | if __name__ == '__main__': | |
305b8c10 RD |
857 | err = main(sys.argv) |
858 | sys.exit(err) | |
5c3a94a6 RD |
859 | |
860 | #---------------------------------------------------------------------------- |