File: configure.ac

package info (click to toggle)
pcp 4.3.2+really4.3.1-0.1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 175,188 kB
  • sloc: ansic: 261,305; sh: 123,606; xml: 107,279; cpp: 72,127; perl: 18,283; python: 15,453; yacc: 8,249; lex: 2,585; makefile: 1,957; fortran: 60; java: 52
file content (3802 lines) | stat: -rw-r--r-- 111,238 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
dnl
dnl Copyright (c) 2012-2018 Red Hat.
dnl Copyright (c) 2008 Aconex.  All Rights Reserved.
dnl Copyright (c) 2000-2004,2008 Silicon Graphics, Inc.  All Rights Reserved.
dnl
dnl This program is free software; you can redistribute it and/or modify it
dnl under the terms of the GNU General Public License as published by the
dnl Free Software Foundation; either version 2 of the License, or (at your
dnl option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dnl for more details.
dnl

dnl unpacking check - this file must exist
AC_INIT(src/include/pcp/pmapi.h)

dnl need 2.63 for AS_VAR_IF and AS_VAR_COPY
AC_PREREQ([2.63])dnl

dnl Irix build issue ... use the tools from the local filesystems
unset ROOT TOOLROOT

AC_ARG_WITH([64bit],
    [AS_HELP_STRING([--with-64bit],
		    [turn on 64 bit compilation mode (default is platform dependent)])],
    [use_64bit=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-64bit=$withval"])

AC_ARG_WITH([optimization],
    [AS_HELP_STRING([--with-optimization],
		    [enable optimization for C/C++ code (default is yes)])],
    [use_optimization=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-optimization=$withval"],
    [use_optimizaton=yes])

AC_ARG_WITH([threads],
    [AC_HELP_STRING([--with-threads],
		    [enable support for multiple threads (default is on)])],
    [do_threads=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-threads=$withval"],
    [do_threads=check])

AC_ARG_WITH([secure-sockets],
    [AC_HELP_STRING([--with-secure-sockets],
		    [enable support for secure sockets (default is on)])],
    [do_secure=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-secure-sockets=$withval"],
    [do_secure=check])

AC_ARG_WITH([static-probes],
    [AC_HELP_STRING([--with-static-probes],
		    [enable support for static probes (default is on)])],
    [do_probes=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-static-probes=$withval"],
    [do_probes=check])

AC_ARG_WITH([infiniband],
    [AC_HELP_STRING([--with-infiniband],
		    [enable support for Infiniband metrics (default is on)])],
    [do_infiniband=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-infiniband=$withval"],
    [do_infiniband=check])

AC_ARG_WITH([user],
    [AS_HELP_STRING([--with-user],
		    [user account under which daemons run (default is pcp)])],
    [pcp_user=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-user-account=$withval"],
    [pcp_user=pcp])
AC_SUBST(pcp_user)

AC_ARG_WITH([group],
    [AS_HELP_STRING([--with-group],
		    [user group under which daemons run (default is pcp)])],
    [pcp_group=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-group-account=$withval"],
    [pcp_group=pcp])
AC_SUBST(pcp_group)

AC_ARG_WITH([discovery],
    [AC_HELP_STRING([--with-discovery],
                    [enable support for service discovery (default is on)])],
    [do_discovery=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-discovery=$withval"],
    [do_discovery=check])

AC_ARG_WITH([systemd],
    [AC_HELP_STRING([--with-systemd],
                    [enable support for systemd services (default is on)])],
    [do_systemd=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-systemd=$withval"],
    [do_systemd=check])

AC_ARG_WITH([qt],
    [AC_HELP_STRING([--with-qt],
                    [enable support for tools requiring Qt (default is on)])],
    [do_qt=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-qt=$withval"],
    [do_qt=check])

AC_ARG_WITH([qt3d],
    [AC_HELP_STRING([--with-qt3d],
                    [enable support for 3D scene graph API (default is on)])],
    [do_qt3d=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-qt3d=$withval"],
    [do_qt3d=check])

AC_ARG_WITH([perl],
    [AC_HELP_STRING([--with-perl],
                    [enable support for tools requiring Perl (default is on)])],
    [do_perl=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-perl=$withval"],
    [do_perl=check])

AC_ARG_WITH([python],
    [AC_HELP_STRING([--with-python],
                    [enable support for tools requiring Python (default is on)])],
    [do_python=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-python=$withval"],
    [do_python=check])

AC_ARG_WITH([python3],
    [AC_HELP_STRING([--with-python3],
                    [enable support for tools requiring Python3 (default is on)])],
    [do_python3=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-python3=$withval"],
    [do_python3=check])

AC_ARG_WITH([dstat-symlink],
    [AC_HELP_STRING([--with-dstat-symlink],
		    [enable support for /usr/bin/dstat symlink (default is on)])],
    [do_dstat_symlink=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-dstat-symlink=$withval"],
    [do_dstat_symlink=check])

AC_ARG_WITH([books],
    [AC_HELP_STRING([--with-books],
                    [enable building of the PCP books (default is off)])],
    [do_books=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-books=$withval"],
    [do_books=no])

AC_ARG_WITH([books-brand],
    [AC_HELP_STRING([--with-books-brand=BRAND],
                    [choose the docbook brand when building the PCP books (default is common)])],
    [do_books_brand=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-books-brand=$withval"],
    [do_books_brand=common])

AC_ARG_WITH([papi],
    [AC_HELP_STRING([--with-papi@<:@=DIR|=MODULE@:>@],
		   [enable performance api counter pmda (default is on)
		   The optional argument may be a full path of a PAPI installation prefix,
		   or a pkgconfig module name.])],
    [do_papi=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-papi=$withval"],
    [do_papi=check])

AC_ARG_WITH([perfevent],
    [AC_HELP_STRING([--with-perfevent],
		   [enable perfevent pmda (default is on)])],
    [do_perfevent=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-perfevent=$withval"],
    [do_perfevent=check])

AC_ARG_WITH([pmdapodman],
    [AC_HELP_STRING([--with-pmdapodman],
		   [enable podman pmda (default is on)])],
    [do_pmdapodman=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-pmdapodman=$withval"],
    [do_pmdapodman=check])

AC_ARG_WITH([pmdabcc],
    [AC_HELP_STRING([--with-pmdabcc],
		   [enable BCC pmda (default is on)])],
    [do_pmdabcc=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-pmdabcc=$withval"],
    [do_pmdabcc=check])

AC_ARG_WITH([pmdajson],
    [AC_HELP_STRING([--with-pmdajson],
		   [enable JSON pmda (default is on)])],
    [do_pmdajson=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-pmdajson=$withval"],
    [do_pmdajson=check])

AC_ARG_WITH([pmdanutcracker],
    [AC_HELP_STRING([--with-pmdanutcracker],
		   [enable nutcracker pmda (default is on)])],
    [do_pmdanutcracker=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-pmdanutcracker=$withval"],
    [do_pmdanutcracker=check])

AC_ARG_WITH([pmdasnmp],
    [AC_HELP_STRING([--with-pmdasnmp],
		   [enable SNMP pmda (default is on)])],
    [do_pmdasnmp=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-pmdasnmp=$withval"],
    [do_pmdasnmp=check])

AC_ARG_WITH([manager],
    [AC_HELP_STRING([--with-manager],
		   [enable daemon manager (default is on)])],
    [do_manager=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-manager=$withval"],
    [do_manager=check])

AC_ARG_WITH([webapi],
    [AC_HELP_STRING([--with-webapi],
		   [enable REST API daemon (default is on)])],
    [do_webapi=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-webapi=$withval"],
    [do_webapi=check])

AC_ARG_WITH([webapps],
    [AC_HELP_STRING([--with-webapps],
                    [enable building of webapp packages (default is off)])],
    [do_webapps=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-webapps=$withval"],
    [do_webapps=no])

AC_ARG_WITH([selinux],
    [AC_HELP_STRING([--with-selinux],
                    [enable building of selinux package (default is on)])],
    [do_selinux=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-selinux=$withval"],
    [do_selinux=check])
dnl things set in the environment by Makepkgs never make it into an RPM
dnl build where the environment is stripped ... use a --with-foo=path
dnl construct to workaround this

AC_ARG_WITH([make],
    [AC_HELP_STRING([--with-make],
                    [path to GNU compatible make(1) (default is empty for auto discovery)])],
    [MAKE=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-make=$withval"],
    [MAKE=''])

AC_ARG_WITH([tar],
    [AC_HELP_STRING([--with-tar],
                    [path to GNU compatible tar(1) (default is empty for auto discovery)])],
    [TAR=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-tar=$withval"],
    [TAR=''])

AC_ARG_WITH([zip],
    [AC_HELP_STRING([--with-zip],
                    [path to GNU compatible zip(1) (default is empty for auto discovery)])],
    [ZIP=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-zip=$withval"],
    [ZIP=''])

AC_ARG_WITH(
    [transparent-decompression],
    [AC_HELP_STRING([--with-transparent-decompression],
		    [enable support for transparent decompression of archives (default is on)])],
    [do_decompression=$withval; PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --with-transparent-decompression=$withval"],
    [do_decompression=check])


dnl
dnl Note: the following environment variables may be set to override defaults:
dnl MAKE CC CPP LD LEX YACC INSTALL AWK SED ECHO
dnl

dnl Guess target platfrom
AC_CANONICAL_SYSTEM
if test -z "$target"
then
    echo '
FATAL ERROR: Cannot guess your target, try explicit specification
             using --target or mailto: pcp@groups.io to ask.'
    rm -rf conftest conftest.*
    exit 1
else
    dnl Remove 4th name component, if present, from target, target_os,
    dnl  build and build_os. Squash all x86 cpus into one LCD form - i386
    target=`echo $target | sed '[s/^\([^-][^-]*-[^-][^-]*-[^-][^-]*\)-.*$/\1/]'`
    target_os=`echo $target_os | sed '[s/solaris2\..*/solaris/]'`
    target_os=`echo $target_os | sed '[s/^\([^-][^-]*\)-.*$/\1/]' | sed '[s/[\.0-9]*//g]'`

    build=`echo $build | sed '[s/^\([^-][^-]*-[^-][^-]*-[^-][^-]*\)-.*$/\1/]'`
    build_os=`echo $build_os | sed '[s/solaris2\..*/solaris/]'`
    build_os=`echo $build_os | sed '[s/^\([^-][^-]*\)-.*$/\1/]'`
fi

echo Building on $build for $target
echo "Build: os=$build_os cpu=$build_cpu"
echo "Target: os=$target_os cpu=$target_cpu"

if test "$cross_compiling" = "yes"; then
    if test -f ./config.$target_os; then
	. ./config.$target_os
    else
	echo
	echo "
FATAL ERROR: Cannot perform cross-compilation without a file to source
             configuration information from (config.$target_os is missing)"
	rm -rf conftest conftest.*
	exit 1
    fi
fi
AC_SUBST(cross_compiling)

dnl CFLAGS setting is a co-dependency between here and PCFLAGS in
dnl src/include/builddefs.in ... need to be the same in both places

target_distro=$target_os
if test $target_os = linux
then
    AC_DEFINE(IS_LINUX, [1], [Platform is Linux])
    test -f /etc/SuSE-release && target_distro=suse
    grep -q 'ID_LIKE="suse"' /etc/os-release 2> /dev/null && target_distro=suse
    test -f /etc/fedora-release && target_distro=fedora
    test -f /etc/redhat-release && target_distro=redhat
    test -f /etc/debian_version && target_distro=debian
    test -f /etc/slackware-version && target_distro=slackware
    test -f /etc/gentoo-release && target_distro=gentoo
    test -f /etc/mandriva-release && target_distro=mandriva
    test -f /etc/arch-release && target_distro=arch
    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
    pcp_platform_paths='/usr/bin/X11:/usr/local/bin'
    pcp_ps_all_flags=-efw
elif test $target_os = darwin
then
    AC_DEFINE(IS_DARWIN, [1], [Platform is Darwin (Mac OS X)])
    target_distro=macosx
    version=`sw_vers -productVersion`
    CFLAGS="-fPIC -no-cpp-precomp -fno-strict-aliasing"
    case "$version"
    in
	10.[0-5].*)
	    dnl no knowledge before this ...
	    ;;
	10.[6-9].*|10.1[0-3].*)
	    target_distro=cocoa
	    CFLAGS="$CFLAGS -arch i386 -arch x86_64"
	    ;;
	*)
	    dnl at least 10.14 (Mojave) ...
	    target_distro=cocoa
	    CFLAGS="$CFLAGS -arch x86_64"
	    ;;
    esac
    export CFLAGS
    pcp_platform_paths='/usr/local/bin'
    pcp_ps_all_flags="-axw -o user,pid,ppid,cpu,stime,tty,time,command"
elif test $target_os = mingw
then
    AC_DEFINE(IS_MINGW, [1], [Platform is MinGW (Windows)])
    CFLAGS="-fno-strict-aliasing"
    pcp_platform_paths=''
    pcp_ps_all_flags=-efW
elif test $target_os = solaris
then
    AC_DEFINE(IS_SOLARIS, [1], [Platform is Solaris])
    export CFLAGS_IF_GCC="-fPIC -fno-strict-aliasing -D_XPG4_2 -D__EXTENSIONS__"
    export CFLAGS_IF_SUNCC="-fPIC -xalias_level=any -D_XPG4_2 -D__EXTENSIONS__"
    pcp_platform_paths='/usr/bin/X11:/usr/local/bin:/opt/sfw/bin:/opt/csw/bin'
    pcp_ps_all_flags=-ef
elif test $target_os = aix
then
    AC_DEFINE(IS_AIX, [1], [Platform is AIX])
    export CFLAGS="-qcpluscmt"
    pcp_platform_paths='/usr/bin/X11:/usr/local/bin'
    pcp_ps_all_flags=-ef
elif test $target_os = freebsd || test $target_os = kfreebsd
then
    AC_DEFINE(IS_FREEBSD, [1], [Platform is FreeBSD])
    test -f /etc/debian_version && target_distro=debian
    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
    if test $target_os = kfreebsd
    then
	pcp_ps_all_flags=-efw
    else
	pcp_ps_all_flags=auxww
    fi
    pcp_platform_paths='/usr/bin/X11'
    test -d /usr/local/bin && pcp_platform_paths="$pcp_platform_paths:/usr/local/bin"
    test -d /usr/bsd && pcp_platform_paths="$pcp_platform_paths:/usr/bsd"
elif test $target_os = gnu
then
    AC_DEFINE(IS_GNU, [1], [Platform is GNU Hurd])
    test -f /etc/debian_version && target_distro=debian
    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
    pcp_platform_paths='/usr/bin/X11:/usr/local/bin'
    pcp_ps_all_flags=-efw
elif test $target_os = netbsdelf -o $target_os = netbsd
then
    target_os=netbsd
    AC_DEFINE(IS_NETBSD, [1], [Platform is NetBSD])
    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE -D_NETBSD_SOURCE"
    pcp_platform_paths='/usr/pkg/bin'
    pcp_ps_all_flags=auxww
elif test $target_os = openbsd
then
    target_os=openbsd
    AC_DEFINE(IS_OPENBSD, [1], [Platform is OpenBSD])
    export CFLAGS="-fPIC -fno-strict-aliasing -D_GNU_SOURCE"
    pcp_platform_paths='/usr/local/bin'
    pcp_ps_all_flags=auxww
else
    echo
    echo "FATAL ERROR: need platform-specific customization for \"$target_os\""
    rm -rf conftest conftest.*
    exit 1
fi
AC_SUBST(pcp_platform_paths)
AC_SUBST(pcp_ps_all_flags)

dnl default C and C++ compiler optimization to -O2 -g
if test "$use_optimization" = no
then
    optimization="-O0 -g"
else
    optimization="-O2 -g"
fi
AC_SUBST(optimization)

PKG_PROG_PKG_CONFIG
if test -z "$PKG_CONFIG"; then
    AC_MSG_ERROR([cannot find a 'pkg-config' command])
fi

dnl check if user wants their own C compiler
cflags_abi=
AC_PROG_CC(suncc egcc gcc cc clang)
if test $target_os = solaris
then
    AC_PATH_PROG(CCPATH,$CC,$CC)
    cc=$CCPATH
    if test "$GCC" = "yes"
    then
	CFLAGS="$CFLAGS $CFLAGS_IF_GCC"
    else
	CFLAGS="$CFLAGS $CFLAGS_IF_SUNCC"
    fi
    if test "$use_64bit" = "no"
    then
	:
    else
	AC_MSG_CHECKING([for 64 bit Solaris host])
	case `isainfo -k`
	in
	    amd64|sparcv9)
		cflags_abi=-m64
		CFLAGS="$CFLAGS -m64"
		LDFLAGS="$LDFLAGS -m64"
		AC_MSG_RESULT(yes)
		;;
	    *)
		AC_MSG_RESULT(no)
		;;
	esac
    fi
else
    cc=$CC
fi
AC_SUBST(cc)
cc_is_gcc=$GCC
AC_SUBST(cc_is_gcc)
AC_SUBST(cflags_abi)
dnl these become CFLAGS and LDFLAGS for the build
PCFLAGS="$CFLAGS"
PLDFLAGS=$LDFLAGS

if echo "$CFLAGS" | grep 'D_FORTIFY_SOURCE' >/dev/null
then
    dnl for cc use locally in configure (not exported via $PCFLAGS),
    dnl add -O in case -D_FORTIFY_SOURCE has been added to CFLAGS above,
    dnl as -D_FORTIFY_SOURCE requires -O but we've separated optimization
    dnl flags out into $CFLAGS_OPT for our build infrastructure
    CFLAGS="-O $PCFLAGS"
fi

dnl some versions of gcc (e.g. version 4.8.4 on Gentoo Hardened) have added
dnl a predefined for _FORTIFY_SOURCE but only when -O is specified ... so
dnl to be safe we have -U_FORTIFY_SOURCE before -D_FORTIFY_SOURCE=2 below

dnl Add some security-related gcc flags
if echo "$CFLAGS" | grep stack-protector >/dev/null
then
    dnl already set, probably from the environment
    :
else
    AC_ARG_ENABLE([ssp],
    [AS_HELP_STRING([--disable-ssp], [disable gcc stack-protector])])
    AS_IF([test "x$cc_is_gcc" = xyes -a "x$enable_ssp" != xno -a "x$use_optimization" = xyes ],[
       save_CFLAGS="$CFLAGS"
       CFLAGS="$CFLAGS -O -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
       AC_COMPILE_IFELSE([AC_LANG_SOURCE([int something ();])], [
	   AC_MSG_NOTICE([Compiling with gcc -fstack-protector-all et al.])
	   PCFLAGS="$PCFLAGS -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"],[
	   AC_MSG_NOTICE([Compiler does not support -fstack-protector-all et al.])
	   CFLAGS="$save_CFLAGS"
       ])
    ])
fi
AC_SUBST(PCFLAGS)
AC_SUBST(PLDFLAGS)

dnl Check for even more security-related gcc/linker flags, useful for daemons
AC_ARG_ENABLE([pie],
  [AS_HELP_STRING([--disable-pie], [disable position-independent-executable])])
AS_IF([test "x$cc_is_gcc" = xyes -a "x$enable_pie" != xno],[
   PIECFLAGS='-fPIE'
   PIELDFLAGS='-pie -Wl,-z,relro -Wl,-z,now'
   save_CFLAGS="$CFLAGS"
   save_LDFLAGS="$LDFLAGS"
   CFLAGS="$CFLAGS $PIECFLAGS"
   LDFLAGS="$LDFLAGS $PIELDFLAGS"
   AC_LINK_IFELSE([AC_LANG_SOURCE([void main () {}])], [
       AC_MSG_NOTICE([Compiling with gcc pie et al.])
   ], [
       AC_MSG_NOTICE([Compiler does not support -pie et al.])
       PIECFLAGS=""
       PIELDFLAGS=""
   ])
   CFLAGS="$save_CFLAGS"
   LDFLAGS="$save_LDFLAGS"
])
AC_SUBST(PIELDFLAGS)
AC_SUBST(PIECFLAGS)

dnl Check for support for symbol hiding via gcc flags
AC_ARG_ENABLE([visibility],
  [AS_HELP_STRING([--disable-visibility], [disable gcc symbol visibility])])
AS_IF([test "x$cc_is_gcc" = xyes -a "$enable_visibility" != no],[
   INVISIBILITY="-fvisibility=hidden"
   save_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -c $INVISIBILITY"
   AC_COMPILE_IFELSE([AC_LANG_SOURCE([int visible () { return 0; }])], [
       AC_MSG_NOTICE([Compiling DSO PMDAs with gcc -fvisibility=hidden])
   ], [
       AC_MSG_NOTICE([Compiler does not support -fvisibility.])
       INVISIBILITY=""
   ])
   CFLAGS="$save_CFLAGS"
])
AC_SUBST(INVISIBILITY)

AC_PROG_CXX(eg++ g++ c++ clang++)
cxx=$CXX
AC_SUBST(cxx)
AC_MSG_CHECKING([for working C++ compiler])
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(
   [AC_LANG_PROGRAM([[#include <cstdio>]],
                    [[const char gday[] = "G'day, world\n";]])],
   [AC_MSG_RESULT([yes])],
   [AC_MSG_RESULT([no])
    cxx=""])
AC_LANG_POP([C++])

dnl Prevent shared libraries from being built for libpcp and other core libraries
AC_ARG_ENABLE([shared],
  [AS_HELP_STRING([--disable-shared], [disable core shared libary generation])],
  [PACKAGE_CONFIGURE="$PACKAGE_CONFIGURE --disable-shared=$withval"],
  [enable_shared=false])
AC_SUBST(enable_shared)

dnl check if user wants to use any of their own commands;
dnl ordering is important: some tests use earlier results

test -z "$AWK" && AC_PATH_PROGS(AWK, gawk awk, /usr/bin/awk)
case "$AWK"
in
    gawk|*/gawk)
	awk="$AWK --posix"
	;;
    *)
	awk=$AWK
	;;
esac
AC_SUBST(awk)

if test -z "$SED"; then
    AC_PATH_PROG(SED, sed, /bin/sed)
fi
if test ! -x "$SED"; then
    AC_MSG_ERROR([cannot find a valid 'sed' command.])
fi
sed=$SED
AC_SUBST(sed)

if test -z "$ECHO"; then
    AC_PATH_PROG(ECHO, echo, /bin/echo)
fi
if test ! -x "$ECHO"; then
    AC_MSG_ERROR([cannot find a valid 'echo' command.])
fi
echo=$ECHO
AC_SUBST(echo)

if test -z "$FIND"; then
    AC_PATH_PROG(FIND, find, /usr/bin/find)
fi
if test ! -x "$FIND"; then
    AC_MSG_ERROR([cannot find a valid 'find' command.])
fi
find=$FIND
AC_SUBST(find)

if test -z "$WHICH"; then
    AC_PATH_PROG(WHICH, which, /usr/bin/which)
fi
if test ! -x "$WHICH"; then
    AC_MSG_ERROR([cannot find a valid 'which' command.])
fi
which=$WHICH
AC_SUBST(which)

AC_PROG_LEX
lex=`$echo $LEX | awk '{print $1}'`
lex=`$which "$lex"`
if test ! -x "$lex"; then
    AC_MSG_ERROR([cannot find a valid 'lex'/'flex' command.])
fi
lex=$LEX
AC_SUBST(lex)

AC_PROG_YACC
yacc=`$echo $YACC | awk '{print $1}'`
yacc=`$which "$yacc"`
if test ! -x "$yacc"; then
    AC_MSG_ERROR([cannot find a valid 'yacc'/'bison' command.])
fi
yacc=$YACC
AC_SUBST(yacc)

dnl check we don't get the Windows sort ...
AC_MSG_CHECKING([where unix-like sort(1) lives])
if test $target_os = mingw; then
    for d in /bin /usr/bin /mingw/bin /mingw/usr/bin
    do
	if test -x $d/sort; then
	    sort=$d/sort
	    break
	fi
    done
else
    sort=`$which sort`
fi
AC_MSG_RESULT($sort)
$sort -n </dev/null
if test $? != 0
then
    echo
    echo "FATAL ERROR: $sort -n failed!"
    rm -rf conftest conftest.*
    exit 1
fi
AC_SUBST(sort)

dnl echo_n set to -n if echo understands -n to suppress newline
dnl echo_c set to \c if echo understands \c to suppress newline
AC_MSG_CHECKING([if echo uses -n or backslash-c to suppress newlines])
if ( $echo "testing\c"; $echo 1,2,3 ) | grep c >/dev/null
then
  if ( $echo -n testing; $echo 1,2,3 ) | sed s/-n/xn/ | grep xn >/dev/null
  then
    echo_n= echo_c=
    AC_MSG_RESULT([neither?])
  else
    echo_n=-n echo_c=
    AC_MSG_RESULT([ -n])
  fi
else
  echo_n= echo_c='\\c'
  AC_MSG_RESULT([backslash-c])
fi
AC_SUBST(echo_n)
AC_SUBST(echo_c)

dnl subsequent configure checks rely on $EGREP being set
AC_PROG_EGREP

dnl Check for static probes (dtrace, systemtap)
if test "$do_probes" = "check" -o "$do_probes" = "yes"
then
    enable_probes=true
    AC_CHECK_PROGS(DTRACE, dtrace, [])
    if test -z "$DTRACE"
    then
	if test "$do_probes" = "yes"
	then
	    AC_MSG_ERROR([cannot enable static probes - no dtrace executable])
	fi
	enable_probes=false
    fi
    AC_CHECK_HEADERS([sys/sdt.h], [
	if $enable_probes = true
	then
	    if test $target_os = kfreebsd
	    then
		enable_probes=false
	    elif test $target_os = freebsd
	    then
		dnl dtrace support in FreeBSD depends on configuration of kernel
		rm -f conftest.d conftest.h
		cat <<End-of-File >conftest.d
provider eek {
probe urk(int);
};
End-of-File
		if dtrace -s conftest.d -h >/dev/null 2>&1
		then
		    if test ! -f conftest.h
		    then
			enable_probes=false
			if test "$do_probes" = "yes"
			then
			    AC_MSG_ERROR([cannot enable static probes - no .h from dtrace -h])
			fi
		    fi
		else
		    enable_probes=false
		    if test "$do_probes" = "yes"
		    then
			AC_MSG_ERROR([cannot enable static probes - dtrace failed])
		    fi
		fi
	    fi
	fi
    ], [
	enable_probes=false
	if test "$do_probes" = "yes"
	then
	    AC_MSG_ERROR([cannot enable static probes - no SDT header])
	fi
    ])

    if test "$enable_probes" = "true"
    then
        AC_DEFINE(HAVE_STATIC_PROBES, [1], [Static probes (dtrace, systemtap)])
    fi
    AC_SUBST(enable_probes)
    AC_SUBST(DTRACE)
fi

dnl Check for service discovery mechanisms (DNS-SD, Avahi)
AS_IF([test "x$do_discovery" != "xno"], [
    # on Mac OS X, dns_sd.h

    # on Linux, aloha Avahi
    enable_avahi=true
    PKG_CHECK_MODULES([avahi], [avahi-client],
        [AC_CHECK_LIB(avahi-client, avahi_client_new,
    		      [lib_for_avahi="-lavahi-common -lavahi-client"],
                      [enable_avahi=false])
        ],[enable_avahi=false])
    AC_CHECK_HEADERS([avahi-client/publish.h],, [enable_avahi=false])
    AC_CHECK_HEADERS([avahi-common/alternative.h],, [enable_avahi=false])

    if test "$enable_avahi" = "true"
    then
	AC_SUBST(lib_for_avahi)
	AC_SUBST(avahi_CFLAGS)
	AC_DEFINE(HAVE_AVAHI, [1], [Service discovery via Avahi])
	enable_discovery=true
    fi

    if test "$do_discovery" != "check" -a "$enable_discovery" != "true"
    then
	AC_MSG_ERROR([cannot enable service discovery - no supported mechanisms])
    fi
    if test "$enable_discovery" = "true"
    then
	AC_DEFINE(HAVE_SERVICE_DISCOVERY, [1], [Service discovery mechanisms])
    fi
])
AC_SUBST(enable_discovery)
AC_SUBST(enable_avahi)

dnl Check for systemd services
enable_systemd=false
AS_IF([test "x$do_systemd" != "xno"], [
    enable_systemd=true

    PKG_CHECK_VAR([SYSTEMD_SYSTEMUNITDIR], [systemd], [systemdsystemunitdir],
	[pcp_systemdunit_dir=$SYSTEMD_SYSTEMUNITDIR], [enable_systemd=false])
    AC_SUBST(pcp_systemdunit_dir)
    if test -z "$pcp_systemdunit_dir"
    then
	if test "$do_systemd" = "yes"
	then
	    AC_MSG_ERROR([cannot enable systemd support - no systemunitdir path])
	fi
	enable_systemd=false
    fi
])
AC_SUBST(enable_systemd)

dnl NB: No AC_PREFIX_DEFAULT is needed, as the default configure invocation
dnl targets a build for non-system directories such as /usr/local.
dnl AC_PREFIX_DEFAULT([])

. ./VERSION.pcp
PACKAGE_VERSION=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
AC_SUBST(PACKAGE_VERSION)
AC_SUBST(PACKAGE_MAJOR)
AC_SUBST(PACKAGE_MINOR)
AC_SUBST(PACKAGE_REVISION)
AC_SUBST(PACKAGE_BUILD)

if test -z "$PACKAGE_BUILD_DATE" ; then
    PACKAGE_BUILD_DATE=`date +%Y-%m-%d`
fi
AC_SUBST(PACKAGE_BUILD_DATE)

if test -z "$PACKAGE_DISTRIBUTION" ; then
    PACKAGE_DISTRIBUTION=$target_distro
fi
AC_SUBST(PACKAGE_DISTRIBUTION)

dnl generate PM_VERSION_CURRENT for header
pm_version_current=`awk </dev/null "BEGIN { print (${PACKAGE_MAJOR}*256+${PACKAGE_MINOR})*256+${PACKAGE_REVISION} }"`
AC_SUBST(pm_version_current)

dnl output header files with cpp defs HAVE_*, etc
AC_CONFIG_HEADERS(src/include/pcp/config.h src/include/pcp/configsz.h)
AC_OUTPUT(src/include/pcp/platform_defs.h src/include/pcp/platformsz.h)

AC_CHECK_PROGS(GIT, git)
AC_SUBST(GIT)

AC_CHECK_PROGS(CPPCHECK, cppcheck, /bin/true)
AC_SUBST(CPPCHECK)

AC_CHECK_PROGS(PYLINT, pylint, /bin/true)
AC_SUBST(PYLINT)

dnl check if python available for the build and runtime
AC_CHECK_PROGS(PYTHON, [python python2.7])
AC_SUBST(PYTHON)

dnl check if python3 available for the build and runtime
AC_CHECK_PROGS(PYTHON3, [python3 python3.7 python3.6 python3.4])
AC_SUBST(PYTHON3)

dnl check if python tools/packages wanted (need python >= 2.6)
enable_python2=false
AS_IF([test "x$do_python" != "xno"], [
    enable_python2=true
    if test -z "$PYTHON"
    then
	enable_python2=false
    else
	AC_MSG_CHECKING([Python version])
	eval `$PYTHON -V 2>&1 | awk '/^Python/ { ver=2; print $ver }' | awk -F. '{ major=1; minor=2; point=3; printf "export PY_MAJOR=%d PY_MINOR=%d PY_POINT=%d\n",$major,$minor,$point }'`
	AC_MSG_RESULT([$PY_MAJOR.$PY_MINOR.$PY_POINT])
	if test "$PY_MAJOR" -lt 2; then
	    echo WARNING: Python version 2.6 or later does not seem to be installed.
	    enable_python2=false
	else
	    if test "$PY_MAJOR" -eq 2 -a "$PY_MINOR" -lt 6 ; then
		echo WARNING: Python version 2.$PY_MINOR is too old.
		echo Python version 2.6 or later is required for Python builds.
		enable_python2=false
	    else
		AC_CHECK_HEADERS([python${PY_MAJOR}.${PY_MINOR}/Python.h], [], [
		    echo WARNING: Python version $PY_MAJOR.$PY_MINOR header file may be missing.
		    echo Proceeding with the Python $PY_MAJOR installation found, regardless.
		])
	    fi
	fi
    fi

    if test "$do_python" != "check" -a "$enable_python2" != "true"
    then
	AC_MSG_ERROR([cannot enable Python - no supported version found])
    fi
])
AC_SUBST(enable_python2)

dnl check if python3 tools/packages wanted (need python >= 3.3)
enable_python3=false
AS_IF([test "x$do_python3" != "xno"], [
    enable_python3=true
    if test -z "$PYTHON3"
    then
	enable_python3=false
    else
	AC_MSG_CHECKING([Python3 version])
	eval `$PYTHON3 -V 2>&1 | awk '/^Python/ { ver=2; print $ver }' | awk -F. '{ major=1; minor=2; point=3; printf "export PY_MAJOR=%d PY_MINOR=%d PY_POINT=%d\n",$major,$minor,$point }'`
	AC_MSG_RESULT([$PY_MAJOR.$PY_MINOR.$PY_POINT])
	if test "$PY_MAJOR" -lt 3; then
	    echo WARNING: Python version 3.3 or later does not seem to be installed.
	    enable_python3=false
	else
	    if test "$PY_MAJOR" -eq 3 -a "$PY_MINOR" -lt 3 ; then
		echo WARNING: Python version 3.$PY_MINOR is too old.
		echo Python version 3.3 or later is required for Python builds.
		enable_python3=false
	    else
		AC_CHECK_HEADERS([python${PY_MAJOR}.${PY_MINOR}m/Python.h], [], [
		    echo WARNING: Python version $PY_MAJOR.$PY_MINOR header file may be missing.
		    echo Proceeding with the Python $PY_MAJOR installation found, regardless.
		])
	    fi
	fi
    fi

    if test "$do_python3" != "check" -a "$enable_python3" != "true"
    then
	AC_MSG_ERROR([cannot enable Python3 - no supported version found])
    fi
])
AC_SUBST(enable_python3)

dnl convenience macro to determine if either python is available
AC_MSG_CHECKING([for any python version])
if test "$cross_compiling" = "yes"; then
    ans=$have_python
    echo "cross-compile -> \"$ans\"" >&5
elif test "$enable_python2" = "true" -o "$enable_python3" = "true"
then
    have_python=true
else
    have_python=false
fi
AC_SUBST(have_python)
if $have_python; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl choose the prefered python executable (py2 -> py3 transtion)
if test "$enable_python3" = "true"
then
    pcp_python_prog=$PYTHON3
elif test "$enable_python2" = "true"
then
    pcp_python_prog=$PYTHON
else
    pcp_python_prog=""
fi
AC_SUBST(pcp_python_prog)

dnl Enable for support for the /usr/bin/dstat compatibility symlink
AC_MSG_CHECKING(for dstat symlink)
enable_dstat=false
if test "$do_dstat_symlink" = "check" -o "$do_dstat_symlink" = "yes"
then
    enable_dstat=true
    if test "$have_python" = "false"
    then
	AC_MSG_ERROR([cannot enable dstat symlink - no python found])
    fi
fi
AC_SUBST(enable_dstat)
if $enable_dstat; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl check availability of some Python modules
dnl usage PCP_CHECK_PYTHON_MODULE(module_name) or
dnl PCP_CHECK_PYTHON_MODULE(module_name, <import string>)
dnl default <import string> is "import module_name"
dnl
dnl sets $have_python_<module_name> as true or false
dnl
AC_DEFUN([PCP_CHECK_PYTHON_MODULE],
  [ AC_MSG_CHECKING(for Python module $1)
    if test -n "$2"
    then
	txt="$2"
    else
	txt="import $1"
    fi
    $pcp_python_prog -c 'import sys;
'"$txt" >>config.log 2>&1
    if test "$?" = 0
    then
	AC_MSG_RESULT(yes)
	eval have_python_$1=true
    else
	AC_MSG_RESULT(no)
	eval have_python_$1=false
    fi
  ])
PCP_CHECK_PYTHON_MODULE(BPF, [from bcc import BPF])
AC_SUBST(have_python_BPF)
PCP_CHECK_PYTHON_MODULE(OrderedDict, [from collections import OrderedDict])
AC_SUBST(have_python_OrderedDict)
PCP_CHECK_PYTHON_MODULE(jsonpointer)
AC_SUBST(have_python_jsonpointer)
PCP_CHECK_PYTHON_MODULE(openpyxl)
AC_SUBST(have_python_openpyxl)
PCP_CHECK_PYTHON_MODULE(setuptools)
AC_SUBST(have_python_setuptools)
PCP_CHECK_PYTHON_MODULE(requests)
AC_SUBST(have_python_requests)
PCP_CHECK_PYTHON_MODULE(libvirt)
AC_SUBST(have_python_libvirt)
PCP_CHECK_PYTHON_MODULE(six)
AC_SUBST(have_python_six)

AC_MSG_CHECKING([if the python InfluxDB support should be included])
have_python_influxdb=false
if test "$have_python" = true
then
    $have_python_requests && $have_python_OrderedDict && have_python_influxdb=true
fi
AC_SUBST(have_python_influxdb)
if $have_python_influxdb; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the json PMDA should be included])
pmda_json=false
AS_IF([test "x$do_pmdajson" = "xyes"], [pmda_json=true])
AS_IF([test "x$do_pmdajson" = "xcheck"], [
    dnl JSON PMDA needs both the six and jsonpointer Python modules
    $have_python_jsonpointer && $have_python_six && \
	$have_python_OrderedDict && pmda_json=true
])
AC_SUBST(PMDA_JSON, $pmda_json)
if $pmda_json; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the bcc PMDA should be included])
pmda_bcc=false
AS_IF([test "x$do_pmdabcc" = "xyes"], [pmda_bcc=true])
AS_IF([test "x$do_pmdabcc" = "xcheck"], [
    dnl BCC PMDA needs python3, and OrderedDict and BPF Python modules
    $enable_python3 && $have_python_BPF && \
	$have_python_OrderedDict && pmda_bcc=true
])
AC_SUBST(PMDA_BCC, $pmda_bcc)
if $pmda_bcc; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl check if perl available for the build and runtime
AC_CHECK_PROGS(PERL, perl)
AC_SUBST(PERL)

enable_perl=false
AS_IF([test "x$do_perl" != "xno"], [
    enable_perl=true
    AC_MSG_CHECKING([for any perl version])
    if test "$cross_compiling" = "yes"; then
        ans=$have_perl
        echo "cross-compile -> \"$ans\"" >&5
    elif test -n "$PERL"
    then
        pcp_perl_prog=$PERL
        have_perl=true
    else
        pcp_perl_prog=""
        have_perl=false
    fi
    AC_MSG_RESULT($pcp_perl_prog)
], [have_perl=false])
AC_SUBST(pcp_perl_prog)
AC_SUBST(enable_perl)
AC_SUBST(have_perl)

AC_MSG_CHECKING([if the SNMP PMDA should be included])
pmda_snmp=false
AS_IF([test "x$do_pmdasnmp" = "xyes"], [pmda_snmp=true])
AS_IF([test "x$do_pmdasnmp" = "xcheck"], [
    dnl SNMP PMDA needs perl and the Net::SNMP module
    if test "$have_perl" = true
    then
	if $pcp_perl_prog -e "use Net::SNMP" >/dev/null 2>&1
	then
	    pmda_snmp=true
	fi
    fi
])
AC_SUBST(PMDA_SNMP, $pmda_snmp)
if $pmda_snmp; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the mysql PMDA should be included])
pmda_mysql=false
if test "$have_perl" = true
then
    dnl rpm build for mysql PMDA needs Perl DBI and DBD::mysql
    if $pcp_perl_prog -e "use DBI" >/dev/null 2>&1
    then
	if $pcp_perl_prog -e "use DBD::mysql" >/dev/null 2>&1
	then
	    pmda_mysql=true
	fi
    fi
fi
AC_SUBST(PMDA_MYSQL, $pmda_mysql)
if $pmda_mysql; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the postgresql PMDA should be included])
pmda_postgresql=false
if test "$have_python" = true
then
    dnl rpm build for postgresql PMDA needs python psycopg2 module
    if $pcp_python_prog -c "import psycopg2" >/dev/null 2>&1
    then
	pmda_postgresql=true
    fi
fi
AC_SUBST(PMDA_POSTGRESQL, $pmda_postgresql)
if $pmda_postgresql; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the oracle PMDA should be included])
pmda_oracle=false
if test "$have_perl" = true
then
    dnl rpm build for oracle PMDA needs Perl DBI
    if $pcp_perl_prog -e "use DBI" >/dev/null 2>&1
    then
	pmda_oracle=true
    fi
fi
AC_SUBST(PMDA_ORACLE, $pmda_oracle)
if $pmda_oracle; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the elasticsearch PMDA should be included])
pmda_elasticsearch=false
if test "$have_python" = true
then
    dnl rpm build for elasticsearch PMDA needs Python urllib module
    if $pcp_python_prog -c "import urllib" >/dev/null 2>&1
    then
	pmda_elasticsearch=true
    fi
    if $pcp_python_prog -c "import urllib2" >/dev/null 2>&1
    then
	pmda_elasticsearch=true
    fi

fi
AC_SUBST(PMDA_ELASTICSEARCH, $pmda_elasticsearch)
if $pmda_elasticsearch; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the nginx PMDA should be included])
pmda_nginx=false
if test "$have_perl" = true
then
    dnl rpm build for nginx PMDA needs Perl LWP::UserAgent
    if $pcp_perl_prog -e "use LWP::UserAgent" >/dev/null 2>&1
    then
	pmda_nginx=true
    fi
fi
AC_SUBST(PMDA_NGINX, $pmda_nginx)
if $pmda_nginx; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the activemq PMDA should be included])
pmda_activemq=false
if test "$have_perl" = true
then
    dnl rpm build for activemq PMDA needs Perl modules LWP::UserAgent
    dnl and JSON
    pmda_activemq=true
    for module in 'LWP::UserAgent' JSON
    do
	if $pcp_perl_prog -e "use $module" >/dev/null 2>&1
	then
	    :
	else
	    pmda_activemq=false
	    break
	fi
    done
fi
AC_SUBST(PMDA_ACTIVEMQ, $pmda_activemq)
if $pmda_activemq; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the bind2 PMDA should be included])
pmda_bind2=false
if test "$have_perl" = true
then
    dnl rpm build for bind2 PMDA needs Perl LWP::UserAgent, XML::LibXML
    if $pcp_perl_prog -e "use LWP::UserAgent" >/dev/null 2>&1
    then
	if $pcp_perl_prog -e "use XML::LibXML" >/dev/null 2>&1
	then
	    if $pcp_perl_prog -e "use File::Slurp" >/dev/null 2>&1
	    then
	        pmda_bind2=true
	    fi
	fi
    fi
fi
AC_SUBST(PMDA_BIND2, $pmda_bind2)
if $pmda_bind2; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the nutcracker PMDA should be included])
pmda_nutcracker=false
AS_IF([test "x$do_pmdanutcracker" = "xyes"], [pmda_nutcracker=true])
AS_IF([test "x$do_pmdanutcracker" = "xcheck"], [
    dnl build for nutcracker PMDA needs perl JSON & YAML::XS modules
    if test "$have_perl" = true
    then
	if $pcp_perl_prog -e "use YAML::XS" >/dev/null 2>&1
	then
	    if $pcp_perl_prog -e "use JSON" >/dev/null 2>&1
	    then
		pmda_nutcracker=true
	    fi
	fi
    fi
])
AC_SUBST(PMDA_NUTCRACKER, $pmda_nutcracker)
if $pmda_nutcracker; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the LIO PMDA should be included])
pmda_lio=false
if test "$have_python" = true
then
    dnl rpm build for LIO PMDA needs Python rtslib module
    if $pcp_python_prog -c "import rtslib" >/dev/null 2>&1
    then
	pmda_lio=true
    fi
fi
AC_SUBST(PMDA_LIO, $pmda_lio)
if $pmda_lio; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the Prometheus PMDA should be included])
pmda_prometheus=false
if test "$have_python" = true
then
    $have_python_requests && $have_python_OrderedDict && pmda_prometheus=true
fi
AC_SUBST(PMDA_PROMETHEUS, $pmda_prometheus)
if $pmda_prometheus; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AC_MSG_CHECKING([if the libvirt PMDA should be included])
pmda_libvirt=false
if test "$have_python" = true
then
    dnl rpm build for libvirt PMDA needs Python libvirt and lxml modules
    if test "$have_python_libvirt" = true
    then
	if $pcp_python_prog -c "import lxml" >/dev/null 2>&1
	then
	    pmda_libvirt=true
	fi
    fi
fi
AC_SUBST(PMDA_LIBVIRT, $pmda_libvirt)
if $pmda_libvirt; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

qmake=$QMAKE
enable_qt=false
qt_release=release
qt_version=0
AS_IF([test "x$do_qt" != "xno"], [
    enable_qt=true

    if test -z "$QMAKE"
    then
	dnl default to qmake from qtchooser whenever it is available
	dnl ... unfortunately this is not always correct, as when more
	dnl than one Qt version is installed, the default may not be our
	dnl preferred version, which is Qt5
	AC_PATH_PROGS(QTCHOOSER, [qtchooser],, [$QTDIR/bin:/usr/lib/qtchooser:/usr/bin:/usr/lib64/qt5/bin:/usr/lib/qt5/bin:/usr/lib64/qt4/bin:/usr/lib/qt4/bin:/usr/local/bin])
	AC_PATH_PROGS(QMAKE, [qmake qmake-qt5 qmake-qt4],, [$QTDIR/bin:/usr/lib/qtchooser:/usr/bin:/usr/lib64/qt5/bin:/usr/lib/qt5/bin:/usr/lib64/qt4/bin:/usr/lib/qt4/bin:/usr/local/bin])
	test "x$cc_is_gcc" = xyes -a $target_os = solaris && QMAKE="$QMAKE -spec solaris-g++"
    fi
    qmake=$QMAKE
    if test -z "$QMAKE"
    then
	enable_qt=false
    else
	if test -n "$QT_SELECT"
	then
	    AC_MSG_CHECKING([Qt version, QT_SELECT=$QT_SELECT])
	    dnl QT_SELECT set, check and fallback to Qt4 if given
	    dnl preference is not successful
	    export QT_SELECT
	    $qmake --version 2>&1 >/dev/null
	    if test $? -eq 1; then
		export QT_SELECT=4
	    fi
	else
	    dnl QT_SELECT not set, if we have qtchooser use that to see
	    dnl if Qt5 is available, otherwise we fallthrough to the 
	    dnl qmake default version
	    if test -n "$QTCHOOSER"
	    then
		AC_MSG_CHECKING([Qt version, using qtchooser])
		dnl if Qt5 appears to be present, pick that one, else Qt4
		if $QTCHOOSER -l | grep '^5$' >/dev/null
		then
		    export QT_SELECT=5
		else
		    export QT_SELECT=4
		fi
	    else
		AC_MSG_CHECKING([Qt version])
		unset QT_SELECT
	    fi
	fi
	eval `$qmake --version 2>&1 | awk '/Using Qt version/ { ver=4; print $ver }' | awk -F. '{ major=1; minor=2; point=3; printf "export QT_MAJOR=%d QT_MINOR=%d QT_POINT=%d\n",$major,$minor,$point }'`
	AC_MSG_RESULT([$QT_MAJOR.$QT_MINOR.$QT_POINT])
	if test -z "$QT_MAJOR" -o -z "$QT_MINOR"; then
	    echo WARNING: cannot extract Qt version number from ...
	    $qmake --version
	    echo Cannot include the Qt components in the build.
	    enable_qt=false
	    qt_version=0
	elif test "$QT_MAJOR" -lt 4; then
	    echo WARNING: Qt version 4.4 or later does not seem to be installed.
	    echo Cannot proceed with the Qt $QT_MAJOR installation found.
	    enable_qt=false
	    qt_version=0
	elif test "$QT_MAJOR" -eq 4 -a "$QT_MINOR" -lt 4 ; then
	    echo WARNING: Qt version 4.$QT_MINOR is too old.
	    echo Qt version 4.4 or later is required for Qt builds.
	    enable_qt=false
	    qt_version=0
	else
	    qt_version=$QT_MAJOR
	fi
    fi

    if test "$do_qt" != "check" -a "$enable_qt" != "true"
    then
	AC_MSG_ERROR([cannot enable Qt - no supported Qt installation found])
    elif test "$enable_qt" = "true" -a "x$cxx" = "x"
    then
	enable_qt=false
	test "$do_qt" != "check" && \
	AC_MSG_ERROR([C++ compiler unavailable, cannot build Qt components])
    elif test "$do_qt" = "debug"
    then
	dnl Debug/release style build? (non-debug by default)
	qt_release=debug
	enable_qt=true
    fi
])
AC_SUBST(qt_release)
AC_SUBST(qt_version)
AC_SUBST(enable_qt)
AC_SUBST(qmake)

enable_qt3d=false
AS_IF([test "x$do_qt3d" != "xno"], [
    if test -f /usr/include/Coin3/Inventor/Qt/SoQt.h -o -f /usr/include/Inventor/Qt/SoQt.h
    then
	enable_qt3d=$enable_qt
    elif test x"$do_qt3d" = x"yes"
    then
	AC_MSG_ERROR([cannot enable support for 3D scene graph API])
    fi
])
AC_SUBST(enable_qt3d)

dnl check if user wants their own make program
dnl note: all makefiles in this package use the gmake syntax
if test -z "$MAKE"
then
    AC_PATH_PROG(MAKE, gmake)
    if test -z "$MAKE"
    then
	# look elsewhere ...
	AC_MSG_CHECKING([for GNU make elsewhere])
	for f in /usr/local/bin/gmake /usr/freeware/bin/gmake /usr/local/bin/make /opt/sfw/bin/gmake nowhere
	do
	    if test -x $f
	    then
		MAKE=$f
		break
	    fi
	done
	if test $f = nowhere
	then
	    # Check if /usr/bin/make is any good
            mver=`/usr/bin/make --version 2>/dev/null | sed -n -e1p | cut -c1-8`
	    if test "$mver" != "GNU Make"
	    then
		echo
		echo "FATAL ERROR: could not find GNU make anywhere"
		echo "You need to set \$MAKE as the full path to GNU make "
		echo "in the environment."
		rm -rf conftest conftest.*
		exit 1
	    else
		MAKE=/usr/bin/make
	    fi
	fi
	AC_MSG_RESULT($MAKE)
    fi
fi
make=$MAKE
AC_SUBST(make)

dnl check if users wants their own CPP
if test -z "$CPP"; then
    AC_PROG_CPP
fi
cpp=$CPP
AC_SUBST(cpp)

dnl check if users wants their own linker
if test -z "$LD"; then
    AC_PATH_PROG(LD, ld, /usr/bin/ld)
fi
ld=$LD
AC_SUBST(ld)

dnl Provide ways to override owner and group for installed files
if test -z "$PCP_USER_INSTALL" ; then
    pcp_user_install=root
else
    pcp_user_install="$PCP_USER_INSTALL"
fi
AC_SUBST(pcp_user_install)
if test -z "$PCP_GROUP_INSTALL" ; then
    case "$target_os"
    in
	darwin|freebsd|netbsd|openbsd)
	    pcp_group_install=wheel
	    ;;
	*)
	    pcp_group_install=root
	    ;;
    esac
else
    pcp_group_install="$PCP_GROUP_INSTALL"
fi
AC_SUBST(pcp_group_install)

dnl check if the tar program is available
if test -z "$TAR"; then
    AC_PATH_PROGS(TAR, gtar tar, tar)
fi
if test $target_os = darwin -a -x /usr/bin/gnutar
then
    TAR=/usr/bin/gnutar
fi
tar=$TAR
AC_SUBST(tar)

dnl check if the gzip program is available
dnl (needed to gzip man pages on some platforms)
if test -z "$ZIP"; then
    AC_PATH_PROG(ZIP, gzip, /bin/gzip)
fi
test ! -x "$ZIP" && ZIP=/usr/local/bin/gzip
test ! -x "$ZIP" && ZIP=/usr/freeware/bin/gzip
test ! -x "$ZIP" && ZIP=/usr/bin/gzip
gzip=$ZIP
test -z "$gzip" && gzip=no-gzip
AC_SUBST(gzip)

dnl check if the bzip2 program is available
dnl (needed to bzip2 man pages on some platforms)
if test -z "$BZIP2"; then
    AC_PATH_PROG(BZIP2, bzip2, /bin/bzip2)
fi
test ! -x "$BZIP2" && BZIP2=/usr/bin/bzip2
test ! -x "$BZIP2" && BZIP2=/usr/local/bin/bzip2
test ! -x "$BZIP2" && BZIP2=/usr/freeware/bin/bzip2
bzip2=$BZIP2
test -z "$bzip2" && bzip2=no-bzip2
AC_SUBST(bzip2)

dnl check if the lzma program is available
dnl (needed to lzma man pages on some platforms)
if test -z "$LZMA"; then
    AC_PATH_PROG(LZMA, lzma, /bin/lzma)
fi
test ! -x "$LZMA" && LZMA=/usr/bin/lzma
test ! -x "$LZMA" && LZMA=/usr/local/bin/lzma
test ! -x "$LZMA" && LZMA=/usr/freeware/bin/lzma
lzma=$LZMA
test -z "$lzma" && lzma=no-lzma
AC_SUBST(lzma)

dnl check if the xz program is available
dnl (needed to xz man pages on some platforms)
if test -z "$XZ"; then
    AC_PATH_PROG(XZ, xz, /bin/xz)
fi
test ! -x "$XZ" && XZ=/usr/bin/xz
test ! -x "$XZ" && XZ=/usr/local/bin/xz
test ! -x "$XZ" && XZ=/usr/freeware/bin/xz
xz=$XZ
test -z "$xz" && xz=no-xz
AC_SUBST(xz)

dnl check if the hdiutil program is available
if test -z "$HDIUTIL"; then
    AC_PATH_PROG(HDIUTIL, hdiutil)
fi
hdiutil=$HDIUTIL
AC_SUBST(hdiutil)

dnl check if the mkinstallp program is available (AIX)
if test -z "$MKINSTALLP"; then
    AC_PATH_PROG(MKINSTALLP, mkinstallp)
fi
mkinstallp=$MKINSTALLP
AC_SUBST(mkinstallp)

dnl check for the Solaris pmgmk package maker
if test -z "$PKGMK"; then
    AC_PATH_PROG(PKGMK, pkgmk)
fi
pkgmk=$PKGMK
AC_SUBST(pkgmk)

dnl check if the dlltool program is available
if test -z "$DLLTOOL"; then
    AC_PATH_PROG(DLLTOOL, dlltool)
fi
dlltool=$DLLTOOL
AC_SUBST(dlltool)

dnl check if the rpmbuild program is available
if test -z "$RPMBUILD"; then
    AC_PATH_PROG(RPMBUILD, rpmbuild)
fi
test $target_distro = slackware && RPMBUILD=''
rpmbuild=$RPMBUILD
AC_SUBST(rpmbuild)

dnl check if the rpm program is available
if test -z "$RPM"; then
    AC_PATH_PROG(RPM, rpm)
fi
test $target_distro = slackware && RPM=''
rpm=$RPM
AC_SUBST(rpm)

dnl if rpmbuild exists, use it, otherwise use rpm
if test -n "$RPMBUILD" -a -x "$RPMBUILD"
then
    rpmprog=$RPMBUILD
else
    rpmprog=$RPM
fi
AC_SUBST(rpmprog)

dnl check if the pod2man program is available (perl man page builder)
if test -z "$POD2MAN"; then
    AC_PATH_PROG(POD2MAN, pod2man)
fi
pod2man=$POD2MAN
AC_SUBST(pod2man)

dnl extra check for the Perl MakeMaker package
AC_MSG_CHECKING([if ExtUtils::MakeMaker is installed])
perl -e "use ExtUtils::MakeMaker" 2>/dev/null
if test $? -eq 0
then
    AC_MSG_RESULT([ yes])
else
    AC_MSG_RESULT([ no])
    echo
    echo "FATAL ERROR: Perl ExtUtils::MakeMaker module missing."
    echo "You can either install this from your distribution, or"
    echo "download from CPAN (Comprehensive Perl Archive Network)."
    rm -rf conftest conftest.*
    exit 1
fi

AC_PATH_PROG(TRUEPROG, true)

dnl check if the makedepend program is available
if test -z "$MAKEDEPEND"; then
    AC_PATH_PROG(MAKEDEPEND, makedepend, $TRUEPROG)
fi
makedepend=$MAKEDEPEND
AC_SUBST(makedepend)

dnl check if the md5sum program is available
if test -z "$MD5SUM"; then
   AC_PATH_PROG(MD5SUM, md5sum, $TRUEPROG)
fi
md5sum=$MD5SUM
AC_SUBST(md5sum)

dnl check if the Debian dpkg program is available
if test -z "$DPKG"; then
   AC_PATH_PROG(DPKG, dpkg)
fi
dpkg=$DKPG
AC_SUBST(dpkg)

dnl check for the Slackware makepkg packaging tool
if test -z "$MAKEPKG"; then
   AC_PATH_PROG(MAKEPKG, makepkg)
fi
makepkg=$MAKEPKG
AC_SUBST(makepkg)

dnl check if a toolchain is available for the books
test -z "$PUBLICAN" && AC_PATH_PROG(PUBLICAN, publican)
publican=$PUBLICAN
AC_SUBST(publican)

book_toolchain=""
if test "$do_books" = "check" -o "$do_books" = "yes"
then
    if test "$BOOK_TOOLCHAIN" != ""
    then
        book_toolchain=$BOOK_TOOLCHAIN
    elif test "$PUBLICAN" != ""
    then
        book_toolchain=publican
    elif test "$do_books" = "yes"
    then
	AC_MSG_ERROR([cannot enable books build - no toolchain found])
    fi
fi
AC_SUBST(book_toolchain)

book_brand="common"
if test "$do_books_brand" != ""
then
    book_brand=$do_books_brand
fi
AC_SUBST(book_brand)

dnl check if symbolic links are supported
AC_PROG_LN_S
if test $target_os = mingw; then
    as_ln_s=/bin/true
fi

dnl if /proc is not mounted, try and mount it
dnl before trying to run the ps style test below
if test -d /proc
then
    test -f /proc/stat || mount /proc >/dev/null 2>&1
fi

dnl set platform specific ps
if test -n "$PROCPS"
then
    pcp_ps_prog="$PROCPS"
else
    pcp_ps_prog=ps
fi
AC_SUBST(pcp_ps_prog)

dnl set platform specific event logger
if test $target_os = mingw
then
    pcp_syslog_prog=pcp-eventlog
else
    pcp_syslog_prog=logger
fi
AC_SUBST(pcp_syslog_prog)

grep=grep
if test $target_os = solaris
then
    test -f /usr/xpg4/bin/grep && grep=/usr/xpg4/bin/grep
fi
AC_SUBST(grep)

dnl Checks for C header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h malloc.h strings.h syslog.h)
AC_CHECK_HEADERS(stddef.h sched.h dlfcn.h dl.h)
AC_CHECK_HEADERS(sys/times.h sys/resource.h sys/prctl.h)
AC_CHECK_HEADERS(sys/sysinfo.h sys/systeminfo.h)
AC_CHECK_HEADERS(endian.h standards.h sys/byteorder.h)
AC_CHECK_HEADERS(libgen.h sys/mman.h sys/un.h)
AC_CHECK_HEADERS(values.h stdint.h ieeefp.h math.h)
AC_CHECK_HEADERS(pwd.h grp.h regex.h sys/wait.h)
AC_CHECK_HEADERS(termio.h termios.h sys/termios.h)
AC_CHECK_HEADERS(sys/ioctl.h sys/select.h sys/socket.h)
AC_CHECK_HEADERS(netdb.h poll.h)
if test $target_os = darwin -o $target_os = openbsd
then
    AC_CHECK_HEADERS(net/if.h, [], [], [#include <sys/types.h>
#include <sys/socket.h>])
else
    AC_CHECK_HEADERS(net/if.h)
fi
AC_CHECK_HEADERS(netinet/in.h netinet/tcp.h arpa/inet.h)
AC_CHECK_HEADERS(windows.h winsock2.h ws2tcpip.h)
AC_CHECK_HEADERS(execinfo.h bits/wordsize.h)
AC_CHECK_HEADERS(iptypes.h, [], [], [#include <windows.h>])
AC_CHECK_HEADERS(iphlpapi.h, [], [], [#include <winsock2.h>])
AC_CHECK_HEADERS(netioapi.h, [], [], [#include <winsock2.h>])
AC_CHECK_HEADERS(fts.h libzfs.h)
AC_CHECK_HEADERS(sys/statvfs.h sys/statfs.h sys/mount.h)
AC_CHECK_HEADERS(ncurses/curses.h)
AC_CHECK_HEADERS(linux/perf_event.h)

dnl Check if we have <sys/endian.h> ... standard way
AC_MSG_CHECKING([for sys/endian.h ])
AC_TRY_COMPILE(
[
    #include <sys/endian.h>
],
[
], AC_DEFINE(HAVE_SYS_ENDIAN_H, [1], [sys/endian.h]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl Check if we have <machine/endian.h> ... MacOSX way
AC_MSG_CHECKING([for machine/endian.h ])
AC_TRY_COMPILE(
[
    #include <machine/endian.h>
],
[
], AC_DEFINE(HAVE_MACHINE_ENDIAN_H, [1], [machine/endian.h]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl Check if we have <sys/endian.h> ... IRIX strangeness
AC_MSG_CHECKING([for sys/endian.h (IRIX variant) ])
AC_TRY_COMPILE(
[
    #include <standards.h>
    #include <sys/endian.h>
],
[
], AC_DEFINE(HAVE_SYS_ENDIAN_H, [1], [IRIX sys/endian.h]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_INLINE

dnl check if regex functions come from libregex (mingw)
AC_CHECK_LIB(regex, regcomp)
lib_for_regex=""
if test $ac_cv_lib_regex_regcomp = yes
then
    lib_for_regex="-lregex"
fi
AC_SUBST(lib_for_regex)

PKG_CHECK_MODULES([libuv], [libuv >= 1.16], [have_libuv=true], [have_libuv=false])
AC_SUBST(HAVE_LIBUV, [$have_libuv])

PKG_CHECK_MODULES([libvarlink], [libvarlink], [have_libvarlink=true], [have_libvarlink=false])
AC_SUBST(HAVE_LIBVARLINK, [$have_libvarlink])

PKG_CHECK_MODULES([ncurses], [ncurses], [have_ncurses=true], [have_ncurses=false])
AC_SUBST(HAVE_NCURSES, [$have_ncurses])

PKG_CHECK_MODULES([DEVMAPPER], [devmapper], [have_devmapper=true], [have_devmapper=false])
if $have_devmapper
then
    AC_MSG_CHECKING([for dm_stats_counter_t ])
    AC_TRY_COMPILE([
            #include <libdevmapper.h>
	],
	[ dm_stats_counter_t ctr; ],
	have_devmapper=true
	AC_MSG_RESULT(yes),
	have_devmapper=false
	AC_MSG_RESULT(no))
fi
AC_SUBST(HAVE_DEVMAPPER, [$have_devmapper])

PKG_CHECK_MODULES([SYSTEMD], [libsystemd], [pmda_systemd=true], [pmda_systemd=false])
if $pmda_systemd
then
    :
else
    dnl libsystemd-journal is an alternative for older distros
    PKG_CHECK_MODULES([SYSTEMD], [libsystemd-journal],
		      [pmda_systemd=true], [pmda_systemd=false])
fi
AC_MSG_CHECKING([if the systemd PMDA should be included])
AC_SUBST(PMDA_SYSTEMD, $pmda_systemd)
if $pmda_systemd; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

pmda_infiniband=false
AS_IF([test "x$do_infiniband" != "xno"], [
    AC_CHECK_HEADERS([infiniband/umad.h], [
	AC_CHECK_HEADERS([infiniband/mad.h], [pmda_infiniband=true], [])
    ], [])
    savedLIBS=$LIBS
    IB_LIBS=""
    AC_CHECK_LIB(ibmad, madrpc_init)
    AC_CHECK_LIB(ibumad, umad_init)
    if test $ac_cv_lib_ibmad_madrpc_init = yes -a $ac_cv_lib_ibumad_umad_init = yes
    then
	IB_LIBS="-libmad -libumad"
	LIBS="$IB_LIBS"
	AC_MSG_CHECKING([for port_performance_query_via])
	AC_TRY_LINK_FUNC(port_performance_query_via,
                AC_DEFINE(HAVE_PORT_PERFORMANCE_QUERY_VIA, [1], [port_performance_query_via API])
		have_port_performance_query_via=true
		AC_MSG_RESULT(yes),
                have_port_performance_query_via=false
		AC_MSG_RESULT(no))
	AC_MSG_CHECKING([for pma_query_via])
	AC_TRY_LINK_FUNC(pma_query_via,
		AC_DEFINE(HAVE_PMA_QUERY_VIA, [1], [pma_query_via API])
                have_pma_query_via=true
		AC_MSG_RESULT(yes),
                have_pma_query_via=false
		AC_MSG_RESULT(no))
	LIBS=$savedLIBS
	if test $have_pma_query_via -o $have_port_performance_query_via
	then
	    :
	else
	    pmda_infiniband=false
	fi
    else
	pmda_infiniband=false
    fi
    LIBS=$savedLIBS
    AC_SUBST(IB_LIBS)
])
AC_MSG_CHECKING([if the infiniband PMDA should be included])
AC_SUBST(PMDA_INFINIBAND, $pmda_infiniband)
if $pmda_infiniband; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

pmda_papi=false
AS_IF([test "x$do_papi" != "xno"], [
    enable_papi=true

    saved_LDFLAGS="$LDFLAGS"
    saved_CFLAGS="$CFLAGS"
    savedLIBS=$LIBS

    dnl potentially from the environment, else empty
    CFLAGS="$papi_CFLAGS"
    LDFLAGS="$papi_LIBS"

    case "$do_papi" in
	yes|no|check)
	    ;;
	*/*)
	    PAPI_ROOTDIR=$do_papi;
	    CFLAGS="-I$PAPI_ROOTDIR/include"
	    LDFLAGS="-L$PAPI_ROOTDIR/lib"
	    ;;
	 *)
	    PKG_CHECK_MODULES(papi,[$do_papi],[
		  CFLAGS="$papi_CFLAGS"
		  LDFLAGS="$papi_LIBS"])
	    ;;
    esac

    # $papi_LIBS may include -lpapi harmlessly redundantly with AC_CHECK_LIB
    AC_CHECK_LIB([papi], [PAPI_library_init],
		 [papi_libs="$LDFLAGS -lpapi"],
		 [enable_papi=false])
    AC_CHECK_HEADERS([papi.h], [papi_cflags="$CFLAGS"], [enable_papi=false])
    if test "$do_papi" != "check" -a "$enable_papi" != "true"
    then
	AC_MSG_ERROR([PAPI is not installed, cannot enable the PAPI PMDA])
    else
	pmda_papi=$enable_papi
    fi
    LIBS=$savedLIBS
    CFLAGS="$saved_CFLAGS"
    LDFLAGS="$saved_LDFLAGS"
    AC_SUBST(PAPI_CFLAGS, $papi_cflags)
    AC_SUBST(PAPI_LIBS, $papi_libs)
])
AC_MSG_CHECKING([if the papi PMDA should be included])
AC_SUBST(PMDA_PAPI, $pmda_papi)
if $pmda_papi; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

AS_IF([test "x$pmda_papi" = "xtrue"], [
    	dnl check if struct PAPI_component_info_t has a disabled field
	AC_MSG_CHECKING([whether struct PAPI_component_info_t has a disabled field])
cat <<End-of-File >conftest.c
#include <papi.h>
int main() { PAPI_component_info_t *c; c->disabled = 0; }
End-of-File
	(eval $ac_compile) 2>conftest.out
	cat conftest.out >&5
    	if test -s conftest.out
    	then
	   AC_MSG_RESULT(no)
    	else
    	   AC_DEFINE(HAVE_PAPI_DISABLED_COMP, [1], [PAPI_component_info_t field])
    	   AC_MSG_RESULT(yes)

    	fi
    	rm -f conftest.*
])

pmda_perfevent=false
AS_IF([test "x$do_perfevent" = "xyes"], [
    pmda_perfevent=true
    pfm_libs="-lpfm"
    AC_SUBST(PFM_LIBS, $pfm_libs)
], [test "x$do_perfevent" != "xno" ], [
    enable_perfevent=true

    savedLIBS=$LIBS
    AC_CHECK_LIB([pfm], [pfm_get_os_event_encoding],
		 [pfm_libs="-lpfm"],
		 [enable_perfevent=false])
    AC_CHECK_HEADERS([perfmon/pfmlib_perf_event.h], [], [enable_perfevent=false])
    if test "$do_perfevent" != "check" -a "$enable_perfevent" != "true"
    then
	AC_MSG_ERROR([libpfm is not installed, cannot enable the perfevent PMDA])
    else
	pmda_perfevent=$enable_perfevent
    fi
    LIBS=$savedLIBS
    AC_SUBST(PFM_LIBS, $pfm_libs)
])
AC_MSG_CHECKING([if the perfevent PMDA should be included])
AC_SUBST(PMDA_PERFEVENT, $pmda_perfevent)
if $pmda_perfevent; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl Do you have varlink libraries for pmdapodman?
AC_MSG_CHECKING([if the podman PMDA should be included])
pmda_podman=false
AS_IF([test "x$do_pmdapodman" = "xyes"], [pmda_podman=true])
AS_IF([test "x$do_pmdapodman" = "xcheck"], [$have_libvarlink && pmda_podman=true])
AC_SUBST(PMDA_PODMAN, $pmda_podman)
if $pmda_podman; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl Do you have RPM Package Manager libraries for pmdarpm?
pmda_rpm=false
savedLIBS=$LIBS
AC_MSG_CHECKING([for rpmlib > 4.4.2])
AC_COMPILE_IFELSE(
   [AC_LANG_PROGRAM([[#include <rpm/header.h>]],
                    [[(void)HEADERGET_EXT;]])],
   [AC_MSG_RESULT([yes])
    pmda_rpm=true],
   [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([if the rpm PMDA should be included])
AC_SUBST(PMDA_RPM,$pmda_rpm)
if $pmda_rpm; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi
LIBS=$savedLIBS

dnl Do you have the required qshape script for the postfix PMDA
dnl The logic here is copied from the PMDA's Install script
pmda_postfix=false
AC_CHECK_PROGS(QSHAPE, qshape, [], path=[$PATH:/usr/sbin])
AC_MSG_CHECKING([if the postfix PMDA should be included])
if test -n "$QSHAPE"
then
    pmda_postfix=true
else
    for script in /usr/share/doc/packages/postfix-doc/auxiliary/qshape/qshape.pl
    do
	if test -f "$script"
	then
	    pmda_postfix=true
	    break
	fi
    done
fi
AC_SUBST(PMDA_POSTFIX,$pmda_postfix)
if $pmda_postfix; then AC_MSG_RESULT(yes); else AC_MSG_RESULT(no); fi

dnl Do you have system microhttpd libraries for pmwebd?
PKG_CHECK_MODULES([libmicrohttpd], [libmicrohttpd > 0.9.9], [have_libmicrohttpd=true], [have_libmicrohttpd=false])
AC_SUBST(HAVE_LIBMICROHTTPD, [$have_libmicrohttpd])

dnl Do you have graphics libraries for pmwebd?
PKG_CHECK_MODULES([cairo], [cairo >= 1.2, cairo-ft >= 1.2, cairo-png >= 1.2], [have_cairo=true], [have_cairo=false])
AC_SUBST(HAVE_CAIRO, [$have_cairo])

AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([boost/flyweight.hpp])
AC_LANG_POP
AC_SUBST(HAVE_BOOST_FLYWEIGHT_HPP, [$ac_cv_header_boost_flyweight_hpp])

have_boost=false
test "$ac_cv_header_boost_flyweight_hpp" = yes && have_boost=true
AC_SUBST(have_boost)

enable_webapi=false
AS_IF([test "x$do_webapi" != "xno"], [
    enable_webapi=true

    if test "$have_libmicrohttpd" != "true"
    then
	enable_webapi=false
	test "$do_webapi" != "check" && \
	AC_MSG_ERROR([libmicrohttpd is not installed, cannot enable the web API])
    elif test "$do_webapi" != "check" -a "x$cxx" = "x"
    then
	enable_webapi=false
	test "$do_webapi" != "check" && \
	AC_MSG_ERROR([C++ compiler unavailable, cannot enable the web API])
    fi
])
AC_SUBST(enable_webapi)

enable_manager=false
AS_IF([test "x$do_manager" != "xno"], [
    enable_manager=true

    if test "$target_os" = "mingw"
    then
	enable_manager=false
	test "$do_manager" != "check" && \
	AC_MSG_ERROR([MinGW build, cannot enable daemon manager])
    elif test "x$cxx" = "x"
    then
	enable_manager=false
	test "$do_manager" != "check" && \
	AC_MSG_ERROR([C++ compiler unavailable, cannot enable daemon manager])
    fi
    AC_MSG_CHECKING([compilation features for daemon manager])
    AC_TRY_COMPILE(
	[ #ifndef _XOPEN_SOURCE
	  #define _XOPEN_SOURCE 600
	  #endif
	  #include <stdio.h>
	], [],
	AC_MSG_RESULT(yes),
	enable_manager=false
	AC_MSG_RESULT(no))
])
AC_SUBST(enable_manager)

AC_CHECK_PROGS(SEINFO, seinfo)
AC_SUBST(SEINFO)
AC_MSG_CHECKING([if selinux policy should be included])
enable_selinux=false
if test $target_os = mingw
then
    :
else
    AS_IF([test "x$do_selinux" != "xno"], [
    for makefile in /usr/share/selinux/devel/Makefile
    do
	if test -f "$makefile" -a "x$SEINFO" != "x"
	then
	    enable_selinux=true
	    AC_MSG_RESULT(yes)
	fi
    done

    ])
fi
test "$enable_selinux" = "false" && AC_MSG_RESULT(no)
AC_SUBST(enable_selinux)
AC_SUBST(pcp_selinux_dir)


pcp_selinux_class_status=false
pcp_selinux_cap_userns_ptrace=false
pcp_selinux_container_runtime=false
pcp_selinux_nsfs=false
pcp_selinux_docker_var_lib=false
pcp_selinux_svirt_lxc_net=false
pcp_selinux_systemd_unit_file=false
pcp_selinux_systemd_exec=false
pcp_selinux_tracefs=false
pcp_selinux_unreserved_port=false
pcp_selinux_sock_file_getattr=false
pcp_selinux_hostname_exec_map=false
pcp_selinux_mock=false
pcp_selinux_unconfined=false
pcp_selinux_numad=false
pcp_selinux_bpf_class=false
pcp_selinux_wap_port=false
pcp_selinux_files_list_non_auth_dirs=false

AS_IF([test "x$enable_selinux" != "xfalse"], [
for policy_file in /etc/selinux/targeted/policy/policy.*
do
    seinfo --common >/dev/null 2>&1
    if test $? -eq 0
    then
        seinfo_common_flag="--common"
    else
        seinfo_common_flag="--class"
    fi
    if test -f "$policy_file"
    then
        class_status=`eval seinfo -x --class=system $seinfo_common_flag  -- $policy_file | grep status | awk '{ print $1 }'`
    	if test "x$class_status" != "x"
	then
	    pcp_selinux_class_status=true
	fi
	container_runtime=`eval seinfo -t -- $policy_file | grep container_runtime_t | awk '{ print $1 }'`
	if test "x$container_runtime" != "x"
	then
	    pcp_selinux_container_runtime=true
	fi
	nsfs=`eval seinfo -t -- $policy_file | grep nsfs_t | awk '{ print $1 }'`
	if test "x$nsfs" != "x"
	then
	    pcp_selinux_nsfs=true
	fi
	docker_var_lib=`eval seinfo -t -- $policy_file | grep docker_var_lib_t | awk '{ print $1 }'`
	if test "x$docker_var_lib" != "x"
	then
	    pcp_selinux_docker_var_lib=true
	fi
	svirt_lxc_net=`eval seinfo -t -- $policy_file | grep svirt_lxc_net_t | awk '{ print $1 }'`
	if test "x$svirt_lxc_net" != "x"
	then
	    pcp_selinux_svirt_lxc_net=true
	fi
	systemd_unit_file=`eval seinfo -t -- $policy_file | grep systemd_unit_file_t | awk '{ print $1 }'`
	if test "x$systemd_unit_file" != "x"
	then
	    pcp_selinux_systemd_unit_file=true
	fi
	systemd_exec=`eval seinfo -t -- $policy_file | grep systemd_systemctl_exec_t | awk '{ print $1 }'`
	if test "x$systemd_exec" != "x"
	then
	    pcp_selinux_systemd_exec=true
	fi
	cap_userns_ptrace=`eval seinfo -x --class=cap_userns $seinfo_common_flag -- $policy_file 2>&1 | grep sys_ptrace | awk '{ print $1 }'`
    	if test "x$cap_userns_ptrace" != "x"
	then
	    pcp_selinux_cap_userns_ptrace=true
	fi
	unreserved_port=`eval seinfo -t -- $policy_file | grep unreserved_port_t | awk '{ print $1 }'`
	if test "x$unreserved_port" != "x"
	then
	    pcp_selinux_unreserved_port=true
	fi
	tracefs=`eval seinfo -t -- $policy_file | grep tracefs_t | awk '{ print $1 }'`
	if test "x$tracefs" != "x"
	then
	    pcp_selinux_tracefs=true
	fi
	sock_file_getattr=`eval seinfo -x --class=sock_file $seinfo_common_flag -- $policy_file | grep getattr | awk '{ print $1 }'`
	if test "x$sock_file_getattr" != "x"
	then
	    pcp_selinux_sock_file_getattr=true
	fi
	hostname_exec_map_a=`eval seinfo -x --class=file $seinfo_common_flag -- $policy_file | grep map | awk '{ print $1 }'`
	hostname_exec_map_b=`eval seinfo -x --common file -- $policy_file 2>/dev/null | grep map | awk '{ print $1 }'`
	if test "x$hostname_exec_map_a" != "x" -o "x$hostname_exec_map_b" != "x"
	then
	    pcp_selinux_hostname_exec_map=true
	fi
	mock_var_lib=`eval seinfo -t -- $policy_file | grep mock_var_lib_t | awk '{ print $1 }'`
	if test "x$mock_var_lib" != "x"
	then
	    pcp_selinux_mock=true
	fi
       unconfined=`eval seinfo -t -- $policy_file | grep unconfined_service_t | awk '{ print $1 }'`
       if test "x$unconfined" != "x"
       then
           pcp_selinux_unconfined=true
       fi
       numad=`eval seinfo -t -- $policy_file | grep numad_t | awk '{ print $1 }'`
       if test "x$numad" != "x"
       then
           pcp_selinux_numad=true
       fi
       bpf_class=`eval seinfo -x --class=bpf -- $policy_file 2>/dev/null | grep bpf | awk '{ print $1 }'`
       if test "x$bpf_class" != "x"
       then
	    pcp_selinux_bpf_status=true
       fi
       wap_port=`eval seinfo -t -- $policy_file | grep wap_wsp_port_t | awk '{ print $1 }'`
       if test "x$wap_port" != "x"
       then
            pcp_selinux_wap_port=true
       fi
       auth_file_type=`eval seinfo -a -- $policy_file | grep non_auth_file_type | awk '{ print $1 }'`
       if test "x$auth_file_type" != "x"
       then
           pcp_selinux_files_list_non_auth_dirs=true
       fi
    fi
done
])
AC_SUBST(pcp_selinux_class_status)
AC_SUBST(pcp_selinux_cap_userns_ptrace)
AC_SUBST(pcp_selinux_container_runtime)
AC_SUBST(pcp_selinux_nsfs)
AC_SUBST(pcp_selinux_docker_var_lib)
AC_SUBST(pcp_selinux_svirt_lxc_net)
AC_SUBST(pcp_selinux_systemd_unit_file)
AC_SUBST(pcp_selinux_systemd_exec)
AC_SUBST(pcp_selinux_unreserved_port)
AC_SUBST(pcp_selinux_tracefs)
AC_SUBST(pcp_selinux_sock_file_getattr)
AC_SUBST(pcp_selinux_hostname_exec_map)
AC_SUBST(pcp_selinux_mock)
AC_SUBST(pcp_selinux_unconfined)
AC_SUBST(pcp_selinux_numad)
AC_SUBST(pcp_selinux_bpf_status)
AC_SUBST(pcp_selinux_wap_port)
AC_SUBST(pcp_selinux_files_list_non_auth_dirs)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_WAIT3
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(mktime nanosleep usleep unsetenv)
AC_CHECK_FUNCS(select socket syslog sendmsg recvmsg setns)
AC_CHECK_FUNCS(getuid getgid getpeerucred getpeereid)
AC_CHECK_FUNCS(uname gethostname getdomainname getmachineid)
AC_CHECK_FUNCS(__clone pipe2 fcntl ioctl)
AC_CHECK_FUNCS(prctl setlinebuf waitpid atexit kill)
AC_CHECK_FUNCS(chown fchmod getcwd scandir mkstemp)
AC_CHECK_FUNCS(brk sbrk posix_memalign memalign valloc)
AC_CHECK_FUNCS(signal sighold sigrelse tcgetattr)
AC_CHECK_FUNCS(regex regcmp regexec regcomp)
AC_CHECK_FUNCS(strtod strtol strtoll strtoull strndup strchrnul)
AC_CHECK_FUNCS(getgrent getgrent_r getgrnam getgrnam_r getgrgid getgrgid_r)
AC_CHECK_FUNCS(getpwent getpwent_r getpwnam getpwnam_r getpwuid getpwuid_r)
AC_CHECK_FUNCS(sysinfo trace_back_stack backtrace)

dnl only define readdir64 on non-linux platforms that support it
if test $target_os != linux -a $target_os != freebsd -a $target_os != kfreebsd -a $target_os != netbsd; then
    AC_CHECK_FUNCS(readdir64)
fi

dnl typedefs missing from sys/types.h, stdlib.h or stddef.h
if test $target_os = solaris
then
   AC_CHECK_TYPE(__int32_t, int32_t)
   AC_CHECK_TYPE(__uint32_t, uint32_t)
   AC_CHECK_TYPE(__int64_t, int64_t)
   AC_CHECK_TYPE(__uint64_t, uint64_t)
   AC_CHECK_TYPE(uint_t, u_int32_t)
else
    AC_CHECK_TYPE(__int32_t, int)
    AC_CHECK_TYPE(__uint32_t, unsigned int)
    AC_CHECK_TYPE(__int64_t, long long)
    AC_CHECK_TYPE(__uint64_t, unsigned long long)
    AC_CHECK_TYPE(uint_t, unsigned int)
fi

dnl check if we have a type for the pointer's size integer (__psint_t)
AC_MSG_CHECKING([for __psint_t ])
AC_TRY_COMPILE(
[
    #include <sys/types.h>
    #include <stdlib.h>
    #include <stddef.h>
], [ __psint_t psint; ],
AC_DEFINE(HAVE___PSINT_T, [1], [__psint_t type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check if we have a type for pointer difference (ptrdiff_t)
AC_MSG_CHECKING([for ptrdiff_t ])
AC_TRY_COMPILE([
    #include <stddef.h>
    #ifdef HAVE_MALLOC_H
    #include <malloc.h>
    #endif
], [ ptrdiff_t ptrdiff; ],
AC_DEFINE(HAVE_PTRDIFF_T, [1], [ptrdiff_t type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check if we have types for uid_t, gid_t (POSIX) or SID (Win32)
AC_MSG_CHECKING([for uid_t ])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #ifdef HAVE_PWD_H
    #include <pwd.h>
    #endif
], [ uid_t uid; ],
AC_DEFINE(HAVE_UID_T, [1], [uid_t type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
AC_MSG_CHECKING([for gid_t ])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #ifdef HAVE_GRP_H
    #include <grp.h>
    #endif
], [ gid_t gid; ],
AC_DEFINE(HAVE_GID_T, [1], [gid_t type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
AC_MSG_CHECKING([for SID ])
AC_TRY_COMPILE([
    #ifdef HAVE_WINDOWS_H
    #include <windows.h>
    #endif
], [ SID sid; ],
AC_DEFINE(HAVE_SID, [1], [sid type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check if we have a type for socklen_t
AC_MSG_CHECKING([for socklen_t ])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #ifdef HAVE_SYS_SOCKET_H
    #include <sys/socket.h>
    #endif
], [ socklen_t len; ],
AC_DEFINE(HAVE_SOCKLEN_T, [1], [socklen_t type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check if LL suffix on constants is supported
AC_TRY_COMPILE([
    #include <stdio.h>
], [ long long x = 0LL; ],
AC_DEFINE(HAVE_CONST_LONGLONG, [1], [LL suffix on constants]))

dnl check if _environ is declared globally
AC_TRY_LINK([
    #include <stdlib.h>
    #include <unistd.h>
], [ char **x = _environ; ],
AC_DEFINE(HAVE_UNDERBAR_ENVIRON, [1], [_environ declared globally]))

dnl check for PR_TERMCHILD and PR_SET_PDEATHSIG in <sys/prctl.h>
AC_MSG_CHECKING([for PR_TERMCHILD constant in sys/prctl.h])
AC_TRY_COMPILE([
    #ifdef HAVE_SYS_PRCTL_H
    #include <sys/prctl.h>
    #endif
], [ int i = PR_TERMCHILD; ],
AC_DEFINE(HAVE_PR_TERMCHILD, [1], [PR_TERMCHILD constant]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

AC_MSG_CHECKING([for PR_SET_PDEATHSIG constant in sys/prctl.h])
AC_TRY_COMPILE([
    #ifdef HAVE_SYS_PRCTL_H
    #include <sys/prctl.h>
    #endif
], [ int i = PR_SET_PDEATHSIG; ],
AC_DEFINE(HAVE_PR_SET_PDEATHSIG, [1], [PR_SET_PDEATHSIG constant]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

AC_HEADER_TIOCGWINSZ

dnl check if linker needs -rdynamic for dynamically loaded shared
dnl libraries to see the symbols in the process loading them.
dnl This is e.g., needed on linux for pmcd loading pmda_pmcd.so.
AC_MSG_CHECKING([if linker supports -rdynamic])
save_CFLAGS="$CFLAGS"
CFLAGS="-rdynamic"
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
    [AC_MSG_RESULT([yes])
     rdynamic_flag=-rdynamic],
    [AC_MSG_RESULT([no])
     rdynamic_flag=]
)
CFLAGS="$save_CFLAGS"
AC_SUBST([rdynamic_flag])


dnl check if argument to user's select() method in scandir call is const
AC_MSG_CHECKING([whether const arg for scandir() select method])
cat <<End-of-File >conftest.c
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
static int
my_select(const struct dirent *foo) { return 0; }
int main() { struct dirent **list; return scandir(".", &list, my_select, NULL); }
End-of-File
(eval $ac_compile) 2>conftest.out
cat conftest.out >&5
if test -s conftest.out
then
    AC_MSG_RESULT(no)
else
    AC_DEFINE(HAVE_CONST_DIRENT, [1], [const arg for scandir() select method])
    AC_MSG_RESULT(yes)
fi
rm -f conftest.*

dnl check if struct dirent has a d_off (directory offset) field
AC_MSG_CHECKING([whether struct dirent has a d_off field])
cat <<End-of-File >conftest.c
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
int main() { struct dirent d; d.d_off = 0; }
End-of-File
(eval $ac_compile) 2>conftest.out
cat conftest.out >&5
if test -s conftest.out
then
    AC_MSG_RESULT(no)
else
    AC_DEFINE(HAVE_DIRENT_D_OFF, [1], [struct dirent d_off field])
    AC_MSG_RESULT(yes)
fi
rm -f conftest.*

dnl check if printf %p has 0x prefix
AC_MSG_CHECKING([if printf %p produces 0x prefix])
if test "$cross_compiling" = "yes"; then
    ans=$printf_p_prefix
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <stdio.h>
int main(int argc,  char **argv) { printf("%p", argv); return(0); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
case "$ans"
in
    0x*)
	AC_DEFINE(HAVE_PRINTF_P_PFX, [1], [printf %p produces 0x])
	AC_MSG_RESULT(yes)
	;;
    *)
	AC_MSG_RESULT(no)
	;;
esac
rm -rf conftest conftest.*

_do_type()
{
    # need to deal with this sort of cpp output ...
    #   typedef long pid_t;
    #   typedef unsigned int pid_t;
    #   typedef unsigned int pid_t __attribute__ ((__mode__ (__SI__)));
    #   __extension__ typedef int pid_t;
    #   typedef foo_t
    #                  pid_t;
    #   typedef struct {
    #         ....
    #   } pid_t;
    #   typedef ... *pid;
    # and chaining of the form
    #   typedef long __pid_t;
    #   typedef __pid_t pid_t;
    #
    if test $target_os = darwin
    then
	# Need to strip -arch foo args for gcc -E
	_myflags=`echo "$CPPFLAGS" "$CFLAGS" | sed -e 's/-arch [[^ ]]*//g'`
    else
	_myflags="$CPPFLAGS $CFLAGS"
    fi
    _raw=`$CPP $_myflags conftest.c \
    | $SED \
	-e 's/[[ 	]]__attribute__ ((.*));/;/' \
	-e 's/__extension__[[ 	]][[ 	]]*//' \
    | $AWK '
/bozo/		{ print; next }
$1 == "typedef"	{ printf "%s",$0
		  if ($NF ~ /;$/) {
		      print ""
		      next
		  }
		  wantsemi = 1
		  if ($0 ~ /{/) depth = 1
		  next
		}
wantsemi == 1	{ printf " %s",$0
		  if ($0 ~ /{/) depth++
		  if (depth) {
		      if ($0 ~ /}/) depth--
		      if (depth > 0) next
		  }
		  if ($NF ~ /;$/) {
		      print ""
		      wantsemi = 0
		      next
		  }
		}' \
    | $SED \
	-e 's/\*/* /g' \
	-e 's/^[[ 	]]*//' \
        -e 's/;[[ 	]]*$//' \
    | $AWK '
$1 == "typedef"	{ map[[$NF]] = ""
		  for (i = 2; i < NF; i++) {
		    if (i == 2)
			map[[$NF]] = $i
		    else
			map[[$NF]] = map[[$NF]] " " $i
		  }
		  print $NF " -> " map[[$NF]] >"conftest.debug"
		  next
		}
$2 == "bozo"	{ t = $1
		  printf "best guess: %s",t >"conftest.debug"
		  while (map[[t]] != "") {
		    t = map[[t]]
		    printf " -> %s",t >"conftest.debug"
		  }
		  print "" >"conftest.debug"
		  print t
		  exit
		}'`
    case "$_raw"
    in
    int)
    	_fmt='d'
	;;
    unsigned|'unsigned int')
    	_fmt='u'
	;;
    long|'long int')
	_fmt='ld'
	;;
    'long long'|'long long int')
        if test $target_os = mingw; then
            _fmt='I64d'
        else
	    _fmt='lld'
        fi
	;;
    'unsigned long'|'unsigned long int'|'long unsigned int')
	_fmt='lu'
	;;
    'unsigned long long'|'unsigned long long int')
        if test $target_os = mingw; then
            _fmt='I64u'
        else
	    _fmt='llu'
        fi
	;;
    *\*)	# pointer to a something
	_fmt='p'
	;;
    struct\ *)	# not much can be done here ...
	_fmt='p'
	;;
    *)
	echo
	echo "FATAL ERROR: don't know what to do with type \"$_raw\""
	echo "... typedef mapping ..."
	cat conftest.debug
	rm -rf conftest conftest.*
	exit 1
	;;
    esac
}

dnl printf type for pid_t
AC_MSG_CHECKING([printf type for pid_t])
if test "$cross_compiling" = "yes"; then
    ans=$printf_fmt_pid
    echo "cross-compile -> \"$ans\"" >&5
    fmt_pid=$ans
else
    cat <<End-of-File >conftest.c
#include <sys/types.h>
#include <unistd.h>
#if defined pid_t	/* for NetBSD 8.0 */
#undef pid_t
#endif
pid_t bozo;
End-of-File
    _do_type
    fmt_pid=$_fmt
fi
AC_MSG_RESULT($fmt_pid)
AC_SUBST(fmt_pid)
rm -rf conftest.c conftest.debug

dnl printf type for int64_t
AC_MSG_CHECKING([printf type for int64_t ])
if test "$cross_compiling" = "yes"; then
    ans=$printf_fmt_int64
    echo "cross-compile -> \"$ans\"" >&5
else
    dnl first approach ... is there a #define that we can leverage?
    cat <<End-of-File >conftest.c
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main()
{
#if defined(__PRI64_PREFIX)
    /* most of the civilized universe */
    printf("%s\n", __PRI64_PREFIX "d");
#elif defined(__PRI_64_LENGTH_MODIFIER__)
    /* Darwin */
    printf("%s\n", __PRI_64_LENGTH_MODIFIER__ "d");
#else
    bozo!	/* fall through to the second approach below */
#endif
    return(0);
}
End-of-File
    ans=''
    (eval $ac_link) 2>&5
    if test -x ./conftest
    then
	ans=`./conftest`
	echo "./conftest (first approach) -> \"$ans\"" >&5
    fi
    if test -z "$ans"
    then
	dnl second approach _WORDSIZE may help ...
	cat <<End-of-File >conftest.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main()
{
#ifdef __WORDSIZE
/* logic copied from <inttypes.h> */
#if __WORDSIZE == 64
    printf("ld\n");
#else
    printf("lld\n");
#endif
#else
/*
 * on NetBSD and OpenBSD, for example, there is no __WORDSIZE
 * so fall through to the third approach below ...
 */
#endif
    return(0);
}
End-of-File
	(eval $ac_link) 2>&5
	if test -x ./conftest
	then
	    ans=`./conftest`
	    if test $target_os = mingw -a "$ans" = "lld"; then
		ans='I64d'
	    fi
	    echo "./conftest (second approach) -> \"$ans\"" >&5
	fi
    fi
    if test -z "$ans" -a "$GCC" = "yes"
    then
	dnl third approach, for gcc look for a printf format that
	dnl does not produce compiler warnings
	rm -f conftest.ans
	for fmt in lld ld d
	do
	    cat <<End-of-File >conftest.$ac_ext
#include <stdio.h>
#include <sys/types.h>
int main(void)
{
    int64_t	x = -1;
    printf("%$fmt\n", x);
    return 0;
}
End-of-File
	    $CC -Wall $CFLAGS $CPPFLAGS -c conftest.$ac_ext 2>conftest.err
	    if test -s conftest.err >/dev/null
	    then
		echo "-- not $fmt for fmt_64" >&5
		cat conftest.err >&5
	    else
		echo "$fmt" >conftest.ans
		echo "no warnings (third approach) -> \"$fmt\"" >&5
		break
	    fi
	done
	test -s conftest.ans && ans=`cat conftest.ans`
	rm -f conftest.ans conftest.err
    fi
fi
if test -z "$ans"
then
    echo 'FATAL ERROR: Cannot determine printf format for int64_t type'
    rm -rf conftest conftest.*
    exit 1
fi
fmt_int64=$ans
AC_MSG_RESULT($fmt_int64)
AC_SUBST(fmt_int64)
dnl and the unsigned version of this ...
fmt_uint64=`echo $fmt_int64 | sed -e 's/d$/u/'`
AC_SUBST(fmt_uint64)
rm -rf conftest.* conftest

AC_MSG_CHECKING([strtol or strtoll for int64_t])
if test "$cross_compiling" = "yes"; then
    ans="$strtoint64"
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <stdio.h>
#include <stdlib.h>
main()
{
    long long int	value = -1;
    value = strtol("1234567812345678", NULL, 16);
    if (value == 0x1234567812345678LL) {
	printf("strotol\n");
	exit(0);
    }
    value = strtoll("1234567812345678", NULL, 16);
    if (value == 0x1234567812345678LL) {
	printf("strtoll\n");
	exit(0);
    }
    exit(1);
}
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
case "$ans"
in
    strtol)
	AC_DEFINE(strtoint64, [strtol], [Define strtoint64 as strtol])
	AC_DEFINE(strtouint64, [strtoul], [Define strtoint64 as strtoul])
	AC_MSG_RESULT([strtol])
	;;
    strtoll)
	AC_DEFINE(strtoint64, [strtoll], [Define strtoint64 as strtoll])
	AC_DEFINE(strtouint64, [strtoull], [Define strtoint64 as strtoull])
	AC_MSG_RESULT([strtoll])
	;;
    *)
	AC_DEFINE(strtoint64, [strtoll], [Default strtoint64 to strtoll])
	AC_DEFINE(strtouint64, [strtoull], [Default strtouint64 to strtoull])
	AC_MSG_RESULT([assuming strtoll])
	;;
esac
rm -rf conftest conftest.*

if test "$do_threads" = "check" -o "$do_threads" = "yes"
then
    AC_CHECK_HEADERS(
	pthread.h,
	[],
	[
	    if test "$do_threads" = "yes"
	    then
		AC_MSG_ERROR([cannot enable multi-threaded mode - no pthread.h])
	    fi
	])

    dnl Check if pthread_mutex_t is defined in pthread.h
    dnl Ignore the fact that pthread.h could be missing - we don't
    dnl really care if this test fails because of missing pthread_mutex_t
    dnl or because of missing headers.
    AC_MSG_CHECKING([for pthread_mutex_t in pthread.h])
    AC_TRY_COMPILE(
	[#include <pthread.h>], [pthread_mutex_t mymutex;],
	AC_DEFINE(HAVE_PTHREAD_MUTEX_T, [1], [pthread_mutex_t type]) AC_MSG_RESULT(yes),
	[
	    if test "$do_threads" = "yes"
	    then
		AC_MSG_ERROR([cannot enable multi-threaded mode - no mutexes])
	    else
		AC_MSG_RESULT(no)
	    fi
	])

    dnl Check which library provide pthread stuff
    AC_MSG_CHECKING([where pthread_create() is defined])
    for cand in "" pthreads pthread ; do
	savedLIBS=$LIBS
	if test -n "$cand"
	then
	    LIBS=`echo $LIBS -l$cand`
	fi
	AC_TRY_LINK(
	[
	    #include <pthread.h>
	],
	[
	    pthread_create(NULL, NULL, NULL, NULL);
	],  AC_MSG_RESULT(lib${cand:-c})
	    if test -z "$cand"
	    then
		lib_for_pthreads="$cand"
	    else
		lib_for_pthreads="-l$cand"
	    fi
	    LIBS=$savedLIBS
	    break )
	LIBS=$savedLIBS
    done
    AC_SUBST(lib_for_pthreads)

    if test "$ac_cv_header_pthread_h" = "yes"
    then
	dnl printf type for pthread_t
	AC_MSG_CHECKING([printf type for pthread_t])
	cat <<End-of-File >conftest.c
#include <pthread.h>
pthread_t bozo;
End-of-File
	_do_type
	fmt_pthread=$_fmt
	AC_MSG_RESULT($fmt_pthread)
	AC_SUBST(fmt_pthread)
	rm -rf conftest.c conftest.debug

	dnl check if gcc supports __thread for thread private data
	AC_MSG_CHECKING([if compiler supports __thread])
	dnl __thread support is broken in some places
	if test $target_os = netbsd
	then
	    AC_TRY_COMPILE([#include <pthread.h>
#if __GNUC__ < 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ < 5 )
broken!
#else
__thread int x;
#endif], [],
		AC_DEFINE(HAVE___THREAD, [1], [__thread private data]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
	else
	    AC_TRY_COMPILE([#include <pthread.h>
__thread int x;], [],
		AC_DEFINE(HAVE___THREAD, [1], [__thread private data]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
	fi

	dnl Check if pthread_barrier_t is defined in pthread.h
	AC_MSG_CHECKING([for pthread_barrier_t in pthread.h])
	AC_TRY_COMPILE([#include <pthread.h>], [pthread_barrier_t mybarrier;],
	    AC_DEFINE(HAVE_PTHREAD_BARRIER_T, [1], [pthread_barrier_t type]) AC_MSG_RESULT(yes),
	    AC_MSG_RESULT(no))
    fi
fi

AC_MSG_CHECKING([sizeof suseconds_t])
if test "$cross_compiling" = "yes"; then
    ans=$sizeof_suseconds_t
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <sys/time.h>
main() { printf("%d", (int)sizeof(suseconds_t)); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
    rm -rf conftest conftest.*
fi
AC_MSG_RESULT($ans)
if test -n "$ans"; then
    AC_DEFINE_UNQUOTED(PM_SIZEOF_SUSECONDS_T, $ans, [sizeof suseconds_t])
fi

AC_MSG_CHECKING([sizeof time_t])
if test "$cross_compiling" = "yes"; then
    ans=$sizeof_time_t
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <sys/time.h>
main() { printf("%d", (int)sizeof(time_t)); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
    rm -rf conftest conftest.*
fi
AC_MSG_RESULT($ans)
if test -n "$ans"; then
    AC_DEFINE_UNQUOTED(PM_SIZEOF_TIME_T, $ans, [sizeof time_t])
fi

dnl check sizeof long
AC_MSG_CHECKING([sizeof long])
if test "$cross_compiling" = "yes"; then
    ans=$sizeof_long
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <stdio.h>
main() { printf("%d", (int)sizeof(long)); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
AC_MSG_RESULT($ans)
if test "$ans" = 4; then
    AC_DEFINE(HAVE_32BIT_LONG, [1], [sizeof long])
elif test "$ans" = 8; then
    AC_DEFINE(HAVE_64BIT_LONG, [1], [sizeof long])
else
    echo
    echo "FATAL ERROR: size of long is not 32 or 64 bits, cannot proceed."
    echo "sizeof(char *) -> $ans"
    rm -rf conftest conftest.*
    exit 1
fi
rm -rf conftest conftest.*

dnl check sizeof pointer
AC_MSG_CHECKING([sizeof pointer])
if test "$cross_compiling" = "yes"; then
    ans=$sizeof_pointer
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <stdio.h>
main() { printf("%d", (int)sizeof(char *)); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
AC_MSG_RESULT($ans)
if test "$ans" = 4; then
    AC_DEFINE(HAVE_32BIT_PTR, [1], [pointer size])
    PCP_PTR_SIZE=32
elif test "$ans" = 8; then
    AC_DEFINE(HAVE_64BIT_PTR, [1], [pointer size])
    PCP_PTR_SIZE=64
else
    echo
    echo "FATAL ERROR: size of pointer is not 32 or 64 bits, cannot proceed."
    echo "sizeof(char *) -> $ans"
    rm -rf conftest conftest.*
    exit 1
fi
rm -rf conftest conftest.*

dnl check sizeof int. If not 32, we die
AC_MSG_CHECKING([sizeof int])
if test "$cross_compiling" = "yes"; then
    ans=$sizeof_int
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
#include <stdio.h>
main() { printf("%d", (int)sizeof(int)); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
AC_MSG_RESULT($ans)
if test "$ans" != 4
then
    echo
    echo "FATAL ERROR: sizeof(int) is not 32 bits, cannot proceed."
    echo "Note: 32-bit ints are assumed in the PCP external file formats and"
    echo "      the over-the-wire PDU formats"
    rm -rf conftest conftest.*
    exit 1
fi
rm -rf conftest conftest.*

dnl check bit field allocation order within a word
AC_MSG_CHECKING([if bit fields allocated left-to-right])
if test "$cross_compiling" = "yes"; then
    ans=$bit_field_scheme
    echo "cross-compile -> \"$ans\"" >&5
else
    cat <<End-of-File >conftest.c
union { struct { unsigned int b:4; unsigned int c:4; } a; int p; } u;
main() { u.a.b = 1; u.a.c = 2; printf("%0*x", 2*sizeof(int), u.p); }
End-of-File
    (eval $ac_compile) 2>&5
    (eval $ac_link) 2>&5
    ans=`./conftest`
    echo "./conftest -> \"$ans\"" >&5
fi
case "$ans"
in
    1200*|*0012)
	# left-to-right starting from MSB (SGI cc on MIPS), or
	# left-to-right ending at LSB
	AC_DEFINE(HAVE_BITFIELDS_LTOR, [1], [left-to-right bitfield ordering])
	AC_MSG_RESULT(yes)
	;;
    2100*|*0021)
	# right-to-left ending at MSB, or
	# right-to-left starting from LSB (gcc in Intel)
	AC_MSG_RESULT(no)
	;;
    *)
	AC_MSG_RESULT(unknown)
	echo "FATAL ERROR: could not fathom your compiler's bit field allocation scheme"
	rm -f conftest conftest.*
	exit 1
	;;
esac
rm -rf conftest conftest.*

dnl check if compiler can cast __uint64_t to double
AC_TRY_LINK(
[
    #include <stdlib.h>
    #include <unistd.h>
],
[
    __uint64_t x = 0;
    double y = (double)x;
], AC_DEFINE(HAVE_CAST_U64_DOUBLE, [1], [compiler casts u64 to double]))

dnl check if basename and dirname need -lgen, -lpcp or nothing to work
dnl (assume both go together)
AC_CHECK_FUNCS(basename)
if test $ac_cv_func_basename = yes
then
    AC_DEFINE(HAVE_BASENAME, [1], [basename API])
    AC_DEFINE(HAVE_DIRNAME, [1], [dirname API])
    lib_for_basename=""
else
    AC_CHECK_LIB(gen, basename)
    if test $ac_cv_lib_gen_basename = yes
    then
	AC_DEFINE(HAVE_BASENAME, [1], [basename API])
	AC_DEFINE(HAVE_DIRNAME, [1], [dirname API])
	lib_for_basename="-lgen"
    else
	lib_for_basename="-lpcp"
    fi
fi
AC_SUBST(lib_for_basename)

dnl check if clock_gettime needs -lrt to work
lib_for_clock_gettime=
AC_CHECK_FUNCS(clock_gettime)
if test $ac_cv_func_clock_gettime = no
then
    AC_CHECK_LIB(rt, clock_gettime)
    if test $ac_cv_lib_rt_clock_gettime = yes
    then
	AC_DEFINE(HAVE_CLOCK_GETTIME, [1], [clock_gettime API])
	lib_for_rt=-lrt
    fi
fi
AC_SUBST(lib_for_rt)

dnl check if dlopen et al need -ldl to work
lib_for_dlopen=
AC_CHECK_FUNCS(dlopen)
if test $ac_cv_func_dlopen = no
then
    AC_CHECK_LIB(dl, dlopen)
    if test $ac_cv_lib_dl_dlopen = yes
    then
	AC_DEFINE(HAVE_DLOPEN, [1], [dlopen API])
	lib_for_dlopen=-ldl
    fi
fi
AC_SUBST(lib_for_dlopen)

dnl check if flog10, pow, fpclassify and isnanf are available
dnl in the maths library
lib_for_math=
AC_CHECK_FUNCS(flog10)
if test $ac_cv_func_flog10 = no
then
    AC_CHECK_LIB(m, flog10)
    if test $ac_cv_lib_m_flog10 = yes
    then
	AC_DEFINE(HAVE_FLOG10, [1], [flog10 math API])
	lib_for_math=-lm
    fi
else
    AC_DEFINE(HAVE_FLOG10, [1], [flog10 math API])
fi
AC_CHECK_FUNCS(pow)
if test $ac_cv_func_pow = no
then
    AC_CHECK_LIB(m, pow)
    if test $ac_cv_lib_m_pow = yes
    then
	AC_DEFINE(HAVE_POW, [1], [pow math API])
	lib_for_math=-lm
    fi
else
    AC_DEFINE(HAVE_POW, [1], [pow math API])
fi
AC_MSG_CHECKING([for fpclassify()])
ac_cv_func_fpclassify=no
AC_TRY_LINK(
[
    #include <math.h>
],
[
    double x = 123.456;
    if (fpclassify(x) == FP_NAN) exit(1);
], ac_cv_func_fpclassify=yes)
AC_MSG_RESULT($ac_cv_func_fpclassify)
if test $ac_cv_func_fpclassify = no
then
    dnl try with -lm
    AC_MSG_CHECKING([for fpclassify() with -lm])
    savedLIBS=$LIBS
    LIBS=-lm
    AC_TRY_LINK(
[
    #include <math.h>
],
[
    double x = 123.456;
    if (fpclassify(x) == FP_NAN) exit(1);
], ac_cv_func_fpclassify=yes)
    AC_MSG_RESULT($ac_cv_func_fpclassify)
    if test $ac_cv_func_fpclassify = yes
    then
	lib_for_math=-lm
    fi
    LIBS=$savedLIBS
fi
if test $ac_cv_func_fpclassify = yes
then
    AC_DEFINE(HAVE_FPCLASSIFY, [1], [fpclassify math API])
else
    dnl prefer fpclassify() but will take isnan() and isnanf() as
    dnl possible alternates
    AC_CHECK_FUNCS(isnan)
    if test $ac_cv_func_isnan = no
    then
	AC_CHECK_LIB(m, isnan)
	if test $ac_cv_lib_m_isnan = yes
	then
	    AC_DEFINE(HAVE_ISNAN, [1], [isnan math API])
	    lib_for_math=-lm
	fi
    fi
    AC_CHECK_FUNCS(isnanf)
    if test $ac_cv_func_isnanf = no
    then
	AC_CHECK_LIB(m, isnanf)
	if test $ac_cv_lib_m_isnanf = yes
	then
	    AC_DEFINE(HAVE_ISNANF, [1], [isnanf math API])
	    lib_for_math=-lm
	fi
    fi
fi
AC_SUBST(lib_for_math)

dnl check if we have the SIG_PF typedef
AC_TRY_LINK([#include <signal.h>], [SIG_PF x;],
    AC_DEFINE(HAVE_SIGPF, [1], [SIG_PF typedef]))

dnl check if we have the SA_SIGINFO #define
AC_TRY_LINK([#include <signal.h>], [int x = SA_SIGINFO;],
    AC_DEFINE(HAVE_SA_SIGINFO, [1], [SA_SIGINFO macro]))

dnl check if we support the SIGPIPE signal
AC_TRY_LINK([#include <signal.h>], [int x = SIGPIPE;],
    AC_DEFINE(HAVE_SIGPIPE, [1], [SIGPIPE signal]))

dnl check if we support the SIGHUP signal
AC_TRY_LINK([#include <signal.h>], [int x = SIGHUP;],
    AC_DEFINE(HAVE_SIGHUP, [1], [SIGHUP signal]))

dnl check if we support the SIGBUS signal
AC_TRY_LINK([#include <signal.h>], [int x = SIGBUS;],
    AC_DEFINE(HAVE_SIGBUS, [1], [SIGBUS signal]))

dnl check if we need to explicitly include signal.h
AC_TRY_LINK([#include <sys/wait.h>],
[   typedef void (*SIGRET)(int);
    SIGRET x = SIG_IGN;
], AC_DEFINE(HAVE_WAIT_INCLUDES_SIGNAL, [1], [indirect signal.h]))

dnl check for name and type of time fields in struct stat
dnl IRIX example	timespec_t st_mtim;
dnl Linux example 	struct timespec st_mtim;
dnl Darwin example 	struct timespec st_mtimespec;
dnl Solaris example	timestruc_t st_mtim;
dnl FreeBSD (6.1)	struct timespec st_mtimespec;
dnl			struct timespec {
dnl				time_t tv_sec;
dnl				long tv_nsec;
dnl			};
dnl
have_stat_type=false
have_stat_name=false
if test $have_stat_name = false
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<[ 	]st_mtimespec>>changequote([, ]),
    sys/stat.h, [ have_stat_name=true;
    AC_DEFINE(HAVE_ST_MTIME_WITH_SPEC, [1], [st_mtimespec stat field]) ])
fi
if test $have_stat_name = false -a $target_os != darwin -a $target_os != linux -a $target_os != kfreebsd -a $target_os != netbsd
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<[ 	]st_mtime>>changequote([, ]),
    sys/stat.h, [ have_stat_name=true;
    AC_DEFINE(HAVE_ST_MTIME_WITH_E, [1], [st_mtime stat field]) ])
fi
if test $have_stat_type = false
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<timestruc_t[ 	][ 	]*st_mtim>>changequote([, ]),
    sys/stat.h, [ have_stat_type=true;
    AC_DEFINE(HAVE_STAT_TIMESTRUC, [1], [timestruc_t type]) ])
fi
if test $have_stat_type = false
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<timespec_t[ 	][ 	]*st_mtim>>changequote([, ]),
    sys/stat.h, [ have_stat_type=true;
    AC_DEFINE(HAVE_STAT_TIMESPEC_T, [1], [timespec_t type]) ])
fi
if test $have_stat_type = false
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<timespec[ 	][ 	]*st_mtim>>changequote([, ]),
    sys/stat.h, [ have_stat_type=true;
    AC_DEFINE(HAVE_STAT_TIMESPEC, [1], [timespec type]) ])
fi
if test $have_stat_type = false
then
    AC_EGREP_HEADER(
    changequote(<<, >>)<<time_t[ 	][ 	]*st_mtim>>changequote([, ]),
    sys/stat.h, [ have_stat_type=true;
    AC_DEFINE(HAVE_STAT_TIME_T, [1], [time_t type]) ])
fi
if test $have_stat_type = false
then
    echo 'FATAL ERROR: Cannot determine struct stat time types.'
    rm -rf conftest conftest.*
    exit 1
fi

dnl
dnl Work out where to install stuff for this package
dnl (and where to find stuff at run-time for add-on packages).
dnl

dnl
dnl Predictable directory containing pcp.conf, or overridden
dnl by the $PCP_CONF environment variable. If this is not set
dnl (default /etc/pcp.conf), then $PCP_CONF must be set in
dnl the environment.
dnl
dnl The eval echo stuff is used to get around unfavourable
dnl elements of the GNU standards, which cause embedding of
dnl ${prefix} within many of these various $dirs.
dnl http://www.gnu.org/software/autoconf/manual/autoconf.html#Installation-Directory-Variables
dnl
pcp_etc_dir=`eval echo $sysconfdir`
pcp_etc_dir=`eval echo $pcp_etc_dir`
AC_SUBST(pcp_etc_dir)
pcp_saslconf_dir=`eval echo $sysconfdir/sasl2`
pcp_saslconf_dir=`eval echo $pcp_saslconf_dir`
AC_SUBST(pcp_saslconf_dir)
pcp_sysconf_dir=`eval echo $sysconfdir/pcp`
pcp_sysconf_dir=`eval echo $pcp_sysconf_dir`
AC_SUBST(pcp_sysconf_dir)
pcp_pmcdconf_path=$pcp_sysconf_dir/pmcd/pmcd.conf
pcp_pmcdrclocal_path=$pcp_sysconf_dir/pmcd/rc.local
pcp_pmcdoptions_path=$pcp_sysconf_dir/pmcd/pmcd.options
pcp_pmwebdoptions_path=$pcp_sysconf_dir/pmwebd/pmwebd.options
pcp_pmmgroptions_path=$pcp_sysconf_dir/pmmgr/pmmgr.options
pcp_pmproxyoptions_path=$pcp_sysconf_dir/pmproxy/pmproxy.options
pcp_pmiecontrol_path=$pcp_sysconf_dir/pmie/control
pcp_pmsnapcontrol_path=$pcp_sysconf_dir/pmsnap/control
pcp_pmloggercontrol_path=$pcp_sysconf_dir/pmlogger/control
AC_SUBST(pcp_pmcdconf_path)
AC_SUBST(pcp_pmcdoptions_path)
AC_SUBST(pcp_pmcdrclocal_path)
AC_SUBST(pcp_pmwebdoptions_path)
AC_SUBST(pcp_pmmgroptions_path)
AC_SUBST(pcp_pmproxyoptions_path)
AC_SUBST(pcp_pmiecontrol_path)
AC_SUBST(pcp_pmsnapcontrol_path)
AC_SUBST(pcp_pmloggercontrol_path)

dnl shared PCP files (shareable for diskless)
pcp_share_dir=`eval echo $datarootdir/pcp`
pcp_share_dir=`eval echo $pcp_share_dir`
AC_SUBST(pcp_share_dir)

dnl private PCP executables
pcp_binadm_dir=`eval echo $libexecdir/pcp/bin`
pcp_binadm_dir=`eval echo $pcp_binadm_dir`
AC_SUBST(pcp_binadm_dir)

dnl non-shared (i.e. system local) PCP files
pcp_var_dir=`eval echo $localstatedir/lib/pcp`
pcp_var_dir=`eval echo $pcp_var_dir`
AC_SUBST(pcp_var_dir)

dnl pmcd control and options files
AC_ARG_WITH(configdir,[AC_HELP_STRING([--with-configdir],[configuration directory [LOCALSTATEDIR/pcp/config]])],
                      [pcp_config_dir=$withval],
                      [pcp_config_dir=$pcp_var_dir/config])

pcp_pmdas_dir=$pcp_var_dir/pmdas
AC_SUBST(pcp_pmdas_dir)

pcp_selinux_dir=$pcp_var_dir/selinux
AC_SUBST(pcp_selinux_dir)

dnl runtime shared libraries
pcp_lib_dir=`eval echo $libdir`
pcp_lib_dir=`eval echo $pcp_lib_dir`
pcp_lib32_dir=`echo $pcp_lib_dir | sed -e s,64,, -e s,//,/,`
AC_SUBST(pcp_lib_dir)
AC_SUBST(pcp_lib32_dir)

dnl perl modules
AC_ARG_WITH(perl_installdirs,[AC_HELP_STRING([--with-perl_installdirs],[perl installdirs [vendor]])],
                      [perl_installdirs=$withval],
                      [perl_installdirs=vendor])
perl_installdirs=`eval echo $perl_installdirs`
perl_installdirs=`eval echo $perl_installdirs`
AC_SUBST(perl_installdirs)
AC_ARG_WITH(perl_install_base,[AC_HELP_STRING([--with-perl_install_base],[perl install_base [PREFIX]])],
                      [perl_install_base=$withval],
                      [perl_install_base=$prefix])
perl_install_base=`eval echo $perl_install_base`
perl_install_base=`eval echo $perl_install_base`
AC_SUBST(perl_install_base)

AC_ARG_WITH(python_prefix,[AC_HELP_STRING([--with-python_prefix],[python setup.py prefix [PREFIX]])],
                      [python_prefix=$withval],
                      [python_prefix=$prefix])
python_prefix=`eval echo $python_prefix`
python_prefix=`eval echo $python_prefix`
AC_SUBST(python_prefix)

AC_PATH_XTRA
pcp_x11_incflags=$X_CFLAGS
AC_SUBST(pcp_x11_incflags)
pcp_x11_libflags=$X_LIBS
AC_SUBST(pcp_x11_libflags)
pcp_x11_extra=$X_EXTRA_LIBS
AC_SUBST(pcp_x11_extra)
pcp_x11_pre=$X_PRE_LIBS
AC_SUBST(pcp_x11_pre)

dnl man pages (source)
have_manpages=false
have_gzipped_manpages=false
have_bzip2ed_manpages=false
have_lzmaed_manpages=false
have_xzed_manpages=false
need_old_tbl_header=false
man_header=
pcp_man_dir=`eval echo $mandir`
pcp_man_dir=`eval echo $pcp_man_dir`

dnl guess compression in use
for d in /usr/man /usr/share/man $pcp_man_dir
do
    for sd in man1 sman1
    do
	if test -f $d/$sd/man.1.gz
	then
	    have_gzipped_manpages=true
	    have_manpages=true
	    man_header=`$ZIP -d < $d/$sd/man.1.gz | head -1`
	    break
	elif test -f $d/$sd/man.1.bz2
	then
	    have_bzip2ed_manpages=true
	    have_manpages=true
	    man_header=`$BZIP2 -d < $d/$sd/man.1.bz2 | head -1`
	    break
	elif test -f $d/$sd/man.1.lzma
	then
	    have_lzmaed_manpages=true
	    have_manpages=true
	    man_header=`$LZMA -d < $d/$sd/man.1.lzma | head -1`
	    break
	elif test -f $d/$sd/man.1.xz
	then
	    have_xzed_manpages=true
	    have_manpages=true
	    man_header=`$XZ -d < $d/$sd/man.1.xz | head -1`
	    break
	elif test -f $d/$sd/man.1
	then
	    man_header=`head -1 $d/$sd/man.1`
	    have_manpages=true
	    break
	fi
    done
done
if test x"$man_header" = "x'\\\" t" -o x"$man_header" = "x'\\\" te" ; then
    need_old_tbl_header=true
fi
AC_SUBST(pcp_man_dir)
AC_SUBST(have_manpages)
AC_SUBST(have_gzipped_manpages)
AC_SUBST(have_bzip2ed_manpages)
AC_SUBST(have_lzmaed_manpages)
AC_SUBST(have_xzed_manpages)
AC_SUBST(need_old_tbl_header)

dnl public binaries
pcp_bin_dir=`eval echo $bindir`
pcp_bin_dir=`eval echo $pcp_bin_dir`
AC_SUBST(pcp_bin_dir)

pcp_sbin_dir=`eval echo $sbindir`
pcp_sbin_dir=`eval echo $pcp_sbin_dir`
AC_SUBST(pcp_sbin_dir)

dnl include files
pcp_inc_dir=`eval echo $includedir/pcp`
pcp_inc_dir=`eval echo $pcp_inc_dir`
AC_SUBST(pcp_inc_dir)

dnl books - pdfs, html
if test $target_os = linux; then
    pcp_books_dir=`eval echo $datarootdir/doc/pcp-doc`
else
    pcp_books_dir=`eval echo $datarootdir/doc/pcp`
fi
pcp_books_dir=`eval echo $pcp_books_dir`
pcp_html_dir=`eval echo $pcp_books_dir/html`
AC_SUBST(pcp_books_dir)
AC_SUBST(pcp_html_dir)

dnl icon pixmap files
if test $target_os = linux; then
    pcp_icons_dir=`eval echo $datarootdir/pcp-gui/pixmaps`
else
    pcp_icons_dir=`eval echo $datarootdir/pcp/pixmaps`
fi
pcp_icons_dir=`eval echo $pcp_icons_dir`
AC_SUBST(pcp_icons_dir)

test -z "$INKSCAPE" && AC_PATH_PROG(INKSCAPE, inkscape)
inkscape=$INKSCAPE
AC_SUBST(inkscape)

have_hicolor_icons=false
if test -d /usr/share/icons/hicolor -a -n "$INKSCAPE"
then
    AC_MSG_NOTICE([adding hicolor desktop icons to the build])
    have_hicolor_icons=true
fi
AC_SUBST(have_hicolor_icons)

dnl desktop application entries
pcp_desktop_dir=`eval echo $datarootdir/applications`
pcp_desktop_dir=`eval echo $pcp_desktop_dir`
AC_SUBST(pcp_desktop_dir)

dnl rc/startup files
AC_ARG_WITH(rcdir,[AC_HELP_STRING([--with-rcdir],[rc directory [SYSCONFDIR/rc.d]])],
                  [pcp_rc_dir=$withval], [
if $enable_systemd
then
    pcp_rc_dir="$pcp_share_dir/lib"
else
    pcp_rc_dir="$pcp_etc_dir/init.d"
fi])
AC_SUBST(pcp_rc_dir)

dnl rc sysconfig dir
AC_ARG_WITH(sysconfigdir,[AC_HELP_STRING([--with-sysconfigdir],[sysconfig directory [SYSCONFDIR/sysconfig]])],
                  [pcp_sysconfig_dir=$withval],
                  [pcp_sysconfig_dir=$pcp_etc_dir/sysconfig])
AC_SUBST(pcp_sysconfig_dir)

dnl logs
AC_ARG_WITH(logdir,[AC_HELP_STRING([--with-logdir],[log directory [LOCALSTATEDIR/log/pcp]])],
                  [pcp_log_dir=$withval],
                  [pcp_log_dir=$localstatedir/log/pcp])
pcp_log_dir=`eval echo $pcp_log_dir`
pcp_log_dir=`eval echo $pcp_log_dir`
AC_SUBST(pcp_log_dir)

pcp_sa_dir=$pcp_log_dir/sa
AC_SUBST(pcp_sa_dir)

AC_ARG_WITH(rundir,[AC_HELP_STRING([--with-rundir],[run directory [LOCALSTATEDIR/run/pcp]])],
                  [pcp_run_dir=$withval], [
if test -d /run
then
    pcp_run_dir="/run/pcp"
else
    pcp_run_dir="$localstatedir/run/pcp"
fi])
pcp_run_dir=`eval echo $pcp_run_dir`
pcp_run_dir=`eval echo $pcp_run_dir`
AC_SUBST(pcp_run_dir)

dnl world-writeable temporary files directory
AC_ARG_WITH(tmpdir,[AC_HELP_STRING([--with-tmpdir],[tmp directory [LOCALSTATEDIR/tmp]])],
                   [pcp_tmpfile_dir=$withval],
                   [pcp_tmpfile_dir=$localstatedir/tmp])
pcp_tmpfile_dir=`eval echo $pcp_tmpfile_dir`
pcp_tmpfile_dir=`eval echo $pcp_tmpfile_dir`
AC_SUBST(pcp_tmpfile_dir)

dnl non-world-writeable status files directory
pcp_tmp_dir=`eval echo $pcp_var_dir/tmp`
AC_SUBST(pcp_tmp_dir)

dnl doc directory
AC_ARG_WITH(docdir,[AC_HELP_STRING([--with-docdir],[docs directory [DOCDIR/pcp-VERSION]])],
                   [pcp_doc_dir=$withval],
                   [PACKAGE=pcp-${PACKAGE_VERSION}; pcp_doc_dir=$docdir])
pcp_doc_dir=`eval echo $pcp_doc_dir`
pcp_doc_dir=`eval echo $pcp_doc_dir`
AC_SUBST(pcp_doc_dir)

dnl demos directory
AC_ARG_WITH(demosdir,[AC_HELP_STRING([--with-demosdir],[run directory [DATADIR/pcp/demos]])],
                   [pcp_demos_dir=$withval],
                   [pcp_demos_dir=$pcp_share_dir/demos])
AC_SUBST(pcp_demos_dir)

if test -z "$XCONFIRM"
then
    AC_PATH_PROG(ac_xconfirm_prog, xconfirm, $pcp_bin_dir/pmconfirm)
else
    ac_xconfirm_prog=$XCONFIRM
fi
AC_SUBST(ac_xconfirm_prog)

dnl Check for FNDELAY defined in <fcntl.h>
if test "$ac_cv_header_fcntl_h" = "yes"
then
    AC_MSG_CHECKING([for FNDELAY in fcntl.h])
    AC_TRY_COMPILE([#include <fcntl.h>],
	[ int i = FNDELAY; ],
	AC_DEFINE(HAVE_FNDELAY, [1], [FNDELAY macro])
	AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
fi

dnl check for zpool_vdev_name API style from <libzfs.h>
if test "$ac_cv_header_libzfs_h" = "yes"
then
    AC_MSG_CHECKING([for 5-argument style zpool_vdev_name])
    AC_TRY_COMPILE([#include <libzfs.h>],
	[ libzfs_handle_t *zh;
	  zpool_handle_t *zp;
	  nvlist_t *np;
	  (void) zpool_vdev_name(zh, zp, np, B_FALSE, B_FALSE);
	],
	AC_DEFINE(HAVE_ZPOOL_VDEV_NAME_5ARG, [1], [5-arg zpool_vdev_name])
	AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

    AC_MSG_CHECKING([for 4-argument style zpool_vdev_name])
    AC_TRY_COMPILE([#include <libzfs.h>],
	[ libzfs_handle_t *zh;
	  zpool_handle_t *zp;
	  nvlist_t *np;
	  (void) zpool_vdev_name(zh, zp, np, B_FALSE);
	],
	AC_DEFINE(HAVE_ZPOOL_VDEV_NAME_4ARG, [1], [4-arg zpool_vdev_name])
	AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
fi

dnl check for zfs_iter_snapshots API style from <libzfs.h>
if test "$ac_cv_header_libzfs_h" = "yes"
then
    AC_MSG_CHECKING([for 4-argument style zfs_iter_snapshots])
    AC_TRY_COMPILE([#include <libzfs.h>],
	[ zfs_handle_t *zh;
	  zfs_iter_f callback;
	  (void)zfs_iter_snapshots(zh, B_FALSE, callback, NULL);
	],
	AC_DEFINE(HAVE_ZFS_ITER_SNAPSHOTS_4ARG, [1], [4-arg zfs_iter_snapshots])
	AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

    AC_MSG_CHECKING([for 3-argument style zfs_iter_snapshots])
    AC_TRY_COMPILE([#include <libzfs.h>],
	[ zfs_handle_t *zh;
	  zfs_iter_f callback;
	  (void)zfs_iter_snapshots(zh, callback, NULL);
	],
	AC_DEFINE(HAVE_ZFS_ITER_SNAPSHOTS_3ARG, [1], [3-arg zfs_iter_snapshots])
	AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
fi

dnl Check for Network Security Services (NSS) and
dnl Simple Authentication and Security Layer (SASL)
if test "$do_secure" = "check" -o "$do_secure" = "yes"
then
    enable_secure=true

    saved_CFLAGS="$CFLAGS"
    saved_CPPFLAGS="$CPPFLAGS"
    NSS_INC_DIRS="-I/usr/include/nss -I/usr/include/nss3"
    NSPR_INC_DIRS="-I/usr/include/nspr -I/usr/include/nspr4"
    CFLAGS="$CFLAGS $NSS_INC_DIRS $NSPR_INC_DIRS"
    CPPFLAGS="$CPPFLAGS $NSS_INC_DIRS $NSPR_INC_DIRS"

    AC_CHECK_HEADERS([nss/nss.h], [NSSCFLAGS=-I/usr/include/nss], [
	AC_CHECK_HEADERS([nss3/nss.h], [NSSCFLAGS=-I/usr/include/nss3], [
	    enable_secure=false
	    if test "$do_secure" = "yes"
	    then
		AC_MSG_ERROR([cannot enable secure sockets mode - no NSS header])
	    fi
	])
    ])
    AC_SUBST(NSSCFLAGS)

    AC_CHECK_HEADERS([nspr/nspr.h], [NSPRCFLAGS=-I/usr/include/nspr], [
	AC_CHECK_HEADERS([nspr4/nspr.h], [NSPRCFLAGS=-I/usr/include/nspr4], [
	    enable_secure=false
	    if test "$do_secure" = "yes"
	    then
		AC_MSG_ERROR([cannot enable secure sockets mode - no NSPR header])
	    fi
	])
    ])
    AC_SUBST(NSPRCFLAGS)

    AC_CHECK_HEADERS([sasl/sasl.h], [SASLCFLAGS=-I/usr/include/sasl], [
	enable_secure=false
	if test "$do_secure" = "yes"
	then
	    AC_MSG_ERROR([cannot enable secure sockets mode - no SASL header])
	fi
    ])
    AC_SUBST(SASLCFLAGS)

    AC_CHECK_LIB(sasl2, sasl_server_init, [lib_for_sasl="-lsasl2"], [
	enable_secure=false
	if test "$do_secure" = "yes"
	then
	    AC_MSG_ERROR([cannot enable secure sockets mode - no SASL library])
	fi
    ])
    AC_SUBST(lib_for_sasl)

    AC_CHECK_LIB(ssl, SSL_ImportFD, [lib_for_ssl="-lssl"], [
	AC_CHECK_LIB(ssl3, SSL_ImportFD, [lib_for_ssl="-lssl3"], [
	    enable_secure=false
	    if test "$do_secure" = "yes"
	    then
		AC_MSG_ERROR([cannot enable secure sockets mode - no SSL library])
	    fi
	])
    ])
    AC_SUBST(lib_for_ssl)

    AC_CHECK_LIB(nss, NSS_Init, [lib_for_nss="-lnss"], [
	AC_CHECK_LIB(nss3, NSS_Init, [lib_for_nss="-lnss3"], [
	    enable_secure=false
	    if test "$do_secure" = "yes"
	    then
		AC_MSG_ERROR([cannot enable secure sockets mode - no NSS library])
	    fi
	])
    ])
    AC_SUBST(lib_for_nss)

    AC_CHECK_LIB(nspr, PR_Init, [lib_for_nspr="-lnspr"], [
	AC_CHECK_LIB(nspr4, PR_Init, [lib_for_nspr="-lnspr4"], [
	    enable_secure=false
	    if test "$do_secure" = "yes"
	    then
		AC_MSG_ERROR([cannot enable secure sockets mode - no NSPR library])
	    fi
	])
    ])
    AC_SUBST(lib_for_nspr)

    if test "$enable_secure" = "true"
    then
	AC_DEFINE(HAVE_SECURE_SOCKETS, [1], [Encrypted sockets])
    fi
    AC_SUBST(enable_secure)

    CPPFLAGS="$saved_CPPFLAGS"
    CFLAGS="$saved_CFLAGS"
fi

dnl check for -latomic, needed for some -march=i386 builds with i686 c++ distro headers
AC_CHECK_LIB(atomic, __atomic_fetch_add_4, [lib_for_atomic="-latomic"])
AC_SUBST(lib_for_atomic)

dnl Check for decompression libraries
enable_lzma=false
enable_decompression=false
AS_IF([test "x$do_decompression" != "xno"], [
    # Check for -llzma
    enable_lzma=true
    PKG_CHECK_MODULES([lzma], [liblzma],
        [AC_CHECK_LIB(lzma, lzma_index_stream_flags,
		      [lib_for_lzma="-llzma"],
		      [enable_lzma=false])
        ],[enable_lzma=false])

    AC_CHECK_HEADERS([lzma.h], [], [enable_lzma=false])

    if test "$enable_lzma" = "true"
    then
        AC_SUBST(lib_for_lzma)
	AC_SUBST(lzma_CFLAGS)
	AC_DEFINE(HAVE_LZMA_DECOMPRESSION, [1], [lzma decompression])
	enable_decompression=true
    fi

    if test "$do_decompression" != "check" -a "$enable_decompression" != "true"
    then
	AC_MSG_ERROR([cannot enable transparent decompression - no supported compression formats])
    fi

    if test "$enable_decompression" = "true"
    then
	AC_DEFINE(HAVE_TRANSPARENT_DECOMPRESSION, [1], [Transparent decompression])
    fi
])
AC_SUBST(enable_decompression)
AC_SUBST(enable_lzma)

dnl check for array sessions
if test -f /usr/include/sn/arsess.h
then
    pcp_mpi_dirs=libpcp_mpi\ libpcp_mpiread
else
    pcp_mpi_dirs=
fi
AC_SUBST(pcp_mpi_dirs)

dnl check for Unix Domain socket family structure
AC_MSG_CHECKING([for struct sockaddr_un in sys/un.h])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #ifdef HAVE_SYS_SOCKET_H
    #include <sys/socket.h>
    #endif
    #ifdef HAVE_SYS_UN_H
    #include <sys/un.h>
    #endif
], [ struct sockaddr_un sa; sa.sun_family = AF_UNIX; ],
AC_DEFINE(HAVE_STRUCT_SOCKADDR_UN, [1], [sockaddr_un type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check for Linux Unix Domain socket credential structure
AC_MSG_CHECKING([for struct ucred in sys/socket.h])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #ifdef HAVE_SYS_SOCKET_H
    #include <sys/socket.h>
    #endif
    #ifdef HAVE_SYS_UN_H
    #include <sys/un.h>
    #endif
], [ struct ucred ucred; ucred.uid = 0; ],
AC_DEFINE(HAVE_STRUCT_UCRED, [1], [ucred type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check for struct timespec in <time.h>
AC_MSG_CHECKING([for struct timespec in time.h])
AC_TRY_COMPILE([
    #include <time.h>
], [ struct timespec foo; ],
AC_DEFINE(HAVE_STRUCT_TIMESPEC, [1], [timespec type]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl check if we have IRIX style altzone
AC_MSG_CHECKING([for altzone in time.h])
AC_TRY_COMPILE([
    #include <time.h>
], [ time_t az = altzone; ],
AC_DEFINE(HAVE_ALTZONE, [1], [altzone global]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl If there is no altzone, check if strftime can handle %z
AC_MSG_CHECKING([if strftime knows about %z])
AC_TRY_RUN(
[
#include <time.h>
int main () {
    char b[32]="";
    time_t t = time(NULL);
    struct tm * t1 = localtime (&t);
    if (strftime (b, 32, "%z", t1) < 3)
       return (1);
    if (strcmp(b, "%z") == 0)
       return(1);
    return (0);
}
], AC_DEFINE(HAVE_STRFTIME_z, [1], [strftime with %z]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no), AC_MSG_RESULT(no))

dnl does strerror_r return char * a la GNU
dnl (as opposed to the int return for XSI-compliant variants)
AC_MSG_CHECKING([if strerror_r returns char *])
AC_TRY_COMPILE(
    [#include <string.h>], [strerror_r(0, NULL, 0)[0];],
    AC_DEFINE(HAVE_STRERROR_R_PTR, [1], [strerror_r return]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl first check for readline on its own then with curses
savedLIBS=$LIBS
LIBS=
lib_for_curses=
lib_for_readline=
AC_CHECK_FUNC(readline,,
    [
	AC_CHECK_LIB(readline, readline,,
	    [
		dnl AC seems to cache lib/func results
		dnl so use another readline func here
		AC_CHECK_LIB(readline, add_history,,,[-lcurses])
	    ])
    ])
if test $ac_cv_func_readline = yes
then
    AC_DEFINE(HAVE_READLINE, [1], [readline API])
elif test $ac_cv_lib_readline_readline = yes
then
    AC_DEFINE(HAVE_READLINE, [1], [readline API])
    lib_for_readline=-lreadline
elif test $ac_cv_lib_readline_add_history = yes
then
    AC_DEFINE(HAVE_READLINE, [1], [readline API])
    lib_for_curses=-lcurses
    lib_for_readline=-lreadline
fi
AC_SUBST(lib_for_readline)
AC_SUBST(lib_for_curses)
LIBS=$savedLIBS

dnl Look for zlib
PKG_CHECK_MODULES([zlib], [zlib >= 1.0.0], [have_zlib=true], [have_zlib=false])
AC_SUBST(HAVE_ZLIB, [$have_zlib])

dnl Check if we have AI_ADDRCONFIG
AC_MSG_CHECKING([for AI_ADDRCONFIG])
AC_TRY_COMPILE(
[
    #include <netdb.h>
    int test = AI_ADDRCONFIG;
],
[
], AC_DEFINE(HAVE_AI_ADDRCONFIG, [1], [AI_ADDRCONFIG macro]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))

dnl Find external source tarballs for packaging

have_webapps=false
if test $do_webapps != "no"
then
    AC_MSG_NOTICE([adding web applications to the build])
    have_webapps=true
fi
AC_SUBST(have_webapps)

dnl Capture special options passed to configure
pcp_prefix=`eval echo $prefix`
AC_SUBST(pcp_prefix)
AC_SUBST(PACKAGE_CONFIGURE)

dnl
dnl output files
dnl

AC_OUTPUT(
dnl   Build definitions for use in Makefiles
    src/include/builddefs
dnl   PCP paths and other defs
    src/include/pcp.conf
dnl   Linux Software Map entry
    pcp.lsm
dnl   Preamble for deb install scripts
    debian/pcp.preinst.head
    debian/pcp.postinst.head
dnl   Preamble for tar install scripts
    build/tar/preinstall.head
    build/tar/postinstall.head
dnl   Build definitions for use in packaging
    build/GNUlocaldefs
    build/mac/uninstall-pcp
)

dnl verbose diagnostics
dnl
dnl echo config.status: settings dump begin
dnl grep '^S.".*=' config.status
dnl echo config.status: settings dump end