summaryrefslogtreecommitdiffstats
path: root/configure.py
blob: 7ffc1434661e187ee7dbeaa3a2cff95873df6097 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
# This script generates the PyTQt configuration and generates the Makefiles.
#
# Copyright (c) 2007
# 	Riverbank Computing Limited <info@riverbankcomputing.co.uk>
# 
# This file is part of PyTQt.
# 
# This copy of PyTQt is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later
# version.
# 
# PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# 
# You should have received a copy of the GNU General Public License along with
# PyTQt; see the file LICENSE.  If not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


import sys
import os
import string
import glob
import getopt
import shutil
import py_compile

from sip4_tqt import sipconfig

src_dir = os.path.dirname(os.path.abspath(__file__))

# Initialise the globals.
pyqt_version = 0x031201
pyqt_version_str = "3.18.1"

sip_min_version = 0x040800


# Try and find a TQt installation to use as the default.
try:
    qt_dir = os.environ["QTDIR"]
except KeyError:
    qt_dir = ""


qt_version = 0
qt_edition = ""
qt_incdir = None
qt_libdir = None
qt_threaded = 0
qt_winconfig = ""

pyqt = None
pyqt_modules = []
qt_sip_flags = []
qtext_sip_flags = []
qtpe_sip_flags = []
qsci_version = 0
disabled_classes = []

if sys.platform == "win32":
    qsci_define = "TQEXTSCINTILLA_DLL"
else:
    qsci_define = ""

# Get the SIP configuration.
sipcfg = sipconfig.Configuration()

# Command line options.
opt_qtlib = None
opt_qconfigdir = None
opt_pyqtbindir = sipcfg.default_bin_dir
opt_pyqtmoddir = os.path.join(sipcfg.default_mod_dir, "python_tqt")
opt_pyqtsipdir = sipcfg.default_sip_dir
opt_qtpetag = None
opt_qsciincdir = None
opt_qscilibdir = None
opt_static = 0
opt_debug = 0
opt_concat = 0
opt_split = 1
opt_tracing = 0
opt_verbose = 0
opt_keepfeatures = 0

opt_vendorcheck = 0
opt_vendincdir = sipcfg.py_inc_dir
opt_vendlibdir = sipcfg.py_lib_dir


def usage(rcode = 2):
    """Display a usage message and exit.

    rcode is the return code passed back to the calling process.
    """
    if qt_dir:
        def_qt_dir = qt_dir
    else:
        def_qt_dir = "none"

    sys.stdout.write("Usage:\n")
    sys.stdout.write("    python configure.py [-h] [-a tag] [-b dir] [-c] [-d dir] [-e lib] [-f] [-g dir] [-i] [-j #] [-k] [-l dir] [-m dir] [-n dir] [-o dir] [-q dir] [-r] [-s] [-u] [-v dir] [-w] [-y lib] option=value option+=value ...\n")
    sys.stdout.write("where:\n")
    sys.stdout.write("  -h      display this help message\n")
    sys.stdout.write("  -a tag  explicitly enable the qtpe module\n")
    sys.stdout.write("  -b dir  where pyuic and pylupdate will be installed [default %s]\n" % opt_pyqtbindir)
    sys.stdout.write("  -c      concatenate each module's C/C++ source files\n")
    sys.stdout.write("  -d dir  where the PyTQt modules will be installed [default %\ns]" % opt_pyqtmoddir)
    sys.stdout.write("  -e lib  explicitly specify the python library\n")
    sys.stdout.write("  -f      keep any existing features file (when cross-compiling) [default remove]\n")
    sys.stdout.write("  -g dir  where the TQt qconfig.h file can be found [default TQt include directory]\n")
    sys.stdout.write("  -i      enable checking of signed interpreters using the VendorID package [default disabled]\n")
    sys.stdout.write("  -j #    split the concatenated C++ source files into # pieces [default 1]\n")
    sys.stdout.write("  -k      build the PyTQt modules as static libraries\n")
    sys.stdout.write("  -l dir  the directory containing the VendorID header file [default %s]\n" % opt_vendincdir)
    sys.stdout.write("  -m dir  the directory containing the VendorID library [default %s]\n" % opt_vendlibdir)
    sys.stdout.write("  -n dir  the directory containing the TQScintilla header files [default TQt include directory]\n")
    sys.stdout.write("  -o dir  the directory containing the TQScintilla library [default TQt lib directory]\n")
    sys.stdout.write("  -q dir  the root directory of the TQt installation [default %s]\n" % def_qt_dir)
    sys.stdout.write("  -r      generate code with tracing enabled [default disabled]\n")
    sys.stdout.write("  -s      TQScintilla is a static library and not a DLL (Windows only)\n")
    sys.stdout.write("  -u      build with debugging symbols (requires a debug build of Python on Windows\n")
    sys.stdout.write("  -v dir  where the PyTQt .sip files will be installed [default %s]\n" % opt_pyqtsipdir)
    sys.stdout.write("  -w      don't suppress compiler output during configuration\n")
    sys.stdout.write("  -y lib  explicitly specify the type of TQt library, either qt, qt-mt, qte, qte-mt, qtmt, tqt, tqt-mt, tqte, tqte-mt or tqtmt\n")

    sys.exit(rcode)


class ConfigureBase:
    """This is the base class for all PyTQt version specific configurer classes.
    Anything here is common to all configurers.
    """
    def check_modules(self):
        """Check which modules should be built and add them to the global list.

        Returns the name of any additional library that needs to be linked with
        the main module.
        """
        return None

    def sip_flags(self):
        """Get the configuration specific SIP flags.

        Returns a list of flags.
        """
        return []

    def qt_version_tags(self):
        """Get the versions tags for the configuration.

        Returns a dictionary of versions and corresponding tags.
        """
        return {}

    def code(self, extra_include_dirs, extra_lib_dir, extra_libs):
        """Generate the code for a configuration.

        extra_include_dirs is a list of directories to add to those supplied by
        the SIP configuration.
        extra_lib_dir is an optional directory to add to those supplied by the
        SIP configuration.
        extra_lib_dirs is an optional list of directories to add to those
        supplied by the SIP configuration.
        """
        pass

    def tools(self):
        """Create the Makefiles for any other sub-directories and return a list
        of those directories.

        Returns a list of sub-directories with Makefile.
        """
        return []

    def module_dir(self):
        """Return the configuration's module directory.
        """
        return opt_pyqtmoddir

    def module_installs(self):
        """Return a list of files to install in the module directory other than
        the modules themselves.
        """
        return ["__init__.py", "pyqtconfig.py"]

    def sip_dir(self):
        """Return the configuration's .sip files directory.
        """
        return opt_pyqtsipdir


