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