Mercurial > hg > mxe-octave-anirudha
annotate darwin_files/standalone.py @ 3235:f53543bd5dd6 GSoC_end
[Darwin] Copy launch_octave.sh script inside the App Bundle
author | Anirudha Bose <ani07nov@gmail.com> |
---|---|
date | Tue, 24 Sep 2013 01:33:33 +0530 |
parents | 2a5a191f6302 |
children |
rev | line source |
---|---|
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
2 ## |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
3 ## This Python script can be used to rewrite dylib references in Mach-O headers |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
4 ## and resolve the dynamic shared library install names which originally point |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
5 ## to the libraries in MXE $(HOST_LIBDIR). |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
6 ## |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
7 ## Requirements: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
8 ## * Python 2.7 |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
9 ## * Macholib (pip install http://pypi.python.org/pypi/macholib) |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
10 ## |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
11 ## Usage: |
3225
2a5a191f6302
Specify in usage message that "octave.app" must be created inside "dist" folder
Anirudha Bose <ani07nov@gmail.com>
parents:
3224
diff
changeset
|
12 ## * Make sure the MXE directory is your current working directory. Create an App Bundle "octave.app" |
2a5a191f6302
Specify in usage message that "octave.app" must be created inside "dist" folder
Anirudha Bose <ani07nov@gmail.com>
parents:
3224
diff
changeset
|
13 ## and save it in the path "mxe-octave-anirudha/dist/"; then execute the following command: |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
14 ## |
3235
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
15 ## python -mmacholib find ./dist/Octave-3.7.5.app/Contents/Resources/ 2>/dev/null | python ./darwin_files/standalone.py |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
16 ## |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
17 ## Important Notes: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
18 ## * Octave should be compiled with the option -headerpad_max_install_names in the LDFLAGS. |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
19 ## * The script must be executed as root, if Octave was compiled with root permissions. |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
20 ## * Before applying this script, make sure the bin and lib directory is present inside the |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
21 ## Resources folder. |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
22 ## * Shared libraries like libcholmod.so, libumfpack.so, and others which end with .so |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
23 ## extension are not assigned any path in the Mach-O headers during compilation. This is |
3217
a3a6870253d7
[Darwin] darwin_files/standalone.py: Enable running of script on the same application bundle more than once
Anirudha Bose <ani07nov@gmail.com>
parents:
3216
diff
changeset
|
24 ## likely to happen while using MXE. This script can fix such errors too. |
3222
b25bac22a278
darwin_files/standalone.py: Add information about the assumed location of MXE directory
Anirudha Bose <ani07nov@gmail.com>
parents:
3221
diff
changeset
|
25 ## * The script assumes that the path to MXE directory starts with "/Users...". For example, the MXE |
b25bac22a278
darwin_files/standalone.py: Add information about the assumed location of MXE directory
Anirudha Bose <ani07nov@gmail.com>
parents:
3221
diff
changeset
|
26 ## directory can be located in a place like "/Users/mac6-user1/mxe/mxe-octave-anirudha/". |
b25bac22a278
darwin_files/standalone.py: Add information about the assumed location of MXE directory
Anirudha Bose <ani07nov@gmail.com>
parents:
3221
diff
changeset
|
27 ## The Mach-O headers which point to System libraries or libraries belonging to Macports are |
b25bac22a278
darwin_files/standalone.py: Add information about the assumed location of MXE directory
Anirudha Bose <ani07nov@gmail.com>
parents:
3221
diff
changeset
|
28 ## ignored. |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
29 |
3216
488d0100db6e
[Darwin] darwin_files/standalone.py: Move "from __future__import" line to the beginning of the file
Anirudha Bose <ani07nov@gmail.com>
parents:
3215
diff
changeset
|
30 from __future__ import print_function |
488d0100db6e
[Darwin] darwin_files/standalone.py: Move "from __future__import" line to the beginning of the file
Anirudha Bose <ani07nov@gmail.com>
parents:
3215
diff
changeset
|
31 from macholib.MachO import MachO |
488d0100db6e
[Darwin] darwin_files/standalone.py: Move "from __future__import" line to the beginning of the file
Anirudha Bose <ani07nov@gmail.com>
parents:
3215
diff
changeset
|
32 |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
33 __author__ = "Anirudha Bose" |
3223
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
34 __email__ = "ani07nov@gmail.com" |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
35 |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
36 import os |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
37 import sys |
3235
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
38 import subprocess |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
39 |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
40 def dylibs_fix(path): |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
41 m = MachO(path) |
3220
de181f6edcbf
[Darwin] darwin_files/standalone.py: Add command to strip Mach-O files in the app bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3217
diff
changeset
|
42 os.system("sudo strip "+path+" 2>/dev/null") |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
43 for header in m.headers: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
44 seen = set() |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
45 for idx, name, other in header.walkRelocatables(): |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
46 if other not in seen: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
47 seen.add(other) |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
48 relative_name = other[other.find("lib"):] |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
49 if other.startswith("/Users"): |
3220
de181f6edcbf
[Darwin] darwin_files/standalone.py: Add command to strip Mach-O files in the app bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3217
diff
changeset
|
50 command = 'sudo install_name_tool -change "%s" "@executable_path/../%s" ./%s'%(other,relative_name,path) |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
51 os.system(command) |
3217
a3a6870253d7
[Darwin] darwin_files/standalone.py: Enable running of script on the same application bundle more than once
Anirudha Bose <ani07nov@gmail.com>
parents:
3216
diff
changeset
|
52 elif other.endswith(".so") and not other.startswith("@executable_path"): |
3220
de181f6edcbf
[Darwin] darwin_files/standalone.py: Add command to strip Mach-O files in the app bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3217
diff
changeset
|
53 command = 'sudo install_name_tool -change "%s" "@executable_path/../lib/%s" ./%s'%(other,other,path) |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
54 os.system(command) |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
55 def main(): |
3220
de181f6edcbf
[Darwin] darwin_files/standalone.py: Add command to strip Mach-O files in the app bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3217
diff
changeset
|
56 print("Stripping Mach-O files and rewriting Mach-O headers ...") |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
57 for path in sys.stdin: |
3215
d1fb703f2cd0
darwin_files/standalone.py: Remove trailing new-line character from path name
Anirudha Bose <ani07nov@gmail.com>
parents:
3214
diff
changeset
|
58 dylibs_fix(path.replace('\n','')) |
3223
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
59 print("[Completed]") |
3235
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
60 Resources_dir = "./dist/Octave-3.7.5.app/Contents/Resources/" |
3223
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
61 print("\nBuilding Octave Forge packages ...") |
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
62 os.system("make octave-forge-packages") |
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
63 os.system("cp ./build_packages.m %s/src/"%(Resources_dir)) |
8654ba32cd42
darwin_files/standalone.py: Enable building of Octave Forge Packages
Anirudha Bose <ani07nov@gmail.com>
parents:
3222
diff
changeset
|
64 print("[Completed]") |
3224
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
65 print("\nSetting up octaverc file ...") |
3235
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
66 f = open("./dist/Octave-3.7.5.app/Contents/Resources/share/octave/site/m/startup/octaverc","w") |
3224
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
67 f.write("EXEC_PATH (cstrcat (fullfile (OCTAVE_HOME, 'bin'), pathsep, EXEC_PATH));") |
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
68 f.close() |
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
69 print("[Completed]") |
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
70 print("\nMaking all files writable by user ...") |
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
71 os.system("chmod -R u+w %s"%(Resources_dir)) |
436c9b7f2dfd
darwin_files/standalone.py: Set up octaverc file, and make all files writable by user
Anirudha Bose <ani07nov@gmail.com>
parents:
3223
diff
changeset
|
72 print("[Completed]") |
3235
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
73 print("\nCopying Octave Application Bundle launch script ...") |
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
74 os.system("cp ./darwin_files/launch_octave.sh ./dist/Octave-3.7.5.app/Contents/Resources/") |
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
75 os.system("chmod +x ./dist/Octave-3.7.5.app/Contents/Resources/launch_octave.sh") |
f53543bd5dd6
[Darwin] Copy launch_octave.sh script inside the App Bundle
Anirudha Bose <ani07nov@gmail.com>
parents:
3225
diff
changeset
|
76 print("[Completed]") |
3214
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
77 |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
78 if __name__ == '__main__': |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
79 try: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
80 sys.exit(main()) |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
81 except KeyboardInterrupt: |
0e32c67b78ca
[Darwin] Python script for fixing "dyld: Library not loaded" errors
Anirudha Bose <ani07nov@gmail.com>
parents:
diff
changeset
|
82 pass |