class ConfigurePyTQt3(ConfigureBase):
    """This class defines the methods to configure PyTQt v3.
    """
    def check_modules(self):
        pyqt_modules.append("qt")

        check_module("qtcanvas", "qcanvas.h", "TQCanvas()")
        check_module("qtnetwork", "qsocket.h", "TQSocket()")
        check_module("qttable", "qtable.h", "TQTable()")
        check_module("qtxml", "qdom.h", "TQDomImplementation()")
        check_module("qtgl", "qgl.h", "TQGLWidget()", opengl=1)

        if qt_version >= 0x030000:
            check_module("qtui", "qwidgetfactory.h", "TQWidgetFactory()", lib="tqui")

            if qt_edition in ("enterprise", "free"):
                check_module("qtsql", "qsql.h", "TQSql()")

                if sys.platform == "win32" and sipcfg.sip_version >= 0x040200:
                    check_module("qtaxcontainer", "qaxobject.h", "TQAxObject()", lib="qaxcontainer")

        if qsci_version:
            check_module("qtext", "qextscintillabase.h", "QextScintillaBase()", define=qsci_define, include_dir=opt_qsciincdir, lib_dir=opt_qscilibdir, lib="qscintilla")

        if opt_qtpetag:
            pyqt_modules.append("qtpe")

        qtmod_lib = None

        if qt_version >= 0x030100:
            sipconfig.inform("Checking to see if the TQAssistantClient class is available...")

            if check_class("qassistantclient.h", "TQAssistantClient(\"foo\")", lib="qassistantclient"):
                qtmod_lib = "qassistantclient"
            else:
                if check_class("ntqassistantclient.h", "TQAssistantClient(\"foo\")", lib="qassistantclient"):
                    qtmod_lib = "qassistantclient"
                else:
                    disabled_classes.append("TQAssistantClient")

        return qtmod_lib

    def sip_flags(self):
        return get_feature_flags()

    def qt_version_tags(self):
        return {
            0x010403: None,
            0x020000: "TQt_1_43",
            0x020100: "TQt_2_00",
            0x020200: "TQt_2_1_0",
            0x020300: "TQt_2_2_0",
            0x020301: "TQt_2_3_0",
            0x030000: "TQt_2_3_1",
            0x030001: "TQt_3_0_0",
            0x030002: "TQt_3_0_1",
            0x030004: "TQt_3_0_2",
            0x030005: "TQt_3_0_4",
            0x030006: "TQt_3_0_5",
            0x030100: "TQt_3_0_6",
            0x030101: "TQt_3_1_0",
            0x030102: "TQt_3_1_1",
            0x030200: "TQt_3_1_2",
            0x030300: "TQt_3_2_0",
            0x030305: "TQt_3_3_0",
            0x030306: "TQt_3_3_5",
            0x040000: "TQt_3_3_6"
        }

    def code(self, extra_include_dirs, extra_lib_dir, extra_libs):
        generate_code("qt", extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=extra_libs)

        if "qtext" in pyqt_modules:
            generate_code("qtext", extra_define=qsci_define, extra_include_dirs=[opt_qsciincdir], extra_lib_dir=opt_qscilibdir, extra_libs=["qscintilla"], sip_flags=qtext_sip_flags)

        if "qtgl" in pyqt_modules:
            generate_code("qtgl", opengl=1)

        if "qtpe" in pyqt_modules:
            generate_code("qtpe", extra_libs=["qpe"], sip_flags=qtpe_sip_flags)

        if "qtui" in pyqt_modules:
            generate_code("qtui", extra_libs=["tqui"])

        if "qtaxcontainer" in pyqt_modules:
            generate_code("qtaxcontainer", extra_libs=["qaxcontainer"])

        # The rest don't need special handling.
        for m in ("qtcanvas", "qtnetwork", "qtsql", "qttable", "qtxml"):
            if m in pyqt_modules:
                generate_code(m)

    def tools(self):
        tool_dirs = []

        if qt_version >= 0x030000:
            # The Professional Edition needs special handling.
            prof = (qt_edition == "professional")

            sipconfig.inform("Creating pyuic Makefile...")

            if prof or "qtxml" not in pyqt_modules:
                buildfile= "pyuic-prof.sbf"

                for xml in ("qdom.cpp", "qxml.cpp"):
                    shutil.copyfile(qt_dir + "/src/xml/" + xml, "pyuic3/" + xml)
            else:
                buildfile= "pyuic.sbf"

            makefile = sipconfig.ProgramMakefile(
                configuration=sipcfg,
                build_file=os.path.join(src_dir, "pyuic3", buildfile),
                dir="pyuic3",
                install_dir=opt_pyqtbindir,
                console=1,
                qt=1,
                warnings=1
            )

            makefile.extra_defines.append("UIC")
            makefile.extra_defines.append("QT_INTERNAL_XML")

            if prof or "qtxml" not in pyqt_modules:
                makefile.extra_defines.append("TQT_MODULE_XML")

            if qt_version < 0x030100:
                makefile.extra_include_dirs.append(qt_dir + "/src/3rdparty/zlib")
            makefile.extra_include_dirs.append(os.path.join(src_dir, "pyuic3"))
            
            if not os.access("pyuic3", os.F_OK):
                os.mkdir("pyuic3")

            makefile.generate()
            tool_dirs.append("pyuic3")

            sipconfig.inform("Creating pylupdate Makefile...")

            if prof or "qtxml" not in pyqt_modules:
                buildfile= "pylupdate-prof.sbf"

                shutil.copyfile(qt_dir + "/src/xml/qxml.cpp", "pylupdate3/qxml.cpp")
            else:
                buildfile= "pylupdate.sbf"

            makefile = sipconfig.ProgramMakefile(
                configuration=sipcfg,
                build_file=os.path.join(src_dir, "pylupdate3", buildfile),
                dir="pylupdate3",
                install_dir=opt_pyqtbindir,
                console=1,
                qt=1,
                warnings=1
            )

            makefile.extra_defines.append("QT_INTERNAL_XML")

            if prof or "qtxml" not in pyqt_modules:
                makefile.extra_defines.append("TQT_MODULE_XML")

            makefile.extra_include_dirs.append(os.path.join(src_dir, "pylupdate3"))

            if not os.access("pylupdate3", os.F_OK):
                os.mkdir("pylupdate3")

            makefile.generate()
            tool_dirs.append("pylupdate3")
        elif qt_version >= 0x020000:
            sipconfig.inform("Creating pyuic Makefile...")

            makefile = sipconfig.ProgramMakefile(
                configuration=sipcfg,
                build_file="pyuic.sbf",
                dir="pyuic2",
                install_dir=opt_pyqtbindir,
                console=1,
                qt=1,
                warnings=1
            )

            makefile.extra_defines.append("UIC")
            makefile.extra_include_dirs.append(qt_dir + "/src/3rdparty/zlib")

            makefile.generate()
            tool_dirs.append("pyuic2")

        return tool_dirs


