-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.py
1853 lines (1440 loc) · 60.5 KB
/
configure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This script generates the PyQt configuration and generates the Makefiles.
#
# Copyright (c) 2008 Riverbank Computing Limited <[email protected]>
#
# This file is part of PyQt.
#
# This file may be used under the terms of the GNU General Public
# License versions 2.0 or 3.0 as published by the Free Software
# Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
# included in the packaging of this file. Alternatively you may (at
# your option) use any later version of the GNU General Public
# License if such license has been publicly approved by Riverbank
# Computing Limited (or its successors, if any) and the KDE Free Qt
# Foundation. In addition, as a special exception, Riverbank gives you
# certain additional rights. These rights are described in the Riverbank
# GPL Exception version 1.1, which can be found in the file
# GPL_EXCEPTION.txt in this package.
#
# Please review the following information to ensure GNU General
# Public Licensing requirements will be met:
# http://trolltech.com/products/qt/licenses/licensing/opensource/. If
# you are unsure which license is appropriate for your use, please
# review the following information:
# http://trolltech.com/products/qt/licenses/licensing/licensingoverview
# or contact the sales department at [email protected].
#
# This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
# INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
# granted herein.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
import sys
import os
import string
import glob
import optparse
import shutil
import sipconfig
# Initialise the globals.
pyqt_version = 0x040404
pyqt_version_str = "4.4.4-snapshot-20080827"
sip_min_version = 0x040705
qt_version = 0
qt_edition = ""
qt_dir = None
qt_incdir = None
qt_libdir = None
qt_bindir = None
qt_datadir = None
qt_pluginsdir = None
qt_xfeatures = None
qt_shared = ""
qt_framework = 0
qt_sip_flags = []
pyqt_modules = []
pyqt_modroot = None
# Get the SIP configuration.
sipcfg = sipconfig.Configuration()
pydbusmoddir = None
dbusincdirs = []
dbuslibdirs = []
dbuslibs = []
# Under Windows qmake and the Qt DLLs must be into the system PATH otherwise
# the dynamic linker won't be able to resolve the symbols. On other systems we
# assume we can just run qmake by using its full pathname.
if sys.platform == "win32":
MSG_CHECK_QMAKE = "Make sure you have a working Qt v4 qmake on your PATH."
else:
MSG_CHECK_QMAKE = "Make sure you have a working Qt v4 qmake on your PATH or use the -q argument to explicitly specify a working Qt v4 qmake."
def find_default_qmake():
"""Find a default qmake, ie. the first on the path.
"""
try:
path = os.environ["PATH"]
except KeyError:
path = ""
if sys.platform == "win32":
base_qmake = "qmake.exe"
else:
base_qmake = "qmake"
for d in path.split(os.pathsep):
qmake = os.path.join(d, base_qmake)
if os.access(qmake, os.X_OK):
return qmake
return ""
def create_optparser():
"""Create the parser for the command line.
"""
qmake = find_default_qmake()
def store_abspath(option, opt_str, value, parser):
setattr(parser.values, option.dest, os.path.abspath(value))
def store_abspath_dir(option, opt_str, value, parser):
if not os.path.isdir(value):
raise optparse.OptionValueError("'%s' is not a directory" % value)
setattr(parser.values, option.dest, os.path.abspath(value))
def store_abspath_file(option, opt_str, value, parser):
if not os.path.isfile(value):
raise optparse.OptionValueError("'%s' is not a file" % value)
setattr(parser.values, option.dest, os.path.abspath(value))
p = optparse.OptionParser(usage="python %prog [opts] [macro=value] "
"[macro+=value]", version=pyqt_version_str)
# Note: we don't use %default to be compatible with Python 2.3.
p.add_option("-k", "--static", action="store_true", default=False,
dest="static", help="build modules as static libraries")
p.add_option("-r", "--trace", action="store_true", default=False,
dest="tracing", help="build modules with tracing enabled")
p.add_option("-u", "--debug", action="store_true", default=False,
help="build modules with debugging symbols")
p.add_option("-w", "--verbose", action="count", default=0, dest="verbose",
help="verbose output during configuration")
p.add_option("-c", "--concatenate", action="store_true", default=False,
dest="concat", help="concatenate each module's C++ source files")
p.add_option("-j", "--concatenate-split", type="int", default=1,
metavar="N", dest="split",
help="split the concatenated C++ source files into N pieces "
"[default: 1]")
p.add_option("-g", "--consolidate", action="store_true", default=False,
dest="bigqt", help="create a single module which links against "
"all the Qt libraries")
# These are internal options used to build the mega Windows GPL package.
p.add_option("--mwg-odbc", action="store_true", default=False,
dest="mwg_odbc", help=optparse.SUPPRESS_HELP)
p.add_option("--mwg-openssl", action="callback", default=None,
dest="mwg_ssl_dir", metavar="DIR", callback=store_abspath_dir,
type="string", help=optparse.SUPPRESS_HELP)
p.add_option("--mwg-qsci", action="callback", default=None,
dest="mwg_qsci_dir", metavar="DIR", callback=store_abspath_dir,
type="string", help=optparse.SUPPRESS_HELP)
p.add_option("--mwg-qwt", action="callback", default=None,
dest="mwg_qwt_dir", metavar="DIR", callback=store_abspath_dir,
type="string", help=optparse.SUPPRESS_HELP)
# Configuration.
g = optparse.OptionGroup(p, title="Configuration")
g.add_option("--confirm-license", action="store_true", default=False,
dest="license_confirmed", help="confirm acceptance of the license")
g.add_option("-e", "--enable", action="append", default=[],
metavar="MODULE", dest="enabled", help="enable checks for the "
"specified MODULE [default: checks for all modules will be "
"enabled]")
g.add_option("-t", "--plugin", action="append", default=[],
metavar="PLUGIN", dest="staticplugins", help="add PLUGIN to the "
"list be linked (if Qt is built as static libraries)")
if sys.platform != "win32":
g.add_option("-q", "--qmake", action="callback", metavar="FILE",
default=qmake, dest="qmake", callback=store_abspath_file,
type="string",
help="the pathname of qmake [default: %s]" % (qmake or "none"))
g.add_option("-s", "--dbus", action="callback", metavar="DIR",
dest="pydbusincdir", callback=store_abspath_dir, type="string",
help="the directory containing the dbus/dbus-python.h header file "
"[default: supplied by pkg-config]")
p.add_option_group(g)
# Installation.
g = optparse.OptionGroup(p, title="Installation")
g.add_option("-b", "--bindir", action="callback",
default=sipcfg.default_bin_dir, type="string", metavar="DIR",
dest="pyqtbindir", callback=store_abspath, help="where pyuic4, "
"pyrcc4 and pylupdate4 will be installed [default: %s]" %
sipcfg.default_bin_dir)
g.add_option("-d", "--destdir", action="callback",
default=sipcfg.default_mod_dir, type="string", metavar="DIR",
dest="pyqtmoddir", callback=store_abspath, help="where the PyQt4 "
"Python package will be installed [default: %s]" %
sipcfg.default_mod_dir)
g.add_option("-p", "--plugin-destdir", action="callback", type="string",
metavar="DIR", dest="plugindir", callback=store_abspath,
help="where the Designer plugin will be installed [default: "
"QTDIR/plugins]")
g.add_option("--no-sip-files", action="store_false", default=True,
dest="install_sipfiles", help="disable the installation of the "
".sip files [default: enabled]")
g.add_option("-v", "--sipdir", action="callback",
default=os.path.join(sipcfg.default_sip_dir, "PyQt4"),
metavar="DIR", dest="pyqtsipdir", callback=store_abspath,
type="string", help="where the PyQt4 .sip files will be installed "
"[default: %s]" % sipcfg.default_sip_dir)
p.add_option_group(g)
# Vendor ID.
g = optparse.OptionGroup(p, title="VendorID support")
g.add_option("-i", "--vendorid", action="store_true", default=False,
dest="vendorcheck", help="enable checking of signed interpreters "
"using the VendorID package [default: disabled]")
g.add_option("-l", "--vendorid-incdir", action="callback",
default=sipcfg.py_inc_dir, type="string", metavar="DIR",
dest="vendincdir", callback=store_abspath_dir, help="the "
"directory containing the VendorID header file [default: %s]" %
sipcfg.py_inc_dir)
g.add_option("-m", "--vendorid-libdir", action="callback",
default=sipcfg.py_lib_dir, type="string", metavar="DIR",
dest="vendlibdir", callback=store_abspath_dir, help="the "
"directory containing the VendorID library [default: %s]" %
sipcfg.py_lib_dir)
p.add_option_group(g)
# QScintilla.
g = optparse.OptionGroup(p, title="QScintilla support")
g.add_option("-a", "--qsci-api", action="store_true", default=None,
dest="api", help="always install the PyQt API file for QScintilla "
"[default: install only if QScintilla installed]")
g.add_option("--no-qsci-api", action="store_false", default=None,
dest="api", help="do not install the PyQt API file for QScintilla "
"[default: install only if QScintilla installed]")
g.add_option("-n", "--qsci-api-destdir", action="callback", dest="qscidir",
metavar="DIR", callback=store_abspath, type="string", help="where "
"the PyQt API file for QScintilla will be installed [default: "
"QTDIR/qsci]")
p.add_option_group(g)
return p
class ConfigurePyQt4:
"""This class defines the methods to configure PyQt4.
"""
def __init__(self, generator):
self.generator = generator
def qt_version_tags(self):
"""Get the versions tags for the configuration.
Returns a dictionary of versions and corresponding tags.
"""
return {
0x040101: None,
0x040102: "Qt_4_1_1",
0x040103: "Qt_4_1_2",
0x040200: "Qt_4_1_3",
0x040202: "Qt_4_2_0",
0x040300: "Qt_4_2_2",
0x040303: "Qt_4_3_0",
0x040400: "Qt_4_3_3",
0x040401: "Qt_4_4_0",
0x050000: "Qt_4_4_1"
}
def check_modules(self):
if opts.mwg_odbc:
sql_libs = ["odbc32"]
else:
sql_libs = None
if opts.mwg_ssl_dir:
ass_lib_dirs = [os.path.join(opts.mwg_ssl_dir, "lib")]
ass_libs = ["ssleay32", "libeay32"]
else:
ass_lib_dirs = None
ass_libs = None
# Note that the order in which we check is important for the
# consolidated module - a module's dependencies must be checked first.
pyqt_modules.append("QtCore")
check_module("QtGui", "qwidget.h", "new QWidget()")
check_module("QtHelp", "qhelpengine.h", "new QHelpEngine(\"foo\")")
check_module("QtNetwork", "qhostaddress.h", "new QHostAddress()")
check_module("QtOpenGL", "qgl.h", "new QGLWidget()")
check_module("QtScript", "qscriptengine.h", "new QScriptEngine()")
check_module("QtSql", "qsqldatabase.h", "new QSqlDatabase()",
extra_libs=sql_libs)
check_module("QtSvg", "qsvgwidget.h", "new QSvgWidget()")
check_module("QtTest", "QtTest", "QTest::qSleep(0)")
check_module("QtWebKit", "qwebpage.h", "new QWebPage()")
check_module("QtXml", "qdom.h", "new QDomDocument()")
check_module("QtXmlPatterns", "qxmlname.h", "new QXmlName()")
check_module("phonon", "phonon", "new Phonon::VideoWidget()")
check_module("QtAssistant", "qassistantclient.h",
"new QAssistantClient(\"foo\")", extra_lib_dirs=ass_lib_dirs,
extra_libs=ass_libs)
if not qt_shared:
sipconfig.inform("QtDesigner module disabled with static Qt libraries.")
elif sipcfg.universal:
sipconfig.inform("QtDesigner module disabled with universal binaries.")
else:
check_module("QtDesigner", "QExtensionFactory",
"new QExtensionFactory()")
check_module("QAxContainer", "qaxobject.h", "new QAxObject()",
extra_libs=["QAxContainer"])
if os.path.isdir("dbus"):
check_dbus()
def code(self):
cons_xtra_incdirs = []
cons_xtra_libdirs = []
cons_xtra_libs = []
sp_libs, sp_libdirs = self._static_plugins("QtCore")
sp_incdirs = []
if opts.vendorcheck:
sp_incdirs.append(opts.vendincdir)
sp_libdirs.append(opts.vendlibdir)
sp_libs.append("vendorid")
if opts.bigqt:
cons_xtra_incdirs.extend(sp_incdirs)
cons_xtra_libdirs.extend(sp_libdirs)
cons_xtra_libs.extend(sp_libs)
generate_code("QtCore")
else:
generate_code("QtCore", extra_include_dirs=sp_incdirs,
extra_lib_dirs=sp_libdirs, extra_libs=sp_libs)
if "QtGui" in pyqt_modules:
sp_libs, sp_libdirs = self._static_plugins("QtGui")
if opts.bigqt:
cons_xtra_libdirs.extend(sp_libdirs)
cons_xtra_libs.extend(sp_libs)
generate_code("QtGui")
else:
generate_code("QtGui", extra_lib_dirs=sp_libdirs,
extra_libs=sp_libs)
if "QtHelp" in pyqt_modules:
generate_code("QtHelp")
if "QtNetwork" in pyqt_modules:
generate_code("QtNetwork")
if "QtOpenGL" in pyqt_modules:
generate_code("QtOpenGL")
if "QtScript" in pyqt_modules:
generate_code("QtScript")
if "QtSql" in pyqt_modules:
sp_libs, sp_libdirs = self._static_plugins("QtSql")
if opts.bigqt:
cons_xtra_libdirs.extend(sp_libdirs)
cons_xtra_libs.extend(sp_libs)
generate_code("QtSql")
else:
generate_code("QtSql", extra_lib_dirs=sp_libdirs,
extra_libs=sp_libs)
if "QtSvg" in pyqt_modules:
generate_code("QtSvg")
if "QtTest" in pyqt_modules:
generate_code("QtTest")
if "QtWebKit" in pyqt_modules:
generate_code("QtWebKit")
if "QtXml" in pyqt_modules:
generate_code("QtXml")
if "QtXmlPatterns" in pyqt_modules:
generate_code("QtXmlPatterns")
if "phonon" in pyqt_modules:
generate_code("phonon")
if "QtAssistant" in pyqt_modules:
generate_code("QtAssistant")
if "QtDesigner" in pyqt_modules:
qpy_dir = os.path.abspath(os.path.join("qpy", "QtDesigner"))
if sys.platform == "win32":
if opts.debug:
qpy_lib_dir = os.path.join(qpy_dir, "debug")
else:
qpy_lib_dir = os.path.join(qpy_dir, "release")
else:
qpy_lib_dir = qpy_dir
if opts.bigqt:
cons_xtra_incdirs.append(qpy_dir)
cons_xtra_libdirs.append(qpy_lib_dir)
cons_xtra_libs.append("qpydesigner")
generate_code("QtDesigner")
else:
generate_code("QtDesigner", extra_include_dirs=[qpy_dir],
extra_lib_dirs=[qpy_lib_dir],
extra_libs=["qpydesigner"])
if "QAxContainer" in pyqt_modules:
generate_code("QAxContainer")
# Generate the composite module.
qtmod_sipdir = os.path.join("sip", "Qt")
mk_clean_dir(qtmod_sipdir)
qtmod_sipfile = os.path.join(qtmod_sipdir, "Qtmod.sip")
f = open(qtmod_sipfile, "w")
f.write("""%CompositeModule PyQt4.Qt
""")
for m in pyqt_modules:
f.write("%%Include %s/%smod.sip\n" % (m, m))
f.close()
generate_code("Qt")
# Generate the consolidated module if required.
if opts.bigqt:
xtra_sip_flags = []
_qtmod_sipdir = os.path.join("sip", "_qt")
mk_clean_dir(_qtmod_sipdir)
_qtmod_sipfile = os.path.join(_qtmod_sipdir, "_qtmod.sip")
f = open(_qtmod_sipfile, "w")
f.write("""%ConsolidatedModule PyQt4._qt
""")
for m in pyqt_modules:
f.write("%%Include %s/%smod.sip\n" % (m, m))
if opts.mwg_qsci_dir:
f.write("%Include Qsci/Qscimod.sip\n")
cons_xtra_libs.append("qscintilla2")
# Copy in the QScintilla .sip files and fix the main one.
src_dir = os.path.join(opts.mwg_qsci_dir, "Python", "sip")
dst_dir = os.path.join("sip", "Qsci")
try:
shutil.rmtree(dst_dir);
except:
pass
shutil.copytree(src_dir, dst_dir)
os.rename(os.path.join(dst_dir, "qscimod4.sip"), os.path.join(dst_dir, "Qscimod.sip"))
generate_code("Qsci")
if opts.mwg_qwt_dir:
f.write("%Include Qwt5/Qwt5mod.sip\n")
from numpy.distutils.misc_util import get_numpy_include_dirs
cons_xtra_incdirs.extend(get_numpy_include_dirs())
cons_xtra_incdirs.append(os.path.join(
os.environ['HOME'], 'usr', 'lib',
'qt4.4', 'include', 'qwt'))
cons_xtra_libs.append("qwt")
# Copy in the PyQwt .sip files and fix the main one.
src_dir = os.path.join(opts.mwg_qwt_dir, "sip", "qwt5qt4")
dst_dir = os.path.join("sip", "Qwt5")
try:
shutil.rmtree(dst_dir);
except:
pass
shutil.copytree(src_dir, dst_dir)
os.rename(os.path.join(dst_dir, "QwtModule.sip"), os.path.join(dst_dir, "Qwt5mod.sip"))
xtra_sip_flags = ["-t", "Qwt_5_1_1",
"-x", "CXX_DYNAMIC_CAST",
"-x", "HAS_QWT4",
"-x", "HAS_NUMARRAY",
"-x", "HAS_NUMERIC"]
generate_code("Qwt5", extra_sip_flags=xtra_sip_flags)
f.close()
if opts.mwg_odbc:
cons_xtra_libs.append("odbc32")
if opts.mwg_ssl_dir:
cons_xtra_libdirs.append(os.path.join(opts.mwg_ssl_dir, "lib"))
cons_xtra_libs.extend(["ssleay32", "libeay32"])
generate_code("_qt", extra_include_dirs=cons_xtra_incdirs,
extra_lib_dirs=cons_xtra_libdirs,
extra_libs=cons_xtra_libs, extra_sip_flags=xtra_sip_flags)
if opts.mwg_qwt_dir:
extra_sources = glob.glob(os.path.join(
opts.mwg_qwt_dir, 'support', '*.cpp'))
for source in extra_sources:
shutil.copy2(
source, os.path.join('_qt', os.path.basename(source)))
extra_headers = glob.glob(os.path.join(
opts.mwg_qwt_dir, 'support', '*.h'))
for header in extra_headers:
shutil.copy2(
header, os.path.join('_qt', os.path.basename(header)))
# FIXME: sip-4.7 does not generate those include files anymore
for name in [os.path.join('_qt', name) for name in [
'sipQwtQwtArrayDouble.h',
'sipQwtQwtArrayInt.h',
'sipQwtQwtArrayQwtDoubleInterval.h',
'sipQwtQwtArrayQwtDoublePoint.h',
]]:
if not os.path.exists(name):
open(name, 'w')
# HACK: makefile patching is platform dependent
text = open(os.path.join('_qt', 'Makefile')).read()
text = text.replace('CPPFLAGS =', 'CPPFLAGS = -DHAS_NUMPY')
extra_objects = [
os.path.splitext(os.path.basename(source))[0]+'.o'
for source in extra_sources]
extra_objects.insert(0, 'OFILES =')
text = text.replace('OFILES =', ' '.join(extra_objects))
open(os.path.join('_qt', 'Makefile'), 'w').write(text)
# Tell the user about any plugins not found.
if opts.staticplugins:
sipconfig.inform("Unable to find the following static plugins: %s" % ", ".join(opts.staticplugins))
# Generate the QScintilla API file.
sipconfig.inform("Creating QScintilla API file...")
f = open("PyQt4.api", "w")
for m in pyqt_modules:
api = open(m + ".api")
for l in api:
f.write("PyQt4." + l)
api.close()
os.remove(m + ".api")
f.close()
def _static_plugins(self, mname):
"""Return a tuple of the libraries (in platform neutral format) and the
directories they are contained in for all the requested static plugins
for the given module. Generate the additional .sip file needed to
ensure the plugins get linked.
mname is the name of the module.
"""
plugin_dirs = {
"QtCore": ("codecs", ),
# Note that we put iconengines after imageformats so that qsvg is
# found in the latter rather than the former. The name clash is
# probably a Qt bug.
"QtGui": ("inputmethods", "imageformats", "iconengines"),
"QtSql": ("sqldrivers", )
}
libs = []
libdirs = []
for plug in opts.staticplugins:
# Convert the plugin name to a platform specific filename.
if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):
pfname = plug + ".lib"
else:
pfname = "lib" + plug + ".a"
for pdir in plugin_dirs[mname]:
ppath = os.path.join(qt_pluginsdir, pdir)
# See if the plugin exists.
if os.access(os.path.join(ppath, pfname), os.F_OK):
sipconfig.inform("Adding the %s static plugin to the %s module..." % (plug, mname))
libs.append(plug)
if ppath not in libdirs:
libdirs.append(ppath)
break
# Remove those plugins we have handled.
opts.staticplugins = [p for p in opts.staticplugins if p not in libs]
# If we have any plugins for this module then generate a .sip file that
# will include the code needed to ensure the plugin gets linked.
if libs:
sp_sipfile = os.path.join("sip", mname, "staticplugins.sip")
f = open(sp_sipfile, "w")
f.write("""%ModuleCode
#include <QtPlugin>
""")
for l in libs:
f.write("Q_IMPORT_PLUGIN(%s)\n" % l)
f.write("""
%End
""")
f.close()
return libs, libdirs
def module_installs(self):
return ["__init__.py", "pyqtconfig.py"]
def qpylibs(self):
# See which QPy libraries to build.
qpylibs = {}
if "QtDesigner" in pyqt_modules:
qpylibs["QtDesigner"] = "qpydesigner.pro"
# Run qmake to generate the Makefiles.
qmake_args = fix_qmake_args()
cwd = os.getcwd()
for qpy, pro in qpylibs.iteritems():
sipconfig.inform("Creating QPy library for %s Makefile..." % qpy)
os.chdir(os.path.join("qpy", qpy))
if sipcfg.universal:
upro = "u_" + pro
f = open(upro, 'w+')
f.write(
"""# Setup the normal .pro file for universal binaries.
CONFIG += ppc i386
QMAKE_MAC_SDK = %s
include(%s)
""" % (sipcfg.universal, pro))
f.close()
pro = upro
run_command("%s %s %s" % (opts.qmake, qmake_args, pro))
os.chdir(cwd)
sipconfig.inform("Creating QPy libraries Makefile...")
sipconfig.ParentMakefile(
configuration=sipcfg,
dir="qpy",
subdirs=qpylibs.keys()
).generate()
return ["qpy"]
def tools(self):
tool = []
if pydbusmoddir:
sipconfig.inform("Creating dbus support module Makefile...")
makefile = sipconfig.ModuleMakefile(
configuration=sipcfg,
build_file="dbus.sbf",
dir="dbus",
install_dir=pydbusmoddir,
qt=["QtCore"],
debug=opts.debug,
universal=sipcfg.universal
)
add_makefile_extras(makefile, dbusincdirs, dbuslibdirs, dbuslibs)
makefile.generate()
tool.append("dbus")
# Only include ElementTree for older versions of Python.
if sipcfg.py_version < 0x020500:
sipconfig.inform("Creating elementtree Makefile...")
makefile = sipconfig.PythonModuleMakefile(
configuration=sipcfg,
dstdir=os.path.join(pyqt_modroot, "elementtree"),
dir="elementtree"
)
makefile.generate()
tool.append("elementtree")
# Create the pyuic4 wrapper. Use the GUI version on MacOS (so that
# previews work properly and normal console use will work anyway), but
# not on Windows (so that normal console use will work).
sipconfig.inform("Creating pyuic4 wrapper...")
uicdir=os.path.join(pyqt_modroot, "uic")
wrapper = sipconfig.create_wrapper(os.path.join(uicdir, "pyuic.py"), os.path.join("pyuic", "pyuic4"), (sys.platform == "darwin"))
sipconfig.inform("Creating pyuic4 Makefile...")
makefile = sipconfig.PythonModuleMakefile(
configuration=sipcfg,
dstdir=uicdir,
srcdir="uic",
dir="pyuic",
installs=[[os.path.basename(wrapper), opts.pyqtbindir]]
)
makefile.generate()
tool.append("pyuic")
if "QtXml" in pyqt_modules:
sipconfig.inform("Creating pylupdate4 Makefile...")
makefile = sipconfig.ProgramMakefile(
configuration=sipcfg,
build_file="pylupdate.sbf",
dir="pylupdate",
install_dir=opts.pyqtbindir,
console=1,
qt=["QtCore", "QtGui", "QtXml"],
debug=opts.debug,
warnings=1,
universal=sipcfg.universal
)
makefile.generate()
tool.append("pylupdate")
sipconfig.inform("Creating pyrcc4 Makefile...")
makefile = sipconfig.ProgramMakefile(
configuration=sipcfg,
build_file="pyrcc.sbf",
dir="pyrcc",
install_dir=opts.pyqtbindir,
console=1,
qt=["QtCore", "QtXml"],
debug=opts.debug,
warnings=1,
universal=sipcfg.universal
)
makefile.generate()
tool.append("pyrcc")
else:
sipconfig.inform("pylupdate4 and pyrcc4 will not be built because the Qt XML module is missing.")
if "QtDesigner" in pyqt_modules:
enabled = True
py_major = sipcfg.py_version >> 16
py_minor = (sipcfg.py_version >> 8) & 0x0ff
if sys.platform == "win32":
lib_dir_flag = quote("-L%s" % sipcfg.py_lib_dir)
link = "%s -lpython%d%d" % (lib_dir_flag, py_major, py_minor)
pysh_lib = "python%d%d.dll" % (py_major, py_minor)
else:
# Use distutils to get the additional configuration.
from distutils.sysconfig import get_config_vars
ducfg = get_config_vars()
if sys.platform == "darwin":
# We need to work out how to specify the right framework
# version.
link = "-framework Python"
elif ("--enable-shared" in ducfg.get("CONFIG_ARGS", "") and
glob.glob("%s/lib/libpython%d.%d*" % (ducfg["prefix"], py_major, py_minor))):
lib_dir_flag = quote("-L%s/lib" % ducfg["prefix"])
link = "%s -lpython%d.%d" % (lib_dir_flag, py_major, py_minor)
else:
sipconfig.inform("Qt Designer plugin disabled because Python library is static")
enabled = False
pysh_lib = ducfg["LDLIBRARY"]
if enabled:
sipconfig.inform("Creating Qt Designer plugin Makefile...")
# Run qmake to generate the Makefile.
qmake_args = fix_qmake_args()
cwd = os.getcwd()
os.chdir("designer")
# Create the qmake project file.
fin = open("python.pro-in")
prj = fin.read()
fin.close()
prj = prj.replace("@PYINCDIR@", quote(sipcfg.py_inc_dir))
prj = prj.replace("@PYLINK@", link)
prj = prj.replace("@PYSHLIB@", pysh_lib)
prj = prj.replace("@QTPLUGINDIR@", quote(opts.plugindir + "/designer"))
fout = open("python.pro", "w+")
if sipcfg.universal:
fout.write("CONFIG += ppc i386\n")
fout.write("QMAKE_MAC_SDK = %s\n" % sipcfg.universal)
fout.write(prj)
fout.close()
run_command("%s %s" % (opts.qmake, qmake_args))
os.chdir(cwd)
tool.append("designer")
return tool
def quote(path):
"""Return a path with quotes added if it contains spaces."""
if " " in path:
path = '"%s"' % path
return path
def inform_user():
"""Tell the user the option values that are going to be used.
"""
if qt_edition:
edstr = qt_edition + " edition "
else:
edstr = ""
if qt_shared:
lib_type = "shared"
else:
lib_type = "static"
sipconfig.inform("Qt v%s %sis being used." % (sipconfig.version_to_string(qt_version), edstr))
if sys.platform == "darwin" and qt_framework:
sipconfig.inform("Qt is built as a framework.")
sipconfig.inform("SIP %s is being used." % sipcfg.sip_version_str)
sipconfig.inform("The Qt header files are in %s." % qt_incdir)
sipconfig.inform("The %s Qt libraries are in %s." % (lib_type, qt_libdir))
sipconfig.inform("The Qt binaries are in %s." % qt_bindir)
sipconfig.inform("The Qt mkspecs directory is in %s." % qt_datadir)
sipconfig.inform("These PyQt modules will be built: %s." % string.join(pyqt_modules))
sipconfig.inform("The PyQt Python package will be installed in %s." % opts.pyqtmoddir)
sipconfig.inform("The Designer plugin will be installed in %s." % os.path.join(opts.plugindir, "designer"))
if opts.api:
sipconfig.inform("The QScintilla API file will be installed in %s." % os.path.join(opts.qscidir, "api", "python"))
if pydbusmoddir:
sipconfig.inform("The dbus support module will be installed in %s." % pydbusmoddir)
sipconfig.inform("The PyQt .sip files will be installed in %s." % opts.pyqtsipdir)
sipconfig.inform("pyuic4, pyrcc4 and pylupdate4 will be installed in %s." % opts.pyqtbindir)
if opts.vendorcheck:
sipconfig.inform("PyQt will only be usable with signed interpreters.")
def create_config(module, template, macros):
"""Create the PyQt configuration module so that it can be imported by build
scripts.
module is the module file name.
template is the template file name.
macros is the dictionary of platform specific build macros.
"""
sipconfig.inform("Creating %s..." % module)
content = {
"pyqt_config_args": sys.argv[1:],
"pyqt_version": pyqt_version,
"pyqt_version_str": pyqt_version_str,
"pyqt_bin_dir": opts.pyqtbindir,
"pyqt_mod_dir": pyqt_modroot,
"pyqt_sip_dir": opts.pyqtsipdir,
"pyqt_modules": pyqt_modules,
"pyqt_sip_flags": qt_sip_flags,
"qt_version": qt_version,
"qt_edition": qt_edition,
"qt_winconfig": qt_shared,
"qt_framework": qt_framework,
"qt_threaded": 1,
"qt_dir": qt_dir,
"qt_data_dir": qt_datadir,
"qt_inc_dir": qt_incdir,
"qt_lib_dir": qt_libdir
}
sipconfig.create_config_module(module, template, content, macros)
def run_command(cmd):
"""Run a command and display the output if verbose mode is enabled.
cmd is the command to run.
"""
if opts.verbose:
sys.stdout.write(cmd + "\n")
fout = get_command_stdout(cmd, and_stderr=True)
# Read stdout and stderr until there is no more output.
lout = fout.readline()
while lout:
if opts.verbose:
sys.stdout.write(lout)
lout = fout.readline()
fout.close()
try:
os.wait()
except:
pass
def remove_file(fname):
"""Remove a file which may or may not exist.
fname is the name of the file.
"""
try:
os.remove(fname)
except OSError:
pass
def compile_qt_program(name, mname, extra_include_dirs=None, extra_lib_dirs=None, extra_libs=None):
"""Compile a simple Qt application.
name is the name of the single source file.
mname is the name of the Qt module.
extra_include_dirs is an optional list of extra include directories.
extra_lib_dirs is an optional list of extra library directories.
extra_libs is an optional list of extra libraries.
Returns the name of the executable suitable for running or None if it
wasn't created.
"""
opengl = (mname == "QtOpenGL")
qt = [mname]
if mname == "QtWebKit":
qt.append("QtCore")
makefile = sipconfig.ProgramMakefile(sipcfg, console=1, qt=qt, warnings=0, opengl=opengl, debug=opts.debug)
add_makefile_extras(makefile, extra_include_dirs, extra_lib_dirs, extra_libs)
exe, build = makefile.build_command(name)
# Make sure the executable file doesn't exist.
remove_file(exe)
run_command(build)
if not os.access(exe, os.X_OK):
return None
if sys.platform != "win32":
exe = "./" + exe
return exe
def add_makefile_extras(makefile, extra_include_dirs, extra_lib_dirs, extra_libs):
"""Add any extra include or library directories or libraries to a makefile.