]>
Commit | Line | Data |
---|---|---|
3b2c81c7 RD |
1 | #!/usr/bin/env python |
2 | ||
3 | ################################### | |
4 | # Author: Kevin Ollivier | |
526954c5 | 5 | # Licence: wxWindows licence |
3b2c81c7 RD |
6 | ################################### |
7 | ||
8 | import os | |
9 | import re | |
10 | import sys | |
11 | import builder | |
3b2c81c7 RD |
12 | import glob |
13 | import optparse | |
14 | import platform | |
15 | import shutil | |
16 | import types | |
b4f28d1e | 17 | import subprocess |
3b2c81c7 RD |
18 | |
19 | # builder object | |
20 | wxBuilder = None | |
21 | ||
22 | # other globals | |
23 | scriptDir = None | |
24 | wxRootDir = None | |
25 | contribDir = None | |
26 | options = None | |
27 | configure_opts = None | |
28 | exitWithException = True | |
29 | ||
6d6f2e7c RD |
30 | verbose = False |
31 | ||
32 | ||
33 | def numCPUs(): | |
e2db04f8 RD |
34 | """ |
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 | |
37 | """ | |
38 | # Linux, Unix and MacOS: | |
39 | if hasattr(os, "sysconf"): | |
016a3d4c | 40 | if "SC_NPROCESSORS_ONLN" in os.sysconf_names: |
e2db04f8 RD |
41 | # Linux & Unix: |
42 | ncpus = os.sysconf("SC_NPROCESSORS_ONLN") | |
43 | if isinstance(ncpus, int) and ncpus > 0: | |
44 | return ncpus | |
45 | else: # OSX: | |
b4f28d1e RD |
46 | p = subprocess.Popen("sysctl -n hw.ncpu", shell=True, stdout=subprocess.PIPE) |
47 | return p.stdout.read() | |
48 | ||
e2db04f8 | 49 | # Windows: |
016a3d4c | 50 | if "NUMBER_OF_PROCESSORS" in os.environ: |
e2db04f8 RD |
51 | ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]); |
52 | if ncpus > 0: | |
53 | return ncpus | |
54 | return 1 # Default | |
6d6f2e7c | 55 | |
3b2c81c7 | 56 | |
1ffe914a | 57 | def getXcodePath(): |
016a3d4c | 58 | return getoutput("xcode-select -print-path") |
1ffe914a RD |
59 | |
60 | ||
3b2c81c7 RD |
61 | def exitIfError(code, msg): |
62 | if code != 0: | |
016a3d4c | 63 | print(msg) |
3b2c81c7 | 64 | if exitWithException: |
016a3d4c | 65 | raise builder.BuildError(msg) |
3b2c81c7 RD |
66 | else: |
67 | sys.exit(1) | |
68 | ||
69 | ||
e2db04f8 RD |
70 | def getWxRelease(wxRoot=None): |
71 | if not wxRoot: | |
72 | global wxRootDir | |
73 | wxRoot = wxRootDir | |
74 | ||
75 | configureText = open(os.path.join(wxRoot, "configure.in"), "r").read() | |
3b2c81c7 RD |
76 | majorVersion = re.search("wx_major_version_number=(\d+)", configureText).group(1) |
77 | minorVersion = re.search("wx_minor_version_number=(\d+)", configureText).group(1) | |
78 | ||
6d6f2e7c | 79 | versionText = "%s.%s" % (majorVersion, minorVersion) |
3b2c81c7 | 80 | |
6d6f2e7c RD |
81 | if int(minorVersion) % 2: |
82 | releaseVersion = re.search("wx_release_number=(\d+)", configureText).group(1) | |
83 | versionText += ".%s" % (releaseVersion) | |
3b2c81c7 | 84 | |
6d6f2e7c | 85 | return versionText |
3b2c81c7 RD |
86 | |
87 | ||
e2db04f8 RD |
88 | def getFrameworkName(options): |
89 | # the name of the framework is based on the wx port being built | |
90 | name = "wxOSX" | |
91 | if options.osx_cocoa: | |
92 | name += "Cocoa" | |
93 | else: | |
94 | name += "Carbon" | |
95 | return name | |
96 | ||
97 | ||
98 | def getPrefixInFramework(options, wxRoot=None): | |
99 | # the path inside the framework that is the wx --prefix | |
100 | fwPrefix = os.path.join( | |
101 | os.path.abspath(options.mac_framework_prefix), | |
102 | "%s.framework/Versions/%s" % (getFrameworkName(options), getWxRelease(wxRoot))) | |
103 | return fwPrefix | |
104 | ||
105 | ||
e5ad1e9d | 106 | def macFixupInstallNames(destdir, prefix, buildDir=None): |
3b2c81c7 RD |
107 | # When an installdir is used then the install_names embedded in |
108 | # the dylibs are not correct. Reset the IDs and the dependencies | |
109 | # to use just the prefix. | |
016a3d4c | 110 | print("**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir)) |
3b2c81c7 RD |
111 | pwd = os.getcwd() |
112 | os.chdir(destdir+prefix+'/lib') | |
113 | dylibs = glob.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib') | |
114 | for lib in dylibs: | |
115 | cmd = 'install_name_tool -id %s/lib/%s %s/lib/%s' % \ | |
116 | (prefix,lib, destdir+prefix,lib) | |
016a3d4c | 117 | print(cmd) |
6d6f2e7c | 118 | run(cmd) |
3b2c81c7 | 119 | for dep in dylibs: |
e5ad1e9d RD |
120 | if buildDir is not None: |
121 | cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \ | |
122 | (buildDir,dep, prefix,dep, destdir+prefix,lib) | |
123 | else: | |
124 | cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \ | |
125 | (destdir+prefix,dep, prefix,dep, destdir+prefix,lib) | |
016a3d4c | 126 | print(cmd) |
6d6f2e7c | 127 | run(cmd) |
3b2c81c7 RD |
128 | os.chdir(pwd) |
129 | ||
130 | ||
6d6f2e7c RD |
131 | def run(cmd): |
132 | global verbose | |
133 | if verbose: | |
016a3d4c | 134 | print("Running %s" % cmd) |
6d6f2e7c | 135 | return exitIfError(os.system(cmd), "Error running %s" % cmd) |
3b2c81c7 | 136 | |
e2db04f8 | 137 | |
016a3d4c RD |
138 | def getoutput(cmd): |
139 | sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
140 | output = None | |
141 | output = sp.stdout.read() | |
142 | if sys.version_info > (3,): | |
143 | output = output.decode('utf-8') # TODO: is utf-8 okay here? | |
144 | output = output.rstrip() | |
145 | rval = sp.wait() | |
146 | if rval: | |
147 | # Failed! | |
148 | print("Command '%s' failed with exit code %d." % (cmd, rval)) | |
149 | sys.exit(rval) | |
150 | return output | |
151 | ||
152 | ||
3b2c81c7 RD |
153 | def main(scriptName, args): |
154 | global scriptDir | |
155 | global wxRootDir | |
156 | global contribDir | |
157 | global options | |
158 | global configure_opts | |
159 | global wxBuilder | |
160 | ||
161 | scriptDir = os.path.dirname(os.path.abspath(scriptName)) | |
162 | wxRootDir = os.path.abspath(os.path.join(scriptDir, "..", "..")) | |
163 | ||
164 | contribDir = os.path.join("contrib", "src") | |
165 | installDir = None | |
166 | ||
6d6f2e7c | 167 | VERSION = tuple([int(i) for i in getWxRelease().split('.')[:2]]) |
3b2c81c7 RD |
168 | |
169 | if sys.platform.startswith("win"): | |
170 | contribDir = os.path.join(wxRootDir, "contrib", "build") | |
171 | ||
172 | if sys.platform.startswith("win"): | |
173 | toolkit = "msvc" | |
174 | else: | |
175 | toolkit = "autoconf" | |
176 | ||
e2db04f8 RD |
177 | defJobs = str(numCPUs()) |
178 | defFwPrefix = '/Library/Frameworks' | |
179 | ||
3b2c81c7 | 180 | option_dict = { |
e2db04f8 RD |
181 | "clean" : (False, "Clean all files from the build directory"), |
182 | "debug" : (False, "Build the library in debug symbols"), | |
183 | "builddir" : ("", "Directory where the build will be performed for autoconf builds."), | |
184 | "prefix" : ("", "Configured prefix to use for autoconf builds. Defaults to installdir if set. Ignored for framework builds."), | |
185 | "jobs" : (defJobs, "Number of jobs to run at one time in make. Default: %s" % defJobs), | |
186 | "install" : (False, "Install the toolkit to the installdir directory, or the default dir."), | |
187 | "installdir" : ("", "Directory where built wxWidgets will be installed"), | |
188 | "mac_distdir" : (None, "If set on Mac, will create an installer package in the specified dir."), | |
189 | "mac_universal_binary" | |
508c5afe | 190 | : ("", "Comma separated list of architectures to include in the Mac universal binary"), |
3b2c81c7 | 191 | "mac_framework" : (False, "Install the Mac build as a framework"), |
e2db04f8 RD |
192 | "mac_framework_prefix" |
193 | : (defFwPrefix, "Prefix where the framework should be installed. Default: %s" % defFwPrefix), | |
932d0768 | 194 | "cairo" : (False, "Enable dynamicly loading the Cairo lib for wxGraphicsContext on MSW"), |
e2db04f8 RD |
195 | "no_config" : (False, "Turn off configure step on autoconf builds"), |
196 | "config_only" : (False, "Only run the configure step and then exit"), | |
197 | "rebake" : (False, "Regenerate Bakefile and autoconf files"), | |
198 | "unicode" : (False, "Build the library with unicode support"), | |
199 | "wxpython" : (False, "Build the wxWidgets library with all options needed by wxPython"), | |
200 | "cocoa" : (False, "Build the old Mac Cooca port."), | |
201 | "osx_cocoa" : (False, "Build the new Cocoa port"), | |
202 | "shared" : (False, "Build wx as a dynamic library"), | |
e2db04f8 RD |
203 | "extra_make" : ("", "Extra args to pass on [n]make's command line."), |
204 | "features" : ("", "A comma-separated list of wxUSE_XYZ defines on Win, or a list of configure flags on unix."), | |
b4f28d1e | 205 | "verbose" : (False, "Print commands as they are run, (to aid with debugging this script)"), |
3b2c81c7 RD |
206 | } |
207 | ||
208 | parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0") | |
e2db04f8 RD |
209 | |
210 | keys = option_dict.keys() | |
016a3d4c | 211 | for opt in sorted(keys): |
3b2c81c7 | 212 | default = option_dict[opt][0] |
3b2c81c7 | 213 | action = "store" |
016a3d4c | 214 | if type(default) == bool: |
3b2c81c7 | 215 | action = "store_true" |
e2db04f8 RD |
216 | parser.add_option("--" + opt, default=default, action=action, dest=opt, |
217 | help=option_dict[opt][1]) | |
3b2c81c7 RD |
218 | |
219 | options, arguments = parser.parse_args(args=args) | |
b4f28d1e RD |
220 | |
221 | global verbose | |
222 | if options.verbose: | |
223 | verbose = True | |
224 | ||
3b2c81c7 RD |
225 | # compiler / build system specific args |
226 | buildDir = options.builddir | |
6d6f2e7c | 227 | args = [] |
3b2c81c7 RD |
228 | installDir = options.installdir |
229 | prefixDir = options.prefix | |
230 | ||
231 | if toolkit == "autoconf": | |
e5ad1e9d RD |
232 | if not buildDir: |
233 | buildDir = os.getcwd() | |
3b2c81c7 RD |
234 | configure_opts = [] |
235 | if options.features != "": | |
236 | configure_opts.extend(options.features.split(" ")) | |
237 | ||
238 | if options.unicode: | |
239 | configure_opts.append("--enable-unicode") | |
240 | ||
241 | if options.debug: | |
242 | configure_opts.append("--enable-debug") | |
243 | ||
3b2c81c7 | 244 | if options.cocoa: |
e5ad1e9d | 245 | configure_opts.append("--with-old_cocoa") |
3b2c81c7 RD |
246 | |
247 | if options.osx_cocoa: | |
248 | configure_opts.append("--with-osx_cocoa") | |
e5ad1e9d | 249 | |
3b2c81c7 RD |
250 | wxpy_configure_opts = [ |
251 | "--with-opengl", | |
252 | "--enable-sound", | |
253 | "--enable-graphics_ctx", | |
254 | "--enable-mediactrl", | |
255 | "--enable-display", | |
256 | "--enable-geometry", | |
257 | "--enable-debug_flag", | |
258 | "--enable-optimise", | |
259 | "--disable-debugreport", | |
260 | "--enable-uiactionsim", | |
261 | ] | |
262 | ||
263 | if sys.platform.startswith("darwin"): | |
264 | wxpy_configure_opts.append("--enable-monolithic") | |
265 | else: | |
266 | wxpy_configure_opts.append("--with-sdl") | |
267 | wxpy_configure_opts.append("--with-gnomeprint") | |
268 | ||
be7a5775 RD |
269 | # Ensure that the Carbon build stays compatible back to 10.4 and |
270 | # for the Cocoa build allow running on 10.5 and newer. We only add | |
271 | # them to the wxpy options because this is a hard-requirement for | |
272 | # wxPython, but other cases it is optional and is left up to the | |
273 | # developer. TODO: there should be a command line option to set | |
274 | # the SDK... | |
275 | if sys.platform.startswith("darwin"): | |
1ffe914a | 276 | xcodePath = getXcodePath() |
68a1c7d3 | 277 | sdks = [ |
1ffe914a RD |
278 | xcodePath+"/SDKs/MacOSX10.5.sdk", |
279 | xcodePath+"/SDKs/MacOSX10.6.sdk", | |
280 | xcodePath+"/SDKs/MacOSX10.7.sdk", | |
68a1c7d3 | 281 | ] |
68a1c7d3 RD |
282 | |
283 | # use the lowest available sdk | |
284 | for sdk in sdks: | |
285 | if os.path.exists(sdk): | |
286 | wxpy_configure_opts.append( | |
287 | "--with-macosx-sdk=%s" % sdk) | |
288 | break | |
be7a5775 | 289 | |
3b2c81c7 RD |
290 | if not options.mac_framework: |
291 | if installDir and not prefixDir: | |
292 | prefixDir = installDir | |
293 | if prefixDir: | |
e2db04f8 | 294 | prefixDir = os.path.abspath(prefixDir) |
3b2c81c7 | 295 | configure_opts.append("--prefix=" + prefixDir) |
e2db04f8 RD |
296 | |
297 | ||
3b2c81c7 RD |
298 | if options.wxpython: |
299 | configure_opts.extend(wxpy_configure_opts) | |
300 | if options.debug: | |
301 | # wxPython likes adding these debug options too | |
302 | configure_opts.append("--enable-debug_gdb") | |
303 | configure_opts.append("--disable-optimise") | |
e2db04f8 RD |
304 | configure_opts.remove("--enable-optimise") |
305 | ||
3b2c81c7 RD |
306 | |
307 | if options.rebake: | |
6d6f2e7c | 308 | retval = run("make -f autogen.mk") |
3b2c81c7 RD |
309 | exitIfError(retval, "Error running autogen.mk") |
310 | ||
311 | if options.mac_framework: | |
e2db04f8 RD |
312 | # TODO: Should options.install be automatically turned on if the |
313 | # mac_framework flag is given? | |
314 | ||
3b2c81c7 RD |
315 | # framework builds always need to be monolithic |
316 | if not "--enable-monolithic" in configure_opts: | |
317 | configure_opts.append("--enable-monolithic") | |
6d6f2e7c | 318 | |
e2db04f8 RD |
319 | # The --prefix given to configure will be the framework prefix |
320 | # plus the framework specific dir structure. | |
321 | prefixDir = getPrefixInFramework(options) | |
6d6f2e7c | 322 | configure_opts.append("--prefix=" + prefixDir) |
5be89298 RD |
323 | |
324 | # the framework build adds symlinks above the installDir + prefixDir folder | |
325 | # so we need to wipe from the framework root instead of inside the prefixDir. | |
326 | frameworkRootDir = os.path.abspath(os.path.join(installDir + prefixDir, "..", "..")) | |
327 | if os.path.exists(frameworkRootDir): | |
328 | if os.path.exists(frameworkRootDir): | |
329 | shutil.rmtree(frameworkRootDir) | |
6d6f2e7c RD |
330 | |
331 | if options.mac_universal_binary: | |
508c5afe | 332 | configure_opts.append("--enable-universal_binary=%s" % options.mac_universal_binary) |
e2db04f8 | 333 | |
3b2c81c7 | 334 | |
016a3d4c | 335 | print("Configure options: " + repr(configure_opts)) |
3b2c81c7 | 336 | wxBuilder = builder.AutoconfBuilder() |
6d6f2e7c | 337 | if not options.no_config and not options.clean: |
3b2c81c7 RD |
338 | olddir = os.getcwd() |
339 | if buildDir: | |
340 | os.chdir(buildDir) | |
341 | exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts), | |
342 | "Error running configure") | |
343 | os.chdir(olddir) | |
e5ad1e9d RD |
344 | |
345 | if options.config_only: | |
016a3d4c | 346 | print("Exiting after configure") |
e5ad1e9d | 347 | return |
3b2c81c7 RD |
348 | |
349 | elif toolkit in ["msvc", "msvcProject"]: | |
350 | flags = {} | |
351 | buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw")) | |
e5ad1e9d | 352 | |
016a3d4c | 353 | print("creating wx/msw/setup.h from setup0.h") |
3b2c81c7 RD |
354 | if options.unicode: |
355 | flags["wxUSE_UNICODE"] = "1" | |
356 | if VERSION < (2,9): | |
357 | flags["wxUSE_UNICODE_MSLU"] = "1" | |
358 | ||
359 | if options.cairo: | |
932d0768 | 360 | if not os.environ.get("CAIRO_ROOT"): |
016a3d4c | 361 | print("WARNING: Expected CAIRO_ROOT set in the environment!") |
3b2c81c7 RD |
362 | flags["wxUSE_CAIRO"] = "1" |
363 | ||
364 | if options.wxpython: | |
365 | flags["wxDIALOG_UNIT_COMPATIBILITY "] = "0" | |
e5ad1e9d | 366 | flags["wxUSE_DEBUGREPORT"] = "0" |
3b2c81c7 | 367 | flags["wxUSE_DIALUP_MANAGER"] = "0" |
e5ad1e9d RD |
368 | flags["wxUSE_GRAPHICS_CONTEXT"] = "1" |
369 | flags["wxUSE_DISPLAY"] = "1" | |
3b2c81c7 RD |
370 | flags["wxUSE_GLCANVAS"] = "1" |
371 | flags["wxUSE_POSTSCRIPT"] = "1" | |
372 | flags["wxUSE_AFM_FOR_POSTSCRIPT"] = "0" | |
3b2c81c7 | 373 | flags["wxUSE_DATEPICKCTRL_GENERIC"] = "1" |
e5ad1e9d | 374 | |
3b2c81c7 RD |
375 | if VERSION < (2,9): |
376 | flags["wxUSE_DIB_FOR_BITMAP"] = "1" | |
377 | ||
378 | if VERSION >= (2,9): | |
379 | flags["wxUSE_UIACTIONSIMULATOR"] = "1" | |
932d0768 | 380 | |
3b2c81c7 RD |
381 | |
382 | mswIncludeDir = os.path.join(wxRootDir, "include", "wx", "msw") | |
383 | setup0File = os.path.join(mswIncludeDir, "setup0.h") | |
384 | setupText = open(setup0File, "rb").read() | |
385 | ||
386 | for flag in flags: | |
387 | setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText) | |
388 | if subsMade == 0: | |
016a3d4c | 389 | print("Flag %s wasn't found in setup0.h!" % flag) |
3b2c81c7 RD |
390 | sys.exit(1) |
391 | ||
392 | setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb") | |
393 | setupFile.write(setupText) | |
394 | setupFile.close() | |
395 | args = [] | |
396 | if toolkit == "msvc": | |
016a3d4c | 397 | print("setting build options...") |
3b2c81c7 RD |
398 | args.append("-f makefile.vc") |
399 | if options.unicode: | |
400 | args.append("UNICODE=1") | |
401 | if VERSION < (2,9): | |
402 | args.append("MSLU=1") | |
403 | ||
404 | if options.wxpython: | |
405 | args.append("OFFICIAL_BUILD=1") | |
406 | args.append("SHARED=1") | |
407 | args.append("MONOLITHIC=0") | |
408 | args.append("USE_OPENGL=1") | |
409 | args.append("USE_GDIPLUS=1") | |
3b2c81c7 RD |
410 | |
411 | if not options.debug: | |
3b2c81c7 RD |
412 | args.append("BUILD=release") |
413 | else: | |
414 | args.append("BUILD=debug") | |
9f2b6b31 RD |
415 | |
416 | if options.shared: | |
417 | args.append("SHARED=1") | |
932d0768 | 418 | |
9f2b6b31 | 419 | if options.cairo: |
932d0768 RD |
420 | args.append( |
421 | "CPPFLAGS=/I%s" % | |
422 | os.path.join(os.environ.get("CAIRO_ROOT", ""), 'include\\cairo')) | |
3b2c81c7 RD |
423 | |
424 | wxBuilder = builder.MSVCBuilder() | |
425 | ||
426 | if toolkit == "msvcProject": | |
427 | args = [] | |
428 | if options.shared or options.wxpython: | |
429 | args.append("wx_dll.dsw") | |
430 | else: | |
431 | args.append("wx.dsw") | |
432 | ||
433 | # TODO: | |
434 | wxBuilder = builder.MSVCProjectBuilder() | |
435 | ||
e2db04f8 | 436 | |
3b2c81c7 | 437 | if not wxBuilder: |
016a3d4c | 438 | print("Builder not available for your specified platform/compiler.") |
3b2c81c7 RD |
439 | sys.exit(1) |
440 | ||
441 | if options.clean: | |
016a3d4c | 442 | print("Performing cleanup.") |
9f2b6b31 | 443 | wxBuilder.clean(dir=buildDir, options=args) |
3b2c81c7 RD |
444 | |
445 | sys.exit(0) | |
6d6f2e7c RD |
446 | |
447 | if options.extra_make: | |
448 | args.append(options.extra_make) | |
e2db04f8 | 449 | |
5be89298 RD |
450 | if not sys.platform.startswith("win"): |
451 | args.append("--jobs=" + options.jobs) | |
6d6f2e7c | 452 | exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building") |
6d6f2e7c RD |
453 | |
454 | if options.install: | |
455 | extra=None | |
456 | if installDir: | |
457 | extra = ['DESTDIR='+installDir] | |
9f2b6b31 | 458 | wxBuilder.install(dir=buildDir, options=extra) |
e2db04f8 RD |
459 | |
460 | if options.install and options.mac_framework: | |
3b2c81c7 RD |
461 | |
462 | def renameLibrary(libname, frameworkname): | |
463 | reallib = libname | |
464 | links = [] | |
465 | while os.path.islink(reallib): | |
466 | links.append(reallib) | |
467 | reallib = "lib/" + os.readlink(reallib) | |
468 | ||
016a3d4c | 469 | #print("reallib is %s" % reallib) |
6d6f2e7c | 470 | run("mv -f %s lib/%s.dylib" % (reallib, frameworkname)) |
3b2c81c7 RD |
471 | |
472 | for link in links: | |
6d6f2e7c | 473 | run("ln -s -f %s.dylib %s" % (frameworkname, link)) |
3b2c81c7 | 474 | |
6d6f2e7c RD |
475 | frameworkRootDir = prefixDir |
476 | if installDir: | |
016a3d4c | 477 | print("installDir = %s" % installDir) |
6d6f2e7c RD |
478 | frameworkRootDir = installDir + prefixDir |
479 | os.chdir(frameworkRootDir) | |
3b2c81c7 RD |
480 | build_string = "" |
481 | if options.debug: | |
482 | build_string = "d" | |
6d6f2e7c | 483 | |
b4f28d1e | 484 | fwname = getFrameworkName(options) |
016a3d4c RD |
485 | version = getoutput("bin/wx-config --release") |
486 | version_full = getoutput("bin/wx-config --version") | |
487 | basename = getoutput("bin/wx-config --basename") | |
488 | configname = getoutput("bin/wx-config --selected-config") | |
5be89298 RD |
489 | |
490 | os.makedirs("Resources") | |
491 | wxplist = dict( | |
492 | CFBundleDevelopmentRegion="English", | |
493 | CFBundleIdentifier='org.wxwidgets.wxosxcocoa', | |
494 | CFBundleName=fwname, | |
495 | CFBundleVersion=version_full, | |
496 | CFBundleExecutable=fwname, | |
497 | CFBundleGetInfoString="%s %s" % (fwname, version_full), | |
498 | CFBundlePackageType="FMWK", | |
499 | CFBundleSignature="WXCO", | |
500 | CFBundleShortVersionString=version_full, | |
501 | CFBundleInfoDictionaryVersion="6.0", | |
502 | ) | |
503 | ||
504 | import plistlib | |
505 | plistlib.writePlist(wxplist, os.path.join(frameworkRootDir, "Resources", "Info.plist")) | |
3b2c81c7 RD |
506 | |
507 | # we make wx the "actual" library file and link to it from libwhatever.dylib | |
508 | # so that things can link to wx and survive minor version changes | |
b4f28d1e RD |
509 | renameLibrary("lib/lib%s-%s.dylib" % (basename, version), fwname) |
510 | run("ln -s -f lib/%s.dylib %s" % (fwname, fwname)) | |
3b2c81c7 | 511 | |
5be89298 | 512 | run("ln -s -f include Headers") |
3b2c81c7 RD |
513 | |
514 | for lib in ["GL", "STC", "Gizmos", "Gizmos_xrc"]: | |
515 | libfile = "lib/lib%s_%s-%s.dylib" % (basename, lib.lower(), version) | |
516 | if os.path.exists(libfile): | |
517 | frameworkDir = "framework/wx%s/%s" % (lib, version) | |
518 | if not os.path.exists(frameworkDir): | |
519 | os.makedirs(frameworkDir) | |
520 | renameLibrary(libfile, "wx" + lib) | |
6d6f2e7c | 521 | run("ln -s -f ../../../%s %s/wx%s" % (libfile, frameworkDir, lib)) |
3b2c81c7 RD |
522 | |
523 | for lib in glob.glob("lib/*.dylib"): | |
524 | if not os.path.islink(lib): | |
525 | corelibname = "lib/lib%s-%s.0.dylib" % (basename, version) | |
6d6f2e7c RD |
526 | run("install_name_tool -id %s %s" % (os.path.join(prefixDir, lib), lib)) |
527 | run("install_name_tool -change %s %s %s" % (os.path.join(frameworkRootDir, corelibname), os.path.join(prefixDir, corelibname), lib)) | |
b4f28d1e | 528 | |
3b2c81c7 RD |
529 | os.chdir("include") |
530 | ||
e2db04f8 | 531 | header_template = """ |
3b2c81c7 RD |
532 | #ifndef __WX_FRAMEWORK_HEADER__ |
533 | #define __WX_FRAMEWORK_HEADER__ | |
534 | ||
535 | %s | |
536 | ||
537 | #endif // __WX_FRAMEWORK_HEADER__ | |
538 | """ | |
539 | headers = "" | |
540 | header_dir = "wx-%s/wx" % version | |
541 | for include in glob.glob(header_dir + "/*.h"): | |
5be89298 | 542 | headers += "#include <wx/" + os.path.basename(include) + ">\n" |
3b2c81c7 | 543 | |
5be89298 | 544 | framework_header = open("%s.h" % fwname, "w") |
3b2c81c7 RD |
545 | framework_header.write(header_template % headers) |
546 | framework_header.close() | |
547 | ||
6d6f2e7c | 548 | run("ln -s -f %s wx" % header_dir) |
5be89298 RD |
549 | os.chdir("wx-%s/wx" % version) |
550 | run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h setup.h" % configname) | |
3b2c81c7 | 551 | |
5be89298 RD |
552 | os.chdir(os.path.join(frameworkRootDir, "..")) |
553 | run("ln -s -f %s Current" % getWxRelease()) | |
554 | os.chdir("..") | |
6d6f2e7c RD |
555 | run("ln -s -f Versions/Current/Headers Headers") |
556 | run("ln -s -f Versions/Current/Resources Resources") | |
b4f28d1e | 557 | run("ln -s -f Versions/Current/%s %s" % (fwname, fwname)) |
3b2c81c7 | 558 | |
6d6f2e7c | 559 | # sanity check to ensure the symlink works |
e2db04f8 | 560 | os.chdir("Versions/Current") |
b4f28d1e RD |
561 | |
562 | # put info about the framework into wx-config | |
563 | os.chdir(frameworkRootDir) | |
564 | text = file('lib/wx/config/%s' % configname).read() | |
565 | text = text.replace("MAC_FRAMEWORK=", "MAC_FRAMEWORK=%s" % getFrameworkName(options)) | |
566 | if options.mac_framework_prefix not in ['/Library/Frameworks', | |
567 | '/System/Library/Frameworks']: | |
568 | text = text.replace("MAC_FRAMEWORK_PREFIX=", | |
569 | "MAC_FRAMEWORK_PREFIX=%s" % options.mac_framework_prefix) | |
570 | file('lib/wx/config/%s' % configname, 'w').write(text) | |
571 | ||
572 | # The framework is finished! | |
016a3d4c | 573 | print("wxWidgets framework created at: " + |
e2db04f8 RD |
574 | os.path.join( installDir, |
575 | options.mac_framework_prefix, | |
016a3d4c | 576 | '%s.framework' % fwname)) |
e2db04f8 RD |
577 | |
578 | ||
579 | # adjust the install_name if needed | |
3b2c81c7 RD |
580 | if sys.platform.startswith("darwin") and \ |
581 | options.install and \ | |
582 | options.installdir and \ | |
e2db04f8 | 583 | not options.mac_framework and \ |
3b2c81c7 | 584 | not options.wxpython: # wxPython's build will do this later if needed |
6d6f2e7c RD |
585 | if not prefixDir: |
586 | prefixDir = '/usr/local' | |
587 | macFixupInstallNames(options.installdir, prefixDir)#, buildDir) | |
588 | ||
589 | # make a package if a destdir was set. | |
590 | if options.mac_framework and \ | |
e2db04f8 | 591 | options.install and \ |
6d6f2e7c RD |
592 | options.installdir and \ |
593 | options.mac_distdir: | |
3b2c81c7 | 594 | |
6d6f2e7c RD |
595 | if os.path.exists(options.mac_distdir): |
596 | shutil.rmtree(options.mac_distdir) | |
597 | ||
598 | packagedir = os.path.join(options.mac_distdir, "packages") | |
599 | os.makedirs(packagedir) | |
600 | basename = os.path.basename(prefixDir.split(".")[0]) | |
601 | packageName = basename + "-" + getWxRelease() | |
1ffe914a | 602 | packageMakerPath = getXcodePath()+"/usr/bin/packagemaker " |
6d6f2e7c RD |
603 | args = [] |
604 | args.append("--root %s" % options.installdir) | |
605 | args.append("--id org.wxwidgets.%s" % basename.lower()) | |
606 | args.append("--title %s" % packageName) | |
607 | args.append("--version %s" % getWxRelease()) | |
608 | args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg")) | |
609 | cmd = packageMakerPath + ' '.join(args) | |
016a3d4c | 610 | print("cmd = %s" % cmd) |
6d6f2e7c RD |
611 | run(cmd) |
612 | ||
613 | os.chdir(options.mac_distdir) | |
614 | ||
615 | run('hdiutil create -srcfolder %s -volname "%s" -imagekey zlib-level=9 %s.dmg' % (packagedir, packageName, packageName)) | |
3b2c81c7 | 616 | |
6d6f2e7c | 617 | shutil.rmtree(packagedir) |
3b2c81c7 RD |
618 | |
619 | if __name__ == '__main__': | |
620 | exitWithException = False # use sys.exit instead | |
621 | main(sys.argv[0], sys.argv[1:]) | |
622 |