Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: trunk
file 4091 lines (3814 sloc) 129.295 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 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 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090
dnl Process this file with autoconf to produce a configure script.
AC_INIT()
{
AC_CONFIG_AUX_DIR(tool)

AC_PREREQ(2.67)

AC_DEFUN([RUBY_PREREQ_AC],
[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]), [$1]), [-1],
AC_MSG_ERROR([Autoconf version ]$1[ or higher is required]$2))])

AC_DISABLE_OPTION_CHECKING

AC_DEFUN([RUBY_RM_RECURSIVE], [
m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]), [2.70]), [-1], [
# suppress error messages, rm: cannot remove 'conftest.dSYM', from
# AC_EGREP_CPP with CFLAGS=-g on Darwin.
#
# TODO: remove this hack when AC_PREREQ() becomes 2.70 or later.
AS_CASE([$build_os], [darwin*], [
rm() {
    rm_recursive=''
    for arg do
AS_CASE("$arg",
[--*], [],
[-*r*], [break],
[conftest.*], [if test -d "$arg"; then rm_recursive=-r; break; fi],
[])
    done
    command rm $rm_recursive "[$]@"
}
])])])

{ # environment section

AC_ARG_WITH(baseruby,
AS_HELP_STRING([--with-baseruby=RUBY], [use RUBY as baseruby; RUBY is the pathname of ruby]),
[
AS_CASE(["$withval"],[*ruby*],[BASERUBY=$withval],[AC_MSG_ERROR(need ruby)])
],
[
BASERUBY="ruby"
])
if test "`RUBYOPT=- $BASERUBY -e 'p 42' 2>/dev/null`" = 42; then
    if test "`RUBYOPT=- $BASERUBY --disable=gems -e 'p 42' 2>/dev/null`" = 42; then
BASERUBY="$BASERUBY --disable=gems"
    fi
else
    BASERUBY="echo executable host ruby is required. use --with-baseruby option.; false"
fi
AC_SUBST(BASERUBY)

for conf in config.guess config.sub; do
    test -f "$srcdir/tool/$conf" && continue
    $BASERUBY -C "$srcdir/tool" get-config_files $conf
done

AC_DEFUN([RUBY_MINGW32],
[AS_CASE(["$host_os"],
[cygwin*], [
AC_CACHE_CHECK(for mingw32 environment, rb_cv_mingw32,
[AC_TRY_CPP([
#ifndef __MINGW32__
# error
#endif
], rb_cv_mingw32=yes,rb_cv_mingw32=no)
rm -f conftest*])
if test "$rb_cv_mingw32" = yes; then
    target_os="mingw32"
    : ${ac_tool_prefix:="`expr "$CC" : ['\(.*-\)g\?cc[^/]*$']`"}
fi
])
AS_CASE(["$target_os"], [mingw*msvc], [
target_os="`echo ${target_os} | sed 's/msvc$//'`"
])
AS_CASE(["$target_cpu-$target_os"], [x86_64-mingw*], [
target_cpu=x64
])
])

AC_DEFUN([RUBY_NACL],
[
 AS_CASE(["${host_os}"],
[nacl], [
  ac_cv_exeext=.nexe
  host_vendor=chromium
  ac_cv_host=chromium
  AC_MSG_CHECKING([wheather \$NACL_SDK_ROOT is set])
  if test x"${NACL_SDK_ROOT}" = x; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([You need to set \$NACL_SDK_ROOT environment variable to build for NativeClient])
  fi
  AC_MSG_RESULT([yes])

  nacl_cv_build_variant=glibc
  AC_ARG_WITH(newlib,
              AS_HELP_STRING([--with-newlib], [uses newlib version of NativeClient SDK]),
              [AS_CASE([$withval],
                       [no], [nacl_cv_build_variant=glibc],
                       [yes], [nacl_cv_build_variant=newlib])])

  AS_CASE(["$build_cpu"],
          [x86_64|i?86], [nacl_cv_cpu_nick=x86], [nacl_cv_cpu_nick=$build_cpu])
  AS_CASE(["$build_os"],
          [linux*], [nacl_cv_os_nick=linux],
          [darwin*], [nacl_cv_os_nick=mac],
          [cygwin*|mingw*], [nacl_cv_os_nick=win],
          [nacl_cv_os_nick=$build_os])

  host="$host_cpu-chromium-$host_os-"
  ac_tool_prefix="$host_cpu-nacl-"

  AC_MSG_CHECKING([NativeClient toolchain])
  if test -d \
    "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"; then
    NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"
  else
    AS_CASE(
      ["${nacl_cv_build_variant}"],
      [glibc], [if test \
        -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_newlib" \
        -a -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"; then
        NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"
      fi],
      [newlib], [ NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}" ])
  fi
  if test ! -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/${ac_tool_prefix}gcc"; then
    if test "${build_cpu}" = i686 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
      ac_tool_prefix=nacl-
    fi
    if test "${build_cpu}" = x86_64 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
      ac_tool_prefix=nacl64-
    fi
  fi
  if test -z "${NACL_TOOLCHAIN}"; then
    AC_MSG_ERROR([Unrecognized --host and --build combination or NaCl SDK is not installed])
  fi
  AC_MSG_RESULT(${NACL_TOOLCHAIN})

  AC_MSG_CHECKING([path to SDK])
  if ! echo -- "${PATH}" | grep -F "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/bin" > /dev/null; then
    PATH="${PATH}:${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/bin"
  fi

  AC_SUBST(NACL_TOOLCHAIN)
  AC_SUBST(NACL_SDK_ROOT)
  AC_SUBST(NACL_SDK_VARIANT, nacl_cv_build_variant)
])])

AC_DEFUN([RUBY_NACL_CHECK_PEPPER_TYPES],
[AS_CASE(["${host_os}"],
[nacl], [
 AC_CHECK_TYPES([struct PPB_Core, struct PPB_Messaging, struct PPB_Var,
              struct PPB_URLLoader, struct PPB_URLRequestInfo,
              struct PPB_URLResponseInfo, struct PPB_FileRef,
              struct PPP_Instance])
])
])

AC_DEFUN([RUBY_CPPOUTFILE],
[AC_CACHE_CHECK(whether ${CPP} accepts -o, rb_cv_cppoutfile,
[save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS='-o conftest-1.i'
rb_cv_cppoutfile=no
AC_TRY_CPP([test-for-cppout],
[grep test-for-cppout conftest-1.i > /dev/null && rb_cv_cppoutfile=yes])
CPPFLAGS="$save_CPPFLAGS"
rm -f conftest*])
if test "$rb_cv_cppoutfile" = yes; then
  CPPOUTFILE='-o conftest.i'
elif test "$rb_cv_cppoutfile" = no; then
  CPPOUTFILE='> conftest.i'
elif test -n "$rb_cv_cppoutfile"; then
  CPPOUTFILE="$rb_cv_cppoutfile"
fi
AC_SUBST(CPPOUTFILE)])

AC_DEFUN([RUBY_PROG_GNU_LD],
[AC_CACHE_CHECK(whether the linker is GNU ld, rb_cv_prog_gnu_ld,
[if `$CC $CFLAGS $CPPFLAGS $LDFLAGS --print-prog-name=ld 2>&1` -v 2>&1 | grep "GNU ld" > /dev/null; then
  rb_cv_prog_gnu_ld=yes
else
  rb_cv_prog_gnu_ld=no
fi
])
GNU_LD=$rb_cv_prog_gnu_ld
AC_SUBST(GNU_LD)])

eval `sed -n 's/^#define RUBY_API_VERSION_\([A-Z][A-Z_0-9]*\) \([0-9][0-9]*\)/\1=\2/p' $srcdir/include/ruby/version.h`
for v in MAJOR MINOR TEENY; do
    if eval "test \"\$$v\" = ''"; then
AC_MSG_ERROR(could not determine $v number from version.h)
    fi
done
AC_SUBST(MAJOR)
AC_SUBST(MINOR)
AC_SUBST(TEENY)
RUBY_PROGRAM_VERSION=`sed -n 's/^#define RUBY_VERSION "\(.*\)"/\1/p' $srcdir/version.h`
AC_SUBST(RUBY_PROGRAM_VERSION)
RUBY_RELEASE_DATE=`sed -n 's/^#define RUBY_RELEASE_DATE "\(.*\)"/\1/p' $srcdir/version.h`
AC_SUBST(RUBY_RELEASE_DATE)
RUBY_PATCHLEVEL=`sed -n 's/^#define RUBY_PATCHLEVEL //p' $srcdir/version.h`
AC_DEFINE(CANONICALIZATION_FOR_MATHN)
dnl checks for alternative programs
AC_CANONICAL_BUILD
RUBY_RM_RECURSIVE
AC_ARG_WITH(gcc,
AS_HELP_STRING([--without-gcc], [never use gcc]),
[
AS_CASE([$withval],
[no], [: ${CC=cc}],
[yes], [: ${CC=gcc}],
[CC=$withval])])
dnl If the user switches compilers, we can't believe the cache
if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"
then
  AC_MSG_ERROR(cached CC is different -- throw away $cache_file
(it is also a good idea to do 'make clean' before compiling))
fi
AS_CASE(["$build_os"],
  [darwin1*.*], [
    AS_CASE(["x$CC"],
      [xgcc-4.2|x/usr/bin/gcc-4.2], [: ${CXX=g++-4.2}],
      [xgcc|x/usr/bin/gcc], [: ${CXX=g++}],
      [xcc|x/usr/bin/cc], [: ${CXX=c++}],
      [xclang|x/usr/bin/clang], [: ${CXX=clang++}])
  ])
test -z "$CC" || ac_cv_prog_CC="$CC"
test -z "$CXX" || ac_cv_prog_CXX="$CXX"

if test "$program_prefix" = NONE; then
  program_prefix=
fi
RUBY_BASE_NAME=`echo ruby | sed "$program_transform_name"`
RUBYW_BASE_NAME=`echo rubyw | sed "$program_transform_name"`
AC_SUBST(RUBY_BASE_NAME)
AC_SUBST(RUBYW_BASE_NAME)
AC_SUBST(RUBY_VERSION_NAME, '${RUBY_BASE_NAME}-${ruby_version}')

AC_CANONICAL_TARGET
test x"$target_alias" = x &&
target_os=`echo $target_os | sed 's/linux-gnu$/linux/;s/linux-gnu/linux-/'`
ac_install_sh='' # unusable for extension libraries.

AC_ARG_WITH(os-version-style,
AS_HELP_STRING([--with-os-version-style=TYPE],
[OS version number for target and target_os [[full]]]
[(full|teeny|minor+0|minor|major+0|major|none)]),
[os_version_style=$withval],
[os_version_style=full
AS_CASE($target_os, [[*[0-9].*]],
[AS_CASE([`/usr/bin/ruby -e 'puts RUBY_PLATFORM' 2>/dev/null`],
[[*-*[0-9].*.0]], [os_version_style=minor+0],
[[*-*[0-9].*.*]], [os_version_style=full],
[[*-*[0-9].0] ], [os_version_style=major+0],
[[*-*[0-9].*] ], [os_version_style=minor],
[[*-*[0-9]] ], [os_version_style=major],
)])
])
os_version_style_transform=
AS_CASE("${os_version_style}",
[full|teeny], [],
[minor+0], [os_version_style_transform=['s/\([0-9]\.[0-9][0-9]*\)\.[0-9][.0-9]*$/\1.0/']],
[minor], [os_version_style_transform=['s/\([0-9]\.[0-9][0-9]*\)\.[0-9][.0-9]*$/\1/']],
[major+0], [os_version_style_transform=['s/\([0-9]\)\.[0-9][.0-9]*$/\1.0/']],
[major], [os_version_style_transform=['s/\([0-9]\)\.[0-9][.0-9]*$/\1/']],
[none], [os_version_style_transform=['s/[0-9]\.[0-9][.0-9]*$//']],
[AC_MSG_ERROR(unknown --with-os-version-style: $withval)])
AS_IF([test -z "$target_alias" -a -n "$os_version_style_transform"],
[
target=`echo ${target} | sed "$os_version_style_transform"`
target_os=`echo ${target_os} | sed "$os_version_style_transform"`
])

AC_DEFUN([RUBY_APPEND_OPTION],
[# RUBY_APPEND_OPTION($1)
AS_CASE([" [$]{$1-} "],
[*' $2 '*], [], [' '], [ $1="$2"], [ $1="[$]$1 $2"])])
AC_DEFUN([RUBY_APPEND_OPTIONS],
[# RUBY_APPEND_OPTIONS($1)
for rb_opt in $2; do
AS_CASE([" [$]{$1-} "],
[*" [$]{rb_opt} "*], [], [' '], [ $1="[$]{rb_opt}"], [ $1="[$]$1 [$]{rb_opt}"])
done])
AC_DEFUN([RUBY_PREPEND_OPTION],
[# RUBY_PREPEND_OPTION($1)
AS_CASE([" [$]{$1-} "],
[*' $2 '*], [], [' '], [ $1="$2"], [ $1="$2 [$]$1"])])
AC_DEFUN([RUBY_PREPEND_OPTIONS],
[# RUBY_PREPEND_OPTIONS($1)
unset rb_opts; for rb_opt in $2; do
AS_CASE([" [$]{rb_opts} [$]{$1-} "],
[*" [$]{rb_opt} "*], [], [' '], [ $1="[$]{rb_opt}"], [ rb_opts="[$]{rb_opts}[$]{rb_opt} "])
done
$1="[$]{rb_opts}[$]$1"])

AC_ARG_WITH(arch,
AS_HELP_STRING([--with-arch=ARCHS],
[build an Apple/NeXT Multi Architecture Binary (MAB);
                          ARCHS is a comma-delimited list of architectures for
                          which to build; if this option is disabled or omitted
entirely, then the package will be built only for the
target platform]),
       [target_archs="$withval"], [unset target_archs])

AC_DEFUN([RUBY_DEFAULT_ARCH], [
AC_MSG_CHECKING([arch option])
AS_CASE([$1],
[*64], [ARCH_FLAG=-m64],
[[i[3-6]86]], [ARCH_FLAG=-m32],
[AC_MSG_ERROR(unknown target architecture: $target_archs)]
)
AC_MSG_RESULT([$ARCH_FLAG])
])

AC_DEFUN([RUBY_UNIVERSAL_ARCH], [
# RUBY_UNIVERSAL_ARCH begin
ARCH_FLAG=`expr " $CFLAGS " : ['.* \(-m[0-9][0-9]*\) ']`
test ${CFLAGS+set} && CFLAGS=`echo "$CFLAGS" | sed -e 's/ *-arch *[^ ]*//g' -e 's/ *-m32//g' -e 's/ *-m64//g'`
test ${LDFLAGS+set} && LDFLAGS=`echo "$LDFLAGS" | sed -e 's/ *-arch *[^ ]*//g' -e 's/ *-m32//g' -e 's/ *-m64//g'`
unset universal_binary universal_archnames
if test ${target_archs+set}; then
    AC_MSG_CHECKING([target architectures])
    target_archs=`echo $target_archs | tr , ' '`
    # /usr/lib/arch_tool -archify_list $TARGET_ARCHS
    for archs in $target_archs
    do
AS_CASE([",$universal_binary,"],[*",$archs,"*], [],[
cpu=`$SHELL "$ac_aux_dir/config.sub" "${archs}-${target_os}" 2>&1` || {
AC_MSG_RESULT([failed])
AC_MSG_ERROR([$cpu])
}
cpu=`echo $cpu | sed 's/-.*-.*//'`
universal_binary="${universal_binary+$universal_binary,}$cpu"
universal_archnames="${universal_archnames} ${archs}=${cpu}"
ARCH_FLAG="${ARCH_FLAG+$ARCH_FLAG }-arch $archs"
])
    done
    target_archs="$universal_binary"
    unset universal_binary
    AS_CASE(["$target_archs"],
      [*,*], [universal_binary=yes],
             [unset universal_archnames])
    AC_MSG_RESULT([$target_archs])

    target=`echo $target | sed "s/^$target_cpu-/-/"`
    target_alias=`echo $target_alias | sed "s/^$target_cpu-/-/"`
    if test "${universal_binary-no}" = yes; then
AC_SUBST(try_header,try_compile)
target_cpu=universal
real_cross_compiling=$cross_compiling
    else
if test x"$target_cpu" != x"${target_archs}"; then
echo 'int main(){return 0;}' > conftest.c
if $CC $CFLAGS $ARCH_FLAG -o conftest conftest.c > /dev/null 2>&1; then
rm -fr conftest.*
else
RUBY_DEFAULT_ARCH("$target_archs")
fi
fi
target_cpu=${target_archs}
    fi
    AS_CASE(["$target"], [-*], [ target="$target_cpu${target}"])
    AS_CASE(["$target_alias"], [-*], [ target_alias="$target_cpu${target_alias}"])
else
    if test x"$target_alias" = x; then
AS_CASE(["$target_os"],
[darwin*], [
AC_MSG_CHECKING([for real target cpu])
target=`echo $target | sed "s/^$target_cpu-/-/"`
target_cpu=`$CC -E - 2>/dev/null <<EOF |
#ifdef __x86_64__
"processor-name=x86_64"
#endif
#ifdef __i386__
"processor-name=i386"
#endif
#ifdef __ppc__
"processor-name=powerpc"
#endif
#ifdef __ppc64__
"processor-name=powerpc64"
#endif
EOF
sed -n 's/^"processor-name=\(.*\)"/\1/p'`
target="$target_cpu${target}"
AC_MSG_RESULT([$target_cpu])
])
    fi
    target_archs="$target_cpu"
fi
if test "${target_archs}" != "${rb_cv_target_archs-${target_archs}}"; then
    AC_MSG_ERROR([target arch(s) has changed from ${rb_cv_target_archs-nothing} to ${target_archs}])
else
    rb_cv_target_archs=${target_archs}
fi
if test "x${ARCH_FLAG}" != x; then
    CFLAGS="$CFLAGS ${ARCH_FLAG}"
    LDFLAGS="${LDFLAGS+$LDFLAGS }${ARCH_FLAG}"
fi
# RUBY_UNIVERSAL_ARCH end
])

AC_ARG_ENABLE(load-relative,
       AS_HELP_STRING([--enable-load-relative], [resolve load paths at run time]),
       [load_relative=$enableval])

AC_ARG_PROGRAM

dnl Checks for programs.

cflagspat=
test -z "$optflags" ||
    cflagspat="$cflagspat;s|"`eval echo '"'"${optflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
test -z "$debugflags" ||
    cflagspat="$cflagspat;s|"`eval echo '"'"${debugflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
test -z "warnflags" ||
    cflagspat="$cflagspat;s|"`eval echo '"'"${warnflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/ *$/ /'`'| |g'
if test -z "${CFLAGS+set}"; then
    cflags=`echo " $cflags " | sed "$cflagspat;s/^ *//;s/ *$//"`
    orig_cflags="$cflags"
    cflags="$cflags "'${optflags} ${debugflags} ${warnflags}'
fi
if test -z "${CXXFLAGS+set}"; then
    cxxflags=`echo " $cxxflags " | sed "$cflagspat;s/^ *//;s/ *$//"`
    orig_cxxflags="$cxxflags"
    cxxflags="$cxxflags "'${optflags} ${debugflags} ${warnflags}'
fi

RUBY_NACL
AS_CASE(["$host_os:$build_os"],
[darwin*:darwin*], [
    AC_CHECK_TOOLS(CC, [gcc-4.2 clang gcc cc])
    # Following Apple deployed clang are broken
    # clang version 1.0 (http://llvm.org/svn/llvm-project/cfe/tags/Apple/clang-23 exported)
    # Apple clang version 2.0 (tags/Apple/clang-137) (based on LLVM 2.9svn)
    # Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
    if ! $CC -E -xc - <<SRC >/dev/null; then
@%:@if defined __APPLE_CC__ && defined __clang_major__ && __clang_major__ < 3
@%:@error premature clang
@%:@endif
SRC
AC_MSG_ERROR([clang version 3.0 or later is required])
    fi
])
if test x"${build}" != x"${host}"; then
  AC_CHECK_TOOL(CC, gcc)
fi

AC_PROG_CC
AC_PROG_CXX
RUBY_MINGW32
AC_PROG_GCC_TRADITIONAL
AC_SUBST(GCC)
AS_CASE(["$target_os"],
[solaris*], [AC_PATH_TOOL([LD], [ld], [/usr/ccs/bin/ld], [/usr/ccs/bin:$PATH])],
[AC_CHECK_TOOL([LD], [ld], [ld])])
AC_SUBST(LD)
if test "$GCC" = yes; then
    linker_flag=-Wl,
    : ${optflags=-O3}
    gcc_major=`echo =__GNUC__ | $CC -E -xc - | sed '/^=/!d;s///'`
    test -n "$gcc_major" || gcc_major=0
    # RUBY_APPEND_OPTIONS(XCFLAGS, ["-include ruby/config.h" "-include ruby/missing.h"])
else
    linker_flag=
fi

RUBY_PROG_GNU_LD
RUBY_CPPOUTFILE

: ${OUTFLAG='-o '}
: ${COUTFLAG=${OUTFLAG}}
AC_SUBST(OUTFLAG)
AC_SUBST(COUTFLAG)

cc_version=
for option in --version -v -V -qversion; do
    cc_version_message=`$CC $option 2>&1`
    cc_version_status=$?
    AS_CASE($cc_version_status, [0], [:], [continue])
    AS_CASE($cc_version_message, [*Warning*], [continue])
    cc_version='$(CC) '$option
done
AC_SUBST(CC_VERSION, $cc_version)

RUBY_UNIVERSAL_ARCH
if test "$target_cpu" != "$host_cpu" -a "$GCC" = yes -a "$cross_compiling" = no -a "$universal_binary" = no; then
    RUBY_DEFAULT_ARCH("$target_cpu")
fi

AS_CASE(["$target_cpu-$target_os"], [[i[3-6]86*]], [
AC_CACHE_CHECK([for __sync_val_compare_and_swap], [rb_cv_gcc_compiler_cas], [
AC_TRY_LINK([unsigned long atomic_var;],
[
__sync_val_compare_and_swap(&atomic_var, 0, 1);
],
[rb_cv_gcc_compiler_cas=yes],
[rb_cv_gcc_compiler_cas=no])])
if test "$rb_cv_gcc_compiler_cas" = no; then
unset rb_cv_gcc_compiler_cas
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -march=i486"
AC_CACHE_CHECK([for __sync_val_compare_and_swap with -march=i486], [rb_cv_gcc_compiler_cas], [
AC_TRY_LINK([unsigned long atomic_var;],
[
__sync_val_compare_and_swap(&atomic_var, 0, 1);
],
[rb_cv_gcc_compiler_cas=yes
ARCH_FLAG="-march=i486"],
[rb_cv_gcc_compiler_cas=no])])
CFLAGS="$save_CFLAGS"
fi])

AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(AR, ar)
if test -z "$AR"; then
  AC_CHECK_PROGS(AR, aal, ar)
fi

AC_CHECK_TOOL(AS, as)
ASFLAGS=$ASFLAGS
AC_SUBST(ASFLAGS)

AS_CASE(["$target_os"],[cygwin*|mingw*], [ac_cv_prog_ac_ct_OBJCOPY=":"])

# BSD's ports and MacPorts prefix GNU binutils with 'g'
AC_CHECK_TOOLS(OBJDUMP, [objdump gobjdump])
AC_CHECK_TOOLS(OBJCOPY, [objcopy gobjcopy])

AS_CASE(["$target_os"],
[cygwin*|mingw*], [
    AC_CHECK_TOOL(WINDRES, windres)
    AC_CHECK_TOOL(DLLWRAP, dllwrap)
    target=`echo $target | sed "s/^$target_cpu-/-/"`
    target_alias=`echo $target_alias | sed "s/^$target_cpu-/-/"`
    target_cpu=`echo $target_cpu | sed s/i.86/i386/`
    AS_CASE(["$target"], [-*], [ target="$target_cpu${target}"])
    AS_CASE(["$target_alias"], [-*], [ target_alias="$target_cpu${target_alias}"])
    AS_CASE(["$target_os"],
    [mingw*], [
test "$rb_cv_msvcrt" = "" && unset rb_cv_msvcrt
AC_CACHE_CHECK(for mingw32 runtime DLL, rb_cv_msvcrt, [
AC_TRY_LINK([@%:@include <stdio.h>],
[FILE* volatile f = stdin; return 0;],
[rb_cv_msvcrt=`$OBJDUMP -p conftest$ac_exeext |
tr A-Z a-z |
sed -n '/^[[ ]]*dll name: \(msvc.*\)\.dll$/{s//\1/p;q;}'`],
[rb_cv_msvcrt=msvcrt])
test "$rb_cv_msvcrt" = "" && rb_cv_msvcrt=msvcrt])
RT_VER=`echo "$rb_cv_msvcrt" | tr -cd [0-9]`
test "$RT_VER" = "" && RT_VER=60
AC_DEFINE_UNQUOTED(RUBY_MSVCRT_VERSION, $RT_VER)
    ])
    : ${enable_shared=yes}
    ],
[aix*], [AC_CHECK_TOOL(NM, nm, /usr/ccs/bin/nm, /usr/ccs/bin:$PATH)],
[hiuxmpp*], [AC_DEFINE(__HIUX_MPP__)]) # by TOYODA Eizi <toyoda@npd.kishou.go.jp>
AC_CHECK_TOOL(NM, nm)

AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_MKDIR_P
if test "x$MKDIR_P" = "x -d"; then
  if test x"$as_mkdir_p" != xfalse; then
    MKDIR_P='mkdir -p'
    echo "use 'mkdir -p' as MKDIR_P"
  else
    AC_MSG_ERROR([mkdir -p is required])
  fi
fi
MAKEDIRS="$MKDIR_P"
AC_SUBST(MAKEDIRS)

AC_DEFUN([RUBY_DTRACE_AVAILABLE],
[AC_CACHE_CHECK(whether dtrace USDT is available, rb_cv_dtrace_available,
[
    echo "provider conftest{ probe fire(); };" > conftest_provider.d
    if $DTRACE -h -o conftest_provider.h -s conftest_provider.d >/dev/null 2>/dev/null; then
      # DTrace is available on the system
      rb_cv_dtrace_available=yes
    else
      # DTrace is not available while dtrace command exists
      # for example FreeBSD 8 or FreeBSD 9 without DTrace build option
      rb_cv_dtrace_available=no
    fi
    rm -f conftest.[co] conftest_provider.[dho]
])
])

AC_DEFUN([RUBY_DTRACE_POSTPROCESS],
[AC_CACHE_CHECK(whether $DTRACE needs post processing, rb_cv_prog_dtrace_g,
[
  if {
    cat >conftest_provider.d <<_PROBES &&
    provider conftest {
      probe fire();
    };
_PROBES
    $DTRACE -h -o conftest_provider.h -s conftest_provider.d >/dev/null 2>/dev/null &&
    cat >conftest.c <<_CONF &&
    @%:@include "conftest_provider.h"
    int main(void){ CONFTEST_FIRE(); return 0; }
_CONF
    $CC $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c &&
    $DTRACE -G -s conftest_provider.d conftest.o 2>/dev/null
  }; then
    rb_cv_prog_dtrace_g=yes
  else
    rb_cv_prog_dtrace_g=no
  fi
  rm -f conftest.[co] conftest_provider.[dho]
])
])

AC_CHECK_PROG([DTRACE], [${ac_tool_prefix}dtrace], [${ac_tool_prefix}dtrace])
if test "$cross_compiling:$ac_cv_prog_DTRACE" = no: -a -n "$ac_tool_prefix"; then
    AC_CHECK_PROG([DTRACE], [dtrace], [dtrace])
fi

AC_CHECK_PROGS(DOT, dot)
AC_CHECK_PROGS(DOXYGEN, doxygen)
AS_CASE(["${host_os}"], [nacl], [AC_PATH_PROG(PYTHON, python)])

AC_CHECK_PROG(PKG_CONFIG, pkg-config, [pkg-config], [], [],
    [`"$as_dir/$ac_word$ac_exec_ext" --print-errors --version > /dev/null 2>&1 || echo "$as_dir/$ac_word$ac_exec_ext"`])

# checks for UNIX variants that set C preprocessor variables
AC_USE_SYSTEM_EXTENSIONS

AC_SUBST(RM, ['rm -f'])
AC_SUBST(CP, ['cp'])
RMDIRS='$(top_srcdir)/tool/rmdirs'
RMDIR=rmdir
mkdir "rmdirs_$$_test" "rmdirs_$$_test/a"
rmdir --ignore-fail-on-non-empty "rmdirs_$$_test" 2>/dev/null &&
RMDIR='rmdir --ignore-fail-on-non-empty'
$RMDIR -p "rmdirs_$$_test/a" 2>/dev/null &&
{ test -d "rmdirs_$$_test" || RMDIRS="$RMDIR -p"; }
rmdir "rmdirs_$$_test/a" "rmdirs_$$_test" 2>/dev/null
AC_SUBST(RMDIR)
AC_SUBST(RMDIRS)
AC_SUBST(RMALL, ['rm -fr'])

AC_MSG_CHECKING([for cd using physical directory])
rm -fr conf$$.dir
mkdir conf$$.dir &&
(cd conf$$.dir && mkdir src build && cd src &&
$as_ln_s ../build . > /dev/null 2>&1 && cd build &&
for chdir in 'cd -P' 'PWD= cd'; do
    /bin/sh -c "$chdir ../src && echo '$chdir' > cdcmd" 2> /dev/null && break
done)
if test -f conf$$.dir/src/cdcmd; then
    read CHDIR < conf$$.dir/src/cdcmd 2> /dev/null
else
    CHDIR=cd
fi
rm -fr conf$$.dir
AC_MSG_RESULT([$CHDIR])
AC_SUBST(CHDIR)

}
{ # compiler section

AC_DEFUN([RUBY_WERROR_FLAG], [dnl
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $rb_cv_warnflags"
if test "${ac_c_werror_flag+set}"; then
  rb_c_werror_flag="$ac_c_werror_flag"
else
  unset rb_c_werror_flag
fi
ac_c_werror_flag=yes
$1
CFLAGS="$save_CFLAGS"
save_CFLAGS=
if test "${rb_c_werror_flag+set}"; then
  ac_c_werror_flag="$rb_c_werror_flag"
else
  unset ac_c_werror_flag
fi])

RUBY_WERROR_FLAG([
    AC_MSG_CHECKING([whether CFLAGS is valid])
    AC_TRY_COMPILE([], [],
[AC_MSG_RESULT(yes)],
[
AC_MSG_RESULT(no)
AC_MSG_ERROR([something wrong with CFLAGS="$CFLAGS"])
]
    )
    AC_MSG_CHECKING([whether LDFLAGS is valid])
    AC_TRY_LINK([], [],
[AC_MSG_RESULT(yes)],
[
AC_MSG_RESULT(no)
AC_MSG_ERROR([something wrong with LDFLAGS="$LDFLAGS"])
]
    )
])

AC_DEFUN(RUBY_TRY_CFLAGS, [
    AC_MSG_CHECKING([whether ]$1[ is accepted as CFLAGS])
    RUBY_WERROR_FLAG([
    CFLAGS="[$]CFLAGS $1"
    AC_TRY_COMPILE([$4], [$5],
[$2
AC_MSG_RESULT(yes)],
[$3
AC_MSG_RESULT(no)])
    ])
])

AC_DEFUN(RUBY_TRY_LDFLAGS, [
    save_LDFLAGS="$LDFLAGS"
    LDFLAGS="[$]LDFLAGS $1"
    AC_MSG_CHECKING([whether $1 is accepted as LDFLAGS])
    RUBY_WERROR_FLAG([
    AC_TRY_LINK([$4], [$5],
[$2
AC_MSG_RESULT(yes)],
[$3
AC_MSG_RESULT(no)])
    ])
    LDFLAGS="$save_LDFLAGS"
    save_LDFLAGS=
])

AS_CASE([$RUBY_PATCHLEVEL], [-*],
[particular_werror_flags=yes], [particular_werror_flags=no])
AC_ARG_ENABLE(werror,
AS_HELP_STRING([--disable-werror],
[don't make warnings into errors
even if a compiler support -Werror feature
[[disabled by default unless development version]]]),
[particular_werror_flags=$enableval])

rb_cv_warnflags="$warnflags"
if test "$GCC:${warnflags+set}:no" = yes::no; then
    if test $gcc_major -ge 4; then
extra_warning=-Werror=extra-tokens
    else
extra_warning=
    fi
    for wflag in -Wno-unused-parameter -Wno-parentheses -Wno-long-long \
-Wno-missing-field-initializers \
-Wunused-variable \
-Werror=pointer-arith \
-Werror=write-strings \
-Werror=declaration-after-statement \
-Werror=shorten-64-to-32 \
-Werror=implicit-function-declaration \
-Werror=division-by-zero \
-Werror=deprecated-declarations \
-Wno-packed-bitfield-compat \
$extra_warning \
; do
if test "$particular_werror_flags" != yes; then
wflag=`echo x$wflag | sed 's/^x-Werror=/-W/;s/^x//'`
fi
ok=no
RUBY_TRY_CFLAGS($wflag, [
RUBY_APPEND_OPTIONS(warnflags, $wflag)
ok=yes
])
AS_CASE([$ok:$wflag], [no:-Werror=*], [
wflag=`echo x$wflag | sed 's/^x-Werror=/-W/'`
RUBY_TRY_CFLAGS($wflag, [
RUBY_APPEND_OPTIONS(warnflags, $wflag)
particular_werror_flags=no
])
])
    done
    AS_CASE([" $warnflags "],[*" -Wno-missing-field-initializers "*], [wflag="-Wall -Wextra"],
                             [wflag=-Wall])
    RUBY_TRY_CFLAGS($wflag, [warnflags="$wflag${warnflags+ $warnflags}"])
    # Disable warnflags while conftest. -Werror=* flags might make bad OS capability guess.
    rb_cv_warnflags="$warnflags"
    warnflags=
fi
RUBY_TRY_CFLAGS(-Qunused-arguments, [RUBY_APPEND_OPTIONS(rb_cv_wsuppress_flags, -Qunused-arguments)])

if test "$GCC" = yes; then
    # -D_FORTIFY_SOURCE
    # When defined _FORTIFY_SOURCE, glibc enables some additional sanity
    # argument check. The performance drop is very little and Ubuntu enables
    # _FORTIFY_SOURCE=2 by default. So, let's support it for protecting us from
    # a mistake of silly C extensions.
    RUBY_TRY_CFLAGS(-D_FORTIFY_SOURCE=2, [RUBY_APPEND_OPTION(XCFLAGS, -D_FORTIFY_SOURCE=2)])

    # -fstack-protector
    AS_CASE(["$target_os"],
    [mingw*|nacl|haiku], [
stack_protector=no
    ])
    if test -z "${stack_protector+set}"; then
RUBY_TRY_CFLAGS(-fstack-protector, [stack_protector=yes], [stack_protector=no])
if test "x$stack_protector" = xyes; then
RUBY_TRY_LDFLAGS(-fstack-protector, [], [stack_protector=broken])
fi
    fi
    if test "x$stack_protector" = xyes; then
RUBY_APPEND_OPTION(XCFLAGS, -fstack-protector)
RUBY_APPEND_OPTION(XLDFLAGS, -fstack-protector)
RUBY_APPEND_OPTION(LDFLAGS, -fstack-protector)
    fi

    AS_CASE(["$target_os"],[mingw*], [
      # On Windows platforms, system provided headers are VC++
      # optimized. That is, C++ habits are often contaminated into
      # various headers. Most frequent situation is the use of //
      # comments. We bypass ANSI C mode for them. Otherwise
      # extension libs cannot include those headers.
    ],
    [cygwin*|darwin*|netbsd*], [
      # need lgamma_r(), finite()
    ],
    [haiku], [
      # Haiku R1/alpha3 uses gcc-4.4.4 which can not handle anonymous union
      # with ANSI standard flags. Anonumous union is required to compile
      # socket extension where <net/if.h> uses anonymous union.
    ],
    [
      # ANSI (no XCFLAGS because this is C only)
for ansi_options in -std=iso9899:1999 "-ansi -std=iso9899:199409"; do
RUBY_TRY_CFLAGS(${ansi_options}, [
RUBY_APPEND_OPTIONS(warnflags, ${ansi_options})
RUBY_APPEND_OPTIONS(strict_warnflags, ${ansi_options})
], [ansi_options=])
test "x${ansi_options}" = x || break
done
    ])

    # suppress annoying -Wstrict-overflow warnings
    RUBY_TRY_CFLAGS(-fno-strict-overflow, [RUBY_APPEND_OPTION(XCFLAGS, -fno-strict-overflow)])

    test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-ggdb3, [debugflags=-ggdb3])}
    test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-ggdb, [debugflags=-ggdb])}
    test "${debugflags+set}" || {RUBY_TRY_CFLAGS(-g3, [debugflags=-g3])}
