summaryrefslogtreecommitdiffstats
path: root/configure
blob: 3d672e59e87c11d9a9b8b205dce96574b519b680 (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
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
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
#!/bin/sh
#
#
# Configures to build the TQt library
#
# Copyright (C) 1999-2008 Trolltech ASA.  All rights reserved.
#


#-------------------------------------------------------------------------------
# script initialization
#-------------------------------------------------------------------------------

# the name of this script
relconf=`basename $0`
# the directory of this script is the "source tree"
relpath=`dirname $0`
relpath=`(cd $relpath; /bin/pwd)`
# the current directory is the "build tree" or "object tree"
outpath=`/bin/pwd`

# later cache the command line in config.status
OPT_CMDLINE=`echo $@ | sed "s,-v ,,g; s,-v$,,g"`

# initialize global variables
QMAKE_SWITCHES=
QMAKE_VARS=
QMAKE_CONFIG=

SUPPORTED=

#-------------------------------------------------------------------------------
# operating system detection
#-------------------------------------------------------------------------------

# need that throughout the script
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown


#-------------------------------------------------------------------------------
# window system detection
#-------------------------------------------------------------------------------

PLATFORM_X11=no
PLATFORM_MAC=no
PLATFORM_QNX=no

if [ -f $relpath/src/kernel/qapplication_mac.cpp ] && [ -d /System/Library/Frameworks/Carbon.framework ]; then
    # Qt/Mac
    # ~ the Carbon SDK exists
    # ~ src/kernel/qapplication_mac.cpp is present
    # ~ this is the internal edition and Qt/Mac sources exist
    PLATFORM_MAC=maybe
fi


#-------------------------------------------------------------------------------
# Free license only: no check for other licenses
#-------------------------------------------------------------------------------
[ "$PLATFORM_MAC" = "maybe" ] && PLATFORM_MAC=yes
Edition="free"
Licensee="Free"
Products="qt-free"

# modules depending on free license
MODULES="styles tools kernel widgets dialogs workspace inputmethod \
         network canvas table xml opengl sql"
CFG_MODULES_AVAILABLE=$MODULES
QMAKE_VARS="$QMAKE_VARS \"QT_PRODUCT=$Products\""
QMAKE_VARS="$QMAKE_VARS \"styles += windows motif mac platinum sgi cde motifplus\""
QMAKE_VARS="$QMAKE_VARS \"kbd-drivers += tty\" \"mouse-drivers += pc\""


#-------------------------------------------------------------------------------
# initalize variables
#-------------------------------------------------------------------------------

# TQTDIR may be set and point to an old or system-wide TQt installation
unset TQTDIR

# initalize internal variables
CFG_CONFIGURE_EXIT_ON_ERROR=yes
CFG_PROFILE=no
CFG_EXCEPTION_SUPPORT=unspecified
CFG_INCREMENTAL=auto
CFG_QCONFIG=full
CFG_DEBUG=no
CFG_SHARED=yes
CFG_GIF=no
CFG_THREAD=auto
CFG_SM=auto
CFG_XSHAPE=auto
CFG_XINERAMA=auto
CFG_BIG_CODECS=yes
CFG_ZLIB=yes
CFG_PNG=yes
CFG_LIBPNG=system
CFG_JPEG=auto
CFG_LIBJPEG=system
CFG_MNG=auto
CFG_LIBMNG=system
CFG_XCURSOR=auto
CFG_XRANDR=auto
CFG_XRENDER=auto
CFG_FREETYPE=auto
CFG_SQL_AVAILABLE=
CFG_SQL_AUTODETECTED=
CFG_STYLE_AVAILABLE=
#Keep this position for CFG_IM* to avoid patch rejection
CFG_IM=yes
CFG_IM_EXT=no
CFG_TABLET=auto
CFG_XKB=auto
CFG_NIS=auto
CFG_CUPS=auto
CFG_LARGEFILE=auto
CFG_NEWABI=no ### need to break ABI for full Large File support...
CFG_STL=auto
CFG_PRECOMPILE=no
CFG_IPV6=auto
CFG_NAS=no
CFG_USER_BUILD_KEY=
CFG_ACCESSIBILITY=auto
CFG_DLOPEN_OPENGL=no
CFG_ENDIAN=auto
CFG_GLIBMAINLOOP=no
CFG_LIBGLIBMAINLOOP=
D_FLAGS=
I_FLAGS=
L_FLAGS=
R_FLAGS=
l_FLAGS=
QCONFIG_FLAGS=
XPLATFORM=
PLATFORM=$QMAKESPEC
QMAKE_PROJECTS=
QMAKE_IGNORE_PROJECTS=
OPT_CONCURRENT=0
OPT_SHADOW=maybe
OPT_FAST=auto
OPT_VERBOSE=no
OPT_HELP=

# initalize variables used for installation
QT_INSTALL_PREFIX=
QT_INSTALL_DOCS=
QT_INSTALL_HEADERS=
QT_INSTALL_LIBS=
QT_INSTALL_BINS=
QT_INSTALL_PLUGINS=
QT_INSTALL_DATA=
QT_INSTALL_TRANSLATIONS=
QT_INSTALL_SYSCONF=
QT_INSTALL_SHARE=

#-------------------------------------------------------------------------------
# check SQL drivers and styles available in this package
#-------------------------------------------------------------------------------

CFG_SQL_AVAILABLE=`find $relpath/plugins/src/sqldrivers/* -prune -type d -exec basename {} \;`
# normalize whitespace
CFG_SQL_AVAILABLE=`echo $CFG_SQL_AVAILABLE`

CFG_STYLE_AVAILABLE=`find $relpath/plugins/src/styles/* -prune -type d -exec basename {} \;`
# normalize whitespace
CFG_STYLE_AVAILABLE=`echo $CFG_STYLE_AVAILABLE`

#-------------------------------------------------------------------------------
# parse command line arguments
#-------------------------------------------------------------------------------

# parse the arguments, setting things to "yes" or "no"
while [ "$#" -gt 0 ]; do
    CURRENT_OPT="$1"
    UNKNOWN_ARG=no
    case $1 in
    #Autoconf style options
    --enable-*)
	VAR=`echo $1 | sed "s,^--enable-\(.*\),\1,"`
	VAL=yes
	;;
    --disable-*)
	VAR=`echo $1 | sed "s,^--disable-\(.*\),\1,"`
	VAL=no
	;;
    --*=*)
	VAR=`echo $1 | sed "s,^--\(.*\)=.*,\1,"`
	VAL=`echo $1 | sed "s,^--.*=\(.*\),\1,"`
	;;
    --no-*)
	VAR=`echo $1 | sed "s,^--no-\(.*\),\1,"`
	VAL=no
	;;
    --*)
	VAR=`echo $1 | sed "s,^--\(.*\),\1,"`
	VAL=yes
	;;
    #Qt plugin options
    -no-*-*|-plugin-*-*|-qt-*-*)
	VAR=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	VAL=`echo $1 | sed "s,^-\([^-]*\).*,\1,"`
	;;
    #Qt style no options
    -no-*)
	VAR=`echo $1 | sed "s,^-no-\(.*\),\1,"`
	VAL=no
	;;
    #Qt style yes options
    -incremental|-profile|-shared|-static|-sm|-thread|-xinerama|-xshape|-tablet|-pch|-stl|-ipv6|-big-codecs|-xcursor|-xrandr|-xrender|-xft|-xkb|-nis|-cups|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-version-script|-dlopen-opengl|-glibmainloop)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	VAL=yes
	;;
    #Qt style options that pass an argument
    -prefix|-sysshare|-docdir|-headerdir|-plugindir|-datadir|-libdir|-bindir|-translationdir|-sysconfdir|-make|-nomake|-platform|-xplatform|-buildkey)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	shift
	VAL=$1
	;;
    #Qt style complex options in one command
    -enable-*|-disable-*)
	VAR=`echo $1 | sed "s,^-\([^-]*\)-.*,\1,"`
	VAL=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	;;
    #Qt Builtin/System style options
    -no-*|-system-*|-qt-*)
	VAR=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
	VAL=`echo $1 | sed "s,^-\([^-]*\)-.*,\1,"`
	;;
    #Options that cannot be generalized
    -k|-continue)
	VAR=fatal_error
	VAL=no
	;;
    #Qt style yes options for immodule
    #Keep this place to avoid patch rejection
    -inputmethod|-inputmethod-ext)
	VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
	VAL=yes
	;;
    -*-endian)
	VAR=endian
	VAL=`echo $1 | sed "s,^-\(.*\)-.*,\1,"`
	;;
    -j?*)
	VAR="concurrent"
	VAL="`echo $1 | sed 's,-j,,'`"
	;;
    -D?*|-D)
	VAR="define"
	if [ "$1" = "-D" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-D,,'`
        fi
	;;
    -I?*|-I)
	VAR="ipath"
	if [ "$1" = "-I" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-I,,'`
        fi
	;;
    -L?*|-L)
	VAR="lpath"
	if [ "$1" = "-L" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-L,,'`
        fi
	;;
    -R?*|-R)
	VAR="rpath"
	if [ "$1" = "-R" ]; then
	    shift
	    VAL="$1"
	else
	    VAL=`echo $1 | sed 's,-R,,'`
        fi
	;;
    -l?*)
	VAR="link"
	VAL=`echo $1 | sed 's,-l,,'`
	;;
    *)
	UNKNOWN_ARG=yes
	;;
    esac
    if [ "$UNKNOWN_ARG" = "yes" ]; then
	echo "$1: unknown argument"
	OPT_HELP=yes
	ERROR=yes
	shift
	continue
     fi
    shift

    UNKNOWN_OPT=no
    case $VAR in
    accessibility)
       	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_ACCESSIBILITY="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    prefix)
	QT_INSTALL_PREFIX="$VAL"
	;;
    docdir)
	QT_INSTALL_DOCS="$VAL"
	;;
    headerdir)
	QT_INSTALL_HEADERS="$VAL"
	;;
    plugindir)
	QT_INSTALL_PLUGINS="$VAL"
	;;
    datadir)
	QT_INSTALL_DATA="$VAL"
	;;
    libdir)
	QT_INSTALL_LIBS="$VAL"
	;;
    translationdir)
	QT_INSTALL_TRANSLATIONS="$VAL"
	;;
    sysconfdir)
	QT_INSTALL_SYSCONF="$VAL"
	;;
    sysshare)
	QT_INSTALL_SHARE="$VAL"
	;;
    qconfig)
	CFG_QCONFIG="$VAL"
	;;
    bindir)
	QT_INSTALL_BINS="$VAL"
	;;
    buildkey)
	CFG_USER_BUILD_KEY="$VAL"
	;;
    endian)
        if [ "$VAL" = "little" ]; then
            CFG_ENDIAN="TQ_LITTLE_ENDIAN"
        elif [ "$VAL" = "big" ]; then
	    CFG_ENDIAN="TQ_BIG_ENDIAN"
        else
	    UNKNOWN_OPT=yes
	fi
        ;;
    nomake)
	QMAKE_IGNORE_PROJECTS="$QMAKE_IGNORE_PROJECTS $VAL"
	;;
    make)
	if [ -f $relpath/$VAL ]; then
	    QMAKE_PROJECTS="$QMAKE_PROJECTS $relpath/$VAL"
	else
	    if [ -d $relpath/$VAL ]; then
		QMAKE_PROJECTS="$QMAKE_PROJECTS `find $relpath/$VAL -name '*.pro' -print`"
	    else
		QMAKE_PROJECTS="$QMAKE_PROJECTS `find $relpath/. -name '*.pro' -print`"
	    fi
	fi
	;;
    x11)
        if [ "$Edition" = "troll" ] && [ "$VAL" = "yes" ]; then
	    if [ "$PLATFORM_MAC" = "yes" ]; then
		PLATFORM_MAC=no
	    fi
	    PLATFORM_X11=yes
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    profile)
	if [ "$VAL" = "yes" ]; then
	    CFG_PROFILE=yes
	    QMAKE_VARS="$QMAKE_VARS QMAKE_CFLAGS+=-pg QMAKE_CXXFLAGS+=-pg"
	    QMAKE_VARS="$QMAKE_VARS QMAKE_LFLAGS+=-pg"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    exceptions|g++-exceptions)
	if [ "$VAL" = "no" ]; then
	    CFG_EXCEPTION_SUPPORT=no
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    version-script)
	if [ "$VAL" = "yes" ]; then
	    QMAKE_CONFIG="$QMAKE_CONFIG version_script"
	fi
	;;
    platform)
	PLATFORM="$VAL"
	# keep compatibility with old platform names
	case $PLATFORM in
	aix-64)
	    PLATFORM=aix-xlc-64
	    ;;
	hpux-o64)
	    PLATFORM=hpux-acc-o64
	    ;;
	hpux-n64)
	    PLATFORM=hpux-acc-64
	    ;;
	hpux-acc-n64)
	    PLATFORM=hpux-acc-64
	    ;;
	irix-o32)
	    PLATFORM=irix-cc-o32
	    ;;
	irix-n32)
	    PLATFORM=irix-cc
	    ;;
	irix-64)
	    PLATFORM=irix-cc-64
	    ;;
	irix-cc-n64)
	    PLATFORM=irix-cc-64
	    ;;
	reliant-64)
	    PLATFORM=reliant-cds-64
	    ;;
	solaris-64)
	    PLATFORM=solaris-cc-64
	    ;;
	solaris-64)
	    PLATFORM=solaris-cc-64
	    ;;
	openunix-cc)
	    PLATFORM=unixware-cc
	    ;;
	openunix-g++)
	    PLATFORM=unixware-g++
	    ;;
	unixware7-cc)
	    PLATFORM=unixware-cc
	    ;;
	unixware7-g++)
	    PLATFORM=unixware-g++
	    ;;
	esac
	;;
    xplatform)
	XPLATFORM="$VAL"
	;;
    release)
	if [ "$VAL" = "yes" ]; then
	    CFG_DEBUG=no
	elif [ "$VAL" = "no" ]; then
	    CFG_DEBUG=yes
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    debug)
	CFG_DEBUG="$VAL"
	;;
    static)
	if [ "$VAL" = "yes" ]; then
	    CFG_SHARED=no
	elif [ "$VAL" = "no" ]; then
	    CFG_SHARED=yes
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    incremental)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_INCREMENTAL="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    fatal_error)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_CONFIGURE_EXIT_ON_ERROR="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    shared)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_SHARED="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    gif)
	[ "$VAL" = "qt" ] && VAL=yes
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_GIF="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi
	;;
    sm)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_SM="$VAL"
	else
	    UNKNOWN_OPT=yes
        fi

	;;
    thread)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_THREAD="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xinerama)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XINERAMA="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xshape)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XSHAPE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    tablet)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_TABLET="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    stl)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_STL="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    pch)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_PRECOMPILE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    ipv6)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_IPV6="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    zlib)
	[ "$VAL" = "qt" ] && VAL=yes
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_ZLIB="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	[ "$VAL" = "no" ] && CFG_LIBPNG=no
	;;
    libpng)
	[ "$VAL" = "yes" ] && VAL=qt
	if [ "$VAL" = "no " ]; then
	    echo "-no-png is left for compatibility, in the future please use -no-imgfmt-png"
	    CFG_PNG=no
	fi
	if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_LIBPNG="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    libmng)
	[ "$VAL" = "yes" ] && VAL=qt
	if [ "$VAL" = "no " ]; then
	    echo "-no-mng is left for compatibility, in the future please use -no-imgfmt-mng"
	    CFG_MNG=no
	fi
	if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_LIBMNG="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    libjpeg|jpeg)
	[ "$VAL" = "yes" ] && VAL=qt
	if [ "$VAR" = "jpeg" ]; then
	    echo "-${VAL}-jpeg is left for compatibility, in the future please use -${VAL}-libjpeg"
	fi
	if [ "$VAL" = "qt" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
	    CFG_LIBJPEG="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	if [ "$VAL" = "no " ]; then
	    echo "-no-jpeg is left for compatibility, in the future please use -no-imgfmt-jpeg"
	    CFG_JPEG=no
	fi
	;;
    nas-sound)
	if [ "$VAL" = "system" ] || [ "$VAL" = "no" ]; then
	    CFG_NAS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    big-codecs)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_BIG_CODECS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xcursor)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XCURSOR="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xrandr)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XRANDR="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xrender)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XRENDER="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xft)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_FREETYPE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    xkb)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_XKB="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    cups)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_CUPS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    glibmainloop)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_GLIBMAINLOOP="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    nis)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_NIS="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    largefile)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_LARGEFILE="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    newabi)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_NEWABI="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    enable) #left for commandline compatibility, not documented
	MODULE="$VAL"
	if [ -n $MODULE -a -d "$relpath/src/$MODULE" ]; then
	    if echo "${MODULES}" | grep $MODULE >/dev/null 2>&1; then
		MODULES="$MODULES $MODULE"
	    fi
	fi
	;;
    disable)
	MODULE="$VAL"
	if [ -d "$relpath/src/$MODULE" ]; then
	    MODULES=`echo $MODULES | sed -e "s/$MODULE//"`
	else
	    echo "Unknown module disabled: $MODULE"
	fi
	;;
    h|help)
	if [ "$VAL" = "yes" ]; then
	    OPT_HELP="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    imgfmt-*|style-*|sql-*|kbd-*|mouse-*)
	# if TQt style options were used, $VAL can be "no", "qt", or "plugin"
	# if autoconf style options were used, $VAL can be "yes" or "no"
	[ "$VAL" = "yes" ] && VAL=qt
	# now $VAL should be "no", "qt", or "plugin"... double-check
	if [ "$VAL" != "no" ] && [ "$VAL" != "qt" ] && [ "$VAL" != "plugin" ]; then
	    UNKNOWN_OPT=yes
	fi
	# now $VAL is "no", "qt", or "plugin"
	OPT="$VAL"
	VAL=`echo $VAR | sed "s,^[^-]*-\([^-]*\).*,\1,"`
	VAR=`echo $VAR | sed "s,^\([^-]*\).*,\1,"`
	ERROR=no
	# now $OPT is "no", "qt", or "plugin"
	if [ "$VAR" = "imgfmt" ]; then
	    [ "$OPT" = "qt" ] && OPT=yes
	    # now $OPT is "no", "yes", or "plugin"
	    case "$VAL" in
	    jpeg) CFG_JPEG=$OPT ;;
	    mng) CFG_MNG=$OPT ;;
	    png) CFG_PNG=$OPT ;;
	    *) ERROR=yes ;;
	    esac
	else
	    if [ "$VAR" = "style" ]; then
		ERROR=yes
		for d in $CFG_STYLE_AVAILABLE; do
		    if [ "$VAL" = "$d" ]; then
			ERROR=no
			break
		    fi
		done
	    elif [ "$VAR" = "sql" ]; then
		ERROR=yes
		for d in $CFG_SQL_AVAILABLE; do
		    if [ "$VAL" = "$d" ]; then
			ERROR=no
			break
		    fi
		done
	    fi
	    if [ "$OPT" = "plugin" ] || [ "$OPT" = "qt" ]; then
		if [ "$OPT" = "plugin" ]; then
		    [ "$VAR" = "style" ] && QMAKE_VARS="$QMAKE_VARS \"${VAR}s -= $VAL\""
		    VAR="${VAR}-${OPT}"
		else
		    if [ "$VAR" = "sql" ] || [ "$VAR" = "kbd" ] || [ "$VAR" = "mouse" ]; then
			VAR="${VAR}-driver"
		    fi
		fi
		QMAKE_VARS="$QMAKE_VARS \"${VAR}s += $VAL\""
	    elif [ "$OPT" = "no" ]; then
		PLUG_VAR="${VAR}-plugin"
		if [ "$VAR" = "sql" ] || [ "$VAR" = "kbd" ] || [ "$VAR" = "mouse" ]; then
		    IN_VAR="${VAR}-driver"
		else
		    IN_VAR="${VAR}"
		fi
		QMAKE_VARS="$QMAKE_VARS \"${IN_VAR}s -= $VAL\" \"${PLUG_VAR}s -= $VAL\""
	    fi
	fi
        if [ "$ERROR" = "yes" ]; then
	   echo "$CURRENT_OPT: unknown argument"
	   OPT_HELP=yes;
	fi
	;;
    v|verbose)
	if [ "$VAL" = "yes" ]; then
	    if [ "$OPT_VERBOSE" = "$VAL" ]; then 	    # takes two verboses to turn on qmake debugs
		QMAKE_SWITCHES="$QMAKE_SWITCHES -d"
            else
		OPT_VERBOSE=yes
	    fi
        elif [ "$VAL" = "no" ]; then
	    if [ "$OPT_VERBOSE" = "$VAL" ] && echo "$QMAKE_SWITCHES" | grep ' -d' >/dev/null 2>&1; then
		QMAKE_SWITCHES=`echo $QMAKE_SWITCHES | sed "s, -d,,"`
	    else
		OPT_VERBOSE=no
            fi
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    fast)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    OPT_FAST="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    concurrent)
	OPT_CONCURRENT="$VAL"
	;;
    define)
	D_FLAGS="$D_FLAGS $VAL"
	;;
    ipath)
	I_FLAGS="$I_FLAGS -I${VAL}"
	;;
    lpath)
	L_FLAGS="$L_FLAGS -L${VAL}"
	;;
    rpath)
	R_FLAGS="$R_FLAGS \$\${QMAKE_RPATH}${VAL}"
	;;
    link)
	l_FLAGS="$l_FLAGS -l${VAL}"
	;;
    dlopen-opengl)
	CFG_DLOPEN_OPENGL="$VAL"
	;;
    inputmethod)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_IM="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    inputmethod-ext)
	if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
	    CFG_IM_EXT="$VAL"
	else
	    UNKNOWN_OPT=yes
	fi
	;;
    *)
	UNKNOWN_OPT=yes
	;;
    esac
    if [ "$UNKNOWN_OPT" = "yes" ]; then
	echo "${CURRENT_OPT}: invalid command-line switch"
	OPT_HELP=yes
	ERROR=yes
    fi