def inform_user():
    """Tell the user the option values that are going to be used.
    """
    if qt_edition:
        edstr = qt_edition + " edition "
    else:
        edstr = ""

    sipconfig.inform("TQt v%s %sis being used." % (sipconfig.version_to_string(qt_version), edstr))
    sipconfig.inform("SIP %s is being used." % sipcfg.sip_version_str)
    sipconfig.inform("These PyTQt modules will be built: %s." % string.join(pyqt_modules))

    if disabled_classes:
        sipconfig.inform("Support for these TQt classes has been disabled: %s." % string.join(disabled_classes))

    sipconfig.inform("The PyTQt modules will be installed in %s." % opt_pyqtmoddir)
    sipconfig.inform("The PyTQt .sip files will be installed in %s." % opt_pyqtsipdir)

    sipconfig.inform("The TQt header files are in %s." % qt_incdir)
    sipconfig.inform("The %s TQt library is in %s." % (opt_qtlib, qt_libdir))

    if qt_version >= 0x020000:
        sipconfig.inform("pyuic will be installed in %s." % opt_pyqtbindir)

    if qt_version >= 0x030000:
        sipconfig.inform("pylupdate will be installed in %s." % opt_pyqtbindir)

    if opt_vendorcheck:
        sipconfig.inform("PyTQt will only be usable with signed interpreters.")