fi
test $ac_cv_prog_cc_g = yes && : ${debugflags=-g}

if test "$GCC" = ""; then
    AS_CASE(["$target_os"],[aix*],[warnflags="$warnflags -qinfo=por" rb_cv_warnflags="$rb_cv_warnflags -qinfo=por"])
fi
if test "$GCC" = yes; then
    if test "$gcc_major" -ge 4; then
RUBY_TRY_CFLAGS(-fvisibility=hidden, [visibility_option=yes], [visibility_option=no])
    fi
    AC_SUBST(WERRORFLAG, "-Werror")
    if test "$visibility_option" = yes; then
RUBY_APPEND_OPTION(XCFLAGS, -fvisibility=hidden)
AC_DEFINE(RUBY_SYMBOL_EXPORT_BEGIN, [_Pragma("GCC visibility push(default)")])
AC_DEFINE(RUBY_SYMBOL_EXPORT_END, [_Pragma("GCC visibility pop")])
    else
RUBY_TRY_LDFLAGS([-Wl,-unexported_symbol,_Init_*], [visibility_option=ld], [visibility_option=no])
    fi
    test "$visibility_option" = no -o "$host_os" = nacl || OBJCOPY=:
fi

if test "$GCC" = yes; then
    # optflags

    AS_CASE(["$target_os"], [mingw*], [
RUBY_TRY_CFLAGS(-fno-omit-frame-pointer, [optflags="${optflags+$optflags }-fno-omit-frame-pointer"])
    ])

    # disable fast-math
    for oflag in -fno-fast-math; do
RUBY_TRY_CFLAGS($oflag, [RUBY_APPEND_OPTION(optflags, $oflag)])
    done
    AS_CASE(["$target"],
[*-darwin*], [
# doesn't seem necessary on Mac OS X
],
[[i[4-6]86*]], [
RUBY_TRY_CFLAGS(-msse2 -mfpmath=sse, [
RUBY_APPEND_OPTION(XCFLAGS, -msse2 -mfpmath=sse)
])
            AS_CASE(["$XCFLAGS"],
                [[*-msse2*]], [
                    RUBY_TRY_CFLAGS(-mstackrealign, [
                        RUBY_APPEND_OPTION(XCFLAGS, -mstackrealign)
                    ])
                ])
]
    )
fi

AC_ARG_WITH(opt-dir,
AS_HELP_STRING([--with-opt-dir=DIR-LIST],
[add optional headers and libraries directories separated by $PATH_SEPARATOR]),
[
val=`echo "$PATH_SEPARATOR$withval" | sed "s|$PATH_SEPARATOR\([[^$PATH_SEPARATOR]*]\)| -I\1/include|g;s/^ //"`
CPPFLAGS="$CPPFLAGS $val"
val=`echo "$PATH_SEPARATOR$withval" | sed "s|$PATH_SEPARATOR\([[^$PATH_SEPARATOR]*]\)| -L\1/lib|g;s/^ //"`
LDFLAGS="$LDFLAGS $val"
LDFLAGS_OPTDIR="$val"
OPT_DIR="$withval"
], [OPT_DIR=])

