~ubuntu-branches/ubuntu/vivid/mpich/vivid-proposed

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
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
AC_PREREQ(2.63)
# 
# (C) 2006 by Argonne National Laboratory.
#     See COPYRIGHT in top-level directory.
#
dnl Process this file with autoconf to produce a configure script.
dnl
dnl aclocal_cache.m4, included by sowing/confdb/aclocal.m4, fixes 
dnl bugs in autoconf caching.
dnl
dnl This is a large configure script and it is important to keep it
dnl clearly organized.  In addition, this script must coordinate with 
dnl the other modules that can be used to construct MPICH, such as
dnl the communication device and the process manager.  Each of these
dnl may have special features or limitations that other modules or
dnl this configure may need to take into account.  To handle this, there
dnl are xx major steps in this configure script:
dnl
dnl 1. Identify major modules and source any prerequisite scripts
dnl 2. Determine compiler characteristics 
dnl 3. Setup and configure the other modules
dnl 4. Determine MPI features and characteristics (such as datatype values)
dnl
dnl Each of these is described in more detail below.
dnl
dnl 1. Identify the modules (most are specified by 
dnl --with-<modulename>=instance,
dnl for example, --with-pm=mpd or --with-device=ch3:nemesis).
dnl For each module, source the file mpichprereq if present (in the
dnl module's top-level directory).  This
dnl must be a bourne (sh) shell script; it can access any of the variables
dnl in the configure script.  In addition, there are a few variables that
dnl are defined and provided to allow the modules to communicate their 
dnl needs or limitations to the other modules.  These are:
dnl    MPID_MAX_THREAD_LEVEL - thread level supported by device.
dnl                            if unset, is MPI_THREAD_FUNNELED
dnl    MPID_NO_LONG_LONG     - if yes, the device does not support the 
dnl                            long long integer type
dnl    MPID_NO_LONG_DOUBLE   - if yes, the device does not support the
dnl                            long double type
dnl    MPID_PM_NAMESERVER    - if set, provides the name of the nameserver
dnl                            that the process manager supports.
dnl                            This name server will be used if the
dnl                            default name server is selected.
dnl    MPID_NO_PM            - If yes, the device does not require any
dnl                            PM implementation.  
dnl    MPID_NO_PMI           - If yes, the device does not require any 
dnl                            PMI implementation.
dnl    MPID_MAX_PROCESSOR_NAME - The maximum number of character in a processor
dnl                            name.  If not set, 128 will be used.
dnl    MPID_MAX_ERROR_STRING - The maximum number of character in an error
dnl                            string.  If not set, 1024 will be used.
dnl    MPID_LIBTOOL_STATIC_FLAG - The static compilation flag to use
dnl                               for the example executables within
dnl                               mpich.  If not set, -static will be
dnl                               used.
dnl    PMI_REQUIRES_READABLE_TOKENS - if yes, define the C-preprocessor
dnl                            value USE_HUMAN_READABLE_TOKENS, which is
dnl                            used in src/include/mpimem.h to define token
dnl                            separators used in src/util/mem/argstr.c
dnl    PM_REQUIRES_PMI       - if set, provides the name of the PMI 
dnl                            interface implementation.  If not set,
dnl                            the "simple" PMI implementation is used.
dnl                            A process manager that needs a particular
dnl                            process manager should check that this is
dnl                            not set to an incompatible value.
dnl    MPID_NO_SPAWN         - if yes, the device does not support the
dnl                            dynamic process routines (spawn, connect
dnl                            attach, join, plus port and publish 
dnl                            routines).  The major effect of this
dnl                            is to let the test codes know that
dnl                            spawn is not implemented.
dnl    MPID_NO_RMA           - if yes, the device does not support the
dnl                            MPI RMA routines (MPI_Win_create and 
dnl                            MPI_Put etc.).  The major effect of this
dnl                            is to let the test codes know that 
dnl                            RMA is not implemented.
dnl
dnl Note that the meanings of these variables are defined so that an 
dnl undefined value gives the default.  This makes it easy to expand
dnl the set of such variables, since only modules that need the new
dnl variable will need to be changed.
dnl
dnl 2. Determine compiler characteristics
dnl Here is where features of the compilers are determined, including
dnl support for shared libraries and sizes of the basic datatype types.
dnl
dnl 3. Setup and configure the other modules
dnl Before each module configure is executed, the script setup_<module>
dnl is run if present.  This is a bourne (sh) shell script and may
dnl access configure variables.  It should not make any changes to the
dnl compiler name or flags (e.g., do not add -D_XOPEN_SOURCE to CFLAGS here,
dnl because that may invalidate the determination of the compiler 
dnl characteristics in the prior step).
dnl
dnl 4. Determine MPI features
dnl    
dnl
dnl Special environment variables
dnl To let other scripts and in particular the configure in test/mpi
dnl know that they are being invoked from within the MPICH configure,
dnl the following environment variables are set and exported:
dnl    FROM_MPICH
dnl    MPICH_ENABLE_F77
dnl    MPICH_ENABLE_FC
dnl    MPICH_ENABLE_CXX
dnl
dnl Note that no executable statements are allowed (and any are silently 
dnl dropped) before AC_INIT.

m4_include([maint/version.m4])
dnl 2nd arg is intentionally underquoted
AC_INIT([MPICH],
        MPICH_VERSION_m4,
        [discuss@mpich.org],
        [mpich],
        [http://www.mpich.org/])

if test "x$prefix" != "xNONE" && test -d "$prefix"; then 
    if test "x`(cd \"$prefix\"; echo \"$PWD\")`" = "x`(cd \"$srcdir\"; echo \"$PWD\")`" ||\
       test "x`(cd \"$prefix\"; echo \"$PWD\")`" = "x$PWD"  ; then
        AC_MSG_ERROR([The install directory (--prefix=) cannot be the same as the build or src directory.])
    fi
fi         

CONFIGURE_ARGS_CLEAN=`echo $* | tr '"' ' '`
AC_SUBST(CONFIGURE_ARGS_CLEAN)

# these values come from the m4_include above
MPICH_VERSION=MPICH_VERSION_m4
AC_SUBST([MPICH_VERSION])
MPICH_RELEASE_DATE="MPICH_RELEASE_DATE_m4"
AC_SUBST([MPICH_RELEASE_DATE])
libmpich_so_version="libmpich_so_version_m4"
AC_SUBST([libmpich_so_version])


if test -z "$MPICH_VERSION" ; then
    AC_MSG_ERROR([MPICH_VERSION is empty, check maint/version.m4 for errors])
fi
# Produce a numeric version assuming the following format:
# Version: [MAJ].[MIN].[REV][EXT][EXT_NUMBER]
# Example: 1.0.7rc1 has
#          MAJ = 1
#          MIN = 0
#          REV = 7
#          EXT = rc
#          EXT_NUMBER = 1
#
# Converting to numeric version will convert EXT to a format number:
#          ALPHA (a) = 0
#          BETA (b)  = 1
#          RC (rc)   = 2
#          PATCH (p) = 3
# Regular releases are treated as patch 0
#
# Numeric version will have 1 digit for MAJ, 2 digits for MIN,
# 2 digits for REV, 1 digit for EXT and 2 digits for EXT_NUMBER.
changequote(<<,>>)
V1=`expr $MPICH_VERSION : '\([0-9]*\)\.[0-9]*\.*[0-9]*[a-zA-Z]*[0-9]*'`
V2=`expr $MPICH_VERSION : '[0-9]*\.\([0-9]*\)\.*[0-9]*[a-zA-Z]*[0-9]*'`
V3=`expr $MPICH_VERSION : '[0-9]*\.[0-9]*\.*\([0-9]*\)[a-zA-Z]*[0-9]*'`
V4=`expr $MPICH_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*\([a-zA-Z]*\)[0-9]*'`
V5=`expr $MPICH_VERSION : '[0-9]*\.[0-9]*\.*[0-9]*[a-zA-Z]*\([0-9]*\)'`
changequote([,])

if test "$V2" -le 9 ; then V2=0$V2 ; fi
if test "$V3" = "" ; then V3=0; fi
if test "$V3" -le 9 ; then V3=0$V3 ; fi
if test "$V4" = "a" ; then
    V4=0
elif test "$V4" = "b" ; then
    V4=1
elif test "$V4" = "rc" ; then
    V4=2
elif test "$V4" = "" ; then
    V4=3
    V5=0
elif test "$V4" = "p" ; then
    V4=3
fi
if test "$V5" -le 9 ; then V5=0$V5 ; fi

MPICH_NUMVERSION=`expr $V1$V2$V3$V4$V5 + 0`
AC_SUBST(MPICH_NUMVERSION)

# ABIVERSION is the name used by simplemake, so we reassign the
# libmpich_so_version number to it
ABIVERSION=${libmpich_so_version}
export ABIVERSION
export libmpich_so_version
AC_SUBST(ABIVERSION)

# Print out the configure options
CONFIGURE_ARGUMENTS="$ac_configure_args"
AC_SUBST(CONFIGURE_ARGUMENTS)
if test -n "$ac_configure_args" ; then
    echo "Configuring MPICH version $MPICH_VERSION with $ac_configure_args"
else 
    echo "Configuring MPICH version $MPICH_VERSION"
fi

# Add the information on the system:
echo "Running on system: `uname -a`"

dnl Definitions will be placed in this file rather than in the DEFS variable
AC_CONFIG_HEADER(src/include/mpichconf.h)
AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#ifndef MPICHCONF_H_INCLUDED
#define MPICHCONF_H_INCLUDED
])

# We use an #include strategy here because all of the alternative strategies for
# quashing these variables have various drawbacks.  The alternatives are listed
# here to avoid rediscovery of these problems by someone else in the future:
#
# 1) Strategy: Rewrite mpichconf.h.in with sed at autogen.sh time.
#    Problem: Automatic remaking of config.status and friends will re-run
#             autoheader and blow away our sed changes without an opportunity to
#             patch the resulting file again.
# 2) Strategy: Add literal "#undef PACKAGE" lines to the AH_BOTTOM text.
#    Problem: These lines get rewritten by config.status to be "#define" lines,
#             so the intended quashing never actually occurs.
# 3) Strategy: Use AC_CONFIG_COMMANDS to run a sed rewrite command on
#              mpichconf.h at config.status time.
#    Problem: Causes mpichconf.h to always be rewritten, first by the normal
#             config.status commands and then by sed.  This can cause
#             unnecessary remaking of object files since nearly every C source
#             file includes this header (see the Autoconf Manual, "Automatic
#             Remaking")
#
# The only other plausible strategy would seem to be rewriting config.status
# itself via AC_CONFIG_COMMANDS_POST, but that seems error prone.  The best
# solution would be to stop all subconfigures from including config.h headers
# from other packages.  Then all of this nonsense can be eliminated.
# [goodell@ 2011-08-26]
AH_BOTTOM([
/* Include nopackage.h to undef autoconf-defined macros that cause conflicts in
 * subpackages.  This should not be necessary, but some packages are too
 * tightly intertwined right now (such as ROMIO and the MPICH core) */
#include "nopackage.h"

#endif /* !defined(MPICHCONF_H_INCLUDED) */
])

dnl Set the directory that contains support scripts such as install-sh and
dnl config.guess
AC_CONFIG_AUX_DIR(confdb)
dnl our macro dir is the same as our aux dir
AC_CONFIG_MACRO_DIR([confdb])

# Set the FROM_MPICH variable to tell subconfigures that they are
# built from within MPICH
FROM_MPICH=yes
export FROM_MPICH

# Save a copy of precious flags as USER_* before any of these flags
# are being modified by configure tests.
PAC_PREFIX_ALL_FLAGS(USER)

# WRAPPER_xFLAGS are used by mpicc and friends.
#
# WRAPPER_CFLAGS and other compile flags are used for compile options
# that are added by MPICH, but should be used by applications (such
# as include paths).
#
# All libraries that are detected by MPICH as needed for some of its
# functionality (such as -lpthread) should be added to LIBS so
# autoconf link tests can use them. Libraries that are built by MPICH
# at make time (and hence are not available for autoconf link tests to
# use), such as OPA and MPL, should be added to WRAPPER_LIBS for
# static builds. All libraries in LIBS are added to WRAPPER_LIBS
# (similarly LDFLAGS are added to WRAPPER_LDFLAGS) as well, at the end
# of configure.
PAC_PREFIX_ALL_FLAGS(WRAPPER)
WRAPPER_CFLAGS="$CFLAGS $MPICH_MPICC_FLAGS"
WRAPPER_CPPFLAGS="$CPPFLAGS $MPICH_MPICPP_FLAGS"
WRAPPER_CXXFLAGS="$CXXFLAGS $MPICH_MPICXX_FLAGS"
WRAPPER_FFLAGS="$FFLAGS $MPICH_MPIF77_FLAGS"
WRAPPER_FCFLAGS="$FCFLAGS $MPICH_MPIFC_FLAGS"
WRAPPER_LDFLAGS="$MPICH_LDFLAGS"
WRAPPER_LIBS="$MPICH_LIBS"

# Add MPICHLIB_* to the appropriate flags
AC_ARG_VAR(MPICHLIB_CFLAGS,
	[extra CFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_CPPFLAGS,
	[extra CPPFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_CXXFLAGS,
	[extra CXXFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_FFLAGS,
	[extra FFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_FCFLAGS,
	[extra FCFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_LDFLAGS,
	[extra LDFLAGS used in building MPICH libraries])
AC_ARG_VAR(MPICHLIB_LIBS,
	[extra LIBS used in building MPICH libraries])
CFLAGS="$CFLAGS $MPICHLIB_CFLAGS"
CPPFLAGS="$CPPFLAGS $MPICHLIB_CPPFLAGS"
CXXFLAGS="$CXXFLAGS $MPICHLIB_CXXFLAGS"
FFLAGS="$FFLAGS $MPICHLIB_FFLAGS"
FCFLAGS="$FCFLAGS $MPICHLIB_FCFLAGS"
LDFLAGS="$LDFLAGS $MPICHLIB_LDFLAGS"
LIBS="$LIBS $MPICHLIB_LIBS"

dnl include all subsystem m4 fragments now that the core autoconf functionality
dnl has been setup.  No fragment should do anything except define
dnl PAC_SUBCFG_{PREREQ,BODY} macros which will be expanded later as
dnl appropriate
# begin subsys includes
m4_include([subsys_include.m4])
# end subsys includes

dnl ----------------------------------------------------------------------------
dnl setup top-level argument handling
AC_ARG_ENABLE(echo, 
	AC_HELP_STRING([--enable-echo], [Turn on strong echoing. The default is enable=no.]),
	set -x)

AC_ARG_ENABLE(error-checking,
[  --enable-error-checking=level
      Control the amount of error checking.  
        no        - no error checking
        runtime   - error checking controllable at runtime through environment 
                    variables
        all       - error checking always enabled (default)
],,enable_error_checking=default)

AC_ARG_ENABLE(error-messages,
[  --enable-error-messages=level - Control the amount of detail in error messages.
        all       - Maximum amount of information
        generic   - Only generic messages (no information about the specific
                    instance)
        class     - One message per MPI error class
        none      - No messages
],,enable_error_messages=all)

AC_ARG_ENABLE(timing,
[  --enable-timing=level - Control the amount of timing information
                           collected by the MPICH implementation.
        none    - Collect no data (default)
        all     - Collect lots of data
        runtime - Runtime control of data collected
],,enable_timing=default)

AC_ARG_ENABLE(g,
[  --enable-g=option - Control the level of debugging support in the
                       MPICH implementation.  "option" is a list of comma
                       separated names including.  Default is "most".
        none     - No debugging
        handle   - Trace handle operations
        handlealloc - Trace handle allocations
        dbg      - Add compiler flag, -g, to all internal
                   compiler flags, i.e. MPICHLIB_CFLAGS, MPICHLIB_CXXFLAGS,
                   MPICHLIB_FFLAGS, and MPICHLIB_FCFLAGS.
        debug    - Synonym for dbg
        log      - Enable debug event logging
        mem      - Memory usage tracing
        meminit  - Preinitialize memory associated structures and unions to
                   eliminate access warnings from programs like valgrind
        memarena - Check for overwrite errors in memory allocation arena
        mutex    - Enable error checking on pthread mutexes
        mutexnesting - Check for non-nesting of mutexes
        most     - Most of the above options, excluding some with severe
                   performance impacts.  Recommended for typical development.
        yes      - synonym for "most" (*not* "all")
        all      - All of the above choices
],,enable_g=none)

AC_ARG_ENABLE([mpit_pvars],
[  --enable-mpit-pvars=list - Selectively enable MPI_T performance variables in
                      modules. list is a comma-separated module names,
                      including (Default is "none"):
        none     - No performance info recorded
        recvq    - All message queue-related
        nem      - All nemesis-related
        rma      - All rma-related
        all      - All variables above
],[],[enable_mpit_pvars=none])

dnl We may want to force MPI_Aint to be the same size as MPI_Offset, 
dnl particularly on 32 bit systems with large (64 bit) file systems.
AC_ARG_WITH(aint-size,
	AC_HELP_STRING([--with-aint-size], [Override the size of MPI_AINT (in bytes)]),,
	with_aint_size=0)

AC_ARG_ENABLE(fast,
[  --enable-fast=option - Control the level of fast execution in the
                         MPICH implementation.  option is a list of
                         comma separated names including
        O<n>     - Appends default optimization flags, -O<n>, to all internal
                   compiler flags, i.e. MPICHLIB_CFLAGS, MPICHLIB_CXXFLAGS,
                   MPICHLIB_FFLAGS, and MPICHLIB_FCFLAGS. (default is -O2)
        ndebug   - Appends -DNDEBUG to MPICHLIB_CFLAGS.
        all|yes  - "O2" and "ndebug" are enabled
        none     - None of above options, i.e. --disable-fast
],,enable_fast=O2)

AC_ARG_ENABLE(check-compiler-flags,
	AC_HELP_STRING([--enable-check-compiler-flags], [enable the checks for all compiler
                       options, xxxFLAGS, MPICH_xxxFLAGS. Default is on.]),,
		       enable_check_compiler_flags=yes)

dnl We enable f77 and fc if we can find compilers for them.
dnl In addition, we check whether f77 and fc can work together.
AC_ARG_ENABLE(f77,
	AC_HELP_STRING([--enable-f77], [Enable Fortran 77 bindings]),,enable_f77=yes)

AC_ARG_ENABLE(fc,
	AC_HELP_STRING([--enable-fc], [Enable Fortran 90 bindings]),,enable_fc=yes)

AC_ARG_ENABLE(f90,
	AC_HELP_STRING([--enable-f90],
		[Obsolete option: Use --enable-fc or --disable-fc instead]),
	[AC_MSG_ERROR([
--enable-f90 and --disable-f90 are NO longer valid configure options,
use --enable-fc or --disable-fc instead])]
)

AC_ARG_ENABLE(cxx,
	AC_HELP_STRING([--enable-cxx], [Enable C++ bindings]),,enable_cxx=yes)

AC_ARG_ENABLE(romio,
	AC_HELP_STRING([--enable-romio], [Enable ROMIO MPI I/O implementation]),,
	enable_romio=yes)

AC_ARG_ENABLE(debuginfo,
	AC_HELP_STRING([--enable-debuginfo], [Enable support for debuggers]),,
	enable_debuginfo=no)


## Enable creation of libtool-style versioning or no versioning
AC_ARG_ENABLE(versioning,
        [AC_HELP_STRING([--enable-versioning],[Enable library versioning])],,
        [enable_versioning=yes])

if test "$enable_versioning" = "yes" ; then
   ABIVERSIONFLAGS="-version-info \$(ABIVERSION)"
else
   ABIVERSIONFLAGS="-avoid-version"
fi
export ABIVERSIONFLAGS
AC_SUBST(ABIVERSIONFLAGS)


dnl The environment variable MPICH_DEBUGLIBNAME may be used to
dnl override the default name of the library that the debugger will
dnl load to access the MPICH internal data structures.

dnl "default" is a special device that allows MPICH to choose one
dnl based on the environment.
AC_ARG_WITH(device,
	AC_HELP_STRING([--with-device=name], [Specify the communication device for MPICH]),,
	with_device=default)

AC_ARG_WITH(pmi,
	AC_HELP_STRING([--with-pmi=name], [Specify the pmi interface for MPICH]),,
	with_pmi=default)

AC_ARG_WITH(pm, 
	AC_HELP_STRING([--with-pm=name],
		[Specify the process manager for MPICH.  "no" or "none" are
                 valid values.  Multiple process managers may be specified as
                 long as they all use the same pmi interface by separating them
                 with colons.  The mpiexec for the first named process manager
                 will be installed.  Example: "--with-pm=hydra:mpd:gforker"
                 builds the three process managers hydra, mpd and gforker;
                 only the mpiexec from hydra is installed into the bin
                 directory.]),,with_pm=default)

AC_ARG_WITH(logging,
	AC_HELP_STRING([--with-logging=name], [Specify the logging library for MPICH]),
	[if test -z "$withval" ; then with_logging=rlog ; fi],with_logging=none)

AC_ARG_ENABLE(threads,
[  --enable-threads=level - Control the level of thread support in the 
                           MPICH implementation.  The following levels
                           are supported.
        single          - No threads (MPI_THREAD_SINGLE)
        funneled        - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
        serialized      - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
        multiple        - Fully multi-threaded (MPI_THREAD_MULTIPLE)
        runtime         - Alias to "multiple"

        See also the --enable-thread-cs option for controlling the granularity of
        the concurrency inside of the library
],,enable_threads=default)

AC_ARG_ENABLE(thread-cs,
	AC_HELP_STRING([--enable-thread-cs=type],
			[Choose the method used for critical sections
                         and other atomic updates when multiple
                         threads are present.  Values may be global
                         (default), per-object, lock-free]),,enable_thread_cs=global)

AC_ARG_ENABLE(refcount,
	AC_HELP_STRING([--enable-refcount=type],
			[Choose the method for ensuring atomic updates
                         to the reference counts for MPI objects.
                         Values may be lock, lock-free, none.  The
                         default depends on the thread-cs choice; for
                         global it is none (because none is required),
                         for per-object it is lock, and for lock-free
                         it is lock-free]),,enable_refcount=default)

AC_ARG_ENABLE(mutex-timing,
	AC_HELP_STRING([--enable-mutex-timing], [calculate the time spent waiting on mutexes]),
	AC_DEFINE(MPIU_MUTEX_WAIT_TIME,1,[Define to enable timing mutexes]))

AC_ARG_ENABLE(handle-allocation,
	AC_HELP_STRING([--enable-handle-allocation=type],
			[Choose the method used for allocating MPI
			 object handles.  Values may be 'tls' for
			 thread-local storage or 'mutex' for simple
			 locking.  'mutex' is the default.]),,enable_handle_allocation=default)

AC_ARG_ENABLE([predefined-refcount],
	AS_HELP_STRING([--enable-predefined-refcount],
                       [control whether predefined objects like
		       MPI_COMM_WORLD are reference counted (default
		       depends on --enable-thread-cs choice)]),[],
              [enable_predefined_refcount=default])

AC_ARG_ENABLE(weak-symbols,
	AC_HELP_STRING([--enable-weak-symbols],
			[Use weak symbols to implement PMPI routines (default)]),,
		enable_weak_symbols=yes)

AC_ARG_ENABLE([two-level-namespace],
              [AS_HELP_STRING([--enable-two-level-namespace],
                              [(Darwin only) Build shared libraries and programs
                               built with the mpicc/mpif77/etc. compiler
                               wrappers with '-Wl,-commons,use_dylibs' and
                               without '-Wl,-flat_namespace'.  This may make the
                               MPICH installation and MPI programs more
                               compatible with other libraries.  Only enable
                               this option if you really know what these linker
                               options imply.])],
              [],
              [enable_two_level_namespace=no])

AC_ARG_ENABLE(multi-aliases,
	AC_HELP_STRING([--enable-multi-aliases],
		[Multiple aliasing to support multiple fortran compilers (default)]),,
		enable_multi_aliases=yes)

AC_ARG_ENABLE([wrapper-rpath],
              [AC_HELP_STRING([--enable-wrapper-rpath],
                              [Determine whether the rpath is set when programs
                               are linked by mpicc compiler wrappers.  This only
                               applies when shared libraries are built.  The
                               default is yes; use --disable-wrapper-rpath to
                               turn this feature off.  In that case, shared
                               libraries will be found according to the rules
                               for your system (e.g., in LD_LIBRARY_PATH)])],
              [],[enable_wrapper_rpath=yes])
AC_SUBST([enable_wrapper_rpath])

AC_ARG_ENABLE([long-double],
              [AC_HELP_STRING([--disable-long-double],
                              [Pass --disable-long-double to prevent the MPI
                               library from supporting the C "long double" type,
                               even if the C compiler supports it.  "long
                               double" support is enabled by default, provided
                               the compiler supports it.])],
              [],
              [enable_long_double=yes])

AC_ARG_WITH(cross,
	AC_HELP_STRING([--with-cross=file],
		[Specify the values of variables that configure cannot
                 determine in a cross-compilation environment]),,
		 with_cross=$MPID_DEFAULT_CROSS_FILE)
if test -z "$with_cross" ; then with_cross=no ; fi
if test "$with_cross" != "no"; then
  AC_MSG_NOTICE([Using cross file: $with_cross])
fi

AC_ARG_WITH(namepublisher,
[  --with-namepublisher=name   Choose the system that will support 
                              MPI_PUBLISH_NAME and MPI_LOOKUP_NAME.  Options
                              include
                                   pmi (default)
			           file[:directory] (optional directory)
                                   mpd
                                   no (no service available)],,with_namepublisher=default)
AC_ARG_WITH(name-publisher,
    [],
    with_namepublisher=$with_name_publisher,)

AC_SUBST(MPIFLIBNAME)
AC_SUBST(PMPIFLIBNAME)

dnl The default is a special wrapper library
AC_ARG_WITH(fwrapname,
	AC_HELP_STRING([--with-fwrapname=name],
		[Specify name of library containing Fortran interface routines]),
	[FWRAPNAME=$withval;set_FWRAPNAME="yes"],FWRAPNAME=fmpich)
AC_SUBST(FWRAPNAME)

dnl The default is a special wrapper library
AC_ARG_WITH(fcwrapname,
	AC_HELP_STRING([--with-fcwrapname=name],
		[Specify name of library containing Fortran 90 interface routines]),
	[FCWRAPNAME=$withval;set_FCWRAPNAME="yes"],FCWRAPNAME=mpichf90)
AC_SUBST(FCWRAPNAME)

# Find a C compiler.
# We also need to do this before the F77 and FC test to ensure that we
# find the C preprocessor reliably.
PAC_PROG_CC
AM_PROG_CC_C_O dnl needed for automake "silent-rules"
PAC_PUSH_FLAG([CFLAGS])
AC_PROG_CPP
# Bug in autoconf.  Restore cross settings
if test "$pac_cross_compiling" = "yes" -a "$ac_cv_prog_cc_cross" = "no" ; then
    AC_MSG_RESULT([Resetting cross compilation to yes])
    cross_compiling=yes
    ac_cv_prog_cc_cross=yes
    ac_cv_prog_f77_cross=yes
    ac_cv_prog_fc_cross=yes
    ac_cv_prog_cxx_cross=yes
fi
PAC_POP_FLAG([CFLAGS])

dnl now that autoconf and core compilers are setup, init automake and libtool
dnl
dnl We would like to pass -Werror, but we are cheating in the "examples/"
dnl directory and overriding the user-flags like CFLAGS, which automake-1.12
dnl warns about.  Long-term we may need to use a hand-written Makefile.in or
dnl something else in this special dir.
AM_INIT_AUTOMAKE([-Wall -Wno-portability-recursive foreign 1.12.3 silent-rules subdir-objects])
AM_MAINTAINER_MODE([enable])

AM_PROG_AR

LT_INIT()
# Non-verbose make by default
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

# Disable rpath in the compiler wrappers if shared libraries are disabled, since
# rpath makes no sense in the context of static libraries.
if test "X$enable_shared" = "Xno" ; then
    enable_wrapper_rpath=no
fi

dnl AC_PROG_{CXX,F77,FC} must come early in configure.ac in order to avoid some
dnl esoteric autoconf macro expansion errors
dnl
dnl Also, DO NOT attempt to place shell conditionals (either manually or via
dnl AS_IF) around these macros in an effort to save configure time.  It will
dnl lead to weird AM_CONDITIONAL errors and potentially other problems.

# Before attempting to find valid compilers, set the corresponding precious
# shell variable to "no" for any languages that have been disabled by the user
# with "--disable-LANG".  Libtool understands this as a request to disable
# support for this language. This should save a bit of configure time and also
# prevent user complaints like ticket #1570.
AS_IF([test "x$enable_f77" = "xno"],[F77=no])
AS_IF([test "x$enable_fc"  = "xno"],[FC=no])
AS_IF([test "x$enable_cxx" = "xno"],[CXX=no])

# suppress default "-g -O2" from AC_PROG_CXX
: ${CXXFLAGS=""}
AC_PROG_CXX([PAC_CXX_SEARCH_LIST])

# suppress default "-g -O2" from AC_PROG_F77
: ${FFLAGS=""}
AC_PROG_F77([PAC_F77_SEARCH_LIST])

# suppress default "-g -O2" from AC_PROG_FC
: ${FCFLAGS=""}
AC_PROG_FC([PAC_FC_SEARCH_LIST])


# compute canonical system types
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
# TARGET not needed, MPICH isn't a compiler

# Enable better caching control
PAC_ARG_CACHING

# Set CFLAGS for enable strict if necessary.  Do this *first* because
# it may influence the output of the other tests
PAC_ARG_STRICT

# -----------------------------------------------------------------------------
# First check that we have a clean build if we are doing a VPATH build
PAC_VPATH_CHECK(src/include/mpi.h src/env/mpicc,lib)

# ----------------------------------------------------------------------------
# This test is complicated by the fact that top_srcdir is not set until
# the very end of configure.  Instead, we get it ourselves
if test -z "$top_srcdir" ; then
   use_top_srcdir=$srcdir   
else
   use_top_srcdir=$top_srcdir
fi
if test -z "$master_top_srcdir" ; then 
    # This needs to be an absolute pathname
    case "$use_top_srcdir" in
    /*) ;;
    *)
        use_top_srcdir=`(cd $use_top_srcdir && pwd)`
	;;	
    esac
    master_top_srcdir=$use_top_srcdir
fi
# Get the directory that we're running in...
if test -z "$master_top_builddir" ; then
   master_top_builddir="`pwd`"
fi
AC_SUBST(master_top_builddir)
AC_SUBST(master_top_srcdir)
export master_top_builddir
export master_top_srcdir

# ----------------------------------------------------------------------------
dnl Export important "precious" variables so that any directories configured via
dnl PAC_CONFIG_SUBDIR will agree with the top-level configure about these
dnl critical variables (esp. compiler selection).  These exports should come
dnl before any subconfigures in this script.
dnl
dnl This list is arguably incomplete, and should possibly be automatically
dnl generated from "$ac_precious_vars" using code similar to the implementation
dnl of PAC_CONFIG_SUBDIR.
dnl
dnl To be clear, without these exports any variable values determined by this
dnl configure script will not be seen by child scripts.  Instead they will dnl
dnl receive the only the original inherited environment and configure args used
dnl when this configure script was invoked.
export AR
export AR_FLAGS
export CC
export CFLAGS
export CPPFLAGS
export CXX
export CXXFLAGS
export F77
export FC
export FCFLAGS
export FFLAGS
export LDFLAGS
export LIBS
export MPILIBNAME
export PMPILIBNAME
export RANLIB
export OPALIBNAME
export MPLLIBNAME
# ----------------------------------------------------------------------------
# with-device
if test "$with_device" = "default" ; then
    # Pick the device.  For now, always choose ch3
    with_device=ch3
fi
# Extract the device name from any options
# Allow the device to specify a directory; if no directory, use the
# included directories
# 
DEVICE=$with_device
AC_SUBST(DEVICE)

device_name=`echo $with_device | sed -e 's/:.*$//'`
changequote(<<,>>)
device_args=`echo $with_device | sed -e 's/^[^:]*//' -e 's/^://'`
changequote([,])

devicedir=$use_top_srcdir/src/mpid/$device_name
devicereldir=src/mpid/$device_name
case "$device_name" in
     /*) 
     devicedir=$DEVICE
     # Get the name from the leaf
     device_name=`echo $device_name ~ sed -e 's%.*/%%'`
     # FIXME: should the devicereldir be different (perhaps not -
     # this allows use to build within our tree, even when other data
     # is outside of the tree)
     ;;
     *) 
     ;;
esac
export device_name
export device_args
export devicedir

# See if the device wants to say something about the compilers
if test -f $devicedir/mpichprereq ; then
    . $devicedir/mpichprereq
fi

# expand all of the prereq macros in the correct order
m4_map([PAC_SUBCFG_DO_PREREQ], [PAC_SUBCFG_MODULE_LIST])

# ----------------------------------------------------------------------------
# Set default library names if names haven't already been provided
AC_ARG_VAR([MPILIBNAME],[can be used to override the name of the MPI library (default: "mpich")])
AC_ARG_VAR([PMPILIBNAME],[can be used to override the name of the MPI profiling library (default: "p$MPILIBNAME")])
AC_ARG_VAR([MPICXXLIBNAME],[can be used to override the name of the MPI C++ library (default: "${MPILIBNAME}cxx")])
MPILIBNAME=${MPILIBNAME:-"mpich"}
PMPILIBNAME_set=no
if test -n "$PMPILIBNAME" ; then 
   PMPILIBNAME_set=yes
fi
PMPILIBNAME=${PMPILIBNAME:-"p$MPILIBNAME"}
# Note that the name for this library may be updated after we check for 
# enable_shmem
# Fortran names are set later.
# We use a different library for the C++ wrappers to avoid problems when
# creating shared libraries
if test -z "$MPICXXLIBNAME" ; then MPICXXLIBNAME="${MPILIBNAME}cxx" ; fi
export MPIFLIBNAME
export PMPIFLIBNAME
export MPICXXLIBNAME
AC_SUBST(MPICXXLIBNAME)

# We'll set FORTRAN_BINDING to 1 if we support Fortran 
FORTRAN_BINDING=0

# enable-fast
# strip off multiple options, separated by commas
save_IFS="$IFS"
IFS=","
for option in $enable_fast ; do
    case "$option" in
        O*)
        enable_fast_opts=$option
        ;;
        ndebug)
        enable_fast_ndebug=yes
        ;;
        all|yes)
        enable_fast_ndebug=yes
        enable_fast_opts=O2
        ;;
        none|no)
        enable_fast_ndebug=no
        enable_fast_opts=O0
        ;;
        *)
	IFS="$save_IFS"
        AC_MSG_WARN([Unknown value $option for --enable-fast])
	IFS=","
        ;;
    esac