def create_config(module, template, macros):
    """Create the PyTQt 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":       opt_pyqtbindir,
        "pyqt_mod_dir":       opt_pyqtmoddir,
        "pyqt_sip_dir":       opt_pyqtsipdir,
        "pyqt_modules":       pyqt_modules,
        "pyqt_qt_sip_flags":  qt_sip_flags,
        "qt_version":         qt_version,
        "qt_edition":         qt_edition,
        "qt_winconfig":       qt_winconfig,
        "qt_framework":       0,
        "qt_threaded":        qt_threaded,
        "qt_dir":             qt_dir,
        "qt_inc_dir":         qt_incdir,
        "qt_lib":             opt_qtlib,
        "qt_lib_dir":         qt_libdir
    }

    if "qtaxcontainer" in pyqt_modules:
        content["pyqt_qtaxcontainer_sip_flags"] = qt_sip_flags

    if "qtcanvas" in pyqt_modules:
        content["pyqt_qtcanvas_sip_flags"] = qt_sip_flags

    if "qtext" in pyqt_modules:
        content["pyqt_qtext_sip_flags"] = qtext_sip_flags

        # These are internal.
        content["_pyqt_qscintilla_defines"] = qsci_define
        content["_pyqt_qscintilla_inc_dir"] = opt_qsciincdir
        content["_pyqt_qscintilla_lib_dir"] = opt_qscilibdir

    if "qtgl" in pyqt_modules:
        content["pyqt_qtgl_sip_flags"] = qt_sip_flags

    if "qtnetwork" in pyqt_modules:
        content["pyqt_qtnetwork_sip_flags"] = qt_sip_flags

    if "qtpe" in pyqt_modules:
        content["pyqt_qtpe_sip_flags"] = qtpe_sip_flags

    if "qtsql" in pyqt_modules:
        content["pyqt_qtsql_sip_flags"] = qt_sip_flags

    if "qttable" in pyqt_modules:
        content["pyqt_qttable_sip_flags"] = qt_sip_flags

    if "qtui" in pyqt_modules:
        content["pyqt_qtui_sip_flags"] = qt_sip_flags

    if "qtxml" in pyqt_modules:
        content["pyqt_qtxml_sip_flags"] = qt_sip_flags

    sipconfig.create_config_module(module, template, content, macros)


def compile_qt_program(name, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0, python=0, debug=0):
    """Compile a simple TQt application.

    name is the name of the single source file.
    define is a name to add to the list of preprocessor defines.
    include_dir is the name of a directory to add to the list of include
    directories.
    lib_dir is the name of a directory to add to the list of library
    directories.
    lib is the name of a library to add to the list of libraries.
    opengl is set if the application uses OpenGL.
    python is set if the application #includes Python.h.
    debug is set if this is a debug build.

    Returns the name of the executable suitable for running or None if it
    wasn't created.
    """
    makefile = sipconfig.ProgramMakefile(sipcfg, console=1, qt=1, warnings=0, opengl=opengl, python=python, debug=debug)

    if define:
        makefile.extra_defines.append(define)

    if include_dir:
        makefile.extra_include_dirs.append(include_dir)

    if lib_dir:
        makefile.extra_lib_dirs.append(lib_dir)

    if lib:
        makefile.extra_libs.append(lib)

    exe, build = makefile.build_command(name)

    # Make sure the executable file doesn't exist.
    try:
        os.remove(exe)
    except OSError:
        pass

    if not opt_verbose:
        try:
            import subprocess

            p = subprocess.Popen(build, shell=True, stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

            fout = p.stdout
        except ImportError:
            _, fout = os.popen4(build)

        # Read stdout and stderr until there is no more output.
        lout = fout.readline()
        while lout:
            lout = fout.readline()

        fout.close()

        try:
            os.wait()
        except:
            pass
    else:
        os.system(build)

    if not os.access(exe, os.X_OK):
        return None

    if sys.platform != "win32":
        exe = "./" + exe

    return exe


def check_qscintilla():
    """See if TQScintilla can be found and what its version is.
    """
    # Set the defaults if they haven't been explicitly specified.
    global opt_qsciincdir, opt_qscilibdir

    if opt_qsciincdir is None:
        opt_qsciincdir = qt_incdir

    if opt_qscilibdir is None:
        opt_qscilibdir = qt_libdir

    # Find the TQScintilla header files.
    sciglobal = os.path.join(opt_qsciincdir, "qextscintillaglobal.h")

    if os.access(sciglobal, os.F_OK):
        # Get the TQScintilla version number.
        global qsci_version

        qsci_version, sciversstr = sipconfig.read_version(sciglobal, "TQScintilla", "TQSCINTILLA_VERSION", "TQSCINTILLA_VERSION_STR")

        if glob.glob(os.path.join(opt_qscilibdir, "*qscintilla*")):
            sipconfig.inform("TQScintilla %s is being used." % sciversstr)

            # If we find a snapshot then set a negative version number as a
            # special case.
            if string.find(sciversstr, "snapshot") >= 0:
                qsci_version = -1
        else:
            sipconfig.inform("The TQScintilla library could not be found in %s and so the qtext module will not be built. If TQScintilla is installed then use the -o argument to explicitly specify the correct directory." % opt_qscilibdir)
    else:
        sipconfig.inform("qextscintillaglobal.h could not be found in %s and so the qtext module will not be built. If TQScintilla is installed then use the -n argument to explicitly specify the correct directory." % opt_qsciincdir)


def check_vendorid():
    """See if the VendorID library and include file can be found.
    """
    global opt_vendorcheck

    if opt_vendorcheck:
        if os.access(os.path.join(opt_vendincdir, "vendorid.h"), os.F_OK):
            if glob.glob(os.path.join(opt_vendlibdir, "*vendorid*")):
                sipconfig.inform("The VendorID package was found.")
            else:
                opt_vendorcheck = 0
                sipconfig.inform("The VendorID library could not be found in %s and so signed interpreter checking will be disabled. If the VendorID library is installed then use the -m argument to explicitly specify the correct directory." % opt_vendlibdir)
        else:
            opt_vendorcheck = 0
            sipconfig.inform("vendorid.h could not be found in %s and so signed interpreter checking will be disabled. If the VendorID package is installed then use the -l argument to explicitly specify the correct directory." % opt_vendincdir)


def check_module(mname, incfile, ctor, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0):
    """See if a module can be built and, if so, add it to the global list of
    modules.

    mname is the name of the module.
    incfile is the name of the include file needed for the test.
    ctor is the C++ constructor of the class being used for the test.
    define is a name to add to the list of preprocessor defines.
    include_dir is the name of a directory to add to the list of include
    directories.
    lib_dir is the name of a directory to add to the list of library
    directories.
    lib is the name of a library to add to the list of libraries.
    opengl is set if the application uses OpenGL.
    """
    # Check the module's main .sip file exists.
    if os.access(os.path.join(src_dir, "sip", mname, mname + "mod.sip"), os.F_OK):
        sipconfig.inform("Checking to see if the %s module should be built..." % mname)

        if check_class(incfile, ctor, define, include_dir, lib_dir, lib, opengl):
            pyqt_modules.append(mname)
        else:
            if check_class("nt" + incfile, ctor, define, include_dir, lib_dir, lib, opengl):
                pyqt_modules.append(mname)


def check_class(incfile, ctor, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0):
    """Return non-zero if a class is available.

    incfile is the name of the include file needed for the test.
    ctor is the C++ constructor of the class.
    define is a name to add to the list of preprocessor defines.
    include_dir is the name of a directory to add to the list of include
    directories.
    lib_dir is the name of a directory to add to the list of library
    directories.
    lib is the name of a library to add to the list of libraries.
    opengl is set if the application uses OpenGL.
    """
    cfgtest = "cfgtest.cpp"

    f = open(cfgtest, "w")

    f.write("""#include <%s>

int main(int argc, char **argv)
{
    new %s;
}
""" % (incfile, ctor))

    f.close()

    return compile_qt_program(cfgtest, define, include_dir, lib_dir, lib, opengl)


def check_plugin(cname, incfile):
    """Return non-zero if a class that might be a plugin is in the main TQt
    library.

    cname is the name of the class.
    incfile is the name of the include file needed for the test.
    """
    sipconfig.inform("Checking to see if the %s class is built in..." % cname)

    return check_class(incfile, cname + "()")


def create_features_file(name):
    """Create the features file.

    name is the name of the features file in the current directory.
    """
    # The features that a given TQt configuration may or may not support.  Note
    # that STYLE_WINDOWSXP and ASSISTANTCLIENT require special handling.
    flist = ["ACTION", "CLIPBOARD", "CODECS", "COLORDIALOG", "DATASTREAM",
             "DIAL", "DNS", "DOM", "DRAGANDDROP", "ICONVIEW", "IMAGE_TEXT",
             "INPUTDIALOG", "FILEDIALOG", "FONTDATABASE", "FONTDIALOG",
             "MESSAGEBOX", "MIMECLIPBOARD",
             "NETWORKPROTOCOL", "NETWORKPROTOCOL_FTP", "NETWORKPROTOCOL_HTTP",
             "PICTURE", "PRINTDIALOG", "PRINTER", "PROGRESSDIALOG",
             "PROPERTIES",
             "SEMIMODAL", "SIZEGRIP", "SOUND", "SPLITTER", "STYLE_CDE",
             "STYLE_INTERLACE", "STYLE_MOTIF", "STYLE_MOTIFPLUS",
             "STYLE_PLATINUM", "STYLE_SGI", "STYLE_WINDOWS",
             "TABDIALOG", "TABLE", "TABLEVIEW", "TRANSFORMATIONS",
             "TRANSLATION", "WIZARD", "WORKSPACE"]

    # Generate the program which will generate the features file.
    f = open("mkfeatures.cpp", "w")

    f.write(
"""#include <Python.h>
#include <stdio.h>
#include <tqglobal.h>
#include <tqapplication.h>