test -z "${ac_env_CFLAGS_set}" -a -n "${cflags+set}" && eval CFLAGS="\"$cflags $ARCH_FLAG\""
test -z "${ac_env_CXXFLAGS_set}" -a -n "${cxxflags+set}" && eval CXXFLAGS="\"$cxxflags $ARCH_FLAG\""

}
{ # header and library section

AC_ARG_WITH(winnt-ver,
  AS_HELP_STRING([--with-winnt-ver=0xXXXX], [target Windows NT version (default to 0x0501)]),
  [with_winnt_ver="$withval"], [with_winnt_ver="0x0501"])
AS_CASE(["$target_os"],
[mingw*], [
  RUBY_APPEND_OPTION(CPPFLAGS, -D_WIN32_WINNT=$with_winnt_ver)
  RUBY_APPEND_OPTION(CPPFLAGS, -D__MINGW_USE_VC2005_COMPAT)
])

AS_CASE(["$target_os"],
[freebsd*], [
  AC_CACHE_CHECK([whether pthread should be enabled by default],
    rb_cv_enable_pthread_default,
    [AC_TRY_CPP([
#include <osreldate.h>
#if __FreeBSD_version < 502102
#error pthread should be disabled on this platform
#endif
      ],
      rb_cv_enable_pthread_default=yes,
      rb_cv_enable_pthread_default=no)])
  enable_pthread=$rb_cv_enable_pthread_default
  ],
[mingw*], [
  enable_pthread=no
  ],
[
  enable_pthread=yes
  ])

AC_ARG_ENABLE(pthread,
       AS_HELP_STRING([--enable-pthread], [obsolete, and ignored]))

dnl Checks for libraries.
AS_CASE(["$target_os"],[*bsd*|dragonfly*],[],[ac_cv_func_daemon=no])

POSTLINK=:
AC_SUBST(POSTLINK)
AS_CASE(["$target_os"],
[nextstep*], [ ],
[openstep*], [ ],
[rhapsody*], [ ],
[darwin*], [ RUBY_PREPEND_OPTION(LIBS, -lobjc)
RUBY_APPEND_OPTIONS(CPPFLAGS, -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT)
AC_MSG_CHECKING(whether Mac OS X 10.5 or later)
AC_TRY_CPP([#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040
#error pre OS X 10.4
[!<===== pre OS X 10.4 =====>]
#endif
],
[macosx_10_5=yes], [macosx_10_5=no])
AC_MSG_RESULT($macosx_10_5)
if test $macosx_10_5 = yes; then
ac_cv_header_ucontext_h=no
else
AC_DEFINE(BROKEN_SETREUID, 1)
AC_DEFINE(BROKEN_SETREGID, 1)
fi
ac_cv_type_getgroups=gid_t # getgroups() on Rosetta fills garbage
ac_cv_lib_crypt_crypt=no
ac_cv_func_fdatasync=no # Mac OS X wrongly reports it has fdatasync()
                AC_CACHE_CHECK(for broken crypt with 8bit chars, rb_cv_broken_crypt,
                    [AC_TRY_RUN([
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int
main()
{
    int i;
    for (i = 0; i < 128*128; i++) {
char salt[2], buf[256], *s;
salt[0] = 0x80 | (i & 0x7f);
salt[1] = 0x80 | (i >> 7);
strcpy(buf, crypt("", salt));
if (strcmp(buf, s = crypt("", salt))) {
#if 0
printf("%.2x%.2x: %s -> %s\n", (unsigned char)salt[0], (unsigned char)salt[1],
buf+2, s+2);
#endif
return 1;
}
    }
    return 0;
}
],
rb_cv_broken_crypt=no,
rb_cv_broken_crypt=yes,
rb_cv_broken_crypt=yes)])
                if test "$rb_cv_broken_crypt" = yes; then
                  AC_DEFINE(BROKEN_CRYPT, 1)
                fi
AC_CHECK_PROGS(codesign, codesign)
if test -n "$codesign"; then
POSTLINK="test -z '\$(RUBY_CODESIGN)' || $codesign -s '\$(RUBY_CODESIGN)' -f \$@"
LINK_SO="$LINK_SO
\$(POSTLINK)"
fi
AC_CHECK_HEADERS(crt_externs.h, [], [], [
#include <crt_externs.h>
])
],
[hpux*], [ LIBS="-lm $LIBS"
ac_cv_c_inline=no],
[beos*|haiku*], [
ac_cv_func_link=no
ac_cv_func_sched_yield=no
ac_cv_func_pthread_attr_setinheritsched=no
AS_CASE(["$target_os"],
[beos*], [ ac_cv_header_net_socket_h=yes],
[haiku*], [ ac_cv_func_shutdown=no])
LIBS="$LIBS" # m lib is include in root under BeOS/Haiku
],
[cygwin*], [ ac_cv_header_langinfo_h=yes
AC_CHECK_FUNCS(cygwin_conv_path)
AC_LIBOBJ([langinfo])
],
[mingw*], [ LIBS="-lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi $LIBS"
ac_cv_header_a_out_h=no
ac_cv_header_pwd_h=no
ac_cv_header_utime_h=no
ac_cv_header_sys_ioctl_h=no
ac_cv_header_sys_param_h=no
ac_cv_header_sys_resource_h=no
ac_cv_header_sys_select_h=no
ac_cv_header_sys_time_h=no
ac_cv_header_sys_times_h=no
ac_cv_header_sys_socket_h=no
ac_cv_func_times=yes
ac_cv_func_waitpid=yes
ac_cv_func_fsync=yes
ac_cv_func_seekdir=yes
ac_cv_func_telldir=yes
ac_cv_func_isinf=yes
ac_cv_func_isnan=yes
ac_cv_func_finite=yes
ac_cv_func_link=yes
ac_cv_lib_crypt_crypt=no
ac_cv_func_getpgrp_void=no
ac_cv_func_memcmp_working=yes
ac_cv_lib_dl_dlopen=no
rb_cv_binary_elf=no
rb_cv_negative_time_t=no
ac_cv_func_fcntl=yes
ac_cv_func_flock=yes
ac_cv_func_gmtime_r=yes
rb_cv_large_fd_select=yes
ac_cv_type_struct_timeval=yes
                ac_cv_func_clock_gettime=yes
                ac_cv_func_clock_getres=yes
ac_cv_func_malloc_usable_size=no
{ test "$target_cpu" = x64 && ac_cv_func___builtin_setjmp=no; }
AC_CHECK_TYPE([NET_LUID], [], [],
[@%:@include <windows.h>
@%:@include <iphlpapi.h>])
if test x"$ac_cv_type_NET_LUID" = xyes; then
AC_DEFINE(HAVE_TYPE_NET_LUID, 1)
fi
AC_CHECK_FUNCS(_gmtime64_s)
AC_LIBOBJ([langinfo])
],
[os2-emx*], [ LIBS="-lm $LIBS"
ac_cv_lib_dir_opendir=no],
[bsdi*], [ LIBS="-lm $LIBS"
AC_DEFINE(BROKEN_SETREUID, 1)
AC_DEFINE(BROKEN_SETREGID, 1)
                ac_cv_sizeof_rlim_t=8],
[freebsd*], [ LIBS="-lm $LIBS"
ac_cv_func_getpeername=no
ac_cv_func_getsockname=no
ac_cv_func_shutdown=no
ac_cv_func_close=no
],
[dragonfly*], [ LIBS="-lm $LIBS"
# isinf() and isnan() are macros on DragonFly.
ac_cv_func_isinf=yes
ac_cv_func_isnan=yes
],
[nacl], [
  LIBS="-lm $LIBS"
  if test "${nacl_cv_build_variant}" = "newlib"; then
    RUBY_APPEND_OPTION(CPPFLAGS, -DNACL_NEWLIB)
    RUBY_APPEND_OPTION(LIBS, '-lnosys')
  else
    RUBY_APPEND_OPTION(XCFLAGS, -fPIC)
  fi
  ac_cv_func_shutdown=no
  ac_cv_func_fcntl=no
  ],
[ LIBS="-lm $LIBS"])

AC_CHECK_LIB(crypt, crypt) # glibc (GNU/Linux, GNU/Hurd, GNU/kFreeBSD)
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX
AC_CHECK_LIB(socket, shutdown) # SunOS/Solaris

dnl Checks for header files.
AC_HEADER_DIRENT
dnl AC_HEADER_STDC has been checked in AC_USE_SYSTEM_EXTENSIONS
AC_HEADER_STDBOOL
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS( \
  limits.h \
  sys/file.h \
  sys/ioctl.h \
  sys/syscall.h \
  fcntl.h \
  sys/fcntl.h \
  sys/select.h \
  sys/time.h \
  sys/times.h \
  sys/param.h \
  syscall.h \
  pwd.h \
  grp.h \
  a.out.h \
  utime.h \
  direct.h \
  sys/resource.h \
  sys/mkdev.h \
  sys/utime.h \
  float.h \
  ieeefp.h \
  ucontext.h \
  intrinsics.h \
  langinfo.h \
  locale.h \
  sys/sendfile.h \
  time.h \
  net/socket.h \
  sys/socket.h \
  process.h \
  sys/prctl.h \
  sys/uio.h \
  atomic.h \
  malloc.h \
  malloc_np.h \
  malloc/malloc.h \
  setjmpex.h
)

AC_ARG_WITH([gmp],
  [AS_HELP_STRING([--without-gmp],
    [disable GNU GMP to accelerate Bignum operations])],
  [],
  [with_gmp=yes])
AS_IF([test "x$with_gmp" != xno],
  [AC_CHECK_HEADERS(gmp.h)
   AS_IF([test "x$ac_cv_header_gmp_h" != xno],
     AC_CHECK_LIB([gmp], [__gmpz_init]))
   with_gmp="$ac_cv_lib_gmp___gmpz_init"
   AS_IF([test -z "$with_gmp"], [with_gmp=no])])

dnl check for large file stuff
mv confdefs.h confdefs1.h
: > confdefs.h
AC_SYS_LARGEFILE
mv confdefs.h largefile.h
mv confdefs1.h confdefs.h
cat largefile.h >> confdefs.h

AS_CASE(["$target_os"],[mingw*], [ac_cv_type_off_t=yes;ac_cv_sizeof_off_t=8])

AC_C_BIGENDIAN
AC_C_CONST
AC_C_CHAR_UNSIGNED
AC_C_INLINE
AC_C_VOLATILE

AS_CASE(":$ac_cv_c_const:$ac_cv_c_volatile:",
    [*:no:*], [AC_MSG_ERROR(ANSI C-conforming const and volatile are mandatory)])

AC_CHECK_TYPES([long long, off_t])

AC_CACHE_CHECK([char bit], [rb_cv_char_bit],
    [test "$universal_binary" = yes && cross_compiling=yes
    AC_COMPUTE_INT([rb_cv_char_bit], [CHAR_BIT],
[AC_INCLUDES_DEFAULT([@%:@include <limits.h>])], [rb_cv_char_bit=8])
    test "$universal_binary" = yes && cross_compiling=$real_cross_compiling])

dnl RUBY_CHECK_SIZEOF [typename], [maybe same size types], [macros], [include]
AC_DEFUN([RUBY_CHECK_SIZEOF],
[m4_bmatch([$1], [\.], [], [if test "$universal_binary" = yes; then])
AC_CACHE_CHECK([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])], [
    unset AS_TR_SH(ac_cv_sizeof_$1)
    rbcv_var="
typedef m4_bpatsubst([$1], [\..*]) ac__type_sizeof_;
static ac__type_sizeof_ *rbcv_ptr;
@%:@define AS_TR_CPP(SIZEOF_$1) sizeof((*rbcv_ptr)[]m4_bmatch([$1], [\.], .m4_bpatsubst([$1], [^[^.]*\.])))
"
    m4_ifval([$2], [test -z "${AS_TR_SH(ac_cv_sizeof_$1)+set}" && {
    for t in $2; do
AC_COMPILE_IFELSE(
[AC_LANG_BOOL_COMPILE_TRY(AC_INCLUDES_DEFAULT([$4]
[$rbcv_var]),
[AS_TR_CPP(SIZEOF_$1) == sizeof($t)])], [
AS_TR_SH(ac_cv_sizeof_$1)=AS_TR_CPP([SIZEOF_]$t)
break])
    done
    }])
    unset cond
    m4_ifval([$3], [test -z "${AS_TR_SH(ac_cv_sizeof_$1)+set}" && {
    for s in 32 64 128; do
for t in $3; do
cond="${cond}
@%:@${cond+el}if defined(__${t}${s}__) || defined(__${t}${s}) || defined(_${t}${s}) || defined(${t}${s})"
hdr="AC_INCLUDES_DEFAULT([$4
@%:@if defined(__${t}${s}__) || defined(__${t}${s}) || defined(_${t}${s}) || defined(${t}${s})
@%:@ define AS_TR_CPP(HAVE_$1) 1
@%:@else
@%:@ define AS_TR_CPP(HAVE_$1) 0
@%:@endif])"
AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$hdr], [!AS_TR_CPP(HAVE_$1)])], [continue])
AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$hdr]
[$rbcv_var],
[AS_TR_CPP(HAVE_$1) == (AS_TR_CPP(SIZEOF_$1) == ([$[s / rb_cv_char_bit]]))])],
[AS_TR_SH(ac_cv_sizeof_$1)="${AS_TR_SH(ac_cv_sizeof_$1)+${AS_TR_SH(ac_cv_sizeof_$1)-} }${t}${s}"])
done
    done
    }])
    m4_ifval([$2][$3],
[test "${AS_TR_SH(ac_cv_sizeof_$1)@%:@SIZEOF_}" = "${AS_TR_SH(ac_cv_sizeof_$1)}" && ]){
    test "$universal_binary" = yes && cross_compiling=yes
    AC_COMPUTE_INT([t], AS_TR_CPP(SIZEOF_$1), [AC_INCLUDES_DEFAULT([$4])]
[${cond+$cond
@%:@else}
$rbcv_var
${cond+@%:@endif}
@%:@ifndef AS_TR_CPP(SIZEOF_$1)
@%:@define AS_TR_CPP(SIZEOF_$1) 0
@%:@endif], [t=0])
    test "$universal_binary" = yes && cross_compiling=$real_cross_compiling
    if test ${t-0} != 0; then
AS_TR_SH(ac_cv_sizeof_$1)="${AS_TR_SH(ac_cv_sizeof_$1)+${AS_TR_SH(ac_cv_sizeof_$1)-} }${t}"
    fi
    }
    : ${AS_TR_SH(ac_cv_sizeof_$1)=0}
])
{
    unset cond
    for t in ${AS_TR_SH(ac_cv_sizeof_$1)-}; do
AS_CASE(["$t"],
[[[0-9]*|SIZEOF_*]], [
${cond+echo "@%:@else"}
echo "[@%:@define ]AS_TR_CPP(SIZEOF_$1) [$t]"
break
],
[
s=`expr $t : ['.*[^0-9]\([0-9][0-9]*\)$']`
echo "@%:@${cond+el}if defined(__${t}__) || defined(__${t}) || defined(_${t}) || defined($t)"
echo "@%:@define AS_TR_CPP(SIZEOF_$1) [$[s / rb_cv_char_bit]]"
cond=1
])
    done
    ${cond+echo "@%:@endif"}
} >> confdefs.h
m4_bmatch([$1], [\.], [], [else
AC_CHECK_SIZEOF([$1], 0, [$4])
fi])
])

RUBY_CHECK_SIZEOF(int, [], [ILP])
RUBY_CHECK_SIZEOF(short)
RUBY_CHECK_SIZEOF(long, [int], [ILP LP])
RUBY_CHECK_SIZEOF(long long)
RUBY_CHECK_SIZEOF(__int64)
RUBY_CHECK_SIZEOF(__int128)
RUBY_CHECK_SIZEOF(off_t)
RUBY_CHECK_SIZEOF(void*, [int long "long long"], [ILP LP LLP])
RUBY_CHECK_SIZEOF(float)
RUBY_CHECK_SIZEOF(double)
RUBY_CHECK_SIZEOF(time_t, [long "long long"], [], [@%:@include <time.h>])
RUBY_CHECK_SIZEOF(clock_t, [], [], [@%:@include <time.h>])

AC_CACHE_CHECK(packed struct attribute, rb_cv_packed_struct,
    [rb_cv_packed_struct=no
    for mac in \
"__pragma(pack(push, 1)) x __pragma(pack(pop))" \
"x __attribute__((packed))" \
; do
AC_TRY_COMPILE([@%:@define PACKED_STRUCT(x) $mac
PACKED_STRUCT(struct { int a; });], [],
[rb_cv_packed_struct=$mac; break])
    done])
packed_struct_unaligned=x
if test "$rb_cv_packed_struct" != no; then
    AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], [$rb_cv_packed_struct])
    AS_CASE(["$target_cpu"],
[x86*|i?86|x64], [packed_struct_unaligned='PACKED_STRUCT(x)'])
else
    AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], x)
fi
AC_DEFINE_UNQUOTED(PACKED_STRUCT_UNALIGNED(x), $packed_struct_unaligned)

AC_DEFUN([RUBY_CHECK_PRINTF_PREFIX], [
AC_CACHE_CHECK([for printf prefix for $1], [rb_cv_pri_prefix_]AS_TR_SH($1),[
    [rb_cv_pri_prefix_]AS_TR_SH($1)=[NONE]
    RUBY_WERROR_FLAG(RUBY_APPEND_OPTIONS(CFLAGS, $rb_cv_wsuppress_flags)
    for pri in $2; do
        AC_TRY_COMPILE(
            [@%:@include <stdio.h>
@%:@include <stddef.h>
            @%:@ifdef __GNUC__
            @%:@define PRINTF_ARGS(decl, string_index, first_to_check) \
              decl __attribute__((format(printf, string_index, first_to_check)))
            @%:@else
            @%:@define PRINTF_ARGS(decl, string_index, first_to_check) decl
            @%:@endif
PRINTF_ARGS(void test_sprintf(const char*, ...), 1, 2);],
            [printf("%]${pri}[d", (]$1[)42);
            test_sprintf("%]${pri}[d", (]$1[)42);],
            [rb_cv_pri_prefix_]AS_TR_SH($1)[=[$pri]; break])
    done)])
if test "[$rb_cv_pri_prefix_]AS_TR_SH($1)" != NONE; then
    AC_DEFINE_UNQUOTED([PRI_]m4_ifval($3,$3,AS_TR_CPP(m4_bpatsubst([$1],[_t$])))[_PREFIX],
        "[$rb_cv_pri_prefix_]AS_TR_SH($1)")
fi
])

if test "x$ac_cv_type_long_long" = xyes; then
    RUBY_CHECK_PRINTF_PREFIX(long long, ll I64, LL)
elif test "x$ac_cv_type___int64" = xyes; then
    RUBY_CHECK_PRINTF_PREFIX(__int64, ll I64, LL)
fi

dnl RUBY_CHECK_SIZEOF [typename] [if-signed] [if-unsigned] [included]
AC_DEFUN([RUBY_CHECK_SIGNEDNESS], [dnl
    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$4])], [($1)-1 > 0])],
[$3], [$2])])

dnl RUBY_REPLACE_TYPE [typename] [default type] [macro type] [included]
AC_DEFUN([RUBY_REPLACE_TYPE], [dnl
    AC_CHECK_TYPE([$1],
[n="patsubst([$1],["],[\\"])"],
[n="patsubst([$2],["],[\\"])"],
[$4])
    AC_CACHE_CHECK([for convertible type of [$1]], rb_cv_[$1]_convertible, [
u= t=
AS_CASE(["$n "],
[*" signed "*], [ ],
[*" unsigned "*], [
u=U],
[RUBY_CHECK_SIGNEDNESS($n, [], [u=U], [$4])])
if test x"$t" = x; then
for t in "long long" long int short; do
test -n "$u" && t="unsigned $t"
AC_COMPILE_IFELSE(
[AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT([$4])]
[typedef $n rbcv_conftest_target_type;
typedef $t rbcv_conftest_replace_type;
extern rbcv_conftest_target_type rbcv_conftest_var;
extern rbcv_conftest_replace_type rbcv_conftest_var;
extern rbcv_conftest_target_type rbcv_conftest_func(void);
extern rbcv_conftest_replace_type rbcv_conftest_func(void);
], [sizeof(rbcv_conftest_target_type) == sizeof(rbcv_conftest_replace_type)])],
[n="$t"; break])
done
fi
AS_CASE([" $n "],
[*" long long "*], [
t=LL],
[*" long "*], [
t=LONG],
[
t=INT])
rb_cv_[$1]_convertible=${u}${t}])
    test "${AS_TR_SH(ac_cv_type_[$1])}" = "yes" && n="$1"
    AS_CASE("${rb_cv_[$1]_convertible}", [U*], [u=+1], [u=-1])
    AC_DEFINE_UNQUOTED(rb_[$1], $n)
    AC_DEFINE_UNQUOTED([SIGNEDNESS_OF_]AS_TR_CPP($1), $u)
    AC_DEFINE_UNQUOTED([$3]2NUM[(v)], [${rb_cv_[$1]_convertible}2NUM(v)])
    AC_DEFINE_UNQUOTED(NUM2[$3][(v)], [NUM2${rb_cv_[$1]_convertible}(v)])
    AC_DEFINE_UNQUOTED(PRI_[$3]_PREFIX,
[PRI_`echo ${rb_cv_[$1]_convertible} | sed ['s/^U//']`_PREFIX])
])
RUBY_REPLACE_TYPE(pid_t, int, PIDT)
RUBY_REPLACE_TYPE(uid_t, int, UIDT)
RUBY_REPLACE_TYPE(gid_t, int, GIDT)
RUBY_REPLACE_TYPE(time_t, [], TIMET, [@%:@include <time.h>])
RUBY_REPLACE_TYPE(dev_t, [int long "long long"], DEVT)
RUBY_REPLACE_TYPE(mode_t, ["unsigned int" long], MODET, [@%:@include <sys/stat.h>])
RUBY_REPLACE_TYPE(rlim_t, [int long "long long"], RLIM, [
@%:@ifdef HAVE_SYS_TYPES_H
@%:@include <sys/types.h>
@%:@endif
@%:@ifdef HAVE_SYS_TYPES_H
@%:@include <sys/time.h>
@%:@endif
@%:@include <sys/resource.h>
])
RUBY_REPLACE_TYPE(off_t, [], OFFT)
RUBY_REPLACE_TYPE(clockid_t, [], CLOCKID)

AC_CACHE_CHECK(for prototypes, rb_cv_have_prototypes,
  [AC_TRY_COMPILE([int foo(int x) { return 0; }], [return foo(10);],
rb_cv_have_prototypes=yes,
rb_cv_have_prototypes=no)])
if test "$rb_cv_have_prototypes" = yes; then
  AC_DEFINE(HAVE_PROTOTYPES)
fi

AC_CACHE_CHECK(token paste string, rb_cv_tokenpaste,
  [AC_TRY_COMPILE([@%:@define paste(a,b) a@%:@@%:@b],
[int xy = 1; return paste(x,y);],
rb_cv_tokenpaste=ansi,
rb_cv_tokenpaste=knr)])
if test "$rb_cv_tokenpaste" = ansi; then
  AC_DEFINE(TOKEN_PASTE(x,y),[x@%:@@%:@y])
else
  AC_DEFINE(TOKEN_PASTE(x,y),[x/**/y])
fi

AC_CACHE_CHECK(stringization, rb_cv_stringization, [
  rb_cv_stringization=no
  for string in "#expr" '"expr"'; do
    AC_COMPILE_IFELSE([
      AC_LANG_BOOL_COMPILE_TRY([
#define STRINGIZE0(expr) $string
#define STRINGIZE(expr) STRINGIZE0(expr)
#undef real_test_for_stringization
#define test_for_stringization -.real_test_for_stringization.-
const char stringized[[]] = STRINGIZE(test_for_stringization);
], [sizeof(stringized) == 32])],
      [rb_cv_stringization="$string"; break],
      [rb_cv_stringization=no])
  done]
)
AC_DEFINE(STRINGIZE(expr),STRINGIZE0(expr))
if test x"$rb_cv_stringization" != xno -a "$rb_cv_stringization" != "#expr"; then
  AC_DEFINE_UNQUOTED(STRINGIZE0(expr),$rb_cv_stringization)
  AC_DEFINE(OLD_FASHIONED_STRINGIZATION,1)
fi

AC_CACHE_CHECK([string literal concatenation],
  rb_cv_string_literal_concatenation, [
  AC_COMPILE_IFELSE([
    AC_LANG_BOOL_COMPILE_TRY([
const char concatenated_literal[[]] = "literals" "to"
  "be" "concatenated.";
], [sizeof(concatenated_literal) == 26])],
    [rb_cv_string_literal_concatenation=yes],
    [rb_cv_string_literal_concatenation=no])]
)
if test "$rb_cv_string_literal_concatenation" = no; then
  AC_DEFINE(NO_STRING_LITERAL_CONCATENATION,1)
fi

AC_CACHE_CHECK(for variable length prototypes and stdarg.h, rb_cv_stdarg,
  [AC_TRY_COMPILE([
#include <stdarg.h>
int foo(int x, ...) {
va_list va;
va_start(va, x);
va_arg(va, int);
va_arg(va, char *);
va_arg(va, double);
return 0;
}
], [return foo(10, "", 3.14);],
rb_cv_stdarg=yes,
rb_cv_stdarg=no)])
if test "$rb_cv_stdarg" = yes; then
  AC_DEFINE(HAVE_STDARG_PROTOTYPES)
fi

AC_CACHE_CHECK(for variable length macro, rb_cv_va_args_macro,
  [AC_TRY_COMPILE([
int foo(int x, ...);
@%:@define FOO(a, ...) foo(a, @%:@@%:@__VA_ARGS__)
], [FOO(1);FOO(1,2);FOO(1,2,3);],
  rb_cv_va_args_macro=yes,
  rb_cv_va_args_macro=no)])
if test "$rb_cv_va_args_macro" = yes; then
  AC_DEFINE(HAVE_VA_ARGS_MACRO)
fi

AC_DEFUN([RUBY_DEFINE_IF], [dnl
    m4_ifval([$1], [AS_LITERAL_IF([$1], [], [test "X$1" = X || ])cat <<EOH >> confdefs.h
@%:@if $1
EOH
])dnl
AC_DEFINE_UNQUOTED($2, $3)dnl
    m4_ifval([$1], [AS_LITERAL_IF([$1], [], [test "X$1" = X || ])cat <<EOH >> confdefs.h
@%:@endif /* $1 */
EOH
])dnl
])dnl

dnl RUBY_FUNC_ATTRIBUTE(attrib, macroname, cachevar, condition)
AC_DEFUN([RUBY_FUNC_ATTRIBUTE], [dnl
m4_ifval([$2], dnl
  [AS_VAR_PUSHDEF([attrib],[$2])], dnl
  [AS_VAR_PUSHDEF([attrib],[FUNC_]AS_TR_CPP($1))] dnl
)dnl
m4_ifval([$3], dnl
  [AS_VAR_PUSHDEF([rbcv],[$3])], dnl
  [AS_VAR_PUSHDEF([rbcv],[rb_cv_func_][$1])]dnl
)dnl
m4_pushdef([attrib_code],[m4_bpatsubst([$1],["],[\\"])])
m4_ifval([$4], [rbcv_cond=["$4"]; test "$rbcv_cond" || unset rbcv_cond])
AC_CACHE_CHECK(for [$2] function attribute, rbcv,
[rbcv=x
RUBY_WERROR_FLAG([
for mac in \
    "__attribute__ ((attrib_code)) x" \
    "x __attribute__ ((attrib_code))" \
    "__declspec(attrib_code) x" \
    x; do
  m4_ifval([$4],mac="$mac"${rbcv_cond+" /* only if $rbcv_cond */"})
  AC_TRY_COMPILE(
    m4_ifval([$4],${rbcv_cond+[@%:@if ]$rbcv_cond})
[@%:@define ]attrib[(x) $mac]
m4_ifval([$4],${rbcv_cond+[@%:@else]}
${rbcv_cond+[@%:@define ]attrib[(x) x]}
${rbcv_cond+[@%:@endif]})
    attrib[(void conftest_attribute_check(void));], [],
    [rbcv="$mac"; break])
done
])])
if test "$rbcv" != x; then
    RUBY_DEFINE_IF(m4_ifval([$4],[${rbcv_cond}]), attrib[(x)], $rbcv)
fi
m4_ifval([$4], [unset rbcv_cond]) dnl
AS_VAR_POPDEF([attrib])dnl
AS_VAR_POPDEF([rbcv])dnl
])