done

#-------------------------------------------------------------------------------
# post initialize QT_INSTALL_* variables, and generate qconfig.cpp
#-------------------------------------------------------------------------------

# default $outpath
[ -z "$QT_INSTALL_PREFIX" ]       && QT_INSTALL_PREFIX=$outpath
# default PREFIX/doc
[ -z "$QT_INSTALL_DOCS" ]         && QT_INSTALL_DOCS=$QT_INSTALL_PREFIX/doc
# default PREFIX/include
[ -z "$QT_INSTALL_HEADERS" ]      && QT_INSTALL_HEADERS=$QT_INSTALL_PREFIX/include
# default PREFIX/lib
[ -z "$QT_INSTALL_LIBS" ]         && QT_INSTALL_LIBS=$QT_INSTALL_PREFIX/lib
# default PREFIX/bin
[ -z "$QT_INSTALL_BINS" ]         && QT_INSTALL_BINS=$QT_INSTALL_PREFIX/bin
# default PREFIX/plugins
[ -z "$QT_INSTALL_PLUGINS" ]      && QT_INSTALL_PLUGINS=$QT_INSTALL_PREFIX/plugins
# default PREFIX
[ -z "$QT_INSTALL_DATA" ]         && QT_INSTALL_DATA=$QT_INSTALL_PREFIX
# default PREFIX/translations
[ -z "$QT_INSTALL_TRANSLATIONS" ] && QT_INSTALL_TRANSLATIONS=$QT_INSTALL_PREFIX/translations
# default PREFIX/etc/settings
[ -z "$QT_INSTALL_SYSCONF" ]      && QT_INSTALL_SYSCONF=$QT_INSTALL_PREFIX/etc/settings
# default PREFIX/share
[ -z "$QT_INSTALL_SHARE" ]        && QT_INSTALL_SHARE=$QT_INSTALL_PREFIX/share

# generate qconfig.cpp
[ -d $outpath/src/tools ] || mkdir -p $outpath/src/tools
cat > $outpath/src/tools/qconfig.cpp.new <<EOF
/* Install paths from configure */
#include "ntqglobal.h"

static const char QT_INSTALL_PREFIX      [267] = "qt_nstpath=$QT_INSTALL_PREFIX";
static const char QT_INSTALL_BINS        [267] = "qt_binpath=$QT_INSTALL_BINS";
static const char QT_INSTALL_DOCS        [267] = "qt_docpath=$QT_INSTALL_DOCS";
static const char QT_INSTALL_HEADERS     [267] = "qt_hdrpath=$QT_INSTALL_HEADERS";
static const char QT_INSTALL_LIBS        [267] = "qt_libpath=$QT_INSTALL_LIBS";
static const char QT_INSTALL_PLUGINS     [267] = "qt_plgpath=$QT_INSTALL_PLUGINS";
static const char QT_INSTALL_DATA        [267] = "qt_datpath=$QT_INSTALL_DATA";
static const char QT_INSTALL_TRANSLATIONS[267] = "qt_trnpath=$QT_INSTALL_TRANSLATIONS";
static const char QT_INSTALL_SYSCONF     [267] = "qt_cnfpath=$QT_INSTALL_SYSCONF";
static const char QT_INSTALL_SHARE       [267] = "qt_shapath=$QT_INSTALL_SHARE";

/* strlen( "qt_xxxpath=" ) == 11 */
const char *tqInstallPath()             { return QT_INSTALL_PREFIX       + 11; }
const char *tqInstallPathDocs()         { return QT_INSTALL_DOCS         + 11; }
const char *tqInstallPathHeaders()      { return QT_INSTALL_HEADERS      + 11; }
const char *tqInstallPathLibs()         { return QT_INSTALL_LIBS         + 11; }
const char *tqInstallPathBins()         { return QT_INSTALL_BINS         + 11; }
const char *tqInstallPathPlugins()      { return QT_INSTALL_PLUGINS      + 11; }
const char *tqInstallPathData()         { return QT_INSTALL_DATA         + 11; }
const char *tqInstallPathTranslations() { return QT_INSTALL_TRANSLATIONS + 11; }
const char *tqInstallPathSysconf()      { return QT_INSTALL_SYSCONF      + 11; }
const char *tqInstallPathShare()        { return QT_INSTALL_SHARE        + 11; }
EOF

# avoid unecessary rebuilds by copying only if qconfig.cpp has changed
if cmp -s $outpath/src/tools/qconfig.cpp $outpath/src/tools/qconfig.cpp.new; then
    rm -f $outpath/src/tools/qconfig.cpp.new
else
    [ -f $outpath/src/tools/qconfig.cpp ] && chmod +w $outpath/src/tools/qconfig.cpp
    mv $outpath/src/tools/qconfig.cpp.new $outpath/src/tools/qconfig.cpp
    chmod -w $outpath/src/tools/qconfig.cpp
fi


#-------------------------------------------------------------------------------
# build tree initialization
#-------------------------------------------------------------------------------

#where to find which..
unixtests=$relpath/config.tests/unix
WHICH=$unixtests/which.test

### skip this if the user just needs help...
if [ "$OPT_HELP" != "yes" ]; then

# create the include and include/qmake directory (for ntqconfig.h and ntqmodules.h)
[ -d $outpath/include/qmake ] || mkdir -p $outpath/include/qmake

# create temporary ntqconfig.h for compiling qmake
# when building qmake, we use #defines for the install paths,
# however they are real functions in the library
cat >>$outpath/include/qmake/ntqconfig.h <<EOF
/* All features enabled while building qmake */
EOF

# create temporary ntqmodules.h for compiling qmake
cat >>$outpath/include/qmake/ntqmodules.h <<EOF
/* All modules enabled while building qmake */
EOF

# is this a shadow build?
if [ "$OPT_SHADOW" = "maybe" ]; then
    OPT_SHADOW=no
    if [ "$relpath" != "$outpath" ] && [ '!' -f "$outpath/configure" ]; then
	if [ -h "$outpath" ]; then
	    [ "$relpath" -ef "$outpath" ] || OPT_SHADOW=yes
	else
	    OPT_SHADOW=yes
        fi
    fi
