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