File: configure.ac

package info (click to toggle)
valgrind 1:3.14.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 156,980 kB
  • sloc: ansic: 728,128; exp: 26,134; xml: 22,268; cpp: 7,638; asm: 7,312; makefile: 6,102; perl: 5,910; sh: 5,717
file content (4703 lines) | stat: -rw-r--r-- 147,607 bytes parent folder | download
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

##------------------------------------------------------------##
# 
# The multiple-architecture stuff in this file is pretty
# cryptic.  Read docs/internals/multiple-architectures.txt
# for at least a partial explanation of what is going on.
#
##------------------------------------------------------------##

# Process this file with autoconf to produce a configure script.
AC_INIT([Valgrind],[3.14.0],[valgrind-users@lists.sourceforge.net])
AC_CONFIG_SRCDIR(coregrind/m_main.c)
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign subdir-objects])

AM_MAINTAINER_MODE

#----------------------------------------------------------------------------
# Do NOT modify these flags here. Except in feature tests in which case
# the original values must be properly restored.
#----------------------------------------------------------------------------
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"

#----------------------------------------------------------------------------
# Checks for various programs.
#----------------------------------------------------------------------------

AC_PROG_LN_S
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_CXX
# AC_PROG_OBJC apparently causes problems on older Linux distros (eg. with
# autoconf 2.59).  If we ever have any Objective-C code in the Valgrind code
# base (eg. most likely as Darwin-specific tests) we'll need one of the
# following:
# - put AC_PROG_OBJC in a Darwin-specific part of this file
# - Use AC_PROG_OBJC here and up the minimum autoconf version
# - Use the following, which is apparently equivalent:
#     m4_ifdef([AC_PROG_OBJC],
#        [AC_PROG_OBJC],
#        [AC_CHECK_TOOL([OBJC], [gcc])
#         AC_SUBST([OBJC])
#         AC_SUBST([OBJCFLAGS])
#        ])
AC_PROG_RANLIB
# Set LTO_RANLIB variable to an lto enabled ranlib
if test "x$LTO_RANLIB" = "x"; then
  AC_PATH_PROGS([LTO_RANLIB], [gcc-ranlib])
fi
AC_ARG_VAR([LTO_RANLIB],[Library indexer command for link time optimisation])

# provide a very basic definition for AC_PROG_SED if it's not provided by
# autoconf (as e.g. in autoconf 2.59).
m4_ifndef([AC_PROG_SED],
          [AC_DEFUN([AC_PROG_SED],
                    [AC_ARG_VAR([SED])
                     AC_CHECK_PROGS([SED],[gsed sed])])])
AC_PROG_SED

# If no AR variable was specified, look up the name of the archiver. Otherwise
# do not touch the AR variable.
if test "x$AR" = "x"; then
  AC_PATH_PROGS([AR], [`echo $LD | $SED 's/ld$/ar/'` "ar"], [ar])
fi
AC_ARG_VAR([AR],[Archiver command])

# same for LTO_AR variable for lto enabled archiver
if test "x$LTO_AR" = "x"; then
  AC_PATH_PROGS([LTO_AR], [gcc-ar])
fi
AC_ARG_VAR([LTO_AR],[Archiver command for link time optimisation])


# Check for the compiler support
if test "${GCC}" != "yes" ; then
   AC_MSG_ERROR([Valgrind relies on GCC to be compiled])
fi

# figure out where perl lives
AC_PATH_PROG(PERL, perl)

# figure out where gdb lives
AC_PATH_PROG(GDB, gdb, "/no/gdb/was/found/at/configure/time")
AC_DEFINE_UNQUOTED(GDB_PATH, "$GDB", [path to GDB])

# some older automake's don't have it so try something on our own
ifdef([AM_PROG_AS],[AM_PROG_AS],
[
AS="${CC}"
AC_SUBST(AS)

ASFLAGS=""
AC_SUBST(ASFLAGS)
])


# Check if 'diff' supports -u (universal diffs) and use it if possible.

AC_MSG_CHECKING([for diff -u])
AC_SUBST(DIFF)

# Comparing two identical files results in 0.
tmpfile="tmp-xxx-yyy-zzz"
touch $tmpfile;
if diff -u $tmpfile $tmpfile ; then
    AC_MSG_RESULT([yes])
    DIFF="diff -u"
else
    AC_MSG_RESULT([no])
    DIFF="diff"
fi
rm $tmpfile

# Make sure we can compile in C99 mode.
AC_PROG_CC_C99
if test "$ac_cv_prog_cc_c99" == "no"; then
    AC_MSG_ERROR([Valgrind relies on a C compiler supporting C99])
fi

# We don't want gcc < 3.0
AC_MSG_CHECKING([for a supported version of gcc])

# Obtain the compiler version.
# 
# A few examples of how the ${CC} --version output looks like:
#
# ######## gcc variants ########
# Arch Linux: i686-pc-linux-gnu-gcc (GCC) 4.6.2
# Debian Linux: gcc (Debian 4.3.2-1.1) 4.3.2
# openSUSE: gcc (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
# Exherbo Linux: x86_64-pc-linux-gnu-gcc (Exherbo gcc-4.6.2) 4.6.2
# MontaVista Linux for ARM: arm-none-linux-gnueabi-gcc (Sourcery G++ Lite 2009q1-203) 4.3.3
# OS/X 10.6: i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
# OS/X 10.7: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
#
# ######## clang variants ########
# Clang: clang version 2.9 (tags/RELEASE_29/final)
# Apple clang: Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
# FreeBSD clang: FreeBSD clang version 3.1 (branches/release_31 156863) 20120523
#
# ######## Apple LLVM variants ########
# Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
# Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
#
[
if test "x`${CC} --version | $SED -n -e 's/.*\Apple \(LLVM\) version.*clang.*/\1/p'`" = "xLLVM" ;
then
    is_clang="applellvm"
    gcc_version=`${CC} --version | $SED -n -e 's/.*LLVM version \([0-9.]*\).*$/\1/p'`
elif test "x`${CC} --version | $SED -n -e 's/.*\(clang\) version.*/\1/p'`" = "xclang" ;
then
    is_clang="clang"
    # Don't use -dumpversion with clang: it will always produce "4.2.1".
    gcc_version=`${CC} --version | $SED -n -e 's/.*clang version \([0-9.]*\).*$/\1/p'`
elif test "x`${CC} --version | $SED -n -e 's/icc.*\(ICC\).*/\1/p'`" = "xICC" ; 
then
    is_clang="icc"
    gcc_version=`${CC} -dumpversion 2>/dev/null`
else
    is_clang="notclang"
    gcc_version=`${CC} -dumpversion 2>/dev/null`
    if test "x$gcc_version" = x; then
	gcc_version=`${CC} --version | $SED -n -e 's/[^ ]*gcc[^ ]* ([^)]*) \([0-9.]*\).*$/\1/p'`
    fi
fi
]
AM_CONDITIONAL(COMPILER_IS_CLANG, test $is_clang = clang -o $is_clang = applellvm)
AM_CONDITIONAL(COMPILER_IS_ICC, test $is_clang = icc)

# Note: m4 arguments are quoted with [ and ] so square brackets in shell
# statements have to be quoted.
case "${is_clang}-${gcc_version}" in
     applellvm-5.1|applellvm-[[6-9]].*|applellvm-[[1-9][0-9]]*)
	AC_MSG_RESULT([ok (Apple LLVM version ${gcc_version})])
	;;
     icc-1[[3-9]].*)
	AC_MSG_RESULT([ok (ICC version ${gcc_version})])
	;;
     notclang-[[3-9]]|notclang-[[3-9]].*|notclang-[[1-9][0-9]]*)
	AC_MSG_RESULT([ok (${gcc_version})])
	;;
     clang-2.9|clang-[[3-9]].*|clang-[[1-9][0-9]]*)
	AC_MSG_RESULT([ok (clang-${gcc_version})])
	;;
     *)
	AC_MSG_RESULT([no (${is_clang}-${gcc_version})])
	AC_MSG_ERROR([please use gcc >= 3.0 or clang >= 2.9 or icc >= 13.0 or Apple LLVM >= 5.1])
	;;
esac

#----------------------------------------------------------------------------
# Arch/OS/platform tests.
#----------------------------------------------------------------------------
# We create a number of arch/OS/platform-related variables.  We prefix them
# all with "VGCONF_" which indicates that they are defined at
# configure-time, and distinguishes them from the VGA_*/VGO_*/VGP_*
# variables used when compiling C files.

AC_CANONICAL_HOST

AC_MSG_CHECKING([for a supported CPU])

# ARCH_MAX reflects the most that this CPU can do: for example if it
# is a 64-bit capable PowerPC, then it must be set to ppc64 and not ppc32.
# Ditto for amd64.  It is used for more configuration below, but is not used
# outside this file.
#
# Power PC returns powerpc for Big Endian.  This was not changed when Little
# Endian support was added to the 64-bit architecture.  The 64-bit Little
# Endian systems explicitly state le in the host_cpu.  For clarity in the
# Valgrind code, the ARCH_MAX name will state LE or BE for the endianness of
# the 64-bit system.  Big Endian is the only mode supported on 32-bit Power PC.
# The abreviation PPC or ppc refers to 32-bit and 64-bit systems with either
# Endianness.  The name PPC64 or ppc64 to 64-bit systems of either Endianness.
# The names ppc64be or PPC64BE refer to only 64-bit systems that are Big
# Endian.  Similarly, ppc64le or PPC64LE refer to only 64-bit systems that are
# Little Endian.

case "${host_cpu}" in
     i?86) 
	AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="x86"
        ;;

     x86_64) 
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="amd64"
        ;;

     powerpc64)
     # this only referrs to 64-bit Big Endian
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="ppc64be"
        ;;

     powerpc64le)
     # this only referrs to 64-bit Little Endian
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="ppc64le"
        ;;

     powerpc)
        # On Linux this means only a 32-bit capable CPU.
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="ppc32"
        ;;

     s390x)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="s390x"
        ;;

     arm*)
	AC_MSG_RESULT([ok (${host_cpu})])
	ARCH_MAX="arm"
	;;

     aarch64*)
       AC_MSG_RESULT([ok (${host_cpu})])
       ARCH_MAX="arm64"
       ;;

     mips)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="mips32"
        ;;

     mipsel)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="mips32"
        ;;

     mipsisa32r2)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="mips32"
        ;;

     mips64*)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="mips64"
        ;;

     mipsisa64*)
        AC_MSG_RESULT([ok (${host_cpu})])
        ARCH_MAX="mips64"
        ;;

     *) 
	AC_MSG_RESULT([no (${host_cpu})])
	AC_MSG_ERROR([Unsupported host architecture. Sorry])
	;;
esac

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

# Sometimes it's convenient to subvert the bi-arch build system and
# just have a single build even though the underlying platform is
# capable of both.  Hence handle --enable-only64bit and
# --enable-only32bit.  Complain if both are issued :-)
# [Actually, if either of these options are used, I think both get built,
# but only one gets installed.  So if you use an in-place build, both can be
# used. --njn]

# Check if a 64-bit only build has been requested
AC_CACHE_CHECK([for a 64-bit only build], vg_cv_only64bit,
   [AC_ARG_ENABLE(only64bit, 
      [  --enable-only64bit      do a 64-bit only build],
      [vg_cv_only64bit=$enableval],
      [vg_cv_only64bit=no])])

# Check if a 32-bit only build has been requested
AC_CACHE_CHECK([for a 32-bit only build], vg_cv_only32bit,
   [AC_ARG_ENABLE(only32bit, 
      [  --enable-only32bit      do a 32-bit only build],
      [vg_cv_only32bit=$enableval],
      [vg_cv_only32bit=no])])

# Stay sane
if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
   AC_MSG_ERROR(
      [Nonsensical: both --enable-only64bit and --enable-only32bit.])
fi

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

# VGCONF_OS is the primary build OS, eg. "linux".  It is passed in to
# compilation of many C files via -VGO_$(VGCONF_OS) and
# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
AC_MSG_CHECKING([for a supported OS])
AC_SUBST(VGCONF_OS)

DEFAULT_SUPP=""

case "${host_os}" in
     *linux*)
	AC_MSG_RESULT([ok (${host_os})])
        VGCONF_OS="linux"

        # Ok, this is linux. Check the kernel version
        AC_MSG_CHECKING([for the kernel version])

        kernel=`uname -r`

        case "${kernel}" in
             0.*|1.*|2.0.*|2.1.*|2.2.*|2.3.*|2.4.*|2.5.*) 
        	    AC_MSG_RESULT([unsupported (${kernel})])
        	    AC_MSG_ERROR([Valgrind needs a Linux kernel >= 2.6])
        	    ;;

             *)
        	    AC_MSG_RESULT([2.6 or later (${kernel})])
                    ;;
        esac

        ;;

     *darwin*)
        AC_MSG_RESULT([ok (${host_os})])
        VGCONF_OS="darwin"
        AC_DEFINE([DARWIN_10_5], 100500, [DARWIN_VERS value for Mac OS X 10.5])
        AC_DEFINE([DARWIN_10_6], 100600, [DARWIN_VERS value for Mac OS X 10.6])
        AC_DEFINE([DARWIN_10_7], 100700, [DARWIN_VERS value for Mac OS X 10.7])
        AC_DEFINE([DARWIN_10_8], 100800, [DARWIN_VERS value for Mac OS X 10.8])
        AC_DEFINE([DARWIN_10_9], 100900, [DARWIN_VERS value for Mac OS X 10.9])
        AC_DEFINE([DARWIN_10_10], 101000, [DARWIN_VERS value for Mac OS X 10.10])
        AC_DEFINE([DARWIN_10_11], 101100, [DARWIN_VERS value for Mac OS X 10.11])
        AC_DEFINE([DARWIN_10_12], 101200, [DARWIN_VERS value for macOS 10.12])
        AC_DEFINE([DARWIN_10_13], 101300, [DARWIN_VERS value for macOS 10.13])

	AC_MSG_CHECKING([for the kernel version])
	kernel=`uname -r`

        # Nb: for Darwin we set DEFAULT_SUPP here.  That's because Darwin
        # has only one relevant version, the OS version. The `uname` check
        # is a good way to get that version (i.e. "Darwin 9.6.0" is Mac OS
        # X 10.5.6, and "Darwin 10.x" is Mac OS X 10.6.x Snow Leopard,
        # and possibly "Darwin 11.x" is Mac OS X 10.7.x Lion), 
        # and we don't know of an macros similar to __GLIBC__ to get that info.
        #
        # XXX: `uname -r` won't do the right thing for cross-compiles, but
        # that's not a problem yet.
        #
        # jseward 21 Sept 2011: I seriously doubt whether V 3.7.0 will work
        # on OS X 10.5.x; I haven't tested yet, and only plan to test 3.7.0
        # on 10.6.8 and 10.7.1.  Although tempted to delete the configure
        # time support for 10.5 (the 9.* pattern just below), I'll leave it
        # in for now, just in case anybody wants to give it a try.  But I'm
        # assuming that 3.7.0 is a Snow Leopard and Lion-only release.
	case "${kernel}" in
	     9.*)
		  AC_MSG_RESULT([Darwin 9.x (${kernel}) / Mac OS X 10.5 Leopard])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_5, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin9.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin9-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     10.*)
		  AC_MSG_RESULT([Darwin 10.x (${kernel}) / Mac OS X 10.6 Snow Leopard])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_6, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin10.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     11.*)
		  AC_MSG_RESULT([Darwin 11.x (${kernel}) / Mac OS X 10.7 Lion])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_7, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin11.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     12.*)
		  AC_MSG_RESULT([Darwin 12.x (${kernel}) / Mac OS X 10.8 Mountain Lion])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_8, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin12.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     13.*)
		  AC_MSG_RESULT([Darwin 13.x (${kernel}) / Mac OS X 10.9 Mavericks])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_9, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin13.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     14.*)
		  AC_MSG_RESULT([Darwin 14.x (${kernel}) / Mac OS X 10.10 Yosemite])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_10, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin14.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     15.*)
		  AC_MSG_RESULT([Darwin 15.x (${kernel}) / Mac OS X 10.11 El Capitan])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_11, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin15.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     16.*)
		  AC_MSG_RESULT([Darwin 16.x (${kernel}) / macOS 10.12 Sierra])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_12, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin16.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
	     17.*)
		  AC_MSG_RESULT([Darwin 17.x (${kernel}) / macOS 10.13 High Sierra])
		  AC_DEFINE([DARWIN_VERS], DARWIN_10_13, [Darwin / Mac OS X version])
		  DEFAULT_SUPP="darwin17.supp ${DEFAULT_SUPP}"
		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
		  ;;
             *) 
		  AC_MSG_RESULT([unsupported (${kernel})])
		  AC_MSG_ERROR([Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)])
		  ;;
	esac
        ;;

     solaris2.11*)
        AC_MSG_RESULT([ok (${host_os})])
        VGCONF_OS="solaris"

        uname_v=$( uname -v )
        case "$uname_v" in
             11.4.*)
                 DEFAULT_SUPP="solaris12.supp ${DEFAULT_SUPP}"
                 ;;
             *)
                 DEFAULT_SUPP="solaris11.supp ${DEFAULT_SUPP}"
                 ;;
	esac
        ;;

     solaris2.12*)
        AC_MSG_RESULT([ok (${host_os})])
        VGCONF_OS="solaris"
        DEFAULT_SUPP="solaris12.supp ${DEFAULT_SUPP}"
        ;;

     *) 
	AC_MSG_RESULT([no (${host_os})])
	AC_MSG_ERROR([Valgrind is operating system specific. Sorry.])
	;;
esac

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

# If we are building on a 64 bit platform test to see if the system
# supports building 32 bit programs and disable 32 bit support if it
# does not support building 32 bit programs

