summaryrefslogtreecommitdiffstats
path: root/Include/modsupport.h
blob: bf6478f4c2c5f15efa97bdf4f7bab2a29e48a2a9 (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

#ifndef Py_MODSUPPORT_H
#define Py_MODSUPPORT_H
#ifdef __cplusplus
extern "C" {
#endif

/* Module support interface */

#include <stdarg.h>

/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
   to mean Py_ssize_t */
#ifdef PY_SSIZE_T_CLEAN
#define PyArg_Parse			_PyArg_Parse_SizeT
#define PyArg_ParseTuple		_PyArg_ParseTuple_SizeT
#define PyArg_ParseTupleAndKeywords	_PyArg_ParseTupleAndKeywords_SizeT
#define PyArg_VaParse			_PyArg_VaParse_SizeT
#define PyArg_VaParseTupleAndKeywords	_PyArg_VaParseTupleAndKeywords_SizeT
#define Py_BuildValue			_Py_BuildValue_SizeT
#define Py_VaBuildValue			_Py_VaBuildValue_SizeT
#else
PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
#endif

PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
                                                  const char *, char **, ...);
PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw);
#endif

PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
                                                  const char *, char **, va_list);
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);

PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)

#define Py_CLEANUP_SUPPORTED 0x20000

#define PYTHON_API_VERSION 1013
#define PYTHON_API_STRING "1013"
/* The API version is maintained (independently from the Python version)
   so we can detect mismatches between the interpreter and dynamically
   loaded modules.  These are diagnosed by an error message but
   the module is still loaded (because the mismatch can only be tested
   after loading the module).  The error message is intended to
   explain the core dump a few seconds later.

   The symbol PYTHON_API_STRING defines the same value as a string
   literal.  *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***

   Please add a line or two to the top of this log for each API
   version change:

   22-Feb-2006  MvL	1013	PEP 353 - long indices for sequence lengths

   19-Aug-2002  GvR	1012	Changes to string object struct for
   				interning changes, saving 3 bytes.

   17-Jul-2001	GvR	1011	Descr-branch, just to be on the safe side

   25-Jan-2001  FLD     1010    Parameters added to PyCode_New() and
                                PyFrame_New(); Python 2.1a2

   14-Mar-2000  GvR     1009    Unicode API added

   3-Jan-1999	GvR	1007	Decided to change back!  (Don't reuse 1008!)

   3-Dec-1998	GvR	1008	Python 1.5.2b1

   18-Jan-1997	GvR	1007	string interning and other speedups

   11-Oct-1996	GvR	renamed Py_Ellipses to Py_Ellipsis :-(

   30-Jul-1996	GvR	Slice and ellipses syntax added

   23-Jul-1996	GvR	For 1.4 -- better safe than sorry this time :-)

   7-Nov-1995	GvR	Keyword arguments (should've been done at 1.3 :-( )

   10-Jan-1995	GvR	Renamed globals to new naming scheme

   9-Jan-1995	GvR	Initial version (incompatible with older API)
*/

/* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
   Python 3, it will stay at the value of 3; changes to the limited API
   must be performed in a strictly backwards-compatible manner. */
#define PYTHON_ABI_VERSION 3
#define PYTHON_ABI_STRING "3"

#ifdef Py_TRACE_REFS
 /* When we are tracing reference counts, rename PyModule_Create2 so
    modules compiled with incompatible settings will generate a
    link-time error. */
 #define PyModule_Create2 PyModule_Create2TraceRefs
#endif

PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
                                     int apiver);

#ifdef Py_LIMITED_API
#define PyModule_Create(module) \
	PyModule_Create2(module, PYTHON_ABI_VERSION)
#else
#define PyModule_Create(module) \
	PyModule_Create2(module, PYTHON_API_VERSION)
#endif

#ifndef Py_LIMITED_API
PyAPI_DATA(char *) _Py_PackageContext;
#endif

#ifdef __cplusplus
}
#endif
#endif /* !Py_MODSUPPORT_H */
id='n486' href='#n486'>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 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/

#include "configureapp.h"
#include "environment.h"
#ifdef COMMERCIAL_VERSION
#  include "tools.h"
#endif

#include <QDate>
#include <qdir.h>
#include <qtemporaryfile.h>
#include <qstack.h>
#include <qdebug.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#include <qregexp.h>
#include <qhash.h>

#include <iostream>
#include <windows.h>
#include <conio.h>

QT_BEGIN_NAMESPACE

std::ostream &operator<<( std::ostream &s, const QString &val ) {
    s << val.toLocal8Bit().data();
    return s;
}


using namespace std;

// Macros to simplify options marking
#define MARK_OPTION(x,y) ( dictionary[ #x ] == #y ? "*" : " " )


bool writeToFile(const char* text, const QString &filename)
{
    QByteArray symFile(text);
    QFile file(filename);
    QDir dir(QFileInfo(file).absoluteDir());
    if (!dir.exists())
        dir.mkpath(dir.absolutePath());
    if (!file.open(QFile::WriteOnly)) {
        cout << "Couldn't write to " << qPrintable(filename) << ": " << qPrintable(file.errorString())
             << endl;
        return false;
    }
    file.write(symFile);
    return true;
}

Configure::Configure( int& argc, char** argv )
{
    useUnixSeparators = false;
    // Default values for indentation
    optionIndent = 4;
    descIndent   = 25;
    outputWidth  = 0;
    // Get console buffer output width
    CONSOLE_SCREEN_BUFFER_INFO info;
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleScreenBufferInfo(hStdout, &info))
        outputWidth = info.dwSize.X - 1;
    outputWidth = qMin(outputWidth, 79); // Anything wider gets unreadable
    if (outputWidth < 35) // Insanely small, just use 79
        outputWidth = 79;
    int i;

    /*
    ** Set up the initial state, the default
    */
    dictionary[ "CONFIGCMD" ] = argv[ 0 ];

    for ( i = 1; i < argc; i++ )
        configCmdLine += argv[ i ];


    // Get the path to the executable
    wchar_t module_name[MAX_PATH];
    GetModuleFileName(0, module_name, sizeof(module_name) / sizeof(wchar_t));
    QFileInfo sourcePathInfo = QString::fromWCharArray(module_name);
    sourcePath = sourcePathInfo.absolutePath();
    sourceDir = sourcePathInfo.dir();
    buildPath = QDir::currentPath();
#if 0
    const QString installPath = QString("C:\\Qt\\%1").arg(QT_VERSION_STR);
#else
    const QString installPath = buildPath;
#endif
    if(sourceDir != buildDir) { //shadow builds!
        if (!findFile("perl") && !findFile("perl.exe")) {
            cout << "Error: Creating a shadow build of Qt requires" << endl
                 << "perl to be in the PATH environment";
            exit(0); // Exit cleanly for Ctrl+C
        }

        cout << "Preparing build tree..." << endl;
        QDir(buildPath).mkpath("bin");

        { //duplicate qmake
            QStack<QString> qmake_dirs;
            qmake_dirs.push("qmake");
            while(!qmake_dirs.isEmpty()) {
                QString dir = qmake_dirs.pop();
                QString od(buildPath + "/" + dir);
                QString id(sourcePath + "/" + dir);
                QFileInfoList entries = QDir(id).entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries);
                for(int i = 0; i < entries.size(); ++i) {
                    QFileInfo fi(entries.at(i));
                    if(fi.isDir()) {
                        qmake_dirs.push(dir + "/" + fi.fileName());
                        QDir().mkpath(od + "/" + fi.fileName());
                    } else {
                        QDir().mkpath(od );
                        bool justCopy = true;
                        const QString fname = fi.fileName();
                        const QString outFile(od + "/" + fname), inFile(id + "/" + fname);
                        if(fi.fileName() == "Makefile") { //ignore
                        } else if(fi.suffix() == "h" || fi.suffix() == "cpp") {
                            QTemporaryFile tmpFile;
                            if(tmpFile.open()) {
                                QTextStream stream(&tmpFile);
                                stream << "#include \"" << inFile << "\"" << endl;
                                justCopy = false;
                                stream.flush();
                                tmpFile.flush();
                                if(filesDiffer(tmpFile.fileName(), outFile)) {
                                    QFile::remove(outFile);
                                    tmpFile.copy(outFile);
                                }
                            }
                        }
                        if(justCopy && filesDiffer(inFile, outFile))
                            QFile::copy(inFile, outFile);
                    }
                }
            }
        }

        { //make a syncqt script(s) that can be used in the shadow
            QFile syncqt(buildPath + "/bin/syncqt");
            if(syncqt.open(QFile::WriteOnly)) {
                QTextStream stream(&syncqt);
                stream << "#!/usr/bin/perl -w" << endl
                       << "require \"" << sourcePath + "/bin/syncqt\";" << endl;
            }
            QFile syncqt_bat(buildPath + "/bin/syncqt.bat");
            if(syncqt_bat.open(QFile::WriteOnly)) {
                QTextStream stream(&syncqt_bat);
                stream << "@echo off" << endl
                       << "set QTDIR=" << QDir::toNativeSeparators(sourcePath) << endl
                       << "call " << fixSeparators(sourcePath) << fixSeparators("/bin/syncqt.bat -outdir \"") << fixSeparators(buildPath) << "\"" << endl
                       << "set QTDIR=" << QDir::toNativeSeparators(buildPath) << endl;
                syncqt_bat.close();
            }
        }

        // For Windows CE and shadow builds we need to copy these to the
        // build directory.
        QFile::copy(sourcePath + "/bin/setcepaths.bat" , buildPath + "/bin/setcepaths.bat");

        //copy the mkspecs
        buildDir.mkpath("mkspecs");
        if(!Environment::cpdir(sourcePath + "/mkspecs", buildPath + "/mkspecs")){
            cout << "Couldn't copy mkspecs!" << sourcePath << " " << buildPath << endl;
            dictionary["DONE"] = "error";
            return;
        }
    }

    dictionary[ "QT_SOURCE_TREE" ]    = fixSeparators(sourcePath);
    dictionary[ "QT_BUILD_TREE" ]     = fixSeparators(buildPath);
    dictionary[ "QT_INSTALL_PREFIX" ] = fixSeparators(installPath);

    dictionary[ "QMAKESPEC" ] = getenv("QMAKESPEC");
    if (dictionary[ "QMAKESPEC" ].size() == 0) {
        dictionary[ "QMAKESPEC" ] = Environment::detectQMakeSpec();
        dictionary[ "QMAKESPEC_FROM" ] = "detected";
    } else {
        dictionary[ "QMAKESPEC_FROM" ] = "env";
    }

    dictionary[ "ARCHITECTURE" ]    = "windows";
    dictionary[ "QCONFIG" ]         = "full";
    dictionary[ "EMBEDDED" ]        = "no";
    dictionary[ "BUILD_QMAKE" ]     = "yes";
    dictionary[ "DSPFILES" ]        = "yes";
    dictionary[ "VCPROJFILES" ]     = "yes";
    dictionary[ "QMAKE_INTERNAL" ]  = "no";
    dictionary[ "FAST" ]            = "no";
    dictionary[ "NOPROCESS" ]       = "no";
    dictionary[ "STL" ]             = "yes";
    dictionary[ "EXCEPTIONS" ]      = "yes";
    dictionary[ "RTTI" ]            = "yes";
    dictionary[ "MMX" ]             = "auto";
    dictionary[ "3DNOW" ]           = "auto";
    dictionary[ "SSE" ]             = "auto";
    dictionary[ "SSE2" ]            = "auto";
    dictionary[ "IWMMXT" ]          = "auto";
    dictionary[ "SYNCQT" ]          = "auto";
    dictionary[ "CE_CRT" ]          = "no";
    dictionary[ "CETEST" ]          = "auto";
    dictionary[ "CE_SIGNATURE" ]    = "no";
    dictionary[ "SCRIPT" ]          = "auto";
    dictionary[ "SCRIPTTOOLS" ]     = "auto";
    dictionary[ "XMLPATTERNS" ]     = "auto";
    dictionary[ "PHONON" ]          = "auto";
    dictionary[ "PHONON_BACKEND" ]  = "yes";
    dictionary[ "MULTIMEDIA" ]      = "yes";
    dictionary[ "DIRECTSHOW" ]      = "no";
    dictionary[ "WEBKIT" ]          = "auto";
    dictionary[ "PLUGIN_MANIFESTS" ] = "yes";

    QString version;
    QFile qglobal_h(sourcePath + "/src/corelib/global/qglobal.h");
    if (qglobal_h.open(QFile::ReadOnly)) {
        QTextStream read(&qglobal_h);
        QRegExp version_regexp("^# *define *QT_VERSION_STR *\"([^\"]*)\"");
        QString line;
        while (!read.atEnd()) {
            line = read.readLine();
            if (version_regexp.exactMatch(line)) {
                version = version_regexp.cap(1).trimmed();
                if (!version.isEmpty())
                    break;
            }
        }
        qglobal_h.close();
    }

    if (version.isEmpty())
        version = QString("%1.%2.%3").arg(QT_VERSION>>16).arg(((QT_VERSION>>8)&0xff)).arg(QT_VERSION&0xff);

    dictionary[ "VERSION" ]         = version;
    {
        QRegExp version_re("([0-9]*)\\.([0-9]*)\\.([0-9]*)(|-.*)");
        if(version_re.exactMatch(version)) {
            dictionary[ "VERSION_MAJOR" ] = version_re.cap(1);
            dictionary[ "VERSION_MINOR" ] = version_re.cap(2);
            dictionary[ "VERSION_PATCH" ] = version_re.cap(3);
        }
    }

    dictionary[ "REDO" ]            = "no";
    dictionary[ "DEPENDENCIES" ]    = "no";

    dictionary[ "BUILD" ]           = "debug";
    dictionary[ "BUILDALL" ]        = "auto"; // Means yes, but not explicitly

    dictionary[ "BUILDTYPE" ]      = "none";

    dictionary[ "BUILDDEV" ]        = "no";
    dictionary[ "BUILDNOKIA" ]      = "no";

    dictionary[ "SHARED" ]          = "yes";

    dictionary[ "ZLIB" ]            = "auto";

    dictionary[ "GIF" ]             = "auto";
    dictionary[ "TIFF" ]            = "auto";
    dictionary[ "JPEG" ]            = "auto";
    dictionary[ "PNG" ]             = "auto";
    dictionary[ "MNG" ]             = "auto";
    dictionary[ "LIBTIFF" ]         = "auto";
    dictionary[ "LIBJPEG" ]         = "auto";
    dictionary[ "LIBPNG" ]          = "auto";
    dictionary[ "LIBMNG" ]          = "auto";
    dictionary[ "FREETYPE" ]        = "no";

    dictionary[ "QT3SUPPORT" ]      = "yes";
    dictionary[ "ACCESSIBILITY" ]   = "yes";
    dictionary[ "OPENGL" ]          = "yes";
    dictionary[ "OPENVG" ]          = "no";
    dictionary[ "IPV6" ]            = "yes"; // Always, dynamicly loaded
    dictionary[ "OPENSSL" ]         = "auto";
    dictionary[ "DBUS" ]            = "auto";
    dictionary[ "S60" ]             = "yes";

    dictionary[ "STYLE_WINDOWS" ]   = "yes";
    dictionary[ "STYLE_WINDOWSXP" ] = "auto";
    dictionary[ "STYLE_WINDOWSVISTA" ] = "auto";
    dictionary[ "STYLE_PLASTIQUE" ] = "yes";
    dictionary[ "STYLE_CLEANLOOKS" ]= "yes";
    dictionary[ "STYLE_WINDOWSCE" ] = "no";
    dictionary[ "STYLE_WINDOWSMOBILE" ] = "no";
    dictionary[ "STYLE_MOTIF" ]     = "yes";
    dictionary[ "STYLE_CDE" ]       = "yes";
    dictionary[ "STYLE_S60" ]       = "no";
    dictionary[ "STYLE_GTK" ]       = "no";

    dictionary[ "SQL_MYSQL" ]       = "no";
    dictionary[ "SQL_ODBC" ]        = "no";
    dictionary[ "SQL_OCI" ]         = "no";
    dictionary[ "SQL_PSQL" ]        = "no";
    dictionary[ "SQL_TDS" ]         = "no";
    dictionary[ "SQL_DB2" ]         = "no";
    dictionary[ "SQL_SQLITE" ]      = "auto";
    dictionary[ "SQL_SQLITE_LIB" ]  = "qt";
    dictionary[ "SQL_SQLITE2" ]     = "no";
    dictionary[ "SQL_IBASE" ]       = "no";
    dictionary[ "GRAPHICS_SYSTEM" ] = "raster";

    QString tmp = dictionary[ "QMAKESPEC" ];
    if (tmp.contains("\\")) {
        tmp = tmp.mid( tmp.lastIndexOf( "\\" ) + 1 );
    } else {
        tmp = tmp.mid( tmp.lastIndexOf("/") + 1 );
    }
    dictionary[ "QMAKESPEC" ] = tmp;

    dictionary[ "INCREDIBUILD_XGE" ] = "auto";
    dictionary[ "LTCG" ]            = "no";
}

Configure::~Configure()
{
    for (int i=0; i<3; ++i) {
        QList<MakeItem*> items = makeList[i];
        for (int j=0; j<items.size(); ++j)
            delete items[j];
    }
}

QString Configure::fixSeparators(QString somePath)
{
    return useUnixSeparators ?
           QDir::fromNativeSeparators(somePath) :
           QDir::toNativeSeparators(somePath);
}

// We could use QDir::homePath() + "/.qt-license", but
// that will only look in the first of $HOME,$USERPROFILE
// or $HOMEDRIVE$HOMEPATH. So, here we try'em all to be
// more forgiving for the end user..
QString Configure::firstLicensePath()
{
    QStringList allPaths;
    allPaths << "./.qt-license"
             << QString::fromLocal8Bit(getenv("HOME")) + "/.qt-license"
             << QString::fromLocal8Bit(getenv("USERPROFILE")) + "/.qt-license"
             << QString::fromLocal8Bit(getenv("HOMEDRIVE")) + QString::fromLocal8Bit(getenv("HOMEPATH")) + "/.qt-license";
    for (int i = 0; i< allPaths.count(); ++i)
        if (QFile::exists(allPaths.at(i)))
            return allPaths.at(i);
    return QString();
}


// #### somehow I get a compiler error about vc++ reaching the nesting limit without
// undefining the ansi for scoping.
#ifdef for
#undef for
#endif

