File: configure

package info (click to toggle)
psi 0.14-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 12,704 kB
  • ctags: 22,303
  • sloc: cpp: 150,140; ansic: 26,319; xml: 1,215; makefile: 236; python: 178; ruby: 129; sh: 27
file content (1982 lines) | stat: -rwxr-xr-x 42,672 bytes parent folder | download | duplicates (7)
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
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
#!/bin/sh
#
# Generated by qconf 1.5 ( http://delta.affinix.com/qconf/ )
#

show_usage() {
cat <<EOT
Usage: $0 [OPTION]...

This script creates necessary configuration files to build/install.

Main options:
  --qtdir=[path]    Directory where Qt is installed.
  --static          Create a static library instead of shared.
  --verbose         Show extra configure output.
  --help            This help text.

Project options:
  --release                   Build with debugging turned off (default).
  --debug                     Build with debugging turned on.
  --debug-and-release         Build two versions, with and without debugging
                              turned on (mac only).
  --no-separate-debug-info    Do not store debug information in a separate
                              file (default for mac).
  --separate-debug-info       Strip debug information into a separate .debug
                              file (default for non-mac).
  --no-framework              Do not build as a Mac framework.
  --framework                 Build as a Mac framework (default).
  --universal                 Build with Mac universal binary support.
  --mac-sdk=[path]            Path to Mac universal SDK (PPC host only).
  --disable-tests             Don't build examples and unittests.

Dependency options:
  --with-qca=[path]         Specify path to QCA tree, mainly for building
                            against an uninstalled QCA.
  --with-zlib-inc=[path]    Path to zlib include files
  --with-zlib-lib=[path]    Path to zlib library files

EOT
}

# which/make detection adapted from Qt
which_command() {
	OLD_HOME=$HOME
	HOME=/dev/null
	export HOME

	WHICH=`which which 2>/dev/null`
	if echo $WHICH | grep 'shell built-in command' >/dev/null 2>&1; then
		WHICH=which
	elif [ -z "$WHICH" ]; then
		if which which >/dev/null 2>&1; then
			WHICH=which
		else
			for a in /usr/ucb /usr/bin /bin /usr/local/bin; do
				if [ -x $a/which ]; then
					WHICH=$a/which
					break;
				fi
			done
		fi
	fi

	if [ -z "$WHICH" ]; then
		OLD_IFS=$IFS
		IFS=:
		for a in $PATH; do
			if [ -x $a/$1 ]; then
				echo "$a/$1"
				IFS=$OLD_IFS
				export IFS
				HOME=$OLD_HOME
				export HOME
				return 0
			fi
		done
		IFS=$OLD_IFS
		export IFS
	else
		a=`"$WHICH" "$1" 2>/dev/null`
		if [ ! -z "$a" -a -x "$a" ]; then
			echo "$a"
			HOME=$OLD_HOME
			export HOME
			return 0
		fi
	fi
	HOME=$OLD_HOME
	export HOME
	return 1
}
WHICH=which_command

# find a make command
if [ -z "$MAKE" ]; then
	MAKE=
	for mk in gmake make; do
		if $WHICH $mk >/dev/null 2>&1; then
			MAKE=`$WHICH $mk`
			break
		fi
	done
	if [ -z "$MAKE" ]; then
		echo "You don't seem to have 'make' or 'gmake' in your PATH."
		echo "Cannot proceed."
		exit 1
	fi
fi

show_qt_info() {
	printf "Be sure you have a proper Qt 4.0 build environment set up.  This means not\n"
	printf "just Qt, but also a C++ compiler, a make tool, and any other packages\n"
	printf "necessary for compiling C++ programs.\n"
	printf "\n"
	printf "If you are certain everything is installed, then it could be that Qt 4 is not\n"
	printf "being recognized or that a different version of Qt is being detected by\n"
	printf "mistake (for example, this could happen if \$QTDIR is pointing to a Qt 3\n"
	printf "installation).  At least one of the following conditions must be satisfied:\n"
	printf "\n"
	printf " 1) --qtdir is set to the location of Qt\n"
	printf " 2) \$QTDIR is set to the location of Qt\n"
	printf " 3) QtCore is in the pkg-config database\n"
	printf " 4) qmake is in the \$PATH\n"
	printf "\n"
	printf "This script will use the first one it finds to be true, checked in the above\n"
	printf "order.  #3 and #4 are the recommended options.  #1 and #2 are mainly for\n"
	printf "overriding the system configuration.\n"
	printf "\n"
}

while [ $# -gt 0 ]; do
	optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
	case "$1" in
		--qtdir=*)
			EX_QTDIR=$optarg
			shift
			;;

		--static)
			QC_STATIC="Y"
			shift
			;;

		--release)
			QC_RELEASE="Y"
			shift
			;;

		--debug)
			QC_DEBUG="Y"
			shift
			;;

		--debug-and-release)
			QC_DEBUG_AND_RELEASE="Y"
			shift
			;;

		--no-separate-debug-info)
			QC_NO_SEPARATE_DEBUG_INFO="Y"
			shift
			;;

		--separate-debug-info)
			QC_SEPARATE_DEBUG_INFO="Y"
			shift
			;;

		--no-framework)
			QC_NO_FRAMEWORK="Y"
			shift
			;;

		--framework)
			QC_FRAMEWORK="Y"
			shift
			;;

		--universal)
			QC_UNIVERSAL="Y"
			shift
			;;

		--mac-sdk=*)
			QC_MAC_SDK=$optarg
			shift
			;;

		--disable-tests)
			QC_DISABLE_TESTS="Y"
			shift
			;;

		--with-qca=*)
			QC_WITH_QCA=$optarg
			shift
			;;

		--with-zlib-inc=*)
			QC_WITH_ZLIB_INC=$optarg
			shift
			;;

		--with-zlib-lib=*)
			QC_WITH_ZLIB_LIB=$optarg
			shift
			;;

		--verbose)
			QC_VERBOSE="Y"
			shift
			;;
		--help) show_usage; exit ;;
		*) show_usage; exit ;;
	esac
done


echo "Configuring Iris ..."