case "$ARCH_MAX-$VGCONF_OS" in
     amd64-linux|ppc64be-linux|arm64-linux|amd64-solaris)
        AC_MSG_CHECKING([for 32 bit build support])
        safe_CFLAGS=$CFLAGS
        CFLAGS="-m32"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
          return 0;
        ]])], [
        AC_MSG_RESULT([yes])
        ], [
        vg_cv_only64bit="yes"
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS;;
    mips64-linux)
        AC_MSG_CHECKING([for 32 bit build support])
        safe_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -mips32 -mabi=32"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
          #include <sys/prctl.h>
        ]], [[]])], [
        AC_MSG_RESULT([yes])
        ], [
        vg_cv_only64bit="yes"
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS;;
esac

if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
   AC_MSG_ERROR(
      [--enable-only32bit was specified but system does not support 32 bit builds])
fi

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

# VGCONF_ARCH_PRI is the arch for the primary build target, eg. "amd64".  By
# default it's the same as ARCH_MAX.  But if, say, we do a build on an amd64
# machine, but --enable-only32bit has been requested, then ARCH_MAX (see
# above) will be "amd64" since that reflects the most that this cpu can do,
# but VGCONF_ARCH_PRI will be downgraded to "x86", since that reflects the
# arch corresponding to the primary build (VGCONF_PLATFORM_PRI_CAPS).  It is
# passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_PRI) and
# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
AC_SUBST(VGCONF_ARCH_PRI)

# VGCONF_ARCH_SEC is the arch for the secondary build target, eg. "x86".
# It is passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_SEC)
# and -VGP_$(VGCONF_ARCH_SEC)_$(VGCONF_OS), if there is a secondary target.
# It is empty if there is no secondary target.
AC_SUBST(VGCONF_ARCH_SEC)

# VGCONF_PLATFORM_PRI_CAPS is the primary build target, eg. "AMD64_LINUX".
# The entire system, including regression and performance tests, will be
# built for this target.  The "_CAPS" indicates that the name is in capital
# letters, and it also uses '_' rather than '-' as a separator, because it's
# used to create various Makefile variables, which are all in caps by
# convention and cannot contain '-' characters.  This is in contrast to
# VGCONF_ARCH_PRI and VGCONF_OS which are not in caps.
AC_SUBST(VGCONF_PLATFORM_PRI_CAPS)

# VGCONF_PLATFORM_SEC_CAPS is the secondary build target, if there is one.
# Valgrind and tools will also be built for this target, but not the
# regression or performance tests.
#
# By default, the primary arch is the same as the "max" arch, as commented
# above (at the definition of ARCH_MAX).  We may choose to downgrade it in
# the big case statement just below here, in the case where we're building
# on a 64 bit machine but have been requested only to do a 32 bit build.
AC_SUBST(VGCONF_PLATFORM_SEC_CAPS)

AC_MSG_CHECKING([for a supported CPU/OS combination])

# NB.  The load address for a given platform may be specified in more 
# than one place, in some cases, depending on whether we're doing a biarch,
# 32-bit only or 64-bit only build.  eg see case for amd64-linux below.
# Be careful to give consistent values in all subcases.  Also, all four
# valt_load_addres_{pri,sec}_{norml,inner} values must always be set,
# even if it is to "0xUNSET".
#
case "$ARCH_MAX-$VGCONF_OS" in
     x86-linux)
        VGCONF_ARCH_PRI="x86"
        VGCONF_ARCH_SEC=""
	VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
	VGCONF_PLATFORM_SEC_CAPS=""
        valt_load_address_pri_norml="0x58000000"
        valt_load_address_pri_inner="0x38000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
	;;
     amd64-linux)
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
	if test x$vg_cv_only64bit = xyes; then
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
	elif test x$vg_cv_only32bit = xyes; then
	   VGCONF_ARCH_PRI="x86"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
	else
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC="x86"
	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS="X86_LINUX"
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
           valt_load_address_sec_norml="0x58000000"
           valt_load_address_sec_inner="0x38000000"
	fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
	;;
     ppc32-linux)
        VGCONF_ARCH_PRI="ppc32"
        VGCONF_ARCH_SEC=""
	VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
	VGCONF_PLATFORM_SEC_CAPS=""
        valt_load_address_pri_norml="0x58000000"
        valt_load_address_pri_inner="0x38000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
	;;
     ppc64be-linux)
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
	if test x$vg_cv_only64bit = xyes; then
	   VGCONF_ARCH_PRI="ppc64be"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
	elif test x$vg_cv_only32bit = xyes; then
	   VGCONF_ARCH_PRI="ppc32"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
	else
	   VGCONF_ARCH_PRI="ppc64be"
           VGCONF_ARCH_SEC="ppc32"
	   VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
	   VGCONF_PLATFORM_SEC_CAPS="PPC32_LINUX"
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
           valt_load_address_sec_norml="0x58000000"
           valt_load_address_sec_inner="0x38000000"
	fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
	;;
     ppc64le-linux)
        # Little Endian is only supported on PPC64
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        VGCONF_ARCH_PRI="ppc64le"
        VGCONF_ARCH_SEC=""
        VGCONF_PLATFORM_PRI_CAPS="PPC64LE_LINUX"
        VGCONF_PLATFORM_SEC_CAPS=""
        valt_load_address_pri_norml="0x58000000"
        valt_load_address_pri_inner="0x38000000"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
       ;;
     # Darwin gets identified as 32-bit even when it supports 64-bit.
     # (Not sure why, possibly because 'uname' returns "i386"?)  Just about
     # all Macs support both 32-bit and 64-bit, so we just build both.  If
     # someone has a really old 32-bit only machine they can (hopefully?)
     # build with --enable-only32bit.  See bug 243362.
     x86-darwin|amd64-darwin)
        ARCH_MAX="amd64"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
	if test x$vg_cv_only64bit = xyes; then
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
	   VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x158000000"
           valt_load_address_pri_inner="0x138000000"
	elif test x$vg_cv_only32bit = xyes; then
           VGCONF_ARCH_PRI="x86"
           VGCONF_ARCH_SEC=""
	   VGCONF_PLATFORM_PRI_CAPS="X86_DARWIN"
	   VGCONF_PLATFORM_SEC_CAPS=""
	   VGCONF_ARCH_PRI_CAPS="x86"
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
	else
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC="x86"
	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
	   VGCONF_PLATFORM_SEC_CAPS="X86_DARWIN"
           valt_load_address_pri_norml="0x158000000"
           valt_load_address_pri_inner="0x138000000"
           valt_load_address_sec_norml="0x58000000"
           valt_load_address_sec_inner="0x38000000"
	fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
	;;
     arm-linux) 
	VGCONF_ARCH_PRI="arm"
	VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
	VGCONF_PLATFORM_SEC_CAPS=""
	valt_load_address_pri_norml="0x58000000"
	valt_load_address_pri_inner="0x38000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
	AC_MSG_RESULT([ok (${host_cpu}-${host_os})])
	;;
     arm64-linux)
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        if test x$vg_cv_only64bit = xyes; then
           VGCONF_ARCH_PRI="arm64"
           VGCONF_ARCH_SEC=""
           VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
           VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
        elif test x$vg_cv_only32bit = xyes; then
           VGCONF_ARCH_PRI="arm"
           VGCONF_ARCH_SEC=""
           VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
           VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
        else
           VGCONF_ARCH_PRI="arm64"
           VGCONF_ARCH_SEC="arm"
           VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
           VGCONF_PLATFORM_SEC_CAPS="ARM_LINUX"
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
           valt_load_address_sec_norml="0x58000000"
           valt_load_address_sec_inner="0x38000000"
        fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
     s390x-linux)
        VGCONF_ARCH_PRI="s390x"
        VGCONF_ARCH_SEC=""
        VGCONF_PLATFORM_PRI_CAPS="S390X_LINUX"
        VGCONF_PLATFORM_SEC_CAPS=""
        # To improve branch prediction hit rate we want to have
        # the generated code close to valgrind (host) code
        valt_load_address_pri_norml="0x800000000"
        valt_load_address_pri_inner="0x810000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
     mips32-linux) 
        VGCONF_ARCH_PRI="mips32"
        VGCONF_ARCH_SEC=""
        VGCONF_PLATFORM_PRI_CAPS="MIPS32_LINUX"
        VGCONF_PLATFORM_SEC_CAPS=""
        valt_load_address_pri_norml="0x58000000"
        valt_load_address_pri_inner="0x38000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
     mips64-linux)
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        if test x$vg_cv_only64bit = xyes; then
            VGCONF_ARCH_PRI="mips64"
            VGCONF_PLATFORM_SEC_CAPS=""
            VGCONF_PLATFORM_PRI_CAPS="MIPS64_LINUX"
            VGCONF_PLATFORM_SEC_CAPS=""
            valt_load_address_pri_norml="0x58000000"
            valt_load_address_pri_inner="0x38000000"
        elif test x$vg_cv_only32bit = xyes; then
            VGCONF_ARCH_PRI="mips32"
            VGCONF_ARCH_SEC=""
            VGCONF_PLATFORM_PRI_CAPS="MIPS32_LINUX"
            VGCONF_PLATFORM_SEC_CAPS=""
            valt_load_address_pri_norml="0x58000000"
            valt_load_address_pri_inner="0x38000000"
        else
            VGCONF_ARCH_PRI="mips64"
            VGCONF_ARCH_SEC="mips32"
            VGCONF_PLATFORM_PRI_CAPS="MIPS64_LINUX"
            VGCONF_PLATFORM_SEC_CAPS="MIPS32_LINUX"
            valt_load_address_pri_norml="0x58000000"
            valt_load_address_pri_inner="0x38000000"
            valt_load_address_sec_norml="0x58000000"
            valt_load_address_sec_inner="0x38000000"
        fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
     x86-solaris)
        VGCONF_ARCH_PRI="x86"
        VGCONF_ARCH_SEC=""
        VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
        VGCONF_PLATFORM_SEC_CAPS=""
        valt_load_address_pri_norml="0x58000000"
        valt_load_address_pri_inner="0x38000000"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
     amd64-solaris)
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        if test x$vg_cv_only64bit = xyes; then
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC=""
           VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
           VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
        elif test x$vg_cv_only32bit = xyes; then
           VGCONF_ARCH_PRI="x86"
           VGCONF_ARCH_SEC=""
           VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
           VGCONF_PLATFORM_SEC_CAPS=""
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
        else
           VGCONF_ARCH_PRI="amd64"
           VGCONF_ARCH_SEC="x86"
           VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
           VGCONF_PLATFORM_SEC_CAPS="X86_SOLARIS"
           valt_load_address_pri_norml="0x58000000"
           valt_load_address_pri_inner="0x38000000"
           valt_load_address_sec_norml="0x58000000"
           valt_load_address_sec_inner="0x38000000"
        fi
        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
        ;;
    *)
        VGCONF_ARCH_PRI="unknown"
        VGCONF_ARCH_SEC="unknown"
	VGCONF_PLATFORM_PRI_CAPS="UNKNOWN"
	VGCONF_PLATFORM_SEC_CAPS="UNKNOWN"
        valt_load_address_pri_norml="0xUNSET"
        valt_load_address_pri_inner="0xUNSET"
        valt_load_address_sec_norml="0xUNSET"
        valt_load_address_sec_inner="0xUNSET"
        AC_MSG_RESULT([no (${ARCH_MAX}-${VGCONF_OS})])
        AC_MSG_ERROR([Valgrind is platform specific. Sorry. Please consider doing a port.])
        ;;
esac

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

# Set up VGCONF_ARCHS_INCLUDE_<arch>.  Either one or two of these become
# defined.
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_X86,   
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_AMD64, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC32, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \ 
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC64, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM,   
               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM64, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_S390X,
               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS32,
               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX )
AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS64,
               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ) 

# Set up VGCONF_PLATFORMS_INCLUDE_<platform>.  Either one or two of these
# become defined.
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_LINUX,   
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_LINUX, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC32_LINUX, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \ 
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64BE_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64LE_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM_LINUX, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM64_LINUX, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_S390X_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xS390X_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS32_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS64_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_DARWIN,   
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_DARWIN, 
               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_SOLARIS,
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS)
AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_SOLARIS,
               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)


# Similarly, set up VGCONF_OS_IS_<os>.  Exactly one of these becomes defined.
# Relies on the assumption that the primary and secondary targets are 
# for the same OS, so therefore only necessary to test the primary.
AM_CONDITIONAL(VGCONF_OS_IS_LINUX,
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX)
AM_CONDITIONAL(VGCONF_OS_IS_DARWIN,
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
AM_CONDITIONAL(VGCONF_OS_IS_SOLARIS,
               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)


# Sometimes, in the Makefile.am files, it's useful to know whether or not
# there is a secondary target.
AM_CONDITIONAL(VGCONF_HAVE_PLATFORM_SEC,
               test x$VGCONF_PLATFORM_SEC_CAPS != x)

dnl automake-1.10 does not have AM_COND_IF (added in 1.11), so we supply a
dnl fallback definition
dnl The macro is courtesy of Dave Hart:
dnl   https://lists.gnu.org/archive/html/automake/2010-12/msg00045.html
m4_ifndef([AM_COND_IF], [AC_DEFUN([AM_COND_IF], [
if test -z "$$1_TRUE"; then :
  m4_n([$2])[]dnl
m4_ifval([$3],
[else
  $3
])dnl
fi[]dnl
])])

#----------------------------------------------------------------------------
# Inner Valgrind?
#----------------------------------------------------------------------------

# Check if this should be built as an inner Valgrind, to be run within
# another Valgrind.  Choose the load address accordingly.
AC_SUBST(VALT_LOAD_ADDRESS_PRI)
AC_SUBST(VALT_LOAD_ADDRESS_SEC)
AC_CACHE_CHECK([for use as an inner Valgrind], vg_cv_inner,
   [AC_ARG_ENABLE(inner, 
      [  --enable-inner          enables self-hosting],
      [vg_cv_inner=$enableval],
      [vg_cv_inner=no])])
if test "$vg_cv_inner" = yes; then
    AC_DEFINE([ENABLE_INNER], 1, [configured to run as an inner Valgrind])
    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_inner
    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_inner
else
    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_norml
    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_norml
fi

#----------------------------------------------------------------------------
# Undefined behaviour sanitiser
#----------------------------------------------------------------------------
# Check whether we should build with the undefined beahviour sanitiser.

AC_CACHE_CHECK([for using the undefined behaviour sanitiser], vg_cv_ubsan,
   [AC_ARG_ENABLE(ubsan, 
      [  --enable-ubsan          enables the undefined behaviour sanitiser],
      [vg_cv_ubsan=$enableval],
      [vg_cv_ubsan=no])])

#----------------------------------------------------------------------------
# Extra fine-tuning of installation directories
#----------------------------------------------------------------------------
AC_ARG_WITH(tmpdir,
   [  --with-tmpdir=PATH      Specify path for temporary files],
   tmpdir="$withval",
   tmpdir="/tmp")
AC_DEFINE_UNQUOTED(VG_TMPDIR, "$tmpdir", [Temporary files directory])
AC_SUBST(VG_TMPDIR, [$tmpdir])


#----------------------------------------------------------------------------
# Libc and suppressions
#----------------------------------------------------------------------------
# This variable will collect the suppression files to be used.
AC_SUBST(DEFAULT_SUPP)

AC_CHECK_HEADER([features.h])

if test x$ac_cv_header_features_h = xyes; then
  rm -f conftest.$ac_ext
  cat <<_ACEOF >conftest.$ac_ext
#include <features.h>
#if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
glibc version is: __GLIBC__ __GLIBC_MINOR__
#endif
_ACEOF
  GLIBC_VERSION="`$CPP -P conftest.$ac_ext | $SED -n 's/^glibc version is: //p' | $SED 's/ /./g'`"
fi

# not really a version check
AC_EGREP_CPP([DARWIN_LIBC], [
#include <sys/cdefs.h>
#if defined(__DARWIN_VERS_1050)
  DARWIN_LIBC
#endif
],
GLIBC_VERSION="darwin")

# not really a version check
AC_EGREP_CPP([BIONIC_LIBC], [
#if defined(__ANDROID__)
  BIONIC_LIBC
#endif
],
GLIBC_VERSION="bionic")

# there is only one version of libc on Solaris
if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS; then
    GLIBC_VERSION="solaris"
fi

# GLIBC_VERSION is empty if a musl libc is used, so use the toolchain tuple
# in this case.
if test x$GLIBC_VERSION = x; then
    if $CC -dumpmachine | grep -q musl; then
        GLIBC_VERSION=musl
    fi
fi

AC_MSG_CHECKING([the glibc version])

case "${GLIBC_VERSION}" in
     2.2)
	AC_MSG_RESULT(${GLIBC_VERSION} family)
	DEFAULT_SUPP="glibc-2.2.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.2-LinuxThreads-helgrind.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
	;;
     2.[[3-6]])
	AC_MSG_RESULT(${GLIBC_VERSION} family)
	DEFAULT_SUPP="glibc-${GLIBC_VERSION}.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
	;;
     2.[[7-9]])
	AC_MSG_RESULT(${GLIBC_VERSION} family)
	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
	;;
     2.10|2.11)
	AC_MSG_RESULT(${GLIBC_VERSION} family)
	AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
		  [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
	;;
     2.*)
	AC_MSG_RESULT(${GLIBC_VERSION} family)
	AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
		  [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
	AC_DEFINE([GLIBC_MANDATORY_INDEX_AND_STRLEN_REDIRECT], 1,
		  [Define to 1 if index() and strlen() have been optimized heavily (x86 glibc >= 2.12)])
	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
	;;
     darwin)
	AC_MSG_RESULT(Darwin)
	AC_DEFINE([DARWIN_LIBC], 1, [Define to 1 if you're using Darwin])
	# DEFAULT_SUPP set by kernel version check above.
	;;
     bionic)
	AC_MSG_RESULT(Bionic)
	AC_DEFINE([BIONIC_LIBC], 1, [Define to 1 if you're using Bionic])
	DEFAULT_SUPP="bionic.supp ${DEFAULT_SUPP}"
	;;
     solaris)
	AC_MSG_RESULT(Solaris)
	# DEFAULT_SUPP set in host_os switch-case above.
	# No other suppression file is used.
	;;
     musl)
	AC_MSG_RESULT(Musl)
	AC_DEFINE([MUSL_LIBC], 1, [Define to 1 if you're using Musl libc])
	# no DEFAULT_SUPP file yet for musl libc.
	;;
     2.0|2.1|*)
	AC_MSG_RESULT([unsupported version ${GLIBC_VERSION}])
	AC_MSG_ERROR([Valgrind requires glibc version 2.2 or later, uClibc,])
	AC_MSG_ERROR([musl libc, Darwin libc, Bionic libc or Solaris libc])
	;;
esac

AC_SUBST(GLIBC_VERSION)


if test "$VGCONF_OS" != "solaris"; then
    # Add default suppressions for the X client libraries.  Make no
    # attempt to detect whether such libraries are installed on the
    # build machine (or even if any X facilities are present); just
    # add the suppressions antidisirregardless.
    DEFAULT_SUPP="xfree-4.supp ${DEFAULT_SUPP}"
    DEFAULT_SUPP="xfree-3.supp ${DEFAULT_SUPP}"

    # Add glibc and X11 suppressions for exp-sgcheck
    DEFAULT_SUPP="exp-sgcheck.supp ${DEFAULT_SUPP}"
fi


#----------------------------------------------------------------------------
# Platform variants?
#----------------------------------------------------------------------------

# Normally the PLAT = (ARCH, OS) characterisation of the platform is enough.
# But there are times where we need a bit more control.  The motivating
# and currently only case is Android: this is almost identical to
# {x86,arm,mips}-linux, but not quite.  So this introduces the concept of
# platform variant tags, which get passed in the compile as
# -DVGPV_<arch>_<os>_<variant> along with the main -DVGP_<arch>_<os> definition.
#
# In almost all cases, the <variant> bit is "vanilla".  But for Android
# it is "android" instead.
#
# Consequently (eg), plain arm-linux would build with
#
#   -DVGP_arm_linux -DVGPV_arm_linux_vanilla
#
# whilst an Android build would have
#
#   -DVGP_arm_linux -DVGPV_arm_linux_android
#
# Same for x86. The setup of the platform variant is pushed relatively far
# down this file in order that we can inspect any of the variables set above.

# In the normal case ..
VGCONF_PLATVARIANT="vanilla"

# Android ?
if test "$GLIBC_VERSION" = "bionic";
then
   VGCONF_PLATVARIANT="android"
fi

AC_SUBST(VGCONF_PLATVARIANT)


# FIXME: do we also want to define automake variables
# VGCONF_PLATVARIANT_IS_<WHATEVER>, where WHATEVER is (currently)
# VANILLA or ANDROID ?  This would be in the style of VGCONF_ARCHS_INCLUDE,
# VGCONF_PLATFORMS_INCLUDE and VGCONF_OS_IS above?  Could easily enough
# do that.  Problem is that we can't do and-ing in Makefile.am's, but
# that's what we'd need to do to use this, since what we'd want to write
# is something like
#
# VGCONF_PLATFORMS_INCLUDE_ARM_LINUX && VGCONF_PLATVARIANT_IS_ANDROID
#
# Hmm.  Can't think of a nice clean solution to this.

AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_VANILLA,
               test x$VGCONF_PLATVARIANT = xvanilla)
AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_ANDROID,
               test x$VGCONF_PLATVARIANT = xandroid)


