Split python into a host and target build. Also add a HostPython macro to convenientl...
[openwrt/svn-archive/archive.git] / lang / pyqt4 / patches / 100-cross-compile.patch
1 ---
2 configure.py | 218 ++++++++++++++++++++++++++++++++++++++++-------------------
3 1 file changed, 149 insertions(+), 69 deletions(-)
4
5 --- PyQt-x11-gpl-4.7.4.orig/configure.py
6 +++ PyQt-x11-gpl-4.7.4/configure.py
7 @@ -33,6 +33,7 @@ import os
8 import glob
9 import optparse
10 import shutil
11 +import re
12
13 import sipconfig
14
15 @@ -173,25 +174,17 @@ def create_optparser():
16 metavar="PLUGIN", dest="staticplugins", help="add PLUGIN to the "
17 "list be linked (if Qt is built as static libraries)")
18
19 - if sys.platform != 'win32':
20 - if sys.platform in ('linux2', 'darwin'):
21 - pip_default = True
22 - pip_default_str = "enabled"
23 - else:
24 - pip_default = False
25 - pip_default_str = "disabled"
26 -
27 - g.add_option("--protected-is-public", action="store_true",
28 - default=pip_default, dest="prot_is_public",
29 - help="enable building with 'protected' redefined as 'public' "
30 - "[default: %s]" % pip_default_str)
31 - g.add_option("--protected-not-public", action="store_false",
32 - dest="prot_is_public",
33 - help="disable building with 'protected' redefined as 'public'")
34 - g.add_option("-q", "--qmake", action="callback", metavar="FILE",
35 - default=qmake, dest="qmake", callback=store_abspath_file,
36 - type="string",
37 - help="the pathname of qmake [default: %s]" % (qmake or "none"))
38 + g.add_option("--protected-is-public", action="store_true",
39 + default=True, dest="prot_is_public",
40 + help="enable building with 'protected' redefined as 'public' "
41 + "[default: True]")
42 + g.add_option("--protected-not-public", action="store_false",
43 + dest="prot_is_public",
44 + help="disable building with 'protected' redefined as 'public'")
45 + g.add_option("-q", "--qmake", action="callback", metavar="FILE",
46 + default=qmake, dest="qmake", callback=store_abspath_file,
47 + type="string",
48 + help="the pathname of qmake [default: %s]" % (qmake or "none"))
49
50 g.add_option("-s", "--dbus", action="callback", metavar="DIR",
51 dest="pydbusincdir", callback=store_abspath_dir, type="string",
52 @@ -199,13 +192,13 @@ def create_optparser():
53 "[default: supplied by pkg-config]")
54 p.add_option_group(g)
55
56 - if sys.platform == 'darwin':
57 - g = optparse.OptionGroup(p, title="MacOS X Configuration")
58 - g.add_option("--use-arch", action="store", metavar="ARCH",
59 - dest="use_arch", choices=["i386", "x86_64", "ppc"],
60 - help="the architecture to use when running pyuic4 "
61 - "[default: system default]")
62 - p.add_option_group(g)
63 + g = optparse.OptionGroup(p, title="Arch Configuration")
64 + g.add_option("--use-arch", action="store", metavar="ARCH",
65 + dest="use_arch", choices=["", "i386", "x86_64", "ppc", "arm"],
66 + default="",
67 + help="the architecture to use when running pyuic4 "
68 + "[default: system default]")
69 + p.add_option_group(g)
70
71 # Installation.
72 g = optparse.OptionGroup(p, title="Installation")
73 @@ -264,12 +257,38 @@ def create_optparser():
74 "QTDIR/qsci]")
75 p.add_option_group(g)
76
77 + # Crosscompilation
78 + g = optparse.OptionGroup(p, title="Crosscompilation")
79 + g.add_option("--crosscompile", action="store_true",
80 + default=False, dest="crosscompile",
81 + help="Set, if cross-compiling")
82 + g.add_option("--sipconfig-macros", action="callback", metavar="FILE",
83 + default=None, dest="sipconfig_macros", type="string",
84 + callback=store_abspath_file,
85 + help="Path to a file containing sipconfig macros")
86 + g.add_option("--qmake-prefix", action="append",
87 + default=[], dest="qmake_prefixes", type="string",
88 + help="Commandline prefix to qmake")
89 + g.add_option("--qmake-spec", action="callback", metavar="FILE",
90 + default=None, dest="qmake_spec", callback=store_abspath,
91 + type="string",
92 + help="the pathname to qmake spec file")
93 + g.add_option("--qtdirs-file", action="callback", metavar="FILE",
94 + default=None, dest="qtdirs_file", callback=store_abspath_file,
95 + type="string",
96 + help="Path to a predefined qtdirs file")
97 + g.add_option("--pydbus-installdir", action="callback", metavar="DIR",
98 + default=None, dest="pydbus_installdir", callback=store_abspath,
99 + type="string",
100 + help="Install dir for pydbus module")
101 + p.add_option_group(g)
102 +
103 return p
104
105
106 class pyrccMakefile(sipconfig.ProgramMakefile):
107 """This class implements the Makefile for pyrcc. This is specialised so
108 - that pyrcc is automatically run against the examples.
109 + that pyrcc is automatically run against the examples, if not crosscompiling.
110 """
111
112 def __init__(self):
113 @@ -282,6 +301,8 @@ class pyrccMakefile(sipconfig.ProgramMak
114 def generate_target_default(self, mfile):
115 """Generate the default target."""
116 sipconfig.ProgramMakefile.generate_target_default(self, mfile)
117 + if opts.crosscompile:
118 + return
119
120 # The correct call to pyrcc depends on the Python version.
121 if sys.hexversion >= 0x03000000:
122 @@ -772,7 +793,7 @@ include(%s)
123
124 f.close()
125
126 - run_command("%s %s %s" % (opts.qmake, qmake_args, wrapped_pro))
127 + run_qmake("%s %s" % (qmake_args, wrapped_pro))
128 os.chdir(cwd)
129
130 sipconfig.inform("Creating QPy support libraries Makefile...")
131 @@ -825,12 +846,16 @@ include(%s)
132 # not on Windows (so that normal console use will work).
133 sipconfig.inform("Creating pyuic4 wrapper...")
134
135 - if sys.platform == 'darwin':
136 - gui = True
137 + if opts.use_arch:
138 + gui = False#FIXME
139 use_arch = opts.use_arch
140 else:
141 - gui = False
142 - use_arch = ''
143 + if sys.platform == 'darwin':
144 + gui = True
145 + use_arch = opts.use_arch
146 + else:
147 + gui = False
148 + use_arch = ''
149
150 uicdir=os.path.join(pyqt_modroot, "uic")
151 wrapper = sipconfig.create_wrapper(os.path.join(uicdir, "pyuic.py"), os.path.join("pyuic", "pyuic4"), gui, use_arch)
152 @@ -880,6 +905,7 @@ include(%s)
153 py_major = sipcfg.py_version >> 16
154 py_minor = (sipcfg.py_version >> 8) & 0x0ff
155
156 + print "FIXME CROSSCOMPILE" #FIXME: Crosscompile
157 if sys.platform == 'win32':
158 lib_dir_flag = quote("-L%s" % sipcfg.py_lib_dir)
159 link = "%s -lpython%d%d" % (lib_dir_flag, py_major, py_minor)
160 @@ -938,7 +964,7 @@ include(%s)
161 fout.write(prj)
162 fout.close()
163
164 - run_command("%s %s" % (opts.qmake, qmake_args))
165 + run_qmake(qmake_args)
166 os.chdir(cwd)
167
168 tool.append("designer")
169 @@ -1056,6 +1082,14 @@ def create_config(module, template, macr
170 sipconfig.create_config_module(module, template, content, macros)
171
172
173 +def run_qmake(args):
174 + pfx = " ".join(opts.qmake_prefixes)
175 + if opts.qmake_spec:
176 + spec = "-spec \"" + opts.qmake_spec + "\""
177 + else:
178 + spec = ""
179 + run_command(pfx + " " + opts.qmake + " " + spec + " " + args)
180 +
181 def run_command(cmd):
182 """Run a command and display the output if verbose mode is enabled.
183
184 @@ -1272,30 +1306,38 @@ def check_dbus():
185 """
186 sipconfig.inform("Checking to see if the dbus support module should be built...")
187
188 - sout = get_command_stdout("pkg-config --cflags-only-I --libs dbus-1")
189 - iflags = sout.read().strip()
190 + if opts.crosscompile and not opts.pydbusincdir:
191 + sipconfig.inform("Crosscompiling but no dbus incdir specified. Disabling dbus.")
192 + return
193 +
194 + if not opts.crosscompile:
195 + sout = get_command_stdout("pkg-config --cflags-only-I --libs dbus-1")
196 + iflags = sout.read().strip()
197 +
198 + if not iflags:
199 + sipconfig.inform("DBus v1 does not seem to be installed.")
200 + return
201 +
202 + # Using str() means it will work with both Python v2 and v3.
203 + for f in str(iflags).split():
204 + if f.startswith("-I"):
205 + dbusincdirs.append(f[2:])
206 + elif f.startswith("-L"):
207 + dbuslibdirs.append(f[2:])
208 + elif f.startswith("-l"):
209 + dbuslibs.append(f[2:])
210
211 - if not iflags:
212 - sipconfig.inform("DBus v1 does not seem to be installed.")
213 - return
214 -
215 - # Using str() means it will work with both Python v2 and v3.
216 - for f in str(iflags).split():
217 - if f.startswith("-I"):
218 - dbusincdirs.append(f[2:])
219 - elif f.startswith("-L"):
220 - dbuslibdirs.append(f[2:])
221 - elif f.startswith("-l"):
222 - dbuslibs.append(f[2:])
223 -
224 - try:
225 - import dbus.mainloop
226 - except:
227 - sipconfig.inform("The Python dbus module doesn't seem to be installed.")
228 - return
229 + try:
230 + import dbus.mainloop
231 + except:
232 + sipconfig.inform("The Python dbus module doesn't seem to be installed.")
233 + return
234
235 global pydbusmoddir
236 - pydbusmoddir = dbus.mainloop.__path__[0]
237 + if opts.pydbus_installdir:
238 + pydbusmoddir = opts.pydbus_installdir
239 + else:
240 + pydbusmoddir = dbus.mainloop.__path__[0]
241
242 # Try and find dbus-python.h. We don't use pkg-config because it is broken
243 # for dbus-python (at least for versions up to and including v0.81.0).
244 @@ -1381,6 +1423,7 @@ def set_sip_flags(pyqt):
245
246 pyqt is the configuration instance.
247 """
248 + #FIXME: Needs some crosscompile fixes.
249 # If we don't check for signed interpreters, we exclude the 'VendorID'
250 # feature
251 if not opts.vendorcheck:
252 @@ -1779,6 +1822,8 @@ def check_qt_installation(macros):
253 def fix_qmake_args(args=""):
254 """Make any platform specific adjustments to the arguments passed to qmake.
255 """
256 + if opts.crosscompile:
257 + return args
258 if sys.platform == "darwin":
259 # The Qt binary installer has macx-xcode as the default.
260 args = "-spec %s %s" % (sipcfg.platform, args)
261 @@ -1930,7 +1975,7 @@ int main(int, char **)
262
263 # Create the makefile, first making sure it doesn't already exist.
264 remove_file(make_file)
265 - run_command("%s %s %s" % (opts.qmake, qmake_args, pro_file))
266 + run_qmake("%s %s" % (qmake_args, pro_file))
267
268 if not os.access(make_file, os.F_OK):
269 sipconfig.error("%s failed to create a makefile. %s" % (opts.qmake, MSG_CHECK_QMAKE))
270 @@ -1952,15 +1997,30 @@ int main(int, char **)
271 if not os.access(exe_file, os.X_OK):
272 sipconfig.error("Failed to determine the layout of your Qt installation. Try again using the --verbose flag to see more detail about the problem.")
273
274 - # Create the output file, first making sure it doesn't exist.
275 - remove_file(out_file)
276 - run_command(exe_file)
277 + if opts.qtdirs_file:
278 + # The user supplied a partial qtdirs.out file. We're probably crosscompiling.
279 + # Do _not_ try to execute our qtdirs exe. Take the supplied qtdirs.out files
280 + # instead and add the PyQt_... flags by grepping through the executable.
281 + # This assumes the executable is not compiled with -O0.
282 + read_qtdirs_file(opts.qtdirs_file)
283 + global qt_xfeatures
284 + print("Got %d features from qtdirs.out file: %s" % (len(qt_xfeatures), str(qt_xfeatures)))
285 + found = re.findall(r'PyQt_[\w]+', file(exe_file, "r").read())
286 + print("Grepped %d features from qtdirs.exe file: %s" % (len(found), str(found)))
287 + qt_xfeatures.extend(found)
288 + else:
289 + # Create the output file, first making sure it doesn't exist.
290 + remove_file(out_file)
291 + run_command(exe_file)
292 +
293 + if not os.access(out_file, os.F_OK):
294 + sipconfig.error("%s failed to create %s. Make sure your Qt v4 installation is correct." % (exe_file, out_file))
295
296 - if not os.access(out_file, os.F_OK):
297 - sipconfig.error("%s failed to create %s. Make sure your Qt v4 installation is correct." % (exe_file, out_file))
298 + # Read the directories.
299 + read_qtdirs_file(out_file)
300
301 - # Read the directories.
302 - f = open(out_file, "r")
303 +def read_qtdirs_file(filename):
304 + f = open(filename, "r")
305 lines = f.read().strip().split("\n")
306 f.close()
307
308 @@ -2022,6 +2082,24 @@ int main(int, char **)
309 sipconfig.error("Qt has been built as static libraries so either the -g or -k argument should be used.")
310
311
312 +def load_sipconfig_macros(filename):
313 + macros = {}
314 + fd = file(filename, "r")
315 + for line in fd.readlines():
316 + line = line.split()
317 + try:
318 + key = line[0]
319 + except IndexError:
320 + sipconfig.error("Invalid sipconfig macros file format")
321 + value = ""
322 + try:
323 + value = " ".join(line[1:])
324 + except IndexError:
325 + pass
326 + macros[key] = value
327 + return macros
328 +
329 +
330 def main():
331 """Create the configuration module module.
332 """
333 @@ -2036,7 +2114,7 @@ def main():
334 opts, args = p.parse_args()
335
336 # Provide defaults for platform-specific options.
337 - if sys.platform == 'win32':
338 + if sys.platform == 'win32' and not opts.crosscompile:
339 opts.qmake = find_default_qmake()
340 opts.prot_is_public = False
341
342 @@ -2069,12 +2147,14 @@ def main():
343 # Install the API file if the default directory exists.
344 opts.api = os.path.isdir(opts.qscidir)
345
346 - # Replace the existing build macros with the ones from the Qt installation.
347 - macros = get_build_macros(args)
348 -
349 - if macros is None:
350 - p.print_help()
351 - sys.exit(2)
352 + if opts.sipconfig_macros:
353 + macros = load_sipconfig_macros(opts.sipconfig_macros)
354 + else:
355 + # Replace the existing build macros with the ones from the Qt installation.
356 + macros = get_build_macros(args)
357 + if macros is None:
358 + p.print_help()
359 + sys.exit(2)
360
361 sipcfg.set_build_macros(macros)
362