if [ "$QC_VERBOSE" = "Y" ]; then
echo
echo EX_QTDIR=$EX_QTDIR
echo QC_STATIC=$QC_STATIC
echo QC_RELEASE=$QC_RELEASE
echo QC_DEBUG=$QC_DEBUG
echo QC_DEBUG_AND_RELEASE=$QC_DEBUG_AND_RELEASE
echo QC_NO_SEPARATE_DEBUG_INFO=$QC_NO_SEPARATE_DEBUG_INFO
echo QC_SEPARATE_DEBUG_INFO=$QC_SEPARATE_DEBUG_INFO
echo QC_NO_FRAMEWORK=$QC_NO_FRAMEWORK
echo QC_FRAMEWORK=$QC_FRAMEWORK
echo QC_UNIVERSAL=$QC_UNIVERSAL
echo QC_MAC_SDK=$QC_MAC_SDK
echo QC_DISABLE_TESTS=$QC_DISABLE_TESTS
echo QC_WITH_QCA=$QC_WITH_QCA
echo QC_WITH_ZLIB_INC=$QC_WITH_ZLIB_INC
echo QC_WITH_ZLIB_LIB=$QC_WITH_ZLIB_LIB
echo
fi

printf "Verifying Qt 4 build environment ... "

# run qmake -v and check version
qmake_check_v4() {
	if [ -x "$1" ]; then
		if echo `$1 -v 2>&1` | grep "Qt version 4\." >/dev/null 2>&1; then
			return 0
		elif [ "$QC_VERBOSE" = "Y" ]; then
			echo "Warning: $1 not for Qt 4"
		fi
	fi
	return 1
}

if [ "$QC_VERBOSE" = "Y" ]; then
	echo
fi

qm=""
names="qmake-qt4 qmake4 qmake"

# qt4 check: --qtdir
if [ -z "$qm" ] && [ ! -z "$EX_QTDIR" ]; then
	for n in $names; do
		qstr=$EX_QTDIR/bin/$n
		if qmake_check_v4 "$qstr"; then
			qm=$qstr
			break;
		fi
	done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
	echo "Warning: qmake not found via --qtdir"
fi

# qt4 check: QTDIR
if [ -z "$qm" ] && [ ! -z "$QTDIR" ]; then
	for n in $names; do
		qstr=$QTDIR/bin/$n
		if qmake_check_v4 "$qstr"; then
			qm=$qstr
			break;
		fi
	done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
	echo "Warning: qmake not found via \$QTDIR"
fi

# qt4 check: pkg-config
if [ -z "$qm" ]; then
	str=`pkg-config QtCore --variable=exec_prefix 2>/dev/null`
	if [ ! -z "$str" ]; then
		for n in $names; do
			qstr=$str/bin/$n
			if qmake_check_v4 "$qstr"; then
				qm=$qstr
				break;
			fi
		done
	fi
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
	echo "Warning: qmake not found via pkg-config"
fi

# qt4 check: PATH
if [ -z "$qm" ]; then
	for n in $names; do
		qstr=`$WHICH $n 2>/dev/null`
		if qmake_check_v4 "$qstr"; then
			qm=$qstr
			break;
		fi
	done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
	echo "Warning: qmake not found via \$PATH"
fi

if [ -z "$qm" ]; then
	if [ "$QC_VERBOSE" = "Y" ]; then
		echo " -> fail"
	else
		echo "fail"
	fi
	printf "\n"
	printf "Reason: Unable to find the 'qmake' tool for Qt 4.\n"
	printf "\n"
	show_qt_info
	exit 1;
fi
if [ "$QC_VERBOSE" = "Y" ]; then
	echo qmake found in $qm
fi

# try to determine the active makespec
defmakespec=$QMAKESPEC
if [ -z "$defmakespec" ]; then
	if $WHICH readlink >/dev/null 2>&1; then
		READLINK=`$WHICH readlink`
	fi
	if [ ! -z "$READLINK" ]; then
		qt_mkspecsdir=`$qm -query QT_INSTALL_DATA`/mkspecs
		if [ -d "$qt_mkspecsdir" ] && [ -h "$qt_mkspecsdir/default" ]; then
			defmakespec=`$READLINK $qt_mkspecsdir/default`
		fi
	fi
fi

if [ "$QC_VERBOSE" = "Y" ]; then
	echo makespec is $defmakespec
fi

qm_spec=""
# if the makespec is macx-xcode, force macx-g++
if [ "$defmakespec" = "macx-xcode" ]; then
	qm_spec=macx-g++
	QMAKESPEC=$qm_spec
	export QMAKESPEC
	if [ "$QC_VERBOSE" = "Y" ]; then
		echo overriding makespec to $qm_spec
	fi
fi