#----------------------------------------------------------------------------
# Checking for various library functions and other definitions
#----------------------------------------------------------------------------

# Check for AT_FDCWD

AC_MSG_CHECKING([for AT_FDCWD])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
]], [[
  int a = AT_FDCWD;
]])], [
ac_have_at_fdcwd=yes
AC_MSG_RESULT([yes])
], [
ac_have_at_fdcwd=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL([HAVE_AT_FDCWD], [test x$ac_have_at_fdcwd = xyes])

# Check for stpncpy function definition in string.h
# This explicitly checks with _GNU_SOURCE defined since that is also
# used in the test case (some systems might define it without anyway
# since stpncpy is part of The Open Group Base Specifications Issue 7
# IEEE Std 1003.1-2008.
AC_MSG_CHECKING([for stpncpy])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <string.h>
]], [[
  char *d;
  char *s;
  size_t n = 0;
  char *r = stpncpy(d, s, n);
]])], [
ac_have_gnu_stpncpy=yes
AC_MSG_RESULT([yes])
], [
ac_have_gnu_stpncpy=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL([HAVE_GNU_STPNCPY], [test x$ac_have_gnu_stpncpy = xyes])

# Check for PTRACE_GETREGS

AC_MSG_CHECKING([for PTRACE_GETREGS])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#include <stddef.h>
#include <sys/ptrace.h>
#include <sys/user.h>
]], [[
  void *p;
  long res = ptrace (PTRACE_GETREGS, 0, p, p);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTRACE_GETREGS], 1,
          [Define to 1 if you have the `PTRACE_GETREGS' ptrace request.])
], [
AC_MSG_RESULT([no])
])


# Check for CLOCK_MONOTONIC

AC_MSG_CHECKING([for CLOCK_MONOTONIC])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <time.h>
]], [[
  struct timespec t;
  clock_gettime(CLOCK_MONOTONIC, &t);
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_CLOCK_MONOTONIC], 1,
          [Define to 1 if you have the `CLOCK_MONOTONIC' constant.])
], [
AC_MSG_RESULT([no])
])


# Check for ELF32/64_CHDR

AC_CHECK_TYPES([Elf32_Chdr, Elf64_Chdr], [], [], [[#include <elf.h>]])


# Check for PTHREAD_RWLOCK_T

AC_MSG_CHECKING([for pthread_rwlock_t])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <pthread.h>
]], [[
  pthread_rwlock_t rwl;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_RWLOCK_T], 1,
          [Define to 1 if you have the `pthread_rwlock_t' type.])
], [
AC_MSG_RESULT([no])
])


# Check for PTHREAD_MUTEX_ADAPTIVE_NP

AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <pthread.h>
]], [[
  return (PTHREAD_MUTEX_ADAPTIVE_NP);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
          [Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant.])
], [
AC_MSG_RESULT([no])
])


# Check for PTHREAD_MUTEX_ERRORCHECK_NP

AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <pthread.h>
]], [[
  return (PTHREAD_MUTEX_ERRORCHECK_NP);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], 1,
          [Define to 1 if you have the `PTHREAD_MUTEX_ERRORCHECK_NP' constant.])
], [
AC_MSG_RESULT([no])
])


# Check for PTHREAD_MUTEX_RECURSIVE_NP

AC_MSG_CHECKING([for PTHREAD_MUTEX_RECURSIVE_NP])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <pthread.h>
]], [[
  return (PTHREAD_MUTEX_RECURSIVE_NP);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1,
          [Define to 1 if you have the `PTHREAD_MUTEX_RECURSIVE_NP' constant.])
], [
AC_MSG_RESULT([no])
])


# Check for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP

AC_MSG_CHECKING([for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <pthread.h>
]], [[
  pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], 1,
          [Define to 1 if you have the `PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP' constant.])
], [
AC_MSG_RESULT([no])
])


# Check whether pthread_mutex_t has a member called __m_kind.

AC_CHECK_MEMBER([pthread_mutex_t.__m_kind],
	        [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__M_KIND],
		           1,                                   
			   [Define to 1 if pthread_mutex_t has a member called __m_kind.])
                ],
		[],
		[#include <pthread.h>])


# Check whether pthread_mutex_t has a member called __data.__kind.

AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind],
                [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__DATA__KIND],
		          1,
			  [Define to 1 if pthread_mutex_t has a member __data.__kind.])
                ],
		[],
		[#include <pthread.h>])

# Convenience function.  Set flags based on the existing HWCAP entries.
# The AT_HWCAP entries are generated by glibc, and are based on
# functions supported by the hardware/system/libc.
# Subsequent support for whether the capability will actually be utilized
# will also be checked against the compiler capabilities.
# called as
#      AC_HWCAP_CONTAINS_FLAG[hwcap_string_to_match],[VARIABLE_TO_SET]
AC_DEFUN([AC_HWCAP_CONTAINS_FLAG],[
  AUXV_CHECK_FOR=$1
  AC_MSG_CHECKING([if AT_HWCAP contains the $AUXV_CHECK_FOR indicator])
  if LD_SHOW_AUXV=1 `which true` | grep ^AT_HWCAP | grep -q -w ${AUXV_CHECK_FOR}
  then
    AC_MSG_RESULT([yes])
    AC_SUBST([$2],[yes])
  else
    AC_MSG_RESULT([no])
    AC_SUBST([$2],[])
  fi
])

# gather hardware capabilities. (hardware/kernel/libc)
AC_HWCAP_CONTAINS_FLAG([altivec],[HWCAP_HAS_ALTIVEC])
AC_HWCAP_CONTAINS_FLAG([vsx],[HWCAP_HAS_VSX])
AC_HWCAP_CONTAINS_FLAG([dfp],[HWCAP_HAS_DFP])
AC_HWCAP_CONTAINS_FLAG([arch_2_05],[HWCAP_HAS_ISA_2_05])
AC_HWCAP_CONTAINS_FLAG([arch_2_06],[HWCAP_HAS_ISA_2_06])
AC_HWCAP_CONTAINS_FLAG([arch_2_07],[HWCAP_HAS_ISA_2_07])
AC_HWCAP_CONTAINS_FLAG([arch_3_00],[HWCAP_HAS_ISA_3_00])
AC_HWCAP_CONTAINS_FLAG([htm],[HWCAP_HAS_HTM])

# ISA Levels
AM_CONDITIONAL(HAS_ISA_2_05, [test x$HWCAP_HAS_ISA_2_05 = xyes])
AM_CONDITIONAL(HAS_ISA_2_06, [test x$HWCAP_HAS_ISA_2_06 = xyes])
# compiler support for isa 2.07 level instructions
AC_MSG_CHECKING([that assembler knows ISA 2.07 instructions ])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __asm__ __volatile__("mtvsrd 1,2 ");
]])], [
ac_asm_have_isa_2_07=yes
AC_MSG_RESULT([yes])
], [
ac_asm_have_isa_2_07=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(HAS_ISA_2_07, [test x$ac_asm_have_isa_2_07 = xyes \
                               -a x$HWCAP_HAS_ISA_2_07 = xyes])

# altivec (vsx) support.
# does this compiler support -maltivec and does it have the include file
# <altivec.h> ?
AC_MSG_CHECKING([for Altivec support in the compiler ])
safe_CFLAGS=$CFLAGS
CFLAGS="-maltivec -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <altivec.h>
]], [[
  vector unsigned int v;
]])], [
ac_have_altivec=yes
AC_MSG_RESULT([yes])
], [
ac_have_altivec=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
AM_CONDITIONAL([HAS_ALTIVEC], [test x$ac_have_altivec = xyes \
                                 -a x$HWCAP_HAS_ALTIVEC = xyes])

# Check that both: the compiler supports -mvsx and that the assembler
# understands VSX instructions.  If either of those doesn't work,
# conclude that we can't do VSX.
AC_MSG_CHECKING([for VSX compiler flag support])
safe_CFLAGS=$CFLAGS
CFLAGS="-mvsx -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
]])], [
ac_compiler_supports_vsx_flag=yes
AC_MSG_RESULT([yes])
], [
ac_compiler_supports_vsx_flag=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_MSG_CHECKING([for VSX support in the assembler ])
safe_CFLAGS=$CFLAGS
CFLAGS="-mvsx -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <altivec.h>
]], [[
  vector unsigned int v;
  __asm__ __volatile__("xsmaddadp 32, 32, 33" ::: "memory","cc");
]])], [
ac_compiler_supports_vsx=yes
AC_MSG_RESULT([yes])
], [
ac_compiler_supports_vsx=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
AM_CONDITIONAL([HAS_VSX], [test x$ac_compiler_supports_vsx_flag = xyes \
                             -a x$ac_compiler_supports_vsx = xyes \
                             -a x$HWCAP_HAS_VSX = xyes ])

# DFP (Decimal Float)
AC_MSG_CHECKING([that assembler knows DFP])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  #ifdef __s390__
  __asm__ __volatile__("adtr 1, 2, 3")
  #else
  __asm__ __volatile__("dadd 1, 2, 3");
  __asm__ __volatile__("dcffix 1, 2");
  #endif
]])], [
ac_asm_have_dfp=yes
AC_MSG_RESULT([yes])
], [
ac_asm_have_dfp=no
AC_MSG_RESULT([no])
])
AC_MSG_CHECKING([that compiler knows -mhard-dfp switch])
safe_CFLAGS=$CFLAGS
CFLAGS="-mhard-dfp -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  #ifdef __s390__
  __asm__ __volatile__("adtr 1, 2, 3")
  #else
  __asm__ __volatile__("dadd 1, 2, 3");
  __asm__ __volatile__("dcffix 1, 2");
  #endif
]])], [
ac_compiler_have_dfp=yes
AC_MSG_RESULT([yes])
], [
ac_compiler_have_dfp=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
AM_CONDITIONAL(HAS_DFP, test x$ac_asm_have_dfp = xyes \
                          -a x$ac_compiler_have_dfp = xyes \
                          -a x$HWCAP_HAS_DFP = xyes )

AC_MSG_CHECKING([that compiler knows DFP datatypes])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  _Decimal64 x = 0.0DD;
]])], [
ac_compiler_have_dfp_type=yes
AC_MSG_RESULT([yes])
], [
ac_compiler_have_dfp_type=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(BUILD_DFP_TESTS, test x$ac_compiler_have_dfp_type = xyes \
                                  -a x$HWCAP_HAS_DFP = xyes )


# HTM (Hardware Transactional Memory)
AC_MSG_CHECKING([if compiler accepts the -mhtm flag])
safe_CFLAGS=$CFLAGS
CFLAGS="-mhtm -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  return 0;
]])], [
AC_MSG_RESULT([yes])
ac_compiler_supports_htm=yes
], [
AC_MSG_RESULT([no])
ac_compiler_supports_htm=no
])
CFLAGS=$safe_CFLAGS

AC_MSG_CHECKING([if compiler can find the htm builtins])
safe_CFLAGS=$CFLAGS
CFLAGS="-mhtm -Werror"
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 ]], [[
   if (__builtin_tbegin (0))
      __builtin_tend (0);
 ]])], [
 AC_MSG_RESULT([yes])
ac_compiler_sees_htm_builtins=yes
 ], [
 AC_MSG_RESULT([no])
ac_compiler_sees_htm_builtins=no
 ])
CFLAGS=$safe_CFLAGS

AM_CONDITIONAL(SUPPORTS_HTM, test x$ac_compiler_supports_htm = xyes \
                               -a x$ac_compiler_sees_htm_builtins = xyes \
                               -a x$HWCAP_HAS_HTM = xyes )

