]>
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 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.1.12'
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
)
167 if config
.readConfigFiles(args
):
169 config
.makeMakefile()
172 cmd
= "%s -f %s" % (config
.MAKE
, config
.MAKEFILE
)
173 print "Running:", cmd
176 if not err
and config
.runInstall
:
177 cmd
= "%s -f %s install" % (config
.MAKE
, config
.MAKEFILE
)
178 print "Running:", cmd
182 if not err
and config
.runClean
:
183 cmd
= "%s -f %s clean" % (config
.MAKE
, config
.MAKEFILE
)
184 print "Running:", cmd
187 if not err
and config
.runUninstall
:
188 cmd
= "%s -f %s uninstall" % (config
.MAKE
, config
.MAKEFILE
)
189 print "Running:", cmd
195 #----------------------------------------------------------------------------
200 #----------------------------------------------------------------------------
203 if sys
.platform
!= 'win32':
204 st
= string
.join(string
.split(st
, '\\'), '/')
207 #----------------------------------------------------------------------------
210 return string
.join(string
.split(string
.strip(st
), ' '), ' \\\n\t')
212 #----------------------------------------------------------------------------
215 def __init__(self
, **kw
):
216 self
.__dict
__.update(kw
)
219 #------------------------------------------------------------
220 def setDefaults(self
):
221 self
.VERSION
= __version__
224 self
.SWIGFLAGS
= '-c++ -shadow -python -keyword -dnone -I$(WXPSRCDIR)'
228 self
.OTHERCFLAGS
= ''
229 self
.OTHERLFLAGS
= ''
230 self
.OTHERSWIGFLAGS
= ''
232 self
.OTHERTARGETS
= ''
233 self
.OTHERINSTALLTARGETS
= ''
234 self
.OTHERUNINSTALLTARGETS
= ''
236 self
.DEFAULTRULE
= 'default: $(GENCODEDIR) $(TARGET)'
237 self
.PYVERSION
= sys
.version
[:3]
238 self
.PYPREFIX
= sys
.prefix
239 self
.EXECPREFIX
= sys
.exec_prefix
240 self
.WXDIR
= '$(WXWIN)'
242 self
.WXP_USE_THREAD
= '1'
243 self
.WXUSINGDLL
= '1'
245 self
.WXPSRCDIR
= '$(WXDIR)/utils/wxPython/src'
250 if sys
.platform
== 'win32':
252 self
.PYTHONLIB
= '$(PYPREFIX)\\libs\\python15.lib'
253 self
.TARGETDIR
= '$(PYPREFIX)\\wxPython'
254 self
.LIBS
= '$(PYTHONLIB) $(WXPSRCDIR)\wxc.lib'
255 self
.GENCODEDIR
= 'msw'
256 self
.SWIGTOOLKITFLAG
= '-D__WXMSW__'
258 self
.TARGET
= '$(MODULE).pyd'
259 self
.CFLAGS
= '-I$(PYPREFIX)\include -I$(WXPSRCDIR) -I. /Fp$(MODULE).pch /YXhelpers.h -DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) '
260 self
.LFLAGS
= '$(DEBUGLFLAGS) /DLL /subsystem:windows,3.50 /machine:I386 /nologo'
263 self
.OVERRIDEFLAGS
= '/GX-'
264 self
.RMCMD
= '-erase '
265 self
.WXPSRCDIR
= os
.path
.normpath(self
.WXPSRCDIR
)
271 self
.PYLIB
= '$(EXECPREFIX)/lib/python$(PYVERSION)'
272 self
.LIBPL
= '$(PYLIB)/config'
273 self
.PYTHONLIB
= '$(LIBPL)/libpython$(PYVERSION).a'
274 self
.TARGETDIR
= '$(EXECPREFIX)/lib/python$(PYVERSION)/site-packages/wxPython'
275 self
.TARGET
= '$(MODULE)module$(SO)'
277 self
.HELPERLIB
= 'wxPyHelpers'
278 self
.HELPERLIBDIR
= '/usr/local/lib'
279 self
.CFLAGS
= '-DSWIG_GLOBAL -DHAVE_CONFIG_H $(THREAD) -I. '\
280 '`wx-config --cflags` -I$(PYINCLUDE) -I$(EXECINCLUDE) '\
282 self
.LFLAGS
= '-L$(WXPSRCDIR) `wx-config --libs`'
283 self
.LIBS
= '-l$(HELPERLIB)'
284 self
.RMCMD
= '-rm -f '
286 # **** What to do when I start supporting Motif, etc.???
287 self
.GENCODEDIR
= 'gtk'
288 self
.SWIGTOOLKITFLAG
= '-D__WXGTK__'
290 # Extract a few things from Python's Makefile...
292 filename
= os
.path
.join(self
.EXECPREFIX
,
293 'lib/python'+self
.PYVERSION
,
295 mfText
= string
.split(open(filename
, 'r').read(), '\n')
297 raise SystemExit, "Python development files not found"
299 self
.CCC
= self
.findMFValue(mfText
, 'CCC')
300 self
.CC
= self
.findMFValue(mfText
, 'CC')
301 self
.OPT
= self
.findMFValue(mfText
, 'OPT')
302 self
.SO
= self
.findMFValue(mfText
, 'SO')
303 self
.LDSHARED
= self
.findMFValue(mfText
, 'LDSHARED')
304 self
.CCSHARED
= self
.findMFValue(mfText
, 'CCSHARED')
305 #self.LINKFORSHARED = self.findMFValue(mfText, 'LINKFORSHARED')
306 #self. = self.findMFValue(mfText, '')
307 #self. = self.findMFValue(mfText, '')
310 # The majority of cases will require LDSHARED to be
311 # modified to use the C++ driver instead of the C driver
312 # for linking. We'll try to do it here and if we goof up
313 # then the user can correct it in their build.local file.
314 self
.LDSHARED
= string
.join(['$(CCC)'] +
315 string
.split(self
.LDSHARED
, ' ')[1:],
319 #------------------------------------------------------------
321 # This is called after the config files have been evaluated
322 # so we can do some sanity checking...
323 if sys
.platform
!= 'win32':
325 self
.CCC
= os
.popen('wx-config --cxx', 'r').read()[:-1]
327 print "Warning: C++ compiler not specified (CCC). Assuming c++"
330 self
.CCC
= os
.popen('wx-config --cc', 'r').read()[:-1]
332 print "Warning: C compiler not specified (CC). Assuming cc"
335 #------------------------------------------------------------
336 def findMFValue(self
, mfText
, st
):
337 # Find line begining with st= and return the value
338 # Regex would probably be to cooler way to do this, but
339 # I think this is the most understandable.
341 if string
.find(line
, st
+'=') == 0:
342 st
= string
.strip(line
[len(st
)+1:])
346 #------------------------------------------------------------
347 def makeMakefile(self
):
349 # make a list of object file names
351 for name
in self
.SWIGFILES
:
352 objects
= objects
+ os
.path
.splitext(name
)[0] + self
.OBJEXT
+ ' '
353 for name
in self
.SOURCES
:
354 obj
= os
.path
.basename(name
)
355 objects
= objects
+ os
.path
.splitext(obj
)[0] + self
.OBJEXT
+ ' '
356 self
.OBJECTS
= splitlines(objects
)
359 # now build the text for the dependencies
361 for name
in self
.SWIGFILES
:
362 rootname
= os
.path
.splitext(name
)[0]
363 text
= '$(GENCODEDIR)/%s.cpp $(GENCODEDIR)/%s.py : %s.i %s\n' \
364 '$(TARGETDIR)\\%s.py : $(GENCODEDIR)\\%s.py\n' % \
365 (rootname
, rootname
, rootname
, self
.SWIGDEPS
, rootname
, rootname
)
366 depends
= depends
+ text
368 text
= '%s%s : %s\n' % \
369 (os
.path
.splitext(name
)[0], self
.OBJEXT
, self
.OTHERDEPS
)
370 depends
= depends
+ text
371 for name
in self
.PYFILES
:
372 text
= '$(TARGETDIR)\\%s.py : %s.py\n' % \
373 tuple([os
.path
.splitext(name
)[0]] * 2)
374 depends
= depends
+ text
376 for name
in self
.SOURCES
:
377 name
= os
.path
.basename(name
)
378 text
= '%s%s : %s\n' % \
379 (os
.path
.splitext(name
)[0], self
.OBJEXT
, self
.OTHERDEPS
)
380 depends
= depends
+ text
382 self
.DEPENDS
= swapslash(depends
)
385 # and the list of .py files
387 for name
in self
.SWIGFILES
:
388 pymodules
= pymodules
+ '$(TARGETDIR)\\%s.py ' % os
.path
.splitext(name
)[0]
389 for name
in self
.PYFILES
:
390 pymodules
= pymodules
+ '$(TARGETDIR)\\%s.py ' % os
.path
.splitext(name
)[0]
391 self
.PYMODULES
= splitlines(swapslash(pymodules
))
394 # now make a list of the python files that would need uninstalled
396 for name
in self
.SWIGFILES
:
397 pycleanup
= pycleanup
+ self
.makeCleanupList(name
)
398 for name
in self
.PYFILES
:
399 pycleanup
= pycleanup
+ self
.makeCleanupList(name
)
400 self
.PYCLEANUP
= swapslash(pycleanup
)
403 # finally, build the makefile
404 if sys
.platform
== 'win32':
406 self
.RESFILE
= '$(MODULE).res'
407 self
.RESRULE
= '$(MODULE).res : $(MODULE).rc $(WXDIR)\\include\\wx\\msw\\wx.rc\n\t'\
408 '$(rc) -r /i$(WXDIR)\\include -fo$@ $(MODULE).rc'
409 text
= win32Template
% self
.__dict
__
411 text
= unixTemplate
% self
.__dict
__
412 f
= open(self
.MAKEFILE
, 'w')
416 print "Makefile created: ", self
.MAKEFILE
420 #------------------------------------------------------------
421 def makeCleanupList(self
, name
):
423 st
= st
+ '\t%s$(TARGETDIR)\\%s.py\n' % (self
.RMCMD
, os
.path
.splitext(name
)[0])
424 st
= st
+ '\t%s$(TARGETDIR)\\%s.pyc\n' % (self
.RMCMD
, os
.path
.splitext(name
)[0])
425 st
= st
+ '\t%s$(TARGETDIR)\\%s.pyo\n' % (self
.RMCMD
, os
.path
.splitext(name
)[0])
429 #------------------------------------------------------------
430 def readConfigFiles(self
, args
):
431 return self
.processFile(self
.bldCfg
, 1) and \
432 self
.processFile(os
.path
.join('../..', self
.bldCfgLocal
)) and \
433 self
.processFile(os
.path
.join('..', self
.bldCfgLocal
)) and \
434 self
.processFile(os
.path
.join('.', self
.bldCfgLocal
)) and \
435 self
.processArgs(args
)
437 #------------------------------------------------------------
438 def processFile(self
, filename
, required
=0):
440 text
= open(filename
, 'r').read()
443 print "Unable to open %s" % filename
449 exec(text
, self
.__dict
__)
451 print "Error evaluating %s" % filename
453 traceback
.print_exc()
458 #------------------------------------------------------------
459 def processArgs(self
, args
):
462 pair
= string
.split(st
, '=')
465 self
.__dict
__[name
] = value
467 print "Error parsing command-line: %s" % st
473 #------------------------------------------------------------
479 #----------------------------------------------------------------------------
480 #----------------------------------------------------------------------------
481 #----------------------------------------------------------------------------
484 #----------------------------------------------------------------------
485 # This makefile was autogenerated from build.py. Your changes will be
486 # lost if the generator is run again. You have been warned.
487 #----------------------------------------------------------------------
490 VERSION = %(VERSION)s
492 SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s
495 PYVERSION = %(PYVERSION)s
496 PYPREFIX = %(PYPREFIX)s
497 EXECPREFIX = %(EXECPREFIX)s
498 PYTHONLIB = %(PYTHONLIB)s
500 WXP_USE_THREAD = %(WXP_USE_THREAD)s
501 WXUSINGDLL = %(WXUSINGDLL)s
502 GENCODEDIR = %(GENCODEDIR)s
503 RESFILE = %(RESFILE)s
504 WXPSRCDIR = %(WXPSRCDIR)s
507 TARGETDIR = %(TARGETDIR)s
509 OBJECTS = %(OBJECTS)s
510 PYMODULES = %(PYMODULES)s
516 !if "$(FINAL)" == "0"
517 DEBUGLFLAGS = /DEBUG /INCREMENTAL:YES
519 DEBUGLFLAGS = /INCREMENTAL:NO
521 !if "$(WXP_USE_THREAD)" == "1"
522 THREAD=-DWXP_USE_THREAD=1
529 OVERRIDEFLAGS=%(OVERRIDEFLAGS)s
530 EXTRAFLAGS = $(CFLAGS) %(OTHERCFLAGS)s
532 LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s
533 EXTRALIBS = %(LIBS)s %(OTHERLIBS)s
537 #----------------------------------------------------------------------
539 !include $(WXDIR)\\src\\makevc.env
541 #----------------------------------------------------------------------
543 %(DEFAULTRULE)s %(OTHERTARGETS)s
547 install: $(TARGETDIR) $(TARGETDIR)\\$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s
563 uninstall: %(OTHERUNINSTALLTARGETS)s
564 -erase $(TARGETDIR)\\$(TARGET)
568 #----------------------------------------------------------------------
569 # implicit rule for compiling .cpp and .c files
572 $(CPPFLAGS) /c /Tp $<
575 {$(GENCODEDIR)}.cpp{}.obj:
577 $(CPPFLAGS) /c /Tp $<
587 # Implicit rules to run SWIG
588 {}.i{$(GENCODEDIR)}.cpp:
589 swig $(SWIGFLAGS) -c -o $@ $<
591 {}.i{$(GENCODEDIR)}.py:
592 swig $(SWIGFLAGS) -c -o $(GENCODEDIR)\\tmp_wrap.cpp $<
593 -erase $(GENCODEDIR)\\tmp_wrap.cpp
596 {$(GENCODEDIR)}.py{$(TARGETDIR)}.py:
599 {}.py{$(TARGETDIR)}.py:
602 #----------------------------------------------------------------------
604 $(TARGET) : $(DUMMYOBJ) $(WXLIB) $(OBJECTS) $(RESFILE)
607 $(LFLAGS) /def:$(MODULE).def /implib:./$(MODULE).lib
608 $(DUMMYOBJ) $(OBJECTS) $(RESFILE)
616 $(TARGETDIR)\\$(TARGET) : $(TARGET)
620 pycfiles : $(PYMODULES)
621 $(EXECPREFIX)\\python $(PYPREFIX)\\Lib\\compileall.py -l $(TARGETDIR)
622 $(EXECPREFIX)\\python -O $(PYPREFIX)\Lib\\compileall.py -l $(TARGETDIR)
631 #----------------------------------------------------------------------
635 #----------------------------------------------------------------------
648 #----------------------------------------------------------------------------
649 #----------------------------------------------------------------------------
650 #----------------------------------------------------------------------------
653 #----------------------------------------------------------------------
654 # This makefile was autogenerated from build.py. Your changes will be
655 # lost if the generator is run again. You have been warned.
656 #----------------------------------------------------------------------
661 VERSION = %(VERSION)s
663 SWIGFLAGS = %(SWIGFLAGS)s %(SWIGTOOLKITFLAG)s %(OTHERSWIGFLAGS)s
664 CFLAGS = %(CFLAGS)s $(OPT) %(OTHERCFLAGS)s
665 LFLAGS = %(LFLAGS)s %(OTHERLFLAGS)s
666 LIBS = %(LIBS)s %(OTHERLIBS)s
667 PYVERSION = %(PYVERSION)s
668 PYPREFIX = %(PYPREFIX)s
669 EXECPREFIX = %(EXECPREFIX)s
670 PYINCLUDE = $(PYPREFIX)/include/python$(PYVERSION)
671 EXECINCLUDE = $(EXECPREFIX)/include/python$(PYVERSION)
674 PYTHONLIB = %(PYTHONLIB)s
676 WXP_USE_THREAD = %(WXP_USE_THREAD)s
677 GENCODEDIR = %(GENCODEDIR)s
678 WXPSRCDIR = %(WXPSRCDIR)s
679 HELPERLIB = %(HELPERLIB)s
680 HELPERLIBDIR = %(HELPERLIBDIR)s
682 TARGETDIR = %(TARGETDIR)s
689 LDSHARED = %(LDSHARED)s
690 CCSHARED = %(CCSHARED)s
693 OBJECTS = %(OBJECTS)s
694 PYMODULES = %(PYMODULES)s
698 ifeq ($(WXP_USE_THREAD), 1)
699 THREAD=-DWXP_USE_THREAD
702 #----------------------------------------------------------------------
704 %(DEFAULTRULE)s %(OTHERTARGETS)s
706 install: $(TARGETDIR) $(TARGETDIR)/$(TARGET) pycfiles %(OTHERINSTALLTARGETS)s
712 uninstall: %(OTHERUNINSTALLTARGETS)s
713 -rm -f $(TARGETDIR)/$(TARGET)
717 #----------------------------------------------------------------------
720 $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
722 %%.o : $(GENCODEDIR)/%%.cpp
723 $(CCC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
726 $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
728 %%.o : $(GENCODEDIR)/%%.c
729 $(CC) $(CCSHARED) $(CFLAGS) $(OTHERCFLAGS) -c $<
732 $(GENCODEDIR)/%%.cpp : %%.i
733 swig $(SWIGFLAGS) -c -o $@ $<
735 $(GENCODEDIR)/%%.py : %%.i
736 swig $(SWIGFLAGS) -c -o $(GENCODEDIR)/tmp_wrap.cpp $<
737 rm $(GENCODEDIR)/tmp_wrap.cpp
744 $(TARGETDIR)/%% : $(GENCODEDIR)/%%
747 #----------------------------------------------------------------------
751 #----------------------------------------------------------------------
753 $(TARGET) : $(OBJECTS)
754 $(LDSHARED) $(OBJECTS) $(LFLAGS) $(LIBS) $(OTHERLIBS) -o $(TARGET)
758 pycfiles : $(PYMODULES)
759 $(EXECPREFIX)/bin/python $(PYLIB)/compileall.py -l $(TARGETDIR)
760 $(EXECPREFIX)/bin/python -O $(PYLIB)/compileall.py -l $(TARGETDIR)
764 mkdir -p $(TARGETDIR)
769 #----------------------------------------------------------------------
779 #----------------------------------------------------------------------------
781 if __name__
== '__main__':
785 #----------------------------------------------------------------------------