RUBY_FUNC_ATTRIBUTE(noreturn, NORETURN)
RUBY_FUNC_ATTRIBUTE(deprecated, DEPRECATED)
RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE)

if_i386=${universal_binary+[defined __i386__]}
RUBY_FUNC_ATTRIBUTE(stdcall, [], [], ${if_i386})
RUBY_FUNC_ATTRIBUTE(cdecl, [], [], ${if_i386})
RUBY_FUNC_ATTRIBUTE(fastcall, [], [], ${if_i386})
RUBY_FUNC_ATTRIBUTE(optimize("-Os","-fomit-frame-pointer"), FUNC_MINIMIZED, rb_cv_func_minimized)

if test "$GCC" = yes; then
    AC_CACHE_CHECK([for function alias], [rb_cv_gcc_function_alias],
[rb_cv_gcc_function_alias=no
for a in alias weak,alias; do
AC_TRY_LINK([void foo(void) {}
void bar(void) __attribute__(($a("foo")));], [bar()],
[rb_cv_gcc_function_alias=$a; break])
done])
    if test "$rb_cv_gcc_function_alias" != no; then
AC_DEFINE(HAVE_ATTRIBUTE_FUNCTION_ALIAS)
AC_DEFINE_UNQUOTED([RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args)],
[type prot __attribute__(($rb_cv_gcc_function_alias(@%:@name)));])
AC_DEFINE_UNQUOTED([RUBY_ALIAS_FUNCTION_VOID(prot, name, args)],
[RUBY_ALIAS_FUNCTION_TYPE(void, prot, name, args)])
    fi

    AC_CACHE_CHECK([for __atomic builtins], [rb_cv_gcc_atomic_builtins], [
AC_TRY_LINK([unsigned char atomic_var;],
[
__atomic_exchange_n(&atomic_var, 0, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&atomic_var, 1, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&atomic_var, 1, __ATOMIC_SEQ_CST);
__atomic_fetch_sub(&atomic_var, 1, __ATOMIC_SEQ_CST);
],
[rb_cv_gcc_atomic_builtins=yes],
[rb_cv_gcc_atomic_builtins=no])])
    if test "$rb_cv_gcc_atomic_builtins" = yes; then
AC_DEFINE(HAVE_GCC_ATOMIC_BUILTINS)
    fi

    AC_CACHE_CHECK([for __sync builtins], [rb_cv_gcc_sync_builtins], [
AC_TRY_LINK([unsigned char atomic_var;],
[
__sync_lock_test_and_set(&atomic_var, 0);
__sync_lock_test_and_set(&atomic_var, 1);
__sync_fetch_and_add(&atomic_var, 1);
__sync_fetch_and_sub(&atomic_var, 1);
],
[rb_cv_gcc_sync_builtins=yes],
[rb_cv_gcc_sync_builtins=no])])
    if test "$rb_cv_gcc_sync_builtins" = yes; then
AC_DEFINE(HAVE_GCC_SYNC_BUILTINS)
    fi

    AC_CACHE_CHECK(for __builtin_unreachable, rb_cv_func___builtin_unreachable,
    [RUBY_WERROR_FLAG(
    [AC_TRY_LINK([@%:@include <stdlib.h>],
[exit(0); __builtin_unreachable();],
[rb_cv_func___builtin_unreachable=yes],
[rb_cv_func___builtin_unreachable=no])
    ])
    ])
    if test "$rb_cv_func___builtin_unreachable" = yes; then
AC_DEFINE_UNQUOTED(UNREACHABLE, [__builtin_unreachable()])
    fi
fi

AC_CACHE_CHECK(for exported function attribute, rb_cv_func_exported, [
rb_cv_func_exported=no
RUBY_WERROR_FLAG([
for mac in '__attribute__ ((visibility("default")))' '__declspec(dllexport)'; do
  AC_TRY_COMPILE([@%:@define RUBY_FUNC_EXPORTED $mac extern
    RUBY_FUNC_EXPORTED void conftest_attribute_check(void);], [],
    [rb_cv_func_exported="$mac"; break])
done
])])
if test "$rb_cv_func_exported" != no; then
    AC_DEFINE_UNQUOTED(RUBY_FUNC_EXPORTED, [$rb_cv_func_exported extern])
fi

RUBY_APPEND_OPTION(XCFLAGS, -DRUBY_EXPORT)

AC_CACHE_CHECK(for function name string predefined identifier,
    rb_cv_function_name_string,
    [rb_cv_function_name_string=no
    RUBY_WERROR_FLAG([
for func in __func__ __FUNCTION__; do
AC_TRY_LINK([@%:@include <stdio.h>],
[puts($func);],
[rb_cv_function_name_string=$func
break])
done
    ])]
)
if test "$rb_cv_function_name_string" != no; then
    AC_DEFINE_UNQUOTED(RUBY_FUNCTION_NAME_STRING, [$rb_cv_function_name_string])
fi

dnl Check whether we need to define sys_nerr locally
AC_CHECK_DECLS([sys_nerr], [], [], [$ac_includes_default
@%:@include <errno.h>])

AC_CHECK_DECLS([getenv])

AS_CASE(["$target_cpu"],
[alpha*|sh4|sh4el|sh4eb], [AS_CASE(["$target_os"::"$GCC"],
[*::yes], # gcc
[CFLAGS="-mieee $CFLAGS"],
[osf*], # ccc
[CFLAGS="-ieee $CFLAGS"],
)],
[sparc*], [AC_LIBOBJ([sparc])])

ac_cv_header_net_socket_h=${ac_cv_header_net_socket_h=no}
if test "$ac_cv_header_net_socket_h" = yes; then
    ac_cv_header_sys_socket_h=${ac_cv_header_sys_socket_h=no}
else
    ac_cv_header_sys_socket_h=${ac_cv_header_sys_socket_h=yes}
fi


AC_TYPE_SIZE_T
RUBY_CHECK_SIGNEDNESS(size_t, [AC_MSG_ERROR(size_t is signed)], [],
[@%:@include <sys/types.h>])
RUBY_CHECK_SIZEOF(size_t, [int long void*], [], [@%:@include <sys/types.h>])
RUBY_CHECK_SIZEOF(ptrdiff_t, size_t, [], [@%:@include <stddef.h>])
RUBY_CHECK_PRINTF_PREFIX(size_t, z)
RUBY_CHECK_PRINTF_PREFIX(ptrdiff_t, t)
AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV
RUBY_CHECK_SIZEOF([struct stat.st_size], [int long "long long"], [], [@%:@include <sys/stat.h>])
if test "$ac_cv_member_struct_stat_st_blocks" = yes; then
    RUBY_CHECK_SIZEOF([struct stat.st_blocks], [int long "long long"], [], [@%:@include <sys/stat.h>])
fi
AC_CHECK_MEMBERS([struct stat.st_atim])
AC_CHECK_MEMBERS([struct stat.st_atimespec])
AC_CHECK_MEMBERS([struct stat.st_atimensec])
AC_CHECK_MEMBERS([struct stat.st_mtim])
AC_CHECK_MEMBERS([struct stat.st_mtimespec])
AC_CHECK_MEMBERS([struct stat.st_mtimensec])
AC_CHECK_MEMBERS([struct stat.st_ctim])
AC_CHECK_MEMBERS([struct stat.st_ctimespec])
AC_CHECK_MEMBERS([struct stat.st_ctimensec])

AC_CHECK_TYPES([struct timeval], [], [], [@%:@ifdef HAVE_TIME_H
@%:@include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@include <sys/time.h>
@%:@endif])

if test "${ac_cv_type_struct_timeval}" = yes; then
    RUBY_CHECK_SIZEOF([struct timeval.tv_sec], [time_t long "long long"], [],
[@%:@ifdef HAVE_TIME_H
@%:@include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@include <sys/time.h>
@%:@endif])
    AS_CASE(${ac_cv_sizeof_struct_timeval_tv_sec},
[SIZEOF_INT], [t=int],
[SIZEOF_LONG], [t=long],
[SIZEOF_LONG_LONG], [t=LONG_LONG],
[t=])
    if test "${t}" != ""; then
AC_DEFINE_UNQUOTED(TYPEOF_TIMEVAL_TV_SEC, [$t])
    fi
fi

AC_CHECK_TYPES([struct timespec], [], [], [@%:@ifdef HAVE_TIME_H
@%:@include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@include <sys/time.h>
@%:@endif])

AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@ include <sys/time.h>
@%:@endif])

AC_CHECK_TYPES([clockid_t], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@ include <sys/time.h>
@%:@endif])

AC_CACHE_VAL([rb_cv_large_fd_select],
    [AC_CHECK_TYPE(fd_mask, [rb_cv_large_fd_select=yes], [rb_cv_large_fd_select=no])])
if test "$rb_cv_large_fd_select" = yes; then
    AC_DEFINE(HAVE_RB_FD_INIT, 1)
fi

dnl RUBY_DEFINT TYPENAME, SIZE, [SIGNED-OR-UNSIGNED], [INCLUDES = DEFAULT-INCLUDES]
AC_DEFUN([RUBY_DEFINT], [dnl
AC_CACHE_CHECK([for $1], [rb_cv_type_$1],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
typedef $1 t; int s = sizeof(t) == 42;])],
   [rb_cv_type_$1=yes],
   [AS_CASE([m4_bmatch([$2], [^[1-9][0-9]*$], $2, [$ac_cv_sizeof_]AS_TR_SH($2))],
    ["1"], [ rb_cv_type_$1="m4_if([$3], [], [signed ], [$3 ])char"],
    ["$ac_cv_sizeof_short"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])short"],
    ["$ac_cv_sizeof_int"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])int"],
    ["$ac_cv_sizeof_long"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])long"],
    ["$ac_cv_sizeof_long_long"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])long long"],
    ["$ac_cv_sizeof___int64"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])__int64"],
    ["$ac_cv_sizeof___int128"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])__int128"],
    [ rb_cv_type_$1=no])])])
if test "${rb_cv_type_$1}" != no; then
    AC_DEFINE([HAVE_]AS_TR_CPP($1), 1)
    if test "${rb_cv_type_$1}" = yes; then
m4_bmatch([$2], [^[1-9][0-9]*$], [AC_CHECK_SIZEOF([$1], 0, [AC_INCLUDES_DEFAULT([$4])])],
[RUBY_CHECK_SIZEOF([$1], [$2], [], [AC_INCLUDES_DEFAULT([$4])])])
    else
AC_DEFINE_UNQUOTED($1, [$rb_cv_type_$1])
AC_DEFINE_UNQUOTED([SIZEOF_]AS_TR_CPP($1), [SIZEOF_]AS_TR_CPP([$rb_cv_type_$1]))
    fi
fi
])

RUBY_DEFINT(int8_t, 1)
RUBY_DEFINT(uint8_t, 1, unsigned)
RUBY_DEFINT(int16_t, 2)
RUBY_DEFINT(uint16_t, 2, unsigned)
RUBY_DEFINT(int32_t, 4)
RUBY_DEFINT(uint32_t, 4, unsigned)
RUBY_DEFINT(int64_t, 8)
RUBY_DEFINT(uint64_t, 8, unsigned)
RUBY_DEFINT(int128_t, 16)
RUBY_DEFINT(uint128_t, 16, unsigned)
RUBY_DEFINT(intptr_t, void*)
RUBY_DEFINT(uintptr_t, void*, unsigned)
RUBY_DEFINT(ssize_t, size_t, [], [@%:@include <sys/types.h>]) dnl may differ from int, so not use AC_TYPE_SSIZE_T.

RUBY_NACL_CHECK_PEPPER_TYPES

AC_CACHE_CHECK(for stack end address, rb_cv_stack_end_address,
[rb_cv_stack_end_address=no
  AC_TRY_LINK(
    [extern void *__libc_stack_end;],
    [if (!__libc_stack_end) return 1;],
    [rb_cv_stack_end_address="__libc_stack_end"])
])
if test $rb_cv_stack_end_address != no; then
  AC_DEFINE_UNQUOTED(STACK_END_ADDRESS, $rb_cv_stack_end_address)
fi

# posix_memalign(memptr, alignment, size) implemented for OpenBSD 4.8 doesn't work if alignment > MALLOC_PAGESIZE.
# [ruby-core:42158] https://bugs.ruby-lang.org/issues/5901
# OpenBSD 5.2 fixed the problem. (src/lib/libc/stdlib/malloc.c:1.142)
# MirOS #10semel has the problem but fixed in the repository. (src/lib/libc/stdlib/malloc.c:1.9)
AS_CASE(["$target_os"],
[openbsd*|mirbsd*], [
  AC_CACHE_CHECK(for heap align log on openbsd, rb_cv_page_size_log,
    [rb_cv_page_size_log=no
     for page_log in 12 13; do
       AC_TRY_RUN([
#include <math.h>
#include <unistd.h>

int
main() {
  if ((int)log2((double)sysconf(_SC_PAGESIZE)) != $page_log) return 1;
  return 0;
}
       ],
       rb_cv_page_size_log="$page_log"; break)
     done])
  if test $rb_cv_page_size_log != no; then
    AC_DEFINE_UNQUOTED(HEAP_ALIGN_LOG, $rb_cv_page_size_log)
  else
    AC_DEFINE_UNQUOTED(HEAP_ALIGN_LOG, 12)
  fi
])

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL
AS_CASE(["${target_cpu}-${target_os}:${target_archs}"],
[powerpc-darwin*], [
  AC_LIBSOURCES(alloca.c)
  AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
  AC_DEFINE(C_ALLOCA)
  AC_DEFINE_UNQUOTED(alloca, alloca)
  ],
[universal-darwin*:*ppc*], [
  AC_LIBSOURCES(alloca.c)
  AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
  RUBY_DEFINE_IF([defined __powerpc__], C_ALLOCA, 1)
  RUBY_DEFINE_IF([defined __powerpc__], alloca, alloca)
  ],
[
  AC_FUNC_ALLOCA
  ])
if test "x$ALLOCA" = "x"; then
    AC_CACHE_CHECK([for dynamic size alloca], rb_cv_dynamic_alloca, [
    for chk in ok __chkstk; do
AC_TRY_LINK([
@%:@ifdef HAVE_ALLOCA_H
@%:@include <alloca.h>
@%:@endif
void $chk() {}
int dynamic_alloca_test;
int dynamic_alloca_result;],
[dynamic_alloca_result = alloca(dynamic_alloca_test) != 0;],
[rb_cv_dynamic_alloca=$chk; break])
    done])
    if test "x$rb_cv_dynamic_alloca" = "x__chkstk"; then
AC_DEFINE_UNQUOTED(RUBY_ALLOCA_CHKSTK, _$rb_cv_dynamic_alloca)
AS_CASE("$target_cpu",
[x64|x86_64], [
AC_SUBST([ALLOCA], [\${LIBOBJDIR}x86_64-chkstk.${ac_objext}])
],)
    fi
fi
AC_FUNC_MEMCMP

# http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
# Debian GNU/Linux Etch's libc6.1 2.3.6.ds1-13etch5 has this problem.
# Debian GNU/Linux Lenny's libc6.1 2.7-10 has no problem.
AC_CACHE_CHECK(for broken erfc of glibc-2.3.6 on IA64, rb_cv_broken_glibc_ia64_erfc,
  [AC_TRY_RUN([
#include <math.h>
int
main()
{
   erfc(10000.0);
   return 0;
}
],
rb_cv_broken_glibc_ia64_erfc=no,
rb_cv_broken_glibc_ia64_erfc=yes,
rb_cv_broken_glibc_ia64_erfc=no)])
AS_CASE([$rb_cv_broken_glibc_ia64_erfc],[yes],[ac_cv_func_erf=no])

AS_CASE(["$target_os"],[freebsd*],[
AC_DEFINE(BROKEN_CLOSE)
AC_REPLACE_FUNCS(close)
])
AC_REPLACE_FUNCS(dup2 memmove strerror\
strchr strstr crypt flock\
isnan finite isinf hypot acosh erf tgamma lgamma_r cbrt \
                 strlcpy strlcat ffs setproctitle)

# for missing/setproctitle.c
AS_CASE(["$target_os"],
[aix* | k*bsd*-gnu | kopensolaris*-gnu | linux* | darwin*], [AC_DEFINE(SPT_TYPE,SPT_REUSEARGV)],
[hpux*], [AC_DEFINE(SPT_TYPE,SPT_PSTAT) ],
[])
AC_CHECK_HEADERS(sys/pstat.h)


AC_CACHE_CHECK(for signbit, rb_cv_have_signbit,
  [AC_TRY_LINK([
#include <math.h>
], [int v = signbit(-0.0);],
rb_cv_have_signbit=yes,
rb_cv_have_signbit=no)])
if test "$rb_cv_have_signbit" = yes; then
  AC_DEFINE(HAVE_SIGNBIT)
else
  AC_LIBOBJ([signbit])
fi

AC_CHECK_FUNCS(__syscall)
AC_CHECK_FUNCS(_longjmp) # used for AC_ARG_WITH(setjmp-type)
AC_CHECK_FUNCS(_setjmp) # used for AC_ARG_WITH(setjmp-type)
AC_CHECK_FUNCS(_setjmpex) # used for AC_ARG_WITH(setjmp-type)
AC_CHECK_FUNCS(chroot)
AC_CHECK_FUNCS(chsize)
AC_CHECK_FUNCS(clock_gettime)
AC_CHECK_FUNCS(cosh)
AC_CHECK_FUNCS(daemon)
AC_CHECK_FUNCS(dl_iterate_phdr)
AC_CHECK_FUNCS(dlopen)
AC_CHECK_FUNCS(dladdr)
AC_CHECK_FUNCS(dup)
AC_CHECK_FUNCS(dup3)
AC_CHECK_FUNCS(eaccess)
AC_CHECK_FUNCS(endgrent)
AC_CHECK_FUNCS(fchmod)
AC_CHECK_FUNCS(fchown)
AC_CHECK_FUNCS(fcntl)
AC_CHECK_FUNCS(fdatasync)
AC_CHECK_FUNCS(fmod)
AC_CHECK_FUNCS(fork)
AC_CHECK_FUNCS(fsync)
AC_CHECK_FUNCS(ftruncate)
AC_CHECK_FUNCS(ftruncate64) # used for Win32 platform
AC_CHECK_FUNCS(getcwd)
AC_CHECK_FUNCS(getgrnam_r)
AC_CHECK_FUNCS(getgroups)
AC_CHECK_FUNCS(getpgid)
AC_CHECK_FUNCS(getpgrp)
AC_CHECK_FUNCS(getpriority)
AC_CHECK_FUNCS(getpwnam_r)
AC_CHECK_FUNCS(getrlimit)
AC_CHECK_FUNCS(getsid)
AC_CHECK_FUNCS(gettimeofday) # for making ac_cv_func_gettimeofday
AC_CHECK_FUNCS(gmtime_r)
AC_CHECK_FUNCS(initgroups)
AC_CHECK_FUNCS(ioctl)
AC_CHECK_FUNCS(isfinite)
AC_CHECK_FUNCS(issetugid)
AC_CHECK_FUNCS(killpg)
AC_CHECK_FUNCS(lchmod)
AC_CHECK_FUNCS(lchown)
AC_CHECK_FUNCS(link)
AC_CHECK_FUNCS(llabs)
AC_CHECK_FUNCS(lockf)
AC_CHECK_FUNCS(log2)
AC_CHECK_FUNCS(lstat)
AC_CHECK_FUNCS(malloc_usable_size)
AC_CHECK_FUNCS(malloc_size)
AC_CHECK_FUNCS(mblen)
AC_CHECK_FUNCS(memalign)
AC_CHECK_FUNCS(writev)
AC_CHECK_FUNCS(memrchr)
AC_CHECK_FUNCS(memmem)
AC_CHECK_FUNCS(mktime)
AC_CHECK_FUNCS(pipe2)
AC_CHECK_FUNCS(poll)
AC_CHECK_FUNCS(posix_fadvise)
AC_CHECK_FUNCS(posix_memalign)
AC_CHECK_FUNCS(ppoll)
AC_CHECK_FUNCS(pread)
AC_CHECK_FUNCS(qsort_r)
AC_CHECK_FUNCS(readlink)
AC_CHECK_FUNCS(round)
AC_CHECK_FUNCS(seekdir)
AC_CHECK_FUNCS(select_large_fdset)
AC_CHECK_FUNCS(sendfile)
AC_CHECK_FUNCS(setegid)
AC_CHECK_FUNCS(setenv)
AC_CHECK_FUNCS(seteuid)
AC_CHECK_FUNCS(setgid)
AC_CHECK_FUNCS(setgroups)
AC_CHECK_FUNCS(setpgid)
AC_CHECK_FUNCS(setpgrp)
AC_CHECK_FUNCS(setregid)
AC_CHECK_FUNCS(setresgid)
AC_CHECK_FUNCS(setresuid)
AC_CHECK_FUNCS(setreuid)
AC_CHECK_FUNCS(setrgid)
AC_CHECK_FUNCS(setrlimit)
AC_CHECK_FUNCS(setruid)
AC_CHECK_FUNCS(setsid)
AC_CHECK_FUNCS(setuid)
AC_CHECK_FUNCS(shutdown)
AC_CHECK_FUNCS(sigaction)
AC_CHECK_FUNCS(sigaltstack)
AC_CHECK_FUNCS(sigprocmask)
AC_CHECK_FUNCS(sinh)
AC_CHECK_FUNCS(spawnv)
AC_CHECK_FUNCS(symlink)
AC_CHECK_FUNCS(syscall)
AC_CHECK_FUNCS(sysconf)
AC_CHECK_FUNCS(tanh)
AC_CHECK_FUNCS(telldir)
AC_CHECK_FUNCS(timegm)
AC_CHECK_FUNCS(times)
AC_CHECK_FUNCS(truncate)
AC_CHECK_FUNCS(truncate64) # used for Win32
AC_CHECK_FUNCS(unsetenv)
AC_CHECK_FUNCS(utimensat)
AC_CHECK_FUNCS(utimes)
AC_CHECK_FUNCS(wait4)
AC_CHECK_FUNCS(waitpid)