# isa 3.0 checking
AC_MSG_CHECKING([that assembler knows ISA 3.00 ])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __asm__ __volatile__("cnttzw 1,2 ");
]])], [
ac_asm_have_isa_3_00=yes
AC_MSG_RESULT([yes])
], [
ac_asm_have_isa_3_00=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(HAS_ISA_3_00, [test x$ac_asm_have_isa_3_00 = xyes \
                             -a x$HWCAP_HAS_ISA_3_00 = xyes])

# Check for pthread_create@GLIBC2.0
AC_MSG_CHECKING([for pthread_create@GLIBC2.0()])

safe_CFLAGS=$CFLAGS
CFLAGS="-lpthread -Werror"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
extern int pthread_create_glibc_2_0(void*, const void*,
                                    void *(*)(void*), void*);
__asm__(".symver pthread_create_glibc_2_0, pthread_create@GLIBC_2.0");
]], [[
#ifdef __powerpc__
/*
 * Apparently on PowerPC linking this program succeeds and generates an
 * executable with the undefined symbol pthread_create@GLIBC_2.0.
 */
#error This test does not work properly on PowerPC.
#else
  pthread_create_glibc_2_0(0, 0, 0, 0);
#endif
  return 0;
]])], [
ac_have_pthread_create_glibc_2_0=yes
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PTHREAD_CREATE_GLIBC_2_0], 1,
          [Define to 1 if you have the `pthread_create@glibc2.0' function.])
], [
ac_have_pthread_create_glibc_2_0=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AM_CONDITIONAL(HAVE_PTHREAD_CREATE_GLIBC_2_0,
	       test x$ac_have_pthread_create_glibc_2_0 = xyes)


# Check for dlinfo RTLD_DI_TLS_MODID
AC_MSG_CHECKING([for dlinfo RTLD_DI_TLS_MODID])

safe_LIBS="$LIBS"
LIBS="-ldl"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <link.h>
#include <dlfcn.h>
]], [[
  size_t sizes[10000];
  size_t modid_offset;
  (void) dlinfo ((void*)sizes, RTLD_DI_TLS_MODID, &modid_offset);
  return 0;
]])], [
ac_have_dlinfo_rtld_di_tls_modid=yes
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_DLINFO_RTLD_DI_TLS_MODID], 1,
          [Define to 1 if you have a dlinfo that can do RTLD_DI_TLS_MODID.])
], [
ac_have_dlinfo_rtld_di_tls_modid=no
AC_MSG_RESULT([no])
])
LIBS=$safe_LIBS

AM_CONDITIONAL(HAVE_DLINFO_RTLD_DI_TLS_MODID,
	       test x$ac_have_dlinfo_rtld_di_tls_modid = xyes)


# Check for eventfd_t, eventfd() and eventfd_read()
AC_MSG_CHECKING([for eventfd()])

AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/eventfd.h>
]], [[
  eventfd_t ev;
  int fd;

  fd = eventfd(5, 0);
  eventfd_read(fd, &ev);
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_EVENTFD], 1,
          [Define to 1 if you have the `eventfd' function.])
AC_DEFINE([HAVE_EVENTFD_READ], 1,
          [Define to 1 if you have the `eventfd_read' function.])
], [
AC_MSG_RESULT([no])
])

# Check whether compiler can process #include <thread> without errors
# clang 3.3 cannot process <thread> from e.g.
# gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

AC_MSG_CHECKING([that C++ compiler can include <thread> header file])
AC_LANG(C++)
safe_CXXFLAGS=$CXXFLAGS
CXXFLAGS=-std=c++0x

AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <thread> 
])],
[
ac_cxx_can_include_thread_header=yes
AC_MSG_RESULT([yes])
], [
ac_cxx_can_include_thread_header=no
AC_MSG_RESULT([no])
])
CXXFLAGS=$safe_CXXFLAGS
AC_LANG(C)

AM_CONDITIONAL(CXX_CAN_INCLUDE_THREAD_HEADER, test x$ac_cxx_can_include_thread_header = xyes)


# On aarch64 before glibc 2.20 we would get the kernel user_pt_regs instead
# of the user_regs_struct from sys/user.h. They are structurally the same
# but we get either one or the other.

AC_CHECK_TYPE([struct user_regs_struct],
              [sys_user_has_user_regs=yes], [sys_user_has_user_regs=no],
              [[#include <sys/ptrace.h>]
               [#include <sys/time.h>]
               [#include <sys/user.h>]])
if test "$sys_user_has_user_regs" = "yes"; then
  AC_DEFINE(HAVE_SYS_USER_REGS, 1,
            [Define to 1 if <sys/user.h> defines struct user_regs_struct])
fi

AC_MSG_CHECKING([for __NR_membarrier])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <linux/unistd.h>
]], [[
return __NR_membarrier
]])], [
ac_have_nr_membarrier=yes
AC_MSG_RESULT([yes])
], [
ac_have_nr_membarrier=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(HAVE_NR_MEMBARRIER, [test x$ac_have_nr_membarrier = xyes])

#----------------------------------------------------------------------------
# Checking for supported compiler flags.
#----------------------------------------------------------------------------

case "${host_cpu}" in
    mips*)
        # does this compiler support -march=mips32 (mips32 default) ?
        AC_MSG_CHECKING([if gcc accepts -march=mips32 -mabi=32])

        safe_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -mips32 -mabi=32 -Werror"

        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
          return 0;
        ]])], [
        FLAG_M32="-mips32 -mabi=32"
        AC_MSG_RESULT([yes])
        ], [
        FLAG_M32=""
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS

        AC_SUBST(FLAG_M32)


        # does this compiler support -march=mips64r2 (mips64r2 default) ?
        AC_MSG_CHECKING([if gcc accepts -march=mips64r2 -mabi=64])

        safe_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -march=mips64r2 -mabi=64 -Werror"

        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
          return 0;
        ]])], [
        FLAG_M64="-march=mips64r2 -mabi=64"
        AC_MSG_RESULT([yes])
        ], [
        FLAG_M64=""
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS

        AC_SUBST(FLAG_M64)
        ;;
    *)
        # does this compiler support -m32 ?
        AC_MSG_CHECKING([if gcc accepts -m32])

        safe_CFLAGS=$CFLAGS
        CFLAGS="-m32 -Werror"

        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
          return 0;
        ]])], [
        FLAG_M32="-m32"
        AC_MSG_RESULT([yes])
        ], [
        FLAG_M32=""
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS

        AC_SUBST(FLAG_M32)


        # does this compiler support -m64 ?
        AC_MSG_CHECKING([if gcc accepts -m64])

        safe_CFLAGS=$CFLAGS
        CFLAGS="-m64 -Werror"

        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
          return 0;
        ]])], [
        FLAG_M64="-m64"
        AC_MSG_RESULT([yes])
        ], [
        FLAG_M64=""
        AC_MSG_RESULT([no])
        ])
        CFLAGS=$safe_CFLAGS

        AC_SUBST(FLAG_M64)
        ;;
esac

# does this compiler support -march=octeon (Cavium OCTEON I Specific) ?
AC_MSG_CHECKING([if gcc accepts -march=octeon])

safe_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $FLAG_M64 -march=octeon -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_OCTEON="-march=octeon"
AC_MSG_RESULT([yes])
], [
FLAG_OCTEON=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_OCTEON)


# does this compiler support -march=octeon2 (Cavium OCTEON II Specific) ?
AC_MSG_CHECKING([if gcc accepts -march=octeon2])

safe_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $FLAG_M64 -march=octeon2 -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_OCTEON2="-march=octeon2"
AC_MSG_RESULT([yes])
], [
FLAG_OCTEON2=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_OCTEON2)


# does this compiler support -mmsa (MIPS MSA ASE) ?
AC_MSG_CHECKING([if gcc accepts -mmsa])

safe_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -mmsa -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
    return 0;
]])], [
FLAG_MSA="-mmsa"
AC_MSG_RESULT([yes])
], [
FLAG_MSA=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_MSA)

# Are we compiling for the MIPS64 n32 ABI?
AC_MSG_CHECKING([if gcc is producing mips n32 binaries])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#if !defined(_MIPS_SIM) || (defined(_MIPS_SIM) && (_MIPS_SIM != _ABIN32))
#error NO
#endif
]])], [
VGCONF_ABI=N32
FLAG_M64="-march=mips64r2 -mabi=n32"
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])

# Are we compiling for the MIPS64 n64 ABI?
AC_MSG_CHECKING([if gcc is producing mips n64 binaries])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#if !defined(_MIPS_SIM) || (defined(_MIPS_SIM) && (_MIPS_SIM != _ABI64))
#error NO
#endif
]])], [
VGCONF_ABI=64
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])

AM_CONDITIONAL([VGCONF_HAVE_ABI],
               [test x$VGCONF_ABI != x])
AC_SUBST(VGCONF_ABI)


# does this compiler support -mmmx ?
AC_MSG_CHECKING([if gcc accepts -mmmx])

safe_CFLAGS=$CFLAGS
CFLAGS="-mmmx -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_MMMX="-mmmx"
AC_MSG_RESULT([yes])
], [
FLAG_MMMX=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_MMMX)


# does this compiler support -msse ?
AC_MSG_CHECKING([if gcc accepts -msse])

safe_CFLAGS=$CFLAGS
CFLAGS="-msse -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_MSSE="-msse"
AC_MSG_RESULT([yes])
], [
FLAG_MSSE=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_MSSE)


# does this compiler support -mpreferred-stack-boundary=2 when
# generating code for a 32-bit target?  Note that we only care about
# this when generating code for (32-bit) x86, so if the compiler
# doesn't recognise -m32 it's no big deal.  We'll just get code for
# the Memcheck and other helper functions, that is a bit slower than
# it could be, on x86; and no difference at all on any other platform.
AC_MSG_CHECKING([if gcc accepts -mpreferred-stack-boundary=2 -m32])

safe_CFLAGS=$CFLAGS
CFLAGS="-mpreferred-stack-boundary=2 -m32 -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
PREFERRED_STACK_BOUNDARY_2="-mpreferred-stack-boundary=2"
AC_MSG_RESULT([yes])
], [
PREFERRED_STACK_BOUNDARY_2=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(PREFERRED_STACK_BOUNDARY_2)


# does this compiler support -mlong-double-128 ?
AC_MSG_CHECKING([if gcc accepts -mlong-double-128])
safe_CFLAGS=$CFLAGS
CFLAGS="-mlong-double-128 -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
ac_compiler_supports_mlong_double_128=yes
AC_MSG_RESULT([yes])
], [
ac_compiler_supports_mlong_double_128=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
AM_CONDITIONAL(HAS_MLONG_DOUBLE_128, test x$ac_compiler_supports_mlong_double_128 = xyes)
FLAG_MLONG_DOUBLE_128="-mlong-double-128"
AC_SUBST(FLAG_MLONG_DOUBLE_128)

# does this toolchain support lto ?
# Not checked for if --enable-lto=no was given, or if LTO_AR or LTO_RANLIG
# are not defined
# If not enable-lto=* arg is provided, default to no, as  lto builds are
# a lot slower, and so not appropriate for Valgrind developments.
# --enable-lto=yes should be used by distro packagers.
AC_CACHE_CHECK([for using the link time optimisation], vg_cv_lto,
   [AC_ARG_ENABLE(lto,
      [  --enable-lto          enables building with link time optimisation],
      [vg_cv_lto=$enableval],
      [vg_cv_lto=no])])

if test "x${vg_cv_lto}" != "xno" -a "x${LTO_AR}" != "x" -a "x${LTO_RANLIB}" != "x"; then
AC_MSG_CHECKING([if toolchain accepts lto])
safe_CFLAGS=$CFLAGS
TEST_LTO_CFLAGS="-flto -flto-partition=one -fuse-linker-plugin"
# Note : using 'one' partition is giving a slightly smaller/faster memcheck
# and ld/lto-trans1 still needs a reasonable memory (about 0.5GB) when linking.
CFLAGS="$TEST_LTO_CFLAGS -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  extern void somefun(void);
  somefun();
  return 0;
]])], [
LTO_CFLAGS=$TEST_LTO_CFLAGS
AC_MSG_RESULT([yes])
], [
LTO_CFLAGS=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
fi

AC_SUBST(LTO_CFLAGS)

# if we could not compile with lto args, or lto was disabled,
# then set LTO_AR/LTO_RANLIB to the non lto values
# define in config.h ENABLE_LTO (not needed by the code currently, but
# this guarantees we recompile everything if we re-configure and rebuild
# in a build dir previously build with another value of --enable-lto
if test "x${LTO_CFLAGS}" = "x"; then
   LTO_AR=${AR}
   LTO_RANLIB=${RANLIB}
   vg_cv_lto=no
else
   vg_cv_lto=yes
   AC_DEFINE([ENABLE_LTO], 1, [configured to build with lto link time optimisation])
fi

# Convenience function to check whether GCC supports a particular
# warning option. Takes two arguments,
# first the warning flag name to check (without -W), then the
# substitution name to set with -Wno-warning-flag if the flag exists,
# or the empty string if the compiler doesn't accept the flag. Note
# that checking is done against the warning flag itself, but the
# substitution is then done to cancel the warning flag.
AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
  AC_MSG_CHECKING([if gcc accepts -W$1])
  safe_CFLAGS=$CFLAGS
  CFLAGS="-W$1 -Werror"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
  AC_SUBST([$2], [-Wno-$1])
  AC_MSG_RESULT([yes])], [
  AC_SUBST([$2], [])
  AC_MSG_RESULT([no])])
  CFLAGS=$safe_CFLAGS
])

# Convenience function. Like AC_GCC_WARNING_SUBST_NO, except it substitutes
# -W$1  (instead of -Wno-$1).
AC_DEFUN([AC_GCC_WARNING_SUBST],[
  AC_MSG_CHECKING([if gcc accepts -W$1])
  safe_CFLAGS=$CFLAGS
  CFLAGS="-W$1 -Werror"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
  AC_SUBST([$2], [-W$1])
  AC_MSG_RESULT([yes])], [
  AC_SUBST([$2], [])
  AC_MSG_RESULT([no])])
  CFLAGS=$safe_CFLAGS
])

AC_GCC_WARNING_SUBST_NO([memset-transposed-args], [FLAG_W_NO_MEMSET_TRANSPOSED_ARGS])
AC_GCC_WARNING_SUBST_NO([nonnull], [FLAG_W_NO_NONNULL])
AC_GCC_WARNING_SUBST_NO([overflow], [FLAG_W_NO_OVERFLOW])
AC_GCC_WARNING_SUBST_NO([pointer-sign], [FLAG_W_NO_POINTER_SIGN])
AC_GCC_WARNING_SUBST_NO([uninitialized], [FLAG_W_NO_UNINITIALIZED])
AC_GCC_WARNING_SUBST_NO([unused-function], [FLAG_W_NO_UNUSED_FUNCTION])
AC_GCC_WARNING_SUBST_NO([static-local-in-inline], [FLAG_W_NO_STATIC_LOCAL_IN_INLINE])
AC_GCC_WARNING_SUBST_NO([mismatched-new-delete], [FLAG_W_NO_MISMATCHED_NEW_DELETE])
AC_GCC_WARNING_SUBST_NO([infinite-recursion], [FLAG_W_NO_INFINITE_RECURSION])
AC_GCC_WARNING_SUBST([write-strings], [FLAG_W_WRITE_STRINGS])
AC_GCC_WARNING_SUBST([empty-body], [FLAG_W_EMPTY_BODY])
AC_GCC_WARNING_SUBST([format], [FLAG_W_FORMAT])
# Disabled for now until all platforms are clean
format_checking_enabled=no
#format_checking_enabled=yes
if test "$format_checking_enabled" = "yes"; then
   AC_GCC_WARNING_SUBST([format-signedness], [FLAG_W_FORMAT_SIGNEDNESS])
else
   dumy_assignment_to_avoid_syntax_errors=1
   AC_SUBST([FLAG_W_FORMAT_SIGNEDNESS], [])
fi
AC_GCC_WARNING_SUBST([cast-qual], [FLAG_W_CAST_QUAL])
AC_GCC_WARNING_SUBST([old-style-declaration], [FLAG_W_OLD_STYLE_DECLARATION])
AC_GCC_WARNING_SUBST([ignored-qualifiers], [FLAG_W_IGNORED_QUALIFIERS])
AC_GCC_WARNING_SUBST([missing-parameter-type], [FLAG_W_MISSING_PARAMETER_TYPE])
AC_GCC_WARNING_SUBST([logical-op], [FLAG_W_LOGICAL_OP])

# Does this compiler support -Wformat-security ?
# Special handling is needed, because certain GCC versions require -Wformat
# being present if -Wformat-security is given. Otherwise a warning is issued.
# However, AC_GCC_WARNING_SUBST will stick in -Werror (see r15323 for rationale).
# And with that the warning will be turned into an error with the result
# that -Wformat-security is believed to be unsupported when in fact it is.
AC_MSG_CHECKING([if gcc accepts -Wformat-security])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wformat -Wformat-security -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
AC_SUBST([FLAG_W_FORMAT_SECURITY], [-Wformat-security])
AC_MSG_RESULT([yes])], [
AC_SUBST([FLAG_W_FORMAT_SECURITY], [])
AC_MSG_RESULT([no])])
CFLAGS=$safe_CFLAGS

# does this compiler support -Wextra or the older -W ?

AC_MSG_CHECKING([if gcc accepts -Wextra or -W])

safe_CFLAGS=$CFLAGS
CFLAGS="-Wextra -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
AC_SUBST([FLAG_W_EXTRA], [-Wextra])
AC_MSG_RESULT([-Wextra])
], [
  CFLAGS="-W -Werror"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
    return 0;
  ]])], [
  AC_SUBST([FLAG_W_EXTRA], [-W])
  AC_MSG_RESULT([-W])
  ], [
  AC_SUBST([FLAG_W_EXTRA], [])
  AC_MSG_RESULT([not supported])
  ])
])
CFLAGS=$safe_CFLAGS

# On ARM we do not want to pass -Wcast-align as that produces loads
# of warnings. GCC is just being conservative. See here:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65459#c4
if test "X$VGCONF_ARCH_PRI" = "Xarm"; then
  AC_SUBST([FLAG_W_CAST_ALIGN], [""])
else
  AC_SUBST([FLAG_W_CAST_ALIGN], [-Wcast-align])
fi

# does this compiler support -faligned-new ?
AC_MSG_CHECKING([if g++ accepts -faligned-new])

safe_CXXFLAGS=$CXXFLAGS
CXXFLAGS="-faligned-new -Werror"

AC_LANG(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_FALIGNED_NEW="-faligned-new"
AC_MSG_RESULT([yes])
], [
FLAG_FALIGNED_NEW=""
AC_MSG_RESULT([no])
])
CXXFLAGS=$safe_CXXFLAGS
AC_LANG(C)

AC_SUBST(FLAG_FALIGNED_NEW)

# does this compiler support -fno-stack-protector ?
AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])

safe_CFLAGS=$CFLAGS
CFLAGS="-fno-stack-protector -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
no_stack_protector=yes
FLAG_FNO_STACK_PROTECTOR="-fno-stack-protector"
AC_MSG_RESULT([yes])
], [
no_stack_protector=no
FLAG_FNO_STACK_PROTECTOR=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_FNO_STACK_PROTECTOR)

# Does GCC support disabling Identical Code Folding?
# We want to disabled Identical Code Folding for the
# tools preload shared objects to get better backraces.
# For GCC 5.1+ -fipa-icf is enabled by default at -O2.
# "The optimization reduces code size and may disturb
#  unwind stacks by replacing a function by equivalent
#  one with a different name."
AC_MSG_CHECKING([if gcc accepts -fno-ipa-icf])

safe_CFLAGS=$CFLAGS
CFLAGS="-fno-ipa-icf -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
no_ipa_icf=yes
FLAG_FNO_IPA_ICF="-fno-ipa-icf"
AC_MSG_RESULT([yes])
], [
no_ipa_icf=no
FLAG_FNO_IPA_ICF=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AC_SUBST(FLAG_FNO_IPA_ICF)


# Does this compiler support -fsanitize=undefined. This is true for
# GCC 4.9 and newer. However, the undefined behaviour sanitiser in GCC 5.1
# also checks for alignment violations on memory accesses which the valgrind
# code base is sprinkled (if not littered) with. As those alignment issues
# don't pose a problem we want to suppress warnings about them.
# In GCC 5.1 this can be done by passing -fno-sanitize=alignment. Earlier
# GCCs do not support that.
#
# Only checked for if --enable-ubsan was given.
if test "x${vg_cv_ubsan}" = "xyes"; then
AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined -fno-sanitize=alignment])
safe_CFLAGS=$CFLAGS
CFLAGS="-fsanitize=undefined -fno-sanitize=alignment -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_FSANITIZE="-fsanitize=undefined -fno-sanitize=alignment"
LIB_UBSAN="-static-libubsan"
AC_MSG_RESULT([yes])
], [
CFLAGS="-fsanitize=undefined -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return 0;
]])], [
FLAG_FSANITIZE="-fsanitize=undefined"
LIB_UBSAN="-static-libubsan"
AC_MSG_RESULT([yes])
], [
FLAG_FSANITIZE=""
LIB_UBSAN=""
AC_MSG_RESULT([no])
])
])
CFLAGS=$safe_CFLAGS
AC_SUBST(FLAG_FSANITIZE)
AC_SUBST(LIB_UBSAN)
fi
# does this compiler support --param inline-unit-growth=... ?

AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])

safe_CFLAGS=$CFLAGS
CFLAGS="--param inline-unit-growth=900 -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH],
         ["--param inline-unit-growth=900"])
AC_MSG_RESULT([yes])
], [
AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH], [""])
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS


# does this compiler support -gdwarf-4 -fdebug-types-section ?

AC_MSG_CHECKING([if gcc accepts -gdwarf-4 -fdebug-types-section])

safe_CFLAGS=$CFLAGS
CFLAGS="-gdwarf-4 -fdebug-types-section -Werror"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
ac_have_dwarf4=yes
AC_MSG_RESULT([yes])
], [
ac_have_dwarf4=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(DWARF4, test x$ac_have_dwarf4 = xyes)
CFLAGS=$safe_CFLAGS


# does this compiler support -g -gz=zlib ?

AC_MSG_CHECKING([if gcc accepts -g -gz=zlib])

safe_CFLAGS=$CFLAGS
CFLAGS="-g -gz=zlib"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
ac_have_gz_zlib=yes
AC_MSG_RESULT([yes])
], [
ac_have_gz_zlib=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(GZ_ZLIB, test x$ac_have_gz_zlib = xyes)
CFLAGS=$safe_CFLAGS


# does this compiler support -g -gz=zlib-gnu ?

AC_MSG_CHECKING([if gcc accepts -g -gz=zlib-gnu])

safe_CFLAGS=$CFLAGS
CFLAGS="-g -gz=zlib-gnu"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
ac_have_gz_zlib_gnu=yes
AC_MSG_RESULT([yes])
], [
ac_have_gz_zlib_gnu=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(GZ_ZLIB_GNU, test x$ac_have_gz_zlib_gnu = xyes)
CFLAGS=$safe_CFLAGS


# does this compiler support nested functions ?

AC_MSG_CHECKING([if gcc accepts nested functions])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  int foo() { return 1; }
  return foo();
]])], [
ac_have_nested_functions=yes
AC_MSG_RESULT([yes])
], [
ac_have_nested_functions=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL([HAVE_NESTED_FUNCTIONS], [test x$ac_have_nested_functions = xyes])


# does this compiler support the 'p' constraint in ASM statements ?

AC_MSG_CHECKING([if gcc accepts the 'p' constraint in asm statements])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
   char *p;
   __asm__ __volatile__ ("movdqa (%0),%%xmm6\n" : "=p" (p));
]])], [
ac_have_asm_constraint_p=yes
AC_MSG_RESULT([yes])
], [
ac_have_asm_constraint_p=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL([HAVE_ASM_CONSTRAINT_P], [test x$ac_have_asm_constraint_p = xyes])


# Does this compiler and linker support -pie?
# Some compilers actually do not support -pie and report its usage
# as an error. We need to check if it is safe to use it first.

AC_MSG_CHECKING([if gcc accepts -pie])

safe_CFLAGS=$CFLAGS
CFLAGS="-pie"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
AC_SUBST([FLAG_PIE], ["-pie"])
AC_MSG_RESULT([yes])
], [
AC_SUBST([FLAG_PIE], [""])
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS


# Does this compiler support -no-pie?
# On Ubuntu 16.10+, gcc produces position independent executables (PIE) by
# default. However this gets in the way with some tests, we use -no-pie
# for these.

AC_MSG_CHECKING([if gcc accepts -no-pie])

safe_CFLAGS=$CFLAGS
CFLAGS="-no-pie"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
  return 0;
]])], [
AC_SUBST([FLAG_NO_PIE], ["-no-pie"])
AC_MSG_RESULT([yes])
], [
AC_SUBST([FLAG_NO_PIE], [""])
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS


# We want to use use the -Ttext-segment option to the linker.
# GNU (bfd) ld supports this directly. Newer GNU gold linkers
# support it as an alias of -Ttext. Sadly GNU (bfd) ld's -Ttext
# semantics are NOT what we want (GNU gold -Ttext is fine).
#
# For GNU (bfd) ld -Ttext-segment chooses the base at which ELF headers
# will reside. -Ttext aligns just the .text section start (but not any
# other section).
#
# So test for -Ttext-segment which is supported by all bfd ld versions
# and use that if it exists. If it doesn't exist it must be an older
# version of gold and we can fall back to using -Ttext which has the
# right semantics.

AC_MSG_CHECKING([if the linker accepts -Wl,-Ttext-segment])

safe_CFLAGS=$CFLAGS
CFLAGS="-static -nodefaultlibs -nostartfiles -Wl,-Ttext-segment=$valt_load_address_pri_norml -Werror"

AC_LINK_IFELSE(
[AC_LANG_SOURCE([int _start () { return 0; }])],
[
  linker_using_t_text="no"
  AC_SUBST([FLAG_T_TEXT], ["-Ttext-segment"])
  AC_MSG_RESULT([yes])
], [
  linker_using_t_text="yes"
  AC_SUBST([FLAG_T_TEXT], ["-Ttext"])
  AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

# If the linker only supports -Ttext (not -Ttext-segment) then we will
# have to strip any build-id ELF NOTEs from the statically linked tools.
# Otherwise the build-id NOTE might end up at the default load address.
# (Pedantically if the linker is gold then -Ttext is fine, but newer
# gold versions also support -Ttext-segment. So just assume that unless
# we can use -Ttext-segment we need to strip the build-id NOTEs.
if test "x${linker_using_t_text}" = "xyes"; then
AC_MSG_NOTICE([ld -Ttext used, need to strip build-id NOTEs.])
# does the linker support -Wl,--build-id=none ?  Note, it's
# important that we test indirectly via whichever C compiler
# is selected, rather than testing /usr/bin/ld or whatever
# directly.
AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wl,--build-id=none -Werror"

AC_LINK_IFELSE(
[AC_LANG_PROGRAM([ ], [return 0;])],
[
  AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
  AC_MSG_RESULT([yes])
], [
  AC_SUBST([FLAG_NO_BUILD_ID], [""])
  AC_MSG_RESULT([no])
])
else
AC_MSG_NOTICE([ld -Ttext-segment used, no need to strip build-id NOTEs.])
AC_SUBST([FLAG_NO_BUILD_ID], [""])
fi
CFLAGS=$safe_CFLAGS

# does the ppc assembler support "mtocrf" et al?
AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
__asm__ __volatile__("mtocrf 4,0");
__asm__ __volatile__("mfocrf 0,4");
]])], [
ac_have_as_ppc_mftocrf=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_ppc_mftocrf=no
AC_MSG_RESULT([no])
])
if test x$ac_have_as_ppc_mftocrf = xyes ; then
  AC_DEFINE(HAVE_AS_PPC_MFTOCRF, 1, [Define to 1 if as supports mtocrf/mfocrf.])
fi


# does the ppc assembler support "lfdp" and other phased out floating point insns?
AC_MSG_CHECKING([if ppc32/64 asm supports phased out floating point instructions])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { typedef struct {
      double hi;
      double lo;
     } dbl_pair_t;
     dbl_pair_t dbl_pair[3];
     __asm__ volatile ("lfdp 10, %0"::"m" (dbl_pair[0]));
   } while (0)
]])], [
ac_have_as_ppc_fpPO=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_ppc_fpPO=no
AC_MSG_RESULT([no])
])
if test x$ac_have_as_ppc_fpPO = xyes ; then
  AC_DEFINE(HAVE_AS_PPC_FPPO, 1, [Define to 1 if as supports floating point phased out category.])
fi


# does the amd64 assembler understand "fxsave64" and "fxrstor64"?
AC_MSG_CHECKING([if amd64 assembler supports fxsave64/fxrstor64])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
void* p;
asm __volatile__("fxsave64 (%0)" : : "r" (p) : "memory" );
asm __volatile__("fxrstor64 (%0)" : : "r" (p) : "memory" );
]])], [
ac_have_as_amd64_fxsave64=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_amd64_fxsave64=no
AC_MSG_RESULT([no])
])
if test x$ac_have_as_amd64_fxsave64 = xyes ; then
  AC_DEFINE(HAVE_AS_AMD64_FXSAVE64, 1, [Define to 1 if as supports fxsave64/fxrstor64.])
fi

# does the x86/amd64 assembler understand SSE3 instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_SSE3_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE3])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
     __asm__ __volatile__("fisttpq (%0)" : :"r"(&x) ); } 
  while (0)
]])], [
ac_have_as_sse3=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_sse3=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_SSE3_TESTS, test x$ac_have_as_sse3 = xyes)


# Ditto for SSSE3 instructions (note extra S)
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_SSSE3_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks SSSE3])

save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -msse -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
   __asm__ __volatile__(
      "pabsb (%0),%%xmm7" : : "r"(&x) : "xmm7" ); }
  while (0)
]])], [
ac_have_as_ssse3=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_ssse3=no
AC_MSG_RESULT([no])
])
CFLAGS="$save_CFLAGS"

AM_CONDITIONAL(BUILD_SSSE3_TESTS, test x$ac_have_as_ssse3 = xyes)


# does the x86/amd64 assembler understand the PCLMULQDQ instruction?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_PCLMULQDQ_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports 'pclmulqdq'])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
   __asm__ __volatile__(
      "pclmulqdq \$17,%%xmm6,%%xmm7" : : : "xmm6", "xmm7" ); }
  while (0)
]])], [
ac_have_as_pclmulqdq=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_pclmulqdq=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_PCLMULQDQ_TESTS, test x$ac_have_as_pclmulqdq = xyes)


# does the x86/amd64 assembler understand the VPCLMULQDQ instruction?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_VPCLMULQDQ_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports 'vpclmulqdq'])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
      /*
       * Carry-less multiplication of xmm1 with xmm2 and store the result in
       * xmm3. The immediate is used to determine which quadwords of xmm1 and
       * xmm2 should be used.
       */
   __asm__ __volatile__(
      "vpclmulqdq \$0,%%xmm1,%%xmm2,%%xmm3" : : : );
  } while (0)
]])], [
ac_have_as_vpclmulqdq=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_vpclmulqdq=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_VPCLMULQDQ_TESTS, test x$ac_have_as_vpclmulqdq = xyes)


# does the x86/amd64 assembler understand FMA4 instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_AFM4_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports FMA4 'vfmaddpd'])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
   __asm__ __volatile__(
      "vfmaddpd %%xmm7,%%xmm8,%%xmm6,%%xmm9" : : : );
  } while (0)
]])], [
ac_have_as_vfmaddpd=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_vfmaddpd=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_FMA4_TESTS, test x$ac_have_as_vfmaddpd = xyes)


# does the x86/amd64 assembler understand the LZCNT instruction?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_LZCNT_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports 'lzcnt'])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { 		 
      __asm__ __volatile__("lzcnt %%rax,%%rax" : : : "rax");
  } while (0)
]])], [
  ac_have_as_lzcnt=yes
  AC_MSG_RESULT([yes])
], [
  ac_have_as_lzcnt=no
  AC_MSG_RESULT([no])
])

AM_CONDITIONAL([BUILD_LZCNT_TESTS], [test x$ac_have_as_lzcnt = xyes])


# does the x86/amd64 assembler understand the LOOPNEL instruction?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_LOOPNEL_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports 'loopnel'])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { 		 
      __asm__ __volatile__("1:  loopnel 1b\n");
  } while (0)
]])], [
  ac_have_as_loopnel=yes
  AC_MSG_RESULT([yes])
], [
  ac_have_as_loopnel=no
  AC_MSG_RESULT([no])
])

AM_CONDITIONAL([BUILD_LOOPNEL_TESTS], [test x$ac_have_as_loopnel = xyes])


# does the x86/amd64 assembler understand ADDR32 ?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_ADDR32_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler supports 'addr32'])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { 		 
      asm volatile ("addr32 rep movsb");
  } while (0)
]])], [
  ac_have_as_addr32=yes
  AC_MSG_RESULT([yes])
], [
  ac_have_as_addr32=no
  AC_MSG_RESULT([no])
])

AM_CONDITIONAL([BUILD_ADDR32_TESTS], [test x$ac_have_as_addr32 = xyes])


# does the x86/amd64 assembler understand SSE 4.2 instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_SSE42_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE4.2])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
   __asm__ __volatile__(
      "crc32q %%r15,%%r15" : : : "r15" );
   __asm__ __volatile__(
      "pblendvb (%%rcx), %%xmm11" : : : "memory", "xmm11"); 
   __asm__ __volatile__(
      "aesdec %%xmm2, %%xmm1" : : : "xmm2", "xmm1"); }
  while (0)
]])], [
ac_have_as_sse42=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_sse42=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_SSE42_TESTS, test x$ac_have_as_sse42 = xyes)


# does the x86/amd64 assembler understand AVX instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_AVX_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
   __asm__ __volatile__(
      "vmovupd (%%rsp), %%ymm7" : : : "xmm7" );
   __asm__ __volatile__(
      "vaddpd %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
  while (0)
]])], [
ac_have_as_avx=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_avx=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_AVX_TESTS, test x$ac_have_as_avx = xyes)


# does the x86/amd64 assembler understand AVX2 instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_AVX2_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX2])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
   __asm__ __volatile__(
      "vpsravd (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
   __asm__ __volatile__(
      "vpaddb %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
  while (0)
]])], [
ac_have_as_avx2=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_avx2=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_AVX2_TESTS, test x$ac_have_as_avx2 = xyes)


# does the x86/amd64 assembler understand TSX instructions and
# the XACQUIRE/XRELEASE prefixes?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_TSX_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks TSX])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
   __asm__ __volatile__(
      "       xbegin Lfoo  \n\t"
      "Lfoo:  xend         \n\t"
      "       xacquire lock incq 0(%rsp)     \n\t"
      "       xrelease lock incq 0(%rsp)     \n"
   );
  } while (0)
]])], [
ac_have_as_tsx=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_tsx=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_TSX_TESTS, test x$ac_have_as_tsx = xyes)


# does the x86/amd64 assembler understand BMI1 and BMI2 instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_BMI_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks BMI1 and BMI2])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { unsigned int h, l;
   __asm__ __volatile__( "mulx %rax,%rcx,%r8" );
   __asm__ __volatile__(
      "andn %2, %1, %0" : "=r" (h) : "r" (0x1234567), "r" (0x7654321) );
   __asm__ __volatile__(
      "movl %2, %%edx; mulx %3, %1, %0" : "=r" (h), "=r" (l) : "g" (0x1234567), "rm" (0x7654321) : "edx" ); }
  while (0)
]])], [
ac_have_as_bmi=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_bmi=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_BMI_TESTS, test x$ac_have_as_bmi = xyes)


# does the x86/amd64 assembler understand FMA instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_FMA_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler speaks FMA])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { unsigned int h, l;
   __asm__ __volatile__(
      "vfmadd132ps (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
   __asm__ __volatile__(
      "vfnmsub231sd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" );
   __asm__ __volatile__(
      "vfmsubadd213pd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" ); }
  while (0)
]])], [
ac_have_as_fma=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_fma=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_FMA_TESTS, test x$ac_have_as_fma = xyes)


# does the amd64 assembler understand MPX instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_MPX_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if amd64 assembler knows the MPX instructions])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
    asm ("bndmov %bnd0,(%rsp)");
    asm ("bndldx 3(%rbx,%rdx), %bnd2");
    asm ("bnd call foo\n"
          bnd jmp  end\n"
          foo: bnd ret\n"
          end: nop");
  } while (0)
]])], [
ac_have_as_mpx=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_mpx=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_MPX_TESTS, test x$ac_have_as_mpx = xyes)


# does the amd64 assembler understand ADX instructions?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_ADX_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if amd64 assembler knows the ADX instructions])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do {
    asm ("adcxq %r14,%r8");
  } while (0)
]])], [
ac_have_as_adx=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_adx=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_ADX_TESTS, test x$ac_have_as_adx = xyes)


# Does the C compiler support the "ifunc" attribute
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's
# does the x86/amd64 assembler understand MOVBE?
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_MOVBE_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if x86/amd64 assembler knows the MOVBE insn])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  do { long long int x; 
   __asm__ __volatile__(
      "movbe (%%rsp), %%r15" : : : "memory", "r15" ); }
  while (0)
]])], [
ac_have_as_movbe=yes
AC_MSG_RESULT([yes])
], [
ac_have_as_movbe=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_MOVBE_TESTS, test x$ac_have_as_movbe = xyes)


# Does the C compiler support the "ifunc" attribute
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if gcc supports the ifunc attribute])

AC_LINK_IFELSE([AC_LANG_SOURCE([[
static void mytest(void) {}

static void (*resolve_test(void))(void)
{
    return (void (*)(void))&mytest;
}

void test(void) __attribute__((ifunc("resolve_test")));

int main()
{
    test();
    return 0;
}
]])], [
ac_have_ifunc_attr=yes
AC_MSG_RESULT([yes])
], [
ac_have_ifunc_attr=no
AC_MSG_RESULT([no])
])

AM_CONDITIONAL(BUILD_IFUNC_TESTS, test x$ac_have_ifunc_attr = xyes)

# Does the C compiler support the armv8 crc feature flag
# Note, this doesn't generate a C-level symbol.  It generates a
# automake-level symbol (BUILD_ARMV8_CRC_TESTS), used in test Makefile.am's
AC_MSG_CHECKING([if gcc supports the armv8 crc feature flag])

save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -march=armv8-a+crc -Werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
int main()
{
    return 0;
}
]])], [
ac_have_armv8_crc_feature=yes
AC_MSG_RESULT([yes])
], [
ac_have_armv8_crc_feature=no
AC_MSG_RESULT([no])
])
CFLAGS="$save_CFLAGS"

AM_CONDITIONAL(BUILD_ARMV8_CRC_TESTS, test x$ac_have_armv8_crc_feature = xyes)


# XXX JRS 2010 Oct 13: what is this for?  For sure, we don't need this
# when building the tool executables.  I think we should get rid of it.
#
# Check for TLS support in the compiler and linker
AC_LINK_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
                                [[return foo;]])],
                               [vg_cv_linktime_tls=yes],
                               [vg_cv_linktime_tls=no])
# Native compilation: check whether running a program using TLS succeeds.
# Linking only is not sufficient -- e.g. on Red Hat 7.3 linking TLS programs
# succeeds but running programs using TLS fails.
# Cross-compiling: check whether linking a program using TLS succeeds.
AC_CACHE_CHECK([for TLS support], vg_cv_tls,
	       [AC_ARG_ENABLE(tls, [  --enable-tls            platform supports TLS],
		[vg_cv_tls=$enableval],
               	[AC_RUN_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
                                                [[return foo;]])],
                               [vg_cv_tls=yes],
                               [vg_cv_tls=no],
                               [vg_cv_tls=$vg_cv_linktime_tls])])])

if test "$vg_cv_tls" = yes -a $is_clang != applellvm; then
AC_DEFINE([HAVE_TLS], 1, [can use __thread to define thread-local variables])
fi


#----------------------------------------------------------------------------
# Solaris-specific checks.
#----------------------------------------------------------------------------

if test "$VGCONF_OS" = "solaris" ; then
AC_CHECK_HEADERS([sys/lgrp_user_impl.h])

# Solaris-specific check determining if the Sun Studio Assembler is used to
# build Valgrind.  The test checks if the x86/amd64 assembler understands the
# cmovl.l instruction, if yes then it's Sun Assembler.
#
# C-level symbol: none
# Automake-level symbol: SOLARIS_SUN_STUDIO_AS
#
AC_MSG_CHECKING([if x86/amd64 assembler speaks cmovl.l (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __asm__ __volatile__("cmovl.l %edx, %eax");
]])], [
solaris_have_sun_studio_as=yes
AC_MSG_RESULT([yes])
], [
solaris_have_sun_studio_as=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, test x$solaris_have_sun_studio_as = xyes)

# Solaris-specific check determining if symbols __xpg4 and __xpg6
# are present in linked shared libraries when gcc is invoked with -std=gnu99.
# See solaris/vgpreload-solaris.mapfile for details.
# gcc on older Solaris instructs linker to include these symbols,
# gcc on illumos and newer Solaris does not.
#
# C-level symbol: none
# Automake-level symbol: SOLARIS_XPG_SYMBOLS_PRESENT
#
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -std=gnu99"
AC_MSG_CHECKING([if xpg symbols are present with -std=gnu99 (Solaris-specific)])
temp_dir=$( /usr/bin/mktemp -d )
cat <<_ACEOF >${temp_dir}/mylib.c
#include <stdio.h>
int myfunc(void) { printf("LaPutyka\n"); }
_ACEOF
${CC} ${CFLAGS} -fpic -shared -o ${temp_dir}/mylib.so ${temp_dir}/mylib.c
xpg_present=$( /usr/bin/nm ${temp_dir}/mylib.so | ${EGREP} '(__xpg4|__xpg6)' )
if test "x${xpg_present}" = "x" ; then
    solaris_xpg_symbols_present=no
    AC_MSG_RESULT([no])
else
    solaris_xpg_symbols_present=yes
    AC_MSG_RESULT([yes])
fi
rm -rf ${temp_dir}
AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, test x$solaris_xpg_symbols_present = xyes)
CFLAGS="$save_CFLAGS"


# Solaris-specific check determining if gcc enables largefile support by
# default for 32-bit executables. If it does, then set SOLARIS_UNDEF_LARGESOURCE
# variable with gcc flags which disable it.
#
AC_MSG_CHECKING([if gcc enables largefile support for 32-bit apps (Solaris-specific)])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -m32"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
  return _LARGEFILE_SOURCE;
]])], [
SOLARIS_UNDEF_LARGESOURCE="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
AC_MSG_RESULT([yes])
], [
SOLARIS_UNDEF_LARGESOURCE=""
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
AC_SUBST(SOLARIS_UNDEF_LARGESOURCE)


# Solaris-specific check determining if /proc/self/cmdline
# or /proc/<pid>/cmdline is supported.
#
# C-level symbol: SOLARIS_PROC_CMDLINE
# Automake-level symbol: SOLARIS_PROC_CMDLINE
#
AC_CHECK_FILE([/proc/self/cmdline],
[
solaris_proc_cmdline=yes
AC_DEFINE([SOLARIS_PROC_CMDLINE], 1,
          [Define to 1 if you have /proc/self/cmdline.])
], [
solaris_proc_cmdline=no
])
AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, test x$solaris_proc_cmdline = xyes)


# Solaris-specific check determining default platform for the Valgrind launcher.
# Used in case the launcher cannot select platform by looking at the client
# image (for example because the executable is a shell script).
#
# C-level symbol: SOLARIS_LAUNCHER_DEFAULT_PLATFORM
# Automake-level symbol: none
#
AC_MSG_CHECKING([for default platform of Valgrind launcher (Solaris-specific)])
# Get the ELF class of /bin/sh first.
if ! test -f /bin/sh; then
  AC_MSG_ERROR([Shell interpreter `/bin/sh' not found.])
fi
elf_class=$( /usr/bin/file /bin/sh | sed -n 's/.*ELF \(..\)-bit.*/\1/p' )
case "$elf_class" in
  64)
    default_arch="$VGCONF_ARCH_PRI";
    ;;
  32)
    if test "x$VGCONF_ARCH_SEC" != "x"; then
      default_arch="$VGCONF_ARCH_SEC"
    else
      default_arch="$VGCONF_ARCH_PRI";
    fi
    ;;
  *)
    AC_MSG_ERROR([Cannot determine ELF class of `/bin/sh'.])
    ;;
esac
default_platform="$default_arch-$VGCONF_OS"
AC_MSG_RESULT([$default_platform])
AC_DEFINE_UNQUOTED([SOLARIS_LAUNCHER_DEFAULT_PLATFORM], ["$default_platform"],
                   [Default platform for Valgrind launcher.])


# Solaris-specific check determining if the old syscalls are available.
#
# C-level symbol: SOLARIS_OLD_SYSCALLS
# Automake-level symbol: SOLARIS_OLD_SYSCALLS
#
AC_MSG_CHECKING([for the old Solaris syscalls (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_open;
]])], [
solaris_old_syscalls=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_OLD_SYSCALLS], 1,
          [Define to 1 if you have the old Solaris syscalls.])
], [
solaris_old_syscalls=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, test x$solaris_old_syscalls = xyes)


# Solaris-specific check determining if the new accept() syscall is available.
#
# Old syscall:
# int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
#            int version);
#
# New syscall (available on illumos):
# int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
#            int version, int flags);
#
# If the old syscall is present then the following syscall will fail with
# ENOTSOCK (because file descriptor 0 is not a socket), if the new syscall is
# available then it will fail with EINVAL (because the flags parameter is
# invalid).
#
# C-level symbol: SOLARIS_NEW_ACCEPT_SYSCALL
# Automake-level symbol: none
#
AC_MSG_CHECKING([for the new `accept' syscall (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
#include <errno.h>
]], [[
  errno = 0;
  syscall(SYS_accept, 0, 0, 0, 0, -1);
  return !(errno == EINVAL);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_NEW_ACCEPT_SYSCALL], 1,
          [Define to 1 if you have the new `accept' syscall.])
], [
AC_MSG_RESULT([no])
])


# Solaris-specific check determining if the new illumos pipe() syscall is
# available.
#
# Old syscall:
# longlong_t pipe();
#
# New syscall (available on illumos):
# int pipe(intptr_t arg, int flags);
#
# If the old syscall is present then the following call will succeed, if the
# new syscall is available then it will fail with EFAULT (because address 0
# cannot be accessed).
#
# C-level symbol: SOLARIS_NEW_PIPE_SYSCALL
# Automake-level symbol: none
#
AC_MSG_CHECKING([for the new `pipe' syscall (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
#include <errno.h>
]], [[
  errno = 0;
  syscall(SYS_pipe, 0, 0);
  return !(errno == EFAULT);
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_NEW_PIPE_SYSCALL], 1,
          [Define to 1 if you have the new `pipe' syscall.])
], [
AC_MSG_RESULT([no])
])


# Solaris-specific check determining if the new lwp_sigqueue() syscall is
# available.
#
# Old syscall:
# int lwp_kill(id_t lwpid, int sig);
#
# New syscall (available on Solaris 11):
# int lwp_sigqueue(id_t lwpid, int sig, void *value,
#                  int si_code, timespec_t *timeout);
#
# C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
# Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
#
AC_MSG_CHECKING([for the new `lwp_sigqueue' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h> 
]], [[
  return !SYS_lwp_sigqueue;
]])], [
solaris_lwp_sigqueue_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL], 1,
          [Define to 1 if you have the new `lwp_sigqueue' syscall.])
], [
solaris_lwp_sigqueue_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, test x$solaris_lwp_sigqueue_syscall = xyes)


# Solaris-specific check determining if the lwp_sigqueue() syscall
# takes both pid and thread id arguments or just thread id.
#
# Old syscall (available up to Solaris 11.3):
# int lwp_sigqueue(id_t lwpid, int sig, void *value,
#                  int si_code, timespec_t *timeout);
#
# New syscall (available since Solaris 11.4):
# int lwp_sigqueue(pid_t pid, id_t lwpid, int sig, void *value,
#                  int si_code, timespec_t *timeout);
#
# If the old syscall is present then the following syscall will fail with
# EINVAL (because signal is out of range); if the new syscall is available
# then it will fail with ESRCH (because it would not find such thread in the
# current process).
#
# C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
# Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
#
AM_COND_IF(SOLARIS_LWP_SIGQUEUE_SYSCALL,
AC_MSG_CHECKING([if the `lwp_sigqueue' syscall accepts pid (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
#include <errno.h>
]], [[
  errno = 0;
  syscall(SYS_lwp_sigqueue, 0, 101, 0, 0, 0, 0);
  return !(errno == ESRCH);
]])], [
solaris_lwp_sigqueue_syscall_takes_pid=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID], 1,
          [Define to 1 if you have the new `lwp_sigqueue' syscall which accepts pid.])
], [
solaris_lwp_sigqueue_syscall_takes_pid=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID,
               test x$solaris_lwp_sigqueue_syscall_takes_pid = xyes)
,
AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, test x = y)
)


# Solaris-specific check determining if the new lwp_name() syscall is
# available.
#
# New syscall (available on Solaris 11):
# int lwp_name(int opcode, id_t lwpid, char *name, size_t len);
#
# C-level symbol: SOLARIS_LWP_NAME_SYSCALL
# Automake-level symbol: SOLARIS_LWP_NAME_SYSCALL
#
AC_MSG_CHECKING([for the new `lwp_name' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_lwp_name;
]])], [
solaris_lwp_name_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_LWP_NAME_SYSCALL], 1,
          [Define to 1 if you have the new `lwp_name' syscall.])
], [
solaris_lwp_name_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, test x$solaris_lwp_name_syscall = xyes)


# Solaris-specific check determining if the new getrandom() syscall is
# available.
#
# New syscall (available on Solaris 11):
# int getrandom(void *buf, size_t buflen, uint_t flags);
#
# C-level symbol: SOLARIS_GETRANDOM_SYSCALL
# Automake-level symbol: SOLARIS_GETRANDOM_SYSCALL
#
AC_MSG_CHECKING([for the new `getrandom' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_getrandom;
]])], [
solaris_getrandom_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_GETRANDOM_SYSCALL], 1,
          [Define to 1 if you have the new `getrandom' syscall.])
], [
solaris_getrandom_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, test x$solaris_getrandom_syscall = xyes)


# Solaris-specific check determining if the new zone() syscall subcodes
# ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT are available.  These subcodes
# were added in Solaris 11 but are missing on illumos.
#
# C-level symbol: SOLARIS_ZONE_DEFUNCT
# Automake-level symbol: SOLARIS_ZONE_DEFUNCT
#
AC_MSG_CHECKING([for ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/zone.h>
]], [[
  return !(ZONE_LIST_DEFUNCT && ZONE_GETATTR_DEFUNCT);
]])], [
solaris_zone_defunct=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_ZONE_DEFUNCT], 1,
          [Define to 1 if you have the `ZONE_LIST_DEFUNCT' and `ZONE_GETATTR_DEFUNC' constants.])
], [
solaris_zone_defunct=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, test x$solaris_zone_defunct = xyes)


