]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/distrib/build.py
2 #----------------------------------------------------------------------------
4 # Purpose: This script is used to build wxPython. It reads a build
5 # configuration file in the requested project directory and
6 # based on the contents of the file can build Makefiles for
7 # unix or win32, and can execute make with various options
8 # potentially automating the entire build/install/clean process
9 # from a single command.
13 # Created: 18-Aug-1999
15 # Copyright: (c) 1999 by Total Control Software
16 # Licence: wxWindows license
17 #----------------------------------------------------------------------------
21 This script is used to build wxPython. It reads a build configuration
22 file in the requested project directory and based on the contents of
23 the file can build Makefiles for unix or win32, and can execute make
24 with various options potentially automating the entire
25 build/install/clean process from a single command.
27 The default action is to build the Makefile and exit.
30 -C dir CD to dir before doing anything
31 -B file Use file as the build configuration (default ./build.cfg)
32 -M file Use file as the name of the makefile to create
35 -b Build the module (runs make)
36 -i Install the module (runs make install)
37 -c Cleanup (runs make clean)
38 -u Uninstall (runs make uninstall)
45 The build configuration file lists targets, source files and options
46 for the the build process. The contents of the build.cfg are used to
47 dynamically generate the Makefile.
49 To prevent you from getting screwed when the default build.cfg is
50 updated, you can override the values in build.cfg by putting your
51 custom definitions in a file named build.local. You can also place a
52 build.local file in the parent directory, or even in the grandparent
53 directory for project-wide overrides. Finally, command-line arguments
54 of the form NAME=VALUE can also be used to override simple configuration
55 values. The order of evaluation is:
57 0. comman-line flags (-M, -b, etc.)
59 2. ../../build.local (if present)
60 3. ../build.local (if present)
61 4. ./build.local (if present)
62 5. command-line NAME=VALUEs
64 The config files are actually just Python files that get exec'ed in a
65 separate namespace which is then used later as a configuration object.
66 This keeps the build script simple in that it doesn't have to parse
67 anything, and the config files can be much more than just names and
68 values as any pretty much any python code can be executed. The global
69 variables set in the config namespace are what are used later as
75 The following variables can be set in the config files. Only a few are
76 required, the rest will either have suitable defaults or will be
77 calculated from your current Python runtime environment.
79 MODULE The name of the extension module to produce
80 SWIGFILES A list of files that should be run through SWIG
81 SWIGFLAGS Flags for SWIG
82 SOURCES Other C/C++ sources that should be part of the module
83 PYFILES Other Python files that should be installed with the module
84 CFLAGS Flags to be used by the compiler
85 LFLAGS Flags to be used at the link step
86 LIBS Libraries to be linked with
88 OTHERCFLAGS Extra flags to append to CFLAGS
89 OTHERLFLAGS Extra flags to append to LFLAGS
90 OTHERSWIGFLAGS Extra flags to append to SWIGFLAGS
91 OTHERLIBS Other libraries to be linked with, in addition to LIBS
92 OTHERTARGETS Other targets to be placed on the default rule line
94 Other targets to be placed on the install rule line
95 OTHERRULES This text is placed at the end of the makefile and
96 will typically be used for adding rules and such
97 DEFAULTRULE Text to be used for the default rule in the makefile
99 TARGETDIR Destination for the install step
101 MAKE The make program to use
102 MAKEFILE The name of the makefile
104 runBuild Setting this to 1 is eqivalent to the -b flag
105 runInstall Setting this to 1 is eqivalent to the -i flag
106 runClean Setting this to 1 is eqivalent to the -c flag
107 runUninstall Setting this to 1 is eqivalent to the -u flag
109 PYVERSION Version number of Python used in pathnames
110 PYPREFIX The root of the Python install
111 EXECPREFIX The root of the Python install for binary files
112 PYTHONLIB The Python link library
116 import sys
, os
, string
, getopt
118 #----------------------------------------------------------------------------
119 # This is really the wxPython version number, and will be placed in the
120 # Makefiles for use with the distribution related targets.
122 __version__
= '2.1b3'
124 #----------------------------------------------------------------------------
128 opts
, args
= getopt
.getopt(args
[1:], 'C:B:M:bicu')
133 if not os
.environ
.has_key('WXWIN'):
134 print "WARNING: WXWIN is not set in the environment. WXDIR may not\n"\
135 " be set properly in the makefile, you will have to \n"\
136 " set the environment variable or override in build.local."
139 bldCfgLocal
= 'build.local'
140 MAKEFILE
= 'Makefile'
146 for flag
, value
in opts
:
147 if flag
== '-C': os
.chdir(value
)
148 elif flag
== '-B': bldCfgFile
= value
149 elif flag
== '-M': makefile
= value
150 elif flag
== '-b': runBuild
= 1
151 elif flag
== '-c': runClean
= 1
152 elif flag
== '-i': runInstall
= 1
153 elif flag
== '-u': runUninstall
= 1
155 elif flag
== '-h': usage(); sys
.exit(1)
156 else: usage(); sys
.exit(1)
158 config
= BuildConfig(bldCfg
= bldCfg
,
159 bldCfgLocal
= bldCfgLocal
,
162 runInstall
= runInstall
,
164 runUninstall
= runUninstall
)
166 if config
.readConfigFiles(args
):
167 config
.makeMakefile()
171 cmd
= "%s -f %s" % (config
.MAKE
, config
.MAKEFILE
)
172 print "Running:", cmd
175 if not err
and config
.runInstall
:
176 cmd
= "%s -f %s install" % (config
.MAKE
, config
.MAKEFILE
)
177 print "Running:", cmd
181 if not err
and config
.runClean
:
182 cmd
= "%s -f %s clean" % (config
.MAKE
, config
.MAKEFILE
)
183 print "Running:", cmd
186 if not err
and config
.runUninstall
:
187 cmd
= "%s -f %s uninstall" % (config
.MAKE
, config
.MAKEFILE
)
188 print "Running:", cmd
193 #----------------------------------------------------------------------------
198 #----------------------------------------------------------------------------
201 if sys
.platform
!= 'win32':
202 st
= string
.join(string
.split(st
, '\\'), '/')
205 #----------------------------------------------------------------------------
208 return string
.join(string
.split(string
.strip(st
), ' '), ' \\\n\t')
210 #----------------------------------------------------------------------------
213 def __init__(self
, **kw
):
214 self
.__dict
__.update(kw
)
217 #------------------------------------------------------------
218 def setDefaults(self
):
219 self
.VERSION
= __version__
222 self
.SWIGFLAGS
= '-c++ -shadow -python -dnone -I$(WXPSRCDIR)'
226 self
.OTHERCFLAGS
= ''
227 self
.OTHERLFLAGS
= ''
228 self
.OTHERSWIGFLAGS
= ''
230 self
.OTHERTARGETS
= ''
231 self
.OTHERINSTALLTARGETS
= ''
233 self
.DEFAULTRULE
= 'default: $(GENCODEDIR) $(TARGET)'
234 self
.PYVERSION
= sys
.version
[:3]
235 self
.PYPREFIX
= sys
.prefix
236 self
.EXECPREFIX
= sys
.exec_prefix
237 self
.WXDIR
= '$(WXWIN)'
239 self
.WXP_USE_THREAD
= '1'
240 self
.WXUSINGDLL
= '1'
242 self
.WXPSRCDIR
= '$(WXDIR)/utils/wxPython/src'
245 if sys
.platform
== 'win32':
247 self
.PYTHONLIB
= '$(PYPREFIX)\\libs\\python15.lib'
248 self
.TARGETDIR
= '$(PYPREFIX)\\wxPython'
249 self
.LIBS
= '$(PYTHONLIB) $(WXPSRCDIR)\wxc.lib'
250 self
.GENCODEDIR
= 'msw'
251 self
.SWIGTOOLKITFLAG
= '-D__WXMSW__'
253 self
.TARGET
= '$(MODULE).pyd'
254 self
.CFLAGS
= '-I$(PYPREFIX)\include -I$(WXPSRCDIR) -I. /Fp$(MODULE).pch /YXhelpers.h -DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) '
255 self
.LFLAGS
= '$(DEBUGLFLAGS) /DLL /subsystem:windows,3.50 /machine:I386 /nologo'
258 self
.OVERRIDEFLAGS
= '/GX-'
262 self
.PYLIB
= '$(EXECPREFIX)/lib/python$(PYVERSION)'
263 self
.LIBPL
= '$(PYLIB)/config'
264 self
.PYTHONLIB
= '$(LIBPL)/libpython$(PYVERSION).a'
265 self
.TARGETDIR
= '$(EXECPREFIX)/lib/python$(PYVERSION)/site-packages/wxPython'
266 self
.TARGET
= '$(MODULE)module$(SO)'
268 self
.HELPERLIB
= 'wxPyHelpers'
269 self
.HELPERLIBDIR
= '/usr/local/lib'
270 self
.CFLAGS
= '-DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) -I. '\
271 '`wx-config --cflags` -I$(PYINCLUDE) -I$(EXECINCLUDE) '\
273 self
.LFLAGS
= '-L$(WXPSRCDIR) `wx-config --libs`'
274 self
.LIBS
= '-l$(HELPERLIB)'
276 # **** what to do when I start supporting Motif, etc.???
277 self
.GENCODEDIR
= 'gtk'
278 self
.SWIGTOOLKITFLAG
= '-D__WXGTK__'
280 # Extract a few things from Python's Makefile...
282 filename
= os
.path
.join(self
.EXECPREFIX
,
283 'lib/python'+self
.PYVERSION
,
285 mfText
= string
.split(open(filename
, 'r').read(), '\n')
287 raise SystemExit, "Python development files not found"
289 self
.CCC
= self
.findMFValue(mfText
, 'CCC')
290 self
.CC
= self
.findMFValue(mfText
, 'CC')
291 self
.OPT
= self
.findMFValue(mfText
, 'OPT')
292 self
.SO
= self
.findMFValue(mfText
, 'SO')
293 self
.LDSHARED
= self
.findMFValue(mfText
, 'LDSHARED')
294 self
.CCSHARED
= self
.findMFValue(mfText
, 'CCSHARED')
295 #self.LINKFORSHARED = self.findMFValue(mfText, 'LINKFORSHARED')
296 #self. = self.findMFValue(mfText, '')
297 #self. = self.findMFValue(mfText, '')
300 # The majority of cases will require LDSHARED to be
301 # modified to use the C++ driver instead of the C driver
302 # for linking. We'll try to do it here and if we goof up
303 # then the user can correct it in their build.local file.
304 self
.LDSHARED
= string
.join(['$(CCC)'] +
305 string
.split(self
.LDSHARED
, ' ')[1:],
309 #------------------------------------------------------------
310 def findMFValue(self
, mfText
, st
):
311 # Find line begining with st= and return the value
312 # Regex would probably be to cooler way to do this, but
313 # I think this is the most understandable.
315 if string
.find(line
, st
+'=') == 0:
316 st
= string
.strip(line
[len(st
)+1:])
320 #------------------------------------------------------------
321 def makeMakefile(self
):
323 # make a list of object file names
325 for name
in self
.SWIGFILES
:
326 objects
= objects
+ os
.path
.splitext(name
)[0] + self
.OBJEXT
+ ' '
327 for name
in self
.SOURCES
:
328 objects
= objects
+ os
.path
.splitext(name
)[0] + self
.OBJEXT
+ ' '
329 self
.OBJECTS
= splitlines(objects
)
332 # now build the text for the dependencies
334 for name
in self
.SWIGFILES
:
335 text
= '$(GENCODEDIR)/%s.cpp $(GENCODEDIR)/%s.py : %s.i\n' \
336 '$(TARGETDIR)\\%s.py : $(GENCODEDIR)\\%s.py\n' % \
337 tuple([os
.path
.splitext(name
)[0]] * 5)
338 depends
= depends
+ text
339 for name
in self
.PYFILES
:
340 text
= '$(TARGETDIR)\\%s.py : %s.py\n' % \
341 tuple([os
.path
.splitext(name
)[0]] * 2)
342 depends
= depends
+ text
343 self
.DEPENDS
= swapslash(depends
)
346 # and the list of .py files
348 for name
in self
.SWIGFILES
:
349 pymodules
= pymodules
+ '$(TARGETDIR)\\%s.py ' % os
.path
.splitext(name
)[0]
350 for name
in self
.PYFILES
:
351 pymodules
= pymodules
+ '$(TARGETDIR)\\%s.py ' % os
.path
.splitext(name
)[0]
352 self
.PYMODULES
= splitlines(swapslash(pymodules
))
356 # finally, build the makefile
357 if sys
.platform
== 'win32':
359 self
.RESFILE
= '$(MODULE).res'
360 self
.RESRULE
= '$(MODULE).res : $(MODULE).rc $(WXDIR)\\include\\wx\\msw\\wx.rc\n\t'\
361 '$(rc) -r /i$(WXDIR)\\include -fo$@ $(MODULE).rc'
362 text
= win32Template
% self
.__dict
__
364 text
= unixTemplate
% self
.__dict
__
365 f
= open(self
.MAKEFILE
, 'w')
369 print "Makefile created: ", self
.MAKEFILE
372 #------------------------------------------------------------
373 def readConfigFiles(self
, args
):
374 return self
.processFile(self
.bldCfg
, 1) and \
375 self
.processFile(os
.path
.join('../..', self
.bldCfgLocal
)) and \
376 self
.processFile(os
.path
.join('..', self
.bldCfgLocal
)) and \
377 self
.processFile(os
.path
.join('.', self
.bldCfgLocal
)) and \
378 self
.processArgs(args
)
380 #------------------------------------------------------------
381 def processFile(self
, filename
, required
=0):
383 text
= open(filename
, 'r').read()
386 print "Unable to open %s" % filename
392 exec(text
, self
.__dict
__)
394 print "Error evaluating %s" % filename
396 traceback
.print_exc()
401 #------------------------------------------------------------
402 def processArgs(self
, args
):
405 pair
= string
.split(st
, '=')
408 self
.__dict
__[name
] = value
410 print "Error parsing command-line: %s" % st
416 #------------------------------------------------------------
422 #----------------------------------------------------------------------------
423 #----------------------------------------------------------------------------
426 #----------------------------------------------------------------------
427 # This makefile was autogenerated from build.py. Your changes will be
428 # lost if the generator is run again. You have been warned.
429 #----------------------------------------------------------------------
432 VERSION = %(VERSION)s
434 SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s
435 CFLAGS = %(CFLAGS)s %(OTHERCFLAGS)s
436 LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s
437 PYVERSION = %(PYVERSION)s
438 PYPREFIX = %(PYPREFIX)s
439 EXECPREFIX = %(EXECPREFIX)s
440 PYTHONLIB = %(PYTHONLIB)s
442 WXP_USE_THREAD = %(WXP_USE_THREAD)s
443 WXUSINGDLL = %(WXUSINGDLL)s
444 GENCODEDIR = %(GENCODEDIR)s
445 RESFILE = %(RESFILE)s
446 WXPSRCDIR = %(WXPSRCDIR)s
449 TARGETDIR = %(TARGETDIR)s
451 OBJECTS = %(OBJECTS)s
452 PYMODULES = %(PYMODULES)s
458 !if "$(FINAL)" == "0"
459 DEBUGLFLAGS = /DEBUG /INCREMENTAL:YES
461 DEBUGLFLAGS = /INCREMENTAL:NO
463 !if "$(WXP_USE_THREAD)" == "1"
464 THREAD=-DWXP_USE_THREAD=1
471 OVERRIDEFLAGS=%(OVERRIDEFLAGS)s %(OTHERCFLAGS)s
472 EXTRAFLAGS = %(CFLAGS)s
474 LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s
475 EXTRALIBS = %(LIBS)s %(OTHERLIBS)s
477 #----------------------------------------------------------------------
479 !include $(WXDIR)\\src\\makevc.env
481 #----------------------------------------------------------------------
483 %(DEFAULTRULE)s %(OTHERTARGETS)s
487 install: $(TARGETDIR) $(TARGETDIR)\\$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s
504 -erase $(TARGETDIR)\\$(TARGET)
507 #----------------------------------------------------------------------
508 # implicit rule for compiling .cpp and .c files
511 $(CPPFLAGS) /c /Tp $<
514 {$(GENCODEDIR)}.cpp{}.obj:
516 $(CPPFLAGS) /c /Tp $<
526 # Implicit rules to run SWIG
527 {}.i{$(GENCODEDIR)}.cpp:
528 swig $(SWIGFLAGS) -c -o $@ $<
530 {}.i{$(GENCODEDIR)}.py:
531 swig $(SWIGFLAGS) -c -o $(GENCODEDIR)\\tmp_wrap.cpp $<
532 -erase $(GENCODEDIR)\\tmp_wrap.cpp
535 {$(GENCODEDIR)}.py{$(TARGETDIR)}.py:
538 {}.py{$(TARGETDIR)}.py:
541 #----------------------------------------------------------------------
543 $(TARGET) : $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(RESFILE)
546 $(LFLAGS) /def:$(MODULE).def /implib:./$(MODULE).lib
547 $(DUMMYOBJ) $(OBJECTS) $(RESFILE)
555 $(TARGETDIR)\\$(TARGET) : $(TARGET)
559 pycfiles : $(PYMODULES)
560 $(EXECPREFIX)\\python $(PYPREFIX)\\Lib\\compileall.py -l $(TARGETDIR)
561 $(EXECPREFIX)\\python -O $(PYPREFIX)\Lib\\compileall.py -l $(TARGETDIR)
570 #----------------------------------------------------------------------
574 #----------------------------------------------------------------------
580 #----------------------------------------------------------------------------
581 #----------------------------------------------------------------------------
582 #----------------------------------------------------------------------------
585 #----------------------------------------------------------------------
586 # This makefile was autogenerated from build.py. Your changes will be
587 # lost if the generator is run again. You have been warned.
588 #----------------------------------------------------------------------
593 VERSION = %(VERSION)s
595 SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s
596 CFLAGS = %(CFLAGS)s %(OTHERCFLAGS)s
597 LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s
598 LIBS = %(LIBS)s %(OTHERLIBS)s
599 PYVERSION = %(PYVERSION)s
600 PYPREFIX = %(PYPREFIX)s
601 EXECPREFIX = %(EXECPREFIX)s
602 PYINCLUDE = $(PYPREFIX)/include/python$(PYVERSION)
603 EXECINCLUDE = $(EXECPREFIX)/include/python$(PYVERSION)
606 PYTHONLIB = %(PYTHONLIB)s
608 WXP_USE_THREAD = %(WXP_USE_THREAD)s
609 GENCODEDIR = %(GENCODEDIR)s
610 WXPSRCDIR = %(WXPSRCDIR)s
611 HELPERLIB = %(HELPERLIB)s
612 HELPERLIBDIR = %(HELPERLIBDIR)s
614 TARGETDIR = %(TARGETDIR)s
621 LDSHARED = %(LDSHARED)s
622 CCSHARED = %(CCSHARED)s
625 OBJECTS = %(OBJECTS)s
626 PYMODULES = %(PYMODULES)s
630 ifeq ($(WXP_USE_THREAD), 1)
631 THREAD=-DWXP_USE_THREAD
634 #----------------------------------------------------------------------
636 %(DEFAULTRULE)s %(OTHERTARGETS)s
638 install: $(TARGETDIR) $(TARGETDIR)/$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s
645 -rm -f $(TARGETDIR)/$(TARGET)
649 #----------------------------------------------------------------------
652 $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
654 %%.o : $(GENCODEDIR)/%%.cpp
655 $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
658 $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
660 %%.o : $(GENCODEDIR)/%%.c
661 $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
663 $(GENCODEDIR)/%%.cpp : %%.i
664 swig $(SWIGFLAGS) -c -o $@ $<
666 $(GENCODEDIR)/%%.py : %%.i
667 swig $(SWIGFLAGS) -c -o $(GENCODEDIR)/tmp_wrap.cpp $<
668 rm $(GENCODEDIR)/tmp_wrap.cpp
673 $(TARGETDIR)/%% : $(GENCODEDIR)/%%
676 #----------------------------------------------------------------------
680 #----------------------------------------------------------------------
682 $(TARGET) : $(OBJECTS)
683 $(LDSHARED) $(OBJECTS) $(LFLAGS) $(LIBS) $(OTHERLIBS) -o $(TARGET)
687 pycfiles : $(PYMODULES)
688 $(EXECPREFIX)/bin/python $(PYLIB)/compileall.py -l $(TARGETDIR)
689 $(EXECPREFIX)/bin/python -O $(PYLIB)/compileall.py -l $(TARGETDIR)
698 #----------------------------------------------------------------------
708 #----------------------------------------------------------------------------
710 if __name__
== '__main__':
713 #----------------------------------------------------------------------------