AS_IF([test "$ac_cv_func_getcwd" = yes], [
    AC_CACHE_CHECK(if getcwd allocates buffer if NULL is given, [rb_cv_getcwd_malloc],
[AC_TRY_RUN([
@%:@include <stddef.h>
@%:@include <stdio.h>
@%:@ifdef HAVE_UNISTD_H
@%:@include <unistd.h>
@%:@endif
@%:@ifndef EXIT_SUCCESS
@%:@define EXIT_SUCCESS 0
@%:@endif
@%:@ifndef EXIT_FAILURE
@%:@define EXIT_FAILURE 1
@%:@endif

int
main(int argc, char **argv)
{
    if (!getcwd(NULL, 0)) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}
],
rb_cv_getcwd_malloc=yes,
rb_cv_getcwd_malloc=no,
AS_CASE($target_os,
[linux*|darwin*|*bsd|cygwin*|mingw*|mswin*],
[rb_cv_getcwd_malloc=yes],
[rb_cv_getcwd_malloc=no]))])
    AS_IF([test "$rb_cv_getcwd_malloc" = no], [AC_DEFINE(NO_GETCWD_MALLOC, 1)])
])

AC_DEFUN([RUBY_CHECK_BUILTIN_FUNC], [dnl
AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_builtin_$1),
  [AC_LINK_IFELSE(
    [AC_LANG_PROGRAM([], [$2;])],
    [AS_TR_SH(rb_cv_builtin_$1)=yes],
    [AS_TR_SH(rb_cv_builtin_$1)=no])])
if test "${AS_TR_SH(rb_cv_builtin_$1)}" != no; then
  AC_DEFINE(AS_TR_CPP(HAVE_BUILTIN_$1))
fi])
RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap16, [__builtin_bswap16(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap32, [__builtin_bswap32(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap64, [__builtin_bswap64(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_clz, [__builtin_clz(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_clzl, [__builtin_clzl(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_clzll, [__builtin_clzll(0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr, [__builtin_choose_expr(0, 0, 0)])
RUBY_CHECK_BUILTIN_FUNC(__builtin_types_compatible_p, [__builtin_types_compatible_p(int, int)])

if test "$ac_cv_func_qsort_r" != no; then
  AC_CACHE_CHECK(whether qsort_r is GNU version, rb_cv_gnu_qsort_r,
    [AC_TRY_COMPILE([
@%:@include <stdlib.h>
void qsort_r(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *, void *),
void *arg);
],[ ],
      [rb_cv_gnu_qsort_r=yes],
      [rb_cv_gnu_qsort_r=no])
  ])
  AC_CACHE_CHECK(whether qsort_r is BSD version, rb_cv_bsd_qsort_r,
    [AC_TRY_COMPILE([
@%:@include <stdlib.h>
void qsort_r(void *base, size_t nmemb, size_t size,
void *arg, int (*compar)(void *, const void *, const void *));
],[ ],
      [rb_cv_bsd_qsort_r=yes],
      [rb_cv_bsd_qsort_r=no])
  ])
  AS_CASE("$rb_cv_gnu_qsort_r:$rb_cv_bsd_qsort_r",
  [yes:no], [
    AC_DEFINE(HAVE_GNU_QSORT_R, 1)
  ])
fi

# Some platform need -lrt for clock_gettime, but the other don't.
if test x"$ac_cv_func_clock_gettime" != xyes; then
    # glibc 2.17 moves clock_* functions from librt to the main C library.
    # http://sourceware.org/ml/libc-announce/2012/msg00001.html
    AC_CHECK_LIB(rt, clock_gettime)
    if test x"$ac_cv_lib_rt_clock_gettime" = xyes; then
AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
    fi
fi
AC_CHECK_FUNCS(clock_getres) # clock_getres should be tested after clock_gettime test including librt test.

AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
  [AC_TRY_COMPILE([
#include <stdlib.h>
], [int v = unsetenv("foo");],
rb_cv_unsetenv_return_value=yes,
rb_cv_unsetenv_return_value=no)])
if test "$rb_cv_unsetenv_return_value" = no; then
  AC_DEFINE(VOID_UNSETENV)
fi

# used for AC_ARG_WITH(setjmp-type)
AC_CACHE_CHECK(for sigsetjmp as a macro or function, ac_cv_func_sigsetjmp,
  [AC_TRY_COMPILE([
#include <setjmp.h>
], [sigjmp_buf env; sigsetjmp(env,1);],
ac_cv_func_sigsetjmp=yes,
ac_cv_func_sigsetjmp=no)])

if test x"${ac_cv_func___builtin_setjmp}" = xyes; then
   unset ac_cv_func___builtin_setjmp
fi
AC_CACHE_CHECK(for __builtin_setjmp, ac_cv_func___builtin_setjmp,
    [
    ac_cv_func___builtin_setjmp=no
    for cast in "" "(void **)"; do
RUBY_WERROR_FLAG(
[AC_TRY_LINK([@%:@include <setjmp.h>
@%:@include <stdio.h>
jmp_buf jb;
void t(void) {__builtin_longjmp($cast jb, 1);}
int jump(void) {(void)(__builtin_setjmp($cast jb) ? 1 : 0); return 0;}],
[
void (*volatile f)(void) = t;
if (!jump()) printf("%d\n", f != 0);
],
[ac_cv_func___builtin_setjmp="yes with cast ($cast)"])
])
test "$ac_cv_func___builtin_setjmp" = no || break
    done])

# we don't use _setjmp if _longjmp doesn't exist.
test x$ac_cv_func__longjmp = xno && ac_cv_func__setjmp=no

AC_MSG_CHECKING(for setjmp type)
setjmp_suffix=
AC_ARG_WITH(setjmp-type,
AS_HELP_STRING([--with-setjmp-type], [select setjmp type]),
[
AS_CASE([$withval],
[__builtin_setjmp], [setjmp=__builtin_setjmp],
[_setjmp], [ setjmp_prefix=_],
[sigsetjmp], [ setjmp_prefix=sig],
[setjmp], [ setjmp_prefix=],
[setjmpex], [ setjmp_prefix= setjmp_suffix=ex],
[''], [ unset setjmp_prefix],
[ AC_MSG_ERROR(invalid setjmp type: $withval)])], [unset setjmp_prefix])
setjmp_cast=
if test ${setjmp_prefix+set}; then
    if test "${setjmp_prefix}" && eval test '$ac_cv_func_'${setjmp_prefix}setjmp${setjmp_suffix} = no; then
AC_MSG_ERROR(${setjmp_prefix}setjmp${setjmp_suffix} is not available)
    fi
elif { AS_CASE("$ac_cv_func___builtin_setjmp", [yes*], [true], [false]); }; then
    setjmp_cast=`expr "$ac_cv_func___builtin_setjmp" : "yes with cast (\(.*\))"`
    setjmp_prefix=__builtin_
    setjmp_suffix=
elif test "$ac_cv_header_setjmpex_h:$ac_cv_func__setjmpex" = yes:yes; then
    setjmp_prefix=
    setjmp_suffix=ex
elif test "$ac_cv_func__setjmp" = yes; then
    setjmp_prefix=_
    setjmp_suffix=
elif test "$ac_cv_func_sigsetjmp" = yes; then
    AS_CASE([$target_os],[solaris*|cygwin*],[setjmp_prefix=],[setjmp_prefix=sig])
    setjmp_suffix=
else
    setjmp_prefix=
    setjmp_suffix=
fi
if test x$setjmp_prefix = xsig; then
    setjmp_sigmask=yes
else
    unset setjmp_sigmask
fi
AC_MSG_RESULT(${setjmp_prefix}setjmp${setjmp_suffix}${setjmp_cast:+($setjmp_cast)})
AC_DEFINE_UNQUOTED([RUBY_SETJMP(env)], [${setjmp_prefix}setjmp${setjmp_suffix}($setjmp_cast(env)${setjmp_sigmask+,0})])
AC_DEFINE_UNQUOTED([RUBY_LONGJMP(env,val)], [${setjmp_prefix}longjmp($setjmp_cast(env),val)])
AC_DEFINE_UNQUOTED(RUBY_JMP_BUF, ${setjmp_sigmask+${setjmp_prefix}}jmp_buf)
# End of setjmp check.

AC_ARG_ENABLE(setreuid,
       AS_HELP_STRING([--enable-setreuid], [use setreuid()/setregid() according to need even if obsolete]),
       [use_setreuid=$enableval])
if test "$use_setreuid" = yes; then
    AC_DEFINE(USE_SETREUID)
    AC_DEFINE(USE_SETREGID)
fi
AC_STRUCT_TIMEZONE
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
  [AC_TRY_COMPILE([@%:@include <time.h>],
    [struct tm t; t.tm_gmtoff = 3600;],
  [rb_cv_member_struct_tm_tm_gmtoff=yes],
  [rb_cv_member_struct_tm_tm_gmtoff=no])])
if test "$rb_cv_member_struct_tm_tm_gmtoff" = yes; then
  AC_DEFINE(HAVE_STRUCT_TM_TM_GMTOFF)
fi
AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
  [AC_TRY_LINK([#include <time.h>
  int i;],
[i = daylight;],
rb_cv_have_daylight=yes,
rb_cv_have_daylight=no)])
if test "$rb_cv_have_daylight" = yes; then
  AC_DEFINE(HAVE_DAYLIGHT)
fi
AC_DEFUN([RUBY_CHECK_VARTYPE], [dnl
AC_CACHE_CHECK([for external $1], AS_TR_SH(rb_cv_var_$1),
  [AS_TR_SH(rb_cv_var_$1)=no
  AC_TRY_COMPILE([
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
#endif
$2
;
const volatile void *volatile t;],
    [t = &(&$1)[0];],
    [for t in $3; do
      AC_TRY_COMPILE([
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
#endif
$2
;
extern $t $1;
const volatile void *volatile t;],
        [t = &(&$1)[0];],
        [AS_TR_SH(rb_cv_var_$1)=$t; break])
    done])])
if test "${AS_TR_SH(rb_cv_var_$1)}" != no; then
  AC_DEFINE(AS_TR_CPP(HAVE_VAR_$1))
  AC_DEFINE_UNQUOTED(AS_TR_CPP(TYPEOF_VAR_$1), ${AS_TR_SH(rb_cv_var_$1)})
fi])
RUBY_CHECK_VARTYPE(timezone, [@%:@include <time.h>], [long int])
RUBY_CHECK_VARTYPE(altzone, [@%:@include <time.h>], [long int])
AC_CHECK_FUNCS(timezone)
if test "$ac_cv_func_timezone" = yes; then
  AC_CACHE_CHECK([whether timezone requires zero arguments], rb_cv_func_timezone_void,
    [AC_TRY_COMPILE([@%:@include <time.h>],
      [(void)timezone(0, 0);],
      [rb_cv_func_timezone_void=no],
      [rb_cv_func_timezone_void=yes])]
  )
  if test $rb_cv_func_timezone_void = yes; then
    AC_DEFINE(TIMEZONE_VOID)
  fi
fi

AC_CACHE_CHECK(for negative time_t for gmtime(3), rb_cv_negative_time_t,
  [AC_TRY_RUN([
#include <stdlib.h>
#include <time.h>

void
check(tm, y, m, d, h, s)
    struct tm *tm;
    int y, m, d, h, s;
{
    if (!tm ||
tm->tm_year != y ||
tm->tm_mon != m-1 ||
tm->tm_mday != d ||
tm->tm_hour != h ||
tm->tm_sec != s) {
exit(1);
    }
}

int
main()
{
   time_t t = -1;
   struct tm *tm;

   check(gmtime(&t), 69, 12, 31, 23, 59);
   t = ~(time_t)0 << 31;
   check(gmtime(&t), 1, 12, 13, 20, 52);
   return 0;
}
],
rb_cv_negative_time_t=yes,
rb_cv_negative_time_t=no,
rb_cv_negative_time_t=yes)])
if test "$rb_cv_negative_time_t" = yes; then
  AC_DEFINE(NEGATIVE_TIME_T)
fi

# [ruby-dev:40910] overflow of time on FreeBSD
# http://www.freebsd.org/cgi/query-pr.cgi?pr=145341
AC_CACHE_CHECK(for localtime(3) overflow correctly, rb_cv_localtime_overflow,
  [AC_TRY_RUN([
#include <stdlib.h>
#include <time.h>

void
check(time_t t1)
{
    struct tm *tm;
    time_t t2;
    tm = localtime(&t1);
    if (!tm)
return; /* overflow detected. ok. */
    t2 = mktime(tm);
    if (t1 == t2)
        return; /* round-trip. ok. */
    exit(1);
}

int
main()
{
    time_t t;
    if (~(time_t)0 <= 0) {
        t = (((time_t)1) << (sizeof(time_t) * 8 - 2));
        t |= t - 1;
    }
    else {
        t = ~(time_t)0;
    }
    check(t);
    return 0;
}
],
rb_cv_localtime_overflow=yes,
rb_cv_localtime_overflow=no,
rb_cv_localtime_overflow=no)])
if test "$rb_cv_localtime_overflow" = no; then
  AC_DEFINE(LOCALTIME_OVERFLOW_PROBLEM)
fi

if test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes; then
   AC_DEFINE(POSIX_SIGNAL)
else
  AC_CHECK_FUNCS(sigsetmask)
  AC_CACHE_CHECK(for BSD signal semantics, rb_cv_bsd_signal,
    [AC_TRY_RUN([
#include <stdio.h>
#include <signal.h>

void
sig_handler(dummy)
     int dummy;
{
}

int
main()
{
  signal(SIGINT, sig_handler);
  kill(getpid(), SIGINT);
  kill(getpid(), SIGINT);
  return 0;
}
],
rb_cv_bsd_signal=yes,
rb_cv_bsd_signal=no,
rb_cv_bsd_signal=$ac_cv_func_sigsetmask)])
  if test "$rb_cv_bsd_signal" = yes; then
    AC_DEFINE(BSD_SIGNAL)
  fi
fi

if test "$ac_cv_func_getpgid" = no; then
  # AC_FUNC_GETPGRP fails when cross-compiling with old autoconf.
  # autoconf is changed between 2.52d and 2.52f?
  # http://lists.gnu.org/archive/html/bug-gnu-utils/2001-09/msg00181.html
  # "autoconf cleanup for AC_FUNC_GETPGRP and GETPGRP_VOID"
AC_FUNC_GETPGRP
fi
if test "$ac_cv_func_setpgid:$ac_cv_func_setpgrp" = no:yes; then
  # AC_FUNC_SETPGRP fails when cross-compiling. (until autoconf 2.69?)
  # https://lists.gnu.org/archive/html/bug-autoconf/2013-02/msg00002.html
  # "AC_FUNC_SETPGRP fails to work properly when cross-compiling"
AC_FUNC_SETPGRP
fi

if test x"$target_cpu" = xia64; then
    AC_LIBOBJ([ia64])
    AC_CACHE_CHECK(for __libc_ia64_register_backing_store_base,
                   rb_cv___libc_ia64_register_backing_store_base,
    [rb_cv___libc_ia64_register_backing_store_base=no
    AC_TRY_LINK(
      [extern unsigned long __libc_ia64_register_backing_store_base;],
      [unsigned long p = __libc_ia64_register_backing_store_base;
       printf("%ld\n", p);],
      [rb_cv___libc_ia64_register_backing_store_base=yes])])
    if test $rb_cv___libc_ia64_register_backing_store_base = yes; then
      AC_DEFINE(HAVE___LIBC_IA64_REGISTER_BACKING_STORE_BASE)
    fi
fi

AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
    [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [(-1==(-1>>1))])],
rb_cv_rshift_sign=yes,
rb_cv_rshift_sign=no)])
if test "$rb_cv_rshift_sign" = yes; then
  AC_DEFINE(RSHIFT(x,y), ((x)>>(int)(y)))
else
  AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>(int)(y)) : (x)>>(int)(y)))
fi

if test x"$ac_cv_func_gettimeofday" != xyes; then
    AC_MSG_ERROR(gettimeofday() must exist)
fi

RUBY_CHECK_SIZEOF([struct stat.st_ino], [long "long long"], [], [@%:@include <sys/stat.h>])

if test "$ac_cv_func_sysconf" = yes; then
  AC_DEFUN([RUBY_CHECK_SYSCONF], [dnl
  AC_CACHE_CHECK([whether _SC_$1 is supported], rb_cv_have_sc_[]m4_tolower($1),
    [AC_TRY_COMPILE([#include <unistd.h>
      ],
      [_SC_$1 >= 0],
      rb_cv_have_sc_[]m4_tolower($1)=yes,
      rb_cv_have_sc_[]m4_tolower($1)=no)
    ])
  if test "$rb_cv_have_sc_[]m4_tolower($1)" = yes; then
    AC_DEFINE(HAVE__SC_$1)
  fi
  ])
  RUBY_CHECK_SYSCONF(CLK_TCK)
fi

AC_DEFUN(RUBY_STACK_GROW_DIRECTION, [
    AS_VAR_PUSHDEF([stack_grow_dir], [rb_cv_stack_grow_dir_$1])
    AC_CACHE_CHECK(stack growing direction on $1, stack_grow_dir, [
AS_CASE(["$1"],
[m68*|x86*|x64|i?86|ia64|ppc*|sparc*|alpha*], [ $2=-1],
[hppa*], [ $2=+1],
[
  AC_TRY_RUN([
/* recurse to get rid of inlining */
static int
stack_growup_p(addr, n)
    volatile int *addr, n;
{
    volatile int end;
    if (n > 0)
return *addr = stack_growup_p(addr, n - 1);
    else
return (&end > addr);
}
int main()
{
    int x;
    return stack_growup_p(&x, 10);
}
], $2=-1, $2=+1, $2=0)
  ])
eval stack_grow_dir=\$$2])
eval $2=\$stack_grow_dir
AS_VAR_POPDEF([stack_grow_dir])])
if test "${universal_binary-no}" = yes ; then
    archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
    save_CFLAGS="$CFLAGS" new_cflags=`echo "$CFLAGS" | sed "s|$archflagpat"'||'`
    save_LDFLAGS="$LDFLAGS" new_ldflags=`echo "$LDFLAGS" | sed "s|$archflagpat"'||'`
    stack_dir=
    for archs in ${universal_archnames}; do
archs=`echo $archs | sed 's/=.*//'`
CFLAGS="$new_cflags -arch $archs"
LDFLAGS="$new_ldflags -arch $archs"
RUBY_STACK_GROW_DIRECTION($archs, dir)
if test x$stack_dir = x; then
stack_dir=$dir
elif test x$stack_dir != x$dir; then
stack_dir=no
fi
    done
    CFLAGS="$save_CFLAGS" LDFLAGS="$save_LDFLAGS"
    if test x$stack_dir = xno; then
for archs in ${universal_archnames}; do
archs=`echo $archs | sed 's/=.*//'`
eval dir=\$[rb_cv_stack_grow_dir_]AS_TR_SH([$archs])
RUBY_DEFINE_IF([defined __${archs}__], STACK_GROW_DIRECTION, $dir)
done
    else
AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $stack_dir)
    fi
else
    RUBY_STACK_GROW_DIRECTION($target_cpu, dir)
    AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $dir)
fi

if test x"$enable_pthread" = xyes; then
    for pthread_lib in thr pthread pthreads c c_r root; do
AC_CHECK_LIB($pthread_lib, pthread_kill,
rb_with_pthread=yes, rb_with_pthread=no)
if test "$rb_with_pthread" = "yes"; then break; fi
    done
    if test x"$rb_with_pthread" = xyes; then
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
AC_CHECK_HEADERS(pthread_np.h, [], [], [@%:@include <pthread.h>])
AS_CASE([$pthread_lib],
[c], [],
[root], [],
[c_r], [MAINLIBS="-pthread $MAINLIBS"],
[AS_CASE(["$target_os"],
[openbsd*|mirbsd*], [LIBS="-pthread $LIBS"],
[LIBS="-l$pthread_lib $LIBS"])])
    else
AC_MSG_WARN("Don't know how to find pthread library on your system -- thread support disabled")
    fi
    AC_CHECK_FUNCS(sched_yield pthread_attr_setinheritsched \
pthread_getattr_np pthread_attr_get_np pthread_attr_getstack\
pthread_get_stackaddr_np pthread_get_stacksize_np \
thr_stksegment pthread_stackseg_np pthread_getthrds_np \
pthread_cond_init pthread_condattr_setclock pthread_condattr_init \
pthread_sigmask pthread_setname_np)
    if test "${host_os}" = "nacl"; then
      ac_cv_func_pthread_attr_init=no
    else
      AC_CHECK_FUNCS(pthread_attr_init)
    fi
    if test "$ac_cv_func_pthread_setname_np" = yes; then
AC_CACHE_CHECK([arguments of pthread_setname_np], [rb_cv_func_pthread_setname_np_arguments],
[rb_cv_func_pthread_setname_np_arguments=
for mac in \
"(pthread_self(), name)" \
"(pthread_self(), "%s", name)" \
"(name)" \
; do
AC_TRY_COMPILE([
@%:@include <pthread.h>
@%:@ifdef HAVE_PTHREAD_NP_H
@%:@include <pthread_np.h>
@%:@endif
@%:@define SET_THREAD_NAME(name) pthread_setname_np${mac}
],
[if (SET_THREAD_NAME("conftest")) return 1;],
[rb_cv_func_pthread_setname_np_arguments="${mac}"
break])
done
]
)
if test -n "${rb_cv_func_pthread_setname_np_arguments}"; then
AC_DEFINE_UNQUOTED(SET_THREAD_NAME(name), pthread_setname_np${rb_cv_func_pthread_setname_np_arguments})
else
AC_DEFINE_UNQUOTED(SET_THREAD_NAME(name), (void)0)
fi
    fi
fi
if test x"$ac_cv_header_ucontext_h" = xyes; then
    if test x"$rb_with_pthread" = xyes; then
AC_CHECK_FUNCS(getcontext setcontext)
    fi
fi

