]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/config.py
8b8d4ce35841e34a938f42dca24750058d0e43bf
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.)
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.
17 # Created: 23-March-2004
19 # Copyright: (c) 2004 by Total Control Software
20 # Licence: wxWindows license
21 #----------------------------------------------------------------------
23 import sys
, os
, glob
, fnmatch
, tempfile
24 from distutils
.core
import setup
, Extension
25 from distutils
.file_util
import copy_file
26 from distutils
.dir_util
import mkpath
27 from distutils
.dep_util
import newer
28 from distutils
.spawn
import spawn
30 import distutils
.command
.install_data
31 import distutils
.command
.install_headers
32 import distutils
.command
.clean
34 ####################################
36 ####################################
40 from distutils
.spawn
import spawn
48 #---------------------------------------------------------------------------
51 renamerTemplateStart
= """\
52 // A bunch of %rename directives generated by BuildRenamers in config.py
53 // in order to remove the wx prefix from all global scope names.
55 #ifndef BUILDING_RENAMERS
59 renamerTemplateEnd
= """
63 wxPythonTemplateStart
= """\
64 ## This file reverse renames symbols in the wx package to give
65 ## them their wx prefix again, for backwards compatibility.
67 ## Generated by BuildRenamers in config.py
69 # This silly stuff here is so the wxPython.wx module doesn't conflict
70 # with the wx package. We need to import modules from the wx package
71 # here, then we'll put the wxPython.wx entry back in sys.modules.
74 if sys.modules.has_key('wxPython.wx'):
75 _wx = sys.modules['wxPython.wx']
76 del sys.modules['wxPython.wx']
80 sys.modules['wxPython.wx'] = _wx
84 # Now assign all the reverse-renamed names:
87 wxPythonTemplateEnd
= """
93 #---------------------------------------------------------------------------
95 def run(self
, destdir
, modname
, xmlfile
, wxPythonDir
="wxPython"):
97 assert FOUND_LIBXML2
, "The libxml2 module is required to use the BuildRenamers functionality."
99 swigDest
= os
.path
.join(destdir
, "_"+modname
+"_rename.i")
100 pyDest
= os
.path
.join(wxPythonDir
, modname
+ '.py')
102 swigDestTemp
= tempfile
.mktemp('.tmp')
103 swigFile
= open(swigDestTemp
, "w")
104 swigFile
.write(renamerTemplateStart
)
106 pyDestTemp
= tempfile
.mktemp('.tmp')
107 pyFile
= open(pyDestTemp
, "w")
108 pyFile
.write(wxPythonTemplateStart
% modname
)
110 print "Parsing XML and building renamers..."
111 self
.processXML(xmlfile
, modname
, swigFile
, pyFile
)
113 self
.checkOtherNames(pyFile
, modname
,
114 os
.path
.join(destdir
, '_'+modname
+'_reverse.txt'))
115 pyFile
.write(wxPythonTemplateEnd
)
118 swigFile
.write(renamerTemplateEnd
)
121 # Compare the files just created with the existing one and
122 # blow away the old one if they are different.
123 for dest
, temp
in [(swigDest
, swigDestTemp
),
124 (pyDest
, pyDestTemp
)]:
125 if not os
.path
.exists(dest
):
126 os
.rename(temp
, dest
)
127 elif open(dest
).read() != open(temp
).read():
129 os
.rename(temp
, dest
)
131 print dest
+ " not changed."
134 #---------------------------------------------------------------------------
137 def GetAttr(self
, node
, name
):
138 path
= "./attributelist/attribute[@name='%s']/@value" % name
139 n
= node
.xpathEval2(path
)
146 def processXML(self
, xmlfile
, modname
, swigFile
, pyFile
):
148 topnode
= libxml2
.parseFile(xmlfile
).children
150 # remove any import nodes as we don't need to do renamers for symbols found therein
151 imports
= topnode
.xpathEval2("*/import")
156 # do a depth first iteration over what's left
164 if node
.name
== "class":
165 lastClassName
= name
= self
.GetAttr(node
, "name")
166 lastClassSymName
= sym_name
= self
.GetAttr(node
, "sym_name")
173 # renamed constructors
174 elif node
.name
== "constructor":
175 name
= self
.GetAttr(node
, "name")
176 sym_name
= self
.GetAttr(node
, "sym_name")
182 # only enumitems at the top level
183 elif node
.name
== "enumitem" and node
.parent
.parent
.name
== "include":
184 name
= self
.GetAttr(node
, "name")
185 sym_name
= self
.GetAttr(node
, "sym_name")
189 elif node
.name
in ["cdecl", "constant"]:
190 name
= self
.GetAttr(node
, "name")
191 sym_name
= self
.GetAttr(node
, "sym_name")
192 toplevel
= node
.parent
.name
== "include"
194 # top-level functions
195 if toplevel
and self
.GetAttr(node
, "view") == "globalfunctionHandler":
198 # top-level global vars
199 elif toplevel
and self
.GetAttr(node
, "feature_immutable") == "1":
203 elif self
.GetAttr(node
, "view") == "staticmemberfunctionHandler":
204 name
= lastClassName
+ '_' + name
205 sym_name
= lastClassSymName
+ '_' + sym_name
206 # only output the reverse renamer in this case
207 doRename
= revOnly
= True
209 if doRename
and name
!= sym_name
:
214 if doRename
and name
:
216 if old
.startswith('wx') and not old
.startswith('wxEVT_'):
217 # remove all wx prefixes except wxEVT_ and write a %rename directive for it
220 swigFile
.write("%%rename(%s) %35s;\n" % (new
, old
))
222 # Write assignments to import into the old wxPython namespace
223 if addWX
and not old
.startswith('wx'):
225 pyFile
.write("%s = wx.%s.%s\n" % (old
, modname
, new
))
227 pyFile
.write("%sPtr = wx.%s.%sPtr\n" % (old
, modname
, new
))
230 #---------------------------------------------------------------------------
232 def checkOtherNames(self
, pyFile
, moduleName
, filename
):
233 if os
.path
.exists(filename
):
235 for line
in file(filename
):
236 if line
.endswith('\n'):
238 if line
and not line
.startswith('#'):
239 if line
.endswith('*'):
240 prefixes
.append(line
[:-1])
241 elif line
.find('=') != -1:
242 pyFile
.write("%s\n" % line
)
245 if line
.startswith('wx') or line
.startswith('WX') or line
.startswith('EVT'):
247 pyFile
.write("%s = wx.%s.%s\n" % (wxname
, moduleName
, line
))
251 "\n\nd = globals()\nfor k, v in wx.%s.__dict__.iteritems():"
256 pyFile
.write("\n if ")
259 pyFile
.write("\n elif ")
260 pyFile
.write("k.startswith('%s'):\n d[k] = v" % p
)
261 pyFile
.write("\ndel d, k, v\n\n")
264 #---------------------------------------------------------------------------
266 ## interestingTypes = [ 'class', 'cdecl', 'enumitem', 'constructor', 'constant' ]
267 ## interestingAttrs = [ 'name', 'sym_name', 'decl', 'feature_immutable', 'module',
268 ## 'storage', 'type' ]
272 ## def __init__(self, tagtype):
273 ## self.tagtype = tagtype
276 ## self.sym_name = None
278 ## self.immutable = None
280 ## self.module = None
281 ## self.storage = None
283 ## self.startLine = -1
286 ## def write(self, moduleName, swigFile, pyFile):
292 ## #if self.name.find('DefaultPosition') != -1:
293 ## # pprint.pprint(self.__dict__)
295 ## if self.tagtype in ['cdecl', 'constant']:
296 ## if self.storage == 'typedef':
299 ## # top level functions
300 ## elif self.level == 0 and self.decl != "":
303 ## # top level global vars
304 ## elif self.level == 0 and self.immutable == '1':
308 ## elif self.storage == 'static':
309 ## if not self.klass:
310 ## pprint.pprint(self.__dict__)
312 ## self.name = self.klass + '_' + self.name
313 ## self.sym_name = self.sym_klass + '_' + self.sym_name
314 ## # only output the reverse renamer in this case
315 ## doRename = revOnly = True
319 ## if doRename and self.name != self.sym_name:
320 ## #print "%-25s %-25s" % (self.name, self.sym_name)
321 ## self.name = self.sym_name
325 ## elif self.tagtype == 'class' and self.module == moduleName:
328 ## if self.sym_name != self.klass:
329 ## #print self.sym_name
330 ## self.name = self.sym_name
333 ## elif self.tagtype == 'constructor':
334 ## #print "%-25s %-25s" % (self.name, self.sym_name)
335 ## if self.sym_name != self.klass:
336 ## #print self.sym_name
337 ## self.name = self.sym_name
341 ## elif self.tagtype == 'enumitem' and self.level == 0:
346 ## #print "%-25s %-25s" % (self.name, self.sym_name)
347 ## old = new = self.name
348 ## if old.startswith('wx') and not old.startswith('wxEVT_'):
349 ## # remove all wx prefixes except wxEVT_ and write a %rename directive for it
352 ## swigFile.write("%%rename(%s) %35s;\n" % (new, old))
354 ## # Write assignments to import into the old wxPython namespace
355 ## if addWX and not old.startswith('wx'):
357 ## pyFile.write("%s = wx.%s.%s\n" % (old, moduleName, new))
359 ## pyFile.write("%sPtr = wx.%s.%sPtr\n" % (old, moduleName, new))
364 ## # text = "%07d %d %10s %-35s %s\n" % (
365 ## # self.startLine, self.level, self.tagtype, self.name, self.decl)
366 ## # #rejects.write(text)
370 ## #---------------------------------------------------------------------------
372 ## class ContentHandler(xml.sax.ContentHandler):
373 ## def __init__(self, modname, swigFile, pyFile):
374 ## xml.sax.ContentHandler.__init__(self)
375 ## self.modname = modname
376 ## self.swigFile = swigFile
377 ## self.pyFile = pyFile
378 ## self.elements = []
381 ## self.sym_klass = None
384 ## def setDocumentLocator(self, locator):
385 ## self.locator = locator
389 ## def startElement(self, name, attrs):
390 ## if name in interestingTypes:
391 ## # start of a new element that we are interested in
392 ## ce = Element(name)
393 ## ce.startLine = self.locator.getLineNumber()
394 ## ce.level = len(self.elements)
395 ## if name == 'constructor':
396 ## ce.klass = self.elements[0].name
398 ## ce.klass = self.klass
399 ## ce.sym_klass = self.sym_klass
400 ## self.elements.insert(0, ce)
403 ## elif len(self.elements) and name == 'attribute' and attrs['name'] in interestingAttrs:
404 ## attrName = attrs['name']
405 ## attrVal = attrs['value']
406 ## if attrName.startswith('feature_'):
407 ## attrName = attrName.replace('feature_', '')
408 ## ce = self.elements[0]
409 ## if getattr(ce, attrName) is None:
410 ## setattr(ce, attrName, attrVal)
411 ## if ce.tagtype == 'class' and attrName == 'name' and self.klass is None:
412 ## self.klass = attrVal
413 ## if ce.tagtype == 'class' and attrName == 'sym_name' and self.sym_klass is None:
414 ## self.sym_klass = attrVal
417 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'name':
418 ## ## # save the elements name
419 ## ## ce = self.elements[0]
420 ## ## if ce.name is None:
421 ## ## ce.name = attrs['value']
422 ## ## ce.nameLine = self.locator.getLineNumber()
424 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'sym_name':
425 ## ## # save the elements name
426 ## ## ce = self.elements[0]
427 ## ## if ce.sym_name is None:
428 ## ## ce.sym_name = attrs['value']
430 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'decl':
431 ## ## # save the elements decl
432 ## ## ce = self.elements[0]
433 ## ## ce.decl = attrs['value']
435 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'feature_immutable':
436 ## ## # save the elements decl
437 ## ## ce = self.elements[0]
438 ## ## ce.immutable = int(attrs['value'])
440 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'module':
441 ## ## # save the elements decl
442 ## ## ce = self.elements[0]
443 ## ## ce.module = attrs['value']
445 ## elif name == 'import':
448 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'storage':
449 ## ## # save the elements decl
450 ## ## ce = self.elements[0]
451 ## ## ce.storage = attrs['value']
453 ## ## elif len(self.elements) and name == 'attribute' and attrs['name'] == 'type':
454 ## ## # save the elements decl
455 ## ## ce = self.elements[0]
456 ## ## ce.type = attrs['value']
459 ## def endElement(self, name):
460 ## if name in interestingTypes:
461 ## # end of an element that we are interested in
462 ## ce = self.elements.pop(0)
464 ## if self.imports == 0:
465 ## # only write for items that are in this file, not imported
466 ## ce.write(self.modname, self.swigFile, self.pyFile)
468 ## if name == 'import':
471 ## if name == 'class':
473 ## self.sym_klass = None
476 #---------------------------------------------------------------------------
477 #----------------------------------------------------------------------
478 # flags and values that affect this script
479 #----------------------------------------------------------------------
481 VER_MAJOR
= 2 # The first three must match wxWidgets
484 VER_SUBREL
= 2 # wxPython release num for x.y.z release of wxWidgets
485 VER_FLAGS
= "p" # release flags, such as prerelease num, unicode, etc.
487 DESCRIPTION
= "Cross platform GUI toolkit for Python"
488 AUTHOR
= "Robin Dunn"
489 AUTHOR_EMAIL
= "Robin Dunn <robin@alldunn.com>"
490 URL
= "http://wxPython.org/"
491 DOWNLOAD_URL
= "http://wxPython.org/download.php"
492 LICENSE
= "wxWidgets Library License (LGPL derivative)"
493 PLATFORMS
= "WIN32,OSX,POSIX"
494 KEYWORDS
= "GUI,wx,wxWindows,wxWidgets,cross-platform"
496 LONG_DESCRIPTION
= """\
497 wxPython is a GUI toolkit for Python that is a wrapper around the
498 wxWidgets C++ GUI library. wxPython provides a large variety of
499 window types and controls, all implemented with a native look and
500 feel (by using the native widgets) on the platforms it is supported
505 Development Status :: 6 - Mature
506 Environment :: MacOS X :: Carbon
507 Environment :: Win32 (MS Windows)
508 Environment :: X11 Applications :: GTK
509 Intended Audience :: Developers
510 License :: OSI Approved
511 Operating System :: MacOS :: MacOS X
512 Operating System :: Microsoft :: Windows :: Windows 95/98/2000
513 Operating System :: POSIX
514 Programming Language :: Python
515 Topic :: Software Development :: User Interfaces
518 ## License :: OSI Approved :: wxWidgets Library Licence
521 # Config values below this point can be reset on the setup.py command line.
523 BUILD_GLCANVAS
= 1 # If true, build the contrib/glcanvas extension module
524 BUILD_OGL
= 1 # If true, build the contrib/ogl extension module
525 BUILD_STC
= 1 # If true, build the contrib/stc extension module
526 BUILD_XRC
= 1 # XML based resource system
527 BUILD_GIZMOS
= 1 # Build a module for the gizmos contrib library
528 BUILD_DLLWIDGET
= 0# Build a module that enables unknown wx widgets
529 # to be loaded from a DLL and to be used from Python.
531 # Internet Explorer wrapper (experimental)
532 BUILD_IEWIN
= (os
.name
== 'nt')
533 BUILD_ACTIVEX
= (os
.name
== 'nt') # new version of IEWIN and more
536 CORE_ONLY
= 0 # if true, don't build any of the above
538 PREP_ONLY
= 0 # Only run the prepatory steps, not the actual build.
540 USE_SWIG
= 0 # Should we actually execute SWIG, or just use the
541 # files already in the distribution?
543 SWIG
= "swig" # The swig executable to use.
545 BUILD_RENAMERS
= 1 # Should we build the renamer modules too?
547 FULL_DOCS
= 0 # Some docstrings are split into a basic docstring and a
548 # details string. Setting this flag to 1 will
549 # cause the two strings to be combined and output
550 # as the full docstring.
552 UNICODE
= 0 # This will pass the 'wxUSE_UNICODE' flag to SWIG and
553 # will ensure that the right headers are found and the
554 # right libs are linked.
556 UNDEF_NDEBUG
= 1 # Python 2.2 on Unix/Linux by default defines NDEBUG,
557 # and distutils will pick this up and use it on the
558 # compile command-line for the extensions. This could
559 # conflict with how wxWidgets was built. If NDEBUG is
560 # set then wxWidgets' __WXDEBUG__ setting will be turned
561 # off. If wxWidgets was actually built with it turned
562 # on then you end up with mismatched class structures,
563 # and wxPython will crash.
565 NO_SCRIPTS
= 0 # Don't install the tool scripts
566 NO_HEADERS
= 0 # Don't install the wxPython *.h and *.i files
568 WX_CONFIG
= None # Usually you shouldn't need to touch this, but you can set
569 # it to pass an alternate version of wx-config or alternate
570 # flags, eg. as required by the .deb in-tree build. By
571 # default a wx-config command will be assembled based on
572 # version, port, etc. and it will be looked for on the
575 WXPORT
= 'gtk' # On Linux/Unix there are several ports of wxWidgets available.
576 # Setting this value lets you select which will be used for
577 # the wxPython build. Possibilites are 'gtk', 'gtk2' and
578 # 'x11'. Curently only gtk and gtk2 works.
580 BUILD_BASE
= "build" # Directory to use for temporary build files.
581 # This name will be appended to if the WXPORT or
582 # the UNICODE flags are set to non-standard
586 CONTRIBS_INC
= "" # A dir to add as an -I flag when compiling the contribs
589 # Some MSW build settings
591 FINAL
= 0 # Mirrors use of same flag in wx makefiles,
592 # (0 or 1 only) should probably find a way to
595 HYBRID
= 1 # If set and not debug or FINAL, then build a
596 # hybrid extension that can be used by the
597 # non-debug version of python, but contains
598 # debugging symbols for wxWidgets and wxPython.
599 # wxWidgets must have been built with /MD, not /MDd
600 # (using FINAL=hybrid will do it.)
602 # Version part of wxWidgets LIB/DLL names
603 WXDLLVER
= '%d%d' % (VER_MAJOR
, VER_MINOR
)
605 WXPY_SRC
= '.' # Assume we're in the source tree already, but allow the
606 # user to change it, particularly for extension building.
609 #----------------------------------------------------------------------
612 if hasattr(sys
, 'setup_is_main') and sys
.setup_is_main
:
617 path
= os
.path
.join(*args
)
618 return os
.path
.normpath(path
)
633 #----------------------------------------------------------------------
635 #----------------------------------------------------------------------
642 force
= '--force' in sys
.argv
or '-f' in sys
.argv
643 debug
= '--debug' in sys
.argv
or '-g' in sys
.argv
644 cleaning
= 'clean' in sys
.argv
647 # change the PORT default for wxMac
648 if sys
.platform
[:6] == "darwin":
651 # and do the same for wxMSW, just for consistency
656 #----------------------------------------------------------------------
657 # Check for build flags on the command line
658 #----------------------------------------------------------------------
660 # Boolean (int) flags
661 for flag
in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'BUILD_XRC',
662 'BUILD_GIZMOS', 'BUILD_DLLWIDGET', 'BUILD_IEWIN', 'BUILD_ACTIVEX',
663 'CORE_ONLY', 'PREP_ONLY', 'USE_SWIG', 'UNICODE',
664 'UNDEF_NDEBUG', 'NO_SCRIPTS', 'NO_HEADERS', 'BUILD_RENAMERS',
666 'FINAL', 'HYBRID', ]:
667 for x
in range(len(sys
.argv
)):
668 if sys
.argv
[x
].find(flag
) == 0:
669 pos
= sys
.argv
[x
].find('=') + 1
671 vars()[flag
] = eval(sys
.argv
[x
][pos
:])
675 for option
in ['WX_CONFIG', 'WXDLLVER', 'BUILD_BASE', 'WXPORT', 'SWIG',
676 'CONTRIBS_INC', 'WXPY_SRC']:
677 for x
in range(len(sys
.argv
)):
678 if sys
.argv
[x
].find(option
) == 0:
679 pos
= sys
.argv
[x
].find('=') + 1
681 vars()[option
] = sys
.argv
[x
][pos
:]
684 sys
.argv
= filter(None, sys
.argv
)
687 #----------------------------------------------------------------------
688 # some helper functions
689 #----------------------------------------------------------------------
691 def Verify_WX_CONFIG():
692 """ Called below for the builds that need wx-config,
693 if WX_CONFIG is not set then tries to select the specific
694 wx*-config script based on build options. If not found
695 then it defaults to 'wx-config'.
697 # if WX_CONFIG hasn't been set to an explicit value then construct one.
699 if WX_CONFIG
is None:
700 if debug
: # TODO: Fix this. wxPython's --debug shouldn't be tied to wxWidgets...
708 ver2
= "%s.%s" % (VER_MAJOR
, VER_MINOR
)
712 WX_CONFIG
= 'wx%s%s%s-%s-config' % (port
, uf
, df
, ver2
)
714 searchpath
= os
.environ
["PATH"]
715 for p
in searchpath
.split(':'):
716 fp
= os
.path
.join(p
, WX_CONFIG
)
717 if os
.path
.exists(fp
) and os
.access(fp
, os
.X_OK
):
719 msg("Found wx-config: " + fp
)
723 msg("WX_CONFIG not specified and %s not found on $PATH "
724 "defaulting to \"wx-config\"" % WX_CONFIG
)
725 WX_CONFIG
= 'wx-config'
729 def run_swig(files
, dir, gendir
, package
, USE_SWIG
, force
, swig_args
,
730 swig_deps
=[], add_under
=False):
731 """Run SWIG the way I want it done"""
733 if USE_SWIG
and not os
.path
.exists(os
.path
.join(dir, gendir
)):
734 os
.mkdir(os
.path
.join(dir, gendir
))
736 if USE_SWIG
and not os
.path
.exists(os
.path
.join("docs", "xml-raw")):
737 if not os
.path
.exists("docs"):
739 os
.mkdir(os
.path
.join("docs", "xml-raw"))
743 if add_under
: pre
= '_'
747 basefile
= os
.path
.splitext(file)[0]
748 i_file
= os
.path
.join(dir, file)
749 py_file
= os
.path
.join(dir, gendir
, pre
+basefile
+'.py')
750 cpp_file
= os
.path
.join(dir, gendir
, pre
+basefile
+'_wrap.cpp')
751 xml_file
= os
.path
.join("docs", "xml-raw", basefile
+pre
+'_swig.xml')
754 interface
= ['-interface', '_'+basefile
+'_']
758 sources
.append(cpp_file
)
760 if not cleaning
and USE_SWIG
:
761 for dep
in swig_deps
:
762 if newer(dep
, py_file
) or newer(dep
, cpp_file
):
766 if force
or newer(i_file
, py_file
) or newer(i_file
, cpp_file
):
767 ## we need forward slashes here even on win32
768 #cpp_file = opj(cpp_file) #'/'.join(cpp_file.split('\\'))
769 #i_file = opj(i_file) #'/'.join(i_file.split('\\'))
772 xmltemp
= tempfile
.mktemp('.xml')
774 # First run swig to produce the XML file, adding
775 # an extra -D that prevents the old rename
776 # directives from being used
777 cmd
= [ swig_cmd
] + swig_args
+ \
778 [ '-DBUILDING_RENAMERS', '-xmlout', xmltemp
] + \
779 ['-I'+dir, '-o', cpp_file
, i_file
]
783 # Next run build_renamers to process the XML
784 myRenamer
= BuildRenamers()
785 myRenamer
.run(dir, pre
+basefile
, xmltemp
)
788 # Then run swig for real
789 cmd
= [ swig_cmd
] + swig_args
+ interface
+ \
790 ['-I'+dir, '-o', cpp_file
, '-xmlout', xml_file
, i_file
]
795 # copy the generated python file to the package directory
796 copy_file(py_file
, package
, update
=not force
, verbose
=0)
797 CLEANUP
.append(opj(package
, os
.path
.basename(py_file
)))
803 # Specializations of some distutils command classes
804 class wx_smart_install_data(distutils
.command
.install_data
.install_data
):
805 """need to change self.install_dir to the actual library dir"""
807 install_cmd
= self
.get_finalized_command('install')
808 self
.install_dir
= getattr(install_cmd
, 'install_lib')
809 return distutils
.command
.install_data
.install_data
.run(self
)
812 class wx_extra_clean(distutils
.command
.clean
.clean
):
814 Also cleans stuff that this setup.py copies itself. If the
815 --all flag was used also searches for .pyc, .pyd, .so files
818 from distutils
import log
819 from distutils
.filelist
import FileList
822 distutils
.command
.clean
.clean
.run(self
)
826 fl
.include_pattern("*.pyc", 0)
827 fl
.include_pattern("*.pyd", 0)
828 fl
.include_pattern("*.so", 0)
834 if not self
.dry_run
and os
.path
.exists(f
):
836 log
.info("removing '%s'", f
)
838 log
.warning("unable to remove '%s'", f
)
842 if not self
.dry_run
and os
.path
.exists(f
):
844 log
.info("removing '%s'", f
)
846 log
.warning("unable to remove '%s'", f
)
850 class wx_install_headers(distutils
.command
.install_headers
.install_headers
):
852 Install the header files to the WXPREFIX, with an extra dir per
855 def initialize_options (self
):
857 distutils
.command
.install_headers
.install_headers
.initialize_options(self
)
859 def finalize_options (self
):
860 self
.set_undefined_options('install', ('root', 'root'))
861 distutils
.command
.install_headers
.install_headers
.finalize_options(self
)
866 headers
= self
.distribution
.headers
871 if root
is None or WXPREFIX
.startswith(root
):
873 for header
, location
in headers
:
874 install_dir
= os
.path
.normpath(root
+ WXPREFIX
+ location
)
875 self
.mkpath(install_dir
)
876 (out
, _
) = self
.copy_file(header
, install_dir
)
877 self
.outfiles
.append(out
)
882 def build_locale_dir(destdir
, verbose
=1):
883 """Build a locale dir under the wxPython package for MSW"""
884 moFiles
= glob
.glob(opj(WXDIR
, 'locale', '*.mo'))
886 lang
= os
.path
.splitext(os
.path
.basename(src
))[0]
887 dest
= opj(destdir
, lang
, 'LC_MESSAGES')
888 mkpath(dest
, verbose
=verbose
)
889 copy_file(src
, opj(dest
, 'wxstd.mo'), update
=1, verbose
=verbose
)
890 CLEANUP
.append(opj(dest
, 'wxstd.mo'))
894 def build_locale_list(srcdir
):
895 # get a list of all files under the srcdir, to be used for install_data
896 def walk_helper(lst
, dirname
, files
):
898 filename
= opj(dirname
, f
)
899 if not os
.path
.isdir(filename
):
900 lst
.append( (dirname
, [filename
]) )
902 os
.path
.walk(srcdir
, walk_helper
, file_list
)
906 def find_data_files(srcdir
, *wildcards
):
907 # get a list of all files under the srcdir matching wildcards,
908 # returned in a format to be used for install_data
910 def walk_helper(arg
, dirname
, files
):
915 filename
= opj(dirname
, f
)
916 if fnmatch
.fnmatch(filename
, wc
) and not os
.path
.isdir(filename
):
917 names
.append(filename
)
919 lst
.append( (dirname
, names
) )
922 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
926 def makeLibName(name
):
927 if os
.name
== 'posix':
928 libname
= '%s_%s-%s' % (WXBASENAME
, name
, WXRELEASE
)
930 libname
= 'wxmsw%s%s_%s' % (WXDLLVER
, libFlag(), name
)
936 def adjustCFLAGS(cflags
, defines
, includes
):
937 '''Extrace the raw -I, -D, and -U flags and put them into
938 defines and includes as needed.'''
942 includes
.append(flag
[2:])
943 elif flag
[:2] == '-D':
945 if flag
.find('=') == -1:
946 defines
.append( (flag
, None) )
948 defines
.append( tuple(flag
.split('=')) )
949 elif flag
[:2] == '-U':
950 defines
.append( (flag
[2:], ) )
952 newCFLAGS
.append(flag
)
957 def adjustLFLAGS(lfags
, libdirs
, libs
):
958 '''Extrace the -L and -l flags and put them in libdirs and libs as needed'''
962 libdirs
.append(flag
[2:])
963 elif flag
[:2] == '-l':
964 libs
.append(flag
[2:])
966 newLFLAGS
.append(flag
)
970 #----------------------------------------------------------------------
990 if UNICODE
and WXPORT
not in ['msw', 'gtk2']:
991 raise SystemExit, "UNICODE mode not currently supported on this WXPORT: "+WXPORT
995 CONTRIBS_INC
= [ CONTRIBS_INC
]
1000 #----------------------------------------------------------------------
1001 # Setup some platform specific stuff
1002 #----------------------------------------------------------------------
1005 # Set compile flags and such for MSVC. These values are derived
1006 # from the wxWidgets makefiles for MSVC, other compilers settings
1007 # will probably vary...
1008 if os
.environ
.has_key('WXWIN'):
1009 WXDIR
= os
.environ
['WXWIN']
1011 msg("WARNING: WXWIN not set in environment.")
1012 WXDIR
= '..' # assumes in CVS tree
1013 WXPLAT
= '__WXMSW__'
1016 includes
= ['include', 'src',
1017 opj(WXDIR
, 'lib', 'vc_dll', 'msw' + libFlag()),
1018 opj(WXDIR
, 'include'),
1019 opj(WXDIR
, 'contrib', 'include'),
1022 defines
= [ ('WIN32', None),
1026 ('WXUSINGDLL', '1'),
1028 ('SWIG_GLOBAL', None),
1029 ('WXP_USE_THREAD', '1'),
1033 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
1036 defines
.append( ('__NO_VC_CRTDBG__', None) )
1038 if not FINAL
or HYBRID
:
1039 defines
.append( ('__WXDEBUG__', None) )
1041 libdirs
= [ opj(WXDIR
, 'lib', 'vc_dll') ]
1042 libs
= [ 'wxbase' + WXDLLVER
+ libFlag(), # TODO: trim this down to what is really needed for the core
1043 'wxbase' + WXDLLVER
+ libFlag() + '_net',
1044 'wxbase' + WXDLLVER
+ libFlag() + '_xml',
1045 makeLibName('core')[0],
1046 makeLibName('adv')[0],
1047 makeLibName('html')[0],
1050 libs
= libs
+ ['kernel32', 'user32', 'gdi32', 'comdlg32',
1051 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
1052 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
1053 'advapi32', 'wsock32']
1057 # '/GX-' # workaround for internal compiler error in MSVC on some machines
1061 # Other MSVC flags...
1062 # Too bad I don't remember why I was playing with these, can they be removed?
1064 pass #cflags = cflags + ['/O1']
1066 pass #cflags = cflags + ['/Ox']
1068 pass # cflags = cflags + ['/Od', '/Z7']
1069 # lflags = ['/DEBUG', ]
1073 #----------------------------------------------------------------------
1075 elif os
.name
== 'posix':
1077 includes
= ['include', 'src']
1078 defines
= [('SWIG_GLOBAL', None),
1079 ('HAVE_CONFIG_H', None),
1080 ('WXP_USE_THREAD', '1'),
1083 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
1090 # If you get unresolved symbol errors on Solaris and are using gcc, then
1091 # uncomment this block to add the right flags to the link step and build
1093 ## if os.uname()[0] == 'SunOS':
1094 ## libs.append('gcc')
1095 ## libdirs.append(commands.getoutput("gcc -print-search-dirs | grep '^install' | awk '{print $2}'")[:-1])
1097 cflags
= os
.popen(WX_CONFIG
+ ' --cxxflags', 'r').read()[:-1]
1098 cflags
= cflags
.split()
1101 cflags
.append('-O0')
1103 cflags
.append('-O3')
1105 lflags
= os
.popen(WX_CONFIG
+ ' --libs', 'r').read()[:-1]
1106 lflags
= lflags
.split()
1108 WXBASENAME
= os
.popen(WX_CONFIG
+ ' --basename').read()[:-1]
1109 WXRELEASE
= os
.popen(WX_CONFIG
+ ' --release').read()[:-1]
1110 WXPREFIX
= os
.popen(WX_CONFIG
+ ' --prefix').read()[:-1]
1113 if sys
.platform
[:6] == "darwin":
1114 # Flags and such for a Darwin (Max OS X) build of Python
1115 WXPLAT
= '__WXMAC__'
1122 # Set flags for other Unix type platforms
1126 WXPLAT
= '__WXGTK__'
1127 portcfg
= os
.popen('gtk-config --cflags', 'r').read()[:-1]
1128 elif WXPORT
== 'gtk2':
1129 WXPLAT
= '__WXGTK__'
1130 GENDIR
= 'gtk' # no code differences so use the same generated sources
1131 portcfg
= os
.popen('pkg-config gtk+-2.0 --cflags', 'r').read()[:-1]
1132 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
1133 elif WXPORT
== 'x11':
1134 WXPLAT
= '__WXX11__'
1136 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
1138 raise SystemExit, "Unknown WXPORT value: " + WXPORT
1140 cflags
+= portcfg
.split()
1142 # Some distros (e.g. Mandrake) put libGLU in /usr/X11R6/lib, but
1143 # wx-config doesn't output that for some reason. For now, just
1144 # add it unconditionally but we should really check if the lib is
1145 # really found there or wx-config should be fixed.
1146 libdirs
.append("/usr/X11R6/lib")
1149 # Move the various -I, -D, etc. flags we got from the *config scripts
1150 # into the distutils lists.
1151 cflags
= adjustCFLAGS(cflags
, defines
, includes
)
1152 lflags
= adjustLFLAGS(lflags
, libdirs
, libs
)
1155 #----------------------------------------------------------------------
1157 raise 'Sorry, platform not supported...'
1160 #----------------------------------------------------------------------
1161 # post platform setup checks and tweaks, create the full version string
1162 #----------------------------------------------------------------------
1165 BUILD_BASE
= BUILD_BASE
+ '.unicode'
1168 if os
.path
.exists('DAILY_BUILD'):
1170 VER_FLAGS
+= '.' + open('DAILY_BUILD').read().strip()
1172 VERSION
= "%s.%s.%s.%s%s" % (VER_MAJOR
, VER_MINOR
, VER_RELEASE
,
1173 VER_SUBREL
, VER_FLAGS
)
1176 #----------------------------------------------------------------------
1178 #----------------------------------------------------------------------
1182 swig_args
= ['-c++',
1191 '-I' + opj(WXPY_SRC
, 'src'),
1196 swig_args
.append('-DwxUSE_UNICODE')
1199 swig_args
.append('-D_DO_FULL_DOCS')
1202 swig_deps
= [ opj(WXPY_SRC
, 'src/my_typemaps.i'),
1203 opj(WXPY_SRC
, 'src/common.swg'),
1204 opj(WXPY_SRC
, 'src/pyrun.swg'),
1207 depends
= [ #'include/wx/wxPython/wxPython.h',
1208 #'include/wx/wxPython/wxPython_int.h',
1212 #----------------------------------------------------------------------