gen_files() {
cat >$1/modules.cpp <<EOT
#line 1 "qt42.qcm"
/*
-----BEGIN QCMOD-----
name: Qt >= 4.2
-----END QCMOD-----
*/
class qc_qt42 : public ConfObj
{
public:
	qc_qt42(Conf *c) : ConfObj(c) {}
	QString name() const { return "Qt >= 4.2"; }
	QString shortname() const { return "qt42"; }
	bool exec()
	{
		conf->debug(QString("QT_VERSION = 0x%1").arg(QString::number(QT_VERSION, 16)));
		if(QT_VERSION >= 0x040200)
			return true;
		else
			return false;
	}
};
#line 1 "buildmode.qcm"
/*
-----BEGIN QCMOD-----
name: buildmode
section: project
arg: release,Build with debugging turned off (default).
arg: debug,Build with debugging turned on.
arg: debug-and-release,Build two versions, with and without debugging turned on (mac only).
arg: no-separate-debug-info,Do not store debug information in a separate file (default for mac).
arg: separate-debug-info,Strip debug information into a separate .debug file (default for non-mac).
arg: no-framework,Do not build as a Mac framework.
arg: framework,Build as a Mac framework (default).
-----END QCMOD-----
*/

#define QC_BUILDMODE
bool qc_buildmode_release = false;
bool qc_buildmode_debug = false;
bool qc_buildmode_framework = false;
bool qc_buildmode_separate_debug_info = false;

class qc_buildmode : public ConfObj
{
public:
	qc_buildmode(Conf *c) : ConfObj(c) {}
	QString name() const { return "buildmode"; }
	QString shortname() const { return "buildmode"; }

	// no output
	QString checkString() const { return QString(); }

	bool exec()
	{
		// first, parse out the options
		bool opt_release = false;
		bool opt_debug = false;
		bool opt_debug_and_release = false;
		bool opt_no_framework = false;
		bool opt_framework = false;
		bool opt_no_separate_debug_info = false;
		bool opt_separate_debug_info = false;

		if(conf->getenv("QC_RELEASE") == "Y")
			opt_release = true;
		if(conf->getenv("QC_DEBUG") == "Y")
			opt_debug = true;
		if(conf->getenv("QC_DEBUG_AND_RELEASE") == "Y")
			opt_debug_and_release = true;
		if(conf->getenv("QC_NO_FRAMEWORK") == "Y")
			opt_no_framework = true;
		if(conf->getenv("QC_FRAMEWORK") == "Y")
			opt_framework = true;
		if(conf->getenv("QC_NO_SEPARATE_DEBUG_INFO") == "Y")
			opt_no_separate_debug_info = true;
		if(conf->getenv("QC_SEPARATE_DEBUG_INFO") == "Y")
			opt_separate_debug_info = true;

		bool staticmode = false;
		if(conf->getenv("QC_STATIC") == "Y")
			staticmode = true;

#ifndef Q_OS_MAC
		if(opt_debug_and_release)
		{
			printf("\nError: The --debug-and-release option is for mac only.\n");
			exit(1);
		}

		if(opt_framework)
		{
			printf("\nError: The --framework option is for mac only.\n");
			exit(1);
		}
#endif

		if(opt_framework && opt_debug)
		{
			printf("\nError: Cannot use both --framework and --debug.\n");
			exit(1);
		}

		// sanity check exclusive options
		int x;

		// build mode
		x = 0;
		if(opt_release)
			++x;
		if(opt_debug)
			++x;
		if(opt_debug_and_release)
			++x;
		if(x > 1)
		{
			printf("\nError: Use only one of --release, --debug, or --debug-and-release.\n");
			exit(1);
		}

		// framework
		if(opt_framework && staticmode)
		{
			printf("\nError: Cannot use both --framework and --static.\n");
			exit(1);
		}

		x = 0;
		if(opt_no_framework)
			++x;
		if(opt_framework)
			++x;
		if(x > 1)
		{
			printf("\nError: Use only one of --framework or --no-framework.\n");
			exit(1);
		}

		// debug info
		x = 0;
		if(opt_no_separate_debug_info)
			++x;
		if(opt_separate_debug_info)
			++x;
		if(x > 1)
		{
			printf("\nError: Use only one of --separate-debug-info or --no-separate-debug-info\n");
			exit(1);
		}

		// now process the options

		if(opt_release)
			qc_buildmode_release = true;
		else if(opt_debug)
			qc_buildmode_debug = true;
		else if(opt_debug_and_release)
		{
			qc_buildmode_release = true;
			qc_buildmode_debug = true;
		}
		else // default
			qc_buildmode_release = true;

		if(opt_framework)
			qc_buildmode_framework = true;
		else if(opt_no_framework)
		{
			// nothing to do
		}
		else // default
		{
			if(!staticmode && !opt_debug)
				qc_buildmode_framework = true;
		}

		if(opt_separate_debug_info)
			qc_buildmode_separate_debug_info = true;
		else if(opt_no_separate_debug_info)
		{
			// nothing to do
		}
		else // default
		{
#ifndef Q_OS_MAC
			qc_buildmode_separate_debug_info = true;
#endif
		}

		// make the string
		QStringList opts;
		QString other;

		if(qc_buildmode_release && qc_buildmode_debug)
		{
			opts += "debug_and_release";
			opts += "build_all";
		}
		else if(qc_buildmode_release)
			opts += "release";
		else // qc_buildmode_debug
			opts += "debug";

#ifdef Q_OS_MAC
		if(qc_buildmode_framework)
			opts += "lib_bundle";
#endif

		if(qc_buildmode_separate_debug_info)
		{
			opts += "separate_debug_info";
			other += "QMAKE_CFLAGS += -g\n";
			other += "QMAKE_CXXFLAGS += -g\n";
		}

		QString str = QString("CONFIG += ") + opts.join(" ") + '\n';
		conf->addExtra(str);

		if(!other.isEmpty())
			conf->addExtra(other);

		return true;
	}
};
#line 1 "universal.qcm"
/*
-----BEGIN QCMOD-----
name: Mac universal binary support
section: project
arg: universal,Build with Mac universal binary support.
arg: mac-sdk=[path],Path to Mac universal SDK (PPC host only).
-----END QCMOD-----
*/

#define QC_UNIVERSAL
bool qc_universal_enabled = false;
QString qc_universal_sdk;

//----------------------------------------------------------------------------
// qc_universal
//----------------------------------------------------------------------------
class qc_universal : public ConfObj
{
public:
	qc_universal(Conf *c) : ConfObj(c) {}
	QString name() const { return "Mac universal binary support"; }
	QString shortname() const { return "universal"; }
	QString checkString() const { return QString(); }

	bool exec()
	{
#ifdef Q_OS_MAC
		if(qc_getenv("QC_UNIVERSAL") == "Y")
		{
			qc_universal_enabled = true;

			QString str =
			"contains(QT_CONFIG,x86):contains(QT_CONFIG,ppc) {\n"
			"	CONFIG += x86 ppc\n"
			"}\n";

			QString sdk = qc_getenv("QC_MAC_SDK");
			if(!sdk.isEmpty())
			{
				str += QString("QMAKE_MAC_SDK = %1\n").arg(sdk);
				qc_universal_sdk = sdk;
			}

			conf->addExtra(str);
		}
#endif
		return true;
	}
};
#line 1 "qca.qcm"
/*
-----BEGIN QCMOD-----
name: QCA >= 2.0
arg: with-qca=[path],Specify path to QCA tree, mainly for building against an uninstalled QCA.
-----END QCMOD-----
*/

// based on crypto.prf. any changes made to that file need to be tracked here.
static QString internal_crypto_prf(const QString &incdir, const QString &libdir)
{
	QString out = QString(
"QCA_INCDIR = %1\n"
"QCA_LIBDIR = %2\n"
"\n"
"CONFIG *= qt\n"
"\n"
"LINKAGE =\n"
"\n"
"# on mac, if qca was built as a framework, link against it\n"
"mac: {\n"
"	framework_dir = \$\$QCA_LIBDIR\n"
"	exists(\$\$framework_dir/qca.framework) {\n"
"		#QMAKE_FRAMEWORKPATH *= \$\$framework_dir\n"
"		LIBS += -F\$\$framework_dir\n"
"		INCLUDEPATH += \$\$framework_dir/qca.framework/Headers\n"
"		LINKAGE = -framework qca\n"
"	}\n"
"}\n"
"\n"
"# else, link normally\n"
"isEmpty(LINKAGE) {\n"
"	INCLUDEPATH += \$\$QCA_INCDIR/QtCrypto\n"
"	LIBS += -L\$\$QCA_LIBDIR\n"
"	LINKAGE = -lqca\n"
"	CONFIG(debug, debug|release) {\n"
"		windows:LINKAGE = -lqcad\n"
"		mac:LINKAGE = -lqca_debug\n"
"	}\n"
"}\n"
"\n"
"LIBS += \$\$LINKAGE\n"
	).arg(incdir, libdir);
	return out;
}

#define QC_QCA
QString qc_qca_procode;

//----------------------------------------------------------------------------
// qc_qca
//----------------------------------------------------------------------------
class qc_qca : public ConfObj
{
public:
	qc_qca(Conf *c) : ConfObj(c) {}
	QString name() const { return "QCA >= 2.0"; }
	QString shortname() const { return "qca"; }
	bool exec()
	{
		// get the build mode
#ifdef QC_BUILDMODE
		bool release = qc_buildmode_release;
		bool debug = qc_buildmode_debug;
#else
		// else, default to just release mode
		bool release = true;
		bool debug = false;
#endif

		// test for "crypto" feature and check qca version number
		QString qca_prefix, qca_incdir, qca_libdir, qca_crypto_prf;
		qca_prefix = conf->getenv("QC_WITH_QCA");

		QString proextra;
		if(!qca_prefix.isEmpty()) {
			qca_incdir = qca_prefix + "/include";
			qca_libdir = qca_prefix + "/lib";
			qca_crypto_prf = internal_crypto_prf(qca_incdir, qca_libdir);
			proextra =
			"CONFIG += qt\n"
			"QT -= gui\n";
			proextra += qca_crypto_prf;
		} else {
			proextra =
			"CONFIG += qt crypto\n"
			"QT -= gui\n";
		}

		QString str =
		"#include <QtCrypto>\n"
		"\n"
		"int main()\n"
		"{\n"
		"	unsigned long x = QCA_VERSION;\n"
		"	if(x >= 0x020000 && x < 0x030000) return 0; else return 1;\n"
		"}\n";

		if(release)
		{
			int ret;
			if(!conf->doCompileAndLink(str, QStringList(), QString(), proextra + "CONFIG += release\n", &ret))
				return false;
			if(ret != 0)
				return false;
		}

		if(debug)
		{
			int ret;
			if(!conf->doCompileAndLink(str, QStringList(), QString(), proextra + "CONFIG += debug\n", &ret))
				return false;
			if(ret != 0)
				return false;
		}

		if(!qca_prefix.isEmpty())
			str = qca_crypto_prf;
		else
			str = "CONFIG += crypto\n";

		qc_qca_procode = str;
		conf->addExtra(str);

		return true;
	}
};
#line 1 "zlib.qcm"
/*
-----BEGIN QCMOD-----
name: zlib
arg: with-zlib-inc=[path],Path to zlib include files
arg: with-zlib-lib=[path],Path to zlib library files
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_zlib
//----------------------------------------------------------------------------
class qc_zlib : public ConfObj
{
public:
	qc_zlib(Conf *c) : ConfObj(c) {}
	QString name() const { return "zlib"; }
	QString shortname() const { return "zlib"; }
	bool exec()
	{
		QString inc, lib;
		QString s;

		s = conf->getenv("QC_WITH_ZLIB_INC");
		if(!s.isEmpty()) {
			if(!conf->checkHeader(s, "zlib.h"))
				return false;
			inc = s;
		}
		else {
			if(!conf->findHeader("zlib.h", QStringList(), &s))
				return false;
			inc = s;
		}

		s = conf->getenv("QC_WITH_ZLIB_LIB");
		if(!s.isEmpty()) {
			if(!conf->checkLibrary(s, "z"))
				return false;
			lib = s;
		}
		else {
			if(!conf->findLibrary("z", &s))
				return false;
			lib = s;
		}

		if(!inc.isEmpty())
			conf->addIncludePath(inc);
		if(!lib.isEmpty())
			conf->addLib(QString("-L") + s);
		conf->addLib("-lz");

		return true;
	}
};
#line 1 "extra.qcm"
/*
-----BEGIN QCMOD-----
name: extra
section: project
arg: disable-tests,Don't build examples and unittests.
-----END QCMOD-----
*/

class qc_extra : public ConfObj
{
public:
	qc_extra(Conf *c) : ConfObj(c) {}
	QString name() const { return "extra"; }
	QString shortname() const { return "extra"; }

	// no output
	QString checkString() const { return QString(); }

	bool exec()
	{
		QString str;
		QFile f;

		if(conf->getenv("QC_DISABLE_TESTS") == "Y")
			str += "CONFIG += no_tests\n";

		conf->addExtra(str);

		bool release = true;
		bool debug = false;
		bool debug_info = false;
		bool universal = false;
		QString sdk;

#ifdef QC_BUILDMODE
		release = qc_buildmode_release;
		debug = qc_buildmode_debug;
		debug_info = qc_buildmode_separate_debug_info;
#endif

#ifdef QC_UNIVERSAL
		universal = qc_universal_enabled;
		sdk = qc_universal_sdk;
#endif

		// write confapp_unix.pri
		str = QString();
                QString var = conf->getenv("BINDIR");
                if(!var.isEmpty())
			str += QString("BINDIR = %1\n").arg(var);
		if(debug) // debug or debug-and-release
			str += QString("CONFIG += debug\n");
		else // release
			str += QString("CONFIG += release\n");
		if(debug_info)
		{
			str += QString("CONFIG += separate_debug_info\n");
			str += "QMAKE_CFLAGS += -g\n";
			str += "QMAKE_CXXFLAGS += -g\n";
		}
		if(universal)
		{
			str +=
			"contains(QT_CONFIG,x86):contains(QT_CONFIG,ppc) {\n"
			"	CONFIG += x86 ppc\n"
			"}\n";

			if(!sdk.isEmpty())
				str += QString("QMAKE_MAC_SDK = %1\n").arg(sdk);
		}
#ifdef QC_QCA
		if(!qc_qca_procode.isEmpty())
			str += qc_qca_procode;
#endif
		f.setFileName("confapp_unix.pri");
		if(f.open(QFile::WriteOnly | QFile::Truncate))
			f.write(str.toLatin1());
		f.close();

		return true;
	}

	QString makeEscapedDefine(const QString &var, const QString &val)
	{
		QString str = QString(
		"DEFINES += %1=\\\\\\\\\\\\\\"%2\\\\\\\\\\\\\\"\n"
		).arg(var).arg(val);
		return str;
	}
};

EOT
cat >$1/modules_new.cpp <<EOT
    o = new qc_qt42(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_buildmode(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_universal(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_qca(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_zlib(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_extra(conf);
    o->required = true;
    o->disabled = false;

EOT
cat >$1/conf4.h <<EOT
/*
Copyright (C) 2004-2008  Justin Karneges

This file is free software; unlimited permission is given to copy and/or
distribute it, with or without modifications, as long as this notice is
preserved.
*/

#ifndef QC_CONF4_H
#define QC_CONF4_H

#include <QtCore>

class Conf;

enum VersionMode { VersionMin, VersionExact, VersionMax, VersionAny };

// ConfObj
//
// Subclass ConfObj to create a new configuration module.
class ConfObj
{
public:
	Conf *conf;
	bool required;
	bool disabled;
	bool success;

	ConfObj(Conf *c);
	virtual ~ConfObj();

	// long or descriptive name of what is being checked/performed
	// example: "KDE >= 3.3"
	virtual QString name() const = 0;

	// short name
	// example: "kde"
	virtual QString shortname() const = 0;

	// string to display during check
	// default: "Checking for [name] ..."
	virtual QString checkString() const;

	// string to display after check
	// default: "yes" or "no", based on result of exec()
	virtual QString resultString() const;

	// this is where the checking code goes
	virtual bool exec() = 0;
};

// Conf
//
// Interact with this class from your ConfObj to perform detection
// operations and to output configuration parameters.
class Conf
{
public:
	bool debug_enabled;
	QString qmake_path;
	QString qmakespec;
	QString maketool;

	QString DEFINES;
	QString INCLUDEPATH;
	QString LIBS;
	QString extra;

	QList<ConfObj*> list;
	QMap<QString,QString> vars;

	Conf();
	~Conf();

	QString getenv(const QString &var);
	QString qvar(const QString &s);

	bool exec();

	void debug(const QString &s);

	QString expandIncludes(const QString &inc);
	QString expandLibs(const QString &lib);

	int doCommand(const QString &s, QByteArray *out = 0);
	int doCommand(const QString &prog, const QStringList &args, QByteArray *out = 0);

	bool doCompileAndLink(const QString &filedata, const QStringList &incs, const QString &libs, const QString &proextra, int *retcode = 0);
	bool checkHeader(const QString &path, const QString &h);
	bool findHeader(const QString &h, const QStringList &ext, QString *inc);
	bool checkLibrary(const QString &path, const QString &name);
	bool findLibrary(const QString &name, QString *lib);
	QString findProgram(const QString &prog);
	bool findSimpleLibrary(const QString &incvar, const QString &libvar, const QString &incname, const QString &libname, QString *incpath, QString *libs);
	bool findFooConfig(const QString &path, QString *version, QStringList *incs, QString *libs, QString *otherflags);
	bool findPkgConfig(const QString &name, VersionMode mode, const QString &req_version, QString *version, QStringList *incs, QString *libs, QString *otherflags);

	void addDefine(const QString &str);
	void addLib(const QString &str);
	void addIncludePath(const QString &str);
	void addExtra(const QString &str);

private:
	bool first_debug;

	friend class ConfObj;
	void added(ConfObj *o);
};

#endif

EOT
cat >$1/conf4.cpp <<EOT
/*
Copyright (C) 2004-2008  Justin Karneges

This file is free software; unlimited permission is given to copy and/or
distribute it, with or without modifications, as long as this notice is
preserved.
*/

#include "conf4.h"

#include <stdio.h>
#include <stdlib.h>

class MocTestObject : public QObject
{
	Q_OBJECT
public:
	MocTestObject() {}
};

QString qc_getenv(const QString &var)
{
	char *p = ::getenv(var.toLatin1().data());
	if(!p)
		return QString();
	return QString(p);
}

QStringList qc_pathlist()
{
	QStringList list;
	QString path = qc_getenv("PATH");
	if(!path.isEmpty())
		list = path.split(':', QString::SkipEmptyParts);
	return list;
}

QString qc_findprogram(const QString &prog)
{
	QString out;
	QStringList list = qc_pathlist();
	for(int n = 0; n < list.count(); ++n)
	{
		QFileInfo fi(list[n] + '/' + prog);
		if(fi.exists() && fi.isExecutable())
		{
			out = fi.filePath();
			break;
		}
	}
	return out;
}

QString qc_findself(const QString &argv0)
{
	if(argv0.contains('/'))
		return argv0;
	else
		return qc_findprogram(argv0);
}

int qc_runcommand(const QString &command, QByteArray *out, bool showOutput)
{
	QString fullcmd = command;
	if(!showOutput)
		fullcmd += " 2>/dev/null";
	FILE *f = popen(fullcmd.toLatin1().data(), "r");
	if(!f)
		return -1;
	if(out)
		out->clear();
	while(1)
	{
		char c = (char)fgetc(f);
		if(feof(f))
			break;
		if(out)
			out->append(c);
		if(showOutput)
			fputc(c, stdout);
	}
	int ret = pclose(f);
	if(ret == -1)
		return -1;
	return ret;
}

int qc_runprogram(const QString &prog, const QStringList &args, QByteArray *out, bool showOutput)
{
	QString fullcmd = prog;
	QString argstr = args.join(" ");
	if(!argstr.isEmpty())
		fullcmd += QString(" ") + argstr;
	return qc_runcommand(fullcmd, out, showOutput);

	// TODO: use QProcess once it is fixed
	/*
	QProcess process;
	if(showOutput)
		process.setReadChannelMode(ForwardedChannels);
	process.start(prog, args);
	process.waitForFinished(-1);
	return process.exitCode();
	*/
}

bool qc_removedir(const QString &dirPath)
{
	QDir dir(dirPath);
	if(!dir.exists())
		return false;
	QStringList list = dir.entryList();
	foreach(QString s, list)
	{
		if(s == "." || s == "..")
			continue;
		QFileInfo fi(dir.filePath(s));
		if(fi.isDir())
		{
			if(!qc_removedir(fi.filePath()))
				return false;
		}
		else
		{
			if(!dir.remove(s))
				return false;
		}
	}
	QString dirName = dir.dirName();
	if(!dir.cdUp())
		return false;
	if(!dir.rmdir(dirName))
		return false;
	return true;
}

void qc_splitcflags(const QString &cflags, QStringList *incs, QStringList *otherflags)
{
	incs->clear();
	otherflags->clear();

	QStringList cflagsList = cflags.split(" ");
	for(int n = 0; n < cflagsList.count(); ++n)
	{
		QString str = cflagsList[n];
		if(str.startsWith("-I"))
		{
			// we want everything except the leading "-I"
			incs->append(str.remove(0, 2));
		}
		else
		{
			// we want whatever is left
			otherflags->append(str);
		}
	}
}

QString qc_escapeArg(const QString &str)
{
	QString out;
	for(int n = 0; n < (int)str.length(); ++n) {
		if(str[n] == '-')
			out += '_';
		else
			out += str[n];
	}
	return out;
}

//----------------------------------------------------------------------------
// ConfObj
//----------------------------------------------------------------------------
ConfObj::ConfObj(Conf *c)
{
	conf = c;
	conf->added(this);
	required = false;
	disabled = false;
	success = false;
}

ConfObj::~ConfObj()
{
}

QString ConfObj::checkString() const
{
	return QString("Checking for %1 ...").arg(name());
}

QString ConfObj::resultString() const
{
	if(success)
		return "yes";
	else
		return "no";
}

//----------------------------------------------------------------------------
// qc_internal_pkgconfig
//----------------------------------------------------------------------------
class qc_internal_pkgconfig : public ConfObj
{
public:
	QString pkgname, desc;
	VersionMode mode;
	QString req_ver;

        qc_internal_pkgconfig(Conf *c, const QString &_name, const QString &_desc, VersionMode _mode, const QString &_req_ver) : ConfObj(c)
	{
		pkgname = _name;
		desc = _desc;
		mode = _mode;
		req_ver = _req_ver;
	}

	QString name() const { return desc; }
	QString shortname() const { return pkgname; }

	bool exec()
	{
		QStringList incs;
		QString version, libs, other;
		if(!conf->findPkgConfig(pkgname, mode, req_ver, &version, &incs, &libs, &other))
			return false;

		for(int n = 0; n < incs.count(); ++n)
			conf->addIncludePath(incs[n]);
		if(!libs.isEmpty())
			conf->addLib(libs);
		//if(!other.isEmpty())
		//	conf->addExtra(QString("QMAKE_CFLAGS += %1\n").arg(other));
		return true;
	}
};

//----------------------------------------------------------------------------
// Conf
//----------------------------------------------------------------------------
Conf::Conf()
{
	// TODO: no more vars?
	//vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
	//vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
	//vars.insert("QMAKE_LIBS_X11",   new QString(X11_LIB));
	//vars.insert("QMAKE_CC", CC);

	debug_enabled = false;
}

Conf::~Conf()
{
	qDeleteAll(list);
}

void Conf::added(ConfObj *o)
{
	list.append(o);
}

QString Conf::getenv(const QString &var)
{
	return qc_getenv(var);
}

void Conf::debug(const QString &s)
{
	if(debug_enabled)
	{
		if(first_debug)
			printf("\n");
		first_debug = false;
		printf(" * %s\n", qPrintable(s));
	}
}

bool Conf::exec()
{
	for(int n = 0; n < list.count(); ++n)
	{
		ConfObj *o = list[n];

		// if this was a disabled-by-default option, check if it was enabled
		if(o->disabled)
		{
			QString v = QString("QC_ENABLE_") + qc_escapeArg(o->shortname());
			if(getenv(v) != "Y")
				continue;
		}
		// and the opposite?
		else
		{
			QString v = QString("QC_DISABLE_") + qc_escapeArg(o->shortname());
			if(getenv(v) == "Y")
				continue;
		}

		bool output = true;
		QString check = o->checkString();
		if(check.isEmpty())
			output = false;

		if(output)
		{
			printf("%s", check.toLatin1().data());
			fflush(stdout);
		}

		first_debug = true;
		bool ok = o->exec();
		o->success = ok;

		if(output)
		{
			QString result = o->resultString();
			if(!first_debug)
				printf(" -> %s\n", result.toLatin1().data());
			else
				printf(" %s\n", result.toLatin1().data());
		}

		if(!ok && o->required)
		{
			printf("\nError: need %s!\n", o->name().toLatin1().data());
			return false;
		}
	}
	return true;
}

QString Conf::qvar(const QString &s)
{
	return vars.value(s);
}

QString Conf::expandIncludes(const QString &inc)
{
	return QString("-I") + inc;
}

QString Conf::expandLibs(const QString &lib)
{
	return QString("-L") + lib;
}

int Conf::doCommand(const QString &s, QByteArray *out)
{
	debug(QString("[%1]").arg(s));
	int r = qc_runcommand(s, out, debug_enabled);
	debug(QString("returned: %1").arg(r));
	return r;
}

int Conf::doCommand(const QString &prog, const QStringList &args, QByteArray *out)
{
	QString fullcmd = prog;
	QString argstr = args.join(" ");
	if(!argstr.isEmpty())
		fullcmd += QString(" ") + argstr;
	debug(QString("[%1]").arg(fullcmd));
	int r = qc_runprogram(prog, args, out, debug_enabled);
	debug(QString("returned: %1").arg(r));
	return r;
}

bool Conf::doCompileAndLink(const QString &filedata, const QStringList &incs, const QString &libs, const QString &proextra, int *retcode)
{
	QDir tmp(".qconftemp");
	if(!tmp.mkdir("atest"))
	{
		debug("unable to create atest dir");
		return false;
	}
	QDir dir(tmp.filePath("atest"));
	if(!dir.exists())
	{
		debug("atest dir does not exist");
		return false;
	}

	QString fname = dir.filePath("atest.cpp");
	QString out = "atest";
	QFile f(fname);
	if(!f.open(QFile::WriteOnly | QFile::Truncate))
	{
		debug("unable to open atest.cpp for writing");
		return false;
	}
	if(f.write(filedata.toLatin1()) == -1)
	{
		debug("error writing to atest.cpp");
		return false;
	}
	f.close();

	debug(QString("Wrote atest.cpp:\n%1").arg(filedata));

	QString pro = QString(
		"CONFIG  += console\n"
		"CONFIG  -= qt app_bundle\n"
		"SOURCES += atest.cpp\n");
	QString inc = incs.join(" ");
	if(!inc.isEmpty())
		pro += "INCLUDEPATH += " + inc + '\n';
	if(!libs.isEmpty())
		pro += "LIBS += " + libs + '\n';
	pro += proextra;

	fname = dir.filePath("atest.pro");
	f.setFileName(fname);
	if(!f.open(QFile::WriteOnly | QFile::Truncate))
	{
		debug("unable to open atest.pro for writing");
		return false;
	}
	if(f.write(pro.toLatin1()) == -1)
	{
		debug("error writing to atest.pro");
		return false;
	}
	f.close();

	debug(QString("Wrote atest.pro:\n%1").arg(pro));

	QString oldpath = QDir::currentPath();
	QDir::setCurrent(dir.path());

	bool ok = false;
	int r = doCommand(qmake_path, QStringList() << "atest.pro");
	if(r == 0)
	{
		r = doCommand(maketool, QStringList());
		if(r == 0)
		{
			ok = true;
			if(retcode)
				*retcode = doCommand(QString("./") + out, QStringList());
		}
		r = doCommand(maketool, QStringList() << "distclean");
		if(r != 0)
			debug("error during atest distclean");
	}

	QDir::setCurrent(oldpath);

	// cleanup
	//dir.remove("atest.pro");
	//dir.remove("atest.cpp");
	//tmp.rmdir("atest");

	// remove whole dir since distclean doesn't always work
	qc_removedir(tmp.filePath("atest"));

	if(!ok)
		return false;
	return true;
}

bool Conf::checkHeader(const QString &path, const QString &h)
{
	QFileInfo fi(path + '/' + h);
	if(fi.exists())
		return true;
	return false;
}

bool Conf::findHeader(const QString &h, const QStringList &ext, QString *inc)
{
	if(checkHeader("/usr/include", h))
	{
		*inc = "";
		return true;
	}
	QStringList dirs;
	dirs += "/usr/local/include";
	dirs += ext;
	for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it)
	{
		if(checkHeader(*it, h))
		{
			*inc = *it;
			return true;
		}
	}
	return false;
}

bool Conf::checkLibrary(const QString &path, const QString &name)
{
	QString str =
		//"#include <stdio.h>\n"
		"int main()\n"
		"{\n"
		//"    printf(\"library checker running\\\\n\");\n"
		"    return 0;\n"
		"}\n";

	QString libs;
	if(!path.isEmpty())
		libs += QString("-L") + path + ' ';
	libs += QString("-l") + name;
	if(!doCompileAndLink(str, QStringList(), libs, QString()))
		return false;
	return true;
}

bool Conf::findLibrary(const QString &name, QString *lib)
{
	if(checkLibrary("", name))
	{
		*lib = "";
		return true;
	}
	if(checkLibrary("/usr/local/lib", name))
	{
		*lib = "/usr/local/lib";
		return true;
	}
	return false;
}

QString Conf::findProgram(const QString &prog)
{
	return qc_findprogram(prog);
}

bool Conf::findSimpleLibrary(const QString &incvar, const QString &libvar, const QString &incname, const QString &libname, QString *incpath, QString *libs)
{
	QString inc, lib;
	QString s;

	s = getenv(incvar);
	if(!s.isEmpty()) {
		if(!checkHeader(s, incname))
			return false;
		inc = s;
	}
	else {
		if(!findHeader(incname, QStringList(), &s))
			return false;
		inc = s;
	}

	s = getenv(libvar);
	if(!s.isEmpty()) {
		if(!checkLibrary(s, libname))
			return false;
		lib = s;
	}
	else {
		if(!findLibrary(libname, &s))
			return false;
		lib = s;
	}

	QString lib_out;
	if(!lib.isEmpty())
		lib_out += QString("-L") + s;
	lib_out += QString("-l") + libname;

	*incpath = inc;
	*libs = lib_out;
	return true;
}

bool Conf::findFooConfig(const QString &path, QString *version, QStringList *incs, QString *libs, QString *otherflags)
{
	QStringList args;
	QByteArray out;
	int ret;

	args += "--version";
	ret = doCommand(path, args, &out);
	if(ret != 0)
		return false;

	QString version_out = QString::fromLatin1(out).trimmed();

	args.clear();
	args += "--libs";
	ret = doCommand(path, args, &out);
	if(ret != 0)
		return false;

	QString libs_out = QString::fromLatin1(out).trimmed();

	args.clear();
	args += "--cflags";
	ret = doCommand(path, args, &out);
	if(ret != 0)
		return false;

	QString cflags = QString::fromLatin1(out).trimmed();

	QStringList incs_out, otherflags_out;
	qc_splitcflags(cflags, &incs_out, &otherflags_out);

	*version = version_out;
	*incs = incs_out;
	*libs = libs_out;
	*otherflags = otherflags_out.join(" ");
	return true;
}

bool Conf::findPkgConfig(const QString &name, VersionMode mode, const QString &req_version, QString *version, QStringList *incs, QString *libs, QString *otherflags)
{
	QStringList args;
	QByteArray out;
	int ret;

	args += name;
	args += "--exists";
	ret = doCommand("pkg-config", args, &out);
	if(ret != 0)
		return false;

	if(mode != VersionAny)
	{
		args.clear();
		args += name;
		if(mode == VersionMin)
			args += QString("--atleast-version=%1").arg(req_version);
		else if(mode == VersionMax)
			args += QString("--max-version=%1").arg(req_version);
		else
			args += QString("--exact-version=%1").arg(req_version);
		ret = doCommand("pkg-config", args, &out);
		if(ret != 0)
			return false;
	}

	args.clear();
	args += name;
	args += "--modversion";
	ret = doCommand("pkg-config", args, &out);
	if(ret != 0)
		return false;

	QString version_out = QString::fromLatin1(out).trimmed();

	args.clear();
	args += name;
	args += "--libs";
	ret = doCommand("pkg-config", args, &out);
	if(ret != 0)
		return false;

	QString libs_out = QString::fromLatin1(out).trimmed();

	args.clear();
	args += name;
	args += "--cflags";
	ret = doCommand("pkg-config", args, &out);
	if(ret != 0)
		return false;

	QString cflags = QString::fromLatin1(out).trimmed();

	QStringList incs_out, otherflags_out;
	qc_splitcflags(cflags, &incs_out, &otherflags_out);

	*version = version_out;
	*incs = incs_out;
	*libs = libs_out;
	*otherflags = otherflags_out.join(" ");
	return true;
}

void Conf::addDefine(const QString &str)
{
	if(DEFINES.isEmpty())
		DEFINES = str;
	else
		DEFINES += QString(" ") + str;
	debug(QString("DEFINES += %1").arg(str));
}

void Conf::addLib(const QString &str)
{
	if(LIBS.isEmpty())
		LIBS = str;
	else
		LIBS += QString(" ") + str;
	debug(QString("LIBS += %1").arg(str));
}

void Conf::addIncludePath(const QString &str)
{
	if(INCLUDEPATH.isEmpty())
		INCLUDEPATH = str;
	else
		INCLUDEPATH += QString(" ") + str;
	debug(QString("INCLUDEPATH += %1").arg(str));
}

void Conf::addExtra(const QString &str)
{
	extra += str + '\n';
	debug(QString("extra += %1").arg(str));
}

//----------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------
#include "conf4.moc"

#ifdef HAVE_MODULES
# include"modules.cpp"
#endif

int main()
{
	Conf *conf = new Conf;
	ConfObj *o;
	o = 0;
#ifdef HAVE_MODULES
# include"modules_new.cpp"
#endif

	conf->debug_enabled = (qc_getenv("QC_VERBOSE") == "Y") ? true: false;
	if(conf->debug_enabled)
		printf(" -> ok\n");
	else
		printf("ok\n");

	QString confCommand = qc_getenv("QC_COMMAND");
	QString proName = qc_getenv("QC_PROFILE");
	conf->qmake_path = qc_getenv("QC_QMAKE");
	conf->qmakespec = qc_getenv("QC_QMAKESPEC");
	conf->maketool = qc_getenv("QC_MAKETOOL");

	if(conf->debug_enabled)
		printf("conf command: [%s]\n", qPrintable(confCommand));

	QString confPath = qc_findself(confCommand);
	if(confPath.isEmpty())
	{
		printf("Error: cannot find myself; rerun with an absolute path\n");
		return 1;
	}

	QString srcdir = QFileInfo(confPath).absolutePath();
	QString builddir = QDir::current().absolutePath();
	QString proPath = QDir(srcdir).filePath(proName);

	if(conf->debug_enabled)
	{
		printf("conf path:    [%s]\n", qPrintable(confPath));
		printf("srcdir:       [%s]\n", qPrintable(srcdir));
		printf("builddir:     [%s]\n", qPrintable(builddir));
		printf("profile:      [%s]\n", qPrintable(proPath));
		printf("qmake path:   [%s]\n", qPrintable(conf->qmake_path));
		printf("qmakespec:    [%s]\n", qPrintable(conf->qmakespec));
		printf("make tool:    [%s]\n", qPrintable(conf->maketool));
		printf("\n");
	}

	bool success = false;
	if(conf->exec())
	{
		QFile f("conf.pri");
		if(!f.open(QFile::WriteOnly | QFile::Truncate))
		{
			printf("Error writing %s\n", qPrintable(f.fileName()));
			return 1;
		}

		QString str;
		str += "# qconf\n\n";

		QString var;
		var = qc_getenv("PREFIX");
		if(!var.isEmpty())
			str += QString("PREFIX = %1\n").arg(var);
		var = qc_getenv("BINDIR");
		if(!var.isEmpty())
			str += QString("BINDIR = %1\n").arg(var);
		var = qc_getenv("INCDIR");
		if(!var.isEmpty())
			str += QString("INCDIR = %1\n").arg(var);
		var = qc_getenv("LIBDIR");
		if(!var.isEmpty())
			str += QString("LIBDIR = %1\n").arg(var);
		var = qc_getenv("DATADIR");
		if(!var.isEmpty())
			str += QString("DATADIR = %1\n").arg(var);
		str += '\n';

		if(qc_getenv("QC_STATIC") == "Y")
			str += "CONFIG += staticlib\n";

		// TODO: don't need this?
		//str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n';

		if(!conf->DEFINES.isEmpty())
			str += "DEFINES += " + conf->DEFINES + '\n';
		if(!conf->INCLUDEPATH.isEmpty())
			str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
		if(!conf->LIBS.isEmpty())
			str += "LIBS += " + conf->LIBS + '\n';
		if(!conf->extra.isEmpty())
			str += conf->extra;
		str += '\n';

		QByteArray cs = str.toLatin1();
		f.write(cs);
		f.close();
		success = true;
	}
	QString qmake_path = conf->qmake_path;
	QString qmakespec = conf->qmakespec;
	delete conf;

	if(!success)
		return 1;

	// run qmake on the project file
	QStringList args;
	if(!qmakespec.isEmpty())
	{
		args += "-spec";
		args += qmakespec;
	}
	args += proPath;
	int ret = qc_runprogram(qmake_path, args, 0, true);
	if(ret != 0)
		return 1;

	return 0;
}

EOT
cat >$1/conf4.pro <<EOT
CONFIG  += console
CONFIG  -= app_bundle
QT      -= gui
TARGET   = conf

HEADERS += conf4.h
SOURCES += conf4.cpp


DEFINES += HAVE_MODULES

EOT
}

export EX_QTDIR
export QC_STATIC
export QC_RELEASE
export QC_DEBUG
export QC_DEBUG_AND_RELEASE
export QC_NO_SEPARATE_DEBUG_INFO
export QC_SEPARATE_DEBUG_INFO
export QC_NO_FRAMEWORK
export QC_FRAMEWORK
export QC_UNIVERSAL
export QC_MAC_SDK
export QC_DISABLE_TESTS
export QC_WITH_QCA
export QC_WITH_ZLIB_INC
export QC_WITH_ZLIB_LIB
export QC_VERBOSE
rm -rf .qconftemp
(
	mkdir .qconftemp
	gen_files .qconftemp
	cd .qconftemp
	if [ ! -z "$qm_spec" ]; then
		$qm -spec $qm_spec conf4.pro >/dev/null
	else
		$qm conf4.pro >/dev/null
	fi
	$MAKE clean >/dev/null 2>&1
	$MAKE >../conf.log 2>&1
)

if [ "$?" != "0" ]; then
	rm -rf .qconftemp
	if [ "$QC_VERBOSE" = "Y" ]; then
		echo " -> fail"
	else
		echo "fail"
	fi
	printf "\n"
	printf "Reason: There was an error compiling 'conf'.  See conf.log for details.\n"
	printf "\n"
	show_qt_info
	if [ "$QC_VERBOSE" = "Y" ]; then
		echo "conf.log:"
		cat conf.log
	fi
	exit 1;
fi

QC_COMMAND=$0
export QC_COMMAND
QC_PROFILE=iris.pro
export QC_PROFILE
QC_QMAKE=$qm
export QC_QMAKE
QC_QMAKESPEC=$qm_spec
export QC_QMAKESPEC
QC_MAKETOOL=$MAKE
export QC_MAKETOOL
.qconftemp/conf
ret="$?"
if [ "$ret" = "1" ]; then
	rm -rf .qconftemp
	echo
	exit 1;
else
	if [ "$ret" != "0" ]; then
		rm -rf .qconftemp
		if [ "$QC_VERBOSE" = "Y" ]; then
			echo " -> fail"
		else
			echo "fail"
		fi
		echo
		echo "Reason: Unexpected error launching 'conf'"
		echo
		exit 1;
	fi
fi
rm -rf .qconftemp

echo
echo "Good, your configure finished.  Now run $MAKE."
echo