if test "$ac_cv_func_fork" = "yes" -a "$rb_with_pthread" = "yes"; then
    AC_CACHE_CHECK([if fork works with pthread], rb_cv_fork_with_pthread,
[AC_TRY_RUN([
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif

void *
thread_func(void *dmy)
{
    return dmy;
}

int
use_threads(void)
{
    pthread_t tid;
    if (pthread_create(&tid, 0, thread_func, 0) != 0) {
return -1;
    }
    if (pthread_join(tid, 0) != 0) {
return -1;
    }
    return 0;
}

int
main(int argc, char *argv[])
{
    pid_t pid;
    if (use_threads()) return EXIT_FAILURE;
    pid = fork();

    if (pid) {
int loc;
sleep(1);
if (waitpid(pid, &loc, WNOHANG) == 0) {
kill(pid, SIGKILL);
return EXIT_FAILURE;
}
        if (!WIFEXITED(loc) || WEXITSTATUS(loc) != EXIT_SUCCESS)
           return EXIT_FAILURE;
    }
    else {
if (use_threads()) return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}],
rb_cv_fork_with_pthread=yes,
rb_cv_fork_with_pthread=no,
rb_cv_fork_with_pthread=yes)])
    test x$rb_cv_fork_with_pthread = xyes || AC_DEFINE(CANNOT_FORK_WITH_PTHREAD)
fi


}
{ # runtime section

dnl wheather use dln_a_out or not
AC_ARG_WITH(dln-a-out,
AS_HELP_STRING([--with-dln-a-out], [use dln_a_out if possible]),
[
AS_CASE([$withval],
[yes], [
if test "$enable_shared" = yes; then
AC_MSG_ERROR(dln_a_out can not make shared library)
fi
with_dln_a_out=yes],
[
with_dln_a_out=no])], [with_dln_a_out=no])

AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
[AC_TRY_LINK([],[], [
AS_CASE(["`head -1 conftest$EXEEXT | cat -e`"],
['^?ELF'*], [rb_cv_binary_elf=yes], [rb_cv_binary_elf=no])],
rb_cv_binary_elf=no)])

if test "$rb_cv_binary_elf" = yes; then
  AC_DEFINE(USE_ELF)
  if test "$with_dln_a_out" = yes; then
    AC_MSG_ERROR(dln_a_out does not work with ELF)
  fi
  AC_CHECK_HEADERS([elf.h elf_abi.h])
  if test $ac_cv_header_elf_h = yes -o $ac_cv_header_elf_abi_h = yes; then
    AC_LIBOBJ([addr2line])
  fi
fi

AS_CASE(["$target_os"],
[linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu | nacl], [
    if test "$rb_cv_binary_elf" = no; then
with_dln_a_out=yes
    else
LDFLAGS="$LDFLAGS -rdynamic"
    fi])
LIBEXT=a

AC_SUBST(DLDFLAGS)dnl
AC_SUBST(ARCH_FLAG)dnl

AC_SUBST(STATIC)dnl
AC_SUBST(CCDLFLAGS)dnl
AC_SUBST(LDSHARED)dnl
AC_SUBST(LDSHAREDXX)dnl
AC_SUBST(DLEXT)dnl
AC_SUBST(DLEXT2)dnl
AC_SUBST(LIBEXT)dnl

STATIC=
: ${PATHFLAG=''}

if test "$with_dln_a_out" != yes; then
  rb_cv_dlopen=unknown
  AC_MSG_CHECKING(whether OS depend dynamic link works)
  if test "$GCC" = yes; then
    AS_CASE(["$target_os"],
    [darwin*], [
      # The -fno-common is needed if we wish to embed the Ruby interpreter
      # into a plugin module of some project (as opposed to embedding it
      # within the project's application). The -I/usr/local/include is
      # needed because CPP as discovered by configure (cc -E -traditional)
      # fails to consult /usr/local/include by default. This causes
      # mkmf.rb's have_header() to fail if the desired resource happens to be
      # installed in the /usr/local tree.
      RUBY_APPEND_OPTION(CCDLFLAGS, -fno-common)],
    [bsdi*|beos*|haiku*|cygwin*|mingw*|aix*|interix*], [ ],
    [
      RUBY_APPEND_OPTION(CCDLFLAGS, -fPIC)])
  else
    AS_CASE(["$target_os"],
[hpux*], [CCDLFLAGS="$CCDLFLAGS +Z"],
[solaris*|irix*], [CCDLFLAGS="$CCDLFLAGS -KPIC"],
[sunos*], [CCDLFLAGS="$CCDLFLAGS -PIC"],
[esix*|uxpds*], [CCDLFLAGS="$CCDLFLAGS -KPIC"],
[: ${CCDLFLAGS=""}])
  fi


  AC_ARG_ENABLE(rpath,
       AS_HELP_STRING([--enable-rpath], [embed run path into extension libraries.
       enabled by default on ELF platforms]),
       [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])

  AS_CASE(["$target_os"],
[hpux*], [ DLDFLAGS="$DLDFLAGS -E"
: ${LDSHARED='$(LD) -b'}
XLDFLAGS="$XLDFLAGS -Wl,-E"
: ${LIBPATHENV=SHLIB_PATH}
if test "$rb_cv_prog_gnu_ld" = no; then
RPATHFLAG=' +b %1$-s'
fi
rb_cv_dlopen=yes],
[solaris*], [ if test "$GCC" = yes; then
: ${LDSHARED='$(CC) -shared'}
if test "$rb_cv_prog_gnu_ld" = yes; then
LDFLAGS="$LDFLAGS -Wl,-E"
fi
else
: ${LDSHARED='$(CC) -G'}
fi
if test "$ac_cv_sizeof_voidp" = 8; then
: ${LIBPATHENV=LD_LIBRARY_PATH_64}
fi
rb_cv_dlopen=yes],
[sunos*], [ : ${LDSHARED='$(LD) -assert nodefinitions'}
rb_cv_dlopen=yes],
[irix*], [ : ${LDSHARED='$(LD) -shared'}
rb_cv_dlopen=yes],
[sysv4*], [ : ${LDSHARED='$(LD) -G'}
rb_cv_dlopen=yes],
[nto-qnx*], [ : ${LDSHARED='$(CC) -shared'}
rb_cv_dlopen=yes],
[esix*|uxpds*], [ : ${LDSHARED='$(LD) -G'}
rb_cv_dlopen=yes],
[osf*], [ : ${LDSHARED='$(LD) -shared -expect_unresolved "*"'}
rb_cv_dlopen=yes],
[bsdi3*], [ AS_CASE(["$CC"],
[*shlicc*], [ : ${LDSHARED='$(CC) -r'}
rb_cv_dlopen=yes])],
[linux* | gnu* | k*bsd*-gnu | netbsd* | bsdi* | kopensolaris*-gnu], [
: ${LDSHARED='$(CC) -shared'}
if test "$rb_cv_binary_elf" = yes; then
LDFLAGS="$LDFLAGS -Wl,-export-dynamic"
fi
rb_cv_dlopen=yes],
[interix*], [ : ${LDSHARED='$(CC) -shared'}
XLDFLAGS="$XLDFLAGS -Wl,-E"
LIBPATHFLAG=" -L%1\$-s"
rb_cv_dlopen=yes],
[freebsd*|dragonfly*], [
: ${LDSHARED='$(CC) -shared'}
if test "$rb_cv_binary_elf" = yes; then
LDFLAGS="$LDFLAGS -rdynamic"
DLDFLAGS="$DLDFLAGS "'-Wl,-soname,$@'
else
test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED='$(LD) -Bshareable'
fi
rb_cv_dlopen=yes],
[openbsd*|mirbsd*], [ : ${LDSHARED='$(CC) -shared ${CCDLFLAGS}'}
if test "$rb_cv_binary_elf" = yes; then
LDFLAGS="$LDFLAGS -Wl,-E"
fi
rb_cv_dlopen=yes],
[darwin*], [ : ${LDSHARED='$(CC) -dynamic -bundle'}
: ${LDFLAGS=""}
: ${LIBPATHENV=DYLD_LIBRARY_PATH}
# /usr/local/include is always searched for
# some reason, but /usr/local/lib is not.
hdr=`find /usr/local/include -name \*.h -type f | sed 's:^/usr/local/include/::;q'`
if test -n "$hdr" && $CC -E -include "$hdr" -xc - </dev/null 2>/dev/null | fgrep -q "$hdr"; then
$CC -print-search-dirs | grep -q '^libraries:.*:/usr/local/lib/*' ||
echo " $LDFLAGS " | grep -q ' -L */usr/local/lib/* ' ||
LDFLAGS="${LDFLAGS:+$LDFLAGS }-L/usr/local/lib"
fi
rb_cv_dlopen=yes],
        [aix*], [ : ${LDSHARED='$(CC)'}
LDSHARED="$LDSHARED ${linker_flag}-G"
EXTDLDFLAGS='-e$(TARGET_ENTRY)'
XLDFLAGS="${linker_flag}"'-bE:$(ARCHFILE)'" ${linker_flag}-brtl"
XLDFLAGS="$XLDFLAGS ${linker_flag}-blibpath:${prefix}/lib:${LIBPATH:-/usr/lib:/lib}"
: ${ARCHFILE="ruby.imp"}
                        TRY_LINK='$(CC) $(LDFLAGS) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
                        TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS) $(LIBS)'
: ${LIBPATHENV=LIBPATH}
RPATHFLAG=" ${linker_flag}-blibpath:%1\$-s:${prefix}/lib:${LIBPATH:-/usr/lib:/lib}"
rb_cv_dlopen=yes],
[beos*], [ AS_CASE(["$target_cpu"],
[powerpc*], [
: ${LDSHARED='$(LD) -xms'}
EXTDLDFLAGS='-export $(TARGET_ENTRY)'
DLDFLAGS="$DLDFLAGS -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o"
LDFLAGS="$LDFLAGS -L/boot/home/config/lib -lbe -lroot"
],
[i586*], [
: ${LDSHARED='$(LD) -shared'}
DLDFLAGS="$DLDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib \$(topdir)/_APP_ -lroot"
LDFLAGS="$LDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib -lroot"
])
: ${LIBPATHENV=LIBRARY_PATH}
rb_cv_dlopen=yes],
[haiku*], [ AS_CASE(["$target_cpu"],
[powerpc*], [
: ${LDSHARED='$(LD) -xms'}
EXTDLDFLAGS='-export $(TARGET_ENTRY)'
DLDFLAGS="$DLDFLAGS -lroot glue-noinit.a init_term_dyn.o start_dyn.o"
                            ],
[i586*], [
: ${LDSHARED='$(CC) -shared'}
])
: ${LIBPATHENV=LIBRARY_PATH}
rb_cv_dlopen=yes ],
[nto-qnx*], [ DLDFLAGS="$DLDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
: ${LDSHARED='$(LD) -Bshareable -x'}
LDFLAGS="$LDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
rb_cv_dlopen=yes],
[cygwin*|mingw*], [
: ${LDSHARED='$(CC) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)'}
XLDFLAGS="$XLDFLAGS -Wl,--stack,0x00200000,--enable-auto-import"
DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-image-base,--enable-auto-import"
: ${LIBPATHENV=""}
rb_cv_dlopen=yes],
[hiuxmpp], [ : ${LDSHARED='$(LD) -r'}],
[atheos*], [ : ${LDSHARED='$(CC) -shared'}
rb_cv_dlopen=yes],
[os2-emx*], [ LDFLAGS="$LDFLAGS -Zomf"
],
        [nacl], [ LDSHARED='$(CC) -shared' ],
[ : ${LDSHARED='$(LD)'}])
  AC_MSG_RESULT($rb_cv_dlopen)

  if test "$rb_cv_dlopen" = yes; then
    AS_CASE(["$target_os"],
      [darwin*], [
for flag in \
"-undefined dynamic_lookup" \
"-multiply_defined suppress" \
; do
test "x${linker_flag}" = x || flag="${linker_flag}${flag// /,}"
RUBY_TRY_LDFLAGS([$flag], [], [flag=])
if test "x$flag" != x; then
RUBY_APPEND_OPTIONS(DLDFLAGS, [$flag])
fi
done
      ])
  fi

  if test "$enable_rpath" = yes; then
    if test x"${RPATHFLAG}" = x; then
      for rpathflag in -R "-rpath "; do
AS_CASE("$rpathflag",
[*" "], [AS_CASE(["${linker_flag}"],
[*,], [rpathflag=`echo "$rpathflag" | tr ' ' ,`])])
rpathflag="${linker_flag}${rpathflag}"
RUBY_TRY_LDFLAGS([${rpathflag}.], [], [rpathflag=])
if test "x${rpathflag}" != x; then
RPATHFLAG=" ${rpathflag}%1\$-s"
break
fi
      done
    fi
  fi
fi
if test "${LDSHAREDXX}" = ""; then
    AS_CASE(["${LDSHARED}"],
[*'$(CC)'*], [
LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\$(CC)/$(CXX)/'`
],
[*'${CC}'*], [
LDSHAREDXX=`echo "${LDSHARED}" | sed 's/\${CC}/${CXX}/'`
],
[*$CC*], [
LDSHAREDXX=`echo "${LDSHARED}" | sed "s|$CC|$CXX|"`
],
[ld" "*], [
])
fi
AS_CASE([${RPATHFLAG}],[*'%1$'*],[: ${LIBPATHFLAG=' -L%1$-s'}],[: ${LIBPATHFLAG=' -L%s'}])

AC_SUBST(LINK_SO)
AC_SUBST(LIBPATHFLAG)
AC_SUBST(RPATHFLAG)
AC_SUBST(LIBPATHENV, "${LIBPATHENV-LD_LIBRARY_PATH}")
AC_SUBST(TRY_LINK)

if test "x$OPT_DIR" != x; then
    pat=`echo "${LDFLAGS_OPTDIR}" | sed ['s/[][\\.*|]/\\\\&/']`
    LDFLAGS=`echo "${LDFLAGS}" | sed "s| ${pat}||"`
    val=`IFS="$PATH_SEPARATOR"
        for dir in $OPT_DIR; do
            echo x ${LIBPATHFLAG} ${RPATHFLAG} |
            sed "s/^x *//;s${IFS}"'%1\\$-s'"${IFS}${dir}/lib${IFS}g;s${IFS}%s${IFS}${dir}/lib${IFS}g"
        done | tr '\012' ' '`
    test x"${LDFLAGS}" = x || LDFLAGS="$LDFLAGS "
    LDFLAGS="$LDFLAGS$val"
    test x"${DLDFLAGS}" = x || DLDFLAGS="$DLDFLAGS "
    DLDFLAGS="$DLDFLAGS$val"
    LDFLAGS_OPTDIR="$val"
fi

AS_CASE(["$target_os"],
[freebsd*], [
    AC_CHECK_LIB([procstat], [procstat_open_sysctl])
    ])
AS_CASE(["$target_cpu-$target_os"],
[*-darwin*], [
    AC_CHECK_HEADERS([execinfo.h])
    if test "x$ac_cv_header_execinfo_h" = xyes; then
AC_CHECK_LIB([execinfo], [backtrace])
    fi],
[*-freebsd*|x86_64-netbsd*], [
    AC_CHECK_HEADERS([execinfo.h])
    if test "x$ac_cv_header_execinfo_h" = xyes; then
AC_CHECK_LIB([execinfo], [backtrace])
AC_CHECK_LIB([unwind], [unw_backtrace])
    fi])
AC_CHECK_FUNCS(backtrace)

if test "x$ac_cv_func_backtrace" = xyes; then
  AC_CACHE_CHECK(for broken backtrace, rb_cv_broken_backtrace,
    [AC_TRY_RUN([
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <execinfo.h>

#define TRACE_SIZE 256

void sigsegv(int signum, siginfo_t *info, void *ctx){
    void *trace[TRACE_SIZE];
    int n = backtrace(trace, TRACE_SIZE);
    if (n > 0) {
/*fprintf(stdout, "backtrace:%d\n",n);*/
    } else {
abort();
    }
    _exit(0);
}
int
main()
{
    stack_t ss;
    ss.ss_sp = malloc(SIGSTKSZ);
    if (ss.ss_sp == NULL) {
fprintf(stderr, "cannot allocate memory for sigaltstack\n");
abort();
    }
    ss.ss_size = SIGSTKSZ;
    ss.ss_flags = 0;
    if (sigaltstack(&ss, NULL) == -1) {
fprintf(stderr, "sigaltstack failed\n");
abort();
    }
    struct sigaction sa;
    memset(&sa, 0, sizeof(struct sigaction));
    sigemptyset(&sa.sa_mask);
    sa.sa_sigaction = sigsegv;
    sa.sa_flags |= SA_SIGINFO;
    sa.sa_flags |= SA_ONSTACK;
    sigaction(SIGSEGV, &sa, NULL);
    int *a = NULL;
    a[0] = 1;
    return 0;
}
],
rb_cv_broken_backtrace=no,
rb_cv_broken_backtrace=yes,
rb_cv_broken_backtrace=no)])
  if test "$rb_cv_broken_backtrace" = yes; then
    AC_DEFINE(BROKEN_BACKTRACE, 1)
  fi
fi

AC_ARG_WITH(valgrind,
        AS_HELP_STRING([--without-valgrind],[disable valgrind memcheck support]),
        [], with_valgrind=yes)
AS_IF([test x$with_valgrind != xno],
        [AC_CHECK_HEADERS(valgrind/memcheck.h)])

dln_a_out_works=no
if test "$ac_cv_header_a_out_h" = yes; then
  if test "$with_dln_a_out" = yes || test "$rb_cv_dlopen" = unknown; then
    cat confdefs.h > config.h
    AC_CACHE_CHECK(whether matz's dln works, rb_cv_dln_a_out,
    [AC_TRY_COMPILE([
#define USE_DLN_A_OUT
#include "dln.c"
],
[],
rb_cv_dln_a_out=yes,
rb_cv_dln_a_out=no)])
    if test "$rb_cv_dln_a_out" = yes; then
      dln_a_out_works=yes
      AC_DEFINE(USE_DLN_A_OUT)
    fi
  fi
fi

if test "$dln_a_out_works" = yes; then
  if test "$GCC" = yes; then
    STATIC=-static
  else
    STATIC=-Bstatic
  fi
  DLEXT=so
  CCDLFLAGS=
else
  AS_CASE(["$target_os"],
    [hpux*], [
DLEXT=sl],
    [darwin*], [
RUBY_APPEND_OPTION(XLDFLAGS, [-Wl,-u,_objc_msgSend])
DLEXT=bundle],
    [os2-emx*], [
LOAD_RELATIVE=1
DLEXT=dll],
    [cygwin*|mingw*|*djgpp*], [
LOAD_RELATIVE=1
DLEXT=so],
    [
DLEXT=so])
fi
if test "$rb_cv_dlopen:$load_relative" = yes:yes; then
    if test "$ac_cv_func_dladdr" = yes; then
LOAD_RELATIVE=1
    fi
fi
if test x"$LOAD_RELATIVE" = x1; then
    load_relative=yes
else
    unset load_relative
fi

len=2 # .rb
n=`expr "$DLEXT" : '.*'`; test "$n" -gt "$len" && len=$n
n=`expr "$DLEXT2" : '.*'`; test "$n" -gt "$len" && len=$n
AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
test ".$DLEXT" = "." || AC_DEFINE_UNQUOTED(DLEXT, ".$DLEXT")
test ".$DLEXT2" = "." || AC_DEFINE_UNQUOTED(DLEXT2, ".$DLEXT2")
AC_SUBST(DLEXT)

if test "$with_dln_a_out" = yes; then
  STRIP=true
else
  AC_CHECK_TOOL(STRIP, strip, :)dnl
fi

AS_CASE(["$target_os"],
  [linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu], [
STRIP="$STRIP -S -x"],
  [darwin*], [
STRIP="$STRIP -A -n"])

AC_ARG_WITH(ext,
            AC_HELP_STRING([--with-ext=EXTS],
                           [pass to --with-ext option of extmk.rb]))
AC_ARG_WITH(out-ext,
            AC_HELP_STRING([--with-out-ext=EXTS],
                           [pass to --without-ext option of extmk.rb]))
EXTSTATIC=
AC_SUBST(EXTSTATIC)dnl
AC_ARG_WITH(static-linked-ext,
AS_HELP_STRING([--with-static-linked-ext], [link external modules statically]),
            [AS_CASE([$withval],[yes],[STATIC=;EXTSTATIC=static])])
if test x"$EXTSTATIC" = xstatic; then
  ENCOBJS='enc/encinit.$(OBJEXT) enc/libenc.$(LIBEXT) enc/libtrans.$(LIBEXT)'
  EXTOBJS='ext/extinit.$(OBJEXT)'
  AC_DEFINE_UNQUOTED(EXTSTATIC, 1)
fi
AC_SUBST(ENCOBJS)
AC_SUBST(EXTOBJS)

if test -f "$srcdir/ext/Setup.$target_os"; then
    setup="Setup.$target_os"
else
    setup=
    for file in "$srcdir"/ext/Setup.*; do
AS_CASE(["$file"], [*~|*.bak|*.orig|*.rej|*.tmp], [continue])
setup=`basename "$file"`
AS_CASE(["$target_os"], [`expr "$setup" : 'Setup.\(.*\)'`*], [break])
platform=`sed '/^option *platform */!d;s///;s/|/*|/g;q' "$file"`
if test "x$platform" != x; then
eval "AS_CASE([\"\$target_os\"], [$platform*], [break])"
fi
setup=
    done
    : ${setup:=Setup}
fi
AC_SUBST(setup)

rubylibprefix='${libdir}/${RUBY_BASE_NAME}'
AC_ARG_WITH(rubylibprefix,
AS_HELP_STRING([--with-rubylibprefix=DIR], [prefix for ruby libraries [[LIBDIR/RUBY_BASE_NAME]]]),
[if test "x$withval" = xno; then
AC_MSG_ERROR([No ruby, No libprefix])
fi
rubylibprefix="$withval"])
AC_SUBST(rubylibprefix)

if test x"${exec_prefix}" != xNONE; then
    RUBY_EXEC_PREFIX="$exec_prefix"
elif test x"$prefix" != xNONE; then
    RUBY_EXEC_PREFIX="$prefix"
else
    RUBY_EXEC_PREFIX=$ac_default_prefix
fi
pat=`echo "${RUBY_EXEC_PREFIX}" | tr -c '\012' .`'\(.*\)'
for var in bindir libdir rubylibprefix; do
    eval val='"$'$var'"'
    AS_CASE(["$val"], ["${RUBY_EXEC_PREFIX}"*], [val='${exec_prefix}'"`expr \"$val\" : \"$pat\"`"])
    eval $var='"$val"'
done