done
IFS="$save_IFS"

if test -n "$enable_fast_opts" ; then
   # Allows O<n> where <n> can be [0-9] or ' '.
   opt_flags=`echo $enable_fast_opts | sed -e 's%\(O[0-9] \)%\1%g'`
   if test -n "$opt_flags" ; then
      MPI_DEFAULT_COPTS="-$enable_fast_opts"
      MPI_DEFAULT_CXXOPTS="-$enable_fast_opts"
      MPI_DEFAULT_FOPTS="-$enable_fast_opts"
      MPI_DEFAULT_FCOPTS="-$enable_fast_opts"
   else
      AC_MSG_WARN([Unknown value $enable_fast_opts for --enable-fast])
   fi
fi

if test "$enable_fast_ndebug" = "yes" ; then
    CFLAGS="$CFLAGS -DNDEBUG -DNVALGRIND"
    CXXFLAGS="$CXXFLAGS -DNDEBUG -DNVALGRIND"
    # MPICH does NOT assume any preprocessing support from the Fortran compiler,
    # so no Fortran files contain any preprocessing statements.
    # Don't set FFLAGS or FCFLAGS with any -D.
fi

# error-checking
# Change default into the specific value of the default
if test "$enable_error_checking" = "default" ; then
   enable_error_checking=all
fi
# glue_romio.h needs the variable HAVE_ERROR_CHECKING to have the value 0 or 1
HAVE_ERROR_CHECKING=0
case "$enable_error_checking" in 
    no)
    # if error checking has been disabled, then automatically disable the error
    # checking tests in the test suite
    ac_configure_args="${ac_configure_args} --disable-checkerrors"
    ;;
    all|yes|runtime)
    error_checking_kind=`echo $enable_error_checking | \
    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
    error_checking_kind=MPID_ERROR_LEVEL_$error_checking_kind
    AC_DEFINE_UNQUOTED(HAVE_ERROR_CHECKING,$error_checking_kind,[Define to enable error checking])
    HAVE_ERROR_CHECKING=1
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_error_checking for enable-error-checking])
    ;;
esac
# permit @HAVE_ERROR_CHECKING@ substitution in glue_romio.h 
AC_SUBST([HAVE_ERROR_CHECKING])

# error-messages
case "$enable_error_messages" in 
    no|none)
        error_message_kind="MPICH_ERROR_MSG_NONE"
    ;;
    all|yes)
	error_message_kind="MPICH_ERROR_MSG_ALL"
    ;;
    generic)
	error_message_kind="MPICH_ERROR_MSG_GENERIC"
    ;;
    class)
	error_message_kind="MPICH_ERROR_MSG_CLASS"
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_error_messages for enable-error-messages])
    ;;
esac
AC_DEFINE_UNQUOTED(MPICH_ERROR_MSG_LEVEL,$error_message_kind,[define to enable error messages])

# ----------------------------------------------------------------------------
#
# enable-timing and with-logging
#
# Still to do: add subsets: e.g., class=pt2pt,class=coll.  See mpich doc
#
# Logging and timing are intertwined.  If you select logging, you
# may also need to select a timing level.  If no timing is selected 
# but logging with rlog is selected, make "all" the default timing level.
#
# FIXME: make timing and logging options work more cleanly together,
# particularly when other logging options are selected (e.g., logging is not
# rlog).
# ----------------------------------------------------------------------------
AM_CONDITIONAL([BUILD_LOGGING_RLOG],[test "X$with_logging" = "Xrlog"])
collect_stats=false
logging_required=false
if test "$enable_timing" = "default" ; then
    if test "$with_logging" = "rlog" ; then
        enable_timing=all
    fi
fi
timing_name=$enable_timing
case "$enable_timing" in
    no)
    timing_name=none
    ;;
    time)
    collect_stats=true
    ;;
    log|log_detailed)
    logging_required=true
    ;;
    yes)
    timing_name=all
    collect_stats=true
    logging_required=true
    ;;
    all|runtime)
    collect_stats=true
    logging_required=true
    ;;
    none|default)
    timing_name=none
    ;;
    *)
    AC_MSG_WARN([Unknown value $enable_timing for enable-timing])
    enable_timing=no
    timing_name=none
    ;; 
esac
#
# The default logging package is rlog; you can get it by 
# specifying --with-logging or --with-logging=rlog
#
case $with_logging in 
    yes)
    logging_name=rlog
    ;;
    no|none)
    logging_name=none
    ;;
    default)
    if test "$logging_required" = "true" ; then
        logging_name=rlog
    else
        logging_name=none
    fi
    ;;
    *)
    logging_name=$with_logging
    ;;
esac
# 
# Include the selected logging subsystem
#
# Choices:
# 1) A subdir of src/util/logging
#     This directory must contain a configure which will be executed
#     to build the 
# 2) An external directory
#     This directory must contain 
#          a mpilogging.h file
#     It may contain 
#          a setup_logging script
#          a configure
#     
#   
logging_subsystems=
if test "$logging_name" != "none" ; then
    # Check for an external name (directory containing a /)
    hasSlash=`echo A$logging_name | sed -e 's%[[^/]]%%g'`
    if test -n "$hasSlash" ; then
        # Check that the external logging system is complete.
	# Any failure will cause configure to abort
        if test ! -d $logging_name ; then
	    AC_MSG_ERROR([External logging directory $logging_name not found.  Configure aborted])
	    logging_name=none
        elif test ! -s $logging_name/mpilogging.h ; then
	    AC_MSG_ERROR([External logging header $logging_name/mpilogging.h not found.  Configure aborted])
	    logging_name=none
        fi

        logdir=$logging_name
	# Force the logdir to be absolute
	logdir=`cd $logdir && pwd`
	# Switch name to "external" because that is how the MPICH
	# code will know it
	logging_name=external
	# Add the dir to the include paths
	#CPPFLAGS="$CPPFLAGS -I$logdir"
	CPPFLAGS="$CPPFLAGS -I$logdir"
	# Add to the list of external modules to setup
	if test -x $logdir/setup_logging ; then
	     EXTERNAL_SETUPS="$EXTERNAL_SETUPS $logdir/setup_logging"
	fi
    else
        logdir=$srcdir/src/util/logging
        logreldir=src/util/logging/$logging_name
        logging_subsystems="$logging_subsystems $logreldir"
        for dir in $logging_name ; do
            if test ! -d $logdir/$dir ; then
	        AC_MSG_ERROR([$logdir/$dir does not exist.  Configure aborted])
	        logging_name=none
            fi
        done
        for dir in $logging_subsystems ; do
            if test ! -x $srcdir/$dir/configure ; then
	        AC_MSG_ERROR([$srcdir/$dir has no configure (required).  Configure aborted])
	        logging_name=none
            fi
        done
    fi
fi
#
# FIXME: Logging doesn't necessarily require timing (e.g., simply logging the 
# sequence of routines).  
if test "$logging_name" != "none" ; then
    if test "$enable_timing" != "no" ; then
	if test "$enable_timing" = "default" -o "$enable_timing" = "none" ; then
	    enable_timing=log
	    timing_name=log
    	fi
	subsystems="$subsystems $logging_subsystems"
    else
	AC_MSG_WARN([Timing was disabled.  Logging has been disabled as well.])
	with_logging=no
	logging_name=none
    fi
else
    if test "$logging_required" = "true" ; then
	AC_MSG_WARN([Timing was enabled with log option but no logging library is available.  Timing has been disabled.])
	enable_timing=no
	timing_name=none
    fi
fi
if test "$timing_name" != "none" ; then
    timing_kind=`echo $timing_name | \
       tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
    timing_kind=MPID_TIMING_KIND_$timing_kind
    AC_DEFINE_UNQUOTED(HAVE_TIMING,$timing_kind,[define to enable timing collection])
    if test "$collect_stats" = "true" ; then
        AC_DEFINE(COLLECT_STATS,1,[define to enable collection of statistics])
    fi
fi

use_logging_variable="MPID_LOGGING_`echo $logging_name | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
AC_DEFINE_UNQUOTED(USE_LOGGING,$use_logging_variable,[define to choose logging library])
# ----------------------------------------------------------------------------
# End of logging tests
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Check to see if the device does not support spawn.  
# FIXME: This should provide the option of not building the dynamic
# process routines.  It could also allow us to specialize support
# for all processes are members of MPI_COMM_WORLD (only one comm_world).
# ----------------------------------------------------------------------------
if test "$MPID_NO_SPAWN" = yes ; then
    AC_MSG_WARN([The device $with_device does not support MPI dynamic process routines])   
fi

# MPL
AC_ARG_VAR([MPLLIBNAME],[can be used to override the name of the MPL library (default: "mpl")])
MPLLIBNAME=${MPLLIBNAME:-"mpl"}
export MPLLIBNAME
AC_SUBST(MPLLIBNAME)
AC_ARG_WITH([mpl-prefix],
            [AS_HELP_STRING([[--with-mpl-prefix[=DIR]]],
                            [use the MPL library installed in DIR,
                             rather than the one included in src/mpl.  Pass
                             "embedded" to force usage of the MPL source
                             distributed with MPICH2.])],
            [],dnl action-if-given
            [with_mpl_prefix=embedded]) dnl action-if-not-given
mpldir=""
AC_SUBST([mpldir])
mplsrcdir=""
AC_SUBST([mplsrcdir])
mpllibdir=""
AC_SUBST([mpllibdir])
if test "$with_mpl_prefix" = "embedded" ; then
    PAC_CONFIG_SUBDIR(src/mpl,,AC_MSG_ERROR(MPL configure failed))
    PAC_PREPEND_FLAG([-l${MPLLIBNAME}], [WRAPPER_LIBS])
    PAC_APPEND_FLAG([-I${master_top_builddir}/src/mpl/include], [CPPFLAGS])
    PAC_APPEND_FLAG([-I${use_top_srcdir}/src/mpl/include], [CPPFLAGS])

    mpllibdir="${master_top_builddir}/src/mpl"
    mplsrcdir="${master_top_builddir}/src/mpl"
else
    # The user specified an already-installed MPL; just sanity check, don't
    # subconfigure it
    AS_IF([test -s "${with_mpl_prefix}/include/mplconfig.h"],
          [:],[AC_MSG_ERROR([the MPL installation in "${with_mpl_prefix}" appears broken])])
    PAC_APPEND_FLAG([-I${with_mpl_prefix}/include],[CPPFLAGS])
    PAC_PREPEND_FLAG([-l${MPLLIBNAME}],[WRAPPER_LIBS])
    PAC_APPEND_FLAG([-L${with_mpl_prefix}/lib],[WRAPPER_LDFLAGS])
    mpllibdir="${with_mpl_prefix}/lib"
fi

# OpenPA
AC_ARG_VAR([OPALIBNAME],[can be used to override the name of the OpenPA library (default: "opa")])
OPALIBNAME=${OPALIBNAME:-"opa"}
export OPALIBNAME
AC_SUBST(OPALIBNAME)
AC_ARG_WITH([openpa-prefix],
            [AS_HELP_STRING([[--with-openpa-prefix[=DIR]]],
                            [use the OpenPA atomics library installed in DIR,
                             rather than the one included in src/openpa.  Pass
                             "embedded" to force usage of the OpenPA source
                             distributed with MPICH.])],
            [],
            [# see if OPA is already installed on the system
             PAC_PUSH_FLAG([LIBS])
             PAC_PREPEND_FLAG([-l${OPALIBNAME}],[LIBS])
             AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
#include "opa_primitives.h"
],[
OPA_int_t i;
OPA_store_int(i,10);
OPA_fetch_and_incr_int(&i,5);
])dnl
                             ],
                            [with_openpa_prefix=system],[with_openpa_prefix=embedded])
             PAC_POP_FLAG([LIBS])
             ])

opasrcdir=""
AC_SUBST([opasrcdir])
opalibdir=""
AC_SUBST([opalibdir])

if test "$with_openpa_prefix" = "embedded" ; then
    if test -e "${use_top_srcdir}/src/openpa" ; then
        opasrcdir="${master_top_builddir}/src/openpa"
        opalibdir="${master_top_builddir}/src/openpa/src"
        PAC_APPEND_FLAG([-I${use_top_srcdir}/src/openpa/src],[CPPFLAGS])
        PAC_APPEND_FLAG([-I${master_top_builddir}/src/openpa/src],[CPPFLAGS])

        # OPA defaults to "auto", but in MPICH we want "auto_allow_emulation" to
        # easily permit using channels like ch3:sock that don't care about atomics
        AC_ARG_WITH([atomic-primitives],
                    [AS_HELP_STRING([--with-atomic-primitives],
                                    [Force OPA to use a specific atomic primitives
                                     implementation.  See the src/openpa directory
                                     for more info.])],
                    [],[with_atomic_primitives=not_specified])
        opa_subdir_args=""
        if test "$with_atomic_primitives" = "not_specified" ; then
            opa_subdir_args="--with-atomic-primitives=auto_allow_emulation"
        fi
        PAC_CONFIG_SUBDIR_ARGS([src/openpa],[$opa_subdir_args],[],[AC_MSG_ERROR([OpenPA configure failed])])
        PAC_PREPEND_FLAG([-l${OPALIBNAME}],[WRAPPER_LIBS])
    else
        AC_MSG_WARN([Attempted to use the embedded OpenPA source tree in "src/openpa", but it is missing.  Configuration or compilation may fail later.])
    fi
elif test "$with_openpa_prefix" = "system" ; then
    PAC_PREPEND_FLAG([-l${OPALIBNAME}],[WRAPPER_LIBS])
elif test "$with_openpa_prefix" = "no" ; then
    # The user doesn't want to use OPA.  This may or may not cause MPICH to
    # fail to configure/build, depending on many other factors.
    :
else
    # The user specified an already-installed OPA; just sanity check, don't
    # subconfigure it
    AS_IF([test -s "${with_openpa_prefix}/include/opa_primitives.h" -a -s "${with_openpa_prefix}/include/opa_config.h"],
          [:],[AC_MSG_ERROR([the OpenPA installation in "${with_openpa_prefix}" appears broken])])
    PAC_APPEND_FLAG([-I${with_openpa_prefix}/include],[CPPFLAGS])
    PAC_PREPEND_FLAG([-l${OPALIBNAME}],[WRAPPER_LIBS])
    if test -d ${with_openpa_prefix}/lib64 ; then
        PAC_APPEND_FLAG([-L${with_openpa_prefix}/lib64],[WRAPPER_LDFLAGS])
        opalibdir="${with_openpa_prefix}/lib64"
    else
        opalibdir="${with_openpa_prefix}/lib"
    fi
    PAC_APPEND_FLAG([-L${with_openpa_prefix}/lib],[WRAPPER_LDFLAGS])
fi

# ----------------------------------------------------------------------------
# Threads
# ----------------------------------------------------------------------------
#
# Threads must be supported by the device.  First, set the default to
# be the highest supported by the device
# "runtime" was an old (now deprecated) option; just map it to multiple
if test "$enable_threads" = "runtime" ; then enable_threads=multiple ; fi
if test "$enable_threads" = "yes" ; then enable_threads=default ; fi
if test "$enable_threads" = "no" ; then enable_threads=single ; fi
if test "$enable_threads" = default ; then
    # XXX DJG bug is here, PREREQ is not being used right now
    if test -n "$MPID_MAX_THREAD_LEVEL" ; then
        case $MPID_MAX_THREAD_LEVEL in
            MPI_THREAD_SINGLE)     enable_threads=single ;;
            MPI_THREAD_FUNNELED)   enable_threads=funneled ;;
            MPI_THREAD_SERIALIZED) enable_threads=serialized ;;
            MPI_THREAD_MULTIPLE)   enable_threads=multiple ;;
            *) AC_MSG_ERROR([Unrecognized thread level from device $MPID_MAX_THREAD_LEVEL])
    	    ;;
        esac
    else
        enable_threads=single
    fi
fi

MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
case "$enable_threads" in 
    single)
    thread_pkg_required=no
    MPICH_THREAD_LEVEL=MPI_THREAD_SINGLE
    ;;
    funneled)
    thread_pkg_required=no
    MPICH_THREAD_LEVEL=MPI_THREAD_FUNNELED
    ;;
    serialized)
    thread_pkg_required=no
    MPICH_THREAD_LEVEL=MPI_THREAD_SERIALIZED
    ;;
    multiple)
    thread_pkg_required=yes
    MPICH_THREAD_LEVEL=MPI_THREAD_MULTIPLE
    ;;
    *)
    AC_MSG_ERROR(["$enable_threads" is not a valid value for --enable-threads])     
    ;;
esac
# Check that the requested thread level is available.
threadLevelOK=yes
if test ! -z "$MPID_MAX_THREAD_LEVEL" ; then
    # Check that MPID_MAX_THREAD_LEVEL is at least as large as the
    # selected MPICH_THREAD_LEVEL
    case $MPICH_THREAD_LEVEL in 
        MPI_THREAD_MULTIPLE)
	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" ; then
	    threadLevelOK=no
        fi
	;;
	MPI_THREAD_SERIALIZED)
	if test "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_MULTIPLE" -a \
	        "$MPID_MAX_THREAD_LEVEL" != "MPI_THREAD_SERIALIZED" ; then
            threadLevelOK=no
        fi
	;;
	MPI_THREAD_FUNNELED)
        if test "$MPID_MAX_THREAD_LEVEL" = "MPI_THREAD_SINGLE" ; then
            threadLevelOK=no
        fi
	;;
	MPI_THREAD_SINGLE)
	;;
    esac
fi
if test "$threadLevelOK" != yes ; then
   AC_MSG_ERROR([The device $with_device does not support $MPICH_THREAD_LEVEL])
fi

export MPICH_THREAD_LEVEL
AC_DEFINE_UNQUOTED(MPICH_THREAD_LEVEL,$MPICH_THREAD_LEVEL,[Level of thread support selected at compile time])

# Check for value thread_cs choice; set the refcount default if necessary
thread_granularity=MPIU_THREAD_GRANULARITY_SINGLE
thread_refcount=MPIU_REFCOUNT_NONE
if test "$enable_threads" = "multiple" ; then
    case $enable_thread_cs in 
    global)
    thread_granularity=MPIU_THREAD_GRANULARITY_GLOBAL
    if test "$enable_refcount" = "default" ; then enable_refcount=none ; fi
    ;;
    brief-global|brief_global)
    AC_MSG_ERROR([--enable-thread-cs=brief-global is no longer supported, please select a different granularity])
    ;;
    per-object|per_object)
    thread_granularity=MPIU_THREAD_GRANULARITY_PER_OBJECT
    if test "$enable_refcount" = "default" ; then enable_refcount=lock ; fi
    ;;
    lock-free|lock_free|lockfree)
    thread_granularity=MPIU_THREAD_GRANULARITY_LOCK_FREE
    if test "$enable_refcount" = "default" ; then enable_refcount=lock-free ; fi
    if test "$enable_predefined_refcount" = "default" ; then enable_predefined_refcount=no ; fi
    ;;
    *)
    AC_MSG_ERROR([Unrecognized value $enable_thread_cs for --enable-thread-cs])
    ;;
    esac

    case $enable_refcount in
    lock)
    thread_refcount=MPIU_REFCOUNT_LOCK
    ;;
    lock-free|lock_free|lockfree)
    thread_refcount=MPIU_REFCOUNT_LOCKFREE
    ;;
    none)
    thread_refcount=MPIU_REFCOUNT_NONE
    ;;
    *)
    AC_MSG_ERROR([Unrecognized value $enable_refcount for --enable-refcount])
    ;;
    esac
fi
AC_DEFINE_UNQUOTED([MPIU_THREAD_GRANULARITY],$thread_granularity,[Method used to implement atomic updates and access])

if test "$enable_predefined_refcount" = "no" ; then
    AC_DEFINE([MPIU_THREAD_SUPPRESS_PREDEFINED_REFCOUNTS],[1],[define to disable reference counting predefined objects like MPI_COMM_WORLD])
fi

case $enable_handle_allocation in
    mutex|default)
        handle_allocation_method=MPIU_HANDLE_ALLOCATION_MUTEX
    ;;
    tls)
        handle_allocation_method=MPIU_HANDLE_ALLOCATION_THREAD_LOCAL
    ;;
    *)
        AC_MSG_ERROR([Unrecognized value $enable_handle_allocation for --enable-handle-allocation])
    ;;
esac
AC_DEFINE_UNQUOTED([MPIU_HANDLE_ALLOCATION_METHOD],$handle_allocation_method,[Method used to allocate MPI object handles])


AC_DEFINE_UNQUOTED([MPIU_THREAD_REFCOUNT],$thread_refcount,[Method used to implement refcount updates])

# enable-g
# strip off multiple options, separated by commas
save_IFS="$IFS"
IFS=","
for option in $enable_g ; do
    case "$option" in 
        debug|dbg)
        enable_append_g=yes
	;;
        no|none)
	;;
	handlealloc)
	perform_handlealloc=yes
	;;
	handle)
        perform_handle=yes
	;;
	meminit)
	perform_meminit=yes
	;;
	memarena)
	perform_memarena=yes
	perform_memtracing=yes
	;;
	mem)
	perform_memtracing=yes
	;;
	log)
	perform_dbglog=yes
	;;
	mutex)
	perform_dbgmutex=yes
	;;
	mutexnesting)
	perform_mutexnesting=yes
	;;
        most|yes)
        perform_memtracing=yes
        perform_dbglog=yes
        enable_append_g=yes
        perform_meminit=yes
        perform_dbgmutex=yes
        perform_mutexnesting=yes
        perform_handlealloc=yes
        perform_handle=yes
        ;;
	all)
        perform_memarena=yes
	perform_memtracing=yes
	perform_dbglog=yes
	enable_append_g=yes
	perform_meminit=yes
	perform_dbgmutex=yes
	perform_mutexnesting=yes
	perform_handlealloc=yes
        perform_handle=yes
	;;
	*)
	IFS=$save_IFS
	AC_MSG_WARN([Unknown value $option for enable-g])
	IFS=","
	;;
    esac
done
IFS="$save_IFS"

if test "$enable_append_g" = "yes" ; then
    CFLAGS="$CFLAGS -g"
    CXXFLAGS="$CXXFLAGS -g"
    FFLAGS="$FFLAGS -g"
    FCFLAGS="$FCFLAGS -g"
fi
if test -n "$perform_meminit" ; then
    AC_DEFINE(MPICH_DEBUG_MEMINIT,1,[Define to enable preinitialization of memory used by structures and unions])
fi
if test "$perform_handlealloc" = yes ; then
    AC_DEFINE(MPICH_DEBUG_HANDLEALLOC,1,[Define to enable checking of handles still allocated at MPI_Finalize])
fi
AS_IF([test "X$perform_handle" = "Xyes"],
      [AC_DEFINE(MPICH_DEBUG_HANDLES,1,[Define to enable handle checking])])

if test -n "$perform_memtracing" ; then
    enable_g_mem=yes
    AC_DEFINE(USE_MEMORY_TRACING,1,[Define to enable memory tracing])
    if test -n "$perform_memarena" ; then
        AC_DEFINE(MPICH_DEBUG_MEMARENA,1,[Define if each function exit should confirm memory arena correctness])
    fi
fi
if test -n "$perform_mutexnesting" ; then 
    AC_DEFINE(MPICH_DEBUG_MUTEXNESTING,1,[Define to check nesting in mutexes])
fi
USE_DBG_LOGGING=0
if test -n "$perform_dbglog" ; then
   if test "$with_logging" != "none" ; then
       AC_MSG_WARN([--with-logging overrides --enable-g=log])
   else
       AC_DEFINE(USE_DBG_LOGGING,1,[Define to enable logging macros])
       USE_DBG_LOGGING=1
   fi
fi
# allow @USE_DBG_LOGGING@ substitution in glue_romio.h
AC_SUBST([USE_DBG_LOGGING])

if test -n "$perform_dbgmutex" ; then 
   AC_DEFINE(MPICH_DEBUG_MUTEX,1,[Define to enable mutex debugging])
fi

pac_cross_compiling=no
if test "$with_cross" != "no" ; then
    if test -s "$with_cross" ; then
        AC_MSG_RESULT([Reading values from cross-compilation file $with_cross])
        . $with_cross
	# Autoconf 2.52 no longer sets cross_compiling except with the
	# awkward "targethost" options.
	pac_cross_compiling=yes
	cross_compiling=yes
	ac_cv_prog_cc_cross=yes
	ac_cv_prog_f77_cross=yes
 	ac_cv_prog_fc_cross=yes
        ac_cv_prog_cxx_cross=yes
        export cross_compiling
	# Export all cross variables.  Any subsidiary configure should also
        # export CROSS_xxx
	rm -f confcross
	(set) 2>&1 | grep CROSS_ | \
	      sed -e 's/^/export /g' -e 's/=.*//g' > confcross
	. confcross
	rm -f confcross      
    fi
fi

# This goes here because we need the top_srcdir
if test "$enable_romio" = "yes" ; then
   if test -d $use_top_srcdir/src/mpi/romio ; then
       subsystems="$subsystems src/mpi/romio"
       AC_DEFINE(HAVE_ROMIO,1,[Define if ROMIO is enabled])

       # make it possible to "#include" mpio.h at build time
       #
       # This ought to be sufficient, but there is also a symlink setup in
       # src/include to accomodate current mpicc limitations.  See
       # src/mpi/Makefile.mk for more info.
       PAC_APPEND_FLAG([-I${master_top_builddir}/src/mpi/romio/include],[CPPFLAGS])

       # Set environment variables that the romio configure expects
       export use_top_srcdir
       top_build_dir=`pwd`
       export top_build_dir
       # if there is no $top_build_dir/lib, romio puts lib in wrong place
       # This test used -e under Linux, but not all test programs understand
       # -e
       if test ! -d lib ; then mkdir lib ; fi
       # tell mpi.h to include mpio.h
       PAC_HAVE_ROMIO
   else
       AC_MSG_WARN([ROMIO src directory is not available])
   fi
fi

AM_CONDITIONAL([BUILD_ROMIO], [test x$enable_romio = xyes])

#
# FIXME: If an external device, don't necessarily complain (e.g.,
# if the device is already built)
if test ! -d $devicedir ; then
    AC_MSG_ERROR([Device $device_name is unknown])
elif test -f $devicedir/subconfigure.m4 ; then
    # this is a new-style subconfigure device, don't add it as a subsystem
    :
elif test ! -x $devicedir/configure ; then
    if test -s $devicedir/configure ; then
        AC_MSG_WARN([The configure in $devicedir exists but is not executable])
    else
        AC_MSG_WARN([Device $device_name has no configure])
    fi
    device_name=""
else 
    # Add the device to the configure list
    devsubsystems="$devsubsystems $devicereldir"
    # Make device_name available to subdirs
fi

# with-pm
if test "$with_pm" = "none" ; then
    # add "none" as synonym for "no" to agree with older erroneous docs
    with_pm="no"
fi
if test "$MPID_NO_PM" = yes ; then
    if test "$with_pm" != "default" -a "$with_pm" != no ; then
        AC_MSG_ERROR([The PM chosen ($with_pm) is is not valid for the selected device ($with_device)])
    fi
    # This is used to change with_pm=default to with_pm=no in the case
    # where the device does not want a PM
    with_pm=no
fi
if test -z "$with_pm" ; then
    with_pm="no"
fi
if test "$with_pmi" = "uni" -a "$with_pm" = "default" ; then
    with_pm="no"
fi
if test "$with_pm" = "default" -o "$with_pm" = "yes" ; then
   if test ! -z "$MPID_DEFAULT_PM" ; then
      with_pm=${MPID_DEFAULT_PM}
   else
      with_pm=hydra
   fi
fi

# We allow multiple pm names, separated by : or ,
if test "$with_pm" != "no" ; then
    pm_names="`echo $with_pm | sed -e 's/:/ /g' -e 's/,/ /g'`"
else
    pm_names=""
fi
#
hasError=no
# We need to be careful about PM's that have either conflicting 
# requirements (e.g., different PMI implementations) or different
# optional features (e.g., MPID_PM_NAMESERVER).
# In addition, we need to interleave the setup of the PMI and PM
# modules.  The order is as follows:
#
# For each PM, execute the mpichprereq script for that pm (if present).  
# This script provides information about the PM, including which PMI
# implementations are supported.
# 
# Then, for the selected PMI, the setup script (if any) is run.  This is
# necessary because the setup of the PM may require information discovered
# or provided duing the PMI setup step.
#
# Finally, for each PM, the setup script is executed.
# 
# Step 1: invoke the mpichprereq for each PM
for pm_name in $pm_names ; do
    if test -z "$first_pm_name" ; then
       first_pm_name=$pm_name
       export first_pm_name
    fi
    if test ! -d $use_top_srcdir/src/pm/$pm_name ; then
        AC_MSG_WARN([$use_top_srcdir/src/pm/$pm_name does not exist. PM is unknown])
	hasError=yes
    elif test ! -x $use_top_srcdir/src/pm/$pm_name/configure -a \
              ! -f $use_top_srcdir/src/pm/$pm_name/subconfigure.m4 ; then
        if test -s $use_top_srcdir/src/pm/$pm_name/configure ; then
	    AC_MSG_WARN([The configure in $use_top_srcdir/src/pm/$pm_name exists but is not executable])
        else
            AC_MSG_WARN([pm $pm_name has no configure or subconfigure.m4])
        fi
        pm_name=""
	hasError=yes
    else
	nameserver=$MPID_PM_NAMESERVER
        if test -f $use_top_srcdir/src/pm/$pm_name/mpichprereq ; then 
	    echo sourcing $use_top_srcdir/src/pm/$pm_name/mpichprereq
	    . $use_top_srcdir/src/pm/$pm_name/mpichprereq
	fi
	# Check for a change; if found, we'll take the default
	if test "$MPID_PM_NAMESERVER" != "$nameserver" ; then
            if test "$first_pm_name" != "$pm_name" ; then
	        # Reject suggestion (use the default, common mode)
		MPID_PM_NAMESERVER=""
	    fi
	fi
    fi
done
if test "$hasError" != no ; then
    AC_MSG_ERROR([Aborting configure because an error was seen in the selection of process managers])
fi
#
# pm_name is the *primary* pm
pm_name=$first_pm_name
AC_SUBST(pm_name)