void Configure::parseCmdLine()
{
    int argCount = configCmdLine.size();
    int i = 0;

#if !defined(EVAL)
    if (argCount < 1) // skip rest if no arguments
        ;
    else if( configCmdLine.at(i) == "-redo" ) {
        dictionary[ "REDO" ] = "yes";
        configCmdLine.clear();
        reloadCmdLine();
    }
    else if( configCmdLine.at(i) == "-loadconfig" ) {
        ++i;
        if (i != argCount) {
            dictionary[ "REDO" ] = "yes";
            dictionary[ "CUSTOMCONFIG" ] = "_" + configCmdLine.at(i);
            configCmdLine.clear();
            reloadCmdLine();
        } else {
            dictionary[ "HELP" ] = "yes";
        }
        i = 0;
    }
    argCount = configCmdLine.size();
#endif

    // Look first for XQMAKESPEC
    for(int j = 0 ; j < argCount; ++j)
    {
        if( configCmdLine.at(j) == "-xplatform") {
            ++j;
            if (j == argCount)
                break;
            dictionary["XQMAKESPEC"] = configCmdLine.at(j);
            if (!dictionary[ "XQMAKESPEC" ].isEmpty())
                applySpecSpecifics();
        }
    }

    for( ; i<configCmdLine.size(); ++i ) {
        bool continueElse[] = {false, false};
        if( configCmdLine.at(i) == "-help"
            || configCmdLine.at(i) == "-h"
            || configCmdLine.at(i) == "-?" )
            dictionary[ "HELP" ] = "yes";

#if !defined(EVAL)
        else if( configCmdLine.at(i) == "-qconfig" ) {
            ++i;
            if (i==argCount)
                break;
            dictionary[ "QCONFIG" ] = configCmdLine.at(i);
        }

        else if ( configCmdLine.at(i) == "-buildkey" ) {
            ++i;
            if (i==argCount)
                break;
            dictionary[ "USER_BUILD_KEY" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-release" ) {
            dictionary[ "BUILD" ] = "release";
            if (dictionary[ "BUILDALL" ] == "auto")
                dictionary[ "BUILDALL" ] = "no";
        } else if( configCmdLine.at(i) == "-debug" ) {
            dictionary[ "BUILD" ] = "debug";
            if (dictionary[ "BUILDALL" ] == "auto")
                dictionary[ "BUILDALL" ] = "no";
        } else if( configCmdLine.at(i) == "-debug-and-release" )
            dictionary[ "BUILDALL" ] = "yes";

        else if( configCmdLine.at(i) == "-shared" )
            dictionary[ "SHARED" ] = "yes";
        else if( configCmdLine.at(i) == "-static" )
            dictionary[ "SHARED" ] = "no";
        else if( configCmdLine.at(i) == "-developer-build" )
            dictionary[ "BUILDDEV" ] = "yes";
        else if( configCmdLine.at(i) == "-nokia-developer" ) {
            cout << "Detected -nokia-developer option" << endl;
            cout << "Nokia employees and agents are allowed to use this software under" << endl;
            cout << "the authority of Nokia Corporation and/or its subsidiary(-ies)" << endl;
            dictionary[ "BUILDNOKIA" ] = "yes";
            dictionary[ "BUILDDEV" ] = "yes";
            dictionary["LICENSE_CONFIRMED"] = "yes";
        }
        else if( configCmdLine.at(i) == "-opensource" ) {
            dictionary[ "BUILDTYPE" ] = "opensource";
        }
        else if( configCmdLine.at(i) == "-commercial" ) {
            dictionary[ "BUILDTYPE" ] = "commercial";
        }
        else if( configCmdLine.at(i) == "-ltcg" ) {
            dictionary[ "LTCG" ] = "yes";
        }
        else if( configCmdLine.at(i) == "-no-ltcg" ) {
            dictionary[ "LTCG" ] = "no";
        }
#endif

        else if( configCmdLine.at(i) == "-platform" ) {
            ++i;
            if (i==argCount)
                break;
            dictionary[ "QMAKESPEC" ] = configCmdLine.at(i);
        dictionary[ "QMAKESPEC_FROM" ] = "commandline";
        } else if( configCmdLine.at(i) == "-arch" ) {
            ++i;
            if (i==argCount)
                break;
            dictionary[ "ARCHITECTURE" ] = configCmdLine.at(i);
            if (configCmdLine.at(i) == "boundschecker") {
                dictionary[ "ARCHITECTURE" ] = "generic";   // Boundschecker uses the generic arch,
                qtConfig += "boundschecker";                // but also needs this CONFIG option
            }
        } else if( configCmdLine.at(i) == "-embedded" ) {
            dictionary[ "EMBEDDED" ] = "yes";
        } else if( configCmdLine.at(i) == "-xplatform") {
            ++i;
            // do nothing
        }


#if !defined(EVAL)
        else if( configCmdLine.at(i) == "-no-zlib" ) {
            // No longer supported since Qt 4.4.0
            // But save the information for later so that we can print a warning
            //
            // If you REALLY really need no zlib support, you can still disable
            // it by doing the following:
            //   add "no-zlib" to mkspecs/qconfig.pri
            //   #define QT_NO_COMPRESS (probably by adding to src/corelib/global/qconfig.h)
            //
            // There's no guarantee that Qt will build under those conditions

            dictionary[ "ZLIB_FORCED" ] = "yes";
        } else if( configCmdLine.at(i) == "-qt-zlib" ) {
            dictionary[ "ZLIB" ] = "qt";
        } else if( configCmdLine.at(i) == "-system-zlib" ) {
            dictionary[ "ZLIB" ] = "system";
        }

        // Image formats --------------------------------------------
        else if( configCmdLine.at(i) == "-no-gif" )
            dictionary[ "GIF" ] = "no";
        else if( configCmdLine.at(i) == "-qt-gif" )
            dictionary[ "GIF" ] = "auto";

        else if( configCmdLine.at(i) == "-no-libtiff" ) {
              dictionary[ "TIFF"] = "no";
              dictionary[ "LIBTIFF" ] = "no";
        } else if( configCmdLine.at(i) == "-qt-libtiff" ) {
            dictionary[ "TIFF" ] = "plugin";
            dictionary[ "LIBTIFF" ] = "qt";
        } else if( configCmdLine.at(i) == "-system-libtiff" ) {
              dictionary[ "TIFF" ] = "plugin";
              dictionary[ "LIBTIFF" ] = "system";
        }

        else if( configCmdLine.at(i) == "-no-libjpeg" ) {
            dictionary[ "JPEG" ] = "no";
            dictionary[ "LIBJPEG" ] = "no";
        } else if( configCmdLine.at(i) == "-qt-libjpeg" ) {
            dictionary[ "JPEG" ] = "plugin";
            dictionary[ "LIBJPEG" ] = "qt";
        } else if( configCmdLine.at(i) == "-system-libjpeg" ) {
            dictionary[ "JPEG" ] = "plugin";
            dictionary[ "LIBJPEG" ] = "system";
        }

        else if( configCmdLine.at(i) == "-no-libpng" ) {
            dictionary[ "PNG" ] = "no";
            dictionary[ "LIBPNG" ] = "no";
        } else if( configCmdLine.at(i) == "-qt-libpng" ) {
            dictionary[ "PNG" ] = "qt";
            dictionary[ "LIBPNG" ] = "qt";
        } else if( configCmdLine.at(i) == "-system-libpng" ) {
            dictionary[ "PNG" ] = "qt";
            dictionary[ "LIBPNG" ] = "system";
        }

        else if( configCmdLine.at(i) == "-no-libmng" ) {
            dictionary[ "MNG" ] = "no";
            dictionary[ "LIBMNG" ] = "no";
        } else if( configCmdLine.at(i) == "-qt-libmng" ) {
            dictionary[ "MNG" ] = "qt";
            dictionary[ "LIBMNG" ] = "qt";
        } else if( configCmdLine.at(i) == "-system-libmng" ) {
            dictionary[ "MNG" ] = "qt";
            dictionary[ "LIBMNG" ] = "system";
        }

        // Text Rendering --------------------------------------------
        else if( configCmdLine.at(i) == "-no-freetype" )
            dictionary[ "FREETYPE" ] = "no";
        else if( configCmdLine.at(i) == "-qt-freetype" )
            dictionary[ "FREETYPE" ] = "yes";

        // CE- C runtime --------------------------------------------
        else if( configCmdLine.at(i) == "-crt" ) {
            ++i;
            if (i==argCount)
                break;
            QDir cDir(configCmdLine.at(i));
            if (!cDir.exists())
                cout << "WARNING: Could not find directory (" << qPrintable(configCmdLine.at(i)) << ")for C runtime deployment" << endl;
            else
                dictionary[ "CE_CRT" ] = QDir::toNativeSeparators(cDir.absolutePath());
        } else if (configCmdLine.at(i) == "-qt-crt") {
            dictionary[ "CE_CRT" ] = "yes";
        } else if (configCmdLine.at(i) == "-no-crt") {
            dictionary[ "CE_CRT" ] = "no";
        }
        // cetest ---------------------------------------------------
        else if (configCmdLine.at(i) == "-no-cetest") {
            dictionary[ "CETEST" ] = "no";
            dictionary[ "CETEST_REQUESTED" ] = "no";
        } else if (configCmdLine.at(i) == "-cetest") {
            // although specified to use it, we stay at "auto" state
            // this is because checkAvailability() adds variables
            // we need for crosscompilation; but remember if we asked
            // for it.
            dictionary[ "CETEST_REQUESTED" ] = "yes";
        }
        // Qt/CE - signing tool -------------------------------------
        else if( configCmdLine.at(i) == "-signature") {
            ++i;
            if (i==argCount)
                break;
            QFileInfo info(configCmdLine.at(i));
            if (!info.exists())
                cout << "WARNING: Could not find signature file (" << qPrintable(configCmdLine.at(i)) << ")" << endl;
            else
                dictionary[ "CE_SIGNATURE" ] = QDir::toNativeSeparators(info.absoluteFilePath());
        }
        // Styles ---------------------------------------------------
        else if( configCmdLine.at(i) == "-qt-style-windows" )
            dictionary[ "STYLE_WINDOWS" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-windows" )
            dictionary[ "STYLE_WINDOWS" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-windowsce" )
            dictionary[ "STYLE_WINDOWSCE" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-windowsce" )
            dictionary[ "STYLE_WINDOWSCE" ] = "no";
        else if( configCmdLine.at(i) == "-qt-style-windowsmobile" )
            dictionary[ "STYLE_WINDOWSMOBILE" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-windowsmobile" )
            dictionary[ "STYLE_WINDOWSMOBILE" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-windowsxp" )
            dictionary[ "STYLE_WINDOWSXP" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-windowsxp" )
            dictionary[ "STYLE_WINDOWSXP" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-windowsvista" )
            dictionary[ "STYLE_WINDOWSVISTA" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-windowsvista" )
            dictionary[ "STYLE_WINDOWSVISTA" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-plastique" )
            dictionary[ "STYLE_PLASTIQUE" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-plastique" )
            dictionary[ "STYLE_PLASTIQUE" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-cleanlooks" )
            dictionary[ "STYLE_CLEANLOOKS" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-cleanlooks" )
            dictionary[ "STYLE_CLEANLOOKS" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-motif" )
            dictionary[ "STYLE_MOTIF" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-motif" )
            dictionary[ "STYLE_MOTIF" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-cde" )
            dictionary[ "STYLE_CDE" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-cde" )
            dictionary[ "STYLE_CDE" ] = "no";

        else if( configCmdLine.at(i) == "-qt-style-s60" )
            dictionary[ "STYLE_S60" ] = "yes";
        else if( configCmdLine.at(i) == "-no-style-s60" )
            dictionary[ "STYLE_S60" ] = "no";

        // Qt 3 Support ---------------------------------------------
        else if( configCmdLine.at(i) == "-no-qt3support" )
            dictionary[ "QT3SUPPORT" ] = "no";

        // Work around compiler nesting limitation
        else
            continueElse[1] = true;
        if (!continueElse[1]) {
        }

        // OpenGL Support -------------------------------------------
        else if( configCmdLine.at(i) == "-no-opengl" ) {
            dictionary[ "OPENGL" ]    = "no";
        } else if ( configCmdLine.at(i) == "-opengl-es-cm" ) {
            dictionary[ "OPENGL" ]          = "yes";
            dictionary[ "OPENGL_ES_CM" ]    = "yes";
        } else if ( configCmdLine.at(i) == "-opengl-es-cl" ) {
            dictionary[ "OPENGL" ]          = "yes";
            dictionary[ "OPENGL_ES_CL" ]    = "yes";
        } else if ( configCmdLine.at(i) == "-opengl-es-2" ) {
            dictionary[ "OPENGL" ]          = "yes";
            dictionary[ "OPENGL_ES_2" ]     = "yes";
        }

        // OpenVG Support -------------------------------------------
        else if( configCmdLine.at(i) == "-openvg" ) {
            dictionary[ "OPENVG" ]    = "yes";
        } else if( configCmdLine.at(i) == "-no-openvg" ) {
            dictionary[ "OPENVG" ]    = "no";
        }

        // Databases ------------------------------------------------
        else if( configCmdLine.at(i) == "-qt-sql-mysql" )
            dictionary[ "SQL_MYSQL" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-mysql" )
            dictionary[ "SQL_MYSQL" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-mysql" )
            dictionary[ "SQL_MYSQL" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-odbc" )
            dictionary[ "SQL_ODBC" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-odbc" )
            dictionary[ "SQL_ODBC" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-odbc" )
            dictionary[ "SQL_ODBC" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-oci" )
            dictionary[ "SQL_OCI" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-oci" )
            dictionary[ "SQL_OCI" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-oci" )
            dictionary[ "SQL_OCI" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-psql" )
            dictionary[ "SQL_PSQL" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-psql" )
            dictionary[ "SQL_PSQL" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-psql" )
            dictionary[ "SQL_PSQL" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-tds" )
            dictionary[ "SQL_TDS" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-tds" )
            dictionary[ "SQL_TDS" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-tds" )
            dictionary[ "SQL_TDS" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-db2" )
            dictionary[ "SQL_DB2" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-db2" )
            dictionary[ "SQL_DB2" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-db2" )
            dictionary[ "SQL_DB2" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-sqlite" )
            dictionary[ "SQL_SQLITE" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-sqlite" )
            dictionary[ "SQL_SQLITE" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-sqlite" )
            dictionary[ "SQL_SQLITE" ] = "no";
        else if( configCmdLine.at(i) == "-system-sqlite" )
            dictionary[ "SQL_SQLITE_LIB" ] = "system";
        else if( configCmdLine.at(i) == "-qt-sql-sqlite2" )
            dictionary[ "SQL_SQLITE2" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-sqlite2" )
            dictionary[ "SQL_SQLITE2" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-sqlite2" )
            dictionary[ "SQL_SQLITE2" ] = "no";

        else if( configCmdLine.at(i) == "-qt-sql-ibase" )
            dictionary[ "SQL_IBASE" ] = "yes";
        else if( configCmdLine.at(i) == "-plugin-sql-ibase" )
            dictionary[ "SQL_IBASE" ] = "plugin";
        else if( configCmdLine.at(i) == "-no-sql-ibase" )
            dictionary[ "SQL_IBASE" ] = "no";
#endif
        // IDE project generation -----------------------------------
        else if( configCmdLine.at(i) == "-no-dsp" )
            dictionary[ "DSPFILES" ] = "no";
        else if( configCmdLine.at(i) == "-dsp" )
            dictionary[ "DSPFILES" ] = "yes";

        else if( configCmdLine.at(i) == "-no-vcp" )
            dictionary[ "VCPFILES" ] = "no";
        else if( configCmdLine.at(i) == "-vcp" )
            dictionary[ "VCPFILES" ] = "yes";

        else if( configCmdLine.at(i) == "-no-vcproj" )
            dictionary[ "VCPROJFILES" ] = "no";
        else if( configCmdLine.at(i) == "-vcproj" )
            dictionary[ "VCPROJFILES" ] = "yes";

        else if( configCmdLine.at(i) == "-no-incredibuild-xge" )
            dictionary[ "INCREDIBUILD_XGE" ] = "no";
        else if( configCmdLine.at(i) == "-incredibuild-xge" )
            dictionary[ "INCREDIBUILD_XGE" ] = "yes";
#if !defined(EVAL)
        // Others ---------------------------------------------------
        else if (configCmdLine.at(i) == "-fpu" )
        {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "ARM_FPU_TYPE" ] = configCmdLine.at(i);
        }

        // S60 Support -------------------------------------------
        else if( configCmdLine.at(i) == "-s60" )
            dictionary[ "S60" ]    = "yes";
        else if( configCmdLine.at(i) == "-no-s60" )
            dictionary[ "S60" ]    = "no";

        else if (configCmdLine.at(i) == "-fast" )
            dictionary[ "FAST" ] = "yes";
        else if (configCmdLine.at(i) == "-no-fast" )
            dictionary[ "FAST" ] = "no";

        else if( configCmdLine.at(i) == "-stl" )
            dictionary[ "STL" ] = "yes";
        else if( configCmdLine.at(i) == "-no-stl" )
            dictionary[ "STL" ] = "no";

        else if ( configCmdLine.at(i) == "-exceptions" )
            dictionary[ "EXCEPTIONS" ] = "yes";
        else if ( configCmdLine.at(i) == "-no-exceptions" )
            dictionary[ "EXCEPTIONS" ] = "no";

        else if ( configCmdLine.at(i) == "-rtti" )
            dictionary[ "RTTI" ] = "yes";
        else if ( configCmdLine.at(i) == "-no-rtti" )
            dictionary[ "RTTI" ] = "no";

        else if( configCmdLine.at(i) == "-accessibility" )
            dictionary[ "ACCESSIBILITY" ] = "yes";
        else if( configCmdLine.at(i) == "-no-accessibility" ) {
            dictionary[ "ACCESSIBILITY" ] = "no";
            cout << "Setting accessibility to NO" << endl;
        }

        else if (configCmdLine.at(i) == "-no-mmx")
            dictionary[ "MMX" ] = "no";
        else if (configCmdLine.at(i) == "-mmx")
            dictionary[ "MMX" ] = "yes";
        else if (configCmdLine.at(i) == "-no-3dnow")
            dictionary[ "3DNOW" ] = "no";
        else if (configCmdLine.at(i) == "-3dnow")
            dictionary[ "3DNOW" ] = "yes";
        else if (configCmdLine.at(i) == "-no-sse")
            dictionary[ "SSE" ] = "no";
        else if (configCmdLine.at(i) == "-sse")
            dictionary[ "SSE" ] = "yes";
        else if (configCmdLine.at(i) == "-no-sse2")
            dictionary[ "SSE2" ] = "no";
        else if (configCmdLine.at(i) == "-sse2")
            dictionary[ "SSE2" ] = "yes";
        else if (configCmdLine.at(i) == "-no-iwmmxt")
            dictionary[ "IWMMXT" ] = "no";
        else if (configCmdLine.at(i) == "-iwmmxt")
            dictionary[ "IWMMXT" ] = "yes";

        else if( configCmdLine.at(i) == "-no-openssl" ) {
              dictionary[ "OPENSSL"] = "no";
        } else if( configCmdLine.at(i) == "-openssl" ) {
              dictionary[ "OPENSSL" ] = "yes";
        } else if( configCmdLine.at(i) == "-openssl-linked" ) {
              dictionary[ "OPENSSL" ] = "linked";
        } else if( configCmdLine.at(i) == "-no-qdbus" ) {
            dictionary[ "DBUS" ] = "no";
        } else if( configCmdLine.at(i) == "-qdbus" ) {
            dictionary[ "DBUS" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-dbus" ) {
            dictionary[ "DBUS" ] = "no";
        } else if( configCmdLine.at(i) == "-dbus" ) {
            dictionary[ "DBUS" ] = "yes";
        } else if( configCmdLine.at(i) == "-dbus-linked" ) {
            dictionary[ "DBUS" ] = "linked";
        } else if( configCmdLine.at(i) == "-no-script" ) {
            dictionary[ "SCRIPT" ] = "no";
        } else if( configCmdLine.at(i) == "-script" ) {
            dictionary[ "SCRIPT" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-scripttools" ) {
            dictionary[ "SCRIPTTOOLS" ] = "no";
        } else if( configCmdLine.at(i) == "-scripttools" ) {
            dictionary[ "SCRIPTTOOLS" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-xmlpatterns" ) {
            dictionary[ "XMLPATTERNS" ] = "no";
        } else if( configCmdLine.at(i) == "-xmlpatterns" ) {
            dictionary[ "XMLPATTERNS" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-multimedia" ) {
            dictionary[ "MULTIMEDIA" ] = "no";
        } else if( configCmdLine.at(i) == "-multimedia" ) {
            dictionary[ "MULTIMEDIA" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-phonon" ) {
            dictionary[ "PHONON" ] = "no";
        } else if( configCmdLine.at(i) == "-phonon" ) {
            dictionary[ "PHONON" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-phonon-backend" ) {
            dictionary[ "PHONON_BACKEND" ] = "no";
        } else if( configCmdLine.at(i) == "-phonon-backend" ) {
            dictionary[ "PHONON_BACKEND" ] = "yes";
        } else if( configCmdLine.at(i) == "-phonon-wince-ds9" ) {
            dictionary[ "DIRECTSHOW" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-webkit" ) {
            dictionary[ "WEBKIT" ] = "no";
        } else if( configCmdLine.at(i) == "-webkit" ) {
            dictionary[ "WEBKIT" ] = "yes";
        } else if( configCmdLine.at(i) == "-no-plugin-manifests" ) {
            dictionary[ "PLUGIN_MANIFESTS" ] = "no";
        } else if( configCmdLine.at(i) == "-plugin-manifests" ) {
            dictionary[ "PLUGIN_MANIFESTS" ] = "yes";
        }

        // Work around compiler nesting limitation
        else
            continueElse[0] = true;
        if (!continueElse[0]) {
        }

        else if( configCmdLine.at(i) == "-internal" )
            dictionary[ "QMAKE_INTERNAL" ] = "yes";

        else if( configCmdLine.at(i) == "-no-qmake" )
            dictionary[ "BUILD_QMAKE" ] = "no";
        else if( configCmdLine.at(i) == "-qmake" )
            dictionary[ "BUILD_QMAKE" ] = "yes";

        else if( configCmdLine.at(i) == "-dont-process" )
            dictionary[ "NOPROCESS" ] = "yes";
        else if( configCmdLine.at(i) == "-process" )
            dictionary[ "NOPROCESS" ] = "no";

        else if( configCmdLine.at(i) == "-no-qmake-deps" )
            dictionary[ "DEPENDENCIES" ] = "no";
        else if( configCmdLine.at(i) == "-qmake-deps" )
            dictionary[ "DEPENDENCIES" ] = "yes";


        else if( configCmdLine.at(i) == "-qtnamespace" ) {
            ++i;
            if(i==argCount)
                break;
            qmakeDefines += "QT_NAMESPACE="+configCmdLine.at(i);
        } else if( configCmdLine.at(i) == "-qtlibinfix" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_LIBINFIX" ] = configCmdLine.at(i);
        } else if( configCmdLine.at(i) == "-D" ) {
            ++i;
            if (i==argCount)
                break;
            qmakeDefines += configCmdLine.at(i);
        } else if( configCmdLine.at(i) == "-I" ) {
            ++i;
            if (i==argCount)
                break;
            qmakeIncludes += configCmdLine.at(i);
        } else if( configCmdLine.at(i) == "-L" ) {
            ++i;
            if (i==argCount)
                break;
            QFileInfo check(configCmdLine.at(i));
            if (!check.isDir()) {
                cout << "Argument passed to -L option is not a directory path. Did you mean the -l option?" << endl;
                dictionary[ "DONE" ] = "error";
                break;
            }
            qmakeLibs += QString("-L" + configCmdLine.at(i));
        } else if( configCmdLine.at(i) == "-l" ) {
            ++i;
            if (i==argCount)
                break;
            qmakeLibs += QString("-l" + configCmdLine.at(i));
        } else if (configCmdLine.at(i).startsWith("OPENSSL_LIBS=")) {
            opensslLibs = configCmdLine.at(i);
        }

        else if( ( configCmdLine.at(i) == "-override-version" ) || ( configCmdLine.at(i) == "-version-override" ) ){
            ++i;
            if (i==argCount)
                break;
            dictionary[ "VERSION" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-saveconfig" ) {
            ++i;
            if (i==argCount)
                break;
            dictionary[ "CUSTOMCONFIG" ] = "_" + configCmdLine.at(i);
        }

        else if (configCmdLine.at(i) == "-confirm-license") {
            dictionary["LICENSE_CONFIRMED"] = "yes";
        }

        else if (configCmdLine.at(i) == "-nomake") {
            ++i;
            if (i==argCount)
                break;
            disabledBuildParts += configCmdLine.at(i);
        }

        // Directories ----------------------------------------------
        else if( configCmdLine.at(i) == "-prefix" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_PREFIX" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-bindir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_BINS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-libdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_LIBS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-docdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_DOCS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-headerdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_HEADERS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-plugindir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_PLUGINS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-datadir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_DATA" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-translationdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_TRANSLATIONS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-examplesdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_EXAMPLES" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-demosdir" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_INSTALL_DEMOS" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-hostprefix" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "QT_HOST_PREFIX" ] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i) == "-make" ) {
            ++i;
            if(i==argCount)
                break;
            dictionary[ "MAKE" ] = configCmdLine.at(i);
        }

        else if (configCmdLine.at(i) == "-graphicssystem") {
            ++i;
            if (i == argCount)
                break;
            QString system = configCmdLine.at(i);
            if (system == QLatin1String("raster")
                || system == QLatin1String("opengl")
                || system == QLatin1String("openvg"))
                dictionary["GRAPHICS_SYSTEM"] = configCmdLine.at(i);
        }

        else if( configCmdLine.at(i).indexOf( QRegExp( "^-(en|dis)able-" ) ) != -1 ) {
            // Scan to see if any specific modules and drivers are enabled or disabled
            for( QStringList::Iterator module = modules.begin(); module != modules.end(); ++module ) {
                if( configCmdLine.at(i) == QString( "-enable-" ) + (*module) ) {
                    enabledModules += (*module);
                    break;
                }
                else if( configCmdLine.at(i) == QString( "-disable-" ) + (*module) ) {
                    disabledModules += (*module);
                    break;
                }
            }
        }

        else {
            dictionary[ "HELP" ] = "yes";
            cout << "Unknown option " << configCmdLine.at(i) << endl;
            break;
        }

#endif
    }

    // Ensure that QMAKESPEC exists in the mkspecs folder
    QDir mkspec_dir = fixSeparators(sourcePath + "/mkspecs");
    QStringList mkspecs = mkspec_dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);

    if (dictionary["QMAKESPEC"].toLower() == "features"
        || !mkspecs.contains(dictionary["QMAKESPEC"], Qt::CaseInsensitive)) {
        dictionary[ "HELP" ] = "yes";
        if (dictionary ["QMAKESPEC_FROM"] == "commandline") {
            cout << "Invalid option \"" << dictionary["QMAKESPEC"] << "\" for -platform." << endl;
        } else if (dictionary ["QMAKESPEC_FROM"] == "env") {
            cout << "QMAKESPEC environment variable is set to \"" << dictionary["QMAKESPEC"]
                 << "\" which is not a supported platform" << endl;
        } else { // was autodetected from environment
            cout << "Unable to detect the platform from environment. Use -platform command line"
                    "argument or set the QMAKESPEC environment variable and run configure again" << endl;
        }
        cout << "See the README file for a list of supported operating systems and compilers." << endl;
    } else {
        if( dictionary[ "QMAKESPEC" ].endsWith( "-icc" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc.net" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc2002" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc2003" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc2005" ) ||
            dictionary[ "QMAKESPEC" ].endsWith( "-msvc2008" )) {
            if ( dictionary[ "MAKE" ].isEmpty() ) dictionary[ "MAKE" ] = "nmake";
            dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32";
        } else if ( dictionary[ "QMAKESPEC" ] == QString( "win32-g++" ) ) {
            if ( dictionary[ "MAKE" ].isEmpty() ) dictionary[ "MAKE" ] = "mingw32-make";
            if (Environment::detectExecutable("sh.exe")) {
                dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32-g++-sh";
            } else {
                dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32-g++";
            }
        } else if ( dictionary[ "QMAKESPEC" ] == QString( "win32-mwc" ) ) {
                dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32-mwc";
                dictionary[ "MAKE" ] = "make";
        } else {
            if ( dictionary[ "MAKE" ].isEmpty() ) dictionary[ "MAKE" ] = "make";
            dictionary[ "QMAKEMAKEFILE" ] = "Makefile.win32";
        }
    }

    // Tell the user how to proceed building Qt after configure finished its job
    dictionary["QTBUILDINSTRUCTION"] = dictionary["MAKE"];
    if (dictionary.contains("XQMAKESPEC")) {
        if (dictionary["XQMAKESPEC"].startsWith("symbian")) {
            dictionary["QTBUILDINSTRUCTION"] = dictionary["MAKE"] + QString(" debug-winscw|debug-armv5|release-armv5");
        } else if (dictionary["XQMAKESPEC"].startsWith("wince")) {
            dictionary["QTBUILDINSTRUCTION"] =
                QString("setcepaths.bat ") + dictionary["XQMAKESPEC"] + QString(" && ") + dictionary["MAKE"];
        }
    }

    // Tell the user how to confclean before the next configure
    dictionary["CONFCLEANINSTRUCTION"] = dictionary["MAKE"] + QString(" confclean");

    // Ensure that -spec (XQMAKESPEC) exists in the mkspecs folder as well
    if (dictionary.contains("XQMAKESPEC") &&
        !mkspecs.contains(dictionary["XQMAKESPEC"], Qt::CaseInsensitive)) {
            dictionary["HELP"] = "yes";
            cout << "Invalid option \"" << dictionary["XQMAKESPEC"] << "\" for -xplatform." << endl;
    }

    // Ensure that the crt to be deployed can be found
    if (dictionary["CE_CRT"] != QLatin1String("yes") && dictionary["CE_CRT"] != QLatin1String("no")) {
        QDir cDir(dictionary["CE_CRT"]);
        QStringList entries = cDir.entryList();
        bool hasDebug = entries.contains("msvcr80.dll");
        bool hasRelease = entries.contains("msvcr80d.dll");
        if ((dictionary["BUILDALL"] == "auto") && (!hasDebug || !hasRelease)) {
            cout << "Could not find debug and release c-runtime." << endl;
            cout << "You need to have msvcr80.dll and msvcr80d.dll in" << endl;
            cout << "the path specified. Setting to -no-crt";
            dictionary[ "CE_CRT" ] = "no";
        } else if ((dictionary["BUILD"] == "debug") && !hasDebug) {
            cout << "Could not find debug c-runtime (msvcr80d.dll) in the directory specified." << endl;
            cout << "Setting c-runtime automatic deployment to -no-crt" << endl;
            dictionary[ "CE_CRT" ] = "no";
        } else if ((dictionary["BUILD"] == "release") && !hasRelease) {
            cout << "Could not find release c-runtime (msvcr80.dll) in the directory specified." << endl;
            cout << "Setting c-runtime automatic deployment to -no-crt" << endl;
            dictionary[ "CE_CRT" ] = "no";
        }
    }

    useUnixSeparators = (dictionary["QMAKESPEC"] == "win32-g++");

    // Allow tests for private classes to be compiled against internal builds
    if (dictionary["BUILDDEV"] == "yes")
        qtConfig += "private_tests";


#if !defined(EVAL)
    for( QStringList::Iterator dis = disabledModules.begin(); dis != disabledModules.end(); ++dis ) {
        modules.removeAll( (*dis) );
    }
    for( QStringList::Iterator ena = enabledModules.begin(); ena != enabledModules.end(); ++ena ) {
        if( modules.indexOf( (*ena) ) == -1 )
            modules += (*ena);
    }
    qtConfig += modules;

    for( QStringList::Iterator it = disabledModules.begin(); it != disabledModules.end(); ++it )
        qtConfig.removeAll(*it);

    if( ( dictionary[ "REDO" ] != "yes" ) && ( dictionary[ "HELP" ] != "yes" ) )
        saveCmdLine();
#endif
}

#if !defined(EVAL)
void Configure::validateArgs()
{
    // Validate the specified config

    // Get all possible configurations from the file system.
    QDir dir;
    QStringList filters;
    filters << "qconfig-*.h";
    dir.setNameFilters(filters);
    dir.setPath(sourcePath + "/src/corelib/global/");

    QStringList stringList =  dir.entryList();

    QStringList::Iterator it;
    for( it = stringList.begin(); it != stringList.end(); ++it )
        allConfigs << it->remove("qconfig-").remove(".h");
    allConfigs << "full";

    // Try internal configurations first.
    QStringList possible_configs = QStringList()
        << "minimal"
        << "small"
        << "medium"
        << "large"
        << "full";
    int index = possible_configs.indexOf(dictionary["QCONFIG"]);
    if (index >= 0) {
        for (int c = 0; c <= index; c++) {
            qmakeConfig += possible_configs[c] + "-config";
        }
        return;
    }

    // If the internal configurations failed, try others.
    QStringList::Iterator config;
    for( config = allConfigs.begin(); config != allConfigs.end(); ++config ) {
        if( (*config) == dictionary[ "QCONFIG" ] )
            break;
    }
    if( config == allConfigs.end() ) {
        dictionary[ "HELP" ] = "yes";
        cout << "No such configuration \"" << qPrintable(dictionary[ "QCONFIG" ]) << "\"" << endl ;
    }
    else
        qmakeConfig += (*config) + "-config";
}
#endif


// Output helper functions --------------------------------[ Start ]-
/*!
    Determines the length of a string token.
*/
static int tokenLength(const char *str)
{
    if (*str == 0)
        return 0;

    const char *nextToken = strpbrk(str, " _/\n\r");
    if (nextToken == str || !nextToken)
        return 1;

    return int(nextToken - str);
}

/*!
    Prints out a string which starts at position \a startingAt, and
    indents each wrapped line with \a wrapIndent characters.
    The wrap point is set to the console width, unless that width
    cannot be determined, or is too small.
*/
void Configure::desc(const char *description, int startingAt, int wrapIndent)
{
    int linePos = startingAt;

    bool firstLine = true;
    const char *nextToken = description;
    while (*nextToken) {
        int nextTokenLen = tokenLength(nextToken);
        if (*nextToken == '\n'                         // Wrap on newline, duh
            || (linePos + nextTokenLen > outputWidth)) // Wrap at outputWidth
        {
            printf("\n");
            linePos = 0;
            firstLine = false;
            if (*nextToken == '\n')
                ++nextToken;
            continue;
        }
        if (!firstLine && linePos < wrapIndent) {  // Indent to wrapIndent
            printf("%*s", wrapIndent , "");
            linePos = wrapIndent;
            if (*nextToken == ' ') {
                ++nextToken;
                continue;
            }
        }
        printf("%.*s", nextTokenLen, nextToken);
        linePos += nextTokenLen;
        nextToken += nextTokenLen;
    }
}

/*!
    Prints out an option with its description wrapped at the
    description starting point. If \a skipIndent is true, the
    indentation to the option is not outputted (used by marked option
    version of desc()). Extra spaces between option and its
    description is filled with\a fillChar, if there's available
    space.
*/
void Configure::desc(const char *option, const char *description, bool skipIndent, char fillChar)
{
    if (!skipIndent)
        printf("%*s", optionIndent, "");

    int remaining  = descIndent - optionIndent - strlen(option);
    int wrapIndent = descIndent + qMax(0, 1 - remaining);
    printf("%s", option);

    if (remaining > 2) {
        printf(" "); // Space in front
        for (int i = remaining; i > 2; --i)
            printf("%c", fillChar); // Fill, if available space
    }
    printf(" "); // Space between option and description

    desc(description, wrapIndent, wrapIndent);
    printf("\n");
}

/*!
    Same as above, except it also marks an option with an '*', if
    the option is default action.
*/
void Configure::desc(const char *mark_option, const char *mark, const char *option, const char *description, char fillChar)
{
    const QString markedAs = dictionary.value(mark_option);
    if (markedAs == "auto" && markedAs == mark) // both "auto", always => +
        printf(" +  ");
    else if (markedAs == "auto")                // setting marked as "auto" and option is default => +
        printf(" %c  " , (defaultTo(mark_option) == QLatin1String(mark))? '+' : ' ');
    else if (QLatin1String(mark) == "auto" && markedAs != "no")     // description marked as "auto" and option is available => +
        printf(" %c  " , checkAvailability(mark_option) ? '+' : ' ');
    else                                        // None are "auto", (markedAs == mark) => *
        printf(" %c  " , markedAs == QLatin1String(mark) ? '*' : ' ');

    desc(option, description, true, fillChar);
}

/*!
    Modifies the default configuration based on given -platform option.
    Eg. switches to different default styles for Windows CE.
*/
void Configure::applySpecSpecifics()
{
    if (dictionary[ "XQMAKESPEC" ].startsWith("wince")) {
        dictionary[ "STYLE_WINDOWSXP" ]     = "no";
        dictionary[ "STYLE_WINDOWSVISTA" ]  = "no";
        dictionary[ "STYLE_PLASTIQUE" ]     = "no";
        dictionary[ "STYLE_CLEANLOOKS" ]    = "no";
        dictionary[ "STYLE_WINDOWSCE" ]     = "yes";
        dictionary[ "STYLE_WINDOWSMOBILE" ] = "yes";
        dictionary[ "STYLE_MOTIF" ]         = "no";
        dictionary[ "STYLE_CDE" ]           = "no";
        dictionary[ "STYLE_S60" ]           = "no";
        dictionary[ "FREETYPE" ]            = "no";
        dictionary[ "QT3SUPPORT" ]          = "no";
        dictionary[ "OPENGL" ]              = "no";
        dictionary[ "OPENSSL" ]             = "no";
        dictionary[ "STL" ]                 = "no";
        dictionary[ "EXCEPTIONS" ]          = "no";
        dictionary[ "RTTI" ]                = "no";
        dictionary[ "ARCHITECTURE" ]        = "windowsce";
        dictionary[ "3DNOW" ]               = "no";
        dictionary[ "SSE" ]                 = "no";
        dictionary[ "SSE2" ]                = "no";
        dictionary[ "MMX" ]                 = "no";
        dictionary[ "IWMMXT" ]              = "no";
        dictionary[ "CE_CRT" ]              = "yes";
        dictionary[ "WEBKIT" ]              = "no";
        dictionary[ "PHONON" ]              = "yes";
        dictionary[ "DIRECTSHOW" ]          = "no";
        dictionary[ "LTCG" ]                = "yes";
        // We only apply MMX/IWMMXT for mkspecs we know they work
        if (dictionary[ "XQMAKESPEC" ].startsWith("wincewm")) {
            dictionary[ "MMX" ]    = "yes";
            dictionary[ "IWMMXT" ] = "yes";
            dictionary[ "DIRECTSHOW" ] = "yes";
        }
        dictionary[ "QT_HOST_PREFIX" ]      = dictionary[ "QT_INSTALL_PREFIX" ];
        dictionary[ "QT_INSTALL_PREFIX" ]   = "";

    } else if(dictionary[ "XQMAKESPEC" ].startsWith("symbian")) {
        dictionary[ "ACCESSIBILITY" ]       = "no";
        dictionary[ "STYLE_WINDOWSXP" ]     = "no";
        dictionary[ "STYLE_WINDOWSVISTA" ]  = "no";
        dictionary[ "STYLE_PLASTIQUE" ]     = "no";
        dictionary[ "STYLE_CLEANLOOKS" ]    = "no";
        dictionary[ "STYLE_WINDOWSCE" ]     = "no";
        dictionary[ "STYLE_WINDOWSMOBILE" ] = "no";
        dictionary[ "STYLE_MOTIF" ]         = "no";
        dictionary[ "STYLE_CDE" ]           = "no";
        dictionary[ "STYLE_S60" ]           = "yes";
        dictionary[ "FREETYPE" ]            = "no";
        dictionary[ "QT3SUPPORT" ]          = "no";
        dictionary[ "OPENGL" ]              = "no";
        dictionary[ "OPENSSL" ]             = "yes";
        dictionary[ "STL" ]                 = "yes";
        dictionary[ "EXCEPTIONS" ]          = "yes";
        dictionary[ "RTTI" ]                = "yes";
        dictionary[ "ARCHITECTURE" ]        = "symbian";
        dictionary[ "3DNOW" ]               = "no";
        dictionary[ "SSE" ]                 = "no";
        dictionary[ "SSE2" ]                = "no";
        dictionary[ "MMX" ]                 = "no";
        dictionary[ "IWMMXT" ]              = "no";
        dictionary[ "CE_CRT" ]              = "no";
        dictionary[ "DIRECT3D" ]            = "no";
        dictionary[ "WEBKIT" ]              = "no";
        dictionary[ "ASSISTANT_WEBKIT" ]    = "no";
        dictionary[ "PHONON" ]              = "yes";
        dictionary[ "XMLPATTERNS" ]         = "no";
        dictionary[ "QT_GLIB" ]             = "no";
        dictionary[ "S60" ]                 = "yes";
        // iconv makes makes apps start and run ridiculously slowly in symbian emulator (HW not tested)
        // iconv_open seems to return -1 always, so something is probably missing from the platform.
        dictionary[ "QT_ICONV" ]            = "no";
        dictionary[ "SCRIPTTOOLS" ]         = "no";
        dictionary[ "QT_HOST_PREFIX" ]      = dictionary[ "QT_INSTALL_PREFIX" ];
        dictionary[ "QT_INSTALL_PREFIX" ]   = "";
        dictionary[ "QT_INSTALL_PLUGINS" ]  = "\\resource\\qt\\plugins";
        dictionary[ "ARM_FPU_TYPE" ]        = "softvfp";
        dictionary[ "SQL_SQLITE" ]          = "yes";
        dictionary[ "SQL_SQLITE_LIB" ]      = "system";

    } else if(dictionary[ "XQMAKESPEC" ].startsWith("linux")) { //TODO actually wrong.
      //TODO
        dictionary[ "STYLE_WINDOWSXP" ]     = "no";
        dictionary[ "STYLE_WINDOWSVISTA" ]  = "no";
        dictionary[ "KBD_DRIVERS" ]         = "tty";
        dictionary[ "GFX_DRIVERS" ]         = "linuxfb vnc";
        dictionary[ "MOUSE_DRIVERS" ]       = "pc linuxtp";
        dictionary[ "QT3SUPPORT" ]          = "no";
        dictionary[ "OPENGL" ]              = "no";
        dictionary[ "EXCEPTIONS" ]          = "no";
        dictionary[ "DBUS"]                 = "no";
        dictionary[ "QT_QWS_DEPTH" ]        = "4 8 16 24 32";
        dictionary[ "QT_SXE" ]              = "no";
        dictionary[ "QT_INOTIFY" ]          = "no";
        dictionary[ "QT_LPR" ]              = "no";
        dictionary[ "QT_CUPS" ]             = "no";
        dictionary[ "QT_GLIB" ]             = "no";
        dictionary[ "QT_ICONV" ]            = "no";

        dictionary["DECORATIONS"]           = "default windows styled";
        dictionary[ "QMAKEADDITIONALARGS" ] = "-unix";
    }
}

QString Configure::locateFileInPaths(const QString &fileName, const QStringList &paths)
{
    QDir d;
    for( QStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it ) {
        // Remove any leading or trailing ", this is commonly used in the environment
        // variables
        QString path = (*it);
        if ( path.startsWith( "\"" ) )
            path = path.right( path.length() - 1 );
        if ( path.endsWith( "\"" ) )
            path = path.left( path.length() - 1 );
        if( d.exists(path + QDir::separator() + fileName) ) {
            return (path);
        }
    }
    return QString();
}

QString Configure::locateFile( const QString &fileName )
{
    QString file = fileName.toLower();
    QStringList paths;
#if defined(Q_OS_WIN32)
    QRegExp splitReg("[;,]");
#else
    QRegExp splitReg("[:]");
#endif
    if (file.endsWith(".h"))
        paths = QString::fromLocal8Bit(getenv("INCLUDE")).split(splitReg, QString::SkipEmptyParts);
    else if ( file.endsWith( ".lib" ) )
        paths = QString::fromLocal8Bit(getenv("LIB")).split(splitReg, QString::SkipEmptyParts);
    else
        paths = QString::fromLocal8Bit(getenv("PATH")).split(splitReg, QString::SkipEmptyParts);
    return locateFileInPaths(file, paths);
}

// Output helper functions ---------------------------------[ Stop ]-


bool Configure::displayHelp()
{
    if( dictionary[ "HELP" ] == "yes" ) {
        desc("Usage: configure [-buildkey <key>]\n"
//      desc("Usage: configure [-prefix dir] [-bindir <dir>] [-libdir <dir>]\n"
//                  "[-docdir <dir>] [-headerdir <dir>] [-plugindir <dir>]\n"
//                  "[-datadir <dir>] [-translationdir <dir>]\n"
//                  "[-examplesdir <dir>] [-demosdir <dir>][-buildkey <key>]\n"
                    "[-release] [-debug] [-debug-and-release] [-shared] [-static]\n"
                    "[-no-fast] [-fast] [-no-exceptions] [-exceptions]\n"
                    "[-no-accessibility] [-accessibility] [-no-rtti] [-rtti]\n"
                    "[-no-stl] [-stl] [-no-sql-<driver>] [-qt-sql-<driver>]\n"
                    "[-plugin-sql-<driver>] [-system-sqlite] [-arch <arch>]\n"
                    "[-D <define>] [-I <includepath>] [-L <librarypath>]\n"
                    "[-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]\n"
                    "[-no-qmake] [-qmake] [-dont-process] [-process]\n"
                    "[-no-style-<style>] [-qt-style-<style>] [-redo]\n"
                    "[-saveconfig <config>] [-loadconfig <config>]\n"
                    "[-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libpng]\n"
                    "[-qt-libpng] [-system-libpng] [-no-libtiff] [-qt-libtiff]\n"
                    "[-system-libtiff] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]\n"
                    "[-no-libmng] [-qt-libmng] [-system-libmng] [-no-qt3support] [-mmx]\n"
                    "[-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]\n"
                    "[-no-iwmmxt] [-iwmmxt] [-openssl] [-openssl-linked]\n"
                    "[-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform <spec>]\n"
                    "[-qtnamespace <namespace>] [-qtlibinfix <infix>] [-no-phonon]\n"
                    "[-phonon] [-no-phonon-backend] [-phonon-backend]\n"
                    "[-no-multimedia] [-multimedia] [-no-webkit] [-webkit]\n"
                    "[-no-script] [-script] [-no-scripttools] [-scripttools]\n"
                    "[-graphicssystem raster|opengl|openvg]\n\n", 0, 7);

        desc("Installation options:\n\n");

#if !defined(EVAL)
/*
        desc(" These are optional, but you may specify install directories.\n\n", 0, 1);

        desc(                   "-prefix dir",          "This will install everything relative to dir\n(default $QT_INSTALL_PREFIX)\n");

        desc(" You may use these to separate different parts of the install:\n\n", 0, 1);

        desc(                   "-bindir <dir>",        "Executables will be installed to dir\n(default PREFIX/bin)");
        desc(                   "-libdir <dir>",        "Libraries will be installed to dir\n(default PREFIX/lib)");
        desc(                   "-docdir <dir>",        "Documentation will be installed to dir\n(default PREFIX/doc)");
        desc(                   "-headerdir <dir>",     "Headers will be installed to dir\n(default PREFIX/include)");
        desc(                   "-plugindir <dir>",     "Plugins will be installed to dir\n(default PREFIX/plugins)");
        desc(                   "-datadir <dir>",       "Data used by Qt programs will be installed to dir\n(default PREFIX)");
        desc(                   "-translationdir <dir>","Translations of Qt programs will be installed to dir\n(default PREFIX/translations)\n");
        desc(                   "-examplesdir <dir>",   "Examples will be installed to dir\n(default PREFIX/examples)");
        desc(                   "-demosdir <dir>",      "Demos will be installed to dir\n(default PREFIX/demos)");
*/
        desc(" You may use these options to turn on strict plugin loading:\n\n", 0, 1);

        desc(                   "-buildkey <key>",      "Build the Qt library and plugins using the specified <key>.  "
                                                        "When the library loads plugins, it will only load those that have a matching <key>.\n");

        desc("Configure options:\n\n");

        desc(" The defaults (*) are usually acceptable. A plus (+) denotes a default value"
             " that needs to be evaluated. If the evaluation succeeds, the feature is"
             " included. Here is a short explanation of each option:\n\n", 0, 1);

        desc("BUILD", "release","-release",             "Compile and link Qt with debugging turned off.");
        desc("BUILD", "debug",  "-debug",               "Compile and link Qt with debugging turned on.");
        desc("BUILDALL", "yes", "-debug-and-release",   "Compile and link two Qt libraries, with and without debugging turned on.\n");

        desc("OPENSOURCE", "opensource", "-opensource",   "Compile and link the Open-Source Edition of Qt.");
        desc("COMMERCIAL", "commercial", "-commercial",   "Compile and link the Commercial Edition of Qt.\n");

        desc("BUILDDEV", "yes", "-developer-build",      "Compile and link Qt with Qt developer options (including auto-tests exporting)\n");

        desc("SHARED", "yes",   "-shared",              "Create and use shared Qt libraries.");
        desc("SHARED", "no",    "-static",              "Create and use static Qt libraries.\n");

        desc("LTCG", "yes",   "-ltcg",                  "Use Link Time Code Generation. (Release builds only)");
        desc("LTCG", "no",    "-no-ltcg",               "Do not use Link Time Code Generation.\n");

        desc("FAST", "no",      "-no-fast",             "Configure Qt normally by generating Makefiles for all project files.");
        desc("FAST", "yes",     "-fast",                "Configure Qt quickly by generating Makefiles only for library and "
                                                        "subdirectory targets.  All other Makefiles are created as wrappers "
                                                        "which will in turn run qmake\n");

        desc("EXCEPTIONS", "no", "-no-exceptions",      "Disable exceptions on platforms that support it.");
        desc("EXCEPTIONS", "yes","-exceptions",         "Enable exceptions on platforms that support it.\n");

        desc("ACCESSIBILITY", "no",  "-no-accessibility", "Do not compile Windows Active Accessibility support.");
        desc("ACCESSIBILITY", "yes", "-accessibility",    "Compile Windows Active Accessibility support.\n");

        desc("STL", "no",       "-no-stl",              "Do not compile STL support.");
        desc("STL", "yes",      "-stl",                 "Compile STL support.\n");

        desc(                   "-no-sql-<driver>",     "Disable SQL <driver> entirely, by default none are turned on.");
        desc(                   "-qt-sql-<driver>",     "Enable a SQL <driver> in the Qt Library.");
        desc(                   "-plugin-sql-<driver>", "Enable SQL <driver> as a plugin to be linked to at run time.\n"
                                                        "Available values for <driver>:");
        desc("SQL_MYSQL", "auto", "",                   "  mysql", ' ');
        desc("SQL_PSQL", "auto", "",                    "  psql", ' ');
        desc("SQL_OCI", "auto", "",                     "  oci", ' ');
        desc("SQL_ODBC", "auto", "",                    "  odbc", ' ');
        desc("SQL_TDS", "auto", "",                     "  tds", ' ');
        desc("SQL_DB2", "auto", "",                     "  db2", ' ');
        desc("SQL_SQLITE", "auto", "",                  "  sqlite", ' ');
        desc("SQL_SQLITE2", "auto", "",                 "  sqlite2", ' ');
        desc("SQL_IBASE", "auto", "",                   "  ibase", ' ');
        desc(                   "",                     "(drivers marked with a '+' have been detected as available on this system)\n", false, ' ');

        desc(                   "-system-sqlite",       "Use sqlite from the operating system.\n");

        desc("QT3SUPPORT", "no","-no-qt3support",       "Disables the Qt 3 support functionality.\n");
        desc("OPENGL", "no","-no-opengl",               "Disables OpenGL functionality\n");

        desc("OPENVG", "no","-no-openvg",               "Disables OpenVG functionality\n");
        desc("OPENVG", "yes","-openvg",                 "Enables OpenVG functionality");
        desc(                   "",                     "Requires EGL support, typically supplied by an OpenGL", false, ' ');
        desc(                   "",                     "or other graphics implementation\n", false, ' ');

#endif
        desc(                   "-platform <spec>",     "The operating system and compiler you are building on.\n(default %QMAKESPEC%)\n");
        desc(                   "-xplatform <spec>",    "The operating system and compiler you are cross compiling to.\n");
        desc(                   "",                     "See the README file for a list of supported operating systems and compilers.\n", false, ' ');

#if !defined(EVAL)
        desc(                   "-qtnamespace <namespace>", "Wraps all Qt library code in 'namespace name {...}");
        desc(                   "-qtlibinfix <infix>",  "Renames all Qt* libs to Qt*<infix>\n");
        desc(                   "-D <define>",          "Add an explicit define to the preprocessor.");
        desc(                   "-I <includepath>",     "Add an explicit include path.");
        desc(                   "-L <librarypath>",     "Add an explicit library path.");
        desc(                   "-l <libraryname>",     "Add an explicit library name, residing in a librarypath.\n");
#endif
        desc(                   "-graphicssystem <sys>",   "Specify which graphicssystem should be used.\n"
                                "Available values for <sys>:");
        desc("GRAPHICS_SYSTEM", "raster", "", "  raster - Software rasterizer", ' ');
        desc("GRAPHICS_SYSTEM", "opengl", "", "  opengl - Using OpenGL acceleration, experimental!", ' ');
        desc("GRAPHICS_SYSTEM", "openvg", "", "  openvg - Using OpenVG acceleration, experimental!", ' ');


        desc(                   "-help, -h, -?",        "Display this information.\n");

#if !defined(EVAL)
        // 3rd party stuff options go below here --------------------------------------------------------------------------------
        desc("Third Party Libraries:\n\n");

        desc("ZLIB", "qt",      "-qt-zlib",             "Use the zlib bundled with Qt.");
        desc("ZLIB", "system",  "-system-zlib",         "Use zlib from the operating system.\nSee http://www.gzip.org/zlib\n");

        desc("GIF", "no",       "-no-gif",              "Do not compile the plugin for GIF reading support.");
        desc("GIF", "auto",     "-qt-gif",              "Compile the plugin for GIF reading support.\nSee also src/plugins/imageformats/gif/qgifhandler.h\n");

        desc("LIBPNG", "no",    "-no-libpng",           "Do not compile in PNG support.");
        desc("LIBPNG", "qt",    "-qt-libpng",           "Use the libpng bundled with Qt.");
        desc("LIBPNG", "system","-system-libpng",       "Use libpng from the operating system.\nSee http://www.libpng.org/pub/png\n");

        desc("LIBMNG", "no",    "-no-libmng",           "Do not compile in MNG support.");
        desc("LIBMNG", "qt",    "-qt-libmng",           "Use the libmng bundled with Qt.");
        desc("LIBMNG", "system","-system-libmng",       "Use libmng from the operating system.\nSee See http://www.libmng.com\n");

        desc("LIBTIFF", "no",    "-no-libtiff",         "Do not compile the plugin for TIFF support.");
        desc("LIBTIFF", "qt",    "-qt-libtiff",         "Use the libtiff bundled with Qt.");
        desc("LIBTIFF", "system","-system-libtiff",     "Use libtiff from the operating system.\nSee http://www.libtiff.org\n");

        desc("LIBJPEG", "no",    "-no-libjpeg",         "Do not compile the plugin for JPEG support.");
        desc("LIBJPEG", "qt",    "-qt-libjpeg",         "Use the libjpeg bundled with Qt.");
        desc("LIBJPEG", "system","-system-libjpeg",     "Use libjpeg from the operating system.\nSee http://www.ijg.org\n");

#endif
        // Qt\Windows only options go below here --------------------------------------------------------------------------------
        desc("Qt for Windows only:\n\n");

        desc("DSPFILES", "no",  "-no-dsp",              "Do not generate VC++ .dsp files.");
        desc("DSPFILES", "yes", "-dsp",                 "Generate VC++ .dsp files, only if spec \"win32-msvc\".\n");

        desc("VCPROJFILES", "no", "-no-vcproj",         "Do not generate VC++ .vcproj files.");
        desc("VCPROJFILES", "yes", "-vcproj",           "Generate VC++ .vcproj files, only if platform \"win32-msvc.net\".\n");

        desc("INCREDIBUILD_XGE", "no", "-no-incredibuild-xge", "Do not add IncrediBuild XGE distribution commands to custom build steps.");
        desc("INCREDIBUILD_XGE", "yes", "-incredibuild-xge",   "Add IncrediBuild XGE distribution commands to custom build steps. This will distribute MOC and UIC steps, and other custom buildsteps which are added to the INCREDIBUILD_XGE variable.\n(The IncrediBuild distribution commands are only added to Visual Studio projects)\n");

        desc("PLUGIN_MANIFESTS", "no", "-no-plugin-manifests", "Do not embed manifests in plugins.");
        desc("PLUGIN_MANIFESTS", "yes", "-plugin-manifests",   "Embed manifests in plugins.\n");

#if !defined(EVAL)
        desc("BUILD_QMAKE", "no", "-no-qmake",          "Do not compile qmake.");
        desc("BUILD_QMAKE", "yes", "-qmake",            "Compile qmake.\n");

        desc("NOPROCESS", "yes", "-dont-process",       "Do not generate Makefiles/Project files. This will override -no-fast if specified.");
        desc("NOPROCESS", "no",  "-process",            "Generate Makefiles/Project files.\n");

        desc("RTTI", "no",      "-no-rtti",             "Do not compile runtime type information.");
        desc("RTTI", "yes",     "-rtti",                "Compile runtime type information.\n");
        desc("MMX", "no",       "-no-mmx",              "Do not compile with use of MMX instructions");
        desc("MMX", "yes",      "-mmx",                 "Compile with use of MMX instructions");
        desc("3DNOW", "no",     "-no-3dnow",            "Do not compile with use of 3DNOW instructions");
        desc("3DNOW", "yes",    "-3dnow",               "Compile with use of 3DNOW instructions");
        desc("SSE", "no",       "-no-sse",              "Do not compile with use of SSE instructions");
        desc("SSE", "yes",      "-sse",                 "Compile with use of SSE instructions");
        desc("SSE2", "no",      "-no-sse2",             "Do not compile with use of SSE2 instructions");
        desc("SSE2", "yes",      "-sse2",               "Compile with use of SSE2 instructions");
        desc("OPENSSL", "no",    "-no-openssl",         "Do not compile in OpenSSL support");
        desc("OPENSSL", "yes",   "-openssl",            "Compile in run-time OpenSSL support");
        desc("OPENSSL", "linked","-openssl-linked",     "Compile in linked OpenSSL support");
        desc("DBUS", "no",       "-no-dbus",            "Do not compile in D-Bus support");
        desc("DBUS", "yes",      "-dbus",               "Compile in D-Bus support and load libdbus-1 dynamically");
        desc("DBUS", "linked",   "-dbus-linked",        "Compile in D-Bus support and link to libdbus-1");
        desc("PHONON", "no",    "-no-phonon",           "Do not compile in the Phonon module");
        desc("PHONON", "yes",   "-phonon",              "Compile the Phonon module (Phonon is built if a decent C++ compiler is used.)");
        desc("PHONON_BACKEND","no", "-no-phonon-backend","Do not compile the platform-specific Phonon backend-plugin");
        desc("PHONON_BACKEND","yes","-phonon-backend",  "Compile in the platform-specific Phonon backend-plugin");
        desc("MULTIMEDIA", "no", "-no-multimedia",      "Do not compile the multimedia module");
        desc("MULTIMEDIA", "yes","-multimedia",         "Compile in multimedia module");
        desc("WEBKIT", "no",    "-no-webkit",           "Do not compile in the WebKit module");
        desc("WEBKIT", "yes",   "-webkit",              "Compile in the WebKit module (WebKit is built if a decent C++ compiler is used.)");
        desc("SCRIPT", "no",    "-no-script",           "Do not build the QtScript module.");
        desc("SCRIPT", "yes",   "-script",              "Build the QtScript module.");
        desc("SCRIPTTOOLS", "no", "-no-scripttools",    "Do not build the QtScriptTools module.");
        desc("SCRIPTTOOLS", "yes", "-scripttools",      "Build the QtScriptTools module.");

        desc(                   "-arch <arch>",         "Specify an architecture.\n"
                                                        "Available values for <arch>:");
        desc("ARCHITECTURE","windows",       "",        "  windows", ' ');
        desc("ARCHITECTURE","windowsce",     "",        "  windowsce", ' ');
        desc("ARCHITECTURE","symbian",     "",          "  symbian", ' ');
        desc("ARCHITECTURE","boundschecker",     "",    "  boundschecker", ' ');
        desc("ARCHITECTURE","generic", "",              "  generic\n", ' ');

        desc(                   "-no-style-<style>",    "Disable <style> entirely.");
        desc(                   "-qt-style-<style>",    "Enable <style> in the Qt Library.\nAvailable styles: ");

        desc("STYLE_WINDOWS", "yes", "",                "  windows", ' ');
        desc("STYLE_WINDOWSXP", "auto", "",             "  windowsxp", ' ');
        desc("STYLE_WINDOWSVISTA", "auto", "",          "  windowsvista", ' ');
        desc("STYLE_PLASTIQUE", "yes", "",              "  plastique", ' ');
        desc("STYLE_CLEANLOOKS", "yes", "",             "  cleanlooks", ' ');
        desc("STYLE_MOTIF", "yes", "",                  "  motif", ' ');
        desc("STYLE_CDE", "yes", "",                    "  cde", ' ');
        desc("STYLE_WINDOWSCE", "yes", "",              "  windowsce", ' ');
        desc("STYLE_WINDOWSMOBILE" , "yes", "",         "  windowsmobile", ' ');
        desc("STYLE_S60" , "yes", "",                   "  s60\n", ' ');

/*      We do not support -qconfig on Windows yet

        desc(                   "-qconfig <local>",     "Use src/tools/qconfig-local.h rather than the default.\nPossible values for local:");
        for (int i=0; i<allConfigs.size(); ++i)
            desc(               "",                     qPrintable(QString("  %1").arg(allConfigs.at(i))), false, ' ');
        printf("\n");
*/
#endif
        desc(                   "-loadconfig <config>", "Run configure with the parameters from file configure_<config>.cache.");
        desc(                   "-saveconfig <config>", "Run configure and save the parameters in file configure_<config>.cache.");
        desc(                   "-redo",                "Run configure with the same parameters as last time.\n");

        // Qt\Windows CE only options go below here -----------------------------------------------------------------------------
        desc("Qt for Windows CE only:\n\n");
        desc("IWMMXT", "no",       "-no-iwmmxt",           "Do not compile with use of IWMMXT instructions");
        desc("IWMMXT", "yes",      "-iwmmxt",              "Do compile with use of IWMMXT instructions (Qt for Windows CE on Arm only)");
        desc("CE_CRT", "no",       "-no-crt" ,             "Do not add the C runtime to default deployment rules");
        desc("CE_CRT", "yes",      "-qt-crt",              "Qt identifies C runtime during project generation");
        desc(                      "-crt <path>",          "Specify path to C runtime used for project generation.");
        desc("CETEST", "no",       "-no-cetest",           "Do not compile Windows CE remote test application");
        desc("CETEST", "yes",      "-cetest",              "Compile Windows CE remote test application");
        desc(                      "-signature <file>",    "Use file for signing the target project");
        desc("OPENGL_ES_CM", "no", "-opengl-es-cm",        "Enable support for OpenGL ES Common");
        desc("OPENGL_ES_CL", "no", "-opengl-es-cl",        "Enable support for OpenGL ES Common Lite");
        desc("OPENGL_ES_2",  "no", "-opengl-es-2",         "Enable support for OpenGL ES 2.0");
        desc("DIRECTSHOW", "no",   "-phonon-wince-ds9",    "Enable Phonon Direct Show 9 backend for Windows CE");

        // Qt\Symbian only options go below here -----------------------------------------------------------------------------
        desc("Qt for Symbian OS only:\n\n");
        desc("FREETYPE", "no",     "-no-freetype",         "Do not compile in Freetype2 support.");
        desc("FREETYPE", "yes",    "-qt-freetype",         "Use the libfreetype bundled with Qt.");
        desc(                      "-fpu <flags>",         "VFP type on ARM, supported options: softvfp(default) | vfpv2 | softvfp+vfpv2");
        desc("S60", "no",          "-no-s60",              "Do not compile in S60 support.");
        desc("S60", "yes",         "-s60",                 "Compile with support for the S60 UI Framework\n");
        return true;
    }
    return false;
}

QString Configure::findFileInPaths(const QString &fileName, const QString &paths)
{
#if defined(Q_OS_WIN32)
    QRegExp splitReg("[;,]");
#else
    QRegExp splitReg("[:]");
#endif
    QStringList pathList = paths.split(splitReg, QString::SkipEmptyParts);
    QDir d;
    for( QStringList::ConstIterator it = pathList.begin(); it != pathList.end(); ++it ) {
        // Remove any leading or trailing ", this is commonly used in the environment
        // variables
        QString path = (*it);
        if ( path.startsWith( '\"' ) )
            path = path.right( path.length() - 1 );
        if ( path.endsWith( '\"' ) )
            path = path.left( path.length() - 1 );
        if( d.exists( path + QDir::separator() + fileName ) )
            return path;
    }
    return QString();
}

bool Configure::findFile( const QString &fileName )
{
    const QString file = fileName.toLower();
    const QString pathEnvVar = QString::fromLocal8Bit(getenv("PATH"));
    const QString mingwPath = dictionary["QMAKESPEC"].endsWith("-g++") ?
        findFileInPaths("mingw32-g++.exe", pathEnvVar) : QString();

    QString paths;
    if (file.endsWith(".h")) {
        if (!mingwPath.isNull() && !findFileInPaths(file, mingwPath + QLatin1String("/../include")).isNull())
		    return true;
        paths = QString::fromLocal8Bit(getenv("INCLUDE"));
    } else if ( file.endsWith( ".lib" ) ||  file.endsWith( ".a" ) ) {
        if (!mingwPath.isNull() && !findFileInPaths(file, mingwPath + QLatin1String("/../lib")).isNull())
		    return true;
        paths = QString::fromLocal8Bit(getenv("LIB"));
    } else {
        paths = pathEnvVar;
    }
    return !findFileInPaths(file, paths).isNull();
}

/*!
    Default value for options marked as "auto" if the test passes.
    (Used both by the autoDetection() below, and the desc() function
    to mark (+) the default option of autodetecting options.
*/
QString Configure::defaultTo(const QString &option)
{
    // We prefer using the system version of the 3rd party libs
    if (option == "ZLIB"
        || option == "LIBJPEG"
        || option == "LIBPNG"
        || option == "LIBMNG"
        || option == "LIBTIFF")
        return "system";

    // We want PNG built-in
    if (option == "PNG")
        return "qt";

    // The JPEG image library can only be a plugin
    if (option == "JPEG"
        || option == "MNG" || option == "TIFF")
        return "plugin";

    // GIF off by default
    if (option == "GIF") {
        if (dictionary["SHARED"] == "yes")
            return "plugin";
        else
            return "yes";
    }

    // By default we do not want to compile OCI driver when compiling with
    // MinGW, due to lack of such support from Oracle. It prob. wont work.
    // (Customer may force the use though)
    if (dictionary["QMAKESPEC"].endsWith("-g++")
        && option == "SQL_OCI")
        return "no";

    if (option == "SQL_MYSQL"
        || option == "SQL_MYSQL"
        || option == "SQL_ODBC"
        || option == "SQL_OCI"
        || option == "SQL_PSQL"
        || option == "SQL_TDS"
        || option == "SQL_DB2"
        || option == "SQL_SQLITE"
        || option == "SQL_SQLITE2"
        || option == "SQL_IBASE")
        return "plugin";

    if (option == "SYNCQT"
        && (!QFile::exists(sourcePath + "/bin/syncqt") ||
            !QFile::exists(sourcePath + "/bin/syncqt.bat")))
        return "no";

    return "yes";
}

/*!
    Checks the system for the availability of a feature.
    Returns true if the feature is available, else false.
*/
bool Configure::checkAvailability(const QString &part)
{
    bool available = false;
    if (part == "STYLE_WINDOWSXP")
        available = (findFile("uxtheme.h"));

    else if (part == "ZLIB")
        available = findFile("zlib.h");

    else if (part == "LIBJPEG")
        available = findFile("jpeglib.h");
    else if (part == "LIBPNG")
        available = findFile("png.h");
    else if (part == "LIBMNG")
        available = findFile("libmng.h");
    else if (part == "LIBTIFF")
        available = findFile("tiffio.h");
    else if (part == "SQL_MYSQL")
        available = findFile("mysql.h") && findFile("libmySQL.lib");
    else if (part == "SQL_ODBC")
        available = findFile("sql.h") && findFile("sqlext.h") && findFile("odbc32.lib");
    else if (part == "SQL_OCI")
        available = findFile("oci.h") && findFile("oci.lib");
    else if (part == "SQL_PSQL")
        available = findFile("libpq-fe.h") && findFile("libpq.lib") && findFile("ws2_32.lib") && findFile("advapi32.lib");
    else if (part == "SQL_TDS")
        available = findFile("sybfront.h") && findFile("sybdb.h") && findFile("ntwdblib.lib");
    else if (part == "SQL_DB2")
        available = findFile("sqlcli.h") && findFile("sqlcli1.h") && findFile("db2cli.lib");
    else if (part == "SQL_SQLITE")
        if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian"))
            available = false; // In Symbian we only support system sqlite option
        else
            available = true; // Built in, we have a fork
    else if (part == "SQL_SQLITE_LIB") {
        if (dictionary[ "SQL_SQLITE_LIB" ] == "system") {
		    // Symbian has multiple .lib/.dll files we need to find
            if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) {
			    available = true; // There is sqlite_symbian plugin which exports the necessary stuff
			    dictionary[ "QT_LFLAGS_SQLITE" ] += "-lsqlite3";
		    } else {
			    available = findFile("sqlite3.h") && findFile("sqlite3.lib");
			    if (available)
				    dictionary[ "QT_LFLAGS_SQLITE" ] += "sqlite3.lib";
		    }
        } else
            available = true;
    } else if (part == "SQL_SQLITE2")
        available = findFile("sqlite.h") && findFile("sqlite.lib");
    else if (part == "SQL_IBASE")
        available = findFile("ibase.h") && (findFile("gds32_ms.lib") || findFile("gds32.lib"));
    else if (part == "IWMMXT")
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce");
    else if (part == "OPENGL_ES_CM")
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce");
    else if (part == "OPENGL_ES_CL")
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce");
    else if (part == "OPENGL_ES_2")
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce");
    else if (part == "DIRECTSHOW")
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce");
    else if (part == "SSE2")
        available = (dictionary.value("QMAKESPEC") != "win32-msvc") && (dictionary.value("QMAKESPEC") != "win32-g++");
    else if (part == "3DNOW" )
        available = (dictionary.value("QMAKESPEC") != "win32-msvc") && (dictionary.value("QMAKESPEC") != "win32-icc") && findFile("mm3dnow.h") && (dictionary.value("QMAKESPEC") != "win32-g++");
    else if (part == "MMX" || part == "SSE")
        available = (dictionary.value("QMAKESPEC") != "win32-msvc") && (dictionary.value("QMAKESPEC") != "win32-g++");
    else if (part == "OPENSSL")
        available = findFile("openssl\\ssl.h");
    else if (part == "DBUS")
        available = findFile("dbus\\dbus.h");
    else if (part == "CETEST") {
        QString rapiHeader = locateFile("rapi.h");
        QString rapiLib = locateFile("rapi.lib");
        available = (dictionary[ "ARCHITECTURE" ]  == "windowsce") && !rapiHeader.isEmpty() && !rapiLib.isEmpty();
        if (available) {
            dictionary[ "QT_CE_RAPI_INC" ] += QLatin1String("\"") + rapiHeader + QLatin1String("\"");
            dictionary[ "QT_CE_RAPI_LIB" ] += QLatin1String("\"") + rapiLib + QLatin1String("\"");
        }
        else if (dictionary[ "CETEST_REQUESTED" ] == "yes") {
            cout << "cetest could not be enabled: rapi.h and rapi.lib could not be found." << endl;
            cout << "Make sure the environment is set up for compiling with ActiveSync." << endl;
            dictionary[ "DONE" ] = "error";
        }
    }
    else if (part == "INCREDIBUILD_XGE")
        available = findFile("BuildConsole.exe") && findFile("xgConsole.exe");
    else if (part == "XMLPATTERNS")
    {
        /* MSVC 6.0 and MSVC 2002/7.0 has too poor C++ support for QtXmlPatterns. */
        return dictionary.value("QMAKESPEC") != "win32-msvc"
               && dictionary.value("QMAKESPEC") != "win32-msvc.net" // Leave for now, since we can't be sure if they are using 2002 or 2003 with this spec
               && dictionary.value("QMAKESPEC") != "win32-msvc2002"
               && dictionary.value("EXCEPTIONS") == "yes";
    } else if (part == "PHONON") {
        available = findFile("vmr9.h") && findFile("dshow.h") && findFile("dmo.h") && findFile("dmodshow.h")
            && (findFile("strmiids.lib") || findFile("libstrmiids.a"))
            && (findFile("dmoguids.lib") || findFile("libdmoguids.a"))
            && (findFile("msdmo.lib") || findFile("libmsdmo.a"))
            && findFile("d3d9.h");

        if (!available) {
            cout << "All the required DirectShow/Direct3D files couldn't be found." << endl
                 << "Make sure you have either the platform SDK AND the DirectShow SDK or the Windows SDK installed." << endl
                 << "If you have the DirectShow SDK installed, please make sure that you have run the <path to SDK>\\SetEnv.Cmd script." << endl;
            if (!findFile("vmr9.h"))  cout << "vmr9.h not found" << endl;
            if (!findFile("dshow.h")) cout << "dshow.h not found" << endl;
            if (!findFile("strmiids.lib")) cout << "strmiids.lib not found" << endl;
            if (!findFile("dmoguids.lib")) cout << "dmoguids.lib not found" << endl;
            if (!findFile("msdmo.lib")) cout << "msdmo.lib not found" << endl;
            if (!findFile("d3d9.h")) cout << "d3d9.h not found" << endl;
        }
    } else if (part == "MULTIMEDIA") {
        available = true;
    } else if (part == "WEBKIT" || part == "SCRIPT" || part == "SCRIPTTOOLS") {
        available = (dictionary.value("QMAKESPEC") == "win32-msvc2005") || (dictionary.value("QMAKESPEC") == "win32-msvc2008") || (dictionary.value("QMAKESPEC") == "win32-g++");
    }

    return available;
}

/*
    Autodetect options marked as "auto".
*/
void Configure::autoDetection()
{
    // Style detection
    if (dictionary["STYLE_WINDOWSXP"] == "auto")
        dictionary["STYLE_WINDOWSXP"] = checkAvailability("STYLE_WINDOWSXP") ? defaultTo("STYLE_WINDOWSXP") : "no";
    if (dictionary["STYLE_WINDOWSVISTA"] == "auto") // Vista style has the same requirements as XP style
        dictionary["STYLE_WINDOWSVISTA"] = checkAvailability("STYLE_WINDOWSXP") ? defaultTo("STYLE_WINDOWSVISTA") : "no";

    // Compression detection
    if (dictionary["ZLIB"] == "auto")
        dictionary["ZLIB"] =  checkAvailability("ZLIB") ? defaultTo("ZLIB") : "qt";

    // Image format detection
    if (dictionary["GIF"] == "auto")
        dictionary["GIF"] = defaultTo("GIF");
    if (dictionary["JPEG"] == "auto")
        dictionary["JPEG"] = defaultTo("JPEG");
    if (dictionary["PNG"] == "auto")
        dictionary["PNG"] = defaultTo("PNG");
    if (dictionary["MNG"] == "auto")
        dictionary["MNG"] = defaultTo("MNG");
    if (dictionary["TIFF"] == "auto")
        dictionary["TIFF"] = dictionary["ZLIB"] == "no" ? "no" : defaultTo("TIFF");
    if (dictionary["LIBJPEG"] == "auto")
        dictionary["LIBJPEG"] = checkAvailability("LIBJPEG") ? defaultTo("LIBJPEG") : "qt";
    if (dictionary["LIBPNG"] == "auto")
        dictionary["LIBPNG"] = checkAvailability("LIBPNG") ? defaultTo("LIBPNG") : "qt";
    if (dictionary["LIBMNG"] == "auto")
        dictionary["LIBMNG"] = checkAvailability("LIBMNG") ? defaultTo("LIBMNG") : "qt";
    if (dictionary["LIBTIFF"] == "auto")
        dictionary["LIBTIFF"] = checkAvailability("LIBTIFF") ? defaultTo("LIBTIFF") : "qt";

    // SQL detection (not on by default)
    if (dictionary["SQL_MYSQL"] == "auto")
        dictionary["SQL_MYSQL"] = checkAvailability("SQL_MYSQL") ? defaultTo("SQL_MYSQL") : "no";
    if (dictionary["SQL_ODBC"] == "auto")
        dictionary["SQL_ODBC"] = checkAvailability("SQL_ODBC") ? defaultTo("SQL_ODBC") : "no";
    if (dictionary["SQL_OCI"] == "auto")
        dictionary["SQL_OCI"] = checkAvailability("SQL_OCI") ? defaultTo("SQL_OCI") : "no";
    if (dictionary["SQL_PSQL"] == "auto")
        dictionary["SQL_PSQL"] = checkAvailability("SQL_PSQL") ? defaultTo("SQL_PSQL") : "no";
    if (dictionary["SQL_TDS"] == "auto")
        dictionary["SQL_TDS"] = checkAvailability("SQL_TDS") ? defaultTo("SQL_TDS") : "no";
    if (dictionary["SQL_DB2"] == "auto")
        dictionary["SQL_DB2"] = checkAvailability("SQL_DB2") ? defaultTo("SQL_DB2") : "no";
    if (dictionary["SQL_SQLITE"] == "auto")
        dictionary["SQL_SQLITE"] = checkAvailability("SQL_SQLITE") ? defaultTo("SQL_SQLITE") : "no";
    if (dictionary["SQL_SQLITE_LIB"] == "system")
        if (!checkAvailability("SQL_SQLITE_LIB"))
            dictionary["SQL_SQLITE_LIB"] = "no";
    if (dictionary["SQL_SQLITE2"] == "auto")
        dictionary["SQL_SQLITE2"] = checkAvailability("SQL_SQLITE2") ? defaultTo("SQL_SQLITE2") : "no";
    if (dictionary["SQL_IBASE"] == "auto")
        dictionary["SQL_IBASE"] = checkAvailability("SQL_IBASE") ? defaultTo("SQL_IBASE") : "no";
    if (dictionary["MMX"] == "auto")
        dictionary["MMX"] = checkAvailability("MMX") ? "yes" : "no";
    if (dictionary["3DNOW"] == "auto")
        dictionary["3DNOW"] = checkAvailability("3DNOW") ? "yes" : "no";
    if (dictionary["SSE"] == "auto")
        dictionary["SSE"] = checkAvailability("SSE") ? "yes" : "no";
    if (dictionary["SSE2"] == "auto")
        dictionary["SSE2"] = checkAvailability("SSE2") ? "yes" : "no";
    if (dictionary["IWMMXT"] == "auto")
        dictionary["IWMMXT"] = checkAvailability("IWMMXT") ? "yes" : "no";
    if (dictionary["OPENSSL"] == "auto")
        dictionary["OPENSSL"] = checkAvailability("OPENSSL") ? "yes" : "no";
    if (dictionary["DBUS"] == "auto")
        dictionary["DBUS"] = checkAvailability("DBUS") ? "yes" : "no";
    if (dictionary["SCRIPT"] == "auto")
        dictionary["SCRIPT"] = checkAvailability("SCRIPT") ? "yes" : "no";
    if (dictionary["SCRIPTTOOLS"] == "auto")
        dictionary["SCRIPTTOOLS"] = checkAvailability("SCRIPTTOOLS") ? "yes" : "no";
    if (dictionary["XMLPATTERNS"] == "auto")
        dictionary["XMLPATTERNS"] = checkAvailability("XMLPATTERNS") ? "yes" : "no";
    if (dictionary["PHONON"] == "auto")
        dictionary["PHONON"] = checkAvailability("PHONON") ? "yes" : "no";
    if (dictionary["WEBKIT"] == "auto")
        dictionary["WEBKIT"] = checkAvailability("WEBKIT") ? "yes" : "no";

    // Qt/WinCE remote test application
    if (dictionary["CETEST"] == "auto")
        dictionary["CETEST"] = checkAvailability("CETEST") ? "yes" : "no";

    // Detection of IncrediBuild buildconsole
    if (dictionary["INCREDIBUILD_XGE"] == "auto")
        dictionary["INCREDIBUILD_XGE"] = checkAvailability("INCREDIBUILD_XGE") ? "yes" : "no";

    // Mark all unknown "auto" to the default value..
    for (QMap<QString,QString>::iterator i = dictionary.begin(); i != dictionary.end(); ++i) {
        if (i.value() == "auto")
            i.value() = defaultTo(i.key());
    }
}

bool Configure::verifyConfiguration()
{
    if (dictionary["SQL_SQLITE_LIB"] == "no" && dictionary["SQL_SQLITE"] != "no") {
        cout << "WARNING: Configure could not detect the presence of a system SQLite3 lib." << endl
             << "Configure will therefore continue with the SQLite3 lib bundled with Qt." << endl
             << "(Press any key to continue..)";
        if(_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
            exit(0);      // Exit cleanly for Ctrl+C

        dictionary["SQL_SQLITE_LIB"] = "qt"; // Set to Qt's bundled lib an continue
    }
    if (dictionary["QMAKESPEC"].endsWith("-g++")
        && dictionary["SQL_OCI"] != "no") {
        cout << "WARNING: Qt does not support compiling the Oracle database driver with" << endl
             << "MinGW, due to lack of such support from Oracle. Consider disabling the" << endl
             << "Oracle driver, as the current build will most likely fail." << endl;
        cout << "(Press any key to continue..)";
        if(_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
            exit(0);      // Exit cleanly for Ctrl+C
    }
    if (dictionary["QMAKESPEC"].endsWith("win32-msvc.net")) {
        cout << "WARNING: The makespec win32-msvc.net is deprecated. Consider using" << endl
             << "win32-msvc2002 or win32-msvc2003 instead." << endl;
        cout << "(Press any key to continue..)";
        if(_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
            exit(0);      // Exit cleanly for Ctrl+C
    }
	if (0 != dictionary["ARM_FPU_TYPE"].size())
	{
		QStringList l= QStringList()
			<< "softvfp"
			<< "softvfp+vfpv2"
			<< "vfpv2";
		if (!(l.contains(dictionary["ARM_FPU_TYPE"])))
			cout << QString("WARNING: Using unsupported fpu flag: %1").arg(dictionary["ARM_FPU_TYPE"]) << endl;
	}

    return true;
}

/*
 Things that affect the Qt API/ABI:
   Options:
     minimal-config small-config medium-config large-config full-config

   Options:
     debug release
     stl

 Things that do not affect the Qt API/ABI:
     system-jpeg no-jpeg jpeg
     system-mng no-mng mng
     system-png no-png png
     system-zlib no-zlib zlib
     system-tiff no-tiff tiff
     no-gif gif
     dll staticlib

     nocrosscompiler
     GNUmake
     largefile
     nis
     nas
     tablet
     ipv6

     X11     : x11sm xinerama xcursor xfixes xrandr xrender fontconfig xkb
     Embedded: embedded freetype
*/
void Configure::generateBuildKey()
{
    QString spec = dictionary["QMAKESPEC"];

    QString compiler = "msvc"; // ICC is compatible
    if (spec.endsWith("-g++"))
        compiler = "mingw";
    else if (spec.endsWith("-borland"))
        compiler = "borland";

    // Build options which changes the Qt API/ABI
    QStringList build_options;
    if (!dictionary["QCONFIG"].isEmpty())
        build_options += dictionary["QCONFIG"] + "-config ";
    build_options.sort();

    // Sorted defines that start with QT_NO_
    QStringList build_defines = qmakeDefines.filter(QRegExp("^QT_NO_"));
    build_defines.sort();

    // Build up the QT_BUILD_KEY ifdef
    QString buildKey = "QT_BUILD_KEY \"";
    if (!dictionary["USER_BUILD_KEY"].isEmpty())
        buildKey += dictionary["USER_BUILD_KEY"] + " ";

    QString build32Key = buildKey + "Windows " + compiler + " %1 " + build_options.join(" ") + " " + build_defines.join(" ");
    QString build64Key = buildKey + "Windows x64 " + compiler + " %1 " + build_options.join(" ") + " " + build_defines.join(" ");
    build32Key = build32Key.simplified();
    build64Key = build64Key.simplified();
    build32Key.prepend("#  define ");
    build64Key.prepend("#  define ");

    QString buildkey = // Debug builds
                       "#if (defined(_DEBUG) || defined(DEBUG))\n"
                       "# if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))\n"
                       + build64Key.arg("debug") + "\"\n"
                       "# else\n"
                       + build32Key.arg("debug") + "\"\n"
                       "# endif\n"
                       "#else\n"
                       // Release builds
                       "# if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))\n"
                       + build64Key.arg("release") + "\"\n"
                       "# else\n"
                       + build32Key.arg("release") + "\"\n"
                       "# endif\n"
                       "#endif\n";

    dictionary["BUILD_KEY"] = buildkey;
}

void Configure::generateOutputVars()
{
    // Generate variables for output
    // Build key ----------------------------------------------------
    if ( dictionary.contains("BUILD_KEY") ) {
        qmakeVars += dictionary.value("BUILD_KEY");
    }

    QString build = dictionary[ "BUILD" ];
    bool buildAll = (dictionary[ "BUILDALL" ] == "yes");
    if ( build == "debug") {
        if (buildAll)
            qtConfig += "release";
        qtConfig += "debug";
    } else if (build == "release") {
        if (buildAll)
            qtConfig += "debug";
        qtConfig += "release";
    }

    // Compression --------------------------------------------------
    if( dictionary[ "ZLIB" ] == "qt" )
        qtConfig += "zlib";
    else if( dictionary[ "ZLIB" ] == "system" )
        qtConfig += "system-zlib";

    // Image formates -----------------------------------------------
    if( dictionary[ "GIF" ] == "no" )
        qtConfig += "no-gif";
    else if( dictionary[ "GIF" ] == "yes" )
        qtConfig += "gif";
    else if( dictionary[ "GIF" ] == "plugin" )
        qmakeFormatPlugins += "gif";

    if( dictionary[ "TIFF" ] == "no" )
          qtConfig += "no-tiff";
    else if( dictionary[ "TIFF" ] == "plugin" )
        qmakeFormatPlugins += "tiff";
    if( dictionary[ "LIBTIFF" ] == "system" )
        qtConfig += "system-tiff";

    if( dictionary[ "JPEG" ] == "no" )
        qtConfig += "no-jpeg";
    else if( dictionary[ "JPEG" ] == "plugin" )
        qmakeFormatPlugins += "jpeg";
    if( dictionary[ "LIBJPEG" ] == "system" )
        qtConfig += "system-jpeg";

    if( dictionary[ "PNG" ] == "no" )
        qtConfig += "no-png";
    else if( dictionary[ "PNG" ] == "qt" )
        qtConfig += "png";
    if( dictionary[ "LIBPNG" ] == "system" )
        qtConfig += "system-png";

    if( dictionary[ "MNG" ] == "no" )
        qtConfig += "no-mng";
    else if( dictionary[ "MNG" ] == "qt" )
        qtConfig += "mng";
    if( dictionary[ "LIBMNG" ] == "system" )
        qtConfig += "system-mng";

    // Text rendering --------------------------------------------------
    if( dictionary[ "FREETYPE" ] == "yes" )
        qtConfig += "freetype";

    // Styles -------------------------------------------------------
    if ( dictionary[ "STYLE_WINDOWS" ] == "yes" )
        qmakeStyles += "windows";

    if ( dictionary[ "STYLE_PLASTIQUE" ] == "yes" )
        qmakeStyles += "plastique";

    if ( dictionary[ "STYLE_CLEANLOOKS" ] == "yes" )
        qmakeStyles += "cleanlooks";

    if ( dictionary[ "STYLE_WINDOWSXP" ] == "yes" )
        qmakeStyles += "windowsxp";

    if ( dictionary[ "STYLE_WINDOWSVISTA" ] == "yes" )
        qmakeStyles += "windowsvista";

    if ( dictionary[ "STYLE_MOTIF" ] == "yes" )
        qmakeStyles += "motif";

    if ( dictionary[ "STYLE_SGI" ] == "yes" )
        qmakeStyles += "sgi";

    if ( dictionary[ "STYLE_WINDOWSCE" ] == "yes" )
    qmakeStyles += "windowsce";

    if ( dictionary[ "STYLE_WINDOWSMOBILE" ] == "yes" )
    qmakeStyles += "windowsmobile";

    if ( dictionary[ "STYLE_CDE" ] == "yes" )
        qmakeStyles += "cde";

    if ( dictionary[ "STYLE_S60" ] == "yes" )
        qmakeStyles += "s60";

    // Databases ----------------------------------------------------
    if ( dictionary[ "SQL_MYSQL" ] == "yes" )
        qmakeSql += "mysql";
    else if ( dictionary[ "SQL_MYSQL" ] == "plugin" )
        qmakeSqlPlugins += "mysql";

    if ( dictionary[ "SQL_ODBC" ] == "yes" )
        qmakeSql += "odbc";
    else if ( dictionary[ "SQL_ODBC" ] == "plugin" )
        qmakeSqlPlugins += "odbc";

    if ( dictionary[ "SQL_OCI" ] == "yes" )
        qmakeSql += "oci";
    else if ( dictionary[ "SQL_OCI" ] == "plugin" )
        qmakeSqlPlugins += "oci";

    if ( dictionary[ "SQL_PSQL" ] == "yes" )
        qmakeSql += "psql";
    else if ( dictionary[ "SQL_PSQL" ] == "plugin" )
        qmakeSqlPlugins += "psql";

    if ( dictionary[ "SQL_TDS" ] == "yes" )
        qmakeSql += "tds";
    else if ( dictionary[ "SQL_TDS" ] == "plugin" )
        qmakeSqlPlugins += "tds";

    if ( dictionary[ "SQL_DB2" ] == "yes" )
        qmakeSql += "db2";
    else if ( dictionary[ "SQL_DB2" ] == "plugin" )
        qmakeSqlPlugins += "db2";

    if ( dictionary[ "SQL_SQLITE" ] == "yes" )
        qmakeSql += "sqlite";
    else if ( dictionary[ "SQL_SQLITE" ] == "plugin" )
        qmakeSqlPlugins += "sqlite";

    if ( dictionary[ "SQL_SQLITE_LIB" ] == "system" )
        qmakeConfig += "system-sqlite";

    if ( dictionary[ "SQL_SQLITE2" ] == "yes" )
        qmakeSql += "sqlite2";
    else if ( dictionary[ "SQL_SQLITE2" ] == "plugin" )
        qmakeSqlPlugins += "sqlite2";

    if ( dictionary[ "SQL_IBASE" ] == "yes" )
        qmakeSql += "ibase";
    else if ( dictionary[ "SQL_IBASE" ] == "plugin" )
        qmakeSqlPlugins += "ibase";

    // Other options ------------------------------------------------
    if( dictionary[ "BUILDALL" ] == "yes" ) {
        qmakeConfig += "build_all";
    }
    qmakeConfig += dictionary[ "BUILD" ];
    dictionary[ "QMAKE_OUTDIR" ] = dictionary[ "BUILD" ];

    if ( dictionary[ "SHARED" ] == "yes" ) {
        QString version = dictionary[ "VERSION" ];
        if (!version.isEmpty()) {
            qmakeVars += "QMAKE_QT_VERSION_OVERRIDE = " + version.left(version.indexOf("."));
            version.remove(QLatin1Char('.'));
        }
        dictionary[ "QMAKE_OUTDIR" ] += "_shared";
    } else {
        dictionary[ "QMAKE_OUTDIR" ] += "_static";
    }

    if( dictionary[ "ACCESSIBILITY" ] == "yes" )
        qtConfig += "accessibility";

    if( !qmakeLibs.isEmpty() )
        qmakeVars += "LIBS           += " + qmakeLibs.join( " " );

    if( !dictionary["QT_LFLAGS_SQLITE"].isEmpty() )
        qmakeVars += "QT_LFLAGS_SQLITE += " + dictionary["QT_LFLAGS_SQLITE"];

    if (dictionary[ "QT3SUPPORT" ] == "yes")
        qtConfig += "qt3support";

    if (dictionary[ "OPENGL" ] == "yes")
        qtConfig += "opengl";

    if ( dictionary["OPENGL_ES_CM"] == "yes" ) {
        qtConfig += "opengles1";
    }

    if ( dictionary["OPENGL_ES_2"] == "yes" ) {
        qtConfig += "opengles2";
    }

    if ( dictionary["OPENGL_ES_CL"] == "yes" ) {
        qtConfig += "opengles1cl";
    }

    if ( dictionary["OPENVG"] == "yes" ) {
        qtConfig += "openvg";
        qtConfig += "egl";
    }

    if ( dictionary["S60"] == "yes" ) {
        qtConfig += "s60";
    }

     if ( dictionary["DIRECTSHOW"] == "yes" )
        qtConfig += "directshow";

    if (dictionary[ "OPENSSL" ] == "yes")
        qtConfig += "openssl";
    else if (dictionary[ "OPENSSL" ] == "linked")
        qtConfig += "openssl-linked";

    if (dictionary[ "DBUS" ] == "yes")
        qtConfig += "dbus";
    else if (dictionary[ "DBUS" ] == "linked")
        qtConfig += "dbus dbus-linked";

    if (dictionary["IPV6"] == "yes")
        qtConfig += "ipv6";
    else if (dictionary["IPV6"] == "no")
        qtConfig += "no-ipv6";

    if (dictionary[ "CETEST" ] == "yes")
        qtConfig += "cetest";

    if (dictionary[ "SCRIPT" ] == "yes")
        qtConfig += "script";

    if (dictionary[ "SCRIPTTOOLS" ] == "yes") {
        if (dictionary[ "SCRIPT" ] == "no") {
            cout << "QtScriptTools was requested, but it can't be built due to QtScript being "
                    "disabled." << endl;
            dictionary[ "DONE" ] = "error";
        }
        qtConfig += "scripttools";
    }

    if (dictionary[ "XMLPATTERNS" ] == "yes")
        qtConfig += "xmlpatterns";

    if (dictionary["PHONON"] == "yes") {
        qtConfig += "phonon";
        if (dictionary["PHONON_BACKEND"] == "yes")
            qtConfig += "phonon-backend";
    }

    if (dictionary["MULTIMEDIA"] == "yes")
        qtConfig += "multimedia";

    if (dictionary["WEBKIT"] == "yes")
        qtConfig += "webkit";

    // We currently have no switch for QtSvg, so add it unconditionally.
    qtConfig += "svg";

    // Add config levels --------------------------------------------
    QStringList possible_configs = QStringList()
        << "minimal"
        << "small"
        << "medium"
        << "large"
        << "full";

    QString set_config = dictionary["QCONFIG"];
    if (possible_configs.contains(set_config)) {
        foreach(QString cfg, possible_configs) {
            qtConfig += (cfg + "-config");
            if (cfg == set_config)
                break;
        }
    }

    if (dictionary.contains("XQMAKESPEC") && ( dictionary["QMAKESPEC"] != dictionary["XQMAKESPEC"] ) )
            qmakeConfig += "cross_compile";

    // Directories and settings for .qmake.cache --------------------

    // if QT_INSTALL_* have not been specified on commandline, define them now from QT_INSTALL_PREFIX
    // if prefix is empty (WINCE), make all of them empty, if they aren't set
    bool qipempty = false;
    if(dictionary[ "QT_INSTALL_PREFIX" ].isEmpty())
        qipempty = true;

    if( !dictionary[ "QT_INSTALL_DOCS" ].size() )
        dictionary[ "QT_INSTALL_DOCS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/doc" );
    if( !dictionary[ "QT_INSTALL_HEADERS" ].size() )
        dictionary[ "QT_INSTALL_HEADERS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/include" );
    if( !dictionary[ "QT_INSTALL_LIBS" ].size() )
        dictionary[ "QT_INSTALL_LIBS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/lib" );
    if( !dictionary[ "QT_INSTALL_BINS" ].size() )
        dictionary[ "QT_INSTALL_BINS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/bin" );
    if( !dictionary[ "QT_INSTALL_PLUGINS" ].size() )
        dictionary[ "QT_INSTALL_PLUGINS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/plugins" );
    if( !dictionary[ "QT_INSTALL_DATA" ].size() )
        dictionary[ "QT_INSTALL_DATA" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] );
    if( !dictionary[ "QT_INSTALL_TRANSLATIONS" ].size() )
        dictionary[ "QT_INSTALL_TRANSLATIONS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/translations" );
    if( !dictionary[ "QT_INSTALL_EXAMPLES" ].size() )
        dictionary[ "QT_INSTALL_EXAMPLES" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/examples");
    if( !dictionary[ "QT_INSTALL_DEMOS" ].size() )
        dictionary[ "QT_INSTALL_DEMOS" ] = qipempty ? "" : fixSeparators( dictionary[ "QT_INSTALL_PREFIX" ] + "/demos" );

    if(dictionary.contains("XQMAKESPEC") && dictionary[ "XQMAKESPEC" ].startsWith("linux"))
        dictionary[ "QMAKE_RPATHDIR" ] = dictionary[ "QT_INSTALL_LIBS" ];

    qmakeVars += QString("OBJECTS_DIR     = ") + fixSeparators( "tmp/obj/" + dictionary[ "QMAKE_OUTDIR" ] );
    qmakeVars += QString("MOC_DIR         = ") + fixSeparators( "tmp/moc/" + dictionary[ "QMAKE_OUTDIR" ] );
    qmakeVars += QString("RCC_DIR         = ") + fixSeparators("tmp/rcc/" + dictionary["QMAKE_OUTDIR"]);

    if (!qmakeDefines.isEmpty())
        qmakeVars += QString("DEFINES        += ") + qmakeDefines.join( " " );
    if (!qmakeIncludes.isEmpty())
        qmakeVars += QString("INCLUDEPATH    += ") + qmakeIncludes.join( " " );
    if (!opensslLibs.isEmpty())
        qmakeVars += opensslLibs;
    else if (dictionary[ "OPENSSL" ] == "linked") {
    	if(dictionary[ "XQMAKESPEC" ].startsWith("symbian") )
            qmakeVars += QString("OPENSSL_LIBS    = -llibssl -llibcrypto");
        else
            qmakeVars += QString("OPENSSL_LIBS    = -lssleay32 -llibeay32");
        }
    if (!qmakeSql.isEmpty())
        qmakeVars += QString("sql-drivers    += ") + qmakeSql.join( " " );
    if (!qmakeSqlPlugins.isEmpty())
        qmakeVars += QString("sql-plugins    += ") + qmakeSqlPlugins.join( " " );
    if (!qmakeStyles.isEmpty())
        qmakeVars += QString("styles         += ") + qmakeStyles.join( " " );
    if (!qmakeStylePlugins.isEmpty())
        qmakeVars += QString("style-plugins  += ") + qmakeStylePlugins.join( " " );
    if (!qmakeFormatPlugins.isEmpty())
        qmakeVars += QString("imageformat-plugins += ") + qmakeFormatPlugins.join( " " );

    if (dictionary["QMAKESPEC"].endsWith("-g++")) {
        QString includepath = qgetenv("INCLUDE");
        bool hasSh = Environment::detectExecutable("sh.exe");
        QChar separator = (!includepath.contains(":\\") && hasSh ? QChar(':') : QChar(';'));
        qmakeVars += QString("TMPPATH            = $$quote($$(INCLUDE))");
        qmakeVars += QString("QMAKE_INCDIR_POST += $$split(TMPPATH,\"%1\")").arg(separator);
        qmakeVars += QString("TMPPATH            = $$quote($$(LIB))");
        qmakeVars += QString("QMAKE_LIBDIR_POST += $$split(TMPPATH,\"%1\")").arg(separator);
    }

    if( !dictionary[ "QMAKESPEC" ].length() ) {
        cout << "Configure could not detect your compiler. QMAKESPEC must either" << endl
             << "be defined as an environment variable, or specified as an" << endl
             << "argument with -platform" << endl;
        dictionary[ "HELP" ] = "yes";

        QStringList winPlatforms;
        QDir mkspecsDir( sourcePath + "/mkspecs" );
        const QFileInfoList &specsList = mkspecsDir.entryInfoList();
        for(int i = 0; i < specsList.size(); ++i) {
            const QFileInfo &fi = specsList.at(i);
            if( fi.fileName().left( 5 ) == "win32" ) {
                winPlatforms += fi.fileName();
            }
        }
        cout << "Available platforms are: " << qPrintable(winPlatforms.join( ", " )) << endl;
        dictionary[ "DONE" ] = "error";
    }
}

#if !defined(EVAL)
void Configure::generateCachefile()
{
    // Generate .qmake.cache
    QFile cacheFile( buildPath + "/.qmake.cache" );
    if( cacheFile.open( QFile::WriteOnly | QFile::Text ) ) { // Truncates any existing file.
        QTextStream cacheStream( &cacheFile );
        for( QStringList::Iterator var = qmakeVars.begin(); var != qmakeVars.end(); ++var ) {
            cacheStream << (*var) << endl;
        }
        cacheStream << "CONFIG         += " << qmakeConfig.join( " " ) << " incremental create_prl link_prl depend_includepath QTDIR_build" << endl;

        QStringList buildParts;
        buildParts << "libs" << "tools" << "examples" << "demos" << "docs" << "translations";
        foreach(QString item, disabledBuildParts) {
            buildParts.removeAll(item);
        }
        cacheStream << "QT_BUILD_PARTS  = " << buildParts.join( " " ) << endl;

        QString targetSpec = dictionary.contains("XQMAKESPEC") ? dictionary[ "XQMAKESPEC" ] : dictionary[ "QMAKESPEC" ];
        QString mkspec_path = fixSeparators(sourcePath + "/mkspecs/" + targetSpec);
        if(QFile::exists(mkspec_path))
            cacheStream << "QMAKESPEC       = " << mkspec_path << endl;
        else
            cacheStream << "QMAKESPEC       = " << fixSeparators(targetSpec) << endl;
        cacheStream << "ARCH            = " << fixSeparators(dictionary[ "ARCHITECTURE" ]) << endl;
        cacheStream << "QT_BUILD_TREE   = " << fixSeparators(dictionary[ "QT_BUILD_TREE" ]) << endl;
        cacheStream << "QT_SOURCE_TREE  = " << fixSeparators(dictionary[ "QT_SOURCE_TREE" ]) << endl;

        if (dictionary["QT_EDITION"] != "QT_EDITION_OPENSOURCE")
            cacheStream << "DEFINES        *= QT_EDITION=QT_EDITION_DESKTOP" << endl;

        //so that we can build without an install first (which would be impossible)
        cacheStream << "QMAKE_MOC       = $$QT_BUILD_TREE" << fixSeparators("/bin/moc.exe") << endl;
        cacheStream << "QMAKE_UIC       = $$QT_BUILD_TREE" << fixSeparators("/bin/uic.exe") << endl;
        cacheStream << "QMAKE_UIC3      = $$QT_BUILD_TREE" << fixSeparators("/bin/uic3.exe") << endl;
        cacheStream << "QMAKE_RCC       = $$QT_BUILD_TREE" << fixSeparators("/bin/rcc.exe") << endl;
        cacheStream << "QMAKE_DUMPCPP   = $$QT_BUILD_TREE" << fixSeparators("/bin/dumpcpp.exe") << endl;
        cacheStream << "QMAKE_INCDIR_QT = $$QT_BUILD_TREE" << fixSeparators("/include") << endl;
        cacheStream << "QMAKE_LIBDIR_QT = $$QT_BUILD_TREE" << fixSeparators("/lib") << endl;
        if (dictionary["CETEST"] == "yes") {
            cacheStream << "QT_CE_RAPI_INC  = " << fixSeparators(dictionary[ "QT_CE_RAPI_INC" ]) << endl;
            cacheStream << "QT_CE_RAPI_LIB  = " << fixSeparators(dictionary[ "QT_CE_RAPI_LIB" ]) << endl;
        }

        // embedded
        if( !dictionary["KBD_DRIVERS"].isEmpty())
            cacheStream << "kbd-drivers += "<< dictionary["KBD_DRIVERS"]<<endl;
        if( !dictionary["GFX_DRIVERS"].isEmpty())
            cacheStream << "gfx-drivers += "<< dictionary["GFX_DRIVERS"]<<endl;
        if( !dictionary["MOUSE_DRIVERS"].isEmpty())
            cacheStream << "mouse-drivers += "<< dictionary["MOUSE_DRIVERS"]<<endl;
        if( !dictionary["DECORATIONS"].isEmpty())
            cacheStream << "decorations += "<<dictionary["DECORATIONS"]<<endl;

        if( !dictionary["QMAKE_RPATHDIR"].isEmpty() )
            cacheStream << "QMAKE_RPATHDIR += "<<dictionary["QMAKE_RPATHDIR"];

        cacheStream.flush();
        cacheFile.close();
    }
    QFile configFile( dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qconfig.pri" );
    if( configFile.open( QFile::WriteOnly | QFile::Text ) ) { // Truncates any existing file.
        QTextStream configStream( &configFile );
        configStream << "CONFIG+= ";
        configStream << dictionary[ "BUILD" ];
        if( dictionary[ "SHARED" ] == "yes" )
            configStream << " shared";
        else
            configStream << " static";

        if( dictionary[ "LTCG" ] == "yes" )
            configStream << " ltcg";
        if( dictionary[ "STL" ] == "yes" )
            configStream << " stl";
        if ( dictionary[ "EXCEPTIONS" ] == "yes" )
            configStream << " exceptions";
        if ( dictionary[ "EXCEPTIONS" ] == "no" )
            configStream << " exceptions_off";
        if ( dictionary[ "RTTI" ] == "yes" )
            configStream << " rtti";
        if ( dictionary[ "MMX" ] == "yes" )
            configStream << " mmx";
        if ( dictionary[ "3DNOW" ] == "yes" )
            configStream << " 3dnow";
        if ( dictionary[ "SSE" ] == "yes" )
            configStream << " sse";
        if ( dictionary[ "SSE2" ] == "yes" )
            configStream << " sse2";
        if ( dictionary[ "IWMMXT" ] == "yes" )
            configStream << " iwmmxt";
        if ( dictionary["INCREDIBUILD_XGE"] == "yes" )
            configStream << " incredibuild_xge";
        if ( dictionary["PLUGIN_MANIFESTS"] == "no" )
            configStream << " no_plugin_manifest";

        configStream << endl;
        configStream << "QT_ARCH = " << dictionary[ "ARCHITECTURE" ] << endl;
        if (dictionary["QT_EDITION"].contains("OPENSOURCE"))
            configStream << "QT_EDITION = " << QLatin1String("OpenSource") << endl;
        else
            configStream << "QT_EDITION = " << dictionary["EDITION"] << endl;
        configStream << "QT_CONFIG += " << qtConfig.join(" ") << endl;

        configStream << "#versioning " << endl
                     << "QT_VERSION = " << dictionary["VERSION"] << endl
                     << "QT_MAJOR_VERSION = " << dictionary["VERSION_MAJOR"] << endl
                     << "QT_MINOR_VERSION = " << dictionary["VERSION_MINOR"] << endl
                     << "QT_PATCH_VERSION = " << dictionary["VERSION_PATCH"] << endl;

        configStream << "#Qt for Windows CE c-runtime deployment" << endl
                     << "QT_CE_C_RUNTIME = " << fixSeparators(dictionary[ "CE_CRT" ]) << endl;

        if(dictionary["CE_SIGNATURE"] != QLatin1String("no"))
            configStream << "DEFAULT_SIGNATURE=" << dictionary["CE_SIGNATURE"] << endl;

        if(!dictionary["QMAKE_RPATHDIR"].isEmpty())
            configStream << "QMAKE_RPATHDIR += " << dictionary["QMAKE_RPATHDIR"] << endl;

        if (!dictionary["QT_LIBINFIX"].isEmpty())
            configStream << "QT_LIBINFIX = " << dictionary["QT_LIBINFIX"] << endl;

        if(!dictionary["ARM_FPU_TYPE"].isEmpty()) {
            configStream<<"QMAKE_CXXFLAGS.ARMCC += --fpu "<< dictionary["ARM_FPU_TYPE"];
        }

        configStream.flush();
        configFile.close();
    }
}
#endif

QString Configure::addDefine(QString def)
{
    QString result, defNeg, defD = def;

    defD.replace(QRegExp("=.*"), "");
    def.replace(QRegExp("="), " ");

    if(def.startsWith("QT_NO_")) {
        defNeg = defD;
        defNeg.replace("QT_NO_", "QT_");
    } else if(def.startsWith("QT_")) {
        defNeg = defD;
        defNeg.replace("QT_", "QT_NO_");
    }

    if (defNeg.isEmpty()) {
        result = "#ifndef $DEFD\n"
                 "# define $DEF\n"
                 "#endif\n\n";
    } else {
        result = "#if defined($DEFD) && defined($DEFNEG)\n"
                 "# undef $DEFD\n"
                 "#elif !defined($DEFD)\n"
                 "# define $DEF\n"
                 "#endif\n\n";
    }
    result.replace("$DEFNEG", defNeg);
    result.replace("$DEFD", defD);
    result.replace("$DEF", def);
    return result;
}

#if !defined(EVAL)
// ### This should be removed once Qt for S60 is out.
static void applyTemporarySymbianFlags(QStringList &qconfigList)
{
    qconfigList += "QT_NO_CONCURRENT";
    qconfigList += "QT_NO_QFUTURE";
    // This is removed because it uses UNIX signals which are not implemented yet
    qconfigList += "QT_NO_CRASHHANDLER";
    qconfigList += "QT_NO_PRINTER";
    qconfigList += "QT_NO_CURSOR";
    qconfigList += "QT_NO_SYSTEMTRAYICON";
}

void Configure::generateConfigfiles()
{
    QDir(buildPath).mkpath("src/corelib/global");
    QString outName( buildPath + "/src/corelib/global/qconfig.h" );
    QTemporaryFile tmpFile;
    QTextStream tmpStream;

    if(tmpFile.open()) {
        tmpStream.setDevice(&tmpFile);

        if( dictionary[ "QCONFIG" ] == "full" ) {
            tmpStream << "/* Everything */" << endl;
        } else {
            QString configName( "qconfig-" + dictionary[ "QCONFIG" ] + ".h" );
            tmpStream << "/* Copied from " << configName << "*/" << endl;
            tmpStream << "#ifndef QT_BOOTSTRAPPED" << endl;
            QFile inFile( sourcePath + "/src/corelib/global/" + configName );
            if( inFile.open( QFile::ReadOnly ) ) {
                QByteArray buffer = inFile.readAll();
                tmpFile.write( buffer.constData(), buffer.size() );
                inFile.close();
            }
            tmpStream << "#endif // QT_BOOTSTRAPPED" << endl;
        }
        tmpStream << endl;

        if( dictionary[ "SHARED" ] == "yes" ) {
            tmpStream << "#ifndef QT_DLL" << endl;
            tmpStream << "#define QT_DLL" << endl;
            tmpStream << "#endif" << endl;
        }
        tmpStream << endl;
        tmpStream << "/* License information */" << endl;
        tmpStream << "#define QT_PRODUCT_LICENSEE \"" << licenseInfo[ "LICENSEE" ] << "\"" << endl;
        tmpStream << "#define QT_PRODUCT_LICENSE \"" << dictionary[ "EDITION" ] << "\"" << endl;
        tmpStream << endl;
        tmpStream << "// Qt Edition" << endl;
        tmpStream << "#ifndef QT_EDITION" << endl;
        tmpStream << "#  define QT_EDITION " << dictionary["QT_EDITION"] << endl;
        tmpStream << "#endif" << endl;
        tmpStream << endl;
        tmpStream << dictionary["BUILD_KEY"];
        tmpStream << endl;
        if (dictionary["BUILDDEV"] == "yes") {
            dictionary["QMAKE_INTERNAL"] = "yes";
            tmpStream << "/* Used for example to export symbols for the certain autotests*/" << endl;
            tmpStream << "#define QT_BUILD_INTERNAL" << endl;
            tmpStream << endl;
        }
        tmpStream << "/* Machine byte-order */" << endl;
        tmpStream << "#define Q_BIG_ENDIAN 4321" << endl;
        tmpStream << "#define Q_LITTLE_ENDIAN 1234" << endl;
        if ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
            tmpStream << "#define Q_BYTE_ORDER Q_BIG_ENDIAN" << endl;
        else
            tmpStream << "#define Q_BYTE_ORDER Q_LITTLE_ENDIAN" << endl;

        tmpStream << endl << "// Compile time features" << endl;
        tmpStream << "#define QT_ARCH_" << dictionary["ARCHITECTURE"].toUpper() << endl;
        QStringList qconfigList;
        if(dictionary["STL"] == "no")                qconfigList += "QT_NO_STL";
        if(dictionary["STYLE_WINDOWS"] != "yes")     qconfigList += "QT_NO_STYLE_WINDOWS";
        if(dictionary["STYLE_PLASTIQUE"] != "yes")   qconfigList += "QT_NO_STYLE_PLASTIQUE";
        if(dictionary["STYLE_CLEANLOOKS"] != "yes")   qconfigList += "QT_NO_STYLE_CLEANLOOKS";
        if(dictionary["STYLE_WINDOWSXP"] != "yes" && dictionary["STYLE_WINDOWSVISTA"] != "yes")
            qconfigList += "QT_NO_STYLE_WINDOWSXP";
        if(dictionary["STYLE_WINDOWSVISTA"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSVISTA";
        if(dictionary["STYLE_MOTIF"] != "yes")       qconfigList += "QT_NO_STYLE_MOTIF";
        if(dictionary["STYLE_CDE"] != "yes")         qconfigList += "QT_NO_STYLE_CDE";
        if(dictionary["STYLE_S60"] != "yes")         qconfigList += "QT_NO_STYLE_S60";
        if(dictionary["STYLE_WINDOWSCE"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSCE";
        if(dictionary["STYLE_WINDOWSMOBILE"] != "yes")   qconfigList += "QT_NO_STYLE_WINDOWSMOBILE";
        if(dictionary["STYLE_GTK"] != "yes")         qconfigList += "QT_NO_STYLE_GTK";

        if(dictionary["GIF"] == "yes")              qconfigList += "QT_BUILTIN_GIF_READER=1";
        if(dictionary["PNG"] == "no")               qconfigList += "QT_NO_IMAGEFORMAT_PNG";
        if(dictionary["MNG"] == "no")               qconfigList += "QT_NO_IMAGEFORMAT_MNG";
        if(dictionary["JPEG"] == "no")              qconfigList += "QT_NO_IMAGEFORMAT_JPEG";
        if(dictionary["TIFF"] == "no")              qconfigList += "QT_NO_IMAGEFORMAT_TIFF";
        if(dictionary["ZLIB"] == "no") {
            qconfigList += "QT_NO_ZLIB";
            qconfigList += "QT_NO_COMPRESS";
        }

        if(dictionary["ACCESSIBILITY"] == "no")     qconfigList += "QT_NO_ACCESSIBILITY";
        if(dictionary["EXCEPTIONS"] == "no")        qconfigList += "QT_NO_EXCEPTIONS";
        if(dictionary["OPENGL"] == "no")            qconfigList += "QT_NO_OPENGL";
        if(dictionary["OPENVG"] == "no")            qconfigList += "QT_NO_OPENVG";
        if(dictionary["OPENSSL"] == "no")           qconfigList += "QT_NO_OPENSSL";
        if(dictionary["OPENSSL"] == "linked")       qconfigList += "QT_LINKED_OPENSSL";
        if(dictionary["DBUS"] == "no")              qconfigList += "QT_NO_DBUS";
        if(dictionary["IPV6"] == "no")              qconfigList += "QT_NO_IPV6";
        if(dictionary["WEBKIT"] == "no")            qconfigList += "QT_NO_WEBKIT";
        if(dictionary["PHONON"] == "no")            qconfigList += "QT_NO_PHONON";
        if(dictionary["MULTIMEDIA"] == "no")        qconfigList += "QT_NO_MULTIMEDIA";
        if(dictionary["XMLPATTERNS"] == "no")       qconfigList += "QT_NO_XMLPATTERNS";
        if(dictionary["SCRIPT"] == "no")            qconfigList += "QT_NO_SCRIPT";
        if(dictionary["SCRIPTTOOLS"] == "no")       qconfigList += "QT_NO_SCRIPTTOOLS";
        if(dictionary["FREETYPE"] == "no")          qconfigList += "QT_NO_FREETYPE";
        if(dictionary["S60"] == "no")               qconfigList += "QT_NO_S60";

        if(dictionary["OPENGL_ES_CM"] == "yes" ||
           dictionary["OPENGL_ES_CL"] == "yes" ||
           dictionary["OPENGL_ES_2"]  == "yes")     qconfigList += "QT_OPENGL_ES";

        if(dictionary["OPENGL_ES_CM"] == "yes")     qconfigList += "QT_OPENGL_ES_1";
        if(dictionary["OPENGL_ES_2"]  == "yes")     qconfigList += "QT_OPENGL_ES_2";
        if(dictionary["OPENGL_ES_CL"] == "yes")     qconfigList += "QT_OPENGL_ES_1_CL";

        if(dictionary["SQL_MYSQL"] == "yes")        qconfigList += "QT_SQL_MYSQL";
        if(dictionary["SQL_ODBC"] == "yes")         qconfigList += "QT_SQL_ODBC";
        if(dictionary["SQL_OCI"] == "yes")          qconfigList += "QT_SQL_OCI";
        if(dictionary["SQL_PSQL"] == "yes")         qconfigList += "QT_SQL_PSQL";
        if(dictionary["SQL_TDS"] == "yes")          qconfigList += "QT_SQL_TDS";
        if(dictionary["SQL_DB2"] == "yes")          qconfigList += "QT_SQL_DB2";
        if(dictionary["SQL_SQLITE"] == "yes")       qconfigList += "QT_SQL_SQLITE";
        if(dictionary["SQL_SQLITE2"] == "yes")      qconfigList += "QT_SQL_SQLITE2";
        if(dictionary["SQL_IBASE"] == "yes")        qconfigList += "QT_SQL_IBASE";

        if (dictionary["GRAPHICS_SYSTEM"] == "openvg") qconfigList += "QT_GRAPHICSSYSTEM_OPENVG";
        if (dictionary["GRAPHICS_SYSTEM"] == "opengl") qconfigList += "QT_GRAPHICSSYSTEM_OPENGL";
        if (dictionary["GRAPHICS_SYSTEM"] == "raster") qconfigList += "QT_GRAPHICSSYSTEM_RASTER";
        // ### This block should be removed once Qt for S60 is out.
        if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) {
            applyTemporarySymbianFlags(qconfigList);
        }

        qconfigList.sort();
        for (int i = 0; i < qconfigList.count(); ++i)
            tmpStream << addDefine(qconfigList.at(i));

        if(dictionary["EMBEDDED"] == "yes")
        {
            // Check for keyboard, mouse, gfx.
            QStringList kbdDrivers = dictionary["KBD_DRIVERS"].split(" ");;
            QStringList allKbdDrivers;
            allKbdDrivers<<"tty"<<"usb"<<"sl5000"<<"yopy"<<"vr41xx"<<"qvfb"<<"um";
            foreach(QString kbd, allKbdDrivers) {
                if( !kbdDrivers.contains(kbd))
                    tmpStream<<"#define QT_NO_QWS_KBD_"<<kbd.toUpper()<<endl;
            }

            QStringList mouseDrivers = dictionary["MOUSE_DRIVERS"].split(" ");
            QStringList allMouseDrivers;
            allMouseDrivers << "pc"<<"bus"<<"linuxtp"<<"yopy"<<"vr41xx"<<"tslib"<<"qvfb";
            foreach(QString mouse, allMouseDrivers) {
                if( !mouseDrivers.contains(mouse) )
                    tmpStream<<"#define QT_NO_QWS_MOUSE_"<<mouse.toUpper()<<endl;
            }

            QStringList gfxDrivers = dictionary["GFX_DRIVERS"].split(" ");
            QStringList allGfxDrivers;
            allGfxDrivers<<"linuxfb"<<"transformed"<<"qvfb"<<"vnc"<<"multiscreen"<<"ahi";
            foreach(QString gfx, allGfxDrivers) {
                if( !gfxDrivers.contains(gfx))
                    tmpStream<<"#define QT_NO_QWS_"<<gfx.toUpper()<<endl;
            }

            tmpStream<<"#define Q_WS_QWS"<<endl;

            QStringList depths = dictionary[ "QT_QWS_DEPTH" ].split(" ");
            foreach(QString depth, depths)
              tmpStream<<"#define QT_QWS_DEPTH_"+depth<<endl;
        }

        if( dictionary[ "QT_CUPS" ] == "no")
          tmpStream<<"#define QT_NO_CUPS"<<endl;

        if( dictionary[ "QT_ICONV" ]  == "no")
          tmpStream<<"#define QT_NO_ICONV"<<endl;

        if(dictionary[ "QT_GLIB" ] == "no")
          tmpStream<<"#define QT_NO_GLIB"<<endl;

        if(dictionary[ "QT_LPR" ] == "no")
          tmpStream<<"#define QT_NO_LPR"<<endl;

        if(dictionary[ "QT_INOTIFY" ] == "no" )
          tmpStream<<"#define QT_NO_INOTIFY"<<endl;

        if(dictionary[ "QT_SXE" ] == "no")
          tmpStream<<"#define QT_NO_SXE"<<endl;

        tmpStream.flush();
        tmpFile.flush();

        // Replace old qconfig.h with new one
        ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL);
        QFile::remove(outName);
        tmpFile.copy(outName);
        tmpFile.close();

        if(!QFile::exists(buildPath + "/include/QtCore/qconfig.h")) {
            if (!writeToFile("#include \"../../src/corelib/global/qconfig.h\"\n",
                             buildPath + "/include/QtCore/qconfig.h")
            || !writeToFile("#include \"../../src/corelib/global/qconfig.h\"\n",
                            buildPath + "/include/Qt/qconfig.h")) {
                dictionary["DONE"] = "error";
                return;
            }
        }
    }

    // Copy configured mkspec to default directory, but remove the old one first, if there is any
    QString defSpec = buildPath + "/mkspecs/default";
    QFileInfo defSpecInfo(defSpec);
    if (defSpecInfo.exists()) {
        if (!Environment::rmdir(defSpec)) {
            cout << "Couldn't update default mkspec! Are files in " << qPrintable(defSpec) << " read-only?" << endl;
            dictionary["DONE"] = "error";
            return;
        }
    }

    QString spec = dictionary.contains("XQMAKESPEC") ? dictionary["XQMAKESPEC"] : dictionary["QMAKESPEC"];
    QString pltSpec = sourcePath + "/mkspecs/" + spec;
    if (!Environment::cpdir(pltSpec, defSpec)) {
        cout << "Couldn't update default mkspec! Does " << qPrintable(pltSpec) << " exist?" << endl;
        dictionary["DONE"] = "error";
        return;
    }

    outName = defSpec + "/qmake.conf";
    ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL );
    QFile qmakeConfFile(outName);
    if (qmakeConfFile.open(QFile::Append | QFile::WriteOnly | QFile::Text)) {
        QTextStream qmakeConfStream;
        qmakeConfStream.setDevice(&qmakeConfFile);
        qmakeConfStream << endl << "QMAKESPEC_ORIGINAL=" << pltSpec << endl;
        qmakeConfStream.flush();
        qmakeConfFile.close();
    }

    // Generate the new qconfig.cpp file
    QDir(buildPath).mkpath("src/corelib/global");
    outName = buildPath + "/src/corelib/global/qconfig.cpp";

    QTemporaryFile tmpFile2;
    if (tmpFile2.open()) {
        tmpStream.setDevice(&tmpFile2);
        tmpStream << "/* Licensed */" << endl
                  << "static const char qt_configure_licensee_str          [512 + 12] = \"qt_lcnsuser=" << licenseInfo["LICENSEE"] << "\";" << endl
                  << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl;
        if(!dictionary[ "QT_HOST_PREFIX" ].isNull())
            tmpStream << "#if !defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)" << endl;
        tmpStream << "static const char qt_configure_prefix_path_str       [512 + 12] = \"qt_prfxpath=" << QString(dictionary["QT_INSTALL_PREFIX"]).replace( "\\", "\\\\" ) << "\";" << endl
                  << "static const char qt_configure_documentation_path_str[512 + 12] = \"qt_docspath=" << QString(dictionary["QT_INSTALL_DOCS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_headers_path_str      [512 + 12] = \"qt_hdrspath=" << QString(dictionary["QT_INSTALL_HEADERS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_libraries_path_str    [512 + 12] = \"qt_libspath=" << QString(dictionary["QT_INSTALL_LIBS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_binaries_path_str     [512 + 12] = \"qt_binspath=" << QString(dictionary["QT_INSTALL_BINS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_plugins_path_str      [512 + 12] = \"qt_plugpath=" << QString(dictionary["QT_INSTALL_PLUGINS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_data_path_str         [512 + 12] = \"qt_datapath=" << QString(dictionary["QT_INSTALL_DATA"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_translations_path_str [512 + 12] = \"qt_trnspath=" << QString(dictionary["QT_INSTALL_TRANSLATIONS"]).replace( "\\", "\\\\" ) << "\";" << endl
                  << "static const char qt_configure_examples_path_str     [512 + 12] = \"qt_xmplpath=" << QString(dictionary["QT_INSTALL_EXAMPLES"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  << "static const char qt_configure_demos_path_str        [512 + 12] = \"qt_demopath=" << QString(dictionary["QT_INSTALL_DEMOS"]).replace( "\\", "\\\\" ) << "\";"  << endl
                  //<< "static const char qt_configure_settings_path_str [256] = \"qt_stngpath=" << QString(dictionary["QT_INSTALL_SETTINGS"]).replace( "\\", "\\\\" ) << "\";" << endl
                  ;
        if(!dictionary[ "QT_HOST_PREFIX" ].isNull()) {
             tmpStream << "#else" << endl
                       << "static const char qt_configure_prefix_path_str       [512 + 12] = \"qt_prfxpath=" << QString(dictionary[ "QT_HOST_PREFIX" ]).replace( "\\", "\\\\" ) << "\";" << endl
                       << "static const char qt_configure_documentation_path_str[512 + 12] = \"qt_docspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/doc").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_headers_path_str      [512 + 12] = \"qt_hdrspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/include").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_libraries_path_str    [512 + 12] = \"qt_libspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/lib").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_binaries_path_str     [512 + 12] = \"qt_binspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/bin").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_plugins_path_str      [512 + 12] = \"qt_plugpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/plugins").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_data_path_str         [512 + 12] = \"qt_datapath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ]).replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_translations_path_str [512 + 12] = \"qt_trnspath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/translations").replace( "\\", "\\\\" ) <<"\";" << endl
                       << "static const char qt_configure_examples_path_str     [512 + 12] = \"qt_xmplpath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/example").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "static const char qt_configure_demos_path_str        [512 + 12] = \"qt_demopath=" << fixSeparators(dictionary[ "QT_HOST_PREFIX" ] + "/demos").replace( "\\", "\\\\" ) <<"\";"  << endl
                       << "#endif //QT_BOOTSTRAPPED" << endl;
        }
        tmpStream << "/* strlen( \"qt_lcnsxxxx\" ) == 12 */" << endl
                  << "#define QT_CONFIGURE_LICENSEE qt_configure_licensee_str + 12;" << endl
                  << "#define QT_CONFIGURE_LICENSED_PRODUCTS qt_configure_licensed_products_str + 12;" << endl
                  << "#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_DOCUMENTATION_PATH qt_configure_documentation_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_HEADERS_PATH qt_configure_headers_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_LIBRARIES_PATH qt_configure_libraries_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_BINARIES_PATH qt_configure_binaries_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_PLUGINS_PATH qt_configure_plugins_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_DATA_PATH qt_configure_data_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_TRANSLATIONS_PATH qt_configure_translations_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_EXAMPLES_PATH qt_configure_examples_path_str + 12;" << endl
                  << "#define QT_CONFIGURE_DEMOS_PATH qt_configure_demos_path_str + 12;" << endl
                  //<< "#define QT_CONFIGURE_SETTINGS_PATH qt_configure_settings_path_str + 12;" << endl
                  << endl;

        tmpStream.flush();
        tmpFile2.flush();

        // Replace old qconfig.cpp with new one
        ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL );
        QFile::remove( outName );
        tmpFile2.copy(outName);
        tmpFile2.close();
    }
}
#endif

#if !defined(EVAL)
void Configure::displayConfig()
{
    // Give some feedback
    cout << "Environment:" << endl;
    QString env = QString::fromLocal8Bit(getenv("INCLUDE")).replace(QRegExp("[;,]"), "\r\n      ");
    if (env.isEmpty())
        env = "Unset";
    cout << "    INCLUDE=\r\n      " << env << endl;
    env = QString::fromLocal8Bit(getenv("LIB")).replace(QRegExp("[;,]"), "\r\n      ");
    if (env.isEmpty())
        env = "Unset";
    cout << "    LIB=\r\n      " << env << endl;
    env = QString::fromLocal8Bit(getenv("PATH")).replace(QRegExp("[;,]"), "\r\n      ");
    if (env.isEmpty())
        env = "Unset";
    cout << "    PATH=\r\n      " << env << endl;

    if (dictionary["EDITION"] == "OpenSource") {
        cout << "You are licensed to use this software under the terms of the GNU GPL version 3.";
        cout << "You are licensed to use this software under the terms of the Lesser GNU LGPL version 2.1." << endl;
        cout << "See " << dictionary["LICENSE FILE"] << "3" << endl << endl
             << " or " << dictionary["LICENSE FILE"] << "L" << endl << endl;
    } else {
        QString l1 = licenseInfo[ "LICENSEE" ];
        QString l2 = licenseInfo[ "LICENSEID" ];
        QString l3 = dictionary["EDITION"] + ' ' + "Edition";
        QString l4 = licenseInfo[ "EXPIRYDATE" ];
        cout << "Licensee...................." << (l1.isNull() ? "" : l1) << endl;
        cout << "License ID.................." << (l2.isNull() ? "" : l2) << endl;
        cout << "Product license............." << (l3.isNull() ? "" : l3) << endl;
        cout << "Expiry Date................." << (l4.isNull() ? "" : l4) << endl << endl;
    }

    cout << "Configuration:" << endl;
    cout << "    " << qmakeConfig.join( "\r\n    " ) << endl;
    cout << "Qt Configuration:" << endl;
    cout << "    " << qtConfig.join( "\r\n    " ) << endl;
    cout << endl;

    if (dictionary.contains("XQMAKESPEC"))
        cout << "QMAKESPEC..................." << dictionary[ "XQMAKESPEC" ] << " (" << dictionary["QMAKESPEC_FROM"] << ")" << endl;
    else
        cout << "QMAKESPEC..................." << dictionary[ "QMAKESPEC" ] << " (" << dictionary["QMAKESPEC_FROM"] << ")" << endl;
    cout << "Architecture................" << dictionary[ "ARCHITECTURE" ] << endl;
    cout << "Maketool...................." << dictionary[ "MAKE" ] << endl;
    cout << "Debug symbols..............." << (dictionary[ "BUILD" ] == "debug" ? "yes" : "no") << endl;
    cout << "Link Time Code Generation..." << dictionary[ "LTCG" ] << endl;
    cout << "Accessibility support......." << dictionary[ "ACCESSIBILITY" ] << endl;
    cout << "STL support................." << dictionary[ "STL" ] << endl;
    cout << "Exception support..........." << dictionary[ "EXCEPTIONS" ] << endl;
    cout << "RTTI support................" << dictionary[ "RTTI" ] << endl;
    cout << "MMX support................." << dictionary[ "MMX" ] << endl;
    cout << "3DNOW support..............." << dictionary[ "3DNOW" ] << endl;
    cout << "SSE support................." << dictionary[ "SSE" ] << endl;
    cout << "SSE2 support................" << dictionary[ "SSE2" ] << endl;
    cout << "IWMMXT support.............." << dictionary[ "IWMMXT" ] << endl;
    cout << "OpenGL support.............." << dictionary[ "OPENGL" ] << endl;
    cout << "OpenVG support.............." << dictionary[ "OPENVG" ] << endl;
    cout << "OpenSSL support............." << dictionary[ "OPENSSL" ] << endl;
    cout << "QtDBus support.............." << dictionary[ "DBUS" ] << endl;
    cout << "QtXmlPatterns support......." << dictionary[ "XMLPATTERNS" ] << endl;
    cout << "Phonon support.............." << dictionary[ "PHONON" ] << endl;
    cout << "Multimedia support.........." << dictionary[ "MULTIMEDIA" ] << endl;
    cout << "WebKit support.............." << dictionary[ "WEBKIT" ] << endl;
    cout << "QtScript support............" << dictionary[ "SCRIPT" ] << endl;
    cout << "QtScriptTools support......." << dictionary[ "SCRIPTTOOLS" ] << endl;
    cout << "Graphics System............." << dictionary[ "GRAPHICS_SYSTEM" ] << endl;
    cout << "Qt3 compatibility..........." << dictionary[ "QT3SUPPORT" ] << endl << endl;

    cout << "Third Party Libraries:" << endl;
    cout << "    ZLIB support............" << dictionary[ "ZLIB" ] << endl;
    cout << "    GIF support............." << dictionary[ "GIF" ] << endl;
    cout << "    TIFF support............" << dictionary[ "TIFF" ] << endl;
    cout << "    JPEG support............" << dictionary[ "JPEG" ] << endl;
    cout << "    PNG support............." << dictionary[ "PNG" ] << endl;
    cout << "    MNG support............." << dictionary[ "MNG" ] << endl;
    cout << "    FreeType support........" << dictionary[ "FREETYPE" ] << endl << endl;

    cout << "Styles:" << endl;
    cout << "    Windows................." << dictionary[ "STYLE_WINDOWS" ] << endl;
    cout << "    Windows XP.............." << dictionary[ "STYLE_WINDOWSXP" ] << endl;
    cout << "    Windows Vista..........." << dictionary[ "STYLE_WINDOWSVISTA" ] << endl;
    cout << "    Plastique..............." << dictionary[ "STYLE_PLASTIQUE" ] << endl;
    cout << "    Cleanlooks.............." << dictionary[ "STYLE_CLEANLOOKS" ] << endl;
    cout << "    Motif..................." << dictionary[ "STYLE_MOTIF" ] << endl;
    cout << "    CDE....................." << dictionary[ "STYLE_CDE" ] << endl;
    cout << "    Windows CE.............." << dictionary[ "STYLE_WINDOWSCE" ] << endl;
    cout << "    Windows Mobile.........." << dictionary[ "STYLE_WINDOWSMOBILE" ] << endl;
    cout << "    S60....................." << dictionary[ "STYLE_S60" ] << endl << endl;

    cout << "Sql Drivers:" << endl;
    cout << "    ODBC...................." << dictionary[ "SQL_ODBC" ] << endl;
    cout << "    MySQL..................." << dictionary[ "SQL_MYSQL" ] << endl;
    cout << "    OCI....................." << dictionary[ "SQL_OCI" ] << endl;
    cout << "    PostgreSQL.............." << dictionary[ "SQL_PSQL" ] << endl;
    cout << "    TDS....................." << dictionary[ "SQL_TDS" ] << endl;
    cout << "    DB2....................." << dictionary[ "SQL_DB2" ] << endl;
    cout << "    SQLite.................." << dictionary[ "SQL_SQLITE" ] << " (" << dictionary[ "SQL_SQLITE_LIB" ] << ")" << endl;
    cout << "    SQLite2................." << dictionary[ "SQL_SQLITE2" ] << endl;
    cout << "    InterBase..............." << dictionary[ "SQL_IBASE" ] << endl << endl;

    cout << "Sources are in.............." << dictionary[ "QT_SOURCE_TREE" ] << endl;
    cout << "Build is done in............" << dictionary[ "QT_BUILD_TREE" ] << endl;
    cout << "Install prefix.............." << dictionary[ "QT_INSTALL_PREFIX" ] << endl;
    cout << "Headers installed to........" << dictionary[ "QT_INSTALL_HEADERS" ] << endl;
    cout << "Libraries installed to......" << dictionary[ "QT_INSTALL_LIBS" ] << endl;
    cout << "Plugins installed to........" << dictionary[ "QT_INSTALL_PLUGINS" ] << endl;
    cout << "Binaries installed to......." << dictionary[ "QT_INSTALL_BINS" ] << endl;
    cout << "Docs installed to..........." << dictionary[ "QT_INSTALL_DOCS" ] << endl;
    cout << "Data installed to..........." << dictionary[ "QT_INSTALL_DATA" ] << endl;
    cout << "Translations installed to..." << dictionary[ "QT_INSTALL_TRANSLATIONS" ] << endl;
    cout << "Examples installed to......." << dictionary[ "QT_INSTALL_EXAMPLES" ] << endl;
    cout << "Demos installed to.........." << dictionary[ "QT_INSTALL_DEMOS" ] << endl << endl;

    if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith(QLatin1String("wince"))) {
        cout << "Using c runtime detection..." << dictionary[ "CE_CRT" ] << endl;
        cout << "Cetest support.............." << dictionary[ "CETEST" ] << endl;
        cout << "Signature..................." << dictionary[ "CE_SIGNATURE"] << endl << endl;
    }

    if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith(QLatin1String("symbian"))) {
        cout << "Support for S60............." << dictionary[ "S60" ] << endl;
    }

    if(dictionary["ASSISTANT_WEBKIT"] == "yes")
        cout << "Using WebKit as html rendering engine in Qt Assistant." << endl;

    if(checkAvailability("INCREDIBUILD_XGE"))
        cout << "Using IncrediBuild XGE......" << dictionary["INCREDIBUILD_XGE"] << endl;
    if( !qmakeDefines.isEmpty() ) {
        cout << "Defines.....................";
        for( QStringList::Iterator defs = qmakeDefines.begin(); defs != qmakeDefines.end(); ++defs )
            cout << (*defs) << " ";
        cout << endl;
    }
    if( !qmakeIncludes.isEmpty() ) {
        cout << "Include paths...............";
        for( QStringList::Iterator incs = qmakeIncludes.begin(); incs != qmakeIncludes.end(); ++incs )
            cout << (*incs) << " ";
        cout << endl;
    }
    if( !qmakeLibs.isEmpty() ) {
        cout << "Additional libraries........";
        for( QStringList::Iterator libs = qmakeLibs.begin(); libs != qmakeLibs.end(); ++libs )
            cout << (*libs) << " ";
        cout << endl;
    }
    if( dictionary[ "QMAKE_INTERNAL" ] == "yes" ) {
        cout << "Using internal configuration." << endl;
    }
    if( dictionary[ "SHARED" ] == "no" ) {
        cout << "WARNING: Using static linking will disable the use of plugins." << endl;
        cout << "         Make sure you compile ALL needed modules into the library." << endl;
    }
    if( dictionary[ "OPENSSL" ] == "linked" && opensslLibs.isEmpty() ) {
        cout << "NOTE: When linking against OpenSSL, you can override the default" << endl;
        cout << "library names through OPENSSL_LIBS." << endl;
        cout << "For example:" << endl;
        cout << "    configure -openssl-linked OPENSSL_LIBS='-lssleay32 -llibeay32'" << endl;
    }
    if( dictionary[ "ZLIB_FORCED" ] == "yes" ) {
        QString which_zlib = "supplied";
        if( dictionary[ "ZLIB" ] == "system")
            which_zlib = "system";

        cout << "NOTE: The -no-zlib option was supplied but is no longer supported." << endl
             << endl
             << "Qt now requires zlib support in all builds, so the -no-zlib" << endl
             << "option was ignored. Qt will be built using the " << which_zlib
             << "zlib" << endl;
    }
}
#endif

#if !defined(EVAL)
void Configure::generateHeaders()
{
    if (dictionary["SYNCQT"] == "yes"
        && findFile("perl.exe")) {
        cout << "Running syncqt..." << endl;
        QStringList args;
        args += buildPath + "/bin/syncqt.bat";
        QStringList env;
        env += QString("QTDIR=" + sourcePath);
        env += QString("PATH=" + buildPath + "/bin/;" + qgetenv("PATH"));
        Environment::execute(args, env, QStringList());
    }
}

void Configure::buildQmake()
{
    if( dictionary[ "BUILD_QMAKE" ] == "yes" ) {
        QStringList args;

        // Build qmake
        QString pwd = QDir::currentPath();
        QDir::setCurrent(buildPath + "/qmake" );

        QString makefile = "Makefile";
        {
            QFile out(makefile);
            if(out.open(QFile::WriteOnly | QFile::Text)) {
                QTextStream stream(&out);
                stream << "#AutoGenerated by configure.exe" << endl
                    << "BUILD_PATH = " << QDir::convertSeparators(buildPath) << endl
                    << "SOURCE_PATH = " << QDir::convertSeparators(sourcePath) << endl;
                stream << "QMAKESPEC = " << dictionary["QMAKESPEC"] << endl;

                if (dictionary["EDITION"] == "OpenSource" ||
                    dictionary["QT_EDITION"].contains("OPENSOURCE"))
                    stream << "QMAKE_OPENSOURCE_EDITION = yes" << endl;
                stream << "\n\n";

                QFile in(sourcePath + "/qmake/" + dictionary["QMAKEMAKEFILE"]);
                if(in.open(QFile::ReadOnly | QFile::Text)) {
                    QString d = in.readAll();
                    //### need replaces (like configure.sh)? --Sam
                    stream << d << endl;
                }
                stream.flush();
                out.close();
            }
        }

        args += dictionary[ "MAKE" ];
        args += "-f";
        args += makefile;

        cout << "Creating qmake..." << endl;
        int exitCode = 0;
        if( exitCode = Environment::execute(args, QStringList(), QStringList()) ) {
            args.clear();
            args += dictionary[ "MAKE" ];
            args += "-f";
            args += makefile;
            args += "clean";
            if( exitCode = Environment::execute(args, QStringList(), QStringList())) {
                cout << "Cleaning qmake failed, return code " << exitCode << endl << endl;
                dictionary[ "DONE" ] = "error";
            } else {
                args.clear();
                args += dictionary[ "MAKE" ];
                args += "-f";
                args += makefile;
                if (exitCode = Environment::execute(args, QStringList(), QStringList())) {
                    cout << "Building qmake failed, return code " << exitCode << endl << endl;
                    dictionary[ "DONE" ] = "error";
                }
            }
        }
        QDir::setCurrent( pwd );
    }
}
#endif

void Configure::buildHostTools()
{
    if (dictionary[ "NOPROCESS" ] == "yes")
        dictionary[ "DONE" ] = "yes";

    if (!dictionary.contains("XQMAKESPEC"))
        return;

    QString pwd = QDir::currentPath();
    QStringList hostToolsDirs;
    hostToolsDirs
        << "src/tools/bootstrap"
        << "src/tools/moc"
        << "src/tools/rcc"
        << "src/tools/uic";

    if(dictionary["XQMAKESPEC"].startsWith("wince"))
        hostToolsDirs << "tools/checksdk";

    if (dictionary[ "CETEST" ] == "yes")
        hostToolsDirs << "tools/qtestlib/wince/cetest";

    for (int i = 0; i < hostToolsDirs.count(); ++i) {
        cout << "Creating " << hostToolsDirs.at(i) << " ..." << endl;
        QString toolBuildPath = buildPath + "/" + hostToolsDirs.at(i);
        QString toolSourcePath = sourcePath + "/" + hostToolsDirs.at(i);

        // generate Makefile
        QStringList args;
        args << QDir::toNativeSeparators(buildPath + "/bin/qmake");
        args << "-spec" << dictionary["QMAKESPEC"] << "-r";
        args << "-o" << QDir::toNativeSeparators(toolBuildPath + "/Makefile");

        QDir().mkpath(toolBuildPath);
        QDir::setCurrent(toolSourcePath);
        int exitCode = 0;
        if (exitCode = Environment::execute(args, QStringList(), QStringList())) {
            cout << "qmake failed, return code " << exitCode << endl << endl;
            dictionary["DONE"] = "error";
            break;
        }

        // build app
        args.clear();
        args += dictionary["MAKE"];
        QDir::setCurrent(toolBuildPath);
        if (exitCode = Environment::execute(args, QStringList(), QStringList())) {
            args.clear();
            args += dictionary["MAKE"];
            args += "clean";
            if(exitCode = Environment::execute(args, QStringList(), QStringList())) {
                cout << "Cleaning " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl;
                dictionary["DONE"] = "error";
                break;
            } else {
                args.clear();
                args += dictionary["MAKE"];
                if (exitCode = Environment::execute(args, QStringList(), QStringList())) {
                    cout << "Building " << hostToolsDirs.at(i) << " failed, return code " << exitCode << endl << endl;
                    dictionary["DONE"] = "error";
                    break;
                }
            }
        }
    }
    QDir::setCurrent(pwd);
}

void Configure::findProjects( const QString& dirName )
{
    if( dictionary[ "NOPROCESS" ] == "no" ) {
        QDir dir( dirName );
        QString entryName;
        int makeListNumber;
        ProjectType qmakeTemplate;
        const QFileInfoList &list = dir.entryInfoList(QStringList(QLatin1String("*.pro")),
                                                      QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
        for(int i = 0; i < list.size(); ++i) {
            const QFileInfo &fi = list.at(i);
            if(fi.fileName() != "qmake.pro") {
                entryName = dirName + "/" + fi.fileName();
                if(fi.isDir()) {
                    findProjects( entryName );
                } else {
                    qmakeTemplate = projectType( fi.absoluteFilePath() );
                    switch ( qmakeTemplate ) {
                    case Lib:
                    case Subdirs:
                        makeListNumber = 1;
                        break;
                    default:
                        makeListNumber = 2;
                        break;
                    }
                    makeList[makeListNumber].append(new MakeItem(sourceDir.relativeFilePath(fi.absolutePath()),
                                                    fi.fileName(),
                                                    "Makefile",
                                                    qmakeTemplate));
                }
            }

        }
    }
}

void Configure::appendMakeItem(int inList, const QString &item)
{
    QString dir;
    if (item != "src")
        dir = "/" + item;
    dir.prepend("/src");
    makeList[inList].append(new MakeItem(sourcePath + dir,
        item + ".pro", buildPath + dir + "/Makefile", Lib ) );
    if( dictionary[ "DSPFILES" ] == "yes" ) {
        makeList[inList].append( new MakeItem(sourcePath + dir,
            item + ".pro", buildPath + dir + "/" + item + ".dsp", Lib ) );
    }
    if( dictionary[ "VCPFILES" ] == "yes" ) {
        makeList[inList].append( new MakeItem(sourcePath + dir,
            item + ".pro", buildPath + dir + "/" + item + ".vcp", Lib ) );
    }
    if( dictionary[ "VCPROJFILES" ] == "yes" ) {
        makeList[inList].append( new MakeItem(sourcePath + dir,
            item + ".pro", buildPath + dir + "/" + item + ".vcproj", Lib ) );
    }
}

void Configure::generateMakefiles()
{
    if( dictionary[ "NOPROCESS" ] == "no" ) {
#if !defined(EVAL)
        cout << "Creating makefiles in src..." << endl;
#endif

        QString spec = dictionary.contains("XQMAKESPEC") ? dictionary[ "XQMAKESPEC" ] : dictionary[ "QMAKESPEC" ];
        if( spec != "win32-msvc" )
            dictionary[ "DSPFILES" ] = "no";

        if( spec != "win32-msvc.net" && !spec.startsWith("win32-msvc2") && !spec.startsWith(QLatin1String("wince")))
            dictionary[ "VCPROJFILES" ] = "no";

        int i = 0;
        QString pwd = QDir::currentPath();
        if (dictionary["FAST"] != "yes") {
            QString dirName;
            bool generate = true;
            bool doDsp = (dictionary["DSPFILES"] == "yes" || dictionary["VCPFILES"] == "yes"
                          || dictionary["VCPROJFILES"] == "yes");
            while (generate) {
                QString pwd = QDir::currentPath();
                QString dirPath = fixSeparators(buildPath + dirName);
                QStringList args;

                args << fixSeparators( buildPath + "/bin/qmake" );

                if (doDsp) {
                    if( dictionary[ "DEPENDENCIES" ] == "no" )
                        args << "-nodepend";
                    args << "-tp" <<  "vc";
                    doDsp = false; // DSP files will be done
                    printf("Generating Visual Studio project files...\n");
                } else {
                    printf("Generating Makefiles...\n");
                    generate = false; // Now Makefiles will be done
                }
                args << "-spec";
                args << spec;
                args << "-r";
                args << (sourcePath + "/projects.pro");
                args << "-o";
                args << buildPath;
                if(!dictionary[ "QMAKEADDITIONALARGS" ].isEmpty())
                    args << dictionary[ "QMAKEADDITIONALARGS" ];

                QDir::setCurrent( fixSeparators( dirPath ) );
                if( int exitCode = Environment::execute(args, QStringList(), QStringList()) ) {
                    cout << "Qmake failed, return code " << exitCode  << endl << endl;
                    dictionary[ "DONE" ] = "error";
                }
            }
        } else {
            findProjects(sourcePath);
            for ( i=0; i<3; i++ ) {
                for ( int j=0; j<makeList[i].size(); ++j) {
                    MakeItem *it=makeList[i][j];
                    QString dirPath = fixSeparators( it->directory + "/" );
                    QString projectName = it->proFile;
                    QString makefileName = buildPath + "/" + dirPath + it->target;

                    // For shadowbuilds, we need to create the path first
                    QDir buildPathDir(buildPath);
                    if (sourcePath != buildPath && !buildPathDir.exists(dirPath))
                        buildPathDir.mkpath(dirPath);

                    QStringList args;

                    args << fixSeparators( buildPath + "/bin/qmake" );
                    args << sourcePath + "/" + dirPath + projectName;
                    args << dictionary[ "QMAKE_ALL_ARGS" ];

                    cout << "For " << qPrintable(dirPath + projectName) << endl;
                    args << "-o";
                    args << it->target;
                    args << "-spec";
                    args << spec;
                    if(!dictionary[ "QMAKEADDITIONALARGS" ].isEmpty())
                        args << dictionary[ "QMAKEADDITIONALARGS" ];

                    QDir::setCurrent( fixSeparators( dirPath ) );

                    QFile file(makefileName);
                    if (!file.open(QFile::WriteOnly)) {
                        printf("failed on dirPath=%s, makefile=%s\n",
                            qPrintable(dirPath), qPrintable(makefileName));
                        continue;
                    }
                    QTextStream txt(&file);
                    txt << "all:\n";
                    txt << "\t" << args.join(" ") << "\n";
                    txt << "\t" << dictionary[ "MAKE" ] << " -f " << it->target << "\n";
                    txt << "first: all\n";
                    txt << "qmake:\n";
                    txt << "\t" << args.join(" ") << "\n";
                }
            }
        }
        QDir::setCurrent( pwd );
    } else {
        cout << "Processing of project files have been disabled." << endl;
        cout << "Only use this option if you really know what you're doing." << endl << endl;
        return;
    }
}

void Configure::showSummary()
{
    QString make = dictionary[ "MAKE" ];
    if (!dictionary.contains("XQMAKESPEC")) {
        cout << endl << endl << "Qt is now configured for building. Just run " << qPrintable(make) << "." << endl;
        cout << "To reconfigure, run " << qPrintable(make) << " confclean and configure." << endl << endl;
    } else if(dictionary.value("QMAKESPEC").startsWith("wince")) {
        // we are cross compiling for Windows CE
        cout << endl << endl << "Qt is now configured for building. To start the build run:" << endl
             << "\tsetcepaths " << dictionary.value("XQMAKESPEC") << endl
             << "\t" << qPrintable(make) << endl
             << "To reconfigure, run " << qPrintable(make) << " confclean and configure." << endl << endl;
    } else { // Compiling for Symbian OS
        cout << endl << endl << "Qt is now configured for building. To start the build run:" << qPrintable(dictionary["QTBUILDINSTRUCTION"]) << "." << endl
        << "To reconfigure, run '" << qPrintable(dictionary["CONFCLEANINSTRUCTION"]) << "' and configure." << endl;
    }
}

Configure::ProjectType Configure::projectType( const QString& proFileName )
{
    QFile proFile( proFileName );
    if( proFile.open( QFile::ReadOnly ) ) {
        QString buffer = proFile.readLine(1024);
        while (!buffer.isEmpty()) {
            QStringList segments = buffer.split(QRegExp( "\\s" ));
            QStringList::Iterator it = segments.begin();

            if(segments.size() >= 3) {
                QString keyword = (*it++);
                QString operation = (*it++);
                QString value = (*it++);

                if( keyword == "TEMPLATE" ) {
                    if( value == "lib" )
                        return Lib;
                    else if( value == "subdirs" )
                        return Subdirs;
                }
            }
            // read next line
            buffer = proFile.readLine(1024);
        }
        proFile.close();
    }
    // Default to app handling
    return App;
}

#if !defined(EVAL)

bool Configure::showLicense(QString orgLicenseFile)
{
    if (dictionary["LICENSE_CONFIRMED"] == "yes") {
        cout << "You have already accepted the terms of the license." << endl << endl;
        return true;
    }

    QString licenseFile = orgLicenseFile;
    QString theLicense;
    if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
        theLicense = "GNU General Public License (GPL) version 3 \nor the GNU Lesser General Public License (LGPL) version 2.1";
    } else {
        // the first line of the license file tells us which license it is
        QFile file(licenseFile);
        if (!file.open(QFile::ReadOnly)) {
            cout << "Failed to load LICENSE file" << endl;
            return false;
        }
        theLicense = file.readLine().trimmed();
    }

    forever {
        char accept = '?';
        cout << "You are licensed to use this software under the terms of" << endl
             << "the " << theLicense << "." << endl
             << endl;
        if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
            cout << "Type '3' to view the GNU General Public License version 3 (GPLv3)." << endl;
            cout << "Type 'L' to view the Lesser GNU General Public License version 2.1 (LGPLv2.1)." << endl;
        } else {
            cout << "Type '?' to view the " << theLicense << "." << endl;
        }
        cout << "Type 'y' to accept this license offer." << endl
             << "Type 'n' to decline this license offer." << endl
             << endl
             << "Do you accept the terms of the license?" << endl;
        cin >> accept;
        accept = tolower(accept);

        if (accept == 'y') {
            return true;
        } else if (accept == 'n') {
            return false;
        } else {
            if (dictionary["EDITION"] == "OpenSource" || dictionary["EDITION"] == "Snapshot") {
                if (accept == '3')
                    licenseFile = orgLicenseFile + "/LICENSE.GPL3";
                else
                    licenseFile = orgLicenseFile + "/LICENSE.LGPL";
            }
            // Get console line height, to fill the screen properly
            int i = 0, screenHeight = 25; // default
            CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
            HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
            if (GetConsoleScreenBufferInfo(stdOut, &consoleInfo))
                screenHeight = consoleInfo.srWindow.Bottom
                             - consoleInfo.srWindow.Top
                             - 1; // Some overlap for context

            // Prompt the license content to the user
            QFile file(licenseFile);
            if (!file.open(QFile::ReadOnly)) {
                cout << "Failed to load LICENSE file" << licenseFile << endl;
                return false;
            }
            QStringList licenseContent = QString(file.readAll()).split('\n');
            while(i < licenseContent.size()) {
                cout << licenseContent.at(i) << endl;
                if (++i % screenHeight == 0) {
                    cout << "(Press any key for more..)";
                    if(_getch() == 3) // _Any_ keypress w/no echo(eat <Enter> for stdout)
                        exit(0);      // Exit cleanly for Ctrl+C
                    cout << "\r";     // Overwrite text above
                }
            }
        }
    }
}

void Configure::readLicense()
{
   if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/src/corelib/kernel/qfunctions_wince.h") &&
       (dictionary.value("QMAKESPEC").startsWith("wince") || dictionary.value("XQMAKESPEC").startsWith("wince")))
        dictionary["PLATFORM NAME"] = "Qt for Windows CE";
    else if (dictionary.value("XQMAKESPEC").startsWith("symbian"))
        dictionary["PLATFORM NAME"] = "Qt for S60";
    else
        dictionary["PLATFORM NAME"] = "Qt for Windows";
    dictionary["LICENSE FILE"] = sourcePath;

    bool openSource = false;
    bool hasOpenSource = QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.GPL3") || QFile::exists(dictionary["LICENSE FILE"] + "/LICENSE.LGPL");
    if (dictionary["BUILDNOKIA"] == "yes" || dictionary["BUILDTYPE"] == "commercial") {
        openSource = false;
    } else if (dictionary["BUILDTYPE"] == "opensource") {
        openSource = true;
    } else if (hasOpenSource) { // No Open Source? Just display the commercial license right away
        forever {
            char accept = '?';
            cout << "Which edition of Qt do you want to use ?" << endl;
            cout << "Type 'c' if you want to use the Commercial Edition." << endl;
            cout << "Type 'o' if you want to use the Open Source Edition." << endl;
            cin >> accept;
            accept = tolower(accept);

            if (accept == 'c') {
                openSource = false;
                break;
            } else if (accept == 'o') {
                openSource = true;
                break;
            }
        }
    }
    if (hasOpenSource && openSource) {
        cout << endl << "This is the " << dictionary["PLATFORM NAME"] << " Open Source Edition." << endl;
        licenseInfo["LICENSEE"] = "Open Source";
        dictionary["EDITION"] = "OpenSource";
        dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
        cout << endl;
        if (!showLicense(dictionary["LICENSE FILE"])) {
            cout << "Configuration aborted since license was not accepted";
            dictionary["DONE"] = "error";
            return;
        }
    } else if (openSource) {
        cout << endl << "Cannot find the GPL license files! Please download the Open Source version of the library." << endl;
        dictionary["DONE"] = "error";
    }
#ifdef COMMERCIAL_VERSION
    else {
        Tools::checkLicense(dictionary, licenseInfo, firstLicensePath());
        if (dictionary["DONE"] != "error" && dictionary["BUILDNOKIA"] != "yes") {
            // give the user some feedback, and prompt for license acceptance
            cout << endl << "This is the " << dictionary["PLATFORM NAME"] << " " << dictionary["EDITION"] << " Edition."<< endl << endl;
            if (!showLicense(dictionary["LICENSE FILE"])) {
                cout << "Configuration aborted since license was not accepted";
                dictionary["DONE"] = "error";
                return;
            }
        }
    }
#else // !COMMERCIAL_VERSION
    else {
        cout << endl << "Cannot build commercial edition from the open source version of the library." << endl;
        dictionary["DONE"] = "error";
    }
#endif
}

void Configure::reloadCmdLine()
{
    if( dictionary[ "REDO" ] == "yes" ) {
        QFile inFile( buildPath + "/configure" + dictionary[ "CUSTOMCONFIG" ] + ".cache" );
        if( inFile.open( QFile::ReadOnly ) ) {
            QTextStream inStream( &inFile );
            QString buffer;
            inStream >> buffer;
            while( buffer.length() ) {
                configCmdLine += buffer;
                inStream >> buffer;
            }
            inFile.close();
        }
    }
}

void Configure::saveCmdLine()
{
    if( dictionary[ "REDO" ] != "yes" ) {
        QFile outFile( buildPath + "/configure" + dictionary[ "CUSTOMCONFIG" ] + ".cache" );
        if( outFile.open( QFile::WriteOnly | QFile::Text ) ) {
            QTextStream outStream( &outFile );
            for( QStringList::Iterator it = configCmdLine.begin(); it != configCmdLine.end(); ++it ) {
                outStream << (*it) << " " << endl;
            }
            outStream.flush();
            outFile.close();
        }
    }
}
#endif // !EVAL

bool Configure::isDone()
{
    return !dictionary["DONE"].isEmpty();
}

bool Configure::isOk()
{
    return (dictionary[ "DONE" ] != "error");
}

bool
Configure::filesDiffer(const QString &fn1, const QString &fn2)
{
    QFile file1(fn1), file2(fn2);
    if(!file1.open(QFile::ReadOnly) || !file2.open(QFile::ReadOnly))
        return true;
    const int chunk = 2048;
    int used1 = 0, used2 = 0;
    char b1[chunk], b2[chunk];
    while(!file1.atEnd() && !file2.atEnd()) {
        if(!used1)
            used1 = file1.read(b1, chunk);
        if(!used2)
            used2 = file2.read(b2, chunk);
        if(used1 > 0 && used2 > 0) {
            const int cmp = qMin(used1, used2);
            if(memcmp(b1, b2, cmp))
                return true;
            if((used1 -= cmp))
                memcpy(b1, b1+cmp, used1);
            if((used2 -= cmp))
                memcpy(b2, b2+cmp, used2);
        }
    }
    return !file1.atEnd() || !file2.atEnd();
}

QT_END_NAMESPACE