BTESTRUBY='$(MINIRUBY)'
if test x"$cross_compiling" = xyes; then
  test x"$MINIRUBY" = x && MINIRUBY="${RUBY-$BASERUBY} -I`$CHDIR .; pwd` "-r'$(arch)-fake'
  XRUBY_LIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["libdir"]']`
  XRUBY_RUBYLIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["rubylibdir"]']`
  XRUBY_RUBYHDRDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["rubyhdrdir"]']`
  AC_SUBST(XRUBY_LIBDIR)
  AC_SUBST(XRUBY_RUBYLIBDIR)
  AC_SUBST(XRUBY_RUBYHDRDIR)
  PREP='$(arch)-fake.rb'
  RUNRUBY_COMMAND='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
  RUNRUBY='$(RUNRUBY_COMMAND)'
  XRUBY='$(MINIRUBY)'
  TEST_RUNNABLE=no
  CROSS_COMPILING=yes

  if test "$host_os" = "nacl"; then
      if test "$build_cpu" = "$host_cpu" || test "${nacl_cv_cpu_nick}" = "x86" -a "$host_cpu" = "i686"; then
          nacl_cv_sel_ldr='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb sel_ldr`'
          nacl_cv_irt_core='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb irt_core`'
          nacl_cv_runnable_ld='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb runnable_ld`'
          nacl_cv_host_lib='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb host_lib`'
          TEST_RUNNABLE=yes
          BTESTRUBY="${nacl_cv_sel_ldr} -a -B ${nacl_cv_irt_core} -w 1:3 -w 2:4"
          BTESTRUBY="$BTESTRUBY -- ${nacl_cv_runnable_ld} --library-path ${nacl_cv_host_lib}"
          BTESTRUBY="$BTESTRUBY `pwd`/"'miniruby$(EXEEXT) -I`cd $(srcdir)/lib; pwd` -I.'
          BTESTRUBY="$BTESTRUBY"' -I$(EXTOUT)/common 3>&1 4>&2 1>/dev/null 2>/dev/null '
      fi
  fi
else
  MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib -I.'
  MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common'
  PREP='miniruby$(EXEEXT)'
  RUNRUBY_COMMAND='$(MINIRUBY) $(srcdir)/tool/runruby.rb --extout=$(EXTOUT) $(RUNRUBYOPT)'
  RUNRUBY='$(RUNRUBY_COMMAND) --'
  XRUBY='$(RUNRUBY)'
  TEST_RUNNABLE=yes
  CROSS_COMPILING=no
fi
AC_SUBST(TEST_RUNNABLE)
AC_SUBST(CROSS_COMPILING)
AC_SUBST(MINIRUBY)
AC_SUBST(BTESTRUBY)
AC_SUBST(PREP)
AC_SUBST(RUNRUBY_COMMAND)
AC_SUBST(RUNRUBY)
AC_SUBST(XRUBY)
AC_SUBST(EXTOUT, [${EXTOUT=.ext}])

FIRSTMAKEFILE=""
LIBRUBY_A='lib$(RUBY_SO_NAME)-static.a'
LIBRUBY='$(LIBRUBY_A)'
LIBRUBYARG_STATIC='-l$(RUBY_SO_NAME)-static'
LIBRUBYARG='$(LIBRUBYARG_STATIC)'
SOLIBS=

AS_CASE(["$target_os"],
  [cygwin*|mingw*|beos*|haiku*|darwin*|os2-emx*], [
    : ${DLDLIBS=""}
    ],
  [
    DLDLIBS="$DLDLIBS -lc"
    ])

AC_ARG_ENABLE(multiarch,
AS_HELP_STRING([--enable-multiarch], [enable multiarch compatible directories]),
[multiarch=], [unset multiarch])
if test ${multiarch+set}; then
   AC_DEFINE(ENABLE_MULTIARCH)
fi

archlibdir='${libdir}/${arch}'
sitearchlibdir='${libdir}/${sitearch}'
archincludedir='${includedir}/${arch}'
sitearchincludedir='${includedir}/${sitearch}'

AC_ARG_WITH(soname,
AS_HELP_STRING([--with-soname=SONAME], [base name of shared library]),
[RUBY_SO_NAME=$withval], [RUBY_SO_NAME='$(RUBY_BASE_NAME)'])

LIBRUBY_LDSHARED=$LDSHARED
LIBRUBY_DLDFLAGS=$DLDFLAGS
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so'
ENABLE_SHARED=no

AC_ARG_ENABLE(shared,
       AS_HELP_STRING([--enable-shared], [build a shared library for Ruby]),
       [enable_shared=$enableval])
libprefix=${multiarch+'$(archlibdir)'}${multiarch-'$(libdir)'}
LIBRUBY_RELATIVE=${load_relative-no}
AS_CASE("$enable_shared", [yes], [
  LIBRUBY='$(LIBRUBY_SO)'
  LIBRUBYARG_SHARED='-l$(RUBY_SO_NAME)'
  LIBRUBYARG='$(LIBRUBYARG_SHARED)'
  LIBRUBY_RELATIVE=no
  test -z "$CCDLFLAGS" || CFLAGS="$CFLAGS $CCDLFLAGS"
  ENABLE_SHARED=yes
  if test "$rb_cv_binary_elf" = yes; then
    SOLIBS='$(LIBS)'
  fi

  # libdir can be overridden in config.site file (on OpenSUSE at least).
  libdir_basename=lib
  if test "$bindir" = '${exec_prefix}/bin'; then
    AS_CASE(["$libdir"], ['${exec_prefix}/'*], [libdir_basename=`basename "$libdir"`])
  fi
  AC_DEFINE_UNQUOTED(LIBDIR_BASENAME, ["${libdir_basename}"])
  libdir_basename="${libdir_basename}"${multiarch+'/${arch}'}

  AS_CASE(["$target_os"],
    [freebsd*|dragonfly*], [],
    [
     if test "$GCC" = yes; then
       RUBY_TRY_LDFLAGS([${linker_flag}--no-undefined], [no_undefined=yes], [no_undefined=no])
       if test "no_undefined" = yes; then
RUBY_APPEND_OPTION(EXTLDFLAGS, [${linker_flag}--no-undefined])
       fi
     fi
    ])

  AS_CASE(["$target_os"],
    [sunos4*], [
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).so'
],
    [linux* | gnu* | k*bsd*-gnu | atheos* | kopensolaris*-gnu], [
LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR)'" $LDFLAGS_OPTDIR"
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).so'
if test "$load_relative" = yes; then
libprefix="'\$\${ORIGIN}/../${libdir_basename}'"
LIBRUBY_RPATHFLAGS="-Wl,-rpath,${libprefix}"
LIBRUBY_RELATIVE=yes
fi
],
    [freebsd*|dragonfly*], [
SOLIBS='$(LIBS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR)'
if test "$rb_cv_binary_elf" != "yes" ; then
LIBRUBY_SO="$LIBRUBY_SO.\$(TEENY)"
LIBRUBY_ALIASES=''
fi
],
    [netbsd*], [
SOLIBS='$(LIBS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR).$(TEENY)'
LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR)'" $LDFLAGS_OPTDIR"
if test "$rb_cv_binary_elf" = yes; then # ELF platforms
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR) lib$(RUBY_SO_NAME).so'
else # a.out platforms
LIBRUBY_ALIASES=""
fi
],
    [openbsd*|mirbsd*], [
SOLIBS='$(LIBS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR).'`expr ${MINOR} \* 10 + ${TEENY}`
],
    [solaris*], [
SOLIBS='$(LIBS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)'
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY) lib$(RUBY_SO_NAME).so'
if test "$GCC" = yes; then
LIBRUBY_DLDFLAGS="$DLDFLAGS "'-Wl,-h,$(@F)'
else
LIBRUBY_DLDFLAGS="$DLDFLAGS "'-h $(@F)'
fi
XLDFLAGS="$XLDFLAGS "'-R${libdir}'
],
    [hpux*], [
XLDFLAGS="$XLDFLAGS "'-Wl,+s,+b,$(libdir)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).sl'
],
    [aix*], [
LIBRUBY_DLDFLAGS="${linker_flag}-bnoentry $XLDFLAGS $LDFLAGS_OPTDIR"
LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
SOLIBS='-lm -lc'
],
    [beos*], [
AS_CASE(["$target_cpu"],
[powerpc*], [
LIBRUBY_DLDFLAGS="-f ruby.exp -lnet -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o $LDFLAGS_OPTDIR"
])
],
    [darwin*], [
RUBY_SO_NAME="$RUBY_SO_NAME"'.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_LDSHARED='$(CC) -dynamiclib'
if test "$load_relative" = yes; then
libprefix="@executable_path/../${libdir_basename}"
LIBRUBY_RELATIVE=yes
fi
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-install_name '${libprefix}'/$(LIBRUBY_SO)'
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-current_version $(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-compatibility_version $(ruby_version)'
if test "$visibility_option" = ld; then
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-Wl,-unexported_symbol,_Init_*'
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "'-Wl,-unexported_symbol,*_threadptr_*'
fi
LIBRUBY_DLDFLAGS="$LIBRUBY_DLDFLAGS "' $(XLDFLAGS)'
LIBRUBY_SO='lib$(RUBY_SO_NAME).dylib'
LIBRUBY_ALIASES='lib$(RUBY_BASE_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
SOLIBS='$(LIBS)'
],
    [interix*], [
LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
],
    [mingw*|cygwin*|mswin*], [
LIBRUBY_RELATIVE=yes
])
], [
  LIBRUBYARG_SHARED=

  # enable PIE if possible
  AC_ARG_ENABLE(pie,
          AS_HELP_STRING([--disable-pie], [disable PIE feature]),
          [pie=$enableval], [pie=])
  AS_CASE(["$target_os"],
  [haiku], [
    # gcc supports PIE, but doesn't work correctly in Haiku
    pie=no
  ],
  [nacl], [
    # -pie implies -shared for NaCl.
    pie=no
  ])
  if test "$GCC" = yes -a -z "$EXTSTATIC" -a "x$pie" != xno; then
    RUBY_TRY_CFLAGS(-fPIE, [pie=yes], [pie=no])
    if test "$pie" = yes; then
      # Use -fPIE when testing -pie. RUBY_TRY_LDFLAGS sets
      # $save_CFLAGS internally, so set other name here.
      save_CFLAGS_before_pie="$CFLAGS"
      CFLAGS="$CFLAGS -fPIE"

      # gcc need -pie but clang need -Wl,-pie.
      for pie in -pie -Wl,-pie; do
RUBY_TRY_LDFLAGS([$pie], [], [pie=])
if test "x$pie" != x; then
RUBY_APPEND_OPTION(XCFLAGS, -fPIE)
RUBY_APPEND_OPTION(XLDFLAGS, $pie)
break
fi
      done
      CFLAGS="$save_CFLAGS_before_pie"
    fi
  fi
])
if test "$enable_rpath" = yes; then
    test -z "$LIBRUBY_RPATHFLAGS" || LIBRUBY_RPATHFLAGS="$LIBRUBY_RPATHFLAGS "
    rpathflag="${RPATHFLAG}"
    AS_CASE(["${cross_compiling}${load_relative}"], [*yes*], [], [rpathflag="$RPATHFLAG$LIBPATHFLAG"])
    rpathflag=`IFS="$PATH_SEPARATOR"
        echo x "$rpathflag" |
        sed "s/^x *//;s${IFS}"'%1\\$-s'"${IFS}${libprefix}${IFS}g;s${IFS}%s${IFS}${libprefix}${IFS}g"
    `
    LIBRUBY_RPATHFLAGS="$LIBRUBY_RPATHFLAGS${rpathflag}"
    LIBRUBYARG_SHARED="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_SHARED"
    LIBRUBYARG_STATIC="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_STATIC"
fi
AC_SUBST(LIBRUBY_RELATIVE)

LDFLAGS="-L. $LDFLAGS"
AC_SUBST(ARCHFILE)

if test "$EXEEXT" = .exe; then
    EXECUTABLE_EXTS='".exe",".com",".cmd",".bat"'
    AC_DEFINE_UNQUOTED(EXECUTABLE_EXTS, $EXECUTABLE_EXTS)
    EXECUTABLE_EXTS=`echo $EXECUTABLE_EXTS | tr -d '"' | tr , ' '`
    AC_SUBST(EXECUTABLE_EXTS)
fi

AC_ARG_ENABLE(dtrace,
        AS_HELP_STRING([--enable-dtrace],
        [enable DTrace for tracing inside ruby. enabled by default on systems having dtrace]),
        [enable_dtrace=$enableval], [enable_dtrace=auto])

if test "${enable_dtrace}" = "auto"; then
    if test x"$DTRACE" != x -a x"$cross_compiling" != xyes; then
        RUBY_DTRACE_AVAILABLE()
        enable_dtrace=$rb_cv_dtrace_available
    else
        enable_dtrace=no
    fi
fi

LIBRUBY_A_OBJS='$(OBJS)'
if test "${enable_dtrace}" = "yes"; then
    if test -z "$DTRACE"; then
        AC_MSG_ERROR([dtrace(1) is missing])
    elif test "$cross_compiling" = yes; then
        AC_MSG_ERROR([--enable-dtrace, however, cross compiling])
    else
        RUBY_DTRACE_AVAILABLE()
        enable_dtrace=$rb_cv_dtrace_available
        if test "${enable_dtrace}" = "no"; then
            AC_MSG_ERROR([--enable-dtrace, however, USDT is not available])
        fi
        RUBY_DTRACE_POSTPROCESS()
        if test "$rb_cv_prog_dtrace_g" = 'yes'; then
            DTRACE_OBJ='probes.$(OBJEXT)'
            DTRACE_GLOMMED_OBJ='ruby-glommed.$(OBJEXT)'
            LIBRUBY_A_OBJS='$(DTRACE_GLOMMED_OBJ)'
        fi
        AS_CASE("${target_os}", [freebsd*], [
            # FreeBSD's dtrace requires libelf
            LIBS="-lelf $LIBS"
        ])
    fi
    DTRACE_EXT=d
else
    DTRACE_EXT=dmyh
fi
AC_SUBST(DTRACE_EXT)
AC_SUBST(DTRACE_OBJ)
AC_SUBST(DTRACE_GLOMMED_OBJ)
AC_SUBST(LIBRUBY_A_OBJS)

}
{ # build section

dnl build rdoc index if requested
RDOCTARGET=""
CAPITARGET=""
AC_ARG_ENABLE(install-doc,
       AS_HELP_STRING([--disable-install-doc], [do not install neither rdoc indexes nor C API documents during install]),
       [install_doc=$enableval], [install_doc=yes])
AC_ARG_ENABLE(install-rdoc,
      AS_HELP_STRING([--disable-install-rdoc], [do not install rdoc indexes during install]),
      [install_rdoc=$enableval], [install_rdoc=yes])
AC_ARG_ENABLE(install-capi,
      AS_HELP_STRING([--disable-install-capi], [do not install C API documents during install]),
      [install_capi=$enableval], [install_capi=yes])

if test "$install_doc" != no; then
    if test "$install_rdoc" != no; then
RDOCTARGET="rdoc"
    else
RDOCTARGET="nodoc"
    fi
    if test "$install_capi" != no -a -n "$DOXYGEN"; then
CAPITARGET="capi"
    else
CAPITARGET="nodoc"
    fi
else
    RDOCTARGET="nodoc"
    CAPITARGET="nodoc"
fi

AC_SUBST(RDOCTARGET)
AC_SUBST(CAPITARGET)

AS_CASE(["$RDOCTARGET:$CAPITARGET"],[nodoc:nodoc],[INSTALLDOC=nodoc],[INSTALLDOC=all])
AC_SUBST(INSTALLDOC)

if test "$rb_with_pthread" = "yes"; then
    THREAD_MODEL=pthread
fi
AC_CACHE_CHECK([for prefix of external symbols], rb_cv_symbol_prefix, [
    AC_TRY_COMPILE([extern void conftest_external(void) {}], [], [
rb_cv_symbol_prefix=`$NM conftest.$ac_objext |
sed -n ['/.*T[ ]\([^ ]*\)conftest_external.*/!d;s//\1/p;q']`
],
[rb_cv_symbol_prefix=''])
    test -n "$rb_cv_symbol_prefix" || rb_cv_symbol_prefix=NONE
])
SYMBOL_PREFIX="$rb_cv_symbol_prefix"
test "x$SYMBOL_PREFIX" = xNONE && SYMBOL_PREFIX=''
DLNOBJ=dln.o
AC_ARG_ENABLE(dln,
AC_HELP_STRING([--disable-dln], [disable dynamic link feature]),
[test "$enableval" = yes || DLNOBJ=dmydln.o])
AC_SUBST(DLNOBJ)
MINIDLNOBJ=dmydln.o

AS_CASE(["$target_os"],
    [linux*], [
],
    [netbsd*], [
RUBY_APPEND_OPTION(CFLAGS, -pipe)
],
    [darwin*], [
RUBY_APPEND_OPTION(CFLAGS, -pipe)
RUBY_APPEND_OPTION(XLDFLAGS, [-framework CoreFoundation])
RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework CoreFoundation])
],
    [os2-emx], [
AC_LIBOBJ([os2])
CFLAGS="$CFLAGS -DOS2"
LIBRUBY_A=`echo $LIBRUBY_A | sed 's/^lib//'`
LIBRUBY_SO=`echo $LIBRUBY_SO | sed 's/^lib//'`
LIBRUBY_ALIASES=`for i in $LIBRUBY_ALIASES; do echo "$i"; done | sed 's/^lib//'`
],
    [osf*], [
if test "$GCC" != "yes" ; then
# compile something small: taint.c is fine for this.
# the main point is the '-v' flag of 'cc'.
AS_CASE(["`cc -v -I. -c main.c -o /tmp/main.o 2>&1`"],
[*/gemc_cc*], [ # we have the new DEC GEM CC
                        CFLAGS="$CFLAGS -oldc"
                        ],
          [ # we have the old MIPS CC
                        ])
# cleanup
rm -f /tmp/main.o
CFLAGS="$CFLAGS -std"
fi
],
    [beos*], [
AS_CASE(["$target_cpu"],[powerpc*], [CFLAGS="$CFLAGS -relax_pointers"])
CPPFLAGS="$CPPFLAGS -I/boot/home/config/include"
],
    [cygwin*|mingw*], [
RUBY_SO_NAME="${RUBY_SO_NAME}"'$(MAJOR)$(MINOR)$(TEENY)'
LIBRUBY_DLDFLAGS="${DLDFLAGS}"' -Wl,--out-implib=$(LIBRUBY)'
AS_CASE(["$target_os"],
[cygwin*], [
if test x"$enable_shared" = xyes; then
LIBRUBY_SO='cyg$(RUBY_SO_NAME)'.dll
LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' $(RUBYDEF)'
fi
],
[mingw*], [
RUBY_SO_NAME="${rb_cv_msvcrt}-${RUBY_SO_NAME}"
if test x"${target_cpu}" != xi386; then
RUBY_SO_NAME="${target_cpu}-${RUBY_SO_NAME}"
fi
if test x"$enable_shared" = xyes; then
LIBRUBY_SO='$(RUBY_SO_NAME)'.dll
LIBRUBY_DLDFLAGS="${LIBRUBY_DLDFLAGS}"' $(RUBYDEF)'
fi
EXPORT_PREFIX=' '
DLDFLAGS="${DLDFLAGS}"' $(DEFFILE)'
AC_LIBOBJ([win32/win32])
AC_LIBOBJ([win32/file])
COMMON_LIBS=m
# COMMON_MACROS="WIN32_LEAN_AND_MEAN="
COMMON_HEADERS="winsock2.h windows.h"
THREAD_MODEL=win32
PLATFORM_DIR=win32
])
LIBRUBY_ALIASES=''
FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
SOLIBS='$(LIBS)'
if test x"$enable_shared" = xyes; then
LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
else
LIBRUBY_SO=dummy
LIBRUBY='lib$(RUBY_SO_NAME).a'
LIBRUBYARG='-l$(RUBY_SO_NAME)'
fi
],
    [hpux*], [
AS_CASE(["$YACC"],[*yacc*], [
XCFLAGS="$XCFLAGS -DYYMAXDEPTH=300"
YACC="$YACC -Nl40000 -Nm40000"
])],
    [nacl], [
FIRSTMAKEFILE=GNUmakefile:nacl/GNUmakefile.in
])

AS_CASE(["$with_gmp: $SOLIBS "], [no:* | *' -lgmp '*|*' $(LIBS) '*], [],
[SOLIBS="-lgmp $SOLIBS"])

MINIOBJS="$MINIDLNOBJ"

AS_CASE(["$THREAD_MODEL"],
[pthread], [AC_CHECK_HEADERS(pthread.h)],
[win32], [],
[""], [AC_MSG_ERROR(thread model is missing)],
           [AC_MSG_ERROR(unknown thread model $THREAD_MODEL)])

AC_ARG_ENABLE(debug-env,
       AS_HELP_STRING([--enable-debug-env], [enable RUBY_DEBUG environment variable]),
       [AC_DEFINE(RUBY_DEBUG_ENV)])

AS_CASE(["$FIRSTMAKEFILE"], [*GNUmakefile:*], [gnumake=yes], [
    AC_MSG_CHECKING([if ${MAKE-make} is GNU make])
    mkdir conftest.dir
    echo "all:; @echo yes" > conftest.dir/GNUmakefile
    echo "all:; @echo no" > conftest.dir/Makefile
    gnumake=`(cd conftest.dir; ${MAKE-make})`
    rm -fr conftest.dir
    AS_CASE(["$gnumake"],
    [*yes*], [
FIRSTMAKEFILE=GNUmakefile:template/GNUmakefile.in
gnumake=yes],
    [
gnumake=no])
    AC_MSG_RESULT($gnumake)
])
AS_IF([test "$gnumake" = yes], [ NULLCMD=: ], [
    AC_MSG_CHECKING([for safe null command for ${MAKE-make}])
    mkdir conftest.dir
    NULLCMD=
    for cmd in : true; do
echo 'A=1' > conftest.dir/Makefile
echo 'B=$(A:1=@'$cmd')' >> conftest.dir/Makefile
echo 'all:; $B 1 2 3 4 5 6 7 8 9' >> conftest.dir/Makefile
if (cd conftest.dir; ${MAKE-make} >/dev/null 2>/dev/null); then
NULLCMD=$cmd
break
fi
    done
    rm -fr conftest.dir
    if test -z "$NULLCMD"; then
AC_MSG_ERROR(no candidate for safe null command)
    fi
    AC_MSG_RESULT($NULLCMD)
])
AC_SUBST(NULLCMD)

