/[ascend]/trunk/scons/installgtk.py
ViewVC logotype

Contents of /trunk/scons/installgtk.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2135 - (show annotations) (download) (as text)
Sat Dec 19 03:43:14 2009 UTC (10 years, 3 months ago) by jpye
File MIME type: text/x-python
File size: 5118 byte(s)
Woops, commited this file to the wrong branch.
1 # SCons support for bundled GTK installation
2 # Written by John Pye, Nov 2009
3
4
5 """
6 This tool provides SCons support for installing the necessary files to allow
7 GTK to run in a standalone installation.
8
9 This approach is suitable for Windows and Mac where we often must assume that
10 GTK+ is not separately installed on the system, or can't assume that the version
11 will be compatible.
12
13 Ultimately, it would be desirable for a Mac 'framework' to be utilised for this
14 purpose, but that is not yet available.
15
16 To use it you must copy this file into the scons/SCons/Tools directory or use
17 the tooldir arg in the Tool function and put a line like 'env.Tool("InstallGTK")'
18 into your file. Then you can do 'env.InstallGTK(sourcebinary, targetdir)' which
19 will read dependencies for sourcebinary and copy required libraries and
20 other files into targetdir.
21 """
22
23 #import SCons.Builder
24 #import SCons.Util
25 #import SCons.Scanner
26 import os.path
27 import glob
28 import subprocess, sys, os.path, re, shutil
29
30 otool_re = re.compile(r"""\s+(.+)\s\(compatibility version (.*), current version (.*)\)""")
31
32 def find_deps(binary):
33 deps = set()
34 P = subprocess.Popen(['/usr/bin/otool','-L',binary],stdout=subprocess.PIPE)
35 O = P.communicate()[0].strip()
36 for o in O.split("\n")[1:]:
37 m = otool_re.match(o)
38 #print " -->",m.group(1)
39 deps.add(m.group(1))
40 return deps
41
42 def generate(env):
43 pass
44
45 def exists(env):
46 pass
47
48 if __name__ == "__main__":
49 import modulefinder
50 M = modulefinder.ModuleFinder()
51 sys.path.append("..")
52 script = os.path.normpath(os.path.join(sys.path[0],"../pygtk/gtkbrowser.py"))
53 M.run_script(script)
54
55 imports = set()
56 ignore_paths = ['/System/Library/Frameworks/Python.framework'
57 ,'/System/Library/Frameworks/Carbon.framework'
58 ,'/System/Library/Frameworks/Cocoa.framework'
59 ,os.path.dirname(script)]
60 for name, m in M.modules.items():
61 if not m.__file__:
62 continue
63 ok = True
64 for i in ignore_paths:
65 if os.path.commonprefix([i,m.__file__]) == i:
66 ok = False
67 if ok is False:
68 continue
69
70 imports.add(m)
71 print m
72
73 print "\n\nChecking otool deps"
74
75 files = set()
76 pyfiles = set()
77 for m in imports:
78 files.add(m.__file__)
79
80 if m.__file__[-3:] == ".so":
81 print "FILE:",m.__file__
82 files |= find_deps(m.__file__)
83
84 elif m.__file__[-3:] == ".py":
85 print "PY:",m.__file__
86 pyfiles.add(m.__file__)
87
88 print "\n\nOTOOL DEPS"
89 for f in files:
90 if f[-3:] != ".py":
91 print f
92
93 print "\n\nRemoving system libs from list"
94 realimports = set()
95 ignore_paths += ['/usr/lib']
96 for f in files:
97 ok = True
98 for i in ignore_paths:
99 if os.path.commonprefix([i,f]) == i:
100 ok = False
101 if ok is False:
102 #print "REMOVE",f
103 continue
104 realimports.add(f)
105 print f
106
107 distpath = os.path.normpath(os.path.join(sys.path[0],"../dist"))
108 if not os.path.exists(distpath):
109 os.mkdir(distpath)
110 targetpath=os.path.join(distpath,"gtk.bundle")
111 if not os.path.exists(targetpath):
112 os.mkdir(targetpath)
113
114 pytarget=os.path.join(targetpath,"python")
115 if not os.path.exists(pytarget):
116 os.mkdir(pytarget)
117 print "PYTHON TARGET =",pytarget
118
119
120 print "\nCopying Python includes"
121 pysite="/Library/Python/2.5/site-packages/"
122 if pysite[-1:]!="/":
123 raise RuntimeError("missing trailing slash in pysite")
124
125 gtksite = os.path.expanduser("~/gtk/inst/")
126 if gtksite[-1:]!="/":
127 raise RuntimeError("missing trailing slash in gtksite")
128
129 for f in pyfiles:
130 if os.path.commonprefix([f,pysite]) == pysite:
131 r = f[len(pysite):]
132 else:
133 raise RuntimeError("Unknown python file location '%s'" % f)
134
135 dir,f1 = os.path.split(r)
136 if not os.path.exists(os.path.join(pytarget,dir)):
137 print "Create directory '%s'"% dir
138 os.makedirs(os.path.join(pytarget,dir))
139
140 print "Copy %s --> %s" % (f, os.path.join(pytarget,r))
141 shutil.copy(f,os.path.join(pytarget,r))
142
143 print "\nCopying Python shared libraries"
144 copied = set()
145 for f in files:
146 if os.path.commonprefix([f,pysite]) == pysite:
147 r = f[len(pysite):]
148 else:
149 continue
150 print "Copy %s --> %s" % (f, os.path.join(pytarget,r))
151
152 dir,f1 = os.path.split(r)
153 if not os.path.exists(os.path.join(pytarget,dir)):
154 print "Create directory '%s'"% dir
155 os.makedirs(os.path.join(pytarget,dir))
156
157 shutil.copy(f,os.path.join(pytarget,r))
158 copied.add(f)
159
160 print "\nCopying GTK libraries"
161 gtktarget = os.path.join(targetpath,"gtk")
162 if not os.path.exists(gtktarget):
163 os.mkdir(gtktarget)
164
165 for f in files:
166 if os.path.commonprefix([f,gtksite]) == gtksite:
167 r = f[len(pysite):]
168 else:
169 continue
170
171 if not os.path.exists(os.path.join(gtktarget,dir)):
172 print "Create directory '%s'"% dir
173 os.makedirs(os.path.join(gtktarget,dir))
174
175 print "Copy %s --> %s" % (f, os.path.join(gtktarget,r))
176 shutil.copy(f,os.path.join(gtktarget,r))
177 copied.add(f)
178
179 if copied != files:
180 print "Some library files were not copied!"
181
182
183
184 # ETC="$PREFIX/etc/gimp/ $PREFIX/etc/gtk-2.0/ $PREFIX/etc/pango/ $PREFIX/lib/gimp/2.0/python/*.py* $PREFIX/lib/gimp/2.0/environ $PREFIX/lib/gimp/2.0/interpreters $PREFIX/etc/fonts"
185
186 # get the 'etc' files for GTK, Pango, fonts
187
188
189
190 #SHARE=`echo $PREFIX/share/gimp/ $PREFIX/share/locale/*/LC_MESSAGES/gimp*`
191
192 # get the share files for
193

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22