# Solaris-specific check determining if commands A_GETSTAT and A_SETSTAT
# for auditon(2) subcode of the auditsys() syscall are available.
# These commands are available in Solaris 11 and illumos but were removed
# in Solaris 11.4.
#
# C-level symbol: SOLARIS_AUDITON_STAT
# Automake-level symbol: SOLARIS_AUDITON_STAT
#
AC_MSG_CHECKING([for A_GETSTAT and A_SETSTAT auditon(2) commands (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <bsm/audit.h>
]], [[
  return !(A_GETSTAT && A_SETSTAT);
]])], [
solaris_auditon_stat=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_AUDITON_STAT], 1,
          [Define to 1 if you have the `A_GETSTAT' and `A_SETSTAT' constants.])
], [
solaris_auditon_stat=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_AUDITON_STAT, test x$solaris_auditon_stat = xyes)


# Solaris-specific check determining if the new shmsys() syscall subcodes
# IPC_XSTAT64, SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM are available.
# These subcodes were added in Solaris 11 but are missing on illumos.
#
# C-level symbol: SOLARIS_SHM_NEW
# Automake-level symbol: SOLARIS_SHM_NEW
#
AC_MSG_CHECKING([for SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/ipc_impl.h>
#include <sys/shm.h>
#include <sys/shm_impl.h>
]], [[
  return !(IPC_XSTAT64 && SHMADV && SHM_ADV_GET && SHM_ADV_SET && SHMGET_OSM);
]])], [
solaris_shm_new=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_SHM_NEW], 1,
          [Define to 1 if you have the `IPC_XSTAT64', `SHMADV', `SHM_ADV_GET', `SHM_ADV_SET' and `SHMGET_OSM' constants.])
], [
solaris_shm_new=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_SHM_NEW, test x$solaris_shm_new = xyes)