# Some versions of PM and PMI require a special definition
if test "$PMI_REQUIRES_READABLE_TOKENS" = "yes" ; then
    AC_DEFINE(USE_HUMAN_READABLE_TOKENS,1,[Define to use ='s and spaces in the string utilities.])
fi

# Step 2:
# Once we've selected the process manager (or managers), we can
# check that we have a compatible PMI implemenatation.
# with-pmi
if test "$MPID_NO_PMI" = yes ; then
    if test "$with_pmi" != "default" -a "$with_pmi" != no ; then
        AC_MSG_ERROR([The PMI chosen ($with_pmi) is is not valid for the selected device ($with_device)])
    fi
    # This is used to change with_pmi=default to with_pmi=no in the case
    # where the device does not want a PMI
    with_pmi=no
elif test "$with_pmi" != "no" ; then
    if test "$with_pmi" = "default" -o "$with_pmi" = "yes" ; then
        if test -n "$PM_REQUIRES_PMI" ; then
	    with_pmi=$PM_REQUIRES_PMI
        else
            with_pmi=simple
        fi
    elif test -n "$PM_REQUIRES_PMI" ; then
        # Test for compatibility between pm and pmi choices
        if test "$PM_REQUIRES_PMI" != "$with_pmi" ; then
	    AC_MSG_ERROR([The PM chosen ($with_pm) requires the PMI implementation $PM_REQUIRES_PMI but $with_pmi was selected as the PMI implementation.])
        fi
    fi
    pmi_name=$with_pmi
    
    if test ! -d $use_top_srcdir/src/pmi/$pmi_name ; then
        AC_MSG_WARN([$use_top_srcdir/src/pmi/$pmi_name does not exist. PMI is unknown])
    elif test ! -x $use_top_srcdir/src/pmi/$pmi_name/configure ; then
        if test ! -f $use_top_srcdir/src/pmi/$pmi_name/subconfigure.m4 ; then
            AC_MSG_WARN([pmi $pmi_name has no configure or subconfigure.m4])
            pmi_name=""
        fi
    else
        # only add to subsystems if a full configure is present
        subsystems="$subsystems src/pmi/$pmi_name"
    fi
else
    AC_MSG_ERROR([A PMI implementation must be selected or the default used.])
fi

# Step 3: complete pm setup.
# Note that checks for errors have already been performed, so this
# loop does not need to perform any extra error checks.
# Note that this uses this_pm_name because pm_name must be the *first*
# of the PM names
for this_pm_name in $pm_names ; do
    # only add the PM to the subsystems if it has a full configure to be
    # executed
    if test -f $use_top_srcdir/src/pm/$this_pm_name/configure ; then
        subsystems="$subsystems src/pm/$this_pm_name"
    fi
    if test -f $use_top_srcdir/src/pm/$this_pm_name/setup_pm ; then 
	echo sourcing $use_top_srcdir/src/pm/$this_pm_name/setup_pm
	. $use_top_srcdir/src/pm/$this_pm_name/setup_pm
    fi
done

# Check for whether the compiler defines a symbol that contains the 
# function name.  The MPICH code, for greater portability, defines
# its own symbols, FCNAME (a string) and FUNCNAME (a token that is not a 
# string).  Code should use these symbols where possible.  However, 
# some debugging macros may want to use a compiler-provided symbol
# for the function name, and this check makes it possible to 
# define such macros in a way that is always correct.
PAC_CC_FUNCTION_NAME_SYMBOL

# Check if $MPI_DEFAULT_COPTS is valid with $CC
if test -n "$MPI_DEFAULT_COPTS" ; then
    if test "$enable_check_compiler_flags" = "yes" ; then
        PAC_C_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_COPTS], [
        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
                                   ] )
    else
        CFLAGS="$CFLAGS $MPI_DEFAULT_COPTS"
    fi
fi

# Set NEEDSPLIB to yes if link commands need both -l$MPILIBNAME
# and -lp$MPILIBNAME.
NEEDSPLIB=yes
if test $enable_weak_symbols = yes ; then
    # Turn off weak symbols if they aren't available
    PAC_PROG_C_WEAK_SYMBOLS(,enable_weak_symbols=no)
fi
if test $enable_weak_symbols = "yes" ; then
    AC_DEFINE(USE_WEAK_SYMBOLS,1,[Define if weak symbols should be used])
    NEEDSPLIB=no
    # Check for the ability to support multiple weak symbols
    if test "$pac_cv_prog_c_weak_symbols" = "pragma weak" ; then
       PAC_PROG_C_MULTIPLE_WEAK_SYMBOLS(AC_DEFINE(HAVE_MULTIPLE_PRAGMA_WEAK,1,[Define if multiple weak symbols may be defined]))
    else
        if test "$pac_cv_prog_c_weak_symbols" = "no" -a "$pac_cv_attr_weak_alias" = "yes"; then
            MPICH_ATTR_WEAK_ALIAS_DEFINITION="__attribute__((weak,alias(fname)))"
        fi
    fi
    AC_SUBST(MPICH_ATTR_WEAK_ALIAS_DEFINITION)
fi
export NEEDSPLIB

AM_CONDITIONAL([BUILD_PROFILING_LIB],[test "$NEEDSPLIB" = "yes"])

# ---------------------------------------------------------------------------
# determine rpath and other shared library flags for CC
# src/env may not exist yet in a vpath build
$MKDIR_P src/env
cc_shlib_conf=src/env/cc_shlib.conf
PAC_COMPILER_SHLIB_FLAGS([CC],[$cc_shlib_conf])
AC_SUBST_FILE([cc_shlib_conf])

# output rpath flags in a usable format for mpich.pc (pkg-config)
if test "X$enable_wrapper_rpath" = "Xyes"; then
    eval WRAPPER_RPATH_LDFLAGS=\"$hardcode_libdir_flag_spec\"
fi
AC_SUBST(WRAPPER_RPATH_LDFLAGS)

# ---------------------------------------------------------------------------
# Support for MPI_T performance variables

# enable-mpit-pvars
# strip off multiple options, separated by commas
save_IFS="$IFS"
IFS=","
for var in $enable_mpit_pvars ; do
    AS_CASE(["$var"],
            [nem],[enable_pvar_nem=yes],
            [recvq],[enable_pvar_recvq=yes],
            [rma],[enable_pvar_rma=yes],
            [all|yes],
            [enable_pvar_nem=yes
             enable_pvar_recvq=yes
             enable_pvar_rma=yes],
            [no|none],[],
            [IFS=$save_IFS
             AC_MSG_WARN([Unknown value ($option) for enable-mpit-pvars])
             IFS=","])
done
IFS="$save_IFS"

if test -n "$enable_pvar_nem" ; then
    status_nem_pvars=1
else
    status_nem_pvars=0
fi
AC_DEFINE_UNQUOTED(ENABLE_PVAR_NEM,$status_nem_pvars,
          [Define to 1 to enable nemesis-related MPI_T performance variables])

if test -n "$enable_pvar_recvq" ; then
    status_recvq_pvars=1
else
    status_recvq_pvars=0
fi
AC_DEFINE_UNQUOTED(ENABLE_PVAR_RECVQ,$status_recvq_pvars,
          [Define to 1 to enable message receive queue-related MPI_T performance variables])

if test -n "$enable_pvar_rma" ; then
    status_rma_pvars=1
else
    status_rma_pvars=0
fi
AC_DEFINE_UNQUOTED(ENABLE_PVAR_RMA,$status_rma_pvars,
          [Define to 1 to enable rma-related MPI_T performance variables])
# ---------------------------------------------------------------------------
# Support for the language bindings: Fortran 77, Fortran 90, and C++
#
# First, we handle the case of no explicit enable/disable option.  In that
# case, we look for a usable compiler.  We cannot use the ac macros for this
# because they abort the configure step if they fail to find a compiler 
# (earlier versions of autoconf did not have this behavior!).
#
# Second, we perform the langugage-specific tests, if necessary.  This may
# be relatively simple (C++) or complex (Fortran 77, including formation of 
# the encoded MPI handles).
#
# Note that the bindings support needs to know some of the properties of
# the C compiler, so those tests (particularly for weak symbols)
# must come first.
# ----------------------------------------------------------------------------

#
# First, determine whether we are/can support the language bindings
#
# Since F90/F90FLAGS are replaced by FC/FCFLAGS, rather than silently
# substituting them, i.e. FC=$F90 and FCFLAGS=$F90FLAGS, we choose to emit
# an error message and abort to avoid any ambiguous/hidden bug in choosing
# Fortran90 compilers.
if test -n "$F90" -o -n "$F90FLAGS" ; then
    AC_MSG_ERROR([F90 and F90FLAGS are replaced by FC and FCFLAGS respectively in this configure, please unset F90/F90FLAGS and set FC/FCFLAGS instead and rerun configure again.])
fi
# ----------------------------------------------------------------------------
# Handle default choices for the Fortran compilers
# Note that these have already been set above

if test "$enable_f77" = "yes" -a "$F77" = "" ; then
   # No Fortran 77 compiler found; abort
   AC_MSG_ERROR([No Fortran 77 compiler found. If you don't need to
   build any Fortran programs, you can disable Fortran support using
   --disable-f77 and --disable-fc. If you do want to build Fortran
   programs, you need to install a Fortran compiler such as gfortran
   or ifort before you can proceed.])
fi

if test "$enable_f77" = yes ; then
    # Check if $MPI_DEFAULT_FOPTS is valid with $F77
    if test -n "$MPI_DEFAULT_FOPTS" ; then
        if test "$enable_check_compiler_flags" = "yes" ; then
            PAC_F77_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FOPTS], [
            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
                                         ] )
        else
            FFLAGS="$FFLAGS $MPI_DEFAULT_FOPTS"
        fi
    fi
fi

#
# We need to know the name mangling for Fortran before testing for FC
# compatibility (we need this because of the way we decide to generate
# the Fortran 77 bindings)
if test "$enable_f77" = yes ; then
    FLIBS_save="$FLIBS"
    FLIBS=""
    AC_F77_LIBRARY_LDFLAGS
    # The autoconf macro for finding FLIBS sometimes makes mistakes
    # (particularly with the Fujitsu frt compiler).  This next step
    # first sees if the FLIBS is valid with the Fortran compiler
    PAC_PROG_F77_FLIBS_VALID
    # Now see if FLIBS works with the C compiler
    PAC_PROG_F77_CHECK_FLIBS

    # Check F77+FLAGS is compatible with CC+CFLAGS before using F77+CC.
    PAC_PROG_F77_OBJ_LINKS_WITH_C

    PAC_PROG_F77_LINKER_WITH_C
    # For name mangle, we need the library flags
    PAC_PROG_F77_NAME_MANGLE
    # Check whether additional libraries are needed when linking with C
    PAC_PROG_F77_AND_C_STDIO_LIBS
    AC_SUBST(F77_OTHER_LIBS)

    # Warn about mixed name mangling, since many of the tests will fail
    if test "$pac_cv_prog_f77_name_mangle" = "mixed" ; then
        AC_MSG_WARN([The compiler $F77 uses mixed case names.  Fortran is monocase
and many Fortran programs may use either upper or lower case names for MPI
calls.  Consider specifying a particular parameter to your Fortran compiler
to select either upper or lower case names.  For the Absoft compiler, 
-f selects lower case and -N109 selects upper case (if you use -f, also use 
-B108 to enable the iargc and getarg routines, which are needed for some
tests and by many user programs).  Specify new command
line options by setting the environment variable FFLAGS to include
the options (e.g., setenv FFLAGS "-f -B108").  In addition, make sure that your
Fortran 90 compiler uses a compatible naming choice.  For the 
Absoft Fortran 90, -YALL_NAMES=LCS selects lower case names and -B108 
adds underscores to names, as required for iargc and getarg.  Pass this
information to configure with the FCFLAGS environment variable.])
        # If Fortran implicitly enabled, disable it now.  Otherwise,
	# abort the configure since warning messages are often lost in
	# the output.
	AC_MSG_ERROR([Aborting configure because of mixed case names in Fortran.  Either select --disable-f77 or set FFLAGS to force the compiler to select monocase names])
    fi

    # The MPI standard requires that MPI_Init in any language initialize
    # MPI in all languages.  This can be a problem when objects produced 
    # by the Fortran compiler require symbols from the Fortran runtime
    # (making linking C-only programs unnecessarily difficult).  What we test 
    # here is whether the much more restricted needs of the Fortran 
    # initialize can be met with no special use of the Fortran runtime
   PAC_F77_INIT_WORKS_WITH_C
   if test "$pac_f_init_works_with_c" = "yes" ; then
       AC_DEFINE(HAVE_MPI_F_INIT_WORKS_WITH_C,1,[Define if the Fortran init code for MPI works from C programs without special libraries])
   fi

   #
   # Some Fortran compilers now pass CHARACTER length as a size_t instead
   # of as an int.  This is hard to test for, since the data is passed by
   # value and for characters less than about 2GB long, the correct
   # value will be used.  In this case, we must use an approach similar to
   # the one used by libtool for shared library options - look at the
   # compiler name or vendor.
   # Known compilers that use size_t instead of int:
   #    Intel Fortran
   #    gfortran
   # Add others as they become known
   AC_ARG_ENABLE(f77characterlen,
       AC_HELP_STRING([--enable-f77characterlen],
           [Select between int and size_t for the length of a Fortran CHARACTER, depending on the F77 compiler.  If --enable-f77characterlen=size_t is given, force the use of size_t.  This is used for passing Fortran CHARACTER data between C and Fortran, and is provided for experts.  Note that the documentation provided by compiler vendors on the calling convention may not be accurate.]),,enable_f77characterlen=no)

   # Set the default
   f77_uses_int_for_str=default

   case "$enable_f77characterlen" in
      yes|no)
      ;;
      size_t)
         f77_uses_int_for_str=no
	 enable_f77characterlen=yes
      ;;
      int)
         f77_uses_int_for_str=yes
	 enable_f77characterlen=yes
      ;;
      *)
      AC_MSG_ERROR([Invalid value provided for --enable-f77characterlen])
      ;;
   esac

   # If we might change the size (enable) and we haven't set the choice,
   # attempt to determine it from the compiler name.  Risky, but we haven't
   # found a reliable way to do this with test codes.
   if test "$enable_f77characterlen" = "yes" -a \
           "$f77_uses_int_for_str" = "default" ; then
       f77_uses_int_for_str=yes
       f77Basename=`basename $F77`
       case $f77Basename in
       ifort*)
       f77_uses_int_for_str=no
       ;;
       gfortran*)
       f77_uses_int_for_str=no
       ;;
       esac
   fi
   # This test is disabled for now.  Despite information in documentation
   # on gfortran, it appears to pass lengths as int, at least in some
   # builds (it used movl when tested in 2/2013).  Tests that failed
   # included infotestf.f, in a call to mpi_info_get.
   # Leave this as a place holder until a proper test can be determined.
   if test  "$enable_f77characterlen" = "yes" -a \
            "$f77_uses_int_for_str" = "no" ; then
       AC_DEFINE(USE_FORT_STR_LEN_SIZET,1,[Define if the length of a CHARACTER*(*) string in Fortran should be passed as size_t instead of int] )
   fi

fi

# FC requires F77 as well.  If the user disabled f77, do not run the
# next test; instead, drop into the warning message
# Set a default value for fc works with f77.  This value is
# set to no *only* if fc was selected but was not compatible with f77
fc_with_f77=yes
if test "$enable_fc" = "yes" -a "$enable_f77" = yes ; then
    enable_fc=no
    if test -n "$FC" ; then 
	# If we allow multiple weak symbols, we should test a name
	# that does not contain an underscore.  The Fortran binding uses
	# this rule for enabling multiple weak symbols:
	# if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES) &&
	#    defined(HAVE_MULTIPLE_PRAGMA_WEAK) && 
	#    defined(F77_NAME_LOWER_2USCORE)
	# 
	testRoutine="t1_2"
	if test "$pac_cv_prog_c_multiple_weak_symbols" = "yes" -a \
               "$enable_weak_symbols" = "yes" -a \
	       "$pac_cv_prog_f77_name_mangle" = "lower doubleunderscore" ; then
	    testRoutine="t12"
        fi
        PAC_FC_AND_F77_COMPATIBLE(fc_with_f77=yes,fc_with_f77=no,$testRoutine)
        if test "$fc_with_f77" != yes ; then
	    enable_fc=no
	    AC_MSG_ERROR([The selected Fortran 90 compiler $FC does not work with the selected Fortran 77 compiler $F77.  Use the environment variables FC and F77 respectively to select compatible Fortran compilers.  The check here tests to see if a main program compiled with the Fortran 90 compiler can link with a subroutine compiled with the Fortran 77 compiler.])
        elif test "$fc_with_f77" = "yes" ; then
            # If we got here, there is a Fortran 90 compiler that we can use
            enable_fc=yes
        fi
    elif test "$pac_cv_prog_fc_works" = no; then
        AC_MSG_WARN([Use --disable-fc to keep configure from searching for a Fortran 90 compiler])
    fi

    if test "$enable_fc" = "yes" -a "$FC" = "" ; then
       # No Fortran 90 compiler found; abort
       AC_MSG_ERROR([No Fortran 90 compiler found. If you don't need
       to build any Fortran 90 programs, you can disable Fortran 90
       support using --disable-fc. If you do want to build Fortran 90
       programs, you need to install a Fortran 90 compiler such as
       gfortran or ifort before you can proceed.])
    fi
fi

if test "$enable_fc" = "yes" -a "$enable_f77" != "yes" ; then
   # Fortran 90 support requires compatible Fortran 77 support
   AC_MSG_ERROR([
Fortran 90 support requires compatible Fortran 77 support.
To force the use of the Fortran 90 compiler for Fortran 77,
do not use configure option --disable-f77, and set the environment
variable F77 to the name of the Fortran 90 compiler, or \$FC.
If you do not want any Fortran support, use configure options
--disable-f77 and --disable-fc.])
   # We should probably do the compatibility test as well
   enable_f77=yes
fi

# ----------------------------------------------------------------------------
# Now test for Fortran compiler characteristics
# ----------------------------------------------------------------------------
if test "$enable_f77" = "yes" ; then
    # determine rpath and other shared library flags for F77
    f77_shlib_conf=src/env/f77_shlib.conf
    PAC_COMPILER_SHLIB_FLAGS([F77],[$f77_shlib_conf])
    AC_SUBST_FILE([f77_shlib_conf])

    AC_LANG_FORTRAN77
    PAC_PROG_F77_EXCLAIM_COMMENTS(has_exclaim="yes",has_exclaim="no")
    PAC_PROG_F77_HAS_INCDIR(src)
    PAC_PROG_F77_LIBRARY_DIR_FLAG

    AC_SUBST(MPIFPMPI)
    if test "$MPI_WITH_PMPI" = "no" ; then
        # If the PMPI routines are not in the same library with the MPI
        # routines, we may need to remove the pmpi declarations
        PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS([MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"],[
        MPIFPMPI=""; 
        AC_MSG_WARN([Removed PMPI_WTIME and PMPI_WTICK from mpif.h])])
    else
        MPIFPMPI=",PMPI_WTIME,PMPI_WTICK"
    fi

    # Once we have name mangle, we can try to limit the number of needed libs
    dnl F77_IN_C_LIBS is not needed currently because mpirinitf_() in setbotf.f
    dnl is called in initthread.c only when FLIBS is not needed to initialize
    dnl Fortran constants from a C main, See PAC_F77_INIT_WORKS_WITH_C.
    dnl PAC_PROG_F77_IN_C_LIBS
    dnl AC_SUBST(F77_IN_C_LIBS)

    # Most systems allow the Fortran compiler to process .F and .F90 files
    # using the C preprocessor.  However, some systems either do not
    # allow this or have serious bugs (OSF Fortran compilers have a bug
    # that generates an error message from cpp).  The following test
    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
    # This is needed for Mac OSX 10.5
    PAC_F77_WORKS_WITH_CPP([F77CPP])
    AC_SUBST(F77CPP)

    # Check that the Fortran compiler will allow us to pass arguments
    # of different types (e.g., for MPI_Send)
    PAC_PROG_F77_MISMATCHED_ARGS(addarg,yes)
    if test "X$addarg" != "X" ; then
        # We could add the names of all of the MPI routines that 
        # accept different types.  Instead, we fail cleanly.  
        # Some Fortran compilers allow you to turn off checking for 
        # mismatched arguments for *all* routines.  Adding an argument
	# that turns off checking for *everything* is not something that 
	# configure should do - if the user wants this, they can follow
	# the instructions in the following error message.
	AC_MSG_ERROR([The Fortran compiler $F77 does not accept programs that call the same routine with arguments of different types without the option $addarg.  Rerun configure with FFLAGS=$addarg])
    fi

    bindings="$bindings f77"
    AC_DEFINE(HAVE_FORTRAN_BINDING,1,[Define if Fortran is supported])
    # Also define the name FORTRAN_BINDING for use in #if @FORTRAN_BINDING@..
    FORTRAN_BINDING=1

fi

dnl By modifying mpif.h to use ! for comments, it can work with many f90 
dnl compilers without creating a separate version.  
dnl Note that this is run AFTER the AC_OUTPUT actions
AC_OUTPUT_COMMANDS([if test "$enable_f77" = yes ; then 
if test "$has_exclaim" = "yes" ; then
    sed -e 's/^C/\!/g' src/binding/f77/mpif.h > src/include/mpif.h
	cp src/include/mpif.h src/binding/f77/mpif.h
else
    cp src/binding/f77/mpif.h src/include
fi
if test "$has_fort_real8" = "yes" ; then
    sed -e 's/DOUBLE PRECISION/REAL*8/g' src/include/mpif.h > src/include/mpif.h.new
    mv src/include/mpif.h.new src/include/mpif.h
    cp src/include/mpif.h src/binding/f77/mpif.h
fi
fi],
master_top_srcdir=$master_top_srcdir
enable_f77=$enable_f77
enable_fc=$enable_fc
has_exclaim=$has_exclaim
has_fort_real8=$pac_cv_fort_real8
includebuild_dir=$includebuild_dir
libbuild_dir=$libbuild_dir
bashWorks=$bashWorks)

if test "$enable_fc" = "yes" ; then
    if test "$enable_f77" != "yes" ; then
        AC_MSG_WARN([Fortran 90 requires Fortran 77])
        enable_fc=no
    else 
        bindingsubsystems="$bindingsubsystems src/binding/f90"
        bindings="$bindings f90"
    fi
fi

# Set defaults for these values so that the Makefile in src/bindings/f90
# is valid even if fc is not enabled (this is necessary for the 
# distclean target)
MPIMODNAME=mpi
MPICONSTMODNAME=mpi_constants
MPISIZEOFMODNAME=mpi_sizeofs
MPIBASEMODNAME=mpi_base
if test "$enable_fc" = "yes" ; then
    # determine rpath and other shared library flags for FC
    fc_shlib_conf=src/env/fc_shlib.conf
    PAC_COMPILER_SHLIB_FLAGS([FC],[$fc_shlib_conf])
    AC_SUBST_FILE([fc_shlib_conf])

    # Determine characteristics of the Fortran 90 compiler
    # Find a Fortran 90 compiler.  Sets FC
    # Work around bug in autoconf that adds -g to FCFLAGS
    saveFCFLAGS="$FCFLAGS"
    dnl FIXME XXX DJG this needs to be reconciled with our separate use of
    dnl AC_PROG_FC earlier
    dnl PAC_PROG_FC
    PAC_PROG_FC_WORKS
    FCFLAGS=$saveFCFLAGS
    if test "$pac_cv_prog_fc_works" = no ; then 
        # Reject this compiler
        if test -n "$FC" ; then
            fc_rejected=yes
            oldFC="$FC"
            FC=""
        fi
    fi

    # Determine the extension for Fortran 90 files (it isn't always .f90)
    FCEXT=$ac_fc_srcext
    AC_SUBST(FCEXT)

    if test -z "$FC" ; then
        if test "$fc_rejected" = "yes" ; then
            AC_MSG_ERROR([Could not find a usable Fortran 90 compiler.  The compiler $oldFC may be incompatible with the Fortran 77 compiler $F77; check the output of configure and consult the installation manuals])
        else
            AC_MSG_ERROR([Could not find a usable Fortran 90 compiler.])
        fi
    fi

    # Find the extension that this compiler uses for modules.
    # Sets FCMODEXT (and adds it to the list substed)
    # Sets FCMODINCFLAG (and adds it to the list substed)
    PAC_FC_MODULE
    AC_SUBST(FCMODINCSPEC)
    if test -z "$FCMODOUTFLAG" ; then
        AC_MSG_ERROR([FCMODOUTFLAG could not be determined but is critical for the current Fortran build system])
    fi

    if test "$pac_cv_fc_module_case" = "upper" ; then
        MPIMODNAME=MPI
        MPICONSTMODNAME=MPI_CONSTANTS
	MPISIZEOFMODNAME=MPI_SIZEOFS
	MPIBASEMODNAME=MPI_BASE
    else
        MPIMODNAME=mpi
        MPICONSTMODNAME=mpi_constants
	MPISIZEOFMODNAME=mpi_sizeofs
	MPIBASEMODNAME=mpi_base
    fi
    AC_SUBST(MPIMODNAME)
    AC_SUBST(MPICONSTMODNAME)
    AC_SUBST(MPISIZEOFMODNAME)
    AC_SUBST(MPIBASEMODNAME)

    # Assume that all Fortran 90 compilers accept -I for include directories
    FCINC=-I
    AC_SUBST(FCINC)
    FCINCFLAG=-I
    AC_SUBST(FCINCFLAG)

    # Check if $MPI_DEFAULT_FCOPTS is valid with $F90
    if test "$enable_default_optimize" = "yes" \
         -a -n "$MPI_DEFAULT_FCOPTS" ; then
        if test "$enable_check_compiler_flags" = "yes" ; then
            PAC_FC_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_FCOPTS], [
            FCFLAGS="$FCFLAGS $MPI_DEFAULT_FCOPTS"
                                     ] )
        else
            FCFLAGS="$FCFLAGS $MPI_DEFAULT_FCOPTS"
        fi
    fi

    # Most systems allow the Fortran compiler to process .F and .F90 files
    # using the C preprocessor.  However, some systems either do not
    # allow this or have serious bugs (OSF Fortran compilers have a bug
    # that generates an error message from cpp).  The following test
    # checks to see if .F works, and if not, whether "cpp -P -C" can be used
    PAC_FC_WORKS_WITH_CPP([FCCPP])
    AC_SUBST(FCCPP)

    # Check whether additional libraries are needed when linking with C
    PAC_PROG_FC_AND_C_STDIO_LIBS
    AC_SUBST(FC_OTHER_LIBS)
    # ------------------------------------------------
fi

if test "X$modincdir" = "X" ; then
  modincdir=$includedir
fi
export modincdir
AC_SUBST(modincdir)

# ----------------------------------------------------------------------------
# We previously allowed "default" as a valid value for $enable_cxx.  Now we
# assume its available by default and error out if it doesn't work (just like
# F77 & FC).  The user must pass "--disable-cxx" in order to successfully
# complete configure in this case.
if test "$enable_cxx" = "default" ; then
    AC_MSG_ERROR([aborting because "--enable-cxx=default" is no longer a supported value])
fi