int main(int argc,char **argv)
{
    FILE *fp;
    TQApplication app(argc,argv,0);

    if ((fp = fopen("%s","w")) == NULL)
    {
        printf("Unable to create '%s'\\n");
        return 1;
    }

#if !defined(WITH_THREAD) || !defined(QT_THREAD_SUPPORT)
    fprintf(fp,"-x TQt_THREAD_SUPPORT\\n");
#endif

#if !defined(Q_WS_WIN) || TQT_VERSION < 0x030000 || defined(QT_NO_STYLE_WINDOWSXP)
    fprintf(fp,"-x TQt_STYLE_WINDOWSXP\\n");
#endif

#if defined(Q_OS_WIN64)
    fprintf(fp,"-x TQt_TQ_LONG_IS_long\\n");
#endif
""" % (name, name))

    for feat in flist:
        f.write(
"""
#if defined(QT_NO_%s)
    fprintf(fp,"-x TQt_%s\\n");
#endif
""" % (feat, feat))

    # Disable TQAssistantClient for the Professional Edition.
    if "TQAssistantClient" in disabled_classes:
        f.write(
"""
    fprintf(fp,"-x TQt_ASSISTANTCLIENT\\n");
""")

    f.write(
"""
    fclose(fp);

    return 0;
}
""")

    f.close()

    # Build the program.
    exe = compile_qt_program("mkfeatures.cpp", include_dir=sipcfg.py_inc_dir, python=1)
    if not exe:
        sipconfig.error("Unable to build mkfeatures utility.")

    os.system(exe)

    # Check the file was created.
    if not os.access(name, os.F_OK):
        sipconfig.error("There was an error creating the features file.")

    # Check what features have been implemented as plugins and disable them.
    plugins = [("STYLE_CDE",       "qcdestyle.h",       "TQCDEStyle"),
               ("STYLE_INTERLACE", "qinterlacestyle.h", "TQInterlaceStyle"),
               ("STYLE_MOTIF",     "qmotifstyle.h",     "TQMotifStyle"),
               ("STYLE_MOTIFPLUS", "qmotifplusstyle.h", "TQMotifPlusStyle"),
               ("STYLE_PLATINUM",  "qplatinumstyle.h",  "TQPlatinumStyle"),
               ("STYLE_SGI",       "qsgistyle.h",       "TQSGIStyle"),
               ("STYLE_WINDOWSXP", "qwindowsxpstyle.h", "TQWindowsXPStyle"),
               ("STYLE_WINDOWS",   "qwindowsstyle.h",   "TQWindowsStyle")]

    f = open(name, "a")

    for (feat, incfile, cname) in plugins:
        if not check_plugin(cname, incfile):
            if not check_plugin(cname, "nt" + incfile):
                f.write("-x TQt_%s\n" % feat)
                disabled_classes.append(cname)

    f.close()


def get_feature_flags():
    """Return the list of SIP flags that exclude unsupported TQt features.
    """
    featfile = "features"

    # Create the features file if it doesn't exist and we are not keeping it.
    if opt_keepfeatures and os.access(featfile,os.F_OK):
        sipconfig.inform("Using existing features file.")
    else:
        sipconfig.inform("Creating features file...")
        create_features_file(featfile)

    # Parse the features file.
    ff = open(featfile, "r")

    flags = []

    line = ff.readline()
    while line:
        flags.extend(string.split(line))
        line = ff.readline()

    if sipcfg.sip_version >= 0x040702:
        flags.extend(['-x', 'TQt_SIP_PRE_4_7_2'])

    return flags


def set_sip_flags():
    """Set the SIP platform, version and feature flags.
    """
    qt_sip_flags.extend(pyqt.sip_flags())

    # If we don't check for signed interpreters, we exclude the 'VendorID'
    # feature
    if not opt_vendorcheck:
        qt_sip_flags.append("-x")
        qt_sip_flags.append("VendorID")

    # Handle the platform tag.
    if opt_qtpetag:
        plattag = "WS_QWS"
    elif sys.platform == "win32":
        plattag = "WS_WIN"
    elif sys.platform == "darwin":
        if "__DARWIN_X11__" in sipcfg.build_macros()["DEFINES"]:
            plattag = "WS_X11"
        else:
            plattag = "WS_MACX"
    else:
        plattag = "WS_X11"

    qt_sip_flags.append("-t")
    qt_sip_flags.append(plattag)

    # Handle the TQt version tag.
    verstag = sipconfig.version_to_sip_tag(qt_version, pyqt.qt_version_tags(), "TQt")

    if verstag:
        qt_sip_flags.append("-t")
        qt_sip_flags.append(verstag)

    # The flags so far are common.
    for f in qt_sip_flags:
        qtext_sip_flags.append(f)
        qtpe_sip_flags.append(f)

    # Handle the TQScintilla version tag.
    if qsci_version:
        qscitags = {
            0x010100: None,
            0x010200: "TQScintilla_1_1",
            0x010300: "TQScintilla_1_2",
            0x010400: "TQScintilla_1_3",
            0x010500: "TQScintilla_1_4",
            0x010600: "TQScintilla_1_5",
            0x010700: "TQScintilla_1_6",
            0x020000: "TQScintilla_1_7"
        }

        verstag = sipconfig.version_to_sip_tag(qsci_version, qscitags, "TQScintilla")

        if verstag:
            qtext_sip_flags.append("-t")
            qtext_sip_flags.append(verstag)

    # Handle the TQtopia tag.
    if opt_qtpetag:
        qtpe_sip_flags.append("-t")
        qtpe_sip_flags.append(opt_qtpetag)


def generate_code(mname, extra_cflags=None, extra_cxxflags=None, extra_define=None, extra_include_dirs=None, extra_lflags=None, extra_lib_dir=None, extra_libs=None, opengl=0, sip_flags=None):
    """Generate the code for a module.

    mname is the name of the module.
    extra_cflags is a string containing additional C compiler flags.
    extra_cxxflags is a string containing additional C++ compiler flags.
    extra_define is a name to add to the list of preprocessor defines.
    extra_include_dirs is a list of directories to add to the list of include
    directories.
    extra_lflags is a string containing additional linker flags.
    extra_lib_dir is the name of a directory to add to the list of library
    directories.
    extra_libs is a list of the names of extra libraries to add to the list of
    libraries.
    opengl is set if the module needs OpenGL support.
    sip_flags is the list of sip flags to use instead of the defaults.
    """
    sipconfig.inform("Generating the C++ source for the %s module..." % mname)

    try:
        shutil.rmtree(mname)
    except:
        pass

    try:
        os.mkdir(mname)
    except:
        sipconfig.error("Unable to create the %s directory." % mname)

    # Build the SIP command line.
    argv = ['"' + sipcfg.sip_bin + '"']

    if sip_flags is None:
        sip_flags = qt_sip_flags

    argv.extend(sip_flags)

    if opt_concat:
        argv.append("-j")
        argv.append(str(opt_split))

    if opt_tracing:
        argv.append("-r")

    argv.append("-c")
    argv.append(mname)

    buildfile = os.path.join(mname, mname + ".sbf")
    argv.append("-b")
    argv.append(buildfile)

    argv.append("-I")
    argv.append(os.path.join(src_dir, "sip"))

    # SIP assumes POSIX style path separators.
    argv.append(string.join([src_dir, "sip", mname, mname + "mod.sip"], "/"))

    os.system(string.join(argv))

    # Check the result.
    if not os.access(buildfile, os.F_OK):
        sipconfig.error("Unable to create the C++ code.")

    # Generate the Makefile.
    sipconfig.inform("Creating the Makefile for the %s module..." % mname)

    installs = []
    sipfiles = []

    for s in glob.glob("sip/" + mname + "/*.sip"):
        sipfiles.append(os.path.join(src_dir, "sip", mname, os.path.basename(s)))

    installs.append([sipfiles, os.path.join(pyqt.sip_dir(), mname)])

    makefile = sipconfig.SIPModuleMakefile(
        configuration=sipcfg,
        build_file=mname + ".sbf",
        dir=mname,
        install_dir=pyqt.module_dir(),
        installs=installs,
        qt=1,
        opengl=opengl,
        warnings=1,
        static=opt_static,
        debug=opt_debug
    )

    if extra_cflags:
        makefile.extra_cflags.append(extra_cflags)

    if extra_cxxflags:
        makefile.extra_cxxflags.append(extra_cxxflags)

    if extra_define:
        makefile.extra_defines.append(extra_define)

    if extra_include_dirs:
        makefile.extra_include_dirs.extend(extra_include_dirs)

    if extra_lflags:
        makefile.extra_lflags.append(extra_lflags)

    if extra_lib_dir:
        makefile.extra_lib_dirs.append(extra_lib_dir)

    if extra_libs:
        makefile.extra_libs.extend(extra_libs)

    makefile.generate()


def check_license():
    """Handle the validation of the PyTQt license.
    """
    try:
        import license
        ltype = license.LicenseType
        lname = license.LicenseName

        try:
            lfile = license.LicenseFile
        except AttributeError:
            lfile = None
    except ImportError:
        ltype = None

    if ltype is None:
        ltype = "GPL"
        lname = "GNU General Public License"
        lfile = None

    sipconfig.inform("This is the %s version of PyTQt %s (licensed under the %s) for Python %s on %s." % (ltype, pyqt_version_str, lname, string.split(sys.version)[0], sys.platform))

    # Common checks.
    if ltype == "GPL" and sys.platform == "win32":
        error("You cannot use the GPL version of PyTQt under Windows.")

    try:
        qted = qt_edition
    except AttributeError:
        qted = None

    if qted and ltype != "internal":
        if (qted == "free" and ltype != "GPL") or (qted != "free" and ltype == "GPL"):
            sipconfig.error("This version of PyTQt and the %s edition of TQt have incompatible licenses." % qted)

    # Confirm the license.
    sys.stdout.write("""