# Solaris-specific check determining if prxregset_t is available.  Illumos
# currently does not define it on the x86 platform.
#
# C-level symbol: SOLARIS_PRXREGSET_T
# Automake-level symbol: SOLARIS_PRXREGSET_T
#
AC_MSG_CHECKING([for the `prxregset_t' type (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/procfs_isa.h>
]], [[
  return !sizeof(prxregset_t);
]])], [
solaris_prxregset_t=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_PRXREGSET_T], 1,
          [Define to 1 if you have the `prxregset_t' type.])
], [
solaris_prxregset_t=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_PRXREGSET_T, test x$solaris_prxregset_t = xyes)


# Solaris-specific check determining if the new frealpathat() syscall is
# available.
#
# New syscall (available on Solaris 11.1):
# int frealpathat(int fd, char *path, char *buf, size_t buflen);
#
# C-level symbol: SOLARIS_FREALPATHAT_SYSCALL
# Automake-level symbol: SOLARIS_FREALPATHAT_SYSCALL
#
AC_MSG_CHECKING([for the new `frealpathat' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_frealpathat;
]])], [
solaris_frealpathat_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_FREALPATHAT_SYSCALL], 1,
          [Define to 1 if you have the new `frealpathat' syscall.])
], [
solaris_frealpathat_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, test x$solaris_frealpathat_syscall = xyes)


# Solaris-specific check determining if the new uuidsys() syscall is
# available.
#
# New syscall (available on newer Solaris):
# int uuidsys(struct uuid *uuid);
#
# C-level symbol: SOLARIS_UUIDSYS_SYSCALL
# Automake-level symbol: SOLARIS_UUIDSYS_SYSCALL
#
AC_MSG_CHECKING([for the new `uuidsys' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_uuidsys;
]])], [
solaris_uuidsys_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_UUIDSYS_SYSCALL], 1,
          [Define to 1 if you have the new `uuidsys' syscall.])
], [
solaris_uuidsys_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, test x$solaris_uuidsys_syscall = xyes)


# Solaris-specific check determining if the new labelsys() syscall subcode
# TNDB_GET_TNIP is available.  This subcode was added in Solaris 11 but is
# missing on illumos.
#
# C-level symbol: SOLARIS_TNDB_GET_TNIP
# Automake-level symbol: SOLARIS_TNDB_GET_TNIP
#
AC_MSG_CHECKING([for TNDB_GET_TNIP (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/tsol/tndb.h>
]], [[
  return !TNDB_GET_TNIP;
]])], [
solaris_tndb_get_tnip=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_TNDB_GET_TNIP], 1,
          [Define to 1 if you have the `TNDB_GET_TNIP' constant.])
], [
solaris_tndb_get_tnip=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, test x$solaris_tndb_get_tnip = xyes)


# Solaris-specific check determining if the new labelsys() syscall opcodes
# TSOL_GETCLEARANCE and TSOL_SETCLEARANCE are available. These opcodes were
# added in Solaris 11 but are missing on illumos.
#
# C-level symbol: SOLARIS_TSOL_CLEARANCE
# Automake-level symbol: SOLARIS_TSOL_CLEARANCE
#
AC_MSG_CHECKING([for TSOL_GETCLEARANCE and TSOL_SETCLEARANCE (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/tsol/tsyscall.h>
]], [[
  return !(TSOL_GETCLEARANCE && TSOL_SETCLEARANCE);
]])], [
solaris_tsol_clearance=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_TSOL_CLEARANCE], 1,
          [Define to 1 if you have the `TSOL_GETCLEARANCE' and `TSOL_SETCLEARANCE' constants.])
], [
solaris_tsol_clearance=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, test x$solaris_tsol_clearance = xyes)