if test "$enable_cxx" = "yes" ; then
    # Another bug in autoconf.  The checks for the C++ compiler do not
    # ensure that you can link a program that is built with the C++ 
    # compiler.  We've seen this error with gcc and icc, particularly
    # when those compilers accept C++ language elements but are unable
    # to link programs that are really C++.  For that reason,
    # we've added a test to see if the C++ compiler can produce
    # an executable.
    AC_CACHE_CHECK([whether the C++ compiler $CXX can build an executable],
    pac_cv_cxx_builds_exe,[
 AC_LANG_PUSH([C++])
 AC_TRY_LINK([
class mytest { 
  int a;
public:
  mytest(void) : a(1) {}
  ~mytest(void) {}
};],[mytest a;],
 pac_cv_cxx_builds_exe=yes, pac_cv_cxx_builds_exe=no)
 AC_LANG_POP([C++])
])
    if test "$pac_cv_cxx_builds_exe" != yes ; then
        AC_MSG_ERROR([Aborting because C++ compiler does not work.  If you do not need a C++ compiler, configure with --disable-cxx])
    fi
    # Recent failures have come when a standard header is loaded
    # The Intel icpc 10.x compiler fails with <string> if gcc 4.2 is installed. 
    AC_CACHE_CHECK([whether C++ compiler works with string],pac_cv_cxx_compiles_string,[
    AC_LANG_PUSH([C++])
    AC_TRY_COMPILE([#include <string>],[return 0;],pac_cv_cxx_compiles_string=yes,pac_cv_cxx_compiles_string=no)
    AC_LANG_POP([C++])
])
    if test "$pac_cv_cxx_compiles_string" != yes ; then 
        AC_MSG_WARN([The C++ compiler $CXX cannot compile a program containing the <string> header - this may indicate a problem with the C++ installation.  Consider configuing with --disable-cxx])
    fi

    AC_LANG_CPLUSPLUS
    AX_CXX_EXCEPTIONS
    AX_CXX_BOOL
    AX_CXX_NAMESPACES
    if test "$ac_cv_cxx_namespaces" != "yes" ; then
        AC_MSG_ERROR([Namespaces are required for the MPI C++ interface])
    fi
    HAVE_CXX_EXCEPTIONS=0
    AC_SUBST(HAVE_CXX_EXCEPTIONS)
    if test "$ac_cv_cxx_exceptions" = "yes" ; then
        HAVE_CXX_EXCEPTIONS=1
    fi
    # iostream and math are needed for examples/cxx/cxxpi.cxx
    AC_CACHE_CHECK([whether <iostream> available],pac_cv_cxx_has_iostream,[
    AC_TRY_COMPILE([
#include <iostream>
],[using namespace std;],pac_cv_cxx_has_iostream=yes,pac_cv_cxx_has_iostream=no)])
    AX_CXX_NAMESPACE_STD
   
    AC_CACHE_CHECK([whether <math> available],pac_cv_cxx_has_math,[
    AC_TRY_COMPILE([
#include <math>
],[using namespace std;],pac_cv_cxx_has_math=yes,pac_cv_cxx_has_math=no)])

    # GNU changed the calling conventions between minor releases (!!!)
    # This is too hard to detect, but we should be able to detect
    # the version mismatch.  By default, we set the GNU version to 0.
    # In a cross-compiling environment, these can be set with environment
    # variables, either directly or through the standard "CROSS" variable.
    if test -z "$GNUCXX_VERSION" ; then
        if test -n "$CROSS_GNUCXX_VERSION" ; then 
	     GNUCXX_VERSION=$CROSS_GNUCXX_VERSION
        else
             GNUCXX_VERSION=0
        fi
    fi
    if test -z "$GNUCXX_MINORVERSION" ; then 
	if test -n "$CROSS_GNUCXX_MINORVERSION" ; then
	     GNUCXX_MINORVERSION=$CROSS_GNUCXX_MINORVERSION
       	else
             GNUCXX_MINORVERSION=0
        fi
    fi
    if test "$cross_compiling" = "no" -a "$ac_compiler_gnu" = "yes" -a \
       "$GNUCXX_VERSION" = 0 -a "$GNUCXX_MINORVERSION" = 0 ; then
         ac_vals=""
	 AC_MSG_CHECKING([for GNU g++ version])
         AC_TRY_RUN([#include <stdio.h>
int main() {
    int v = -1, m = -1;
    FILE *fp = fopen("conftest.out","w");
#ifdef __GNUC_MINOR__
    m = __GNUC_MINOR__;
#endif
#ifdef __GNUC__
    v = __GNUC__;
#endif
    fprintf( fp, "v=%d, m=%d\n", v, m );
    fclose( fp );
    return 0;
}],ac_vals=`cat conftest.out`)
         if test -n "$ac_vals" ; then
             v=`echo "$ac_vals" | sed -e 's/v=\(.*\),.*/\1/'`
             m=`echo "$ac_vals" | sed -e 's/.*m=\(.*\)/\1/'`
             AC_MSG_RESULT([$v . $m])
             GNUCXX_VERSION=$v
             GNUCXX_MINORVERSION=$m
         else
             AC_MSG_RESULT([unknown])
         fi 
    fi    
    AC_SUBST(GNUCXX_VERSION)
    AC_SUBST(GNUCXX_MINORVERSION)

    bindings="$bindings cxx"
    AC_DEFINE(HAVE_CXX_BINDING,1,[Define if C++ is supported])
    INCLUDE_MPICXX_H='#include "mpicxx.h"'
    AC_SUBST(INCLUDE_MPICXX_H)

    # In order to support the Fortran datatypes within C++, 
    # 
    # FORTRAN_BINDING always has a CPP-time value of either 0 or 1,
    # so that it may be used in #if statements without adding to 
    # the CPP name space
    AC_SUBST(FORTRAN_BINDING)

    # Special C++ datatypes.  Set to DATATYPE NULL first; we'll 
    # replace the ones that we have later, after we have determined
    # the C datatypes
    MPIR_CXX_BOOL=0x0c000000
    MPIR_CXX_COMPLEX=0x0c000000
    MPIR_CXX_DOUBLE_COMPLEX=0x0c000000
    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x0c000000
    AC_SUBST(MPIR_CXX_BOOL)
    AC_SUBST(MPIR_CXX_COMPLEX)
    AC_SUBST(MPIR_CXX_DOUBLE_COMPLEX)
    AC_SUBST(MPIR_CXX_LONG_DOUBLE_COMPLEX)

    # determine rpath and other shared library flags for CXX
    cxx_shlib_conf=src/env/cxx_shlib.conf
    PAC_COMPILER_SHLIB_FLAGS([CXX],[$cxx_shlib_conf])
    AC_SUBST_FILE([cxx_shlib_conf])
fi

if test "$enable_cxx" = yes; then
    # Check if $MPI_DEFAULT_CXXOPTS is valid with $CXX
    if test "$enable_default_optimize" = "yes" \
         -a -n "$MPI_DEFAULT_CXXOPTS" ; then
        if test "$enable_check_compiler_flags" = "yes" ; then
            PAC_CXX_CHECK_COMPILER_OPTION( [$MPI_DEFAULT_CXXOPTS], [
            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
                                     ] )
        else
            CXXFLAGS="$CXXFLAGS $MPI_DEFAULT_CXXOPTS"
        fi
    fi
fi

AC_SUBST(bindings)

# ----------------------------------------------------------------------------
# End of the bindings support
# ----------------------------------------------------------------------------

AC_LANG_C
#
# ----------------------------------------------------------------------------
# Done with the basic argument processing and decisions about which 
# subsystems to build
# ----------------------------------------------------------------------------

# Look for perl.  Perl is used *only* in the tests of the commands such as
# mpiexec, mpicc, etc, in test/commands, and in some of the utility
# programs for processing log files .  If perl is not found,
# MPICH may still be built and used.
# We need the full path to perl since we'll use it as the interpreter for
# a shell script.
AC_PATH_PROG(PERL,perl)
# Look for ar.  If we fail, abort
AC_CHECK_PROGS(AR,ar)
if test -z "$AR" ; then
    AC_MSG_ERROR([The program ar is required for building MPICH.  Make sure that your path includes ar])
fi

# FIXME: this is probably unnecessary now that we only do one "ar" at the end
# (via libtool).  If anything, it's likely to cause problems instead.
# AR_FLAGS provides a way to potentially improve build performance on Mac OSX
AR_FLAGS=cr
# this logic is lame, should really write a real test at some point
AS_CASE([$host],
    # Barry proposes AR_FLAGS="Scq" in trac#754, but that won't work correctly for re-builds
    [*-*-darwin*], [AR_FLAGS=Scr]
)
AC_ARG_VAR(AR_FLAGS,[AR command flags]) # causes AC_SUBST too

# Note that we set RANLIB to true if we don't find it (some systems neither
# need it nor provide it)
AC_CHECK_PROGS(RANLIB,ranlib,true)

# Check for the killall program; this can be used in some of the tests
# in test/commands
AC_CHECK_PROGS(KILLALL,killall,true)

# Does xargs need the -r option to handle the case where the input 
# is empty (gnu utils do, Mac OSX does not accept -r)
xargs_out=`echo "" | xargs ls | wc -l | sed -e 's/ //g'`
if test "$xargs_out" != "0" ; then
    XARGS_NODATA_OPT=-r
fi
AC_SUBST(XARGS_NODATA_OPT)

AC_PROG_INSTALL
PAC_PROG_CHECK_INSTALL_WORKS
#
# On Mac OS/X, install breaks libraries unless used with the -p switch
dnl FIXME not necessary now that we are using libtool
dnl PAC_PROG_INSTALL_BREAKS_LIBS
# We also need mkdir -p.
PAC_PROG_MKDIR_P
PAC_PROG_MAKE

#
# Check for bash to allow more robust shell scripts
AC_PATH_PROG(BASH_SHELL,bash)
#
# Confirm that bash has working arrays.  We can use this to 
# build more robust versions of the scripts (particularly the 
# compliation scripts) by taking advantage of the array features in 
# bash.
bashWorks=no
if test -x "$BASH_SHELL" ; then
changequote(%%,::)dnl
    cat >>conftest <<EOF
#! $BASH_SHELL
A[0]="b"
A[1]="c"
rc=1
if test \${A[1]} != "c" ; then rc=2 ; else rc=0 ; fi
exit \$rc
EOF
changequote([,])dnl
    AC_MSG_CHECKING([whether $BASH_SHELL supports arrays])
    chmod +x conftest
    if ./conftest 2>&1 >/dev/null ; then
        bashWorks=yes
    else
        bashWorks=no
    fi
    rm -f conftest*
    AC_MSG_RESULT($bashWorks)
fi
dnl BUILD_BASH_SCRIPTS used to be an AC_SUBST
AM_CONDITIONAL([BUILD_BASH_SCRIPTS], [test "x$bashWorks" = xyes])

# ----------------------------------------------------------------------------
# At this point, we've finally settled on the value of PMPILIBNAME.  We
# can now set NEEDSPLIB.
if test "$NEEDSPLIB" = yes -a "$PMPILIBNAME" = "$MPILIBNAME" ; then
    NEEDSPLIB=no
fi
# Set the defaults for the Fortran libraries to be the same as the C libraries
if test -z "$MPIFLIBNAME" ; then 
    MPIFLIBNAME=$MPILIBNAME 
fi
if test -z "$PMPIFLIBNAME" ; then
    PMPIFLIBNAME=$PMPILIBNAME
fi

# ----------------------------------------------------------------------------
# 
# Add the steps for debugger support
BUILD_TVDLL=no
if test "$enable_debuginfo" = "yes" ; then
   # We can build the Totalview interface DLL only if we know how to build
   # shared libraries.
   
   # FIXME is this really the right test?
   # No.  Before MPICH 1.5, there was the capability to build the debugger
   # libraries without forcing the build of shared libraries for everything.
   # There may be some way to restore this capability, but until then, we
   # at least cause the configure to cleanly fail with a clear error message 
   if test "X$enable_shared" = "Xyes" ; then
       BUILD_TVDLL=yes
   else
       AC_MSG_ERROR([Building with --enable-debuginfo now requires building with shared library support.  Add --enable-shared and reconfigure])
   fi

   # One more nasty problem.  Totalview relies on debugger symbols 
   # being present in the executable.  Some experimental versions of
   # gcc (3.2 20020329 for ia64) do *not* include the object symbols
   # when debugging.  For HPUX, the necessary linking options are
   #    +noobjdebug
   # for C, Fortran, and C++.  We don't have a good test for this yet,
   # so we add a warning
   if test "$ac_cv_prog_gcc" = "yes" ; then
       AC_MSG_WARN([Some versions of gcc do not include debugging information
within the executable.  Totalview requires this information to detect
an MPICH code.  If you have trouble, try linking with the additional
option 
    +noobjdebug
on all link lines (consider adding it to LDFLAGS)])
   fi

    # The debugger library name cannot be set until we know the extension
    # of shared libraries - the name is so on most Unix system, dylib on OS X.
    AC_DEFINE(HAVE_DEBUGGER_SUPPORT,1,[Define if debugger support is included])
    # The debugger support requires a shared library.  This is handled 
    # below, after we check for compiler support for shared libraries
    # Note: if libdir contains exec_prefix, handle the fact that the
    # default exec_prefix is NONE, which (much later in configure)
    # gets turned into the value of prefix
    ##ENVVAR: MPICH_DEBUGLIBNAME - Set this environment variable to 
    ## override the default name of the debugger support library.
    ## The default name is libtvmpich.$SHLIB_EXT (e.g., libtvmpich.so for
    ## most Unix versions, libtvmpich.dylib for Mac OSX).
    ##ENVVAR END:

    # We are cheating a bit here and reaching inside of the libtool macros to
    # extract the correct shared library extension.  It would be nice if this
    # were publicly available in at least the same way that $libext is.
    eval SHLIB_EXT='"'$shrext_cmds'"'

    if test -z "$MPICH_DEBUGLIBNAME" ; then
        DEBUGLIBNAME=libtvmpich$SHLIB_EXT
    else
        # FIXME DJG I don't think this can be supported arbitrarily by the new
        # build system (I'm not sure it was supported correctly by the old
        # system either)
        AC_MSG_WARN([overriding MPICH_DEBUGLIBNAME is currently untested and probably does not work])
        DEBUGLIBNAME=$MPICH_DEBUGLIBNAME
    fi
    if test "x$exec_prefix" = xNONE ; then
        saveExecPrefix=$exec_prefix
	exec_prefix=$prefix
        eval dlldir=$libdir/$DEBUGLIBNAME
	exec_prefix=$saveExecPrefix
    else
        eval dlldir=$libdir/$DEBUGLIBNAME
    fi
    dlldir='"'$dlldir'"'
    AC_DEFINE_UNQUOTED(MPICH_INFODLL_LOC,$dlldir,[Define as the name of the debugger support library])
fi

# used by automakefiles to conditionally build the DLL
AM_CONDITIONAL([BUILD_DEBUGGER_DLL], [test x$BUILD_TVDLL = xyes])

# ----------------------------------------------------------------------------

nameserv_name=""
# Get the default nameserver, if no nameserver was selected.  A process
# manager may advertise a nameserver name by setting the variable
# MPID_PM_NAMESERVER.
if test "$with_namepublisher" = "default" ; then
   if test -n "$MPID_PM_NAMESERVER" ; then
       with_namepublisher=$MPID_PM_NAMESERVER
   else
       # The default is to use pmi to communicate published names
       with_namepublisher=pmi
   fi
fi

if test "$with_namepublisher" != no -a "$with_namepublisher" != "none" ; then
    case "$with_namepublisher" in 
    none|no) ;;
    # Removed ldap namepublisher hook - we no longer support or distribute
    # the ldap-based name server
    file*)
    # Note that we always build the Makefile for the file version because
    # this name publisher is really too simple to require a 
    # separate configure, and we might as well include a basic
    # name publisher with any MPICH distribution
    # We DO need to extract the directory name that is used for writing 
    # the files, with the User's home directory as the default
    nameserv_name="file"
    basedir=`echo $with_namepublisher | sed -e 's/file://'`
    if test "$basedir" = "$with_namepublisher" ; then
        # Reset since no directory was set.
	basedir='"."';
    fi
    AC_DEFINE_UNQUOTED(FILE_NAMEPUB_BASEDIR,$basedir,[Directory to use in namepub])
    AC_DEFINE(USE_FILE_FOR_NAMEPUB,1,[Define if file should be used for name publisher])
    ;;

    mpd)
    nameserv_name="mpd"
    # The mpd nameserver is specific to the mpd process manager
    foundMPD=no
    for pm_name in $pm_names ; do
        if test "$pm_name" = "mpd" ; then 
	    foundMPD=yes
	    break
	fi
    done
    if test "$foundMPD" = no ; then
        AC_MSG_ERROR([The mpd nameserver requires the mpd process manager])
    fi
    ;;

    *)
    # Check for a new namepublisher
    dir=$with_namepublisher
    # If we later need args, here is where we can strip them off of the
    # with argument
    if test -d "$use_top_srcdir/src/nameserv/$dir" ; then
        if test -x "$use_top_srcdir/src/nameserv/$dir/configure" ; then
	    # Run the configure in this directory if necessary
            subsystems="$subsystems src/nameserv/$dir"
        fi
	nameserv_name=$dir
    else
        AC_MSG_WARN([Unknown name publisher $with_namepublisher])
    fi
    ;;
    esac    
fi
if test -n "$nameserv_name" ; then
   AC_DEFINE(HAVE_NAMEPUB_SERVICE,1,[Define if a name publishing service is available])
fi
AM_CONDITIONAL([BUILD_NAMEPUB_FILE],[test "X$nameserv_name" = "Xfile"])
AM_CONDITIONAL([BUILD_NAMEPUB_MPD],[test "X$nameserv_name" = "Xmpd"])
AM_CONDITIONAL([BUILD_NAMEPUB_PMI],[test "X$nameserv_name" = "Xpmi"])

# In case the documentation targets are used, find doctext and attempt to 
# find the source for the doctext LaTeX style files.  Use "false" if
# doctext is not found
AC_PATH_PROG(DOCTEXT,doctext,false)
export DOCTEXT
AC_SUBST(DOCTEXT)

# ----------------------------------------------------------------------------
# Check for C compiler characteristics
AC_C_CONST
AC_C_VOLATILE
AC_C_RESTRICT
AC_C_INLINE

PAC_C_GNU_ATTRIBUTE
PAC_C_BUILTIN_EXPECT
# We need to check for the endianess in order to implement the
# "external32" representations.  This defines "WORDS_BIGENDIAN when
# the system is bigendian.
# As of autoconf 2.62, this macro takes an additional argument for systems
# that can produce object files for either endianess.  
# With the as-always-incompatible-with-every-version autoconf, the 
# arguments for this macro *changed* in 2.62 to
# (if-bigendian,if-littleendian,unknown,universal)
# The fourth argument is new.
# Also note that the definition emitted by autoheader requires that gcc
# be used to compile the programs - other compilers may not define the 
# non-standard __BIG_ENDIAN__ or __LITTLE_ENDIAN__ CPP names on which 
# autoconf 2.62 now depends.
byteOrdering=unknown
AC_C_BIGENDIAN(byteOrdering=big,byteOrdering=little,,byteOrdering=universal)
case $byteOrdering in
    big)
    # Nothing to do - the c_bigendian macro takes care of it
    :
    ;;
    little)
    AC_DEFINE(WORDS_LITTLEENDIAN,1,[Define if words are little endian])
    ;;
    universal)
    AC_DEFINE(WORDS_UNIVERSAL_ENDIAN,1,[Define if configure will not tell us, for universal binaries])
    ;;
    unknown)
    AC_MSG_ERROR([Unable to determine endianess])
    ;;
esac

# We only need this test if we are using Fortran
if test "$enable_f77" ; then
    PAC_PROG_C_UNALIGNED_DOUBLES(,
[AC_MSG_WARN(Your C compiler $CC does not support unaligned accesses
to doubles.  This is required for interoperation with 
Fortran (the Fortran standard requires it).
You may need to specify an additional argument to your C compiler to 
force it to allow unaligned accesses.)])
fi
# Check for __func__ (defined in C99) or __FUNCTION__ (defined in older GCC)
AC_CACHE_CHECK([whether $CC supports __func__],pac_cv_cc_has___func__,
[AC_TRY_COMPILE([],
 [const char *cp = __func__; ],pac_cv_cc_has___func__=yes,
pac_cv_cc_has___func__=no)])
if test "$pac_cv_cc_has___func__" != "yes" ; then
    AC_CACHE_CHECK([whether $CC supports __FUNCTION__],pac_cv_cc_has___FUNCTION__,
[AC_TRY_COMPILE([],
 [const char *cp = __FUNCTION__;],pac_cv_cc_has___FUNCTION__=yes,
pac_cv_cc_has___FUNCTION__=no)])
fi

# ----------------------------------------------------------------------------
# Check on support for long double and long long types.  Do this before the
# structure alignment test because it will test for including those
# types as well.  In addition, allow the device to suppress support for these
# optional C types by setting MPID_NO_LONG_DOUBLE and/or MPID_NO_LONG_LONG
# to yes.
if test "$MPID_NO_LONG_DOUBLE" != "yes" && test "X$enable_long_double" != "Xno" ; then
    AC_CACHE_CHECK([whether long double is supported],
    pac_cv_have_long_double,[
    AC_TRY_COMPILE(,[long double a;],
    pac_cv_have_long_double=yes,pac_cv_have_long_double=no)])
    if test "$pac_cv_have_long_double" = "yes" ; then
        AC_DEFINE(HAVE_LONG_DOUBLE,1,[Define if long double is supported])
    fi
fi
if test "$MPID_NO_LONG_LONG" != "yes" ; then
    AC_CACHE_CHECK([whether long long is supported],
    pac_cv_have_long_long,[
    AC_TRY_COMPILE(,[long long a;],
    pac_cv_have_long_long=yes,pac_cv_have_long_long=no)])
    if test "$pac_cv_have_long_long" = "yes" ; then
        AC_DEFINE(HAVE_LONG_LONG_INT,1,[Define if long long is supported])
    fi
fi
# ----------------------------------------------------------------------------
# Get default structure alignment for integers
dnl PAC_C_MAX_INTEGER_ALIGN places the default alignment into
dnl pac_cv_c_max_integer_align, with possible values including
dnl packed (byte), largest, two, four, eight (or other failure message).
PAC_C_MAX_INTEGER_ALIGN

if test "$pac_cv_c_max_integer_align" = "packed" ; then
    pac_cv_c_struct_align_nr=1
elif test "$pac_cv_c_max_integer_align" = "two" ; then
    pac_cv_c_struct_align_nr=2
elif test "$pac_cv_c_max_integer_align" = "four" ; then
    pac_cv_c_struct_align_nr=4
elif test "$pac_cv_c_max_integer_align" = "eight" ; then
    pac_cv_c_struct_align_nr=8
fi

if test -n "$pac_cv_c_struct_align_nr" ; then
    AC_DEFINE_UNQUOTED(HAVE_MAX_INTEGER_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of integer structures (for MPI structs)])
    AC_DEFINE_UNQUOTED(HAVE_MAX_STRUCT_ALIGNMENT,$pac_cv_c_struct_align_nr,[Controls byte alignment of structures (for aligning allocated structures)])
fi
# Get default structure alignment for floating point types
dnl PAC_C_MAX_FP_ALIGN places the default alignment into
dnl pac_cv_c_max_fp_align, with possible values including
dnl packed (byte), largest, two, four, eight (or other failure message).
PAC_C_MAX_FP_ALIGN

if test "$pac_cv_c_max_fp_align" = "packed" ; then
    pac_cv_c_fp_align_nr=1
elif test "$pac_cv_c_max_fp_align" = "two" ; then
    pac_cv_c_fp_align_nr=2
elif test "$pac_cv_c_max_fp_align" = "four" ; then
    pac_cv_c_fp_align_nr=4
elif test "$pac_cv_c_max_fp_align" = "eight" ; then
    pac_cv_c_fp_align_nr=8
elif test "$pac_cv_c_max_fp_align" = "sixteen" ; then
    pac_cv_c_fp_align_nr=16
elif test "$pac_cv_c_max_fp_align" = "largest" ; then
    AC_MSG_ERROR([Configure detected unsupported structure alignment rules.])
fi

if test -n "$pac_cv_c_fp_align_nr" ; then
    AC_DEFINE_UNQUOTED(HAVE_MAX_FP_ALIGNMENT,$pac_cv_c_fp_align_nr,[Controls byte alignment of structures with floats, doubles, and long doubles (for MPI structs)])
fi

# Test for the alignment of structs containing only long doubles.
if test "$pac_cv_have_long_double" = yes ; then
    # Check for alignment of just float and double (no long doubles)
    PAC_C_MAX_DOUBLE_FP_ALIGN
    PAC_C_MAX_LONGDOUBLE_FP_ALIGN
    # FIXME: If this alignment is not the same as that for all float types,
    # we need to do something else in the alignment rule code.
    if test "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_longdouble_fp_align" -o \
            "$pac_cv_c_max_fp_align" != "$pac_cv_c_max_double_fp_align" ; then
        AC_MSG_WARN([Structures containing long doubles may be aligned differently from structures with floats or longs.  MPICH does not handle this case automatically and you should avoid assumed extents for structures containing float types.])

	double_align=-1
	case $pac_cv_c_max_double_fp_align in 
	packed) double_align=1 ;;
	two)    double_align=2 ;;
	four)   double_align=4 ;;
	eight)  double_align=8 ;;
	esac
	longdouble_align=-1
	case $pac_cv_c_max_longdouble_fp_align in 
	packed) longdouble_align=1 ;;
	two)    longdouble_align=2 ;;
	four)   longdouble_align=4 ;;
	eight)  longdouble_align=8 ;;
	sixteen)longdouble_align=16 ;;
	esac
	
	AC_DEFINE_UNQUOTED(HAVE_MAX_DOUBLE_FP_ALIGNMENT,$double_align,[Controls byte alignment of structs with doubles])
	AC_DEFINE_UNQUOTED(HAVE_MAX_LONG_DOUBLE_FP_ALIGNMENT,$longdouble_align,[Controls byte alignment of structs with long doubles])
    fi
fi

# Test for weird struct alignment rules that vary padding based on
# size of leading type only.
PAC_C_DOUBLE_POS_ALIGN
if test "$pac_cv_c_double_pos_align" = "yes" ; then
    AC_DEFINE_UNQUOTED(HAVE_DOUBLE_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of doubles in the structure])
fi

# Test for same weird issues with long long int.
PAC_C_LLINT_POS_ALIGN
if test "$pac_cv_c_llint_pos_align" = "yes" ; then
   AC_DEFINE_UNQUOTED(HAVE_LLINT_POS_ALIGNMENT,1,[Controls how alignment is applied based on position of long long ints in the structure])
fi

# Test for double alignment not following all our other carefully constructed rules
PAC_C_DOUBLE_ALIGNMENT_EXCEPTION
if test "$pac_cv_c_double_alignment_exception" = "four" ; then
   AC_DEFINE_UNQUOTED(HAVE_DOUBLE_ALIGNMENT_EXCEPTION,4,[Controls how alignment of doubles is performed, separate from other FP values])
fi

# Test whether pointers can be aligned on a int boundary or require
# a pointer boundary.
AC_MSG_CHECKING([for alignment restrictions on pointers])
AC_TRY_RUN(
changequote(<<,>>)
struct foo { int a; void *b; };
int main() {
    int buf[10];
    struct foo *p1;
    p1=(struct foo*)&buf[0];
    p1->b = (void *)0;
    p1=(struct foo*)&buf[1];
    p1->b = (void *)0;
    return 0;
changequote([,])
},pac_cv_pointers_have_int_alignment=yes,pac_cv_pointers_have_int_alignment=no,pac_cv_pointers_have_int_alignment=unknown)

if test "$pac_cv_pointers_have_int_alignment" != "yes" ; then
   AC_DEFINE(NEEDS_POINTER_ALIGNMENT_ADJUST,1,[define if pointers must be aligned on pointer boundaries])
   AC_MSG_RESULT([pointer])
else
   AC_MSG_RESULT([int or better])
fi

# There are further alignment checks after we test for int64_t etc. below.

# Get the size of the C types for encoding in the basic datatypes and for
# the specific-sized integers
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(unsigned char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(unsigned short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(unsigned long long)
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(void *)

AC_HEADER_STDC
AC_CHECK_HEADERS([stddef.h])
AC_CHECK_SIZEOF(wchar_t, 0, [
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
])

AC_CHECK_SIZEOF(float_int, 0, [typedef struct { float a; int b; } float_int; ])
AC_CHECK_SIZEOF(double_int, 0, [typedef struct { double a; int b; } double_int; ])
AC_CHECK_SIZEOF(long_int, 0, [typedef struct { long a; int b; } long_int; ])
AC_CHECK_SIZEOF(short_int, 0, [typedef struct { short a; int b; } short_int; ])
AC_CHECK_SIZEOF(two_int, 0, [typedef struct { int a; int b; } two_int; ])
AC_CHECK_SIZEOF(long_double_int, 0, [typedef struct { long double a; int b;} long_double_int; ])

# sys/bitypes.h defines the int16_t etc. on some systems (e.g., OSF1).
# Include it when testing for these types
AC_CHECK_HEADER(sys/bitypes.h,[use_bitypes="#include <sys/bitypes.h>"
AC_DEFINE(HAVE_SYS_BITYPES_H,1,[Define if sys/bitypes.h exists])])
# A C99 compliant compiler should have inttypes.h for fixed-size int types
AC_CHECK_HEADERS(inttypes.h stdint.h)

# Check for types
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T

# Temporary issue in autoconf integer type checking (remove when
# autoconf fixes this or provides a workaround for it)
if test "$ac_cv_c_int8_t" != no ; then
    AC_DEFINE(HAVE_INT8_T,1,[Define if int8_t is supported by the C compiler])
fi
if test "$ac_cv_c_int16_t" != no ; then
    AC_DEFINE(HAVE_INT16_T,1,[Define if int16_t is supported by the C compiler])
fi
if test "$ac_cv_c_int32_t" != no ; then
    AC_DEFINE(HAVE_INT32_T,1,[Define if int32_t is supported by the C compiler])
fi
if test "$ac_cv_c_int64_t" != no ; then
    AC_DEFINE(HAVE_INT64_T,1,[Define if int64_t is supported by the C compiler])
fi

# The following make these definitions:
#   define _UINT<n>_T 1 
# if uint<n>_t is available.  E.g., define _UINT8_T as 1 if uint8_t is available
# if not available, define uint<n>_t as the related C type, e.g.,
#   define uint8_t unsigned char
#
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

# Temporary issue in autoconf integer type checking (remove when
# autoconf fixes this or provides a workaround for it)
if test "$ac_cv_c_uint8_t" != no ; then
    AC_DEFINE(HAVE_UINT8_T,1,[Define if uint8_t is supported by the C compiler])
fi
if test "$ac_cv_c_uint16_t" != no ; then
    AC_DEFINE(HAVE_UINT16_T,1,[Define if uint16_t is supported by the C compiler])
fi
if test "$ac_cv_c_uint32_t" != no ; then
    AC_DEFINE(HAVE_UINT32_T,1,[Define if uint32_t is supported by the C compiler])
fi
if test "$ac_cv_c_uint64_t" != no ; then
    AC_DEFINE(HAVE_UINT64_T,1,[Define if uint64_t is supported by the C compiler])
fi

# Other C99 types.
AC_CHECK_HEADERS([stdbool.h complex.h])
AC_CHECK_SIZEOF([_Bool],0,[
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
])
AC_CHECK_SIZEOF([float _Complex],0,[
#ifdef HAVE_COMPLEX_H
#include <complex.h>
#endif
])
AC_CHECK_SIZEOF([double _Complex],0,[
#ifdef HAVE_COMPLEX_H
#include <complex.h>
#endif
])
AS_IF([test "X$pac_cv_have_long_double" = "Xyes"],[
  AC_CHECK_SIZEOF([long double _Complex],0,[
#ifdef HAVE_COMPLEX_H
#include <complex.h>
#endif
  ])
])

# we need really could just use the result of AC_CHECK_SIZEOF, but having a
# HAVE_typename macro is useful for consistency
AC_CHECK_TYPES([_Bool, float _Complex, double _Complex])

AS_IF([test "X$pac_cv_have_long_double" = "Xyes"],[
  AC_CHECK_TYPES([long double _Complex])
])

# Generate a hex version of the size of each type
for type in short int long long_long float double long_double wchar_t \
    float_int double_int long_int short_int two_int long_double_int     \
    _Bool float__Complex double__Complex long_double__Complex ; do
    eval len=\$ac_cv_sizeof_$type
    if test -z "$len" ; then 
       len=0
       # Check for sizes from the CHECK_SIZEOF_DERIVED macro
       eval pclen=\$ac_cv_sizeof_$type
       if test -n "$pclen" ; then
           len=$pclen
       else
           # check for a non-optional type
           if test $type != long_long -a \
                   $type != long_double -a \
                   $type != long_double_int -a \
                   $type != _Bool -a \
                   $type != float__Complex -a \
                   $type != double__Complex -a \
                   $type != long_double__Complex ; then
               AC_MSG_ERROR([Configure was unable to determine the size of $type ; if cross compiling,
use the environment variables CROSS_SIZEOF_typename, e.g., CROSS_SIZEOF_SHORT,
or use the --with-cross=file configure option to specify a file containing
Bourne (sh) shell assignments to CROSS_SIZEOF_typename for all datatype 
types.  The program maint/getcross.c can be compiled and run on the target
system; this program outputs an appropriate file for the --with-cross option])
	   fi
       fi
    fi
    #
    # Take len and turn it into two hex digits (there are 8 bits available
    # in the built-in datatype handle for the length; see
    # src/mpid/common/datatype/mpid_datatype.h)
    if test "$len" -gt 255 ; then
         AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type $type is $len bytes)]) 
    fi
    tmplen=$len
    hexlen=""
    while test $tmplen -gt 0 ; do
        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
	case $lowdigit in 
         10) char=a ;;
	 11) char=b ;;
	 12) char=c ;;
	 13) char=d ;;
	 14) char=e ;;
	 15) char=f ;;
	  *) char=$lowdigit ;;
	esac
	hexlen="$char$hexlen"
	tmplen=`expr $tmplen / 16`
    done
    if test $len -lt 16 ; then
        hexlen="0$hexlen"
    fi
    if test $len = 0 ; then
        # This sometimes happens for wchar_t
        hexlen="00";
    fi
    eval len_$type=$hexlen
done
# By definition, sizeof char is 1
MPI_CHAR="0x4c000101"
MPI_UNSIGNED_CHAR="0x4c000102"
MPI_SHORT="0x4c00${len_short}03"
MPI_UNSIGNED_SHORT="0x4c00${len_short}04"
MPI_INT="0x4c00${len_int}05"
MPI_UNSIGNED_INT="0x4c00${len_int}06"
MPI_LONG="0x4c00${len_long}07"
MPI_UNSIGNED_LONG="0x4c00${len_long}08"
if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
    MPI_LONG_LONG="0x4c00${len_long_long}09"
else 
    MPI_LONG_LONG=MPI_DATATYPE_NULL;
fi
MPI_FLOAT="0x4c00${len_float}0a"
MPI_DOUBLE="0x4c00${len_double}0b"
if test "$len_long_double" != 0 -a "$MPID_NO_LONG_DOUBLE" != yes ; then
    MPI_LONG_DOUBLE="0x4c00${len_long_double}0c"
else
    MPI_LONG_DOUBLE=MPI_DATATYPE_NULL
fi
# If you change MPI_BYTE, you must change it in src/binding/f77/buildiface
MPI_BYTE="0x4c00010d"
MPI_WCHAR="0x4c00${len_wchar_t}0e"
MPI_PACKED="0x4c00010f"
MPI_LB="0x4c000010"
MPI_UB="0x4c000011"
#
# These should define the mixed types *only* for contiguous data.
# For example, MPI_SHORT_INT may have a gap; it will need to be defined
# as a derived type instead.  For IA32, this only affects short_int.
MPI_2INT="0x4c00${len_two_int}16"
#
# For now we aren't being too clever about figuring out which of these
# are in fact contiguous, so these are all allocated as "real" types.
#
# These values correspond to direct types 0..5.
#
dnl MPI_FLOAT_INT="0x4c00${len_float_int}12"
dnl MPI_DOUBLE_INT="0x4c00${len_double_int}13"
dnl MPI_LONG_INT="0x4c00${len_long_int}14"
dnl MPI_SHORT_INT="0x4c00${len_short_int}15"
dnl MPI_LONG_DOUBLE_INT="0x4c00${len_long_double_int}17"
MPI_FLOAT_INT="0x8c000000"
MPI_DOUBLE_INT="0x8c000001"
MPI_LONG_INT="0x8c000002"
MPI_SHORT_INT="0x8c000003"
if test "$MPID_NO_LONG_DOUBLE" != yes ; then
    MPI_LONG_DOUBLE_INT="0x8c000004"
else
    MPI_LONG_DOUBLE_INT=MPI_DATATYPE_NULL
fi

# 2 additional predefined types named in MPI-2
MPI_SIGNED_CHAR="0x4c000118"
if test "$len_long_long" != 0 -a "$MPID_NO_LONG_LONG" != yes ; then
    MPI_UNSIGNED_LONG_LONG="0x4c00${len_long_long}19"
else
    MPI_UNSIGNED_LONG_LONG=MPI_DATATYPE_NULL
fi

AC_SUBST(MPI_CHAR)
AC_SUBST(MPI_UNSIGNED_CHAR)
AC_SUBST(MPI_SHORT)
AC_SUBST(MPI_UNSIGNED_SHORT)
AC_SUBST(MPI_INT)
AC_SUBST(MPI_UNSIGNED_INT)
AC_SUBST(MPI_LONG)
AC_SUBST(MPI_UNSIGNED_LONG)
AC_SUBST(MPI_LONG_LONG)
AC_SUBST(MPI_FLOAT)
AC_SUBST(MPI_DOUBLE)
AC_SUBST(MPI_LONG_DOUBLE)
AC_SUBST(MPI_BYTE)
AC_SUBST(MPI_WCHAR)
AC_SUBST(MPI_PACKED)
AC_SUBST(MPI_LB)
AC_SUBST(MPI_UB)
AC_SUBST(MPI_FLOAT_INT)
AC_SUBST(MPI_DOUBLE_INT)
AC_SUBST(MPI_LONG_INT)
AC_SUBST(MPI_SHORT_INT)
AC_SUBST(MPI_2INT)
AC_SUBST(MPI_LONG_DOUBLE_INT)
AC_SUBST(MPI_SIGNED_CHAR)
AC_SUBST(MPI_UNSIGNED_LONG_LONG)
#
# FIXME: Leftover from separate fortran system
## Export the basic C types so that the Fortran system can use them
#export MPI_CHAR
#export MPI_SHORT
#export MPI_INT
#export MPI_LONG
#export MPI_LONG_LONG
#export MPI_FLOAT
#export MPI_DOUBLE
#export MPI_LONG_DOUBLE
#
# Size-specific types.  Initialize as NULL
MPI_REAL4=MPI_DATATYPE_NULL
MPI_REAL8=MPI_DATATYPE_NULL
MPI_REAL16=MPI_DATATYPE_NULL
MPI_COMPLEX8=MPI_DATATYPE_NULL
MPI_COMPLEX16=MPI_DATATYPE_NULL
MPI_COMPLEX32=MPI_DATATYPE_NULL
MPI_INTEGER1=MPI_DATATYPE_NULL
MPI_INTEGER2=MPI_DATATYPE_NULL
MPI_INTEGER4=MPI_DATATYPE_NULL
MPI_INTEGER8=MPI_DATATYPE_NULL
MPI_INTEGER16=MPI_DATATYPE_NULL
AC_SUBST(MPI_REAL4)
AC_SUBST(MPI_REAL8)
AC_SUBST(MPI_REAL16)
AC_SUBST(MPI_COMPLEX8)
AC_SUBST(MPI_COMPLEX16)
AC_SUBST(MPI_COMPLEX32)
AC_SUBST(MPI_INTEGER1)
AC_SUBST(MPI_INTEGER2)
AC_SUBST(MPI_INTEGER4)
AC_SUBST(MPI_INTEGER8)
AC_SUBST(MPI_INTEGER16)
export MPI_REAL4
export MPI_REAL8
export MPI_REAL16
export MPI_COMPLEX8
export MPI_COMPLEX16
export MPI_COMPLEX32
export MPI_INTEGER1
export MPI_INTEGER2
export MPI_INTEGER4
export MPI_INTEGER8
export MPI_INTEGER16
#
# Try to find corresponding types for the size-specific types.
#
# Assume that the float/double/long double are simply spaced
# Datatypes used up through 26 in Fortran
# 27,28,29,2a,2b,2c
if test "$ac_cv_sizeof_float" = "4" ; then
    MPI_REAL4="0x4c000427"
    MPI_COMPLEX8="0x4c000828"
    MPIR_REAL4_CTYPE=float
