]>
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
35 Detects the number of CPUs on a system.
36 This approach is from detectCPUs here: http://www.artima.com/weblogs/viewpost.jsp?thread=230001
38 # Linux, Unix and MacOS:
39 if hasattr(os
, "sysconf"):
40 if os
.sysconf_names
.has_key("SC_NPROCESSORS_ONLN"):
42 ncpus
= os
.sysconf("SC_NPROCESSORS_ONLN")
43 if isinstance(ncpus
, int) and ncpus
> 0:
46 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
48 if os
.environ
.has_key("NUMBER_OF_PROCESSORS"):
49 ncpus
= int(os
.environ
["NUMBER_OF_PROCESSORS"]);
55 def exitIfError(code
, msg
):
59 raise builder
.BuildError
, msg
66 configureText
= open(os
.path
.join(wxRootDir
, "configure.in"), "r").read()
68 majorVersion
= re
.search("wx_major_version_number=(\d+)", configureText
).group(1)
69 minorVersion
= re
.search("wx_minor_version_number=(\d+)", configureText
).group(1)
71 versionText
= "%s.%s" % (majorVersion
, minorVersion
)
73 if int(minorVersion
) % 2:
74 releaseVersion
= re
.search("wx_release_number=(\d+)", configureText
).group(1)
75 versionText
+= ".%s" % (releaseVersion
)
80 def macFixupInstallNames(destdir
, prefix
, buildDir
=None):
81 # When an installdir is used then the install_names embedded in
82 # the dylibs are not correct. Reset the IDs and the dependencies
83 # to use just the prefix.
84 print "**** macFixupInstallNames(%s, %s, %s)" % (destdir
, prefix
, buildDir
)
86 os
.chdir(destdir
+prefix
+'/lib')
87 dylibs
= glob
.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib')
89 cmd
= 'install_name_tool -id %s/lib/%s %s/lib/%s' % \
90 (prefix
,lib
, destdir
+prefix
,lib
)
94 if buildDir
is not None:
95 cmd
= 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
96 (buildDir
,dep
, prefix
,dep
, destdir
+prefix
,lib
)
98 cmd
= 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
99 (destdir
+prefix
,dep
, prefix
,dep
, destdir
+prefix
,lib
)
108 print "Running %s" % cmd
109 return exitIfError(os
.system(cmd
), "Error running %s" % cmd
)
111 def main(scriptName
, args
):
116 global configure_opts
119 scriptDir
= os
.path
.dirname(os
.path
.abspath(scriptName
))
120 wxRootDir
= os
.path
.abspath(os
.path
.join(scriptDir
, "..", ".."))
122 contribDir
= os
.path
.join("contrib", "src")
125 VERSION
= tuple([int(i
) for i
in getWxRelease().split('.')[:2]])
127 if sys
.platform
.startswith("win"):
128 contribDir
= os
.path
.join(wxRootDir
, "contrib", "build")
130 if sys
.platform
.startswith("win"):
136 "clean" : (False, "Clean all files from the build directory"),
137 "debug" : (False, "Build the library in debug symbols"),
138 "builddir" : ("", "Directory where the build will be performed for autoconf builds."),
139 "prefix" : ("", "Configured prefix to use for autoconf builds. Defaults to installdir if set."),
140 "j" : (repr(numCPUs()), "Number of jobs to run at one time."),
141 "install" : (False, "Install the toolkit to the installdir directory, or the default dir."),
142 "installdir" : ("", "Directory where built wxWidgets will be installed"),
143 "mac_distdir": (None, "If set on Mac, will create an installer package in the specified dir."),
144 "mac_universal_binary" : (False, "Build Mac version as a universal binary"),
145 "mac_arch" : ("", "Build just the specified architecture on Mac"),
146 "mac_framework" : (False, "Install the Mac build as a framework"),
147 "no_config" : (False, "Turn off configure step on autoconf builds"),
148 "config_only": (False, "Only run the configure step and then exit"),
149 "rebake" : (False, "Regenerate Bakefile and autoconf files"),
150 "unicode" : (False, "Build the library with unicode support"),
151 "wxpython" : (False, "Build the wxWidgets library with all options needed by wxPython"),
152 "cocoa" : (False, "Build the Cooca port (Mac only currently)."),
153 "osx_cocoa" : (False, "Build the new Cocoa port"),
154 "shared" : (False, "Build wx as a dynamic library"),
155 "cairo" : (False, "Build support for wxCairoContext (always true on GTK+)"),
156 "extra_make" : ("", "Extra args to pass on [n]make's command line."),
157 "features" : ("", "A comma-separated list of wxUSE_XYZ defines on Win, or a list of configure flags on unix."),
160 parser
= optparse
.OptionParser(usage
="usage: %prog [options]", version
="%prog 1.0")
162 for opt
in option_dict
:
163 default
= option_dict
[opt
][0]
166 if type(default
) == types
.BooleanType
:
167 action
= "store_true"
168 parser
.add_option("--" + opt
, default
=default
, action
=action
, dest
=opt
, help=option_dict
[opt
][1])
170 options
, arguments
= parser
.parse_args(args
=args
)
172 # compiler / build system specific args
173 buildDir
= options
.builddir
175 installDir
= options
.installdir
176 prefixDir
= options
.prefix
178 if toolkit
== "autoconf":
180 buildDir
= os
.getcwd()
182 if options
.features
!= "":
183 configure_opts
.extend(options
.features
.split(" "))
186 configure_opts
.append("--enable-unicode")
189 configure_opts
.append("--enable-debug")
192 configure_opts
.append("--with-old_cocoa")
194 if options
.osx_cocoa
:
195 configure_opts
.append("--with-osx_cocoa")
198 configure_opts
.append("--enable-macosx_arch=%s" % options
.mac_arch
)
200 wxpy_configure_opts
= [
203 "--enable-graphics_ctx",
204 "--enable-mediactrl",
207 "--enable-debug_flag",
209 "--disable-debugreport",
210 "--enable-uiactionsim",
213 if sys
.platform
.startswith("darwin"):
214 wxpy_configure_opts
.append("--enable-monolithic")
216 wxpy_configure_opts
.append("--with-sdl")
217 wxpy_configure_opts
.append("--with-gnomeprint")
219 # Ensure that the Carbon build stays compatible back to 10.4 and
220 # for the Cocoa build allow running on 10.5 and newer. We only add
221 # them to the wxpy options because this is a hard-requirement for
222 # wxPython, but other cases it is optional and is left up to the
223 # developer. TODO: there should be a command line option to set
225 if sys
.platform
.startswith("darwin"):
226 if not options
.osx_cocoa
:
227 wxpy_configure_opts
.append(
228 "--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk")
230 wxpy_configure_opts
.append(
231 "--with-macosx-sdk=/Developer/SDKs/MacOSX10.5.sdk")
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
= run("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_universal_binary
= True
255 if options
.osx_cocoa
:
259 prefixDir
= "/Library/Frameworks/%s.framework/Versions/%s" % (name
, getWxRelease())
260 # framework builds always need to be monolithic
261 if not "--enable-monolithic" in configure_opts
:
262 configure_opts
.append("--enable-monolithic")
264 if installDir
and not prefixDir
:
265 prefixDir
= installDir
267 configure_opts
.append("--prefix=" + prefixDir
)
269 if options
.mac_universal_binary
:
270 configure_opts
.append("--enable-universal_binary")
272 print "Configure options: " + `configure_opts`
273 wxBuilder
= builder
.AutoconfBuilder()
274 if not options
.no_config
and not options
.clean
:
278 exitIfError(wxBuilder
.configure(dir=wxRootDir
, options
=configure_opts
),
279 "Error running configure")
282 if options
.config_only
:
283 print "Exiting after configure"
286 elif toolkit
in ["msvc", "msvcProject"]:
288 buildDir
= os
.path
.abspath(os
.path
.join(scriptDir
, "..", "msw"))
290 print "creating wx/msw/setup.h from setup0.h"
292 flags
["wxUSE_UNICODE"] = "1"
294 flags
["wxUSE_UNICODE_MSLU"] = "1"
297 flags
["wxUSE_CAIRO"] = "1"
300 flags
["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
301 flags
["wxUSE_DEBUGREPORT"] = "0"
302 flags
["wxUSE_DIALUP_MANAGER"] = "0"
303 flags
["wxUSE_GRAPHICS_CONTEXT"] = "1"
304 flags
["wxUSE_DISPLAY"] = "1"
305 flags
["wxUSE_GLCANVAS"] = "1"
306 flags
["wxUSE_POSTSCRIPT"] = "1"
307 flags
["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
308 flags
["wxUSE_DATEPICKCTRL_GENERIC"] = "1"
311 flags
["wxUSE_DIB_FOR_BITMAP"] = "1"
314 flags
["wxUSE_UIACTIONSIMULATOR"] = "1"
317 mswIncludeDir
= os
.path
.join(wxRootDir
, "include", "wx", "msw")
318 setup0File
= os
.path
.join(mswIncludeDir
, "setup0.h")
319 setupText
= open(setup0File
, "rb").read()
322 setupText
, subsMade
= re
.subn(flag
+ "\s+?\d", "%s %s" % (flag
, flags
[flag
]), setupText
)
324 print "Flag %s wasn't found in setup0.h!" % flag
327 setupFile
= open(os
.path
.join(mswIncludeDir
, "setup.h"), "wb")
328 setupFile
.write(setupText
)
331 if toolkit
== "msvc":
332 print "setting build options..."
333 args
.append("-f makefile.vc")
335 args
.append("UNICODE=1")
337 args
.append("MSLU=1")
340 args
.append("OFFICIAL_BUILD=1")
341 args
.append("SHARED=1")
342 args
.append("MONOLITHIC=0")
343 args
.append("USE_OPENGL=1")
344 args
.append("USE_GDIPLUS=1")
346 if not options
.debug
:
347 args
.append("BUILD=release")
349 args
.append("BUILD=debug")
351 wxBuilder
= builder
.MSVCBuilder()
353 if toolkit
== "msvcProject":
355 if options
.shared
or options
.wxpython
:
356 args
.append("wx_dll.dsw")
358 args
.append("wx.dsw")
361 wxBuilder
= builder
.MSVCProjectBuilder()
364 print "Builder not available for your specified platform/compiler."
368 print "Performing cleanup."
372 exitIfError(wxBuilder
.clean(os
.path
.join(contribDir
, "gizmos")), "Error building gizmos")
373 exitIfError(wxBuilder
.clean(os
.path
.join(contribDir
, "stc")), "Error building stc")
377 if options
.extra_make
:
378 args
.append(options
.extra_make
)
379 args
.append("-j" + options
.j
)
380 exitIfError(wxBuilder
.build(dir=buildDir
, options
=args
), "Error building")
382 if options
.wxpython
and os
.path
.exists(contribDir
):
383 exitIfError(wxBuilder
.build(os
.path
.join(contribDir
, "gizmos"), options
=args
), "Error building gizmos")
384 exitIfError(wxBuilder
.build(os
.path
.join(contribDir
, "stc"),options
=args
), "Error building stc")
389 extra
= ['DESTDIR='+installDir
]
390 wxBuilder
.install(options
=extra
)
392 if options
.wxpython
and os
.path
.exists(contribDir
):
393 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "gizmos"), options
=extra
), "Error building gizmos")
394 exitIfError(wxBuilder
.install(os
.path
.join(contribDir
, "stc"), options
=extra
), "Error building stc")
396 if options
.mac_framework
:
398 def renameLibrary(libname
, frameworkname
):
401 while os
.path
.islink(reallib
):
402 links
.append(reallib
)
403 reallib
= "lib/" + os
.readlink(reallib
)
405 print "reallib is %s" % reallib
406 run("mv -f %s lib/%s.dylib" % (reallib
, frameworkname
))
409 run("ln -s -f %s.dylib %s" % (frameworkname
, link
))
411 frameworkRootDir
= prefixDir
413 print "installDir = %s" % installDir
414 frameworkRootDir
= installDir
+ prefixDir
415 os
.chdir(frameworkRootDir
)
420 version
= commands
.getoutput("bin/wx-config --release")
421 basename
= commands
.getoutput("bin/wx-config --basename")
422 configname
= commands
.getoutput("bin/wx-config --selected-config")
424 run("ln -s -f bin Resources")
426 # we make wx the "actual" library file and link to it from libwhatever.dylib
427 # so that things can link to wx and survive minor version changes
428 renameLibrary("lib/lib%s-%s.dylib" % (basename
, version
), "wx")
429 run("ln -s -f lib/wx.dylib wx")
431 run("ln -s -f include/wx Headers")
433 for lib
in ["GL", "STC", "Gizmos", "Gizmos_xrc"]:
434 libfile
= "lib/lib%s_%s-%s.dylib" % (basename
, lib
.lower(), version
)
435 if os
.path
.exists(libfile
):
436 frameworkDir
= "framework/wx%s/%s" % (lib
, version
)
437 if not os
.path
.exists(frameworkDir
):
438 os
.makedirs(frameworkDir
)
439 renameLibrary(libfile
, "wx" + lib
)
440 run("ln -s -f ../../../%s %s/wx%s" % (libfile
, frameworkDir
, lib
))
442 for lib
in glob
.glob("lib/*.dylib"):
443 if not os
.path
.islink(lib
):
444 corelibname
= "lib/lib%s-%s.0.dylib" % (basename
, version
)
445 run("install_name_tool -id %s %s" % (os
.path
.join(prefixDir
, lib
), lib
))
446 run("install_name_tool -change %s %s %s" % (os
.path
.join(frameworkRootDir
, corelibname
), os
.path
.join(prefixDir
, corelibname
), lib
))
450 header_template
= """
452 #ifndef __WX_FRAMEWORK_HEADER__
453 #define __WX_FRAMEWORK_HEADER__
457 #endif // __WX_FRAMEWORK_HEADER__
460 header_dir
= "wx-%s/wx" % version
461 for include
in glob
.glob(header_dir
+ "/*.h"):
462 headers
+= "wx/" + os
.path
.basename(include
) + "\n"
464 framework_header
= open("wx.h", "w")
465 framework_header
.write(header_template
% headers
)
466 framework_header
.close()
468 run("ln -s -f %s wx" % header_dir
)
469 run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h wx/setup.h" % configname
)
471 os
.chdir(os
.path
.join(frameworkRootDir
, "..", ".."))
472 run("ln -s -f %s Versions/Current" % getWxRelease())
473 run("ln -s -f Versions/Current/Headers Headers")
474 run("ln -s -f Versions/Current/Resources Resources")
475 run("ln -s -f Versions/Current/wx wx")
477 # sanity check to ensure the symlink works
478 run("cd Versions/Current")
481 # adjust the install_name if needed TODO: skip this for framework builds?
482 if sys
.platform
.startswith("darwin") and \
483 options
.install
and \
484 options
.installdir
and \
485 not options
.wxpython
: # wxPython's build will do this later if needed
487 prefixDir
= '/usr/local'
488 macFixupInstallNames(options
.installdir
, prefixDir
)#, buildDir)
490 # make a package if a destdir was set.
491 if options
.mac_framework
and \
492 options
.installdir
and \
495 if os
.path
.exists(options
.mac_distdir
):
496 shutil
.rmtree(options
.mac_distdir
)
498 packagedir
= os
.path
.join(options
.mac_distdir
, "packages")
499 os
.makedirs(packagedir
)
500 basename
= os
.path
.basename(prefixDir
.split(".")[0])
501 packageName
= basename
+ "-" + getWxRelease()
502 packageMakerPath
= "/Developer/usr/bin/packagemaker "
504 args
.append("--root %s" % options
.installdir
)
505 args
.append("--id org.wxwidgets.%s" % basename
.lower())
506 args
.append("--title %s" % packageName
)
507 args
.append("--version %s" % getWxRelease())
508 args
.append("--out %s" % os
.path
.join(packagedir
, packageName
+ ".pkg"))
509 cmd
= packageMakerPath
+ ' '.join(args
)
510 print "cmd = %s" % cmd
513 os
.chdir(options
.mac_distdir
)
515 run('hdiutil create -srcfolder %s -volname "%s" -imagekey zlib-level=9 %s.dmg' % (packagedir
, packageName
, packageName
))
517 shutil
.rmtree(packagedir
)
519 if __name__
== '__main__':
520 exitWithException
= False # use sys.exit instead
521 main(sys
.argv
[0], sys
.argv
[1:])