fi
if [ "$OPT_VERBOSE" = "yes" -a "$OPT_SHADOW" = "yes" ]; then
    echo "Performing shadow build..."
fi

#detect how mng should be built
if [ "$CFG_MNG" = "auto" ]; then
    if [ "$CFG_SHARED" = "yes" ]; then
	CFG_MNG=plugin
    else
	CFG_MNG=yes
    fi
fi

#detect how jpeg should be built
if [ "$CFG_JPEG" = "auto" ]; then
    if [ "$CFG_MNG" = "yes" ]; then
	CFG_JPEG=yes
    elif [ "$CFG_SHARED" = "yes" ]; then
	CFG_JPEG=plugin
    else
	CFG_JPEG=yes
    fi
fi

#detect accessibility
if [ "$CFG_ACCESSIBILITY" = "auto" ]; then
    if [ "$PLATFORM_MAC" = "yes" ]; then
	CFG_ACCESSIBILITY=yes
    else
	CFG_ACCESSIBILITY=no
    fi
fi

# if the source tree is different from the build tree,
# symlink or copy part of the sources
if [ "$OPT_SHADOW" = "yes" ]; then
    echo "Preparing build tree..."
    [ -d $outpath/bin ] || mkdir -p $outpath/bin

    # need a top level makefile, prefer gnu internally
    if [ -f $relpath/GNUmakefile ]; then
	rm -f $outpath/Makefile
	ln -s $relpath/GNUmakefile $outpath/Makefile
    elif [ -f $relpath/Makefile ]; then
	rm -f $outpath/Makefile
	ln -s $relpath/Makefile $outpath/Makefile
    else
	echo "No top level Makefile." >&2
	exit 1
    fi

    # symlink the qmake directory
    for a in `find $relpath/qmake`; do
	my_a=`echo $a | sed "s,^${relpath}/,${outpath}/,"`
	if [ '!' -f $my_a ]; then
	    if [ -d $a ]; then
		# directories are created...
		mkdir -p $my_a
	    else
		a_dir=`dirname $my_a`
		[ -d $a_dir ] || mkdir -p $a_dir
		# ... and files are symlinked
		case `basename $a` in
		*.o|*.d|GNUmakefile*|qmake)
		    ;;
		*)
		    rm -f $my_a
		    ln -s $a $my_a
		    ;;
		esac
	    fi
	fi
    done

    # symlink the mkspecs directory
    mkdir -p $outpath/mkspecs
    rm -f $outpath/mkspecs/*
    ln -s $relpath/mkspecs/* $outpath/mkspecs
    rm -f $outpath/mkspecs/default

    # symlink the linguist/doc directory (to make the assistant happy)
    mkdir -p $outpath/tools/linguist
    rm -f $outpath/tools/linguist/doc
    ln -s $relpath/tools/linguist/doc $outpath/tools/linguist/doc

    # symlink the designer/templates directory (to make the designer find
    # the templates)
    mkdir -p $outpath/tools/designer
    rm -f $outpath/tools/designer/templates
    ln -s $relpath/tools/designer/templates $outpath/tools/designer/templates
    # symlink the designer/interfaces directory (for the validator)
    rm -f $outpath/tools/designer/interfaces
    ln -s $relpath/tools/designer/interfaces $outpath/tools/designer/interfaces
    # symlink designer/editor/editor.h, dlldefs.h, viewmanager.h (for the validator)
    mkdir -p $outpath/tools/designer/editor
    rm -f $outpath/tools/designer/editor/editor.h
    ln -s $relpath/tools/designer/editor/editor.h $outpath/tools/designer/editor/editor.h
    rm -f $outpath/tools/designer/editor/dlldefs.h
    ln -s $relpath/tools/designer/editor/dlldefs.h $outpath/tools/designer/editor/dlldefs.h
    rm -f $outpath/tools/designer/editor/viewmanager.h
    ln -s $relpath/tools/designer/editor/viewmanager.h $outpath/tools/designer/editor/viewmanager.h

    # symlink the doc directory
    rm -f $outpath/doc
    ln -s $relpath/doc $outpath/doc
else
    # override the Windows Makefile
    if [ -f "$relpath/GNUmakefile" ]; then
	[ "$Edition" = "troll" ] && $WHICH chflags >/dev/null 2>&1 && chflags nouchg $outpath/Makefile
	rm -f $outpath/Makefile
	cp $relpath/GNUmakefile $outpath/Makefile
	chmod +w $outpath/Makefile
    fi
fi

# binaries from qt
QMAKE_VARS="$QMAKE_VARS \"QMAKE_MOC=$outpath/bin/tqmoc\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_UIC=$outpath/bin/tquic -L \$\$QT_BUILD_TREE/plugins\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_QMAKE=$outpath/bin/tqmake\""
# hacky src line
QMAKE_VARS="$QMAKE_VARS \"QMAKE_MOC_SRC=$outpath/src/moc\""

# find out which awk we want to use, prefer gawk, then nawk, then regular awk
AWK=
for e in gawk nawk awk; do
    if $WHICH $e >/dev/null 2>&1 && ( $e -f /dev/null /dev/null ) >/dev/null 2>&1; then
	AWK=$e
    	break
    fi
done
if [ "$OPT_FAST" = "auto" ]; then
   if [ ! -z "$AWK" ] && [ "$Edition" = "troll" ]; then
       OPT_FAST=yes
   else
       OPT_FAST=no
   fi
fi

# find a make command
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 ### help


#-------------------------------------------------------------------------------
# auto-detect all that hasn't been specified in the arguments
#-------------------------------------------------------------------------------

if [ -z "$PLATFORM" ]; then
    PLATFORM_NOTES=
    case "$UNAME_SYSTEM:$UNAME_RELEASE" in
     Darwin:*)
	if [ "$PLATFORM_MAC" = "yes" ]; then
	  PLATFORM=macx-g++
	else
	  PLATFORM=darwin-g++
	fi
	;;
     AIX:*)
	PLATFORM=aix-xlc
	PLATFORM_NOTES="
	    - Also available for AIX: aix-g++ aix-xlc-64
	"
	;;
     QNX:*)
	PLATFORM=qnx-g++
	;;
     dgux:*)
	PLATFORM=dgux-g++
	;;
     ULTRIX:*)
	PLATFORM=ultrix-g++
	;;
     FreeBSD:*)
	PLATFORM=freebsd-g++
	;;
     OpenBSD:*)
	PLATFORM=openbsd-g++
	;;
     NetBSD:*)
	PLATFORM=netbsd-g++
	;;
     BSD/OS:*|BSD/386:*)
	PLATFORM=bsdi-g++
	;;
     IRIX*:*)
	#PLATFORM=irix-g++
	PLATFORM=irix-cc
	#PLATFORM=irix-cc-64
	PLATFORM_NOTES="
	    - Also available for IRIX: irix-g++ irix-cc-64
	"
	;;
     HP-UX:*)
	#PLATFORM=hpux-g++
	PLATFORM=hpux-acc
	#PLATFORM=hpux-acc-64
	#PLATFORM=hpux-cc
	#PLATFORM=hpux-acc-o64
	PLATFORM_NOTES="
	    - Also available for HP-UX: hpux-g++ hpux-acc-64 hpux-acc-o64
	"
	;;
     OSF1:*)
	#PLATFORM=tru64-g++
	PLATFORM=tru64-cxx
	PLATFORM_NOTES="
	    - Also available for Tru64: tru64-g++
	"
	;;
     Linux:*|GNU:*|GNU/*:*)
	PLATFORM=linux-g++
	PLATFORM_NOTES="
	    - Also available for Linux: linux-kcc linux-icc linux-cxx
	"
	;;
     SunOS:5*)
	#PLATFORM=solaris-g++
	PLATFORM=solaris-cc
	#PLATFORM=solaris-cc64
	PLATFORM_NOTES="
	    - Also available for Solaris: solaris-g++ solaris-cc-64
	"
	;;
     ReliantUNIX-*:*|SINIX-*:*)
	PLATFORM=reliant-cds
	#PLATFORM=reliant-cds-64
	PLATFORM_NOTES="
	    - Also available for Reliant UNIX: reliant-cds-64
	"
	;;
     CYGWIN*:*)
	PLATFORM=cygwin-g++
	;;
     LynxOS*:*)
	PLATFORM=lynxos-g++
	;;
     OpenUNIX:*)
	#PLATFORM=unixware-g++
        PLATFORM=unixware-cc
	PLATFORM_NOTES="
	    - Also available for OpenUNIX: unixware-g++
	"
        ;;
     UnixWare:*)
	#PLATFORM=unixware-g++
	PLATFORM=unixware-cc
	PLATFORM_NOTES="
	    - Also available for UnixWare: unixware-g++
	"
	;;
     SCO_SV:*)
	#PLATFORM=sco-g++
	PLATFORM=sco-cc
	PLATFORM_NOTES="
	    - Also available for SCO OpenServer: sco-g++
	"
	;;
     UNIX_SV:*)
	PLATFORM=unixware-g++
	;;
     *)
	if [ "$OPT_HELP" != "yes" ]; then
	    echo
	    for p in $PLATFORMS; do
		echo "    $relconf $* -platform $p"
	    done
	    echo >&2
	    echo "   The build script does not currently recognize all" >&2
	    echo "   platforms supported by Qt." >&2
	    echo "   Rerun this script with a -platform option listed to" >&2
	    echo "   set the system/compiler combination you use." >&2
	    echo >&2
	    exit 2
	fi
    esac
fi

PLATFORMS=`find $relpath/mkspecs/ -type f`

##if [ "$OPT_CONCURRENT" = "0" ] && echo $MAKEFLAGS | grep '.* *-j[0-9]* *.*' >/dev/null 2>&1; then
#    OPT_CONCURRENT=`echo $MAKEFLAGS | sed "s,.* *-j\([0-9]*\) *.*,\1,"`
#fi

[ -z "$XPLATFORM" ] && XPLATFORM="$PLATFORM"
if [ -d "$PLATFORM" ]; then
  QMAKESPEC="$PLATFORM"
else
  QMAKESPEC="$relpath/mkspecs/${PLATFORM}"
fi
if [ -d "$XPLATFORM" ]; then
  XQMAKESPEC="$XPLATFORM"
else
  XQMAKESPEC="$relpath/mkspecs/${XPLATFORM}"
fi
if [ "$QMAKESPEC" = "$XQMAKESPEC" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG nocrosscompiler"
fi

if [ "$PLATFORM_MAC" = "yes" ]; then
   if [ `basename $QMAKESPEC` = "macx-pbuilder" ] || [ `basename $XQMAKESPEC` = "macx-pbuilder" ]; then
      echo >&2
      echo "   Platform 'macx-pbuilder' should not be used when building Qt/Mac." >&2
      echo "   Please build Qt/Mac with 'macx-g++', then if you would like to" >&2
      echo "   use mac-pbuilder on your application code it can link to a Qt/Mac" >&2
      echo "   built with 'macx-g++'" >&2
      echo >&2
      exit 2
  fi
fi

# check specified platforms are supported
if [ '!' -d "$QMAKESPEC" ]; then
    echo
    echo "   The specified system/compiler is not supported:"
    echo
    echo "   	$QMAKESPEC"
    echo
    echo "   Please see the PLATFORMS file for a complete list."
    echo
    exit 2
fi
if [ '!' -d "$XQMAKESPEC" ]; then
    echo
    echo "   The specified system/compiler is not supported:"
    echo
    echo "   	$XQMAKESPEC"
    echo
    echo "   Please see the PLATFORMS file for a complete list."
    echo
    exit 2
fi
if [ '!' -f "${XQMAKESPEC}/qplatformdefs.h" ]; then
    echo
    echo "   The specified system/compiler port is not complete:"
    echo
    echo "   	$XQMAKESPEC/qplatformdefs.h"
    echo
    echo "   Please contact qt-bugs@trolltech.com."
    echo
    exit 2
fi

# now look at the configs and figure out what platform we are config'd for
[ '!' -z "`grep QMAKE_LIBS_X11 $XQMAKESPEC/qmake.conf | awk '{print $3;}'`" ] && PLATFORM_X11=yes

# find default thread option for target
if grep >/dev/null '^QMAKE_LIBS_THREAD' $XQMAKESPEC/qmake.conf; then
    AUTOTHREAD=yes
else
    AUTOTHREAD=never
fi
# common qmake.conf file but dependency on OS version
if [ "$UNAME_SYSTEM" = "HP-UX" ]; then
    if echo $UNAME_RELEASE | grep -E "^B\.(09|10)" >/dev/null 2>&1; then
	AUTOTHREAD=never
    fi
fi
if [ "$UNAME_SYSTEM" = "SunOS" ]; then
    # Solaris 2.5 and 2.6 have libposix4, which was renamed to librt for Solaris >=7
    if echo $UNAME_RELEASE | grep "^5\.[5|6]" >/dev/null 2>&1; then
	sed -e "s,-lrt,-lposix4," $XQMAKESPEC/qmake.conf > $XQMAKESPEC/qmake.conf.new
	mv $XQMAKESPEC/qmake.conf.new $XQMAKESPEC/qmake.conf
    fi
fi
if [ $AUTOTHREAD = never ]; then
    if [ "$CFG_THREAD" = "yes" ]; then
	echo
	echo "ERROR: TQt is not configured to support threading on this platform"
	echo "       See the THREAD settings in $XQMAKESPEC/qmake.conf"
	echo
	exit 2
    fi
    AUTOTHREAD=no
fi
[ "$CFG_THREAD" = "auto" ] && CFG_THREAD=$AUTOTHREAD


#-------------------------------------------------------------------------------
# tests that don't need qmake (must be run before displaying help)
#-------------------------------------------------------------------------------

# auto-detect precompiled header support
if [ "$CFG_PRECOMPILE" = "auto" ]; then
    if $unixtests/precomp.test $XQMAKESPEC $OPT_VERBOSE; then
        CFG_PRECOMPILE=no
    else
        CFG_PRECOMPILE=yes
    fi
fi

# auto-detect SQL-modules support
if echo $MODULES | grep sql >/dev/null; then
    MYSQL_REQ="-lmysqlclient mysql.h"
    OCI_REQ="-lclntsh -lwtc8 oci.h"
    PSQL_REQ="-lpq postgres.h libpq/libpq-fs.h catalog/pg_type.h libpq-fe.h"
    ODBC_REQ="-lodbc sql.h sqlext.h"
    TDS_REQ="-lsybdb sybfront.h sybdb.h"
    DB2_REQ="-ldb2 sqlcli.h sqlcli1.h"
    IBASE_REQ="-lfbclient ibase.h"
    for _SQLDR in $CFG_SQL_AVAILABLE; do
	case $_SQLDR in
	mysql)
	    $unixtests/checkavail "MySQL" $OPT_VERBOSE $MYSQL_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED mysql"
	;;
	psql)
	    $unixtests/checkavail "PostgreSQL" $OPT_VERBOSE $PSQL_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED psql"
	    ;;
	odbc)
	    $unixtests/checkavail "ODBC" $OPT_VERBOSE $ODBC_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED odbc"
	    ;;
	oci)
	    $unixtests/checkavail "OCI" $OPT_VERBOSE $OCI_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED oci"
	    ;;
	tds)
	    $unixtests/checkavail "TDS" $OPT_VERBOSE $TDS_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED tds"
	    ;;
	db2)
	    $unixtests/checkavail "DB2" $OPT_VERBOSE $DB2_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED db2"
	    ;;
	ibase)
	    $unixtests/checkavail "IBASE" $OPT_VERBOSE $IBASE_REQ $L_FLAGS $I_FLAGS && CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED ibase"
	    ;;
	sqlite)
	    if [ -f $relpath/src/3rdparty/sqlite/sqlite.h ]; then
		CFG_SQL_AUTODETECTED="$CFG_SQL_AUTODETECTED sqlite"
	    fi
	    ;;
	*)
	    if [ "$OPT_VERBOSE" = "yes" ]; then
		echo "unknown SQL driver: $_SQLDR"
	    fi
	    ;;
	esac
    done
fi
# auto-detect NIS support
if [ "$CFG_NIS" != "no" ]; then
    if $unixtests/nis.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	if [ "$CFG_NIS" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "NIS support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_NIS=no
        fi
    else
	CFG_NIS=yes
    fi
fi
# auto-detect CUPS support
if [ "$CFG_CUPS" != "no" ]; then
    if $unixtests/cups.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	if [ "$CFG_CUPS" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "Cups support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_CUPS=no
        fi
    else
	CFG_CUPS=yes
    fi
fi

#mac
QT_MAC_VERSION=
if [ "$PLATFORM_MAC" = "yes" ]; then
    mactests=$relpath/config.tests/mac
    QT_MAC_VERSION=`$mactests/mac_version.test "$OPT_VERBOSE" "$relpath" "$outpath"`
    if [ "$CFG_TABLET" = "auto" ]; then
	CFG_TABLET=yes
    fi
fi

# x11
if [ "$PLATFORM_X11" = "yes" ]; then
    x11tests=$relpath/config.tests/x11

    # auto-detect OpenGL support
    if echo $MODULES | grep opengl >/dev/null; then
	if $x11tests/opengl.test $XQMAKESPEC $CFG_THREAD $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    MODULES=`echo $MODULES | sed -e 's/opengl//'`
        else
	    if [ "$CFG_DLOPEN_OPENGL" = "yes" ]; then
		QMAKE_CONFIG="$QMAKE_CONFIG dlopen_opengl"
	    fi
	fi
    fi
    # auto-detect Xcursor support
    if [ "$CFG_XCURSOR" != "no" ]; then
        if $x11tests/xcursor.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XCURSOR" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xcursor support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
            else
                CFG_XCURSOR=no
            fi
	else
            CFG_XCURSOR=yes
        fi
    fi
    # auto-detect XRandR support (resize and rotate extension)
    if [ "$CFG_XRANDR" != "no" ]; then
	if $x11tests/xrandr.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XRANDR" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XRandR support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XRANDR=no
	    fi
	else
	    CFG_XRANDR=yes
	fi
    fi
    # auto-detect XRender support
    if [ "$CFG_XRENDER" != "no" ]; then
	if $x11tests/xrender.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XRENDER" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XRender support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XRENDER=no
		CFG_FREETYPE=no
	    fi
	else
	    CFG_XRENDER=yes
	fi
    else
	CFG_FREETYPE=no
    fi
    # auto-detect Xft support
    if [ "$CFG_XRENDER" = "yes" ] && [ "$CFG_FREETYPE" != "no" ]; then
	mkdir -p $outpath/config.tests/x11
	if $x11tests/xfreetype.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_FREETYPE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xft support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_FREETYPE=no
	    fi
	else
	    CFG_FREETYPE=yes
	fi
    fi
    # add freetype2 include path
    if [ "$CFG_FREETYPE" = "yes" ] && [ -f $outpath/config.tests/x11/xft.inc ];then
	QMAKE_VARS="$QMAKE_VARS \"INCLUDEPATH+=`cat $outpath/config.tests/x11/xft.inc`\""
    fi
    rm -f $outpath/config.tests/x11/xft.inc
    # add Xft specific libraries
    if [ "$CFG_FREETYPE" = "yes" ] && [ -f $outpath/config.tests/x11/xft.lib ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11=`cat $outpath/config.tests/x11/xft.lib` \$\$QMAKE_LIBS_X11\""
    fi
    rm -f $outpath/config.tests/x11/xft.lib
    # add Xft specific config options
    if [ "$CFG_FREETYPE" = "yes" ] && [ -f $outpath/config.tests/x11/xft.cfg ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG `cat $outpath/config.tests/x11/xft.cfg`"
    fi
    rm -f $outpath/config.tests/x11/xft.cfg
    # auto-detect Session Management support
    if [ "$CFG_SM" = "auto" ]; then
	if $x11tests/sm.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_SM" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Session Management support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_SM=no
	    fi
	else
	    CFG_SM=yes
	fi
    fi
    # auto-detect SHAPE support
    if [ "$CFG_XSHAPE" != "no" ]; then
	if $x11tests/xshape.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XSHAPE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XShape support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
            else
                CFG_XSHAPE=no
            fi
	else
	    CFG_XSHAPE=yes
	fi
    fi
    # auto-detect Xinerama support
    if [ "$CFG_XINERAMA" != "no" ]; then
	if $x11tests/xinerama.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XINERAMA" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "Xinerama support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XINERAMA=no
	    fi
	else
	    CFG_XINERAMA=yes
	fi
    fi
    # auto-detect tablet support (currenlty only in IRIX)
    if [ "$CFG_TABLET" = "auto" ]; then
	case $PLATFORM in
	irix-*)
	    if $x11tests/xinput.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
		if [ "$CFG_TABLET" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		    echo "Tablet support cannot be enabled due to functionality tests!"
		    echo " Turn on verbose messaging (-v) to $0 to see the final report."
		    echo " If you believe this message is in error you may use the continue"
		    echo " switch (-continue) to $0 to continue."
		    exit 101
		else
		    CFG_TABLET=no
		fi
	    else
		CFG_TABLET=yes
	    fi
	    ;;
	*)
	    CFG_TABLET=no
	    ### add error message for the "yes" case on non-IRIX systems
	    ;;
	esac
    fi
    # auto-detect XKB support
    if [ "$CFG_XKB" != "no" ]; then
	if $x11tests/xkb.test $XQMAKESPEC $OPT_VERBOSE $L_FLAGS $I_FLAGS; then
	    if [ "$CFG_XKB" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
		echo "XKB support cannot be enabled due to functionality tests!"
		echo " Turn on verbose messaging (-v) to $0 to see the final report."
		echo " If you believe this message is in error you may use the continue"
		echo " switch (-continue) to $0 to continue."
		exit 101
	    else
		CFG_XKB=no
	    fi
	else
	    CFG_XKB=yes
	fi
    fi
fi

# embedded graphics
# immodule extensions
if [ "$CFG_IM" = "no" ]; then
    CFG_IM_EXT=no
fi
if [ "$CFG_IM_EXT" = "yes" ]; then
    CFG_IM=yes
fi

#-------------------------------------------------------------------------------
# help - interactive parts of the script _after_ this section please
#-------------------------------------------------------------------------------

# next, emit a usage message if something failed.
if [ "$OPT_HELP" = "yes" ]; then
    [ "x$ERROR" = "xyes" ] && echo
    if [ "$CFG_THREAD" = "yes" ]; then
	THY="*"
	THN=" "
    else
	THY=" "
	THN="*"
    fi
    if [ "$CFG_NIS" = "no" ]; then
	NSY=" "
	NSN="*"
    else
	NSY="*"
	NSN=" "
    fi
    if [ "$CFG_CUPS" = "no" ]; then
	CUY=" "
	CUN="*"
    else
	CUY="*"
	CUN=" "
    fi
    if [ "$CFG_LARGEFILE" = "no" ]; then
	LFSY=" "
	LFSN="*"
    else
	LFSY="*"
	LFSN=" "
    fi
    if [ "$CFG_STL" = "auto" ]; then
	SHY="*"
	SHN=" "
    else
	SHY=" "
	SHN="*"
    fi
    if [ "$CFG_PRECOMPILE" = "auto" ]; then
	PHY="*"
	PHN=" "
    else
	PHY=" "
	PHN="*"
    fi
    if [ "$CFG_IPV6" = "auto" ]; then
	I6Y="*"
	I6N=" "
    else
	I6Y=" "
	I6N="*"
    fi

    cat <<EOF
Usage:  $relconf [-prefix dir] [-buildkey key] [-docdir dir] [-headerdir dir]
	[-libdir dir] [-bindir dir] [-plugindir dir ] [-datadir dir] [-sysshare dir]
	[-translationdir dir] [-sysconfdir dir] [-debug] [-release]
	[-no-gif] [-qt-gif] [-no-sm] [-sm] [-qt-zlib] [-system-zlib]
	[-qt-libpng] [-system-libpng]
	[-qt-libmng] [-system-libmng] [-no-thread] [-thread] [-no-nis] [-nis]
	[-no-cups] [-cups] [-no-largefile] [-largefile] [-version-script]
	[-no-stl] [-stl] [-no-ipv6 ] [-ipv6] [-Istring] [-lstring]
	[-Lstring] [-Rstring] [-disable-<module>] [-with-<module setting>]
	[-without-<module setting>] [-fast] [-no-fast]

Installation options:

 These are optional, but you may specify install directories.

    -prefix dir ........ This will install everything relative dir
			  (default $QT_INSTALL_PREFIX)

 You may use these to separate different parts of the install:

    -bindir dir ........ Executables will be installed to dir
			  (default PREFIX/bin)
    -libdir dir ........ Libraries will be installed to dir
			  (default PREFIX/lib)
    -docdir dir ........ Documentation will be installed to dir
			  (default PREFIX/doc)
    -headerdir dir ..... Headers will be installed to dir
			  (default PREFIX/include)
    -plugindir dir ..... Plugins will be installed to dir
                          (default PREFIX/plugins)
    -datadir dir ....... Data used by TQt programs will be installed to dir
                          (default PREFIX)
    -translationdir dir  Translations of TQt programs will be installed to dir
                          (default PREFIX/translations)
    -sysconfdir dir ...  Settings used by TQt programs will be looked for in dir
                          (default PREFIX/etc/settings)
    -sysshare dir .....  System shared data will be installed in dir
                          (default PREFIX/share)

 You may use these options to turn on strict plugin loading.

    -buildkey key ...... Build the TQt library and plugins using the specified
			 key.  When the library loads plugins, it will only
			 load those that have a matching key.

Configure options:

 The defaults (*) are usually acceptable.  If marked with a plus (+) a test
 for that feature has not been done yet, but will be evaluated later, the
 plus simply denotes the default value. Here is a short explanation of each
 option:

 *  -release ........... Compile and link TQt with debugging turned off.
    -debug ............. Compile and link TQt with debugging turned on.

 *  -shared ............ Create and use a shared TQt library (libtqt.so).
    -static ............ Create and use a static TQt library (libtqt.a).

 *  -no-gif ............ Do not compile in GIF reading support.
    -qt-gif ............ Compile in GIF reading support.
			 See src/kernel/ntqgif.h

 *  -qt-zlib ........... Use the zlib bundled with Qt.
    -system-zlib ....... Use zlib from the operating system.
			 See http://www.gzip.org/zlib

    -fast .............. Configure TQt quickly by generating Makefiles only for
			 library and subdirectory targets.  All other Makefiles
			 are created as wrappers, which will in turn run qmake.
 *  -no-fast ........... Configure TQt normally by generating Makefiles for all
			 project files.

    -no-exceptions ..... Disable exceptions on platforms that support it.

    -version-script .... Use a version script when linking the TQt library.
			 Internal symbols will be marked as local. Requires
			 a recent GNU binutils package.

			 WARNING: Experimental, may be removed in future
			 versions.

    -platform target ... The operating system and compiler you are building
			 on ($PLATFORM).
    -xplatform target .. The target platform when cross-compiling.

			 See the PLATFORMS file for a list of supported
			 operating systems and compilers.

    -Dstring ........... Add an explicit define to the preprocessor.
    -Istring ........... Add an explicit include path.
    -Lstring ........... Add an explicit library path.
    -Rstring ........... Add an explicit dynamic library runtime search path.
    -lstring ........... Add an explicit library.

    -disable-<module> ..... Disable <module> where module is one of:
                            [ $CFG_MODULES_AVAILABLE ]

    -qt-sql-<driver> ...... Enable a SQL <driver> in the TQt Library, by default
                            none are turned on.
    -plugin-sql-<driver> .. Enable SQL <driver> as a plugin to be linked to
                            at run time.
    -no-sql-<driver> ...... Disable SQL <driver> entirely.

                            Possible values for <driver>:
                            [ $CFG_SQL_AVAILABLE ]

                            Auto-Detected on this system:
                            [$CFG_SQL_AUTODETECTED ]

                            By default none of the SQL drivers are built,
			    even if they are auto-detected.

    -qt-style-<style> ..... Enable a GUI <style> in the TQt Library, by default
                            all available styles are on.
    -plugin-style-<style> . Enable GUI <style> as a plugin to be linked to
                            at run time.
    -no-style-<style> ..... Disable GUI <style> entirely.

                            Possible values for <style>:
                            [ $CFG_STYLE_AVAILABLE ]

 $THN  -no-thread ............ Do not compile threading support.
 $THY  -thread ............... Compile threading support.

 $NSN  -no-nis ............... Do not compile NIS support.
 $NSY  -nis .................. Compile NIS support.

 $PHN  -no-pch ............... Do not use precompiled header support.
 $PHY  -pch .................. Use precompiled header support.

 $CUN  -no-cups............... Do not compile CUPS support.
 $CUY  -cups ................. Compile CUPS support.

 $SHN  -no-stl ............... Do not compile STL support.
 $SHY  -stl .................. Compile STL support.

 $I6N  -no-ipv6 .............. Do not compile IPv6 support.
 $I6Y  -ipv6 ................. Compile IPv6 support.

    -verbose .............. Print verbose information about each step of the
    -v .................... configure process.

    -continue.............. Continue as far as possible if an error occurs.

    -help ................. Print help and usage information.
    -h .................... Print help and usage information.

Image Formats:

    -plugin-imgfmt-<format> Enable <format> to be linked to at runtime.
                            Uses specified lib<format>.
    -qt-imgfmt-<format> ... Enable <format> to be linked into Qt.
                            Uses specified lib<format>.
    -no-imgfmt-<format> ... Fully disable <format> from Qt.

                            Possible values for <format>:
                            [ png jpeg mng ]

Third Party Image Loading Libraries:

    -qt-libpng ......... Use the libpng bundled with Qt.
 *  -system-libpng ..... Use libpng from the operating system.
			 See http://www.libpng.org/pub/png

    -qt-libmng ......... Use the libmng bundled with Qt.
 *  -system-libmng ..... Use libmng from the operating system.
			 See http://www.libmng.com
EOF

if [ "$PLATFORM_MAC" = "yes" ]; then
    cat << EOF

Qt/Mac only:

    -no-tablet ......... Do not compile Tablet support.
 *  -tablet ............ Compile Tablet support.

    -no-accessibility .. Do not compile Accessibility support.
 *  -accessibility ..... Compile Accessibility support.
EOF
fi

if [ "$PLATFORM_X11" = "yes" ]; then
    if [ "$CFG_SM" = "no" ]; then
	SMY=" "
	SMN="*"
    else
	SMY="*"
	SMN=" "
    fi
    if [ "$CFG_XSHAPE" = "no" ]; then
        SHY=" "
        SHN="*"
    else
        SHY="*"
        SHN=" "
    fi
    if [ "$CFG_XINERAMA" = "no" ]; then
	XRY=" "
	XRN="*"
    else
	XRY="*"
	XRN=" "
    fi
    if [ "$CFG_FREETYPE" = "no" ]; then
	XFTY=" "
	XFTN="*"
    else
	XFTY="*"
	XFTN=" "
    fi
    if [ "$CFG_XCURSOR" = "no" ]; then
        XCY=" "
        XCN="*"
    else
        XCY="*"
        XCN=" "
    fi
    if [ "$CFG_XRANDR" = "no" ]; then
        XZY=" "
        XZN="*"
    else
        XZY="*"
        XZN=" "
    fi
    if [ "$CFG_XRENDER" = "no" ]; then
	XRY=" "
	XRN="*"
    else
	XRY="*"
	XRN=" "
    fi
    if [ "$CFG_TABLET" = "no" ]; then
	XIY=" "
	XIN="*"
    else
	XIY="*"
	XIN=" "
    fi
    if [ "$CFG_XKB" = "no" ]; then
        XKY=" "
        XKN="*"
    else
        XKY="*"
        XKN=" "
    fi
    if [ "$CFG_IM" = "no" ]; then
        IMY=" "
        IMN="*"
    else
        IMY="*"
        IMN=" "
    fi
    if [ "$CFG_IM_EXT" = "no" ]; then
        IXY=" "
        IXN="*"
    else
        IXY="*"
        IXN=" "
    fi
    cat << EOF

Qt/X11 only:

 *  -no-nas-sound ...... Do not compile in NAS sound support.
    -system-nas-sound .. Use NAS libaudio from the operating system.
			 See http://radscan.com/nas.html

 $SMN  -no-sm ............. Do not support X Session Management.
 $SMY  -sm ................ Support X Session Management, links in -lSM -lICE.

 $SHN  -no-xshape ......... Do not compile XShape support.
 $SHY  -xshape ............ Compile XShape support.
                         Requires X11/extensions/shape.h.

 $XRN  -no-xinerama ....... Do not compile Xinerama (multihead) support.
 $XRY  -xinerama .......... Compile Xinerama support.
			 Requires X11/extensions/Xinerama.h and libXinerama.

 $XCN  -no-xcursor ........ Do not compile Xcursor support.
 $XCY  -xcursor ........... Compile Xcursor support.
                         Requires X11/Xcursor/Xcursor.h and libXcursor.

 $XZN  -no-xrandr ......... Do not compile XRandR (resize and rotate) support.
 $XZY  -xrandr ............ Compile XRandR support.
                         Requires X11/extensions/Xrandr.h and libXrandr.

 $XRN  -no-xrender ........ Do not compile XRender support.
 $XRY  -xrender ........... Compile XRender support.
			 Requires Xft support (see -xft below),
			 X11/extensions/Xrender.h and libXrender

 $XFTN  -no-xft ............ Do not compile Xft (anti-aliased font) support.
 $XFTY  -xft ............... Compile Xft support.
			 Requires X11/Xft/Xft.h and libXft.

 $XIN  -no-tablet ......... Do not compile Tablet support.
 $XIY  -tablet ............ Compile Tablet support.
			 Requires IRIX with wacom.h and libXi or
			 XFree86 with X11/extensions/XInput.h and libXi.

 $XKN  -no-xkb ............ Do not compile XKB (X KeyBoard extension) support.
 $XKY  -xkb ............... Compile XKB support.

 *  -no-dlopen-opengl .. TQt links against OpenGL libraries directly.
    -dlopen-opengl ..... TQt uses dlopen(3) to resolve OpenGL functions
			 (instead of linking with OpenGL libraries directly).

 $IMN  -no-inputmethod .... Do not compile immodule (extensible input method)
			 support.
 $IMY  -inputmethod ....... Compile immodule support.

 $IXN  -no-inputmethod-ext  Do not compile more immodule extensions support.
 $IXY  -inputmethod-ext ... Compile more immodule extensions support.
			 (breaks ABI with standard TQt3).

EOF
fi

   [ "x$ERROR" = "xyes" ] && exit 1
   exit 0
fi


# -----------------------------------------------------------------------------
# LICENSING
# -----------------------------------------------------------------------------

echo
if [ "$PLATFORM_MAC" = "yes" ]; then
    echo "This is the Qt/Mac Open Source Edition."
elif [ "$PLATFORM_X11" = "yes" ]; then
    echo "This is the Qt/X11 Open Source Edition."
else
    echo "Internal error: unknown platform."
    echo
    exit 2
fi
echo
echo "You are licensed to use this software under the terms of"
echo "the GNU General Public License (GPL) versions 2 or 3."
echo

# work around for broken system header files in IRIX 6.5.18 - 6.5.22
case "$PLATFORM" in
irix-cc*)
    IRIX_VERSION=`uname -R | awk '{FS=".";print $4}' | sed s/\[m\|f\]//g`
    MIPSPRO_MINOR_VERSION=`CC -version 2>&1 | awk '{FS=".";print $2}'`
    if [ "$MIPSPRO_MINOR_VERSION" -gt "3" -a "$IRIX_VERSION" -ge "18" \
	 -a "$IRIX_VERSION" -le "22" ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-LANG:libc_in_namespace_std=off\""
    fi
    ;;
*)
    IRIX_VERSION=-1
    MIPSPRO_MINOR_VERSION=-1
    ;;
esac

# -----------------------------------------------------------------------------
# build qmake
# -----------------------------------------------------------------------------

# symlink includes
if [ -x "$relpath/bin/syncqt" ]; then
    TQTDIR=$relpath perl $relpath/bin/syncqt -inc $relpath/include
    [ "$OPT_SHADOW" = "yes" ] && TQTDIR=$relpath perl $relpath/bin/syncqt -inc $outpath/include
fi

if [ "$OPT_SHADOW" = "yes" ]; then
    # we are doing a shadow build, so we need to use the includes from
    # $outpath/include as well
    QMAKE_VARS="$QMAKE_VARS \"INCLUDEPATH+=${outpath}/include\""
fi

# build qmake
if true; then ###[ '!' -f "$outpath/bin/tqmake" ];
    echo "Creating qmake. Please wait..."
    rm -f mkspecs/default
    ln -s `echo $QMAKESPEC | sed "s,^${relpath}/mkspecs/,,"` mkspecs/default
    # fix makefiles
    for mkfile in GNUmakefile Makefile; do
	EXTRA_LFLAGS=
	EXTRA_CFLAGS=
	in_mkfile="${mkfile}.in"
	if [ "$mkfile" = "Makefile" ]; then
#	    if which qmake >/dev/null 2>&1 && [ -f qmake/qmake.pro ]; then
#		(cd qmake && qmake) >/dev/null 2>&1 && continue
#	    fi
	    in_mkfile="${mkfile}.unix"
	fi
	in_mkfile="$relpath/qmake/$in_mkfile"
	mkfile="$outpath/qmake/$mkfile"
	if [ -f "$mkfile" ]; then
	    [ "$Edition" = "troll" ] && $WHICH chflags >/dev/null 2>&1 && chflags nouchg $mkfile
	    rm -f $mkfile
	fi
	[ -f "$in_mkfile" ] || continue

	echo "########################################################################" >$mkfile
	echo "## This file was autogenerated by configure, all changes will be lost ##" >>$mkfile
	echo "########################################################################" >>$mkfile
        EXTRA_CFLAGS="\$(QMAKE_CFLAGS)"
        EXTRA_CXXFLAGS="\$(QMAKE_CXXFLAGS)"
        EXTRA_LFLAGS="\$(QMAKE_LFLAGS)"
	grep "^QMAKE_CC[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,QMAKE_CC,CC," >>$mkfile
	grep "^QMAKE_CXX[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,QMAKE_CXX,CXX," >>$mkfile
        grep "^QMAKE_CFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
        grep "^QMAKE_CXXFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,\$\$QMAKE_CFLAGS,\$(QMAKE_CFLAGS)," >>$mkfile
        grep "^QMAKE_LFLAGS[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
	if [ "$CFG_DEBUG" = "yes" ]; then
            grep "QMAKE_CFLAGS_DEBUG[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
            grep "^QMAKE_CXXFLAGS_DEBUG[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,\$\$QMAKE_CFLAGS_DEBUG,\$(QMAKE_CFLAGS_DEBUG)," >>$mkfile
	    EXTRA_CFLAGS="$EXTRA_CFLAGS \$(QMAKE_CFLAGS_DEBUG)"
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS \$(QMAKE_CXXFLAGS_DEBUG)"
	else
	    grep "QMAKE_CFLAGS_RELEASE[^_A-Z0-9]" $QMAKESPEC/qmake.conf >>$mkfile
	    grep "^QMAKE_CXXFLAGS_RELEASE[^_A-Z0-9]" $QMAKESPEC/qmake.conf | sed "s,\$\$QMAKE_CFLAGS_RELEASE,\$(QMAKE_CFLAGS_RELEASE)," >>$mkfile
	    EXTRA_CFLAGS="$EXTRA_CFLAGS \$(QMAKE_CFLAGS_RELEASE)"
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS \$(QMAKE_CXXFLAGS_RELEASE)"
        fi
	if [ "$PLATFORM_MAC" = "yes" ]; then
	    echo "CARBON_LFLAGS +=-framework CoreServices" >>$mkfile
	    EXTRA_LFLAGS="$EXTRA_LFLAGS \$(CARBON_LFLAGS)"
	    EXTRA_CFLAGS="$EXTRA_CFLAGS \$(CARBON_CFLAGS) -DQT_MACOSX_VERSION=$QT_MAC_VERSION"
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS \$(CARBON_CFLAGS) -DQT_MACOSX_VERSION=$QT_MAC_VERSION"
	    EXTRA_SOURCES="qurl.o qsettings_mac.o"
	elif [ "$PLATFORM" = "tru64-cxx" ]; then
	    echo "OSF_LFLAGS = -lm"  >>$mkfile
	    EXTRA_LFLAGS="$EXTRA_LFLAGS \$(OSF_LFLAGS)"
        elif [ "$PLATFORM_QNX" = "yes" ]; then
	  echo "QNX_LFLAGS += -fhonor-std -fno-builtins -pipe" >>$mkfile
	  echo "QNX_CFLAGS += -lcpp" >>$mkfile
	  EXTRA_LFLAGS="$EXTRA_CFLAGS \$(QNX_LFLAGS)"
	  EXTRA_CFLAGS="$EXTRA_CFLAGS \$(QNX_CFLAGS)"
	fi
	if [ '!' -z "$D_FLAGS" ]; then
	    for DEF in $D_FLAGS; do
		EXTRA_CFLAGS="$EXTRA_CFLAGS -D${DEF}"
	    done
        fi
	if [ "$MIPSPRO_MINOR_VERSION" -gt "3" \
	      -a "$IRIX_VERSION" -ge "18" -a "$IRIX_VERSION" -le "22" ]; then
	    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -LANG:libc_in_namespace_std=off"
	fi
	QMAKE_BIN_DIR="$QT_INSTALL_BINS"
	[ -z "$QMAKE_BIN_DIR" ] && QMAKE_BIN_DIR="${QT_INSTALL_PREFIX}/bin"
	QMAKE_DATA_DIR="$QT_INSTALL_DATA"
	[ -z "$QMAKE_DATA_DIR" ] && QMAKE_DATA_DIR="${QT_INSTALL_PREFIX}"
        echo >>$mkfile
	sed -e "s,@SOURCE_PATH@,$relpath,g" -e "s,@BUILD_PATH@,$outpath,g" \
	    -e "s,@QMAKE_CFLAGS@,$EXTRA_CFLAGS,g" -e "s,@QMAKE_LFLAGS@,$EXTRA_LFLAGS,g" \
            -e "s,@QMAKE_CXXFLAGS@,$EXTRA_CXXFLAGS,g" \
	    -e "s,@QT_INSTALL_BINS@,\$(INSTALL_ROOT)$QMAKE_BIN_DIR,g" \
	    -e "s,@QT_INSTALL_DATA@,\$(INSTALL_ROOT)$QMAKE_DATA_DIR,g" \
	    -e "s,@QMAKE_QTOBJS@,$EXTRA_SOURCES,g" -e "s,@QMAKESPEC@,$QMAKESPEC,g" $in_mkfile >>$mkfile

	if [ "$Edition" = "troll" ] &&
	    $WHICH makedepend >/dev/null 2>&1 && grep 'depend:' "$mkfile" >/dev/null 2>&1; then
	    (cd $outpath/qmake && $MAKE -f $mkfile depend) >/dev/null 2>&1
	fi
    done

    (cd $outpath/qmake; $MAKE || (echo "qmake failed to build. Aborting." && exit 2)) || exit 2
fi

# clean up temporary ntqconfig.h and ntqmodules.h
rm -f $outpath/include/qmake/ntqconfig.h
rm -f $outpath/include/qmake/ntqmodules.h
rmdir $outpath/include/qmake


#-------------------------------------------------------------------------------
# tests that need qmake
#-------------------------------------------------------------------------------

# work around broken X11 headers when using GCC 2.95 or later
if [ "$PLATFORM_X11" = "yes" ]; then
    NOTYPE=no
    $x11tests/notype.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath && NOTYPE=yes
    [ $NOTYPE = "yes" ] && QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-fpermissive\""
fi

# find if the compiler supports enough of STL for our purposes
if [ $PLATFORM = "hpux-acc" -a "$CFG_STL" != "no" ]; then
   echo
   echo "As of aCC A.3.0.30 you may enable STL support in TQt by adding -AA"
   echo "to the QMAKE_CXXFLAGS and QMAKE_LFLAGS variables in"
   echo "$XQMAKESPEC/qmake.conf"
   echo "and re-running configure. Make sure to use the -AA compiler switch"
   echo "in all your software projects using TQt as it turns on the new C++"
   echo "Standard Library which is not binary compatible with the old one."
   echo
fi

if [ "$CFG_ENDIAN" = "auto" ]; then
    if [ "$PLATFORM_MAC" = "yes" ]; then
        true
    elif $unixtests/endian.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
        CFG_ENDIAN="TQ_LITTLE_ENDIAN"
    else
        CFG_ENDIAN="TQ_BIG_ENDIAN"
    fi
fi

if [ "$CFG_STL" = "auto" ]; then
    if $unixtests/stl.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_STL" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "STL support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_STL=no
	fi
    else
	CFG_STL=yes
    fi
fi

# find if the platform supports IPv6
if [ "$CFG_IPV6" = "auto" ]; then
    if $unixtests/ipv6.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_IPV6" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "IPv6 support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_IPV6=no
	fi
    else
	CFG_IPV6=yes
    fi
fi

# find if the platform supports X/Open Large File compilation environment
if [ "$CFG_LARGEFILE" = "auto" ]; then
    if $unixtests/largefile.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath; then
	if [ "$CFG_LARGEFILE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then
	    echo "Large file support cannot be enabled due to functionality tests!"
	    echo " Turn on verbose messaging (-v) to $0 to see the final report."
	    echo " If you believe this message is in error you may use the continue"
	    echo " switch (-continue) to $0 to continue."
	    exit 101
	else
	    CFG_LARGEFILE=no
	fi
    else
	CFG_LARGEFILE=yes
    fi
fi


#-------------------------------------------------------------------------------
# ask for all that hasn't been auto-detected or specified in the arguments
#-------------------------------------------------------------------------------

# enable accessibility
if [ "$CFG_ACCESSIBILITY" = "yes" ]; then
   QMAKE_CONFIG="$QMAKE_CONFIG accessibility"
fi

# update QMAKE_CONFIG to show our current predefined configuration
case "$CFG_QCONFIG" in
minimal|small|medium|large|full)
    # these are a sequence of increasing functionality
    for c in minimal small medium large full; do
	QMAKE_CONFIG="$QMAKE_CONFIG $c-config"
	if [ "$CFG_QCONFIG" = $c ]; then
	    break;
	fi
    done
    ;;
*)
    # not known to be sufficient for anything
    if [ '!' -f $relpath/src/tools/qconfig-$CFG_QCONFIG.h ]; then
	echo >&2 "No such configuration: $CFG_QCONFIG"
	OPT_HELP=yes
    fi
esac

# update QMAKE_CONFIG to show which modules are being built
for MODULE in $MODULES; do
    if [ -d "$relpath/src/$MODULE" ]; then
	M=`echo $MODULE | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
	QMAKE_CONFIG="$QMAKE_CONFIG $MODULE"
    fi
done


#-------------------------------------------------------------------------------
# ??? ### please add a title to this section
#-------------------------------------------------------------------------------

# build up the variables for output
QMAKE_OUTDIR=""
case $Products in
qt-enterprise)
    QMAKE_CONFIG="$QMAKE_CONFIG enterprise"
    ;;
qt-internal)
    # QMAKE_CONFIG="$QMAKE_CONFIG internal"
    ;;
*)
    ;;
esac

if [ "$CFG_DEBUG" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}debug"
    QMAKE_CONFIG="$QMAKE_CONFIG debug"
elif [ "$CFG_DEBUG" = "no" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}release"
    QMAKE_CONFIG="$QMAKE_CONFIG release"
fi
if [ "$CFG_SHARED" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-shared"
    QMAKE_CONFIG="$QMAKE_CONFIG dll"
elif [ "$CFG_SHARED" = "no" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-static"
    QMAKE_CONFIG="$QMAKE_CONFIG staticlib"
fi
if [ "$CFG_THREAD" = "yes" ]; then
    QMAKE_OUTDIR="${QMAKE_OUTDIR}-mt"
    QMAKE_CONFIG="$QMAKE_CONFIG thread"
fi
QMAKE_VARS="$QMAKE_VARS \"QMAKE_INCDIR_TQT=$relpath/include\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBDIR_TQT=$outpath/lib\""
QMAKE_VARS="$QMAKE_VARS \"QMAKE_RTLDIR_QT=$QT_INSTALL_LIBS\""
QMAKE_VARS="$QMAKE_VARS \"OBJECTS_DIR=.obj/$QMAKE_OUTDIR\" \"MOC_DIR=.moc/$QMAKE_OUTDIR\""
if [ "$CFG_LARGEFILE" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG largefile"
fi
if [ "$CFG_STL" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_STL"
else
    QMAKE_CONFIG="$QMAKE_CONFIG stl"
fi
[ "$CFG_PRECOMPILE" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG precompile_header"
if [ "$CFG_IPV6" = "no" ]; then
    QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_IPV6"
else
    QMAKE_CONFIG="$QMAKE_CONFIG ipv6"
fi
# don't add the link line if we build the image formats as a plugin
if [ "$CFG_LIBMNG" = "system" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG system-mng"
    if [ "$CFG_MNG" = "yes" ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT+=-lmng\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT_THREAD+=-lmng\""
    fi
fi
if [ "$CFG_MNG" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-mng"
elif [ "$CFG_MNG" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG mng"
fi
if [ "$CFG_LIBJPEG" = "system" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG system-jpeg"
    if [ "$CFG_JPEG" = "yes" ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT+=-ljpeg\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT_THREAD+=-ljpeg\""
    fi
fi
if [ "$CFG_JPEG" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-jpeg"
elif [ "$CFG_JPEG" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG jpeg"
fi
if [ "$CFG_LIBPNG" = "no" ]; then
    CFG_PNG="no"
fi
if [ "$CFG_LIBPNG" = "system" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG system-png"
    if [ "$CFG_PNG" = "yes" ]; then
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT+=-lpng\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT_THREAD+=-lpng\""
    fi
fi
if [ "$CFG_PNG" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-png"
elif [ "$CFG_PNG" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG png"
fi
if [ "$CFG_GLIBMAINLOOP" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-glibmainloop"
elif [ "$CFG_GLIBMAINLOOP" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG glibmainloop"

    GLIB_CFLAGS="`pkg-config --cflags glib-2.0` `pkg-config --cflags gthread-2.0`"
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS_GLIB=$GLIB_CFLAGS\""

    GLIB_LINKFLAG="`pkg-config --libs glib-2.0` `pkg-config --libs gthread-2.0`"
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_GLIB=$GLIB_LINKFLAG\""
fi
if [ "$CFG_GIF" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-gif"
elif [ "$CFG_GIF" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG gif"
fi
if [ "x$PLATFORM_MAC" = "xyes" ]; then
    [ "$CFG_ZLIB" = "yes" ] && CFG_ZLIB="system"
fi
if [ "$CFG_ZLIB" = "no" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG no-zlib"
    QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_COMPRESS"
elif [ "$CFG_ZLIB" = "yes" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG zlib"
elif [ "$CFG_ZLIB" = "system" ]; then
    QMAKE_CONFIG="$QMAKE_CONFIG system-zlib"
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT+=-lz\""
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_QT_THREAD+=-lz\""
fi
[ "$CFG_NIS" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG nis"
[ "$CFG_CUPS" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG cups"
[ "$CFG_NAS" = "system" ] && QMAKE_CONFIG="$QMAKE_CONFIG nas"
[ "$CFG_BIG_CODECS" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG bigcodecs"

if [ "$PLATFORM_X11" = "yes" ]; then
    [ "$CFG_SM" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG x11sm"

    # for some reason, the following libraries are not always build shared,
    # so *every* program/lib (including Qt) has to link against them
    if [ "$CFG_XSHAPE" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG xshape"
    fi
    if [ "$CFG_XINERAMA" = "yes" ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG xinerama"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXinerama \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XCURSOR" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG xcursor"
        QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXcursor \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XRANDR" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG xrandr"
        QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXrandr \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XRENDER" = "yes" ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG xrender"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXrender \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_FREETYPE" = "yes" ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG xftfreetype"
    fi
    if [ "$CFG_TABLET" = "yes" ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG tablet"
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBS_X11 = -lXi \$\$QMAKE_LIBS_X11\""
    fi
    if [ "$CFG_XKB" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG xkb"
    fi
    if [ "$CFG_IM" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG inputmethod"
    elif [ "$CFG_IM" = "no" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_IM"
    fi
    if [ "$CFG_IM_EXT" = "yes" ]; then
        QMAKE_CONFIG="$QMAKE_CONFIG inputmethod-ext"
    elif [ "$CFG_IM_EXT" = "no" ]; then
	QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_IM_EXTENSIONS"
    fi
elif [ "$PLATFORM_MAC" = "yes" ]; then
    if [ "$CFG_TABLET" = "yes" ]; then
	QMAKE_CONFIG="$QMAKE_CONFIG tablet"
    fi
fi

[ '!' -z "$D_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"DEFINES+=$D_FLAGS\""
[ '!' -z "$L_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"QMAKE_LIBDIR_FLAGS+=$L_FLAGS\""
[ '!' -z "$l_FLAGS" ] && QMAKE_VARS="$QMAKE_VARS \"LIBS+=$l_FLAGS\""

if [ '!' -z "$R_FLAGS" ]; then
    if grep QMAKE_RPATH $XQMAKESPEC/qmake.conf >/dev/null; then
	echo # Using -R/-rpath, so no need to warn
    else
	echo
	echo "ERROR: -R cannot be used on this platform as \$QMAKE_RPATH is"
	echo "       undefined."
	echo
	exit 1
    fi
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=$R_FLAGS\""
fi

if [ '!' -z "$I_FLAGS" ]; then
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=$I_FLAGS\""
    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=$I_FLAGS\""
fi

# install things
QMAKE_VARS="$QMAKE_VARS \"QT_INSTALL_PREFIX=${QT_INSTALL_PREFIX}\""
QMAKE_VARS="$QMAKE_VARS \"docs.path=${QT_INSTALL_DOCS}\""
QMAKE_VARS="$QMAKE_VARS \"headers.path=${QT_INSTALL_HEADERS}\""
QMAKE_VARS="$QMAKE_VARS \"plugins.path=${QT_INSTALL_PLUGINS}\""
QMAKE_VARS="$QMAKE_VARS \"libs.path=${QT_INSTALL_LIBS}\""
QMAKE_VARS="$QMAKE_VARS \"bins.path=${QT_INSTALL_BINS}\""
QMAKE_VARS="$QMAKE_VARS \"data.path=${QT_INSTALL_DATA}\""
QMAKE_VARS="$QMAKE_VARS \"translations.path=${QT_INSTALL_TRANSLATIONS}\""
QMAKE_VARS="$QMAKE_VARS \"share.path=${QT_INSTALL_SHARE}\""

# turn off exceptions for the compilers that support it
COMPILER=`echo $PLATFORM | cut -f 2- -d-`
if [ "$CFG_EXCEPTION_SUPPORT" = "no" ]; then
    case "$COMPILER" in
    g++*)
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=-fno-exceptions\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-fno-exceptions\""
	QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=-fno-exceptions\""
	;;
    cc*)
	case "$PLATFORM" in
	irix-cc*)
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CFLAGS+=-LANG:exceptions=off\""
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_CXXFLAGS+=-LANG:exceptions=off\""
	    QMAKE_VARS="$QMAKE_VARS \"QMAKE_LFLAGS+=-LANG:exceptions=off\""
	    ;;
	*) ;;
	esac
	;;
    *) ;;
    esac
fi

#-------------------------------------------------------------------------------
# part of configuration information goes into ntqmodules.h
#-------------------------------------------------------------------------------

rm -f $outpath/include/ntqmodules.h.new
cat >$outpath/include/ntqmodules.h.new << EOF
/* These modules are present in this configuration of TQt */
EOF
for MODULE in $MODULES; do
    if [ -d "$relpath/src/$MODULE" ]; then
	M=`echo $MODULE | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
	echo "#define TQT_MODULE_$M" >>$outpath/include/ntqmodules.h.new
    fi
done

# avoid unecessary rebuilds by copying only if ntqmodules.h has changed
if cmp -s $outpath/include/ntqmodules.h $outpath/include/ntqmodules.h.new; then
    rm -f $outpath/include/ntqmodules.h.new
else
    [ -f $outpath/include/ntqmodules.h ] && chmod +w $outpath/include/ntqmodules.h
    mv -f $outpath/include/ntqmodules.h.new $outpath/include/ntqmodules.h
    chmod -w $outpath/include/ntqmodules.h
fi

#-------------------------------------------------------------------------------
# generate TQT_BUILD_KEY
#-------------------------------------------------------------------------------

# some compilers generate binary incompatible code between different versions,
# so we need to generate a build key that is different between these compilers
case "$COMPILER" in
g++*)
    # GNU C++
    QMAKE_CONF_COMPILER=`grep "QMAKE_CXX[^_A-Z0-9a-z]" $QMAKESPEC/qmake.conf | sed "s,.* *= *\(.*\)$,\1,"`
    COMPILER_VERSION=`${QMAKE_CONF_COMPILER} -dumpversion 2>/dev/null | sed 's,^[^0-9]*,,g'`
    case "$COMPILER_VERSION" in
    2.95.*)
	COMPILER_VERSION="2.95.*"
	;;
    3.*)
	COMPILER_VERSION="3.*"
	;;
    [1-9][0-9]|[1-9][0-9].*|[7-9]|[4-9].*)
	COMPILER_VERSION="4.*"
	;;
    *)
	;;
    esac
    [ ! -z "$COMPILER_VERSION" ] && COMPILER="g++-${COMPILER_VERSION}"
    ;;
clang)
    # Clang
    QMAKE_CONF_COMPILER=`grep "QMAKE_CXX[^_A-Z0-9a-z]" $QMAKESPEC/qmake.conf | sed "s,.* *= *\(.*\)$,\1,"`
    COMPILER_VERSION=`${QMAKE_CONF_COMPILER} -dumpversion 2>/dev/null | sed 's,^[^0-9]*,,g'`
    case "$COMPILER_VERSION" in
    *)
	# Consider clang as compatible with g++-4.x and therefore the same build-key is used
	COMPILER="g++-4.*"
	;;
    esac
    ;;
*)
    #
    ;;
esac

# QMAKE_CONFIG can contain the following:
#
# Things that affect the TQt API/ABI:
#
#   Options:
#     minimal-config small-config medium-config large-config full-config
#
#   Modules:
#     styles tools kernel widgets dialogs workspace inputmethod
#
#   Enterprise/Open Source edition modules:
#     network canvas table xml opengl sql
#
#   Options:
#     stl
#
#     X11     : inputmethod-ext
#
# Things that do not affect the TQt API/ABI:
#     system-jpeg no-jpeg jpeg
#     system-mng no-mng mng
#     system-png no-png png
#     system-zlib no-zlib zlib
#     no-gif gif
#     debug release
#     dll staticlib
#
#     internal
#     nocrosscompiler
#     enterprise
#     thread
#     GNUmake
#     largefile
#     nis
#     nas
#     bigcodecs
#     tablet
#     ipv6
#
#     X11     : xftnameunparse x11sm xinerama xcursor xrandr xrender xftfreetype xkb inputmethod
#
ALL_OPTIONS="styles tools kernel widgets dialogs workspace inputmethod network canvas table xml opengl sql stl"
BUILD_CONFIG=
BUILD_OPTIONS=

# determine the build options
for config_option in $QMAKE_CONFIG; do
    SKIP="yes"
    case "$config_option" in
    *-config)
	# take the last *-config setting.  this is the highest config being used,
	# and is the one that we will use for tagging plugins
	BUILD_CONFIG="$config_option"
	;;

    styles|tools|kernel|widgets|dialogs|workspace|inputmethod|network|canvas|table|xml|opengl|sql|stl)
	# these config options affect the TQt API/ABI. they should influence
	# the generation of the buildkey, so we don't skip them
   	SKIP="no"
	;;

    *) # skip all other options since they don't affect the TQt API/ABI.
	;;
    esac

    if [ "$SKIP" = "no" ]; then
	BUILD_OPTIONS="$BUILD_OPTIONS $config_option"
    fi
done

# put the options that we are missing into .options
rm -f .options
for opt in `echo $ALL_OPTIONS`; do
    SKIP="no"
    if echo $BUILD_OPTIONS | grep $opt >/dev/null 2>&1; then
	SKIP="yes"
    fi
    if [ "$SKIP" = "no" ]; then
	echo "$opt" >> .options
    fi
done

# reconstruct BUILD_OPTIONS with a sorted negative feature list
# (ie. only things that are missing are will be put into the build key)
BUILD_OPTIONS=
if [ -f .options ]; then
    for opt in `sort -f .options | uniq`; do
	BUILD_OPTIONS="$BUILD_OPTIONS no-$opt"
    done
fi
rm -f .options

# QT_NO* defines affect the TQt API (and binary compatibility).  they need
# to be included in the build key
for build_option in $D_FLAGS; do
    case "$build_option" in
    QT_NO*)
	echo "$build_option" >> .options
	;;
    *)
	# skip all other compiler defines
	;;
    esac
done

# sort the compile time defines (helps ensure that changes in this configure
# script don't affect the TQT_BUILD_KEY generation)
if [ -f .options ]; then
    for opt in `sort -f .options | uniq`; do
	BUILD_OPTIONS="$BUILD_OPTIONS $opt"
    done
fi
rm -f .options

BUILD_OPTIONS="$BUILD_CONFIG $BUILD_OPTIONS"
TQT_BUILD_KEY="$CFG_USER_BUILD_KEY $UNAME_MACHINE $UNAME_SYSTEM $COMPILER $BUILD_OPTIONS"
# strip out leading/trailing/extra whitespace
TQT_BUILD_KEY=`echo $TQT_BUILD_KEY | sed -e "s,  *, ,g" -e "s,^  *,," -e "s,  *$,,"`

#-------------------------------------------------------------------------------
# part of configuration information goes into ntqconfig.h
#-------------------------------------------------------------------------------

case "$CFG_QCONFIG" in
full)
    echo "/* Everything */" >$outpath/include/ntqconfig.h.new
    ;;
*)
    QCONFIGFILE=qconfig-$CFG_QCONFIG.h
    echo "/* Copied from $QCONFIGFILE */" >$outpath/include/ntqconfig.h.new
    cat $relpath/src/tools/$QCONFIGFILE >>$outpath/include/ntqconfig.h.new
    ;;
esac
cat >> $outpath/include/ntqconfig.h.new <<EOF

/* License information */
#define TQT_PRODUCT_LICENSEE "$Licensee"
#define QT_PRODUCT_LICENSE  "$Products"

/* Build key */
#define TQT_BUILD_KEY "$TQT_BUILD_KEY"

/* Machine byte-order */
#define TQ_BIG_ENDIAN 4321
#define TQ_LITTLE_ENDIAN 1234
EOF
if [ "$CFG_ENDIAN" = "auto" ]; then
cat >> $outpath/include/ntqconfig.h.new << EOF
#if defined(__BIG_ENDIAN__)
# define TQ_BYTE_ORDER TQ_BIG_ENDIAN
#elif defined(__LITTLE_ENDIAN__)
# define TQ_BYTE_ORDER TQ_LITTLE_ENDIAN
#else
# message "Unable to determine byte order!"
#endif
EOF
else
echo "#define TQ_BYTE_ORDER $CFG_ENDIAN" >> $outpath/include/ntqconfig.h.new
fi

cat >> $outpath/include/ntqconfig.h.new << EOF
/* Compile time features */
EOF
[ '!' -z "$LicenseKey" ] && echo "#define QT_PRODUCT_LICENSEKEY \"$LicenseKey\"" >>$outpath/include/ntqconfig.h.new

if [ "$CFG_LARGEFILE" = "yes" ]; then
    echo "#define QT_LARGEFILE_SUPPORT 64" >>$outpath/include/ntqconfig.h.new
fi

$unixtests/ptrsize.test $XQMAKESPEC $OPT_VERBOSE $relpath $outpath
echo "#define TQT_POINTER_SIZE $?" >>$outpath/include/ntqconfig.h.new

if [ ! -z "$QT_MAC_VERSION" ]; then
    echo "#define QT_MACOSX_VERSION  ${QT_MAC_VERSION}  /*from config.tests*/" >>$outpath/include/ntqconfig.h.new
fi

## find excluded styles and add this to $QCONFIG_FLAGS

VSTYLE=no
VNO=no
for QMVAR in $QMAKE_VARS; do

STRIPPED=`echo $QMVAR | sed 's,^",,' | sed 's,"$,,'`

if [ "$VSTYLE" = "yes" ]; then
	if [ "$VNO" = "yes" ]; then
		NOSTYLE=`echo $STRIPPED | tr '[:lower:]' '[:upper:]'`
		QCONFIG_FLAGS="$QCONFIG_FLAGS TQT_NO_STYLE_$NOSTYLE"
		VSTYLE=no
		VNO=no
    	else
		if [ "$STRIPPED" = "-=" ]; then
			VNO=yes
		else
			VSTYLE=no
		fi
	fi
else
	if [ "$STRIPPED" = "styles" ]; then
		VSTYLE=yes
	fi
fi
done


if [ -n "$QCONFIG_FLAGS" ]; then
    for cfg in $QCONFIG_FLAGS; do

cat >>$outpath/include/ntqconfig.h.new << EOF
#ifndef $cfg
# define $cfg
#endif

EOF
    done
fi

# avoid unecessary rebuilds by copying only if ntqconfig.h has changed
if cmp -s $outpath/include/ntqconfig.h $outpath/include/ntqconfig.h.new; then
    rm -f $outpath/include/ntqconfig.h.new
else
    [ -f $outpath/include/ntqconfig.h ] && chmod +w $outpath/include/ntqconfig.h
    mv $outpath/include/ntqconfig.h.new $outpath/include/ntqconfig.h
    chmod -w $outpath/include/ntqconfig.h
fi


#-------------------------------------------------------------------------------
# save configuration into .qmake.cache
#-------------------------------------------------------------------------------

CACHEFILE=$outpath/.qmake.cache
[ -f $CACHEFILE.tmp ] && rm -f $CACHEFILE.tmp
cat >>$CACHEFILE.tmp <<EOF
CONFIG += $QMAKE_CONFIG dylib create_prl link_prl
QMAKESPEC = $XPLATFORM
QT_SOURCE_TREE = $relpath
QT_BUILD_TREE = $outpath
QMAKE_ABSOLUTE_SOURCE_ROOT = \$\$QT_SOURCE_TREE
EOF
# cmdline args
quoted=no
tmp=""
for i in $QMAKE_VARS; do
    if [ "$quoted" = "no" ]; then
	case "$i" in
	\"*\") echo $i | sed 's,^",,' | sed 's,"$,,' >>$CACHEFILE.tmp ;;
	\"*) quoted=yes ; tmp=$i ;;
	*) echo $i >>$CACHEFILE.tmp ;;
	esac
    else
	case "$i" in
	*\") quoted=no
	   echo $tmp $i | sed 's,^",,' | sed 's,"$,,' >>$CACHEFILE.tmp
	   tmp="" ;;
	*) tmp="$tmp $i" >>$CACHEFILE.tmp ;;
    esac
    fi
done
# incrementals
INCREMENTAL=""
[ "$CFG_INCREMENTAL" = "auto" ] && $WHICH p4 >/dev/null 2>&1 && [ "$Edition" = "troll" ] && CFG_INCREMENTAL="yes"
if [ "$CFG_INCREMENTAL" = "yes" ]; then
    openfiles=`find $relpath -perm u+w -mtime -3 | grep 'cpp$'`
    for f in $openfiles; do
	# don't need to worry about generated files
	[ -r `echo $f | sed "s,cpp$,ui,"` ] && continue
	basename $f | grep '^moc_' >/dev/null 2>&1 && continue
	# done
	INCREMENTAL="$INCREMENTAL `basename $f | sed 's,.cpp,.o,'`"
    done
    [ '!' -z "$INCREMENTAL" ] && echo "QMAKE_INCREMENTAL += $INCREMENTAL" >>$CACHEFILE.tmp
    [ -r "$outpath/.qmake.incremental" ] && echo "include($outpath/.qmake.incremental)" >>$CACHEFILE.tmp
fi

# replace .qmake.cache if it differs from the newly created temp file
if cmp -s $CACHEFILE.tmp $CACHEFILE; then
    rm -f $CACHEFILE.tmp
else
    mv -f $CACHEFILE.tmp $CACHEFILE
fi


#-------------------------------------------------------------------------------
# give feedback on configuration
#-------------------------------------------------------------------------------

case "$COMPILER" in
g++*)
    if [ "$CFG_EXCEPTION_SUPPORT" != "no" ]; then
	cat <<EOF

	This target is using the GNU C++ compiler ($PLATFORM).

	Recent versions of this compiler automatically include code for
	exceptions, which increase both the size of the TQt library and the
	amount of memory taken by your applications.

	You may choose to re-run `basename $0` with the -no-exceptions
	option to compile TQt without exceptions. This is completely binary
	compatible, and existing applications should continue to work.

EOF
    fi
    ;;
cc*)
    case "$PLATFORM" in
    irix-cc*)
	if [ "$CFG_EXCEPTION_SUPPORT" != "no" ]; then
	    cat <<EOF

	This target is using the MIPSpro C++ compiler ($PLATFORM).

	You may choose to re-run `basename $0` with the -no-exceptions
	option to compile TQt without exceptions. This will make the
	size of the TQt library smaller and reduce the amount of memory
	taken by your applications.

EOF
	fi
	;;
    *) ;;
    esac
    ;;
*) ;;
esac

echo
if [ "$XPLATFORM" = "$PLATFORM" ]; then
    echo "Build type:    $PLATFORM"
else
    echo "Building on:   $PLATFORM"
    echo "Building for:  $XPLATFORM"
fi

if [ -n "$PLATFORM_NOTES" ]; then
    echo "Platform notes:"
    echo "$PLATFORM_NOTES"
else
    echo
fi

if [ "$OPT_VERBOSE" = "yes" ]; then
    echo "qmake vars ...... $QMAKE_VARS"
    echo "qmake switches .. $QMAKE_SWITCHES"
fi

[ "$OPT_CONCURRENT" != "0" ] && echo "Concurrent .......... $OPT_CONCURRENT"
[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ......... $INCREMENTAL"
echo "Configuration ....... $QMAKE_CONFIG"
echo "STL support ......... $CFG_STL"
echo "PCH support ......... $CFG_PRECOMPILE"
echo "IPv6 support ........ $CFG_IPV6"
echo "Thread support ...... $CFG_THREAD"
echo "NIS support ......... $CFG_NIS"
echo "CUPS support ........ $CFG_CUPS"
if [ "$CFG_LARGEFILE" = "yes" ]; then
    echo "Large File support .. partial"
else
    echo "Large File support .. $CFG_LARGEFILE"
fi
echo "GIF support ......... $CFG_GIF"
if [ "$CFG_MNG" = "no" ]; then
    echo "MNG support ......... $CFG_MNG"
else
    echo "MNG support ......... $CFG_MNG ($CFG_LIBMNG)"
fi
if [ "$CFG_JPEG" = "no" ]; then
    echo "JPEG support ........ $CFG_JPEG"
else
    echo "JPEG support ........ $CFG_JPEG ($CFG_LIBJPEG)"
fi
if [ "$CFG_PNG" = "no" ]; then
    echo "PNG support ......... $CFG_PNG"
else
    echo "PNG support ......... $CFG_PNG ($CFG_LIBPNG)"
fi
if [ "$CFG_GLIBMAINLOOP" = "no" ]; then
    echo "Glib main loop support ......... $CFG_GLIBMAINLOOP"
else
    echo "Glib main loop support ......... $CFG_GLIBMAINLOOP ($CFG_LIBGLIBMAINLOOP)"
fi
echo "zlib support ........ $CFG_ZLIB"
if echo $MODULES | grep opengl >/dev/null; then
    opengl=yes
else
    opengl=no
fi
echo "OpenGL support ...... $opengl"
if [ "$PLATFORM_X11" = "yes" ]; then
    echo "NAS sound support ... $CFG_NAS"
    echo "Session management .. $CFG_SM"
    echo "XShape support ...... $CFG_XSHAPE"
    echo "Xinerama support .... $CFG_XINERAMA"
    echo "Tablet support ...... $CFG_TABLET"
    echo "Xcursor support ..... $CFG_XCURSOR"
    echo "XRandR support ...... $CFG_XRANDR"
    echo "XRender support ..... $CFG_XRENDER"
    echo "Xft support ......... $CFG_FREETYPE"
    echo "XKB Support ......... $CFG_XKB"
    echo "immodule support .... $CFG_IM"
    echo "immodule ext support  $CFG_IM_EXT"
elif [ "$PLATFORM_MAC" = "yes" ]; then
    echo "Accessibility ....... $CFG_ACCESSIBILITY"
    echo "Tablet support ...... $CFG_TABLET"
fi

# complain about not being able to use plugins if we are using a static build
if [ "$CFG_SHARED" = "no" ]; then
    echo
    echo "WARNING: Using static linking will disable the use of plugins."
    echo "Make sure you compile ALL needed modules into the library."
    echo
fi
echo

sepath=`echo $relpath | sed -e 's/\\./\\\\./g'`
PROCS=1
EXEC=""


#-------------------------------------------------------------------------------
# build makefiles based on the configuration
#-------------------------------------------------------------------------------

echo "Finding project files. Please wait..."
if [ -z "$QMAKE_PROJECTS" ]; then
    QMAKE_PROJECTS=`find $relpath/. -name '.pc' -prune -o -name '*.pro' -print | sed 's-/\./-/-'`
else
    QT_PROJECTS=
    for a in `echo $QMAKE_PROJECTS`; do
	put_in="$a"
	for leave_out in `echo $QMAKE_IGNORE_PROJECTS`; do
	    if [ "$put_in" = "$leave_out" ]; then
		put_in=
		break;
	    fi
	done
	[ ! -z "$put_in" ] && QT_PROJECTS="$QT_PROJECTS $put_in"
    done
    if [ -e "${relpath}/projects.pro" ]; then
	for mkfile in "${outpath}/Makefile" "${outpath}/GNUmakefile"; do
	    [ -f "$mkfile" ] && chmod +w "$mkfile"
	    $outpath/bin/tqmake "QT_PROJECTS=$QT_PROJECTS" ${relpath}/projects.pro -o $mkfile
	done
    fi
fi

# .projects      -> projects to process
# .projects.1    -> qt and moc
# .projects.2    -> subdirs and libs
# .projects.3    -> the rest
rm -f .projects .projects.1 .projects.2 .projects.3

if [ -z "$AWK" ]; then
    for p in `echo $QMAKE_PROJECTS`; do
	echo $p >> .projects
    done
else
    cat >projects.awk <<EOF
BEGIN {
    files = 0
    target_file = ""
    input_file = ""

    first = "./.projects.1.tmp"
    second = "./.projects.2.tmp"
    third = "./.projects.3.tmp"
}

FNR == 1 {
    if ( input_file ) {
  if ( ! target_file )
      target_file = third
  print input_file >target_file
    }

    matched_target = 0
    template_lib = 0
    input_file = FILENAME
    target_file = ""
}

/^(TARGET.*=)/ {
    if ( \$3 == "qt" || \$3 == "moc" ) {
  target_file = first
	matched_target = 1
    }
}

matched_target == 0 && /^(TEMPLATE.*=)/ {
    if ( \$3 == "subdirs" )
  target_file = second
    else if ( \$3 == "lib" )
  template_lib = 1
    else
  target_file = third
}

matched_target == 0 && template_lib == 1 && /^(CONFIG.*=)/ {
    if ( \$0 ~ /plugin/ )
	target_file = third
    else
  target_file = second
}

END {
    if ( input_file ) {
  if ( ! target_file )
      target_file = third
  print input_file >>target_file
    }
}

EOF

    rm -f .projects.all
    for p in `echo $QMAKE_PROJECTS`; do
       echo $p >> .projects.all
    done

    # if you get errors about the length of the command line to awk, change the -l arg
    # to split below
    split -l 100 .projects.all .projects.all.
    for p in .projects.all.*; do
       $AWK -f projects.awk `cat $p`
       [ -f .projects.1.tmp ] && cat .projects.1.tmp >> .projects.1
       [ -f .projects.2.tmp ] && cat .projects.2.tmp >> .projects.2
       [ -f .projects.3.tmp ] && cat .projects.3.tmp >> .projects.3
       rm -f .projects.1.tmp .projects.2.tmp .projects.3.tmp $p
    done
    rm -f .projects.all* projects.awk

    [ -f .projects.1 ] && cat .projects.1 >>.projects
    [ -f .projects.2 ] && cat .projects.2 >>.projects
    rm -f .projects.1 .projects.2
    if [ -f .projects.3 ] && [ "$OPT_FAST" = "no" ]; then
       cat .projects.3 >>.projects
       rm -f .projects.3
    fi
fi
# don't sort TQt and MOC in with the other project files
# also work around a segfaulting uniq(1)
if [ -f .sorted.projects.2 ]; then
    sort .sorted.projects.2 > .sorted.projects.2.new
    mv -f .sorted.projects.2.new .sorted.projects.2
    cat .sorted.projects.2 >> .sorted.projects.1
fi
[ -f .sorted.projects.1 ] && sort .sorted.projects.1 >> .sorted.projects
rm -f .sorted.projects.2 .sorted.projects.1
for p in `echo $QMAKE_IGNORE_PROJECTS`; do
    if [ -f .projects ]; then
	grep -v $p .projects > .tmp
	mv -f .tmp .projects
    fi
    if [ -f .projects.3 ]; then
	grep -v $p .projects.3 > .tmp
	mv -f .tmp .projects.3
    fi
done

NORM_PROJECTS=0
FAST_PROJECTS=0
if [ -f .projects ]; then
   uniq .projects >.tmp
   mv -f .tmp .projects
   NORM_PROJECTS=`cat .projects | wc -l | sed -e "s, ,,g"`
fi
if [ -f .projects.3 ]; then
   uniq .projects.3 >.tmp
   mv -f .tmp .projects.3
   FAST_PROJECTS=`cat .projects.3 | wc -l | sed -e "s, ,,g"`
fi
echo "  `expr $NORM_PROJECTS + $FAST_PROJECTS` projects found."
echo

echo "Creating makefiles. Please wait..."
for file in .projects .projects.3; do
    [ '!' -f "$file" ] && continue
    for a in `cat $file`; do
	case $a in
	*-kde.pro|*qtmain.pro) continue ;;
	*/qmake/qmake.pro) continue ;;
	*projects.pro) continue ;;
	*-pro.pro)
	    [ "x$Edition" != "xpro" ] && continue
	;;
	*moc*) SPEC=$QMAKESPEC ;;
	*) SPEC=$XQMAKESPEC ;;
	esac
	dir=`dirname $a | sed -e "s;$sepath;.;g"`
	test -d $dir || mkdir -p $dir
	OUTDIR=$outpath/$dir
	if [ -f "${OUTDIR}/Makefile" ] && [ "$OPT_FAST" = "yes" ]; then
	    # fast configure - the makefile exists, skip it
	    # since the makefile exists, it was generated by qmake, which means we
	    # can skip it, since qmake has a rule to regenerate the makefile if the .pro
	    # file changes...
	    [ "$OPT_VERBOSE" = "yes" ] && echo "  skipping $a"
	    continue;
	fi
	QMAKE_SPEC_ARGS="-spec $SPEC"
	if echo '\c' | grep '\\c' >/dev/null; then
	    echo -n "  for $a"
	else
	    echo "  for $a\c"
	fi

	if [ "$file" = ".projects.3" ]; then
	    if echo '\c' | grep '\\c' >/dev/null; then
		echo -n " (fast)"
	    else
		echo " (fast)\c"
	    fi
	    echo
	    cat >${OUTDIR}/Makefile <<EOF
# ${OUTDIR}/Makefile: generated by configure
#
# WARNING: This makefile will be replaced with a real makefile.
# All changes made to this file will be lost.

all clean install qmake Makefile: FORCE
	$outpath/bin/tqmake $QMAKE_SWITCHES $QMAKE_SPEC_ARGS -o $OUTDIR $a
	cd $OUTDIR
	\$(MAKE) \$@

FORCE:

EOF
	else
	    EXEC="$outpath/bin/tqmake $QMAKE_SWITCHES $QMAKE_SPEC_ARGS -o $OUTDIR $a"
	    if [ "$OPT_VERBOSE" = "yes" ]; then
		echo " (`basename $SPEC`)"
		if echo '\c' | grep '\\c' >/dev/null; then
		    echo -n "$EXEC"
		else
		    echo "$EXEC\c"
		fi
	    fi
	    echo

	    [ -f "${OUTDIR}/Makefile" ] && chmod +w ${OUTDIR}/Makefile
	    if [ "$OPT_CONCURRENT" = "0" ] || [ "$OPT_CONCURRENT" = "1" ]; then
		/bin/sh -c "$EXEC"
	    else
		/bin/sh -c "$EXEC" &
		if [ "$PROCS" != "$OPT_CONCURRENT" ]; then
		    PROCS=`expr $PROCS + 1`
		else
		    PROCS=1
		    [ "$OPT_VERBOSE" = "yes" ] && echo "Waiting.."
		    wait #wait for the processes to end
		fi
	    fi
       fi
    done
done
rm -f .projects .projects.3

#Special Qt/Mac thing. We bootched permissions in TQt 3.3.0 beta 1.
#This is probably the only easy place to detect and remove it ourselves
if [ "$PLATFORM_MAC" = "yes" ]; then
    if [ -d /Library/Qt ]; then
        lslad=`ls -lad /Library/Qt | grep '^d......rwx'`
	if [ -z "$lslad" ]; then
	    echo
	    removed=no
	    rm -rf /Library/Qt && removed=yes
	    if [ "$removed" = "no" ]; then
		cat <<EOF

    The directory '/Library/Qt' has incorrect permissions and configure could
    not fix it automatically. Please remove this direcotry by hand.

EOF
	    fi
	fi
    fi
fi

#-------------------------------------------------------------------------------
# finally save the executed command to another script
#-------------------------------------------------------------------------------
if [ `basename $0` != "config.status" ]; then
    [ -f $outpath/config.status ] && rm -f $outpath/config.status
    echo "#!/bin/sh" >$outpath/config.status
    echo "if [ \"\$#\" -gt 0 ]; then" >>$outpath/config.status
    echo "  echo yes | $relpath/$relconf $OPT_CMDLINE \"\$@\"" >>$outpath/config.status
    echo "else" >>$outpath/config.status
    echo "  echo yes | $relpath/$relconf $OPT_CMDLINE" >>$outpath/config.status
    echo "fi" >>$outpath/config.status
    chmod +x $outpath/config.status
fi

echo
echo TQt is now configured for building. Just run $MAKE.
echo To reconfigure, run $MAKE confclean and configure.
echo