fi
if test "$ac_cv_sizeof_double" = "8" ; then
    MPI_REAL8="0x4c000829"
    MPI_COMPLEX16="0x4c00102a"
    MPIR_REAL8_CTYPE=double
fi
if test "$ac_cv_sizeof_long_double" = "16" -a "$MPID_NO_LONG_DOUBLE" != yes ; then
    MPI_REAL16="0x4c00102b"
    MPI_COMPLEX32="0x4c00202c"
    MPIR_REAL16_CTYPE="long double"
fi
if test -n "$MPIR_REAL4_CTYPE" ; then
    AC_DEFINE_UNQUOTED(MPIR_REAL4_CTYPE,$MPIR_REAL4_CTYPE,[C type to use for MPI_REAL4])
fi
if test -n "$MPIR_REAL8_CTYPE" ; then
    AC_DEFINE_UNQUOTED(MPIR_REAL8_CTYPE,$MPIR_REAL8_CTYPE,[C type to use for MPI_REAL8])
fi
if test -n "$MPIR_REAL16_CTYPE" ; then
    AC_DEFINE_UNQUOTED(MPIR_REAL16_CTYPE,$MPIR_REAL16_CTYPE,[C type to use for MPI_REAL16])
fi
# For complex 8/16/32, we assume that these are 2 consequetive real4/8/16
#
# Search for the integer types
for type in char short int long long_long ; do
    # ctype is a valid C type which we can use to declare a C version of 
    # this item
    ctype=`echo $type | sed 's/_/ /'`
    eval len=\$ac_cv_sizeof_$type
    if test -n "$len" ; then 
    case $len in 
    1) if test "$MPI_INTEGER1" = "MPI_DATATYPE_NULL" ; then
           MPI_INTEGER1="0x4c00012d"
	   MPIR_INTEGER1_CTYPE="$ctype"
       fi
       ;;
    2) if test "$MPI_INTEGER2" = "MPI_DATATYPE_NULL" ; then
           MPI_INTEGER2="0x4c00022f"
	   MPIR_INTEGER2_CTYPE="$ctype"
       fi
       ;;
    4) if test "$MPI_INTEGER4" = "MPI_DATATYPE_NULL" ; then
           MPI_INTEGER4="0x4c000430"
	   MPIR_INTEGER4_CTYPE="$ctype"
       fi
       ;;
    8) if test "$MPI_INTEGER8" = "MPI_DATATYPE_NULL" ; then
           MPI_INTEGER8="0x4c000831"
	   MPIR_INTEGER8_CTYPE="$ctype"
       fi
       ;;
    16) if test "$MPI_INTEGER16" = "MPI_DATATYPE_NULL" ; then
           MPI_INTEGER16="0x4c001032"
	   MPIR_INTEGER16_CTYPE="$ctype"
       fi
       ;;
    *)
    ;;
    esac
    fi
done
#
# Add the definitions of these types
if test -n "$MPIR_INTEGER1_CTYPE" ; then
    AC_DEFINE_UNQUOTED(MPIR_INTEGER1_CTYPE,$MPIR_INTEGER1_CTYPE,[C type to use for MPI_INTEGER1])
fi
if test -n "$MPIR_INTEGER2_CTYPE" ; then
   AC_DEFINE_UNQUOTED(MPIR_INTEGER2_CTYPE,$MPIR_INTEGER2_CTYPE,[C type to use for MPI_INTEGER2])
fi
if test -n "$MPIR_INTEGER4_CTYPE" ; then
   AC_DEFINE_UNQUOTED(MPIR_INTEGER4_CTYPE,$MPIR_INTEGER4_CTYPE,[C type to use for MPI_INTEGER4])
fi
if test -n "$MPIR_INTEGER8_CTYPE" ; then
   AC_DEFINE_UNQUOTED(MPIR_INTEGER8_CTYPE,$MPIR_INTEGER8_CTYPE,[C type to use for MPI_INTEGER8])
fi
if test -n "$MPIR_INTEGER16_CTYPE" ; then
   AC_DEFINE_UNQUOTED(MPIR_INTEGER16_CTYPE,$MPIR_INTEGER16_CTYPE,[C type to use for MPI_INTEGER16])
fi

# ----------------------------------------------------------------------------

# C99 types
# The predefined types must be distinct types (as opposed to aliases to MPI_INT
# or MPI_WHATEVER) in order to correctly support MPI_Type_{get,set}_name.
#
# FIXME the "basic id" portion should be automatically assigned.  It's too easy
# to have a conflict when this is done by hand.
#
# Because we make up a matching type for the fixed-width types if one doesn't
# exist, we don't ever set these to MPI_DATATYPE_NULL.  If we come across a
# platform where 64-bit sizes aren't supported just add a test like the other
# types.
MPI_INT8_T=0x4c000137
MPI_INT16_T=0x4c000238
MPI_INT32_T=0x4c000439
MPI_INT64_T=0x4c00083a
MPI_UINT8_T=0x4c00013b
MPI_UINT16_T=0x4c00023c
MPI_UINT32_T=0x4c00043d
MPI_UINT64_T=0x4c00083e

# The compiler may or may not support these types, depending on its level of C99
# compliance.  We check for each one individually before assigning a handle
# number.
MPI_C_BOOL=MPI_DATATYPE_NULL
MPI_C_FLOAT_COMPLEX=MPI_DATATYPE_NULL
MPI_C_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
MPI_C_LONG_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
if test ${len__Bool} != 0 ; then
    MPI_C_BOOL=0x4c00${len__Bool}3f
fi
if test ${len_float__Complex} != 0 ; then
    MPI_C_FLOAT_COMPLEX=0x4c00${len_float__Complex}40
fi
if test ${len_double__Complex} != 0 ; then
    MPI_C_DOUBLE_COMPLEX=0x4c00${len_double__Complex}41
fi
if test ${len_long_double__Complex} != 0 ; then
    MPI_C_LONG_DOUBLE_COMPLEX=0x4c00${len_long_double__Complex}42
fi

AC_SUBST(MPI_INT8_T)
AC_SUBST(MPI_INT16_T)
AC_SUBST(MPI_INT32_T)
AC_SUBST(MPI_INT64_T)
AC_SUBST(MPI_UINT8_T)
AC_SUBST(MPI_UINT16_T)
AC_SUBST(MPI_UINT32_T)
AC_SUBST(MPI_UINT64_T)
AC_SUBST(MPI_C_BOOL)
AC_SUBST(MPI_C_FLOAT_COMPLEX)
AC_SUBST(MPI_C_DOUBLE_COMPLEX)
AC_SUBST(MPI_C_LONG_DOUBLE_COMPLEX)
export MPI_INT8_T
export MPI_INT16_T
export MPI_INT32_T
export MPI_INT64_T
export MPI_UINT8_T
export MPI_UINT16_T
export MPI_UINT32_T
export MPI_UINT64_T
export MPI_C_BOOL
export MPI_C_FLOAT_COMPLEX
export MPI_C_DOUBLE_COMPLEX
export MPI_C_LONG_DOUBLE_COMPLEX


# ----------------------------------------------------------------------------
# We can now create the Fortran versions of the datatype values, along with
# some of the other datatype-dependent sizes

# There are two parts to handling the datatypes:
#    Convert the C datatype values to their Fortran equivalent.  This
#    involves converting the hex values for the C version into decimal
#    since standard Fortran does not have hex constants
#
#    Determine the existence of the Fortran 'sized' types and set those
#    values.
#
# In addition, we need to look at a few additional constants that depend
# on how the compiler sizes some datatypes.  These are:
#    STATUS_SIZE, INTEGER_KIND, ADDRESS_KIND, and OFFSET_KIND
# 
# ----------------------------------------------------------------------------
if test "$enable_f77" = yes ; then
    # Up to size checking code in master configure.ac (where it tries to 
    # find the matching C sizes) as part of defining mpi_integer8 etc.
    # The results are available in pac_cv_sizeof_f77_<type>
    # Size is 0 if unknown or unavailable (or cross-compiling)
    # Due to limitations in autoconf, we cannot put these into a loop.
    # We also check integer to find the type of MPI_Fint
    #
    # Cross-compilation results can be included with the --with-cross=file
    # option.
    CROSS_F77_SIZEOF_INTEGER=${CROSS_F77_SIZEOF_INTEGER:-0}
    CROSS_F77_SIZEOF_REAL=${CROSS_F77_SIZEOF_REAL:-0}
    CROSS_F77_SIZEOF_DOUBLE_PRECISION=${CROSS_F77_SIZEOF_DOUBLE_PRECISION:-0}
    PAC_PROG_F77_CHECK_SIZEOF_EXT(integer,$CROSS_F77_SIZEOF_INTEGER)
    PAC_PROG_F77_CHECK_SIZEOF_EXT(real,$CROSS_F77_SIZEOF_REAL)
    PAC_PROG_F77_CHECK_SIZEOF_EXT(double precision,$CROSS_F77_SIZEOF_DOUBLE_PRECISION)
    AC_LANG_FORTRAN77
    # If we have sizes for real and double, we do not need to call 
    # mpir_get_fsize at run time.
    # For the size-defined types (e.g., integer*2), we assume that if the
    # compiler allows it, it has the stated size.
    AC_CACHE_CHECK([whether integer*1 is supported],pac_cv_fort_integer1,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*1 i])],
         pac_cv_fort_integer1=yes,
         pac_cv_fort_integer1=no)])
    AC_CACHE_CHECK([whether integer*2 is supported],pac_cv_fort_integer2,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*2 i])],
        pac_cv_fort_integer2=yes,
        pac_cv_fort_integer2=no)])
    AC_CACHE_CHECK([whether integer*4 is supported],pac_cv_fort_integer4,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*4 i])],
        pac_cv_fort_integer4=yes,
        pac_cv_fort_integer4=no)])
    AC_CACHE_CHECK([whether integer*8 is supported],pac_cv_fort_integer8,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*8 i])],
        pac_cv_fort_integer8=yes,
        pac_cv_fort_integer8=no)])
    AC_CACHE_CHECK([whether integer*16 is supported],pac_cv_fort_integer16,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*16 i])],
        pac_cv_fort_integer16=yes,
        pac_cv_fort_integer16=no)])
    AC_CACHE_CHECK([whether real*4 is supported],pac_cv_fort_real4,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*4 a])],
        pac_cv_fort_real4=yes,
        pac_cv_fort_real4=no)])
    AC_CACHE_CHECK([whether real*8 is supported],pac_cv_fort_real8,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*8 a])],
        pac_cv_fort_real8=yes,
        pac_cv_fort_real8=no)])
    AC_CACHE_CHECK([whether real*16 is supported],pac_cv_fort_real16,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      real*16 a])],
        pac_cv_fort_real16=yes,
        pac_cv_fort_real16=no)])

    # Create the default datatype names for the standard MPI Fortran types
    MPI_CHARACTER=0x4c00011a
    AC_SUBST(MPI_CHARACTER)

    if test -z "$pac_cv_f77_sizeof_integer" -o \
       "X$pac_cv_f77_sizeof_integer" = "X0" ; then
        AC_MSG_ERROR([Unable to configure with Fortran support because configure could not determine the size of a Fortran INTEGER.  Consider setting CROSS_F77_SIZEOF_INTEGER to the length in bytes of a Fortran INTEGER])
    fi
    len_integer=$pac_cv_f77_sizeof_integer
    # Convert to two digit hex
    len=$len_integer
    #
    # Take len and turn it into two hex digits (there are 8 bits available
    # in the built-in datatype handle for the length; see
    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
    # from the code in mpich/configure.ac 
    if test "$len" -gt 255 ; then
        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type INTEGER is $len bytes)]) 
    fi
    tmplen=$len
    hexlen=""
    while test $tmplen -gt 0 ; do
        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
        case $lowdigit in 
        10) char=a ;;
        11) char=b ;;
        12) char=c ;;
        13) char=d ;;
        14) char=e ;;
        15) char=f ;;
         *) char=$lowdigit ;;
        esac
        hexlen="$char$hexlen"
        tmplen=`expr $tmplen / 16`
    done
    if test $len -lt 16 ; then
        hexlen="0$hexlen"
    fi
    len_integer=$hexlen
    if test "$len_integer" = 0 ; then
        # We have a problem
        AC_MSG_WARN([Unable to determine size of an INTEGER type; using 4])
        # We make the length 4
        len_integer="04"
    fi
    MPI_INTEGER=0x4c00${len_integer}1b
    MPI_REAL=0x4c00${len_integer}1c
    MPI_LOGICAL=0x4c00${len_integer}1d
    AC_SUBST(MPI_INTEGER)
    AC_SUBST(MPI_REAL)
    AC_SUBST(MPI_LOGICAL)

    if test -z "$pac_cv_f77_sizeof_double_precision" ; then
        AC_MSG_ERROR([Unable to configure with Fortran support because configure could not determine the size of a Fortran DOUBLE PRECISION.  Consider setting CROSS_F77_SIZEOF_DOUBLE_PRECISION to the length in bytes of a Fortran DOUBLE PRECISION])
    fi
    len_double=$pac_cv_f77_sizeof_double_precision
    # Convert to two digit hex
    len=$len_double
    #
    # Take len and turn it into two hex digits (there are 8 bits available
    # in the built-in datatype handle for the length; see
    # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
    # from the code in mpich/configure.ac 
    if test "$len" -gt 255 ; then
        AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE is $len bytes)]) 
    fi
    tmplen=$len
    hexlen=""
    while test $tmplen -gt 0 ; do
        lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
        case $lowdigit in 
        10) char=a ;;
        11) char=b ;;
        12) char=c ;;
        13) char=d ;;
        14) char=e ;;
        15) char=f ;;
         *) char=$lowdigit ;;
        esac
        hexlen="$char$hexlen"
        tmplen=`expr $tmplen / 16`
    done
    if test $len -lt 16 ; then
        hexlen="0$hexlen"
    fi 
    len_double=$hexlen
    if test "$len_double" = 0 ; then
       # We have a problem
       AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
       # We make the length 8
       len_double="08"
    fi

    # Provide the corresponding C types for MPI_REAL and MPI_DOUBLE
    AC_MSG_CHECKING([for C type matching Fortran real])
    noval=yes
    for c_type in float double "long_double" ; do
        eval ctypelen=\$"ac_cv_sizeof_$c_type"
        if test "$pac_cv_f77_sizeof_real" = "$ctypelen" -a \
          "$ctypelen" -gt 0 ; then
	    c_type=`echo $c_type | sed -e 's/_/ /g'`
	    AC_MSG_RESULT($c_type)
	    MPIR_FC_REAL_CTYPE=$c_type
	    noval="no"
	    break
        fi
    done
    if test "$noval" = "yes" ; then
        # Set a default
        MPIR_FC_REAL_CTYPE="float"
        AC_MSG_RESULT([unavailable])
    fi

    noval=yes
    AC_MSG_CHECKING([for C type matching Fortran double])
    for c_type in double "long_double" float ; do
        eval ctypelen=\$"ac_cv_sizeof_$c_type"
        if test "$pac_cv_f77_sizeof_double_precision" = "$ctypelen" -a \
          "$ctypelen" -gt 0 ; then
	    c_type=`echo $c_type | sed -e 's/_/ /g'`
	    AC_MSG_RESULT($c_type)
	    MPIR_FC_DOUBLE_CTYPE=$c_type
	    noval="no"
	    break
        fi
    done
    if test "$noval" = "yes" ; then
        # Set a default
        MPIR_FC_DOUBLE_CTYPE="double"
        AC_MSG_RESULT([unavailable])
    fi

    # These are needed to correctly implement the MPI reduction operations
    AC_DEFINE_UNQUOTED([MPIR_FC_REAL_CTYPE],[$MPIR_FC_REAL_CTYPE],
     [The C type for FORTRAN REAL])
    AC_DEFINE_UNQUOTED([MPIR_FC_DOUBLE_CTYPE],[$MPIR_FC_DOUBLE_CTYPE],
     [The C type for FORTRAN DOUBLE PRECISION])

    # Use the proper length values for these items in case we are building
    # with Fortran integers that are not the same size as C ints and 
    # reals and double precision that are the same size (not valid Fortran,
    # but used by some applications)

    len_2integer=`expr 2 \* $len_integer`
    len_2real=`expr 2 \* $len_integer`
    len_doublecplx=`expr $pac_cv_f77_sizeof_double_precision \* 2`
    if test "$len_doublecplx" = 0 ; then
        # We have a problem
        AC_MSG_WARN([Unable to determine size of a DOUBLE PRECISION type; using 8])
        # We make the length 8*2 (in hex)
        len_doublecplx="16"
    fi

    for lenname in len_2integer len_2real len_doublecplx ; do
        eval len=\$$lenname
	if test "$len" -gt 255 ; then
            AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type $lenname is $len bytes)]) 
	fi	    
    	tmplen=$len
        hexlen=""
        while test $tmplen -gt 0 ; do
            lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
            case $lowdigit in 
            10) char=a ;;
            11) char=b ;;
            12) char=c ;;
            13) char=d ;;
            14) char=e ;;
            15) char=f ;;
            *) char=$lowdigit ;;
            esac
            hexlen="$char$hexlen"
            tmplen=`expr $tmplen / 16`
        done
        if test $len -lt 16 ; then
            hexlen="0$hexlen"
        fi 
        eval ${lenname}=$hexlen
        if test "$hexlen" = 0 ; then
           # We have a problem
           AC_MSG_WARN([Unable to determine size of a $lenname type; using 8])
           # We make the length 8
           eval ${lenname}=$hexlen
        fi
    done

    MPI_DOUBLE_PRECISION=0x4c00${len_double}1f
    MPI_2INTEGER=0x4c00${len_2integer}20
    MPI_2REAL=0x4c00${len_2real}21
    MPI_COMPLEX=0x4c00${len_2real}1e
    AC_SUBST(MPI_COMPLEX)
    AC_SUBST(MPI_DOUBLE_PRECISION)
    AC_SUBST(MPI_2INTEGER)
    AC_SUBST(MPI_2REAL)

dnl     len=$len_doublecplx
dnl     #
dnl     # Take len and turn it into two hex digits (there are 8 bits available
dnl     # in the built-in datatype handle for the length; see
dnl     # src/mpid/common/datatype/mpid_datatype.h).  This code is taken
dnl     # from the code in mpich/configure.ac 
dnl     if test "$len" -gt 255 ; then
dnl         AC_MSG_ERROR([Type sizes greater than 255 bytes are not supported (type DOUBLE COMPLEX is $len bytes)]) 
dnl     fi
dnl     tmplen=$len
dnl     hexlen=""
dnl     while test $tmplen -gt 0 ; do
dnl         lowdigit=`expr $tmplen - 16 \* \( $tmplen / 16 \)`
dnl         case $lowdigit in 
dnl         10) char=a ;;
dnl         11) char=b ;;
dnl         12) char=c ;;
dnl         13) char=d ;;
dnl         14) char=e ;;
dnl         15) char=f ;;
dnl          *) char=$lowdigit ;;
dnl         esac
dnl         hexlen="$char$hexlen"
dnl         tmplen=`expr $tmplen / 16`
dnl     done
dnl     if test $len -lt 16 ; then
dnl         hexlen="0$hexlen"
dnl     fi
dnl     len_doublecplx=$hexlen

    MPI_DOUBLE_COMPLEX=0x4c00${len_doublecplx}22
    MPI_2DOUBLE_PRECISION=0x4c00${len_doublecplx}23
    MPI_2COMPLEX=0x4c00${len_doublecplx}24
    AC_SUBST(MPI_DOUBLE_COMPLEX)
    AC_SUBST(MPI_2DOUBLE_PRECISION)
    AC_SUBST(MPI_2COMPLEX)

    #
    # Temporary for the vast majority of systems that use 4 byte reals and
    # 8 byte doubles
    # Lengths at this point are in hex, hence "10" = 10 base 16 = 16 base 10.
    if test "$len_double" = "08" ; then
        F77_COMPLEX8=$MPI_COMPLEX
    fi
    if test "$len_doublecplx" = "10" ; then
        F77_COMPLEX16=$MPI_DOUBLE_COMPLEX
    fi
    if test "$len_long_double" = "10" -a "$MPID_NO_LONG_DOUBLE" != "yes" ; then
        F77_COMPLEX32="0x4c002025"
    else
        F77_COMPLEX32="MPI_DATATYPE_NULL"
    fi

    len_2dc=`expr $pac_cv_f77_sizeof_double_precision \* 4`
    firstdigit=0
    seconddigit=0
    while test $len_2dc -ge 16 ; do
        firstdigit=`expr $firstdigit + 1`
        len_2dc=`expr $len_2dc - 16`    
    done
    case $len_2dc in
        10) seconddigit=a ;;
        11) seconddigit=b ;;
        12) seconddigit=c ;;
        13) seconddigit=d ;;
        14) seconddigit=e ;;
        15) seconddigit=f ;;
         *) seconddigit=$len_2dc ;;
    esac
    len_2dc="$firstdigit$seconddigit"
    #echo "2double complex = $len_2dc"
    MPI_2DOUBLE_COMPLEX=0x4c00${len_2dc}25
    AC_SUBST(MPI_2DOUBLE_COMPLEX)
    MPI_F77_PACKED=$MPI_PACKED
    MPI_F77_UB=$MPI_UB
    MPI_F77_LB=$MPI_LB
    MPI_F77_BYTE=$MPI_BYTE
    AC_SUBST(MPI_F77_PACKED)
    AC_SUBST(MPI_F77_UB)
    AC_SUBST(MPI_F77_LB)
    AC_SUBST(MPI_F77_BYTE)
    #
    # We must convert all hex values to decimal (!)
    # It would be nice to use expr to extract the next character rather than
    # the heavier-weight sed, but expr under Tru64 Unix discards leading zeros,
    # even when used only with the match (:) command.  Rather than have 
    # configure figure out if expr works, we just use sed.  Sigh.
    for var in CHARACTER INTEGER REAL LOGICAL DOUBLE_PRECISION COMPLEX \
        DOUBLE_COMPLEX 2INTEGER 2REAL 2COMPLEX 2DOUBLE_PRECISION \
        2DOUBLE_COMPLEX F77_PACKED F77_UB F77_LB F77_BYTE; do  
        fullvar="MPI_$var"
        eval fullvarvalue=\$$fullvar
        #echo "$fullvar = $fullvarvalue"
        value=0
        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
        for pos in 3 4 5 6 7 8 9 10 ; do
            # This works, even for Tru64, because only a single character
  	    # is extracted
            char=`expr $fullvarvalue : '\(.\)'`
	    # FIXME: Tru64 Unix eliminates leading zeros (!)
 	    # How do we fix something that broken?
	    fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
            case $char in 
                a) char=10 ;;
	        b) char=11 ;;
	        c) char=12 ;;
	        d) char=13 ;;
	        e) char=14 ;;
	        f) char=15 ;;
            esac
            value=`expr $value \* 16 + $char`
        done
        #echo "$fullvar = $value"
	if test "X$value" = "X"; then
            eval origvarvalue=\$$fullvar
	    AC_MSG_ERROR([Internal Error: Failed to convert $fullvar value to hex!  Original value was $origvarvalue])
        fi
        eval $fullvar=$value
    done
    AC_LANG_C

    # Now, handle the sized types
    #
    # Preload the C mpi types
    # THESE MUST MATCH THE DEFINITIONS IN MPI.H and MPIF.H
    # We use these to match the optional Fortran types
    char_mpi=${MPI_CHAR:-0}
    short_mpi=${MPI_SHORT:-0}
    int_mpi=${MPI_INT:-0}
    long_mpi=${MPI_LONG:-0}
    long_long_mpi=${MPI_LONG_LONG:-0}
    float_mpi=${MPI_FLOAT:-0}
    double_mpi=${MPI_DOUBLE:-0}
    long_double_mpi=${MPI_LONG_DOUBLE:-0}

    #
    # The following code was correct for MPI-1, which allowed these datatypes
    # to be an alias for another MPI type.  MPI-2 requires these to 
    # be distinct types, so these are enumerated
    if test "$use_alias_types" = yes ; then
        for len in 1 2 4 8 16 ; do
            eval F77_INTEGER$len=0
            #eval testval=\$"pac_cv_f77_sizeof_integer_$len"
            eval testval=\$"pac_cv_fort_integer$len"
            if test "$testval" = no ; then continue ; fi
	    testval=$len
            noval="yes"
            AC_MSG_CHECKING([for C type matching Fortran integer*$len])
            for c_type in char short int long "long_long" ; do
	        eval ctypelen=\$"ac_cv_sizeof_$c_type"
  	        if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
	            AC_MSG_RESULT($c_type)
  	            eval F77_INTEGER$len=\$"${c_type}_mpi"
	            noval="no"
	            break
                fi
            done
            if test "$noval" = "yes" ; then
                AC_MSG_RESULT([unavailable])
            fi
        done

        # Complex is set separately above
        for len in 4 8 16 ; do
            len2=`expr $len + $len`
            eval F77_REAL$len=0
            #eval F77_COMPLEX$len2=0
            #eval testval=\$"pac_cv_f77_sizeof_real_$len"
            eval testval=\$"pac_cv_fort_real$len"
            if test "$testval" = no ; then continue ; fi
	    testval=$len
            noval="yes"
            AC_MSG_CHECKING([for C type matching Fortran real*$len])
            for c_type in float double "long_double" ; do
	        eval ctypelen=\$"ac_cv_sizeof_$c_type"
	        if test "$testval" = "$ctypelen" -a "$ctypelen" -gt 0 ; then
	            AC_MSG_RESULT($c_type)
  	            eval F77_REAL$len=\$"${c_type}_mpi"
	            #eval F77_COMPLEX$len2=\$"${c_type}_cplx_mpi"
                    noval="no"
	            break
                fi
            done
            if test "$noval" = "yes" ; then
                AC_MSG_RESULT([unavailable])
            fi
        done
    else 
        # Simply determine which types exist.  These may have been set by the
        # toplevel configure
        for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
            REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do  
  	    eval varname=MPI_$var
            eval varvalue=\$$varname
	    #echo "$varname = $varvalue"
  	    if test "$varvalue" = MPI_DATATYPE_NULL ; then
	        eval F77_$var=0
  	    else
                eval F77_$var=\$$varname
  	    fi
       done
    fi
    # We must convert all hex values to decimal (!)
    for var in INTEGER1 INTEGER2 INTEGER4 INTEGER8 INTEGER16 \
        REAL4 REAL8 REAL16 COMPLEX8 COMPLEX16 COMPLEX32 ; do  
        fullvar="F77_$var"
        eval fullvarvalue=\$$fullvar
        if test "$fullvarvalue" = 0 -o -z "$fullvarvalue" ; then 
            eval $fullvar=MPI_DATATYPE_NULL
            continue
        fi
        #echo "$fullvar = $fullvarvalue"
        value=0
        # See the comments above on why expr with : cannot be used here
        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
        for pos in 3 4 5 6 7 8 9 10 ; do
            #char=`expr substr $fullvarvalue $pos 1`
            char=`expr $fullvarvalue : '\(.\)'`
	    # We don't test for success of expr here because some expr's are
  	    # buggy and set the status to one on expressions like
            #    expr 00ccc : '\(.\)'
            # while both
            #    expr 00ccc : '\(..\)' 
            # and
            #    expr 100cc : '\(.\)'
            # return a zero status.  So the status is set even on success,
            # if the result is a single character that is a zero (!)
	    #rc=$?
    	    #if test "$rc" != 0 ; then
  	    dnl #    AC_MSG_WARN([Failure (status $rc) in extracting first char from $fullvarvalue])
  	    #    break
	    #fi
	    fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
            case $char in 
                a) char=10 ;;
	        b) char=11 ;;
	        c) char=12 ;;
	        d) char=13 ;;
	        e) char=14 ;;
	        f) char=15 ;;
            esac
            value=`expr $value \* 16 + $char`
	    if test $? != 0 ; then
	        AC_MSG_WARN([Failure to evaluate $value \* 16 + $char])
	    fi
        done
        #echo "$fullvar = $value"
        eval $fullvar=$value
    done
    AC_SUBST(F77_INTEGER1)
    AC_SUBST(F77_INTEGER2)
    AC_SUBST(F77_INTEGER4)
    AC_SUBST(F77_INTEGER8)
    AC_SUBST(F77_INTEGER16)
    AC_SUBST(F77_REAL4)
    AC_SUBST(F77_REAL8)
    AC_SUBST(F77_REAL16)
    AC_SUBST(F77_COMPLEX8)
    AC_SUBST(F77_COMPLEX16)
    AC_SUBST(F77_COMPLEX32)

    noval="yes"
    AC_MSG_CHECKING([for C type matching Fortran integer])
    for c_type in char short int long "long_long" ; do
        eval ctypelen=\$"ac_cv_sizeof_$c_type"
        if test "$pac_cv_f77_sizeof_integer" = "$ctypelen" -a \
          "$ctypelen" -gt 0 ; then
	    c_type=`echo $c_type | sed -e 's/_/ /g'`
	    AC_MSG_RESULT($c_type)
	    MPI_FINT=$c_type
	    noval="no"
	    break
        fi
    done
    if test "$noval" = "yes" ; then
        # Set a default
        MPI_FINT="int"
        AC_MSG_RESULT([unavailable])
    fi
    # We also need to check the size of MPI_Aint vs MPI_Fint, and
    # define AINT_LARGER_THAN_FINT if aint is larger (this 
    # affects code in MPI_Address)
    if test "$ac_cv_sizeof_void_p" != "0" -a \
        "$ac_cv_sizeof_void_p" -gt "$pac_cv_f77_sizeof_integer" ; then
        AC_DEFINE(HAVE_AINT_LARGER_THAN_FINT,1,[Define if addresses are larger than Fortran integers])
    fi
    if test "$ac_cv_sizeof_void_p" != 0 -a \
        "$ac_cv_sizeof_void_p" != "$pac_cv_f77_sizeof_integer" ; then
	AC_DEFINE(HAVE_AINT_DIFFERENT_THAN_FINT,1,[Define if addresses are a different size than Fortran integers])
    fi
    
    # Include a defined value for Fint is int
    if test "$MPI_FINT" = "int" ; then
        AC_DEFINE(HAVE_FINT_IS_INT,1,[Define if Fortran integer are the same size as C ints])
    elif test "$SIZEOF_F77_INTEGER" != "$ac_cv_sizeof_int" ; then
        # Make this fatal because we do not want to build a broken fortran
	# interface (was error)
	# Check to see if the f77 binding has enabled the code to support
	# the case of int != fint. 
	if grep HAVE_FINT_IS_INT $master_top_srcdir/src/binding/f77/testf.c 2>&1 1>/dev/null ; then
	    AC_MSG_WARN([Fortran integers and C ints are not the same size.  Support for this case is experimental; use at your own risk])
	else 
            AC_MSG_ERROR([Fortran integers and C ints are not the same size.  The current Fortran binding does not support this case.  Either force the Fortran compiler to use integers of $ac_cv_sizeof_int bytes, or use --disable-f77 on the configure line for MPICH.])
	fi
    fi

    # We must convert all hex values to decimal (!).
    # This is for the C types so they are also available in Fortran
    for var in CHAR SIGNED_CHAR UNSIGNED_CHAR WCHAR SHORT \
                  UNSIGNED_SHORT INT UNSIGNED_INT LONG UNSIGNED_LONG \
                  FLOAT DOUBLE LONG_DOUBLE LONG_LONG_INT \
                  UNSIGNED_LONG_LONG LONG_LONG FLOAT_INT DOUBLE_INT \
                  LONG_INT SHORT_INT "2INT" LONG_DOUBLE_INT \
                  INT8_T INT16_T INT32_T INT64_T            \
                  UINT8_T UINT16_T UINT32_T UINT64_T        \
                  C_BOOL C_FLOAT_COMPLEX C_DOUBLE_COMPLEX   \
                  C_LONG_DOUBLE_COMPLEX AINT OFFSET ; do
        fullvar="MPI_$var"
        fullf77var="MPI_F77_$var"
        eval fullvarvalue=\$$fullvar
        #echo "$fullvar = $fullvarvalue"
        if test "x$fullvarvalue" = "x" -o \
                "x$fullvarvalue" = "xMPI_DATATYPE_NULL" ; then
             eval $fullf77var="MPI_DATATYPE_NULL"
              continue
        fi
        value=0
        fullvarvalue=`echo $fullvarvalue | sed -e 's/..\(.*\)/\1/'`
        offset=0
        for pos in 3 4 5 6 7 8 9 10 ; do
            # This works, even for Tru64, because only a single character
            # is extracted
            char=`expr $fullvarvalue : '\(.\)'`
            # FIXME: Tru64 Unix eliminates leading zeros (!)
            # How do we fix something that broken?
            fullvarvalue=`echo $fullvarvalue | sed -e 's/.\(.*\)/\1/'`
            case $char in 
                a) char=10 ;;
                b) char=11 ;;
                c) char=12 ;;
                d) char=13 ;;
                e) char=14 ;;
                f) char=15 ;;
            esac
            # For Fortran, if the value is too big for an unsigned int, 
            # we need to make it a signed (negative) int. Currently, the
            # types in this class are the minloc/maxloc types.
            if test $pos = 3 -a $char -ge 8 ; then
                #echo "for $var in position $pos found a value >= 8"
                char=`expr $char - 8`
                offset=-2147483648
            fi
            value=`expr $value \* 16 + $char`
        done
        if test "$offset" != 0 ; then 
            #echo "$fullf77var: $value, $offset"
            value=`expr $value + $offset`
        fi
        #echo "$fullf77var = $value"
        eval $fullf77var=$value
    done
    AC_SUBST(MPI_F77_CHAR)
    AC_SUBST(MPI_F77_SIGNED_CHAR)
    AC_SUBST(MPI_F77_UNSIGNED_CHAR)
    AC_SUBST(MPI_F77_WCHAR)
    AC_SUBST(MPI_F77_SHORT)
    AC_SUBST(MPI_F77_UNSIGNED_SHORT)
    MPI_F77_UNSIGNED=$MPI_F77_UNSIGNED_INT
    AC_SUBST(MPI_F77_UNSIGNED)
    AC_SUBST(MPI_F77_INT)
    AC_SUBST(MPI_F77_LONG)
    AC_SUBST(MPI_F77_UNSIGNED_LONG)
    AC_SUBST(MPI_F77_FLOAT)
    AC_SUBST(MPI_F77_DOUBLE)
    AC_SUBST(MPI_F77_LONG_DOUBLE)
    AC_SUBST(MPI_F77_UNSIGNED_LONG_LONG)
    MPI_F77_LONG_LONG_INT=$MPI_F77_LONG_LONG
    AC_SUBST(MPI_F77_LONG_LONG_INT)
    AC_SUBST(MPI_F77_LONG_LONG)
    AC_SUBST(MPI_F77_FLOAT_INT)
    AC_SUBST(MPI_F77_DOUBLE_INT)
    AC_SUBST(MPI_F77_LONG_INT)
    AC_SUBST(MPI_F77_SHORT_INT)
    AC_SUBST(MPI_F77_2INT)
    AC_SUBST(MPI_F77_LONG_DOUBLE_INT)
    AC_SUBST(MPI_F77_INT8_T)
    AC_SUBST(MPI_F77_INT16_T)
    AC_SUBST(MPI_F77_INT32_T)
    AC_SUBST(MPI_F77_INT64_T)
    AC_SUBST(MPI_F77_UINT8_T)
    AC_SUBST(MPI_F77_UINT16_T)
    AC_SUBST(MPI_F77_UINT32_T)
    AC_SUBST(MPI_F77_UINT64_T)
    AC_SUBST(MPI_F77_C_BOOL)
    AC_SUBST(MPI_F77_C_FLOAT_COMPLEX)
    # C_COMPLEX is an alias for FLOAT_COMPLEX
    MPI_F77_C_COMPLEX=$MPI_F77_C_FLOAT_COMPLEX
    AC_SUBST(MPI_F77_C_COMPLEX)
    AC_SUBST(MPI_F77_C_DOUBLE_COMPLEX)
    AC_SUBST(MPI_F77_C_LONG_DOUBLE_COMPLEX)
    # these two are not yet defined, but AC_SUBST only cares about them at 
    # AC_OUTPUT-time
    AC_SUBST(MPI_F77_AINT)
    AC_SUBST(MPI_F77_OFFSET)

    # Try and compute the values of .true. and .false. in Fortran
    # This code has been removed because the Fortran binding code does
    # not yet support it.  
    PAC_F77_LOGICALS_IN_C([$MPI_FINT])

    # Get the INTEGER_KIND, ADDRESS_KIND and OFFSET_KIND if possible
    #
    # For Fortran 90, we'll also need MPI_ADDRESS_KIND and MPI_OFFSET_KIND
    # Since our compiler might BE a Fortran 90 compiler, try and determine the
    # values.  
    if test -z "$FC" ; then
        PAC_F77_IS_FC([
            FC=$F77
            if test -z "$FCFLAGS" ; then
                FCFLAGS="$FFLAGS"
            fi
        ])
    fi
    if test -n "$FC" ; then
        # Offset kind should be for 8 bytes if possible (Romio prefers that)
        # address should be sizeof void * (unless --with-aint-size has
        # been set)
        # FIXME in the current configure implementation OFFSET_KIND and
        # MPI_Offset won't always agree, but generally will.  The MPI Standard
        # implies that these types must have identical size, so this is a bug
        # waiting to happen.
	if test "$with_aint_size" -gt 0 -a \
	        "$with_aint_size" -gt "$ac_cv_sizeof_void_p" ; then
	    testsize=$with_aint_size
        else
            testsize=$ac_cv_sizeof_void_p
        fi
        if test "$testsize" = 0 ; then
            # Set a default
            testsize=4
        fi  
        dnl Using the {} around testsize helps the comments work correctly
        PAC_PROG_FC_INT_KIND(ADDRESS_KIND,${testsize},$CROSS_F90_ADDRESS_KIND)
        if test "$testsize" = 8 ; then
            OFFSET_KIND=$ADDRESS_KIND
        else
            PAC_PROG_FC_INT_KIND(OFFSET_KIND,8,$CROSS_F90_OFFSET_KIND)
        fi
        #
        PAC_PROG_FC_INT_KIND(INTEGER_KIND,$pac_cv_f77_sizeof_integer,$CROSS_F90_INTEGER_KIND)
        if test "$INTEGER_KIND" = "-1" ; then
	    # In our experience, this usually means that there is some
	    # problem building and/or running the f90 program.  Fail
	    # in this case rather than attempt to continue
	    AC_MSG_ERROR([Unable to determine Fortran 90 KIND values for either address-sized integers or offset-sized integers.])
        fi
	#
        # Some compilers won't allow a -1 kind (e.g., absoft).  In this case, 
        # use a fallback (sizeof(int) kind)
        if test "$ADDRESS_KIND" = "-1" -o "$OFFSET_KIND" = "-1" ; then
            if test "$ADDRESS_KIND" = "-1" ; then
	        ADDRESS_KIND=$INTEGER_KIND
            fi
            if test "$OFFSET_KIND" = "-1" ; then
	        OFFSET_KIND=$INTEGER_KIND
            fi
        fi
	AC_LANG_PUSH([Fortran])
        AC_CACHE_CHECK([if real*8 is supported in Fortran 90],
                       [pac_cv_fort90_real8],[
            AC_COMPILE_IFELSE([
                AC_LANG_PROGRAM([],[      real*8 a])
            ],[
                pac_cv_fort90_real8=yes
            ],[
                pac_cv_fort90_real8=no
            ])
        ])
	AC_LANG_POP([Fortran])
	WTIME_DOUBLE_TYPE="DOUBLE PRECISION"
	# Save a copy of the original mpi_base.f90 file
	if test "$enable_fc" = "yes" -a "$pac_cv_fort90_real8" = "yes" ; then
	    WTIME_DOUBLE_TYPE="REAL*8"
        fi
	# WTIME_DOUBLE_TYPE is substituted into mpi_base.f90
	AC_SUBST(WTIME_DOUBLE_TYPE)
    fi
    # Make sure that address kind and offset kind have values.
    if test -z "$ADDRESS_KIND" ; then
        ADDRESS_KIND=0
    fi
    if test -z "$OFFSET_KIND" ; then
        OFFSET_KIND=0
    fi
    # Note, however, that zero value are (in all practical case) invalid 
    # for Fortran 90, and indicate a failure.  Test and fail if Fortran 90
    # enabled.
    if test "$enable_fc" = "yes" ; then
        if test "$ADDRESS_KIND" -le 0 -o "$OFFSET_KIND" -le 0 ; then
	    AC_MSG_ERROR([Unable to determine Fortran 90 integer kinds for MPI types.  If you do not need Fortran 90, add --disable-fc to the configure options.])
	    # If the above is converted to a warning, you need to change 
	    # enable_fc and remote f90 from the bindings
	    enable_fc=no
        fi
    fi
    AC_SUBST(ADDRESS_KIND)
    AC_SUBST(OFFSET_KIND)
    AC_SUBST(INTEGER_KIND)

    # Some compilers may require special directives to handle the common 
    # block in a library.  In particular, directives are needed for Microsoft 
    # Windows to support dynamic library import.  The following six
    # directives may be needed:
    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
    #  CMS\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV1/
    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIV2/
    #  CDEC\$ATTRIBUTES DLLIMPORT::/MPIPRIVC/
    # CMS is for the Microsoft compiler,
    # CDEC is (we believe) for the DEC Fortran compiler.  
    # We need to make this a configure-time variable because some compilers
    # (in particular, a version of the Intel Fortran compiler for Linux)
    # will read directives for other compilers and then flag as fatal
    # errors directives that it does not support but does recognize.

    DLLIMPORT=""
    AC_SUBST(DLLIMPORT)

    # FIXME:
    # We also need to include
    # SIZEOF_FC_MPI_OFFSET
    # SIZEOF_FC_MPI_AINT
    # 
    # If other "kinds" are supported, MPI_SIZEOF needs to identify 
    # those as well.  This is very difficult to do in a general way.

    # To start with, we use the sizes determined for the Fortran 77 values.
    # These must be the same as for the Fortran 90 values.
    CROSS_F90_SIZEOF_INTEGER=${CROSS_F90_SIZEOF_INTEGER:-0}
    CROSS_F90_SIZEOF_REAL=${CROSS_F90_SIZEOF_REAL:-0}
    CROSS_F90_SIZEOF_DOUBLE_PRECISION=${CROSS_F90_SIZEOF_DOUBLE_PRECISION:-0}
    SIZEOF_FC_INTEGER=$CROSS_F90_SIZEOF_INTEGER
    SIZEOF_FC_REAL=$CROSS_F90_SIZEOF_REAL
    SIZEOF_FC_CHARACTER=1
    SIZEOF_FC_DOUBLE_PRECISION=$CROSS_F90_SIZEOF_DOUBLE_PRECISION
    if test "$pac_cv_f77_sizeof_integer" -gt 0 -a \
	    "$SIZEOF_FC_INTEGER" = "0" ; then
        SIZEOF_FC_INTEGER=$pac_cv_f77_sizeof_integer
    fi
    if test "$pac_cv_f77_sizeof_real" -gt 0 -a "$SIZEOF_FC_REAL" = "0" ; then
        SIZEOF_FC_REAL=$pac_cv_f77_sizeof_real
    fi
    if test "$pac_cv_f77_sizeof_double_precision" -gt 0 -a \
       "$SIZEOF_FC_DOUBLE_PRECISION" = "0" ; then
        SIZEOF_FC_DOUBLE_PRECISION=$pac_cv_f77_sizeof_double_precision
    fi
    AC_SUBST(SIZEOF_FC_INTEGER)
    AC_SUBST(SIZEOF_FC_REAL)
    AC_SUBST(SIZEOF_FC_DOUBLE_PRECISION)
    AC_SUBST(SIZEOF_FC_CHARACTER)

    # REQD is short for "real equal double precision" and is set to the
    # Fortran 90 comment character if true.  This is necessary to
    # allow the mpi_sizeofs module to be built, since if this part of the
    # Fortran standard is violated by the compiler (unfortunately common,
    # as some applications are written to require this non-standard 
    # version), the double precision versions of the MPI_SIZEOF routine
    # must be commented out of the module (!).
    REQD=
    if test "$SIZEOF_FC_REAL" = "$SIZEOF_FC_DOUBLE_PRECISION" ; then
        REQD="!"
    fi
    AC_SUBST(REQD)
    # Is integer*1 supported, and is it a different size than integer?
    REQI1="!"
    if test "$pac_cv_fort_integer1" = yes -a "$SIZEOF_FC_INTEGER" != 1 ; then
        REQI1=
    fi
    AC_SUBST(REQI1)
    # Is integer*2 supported, and is it a different size than integer?
    REQI2="!"
    if test "$pac_cv_fort_integer2" = yes -a "$SIZEOF_FC_INTEGER" != 2 ; then
        REQI2=
    fi
    AC_SUBST(REQI2)
    # Is integer*8 supported, and is it a different size than integer?
    REQI8="!"
    if test "$pac_cv_fort_integer8" = yes -a "$SIZEOF_FC_INTEGER" != 8 ; then
        REQI8=
    fi
    AC_SUBST(REQI8)
    # 

    AC_LANG_C