# Solaris-specific check determining if the new pset() syscall subcode
# PSET_GET_NAME is available. This subcode was added in Solaris 11.4 but
# is missing on illumos and Solaris 11.3.
#
# C-level symbol: SOLARIS_PSET_GET_NAME
# Automake-level symbol: SOLARIS_PSET_GET_NAME
#
AC_MSG_CHECKING([for PSET_GET_NAME (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/pset.h>
]], [[
  return !(PSET_GET_NAME);
]])], [
solaris_pset_get_name=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_PSET_GET_NAME], 1,
          [Define to 1 if you have the `PSET_GET_NAME' constants.])
], [
solaris_pset_get_name=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, test x$solaris_pset_get_name = xyes)


# Solaris-specific check determining if the utimesys() syscall is
# available (on illumos and older Solaris).
#
# C-level symbol: SOLARIS_UTIMESYS_SYSCALL
# Automake-level symbol: SOLARIS_UTIMESYS_SYSCALL
#
AC_MSG_CHECKING([for the `utimesys' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_utimesys;
]])], [
solaris_utimesys_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_UTIMESYS_SYSCALL], 1,
          [Define to 1 if you have the `utimesys' syscall.])
], [
solaris_utimesys_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, test x$solaris_utimesys_syscall = xyes)


# Solaris-specific check determining if the utimensat() syscall is
# available (on newer Solaris).
#
# C-level symbol: SOLARIS_UTIMENSAT_SYSCALL
# Automake-level symbol: SOLARIS_UTIMENSAT_SYSCALL
#
AC_MSG_CHECKING([for the `utimensat' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_utimensat;
]])], [
solaris_utimensat_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_UTIMENSAT_SYSCALL], 1,
          [Define to 1 if you have the `utimensat' syscall.])
], [
solaris_utimensat_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, test x$solaris_utimensat_syscall = xyes)


# Solaris-specific check determining if the spawn() syscall is available
# (on newer Solaris).
#
# C-level symbol: SOLARIS_SPAWN_SYSCALL
# Automake-level symbol: SOLARIS_SPAWN_SYSCALL
#
AC_MSG_CHECKING([for the `spawn' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_spawn;
]])], [
solaris_spawn_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_SPAWN_SYSCALL], 1,
          [Define to 1 if you have the `spawn' syscall.])
], [
solaris_spawn_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, test x$solaris_spawn_syscall = xyes)


# Solaris-specific check determining if commands MODNVL_CTRLMAP through
# MODDEVINFO_CACHE_TS for modctl() syscall are available (on newer Solaris).
#
# C-level symbol: SOLARIS_MODCTL_MODNVL
# Automake-level symbol: SOLARIS_MODCTL_MODNVL
#
AC_MSG_CHECKING([for MODNVL_CTRLMAP through MODDEVINFO_CACHE_TS modctl(2) commands (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/modctl.h>
]], [[
  return !(MODNVL_CTRLMAP && MODDEVINFO_CACHE_TS);
]])], [
solaris_modctl_modnvl=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_MODCTL_MODNVL], 1,
          [Define to 1 if you have the `MODNVL_CTRLMAP' through `MODDEVINFO_CACHE_TS' constants.])
], [
solaris_modctl_modnvl=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, test x$solaris_modctl_modnvl = xyes)


# Solaris-specific check determining whether nscd (name switch cache daemon)
# attaches its door at /system/volatile/name_service_door (Solaris)
# or at /var/run/name_service_door (illumos).
#
# Note that /var/run is a symlink to /system/volatile on Solaris
# but not vice versa on illumos.
#
# C-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
# Automake-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
#
AC_MSG_CHECKING([for nscd door location (Solaris-specific)])
if test -e /system/volatile/name_service_door; then
    solaris_nscd_door_system_volatile=yes
    AC_MSG_RESULT([/system/volatile/name_service_door])
    AC_DEFINE([SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE], 1,
              [Define to 1 if nscd attaches to /system/volatile/name_service_door.])
else
    solaris_nscd_door_system_volatile=no
    AC_MSG_RESULT([/var/run/name_service_door])
fi
AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, test x$solaris_nscd_door_system_volatile = xyes)