Type 'L' to view the license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

""")

    while 1:
        try:
            resp = raw_input("Do you accept the terms of the license? ")
        except:
            resp = ""

        resp = string.lower(string.strip(resp))

        if resp == "yes":
            break

        if resp == "no":
            sys.exit(0)

        if resp == "l":
            os.system("more LICENSE")

    # If there should be a license file then check it is where it should be.
    if lfile:
        if os.access(os.path.join("sip", lfile), os.F_OK):
            sipconfig.inform("Found the license file %s." % lfile)
        else:
            sipconfig.error("Please copy the license file %s to the sip directory." % lfile)


def get_build_macros(overrides):
    """Return the dictionary of platform specific build macros from the TQt
    installation.  Return None if any of the overrides was invalid.

    overrides is a list of macros overrides from the user.
    """
    # Get the name of the qmake configuration file to take the macros from.
    if "QMAKESPEC" in os.environ.keys():
        fname = os.path.join(qt_dir, "mkspecs", os.environ["QMAKESPEC"], "qmake.conf")
    else:
        fname = os.path.join(qt_dir, "mkspecs", "default", "qmake.conf")

        if not os.access(fname, os.F_OK):
            sipconfig.error("Unable to find the default configuration file %s. You can use the QMAKESPEC environment variable to specify the correct platform instead of \"default\"." % fname)

    # Add the TQt specific macros to the default.
    names = sipcfg.build_macros().keys()
    names.append("INCDIR_QT")
    names.append("LIBDIR_QT")
    names.append("MOC")

    # Make sure $QTDIR reflects any directory passed on the command line.
    os.environ["QTDIR"] = qt_dir

    properties = {
        "QT_INSTALL_BINS":      os.path.join(qt_dir, "bin"),
        "QT_INSTALL_HEADERS":   os.path.join(qt_dir, "include"),
        "QT_INSTALL_LIBS":      os.path.join(qt_dir, "lib")
    }

    return sipconfig.parse_build_macros(fname, names, overrides, properties)


def check_qt_installation(macros):
    """Check the TQt installation and get the version number and edition.

    macros is the dictionary of build macros.
    """
    # Get the Makefile generator.
    generator = macros["MAKEFILE_GENERATOR"]

    # Set the TQt include and lib directories.
    global qt_incdir, qt_libdir

    qt_incdir = macros["INCDIR_QT"]

    if not qt_incdir:
        qt_incdir = os.path.join(qt_dir, "include")
        macros["INCDIR_QT"] = qt_incdir

    qt_libdir = macros["LIBDIR_QT"]

    if not qt_libdir:
        qt_libdir = os.path.join(qt_dir, "lib")
        macros["LIBDIR_QT"] = qt_libdir

    # Check the TQt header files have been installed.  Quietly check for TQt v4.
    qt4_d = os.path.join(qt_incdir, "TQtCore")

    qglobal = os.path.join(qt4_d, "qglobal.h")

    if not os.access(qglobal, os.F_OK):
        qglobal = os.path.join(qt_incdir, "qglobal.h")

        if not os.access(qglobal, os.F_OK):
            qglobal = os.path.join(qt_incdir, "ntqglobal.h")

            if not os.access(qglobal, os.F_OK):
                sipconfig.error("qglobal.h or ntqglobal.h could not be found in %s." % qt_incdir)

    # Get the TQt version number.
    global qt_version

    qt_version, ignore = sipconfig.read_version(qglobal, "TQt", "TQT_VERSION")

    # Early versions of TQt for the Mac didn't include everything.  Rather than
    # maintain these in the future we just mandate a later version.
    if sys.platform == "darwin" and qt_version < 0x030100:
        sipconfig.error("PyTQt for MacOS/X requires TQt v3.1.0 or later.")

    # The way SIP v4.2 and later handle connections between signals and Python
    # slots only works with TQt v3 and later.  Therefore TQt v2 and earlier needs
    # SIP v3.
    if qt_version < 0x030000:
        sipconfig.error("TQt v2.x and earlier require SIP v3.x.")

    if qt_version >= 0x040000:
        sipconfig.error("TQt v4.x requires PyTQt v4.x.")

    # Try and work out which edition it is.
    global qt_edition

    if qt_version >= 0x030000:
        if opt_qconfigdir:
            qconfigdir = opt_qconfigdir
        else:
            qconfigdir = qt_incdir

        qconfig = os.path.join(qconfigdir, "qconfig.h")

        if not os.access(qconfig,os.F_OK):
            qconfig = os.path.join(qconfigdir, "ntqconfig.h")

            if not os.access(qconfig,os.F_OK):
                sipconfig.error("qconfig.h or ntqconfig.h could not be found in %s." % qconfigdir)

        f = open(qconfig)
        l = f.readline()

        while l:
            wl = string.split(l)
            if len(wl) == 3 and wl[0] == "#define" and wl[1] == "QT_PRODUCT_LICENSE":
                    qt_edition = wl[2][4:-1]
                    break

            l = f.readline()

        f.close()

        if not qt_edition:
            sipconfig.error("The TQt edition could not be determined by parsing %s." % qconfig)
    elif qt_version == 0x020300 and sys.platform == "win32":
        # See if we have the TQt v2 non-commercial version.
        if os.access(os.path.join(qt_libdir, "qt-mt230nc.lib"), os.F_OK):
            qt_edition = "non-commercial"

    if sys.platform == "win32":
        # Work out how TQt was built on Windows.

        global qt_winconfig

        try:
            f = open(os.path.join(qt_dir, ".qtwinconfig"), "r")
        except IOError:
            f = None

        if f:
            cfg = f.readline()
            f.close()

            val = string.find(cfg, "=")

            if val >= 0:
                qt_winconfig = string.strip(cfg[val + 1:])
        else:
            # Assume it was built as a DLL.
            qt_winconfig = "shared"

    # Determine the TQt library to link against and if it has thread support.
    global qt_threaded

    resolve_qt3_library(generator)

    if opt_qtlib in ("qt-mt", "qt-mtedu", "qt-mteval", "qte-mt", "qtmt", "qtmtedu", "qtmteval", "tqt-mt", "tqt-mtedu", "tqt-mteval", "tqte-mt", "tqtmt", "tqtmtedu", "tqtmteval"):
        qt_threaded = 1

    global pyqt

    pyqt = ConfigurePyTQt3()

    # We haven't yet factored out sipconfig's knowledge of how to build TQt
    # binaries and it is expecting to find these in the configuration when it
    # generates the Makefiles.
    sipcfg.qt_version = qt_version
    sipcfg.qt_edition = qt_edition
    sipcfg.qt_winconfig = qt_winconfig
    sipcfg.qt_framework = 0
    sipcfg.qt_threaded = qt_threaded
    sipcfg.qt_dir = qt_dir
    sipcfg.qt_lib = opt_qtlib
    sipcfg.qt_lib_dir = qt_libdir


def resolve_qt3_library(generator):
    """See which version of the TQt v3 library can be found.  (We can't trust
    the configuration files.)

    generator is the name of the Makefile generator.
    """
    global opt_qtlib

    if opt_qtlib:
        if not is_qt_library(generator, opt_qtlib):
            sipconfig.error("The %s TQt library could not be found in %s." % (opt_qtlib, qt_libdir))
    else:
        stlib = is_qt_library(generator, "tqt")
        mtlib = is_qt_library(generator, "tqt-mt")
        edlib = is_qt_library(generator, "tqt-mtedu")
        evlib = is_qt_library(generator, "tqt-mteval")
        emlib = is_qt_library(generator, "tqte")
        etlib = is_qt_library(generator, "tqte-mt")

        # Borland likes to be a little different.
        bmtlib = is_qt_library(generator, "tqtmt")
        bedlib = is_qt_library(generator, "tqtmtedu")
        bevlib = is_qt_library(generator, "tqtmteval")

        names = []

        if stlib:
            opt_qtlib = "tqt"
            names.append(opt_qtlib)

        if mtlib:
            opt_qtlib = "tqt-mt"
            names.append(opt_qtlib)

        if edlib:
            opt_qtlib = "tqt-mtedu"
            names.append(opt_qtlib)

        if evlib:
            opt_qtlib = "tqt-mteval"
            names.append(opt_qtlib)

        if emlib:
            opt_qtlib = "tqte"
            names.append(opt_qtlib)

        if etlib:
            opt_qtlib = "tqte-mt"
            names.append(opt_qtlib)

        if bmtlib:
            opt_qtlib = "tqtmt"
            names.append(opt_qtlib)

        if bedlib:
            opt_qtlib = "tqtmtedu"
            names.append(opt_qtlib)

        if bevlib:
            opt_qtlib = "tqtmteval"
            names.append(opt_qtlib)

        if not names:
            sipconfig.error("No TQt libraries could be found in %s." % qt_libdir)

        if len(names) > 1:
            sipconfig.error("These TQt libraries were found: %s. Use the -y argument to explicitly specify which you want to use." % string.join(names))


def is_qt_library(generator, lib):
    """See if a particular TQt library is installed.

    generator is the name of the Makefile generator.
    lib is the name of the library.
    """
    if generator in ("MSVC", "MSVC.NET", "BMAKE"):
        lpatts = [lib + "[0-9]*.lib", lib + ".lib"]
    else:
        lpatts = ["lib" + lib + ".*"]

    for lpatt in lpatts:
        lmatch = glob.glob(os.path.join(qt_libdir, lpatt))

        if lmatch:
            return lmatch

    return []


def main(argv):
    """Create the configuration module module.

    argv is the list of command line arguments.
    """
    # Check Python isn't too new.
    if sipcfg.py_version >= 0x030000:
        sipconfig.error("PyTQt v3.x does not support Python v3.x")

    # Check SIP is new enough.
    if sipcfg.sip_version_str[:8] != "snapshot":
        if sipcfg.sip_version < sip_min_version:
            sipconfig.error("This version of PyTQt requires SIP v%s or later" % sipconfig.version_to_string(sip_min_version))

    # Parse the command line.
    try:
        optlist, args = getopt.getopt(argv[1:], "ha:b:cd:e:fg:ij:kl:m:n:o:q:rsuv:wy:")
    except getopt.GetoptError:
        usage()

    global qt_dir, opt_qtlib, opt_qconfigdir
    global opt_pyqtbindir, opt_pyqtmoddir, opt_pyqtsipdir
    global opt_qtpetag, opt_static, opt_debug, opt_concat
    global opt_split, opt_tracing, opt_verbose, opt_keepfeatures
    global opt_qsciincdir, opt_qscilibdir, qsci_define
    global opt_vendorcheck, opt_vendincdir, opt_vendlibdir
    global opt_libpython

    for opt, arg in optlist:
        if opt == "-h":
            usage(0)
        elif opt == "-a":
            opt_qtpetag = arg
        elif opt == "-b":
            opt_pyqtbindir = os.path.abspath(arg)
        elif opt == "-c":
            opt_concat = 1
        elif opt == "-d":
            opt_pyqtmoddir = os.path.abspath(arg)
        elif opt == "-e":
            opt_libpython = arg
        elif opt == "-f":
            opt_keepfeatures = 1
        elif opt == "-g":
            opt_qconfigdir = os.path.abspath(arg)
        elif opt == "-i":
            opt_vendorcheck = 1
        elif opt == "-j":
            try:
                opt_split = int(arg)
            except:
                usage()
        elif opt == "-k":
            opt_static = 1
        elif opt == "-l":
            opt_vendincdir = arg
        elif opt == "-m":
            opt_vendlibdir = arg
        elif opt == "-n":
            opt_qsciincdir = arg
        elif opt == "-o":
            opt_qscilibdir = arg
        elif opt == "-q":
            qt_dir = os.path.abspath(arg)
        elif opt == "-r":
            opt_tracing = 1
        elif opt == "-s":
            qsci_define = ""
        elif opt == "-u":
            opt_debug = 1
        elif opt == "-v":
            opt_pyqtsipdir = os.path.abspath(arg)
        elif opt == "-w":
            opt_verbose = 1
        elif opt == "-y":
            if arg in ("qt", "qt-mt", "qt-mtedu", "qt-mteval", "qte", "qte-mt", "qtmt", "qtmtedu", "tqt", "tqt-mt", "tqt-mtedu", "tqt-mteval", "tqte", "tqte-mt", "tqtmt", "tqtmtedu"):
                opt_qtlib = arg
            else:
                usage()

    # Check that we know the name of the TQt root directory.
    if not qt_dir:
        sipconfig.error("A TQt installation could not be found. Use use the -q argument or the QTDIR environment variable to explicitly specify the correct directory.")

    # When building static libraries, signed interpreter checking makes no
    # sense.
    if opt_vendorcheck and opt_static:
        sipconfig.error("Using the VendorID package when building static libraries makes no sense.")

    # Replace the existing build macros with the ones from the TQt installation.
    macros = get_build_macros(args)

    if macros is None:
        usage()

    sipcfg.set_build_macros(macros)

    # Check TQt is what we need.
    check_qt_installation(macros)

    # Check the licenses are compatible.
    check_license()

    # Check for TQScintilla.
    check_qscintilla()

    # Check which modules to build.
    qtmod_lib = pyqt.check_modules()

    # Check for the VendorID package.
    check_vendorid()

    # Set the SIP platform, version and feature flags.
    set_sip_flags()

    # Tell the user what's been found.
    inform_user()

    # Generate the code.

    extra_include_dirs = []
    extra_libs = []

    if qtmod_lib:
        extra_libs.append(qtmod_lib)

    if opt_libpython:
        extra_libs.append(opt_libpython)

    if opt_vendorcheck:
        extra_include_dirs.append(opt_vendincdir)
        extra_lib_dir = opt_vendlibdir
        extra_libs.append("vendorid")
    else:
        extra_lib_dir = None

    pyqt.code(extra_include_dirs, extra_lib_dir, extra_libs)

    # Create the additional Makefiles.
    sipconfig.inform("Creating top level Makefile...")

    open('__init__.py', 'a').close()

    sipconfig.ParentMakefile(
        configuration=sipcfg,
        subdirs=pyqt_modules + pyqt.tools(),
        installs=(pyqt.module_installs(), pyqt.module_dir())
    ).generate()

    # Install the configuration module.
    create_config("pyqtconfig.py", os.path.join(src_dir, "pyqtconfig.py.in"), macros)


###############################################################################
# The script starts here.
###############################################################################

if __name__ == "__main__":
    try:
        main(sys.argv)
    except SystemExit:
        raise
    except:
        sys.stderr.write(
"""An internal error occured.  Please report all the output from the program,
including the following traceback, to support@riverbankcomputing.co.uk.
""")
        raise