]>
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
= 6 # wxPython release num for x.y.z release of wxWidgets
42 VER_FLAGS
= "p" # 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 and more
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 hasattr(sys
, 'setup_is_main') and 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
,
278 swig_deps
=[], add_under
=False):
279 """Run SWIG the way I want it done"""
281 if USE_SWIG
and not os
.path
.exists(os
.path
.join(dir, gendir
)):
282 os
.mkdir(os
.path
.join(dir, gendir
))
284 if USE_SWIG
and not os
.path
.exists(os
.path
.join("docs", "xml-raw")):
285 os
.mkdir(os
.path
.join("docs", "xml-raw"))
289 if add_under
: pre
= '_'
293 basefile
= os
.path
.splitext(file)[0]
294 i_file
= os
.path
.join(dir, file)
295 py_file
= os
.path
.join(dir, gendir
, pre
+basefile
+'.py')
296 cpp_file
= os
.path
.join(dir, gendir
, pre
+basefile
+'_wrap.cpp')
297 xml_file
= os
.path
.join("docs", "xml-raw", basefile
+'_swig.xml')
300 interface
= ['-interface', '_'+basefile
+'_']
304 sources
.append(cpp_file
)
306 if not cleaning
and USE_SWIG
:
307 for dep
in swig_deps
:
308 if newer(dep
, py_file
) or newer(dep
, cpp_file
):
312 if force
or newer(i_file
, py_file
) or newer(i_file
, cpp_file
):
313 ## we need forward slashes here even on win32
314 #cpp_file = opj(cpp_file) #'/'.join(cpp_file.split('\\'))
315 #i_file = opj(i_file) #'/'.join(i_file.split('\\'))
318 #tempfile.tempdir = sourcePath
319 xmltemp
= tempfile
.mktemp('.xml')
321 # First run swig to produce the XML file, adding
322 # an extra -D that prevents the old rename
323 # directives from being used
324 cmd
= [ swig_cmd
] + swig_args
+ \
325 [ '-DBUILDING_RENAMERS', '-xmlout', xmltemp
] + \
326 ['-I'+dir, '-o', cpp_file
, i_file
]
330 # Next run build_renamers to process the XML
331 cmd
= [ sys
.executable
, '-u',
332 './distrib/build_renamers.py', dir, pre
+basefile
, xmltemp
]
337 # Then run swig for real
338 cmd
= [ swig_cmd
] + swig_args
+ interface
+ \
339 ['-I'+dir, '-o', cpp_file
, '-xmlout', xml_file
, i_file
]
344 # copy the generated python file to the package directory
345 copy_file(py_file
, package
, update
=not force
, verbose
=0)
346 CLEANUP
.append(opj(package
, os
.path
.basename(py_file
)))
352 # Specializations of some distutils command classes
353 class wx_smart_install_data(distutils
.command
.install_data
.install_data
):
354 """need to change self.install_dir to the actual library dir"""
356 install_cmd
= self
.get_finalized_command('install')
357 self
.install_dir
= getattr(install_cmd
, 'install_lib')
358 return distutils
.command
.install_data
.install_data
.run(self
)
361 class wx_extra_clean(distutils
.command
.clean
.clean
):
363 Also cleans stuff that this setup.py copies itself. If the
364 --all flag was used also searches for .pyc, .pyd, .so files
367 from distutils
import log
368 from distutils
.filelist
import FileList
371 distutils
.command
.clean
.clean
.run(self
)
375 fl
.include_pattern("*.pyc", 0)
376 fl
.include_pattern("*.pyd", 0)
377 fl
.include_pattern("*.so", 0)
383 if not self
.dry_run
and os
.path
.exists(f
):
385 log
.info("removing '%s'", f
)
387 log
.warning("unable to remove '%s'", f
)
391 if not self
.dry_run
and os
.path
.exists(f
):
393 log
.info("removing '%s'", f
)
395 log
.warning("unable to remove '%s'", f
)
399 class wx_install_headers(distutils
.command
.install_headers
.install_headers
):
401 Install the header files to the WXPREFIX, with an extra dir per
404 def initialize_options (self
):
406 distutils
.command
.install_headers
.install_headers
.initialize_options(self
)
408 def finalize_options (self
):
409 self
.set_undefined_options('install', ('root', 'root'))
410 distutils
.command
.install_headers
.install_headers
.finalize_options(self
)
415 headers
= self
.distribution
.headers
420 if root
is None or WXPREFIX
.startswith(root
):
422 for header
, location
in headers
:
423 install_dir
= os
.path
.normpath(root
+ WXPREFIX
+ location
)
424 self
.mkpath(install_dir
)
425 (out
, _
) = self
.copy_file(header
, install_dir
)
426 self
.outfiles
.append(out
)
431 def build_locale_dir(destdir
, verbose
=1):
432 """Build a locale dir under the wxPython package for MSW"""
433 moFiles
= glob
.glob(opj(WXDIR
, 'locale', '*.mo'))
435 lang
= os
.path
.splitext(os
.path
.basename(src
))[0]
436 dest
= opj(destdir
, lang
, 'LC_MESSAGES')
437 mkpath(dest
, verbose
=verbose
)
438 copy_file(src
, opj(dest
, 'wxstd.mo'), update
=1, verbose
=verbose
)
439 CLEANUP
.append(opj(dest
, 'wxstd.mo'))
443 def build_locale_list(srcdir
):
444 # get a list of all files under the srcdir, to be used for install_data
445 def walk_helper(lst
, dirname
, files
):
447 filename
= opj(dirname
, f
)
448 if not os
.path
.isdir(filename
):
449 lst
.append( (dirname
, [filename
]) )
451 os
.path
.walk(srcdir
, walk_helper
, file_list
)
455 def find_data_files(srcdir
, *wildcards
):
456 # get a list of all files under the srcdir matching wildcards,
457 # returned in a format to be used for install_data
459 def walk_helper(arg
, dirname
, files
):
464 filename
= opj(dirname
, f
)
465 if fnmatch
.fnmatch(filename
, wc
) and not os
.path
.isdir(filename
):
466 names
.append(filename
)
468 lst
.append( (dirname
, names
) )
471 os
.path
.walk(srcdir
, walk_helper
, (file_list
, wildcards
))
475 def makeLibName(name
):
476 if os
.name
== 'posix':
477 libname
= '%s_%s-%s' % (WXBASENAME
, name
, WXRELEASE
)
479 libname
= 'wxmsw%s%s_%s' % (WXDLLVER
, libFlag(), name
)
485 def adjustCFLAGS(cflags
, defines
, includes
):
486 '''Extrace the raw -I, -D, and -U flags and put them into
487 defines and includes as needed.'''
491 includes
.append(flag
[2:])
492 elif flag
[:2] == '-D':
494 if flag
.find('=') == -1:
495 defines
.append( (flag
, None) )
497 defines
.append( tuple(flag
.split('=')) )
498 elif flag
[:2] == '-U':
499 defines
.append( (flag
[2:], ) )
501 newCFLAGS
.append(flag
)
506 def adjustLFLAGS(lfags
, libdirs
, libs
):
507 '''Extrace the -L and -l flags and put them in libdirs and libs as needed'''
511 libdirs
.append(flag
[2:])
512 elif flag
[:2] == '-l':
513 libs
.append(flag
[2:])
515 newLFLAGS
.append(flag
)
519 #----------------------------------------------------------------------
539 if UNICODE
and WXPORT
not in ['msw', 'gtk2']:
540 raise SystemExit, "UNICODE mode not currently supported on this WXPORT: "+WXPORT
544 CONTRIBS_INC
= [ CONTRIBS_INC
]
549 #----------------------------------------------------------------------
550 # Setup some platform specific stuff
551 #----------------------------------------------------------------------
554 # Set compile flags and such for MSVC. These values are derived
555 # from the wxWidgets makefiles for MSVC, other compilers settings
556 # will probably vary...
557 if os
.environ
.has_key('WXWIN'):
558 WXDIR
= os
.environ
['WXWIN']
560 msg("WARNING: WXWIN not set in environment.")
561 WXDIR
= '..' # assumes in CVS tree
565 includes
= ['include', 'src',
566 opj(WXDIR
, 'lib', 'vc_dll', 'msw' + libFlag()),
567 opj(WXDIR
, 'include'),
568 opj(WXDIR
, 'contrib', 'include'),
571 defines
= [ ('WIN32', None),
577 ('SWIG_GLOBAL', None),
578 ('WXP_USE_THREAD', '1'),
582 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
585 defines
.append( ('__NO_VC_CRTDBG__', None) )
587 if not FINAL
or HYBRID
:
588 defines
.append( ('__WXDEBUG__', None) )
590 libdirs
= [ opj(WXDIR
, 'lib', 'vc_dll') ]
591 libs
= [ 'wxbase' + WXDLLVER
+ libFlag(), # TODO: trim this down to what is really needed for the core
592 'wxbase' + WXDLLVER
+ libFlag() + '_net',
593 'wxbase' + WXDLLVER
+ libFlag() + '_xml',
594 makeLibName('core')[0],
595 makeLibName('adv')[0],
596 makeLibName('html')[0],
599 libs
= libs
+ ['kernel32', 'user32', 'gdi32', 'comdlg32',
600 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
601 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
602 'advapi32', 'wsock32']
606 # '/GX-' # workaround for internal compiler error in MSVC on some machines
610 # Other MSVC flags...
611 # Too bad I don't remember why I was playing with these, can they be removed?
613 pass #cflags = cflags + ['/O1']
615 pass #cflags = cflags + ['/Ox']
617 pass # cflags = cflags + ['/Od', '/Z7']
618 # lflags = ['/DEBUG', ]
622 #----------------------------------------------------------------------
624 elif os
.name
== 'posix':
626 includes
= ['include', 'src']
627 defines
= [('SWIG_GLOBAL', None),
628 ('HAVE_CONFIG_H', None),
629 ('WXP_USE_THREAD', '1'),
632 defines
.append( ('NDEBUG',) ) # using a 1-tuple makes it do an undef
639 # If you get unresolved symbol errors on Solaris and are using gcc, then
640 # uncomment this block to add the right flags to the link step and build
642 ## if os.uname()[0] == 'SunOS':
643 ## libs.append('gcc')
644 ## libdirs.append(commands.getoutput("gcc -print-search-dirs | grep '^install' | awk '{print $2}'")[:-1])
646 cflags
= os
.popen(WX_CONFIG
+ ' --cxxflags', 'r').read()[:-1]
647 cflags
= cflags
.split()
654 lflags
= os
.popen(WX_CONFIG
+ ' --libs', 'r').read()[:-1]
655 lflags
= lflags
.split()
657 WXBASENAME
= os
.popen(WX_CONFIG
+ ' --basename').read()[:-1]
658 WXRELEASE
= os
.popen(WX_CONFIG
+ ' --release').read()[:-1]
659 WXPREFIX
= os
.popen(WX_CONFIG
+ ' --prefix').read()[:-1]
662 if sys
.platform
[:6] == "darwin":
663 # Flags and such for a Darwin (Max OS X) build of Python
671 # Set flags for other Unix type platforms
676 portcfg
= os
.popen('gtk-config --cflags', 'r').read()[:-1]
677 elif WXPORT
== 'gtk2':
679 GENDIR
= 'gtk' # no code differences so use the same generated sources
680 portcfg
= os
.popen('pkg-config gtk+-2.0 --cflags', 'r').read()[:-1]
681 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
682 elif WXPORT
== 'x11':
685 BUILD_BASE
= BUILD_BASE
+ '-' + WXPORT
687 raise SystemExit, "Unknown WXPORT value: " + WXPORT
689 cflags
+= portcfg
.split()
691 # Some distros (e.g. Mandrake) put libGLU in /usr/X11R6/lib, but
692 # wx-config doesn't output that for some reason. For now, just
693 # add it unconditionally but we should really check if the lib is
694 # really found there or wx-config should be fixed.
695 libdirs
.append("/usr/X11R6/lib")
698 # Move the various -I, -D, etc. flags we got from the *config scripts
699 # into the distutils lists.
700 cflags
= adjustCFLAGS(cflags
, defines
, includes
)
701 lflags
= adjustLFLAGS(lflags
, libdirs
, libs
)
704 #----------------------------------------------------------------------
706 raise 'Sorry, platform not supported...'
709 #----------------------------------------------------------------------
710 # post platform setup checks and tweaks, create the full version string
711 #----------------------------------------------------------------------
714 BUILD_BASE
= BUILD_BASE
+ '.unicode'
718 VERSION
= "%s.%s.%s.%s%s" % (VER_MAJOR
, VER_MINOR
, VER_RELEASE
,
719 VER_SUBREL
, VER_FLAGS
)
722 #----------------------------------------------------------------------
724 #----------------------------------------------------------------------
742 swig_args
.append('-DwxUSE_UNICODE')
744 swig_deps
= [ 'src/my_typemaps.i',
749 depends
= [ #'include/wx/wxPython/wxPython.h',
750 #'include/wx/wxPython/wxPython_int.h',
754 #----------------------------------------------------------------------