]> git.saurik.com Git - wxWidgets.git/blame - wxPython/config.py
Minor cleanup
[wxWidgets.git] / wxPython / config.py
CommitLineData
1128a89b
RD
1#----------------------------------------------------------------------
2# Name: wx.build.config
3# Purpose: Most of the contents of this module used to be located
4# in wxPython's setup.py script. It was moved here so
5# it would be installed with the rest of wxPython and
6# could therefore be used by the setup.py for other
7# projects that needed this same info and functionality
8# (most likely in order to be compatible with wxPython.)
9#
10# This split from setup.py is still fairly rough, and
11# some things may still get shuffled back and forth,
12# refactored, etc. Please send me any comments and
13# suggestions about this.
14#
15# Author: Robin Dunn
16#
17# Created: 23-March-2004
18# RCS-ID: $Id$
19# Copyright: (c) 2004 by Total Control Software
20# Licence: wxWindows license
21#----------------------------------------------------------------------
22
23import sys, os, glob, fnmatch, tempfile
24from distutils.core import setup, Extension
25from distutils.file_util import copy_file
26from distutils.dir_util import mkpath
27from distutils.dep_util import newer
28from distutils.spawn import spawn
29
d48c1c64 30import distutils.command.install
1128a89b
RD
31import distutils.command.install_data
32import distutils.command.install_headers
33import distutils.command.clean
34
35#----------------------------------------------------------------------
36# flags and values that affect this script
37#----------------------------------------------------------------------
38
39VER_MAJOR = 2 # The first three must match wxWidgets
fbc661d0
KO
40VER_MINOR = 7
41VER_RELEASE = 0
42VER_SUBREL = 0 # wxPython release num for x.y.z release of wxWidgets
063c96c1 43VER_FLAGS = "pre" # release flags, such as prerelease or RC num, etc.
1128a89b
RD
44
45DESCRIPTION = "Cross platform GUI toolkit for Python"
46AUTHOR = "Robin Dunn"
47AUTHOR_EMAIL = "Robin Dunn <robin@alldunn.com>"
48URL = "http://wxPython.org/"
49DOWNLOAD_URL = "http://wxPython.org/download.php"
50LICENSE = "wxWidgets Library License (LGPL derivative)"
51PLATFORMS = "WIN32,OSX,POSIX"
52KEYWORDS = "GUI,wx,wxWindows,wxWidgets,cross-platform"
53
54LONG_DESCRIPTION = """\
55wxPython is a GUI toolkit for Python that is a wrapper around the
56wxWidgets C++ GUI library. wxPython provides a large variety of
57window types and controls, all implemented with a native look and
8cd98969
DS
58feel (by using the native widgets) on the platforms upon which it is
59supported.
1128a89b
RD
60"""
61
62CLASSIFIERS = """\
63Development Status :: 6 - Mature
64Environment :: MacOS X :: Carbon
65Environment :: Win32 (MS Windows)
66Environment :: X11 Applications :: GTK
67Intended Audience :: Developers
68License :: OSI Approved
69Operating System :: MacOS :: MacOS X
70Operating System :: Microsoft :: Windows :: Windows 95/98/2000
71Operating System :: POSIX
72Programming Language :: Python
73Topic :: Software Development :: User Interfaces
74"""
75
76## License :: OSI Approved :: wxWidgets Library Licence
77
78
79# Config values below this point can be reset on the setup.py command line.
80
81BUILD_GLCANVAS = 1 # If true, build the contrib/glcanvas extension module
a0c70b76 82BUILD_OGL = 0 # If true, build the contrib/ogl extension module
1128a89b 83BUILD_STC = 1 # If true, build the contrib/stc extension module
1128a89b 84BUILD_GIZMOS = 1 # Build a module for the gizmos contrib library
2e5aa9c4 85BUILD_ANIMATE = 1 # Build a module for the animate contrib library
1128a89b
RD
86BUILD_DLLWIDGET = 0# Build a module that enables unknown wx widgets
87 # to be loaded from a DLL and to be used from Python.
88
89 # Internet Explorer wrapper (experimental)
ef8b9c3e 90BUILD_ACTIVEX = (os.name == 'nt') # new version of IEWIN and more
1128a89b
RD
91
92
93CORE_ONLY = 0 # if true, don't build any of the above
94
95PREP_ONLY = 0 # Only run the prepatory steps, not the actual build.
96
97USE_SWIG = 0 # Should we actually execute SWIG, or just use the
98 # files already in the distribution?
99
100SWIG = "swig" # The swig executable to use.
101
102BUILD_RENAMERS = 1 # Should we build the renamer modules too?
103
d07d2bc9
RD
104FULL_DOCS = 0 # Some docstrings are split into a basic docstring and a
105 # details string. Setting this flag to 1 will
106 # cause the two strings to be combined and output
107 # as the full docstring.
108
1128a89b
RD
109UNICODE = 0 # This will pass the 'wxUSE_UNICODE' flag to SWIG and
110 # will ensure that the right headers are found and the
111 # right libs are linked.
112
113UNDEF_NDEBUG = 1 # Python 2.2 on Unix/Linux by default defines NDEBUG,
114 # and distutils will pick this up and use it on the
115 # compile command-line for the extensions. This could
116 # conflict with how wxWidgets was built. If NDEBUG is
117 # set then wxWidgets' __WXDEBUG__ setting will be turned
118 # off. If wxWidgets was actually built with it turned
119 # on then you end up with mismatched class structures,
120 # and wxPython will crash.
121
122NO_SCRIPTS = 0 # Don't install the tool scripts
123NO_HEADERS = 0 # Don't install the wxPython *.h and *.i files
124
d48c1c64
RD
125INSTALL_MULTIVERSION = 1 # Install the packages such that multiple versions
126 # can co-exist. When turned on the wx and wxPython
127 # pacakges will be installed in a versioned subdir
128 # of site-packages, and a *.pth file will be
129 # created that adds that dir to the sys.path. In
130 # addition, a wxselect.py module will be installed
131 # to site-pacakges that will allow applications to
8cd98969 132 # choose a specific version if more than one is
d48c1c64
RD
133 # installed.
134
135FLAVOUR = "" # Optional flavour string to be appended to VERSION
136 # in MULTIVERSION installs
d48c1c64 137
eed86594 138EP_ADD_OPTS = 1 # When doing MULTIVERSION installs the wx port and
b6536d60 139 # ansi/unicode settings can optionally be added to the
f189a52b
RD
140 # subdir path used in site-packages
141
b6536d60 142
1128a89b
RD
143WX_CONFIG = None # Usually you shouldn't need to touch this, but you can set
144 # it to pass an alternate version of wx-config or alternate
145 # flags, eg. as required by the .deb in-tree build. By
146 # default a wx-config command will be assembled based on
147 # version, port, etc. and it will be looked for on the
148 # default $PATH.
149
02b800ce
RD
150SYS_WX_CONFIG = None # When installing an in tree build, setup.py uses wx-config
151 # for two different purposes. First, to determine the prefix
152 # where files will be installed, and secondly, to initialise
153 # build_options.py with the correct options for it.
154 # WX_CONFIG is used for the first task. SYS_WX_CONFIG may
155 # be set independently, to the value that should appear in
156 # build_options.py, if it is different to that. The default
157 # is to use the value of WX_CONFIG.
158
5924e48d 159WXPORT = 'gtk2' # On Linux/Unix there are several ports of wxWidgets available.
1128a89b
RD
160 # Setting this value lets you select which will be used for
161 # the wxPython build. Possibilites are 'gtk', 'gtk2' and
162 # 'x11'. Curently only gtk and gtk2 works.
163
164BUILD_BASE = "build" # Directory to use for temporary build files.
165 # This name will be appended to if the WXPORT or
166 # the UNICODE flags are set to non-standard
167 # values. See below.
168
169
170CONTRIBS_INC = "" # A dir to add as an -I flag when compiling the contribs
171
172
173# Some MSW build settings
174
cb56afc4
RD
175MONOLITHIC = 1 # The core wxWidgets lib can be built as either a
176 # single monolithic DLL or as a collection of DLLs.
177 # This flag controls which set of libs will be used
178 # on Windows. (For other platforms it is automatic
179 # via using wx-config.)
180
181FINAL = 0 # Will use the release version of the wxWidgets libs on MSW.
182
183HYBRID = 1 # Will use the "hybrid" version of the wxWidgets
184 # libs on MSW. A "hybrid" build is one that is
185 # basically a release build, but that also defines
186 # __WXDEBUG__ to activate the runtime checks and
187 # assertions in the library. When any of these is
188 # triggered it is turned into a Python exception so
189 # this is a very useful feature to have turned on.
1128a89b 190
1128a89b
RD
191
192 # Version part of wxWidgets LIB/DLL names
193WXDLLVER = '%d%d' % (VER_MAJOR, VER_MINOR)
194
73a22369
RD
195WXPY_SRC = '.' # Assume we're in the source tree already, but allow the
196 # user to change it, particularly for extension building.
197
1128a89b
RD
198
199#----------------------------------------------------------------------
200
201def msg(text):
fb3d05e9 202 if hasattr(sys, 'setup_is_main') and sys.setup_is_main:
1128a89b
RD
203 print text
204
205
206def opj(*args):
73a22369 207 path = os.path.join(*args)
1128a89b
RD
208 return os.path.normpath(path)
209
210
211def libFlag():
212 if FINAL:
213 rv = ''
214 elif HYBRID:
215 rv = 'h'
216 else:
217 rv = 'd'
218 if UNICODE:
219 rv = 'u' + rv
220 return rv
221
222
223#----------------------------------------------------------------------
224# Some other globals
225#----------------------------------------------------------------------
226
227PKGDIR = 'wx'
228wxpExtensions = []
229DATA_FILES = []
230CLEANUP = []
231
232force = '--force' in sys.argv or '-f' in sys.argv
233debug = '--debug' in sys.argv or '-g' in sys.argv
234cleaning = 'clean' in sys.argv
235
236
237# change the PORT default for wxMac
238if sys.platform[:6] == "darwin":
239 WXPORT = 'mac'
240
241# and do the same for wxMSW, just for consistency
242if os.name == 'nt':
243 WXPORT = 'msw'
244
77bef39a 245WXPYTHON_TYPE_TABLE = '_wxPython_table'
1128a89b
RD
246
247#----------------------------------------------------------------------
248# Check for build flags on the command line
249#----------------------------------------------------------------------
250
251# Boolean (int) flags
4b8b345c 252for flag in [ 'BUILD_ACTIVEX', 'BUILD_ANIMATE', 'BUILD_DLLWIDGET',
acb4c4bd 253 'BUILD_GIZMOS', 'BUILD_GLCANVAS',
4b8b345c 254 'BUILD_OGL', 'BUILD_STC',
1128a89b
RD
255 'CORE_ONLY', 'PREP_ONLY', 'USE_SWIG', 'UNICODE',
256 'UNDEF_NDEBUG', 'NO_SCRIPTS', 'NO_HEADERS', 'BUILD_RENAMERS',
b6536d60 257 'FULL_DOCS', 'INSTALL_MULTIVERSION', 'EP_ADD_OPTS',
cb56afc4 258 'MONOLITHIC', 'FINAL', 'HYBRID', ]:
1128a89b
RD
259 for x in range(len(sys.argv)):
260 if sys.argv[x].find(flag) == 0:
261 pos = sys.argv[x].find('=') + 1
262 if pos > 0:
263 vars()[flag] = eval(sys.argv[x][pos:])
264 sys.argv[x] = ''
265
266# String options
02b800ce
RD
267for option in ['WX_CONFIG', 'SYS_WX_CONFIG', 'WXDLLVER', 'BUILD_BASE',
268 'WXPORT', 'SWIG', 'CONTRIBS_INC', 'WXPY_SRC', 'FLAVOUR',
d48c1c64 269 ]:
1128a89b
RD
270 for x in range(len(sys.argv)):
271 if sys.argv[x].find(option) == 0:
272 pos = sys.argv[x].find('=') + 1
273 if pos > 0:
274 vars()[option] = sys.argv[x][pos:]
275 sys.argv[x] = ''
276
277sys.argv = filter(None, sys.argv)
278
279
f35d1a03
RD
280#----------------------------------------------------------------------
281# build options file
282#----------------------------------------------------------------------
283
02b800ce
RD
284if SYS_WX_CONFIG is None:
285 SYS_WX_CONFIG = WX_CONFIG
286
f35d1a03
RD
287build_options_template = """
288UNICODE=%d
289UNDEF_NDEBUG=%d
290INSTALL_MULTIVERSION=%d
291FLAVOUR="%s"
292EP_ADD_OPTS=%d
293WX_CONFIG="%s"
294WXPORT="%s"
295MONOLITHIC=%d
296FINAL=%d
297HYBRID=%d
298""" % (UNICODE, UNDEF_NDEBUG, INSTALL_MULTIVERSION, FLAVOUR, EP_ADD_OPTS,
02b800ce 299 SYS_WX_CONFIG, WXPORT, MONOLITHIC, FINAL, HYBRID)
f35d1a03
RD
300
301try:
302 from build_options import *
303except:
304 build_options_file = os.path.join(os.path.dirname(__file__), "build_options.py")
305 if not os.path.exists(build_options_file):
306 try:
307 myfile = open(build_options_file, "w")
308 myfile.write(build_options_template)
309 myfile.close()
310 except:
311 print "WARNING: Unable to create build_options.py."
312
313
1128a89b
RD
314#----------------------------------------------------------------------
315# some helper functions
316#----------------------------------------------------------------------
317
318def Verify_WX_CONFIG():
e9019d1c 319 """ Called below for the builds that need wx-config, if WX_CONFIG
8cd98969 320 is not set then determines the flags needed based on build
e9019d1c 321 options and searches for wx-config on the PATH.
1128a89b
RD
322 """
323 # if WX_CONFIG hasn't been set to an explicit value then construct one.
324 global WX_CONFIG
325 if WX_CONFIG is None:
adce89c3 326 WX_CONFIG='wx-config'
1128a89b
RD
327 port = WXPORT
328 if port == "x11":
329 port = "x11univ"
e9019d1c
RD
330 flags = ' --toolkit=%s' % port
331 flags += ' --unicode=%s' % (UNICODE and 'yes' or 'no')
332 flags += ' --version=%s.%s' % (VER_MAJOR, VER_MINOR)
1128a89b
RD
333
334 searchpath = os.environ["PATH"]
335 for p in searchpath.split(':'):
e9019d1c 336 fp = os.path.join(p, 'wx-config')
1128a89b
RD
337 if os.path.exists(fp) and os.access(fp, os.X_OK):
338 # success
339 msg("Found wx-config: " + fp)
e9019d1c
RD
340 msg(" Using flags: " + flags)
341 WX_CONFIG = fp + flags
b6536d60
RD
342 if hasattr(sys, 'setup_is_main') and not sys.setup_is_main:
343 WX_CONFIG += " 2>/dev/null "
1128a89b
RD
344 break
345 else:
e9019d1c
RD
346 msg("ERROR: WX_CONFIG not specified and wx-config not found on the $PATH")
347 # should we exit?
1128a89b 348
8cd98969 349 # TODO: execute WX_CONFIG --list and verify a matching config is found
e9019d1c 350
1128a89b 351
54f9ee45
RD
352def run_swig(files, dir, gendir, package, USE_SWIG, force, swig_args,
353 swig_deps=[], add_under=False):
1128a89b
RD
354 """Run SWIG the way I want it done"""
355
356 if USE_SWIG and not os.path.exists(os.path.join(dir, gendir)):
357 os.mkdir(os.path.join(dir, gendir))
358
359 if USE_SWIG and not os.path.exists(os.path.join("docs", "xml-raw")):
73a22369
RD
360 if not os.path.exists("docs"):
361 os.mkdir("docs")
1128a89b
RD
362 os.mkdir(os.path.join("docs", "xml-raw"))
363
364 sources = []
365
54f9ee45
RD
366 if add_under: pre = '_'
367 else: pre = ''
368
1128a89b
RD
369 for file in files:
370 basefile = os.path.splitext(file)[0]
371 i_file = os.path.join(dir, file)
54f9ee45
RD
372 py_file = os.path.join(dir, gendir, pre+basefile+'.py')
373 cpp_file = os.path.join(dir, gendir, pre+basefile+'_wrap.cpp')
fda33067 374 xml_file = os.path.join("docs", "xml-raw", basefile+pre+'_swig.xml')
1128a89b 375
54f9ee45
RD
376 if add_under:
377 interface = ['-interface', '_'+basefile+'_']
378 else:
379 interface = []
380
1128a89b
RD
381 sources.append(cpp_file)
382
383 if not cleaning and USE_SWIG:
384 for dep in swig_deps:
f35d1a03
RD
385 # this may fail for external builds, but it's not
386 # a fatal error, so keep going.
387 try:
388 if newer(dep, py_file) or newer(dep, cpp_file):
389 force = 1
390 break
391 except:
392 pass
1128a89b
RD
393
394 if force or newer(i_file, py_file) or newer(i_file, cpp_file):
8cd98969 395 ## we need forward slashes here, even on win32
1128a89b
RD
396 #cpp_file = opj(cpp_file) #'/'.join(cpp_file.split('\\'))
397 #i_file = opj(i_file) #'/'.join(i_file.split('\\'))
398
399 if BUILD_RENAMERS:
1128a89b
RD
400 xmltemp = tempfile.mktemp('.xml')
401
402 # First run swig to produce the XML file, adding
403 # an extra -D that prevents the old rename
404 # directives from being used
405 cmd = [ swig_cmd ] + swig_args + \
406 [ '-DBUILDING_RENAMERS', '-xmlout', xmltemp ] + \
407 ['-I'+dir, '-o', cpp_file, i_file]
408 msg(' '.join(cmd))
409 spawn(cmd)
410
411 # Next run build_renamers to process the XML
73a22369
RD
412 myRenamer = BuildRenamers()
413 myRenamer.run(dir, pre+basefile, xmltemp)
1128a89b
RD
414 os.remove(xmltemp)
415
416 # Then run swig for real
54f9ee45
RD
417 cmd = [ swig_cmd ] + swig_args + interface + \
418 ['-I'+dir, '-o', cpp_file, '-xmlout', xml_file, i_file]
1128a89b
RD
419 msg(' '.join(cmd))
420 spawn(cmd)
421
422
423 # copy the generated python file to the package directory
424 copy_file(py_file, package, update=not force, verbose=0)
425 CLEANUP.append(opj(package, os.path.basename(py_file)))
426
427 return sources
428
429
430
431# Specializations of some distutils command classes
432class wx_smart_install_data(distutils.command.install_data.install_data):
433 """need to change self.install_dir to the actual library dir"""
434 def run(self):
435 install_cmd = self.get_finalized_command('install')
436 self.install_dir = getattr(install_cmd, 'install_lib')
437 return distutils.command.install_data.install_data.run(self)
438
439
440class wx_extra_clean(distutils.command.clean.clean):
441 """
442 Also cleans stuff that this setup.py copies itself. If the
443 --all flag was used also searches for .pyc, .pyd, .so files
444 """
445 def run(self):
446 from distutils import log
447 from distutils.filelist import FileList
448 global CLEANUP
449
450 distutils.command.clean.clean.run(self)
451
452 if self.all:
453 fl = FileList()
454 fl.include_pattern("*.pyc", 0)
455 fl.include_pattern("*.pyd", 0)
456 fl.include_pattern("*.so", 0)
457 CLEANUP += fl.files
458
459 for f in CLEANUP:
460 if os.path.isdir(f):
461 try:
462 if not self.dry_run and os.path.exists(f):
463 os.rmdir(f)
464 log.info("removing '%s'", f)
465 except IOError:
466 log.warning("unable to remove '%s'", f)
467
468 else:
469 try:
470 if not self.dry_run and os.path.exists(f):
471 os.remove(f)
472 log.info("removing '%s'", f)
473 except IOError:
474 log.warning("unable to remove '%s'", f)
475
476
477
d48c1c64
RD
478class wx_install(distutils.command.install.install):
479 """
480 Turns off install_path_file
481 """
482 def initialize_options(self):
483 distutils.command.install.install.initialize_options(self)
484 self.install_path_file = 0
485
486
1128a89b
RD
487class wx_install_headers(distutils.command.install_headers.install_headers):
488 """
489 Install the header files to the WXPREFIX, with an extra dir per
490 filename too
491 """
38b97c15 492 def initialize_options(self):
1128a89b
RD
493 self.root = None
494 distutils.command.install_headers.install_headers.initialize_options(self)
495
38b97c15 496 def finalize_options(self):
1128a89b
RD
497 self.set_undefined_options('install', ('root', 'root'))
498 distutils.command.install_headers.install_headers.finalize_options(self)
499
500 def run(self):
501 if os.name == 'nt':
502 return
503 headers = self.distribution.headers
504 if not headers:
505 return
506
507 root = self.root
862b5362 508 if root is None or WXPREFIX.startswith(root):
1128a89b
RD
509 root = ''
510 for header, location in headers:
e9019d1c
RD
511 install_dir = os.path.normpath(root +
512 WXPREFIX +
513 '/include/wx-%d.%d/wx' % (VER_MAJOR, VER_MINOR) +
514 location)
1128a89b
RD
515 self.mkpath(install_dir)
516 (out, _) = self.copy_file(header, install_dir)
517 self.outfiles.append(out)
518
519
520
521
522def build_locale_dir(destdir, verbose=1):
523 """Build a locale dir under the wxPython package for MSW"""
524 moFiles = glob.glob(opj(WXDIR, 'locale', '*.mo'))
525 for src in moFiles:
526 lang = os.path.splitext(os.path.basename(src))[0]
527 dest = opj(destdir, lang, 'LC_MESSAGES')
528 mkpath(dest, verbose=verbose)
529 copy_file(src, opj(dest, 'wxstd.mo'), update=1, verbose=verbose)
530 CLEANUP.append(opj(dest, 'wxstd.mo'))
531 CLEANUP.append(dest)
532
533
534def build_locale_list(srcdir):
535 # get a list of all files under the srcdir, to be used for install_data
536 def walk_helper(lst, dirname, files):
537 for f in files:
538 filename = opj(dirname, f)
539 if not os.path.isdir(filename):
540 lst.append( (dirname, [filename]) )
541 file_list = []
542 os.path.walk(srcdir, walk_helper, file_list)
543 return file_list
544
545
546def find_data_files(srcdir, *wildcards):
547 # get a list of all files under the srcdir matching wildcards,
548 # returned in a format to be used for install_data
549
550 def walk_helper(arg, dirname, files):
551 names = []
552 lst, wildcards = arg
553 for wc in wildcards:
554 for f in files:
555 filename = opj(dirname, f)
556 if fnmatch.fnmatch(filename, wc) and not os.path.isdir(filename):
557 names.append(filename)
558 if names:
559 lst.append( (dirname, names ) )
560
561 file_list = []
562 os.path.walk(srcdir, walk_helper, (file_list, wildcards))
563 return file_list
564
565
566def makeLibName(name):
567 if os.name == 'posix':
568 libname = '%s_%s-%s' % (WXBASENAME, name, WXRELEASE)
cb56afc4 569 elif name:
1128a89b 570 libname = 'wxmsw%s%s_%s' % (WXDLLVER, libFlag(), name)
cb56afc4
RD
571 else:
572 libname = 'wxmsw%s%s' % (WXDLLVER, libFlag())
1128a89b
RD
573 return [libname]
574
575
576
577def adjustCFLAGS(cflags, defines, includes):
38b97c15 578 '''Extract the raw -I, -D, and -U flags and put them into
1128a89b
RD
579 defines and includes as needed.'''
580 newCFLAGS = []
581 for flag in cflags:
582 if flag[:2] == '-I':
583 includes.append(flag[2:])
584 elif flag[:2] == '-D':
585 flag = flag[2:]
586 if flag.find('=') == -1:
587 defines.append( (flag, None) )
588 else:
589 defines.append( tuple(flag.split('=')) )
590 elif flag[:2] == '-U':
591 defines.append( (flag[2:], ) )
592 else:
593 newCFLAGS.append(flag)
594 return newCFLAGS
595
596
597
598def adjustLFLAGS(lfags, libdirs, libs):
d48c1c64 599 '''Extract the -L and -l flags and put them in libdirs and libs as needed'''
1128a89b
RD
600 newLFLAGS = []
601 for flag in lflags:
602 if flag[:2] == '-L':
603 libdirs.append(flag[2:])
604 elif flag[:2] == '-l':
605 libs.append(flag[2:])
606 else:
607 newLFLAGS.append(flag)
608
609 return newLFLAGS
610
d48c1c64
RD
611
612
613def getExtraPath(shortVer=True, addOpts=False):
614 """Get the dirname that wxPython will be installed under."""
615
616 if shortVer:
617 # short version, just Major.Minor
618 ep = "wx-%d.%d" % (VER_MAJOR, VER_MINOR)
cb56afc4 619
d48c1c64 620 # plus release if minor is odd
f189a52b
RD
621 if VER_MINOR % 2 == 1:
622 ep += ".%d" % VER_RELEASE
cb56afc4 623
d48c1c64
RD
624 else:
625 # long version, full version
626 ep = "wx-%d.%d.%d.%d" % (VER_MAJOR, VER_MINOR, VER_RELEASE, VER_SUBREL)
627
628 if addOpts:
cb56afc4
RD
629 port = WXPORT
630 if port == "msw": port = "win32"
d48c1c64
RD
631 ep += "-%s-%s" % (WXPORT, (UNICODE and 'unicode' or 'ansi'))
632
633 if FLAVOUR:
634 ep += "-" + FLAVOUR
635
636 return ep
637
1128a89b
RD
638#----------------------------------------------------------------------
639# sanity checks
640
641if CORE_ONLY:
642 BUILD_GLCANVAS = 0
643 BUILD_OGL = 0
644 BUILD_STC = 0
1128a89b
RD
645 BUILD_GIZMOS = 0
646 BUILD_DLLWIDGET = 0
1128a89b 647 BUILD_ACTIVEX = 0
4a40657b 648 BUILD_ANIMATE = 0
1128a89b
RD
649
650if debug:
651 FINAL = 0
652 HYBRID = 0
653
654if FINAL:
655 HYBRID = 0
656
85245f48 657if UNICODE and WXPORT not in ['msw', 'gtk2', 'mac']:
1128a89b
RD
658 raise SystemExit, "UNICODE mode not currently supported on this WXPORT: "+WXPORT
659
660
661if CONTRIBS_INC:
662 CONTRIBS_INC = [ CONTRIBS_INC ]
663else:
664 CONTRIBS_INC = []
665
666
667#----------------------------------------------------------------------
668# Setup some platform specific stuff
669#----------------------------------------------------------------------
670
671if os.name == 'nt':
672 # Set compile flags and such for MSVC. These values are derived
673 # from the wxWidgets makefiles for MSVC, other compilers settings
674 # will probably vary...
675 if os.environ.has_key('WXWIN'):
676 WXDIR = os.environ['WXWIN']
677 else:
678 msg("WARNING: WXWIN not set in environment.")
679 WXDIR = '..' # assumes in CVS tree
680 WXPLAT = '__WXMSW__'
681 GENDIR = 'msw'
543cba02 682
1128a89b
RD
683 includes = ['include', 'src',
684 opj(WXDIR, 'lib', 'vc_dll', 'msw' + libFlag()),
685 opj(WXDIR, 'include'),
686 opj(WXDIR, 'contrib', 'include'),
687 ]
688
689 defines = [ ('WIN32', None),
690 ('_WINDOWS', None),
691
692 (WXPLAT, None),
693 ('WXUSINGDLL', '1'),
694
77bef39a 695 ('SWIG_TYPE_TABLE', WXPYTHON_TYPE_TABLE),
1128a89b
RD
696 ('WXP_USE_THREAD', '1'),
697 ]
698
699 if UNDEF_NDEBUG:
700 defines.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
701
702 if HYBRID:
703 defines.append( ('__NO_VC_CRTDBG__', None) )
704
705 if not FINAL or HYBRID:
706 defines.append( ('__WXDEBUG__', None) )
707
708 libdirs = [ opj(WXDIR, 'lib', 'vc_dll') ]
cb56afc4
RD
709 if MONOLITHIC:
710 libs = makeLibName('')
711 else:
712 libs = [ 'wxbase' + WXDLLVER + libFlag(),
713 'wxbase' + WXDLLVER + libFlag() + '_net',
714 'wxbase' + WXDLLVER + libFlag() + '_xml',
715 makeLibName('core')[0],
716 makeLibName('adv')[0],
717 makeLibName('html')[0],
718 makeLibName('xrc')[0],
719 ]
1128a89b
RD
720
721 libs = libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',
722 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
723 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
724 'advapi32', 'wsock32']
725
726
727 cflags = [ '/Gy',
728 # '/GX-' # workaround for internal compiler error in MSVC on some machines
729 ]
730 lflags = None
731
732 # Other MSVC flags...
733 # Too bad I don't remember why I was playing with these, can they be removed?
734 if FINAL:
735 pass #cflags = cflags + ['/O1']
736 elif HYBRID :
737 pass #cflags = cflags + ['/Ox']
738 else:
739 pass # cflags = cflags + ['/Od', '/Z7']
740 # lflags = ['/DEBUG', ]
741
742
743
744#----------------------------------------------------------------------
745
746elif os.name == 'posix':
747 WXDIR = '..'
748 includes = ['include', 'src']
77bef39a 749 defines = [('SWIG_TYPE_TABLE', WXPYTHON_TYPE_TABLE),
1128a89b
RD
750 ('HAVE_CONFIG_H', None),
751 ('WXP_USE_THREAD', '1'),
752 ]
753 if UNDEF_NDEBUG:
754 defines.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
755
756 Verify_WX_CONFIG()
757
758 libdirs = []
759 libs = []
760
761 # If you get unresolved symbol errors on Solaris and are using gcc, then
762 # uncomment this block to add the right flags to the link step and build
763 # again.
764 ## if os.uname()[0] == 'SunOS':
a432a02b 765 ## import commands
1128a89b
RD
766 ## libs.append('gcc')
767 ## libdirs.append(commands.getoutput("gcc -print-search-dirs | grep '^install' | awk '{print $2}'")[:-1])
768
769 cflags = os.popen(WX_CONFIG + ' --cxxflags', 'r').read()[:-1]
770 cflags = cflags.split()
771 if debug:
772 cflags.append('-g')
773 cflags.append('-O0')
774 else:
775 cflags.append('-O3')
776
777 lflags = os.popen(WX_CONFIG + ' --libs', 'r').read()[:-1]
778 lflags = lflags.split()
779
780 WXBASENAME = os.popen(WX_CONFIG + ' --basename').read()[:-1]
781 WXRELEASE = os.popen(WX_CONFIG + ' --release').read()[:-1]
782 WXPREFIX = os.popen(WX_CONFIG + ' --prefix').read()[:-1]
783
784
2cbbc68d 785 if sys.platform[:6] == "darwin" and WXPORT == 'mac':
1128a89b
RD
786 # Flags and such for a Darwin (Max OS X) build of Python
787 WXPLAT = '__WXMAC__'
788 GENDIR = 'mac'
789 libs = ['stdc++']
790 NO_SCRIPTS = 1
791
792
793 else:
794 # Set flags for other Unix type platforms
795 GENDIR = WXPORT
796
797 if WXPORT == 'gtk':
798 WXPLAT = '__WXGTK__'
799 portcfg = os.popen('gtk-config --cflags', 'r').read()[:-1]
800 elif WXPORT == 'gtk2':
801 WXPLAT = '__WXGTK__'
802 GENDIR = 'gtk' # no code differences so use the same generated sources
803 portcfg = os.popen('pkg-config gtk+-2.0 --cflags', 'r').read()[:-1]
804 BUILD_BASE = BUILD_BASE + '-' + WXPORT
805 elif WXPORT == 'x11':
806 WXPLAT = '__WXX11__'
807 portcfg = ''
808 BUILD_BASE = BUILD_BASE + '-' + WXPORT
809 else:
810 raise SystemExit, "Unknown WXPORT value: " + WXPORT
811
812 cflags += portcfg.split()
813
814 # Some distros (e.g. Mandrake) put libGLU in /usr/X11R6/lib, but
815 # wx-config doesn't output that for some reason. For now, just
816 # add it unconditionally but we should really check if the lib is
817 # really found there or wx-config should be fixed.
818 libdirs.append("/usr/X11R6/lib")
819
820
821 # Move the various -I, -D, etc. flags we got from the *config scripts
822 # into the distutils lists.
823 cflags = adjustCFLAGS(cflags, defines, includes)
824 lflags = adjustLFLAGS(lflags, libdirs, libs)
825
826
827#----------------------------------------------------------------------
828else:
829 raise 'Sorry, platform not supported...'
830
831
832#----------------------------------------------------------------------
833# post platform setup checks and tweaks, create the full version string
834#----------------------------------------------------------------------
835
836if UNICODE:
837 BUILD_BASE = BUILD_BASE + '.unicode'
cb56afc4 838 ##VER_FLAGS += 'u'
1128a89b 839
96acd0c1 840if os.path.exists('DAILY_BUILD'):
4b2826e5
RD
841
842 VER_FLAGS += '.' + open('DAILY_BUILD').read().strip()
1128a89b
RD
843
844VERSION = "%s.%s.%s.%s%s" % (VER_MAJOR, VER_MINOR, VER_RELEASE,
845 VER_SUBREL, VER_FLAGS)
846
847
848#----------------------------------------------------------------------
849# SWIG defaults
850#----------------------------------------------------------------------
851
d1b3d685 852# *.i files could live in the wxWidgets/wxPython/src dir, or in
f35d1a03
RD
853# a subdirectory of the devel package. Let's specify both
854# dirs as includes so we don't have to guess which is correct.
855
856wxfilesdir = ""
bbc916e2 857i_subdir = opj("include", getExtraPath(), "wx", "wxPython", "i_files")
f35d1a03
RD
858if os.name != "nt":
859 wxfilesdir = opj(WXPREFIX, i_subdir)
860else:
861 wxfilesdir = opj(WXPY_SRC, i_subdir)
d1b3d685 862
f35d1a03
RD
863i_files_includes = [ '-I' + opj(WXPY_SRC, 'src'),
864 '-I' + wxfilesdir ]
f35d1a03 865
1128a89b
RD
866swig_cmd = SWIG
867swig_force = force
868swig_args = ['-c++',
869 '-Wall',
870 '-nodefault',
871
872 '-python',
873 '-keyword',
874 '-new_repr',
875 '-modern',
1128a89b 876 '-D'+WXPLAT,
f35d1a03
RD
877 ] + i_files_includes
878
1128a89b
RD
879if UNICODE:
880 swig_args.append('-DwxUSE_UNICODE')
881
d07d2bc9
RD
882if FULL_DOCS:
883 swig_args.append('-D_DO_FULL_DOCS')
884
885
73a22369 886swig_deps = [ opj(WXPY_SRC, 'src/my_typemaps.i'),
1b8c7ba6 887 opj(WXPY_SRC, 'src/pyfragments.swg'),
1128a89b
RD
888 ]
889
890depends = [ #'include/wx/wxPython/wxPython.h',
891 #'include/wx/wxPython/wxPython_int.h',
892 #'src/pyclasses.h',
893 ]
894
895#----------------------------------------------------------------------
c278542b
RD
896
897####################################
898# BuildRenamers
899####################################
900
bbc916e2 901import pprint, shutil
c278542b
RD
902try:
903 import libxml2
904 FOUND_LIBXML2 = True
905except ImportError:
906 FOUND_LIBXML2 = False
907
908#---------------------------------------------------------------------------
909
c278542b
RD
910renamerTemplateStart = """\
911// A bunch of %rename directives generated by BuildRenamers in config.py
912// in order to remove the wx prefix from all global scope names.
913
914#ifndef BUILDING_RENAMERS
915
916"""
917
918renamerTemplateEnd = """
919#endif
920"""
921
922wxPythonTemplateStart = """\
923## This file reverse renames symbols in the wx package to give
924## them their wx prefix again, for backwards compatibility.
925##
926## Generated by BuildRenamers in config.py
927
928# This silly stuff here is so the wxPython.wx module doesn't conflict
929# with the wx package. We need to import modules from the wx package
930# here, then we'll put the wxPython.wx entry back in sys.modules.
931import sys
932_wx = None
933if sys.modules.has_key('wxPython.wx'):
934 _wx = sys.modules['wxPython.wx']
935 del sys.modules['wxPython.wx']
936
937import wx.%s
938
939sys.modules['wxPython.wx'] = _wx
940del sys, _wx
941
942
943# Now assign all the reverse-renamed names:
944"""
945
946wxPythonTemplateEnd = """
947
948"""
949
950
951
952#---------------------------------------------------------------------------
953class BuildRenamers:
954 def run(self, destdir, modname, xmlfile, wxPythonDir="wxPython"):
955
956 assert FOUND_LIBXML2, "The libxml2 module is required to use the BuildRenamers functionality."
957
958 if not os.path.exists(wxPythonDir):
959 os.mkdir(wxPythonDir)
960
961 swigDest = os.path.join(destdir, "_"+modname+"_rename.i")
962 pyDest = os.path.join(wxPythonDir, modname + '.py')
963
964 swigDestTemp = tempfile.mktemp('.tmp')
965 swigFile = open(swigDestTemp, "w")
966 swigFile.write(renamerTemplateStart)
967
968 pyDestTemp = tempfile.mktemp('.tmp')
969 pyFile = open(pyDestTemp, "w")
970 pyFile.write(wxPythonTemplateStart % modname)
971
972 print "Parsing XML and building renamers..."
973 self.processXML(xmlfile, modname, swigFile, pyFile)
974
975 self.checkOtherNames(pyFile, modname,
976 os.path.join(destdir, '_'+modname+'_reverse.txt'))
977 pyFile.write(wxPythonTemplateEnd)
978 pyFile.close()
979
980 swigFile.write(renamerTemplateEnd)
981 swigFile.close()
982
983 # Compare the files just created with the existing one and
984 # blow away the old one if they are different.
985 for dest, temp in [(swigDest, swigDestTemp),
986 (pyDest, pyDestTemp)]:
bbc916e2
KO
987 # NOTE: we don't use shutil.move() because it was introduced
988 # in Python 2.3. Eventually we can switch to it when people
989 # stop building using 2.2.
c278542b 990 if not os.path.exists(dest):
bbc916e2 991 shutil.copyfile(temp, dest)
c278542b
RD
992 elif open(dest).read() != open(temp).read():
993 os.unlink(dest)
bbc916e2 994 shutil.copyfile(temp, dest)
c278542b
RD
995 else:
996 print dest + " not changed."
997 os.unlink(temp)
998
999 #---------------------------------------------------------------------------
1000
1001
1002 def GetAttr(self, node, name):
1003 path = "./attributelist/attribute[@name='%s']/@value" % name
1004 n = node.xpathEval2(path)
1005 if len(n):
1006 return n[0].content
1007 else:
1008 return None
1009
1010
1011 def processXML(self, xmlfile, modname, swigFile, pyFile):
1012
1013 topnode = libxml2.parseFile(xmlfile).children
1014
1015 # remove any import nodes as we don't need to do renamers for symbols found therein
1016 imports = topnode.xpathEval2("*/import")
1017 for n in imports:
1018 n.unlinkNode()
1019 n.freeNode()
1020
1021 # do a depth first iteration over what's left
1022 for node in topnode:
1023 doRename = False
1024 doPtr = False
1025 addWX = False
1026 revOnly = False
1027
1028
1029 if node.name == "class":
1030 lastClassName = name = self.GetAttr(node, "name")
1031 lastClassSymName = sym_name = self.GetAttr(node, "sym_name")
1032 doRename = True
1033 doPtr = True
1034 if sym_name != name:
1035 name = sym_name
1036 addWX = True
1037
1038 # renamed constructors
1039 elif node.name == "constructor":
1040 name = self.GetAttr(node, "name")
1041 sym_name = self.GetAttr(node, "sym_name")
1042 if sym_name != name:
1043 name = sym_name
1044 addWX = True
1045 doRename = True
1046
1047 # only enumitems at the top level
1048 elif node.name == "enumitem" and node.parent.parent.name == "include":
1049 name = self.GetAttr(node, "name")
1050 sym_name = self.GetAttr(node, "sym_name")
1051 doRename = True
1052
1053
1054 elif node.name in ["cdecl", "constant"]:
1055 name = self.GetAttr(node, "name")
1056 sym_name = self.GetAttr(node, "sym_name")
1057 toplevel = node.parent.name == "include"
1058
1059 # top-level functions
1060 if toplevel and self.GetAttr(node, "view") == "globalfunctionHandler":
1061 doRename = True
1062
1063 # top-level global vars
1064 elif toplevel and self.GetAttr(node, "feature_immutable") == "1":
1065 doRename = True
1066
1067 # static methods
1068 elif self.GetAttr(node, "view") == "staticmemberfunctionHandler":
1069 name = lastClassName + '_' + name
1070 sym_name = lastClassSymName + '_' + sym_name
1071 # only output the reverse renamer in this case
1072 doRename = revOnly = True
1073
1074 if doRename and name != sym_name:
1075 name = sym_name
1076 addWX = True
1077
1078
1079 if doRename and name:
1080 old = new = name
1081 if old.startswith('wx') and not old.startswith('wxEVT_'):
1082 # remove all wx prefixes except wxEVT_ and write a %rename directive for it
1083 new = old[2:]
1084 if not revOnly:
1085 swigFile.write("%%rename(%s) %35s;\n" % (new, old))
1086
1087 # Write assignments to import into the old wxPython namespace
1088 if addWX and not old.startswith('wx'):
1089 old = 'wx'+old
1090 pyFile.write("%s = wx.%s.%s\n" % (old, modname, new))
1091 if doPtr:
1092 pyFile.write("%sPtr = wx.%s.%sPtr\n" % (old, modname, new))
1093
1094
1095 #---------------------------------------------------------------------------
1096
1097 def checkOtherNames(self, pyFile, moduleName, filename):
1098 if os.path.exists(filename):
1099 prefixes = []
1100 for line in file(filename):
1101 if line.endswith('\n'):
1102 line = line[:-1]
1103 if line and not line.startswith('#'):
1104 if line.endswith('*'):
1105 prefixes.append(line[:-1])
1106 elif line.find('=') != -1:
1107 pyFile.write("%s\n" % line)
1108 else:
1109 wxname = 'wx' + line
1110 if line.startswith('wx') or line.startswith('WX') or line.startswith('EVT'):
1111 wxname = line
1112 pyFile.write("%s = wx.%s.%s\n" % (wxname, moduleName, line))
1113
1114 if prefixes:
1115 pyFile.write(
1116 "\n\nd = globals()\nfor k, v in wx.%s.__dict__.iteritems():"
1117 % moduleName)
1118 first = True
1119 for p in prefixes:
1120 if first:
1121 pyFile.write("\n if ")
1122 first = False
1123 else:
1124 pyFile.write("\n elif ")
1125 pyFile.write("k.startswith('%s'):\n d[k] = v" % p)
1126 pyFile.write("\ndel d, k, v\n\n")
1127
1128
1129#---------------------------------------------------------------------------