fi
# ----------------------------------------------------------------------------
# C++ types

# default to null types
# Set to "0x0c000000" instead of "MPI_DATATYPE_NULL" because these values
# sometimes are used in preprocessor tests where we cannot compare the
# type-casted values.
MPIR_CXX_BOOL=0x0c000000
MPIR_CXX_COMPLEX=0x0c000000
MPIR_CXX_DOUBLE_COMPLEX=0x0c000000
MPIR_CXX_LONG_DOUBLE_COMPLEX=0x0c000000
MPI_F77_CXX_BOOL=MPI_DATATYPE_NULL
MPI_F77_CXX_FLOAT_COMPLEX=MPI_DATATYPE_NULL
MPI_F77_CXX_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
MPI_F77_CXX_LONG_DOUBLE_COMPLEX=MPI_DATATYPE_NULL
if test "$enable_cxx" = "yes" ; then
    AC_LANG_CPLUSPLUS
    AC_CHECK_SIZEOF(bool)

    # Find a C type that matches the size of the C++ boolean type
    case "$ac_cv_sizeof_bool" in
    	 $ac_cv_sizeof__Bool)
		bool_type=_Bool
		;;
    	 $ac_cv_sizeof_unsigned_char)
		bool_type="unsigned char"
		;;
    	 $ac_cv_sizeof_unsigned_short)
		bool_type="unsigned short"
		;;
    	 $ac_cv_sizeof_unsigned_int)
		bool_type="unsigned int"
		;;
    	 $ac_cv_sizeof_unsigned_long)
		bool_type="unsigned long"
		;;
    	 $ac_cv_sizeof_unsigned_long_long)
		bool_type="unsigned long long"
		;;
         *)
		AC_MSG_ERROR([unable to determine matching C type for C++ bool])
		;;
    esac
    AC_DEFINE_UNQUOTED([MPIR_CXX_BOOL_CTYPE],[$bool_type],
			[a C type used to compute C++ bool reductions])

    AC_CHECK_HEADER(complex)
    if test "$ac_cv_header_complex" = "yes" ; then 
        # The C++ complex types are all templated.  We finagle this by 
        # defining a standin name
        AC_CHECK_SIZEOF(Complex,0,[#include <stdio.h>
#include <complex>
using namespace std;
#define Complex complex<float>
])
        AC_CHECK_SIZEOF(DoubleComplex,0,[#include <stdio.h>
#include <complex>
using namespace std;
#define DoubleComplex complex<double>
])
        if test "$MPID_NO_LONG_DOUBLE" != yes ; then
             AC_CHECK_SIZEOF(LongDoubleComplex,0,[#include <stdio.h>
#include <complex>
using namespace std;
#define LongDoubleComplex complex<long double>
])
        fi

        # If either complex or double complex have length 0, then mark
        # c++ complex as unavailable
        if test "$ac_cv_sizeof_Complex" != 0 -a \
                "$ac_cv_sizeof_DoubleComplex" != 0 ; then
            AC_DEFINE(HAVE_CXX_COMPLEX,1,[Define is C++ supports complex types])
        fi

        # Datatypes are given by
        # 0x4c00 <length in bytes> (1 byte) <unique num> (1 byte)    
        # where the unique nums are
        # 33,34,35,36
        case "$ac_cv_sizeof_bool" in 
           1)    MPIR_CXX_BOOL=0x4c000133 ;;
           2)    MPIR_CXX_BOOL=0x4c000233 ;;
           4)    MPIR_CXX_BOOL=0x4c000433 ;;
           8)    MPIR_CXX_BOOL=0x4c000833 ;;
           *) ;;
        esac
        case "$ac_cv_sizeof_Complex" in 
           8)    MPIR_CXX_COMPLEX=0x4c000834 ;;
           16)   MPIR_CXX_COMPLEX=0x4c001034 ;;
           *) ;;
        esac
        case "$ac_cv_sizeof_DoubleComplex" in 
           8)    MPIR_CXX_DOUBLE_COMPLEX=0x4c000835 ;;
           16)   MPIR_CXX_DOUBLE_COMPLEX=0x4c001035 ;;
           32)   MPIR_CXX_DOUBLE_COMPLEX=0x4c002035 ;;
           *) ;;
        esac
        # only enable CXX "long double" if we have a C "long double", since we
        # currently perform reductions on CXX "long double" types via C.
        if test "X$pac_cv_have_long_double" = "Xyes" ; then
            case "$ac_cv_sizeof_LongDoubleComplex" in
               8)    MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c000836 ;;
               16)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001036 ;;
               24)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c001836 ;;
               32)   MPIR_CXX_LONG_DOUBLE_COMPLEX=0x4c002036 ;;
               *) ;;
            esac
        fi
    fi
    AC_LANG_C

    # Make these available to the collective operations and other code
    AC_DEFINE_UNQUOTED(MPIR_CXX_BOOL_VALUE,$MPIR_CXX_BOOL,[Define as the MPI Datatype handle for MPI::BOOL])
    AC_DEFINE_UNQUOTED(MPIR_CXX_COMPLEX_VALUE,$MPIR_CXX_COMPLEX,[Define as the MPI Datatype handle for MPI::COMPLEX])
    AC_DEFINE_UNQUOTED(MPIR_CXX_DOUBLE_COMPLEX_VALUE,$MPIR_CXX_DOUBLE_COMPLEX,[Define as the MPI Datatype handle for MPI::DOUBLE_COMPLEX])
    AC_DEFINE_UNQUOTED(MPIR_CXX_LONG_DOUBLE_COMPLEX_VALUE,$MPIR_CXX_LONG_DOUBLE_COMPLEX,[Define as the MPI Datatype handle for MPI::LONG_DOUBLE_COMPLEX])
    
    # compute F77 decimal constant values for these types
    PAC_CONV_HEX_TO_DEC([$MPIR_CXX_BOOL],               [MPI_F77_CXX_BOOL])
    PAC_CONV_HEX_TO_DEC([$MPIR_CXX_COMPLEX],            [MPI_F77_CXX_FLOAT_COMPLEX])
    PAC_CONV_HEX_TO_DEC([$MPIR_CXX_DOUBLE_COMPLEX],     [MPI_F77_CXX_DOUBLE_COMPLEX])
    PAC_CONV_HEX_TO_DEC([$MPIR_CXX_LONG_DOUBLE_COMPLEX],[MPI_F77_CXX_LONG_DOUBLE_COMPLEX])
fi
AC_SUBST([MPIR_CXX_BOOL])
AC_SUBST([MPIR_CXX_COMPLEX])
AC_SUBST([MPIR_CXX_DOUBLE_COMPLEX])
AC_SUBST([MPIR_CXX_LONG_DOUBLE_COMPLEX])
AC_SUBST([MPI_F77_CXX_BOOL])
AC_SUBST([MPI_F77_CXX_FLOAT_COMPLEX])
AC_SUBST([MPI_F77_CXX_DOUBLE_COMPLEX])
AC_SUBST([MPI_F77_CXX_LONG_DOUBLE_COMPLEX])

# ----------------------------------------------------------------------------
# Check for the alignment rules moves with types int64_t etc.  These
# are used in the datatype code to perform pack and unpack operations.  
# These only determine if different alignments *work*, not whether they
# work efficiently.  The datatype pack code (should) allow the developer
# to include stricter alignment rules than are needed for correctness to
# get better performance.
if test "$ac_cv_c_int64_t" != "no" -o -n "$INT64_T" ; then
    default_int64_t_alignment=${CROSS_INT64_T_ALIGNMENT:-"unknown"}
    if test -z "$INT64_T" ; then
         if test "$ac_cv_c_int64_t" = yes ; then
	     INT64_T="int64_t"
         else
             INT64_T="$ac_cv_int64_t"
         fi
    fi
    # We use the type that we're going use for int64.
    AC_CACHE_CHECK([for alignment restrictions on $INT64_T],pac_cv_int64_t_alignment,[
    AC_TRY_RUN([
#include <sys/types.h>
#include <stdlib.h>
int main(int argc, char **argv )
{
    $INT64_T *p1, v;
    char    *buf_p = (char *)malloc( 64 ), *bp;
    bp = buf_p;
    /* Make bp aligned on 4, not 8 bytes */
    if (!( (long)bp & 0x7 ) ) bp += 4;
    p1 = ($INT64_T *)bp;
    v = -1;
    *p1 = v;
    if (!( (long)bp & 0x3 ) ) bp += 2;
    p1 = ($INT64_T *)bp;
    *p1 = 1;
    if (!( (long)bp & 0x1 ) ) bp += 1;
    p1 = ($INT64_T *)bp;
    *p1 = 1;
    return 0;
}
],pac_cv_int64_t_alignment=no,pac_cv_int64_t_alignment=yes,pac_cv_int64_t_alignment=$default_int64_t_alignment)
])
    if test "$pac_cv_int64_t_alignment" = "no" ; then
         AC_DEFINE(HAVE_ANY_INT64_T_ALIGNMENT,1,[Define if int64_t works with any alignment])
    fi
fi

if test "$ac_cv_int32_t" != "no" ; then
    default_int32_t_alignment=${CROSS_INT32_T_ALIGNMENT:-"unknown"}
    if test -z "$INT32_T" ; then
         if test "$ac_cv_c_int32_t" = yes ; then
	     INT32_T="int32_t"
         else
             INT32_T="$ac_cv_int32_t"
         fi
    fi
    
    AC_CACHE_CHECK([for alignment restrictions on int32_t],pac_cv_int32_t_alignment,[
    AC_TRY_RUN([
#include <sys/types.h>
#include <stdlib.h>
int main(int argc, char **argv )
{
    $INT32_T *p1, v;
    char    *buf_p = (char *)malloc( 64 ), *bp;
    bp = buf_p;
    /* Make bp aligned on 4, not 8 bytes */
    if (!( (long)bp & 0x7 ) ) bp += 4;
    p1 = ($INT32_T *)bp;
    v = -1;
    *p1 = v;
    if (!( (long)bp & 0x3 ) ) bp += 2;
    p1 = ($INT32_T *)bp;
    *p1 = 1;
    if (!( (long)bp & 0x1 ) ) bp += 1;
    p1 = ($INT32_T *)bp;
    *p1 = 1;
    return 0;
}
],pac_cv_int32_t_alignment=no,pac_cv_int32_t_alignment=yes,pac_cv_int32_t_alignment=$default_int32_t_alignment)
])
    if test "$pac_cv_int32_t_alignment" = "no" ; then
         AC_DEFINE(HAVE_ANY_INT32_T_ALIGNMENT,1,[Define if int32_t works with any alignment])
    fi
fi
# Check for special compile characteristics
# If we are either gcc or icc, see if we can use __asm__
# We test on prog_gcc to allow gcc by any name; if we are using
# icc, the value of CC must be icc for this test to pass
if test "$ac_cv_prog_gcc" = "yes" -o "$ac_cv_prog_CC" = "icc" ; then
AC_MSG_CHECKING([for gcc __asm__ and pentium cmpxchgl instruction])
AC_TRY_RUN([
int main(int argc, char *argv[])
{
long int compval = 10;
volatile long int *p = &compval;
long int oldval = 10;
long int newval = 20;
char ret;
long int readval;
__asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
	: "=q" (ret), "=m" (*p), "=a" (readval)
	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
return (compval == 20) ? 0 : -1;
}
], AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GCC_AND_PENTIUM_ASM, 1,[Define if using gcc on a system with an Intel Pentium class chip])
   lac_cv_use_atomic_updates="yes", 
AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
fi
if test "$lac_cv_use_atomic_updates" = "yes" ; then
    AC_DEFINE(USE_ATOMIC_UPDATES,, [Define if assembly language atomic update macros should be used (if available)])
fi

# check for x86_64
if test "$ac_cv_prog_gcc" = "yes" ; then
AC_MSG_CHECKING([for gcc __asm__ and AMD x86_64 cmpxchgq instruction])
AC_TRY_RUN([
int main(int argc, char *argv[])
{
long int compval = 10;
volatile long int *p = &compval;
long int oldval = 10;
long int newval = 20;
char ret;
long int readval;
__asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
	: "=q" (ret), "=m" (*p), "=a" (readval)
	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
return (compval == 20) ? 0 : -1;
}
], AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GCC_AND_X86_64_ASM, 1,[Define if using gcc on a system with an AMD x86_64 class chip]), 
AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
fi
dnl
dnl check for asm() format
dnl 
dnl AC_MSG_CHECKING([for asm() and pentium cmpxchgl instruction])
dnl AC_TRY_RUN([
dnl int main(int argc, char *argv[])
dnl {
dnl long int compval = 10;
dnl volatile long int *p = &compval;
dnl long int oldval = 10;
dnl long int newval = 20;
dnl char ret;
dnl long int readval;
dnl asm("lock; cmpxchgl %3, %1; sete %0"
dnl 	: "=q" (ret), "=m" (*p), "=a" (readval)
dnl 	: "r" (newval), "m" (*p), "a" (oldval) : "memory");
dnl return (compval == 20) ? 0 : -1;
dnl }
dnl ], AC_MSG_RESULT(yes)
dnl    AC_DEFINE(HAVE_PENTIUM_ASM, 1,[Define if using asm() on a system with an Intel Pentium class chip]),
dnl AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
dnl
dnl
dnl check for IA64
dnl 
if test "$ac_cv_prog_gcc" = "yes" ; then
AC_MSG_CHECKING([for gcc __asm__ and IA64 xchg4 instruction])
AC_TRY_RUN([
unsigned long _InterlockedExchange(volatile void *ptr, unsigned long x)
{
   unsigned long result;
   __asm__ __volatile ("xchg4 %0=[%1],%2" : "=r" (result)
       : "r" (ptr), "r" (x) : "memory");
   return result;
}
int main(int argc, char *argv[])
{
long val = 1;
volatile long *p = &val;
long oldval = _InterlockedExchange(p, (unsigned long)2);
return (oldval == 1 && val == 2) ? 0 : -1;
}
], AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_GCC_AND_IA64_ASM, 1,[Define if using gcc on a system with an IA64 class chip]), 
AC_MSG_RESULT(no), AC_MSG_RESULT(not checking when cross compiling))
fi
# -----------------------------------------------------------------------------
# Check for support of enable-coverage.  Put this near the end of the tests
# because the coverage options may affect the other tests.
PAC_ENABLE_COVERAGE

# -----------------------------------------------------------------------------
# Look for Standard headers
AC_HEADER_STDC
# Check for a specific header
# Grrr.  OS/X fails the test for sys/uio.h because uio *requires* sys/types.h
# to compile.  Thus, we'll make that a separate test
# stddef.h is sometimes needed for types like wchar_t
AC_CHECK_HEADERS(stdlib.h stdarg.h sys/types.h string.h inttypes.h limits.h stddef.h errno.h sys/socket.h sys/time.h unistd.h endian.h assert.h sys/param.h)
AC_CACHE_CHECK([for sys/uio.h],ac_cv_header_sys_uio_h,[
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/uio.h>
],[int a;],ac_cv_header_sys_uio_h=yes,ac_cv_header_sys_uio_h=no)])
if test "$ac_cv_header_sys_uio_h" = yes ; then
    AC_DEFINE(HAVE_SYS_UIO_H,1,[Define if you have the <sys/uio.h> header file.])
fi

# Check for special types
AC_TYPE_SIZE_T

# These are used to support timeouts
AC_CHECK_FUNCS(setitimer alarm)
# These are used for error reporting
AC_CHECK_FUNCS(vsnprintf vsprintf)
if test "$ac_cv_func_vsnprintf" = "yes" ; then
    # vsnprintf may be declared in stdio.h and may need stdarg.h 
    PAC_FUNC_NEEDS_DECL([#include <stdio.h>
#include <stdarg.h>],vsnprintf)
fi
# We would like to use strerror in the file namepublisher; it is also used
# in MPIU_Strerror (whose implementation is broken if strerror is not found)
AC_CHECK_FUNCS(strerror strncasecmp)
AC_FUNC_STRERROR_R
if test "$ac_cv_func_strerror_r" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <string.h>],strerror_r)
fi

# Use snprintf if possible when creating messages
AC_CHECK_FUNCS(snprintf)
if test "$ac_cv_func_snprintf" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <stdio.h>],snprintf)
fi

# qsort will be used in MPI_Comm_split, if available
AC_CHECK_FUNCS([qsort])

# if we are using stdarg, we may need va_copy .  Test to see if we have it
# Since it may be a built-in instead of a function, we must try to 
# compile and link a program that uses it.
# va_copy is currently used only in src/util/dbg_printf.c, in an obsolete
# debugging routine.  We may want to withdraw this (saving the
# test in confdb/aclocal_cc.m4).
AC_CACHE_CHECK([for va_copy],pac_cv_func_va_copy,[
AC_TRY_LINK([
#include <stdarg.h>
void foo1( char *fmt, ... ) {
    va_list ap, list;
    va_start(ap,fmt);
    va_copy(list,ap);
    va_end(list);
    va_end(ap);
}
],[foo1("a test %d", 3);],pac_cv_func_va_copy=yes,pac_cv_func_va_copy=no)])

if test "$pac_cv_func_va_copy" = "yes" ; then
    AC_DEFINE(HAVE_VA_COPY,1,[Define if we have va_copy])
else
    AC_CACHE_CHECK([for __va_copy],pac_cv_func___va_copy,[
    AC_TRY_LINK([
#include <stdarg.h>
void foo1( char *fmt, ... ) {
    va_list ap, list;
    va_start(ap,fmt);
    __va_copy(list,ap);
    va_end(list);
    va_end(ap);
}
],[foo1("a test %d", 3);],pac_cv_func___va_copy=yes,pac_cv_func___va_copy=no)])
    if test "$pac_cv_func___va_copy" = "yes" ; then
        AC_DEFINE(HAVE___VA_COPY,1,[Define if we have __va_copy])
    fi
fi

PAC_C_MACRO_VA_ARGS

dnl
dnl If internationalization selected, try to find the needed functions
dnl if test "$enable_internat" = "yes" ; then
dnl     AC_CHECK_HEADERS(libintl.h)
dnl     AC_CHECK_FUNCS(gettext dgettext)
dnl     if test "$ac_cv_header_libintl" = "yes" -a \
dnl 	    "$ac_cv_func_gettext" = "yes" -a \
dnl 	    "$ac_cv_func_dgettext" = "yes" ; then
dnl 	AC_DEFINE(USE_GETTEXT,1,[Define if messages should use gettext])
dnl     else
dnl         AC_MSG_WARN([Cannot use internationalization because necessary headers and functions are not available])
dnl     fi
dnl fi
# Check for alloca function.  May set HAVE_ALLOCA_H and HAVE_ALLOCA
AC_FUNC_ALLOCA
# We don't use alloca unless USE_ALLOCA is also set.
AC_ARG_ENABLE(alloca,
	AC_HELP_STRING([--enable-alloca],
		[Use alloca to allocate temporary memory if available]),,enable_alloca=no)
if test "$enable_alloca" = yes ; then
    AC_DEFINE(USE_ALLOCA,1,[Define if alloca should be used if available])
fi

