]>
git.saurik.com Git - wxWidgets.git/blob - build/tools/build-wxwidgets.py
3 ###################################
4 # Author: Kevin Ollivier
5 # Licence: wxWindows licence
6 ###################################
28 exitWithException
= True
31 def exitIfError(code
, msg
):
35 raise builder
.BuildError
, msg
42 configureText
= open(os
.path
.join(wxRootDir
, "configure.in"), "r").read()
44 majorVersion
= re
.search("wx_major_version_number=(\d+)", configureText
).group(1)
45 minorVersion
= re
.search("wx_minor_version_number=(\d+)", configureText
).group(1)
47 return "%s.%s" % (majorVersion
, minorVersion
)
51 def doMacLipoBuild(arch
, buildDir
, installDir
,
52 cxxcompiler
="g++-4.0", cccompiler
="gcc-4.0", target
="10.4", flags
=""):
53 archInstallDir
= installDir
+ "/" + arch
54 old_env
= dict(CXX
= os
.environ
.get('CXX'),
55 CC
= os
.environ
.get('CC'),
56 MACOSX_DEPLOYMENT_TARGET
= os
.environ
.get('MACOSX_DEPLOYMENT_TARGET'),
59 os
.environ
["CXX"] = "%s -arch %s %s" % (cxxcompiler
, arch
, flags
)
60 os
.environ
["CC"] = "%s -arch %s %s" % (cccompiler
, arch
, flags
)
61 os
.environ
["MACOSX_DEPLOYMENT_TARGET"] = target
62 archArgs
= ["DESTDIR=" + archInstallDir
]
63 buildRoot
= "bld-" + arch
65 buildRoot
= buildDir
+ "/" + buildRoot
67 if not os
.path
.exists(buildRoot
):
68 os
.makedirs(buildRoot
)
73 if not options
.no_config
:
74 exitIfError(wxBuilder
.configure(dir=wxRootDir
, options
=configure_opts
), "Error running configure for "+arch
)
75 exitIfError(wxBuilder
.build(options
=archArgs
), "Error building for "+arch
)
76 exitIfError(wxBuilder
.install(options
=["DESTDIR=" + archInstallDir
]), "Error Installing for "+arch
)
78 if options
.wxpython
and os
.path
.exists(os
.path
.join(wxRootDir
, contribDir
)):
79 exitIfError(wxBuilder
.build(dir=os
.path
.join(contribDir
, "gizmos"), options
=archArgs
),
80 "Error building gizmos for "+arch
)
81 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "gizmos"), options
=["DESTDIR=" + archInstallDir
]),
82 "Error Installing gizmos for "+arch
)
84 exitIfError(wxBuilder
.build(dir=os
.path
.join(contribDir
, "stc"),options
=archArgs
),
85 "Error building stc for "+arch
)
86 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "stc"),options
=["DESTDIR=" + archInstallDir
]),
87 "Error installing stc for "+arch
)
90 for key
, val
in old_env
.items():
97 def macFixupInstallNames(destdir
, prefix
, buildDir
=None):
98 # When an installdir is used then the install_names embedded in
99 # the dylibs are not correct. Reset the IDs and the dependencies
100 # to use just the prefix.
101 print "**** macFixupInstallNames(%s, %s, %s)" % (destdir
, prefix
, buildDir
)
103 os
.chdir(destdir
+prefix
+'/lib')
104 dylibs
= glob
.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib')
106 cmd
= 'install_name_tool -id %s/lib/%s %s/lib/%s' % \
107 (prefix
,lib
, destdir
+prefix
,lib
)
111 if buildDir
is not None:
112 cmd
= 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
113 (buildDir
,dep
, prefix
,dep
, destdir
+prefix
,lib
)
115 cmd
= 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
116 (destdir
+prefix
,dep
, prefix
,dep
, destdir
+prefix
,lib
)
123 def main(scriptName
, args
):
128 global configure_opts
131 scriptDir
= os
.path
.dirname(os
.path
.abspath(scriptName
))
132 wxRootDir
= os
.path
.abspath(os
.path
.join(scriptDir
, "..", ".."))
134 contribDir
= os
.path
.join("contrib", "src")
137 VERSION
= tuple([int(i
) for i
in getWxRelease().split('.')])
139 if sys
.platform
.startswith("win"):
140 contribDir
= os
.path
.join(wxRootDir
, "contrib", "build")
142 if sys
.platform
.startswith("win"):
148 "clean" : (False, "Clean all files from the build directory"),
149 "debug" : (False, "Build the library in debug symbols"),
150 "builddir" : ("", "Directory where the build will be performed for autoconf builds."),
151 "prefix" : ("", "Configured prefix to use for autoconf builds. Defaults to installdir if set."),
152 "install" : (False, "Install the toolkit to the installdir directory, or the default dir."),
153 "installdir" : ("", "Directory where built wxWidgets will be installed"),
154 "mac_universal_binary" : (False, "Build Mac version as a universal binary"),
155 "mac_arch" : ("", "Build just the specified architecture on Mac"),
156 "mac_lipo" : (False, "EXPERIMENTAL: Create a universal binary by merging a PPC and Intel build together."),
157 "mac_framework" : (False, "Install the Mac build as a framework"),
158 "no_config" : (False, "Turn off configure step on autoconf builds"),
159 "config_only": (False, "Only run the configure step and then exit"),
160 "rebake" : (False, "Regenerate Bakefile and autoconf files"),
161 "unicode" : (False, "Build the library with unicode support"),
162 "wxpython" : (False, "Build the wxWidgets library with all options needed by wxPython"),
163 "cocoa" : (False, "Build the Cooca port (Mac only currently)."),
164 "osx_cocoa" : (False, "Build the new Cocoa port"),
165 "shared" : (False, "Build wx as a dynamic library"),
166 "cairo" : (False, "Build support for wxCairoContext (always true on GTK+)"),
167 "extra_make" : ("", "Extra args to pass on [n]make's command line."),
168 "features" : ("", "A comma-separated list of wxUSE_XYZ defines on Win, or a list of configure flags on unix."),
171 parser
= optparse
.OptionParser(usage
="usage: %prog [options]", version
="%prog 1.0")
173 for opt
in option_dict
:
174 default
= option_dict
[opt
][0]
177 if type(default
) == types
.BooleanType
:
178 action
= "store_true"
179 parser
.add_option("--" + opt
, default
=default
, action
=action
, dest
=opt
, help=option_dict
[opt
][1])
181 options
, arguments
= parser
.parse_args(args
=args
)
183 # compiler / build system specific args
184 buildDir
= options
.builddir
186 installDir
= options
.installdir
187 prefixDir
= options
.prefix
189 if toolkit
== "autoconf":
191 buildDir
= os
.getcwd()
193 if options
.features
!= "":
194 configure_opts
.extend(options
.features
.split(" "))
197 configure_opts
.append("--enable-unicode")
200 configure_opts
.append("--enable-debug")
202 if options
.mac_universal_binary
:
203 configure_opts
.append("--enable-universal_binary")
204 configure_opts
.append("--without-macosx-sdk") # don't let configure default it
207 configure_opts
.append("--with-old_cocoa")
209 if options
.osx_cocoa
:
210 configure_opts
.append("--with-osx_cocoa")
213 configure_opts
.append("--enable-macosx_arch=%s" % options
.mac_arch
)
215 wxpy_configure_opts
= [
218 "--enable-graphics_ctx",
219 "--enable-mediactrl",
222 "--enable-debug_flag",
224 "--disable-debugreport",
225 "--enable-uiactionsim",
228 if sys
.platform
.startswith("darwin"):
229 wxpy_configure_opts
.append("--enable-monolithic")
231 wxpy_configure_opts
.append("--with-sdl")
232 wxpy_configure_opts
.append("--with-gnomeprint")
234 if not options
.mac_framework
:
235 if installDir
and not prefixDir
:
236 prefixDir
= installDir
238 configure_opts
.append("--prefix=" + prefixDir
)
241 configure_opts
.extend(wxpy_configure_opts
)
243 # wxPython likes adding these debug options too
244 configure_opts
.append("--enable-debug_gdb")
245 configure_opts
.append("--disable-optimise")
248 retval
= os
.system("make -f autogen.mk")
249 exitIfError(retval
, "Error running autogen.mk")
251 if options
.mac_framework
:
252 # Framework build is always a universal binary
253 options
.mac_lipo
= True
255 if options
.osx_cocoa
:
257 installDir
= "/Library/Frameworks/%s.framework/Versions/%s" % (name
, getWxRelease())
258 configure_opts
.append("--prefix=" + installDir
)
259 # framework builds always need to be monolithic
260 if not "--enable-monolithic" in configure_opts
:
261 configure_opts
.append("--enable-monolithic")
263 print "Configure options: " + `configure_opts`
264 wxBuilder
= builder
.AutoconfBuilder()
265 if not options
.no_config
and not options
.clean
and not options
.mac_lipo
:
269 exitIfError(wxBuilder
.configure(dir=wxRootDir
, options
=configure_opts
),
270 "Error running configure")
273 if options
.config_only
:
274 print "Exiting after configure"
277 elif toolkit
in ["msvc", "msvcProject"]:
279 buildDir
= os
.path
.abspath(os
.path
.join(scriptDir
, "..", "msw"))
281 print "creating wx/msw/setup.h from setup0.h"
283 flags
["wxUSE_UNICODE"] = "1"
285 flags
["wxUSE_UNICODE_MSLU"] = "1"
288 flags
["wxUSE_CAIRO"] = "1"
291 flags
["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
292 flags
["wxUSE_DEBUGREPORT"] = "0"
293 flags
["wxUSE_DIALUP_MANAGER"] = "0"
294 flags
["wxUSE_GRAPHICS_CONTEXT"] = "1"
295 flags
["wxUSE_DISPLAY"] = "1"
296 flags
["wxUSE_GLCANVAS"] = "1"
297 flags
["wxUSE_POSTSCRIPT"] = "1"
298 flags
["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
299 flags
["wxUSE_DATEPICKCTRL_GENERIC"] = "1"
302 flags
["wxUSE_DIB_FOR_BITMAP"] = "1"
305 flags
["wxUSE_UIACTIONSIMULATOR"] = "1"
308 mswIncludeDir
= os
.path
.join(wxRootDir
, "include", "wx", "msw")
309 setup0File
= os
.path
.join(mswIncludeDir
, "setup0.h")
310 setupText
= open(setup0File
, "rb").read()
313 setupText
, subsMade
= re
.subn(flag
+ "\s+?\d", "%s %s" % (flag
, flags
[flag
]), setupText
)
315 print "Flag %s wasn't found in setup0.h!" % flag
318 setupFile
= open(os
.path
.join(mswIncludeDir
, "setup.h"), "wb")
319 setupFile
.write(setupText
)
322 if toolkit
== "msvc":
323 print "setting build options..."
324 args
.append("-f makefile.vc")
326 args
.append("UNICODE=1")
328 args
.append("MSLU=1")
331 args
.append("OFFICIAL_BUILD=1")
332 args
.append("SHARED=1")
333 args
.append("MONOLITHIC=0")
334 args
.append("USE_OPENGL=1")
335 args
.append("USE_GDIPLUS=1")
337 if not options
.debug
:
338 args
.append("BUILD=release")
340 args
.append("BUILD=debug")
342 wxBuilder
= builder
.MSVCBuilder()
344 if toolkit
== "msvcProject":
346 if options
.shared
or options
.wxpython
:
347 args
.append("wx_dll.dsw")
349 args
.append("wx.dsw")
352 wxBuilder
= builder
.MSVCProjectBuilder()
355 print "Builder not available for your specified platform/compiler."
359 print "Performing cleanup."
363 exitIfError(wxBuilder
.clean(os
.path
.join(contribDir
, "gizmos")), "Error building gizmos")
364 exitIfError(wxBuilder
.clean(os
.path
.join(contribDir
, "stc")), "Error building stc")
370 if options
.mac_universal_binary
:
371 print "WARNING: Cannot specify both mac_lipo and mac_universal_binary, as they conflict."
372 print " Using mac_universal_binary..."
375 # TODO: Add 64-bit when we're building OS X Cocoa
377 # 2.8, use gcc 3.3 on PPC for 10.3 support, but only when building ...
378 macVersion
= platform
.mac_ver()[0]
379 isLeopard
= macVersion
.find("10.5") != -1
381 if not isLeopard
and os
.path
.exists(os
.path
.join(wxRootDir
, contribDir
)):
382 # Building wx 2.8 so make the ppc build compatible with Panther
383 doMacLipoBuild("ppc", buildDir
, installDir
, cxxcompiler
="g++-3.3", cccompiler
="gcc-3.3",
384 target
="10.3", flags
="-DMAC_OS_X_VERSION_MAX_ALLOWED=1040")
386 doMacLipoBuild("ppc", buildDir
, installDir
)
388 doMacLipoBuild("i386", buildDir
, installDir
)
390 # Use lipo to merge together all binaries in the install dirs, and it
391 # also copies all other files and links it finds to the new destination.
392 result
= os
.system("python %s/distrib/scripts/mac/lipo-dir.py %s %s %s" %
393 (wxRootDir
, installDir
+"/ppc", installDir
+"/i386", installDir
))
395 # tweak the wx-config script
396 fname
= os
.path
.abspath(installDir
+ '/bin/wx-config')
397 data
= open(fname
).read()
398 data
= data
.replace('ppc/', '')
399 data
= data
.replace('i386/', '')
400 open(fname
, 'w').write(data
)
402 shutil
.rmtree(installDir
+ "/ppc")
403 shutil
.rmtree(installDir
+ "/i386")
408 if options
.extra_make
:
409 args
.append(options
.extra_make
)
410 exitIfError(wxBuilder
.build(dir=buildDir
, options
=args
), "Error building")
412 if options
.wxpython
and os
.path
.exists(contribDir
):
413 exitIfError(wxBuilder
.build(os
.path
.join(contribDir
, "gizmos"), options
=args
), "Error building gizmos")
414 exitIfError(wxBuilder
.build(os
.path
.join(contribDir
, "stc"),options
=args
), "Error building stc")
419 extra
= ['DESTDIR='+installDir
]
420 wxBuilder
.install(options
=extra
)
422 if options
.wxpython
and os
.path
.exists(contribDir
):
423 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "gizmos"), options
=extra
), "Error building gizmos")
424 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "stc"), options
=extra
), "Error building stc")
426 if options
.mac_framework
:
428 def renameLibrary(libname
, frameworkname
):
431 while os
.path
.islink(reallib
):
432 links
.append(reallib
)
433 reallib
= "lib/" + os
.readlink(reallib
)
435 print "reallib is %s" % reallib
436 os
.system("mv -f %s lib/%s.dylib" % (reallib
, frameworkname
))
439 os
.system("ln -s -f %s.dylib %s" % (frameworkname
, link
))
445 version
= commands
.getoutput("bin/wx-config --release")
446 basename
= commands
.getoutput("bin/wx-config --basename")
447 configname
= commands
.getoutput("bin/wx-config --selected-config")
449 os
.system("ln -s -f bin Resources")
451 # we make wx the "actual" library file and link to it from libwhatever.dylib
452 # so that things can link to wx and survive minor version changes
453 renameLibrary("lib/lib%s-%s.dylib" % (basename
, version
), "wx")
454 os
.system("ln -s -f lib/wx.dylib wx")
456 os
.system("ln -s -f include/wx Headers")
458 for lib
in ["GL", "STC", "Gizmos", "Gizmos_xrc"]:
459 libfile
= "lib/lib%s_%s-%s.dylib" % (basename
, lib
.lower(), version
)
460 if os
.path
.exists(libfile
):
461 frameworkDir
= "framework/wx%s/%s" % (lib
, version
)
462 if not os
.path
.exists(frameworkDir
):
463 os
.makedirs(frameworkDir
)
464 renameLibrary(libfile
, "wx" + lib
)
465 os
.system("ln -s -f ../../../%s %s/wx%s" % (libfile
, frameworkDir
, lib
))
467 for lib
in glob
.glob("lib/*.dylib"):
468 if not os
.path
.islink(lib
):
469 corelibname
= "lib/lib%s-%s.0.dylib" % (basename
, version
)
470 os
.system("install_name_tool -id %s %s" % (os
.path
.join(installDir
, lib
), lib
))
471 os
.system("install_name_tool -change %s %s %s" % (os
.path
.join(installDir
, "i386", corelibname
), os
.path
.join(installDir
, corelibname
), lib
))
475 header_template
= """
477 #ifndef __WX_FRAMEWORK_HEADER__
478 #define __WX_FRAMEWORK_HEADER__
482 #endif // __WX_FRAMEWORK_HEADER__
485 header_dir
= "wx-%s/wx" % version
486 for include
in glob
.glob(header_dir
+ "/*.h"):
487 headers
+= "wx/" + os
.path
.basename(include
) + "\n"
489 framework_header
= open("wx.h", "w")
490 framework_header
.write(header_template
% headers
)
491 framework_header
.close()
493 os
.system("ln -s -f %s wx" % header_dir
)
494 os
.system("ln -s -f ../../../lib/wx/include/%s/wx/setup.h wx/setup.h" % configname
)
496 os
.chdir(os
.path
.join(installDir
, "..", ".."))
497 os
.system("ln -s -f %s Versions/Current" % os
.path
.basename(installDir
))
498 os
.system("ln -s -f Versions/Current/Headers Headers")
499 os
.system("ln -s -f Versions/Current/Resources Resources")
500 os
.system("ln -s -f Versions/Current/wx wx")
503 # adjust the install_name if needed TODO: skip this for framework builds?
504 if sys
.platform
.startswith("darwin") and \
505 options
.install
and \
506 options
.installdir
and \
507 not options
.wxpython
: # wxPython's build will do this later if needed
508 prefix
= options
.prefix
510 prefix
= '/usr/local'
511 macFixupInstallNames(options
.installdir
, prefix
)#, buildDir)
515 if __name__
== '__main__':
516 exitWithException
= False # use sys.exit instead
517 main(sys
.argv
[0], sys
.argv
[1:])