# Solaris-specific check determining if the new gethrt() fasttrap is available.
#
# New fasttrap (available on Solaris 11):
# hrt_t *gethrt(void);
#
# C-level symbol: SOLARIS_GETHRT_FASTTRAP
# Automake-level symbol: SOLARIS_GETHRT_FASTTRAP
#
AC_MSG_CHECKING([for the new `gethrt' fasttrap (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/trap.h>
]], [[
  return !T_GETHRT;
]])], [
solaris_gethrt_fasttrap=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_GETHRT_FASTTRAP], 1,
          [Define to 1 if you have the new `gethrt' fasttrap.])
], [
solaris_gethrt_fasttrap=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, test x$solaris_gethrt_fasttrap = xyes)


# Solaris-specific check determining if the new get_zone_offset() fasttrap
# is available.
#
# New fasttrap (available on Solaris 11):
# zonehrtoffset_t *get_zone_offset(void);
#
# C-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
# Automake-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
#
AC_MSG_CHECKING([for the new `get_zone_offset' fasttrap (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/trap.h>
]], [[
  return !T_GETZONEOFFSET;
]])], [
solaris_getzoneoffset_fasttrap=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_GETZONEOFFSET_FASTTRAP], 1,
          [Define to 1 if you have the new `get_zone_offset' fasttrap.])
], [
solaris_getzoneoffset_fasttrap=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, test x$solaris_getzoneoffset_fasttrap = xyes)


# Solaris-specific check determining if the execve() syscall
# takes fourth argument (flags) or not.
#
# Old syscall (available on illumos):
# int execve(const char *fname, const char **argv, const char **envp);
#
# New syscall (available on Solaris):
# int execve(uintptr_t file, const char **argv, const char **envp, int flags);
#
# If the new syscall is present then it will fail with EINVAL (because flags
# are invalid); if the old syscall is available then it will fail with ENOENT
# (because the file could not be found).
#
# C-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
# Automake-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
#
AC_MSG_CHECKING([if the `execve' syscall accepts flags (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
#include <errno.h>
]], [[
  errno = 0;
  syscall(SYS_execve, "/no/existing/path", 0, 0, 0xdeadbeef, 0, 0);
  return !(errno == EINVAL);
]])], [
solaris_execve_syscall_takes_flags=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS], 1,
          [Define to 1 if you have the new `execve' syscall which accepts flags.])
], [
solaris_execve_syscall_takes_flags=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS,
               test x$solaris_execve_syscall_takes_flags = xyes)


# Solaris-specific check determining version of the repository cache protocol.
# Every Solaris version uses a different one, ranging from 21 to current 25.
# The check is very ugly, though.
#
# C-level symbol: SOLARIS_REPCACHE_PROTOCOL_VERSION vv
# Automake-level symbol: none
#
AC_PATH_PROG(DIS_PATH, dis, false)
if test "x$DIS_PATH" = "xfalse"; then
  AC_MSG_FAILURE([Object code disassembler (`dis') not found.])
fi
AC_CHECK_LIB(scf, scf_handle_bind, [], [
  AC_MSG_WARN([Function `scf_handle_bind' was not found in `libscf'.])
  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
])

AC_MSG_CHECKING([for version of the repository cache protocol (Solaris-specific)])
if test "X$VGCONF_ARCH_PRI" = "Xamd64"; then
  libscf=/usr/lib/64/libscf.so.1
else
  libscf=/usr/lib/libscf.so.1
fi
if ! $DIS_PATH -F scf_handle_bind $libscf  | grep -q 0x526570; then
  AC_MSG_WARN([Function `scf_handle_bind' does not contain repository cache protocol version.])
  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
fi
hex=$( $DIS_PATH -F scf_handle_bind $libscf  | sed -n 's/.*0x526570\(..\).*/\1/p' )
if test -z "$hex"; then
  AC_MSG_WARN([Version of the repository cache protocol is empty?!])
  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
fi
version=$( printf "%d\n" 0x$hex )
AC_MSG_RESULT([$version])
AC_DEFINE_UNQUOTED([SOLARIS_REPCACHE_PROTOCOL_VERSION], [$version],
                   [Version number of the repository door cache protocol.])


# Solaris-specific check determining if "sysstat" segment reservation type
# is available.
#
# New "sysstat" segment reservation (available on Solaris 11.4):
# - program header type:    PT_SUNW_SYSSTAT
# - auxiliary vector entry: AT_SUN_SYSSTAT_ADDR
#
# C-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
# Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
#
AC_MSG_CHECKING([for the new `sysstat' segment reservation (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/auxv.h>
]], [[
  return !AT_SUN_SYSSTAT_ADDR;
]])], [
solaris_reserve_sysstat_addr=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ADDR], 1,
          [Define to 1 if you have the new `sysstat' segment reservation.])
], [
solaris_reserve_sysstat_addr=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, test x$solaris_reserve_sysstat_addr = xyes)


# Solaris-specific check determining if "sysstat_zone" segment reservation type
# is available.
#
# New "sysstat_zone" segment reservation (available on Solaris 11.4):
# - program header type:    PT_SUNW_SYSSTAT_ZONE
# - auxiliary vector entry: AT_SUN_SYSSTAT_ZONE_ADDR
#
# C-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
# Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
#
AC_MSG_CHECKING([for the new `sysstat_zone' segment reservation (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/auxv.h>
]], [[
  return !AT_SUN_SYSSTAT_ZONE_ADDR;
]])], [
solaris_reserve_sysstat_zone_addr=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR], 1,
          [Define to 1 if you have the new `sysstat_zone' segment reservation.])
], [
solaris_reserve_sysstat_zone_addr=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, test x$solaris_reserve_sysstat_zone_addr = xyes)


# Solaris-specific check determining if the system_stats() syscall is available
# (on newer Solaris).
#
# C-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
# Automake-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
#
AC_MSG_CHECKING([for the `system_stats' syscall (Solaris-specific)])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/syscall.h>
]], [[
  return !SYS_system_stats;
]])], [
solaris_system_stats_syscall=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_SYSTEM_STATS_SYSCALL], 1,
          [Define to 1 if you have the `system_stats' syscall.])
], [
solaris_system_stats_syscall=no
AC_MSG_RESULT([no])
])
AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, test x$solaris_system_stats_syscall = xyes)


# Solaris-specific check determining if fpregset_t defines struct _fpchip_state
# (on newer illumos) or struct fpchip_state (Solaris, older illumos).
#
# C-level symbol: SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE
# Automake-level symbol: none
#
AC_CHECK_TYPE([struct _fpchip_state],
              [solaris_fpchip_state_takes_underscore=yes],
              [solaris_fpchip_state_takes_underscore=no],
              [[#include <sys/regset.h>]])
if test "$solaris_fpchip_state_takes_underscore" = "yes"; then
  AC_DEFINE(SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE, 1,
            [Define to 1 if fpregset_t defines struct _fpchip_state])
fi


# Solaris-specific check determining if schedctl page shared between kernel
# and userspace program is executable (illumos, older Solaris) or not (newer
# Solaris).
#
# C-level symbol: SOLARIS_SCHEDCTL_PAGE_EXEC
# Automake-level symbol: none
#
AC_MSG_CHECKING([if schedctl page is executable (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <assert.h>
#include <fcntl.h>
#include <procfs.h>
#include <schedctl.h>
#include <stdio.h>
#include <unistd.h>
]], [[
    schedctl_t *scp = schedctl_init();
    if (scp == NULL)
        return 1;

    int fd = open("/proc/self/map", O_RDONLY);
    assert(fd >= 0);

    prmap_t map;
    ssize_t rd;
    while ((rd = read(fd, &map, sizeof(map))) == sizeof(map)) {
        if (map.pr_vaddr == ((uintptr_t) scp & PAGEMASK)) {
            fprintf(stderr, "%#lx [%zu] %s\n", map.pr_vaddr, map.pr_size,
                    (map.pr_mflags & MA_EXEC) ? "x" : "no-x");
            return (map.pr_mflags & MA_EXEC);
        }
    }

    return 1;
]])], [
solaris_schedctl_page_exec=no
AC_MSG_RESULT([no])
], [
solaris_schedctl_page_exec=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_SCHEDCTL_PAGE_EXEC], 1,
          [Define to 1 if you have the schedctl page executable.])
])


# Solaris-specific check determining if PT_SUNWDTRACE program header provides
# scratch space for DTrace fasttrap provider (illumos, older Solaris) or just
# an initial thread pointer for libc (newer Solaris).
#
# C-level symbol: SOLARIS_PT_SUNDWTRACE_THRP
# Automake-level symbol: none
#
AC_MSG_CHECKING([if PT_SUNWDTRACE serves for initial thread pointer (Solaris-specific)])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <sys/fasttrap_isa.h>
]], [[
    return !FT_SCRATCHSIZE;
]])], [
solaris_pt_sunwdtrace_thrp=yes
AC_MSG_RESULT([yes])
AC_DEFINE([SOLARIS_PT_SUNDWTRACE_THRP], 1,
          [Define to 1 if PT_SUNWDTRACE program header provides just an initial thread pointer for libc.])
], [
solaris_pt_sunwdtrace_thrp=no
AC_MSG_RESULT([no])
])

else
AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)
AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, false)
AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, false)
AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, false)
AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, false)
AM_CONDITIONAL(SOLARIS_AUDITON_STAT, false)
AM_CONDITIONAL(SOLARIS_SHM_NEW, false)
AM_CONDITIONAL(SOLARIS_PRXREGSET_T, false)
AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, false)
AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, false)
AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, false)
AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, false)
AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, false)
AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, false)
AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, false)
AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, false)
AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS, false)
AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, false)
AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, false)
AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, false)
fi # test "$VGCONF_OS" = "solaris"


#----------------------------------------------------------------------------
# Checks for C header files.
#----------------------------------------------------------------------------

AC_HEADER_STDC
AC_CHECK_HEADERS([       \
        asm/unistd.h     \
        endian.h         \
        mqueue.h         \
        sys/endian.h     \
        sys/epoll.h      \
        sys/eventfd.h    \
        sys/klog.h       \
        sys/poll.h       \
        sys/prctl.h      \
        sys/signal.h     \
        sys/signalfd.h   \
        sys/syscall.h    \
        sys/sysnvl.h     \
        sys/time.h       \
        sys/types.h      \
        ])

# Verify whether the <linux/futex.h> header is usable.
AC_MSG_CHECKING([if <linux/futex.h> is usable])

save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -D__user="
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <linux/futex.h>
]], [[
  return FUTEX_WAIT;
]])], [
ac_have_usable_linux_futex_h=yes
AC_DEFINE([HAVE_USABLE_LINUX_FUTEX_H], 1,
          [Define to 1 if you have a usable <linux/futex.h> header file.])
AC_MSG_RESULT([yes])
], [
ac_have_usable_linux_futex_h=no
AC_MSG_RESULT([no])
])
CFLAGS="$save_CFLAGS"


#----------------------------------------------------------------------------
# Checks for typedefs, structures, and compiler characteristics.
#----------------------------------------------------------------------------
AC_TYPE_UID_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_HEADER_TIME


#----------------------------------------------------------------------------
# Checks for library functions.
#----------------------------------------------------------------------------
AC_FUNC_MEMCMP
AC_FUNC_MMAP

AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([rt], [clock_gettime])

AC_CHECK_FUNCS([     \
        clock_gettime\
        epoll_create \
        epoll_pwait  \
        klogctl      \
        mallinfo     \
        memchr       \
        memset       \
        mkdir        \
        mremap       \
        ppoll        \
        pthread_barrier_init       \
        pthread_condattr_setclock  \
        pthread_mutex_timedlock    \
        pthread_rwlock_timedrdlock \
        pthread_rwlock_timedwrlock \
        pthread_spin_lock          \
        pthread_yield              \
        pthread_setname_np         \
        readlinkat   \
        semtimedop   \
        signalfd     \
        sigwaitinfo  \
        strchr       \
        strdup       \
        strpbrk      \
        strrchr      \
        strstr       \
        syscall      \
        utimensat    \
        process_vm_readv  \
        process_vm_writev \
        ])

# AC_CHECK_LIB adds any library found to the variable LIBS, and links these
# libraries with any shared object and/or executable. This is NOT what we
# want for e.g. vgpreload_core-x86-linux.so
LIBS=""

AM_CONDITIONAL([HAVE_PTHREAD_BARRIER],
               [test x$ac_cv_func_pthread_barrier_init = xyes])
AM_CONDITIONAL([HAVE_PTHREAD_MUTEX_TIMEDLOCK],
               [test x$ac_cv_func_pthread_mutex_timedlock = xyes])
AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
               [test x$ac_cv_func_pthread_spin_lock = xyes])
AM_CONDITIONAL([HAVE_PTHREAD_SETNAME_NP],
               [test x$ac_cv_func_pthread_setname_np = xyes])

if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ; then
  AC_DEFINE([DISABLE_PTHREAD_SPINLOCK_INTERCEPT], 1,
            [Disable intercept pthread_spin_lock() on MIPS32 and MIPS64.])
fi

#----------------------------------------------------------------------------
# MPI checks
#----------------------------------------------------------------------------
# Do we have a useable MPI setup on the primary and/or secondary targets?
# On Linux, by default, assumes mpicc and -m32/-m64
# Note: this is a kludge in that it assumes the specified mpicc 
# understands -m32/-m64 regardless of what is specified using
# --with-mpicc=.
AC_PATH_PROG([MPI_CC], [mpicc], [mpicc],
             [$PATH:/usr/lib/openmpi/bin:/usr/lib64/openmpi/bin])

mflag_primary=
if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
     -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS ; then
  mflag_primary=$FLAG_M32
elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
       -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX \
       -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
       -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
       -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX ; then
  mflag_primary=$FLAG_M64
elif test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN ; then
  mflag_primary="$FLAG_M32 -arch i386"
elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN ; then
  mflag_primary="$FLAG_M64 -arch x86_64"
fi

mflag_secondary=
if test x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
     -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX \
     -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS \
     -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX ; then
  mflag_secondary=$FLAG_M32
elif test x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN ; then
  mflag_secondary="$FLAG_M32 -arch i386"
fi


AC_ARG_WITH(mpicc,
   [  --with-mpicc=           Specify name of MPI2-ised C compiler],
   MPI_CC=$withval
)
AC_SUBST(MPI_CC)

## We AM_COND_IF here instead of automake "if" in mpi/Makefile.am so that we can
## use these values in the check for a functioning mpicc.
##
## We leave the MPI_FLAG_M3264_ logic in mpi/Makefile.am and assume that
## mflag_primary/mflag_secondary are sufficient approximations of that behavior
AM_COND_IF([VGCONF_OS_IS_LINUX],
           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
            LDFLAGS_MPI="-fpic -shared"])
AM_COND_IF([VGCONF_OS_IS_DARWIN],
           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -dynamic"
            LDFLAGS_MPI="-dynamic -dynamiclib -all_load"])
AM_COND_IF([VGCONF_OS_IS_SOLARIS],
           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
            LDFLAGS_MPI="-fpic -shared"])

PKG_CHECK_MODULES([MPI_C],[mpi-c],[
	CFLAGS_MPI="$CFLAGS_MPI $MPI_C_CFLAGS"
	LDFLAGS_MPI="$LDFLAGS_MPI $MPI_C_LIBS"
],[
   	CFLAGS_MPI="$CFLAGS_MPI `$MPI_CC -showme:compile`"
	LDFLAGS_MPI="$LDFLAGS_MPI `$MPI_CC -showme:link`"
])

AC_SUBST([CFLAGS_MPI])
AC_SUBST([LDFLAGS_MPI])


## See if MPI_CC works for the primary target
##
AC_MSG_CHECKING([primary target for usable MPI2-compliant C compiler and mpi.h])
saved_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS_MPI $mflag_primary"
saved_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS_MPI $mflag_primary"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <mpi.h>
#include <stdio.h>
]], [[
  int ni, na, nd, comb;
  int r = MPI_Init(NULL,NULL);
  r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
  r |= MPI_Finalize();
  return r; 
]])], [
ac_have_mpi2_pri=yes
AC_MSG_RESULT([yes, $MPI_CC])
], [
ac_have_mpi2_pri=no
AC_MSG_RESULT([no])
])
CFLAGS=$saved_CFLAGS
LDFLAGS="$saved_LDFLAGS"
AM_CONDITIONAL(BUILD_MPIWRAP_PRI, test x$ac_have_mpi2_pri = xyes)

## See if MPI_CC works for the secondary target.  Complication: what if
## there is no secondary target?  We need this to then fail.
## Kludge this by making CFLAGS something which will surely fail in
## such a case.
##
AC_MSG_CHECKING([secondary target for usable MPI2-compliant C compiler and mpi.h])
saved_CFLAGS=$CFLAGS
saved_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS_MPI $mflag_secondary"
CFLAGS="$CFLAGS_MPI $mflag_secondary"
if test x$VGCONF_PLATFORM_SEC_CAPS = x ; then
  CFLAGS="this will surely fail"
fi
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <mpi.h>
#include <stdio.h>
]], [[
  int ni, na, nd, comb;
  int r = MPI_Init(NULL,NULL);
  r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
  r |= MPI_Finalize();
  return r; 
]])], [
ac_have_mpi2_sec=yes
AC_MSG_RESULT([yes, $MPI_CC])
], [
ac_have_mpi2_sec=no
AC_MSG_RESULT([no])
])
CFLAGS=$saved_CFLAGS
LDFLAGS="$saved_LDFLAGS"
AM_CONDITIONAL(BUILD_MPIWRAP_SEC, test x$ac_have_mpi2_sec = xyes)


#----------------------------------------------------------------------------
# Other library checks
#----------------------------------------------------------------------------
# There now follow some tests for Boost, and OpenMP.  These
# tests are present because Drd has some regression tests that use
# these packages.  All regression test programs all compiled only
# for the primary target.  And so it is important that the configure
# checks that follow, use the correct -m32 or -m64 flag for the
# primary target (called $mflag_primary).  Otherwise, we can end up
# in a situation (eg) where, on amd64-linux, the test for Boost checks
# for usable 64-bit Boost facilities, but because we are doing a 32-bit
# only build (meaning, the primary target is x86-linux), the build
# of the regtest programs that use Boost fails, because they are 
# build as 32-bit (IN THIS EXAMPLE).
#
# Hence: ALWAYS USE $mflag_primary FOR CONFIGURE TESTS FOR FACILITIES
# NEEDED BY THE REGRESSION TEST PROGRAMS.


# Check whether the boost library 1.35 or later has been installed.
# The Boost.Threads library has undergone a major rewrite in version 1.35.0.

AC_MSG_CHECKING([for boost])

AC_LANG(C++)
safe_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$mflag_primary"
safe_LIBS="$LIBS"
LIBS="-lboost_thread-mt -lboost_system-mt $LIBS"

AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <boost/thread.hpp>
static void thread_func(void)
{ }
int main(int argc, char** argv)
{
  boost::thread t(thread_func);
  return 0;
}
])],
[
ac_have_boost_1_35=yes
AC_SUBST([BOOST_CFLAGS], [])
AC_SUBST([BOOST_LIBS], ["-lboost_thread-mt -lboost_system-mt"])
AC_MSG_RESULT([yes])
], [
ac_have_boost_1_35=no
AC_MSG_RESULT([no])
])

LIBS="$safe_LIBS"
CXXFLAGS=$safe_CXXFLAGS
AC_LANG(C)

AM_CONDITIONAL([HAVE_BOOST_1_35], [test x$ac_have_boost_1_35 = xyes])


# does this compiler support -fopenmp, does it have the include file
# <omp.h> and does it have libgomp ?

AC_MSG_CHECKING([for OpenMP])

safe_CFLAGS=$CFLAGS
CFLAGS="-fopenmp $mflag_primary -Werror"

AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <omp.h> 
int main(int argc, char** argv)
{
  omp_set_dynamic(0);
  return 0;
}
])],
[
ac_have_openmp=yes
AC_MSG_RESULT([yes])
], [
ac_have_openmp=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS

AM_CONDITIONAL([HAVE_OPENMP], [test x$ac_have_openmp = xyes])


# Check for __builtin_popcount
AC_MSG_CHECKING([for __builtin_popcount()])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __builtin_popcount(2);
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BUILTIN_POPCOUT], 1,
          [Define to 1 if compiler provides __builtin_popcount().])
], [
AC_MSG_RESULT([no])
])

# Check for __builtin_clz
AC_MSG_CHECKING([for __builtin_clz()])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __builtin_clz(2);
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BUILTIN_CLZ], 1,
          [Define to 1 if compiler provides __builtin_clz().])
], [
AC_MSG_RESULT([no])
])

# Check for __builtin_ctz
AC_MSG_CHECKING([for __builtin_ctz()])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
]], [[
  __builtin_ctz(2);
  return 0;
]])], [
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BUILTIN_CTZ], 1,
          [Define to 1 if compiler provides __builtin_ctz().])
], [
AC_MSG_RESULT([no])
])

# does this compiler have built-in functions for atomic memory access for the
# primary target ?
AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the primary target])

safe_CFLAGS=$CFLAGS
CFLAGS="$mflag_primary"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
  int variable = 1;
  return (__sync_bool_compare_and_swap(&variable, 1, 2)
          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
]])], [
  ac_have_builtin_atomic_primary=yes
  AC_MSG_RESULT([yes])
  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() and __sync_add_and_fetch() for the primary target])
], [
  ac_have_builtin_atomic_primary=no
  AC_MSG_RESULT([no])
])

CFLAGS=$safe_CFLAGS

AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC],
               [test x$ac_have_builtin_atomic_primary = xyes])


# does this compiler have built-in functions for atomic memory access for the
# secondary target ?

if test x$VGCONF_PLATFORM_SEC_CAPS != x; then

AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the secondary target])

safe_CFLAGS=$CFLAGS
CFLAGS="$mflag_secondary"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
  int variable = 1;
  return (__sync_add_and_fetch(&variable, 1) ? 1 : 0)
]])], [
  ac_have_builtin_atomic_secondary=yes
  AC_MSG_RESULT([yes])
], [
  ac_have_builtin_atomic_secondary=no
  AC_MSG_RESULT([no])
])

CFLAGS=$safe_CFLAGS

fi

AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_SECONDARY],
               [test x$ac_have_builtin_atomic_secondary = xyes])

# does this compiler have built-in functions for atomic memory access on
# 64-bit integers for all targets ?

AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch on uint64_t for all targets])

AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  #include <stdint.h>
]], [[
  uint64_t variable = 1;
  return __sync_add_and_fetch(&variable, 1)
]])], [
  ac_have_builtin_atomic64_primary=yes
], [
  ac_have_builtin_atomic64_primary=no
])

if test x$VGCONF_PLATFORM_SEC_CAPS != x; then

safe_CFLAGS=$CFLAGS
CFLAGS="$mflag_secondary"

AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  #include <stdint.h>
]], [[
  uint64_t variable = 1;
  return __sync_add_and_fetch(&variable, 1)
]])], [
  ac_have_builtin_atomic64_secondary=yes
], [
  ac_have_builtin_atomic64_secondary=no
])

CFLAGS=$safe_CFLAGS

fi

if test x$ac_have_builtin_atomic64_primary = xyes && \
   test x$VGCONF_PLATFORM_SEC_CAPS = x \
     -o x$ac_have_builtin_atomic64_secondary = xyes; then
  AC_MSG_RESULT([yes])
  ac_have_builtin_atomic64=yes
else
  AC_MSG_RESULT([no])
  ac_have_builtin_atomic64=no
fi

AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC64],
               [test x$ac_have_builtin_atomic64 = xyes])


# does g++ have built-in functions for atomic memory access ?
AC_MSG_CHECKING([if g++ supports __sync_add_and_fetch])

safe_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$mflag_primary"

AC_LANG_PUSH(C++)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
  int variable = 1;
  return (__sync_bool_compare_and_swap(&variable, 1, 2)
          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
]])], [
  ac_have_builtin_atomic_cxx=yes
  AC_MSG_RESULT([yes])
  AC_DEFINE(HAVE_BUILTIN_ATOMIC_CXX, 1, [Define to 1 if g++ supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
], [
  ac_have_builtin_atomic_cxx=no
  AC_MSG_RESULT([no])
])
AC_LANG_POP(C++)

CXXFLAGS=$safe_CXXFLAGS

AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_CXX], [test x$ac_have_builtin_atomic_cxx = xyes])


if test x$ac_have_usable_linux_futex_h = xyes \
        -a x$ac_have_builtin_atomic_primary = xyes; then
  ac_enable_linux_ticket_lock_primary=yes
fi
AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_PRIMARY],
               [test x$ac_enable_linux_ticket_lock_primary = xyes])

if test x$VGCONF_PLATFORM_SEC_CAPS != x \
        -a x$ac_have_usable_linux_futex_h = xyes \
        -a x$ac_have_builtin_atomic_secondary = xyes; then
  ac_enable_linux_ticket_lock_secondary=yes
fi
AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_SECONDARY],
               [test x$ac_enable_linux_ticket_lock_secondary = xyes])


# does libstdc++ support annotating shared pointers ?
AC_MSG_CHECKING([if libstdc++ supports annotating shared pointers])

safe_CXXFLAGS=$CXXFLAGS
CXXFLAGS="-std=c++0x"

AC_LANG_PUSH(C++)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  #include <memory>
]], [[
  std::shared_ptr<int> p
]])], [
  ac_have_shared_ptr=yes
], [
  ac_have_shared_ptr=no
])
if test x$ac_have_shared_ptr = xyes; then
  # If compilation of the program below fails because of a syntax error
  # triggered by substituting one of the annotation macros then that
  # means that libstdc++ supports these macros.
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(a) (a)----
    #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(a) (a)----
    #include <memory>
  ]], [[
    std::shared_ptr<int> p
  ]])], [
    ac_have_shared_pointer_annotation=no
    AC_MSG_RESULT([no])
  ], [
    ac_have_shared_pointer_annotation=yes
    AC_MSG_RESULT([yes])
    AC_DEFINE(HAVE_SHARED_POINTER_ANNOTATION, 1,
              [Define to 1 if libstd++ supports annotating shared pointers])
  ])
else
  ac_have_shared_pointer_annotation=no
  AC_MSG_RESULT([no])
fi
AC_LANG_POP(C++)

CXXFLAGS=$safe_CXXFLAGS

AM_CONDITIONAL([HAVE_SHARED_POINTER_ANNOTATION],
               [test x$ac_have_shared_pointer_annotation = xyes])


#----------------------------------------------------------------------------
# Ok.  We're done checking.
#----------------------------------------------------------------------------

# Nb: VEX/Makefile is generated from Makefile.vex.in.
AC_CONFIG_FILES([
   Makefile 
   VEX/Makefile:Makefile.vex.in
   valgrind.spec
   valgrind.pc
   glibc-2.X.supp
   docs/Makefile 
   tests/Makefile 
   tests/vg_regtest 
   perf/Makefile 
   perf/vg_perf
   gdbserver_tests/Makefile
   gdbserver_tests/solaris/Makefile
   include/Makefile 
   auxprogs/Makefile
   mpi/Makefile
   coregrind/Makefile 
   memcheck/Makefile
   memcheck/tests/Makefile
   memcheck/tests/common/Makefile
   memcheck/tests/amd64/Makefile
   memcheck/tests/x86/Makefile
   memcheck/tests/linux/Makefile
   memcheck/tests/darwin/Makefile
   memcheck/tests/solaris/Makefile
   memcheck/tests/amd64-linux/Makefile
   memcheck/tests/arm64-linux/Makefile
   memcheck/tests/x86-linux/Makefile
   memcheck/tests/amd64-solaris/Makefile
   memcheck/tests/x86-solaris/Makefile
   memcheck/tests/ppc32/Makefile
   memcheck/tests/ppc64/Makefile
   memcheck/tests/s390x/Makefile
   memcheck/tests/mips32/Makefile
   memcheck/tests/mips64/Makefile
   memcheck/tests/vbit-test/Makefile
   cachegrind/Makefile
   cachegrind/tests/Makefile
   cachegrind/tests/x86/Makefile
   cachegrind/cg_annotate
   cachegrind/cg_diff
   callgrind/Makefile
   callgrind/callgrind_annotate
   callgrind/callgrind_control
   callgrind/tests/Makefile
   helgrind/Makefile
   helgrind/tests/Makefile
   massif/Makefile
   massif/tests/Makefile
   massif/ms_print
   lackey/Makefile
   lackey/tests/Makefile
   none/Makefile
   none/tests/Makefile
   none/tests/scripts/Makefile
   none/tests/amd64/Makefile
   none/tests/ppc32/Makefile
   none/tests/ppc64/Makefile
   none/tests/x86/Makefile
   none/tests/arm/Makefile
   none/tests/arm64/Makefile
   none/tests/s390x/Makefile
   none/tests/mips32/Makefile
   none/tests/mips64/Makefile
   none/tests/linux/Makefile
   none/tests/darwin/Makefile
   none/tests/solaris/Makefile
   none/tests/amd64-linux/Makefile
   none/tests/x86-linux/Makefile
   none/tests/amd64-darwin/Makefile
   none/tests/x86-darwin/Makefile
   none/tests/amd64-solaris/Makefile
   none/tests/x86-solaris/Makefile
   exp-sgcheck/Makefile
   exp-sgcheck/tests/Makefile
   drd/Makefile
   drd/scripts/download-and-build-splash2
   drd/tests/Makefile
   exp-bbv/Makefile
   exp-bbv/tests/Makefile
   exp-bbv/tests/x86/Makefile
   exp-bbv/tests/x86-linux/Makefile
   exp-bbv/tests/amd64-linux/Makefile
   exp-bbv/tests/ppc32-linux/Makefile
   exp-bbv/tests/arm-linux/Makefile
   exp-dhat/Makefile
   exp-dhat/tests/Makefile
   shared/Makefile
   solaris/Makefile
])
AC_CONFIG_FILES([coregrind/link_tool_exe_linux],
                [chmod +x coregrind/link_tool_exe_linux])
AC_CONFIG_FILES([coregrind/link_tool_exe_darwin],
                [chmod +x coregrind/link_tool_exe_darwin])
AC_CONFIG_FILES([coregrind/link_tool_exe_solaris],
                [chmod +x coregrind/link_tool_exe_solaris])
AC_OUTPUT

cat<<EOF

         Maximum build arch: ${ARCH_MAX}
         Primary build arch: ${VGCONF_ARCH_PRI}
       Secondary build arch: ${VGCONF_ARCH_SEC}
                   Build OS: ${VGCONF_OS}
     Link Time Optimisation: ${vg_cv_lto}
       Primary build target: ${VGCONF_PLATFORM_PRI_CAPS}
     Secondary build target: ${VGCONF_PLATFORM_SEC_CAPS}
           Platform variant: ${VGCONF_PLATVARIANT}
      Primary -DVGPV string: -DVGPV_${VGCONF_ARCH_PRI}_${VGCONF_OS}_${VGCONF_PLATVARIANT}=1
         Default supp files: ${DEFAULT_SUPP}

EOF