if test "$enable_g_mem" != "yes" ; then
    # Strdup is needed only if memory tracing is not enabled.
    AC_CHECK_FUNCS(strdup)
    if test "$ac_cv_func_strdup" = "yes" ; then
        # Do we need to declare strdup?
        PAC_FUNC_NEEDS_DECL([#include <string.h>],strdup)
    fi
else
    # search.h is used for fancier output from trmem.  Disabled for now,
    # since the tsearch routines have problematic prototypes.
    AC_CHECK_HEADERS(search)
    AC_CHECK_FUNCS(tsearch)
    # Check that we can compile tsearch without error.  Try to compile
    # it with the header and the char * args
    if test "$ac_cv_func_tsearch" = "yes" ; then
        AC_CACHE_CHECK([whether tsearch requires char* args],
	               pac_cv_tsearch_charp,[
        AC_TRY_COMPILE([#include <search.h>
    char *tsearch( char *k, char **r, (int (*)())compare ) { return k; }],
    [int f=0;],pac_cv_tsearch_charp=yes,pac_cv_tsearch_charp=no)])
        if test "$pac_cv_tsearch_charp" = "yes" ; then
	    # this should consider defining a name with the argument type
	    # so that no further ifdefs are needed
	    AC_DEFINE(USE_TSEARCH_WITH_CHARP,1,[Define if tsearch requires char pointers])
	fi
    fi
    # Note that HPUX and AIX may require _INCLUDE_XOPEN_SOURCE or
    # _XOPEN_SOURCE be defined respectively.
fi

# ----------------------------------------------------------------------------
# Look for some non-posix, but commonly provided functions
# ----------------------------------------------------------------------------
# mkstemp() is a better replacement for mktemp()
AC_HAVE_FUNCS(mkstemp)
if test "$ac_cv_func_mkstemp" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],mkstemp)
fi
# fdopen() converts from an fd to a FILE*
AC_HAVE_FUNCS(fdopen)
if test "$ac_cv_func_fdopen" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],fdopen)
fi
# putenv() sets environment variable
AC_HAVE_FUNCS(putenv)
if test "$ac_cv_func_putenv" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <stdlib.h>],putenv)
fi


# ----------------------------------------------------------------------------
# Support for timers.  The following code processes the 
#  --enable-timer-type=name argument and selects the timer based on 
# both that field and what configure is able to determine is available.
# The file src/include/mpichtimer.h is also created.
# Note that at least the handling of the "device" option must come *after* 
# the setup_device script is loaded so that the device can set the appropriate
# fields.  For now, we've split this so that there is an update to the timer
# after the setup_device script is loaded, but we should consider moving
# this entire block.
# FIXME DJG setup_device has been eliminated in favor of subconfigure.m4 files
# ----------------------------------------------------------------------------
# Default type for timer stamp.
MPID_TIMER_TYPE=long
AC_SUBST(MPID_TIMER_TYPE)

# If the device specified a timer type, use that by default.  Else,
# try to detect a type that works on this system.
if test -n "$MPID_DEVICE_TIMER_TYPE" ; then
   default_timer_type=device
else
   default_timer_type=
fi

# clock_gettime is the POSIX gettimeofday
# gethrtime is the Solaris high-resolution timer
dnl
dnl Specific checks that a function works correctly
dnl
dnl Now that we know what the options are, choose the timer to use
dnl
dnl The default preference is
dnl    Solaris gethrtime
dnl    Posix   clock_gettime
dnl    Unix    gettimeofday (one of two versions)
dnl
dnl Also available are various hardware time stamps
dnl    Linux-x86 cycle counter
dnl    Linux-alpha cycle counter
dnl
dnl We also allow --enable-timer-type=name to select a timer type
AC_ARG_ENABLE(timer-type,
[  --enable-timer-type=name - Select the timer to use for MPI_Wtime and
                             internal timestamps.
        gethrtime          - Solaris timer (Solaris systems only)
        clock_gettime      - Posix timer (where available)
        gettimeofday       - Most Unix systems
        linux86_cycle      - Linux x86; returns cycle counts, not time in seconds*
        gcc_ia64_cycle     - IPF ar.itc timer*
	mach_absolute_time - Mach absolute time (alternative to clock_gettime
                             for OSX)
        device - The timer is provided by the device

        *Note that the cycle timers are intended to be used by MPICH
        developers for internal low-level timing.  Normal users should
        not use these as they are not guaranteed to be accurate in
        certain situations.

        linuxalpha_cycle is no longer supported.
],timer_type=$enable_timer_type,timer_type=${default_timer_type})

if test -z "$timer_type" ; then 
    # Try to pick a timer based on what is available
    AC_CHECK_FUNCS(clock_gettime clock_getres gethrtime mach_absolute_time gettimeofday)
    if test "$ac_cv_func_gethrtime" = "yes" ; then
        # Sigh.  The Solaris include files do not define hrtime_t
	# Before we accept this choice, make sure that we can 
	# do arithmetic with hrtime_t .
        AC_CACHE_CHECK([that hrtime_t is properly defined for gethrtime],
	pac_cv_hrtime_works,[
	AC_TRY_COMPILE([
#include <sys/time.h>
],[hrtime_t t1, t2; t1 = 1; t2 = 2; t1 = t1 + t2;],
pac_cv_hrtime_works=yes,pac_cv_hrtime_works=no)])
	# A more ambitious test would look to see if casting an 
	# hrtime_t to int64_t works, and even more ambitious
	# would check whether long or long long was 64 bits (or even
	# better, the sizeof hrtime_t).  
    fi
    if test "$ac_cv_func_gethrtime" = "yes" -a \
            "$pac_cv_hrtime_works" = "yes" ; then
        timer_type=gethrtime
    elif test "$ac_cv_func_clock_gettime" = "yes" -a \
              "$ac_cv_func_clock_getres" = "yes" ; then
	 # Test on both because some systems (e.g., cygwin) provide
	 # clock_gettime but not clock_getres
        timer_type=clock_gettime
    elif test "$ac_cv_func_mach_absolute_time" = "yes" ; then 
        timer_type=mach_absolute_time
    elif test "$ac_cv_func_gettimeofday" = "yes" ; then
        timer_type=gettimeofday
    fi
fi
if test -z "$timer_type" ; then
    AC_MSG_ERROR([No timer found])
fi

# Check for valid timer and select datatypes for the time stamp
case "$timer_type" in

    gethrtime)
    MPID_TIMER_TYPE=hrtime_t
    AC_CHECK_FUNC(gethrtime,,[
         AC_MSG_ERROR([Requested timer gethrtime is not available])
])
    ;;

    clock_gettime)
    missing_function=no
    AC_SEARCH_LIBS([clock_gettime],[rt],,AC_MSG_ERROR([clock_gettime is not available]))
    AC_SEARCH_LIBS([clock_getres],[rt],,AC_MSG_ERROR([clock_getres is not available]))
    MPID_TIMER_TYPE="struct timespec"
    # AIX does not always define struct timespec (!)
    # Make sure that we can use struct timespec
    AC_CACHE_CHECK([whether struct timespec is defined in time.h],
                    pac_cv_struct_timespec_defined,[
    AC_TRY_COMPILE([
#include <time.h>],[
    struct timespec t;],pac_cv_struct_timespec_defined=yes,
    pac_cv_struct_timespec_defined=no)
])
    if test "$pac_cv_struct_timespec_defined" != "yes" ; then
        # Try again, but with -D_XOPEN_SOURCE=500 (works for AIX)
        AC_CACHE_CHECK([whether struct timespec is defined in time.h with _XOPEN_SOURCE=500],
                    pac_cv_struct_timespec_defined_with_xopen500,[
        AC_TRY_COMPILE([
#define _XOPEN_SOURCE 500
#include <time.h>],[
    struct timespec t;],pac_cv_struct_timespec_defined_with_xopen500=yes,
    pac_cv_struct_timespec_defined_with_xopen500=no)
])
	if test "$pac_cv_struct_timespec_defined_with_xopen500" = "yes" ; then
	    # We need to define _XOPEN_SOURCE=500, but we need to ensure that
	    # this is done before any include files are loaded.  At
	    # this point it is really too late to add this definition,
	    # since it may make other tests incompatible.
	    AC_MSG_ERROR([The available timer requires _XOPEN_SOURCE=500.  Add -D_XOPEN_SOURCE=500 to CFLAGS and rerun configure])
        fi
    fi
    # 
    # FreeBSD 4.3 incorrectly puts the header into sys/time.h; 
    # time.h is required (see pages 45 and 46 in the POSIX standard).
    # See if we can compile
    AC_CACHE_CHECK([for CLOCK_REALTIME defined in time.h],pac_cv_posix_clock_realtime,[
    AC_TRY_COMPILE([
#include <time.h>],[
    clockid_t cid = CLOCK_REALTIME;],pac_cv_posix_clock_realtime=yes,
pac_cv_posix_clock_realtime=no)])
    if test "$pac_cv_posix_clock_realtime" = "no" ; then
         AC_MSG_WARN([POSIX timer requires definitions in time.h])
	 # Check for the definition in sys/time.h, which is where
	 # OpenBSD and FreeBSD have put it by mistake
         AC_TRY_COMPILE([
#include <time.h>
#include <sys/time.h>],[
    clockid_t cid = CLOCK_REALTIME;],pac_cv_posix_clock_realtime=yes,
pac_cv_posix_clock_realtime=no)
	if test "$pac_cv_posix_clock_realtime" = yes ; then
	    AC_MSG_WARN([sys/time.h required for POSIX timer])
	    AC_DEFINE(NEEDS_SYS_TIME_H,1,[Define if sys/time.h is required to get timer definitions])
	else
	    AC_MSG_ERROR([Cannot find the definition of CLOCK_REALTIME for the POSIX timer])
	fi
    fi
    ;;

    gettimeofday)
    MPID_TIMER_TYPE="struct timeval"
    # We may have already tested for gettimeofday.  If we got a "yes",
    # we're good to go
    if test "$ac_cv_func_gettimeofday" != "yes" ; then
        AC_CHECK_FUNC(gettimeofday,,[
         AC_MSG_ERROR([Requested timer gettimeofday is not available])
])
    fi
    ;;

    linux86_cycle|linux86_cycle_2)
    
# The following AC_TRY_RUN statements are needed because x86_64 compilers
# usually know about rdtscp but the cpu may or may not actually implement the
# feature.  This is not cross-compile safe, unfortunately.  In the long run we
# should allow the user to override this with a configure flag.
    AC_CACHE_CHECK([that linux86 cycle counter is available],
        pac_cv_linux86_cycle,
            AC_TRY_RUN([
int main()
{
    /* rdtscp */
    long long var, *var_ptr=&var;
    __asm__ __volatile__("rdtscp; shl \$32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
    return 0;
}
            ],pac_cv_linux86_cycle=rdtscp,
                AC_TRY_RUN([[
int main()
{
    /* cpuid 64 */
    long long var, *var_ptr=&var;
    __asm__ __volatile__("push %%rbx ; cpuid ; rdtsc ; pop %%rbx ; shl $32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
    return 0;
}
                ]],pac_cv_linux86_cycle=cpuid_rdtsc64,
                    AC_TRY_RUN([[[
int main()
{
    /* cpuid 32 */
    long long var, *var_ptr=&var;
    __asm__ __volatile__("push %%ebx ; cpuid ; rdtsc ; pop %%ebx" : "=A" (*var_ptr) : : "ecx");
    return 0;
}
                    ]]],pac_cv_linux86_cycle=cpuid_rdtsc32,
                        AC_TRY_RUN([[[[
int main()
{
    /* simple */
    long long var, *var_ptr=&var;
    __asm__ __volatile__("rdtsc" : "=A" (*var_ptr));
    return 0;
}
                        ]]]],pac_cv_linux86_cycle=rdtsc,
                        pac_cv_linux86_cycle=no)
                    )
                ),
dnl The if-cross-compiling clause from the first AC_TRY_RUN.  Hope that if the
dnl compiler knows about the instruction then it's supported by the target
dnl platform.
                AC_TRY_COMPILE(,[[
                    long long var, *var_ptr=&var;
                    __asm__ __volatile__("rdtscp; shl \$32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
                ]],pac_cv_linux86_cycle=rdtscp,
                    AC_TRY_COMPILE(,[[[
                        long long var, *var_ptr=&var;
                        __asm__ __volatile__("push %%rbx ; cpuid ; rdtsc ; pop %%rbx ; shl $32, %%rdx; or %%rdx, %%rax" : "=a" (*var_ptr) : : "ecx", "rdx");
                    ]]],pac_cv_linux86_cycle=cpuid_rdtsc64,
                        AC_TRY_COMPILE(,[[[[
                            long long var, *var_ptr=&var;
                            __asm__ __volatile__("push %%ebx ; cpuid ; rdtsc ; pop %%ebx" : "=A" (*var_ptr) : : "ecx");
                        ]]]],pac_cv_linux86_cycle=cpuid_rdtsc32,
                            AC_TRY_COMPILE(,[[[[[
                                long long var, *var_ptr=&var;
                                __asm__ __volatile__("rdtsc" : "=A" (*var_ptr));
                            ]]]]],pac_cv_linux86_cycle=rdtsc,
                            pac_cv_linux86_cycle=no)
                        )
                    )
                )
            )
    )

    case "$pac_cv_linux86_cycle" in
        "rdtscp")
            AC_DEFINE(LINUX86_CYCLE_RDTSCP,1,[Define which x86 cycle counter to use])
	    ;;
        "cpuid_rdtsc64")
            AC_DEFINE(LINUX86_CYCLE_CPUID_RDTSC64,1,[Define which x86 cycle counter to use])
            ;;
        "cpuid_rdtsc32")
            AC_DEFINE(LINUX86_CYCLE_CPUID_RDTSC32,1,[Define which x86 cycle counter to use])
	    ;;
        "rdtsc")
            AC_DEFINE(LINUX86_CYCLE_RDTSC,1,[Define which x86 cycle counter to use])
	    ;;
        *)
            cpu_gcc_x86_cycle=no
	    ;;
    esac

    if test "$cpu_gcc_x86_cycle" = "no" ; then
        AC_MSG_ERROR([Linux86 cycle counter is not available on this system and or with the $CC compiler])
    fi
    MPID_TIMER_TYPE="long long"
    ;;

    gcc_ia64_cycle)
    AC_CACHE_CHECK([that IPF timer is available],
pac_cv_ia64_cycle,[
    AC_TRY_COMPILE(,[
    long var, *var_ptr=&var;
#ifdef __INTEL_COMPILER
#include "ia64regs.h"
    var=__getReg(_IA64_REG_AR_ITC);
#else
    __asm__ __volatile__("mov %0=ar.itc" : "=r" (var_ptr));
#endif
],pac_cv_gcc_ia64_cycle=yes,pac_cv_gcc_ia64_cycle=no)])
    if test "$pac_cv_gcc_ia64_cycle" != "yes" ; then
        AC_MSG_ERROR([IPF cycle counter is not available on this system and or with the $CC compiler])
     fi
     MPID_TIMER_TYPE="long"
     ;;

    linuxalpha_cycle)
    AC_MSG_ERROR([linuxalpha_cycle is no longer supported])
    ;;

    mach_absolute_time)
    AC_CHECK_FUNC(mach_absolute_time,,[AC_MSG_ERROR([mach_absolute_time is not available])])
    AC_CHECK_FUNC(mach_timebase_info,,[AC_MSG_ERROR([mach_timebase_info is not available])])
    MPID_TIMER_TYPE="uint64_t"
    ;;

    device)
    # The device selected should export the datatype for the timer
    # in MPID_DEVICE_TIMER_TYPE if something other than long is needed
    if test -n "$MPID_DEVICE_TIMER_TYPE" ; then
       MPID_TIMER_TYPE=$MPID_DEVICE_TIMER_TYPE
    fi
    ;;

    *)
    AC_MSG_ERROR([Invalid timer type $timer_type])
    ;;
