]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/config.py
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 #----------------------------------------------------------------------
35 # flags and values that affect this script
36 #----------------------------------------------------------------------
38 VER_MAJOR
= 2 # The first three must match wxWidgets
41 VER_SUBREL
= 3 # wxPython release num for x.y.z release of wxWidgets
42 VER_FLAGS
= "" # release flags, such as prerelease num, unicode, etc.
44 DESCRIPTION
= "Cross platform GUI toolkit for Python"
46 AUTHOR_EMAIL
= "Robin Dunn <robin@alldunn.com>"
47 URL
= "http://wxPython.org/"
48 DOWNLOAD_URL
= "http://wxPython.org/download.php"
49 LICENSE
= "wxWidgets Library License (LGPL derivative)"
50 PLATFORMS
= "WIN32,OSX,POSIX"
51 KEYWORDS
= "GUI,wx,wxWindows,wxWidgets,cross-platform"
53 LONG_DESCRIPTION
= """\
54 wxPython is a GUI toolkit for Python that is a wrapper around the
55 wxWidgets C++ GUI library. wxPython provides a large variety of
56 window types and controls, all implemented with a native look and
57 feel (by using the native widgets) on the platforms it is supported
62 Development Status :: 6 - Mature
63 Environment :: MacOS X :: Carbon
64 Environment :: Win32 (MS Windows)
65 Environment :: X11 Applications :: GTK
66 Intended Audience :: Developers
67 License :: OSI Approved
68 Operating System :: MacOS :: MacOS X
69 Operating System :: Microsoft :: Windows :: Windows 95/98/2000
70 Operating System :: POSIX
71 Programming Language :: Python
72 Topic :: Software Development :: User Interfaces
75 ## License :: OSI Approved :: wxWidgets Library Licence
78 # Config values below this point can be reset on the setup.py command line.
80 BUILD_GLCANVAS
= 1 # If true, build the contrib/glcanvas extension module
81 BUILD_OGL
= 1 # If true, build the contrib/ogl extension module
82 BUILD_STC
= 1 # If true, build the contrib/stc extension module
83 BUILD_XRC
= 1 # XML based resource system
84 BUILD_GIZMOS
= 1 # Build a module for the gizmos contrib library
85 BUILD_DLLWIDGET
= 0# Build a module that enables unknown wx widgets
86 # to be loaded from a DLL and to be used from Python.
88 # Internet Explorer wrapper (experimental)
89 BUILD_IEWIN
= (os
.name
== 'nt')
90 BUILD_ACTIVEX
= (os
.name
== 'nt') # new version of IEWIN
93 CORE_ONLY
= 0 # if true, don't build any of the above
95 PREP_ONLY
= 0 # Only run the prepatory steps, not the actual build.
97 USE_SWIG
= 0 # Should we actually execute SWIG, or just use the
98 # files already in the distribution?
100 SWIG
= "swig" # The swig executable to use.
102 BUILD_RENAMERS
= 1 # Should we build the renamer modules too?
104 UNICODE
= 0 # This will pass the 'wxUSE_UNICODE' flag to SWIG and
105 # will ensure that the right headers are found and the
106 # right libs are linked.
108 UNDEF_NDEBUG
= 1 # Python 2.2 on Unix/Linux by default defines NDEBUG,
109 # and distutils will pick this up and use it on the
110 # compile command-line for the extensions. This could
111 # conflict with how wxWidgets was built. If NDEBUG is
112 # set then wxWidgets' __WXDEBUG__ setting will be turned
113 # off. If wxWidgets was actually built with it turned
114 # on then you end up with mismatched class structures,
115 # and wxPython will crash.
117 NO_SCRIPTS
= 0 # Don't install the tool scripts
118 NO_HEADERS
= 0 # Don't install the wxPython *.h and *.i files
120 WX_CONFIG
= None # Usually you shouldn't need to touch this, but you can set
121 # it to pass an alternate version of wx-config or alternate
122 # flags, eg. as required by the .deb in-tree build. By
123 # default a wx-config command will be assembled based on
124 # version, port, etc. and it will be looked for on the
127 WXPORT
= 'gtk' # On Linux/Unix there are several ports of wxWidgets available.
128 # Setting this value lets you select which will be used for
129 # the wxPython build. Possibilites are 'gtk', 'gtk2' and
130 # 'x11'. Curently only gtk and gtk2 works.
132 BUILD_BASE
= "build" # Directory to use for temporary build files.
133 # This name will be appended to if the WXPORT or
134 # the UNICODE flags are set to non-standard
138 CONTRIBS_INC
= "" # A dir to add as an -I flag when compiling the contribs
141 # Some MSW build settings
143 FINAL
= 0 # Mirrors use of same flag in wx makefiles,
144 # (0 or 1 only) should probably find a way to
147 HYBRID
= 1 # If set and not debug or FINAL, then build a
148 # hybrid extension that can be used by the
149 # non-debug version of python, but contains
150 # debugging symbols for wxWidgets and wxPython.
151 # wxWidgets must have been built with /MD, not /MDd
152 # (using FINAL=hybrid will do it.)
154 # Version part of wxWidgets LIB/DLL names
155 WXDLLVER
= '%d%d' % (VER_MAJOR
, VER_MINOR
)
158 #----------------------------------------------------------------------
161 if sys
.setup_is_main
:
166 path
= apply(os
.path
.join
, args
)
167 return os
.path
.normpath(path
)
182 #----------------------------------------------------------------------
184 #----------------------------------------------------------------------
191 force
= '--force' in sys
.argv
or '-f' in sys
.argv
192 debug
= '--debug' in sys
.argv
or '-g' in sys
.argv
193 cleaning
= 'clean' in sys
.argv
196 # change the PORT default for wxMac
197 if sys
.platform
[:6] == "darwin":
200 # and do the same for wxMSW, just for consistency
205 #----------------------------------------------------------------------
206 # Check for build flags on the command line
207 #----------------------------------------------------------------------
209 # Boolean (int) flags
210 for flag
in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'BUILD_XRC',
211 'BUILD_GIZMOS', 'BUILD_DLLWIDGET', 'BUILD_IEWIN', 'BUILD_ACTIVEX',
212 'CORE_ONLY', 'PREP_ONLY', 'USE_SWIG', 'UNICODE',
213 'UNDEF_NDEBUG', 'NO_SCRIPTS', 'NO_HEADERS', 'BUILD_RENAMERS',
214 'FINAL', 'HYBRID', ]:
215 for x
in range(len(sys
.argv
)):
216 if sys
.argv
[x
].find(flag
) == 0:
217 pos
= sys
.argv
[x
].find('=') + 1
219 vars()[flag
] = eval(sys
.argv
[x
][pos
:])
223 for option
in ['WX_CONFIG', 'WXDLLVER', 'BUILD_BASE', 'WXPORT', 'SWIG',
225 for x
in range(len(sys
.argv
)):
226 if sys
.argv
[x
].find(option
) == 0:
227 pos
= sys
.argv
[x
].find('=') + 1
229 vars()[option
] = sys
.argv
[x
][pos
:]
232 sys
.argv
= filter(None, sys
.argv
)
235 #----------------------------------------------------------------------
236 # some helper functions
237 #----------------------------------------------------------------------
239 def Verify_WX_CONFIG():
240 """ Called below for the builds that need wx-config,
241 if WX_CONFIG is not set then tries to select the specific
242 wx*-config script based on build options. If not found
243 then it defaults to 'wx-config'.
245 # if WX_CONFIG hasn't been set to an explicit value then construct one.
247 if WX_CONFIG
is None:
248 if debug
: # TODO: Fix this. wxPython's --debug shouldn't be tied to wxWidgets...
256 ver2
= "%s.%s" % (VER_MAJOR
, VER_MINOR
)
260 WX_CONFIG
= 'wx%s%s%s-%s-config' % (port
, uf
, df
, ver2
)
262 searchpath
= os
.environ
["PATH"]
263 for p
in searchpath
.split(':'):
264 fp
= os
.path
.join(p
, WX_CONFIG
)
265 if os
.path
.exists(fp
) and os
.access(fp
, os
.X_OK
):
267 msg("Found wx-config: " + fp
)
271 msg("WX_CONFIG not specified and %s not found on $PATH "
272 "defaulting to \"wx-config\"" % WX_CONFIG
)
273 WX_CONFIG
= 'wx-config'
277 def run_swig(files
, dir, gendir
, package
, USE_SWIG
, force
, swig_args
, swig_deps
=[]):
278 """Run SWIG the way I want it done"""
280 if USE_SWIG
and not os
.path
.exists(os
.path
.join(dir, gendir
)):
281 os
.mkdir(os
.path
.join(dir, gendir
))
283 if USE_SWIG
and not os
.path
.exists(os
.path
.join("docs", "xml-raw")):
284 os
.mkdir(os
.path
.join("docs", "xml-raw"))
289 basefile
= os
.path
.splitext(file)[0]
290 i_file
= os
.path
.join(dir, file)
291 py_file
= os
.path
.join(dir, gendir
, basefile
+'.py')
292 cpp_file
= os
.path
.join(dir, gendir
, basefile
+'_wrap.cpp')
293 xml_file
= os
.path
.join("docs", "xml-raw", basefile
+'_swig.xml')
295 sources
.append(cpp_file
)
297 if not cleaning
and USE_SWIG
:
298 for dep
in swig_deps
:
299 if newer(dep
, py_file
) or newer(dep
, cpp_file
):
303 if force
or newer(i_file
, py_file
) or newer(i_file
, cpp_file
):
304 ## we need forward slashes here even on win32
305 #cpp_file = opj(cpp_file) #'/'.join(cpp_file.split('\\'))
306 #i_file = opj(i_file) #'/'.join(i_file.split('\\'))
309 #tempfile.tempdir = sourcePath
310 xmltemp
= tempfile
.mktemp('.xml')
312 # First run swig to produce the XML file, adding
313 # an extra -D that prevents the old rename
314 # directives from being used
315 cmd
= [ swig_cmd
] + swig_args
+ \
316 [ '-DBUILDING_RENAMERS', '-xmlout', xmltemp
] + \
317 ['-I'+dir, '-o', cpp_file
, i_file
]
321 # Next run build_renamers to process the XML
322 cmd
= [ sys
.executable
, '-u',
323 './distrib/build_renamers.py', dir, basefile
, xmltemp
]
328 # Then run swig for real
329 cmd
= [ swig_cmd
] + swig_args
+ ['-I'+dir, '-o', cpp_file
,
330 '-xmlout', xml_file
, i_file
]
335 # copy the generated python file to the package directory
336 copy_file(py_file
, package
, update
=not force
, verbose
=0)
337 CLEANUP
.append(opj(package
, os
.path
.basename(py_file
)))
343 # Specializations of some distutils command classes
344 class wx_smart_install_data(distutils
.command
.install_data
.install_data
):
345 """need to change self.install_dir to the actual library dir"""
347 install_cmd
= self
.get_finalized_command('install')
348 self
.install_dir
= getattr(install_cmd
, 'install_lib')
349 return distutils
.command
.install_data
.install_data
.run(self
)
352 class wx_extra_clean(distutils
.command
.clean
.clean
):
354 Also cleans stuff that this setup.py copies itself. If the
355 --all flag was used also searches for .pyc, .pyd, .so files
358 from distutils
import log
359 from distutils
.filelist
import FileList
362 distutils
.command
.clean
.clean
.run(self
)
366 fl
.include_pattern("*.pyc", 0)
367 fl
.include_pattern("*.pyd", 0)
368 fl
.include_pattern("*.so", 0)
374 if not self
.dry_run
and os
.path
.exists(f
):
376 log
.info("removing '%s'", f
)
378 log
.warning("unable to remove '%s'", f
)
382 if not self
.dry_run
and os
.path
.exists(f
):
384 log
.info("removing '%s'", f
)
386 log
.warning("unable to remove '%s'", f
)
390 class wx_install_headers(distutils
.command
.install_headers
.install_headers
):
392 Install the header files to the WXPREFIX, with an extra dir per
395 def initialize_options (self
):
397 distutils
.command
.install_headers
.install_headers
.initialize_options(self
)
399 def finalize_options (self
):
400 self
.set_undefined_options('install', ('root', 'root'))
401 distutils
.command
.install_headers
.install_headers
.finalize_options(self
)
406 headers
= self
.distribution
.headers
411 if WXPREFIX
.startswith(root
):
413 for header
, location
in headers
:
414 install_dir
= os
.path
.normpath(root
+ WXPREFIX
+ location
)
415 self
.mkpath(install_dir
)
416 (out
, _
) = self
.copy_file(header
, install_dir
)
417 self
.outfiles
.append(out
)
422 def build_locale_dir(destdir
, verbose
=1):
423 """Build a locale dir under the wxPython package for MSW"""
424 moFiles
= glob
.glob(opj(WXDIR
, 'locale', '*.mo'))
426 lang
= os
.path
.splitext(os
.path
.basename(src
))[0]
427 dest
= opj(destdir
, lang
, 'LC_MESSAGES')
428 mkpath(dest
, verbose
=verbose
)
429 copy_file(src
, opj(dest
, 'wxstd.mo'), update
=1, verbose
=verbose
)
430 CLEANUP
.append(opj(dest
, 'wxstd.mo'))
434 def build_locale_list(srcdir
):
435 # get a list of all files under the srcdir, to be used for install_data
436 def walk_helper(lst
, dirname
, files
):
438 filename
= opj(dirname
, f
)
439 if not os
.path
.isdir(filename
):
440 lst
.append( (dirname
, [filename
]) )
442 os
.path
.walk(srcdir
, walk_helper
, file_list
)
446 def find_data_files(srcdir
, *wildcards
):
447 # get a list of all files under the srcdir matching wildcards,
448 # returned in a format to be used for install_data
450 def walk_helper(arg
, dirname
, files
):
455 filename
= opj(dirname
, f
)
456 if fnmatch
.fnmatch(filename
, wc
) and not os
.path
.isdir(filename
):
457 names
.append(filename
)
459 lst
.append( (dirname
, names
) )
462 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
466 def makeLibName(name
):
467 if os
.name
== 'posix':
468 libname
= '%s_%s-%s' % (WXBASENAME
, name
, WXRELEASE
)
470 libname
= 'wxmsw%s%s_%s' % (WXDLLVER
, libFlag(), name
)
476 def adjustCFLAGS(cflags
, defines
, includes
):
477 '''Extrace the raw -I, -D, and -U flags and put them into
478 defines and includes as needed.'''
482 includes
.append(flag
[2:])
483 elif flag
[:2] == '-D':
485 if flag
.find('=') == -1:
486 defines
.append( (flag
, None) )
488 defines
.append( tuple(flag
.split('=')) )
489 elif flag
[:2] == '-U':
490 defines
.append( (flag
[2:], ) )
492 newCFLAGS
.append(flag
)
497 def adjustLFLAGS(lfags
, libdirs
, libs
):
498 '''Extrace the -L and -l flags and put them in libdirs and libs as needed'''
502 libdirs
.append(flag
[2:])
503 elif flag
[:2] == '-l':
504 libs
.append(flag
[2:])
506 newLFLAGS
.append(flag
)
510 #----------------------------------------------------------------------
530 if UNICODE
and WXPORT
not in ['msw', 'gtk2']:
531 raise SystemExit, "UNICODE mode not currently supported on this WXPORT: "+WXPORT
535 CONTRIBS_INC
= [ CONTRIBS_INC
]
540 #----------------------------------------------------------------------
541 # Setup some platform specific stuff
542 #----------------------------------------------------------------------
545 # Set compile flags and such for MSVC. These values are derived
546 # from the wxWidgets makefiles for MSVC, other compilers settings
547 # will probably vary...
548 if os
.environ
.has_key('WXWIN'):
549 WXDIR
= os
.environ
['WXWIN']
551 msg("WARNING: WXWIN not set in environment.")
552 WXDIR
= '..' # assumes in CVS tree
556 includes
= ['include', 'src',
557 opj(WXDIR
, 'lib', 'vc_dll', 'msw' + libFlag()),
558 opj(WXDIR
, 'include'),
559 opj(WXDIR
, 'contrib', 'include'),
562 defines
= [ ('WIN32', None),
568 ('SWIG_GLOBAL', None),
569 ('WXP_USE_THREAD', '1'),
573 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
576 defines
.append( ('__NO_VC_CRTDBG__', None) )
578 if not FINAL
or HYBRID
:
579 defines
.append( ('__WXDEBUG__', None) )
581 libdirs
= [ opj(WXDIR
, 'lib', 'vc_dll') ]
582 libs
= [ 'wxbase' + WXDLLVER
+ libFlag(), # TODO: trim this down to what is really needed for the core
583 'wxbase' + WXDLLVER
+ libFlag() + '_net',
584 'wxbase' + WXDLLVER
+ libFlag() + '_xml',
585 makeLibName('core')[0],
586 makeLibName('adv')[0],
587 makeLibName('html')[0],
590 libs
= libs
+ ['kernel32', 'user32', 'gdi32', 'comdlg32',
591 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
592 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
593 'advapi32', 'wsock32']
597 # '/GX-' # workaround for internal compiler error in MSVC on some machines
601 # Other MSVC flags...
602 # Too bad I don't remember why I was playing with these, can they be removed?
604 pass #cflags = cflags + ['/O1']
606 pass #cflags = cflags + ['/Ox']
608 pass # cflags = cflags + ['/Od', '/Z7']
609 # lflags = ['/DEBUG', ]
613 #----------------------------------------------------------------------
615 elif os
.name
== 'posix':
617 includes
= ['include', 'src']
618 defines
= [('SWIG_GLOBAL', None),
619 ('HAVE_CONFIG_H', None),
620 ('WXP_USE_THREAD', '1'),
623 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
630 # If you get unresolved symbol errors on Solaris and are using gcc, then
631 # uncomment this block to add the right flags to the link step and build
633 ## if os.uname()[0] == 'SunOS':
634 ## libs.append('gcc')
635 ## libdirs.append(commands.getoutput("gcc -print-search-dirs | grep '^install' | awk '{print $2}'")[:-1])
637 cflags
= os
.popen(WX_CONFIG
+ ' --cxxflags', 'r').read()[:-1]
638 cflags
= cflags
.split()
645 lflags
= os
.popen(WX_CONFIG
+ ' --libs', 'r').read()[:-1]
646 lflags
= lflags
.split()
648 WXBASENAME
= os
.popen(WX_CONFIG
+ ' --basename').read()[:-1]
649 WXRELEASE
= os
.popen(WX_CONFIG
+ ' --release').read()[:-1]
650 WXPREFIX
= os
.popen(WX_CONFIG
+ ' --prefix').read()[:-1]
653 if sys
.platform
[:6] == "darwin":
654 # Flags and such for a Darwin (Max OS X) build of Python
662 # Set flags for other Unix type platforms
667 portcfg
= os
.popen('gtk-config --cflags', 'r').read()[:-1]
668 elif WXPORT
== 'gtk2':
670 GENDIR
= 'gtk' # no code differences so use the same generated sources
671 portcfg
= os
.popen('pkg-config gtk+-2.0 --cflags', 'r').read()[:-1]
672 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
673 elif WXPORT
== 'x11':
676 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
678 raise SystemExit, "Unknown WXPORT value: " + WXPORT
680 cflags
+= portcfg
.split()
682 # Some distros (e.g. Mandrake) put libGLU in /usr/X11R6/lib, but
683 # wx-config doesn't output that for some reason. For now, just
684 # add it unconditionally but we should really check if the lib is
685 # really found there or wx-config should be fixed.
686 libdirs
.append("/usr/X11R6/lib")
689 # Move the various -I, -D, etc. flags we got from the *config scripts
690 # into the distutils lists.
691 cflags
= adjustCFLAGS(cflags
, defines
, includes
)
692 lflags
= adjustLFLAGS(lflags
, libdirs
, libs
)
695 #----------------------------------------------------------------------
697 raise 'Sorry, platform not supported...'
700 #----------------------------------------------------------------------
701 # post platform setup checks and tweaks, create the full version string
702 #----------------------------------------------------------------------
705 BUILD_BASE
= BUILD_BASE
+ '.unicode'
709 VERSION
= "%s.%s.%s.%s%s" % (VER_MAJOR
, VER_MINOR
, VER_RELEASE
,
710 VER_SUBREL
, VER_FLAGS
)
713 #----------------------------------------------------------------------
715 #----------------------------------------------------------------------
733 swig_args
.append('-DwxUSE_UNICODE')
735 swig_deps
= [ 'src/my_typemaps.i',
740 depends
= [ #'include/wx/wxPython/wxPython.h',
741 #'include/wx/wxPython/wxPython_int.h',
745 #----------------------------------------------------------------------