]> git.saurik.com Git - wxWidgets.git/blame - wxPython/setup.py
Fixed a compiler performance warning
[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
22d08289
RD
76bcpp_compiling = '-c' in sys.argv and 'my_bcpp' in sys.argv # Bad heuristic
77
78if bcpp_compiling:
79 print "Compiling wxPython by Borland C/C++ Compiler"
80 HYBRID=0
81 WXBCPPLIBVER = string.replace(WXDLLVER,"_","")
82 # Version part of BCPP build LIBRARY name
83 WXDLLVER="" # no dll ver path avaible
84
c368d904
RD
85
86#----------------------------------------------------------------------
87# Check for build flags on the command line
88#----------------------------------------------------------------------
89
90for flag in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'CORE_ONLY',
afa3e1ed 91 'USE_SWIG', 'IN_CVS_TREE', 'FINAL', 'HYBRID', ]:
c368d904
RD
92 for x in range(len(sys.argv)):
93 if string.find(sys.argv[x], flag) == 0:
94 pos = string.find(sys.argv[x], '=') + 1
95 if pos > 0:
96 vars()[flag] = eval(sys.argv[x][pos:])
97 sys.argv[x] = ''
98
afa3e1ed
RL
99for option in ['WX_CONFIG', 'WXDLLVER', ]:
100 for x in range(len(sys.argv)):
101 if string.find(sys.argv[x], option) == 0:
102 pos = string.find(sys.argv[x], '=') + 1
103 if pos > 0:
104 vars()[option] = sys.argv[x][pos:]
105 sys.argv[x] = ''
106
c368d904
RD
107sys.argv = filter(None, sys.argv)
108
109
110if CORE_ONLY:
111 BUILD_GLCANVAS = 0
112 BUILD_OGL = 0
113 BUILD_STC = 0
114
115#----------------------------------------------------------------------
116# Setup some platform specific stuff
117#----------------------------------------------------------------------
118
119if os.name == 'nt':
120 # Set compile flags and such for MSVC. These values are derived
121 # from the wxWindows makefiles for MSVC, others will probably
122 # vary...
123 WXDIR = os.environ['WXWIN']
124 WXPLAT = '__WXMSW__'
125 GENDIR = 'msw'
126
c368d904
RD
127 if debug:
128 FINAL = 0
129 HYBRID = 0
130
131 if HYBRID:
132 FINAL = 0
133
c368d904
RD
134 includes = ['src',
135 os.path.join(WXDIR, 'include'),
136 ]
137
138 defines = [ ('WIN32', None), # Some of these are no longer
139 ('__WIN32__', None), # necessary. Anybody know which?
140 ('_WINDOWS', None),
141 ('__WINDOWS__', None),
142 ('WINVER', '0x0400'),
143 ('__WIN95__', None),
144 ('STRICT', None),
145
146 (WXPLAT, None),
147 ('WXUSINGDLL', '1'),
148
149 ('SWIG_GLOBAL', None),
150 ('HAVE_CONFIG_H', None),
151 ('WXP_USE_THREAD', '1'),
152 ]
153
22d08289
RD
154 if bcpp_compiling: # overwrite it
155 defines = [
156 ('_WINDOWS', None),
157 ('WINVER', '0x0400'),
158 ('STRICT', None),
159
160 ('WXUSINGDLL', '1'),
161
162 ('SWIG_GLOBAL', None),
163 ('HAVE_CONFIG_H', None),
164 ('WXP_USE_THREAD', '1'),
165
166 ('WXUSE_DEFINE','1'),
167 ('_RTLDLL',None),
168 ]
169
170
c368d904
RD
171 if not FINAL or HYBRID:
172 defines.append( ('__WXDEBUG__', None) )
173
174 libdirs = [os.path.join(WXDIR, 'lib'), 'build\\ilib']
175
176 if FINAL:
177 wxdll = 'wx' + WXDLLVER
178 elif HYBRID:
179 wxdll = 'wx' + WXDLLVER + 'h'
180 else:
181 wxdll = 'wx' + WXDLLVER + 'd'
182
c368d904 183
22d08289
RD
184 libs = [wxdll]
185 if bcpp_compiling:
186 libs = ['wx'+WXBCPPLIBVER]
187
188 libs = libs + ['kernel32', 'user32', 'gdi32', 'comdlg32',
c368d904
RD
189 'winspool', 'winmm', 'shell32', 'oldnames', 'comctl32',
190 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', 'uuid', 'rpcrt4',
191 'advapi32', 'wsock32']
192
22d08289 193
1e7ecb7b 194 cflags = ['/GX-'] # workaround for internal compiler error in MSVC 5
c368d904
RD
195 lflags = None
196
22d08289
RD
197
198 if bcpp_compiling: # overwrite it
199 cflags = ['-5', '-VF', ### To supplort MSVC spurious semicolons in the class scope
200 ### else, all semicolons at the end of all DECLARE_...CALLBACK... macros must be eliminated
201 '-Hc', '-H='+WXDIR+'\src\msw\wx32.csm',
202 '@'+WXDIR+'\src\msw\wxwin32.cfg'
203 ]
204
205
206 if not FINAL and HYBRID and not bcpp_compiling:
e7d63784
RD
207 cflags = cflags + ['/Od', '/Z7']
208 lflags = ['/DEBUG', ]
c368d904 209
22d08289
RD
210 elif bcpp_compiling and not FINAL:
211 cflags = cflags + ['/Od', '/v', '/y']
212 lflags = lflags + ['/v', ] ## '/PDB:NONE']
213
214
c368d904
RD
215
216elif os.name == 'posix':
217 # Set flags for Unix type platforms
218
219 WXDIR = '..' # assumes IN_CVS_TREE
220 WXPLAT = '__WXGTK__' # and assumes GTK...
221 GENDIR = 'gtk' # Need to allow for Motif eventually too
222
223 includes = ['src']
224 defines = [('SWIG_GLOBAL', None),
225 ('HAVE_CONFIG_H', None),
226 ('WXP_USE_THREAD', '1'),
227 ]
228 libdirs = []
229 libs = []
230
afa3e1ed 231 cflags = os.popen(WX_CONFIG + ' --cflags', 'r').read()[:-1] + ' ' + \
c368d904
RD
232 os.popen('gtk-config --cflags', 'r').read()[:-1]
233 cflags = string.split(cflags)
234
afa3e1ed 235 lflags = os.popen(WX_CONFIG + ' --libs', 'r').read()[:-1]
c368d904
RD
236 lflags = string.split(lflags)
237
238
239else:
240 raise 'Sorry Charlie...'
241
242
243#----------------------------------------------------------------------
244# Check if the version file needs updated
245#----------------------------------------------------------------------
246
247if IN_CVS_TREE and newer('setup.py', 'src/__version__.py'):
248 open('src/__version__.py', 'w').write("ver = '%s'\n" % VERSION)
249
1b62f00d
RD
250
251
c368d904 252#----------------------------------------------------------------------
1b62f00d 253# SWIG defaults
c368d904
RD
254#----------------------------------------------------------------------
255
c368d904 256swig_force = force
de20db99 257swig_args = ['-c++', '-shadow', '-python', '-keyword', '-dnone', #'-dascii',
c368d904 258 '-I./src', '-D'+WXPLAT]
185d7c3e 259swig_deps = ['src/my_typemaps.i']
c368d904 260
c368d904 261
1b62f00d
RD
262#----------------------------------------------------------------------
263# Define the CORE extension module
264#----------------------------------------------------------------------
265
266if not GL_ONLY:
267 print 'Preparing CORE...'
268 swig_files = [ 'wx.i', 'windows.i', 'windows2.i', 'windows3.i', 'events.i',
269 'misc.i', 'misc2.i', 'gdi.i', 'mdi.i', 'controls.i',
270 'controls2.i', 'cmndlgs.i', 'stattool.i', 'frames.i', 'image.i',
271 'printfw.i', 'sizers.i', 'clip_dnd.i',
272 'filesys.i', 'streams.i',
273 ##'grid.i', 'html.i', 'htmlhelp.i', 'calendar.i', 'utils.i',
274 ]
c368d904 275
1b62f00d
RD
276 swig_sources = run_swig(swig_files, 'src', GENDIR, PKGDIR,
277 USE_SWIG, swig_force, swig_args, swig_deps)
c368d904 278
1b62f00d
RD
279 copy_file('src/__init__.py', PKGDIR, update=1, verbose=0)
280 copy_file('src/__version__.py', PKGDIR, update=1, verbose=0)
c368d904 281
c368d904 282
1b62f00d
RD
283 if IN_CVS_TREE: # update the licence files
284 mkpath('licence')
285 for file in ['preamble.txt', 'licence.txt', 'licendoc.txt', 'lgpl.txt']:
286 copy_file(WXDIR+'/docs/'+file, 'licence/'+file, update=1, verbose=0)
c368d904 287
1b62f00d
RD
288
289 if os.name == 'nt':
290 rc_file = ['src/wxc.rc']
291 else:
292 rc_file = []
293
294
295 ext = Extension('wxc', ['src/helpers.cpp',
296 'src/libpy.c',
297 ] + rc_file + swig_sources,
298
299 include_dirs = includes,
300 define_macros = defines,
301
302 library_dirs = libdirs,
303 libraries = libs,
304
305 extra_compile_args = cflags,
306 extra_link_args = lflags,
307 )
308 wxpExtensions.append(ext)
309
310
311 # Extension for the grid module
312 swig_sources = run_swig(['grid.i'], 'src', GENDIR, PKGDIR,
313 USE_SWIG, swig_force, swig_args, swig_deps)
314 ext = Extension('gridc', swig_sources,
315 include_dirs = includes,
316 define_macros = defines,
317 library_dirs = libdirs,
318 libraries = libs,
319 extra_compile_args = cflags,
320 extra_link_args = lflags,
321 )
322 wxpExtensions.append(ext)
323
324
325 # Extension for the html modules
326 swig_sources = run_swig(['html.i', 'htmlhelp.i'], 'src', GENDIR, PKGDIR,
327 USE_SWIG, swig_force, swig_args, swig_deps)
328 ext = Extension('htmlc', swig_sources,
329 include_dirs = includes,
330 define_macros = defines,
331 library_dirs = libdirs,
332 libraries = libs,
333 extra_compile_args = cflags,
334 extra_link_args = lflags,
335 )
336 wxpExtensions.append(ext)
337
338
339 # Extension for the utils module
340 swig_sources = run_swig(['utils.i'], 'src', GENDIR, PKGDIR,
341 USE_SWIG, swig_force, swig_args, swig_deps)
342 ext = Extension('utilsc', swig_sources,
343 include_dirs = includes,
344 define_macros = defines,
345 library_dirs = libdirs,
346 libraries = libs,
347 extra_compile_args = cflags,
348 extra_link_args = lflags,
349 )
350 wxpExtensions.append(ext)
351
352
353 # Extension for the calendar module
354 swig_sources = run_swig(['calendar.i'], 'src', GENDIR, PKGDIR,
355 USE_SWIG, swig_force, swig_args, swig_deps)
356 ext = Extension('calendarc', swig_sources,
357 include_dirs = includes,
358 define_macros = defines,
359 library_dirs = libdirs,
360 libraries = libs,
361 extra_compile_args = cflags,
362 extra_link_args = lflags,
363 )
364 wxpExtensions.append(ext)
c368d904 365
c368d904
RD
366
367#----------------------------------------------------------------------
368# Define the GLCanvas extension module
369#----------------------------------------------------------------------
370
1b62f00d 371if BUILD_GLCANVAS or GL_ONLY:
c368d904
RD
372 print 'Preparing GLCANVAS...'
373 location = 'contrib/glcanvas'
374 swig_files = ['glcanvas.i']
19cf4f80 375 other_sources = []
c368d904
RD
376
377 swig_sources = run_swig(swig_files, location, GENDIR, PKGDIR,
1e7ecb7b 378 USE_SWIG, swig_force, swig_args)
c368d904
RD
379
380 gl_libs = []
381 if os.name == 'posix':
382 if '-D__WXDEBUG__' in cflags:
383 gl_libs = ['wx_gtkd_gl', 'GL', 'GLU']
384 else:
385 gl_libs = ['wx_gtk_gl', 'GL', 'GLU']
19cf4f80
RD
386 else:
387 other_sources = [location + '/msw/myglcanvas.cpp']
388 gl_libs = ['opengl32', 'glu32']
389
c368d904 390
1e7ecb7b 391 ext = Extension('glcanvasc',
19cf4f80 392 swig_sources + other_sources,
1e7ecb7b
RD
393
394 include_dirs = includes,
395 define_macros = defines,
396
397 library_dirs = libdirs,
398 libraries = libs + gl_libs,
399
400 extra_compile_args = cflags,
401 extra_link_args = lflags,
402 )
403
404 wxpExtensions.append(ext)
c368d904
RD
405
406
407#----------------------------------------------------------------------
408# Define the OGL extension module
409#----------------------------------------------------------------------
410
1b62f00d 411if not GL_ONLY and BUILD_OGL:
c368d904
RD
412 print 'Preparing OGL...'
413 location = 'contrib/ogl'
414 OGLLOC = location + '/contrib/src/ogl'
415 OGLINC = location + '/contrib/include'
416
417 swig_files = ['ogl.i', 'oglbasic.i', 'oglshapes.i', 'oglshapes2.i',
418 'oglcanvas.i']
419
420 swig_sources = run_swig(swig_files, location, '', PKGDIR,
1e7ecb7b 421 USE_SWIG, swig_force, swig_args)
c368d904
RD
422
423 # make sure local copy of contrib files are up to date
424 if IN_CVS_TREE:
425 contrib_copy_tree(WXDIR + '/contrib/include/wx/ogl', OGLINC+'/wx/ogl')
426 contrib_copy_tree(WXDIR + '/contrib/src/ogl', OGLLOC)
427
1e7ecb7b
RD
428 ext = Extension('oglc', ['%s/basic.cpp' % OGLLOC,
429 '%s/bmpshape.cpp' % OGLLOC,
430 '%s/composit.cpp' % OGLLOC,
431 '%s/divided.cpp' % OGLLOC,
432 '%s/lines.cpp' % OGLLOC,
433 '%s/misc.cpp' % OGLLOC,
434 '%s/basic2.cpp' % OGLLOC,
435 '%s/canvas.cpp' % OGLLOC,
436 '%s/constrnt.cpp' % OGLLOC,
437 '%s/drawn.cpp' % OGLLOC,
438 '%s/mfutils.cpp' % OGLLOC,
439 '%s/ogldiag.cpp' % OGLLOC,
440 ] + swig_sources,
441
442 include_dirs = [OGLINC] + includes,
443 define_macros = defines,
444
445 library_dirs = libdirs,
446 libraries = libs,
447
448 extra_compile_args = cflags,
449 extra_link_args = lflags,
450 )
451
452 wxpExtensions.append(ext)
453
454
c368d904
RD
455
456#----------------------------------------------------------------------
457# Define the STC extension module
458#----------------------------------------------------------------------
459
1b62f00d 460if not GL_ONLY and BUILD_STC:
c368d904
RD
461 print 'Preparing STC...'
462 location = 'contrib/stc'
463 STCLOC = location + '/contrib/src/stc'
464 STCINC = location + '/contrib/include'
465 STC_H = location + '/contrib/include/wx/stc'
466
467 # make sure local copy of contrib files are up to date
468 if IN_CVS_TREE:
469 contrib_copy_tree(WXDIR + '/contrib/include/wx/stc', STCINC+'/wx/stc')
470 contrib_copy_tree(WXDIR + '/contrib/src/stc', STCLOC)
471
472
473 swig_files = ['stc_.i']
474 swig_sources = run_swig(swig_files, location, '', PKGDIR,
475 USE_SWIG, swig_force,
476 swig_args + ['-I'+STC_H, '-I'+location],
1e7ecb7b 477 [STC_H+'/stc.h'])
c368d904
RD
478
479 # copy a project specific py module to the main package dir
480 copy_file(location+'/stc.py', PKGDIR, update=1, verbose=1)
481
482 # add some include dirs to the standard set
1e7ecb7b
RD
483 stc_includes = includes[:]
484 stc_includes.append('%s/scintilla/include' % STCLOC)
485 stc_includes.append('%s/scintilla/src' % STCLOC)
486 stc_includes.append(STCINC)
c368d904
RD
487
488 # and some macro definitions
1e7ecb7b
RD
489 stc_defines = defines[:]
490 stc_defines.append( ('__WX__', None) )
491 stc_defines.append( ('SCI_LEXER', None) )
c368d904
RD
492
493
1e7ecb7b
RD
494 ext = Extension('stc_c',
495 ['%s/scintilla/src/AutoComplete.cxx' % STCLOC,
c368d904
RD
496 '%s/scintilla/src/CallTip.cxx' % STCLOC,
497 '%s/scintilla/src/CellBuffer.cxx' % STCLOC,
498 '%s/scintilla/src/ContractionState.cxx' % STCLOC,
499 '%s/scintilla/src/Document.cxx' % STCLOC,
500 '%s/scintilla/src/Editor.cxx' % STCLOC,
501 '%s/scintilla/src/Indicator.cxx' % STCLOC,
502 '%s/scintilla/src/KeyMap.cxx' % STCLOC,
503 '%s/scintilla/src/KeyWords.cxx' % STCLOC,
504 '%s/scintilla/src/LineMarker.cxx' % STCLOC,
505 '%s/scintilla/src/PropSet.cxx' % STCLOC,
506 '%s/scintilla/src/ScintillaBase.cxx' % STCLOC,
507 '%s/scintilla/src/Style.cxx' % STCLOC,
508 '%s/scintilla/src/ViewStyle.cxx' % STCLOC,
509 '%s/scintilla/src/LexCPP.cxx' % STCLOC,
510 '%s/scintilla/src/LexHTML.cxx' % STCLOC,
511 '%s/scintilla/src/LexLua.cxx' % STCLOC,
512 '%s/scintilla/src/LexOthers.cxx' % STCLOC,
513 '%s/scintilla/src/LexPerl.cxx' % STCLOC,
514 '%s/scintilla/src/LexPython.cxx' % STCLOC,
515 '%s/scintilla/src/LexSQL.cxx' % STCLOC,
516 '%s/scintilla/src/LexVB.cxx' % STCLOC,
517 '%s/scintilla/src/DocumentAccessor.cxx' % STCLOC,
518 '%s/scintilla/src/UniConversion.cxx' % STCLOC,
519 '%s/scintilla/src/WindowAccessor.cxx' % STCLOC,
520 '%s/scintilla/src/PosRegExp.cxx' % STCLOC,
521
522 '%s/PlatWX.cpp' % STCLOC,
523 '%s/ScintillaWX.cpp' % STCLOC,
524 '%s/stc.cpp' % STCLOC,
1e7ecb7b
RD
525 ] + swig_sources,
526
527 include_dirs = stc_includes,
528 define_macros = stc_defines,
529
530 library_dirs = libdirs,
531 libraries = libs,
c368d904 532
1e7ecb7b
RD
533 extra_compile_args = cflags,
534 extra_link_args = lflags,
535 )
536
537 wxpExtensions.append(ext)
c368d904
RD
538
539
540
541#----------------------------------------------------------------------
542# Do the Setup/Build/Install/Whatever
543#----------------------------------------------------------------------
544
1b62f00d
RD
545if __name__ == "__main__":
546 if not GL_ONLY:
547 setup(name = PKGDIR,
548 version = VERSION,
549 description = DESCRIPTION,
550 long_description = LONG_DESCRIPTION,
551 author = AUTHOR,
552 author_email = AUTHOR_EMAIL,
553 url = URL,
554 licence = LICENCE,
555
556 packages = [PKGDIR,
557 PKGDIR+'.lib',
558 PKGDIR+'.lib.editor',
559 ],
560
561 ext_package = PKGDIR,
562 ext_modules = wxpExtensions,
563 )
c368d904 564
1b62f00d 565 else:
c368d904 566
1b62f00d
RD
567 setup(name = "wxPython-gl",
568 version = VERSION,
569 description = "wxGLCanvas class for wxPython",
570 author = AUTHOR,
571 author_email = AUTHOR_EMAIL,
572 url = URL,
573 licence = LICENCE,
c368d904 574
1b62f00d 575 py_modules = [ "wxPython.glcanvas" ],
c368d904 576
1b62f00d
RD
577 ext_package = PKGDIR,
578 ext_modules = wxpExtensions,
579 )
c368d904 580
c368d904
RD
581
582
583
584#----------------------------------------------------------------------
585#----------------------------------------------------------------------