esac
# Convert timer type to upper case
timer_type=`echo $timer_type | \
    tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
MPICH_TIMER_KIND=USE_$timer_type
AC_SUBST(MPICH_TIMER_KIND)
# ----------------------------------------------------------------------------
# End of code for timer support (except for ac_ OUTPUT)
# ----------------------------------------------------------------------------
# Setup other replaceable values
AC_SUBST(MPILIBNAME)
AC_SUBST(PMPILIBNAME)

if test "$NEEDSPLIB" = "yes" ; then
   LPMPILIBNAME="-l${PMPILIBNAME}"
fi
AC_SUBST(LPMPILIBNAME)

# Note that aint_size must be used instead of void_p where the desired check
# is on the size of MPI_Aint
aint_size=$ac_cv_sizeof_void_p
if test "$with_aint_size" -gt 0 ; then
   aint_size=$with_aint_size
   if test "$aint_size" != "$ac_cv_sizeof_void_p" ; then
        AC_MSG_RESULT([Overriding MPI_Aint to be $aint_size bytes])
   fi
fi
MPI_AINT=int
for type in int long long_long short ; do
    eval len=\$ac_cv_sizeof_$type
    if test "$len" = "$aint_size" ; then
        MPI_AINT=`echo $type | sed -e 's/_/ /'`
        # Make the sizeof AINT available to other configures
        MPI_SIZEOF_AINT=$len
        export MPI_SIZEOF_AINT
        case $type in
            int)
                MPI_AINT_FMT_DEC_SPEC="%d"
                MPI_AINT_FMT_HEX_SPEC="%x"
                MPIR_AINT_MAX="INT_MAX"
                ;;
            long)
                MPI_AINT_FMT_DEC_SPEC="%ld"
                MPI_AINT_FMT_HEX_SPEC="%lx"
                MPIR_AINT_MAX="LONG_MAX"
                ;;
            long_long)
                MPI_AINT_FMT_DEC_SPEC="%lld"
                MPI_AINT_FMT_HEX_SPEC="%llx"
                # tt#1776: if LLONG_MAX is missing, we fix it up in C, b/c it's
                # easier there.  See mpiiimpl.h.
                MPIR_AINT_MAX="LLONG_MAX"
                ;;
            short)
                MPI_AINT_FMT_DEC_SPEC="%hd"
                MPI_AINT_FMT_HEX_SPEC="%hx"
                MPIR_AINT_MAX="SHRT_MAX"
                ;;
            *)
                AC_MSG_WARN([unable to determine format specifiers for MPI_Aint, defaulting to int])
                MPI_AINT_FMT_DEC_SPEC="%d"
                MPI_AINT_FMT_HEX_SPEC="%x"
                MPIR_AINT_MAX="INT_MAX"
            ;;
        esac
        export MPI_AINT_FMT_DEC_SPEC MPI_AINT_FMT_HEX_SPEC
        break
    fi
done
AC_SUBST(MPI_AINT)
AC_SUBST(MPI_AINT_FMT_DEC_SPEC)
AC_SUBST(MPI_AINT_FMT_HEX_SPEC)
AC_DEFINE_UNQUOTED([MPIR_AINT_MAX],[$MPIR_AINT_MAX],[limits.h _MAX constant for MPI_Aint])

# If sizeof(mpi_aint) = sizeof(int), set this value
if test "$ac_cv_sizeof_int" = "$aint_size" ; then
    AC_DEFINE(SIZEOF_INT_IS_AINT,1,[define if sizeof(int) = sizeof(MPI_Aint)])
fi

# Find a pointer-sized int
for type in int long long_long short ; do
    eval len=\$ac_cv_sizeof_$type
    if test "$len" = "$ac_cv_sizeof_void_p" ; then
        case $type in
            int)
                MPIR_PINT_FMT_DEC_SPEC="\"%d\""
                MPIR_UPINT_FMT_DEC_SPEC="\"%u\""
                ;;
            long)
                MPIR_PINT_FMT_DEC_SPEC="\"%ld\""
                MPIR_UPINT_FMT_DEC_SPEC="\"%lu\""
                ;;
            long_long)
                MPIR_PINT_FMT_DEC_SPEC="\"%lld\""
                MPIR_UPINT_FMT_DEC_SPEC="\"%llu\""
                ;;
            short)
                MPIR_PINT_FMT_DEC_SPEC="\"%hd\""
                MPIR_UPINT_FMT_DEC_SPEC="\"%hu\""
                ;;
            *)
                AC_MSG_WARN([unable to determine format specifiers for MPIR_Pint, defaulting to int])
                MPIR_PINT_FMT_DEC_SPEC="\"%d\""
                MPIR_UPINT_FMT_DEC_SPEC="\"%u\""
            ;;
        esac
        MPIR_PINT=`echo $type | sed -e 's/_/ /'`
        break
    fi
done
AC_DEFINE_UNQUOTED(MPIR_Pint,$MPIR_PINT,[MPIR_Pint is a pointer-sized integer])
# allow @MPIR_PINT@ substitution in glue_romio.h
AC_SUBST([MPIR_PINT])

AC_DEFINE_UNQUOTED(MPIR_PINT_FMT_DEC_SPEC,
    $MPIR_PINT_FMT_DEC_SPEC,[MPIR_PINT_FMT_DEC_SPEC is the format
    specifier for printing Pint as a decimal])
AC_DEFINE_UNQUOTED(MPIR_Upint,unsigned $MPIR_PINT,[MPIR_Upint is an unsigned pointer-sized integer])
AC_DEFINE_UNQUOTED(MPIR_UPINT_FMT_DEC_SPEC,
    $MPIR_UPINT_FMT_DEC_SPEC,[MPIR_UPINT_FMT_DEC_SPEC is the format
    specifier for printing Upint as a decimal])

# ----------------------------------------------------------------------------
# MPI_AINT datatype
# ----------------------------------------------------------------------------
# Must be done after MPI_Aint type determination but before subconfigures.

# convert to 2-char hex size
case "$MPI_SIZEOF_AINT" in
    4)    len_mpi_aint=04 ;;
    8)    len_mpi_aint=08 ;;
    16)   len_mpi_aint=10 ;;
    *)    AC_MSG_ERROR([Unable to convert MPI_SIZEOF_AINT to a hex string.  This is either because we are building on a very strange platform or there is a bug somewhere in configure.]) ;;
esac
# MPI_AINT and MPI_OFFSET are already taken, appending a _DATATYPE suffix
MPI_AINT_DATATYPE=0x4c00${len_mpi_aint}43
AC_SUBST(MPI_AINT_DATATYPE)
export MPI_AINT_DATATYPE

# 0x4c000043 is 1275068483 in decimal, add ($MPI_SIZEOF_AINT * 256) and you get
# the decimal equivalent of the hex number
MPI_F77_AINT=`expr 1275068483 '+' '(' 256 '*' $MPI_SIZEOF_AINT ')'`
AC_SUBST(MPI_F77_AINT)
export MPI_F77_AINT
# ----------------------------------------------------------------------------

# define MPIU_Size_t - used to express the size of objects
# This is used in src/include/mpitypedefs.h to define MPIU_SIZE_T, 
# and is used in various parts of ch3 and mpid/common/sock.  
# This is used to handle the potential problem that a message is 
# too long to fit with an int.  However, we may still need to make
# some more adjustments in the code (this may not be used everywhere
# that it is needed).
#
# FIXME: this should really be in a util configure file, but we don't
# have one at the moment
#
MPIU_SIZE_T="unsigned $MPI_AINT"
AC_DEFINE_UNQUOTED(MPIU_SIZE_T,$MPIU_SIZE_T,[Set to a type that can express the size of the entire address space]) 

if test "$ac_cv_sizeof_void_p" -lt "$aint_size" ; then
    AC_DEFINE(USE_AINT_FOR_ATTRVAL,1,[Define if MPI_Aint should be used instead of void * for storing attribute values])
fi

# with MPI_AINT defined, now we can
# Get the size for the bsendoverhead
AC_CHECK_SIZEOF(MPIR_Bsend_data_t,0,[
#define MPI_Datatype int
typedef $MPI_AINT MPI_Aint;
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include "${master_top_srcdir}/src/include/mpibsend.h"]
)
if test "$ac_cv_sizeof_MPIR_Bsend_data_t" = "0" ; then
    AC_MSG_ERROR([Unable to determine the size of MPI_BSEND_OVERHEAD])
    # In the past, a default of 128 was used (still likely good enough),
    # but the autoconf SIZEOF macro has been changed to ignore the second
    # argument, so code that depended on the prior defined behavior now
    # silently breaks.
fi
BSEND_OVERHEAD=$ac_cv_sizeof_MPIR_Bsend_data_t
export BSEND_OVERHEAD
AC_SUBST(BSEND_OVERHEAD)

#
# See if we need to update the timer type (which was converted to uppercase)
if test "$timer_type" = "DEVICE" ; then
    # The device selected should export the datatype for the timer
    # in MPID_DEVICE_TIMER_TYPE if something other than long is needed
    if test -n "$MPID_DEVICE_TIMER_TYPE" ; then 
       MPID_TIMER_TYPE=$MPID_DEVICE_TIMER_TYPE
    fi
fi

dnl Configure any subdirectories.  Note that config.status will *not* 
dnl reexecute these!
dnl 
dnl Gastly problem.  CONFIG_SUBDIRS only adds the directories to the
dnl list of directories to be configured.  It does NOT control the
dnl timing of the configuration.  For that, we must do something different.
dnl Our original solution was to use a separate macro that does cause 
dnl immediate configure; this macro made use of the code that autoconf 
dnl uses to handle the subdir configure.  However, later versions of 
dnl autoconf did this in a way that caused problems, paritcularly with 
dnl errors reported as inconsistent cache files.  Instead, we simply
dnl invoke the configure scripts (if present) directly.

#
# -----------------------------------------------------------------------------
# Configure threads first.  This is necessary to obtain all required
# definitions, flags, and libraries that the other subsystems will need
#
# 
# -----------------------------------------------------------------------------
AC_ARG_WITH([thread-package],
[  --with-thread-package=package     Thread package to use. Supported thread packages include:
        posix or pthreads - POSIX threads (default, if required)
        solaris - Solaris threads (Solaris OS only)
        win - windows threads
        none - no threads
],,with_thread_package=posix)

if test "${thread_pkg_required}" = "no" -o "${with_thread_package}" = "no" ; then
   with_thread_package=none
fi

if test "${with_thread_package}" = "yes" ; then
   with_thread_package=posix
fi

if test "${thread_pkg_required}" = "yes" -a "${with_thread_package}" = "none" ; then
   AC_ERROR([if no thread package is available, use --enable-threads=single or funneled])
fi

MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_INVALID
case $with_thread_package in 
    posix|pthreads)
	with_thread_package=posix
	AC_CHECK_HEADERS(pthread.h)

        # If pthreads library is found, just include it on the link line. We don't try
        # to test if the C compiler needs it or not, since the C++ or Fortran
        # compilers might need it even if the C compiler doesn't
        # (nvcc with gfortran, for example).
        #
        # OSF1 has __pthread_create but not pthread_create (because of
        # inconsistencies in the pthread spec).  Thus, we look for pthread_key_create
        AC_CHECK_LIB([pthread],[pthread_key_create],have_pthreads=yes)
	if test "$have_pthreads" = "yes" ; then
	   PAC_PREPEND_FLAG([-lpthread],[LIBS])
	fi

        AC_CHECK_FUNCS(pthread_yield)

        # this check should come after the AC_CHECK_LIB for -lpthread
        AC_CHECK_FUNC([pthread_key_create],[],[AC_MSG_ERROR([unable to find pthreads library])])

	# Check for a routine that specify a routine to call on 
	# thread exit.  We can use this to release memory that may
	# be allocated by the MPICH library in the thread.  
	# A complication: pthread_cleanup_push may be a macro; in that
	# case, check_funcs will fail to find it.
	# Under OSX, pthread_cleanup_push and pop are macros that must
	# appear together in the same lexical scope, and hence are
	# really useless in libraries that may allocate data within 
	# a user-managed thread.
	AC_CHECK_FUNCS(pthread_cleanup_push)
	if test "$ac_cv_func_pthread_cleanup_push" = "no" ; then
            AC_CACHE_CHECK([whether pthread_cleanup_push is available (may be a macro in pthread.h)],pac_cv_func_pthread_cleanup_push,[
	    AC_TRY_LINK([
#include <pthread.h>
void f1(void *a) { return; }],
[pthread_cleanup_push( f1, (void *)0 );],
            pac_cv_func_pthread_cleanup_push=yes,
            pac_cv_func_pthread_cleanup_push=no)])
            if test "$pac_cv_func_pthread_cleanup_push" = yes ; then
	        AC_DEFINE(HAVE_PTHREAD_CLEANUP_PUSH_MACRO,1,[Define if pthread_cleanup_push is available, even as a macro])
            fi
    
        fi
	# Check for PTHREAD_MUTEX_RECURSIVE_NP and PTHREAD_MUTEX_RECURSIVE
	AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_RECURSIVE_NP],
	pac_cv_has_pthread_mutex_recursive_np,[
        AC_TRY_COMPILE([#include <pthread.h>],
                       [int a=PTHREAD_MUTEX_RECURSIVE_NP;],
		       pac_cv_has_pthread_mutex_recursive_np=yes,
		       pac_cv_has_pthread_mutex_recursive_np=no)])
	AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_RECURSIVE],
	pac_cv_has_pthread_mutex_recursive,[
        AC_TRY_COMPILE([#include <pthread.h>],
                       [int a=PTHREAD_MUTEX_RECURSIVE;],
		       pac_cv_has_pthread_mutex_recursive=yes,
		       pac_cv_has_pthread_mutex_recursive=no)])
        if test "$pac_cv_has_pthread_mutex_recursive_np" = yes ; then
	    AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE_NP,1,[Define if PTHREAD_MUTEX_RECURSIVE_NP is available in pthread.h])
	fi		       
        if test "$pac_cv_has_pthread_mutex_recursive" = yes ; then
	    AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE,1,[Define if PTHREAD_MUTEX_RECURSIVE is available in pthread.h])
	fi		       

        # Check for PTHREAD_MUTEX_ERRORCHECK_NP and PTHREAD_MUTEX_ERRORCHECK
        AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_ERRORCHECK_NP],
        pac_cv_has_pthread_mutex_errorcheck_np,[
        AC_TRY_COMPILE([#include <pthread.h>],
                       [int a=PTHREAD_MUTEX_ERRORCHECK_NP;],
                       pac_cv_has_pthread_mutex_errorcheck_np=yes,
                       pac_cv_has_pthread_mutex_errorcheck_np=no)])
        AC_CACHE_CHECK([whether pthread.h defines PTHREAD_MUTEX_ERRORCHECK],
        pac_cv_has_pthread_mutex_errorcheck,[
        AC_TRY_COMPILE([#include <pthread.h>],
                       [int a=PTHREAD_MUTEX_ERRORCHECK;],
                       pac_cv_has_pthread_mutex_errorcheck=yes,
                       pac_cv_has_pthread_mutex_errorcheck=no)])

        if test "$pac_cv_has_pthread_mutex_errorcheck" = yes ; then
            AC_DEFINE(PTHREAD_MUTEX_ERRORCHECK_VALUE,PTHREAD_MUTEX_ERRORCHECK,
                      [Define to an expression that will result in an error checking mutex type.])
        elif test "$pac_cv_has_pthread_mutex_errorcheck_np" = yes ; then
            AC_DEFINE(PTHREAD_MUTEX_ERRORCHECK_VALUE,PTHREAD_MUTEX_ERRORCHECK_NP,
                      [Define to an expression that will result in an error checking mutex type.])
        fi

	PAC_FUNC_NEEDS_DECL([#include <pthread.h>],pthread_mutexattr_settype)

        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_POSIX
	;;
    solaris)
	AC_CHECK_HEADERS(thread.h)
	AC_CHECK_FUNCS(thr_yield)
	AC_SEARCH_LIBS(thr_create,thread,found=yes,found=no)
	if test "$found" != "yes" ; then
	   AC_MSG_ERROR([unable to find Solaris threads library])
	fi
	# FIXME: need to add -mt if using solaris compilers
        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_SOLARIS
	;;
    win|windows)
        with_thread_package=win
        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_WIN
        AC_MSG_ERROR([The 'win' thread package is not supported via autoconf builds at this time.])
        ;;
    no|none)
	with_thread_package=none
        MPIU_THREAD_PACKAGE_NAME=MPIU_THREAD_PACKAGE_NONE
	;;
    *)
	AC_MSG_ERROR([The specified thread package, $with_thread_package, is not supported.]) 
	;;
esac

# Define and export the selected thread library so that other packages
# know what's used in MPICH
AC_DEFINE_UNQUOTED([MPIU_THREAD_PACKAGE_NAME],[$MPIU_THREAD_PACKAGE_NAME],[set to the name of the thread package])

# check for compiler-support for thread-local storage (MPIU_TLS_SPECIFIER)
AX_TLS

AC_CHECK_FUNCS(getpid)

# Choose a method to yield the procesor.

# If the user specified a method to use, we check if it's available.
# If a method was not specified, we make a guess based on the OS.  The
# default is to use sched_yield() or yield() if one is available,
# otherwise, default to nothing.  After that we define the appropriate
# macro.

AC_CHECK_HEADERS(sched.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(sys/select.h)
AC_CHECK_FUNCS(sched_yield yield usleep sleep select)

if test "$ac_cv_func_usleep" = "yes" ; then
    PAC_FUNC_NEEDS_DECL([#include <unistd.h>],usleep)
fi

AC_ARG_ENABLE([yield], 
    [AS_HELP_STRING([--enable-yield], [choose a method to yield the processor in busy loops.  Available methods are: sched_yield, yield, select, usleep, sleep, nothing])], 
    [AS_CASE([$enableval],
        [sched_yield], [AS_IF([test "x$ac_cv_func_sched_yield" != "xyes"], [enable_yield=unavail])],
        [yield],       [AS_IF([test "x$ac_cv_func_yield"       != "xyes"], [enable_yield=unavail])],
        [select],      [AS_IF([test "x$ac_cv_func_select"      != "xyes"], [enable_yield=unavail])],
        [usleep],      [AS_IF([test "x$ac_cv_func_usleep"      != "xyes"], [enable_yield=unavail])],
        [sleep],       [AS_IF([test "x$ac_cv_func_sleep"       != "xyes"], [enable_yield=unavail])],
        [nothing|no|none], [],
        [AC_MSG_ERROR([Invalid option $enableval for --enable-yield])])

     AS_IF([test "x$enable_yield" = "xunavail"], 
              [AC_MSG_ERROR([Yield method $enableval is not available on this platform.])])
    ],
    [# none specified by user; make a guess based on os
     AS_CASE([$host],
        [*-*-darwin*], 
            [# In Lion, sched_yield worked but none of the other options had any effect
             AS_IF([test "x$ac_cv_func_sched_yield" = "xyes"], [enable_yield=sched_yield],
                   [enable_yield=nothing])],
        [*-*-linux*], 
            [# sched_yield() has been broken in linux since 2.6.23, and no good alternative exists.
             enable_yield=nothing],
        [# default: just use sched_yield() or yield()
         AS_IF([test "x$ac_cv_func_sched_yield" = "xyes"], [enable_yield=sched_yield],
               [test "x$ac_cv_func_yield" = "xyes"], [enable_yield=yield],
               [enable_yield=nothing])])
    ]
)

# set the appropriate macro
AS_CASE([$enable_yield],
    [sched_yield], 
        [AC_DEFINE(USE_SCHED_YIELD_FOR_YIELD,1,[Define to use sched_yield to yield processor])],
    [yield],
        [AC_DEFINE(USE_YIELD_FOR_YIELD,1,[Define to use yield to yield processor])],
    [select],
        [AC_DEFINE(USE_SELECT_FOR_YIELD,1,[Define to use select to yield processor])],
    [usleep],
        [AC_DEFINE(USE_USLEEP_FOR_YIELD,1,[Define to use usleep to yield processor])],
    [sleep],
        [AC_DEFINE(USE_SLEEP_FOR_YIELD,1,[Define to use sleep to yield processor])],
    [nothing|no|none],
        [AC_DEFINE(USE_NOTHING_FOR_YIELD,1,[Define to use nothing to yield processor])],
    [AC_MSG_ERROR([Invalid value $enable_yield for enable_yield.])]
)

# Check for the Linux functions for controlling processor affinity.
# LINUX: sched_setaffinity
# AIX:   bindprocessor
# OSX (Leopard): thread_policy_set
AC_CHECK_FUNCS(sched_setaffinity sched_getaffinity bindprocessor thread_policy_set)
if test "$ac_cv_func_sched_setaffinity" = "yes" ; then
    # Test for the cpu process set type
    AC_CACHE_CHECK([whether cpu_set_t available],pac_cv_have_cpu_set_t,[
    AC_TRY_COMPILE( [
#include <sched.h>],[ cpu_set_t t; ],pac_cv_have_cpu_set_t=yes,pac_cv_have_cpu_set_t=no)])
    if test "$pac_cv_have_cpu_set_t" = yes ; then
        AC_DEFINE(HAVE_CPU_SET_T,1,[Define if cpu_set_t is defined in sched.h])

	AC_CACHE_CHECK([whether the CPU_SET and CPU_ZERO macros are defined],
	pac_cv_cpu_set_defined,[
        AC_TRY_LINK( [
#include <sched.h>],[ cpu_set_t t; CPU_ZERO(&t); CPU_SET(1,&t); ],
        pac_cv_cpu_set_defined=yes,pac_cv_cpu_set_defined=no)])
	if test "$pac_cv_cpu_set_defined" = "yes" ; then
	    AC_DEFINE(HAVE_CPU_SET_MACROS,1,[Define if CPU_SET and CPU_ZERO defined])
        fi
	# FIXME: Some versions of sched_setaffinity return ENOSYS (!), 
	# so we should test for the unfriendly and useless behavior
    fi
fi
if test "$ac_cv_func_thread_policy_set" = yes ; then
    AC_CACHE_CHECK([whether thread affinity macros defined],
    pac_cv_have_thread_affinity_policy,[
    AC_TRY_COMPILE([#include <mach/thread_policy.h>],[
#if !defined(THREAD_AFFINITY_POLICY) || !defined(THREAD_AFFINITY_TAG_NULL)
    :'thread macros not defined
],pac_cv_have_thread_affinity_policy=yes,
  pac_cv_have_thread_affinity_policy=no)])
    if test "$pac_cv_have_thread_affinity_policy" = yes ; then
        AC_DEFINE(HAVE_OSX_THREAD_AFFINITY,1,[Define is the OSX thread affinity policy macros defined])
    fi
fi

# -----------------------------------------------------------------------------
# End of thread configure
# -----------------------------------------------------------------------------


# Checkpointing
AC_ARG_ENABLE(checkpointing,
    [AC_HELP_STRING([--enable-checkpointing], [Enable application checkpointing])],
    [ if test "$enableval" != "no" ; then
        PAC_SET_HEADER_LIB_PATH(blcr)
	PAC_CHECK_HEADER_LIB_FATAL(blcr, libcr.h, cr, cr_init)
        AC_DEFINE(ENABLE_CHECKPOINTING,1,[Application checkpointing enabled])
      fi ],
)

# Update the cache first with the results of the previous configure steps
# We don't use the subdir cache because ensuring that the cache is consistant
# with the way in which configure wishes to use it is very difficult and 
# too prone to error.
dnl PAC_SUBDIR_CACHE(always)
# -----------------------------------------------------------------------------
# experiment with creating a cache file
#if test "$CONF_USE_CACHEFILE" = yes ; then
#    basecachefile=`pwd`/cache.base
#    set | grep ac_cv > $basecachefile
#    # Tell other configures to load this file
#    echo "Creating and exporting the base cache file $basecachefile"
#    CONF_BASE_CACHEFILE=$basecachefile
#    export CONF_BASE_CACHEFILE
#fi
PAC_CREATE_BASE_CACHE
# -----------------------------------------------------------------------------

#
# Configure the device second.  This way, any libraries or variables that
# it needs can be extracted before building the other subsystems (this is
# particularly important for the bindings, which may need to know the
# libraries in order to create the compilation scripts)

user_specified_atomic_primitives=no
if test "$DEBUG_SUBDIR_CACHE" = yes ; then 
    set -x
fi

dnl "configure" the device here via subconfigure.m4 files
m4_map([PAC_SUBCFG_CONFIGURE_SUBSYS], [PAC_SUBCFG_MODULE_LIST])

# now configure any actual recursively configures subsystems, such as ROMIO and
# hydra, or older components that haven't been updated to a subconfigure.m4 yet
for subsys in $devsubsystems $subsystems ; do 
    PAC_CONFIG_SUBDIR([$subsys],[],[AC_MSG_ERROR([$subsys configure failed])])
done 
if test "$DEBUG_SUBDIR_CACHE" = yes -a "$enable_echo" != yes ; then 
    set +x
fi
dnl PAC_SUBDIR_CACHE_CLEANUP

# Make subsystems available to makefiles.
# FIXME does the makefile actually need this?
subsystems="$devsubsystems $subsystems $bindingsubsystems"

# Find the size of OPA_ptr_t. This step needs to come after the OPA
# configure above in order to get the size OPA_ptr_t evaluated for
# this platform.
AC_CHECK_SIZEOF(OPA_ptr_t,0,[
#include "${master_top_srcdir}/src/openpa/src/opa_primitives.h"
pthread_mutex_t *OPA_emulation_lock;
])

if test "$enable_f77" != "yes" ; then
    # These are Fortran datatypes ONLY.  Set to null if no Fortran compiler.
    # Removed the invalid 2COMPLEX and 2DOUBLE_COMPLEX
    for name in CHARACTER INTEGER REAL LOGICAL COMPLEX DOUBLE_PRECISION \
	2INTEGER 2REAL DOUBLE_COMPLEX 2DOUBLE_PRECISION ; do
	fullname="MPI_$name"
	eval $fullname=MPI_DATATYPE_NULL
    done
    AC_MSG_WARN([Could not define Fortran MPI datatypes for C])
    AC_DEFINE(HAVE_NO_FORTRAN_MPI_TYPES_IN_C,1,[Define if the Fortran types are not available in C])
    # Temporary values for MPI_Fint (need help from the Fortran subsystem)
    MPI_FINT=int
fi
AC_SUBST(MPI_CHARACTER)
AC_SUBST(MPI_INTEGER)
AC_SUBST(MPI_REAL)
AC_SUBST(MPI_LOGICAL)
AC_SUBST(MPI_COMPLEX)
AC_SUBST(MPI_DOUBLE_PRECISION)
AC_SUBST(MPI_2INTEGER)
AC_SUBST(MPI_2REAL)
AC_SUBST(MPI_DOUBLE_COMPLEX)
AC_SUBST(MPI_2DOUBLE_PRECISION)
dnl AC_SUBST(MPI_2COMPLEX)
dnl AC_SUBST(MPI_2DOUBLE_COMPLEX)
AC_SUBST(MPI_FINT)

# If ROMIO was successfully configured, then ROMIO will have exported the
# definition of MPI_OFFSET_TYPE through its localdefs file (created by the
# ROMIO configure in src/mpi/romio/localdefs).  If MPI_OFFSET_TYPE was not
# defined, this code attempts to find a good choice for MPI_OFFSET_TYPE
# (As the offset type is used for File operations, the specific type
# really doesn't matter if ROMIO doesn't provide it).
if test -n "$MPI_OFFSET_TYPE" ; then
    # We got the value from the ROMIO configure
    MPI_OFFSET="$MPI_OFFSET_TYPE"
    # Get and export the size of this type if possible
    if test -z "$MPI_SIZEOF_OFFSET" ; then 
        # set a default
        AC_CACHE_CHECK([the sizeof MPI_Offset],ac_cv_sizeof_MPI_Offset,[
            ac_cv_sizeof_MPI_Offset=unknown
            AC_COMPUTE_INT([ac_cv_sizeof_MPI_Offset],[sizeof($MPI_OFFSET)],[],[
                AC_MSG_WARN([Unable to determine the size of MPI_Offset])
            ])
	])
	if test "$ac_cv_sizeof_MPI_Offset" != "unknown" ; then 
  	    MPI_SIZEOF_OFFSET=$ac_cv_sizeof_MPI_Offset
        fi
    fi
    export MPI_SIZEOF_OFFSET
else
    # Make a guess at the appropriate definition for offset.  Try to 
    # find a 64bit type.
    if test "$ac_cv_sizeof_long" = 8 ; then
        MPI_OFFSET="long"
	# Make the size of this type available to other configures
	MPI_SIZEOF_OFFSET=8
    elif test "$ac_cv_sizeof_long_long" = 8 ; then
        MPI_OFFSET="long long"
	# Make the size of this type available to other configures
	MPI_SIZEOF_OFFSET=8
    else
        MPI_OFFSET=long
        MPI_SIZEOF_OFFSET=$ac_cv_sizeof_long
    fi
    export MPI_SIZEOF_OFFSET
fi
AC_SUBST(MPI_OFFSET)

AS_CASE([$MPI_OFFSET],
        [int],         [MPIR_OFFSET_MAX="INT_MAX"],
        [long],        [MPIR_OFFSET_MAX="LONG_MAX"],
        ['long long'], [MPIR_OFFSET_MAX="LLONG_MAX"],
        [short],       [MPIR_OFFSET_MAX="SHRT_MAX"],
        [AC_MSG_ERROR([unable to determine MPIR_OFFSET_MAX for MPI_Offset])])
AC_DEFINE_UNQUOTED([MPIR_OFFSET_MAX],[$MPIR_OFFSET_MAX],[limits.h _MAX constant for MPI_Offset])

# FIXME: we need an explanation of why we need both MPI_OFFSET and 
# MPI_OFFSET_TYPEDEF.   Why is MPI_OFFSET_TYPEDEF necessary?
# This appears to be used by the Windows "winconfigure.wsf" which is used
# to create a multiline definition using an #ifdef check on USE_GCC 
# We may wish to use a different approach
MPI_OFFSET_TYPEDEF="typedef $MPI_OFFSET MPI_Offset;"
AC_SUBST(MPI_OFFSET_TYPEDEF)
#
# Fortran type for an Offset type (needed to define MPI_DISPLACEMENT_CURRENT
# The value for this comes from ROMIO, and is needed in mpif.h.in
# First, we check that this works with both Fortran compilers (if
# they are defined)
#
# If there is no FORTRAN_MPI_OFFSET type (because ROMIO is disabled),
# just use INTEGER
if test -z "$FORTRAN_MPI_OFFSET" ; then
    FORTRAN_MPI_OFFSET=INTEGER
fi
if test "$enable_f77" = yes -a "$enable_fc" = yes ; then
    AC_LANG_PUSH([Fortran 77])
    AC_MSG_CHECKING([whether the Fortran Offset type works with Fortran 77])
    AC_COMPILE_IFELSE([
        AC_LANG_PROGRAM([],[      $FORTRAN_MPI_OFFSET i])
    ],[has_f77_offsettype=yes],[has_f77_offsetype=no])
    AC_MSG_RESULT($has_f77_offsettype)
    AC_LANG_POP([Fortran 77])

    AC_LANG_PUSH([Fortran])
    AC_MSG_CHECKING([whether the Fortran Offset type works with Fortran 90])
    AC_COMPILE_IFELSE([
        AC_LANG_PROGRAM([],[      $FORTRAN_MPI_OFFSET i])
    ],[has_fc_offsettype=yes],[has_fc_offsetype=no])
    AC_LANG_POP([Fortran])
    AC_MSG_RESULT($has_fc_offsettype)

    if test "$has_f77_offsettype" != yes -o "$has_fc_offsettype" != yes ; then
        AC_MSG_WARN([mpif.h is not compatible with both $F77 $FFLAGS and $FC $FCFLAGS.  We recommend that you set both F77 and FC to the same compiler and reconfigure.])
    fi
fi
AC_SUBST(FORTRAN_MPI_OFFSET)
#

# ----------------------------------------------------------------------------
# MPI_OFFSET datatype
# ----------------------------------------------------------------------------
# must be done after ROMIO configure step
case "$MPI_SIZEOF_OFFSET" in
    4)    len_mpi_offset=04 ;;
    8)    len_mpi_offset=08 ;;
    16)   len_mpi_offset=10 ;;
    *)    AC_MSG_ERROR([Unable to convert MPI_SIZEOF_OFFSET to a hex string.  This is either because we are building on a very strange platform or there is a bug somewhere in configure.]) ;;
esac
MPI_OFFSET_DATATYPE=0x4c00${len_mpi_offset}44
AC_SUBST(MPI_OFFSET_DATATYPE)
export MPI_OFFSET_DATATYPE

# 0x4c000044 is 1275068484 in decimal, add ($MPI_SIZEOF_OFFSET * 256) and you get
# the decimal equivalent of the hex number
MPI_F77_OFFSET=`expr 1275068484 '+' '(' 256 '*' $MPI_SIZEOF_OFFSET ')'`
AC_SUBST(MPI_F77_OFFSET)
export MPI_F77_OFFSET

# ----------------------------------------------------------------------------
# MPI_COUNT datatype
# ----------------------------------------------------------------------------
# quick sanity checking to avoid a bad test immediately below
AS_IF([test -z "$MPI_SIZEOF_AINT"],
      [AC_MSG_ERROR([size of MPI_Aint is unknown at this stage])])
AS_IF([test -z "$MPI_SIZEOF_OFFSET"],
      [AC_MSG_ERROR([size of MPI_Offset is unknown at this stage])])

AS_IF([test "$MPI_SIZEOF_AINT" -gt "$MPI_SIZEOF_OFFSET"],
      [# an unlikely case, but I suppose it's theoretically possible
       MPI_COUNT="$MPI_AINT"
       COUNT_KIND="$ADDRESS_KIND"
       MPIR_COUNT_MAX="$MPIR_AINT_MAX"
       MPI_SIZEOF_COUNT="$MPI_SIZEOF_AINT"],
      [# don't bother checking whether Aint or Offset are larger than int, they
       # surely will be
       MPI_COUNT="$MPI_OFFSET"
       COUNT_KIND="$OFFSET_KIND"
       MPIR_COUNT_MAX="$MPIR_OFFSET_MAX"
       MPI_SIZEOF_COUNT="$MPI_SIZEOF_OFFSET"])
AC_SUBST([MPI_COUNT])
AC_SUBST([COUNT_KIND])
AC_DEFINE_UNQUOTED([MPIR_COUNT_MAX],[$MPIR_COUNT_MAX],[limits.h _MAX constant for MPI_Count])
AC_DEFINE_UNQUOTED(MPIR_Ucount,unsigned $MPI_COUNT,[MPIR_Ucount is an unsigned MPI_Count-sized integer])

AS_CASE([$MPI_SIZEOF_COUNT],
        [4], [len_mpi_count=04],
        [8], [len_mpi_count=08],
        [16],[len_mpi_count=10],
        [AC_MSG_ERROR([Unable to convert MPI_SIZEOF_COUNT to a hex string!])])
MPI_COUNT_DATATYPE=0x4c00${len_mpi_count}45
AC_SUBST([MPI_COUNT_DATATYPE])

# 0x4c000045 is 1275068485 in decimal, add ($MPI_SIZEOF_COUNT * 256) and you get
# the decimal equivalent of the hex number
MPI_F77_COUNT=`expr 1275068485 '+' '(' 256 '*' $MPI_SIZEOF_OFFSET ')'`
AC_SUBST([MPI_F77_COUNT])

# ----------------------------------------------------------------------------

#
# Set size of MPI_Status.  Must come after MPI_Count determination.
#

#
# The size of MPI_Status is needed for the Fortran interface. 
#
# WARNING!!! this is a spot where we duplicate code from mpi.h.in and it *must*
# be kept in sync in order to make a proper computation
AC_CACHE_CHECK([for size of MPI_Status],[pac_cv_sizeof_mpi_status],[
dnl "double-quote" (in m4), otherwise you end up with a heinous bug because of
dnl the array subscripting below
[
    rm -f pac_mpi_status.h
    cat > pac_mpi_status.h <<_EOF
typedef struct {
    int count_lo;
    int count_hi_and_cancelled;
    int MPI_SOURCE;
    int MPI_TAG;
    int MPI_ERROR;
} MPI_Status;
_EOF
]

dnl just compute it, since a 1s-complement or sign-and-magnitude machine is
dnl *highly* unlikely.  Users will report the error if it is ever 
dnl encountered, which will be safer than attempting some never-tested
dnl default fallback.
    AC_COMPUTE_INT([pac_cv_sizeof_mpi_status],
                   [sizeof(MPI_Status)],
                   [#include "pac_mpi_status.h"],
                   [AC_MSG_ERROR([unable to compute status size, are you compiling on a non-2s-complement host?])])
    rm -f pac_mpi_status.h
])

SIZEOF_MPI_STATUS=$pac_cv_sizeof_mpi_status
export SIZEOF_MPI_STATUS
AC_SUBST([SIZEOF_MPI_STATUS])

if test "$enable_f77" = yes -a -z "$MPI_STATUS_SIZE" ; then
    if test -n "$SIZEOF_MPI_STATUS" ; then
        # compute from the C sizeof
        AS_VAR_ARITH([MPI_STATUS_SIZE],[$SIZEOF_MPI_STATUS / $ac_cv_sizeof_int])
        if test "$MPI_STATUS_SIZE" = "0" ; then
            AC_MSG_ERROR([Could not compute the size of MPI_Status])
        fi
    else
        AC_MSG_ERROR([MPI_STATUS_SIZE was not defined!])
    fi
fi # enable_f77 and mpi_status_size not set
AC_SUBST([MPI_STATUS_SIZE])
MPIF_STATUS_SIZE=$MPI_STATUS_SIZE
AC_DEFINE_UNQUOTED([MPIF_STATUS_SIZE],[$MPIF_STATUS_SIZE],[Size of an MPI_STATUS, in Fortran, in Fortran integers])

if test "$enable_f77" = yes ; then
    # Check if multiple __attribute__((alias)) is available
    # This test requires MPI_STATUS_SIZE, and thus must be made after 
    # MPI_STATUS_SIZE is determined
    if test "$enable_multi_aliases" = "yes" ; then
        PAC_C_MULTI_ATTR_ALIAS
        if test "$pac_c_multi_attr_alias" = "yes" ; then
            PAC_F2C_ATTR_ALIGNED_SIZE([1],[CMB_1INT_ALIGNMENT])
            AC_SUBST(CMB_1INT_ALIGNMENT)
            PAC_F2C_ATTR_ALIGNED_SIZE([$MPI_STATUS_SIZE],[CMB_STATUS_ALIGNMENT],
                                      [32])
            AC_SUBST(CMB_STATUS_ALIGNMENT)
            if test "X$CMB_1INT_ALIGNMENT" != "X" \
                 -a "X$CMB_STATUS_ALIGNMENT" != "X" ; then
                AC_DEFINE(HAVE_C_MULTI_ATTR_ALIAS, 1,
                    [Define if multiple __attribute__((alias)) are supported])
            fi
        fi
    fi
fi

# ----------------------------------------------------------------------------

dnl FIXME XXX DJG does this need to actually be conditional on something?
dnl previously it was conditional on the successful execution of
dnl "src/binding/f90/configure" but that would only fail if FC couldn't be
dnl determined or a bad VPATH build env was detected
AC_DEFINE(HAVE_FC_TYPE_ROUTINES,1,[Define if Fortran 90 type routines available])

# -----------------------------------------------------------------------------
# Get the value of MPI_MAX_PROCESSOR_NAME
if test -z "$MPID_MAX_PROCESSOR_NAME" ; then
    if test -z "$MPI_MAX_PROCESSOR_NAME" ; then
       MPI_MAX_PROCESSOR_NAME=128
    fi
    AC_MSG_WARN([The $with_device device did not set the maximum size of a processor name, $MPI_MAX_PROCESSOR_NAME being used.])
else
    MPI_MAX_PROCESSOR_NAME=$MPID_MAX_PROCESSOR_NAME
fi
AC_SUBST(MPI_MAX_PROCESSOR_NAME)

# Get the value of MPI_MAX_LIBRARY_VERSION_STRING
if test -z "$MPID_MAX_LIBRARY_VERSION_STRING" ; then
    MPI_MAX_LIBRARY_VERSION_STRING=8192
else
    MPI_MAX_LIBRARY_VERSION_STRING=$MPID_MAX_LIBRARY_VERSION_STRING
fi
AC_SUBST(MPI_MAX_LIBRARY_VERSION_STRING)

# Get the value of MPI_MAX_ERROR_STRING
if test -z "$MPID_MAX_ERROR_STRING" ; then
    if test -z "$MPI_MAX_ERROR_STRING" ; then
       MPI_MAX_ERROR_STRING=512
    fi
    AC_MSG_WARN([The $with_device device did not set the maximum size of an error string, $MPI_MAX_ERROR_STRING being used.])
else
    MPI_MAX_ERROR_STRING=$MPID_MAX_ERROR_STRING
fi
AC_SUBST(MPI_MAX_ERROR_STRING)

# Get the value of libtool_static_flag
if test ! -z "$MPID_LIBTOOL_STATIC_FLAG" ; then
   mpich_libtool_static_flag="$MPID_LIBTOOL_STATIC_FLAG"
else
   mpich_libtool_static_flag="-static"
fi
AC_SUBST([mpich_libtool_static_flag])

# Add a definition that is used to help support Windows DLLs (used in mpi.h.in)
MPIU_DLL_SPEC_DEF="#define MPIU_DLL_SPEC"
AC_SUBST(MPIU_DLL_SPEC_DEF)

dnl We can configure the test directory after the rest of the configure 
dnl steps because it does not depend on them.
# set and export values that the test/mpi configure will reference to ensure
# that the correct decisions are made since this configure happens before the
# MPICH library is built. 
MPICH_ENABLE_CXX=$enable_cxx
MPICH_ENABLE_F77=$enable_f77
MPICH_ENABLE_FC=$enable_fc
export MPICH_ENABLE_CXX
export MPICH_ENABLE_F77
export MPICH_ENABLE_FC
AM_CONDITIONAL([BUILD_CXX_LIB],[test "$enable_cxx" = "yes"])
AM_CONDITIONAL([BUILD_F77_BINDING],[test "$enable_f77" = "yes"])
dnl FIXME DJG this has been moved to the f90 bindings subconfigure.m4 for now
dnl AM_CONDITIONAL([BUILD_F90_LIB],[test "$enable_fc" = "yes"])
# MPI_SRCDIR gives the test/mpi configure the location of the source
# files for an MPI implementation
if test -n "$ac_abs_srcdir" ; then
    MPI_SRCDIR=$ac_abs_srcdir
fi
# Pass these two values with "MPI" names to the test configure
MPI_NO_SPAWN=$MPID_NO_SPAWN
export MPI_NO_SPAWN
MPI_NO_RMA=$MPID_NO_RMA
export MPI_NO_RMA

# Attach program prefix and suffix to executable names for Makefile
AC_SUBST(MPICXX_NAME)
AC_SUBST(MPICPP_NAME)
PAC_GET_EXENAME("mpicxx", MPICXX_NAME)
PAC_GET_EXENAME("mpic++", MPICPP_NAME)

AC_CONFIG_SUBDIRS([test/mpi])
dnl
dnl Generate the Makefiles from Makefile.in
dnl Also generate mpi.h from mpi.h.in so that we can eliminate all ifdefs
dnl from the file.
dnl
dnl Run a setup command for any external modules (normally, this is empty)
dnl Pass a subset of the environment to the invoked process.
AC_OUTPUT_COMMANDS([
for prog in $EXTERNAL_SETUPS - ; do
    if test "$prog" != "-" ; then 
      dir=`dirname $prog`
      name=`basename $prog`
      (cd $dir && ./$name)
    fi
done],[
EXTERNAL_SETUPS="$EXTERNAL_SETUPS"
LIBDIR="$libbuild_dir"
MPILIBNAME="$MPILIBNAME"
PMPILIBNAME="$PMPILIBNAME"
AR="$AR"
CC="$CC"
CPPFLAGS="$CPPFLAGS"
CFLAGS="$CFLAGS"
export LIBDIR ; export MPILIBNAME ; export AR ; export CC ; export CPPFLAGS 
export PMPILIBNAME 
export CFLAGS
# For test/mpi/configure
MPI_SRCDIR=$MPI_SRCDIR
MPI_NO_SPAWN=$MPID_NO_SPAWN
export MPI_SRCDIR
export MPI_NO_SPAWN
])

if test -z "$includebuild_dir" ; then
    includebuild_dir=`pwd`/src/include
fi
if test -z "$libbuild_dir" ; then
    libbuild_dir=`pwd`/lib
fi
if test -z "$modincbuild_dir" ; then
    # The include files may be in a different directory from the mpif.h file
    modincbuild_dir=`pwd`/src/binding/f90
fi

dnl
dnl If we rerun configure, place a file in the lib directory with the
dnl date.  We can use this to avoid rebuilding the library when
dnl a build aborts due to an error (this is intended to help developers)
AC_OUTPUT_COMMANDS([if [ ! -d lib ] ; then mkdir lib ; fi 
date > lib/newconfig])

AC_OUTPUT_COMMANDS([chmod a+x src/util/dbg/getfuncstack])

AC_OUTPUT_COMMANDS([chmod a+x test/commands/cmdtests])


AC_DEFINE(HAVE_MPICHCONF,1,[Define so that we can test whether the mpichconf.h file has been included])

# Add the LDFLAGS/LIBS we got so far to WRAPPERs
WRAPPER_LDFLAGS="$WRAPPER_LDFLAGS $LDFLAGS"
WRAPPER_LIBS="$WRAPPER_LIBS $LIBS"

if test "$USE_PMI2_API" = "yes" ; then
   AC_DEFINE(USE_PMI2_API, 1, [Define if PMI2 API must be used])
fi

########################################################################

# cause libtool script to be built now so that we can use it to test one last
# linking issue on Darwin
LT_OUTPUT

# see ticket #1590 for some more background on these Darwin linking issues
if test "X$enable_shared" = "Xyes" ; then
    AS_CASE([$host],
        [*-*-darwin*],
        [
        # sanity check that -Wl,-flat_namespace works on darwin, unless the user
        # asked us not to add it
        if test "X$enable_two_level_namespace" = "Xno"; then
            # TODO, move this into a PAC macro with real autoconf caching
            pac_cv_wl_flat_namespace_works=no
            AC_MSG_CHECKING([if the C compiler accepts -Wl,-flat_namespace])
            PAC_PUSH_FLAG([LDFLAGS])
            PAC_APPEND_FLAG([-Wl,-flat_namespace],[LDFLAGS])
            AC_LINK_IFELSE([AC_LANG_PROGRAM([],[int i;])],
                           [AC_MSG_RESULT([yes])
                            pac_cv_wl_flat_namespace_works=yes],
                           [AC_MSG_RESULT([no])])
            PAC_POP_FLAG([LDFLAGS])

            # Technically we may not be able to use the same form of the argument
            # for all four compilers (CC/CXX/F77/FC).  But we only think this is
            # necessary for Darwin for now, so this unconditional, single-var
            # approximation will work for now.
            if test "X$pac_cv_wl_flat_namespace_works" = "Xyes" ; then
                PAC_APPEND_FLAG([-Wl,-flat_namespace], [LDFLAGS])
                PAC_APPEND_FLAG([-Wl,-flat_namespace], [WRAPPER_LDFLAGS])
            fi
        fi

        # We only need to bother with -Wl,-commons,-use_dylibs if we are
        # building fortran bindings (no common block usage in our C libs).
        if test "X$enable_f77" = "Xyes" ; then
            # We also don't need this argument if flat_namespace is used.
            if test "X$enable_two_level_namespace" != "Xno" ; then
                # TODO, move this into a PAC macro with real autoconf caching
                pac_cv_wl_commons_use_dylibs_works=no
                AC_MSG_CHECKING([if the F77 compiler accepts -Wl,-commons,use_dylibs])
                AC_LANG_PUSH([Fortran 77])
                PAC_PUSH_FLAG([LDFLAGS])
                PAC_APPEND_FLAG([-Wl,-commons,use_dylibs], [LDFLAGS])
                AC_LINK_IFELSE([AC_LANG_PROGRAM([],[      INTEGER i])],
                               [AC_MSG_RESULT([yes])
                                pac_cv_wl_commons_use_dylibs_works=yes],
                               [AC_MSG_RESULT([no])])
                PAC_POP_FLAG([LDFLAGS])
                AC_LANG_POP([Fortran 77])

                # Add the flag to the WRAPPER_LDFLAGS, since this common block issue
                # is really only a problem for dynamically linked user programs.
                #
                # Technically we may not be able to use the same form of the argument
                # for all four compilers (CC/CXX/F77/FC).  But we only think this is
                # necessary for Darwin for now, so this unconditional, single-var
                # approximation will work for now.
                if test "X$pac_cv_wl_commons_use_dylibs_works" = "Xyes" ; then
                    PAC_APPEND_FLAG([-Wl,-commons,use_dylibs], [WRAPPER_LDFLAGS])
                fi
            fi
        fi
        ]
    )
fi

########################################################################

if test -z "$pkgconfigdir" ; then
  # The default pkgconfig dir is under the lib dir
  pkgconfigdir=$libdir/pkgconfig
fi
AC_SUBST(pkgconfigdir)
export pkgconfigdir

dnl This includes an experimental pkgconfig file for ch3 in the src/pkgconfig
dnl directory
AC_OUTPUT(Makefile \
          examples/Makefile \
          test/Makefile \
          test/commands/Makefile \
          src/include/mpichinfo.h \
	  mpich-doxygen \
          src/include/glue_romio.h \
          src/include/mpichtimer.h \
          src/binding/cxx/mpicxx.h \
	  src/binding/f77/mpif.h \
	  src/binding/f77/setbotf.f \
	  src/binding/f77/setbot.c \
	  src/binding/f90/mpi_sizeofs.f90 \
	  src/binding/f90/mpi_base.f90 \
	  src/binding/f90/mpi_constants.f90 \
	  src/packaging/pkgconfig/mpich.pc \
	  src/packaging/envmods/mpich.module \
          src/env/mpixxx_opts.conf \
          src/env/mpicc.sh \
	  src/env/mpicc.bash \
          src/env/mpicxx.sh \
	  src/env/mpicxx.bash \
	  src/env/mpif77.sh \
	  src/env/mpif77.bash \
	  src/env/mpif90.sh \
	  src/env/mpif90.bash \
          src/env/parkill \
	  src/util/dbg/getfuncstack \
          src/include/mpi.h \
          doc/design/Makefile \
          doc/installguide/Makefile \
          doc/logging/Makefile \
          doc/refman/Makefile \
          doc/userguide/Makefile \
          test/commands/cmdtests)

echo 'Configuration completed.'