]> git.saurik.com Git - wxWidgets.git/blame - wxPython/setup.py
Some Unicode compilation fixes. This Unicode stuff in file functions is
[wxWidgets.git] / wxPython / setup.py
CommitLineData
c368d904
RD
1#!/usr/bin/env python
2#----------------------------------------------------------------------
3
4import sys, os, string
5from distutils.core import setup, Extension
6from distutils.file_util import copy_file
7from distutils.dir_util import mkpath
8from distutils.dep_util import newer
9
10from my_distutils import run_swig, contrib_copy_tree
11
12#----------------------------------------------------------------------
13# flags and values that affect this script
14#----------------------------------------------------------------------
15
1b62f00d 16VERSION = "2.3b3"
c368d904
RD
17DESCRIPTION = "Cross platform GUI toolkit for Python"
18AUTHOR = "Robin Dunn"
19AUTHOR_EMAIL = "robin@alldunn.com"
20URL = "http://wxPython.org/"
21LICENCE = "wxWindows (LGPL derivative)"
22LONG_DESCRIPTION = """\
23wxPython is a GUI toolkit for Python that is a wrapper around the
24wxWindows C++ GUI library. wxPython provides a large variety of
1b62f00d 25window types and controls, all implemented with a native look and
c368d904
RD
26feel (and native runtime speed) on the platforms it is supported
27on.
28"""
29
30
31BUILD_GLCANVAS = 1 # If true, build the contrib/glcanvas extension module
32BUILD_OGL = 1 # If true, build the contrib/ogl extension module
33BUILD_STC = 1 # If true, build the contrib/stc extension module
34CORE_ONLY = 0 # if true, don't build any of the above
1b62f00d
RD
35GL_ONLY = 0 # Only used when making the -gl RPM. See the "b" script
36 # for the ugly details
c368d904
RD
37
38USE_SWIG = 0 # Should we actually execute SWIG, or just use the
39 # files already in the distribution?
40
41IN_CVS_TREE = 0 # Set to true if building in a full wxWindows CVS
42 # tree, otherwise will assume all needed files are
43 # available in the wxPython source distribution
44
afa3e1ed
RL
45WX_CONFIG = "wx-config" # Usually you shouldn't need to touch this,
46 # but you can set it to pass an alternate
47 # version of wx-config or alternate flags,
48 # eg. as required by the .deb in-tree build.
c368d904
RD
49
50# Some MSW build settings
51
52FINAL = 1 # Mirrors use of same flag in wx makefiles,
53 # (0 or 1 only) should probably find a way to
54 # autodetect this...
55
56HYBRID = 0 # If set and not debug or FINAL, then build a
57 # hybrid extension that can be used by the
58 # non-debug version of python, but contains
59 # debugging symbols for wxWindows and wxPython.
60 # wxWindows must have been built with /MD, not /MDd
61 # (using FINAL=hybrid will do it.)
62
63WXDLLVER = '23_0' # Version part of DLL name
64
65
66#----------------------------------------------------------------------
67# Some other globals
68#----------------------------------------------------------------------
69
70PKGDIR = 'wxPython'
71wxpExtensions = []
72
73force = '--force' in sys.argv or '-f' in sys.argv
74debug = '--debug' in sys.argv or '-g' in sys.argv
75
76
77#----------------------------------------------------------------------
78# Check for build flags on the command line
79#----------------------------------------------------------------------
80
81for flag in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'CORE_ONLY',
afa3e1ed 82 'USE_SWIG', 'IN_CVS_TREE', 'FINAL', 'HYBRID', ]:
c368d904
RD
83 for x in range(len(sys.argv)):
84 if string.find(sys.argv[x], flag) == 0:
85 pos = string.find(sys.argv[x], '=') + 1
86 if pos > 0:
87 vars()[flag] = eval(sys.argv[x][pos:])
88 sys.argv[x] = ''
89
afa3e1ed
RL
90for option in ['WX_CONFIG', 'WXDLLVER', ]:
91 for x in range(len(sys.argv)):
92 if string.find(sys.argv[x], option) == 0:
93 pos = string.find(sys.argv[x], '=') + 1
94 if pos > 0:
95 vars()[option] = sys.argv[x][pos:]
96 sys.argv[x] = ''
97
c368d904
RD
98sys.argv = filter(None, sys.argv)
99
100
101if CORE_ONLY:
102 BUILD_GLCANVAS = 0
103 BUILD_OGL = 0
104 BUILD_STC = 0
105
106#----------------------------------------------------------------------
107# Setup some platform specific stuff
108#----------------------------------------------------------------------
109
110if os.name == 'nt':
111 # Set compile flags and such for MSVC. These values are derived
112 # from the wxWindows makefiles for MSVC, others will probably
113 # vary...
114 WXDIR = os.environ['WXWIN']
115 WXPLAT = '__WXMSW__'
116 GENDIR = 'msw'
117
c368d904
RD
118 if debug:
119 FINAL = 0
120 HYBRID = 0
121
122 if HYBRID:
123 FINAL = 0
124
c368d904
RD
125 includes = ['src',
126 os.path.join(WXDIR, 'include'),
127 ]
128
129 defines = [ ('WIN32', None), # Some of these are no longer
130 ('__WIN32__', None), # necessary. Anybody know which?
131 ('_WINDOWS', None),
132 ('__WINDOWS__', None),
133 ('WINVER', '0x0400'),
134 ('__WIN95__', None),
135 ('STRICT', None),
136
137 (WXPLAT, None),
138 ('WXUSINGDLL', '1'),
139
140 ('SWIG_GLOBAL', None),
141 ('HAVE_CONFIG_H', None),
142 ('WXP_USE_THREAD', '1'),
143 ]
144
145 if not FINAL or HYBRID:
146 defines.append( ('__WXDEBUG__', None) )
147
148 libdirs = [os.path.join(WXDIR, 'lib'), 'build\\ilib']
149
150 if FINAL:
151 wxdll = 'wx' + WXDLLVER
152 elif HYBRID:
153 wxdll = 'wx' + WXDLLVER + 'h'
154 else:
155 wxdll = 'wx' + WXDLLVER + 'd'
156
c368d904
RD
157
158 libs = [wxdll, 'kernel32', 'user32', 'gdi32', 'comdlg32',
159 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
160 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
161 'advapi32', 'wsock32']
162
1e7ecb7b 163 cflags = ['/GX-'] # workaround for internal compiler error in MSVC 5
c368d904
RD
164 lflags = None
165
166 if not FINAL and HYBRID:
e7d63784
RD
167 cflags = cflags + ['/Od', '/Z7']
168 lflags = ['/DEBUG', ]
c368d904
RD
169
170
171elif os.name == 'posix':
172 # Set flags for Unix type platforms
173
174 WXDIR = '..' # assumes IN_CVS_TREE
175 WXPLAT = '__WXGTK__' # and assumes GTK...
176 GENDIR = 'gtk' # Need to allow for Motif eventually too
177
178 includes = ['src']
179 defines = [('SWIG_GLOBAL', None),
180 ('HAVE_CONFIG_H', None),
181 ('WXP_USE_THREAD', '1'),
182 ]
183 libdirs = []
184 libs = []
185
afa3e1ed 186 cflags = os.popen(WX_CONFIG + ' --cflags', 'r').read()[:-1] + ' ' + \
c368d904
RD
187 os.popen('gtk-config --cflags', 'r').read()[:-1]
188 cflags = string.split(cflags)
189
afa3e1ed 190 lflags = os.popen(WX_CONFIG + ' --libs', 'r').read()[:-1]
c368d904
RD
191 lflags = string.split(lflags)
192
193
194else:
195 raise 'Sorry Charlie...'
196
197
198#----------------------------------------------------------------------
199# Check if the version file needs updated
200#----------------------------------------------------------------------
201
202if IN_CVS_TREE and newer('setup.py', 'src/__version__.py'):
203 open('src/__version__.py', 'w').write("ver = '%s'\n" % VERSION)
204
1b62f00d
RD
205
206
c368d904 207#----------------------------------------------------------------------
1b62f00d 208# SWIG defaults
c368d904
RD
209#----------------------------------------------------------------------
210
c368d904 211swig_force = force
de20db99 212swig_args = ['-c++', '-shadow', '-python', '-keyword', '-dnone', #'-dascii',
c368d904 213 '-I./src', '-D'+WXPLAT]
185d7c3e 214swig_deps = ['src/my_typemaps.i']
c368d904 215
c368d904 216
1b62f00d
RD
217#----------------------------------------------------------------------
218# Define the CORE extension module
219#----------------------------------------------------------------------
220
221if not GL_ONLY:
222 print 'Preparing CORE...'
223 swig_files = [ 'wx.i', 'windows.i', 'windows2.i', 'windows3.i', 'events.i',
224 'misc.i', 'misc2.i', 'gdi.i', 'mdi.i', 'controls.i',
225 'controls2.i', 'cmndlgs.i', 'stattool.i', 'frames.i', 'image.i',
226 'printfw.i', 'sizers.i', 'clip_dnd.i',
227 'filesys.i', 'streams.i',
228 ##'grid.i', 'html.i', 'htmlhelp.i', 'calendar.i', 'utils.i',
229 ]
c368d904 230
1b62f00d
RD
231 swig_sources = run_swig(swig_files, 'src', GENDIR, PKGDIR,
232 USE_SWIG, swig_force, swig_args, swig_deps)
c368d904 233
1b62f00d
RD
234 copy_file('src/__init__.py', PKGDIR, update=1, verbose=0)
235 copy_file('src/__version__.py', PKGDIR, update=1, verbose=0)
c368d904 236
c368d904 237
1b62f00d
RD
238 if IN_CVS_TREE: # update the licence files
239 mkpath('licence')
240 for file in ['preamble.txt', 'licence.txt', 'licendoc.txt', 'lgpl.txt']:
241 copy_file(WXDIR+'/docs/'+file, 'licence/'+file, update=1, verbose=0)
c368d904 242
1b62f00d
RD
243
244 if os.name == 'nt':
245 rc_file = ['src/wxc.rc']
246 else:
247 rc_file = []
248
249
250 ext = Extension('wxc', ['src/helpers.cpp',
251 'src/libpy.c',
252 ] + rc_file + swig_sources,
253
254 include_dirs = includes,
255 define_macros = defines,
256
257 library_dirs = libdirs,
258 libraries = libs,
259
260 extra_compile_args = cflags,
261 extra_link_args = lflags,
262 )
263 wxpExtensions.append(ext)
264
265
266 # Extension for the grid module
267 swig_sources = run_swig(['grid.i'], 'src', GENDIR, PKGDIR,
268 USE_SWIG, swig_force, swig_args, swig_deps)
269 ext = Extension('gridc', swig_sources,
270 include_dirs = includes,
271 define_macros = defines,
272 library_dirs = libdirs,
273 libraries = libs,
274 extra_compile_args = cflags,
275 extra_link_args = lflags,
276 )
277 wxpExtensions.append(ext)
278
279
280 # Extension for the html modules
281 swig_sources = run_swig(['html.i', 'htmlhelp.i'], 'src', GENDIR, PKGDIR,
282 USE_SWIG, swig_force, swig_args, swig_deps)
283 ext = Extension('htmlc', swig_sources,
284 include_dirs = includes,
285 define_macros = defines,
286 library_dirs = libdirs,
287 libraries = libs,
288 extra_compile_args = cflags,
289 extra_link_args = lflags,
290 )
291 wxpExtensions.append(ext)
292
293
294 # Extension for the utils module
295 swig_sources = run_swig(['utils.i'], 'src', GENDIR, PKGDIR,
296 USE_SWIG, swig_force, swig_args, swig_deps)
297 ext = Extension('utilsc', swig_sources,
298 include_dirs = includes,
299 define_macros = defines,
300 library_dirs = libdirs,
301 libraries = libs,
302 extra_compile_args = cflags,
303 extra_link_args = lflags,
304 )
305 wxpExtensions.append(ext)
306
307
308 # Extension for the calendar module
309 swig_sources = run_swig(['calendar.i'], 'src', GENDIR, PKGDIR,
310 USE_SWIG, swig_force, swig_args, swig_deps)
311 ext = Extension('calendarc', swig_sources,
312 include_dirs = includes,
313 define_macros = defines,
314 library_dirs = libdirs,
315 libraries = libs,
316 extra_compile_args = cflags,
317 extra_link_args = lflags,
318 )
319 wxpExtensions.append(ext)
c368d904 320
c368d904
RD
321
322#----------------------------------------------------------------------
323# Define the GLCanvas extension module
324#----------------------------------------------------------------------
325
1b62f00d 326if BUILD_GLCANVAS or GL_ONLY:
c368d904
RD
327 print 'Preparing GLCANVAS...'
328 location = 'contrib/glcanvas'
329 swig_files = ['glcanvas.i']
19cf4f80 330 other_sources = []
c368d904
RD
331
332 swig_sources = run_swig(swig_files, location, GENDIR, PKGDIR,
1e7ecb7b 333 USE_SWIG, swig_force, swig_args)
c368d904
RD
334
335 gl_libs = []
336 if os.name == 'posix':
337 if '-D__WXDEBUG__' in cflags:
338 gl_libs = ['wx_gtkd_gl', 'GL', 'GLU']
339 else:
340 gl_libs = ['wx_gtk_gl', 'GL', 'GLU']
19cf4f80
RD
341 else:
342 other_sources = [location + '/msw/myglcanvas.cpp']
343 gl_libs = ['opengl32', 'glu32']
344
c368d904 345
1e7ecb7b 346 ext = Extension('glcanvasc',
19cf4f80 347 swig_sources + other_sources,
1e7ecb7b
RD
348
349 include_dirs = includes,
350 define_macros = defines,
351
352 library_dirs = libdirs,
353 libraries = libs + gl_libs,
354
355 extra_compile_args = cflags,
356 extra_link_args = lflags,
357 )
358
359 wxpExtensions.append(ext)
c368d904
RD
360
361
362#----------------------------------------------------------------------
363# Define the OGL extension module
364#----------------------------------------------------------------------
365
1b62f00d 366if not GL_ONLY and BUILD_OGL:
c368d904
RD
367 print 'Preparing OGL...'
368 location = 'contrib/ogl'
369 OGLLOC = location + '/contrib/src/ogl'
370 OGLINC = location + '/contrib/include'
371
372 swig_files = ['ogl.i', 'oglbasic.i', 'oglshapes.i', 'oglshapes2.i',
373 'oglcanvas.i']
374
375 swig_sources = run_swig(swig_files, location, '', PKGDIR,
1e7ecb7b 376 USE_SWIG, swig_force, swig_args)
c368d904
RD
377
378 # make sure local copy of contrib files are up to date
379 if IN_CVS_TREE:
380 contrib_copy_tree(WXDIR + '/contrib/include/wx/ogl', OGLINC+'/wx/ogl')
381 contrib_copy_tree(WXDIR + '/contrib/src/ogl', OGLLOC)
382
1e7ecb7b
RD
383 ext = Extension('oglc', ['%s/basic.cpp' % OGLLOC,
384 '%s/bmpshape.cpp' % OGLLOC,
385 '%s/composit.cpp' % OGLLOC,
386 '%s/divided.cpp' % OGLLOC,
387 '%s/lines.cpp' % OGLLOC,
388 '%s/misc.cpp' % OGLLOC,
389 '%s/basic2.cpp' % OGLLOC,
390 '%s/canvas.cpp' % OGLLOC,
391 '%s/constrnt.cpp' % OGLLOC,
392 '%s/drawn.cpp' % OGLLOC,
393 '%s/mfutils.cpp' % OGLLOC,
394 '%s/ogldiag.cpp' % OGLLOC,
395 ] + swig_sources,
396
397 include_dirs = [OGLINC] + includes,
398 define_macros = defines,
399
400 library_dirs = libdirs,
401 libraries = libs,
402
403 extra_compile_args = cflags,
404 extra_link_args = lflags,
405 )
406
407 wxpExtensions.append(ext)
408
409
c368d904
RD
410
411#----------------------------------------------------------------------
412# Define the STC extension module
413#----------------------------------------------------------------------
414
1b62f00d 415if not GL_ONLY and BUILD_STC:
c368d904
RD
416 print 'Preparing STC...'
417 location = 'contrib/stc'
418 STCLOC = location + '/contrib/src/stc'
419 STCINC = location + '/contrib/include'
420 STC_H = location + '/contrib/include/wx/stc'
421
422 # make sure local copy of contrib files are up to date
423 if IN_CVS_TREE:
424 contrib_copy_tree(WXDIR + '/contrib/include/wx/stc', STCINC+'/wx/stc')
425 contrib_copy_tree(WXDIR + '/contrib/src/stc', STCLOC)
426
427
428 swig_files = ['stc_.i']
429 swig_sources = run_swig(swig_files, location, '', PKGDIR,
430 USE_SWIG, swig_force,
431 swig_args + ['-I'+STC_H, '-I'+location],
1e7ecb7b 432 [STC_H+'/stc.h'])
c368d904
RD
433
434 # copy a project specific py module to the main package dir
435 copy_file(location+'/stc.py', PKGDIR, update=1, verbose=1)
436
437 # add some include dirs to the standard set
1e7ecb7b
RD
438 stc_includes = includes[:]
439 stc_includes.append('%s/scintilla/include' % STCLOC)
440 stc_includes.append('%s/scintilla/src' % STCLOC)
441 stc_includes.append(STCINC)
c368d904
RD
442
443 # and some macro definitions
1e7ecb7b
RD
444 stc_defines = defines[:]
445 stc_defines.append( ('__WX__', None) )
446 stc_defines.append( ('SCI_LEXER', None) )
c368d904
RD
447
448
1e7ecb7b
RD
449 ext = Extension('stc_c',
450 ['%s/scintilla/src/AutoComplete.cxx' % STCLOC,
c368d904
RD
451 '%s/scintilla/src/CallTip.cxx' % STCLOC,
452 '%s/scintilla/src/CellBuffer.cxx' % STCLOC,
453 '%s/scintilla/src/ContractionState.cxx' % STCLOC,
454 '%s/scintilla/src/Document.cxx' % STCLOC,
455 '%s/scintilla/src/Editor.cxx' % STCLOC,
456 '%s/scintilla/src/Indicator.cxx' % STCLOC,
457 '%s/scintilla/src/KeyMap.cxx' % STCLOC,
458 '%s/scintilla/src/KeyWords.cxx' % STCLOC,
459 '%s/scintilla/src/LineMarker.cxx' % STCLOC,
460 '%s/scintilla/src/PropSet.cxx' % STCLOC,
461 '%s/scintilla/src/ScintillaBase.cxx' % STCLOC,
462 '%s/scintilla/src/Style.cxx' % STCLOC,
463 '%s/scintilla/src/ViewStyle.cxx' % STCLOC,
464 '%s/scintilla/src/LexCPP.cxx' % STCLOC,
465 '%s/scintilla/src/LexHTML.cxx' % STCLOC,
466 '%s/scintilla/src/LexLua.cxx' % STCLOC,
467 '%s/scintilla/src/LexOthers.cxx' % STCLOC,
468 '%s/scintilla/src/LexPerl.cxx' % STCLOC,
469 '%s/scintilla/src/LexPython.cxx' % STCLOC,
470 '%s/scintilla/src/LexSQL.cxx' % STCLOC,
471 '%s/scintilla/src/LexVB.cxx' % STCLOC,
472 '%s/scintilla/src/DocumentAccessor.cxx' % STCLOC,
473 '%s/scintilla/src/UniConversion.cxx' % STCLOC,
474 '%s/scintilla/src/WindowAccessor.cxx' % STCLOC,
475 '%s/scintilla/src/PosRegExp.cxx' % STCLOC,
476
477 '%s/PlatWX.cpp' % STCLOC,
478 '%s/ScintillaWX.cpp' % STCLOC,
479 '%s/stc.cpp' % STCLOC,
1e7ecb7b
RD
480 ] + swig_sources,
481
482 include_dirs = stc_includes,
483 define_macros = stc_defines,
484
485 library_dirs = libdirs,
486 libraries = libs,
c368d904 487
1e7ecb7b
RD
488 extra_compile_args = cflags,
489 extra_link_args = lflags,
490 )
491
492 wxpExtensions.append(ext)
c368d904
RD
493
494
495
496#----------------------------------------------------------------------
497# Do the Setup/Build/Install/Whatever
498#----------------------------------------------------------------------
499
1b62f00d
RD
500if __name__ == "__main__":
501 if not GL_ONLY:
502 setup(name = PKGDIR,
503 version = VERSION,
504 description = DESCRIPTION,
505 long_description = LONG_DESCRIPTION,
506 author = AUTHOR,
507 author_email = AUTHOR_EMAIL,
508 url = URL,
509 licence = LICENCE,
510
511 packages = [PKGDIR,
512 PKGDIR+'.lib',
513 PKGDIR+'.lib.editor',
514 ],
515
516 ext_package = PKGDIR,
517 ext_modules = wxpExtensions,
518 )
c368d904 519
1b62f00d 520 else:
c368d904 521
1b62f00d
RD
522 setup(name = "wxPython-gl",
523 version = VERSION,
524 description = "wxGLCanvas class for wxPython",
525 author = AUTHOR,
526 author_email = AUTHOR_EMAIL,
527 url = URL,
528 licence = LICENCE,
c368d904 529
1b62f00d 530 py_modules = [ "wxPython.glcanvas" ],
c368d904 531
1b62f00d
RD
532 ext_package = PKGDIR,
533 ext_modules = wxpExtensions,
534 )
c368d904 535
c368d904
RD
536
537
538
539#----------------------------------------------------------------------
540#----------------------------------------------------------------------