if test "${universal_binary-no}" = yes ; then
    AC_CACHE_CHECK([for architecture macros], rb_cv_architecture_macros, [
    mv confdefs.h confdefs1.h
    : > confdefs.h
    AC_TRY_COMPILE([@%:@if defined __`echo ${universal_archnames} |
    sed 's/=[^ ]*//g;s/ /__ || defined __/g'`__
@%:@else
@%:@error
>>>>>><<<<<<
@%:@endif], [],
[
    rb_cv_architecture_macros=yes
    mv -f confdefs1.h confdefs.h
], [
    rb_cv_architecture_macros=no
    archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
    new_cflags=`echo "$CFLAGS" | sed "s|$archflagpat"'||'`
    for archs in ${universal_archnames}; do
cpu=${archs@%:@*=}
archs=${archs%=*}
CFLAGS="$new_cflags -arch $archs"
archs="__${archs}__"
AC_MSG_CHECKING([for macro ${archs} on ${cpu}])
AC_TRY_COMPILE([@%:@ifndef ${archs}
@%:@error
@%:@endif], [], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
    done
    mv -f confdefs1.h confdefs.h
    AC_MSG_ERROR([failed])
    ])])
    AC_CACHE_CHECK(whether __ARCHITECTURE__ is available, rb_cv_architecture_available,
AC_TRY_COMPILE([@%:@include <stdio.h>
const char arch[[]] = __ARCHITECTURE__;], [puts(arch);],
[rb_cv_architecture_available=yes], [rb_cv_architecture_available=no]))
fi

if test "$ac_cv_func_memmem" = yes; then
  AC_CACHE_CHECK(for broken memmem, rb_cv_broken_memmem, [
    AC_TRY_RUN([
#include <string.h>

int
main()
{
  char *str = "hogefugafoobar";
  char *rs = "foo";
  char *empty = "";
  char *p;

  p = memmem(str, strlen(str), rs, strlen(rs));
  if (p == str+8) {
    p = memmem(str, strlen(str), empty, strlen(empty));
    if (p == str)
      return 0;
    else
      return 1;
  }
  else {
    return 1;
  }
}
    ],
    rb_cv_broken_memmem=no,
    rb_cv_broken_memmem=yes,
    rb_cv_broken_memmem=yes)
  ])
  test x"$rb_cv_broken_memmem" = xyes && ac_cv_func_memmem=no
fi


CPPFLAGS="$CPPFLAGS "'$(DEFS)'
test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
if test -n "${cflags+set}"; then
    cflagspat=`eval echo '"'"${cflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/^ *$/ /'`
    CFLAGS=`echo " $CFLAGS " | sed "s|$cflagspat"'|${cflags}|;s/^ *//;s/ *$//'`
fi
if test -n "${cxxflags+set}"; then
    cxxflagspat=`eval echo '"'"${cxxflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^ */ /;s/^ *$/ /'`
    CXXFLAGS=`echo " $CXXFLAGS " | sed "s|$cxxflagspat"'|${cxxflags}|;s/^ *//;s/ *$//'`
fi
if test "${ARCH_FLAG}"; then
    archflagpat=`eval echo '"'"${ARCH_FLAG}"'"' | sed 's/[[][|.*]]/\\&/g'`
    CFLAGS=`echo "$CFLAGS" | sed "s| *$archflagpat"'||'`
    CXXFLAGS=`echo "$CXXFLAGS" | sed "s| *$archflagpat"'||'`
    LDFLAGS=`echo "$LDFLAGS" | sed "s| *$archflagpat"'||'`
fi
warnflags="$rb_cv_warnflags"
AC_SUBST(cppflags)dnl
AC_SUBST(cflags, ["$orig_cflags "'${optflags} ${debugflags} ${warnflags}'])dnl
AC_SUBST(cxxflags, ["$orig_cxxflags "'${optflags} ${debugflags} ${warnflags}'])dnl
AC_SUBST(optflags)dnl
AC_SUBST(debugflags)dnl
AC_SUBST(warnflags)dnl
AC_SUBST(strict_warnflags)dnl
AC_SUBST(XCFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl
AC_SUBST(EXTLDFLAGS)dnl
AC_SUBST(EXTDLDFLAGS)dnl
AC_SUBST(LIBRUBY_LDSHARED)
AC_SUBST(LIBRUBY_DLDFLAGS)
AC_SUBST(RUBY_INSTALL_NAME)
AC_SUBST(rubyw_install_name)
AC_SUBST(RUBYW_INSTALL_NAME)
AC_SUBST(RUBY_SO_NAME)
AC_SUBST(LIBRUBY_A)
AC_SUBST(LIBRUBY_SO)
AC_SUBST(LIBRUBY_ALIASES)
AC_SUBST(LIBRUBY)
AC_SUBST(LIBRUBYARG)
AC_SUBST(LIBRUBYARG_STATIC)
AC_SUBST(LIBRUBYARG_SHARED)
AC_SUBST(SOLIBS)
AC_SUBST(DLDLIBS)
AC_SUBST(ENABLE_SHARED)
AC_SUBST(MAINLIBS)
AC_SUBST(COMMON_LIBS)
AC_SUBST(COMMON_MACROS)
AC_SUBST(COMMON_HEADERS)
AC_SUBST(EXPORT_PREFIX)
AC_SUBST(SYMBOL_PREFIX)
AC_SUBST(MINIOBJS)
AC_SUBST(THREAD_MODEL)
AC_SUBST(PLATFORM_DIR)

firstmf=`echo $FIRSTMAKEFILE | sed 's/:.*//'`
firsttmpl=`echo $FIRSTMAKEFILE | sed 's/.*://'`
MAKEFILES="Makefile $firstmf"
MAKEFILES="`echo $MAKEFILES`"
AC_SUBST(MAKEFILES)

ri_prefix=
test "$program_prefix" != NONE &&
  ri_prefix=$program_prefix

ri_suffix=
test "$program_suffix" != NONE &&
  ri_suffix=$program_suffix

RUBY_INSTALL_NAME="${ri_prefix}"'$(RUBY_BASE_NAME)'"${ri_suffix}"
AS_CASE(["$target_os"],
  [cygwin*|mingw*], [
    RUBYW_INSTALL_NAME="${ri_prefix}"'$(RUBYW_BASE_NAME)'"${ri_suffix}"
    rubyw_install_name='$(RUBYW_INSTALL_NAME)'
    ])

rubylibdir='${rubylibprefix}/${ruby_version}'
rubyarchdir=${multiarch+'${rubyarchprefix}/${ruby_version}'}${multiarch-'${rubylibdir}/${arch}'}

rubyarchprefix=${multiarch+'${archlibdir}/${RUBY_BASE_NAME}'}${multiarch-'${rubylibprefix}/${arch}'}
AC_ARG_WITH(rubyarchprefix,
AS_HELP_STRING([--with-rubyarchprefix=DIR],
[prefix for architecture dependent ruby libraries [[RUBYLIBPREFIX/ARCH]]]),
[rubyarchprefix="$withval"])
AC_SUBST(rubyarchprefix)

rubysitearchprefix=${multiarch+'${sitearchlibdir}/${RUBY_BASE_NAME}'}${multiarch-'${rubylibprefix}/${sitearch}'}
AC_ARG_WITH(rubysitearchprefix,
AS_HELP_STRING([--with-rubysitearchprefix=DIR],
[prefix for architecture dependent site libraries [[RUBYLIBPREFIX/SITEARCH]]]),
[rubysitearchprefix="$withval"])
AC_SUBST(rubysitearchprefix)

RI_BASE_NAME=`echo ${RUBY_BASE_NAME} | sed 's/ruby/ri/'`
ridir='${datarootdir}/${RI_BASE_NAME}'
AC_ARG_WITH(ridir,
AS_HELP_STRING([--with-ridir=DIR], [ri documentation [[DATAROOTDIR/ri]]]),
[ridir=$withval])
AC_SUBST(ridir)
AC_SUBST(RI_BASE_NAME)

AC_ARG_WITH(ruby-version,
AS_HELP_STRING([--with-ruby-version=STR], [ruby version string for version specific directories [[full]] (full|minor|STR)]),
            [ruby_version=$withval],
            [ruby_version=full])
unset RUBY_LIB_VERSION
unset RUBY_LIB_VERSION_STYLE
AS_CASE(["$ruby_version"],
  [full], [RUBY_LIB_VERSION_STYLE='3 /* full */'],
  [minor], [RUBY_LIB_VERSION_STYLE='2 /* minor */'])
if test ${RUBY_LIB_VERSION_STYLE+set}; then
    {
    echo "#define RUBY_LIB_VERSION_STYLE $RUBY_LIB_VERSION_STYLE"
    echo '#define STRINGIZE(x) x'
    test -f revision.h -o -f "${srcdir}/revision.h" || echo '#define RUBY_REVISION 0'
    echo '#include "verconf.h"'
    echo '#include "version.h"'
    echo 'ruby_version=RUBY_LIB_VERSION'
    } > conftest.c
    test -f verconf.h || > verconf.h
    ruby_version="`$CPP -I. -I"${srcdir}" -I"${srcdir}/include" conftest.c | sed '/^ruby_version=/!d;s/ //g'`"
    eval $ruby_version
elif test -z "${ruby_version}"; then
    AC_MSG_ERROR([No ruby version, No place for bundled libraries])
else
    RUBY_LIB_VERSION="\"${ruby_version}\""
fi
AC_SUBST(RUBY_LIB_VERSION_STYLE)
AC_SUBST(RUBY_LIB_VERSION)

AC_ARG_WITH(sitedir,
AS_HELP_STRING([--with-sitedir=DIR], [site libraries in DIR [[RUBY_LIB_PREFIX/site_ruby]], "no" to disable site directory]),
            [sitedir=$withval],
            [sitedir='${rubylibprefix}/site_ruby'])
sitelibdir='${sitedir}/${ruby_version}'

AC_ARG_WITH(sitearchdir,
AS_HELP_STRING([--with-sitearchdir=DIR],
[architecture dependent site libraries in DIR [[SITEDIR/SITEARCH]], "no" to disable site directory]),
            [sitearchdir=$withval],
            [sitearchdir=${multiarch+'${rubysitearchprefix}/site_ruby/${ruby_version}'}${multiarch-'${sitelibdir}/${sitearch}'}])

AC_ARG_WITH(vendordir,
AS_HELP_STRING([--with-vendordir=DIR], [vendor libraries in DIR [[RUBY_LIB_PREFIX/vendor_ruby]], "no" to disable vendor directory]),
            [vendordir=$withval],
            [vendordir='${rubylibprefix}/vendor_ruby'])
vendorlibdir='${vendordir}/${ruby_version}'

AC_ARG_WITH(vendorarchdir,
AS_HELP_STRING([--with-vendorarchdir=DIR],
[architecture dependent vendor libraries in DIR [[VENDORDIR/SITEARCH]], "no" to disable vendor directory]),
            [vendorarchdir=$withval],
            [vendorarchdir=${multiarch+'${rubysitearchprefix}/vendor_ruby/${ruby_version}'}${multiarch-'${vendorlibdir}/${sitearch}'}])

if test "${LOAD_RELATIVE+set}"; then
    AC_DEFINE_UNQUOTED(LOAD_RELATIVE, $LOAD_RELATIVE)
    RUBY_EXEC_PREFIX=''
fi

AC_SUBST(RUBY_EXEC_PREFIX)

AC_SUBST(libdirname, ${multiarch+arch}libdir)
AC_SUBST(archlibdir)dnl
AC_SUBST(sitearchlibdir)dnl
AC_SUBST(archincludedir)dnl
AC_SUBST(sitearchincludedir)dnl
AC_SUBST(arch)dnl
AC_SUBST(sitearch)dnl
AC_SUBST(ruby_version)dnl
AC_SUBST(rubylibdir)dnl
AC_SUBST(rubyarchdir)dnl
AC_SUBST(sitedir)dnl
AC_SUBST(sitelibdir)dnl
AC_SUBST(sitearchdir)dnl
AC_SUBST(vendordir)dnl
AC_SUBST(vendorlibdir)dnl
AC_SUBST(vendorarchdir)dnl

AC_SUBST(configure_args, "`echo "${ac_configure_args}" | sed 's/\\$/$$/g'`")dnl

if test "${universal_binary-no}" = yes ; then
    arch="universal-${target_os}"
    if test "${rb_cv_architecture_available}" = yes; then
AC_DEFINE_UNQUOTED(RUBY_PLATFORM_CPU, __ARCHITECTURE__)
    else
for archs in ${universal_archnames}; do
cpu=`echo $archs | sed 's/.*=//'`
archs=`echo $archs | sed 's/=.*//'`
RUBY_DEFINE_IF([defined __${archs}__], RUBY_PLATFORM_CPU, ["${cpu}"])
done
    fi
    ints='long int short'
    test "$ac_cv_type_long_long" = yes && ints="'long long' $ints"
    AC_SUBST(UNIVERSAL_ARCHNAMES, "${universal_archnames}")
    AC_SUBST(UNIVERSAL_INTS, "${ints}")
    AC_DEFINE_UNQUOTED(RUBY_PLATFORM_OS, "${target_os}")
    AC_DEFINE_UNQUOTED(RUBY_ARCH, "universal-"RUBY_PLATFORM_OS)
    AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "universal."RUBY_PLATFORM_CPU"-"RUBY_PLATFORM_OS)
else
    arch="${target_cpu}-${target_os}"
    AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "${arch}")
fi

unset sitearch
AS_CASE(["$target_os"],[mingw*],[sitearch="$target_cpu-$rb_cv_msvcrt"])
: ${sitearch='${arch}'}

AC_ARG_WITH(search-path,
AS_HELP_STRING([--with-search-path=DIR], [specify the additional search path]),
[search_path=$withval])
if test "$search_path" != ""; then
    AC_SUBST(RUBY_SEARCH_PATH, $search_path)
fi

AC_ARG_WITH(rubyhdrdir,
AS_HELP_STRING([--with-rubyhdrdir=DIR], [core headers in DIR [[INCLUDEDIR/RUBY_BASE_NAME-RUBY_VERSION]]]),
[rubyhdrdir=$withval],
[rubyhdrdir='${includedir}/${RUBY_VERSION_NAME}'])

AC_ARG_WITH(rubyarchhdrdir,
AS_HELP_STRING([--with-rubyarchhdrdir=DIR],
[architecture dependent core headers in DIR [[$(rubyhdrdir)/$(arch)]]]),
[rubyarchhdrdir=$withval],
[rubyarchhdrdir=${multiarch+'${archincludedir}/${RUBY_VERSION_NAME}'}${multiarch-'${rubyhdrdir}/${arch}'}])

AC_ARG_WITH(sitehdrdir,
AS_HELP_STRING([--with-sitehdrdir=DIR], [core site headers in DIR [[RUBYHDRDIR/site_ruby]]]),
[sitehdrdir=$withval],
[sitehdrdir='${rubyhdrdir}/site_ruby'])

AC_ARG_WITH(sitearchhdrdir,
AS_HELP_STRING([--with-sitearchhdrdir=DIR],
[architecture dependent core site headers in DIR [[RUBYHDRDIR/site_ruby]]]),
[sitearchhdrdir=$withval],
[sitearchhdrdir=${multiarch+'${sitearchincludedir}/${RUBY_VERSION_NAME}/site_ruby'}${multiarch-'${sitehdrdir}/${sitearch}'}])

AC_ARG_WITH(vendorhdrdir,
AS_HELP_STRING([--with-vendorhdrdir=DIR], [core vendor headers in DIR [[RUBYHDRDIR/vendor_ruby]]]),
[vendorhdrdir=$withval],
[vendorhdrdir='${rubyhdrdir}/vendor_ruby'])

AC_ARG_WITH(vendorarchhdrdir,
AS_HELP_STRING([--with-vendorarchhdrdir=DIR],
[architecture dependent core vendor headers in DIR [[RUBYHDRDIR/vendor_ruby]]]),
[vendorarchhdrdir=$withval],
[vendorarchhdrdir=${multiarch+'${sitearchincludedir}/${RUBY_VERSION_NAME}/vendor_ruby'}${multiarch-'${vendorhdrdir}/${sitearch}'}])

AC_SUBST(rubyhdrdir)dnl
AC_SUBST(sitehdrdir)dnl
AC_SUBST(vendorhdrdir)dnl
AC_SUBST(rubyarchhdrdir)dnl
AC_SUBST(sitearchhdrdir)dnl
AC_SUBST(vendorarchhdrdir)dnl

AC_ARG_WITH(mantype,
AS_HELP_STRING([--with-mantype=TYPE], [specify man page type; TYPE is one of man and doc]),
[
AS_CASE(["$withval"],
[man|doc], [MANTYPE=$withval],
[AC_MSG_ERROR(invalid man type: $withval)])
])
if test -z "$MANTYPE"; then
AC_PATH_PROGS(NROFF, nroff awf, /bin/false, "/usr/bin:/usr/ucb")
if ${NROFF} -mdoc ${srcdir}/man/ruby.1 >/dev/null 2>&1; then
MANTYPE=doc
else
MANTYPE=man
fi
fi
AC_SUBST(MANTYPE)

AC_ARG_ENABLE(rubygems,
AS_HELP_STRING([--disable-rubygems], [disable rubygems by default]),
[enable_rubygems="$enableval"], [enable_rubygems=yes])
if test x"$enable_rubygems" = xno; then
    AC_DEFINE(DISABLE_RUBYGEMS, 1)
    USE_RUBYGEMS=NO
else
    USE_RUBYGEMS=YES
fi
AC_SUBST(USE_RUBYGEMS)

arch_hdrdir="${EXTOUT}/include/${arch}/ruby"
AS_MKDIR_P("${arch_hdrdir}")
config_h="${arch_hdrdir}/config.h"
guard=INCLUDE_RUBY_CONFIG_H
{
  echo "#ifndef $guard"
  echo "#define $guard 1"
  grep -v "^#define PACKAGE_" confdefs.h
  echo "#endif /* $guard */"
} | tr -d '\015' |
${srcdir}/tool/ifchange "${config_h}" -
tr -d '\015' < largefile.h > confdefs.h
rm largefile.h

BUILTIN_ENCS=["`sed -n -e '/^BUILTIN_ENCS[ ]*=/{' \
-e s/// -e :l -e '/\\\\$/N' -e 's/\\\\\\n/ /' -e 't l' -e p \
-e '}' "${srcdir}/enc/Makefile.in"`"]
BUILTIN_ENCOBJS=
for e in $BUILTIN_ENCS; do BUILTIN_ENCOBJS="$BUILTIN_ENCOBJS `basename $e .c`"'.$(OBJEXT)'; done
AC_SUBST(BUILTIN_ENCOBJS)

BUILTIN_TRANSES=["`sed -n -e '/^BUILTIN_TRANSES[ ]*=/{' \
-e s/// -e :l -e '/\\\\$/N' -e 's/\\\\\\n/ /' -e 't l' -e p \
-e '}' "${srcdir}/enc/Makefile.in"`"]
BUILTIN_TRANSSRCS=
BUILTIN_TRANSOBJS=
for e in $BUILTIN_TRANSES; do
  BUILTIN_TRANSSRCS="$BUILTIN_TRANSSRCS `basename $e .trans`"'.c';
  BUILTIN_TRANSOBJS="$BUILTIN_TRANSOBJS `basename $e .trans`"'.$(OBJEXT)';
done
AC_SUBST(BUILTIN_TRANSSRCS)
AC_SUBST(BUILTIN_TRANSOBJS)

PACKAGE=$RUBY_BASE_NAME
AC_SUBST(PACKAGE)
AC_MSG_RESULT($PACKAGE library version = $ruby_version)

AS_CASE([" $CPP "], [*" $CC "*], [CPP=`echo " $CPP " | sed "s| $CC |"' $(CC) |;s/^ *//;s/ *$//'`])

if test x"$firstmf" != x; then
    AC_CONFIG_FILES($firstmf:$firsttmpl, [], [firstmf="$firstmf" firsttmpl="$firsttmpl"])
fi
AC_CONFIG_FILES(Makefile, [
    tmpmk=confmk$$.tmp
    {
if test ${VCS+set}; then
:
elif svn info "$srcdir" > /dev/null 2>&1; then
VCS='svn'
elif test -d "$srcdir/.git/svn"; then
VCS='git svn'
elif test -d "$srcdir/.git"; then
VCS='git'
else
VCS='echo cannot'
fi
AS_CASE("$VCS",
[svn], [VCSUP='$(VCS) up $(SVNUPOPTIONS)'],
["git svn"], [VCSUP='$(VCS) rebase $(GITSVNREBASEOPTIONS)'],
[git], [VCSUP='$(VCS) pull $(GITPULLOPTIONS)'],
[VCSUP='$(VCS)'])
sed '/^MISSING/s/\$U\././g;/^VCS *=/s#@VCS@#'"$VCS"'#;/^VCSUP *=/s#@VCSUP@#'"$VCSUP"'#' Makefile
echo; test x"$EXEEXT" = x || echo 'miniruby: miniruby$(EXEEXT)'
if test "$gnumake" != yes; then
echo ['$(MKFILES): $(srcdir)/common.mk']
sed ['s/{\$([^(){}]*)[^{}]*}//g'] ${srcdir}/common.mk
else
echo 'distclean-local::; @$(RM) GNUmakefile uncommon.mk'
fi
    } > $tmpmk && if ! grep '^ruby:' $tmpmk > /dev/null; then
if test "${gnumake}" = yes; then
tmpgmk=confgmk$$.tmp
{
echo "include $tmpmk"
echo "-include uncommon.mk"
} > $tmpgmk
else
tmpgmk=$tmpmk
fi &&
test -z "`${MAKE-make} -f $tmpgmk info-program | grep '^PROGRAM=ruby$'`" &&
echo 'ruby: $(PROGRAM);' >> $tmpmk
test "$tmpmk" = "$tmpgmk" || rm -f "$tmpgmk"
    fi && mv -f $tmpmk Makefile],
[EXEEXT='$EXEEXT' gnumake='$gnumake'])

AC_ARG_WITH([ruby-pc],
AC_HELP_STRING([pc file basename]),
[ruby_pc="$withval"],
[ruby_pc="${RUBY_BASE_NAME}-${MAJOR}.${MINOR}.pc"])
AC_SUBST(ruby_pc)
AC_SUBST(exec, [exec])

AC_CONFIG_FILES($ruby_pc:template/ruby.pc.in,
    [
    if sed ['s/\$(\([A-Za-z_][A-Za-z0-9_]*\))/${\1}/g;s/@[A-Za-z_][A-Za-z0-9_]*@//'] $ruby_pc > ruby.tmp.pc &&
{
test -z "$PKG_CONFIG" ||
PKG_CONFIG_PATH=. $PKG_CONFIG --print-errors ruby.tmp
}
    then
mv -f ruby.tmp.pc $ruby_pc
    else
exit 1
    fi
    ],
    [ruby_pc='$ruby_pc' PKG_CONFIG='$PKG_CONFIG'])

AC_OUTPUT
}
}
Something went wrong with that request. Please try again.