File: configure.ac

package info (click to toggle)
squid 7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,440 kB
  • sloc: cpp: 184,513; ansic: 12,442; sh: 5,688; makefile: 5,247; perl: 2,560; sql: 326; python: 240; awk: 141; sed: 1
file content (2622 lines) | stat: -rw-r--r-- 93,195 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
## Copyright (C) 1996-2025 The Squid Software Foundation and contributors
##
## Squid software is distributed under GPLv2+ license and includes
## contributions from numerous individuals and organizations.
## Please see the COPYING and CONTRIBUTORS files for details.
##

AC_INIT([Squid Web Proxy],[7.2],[https://bugs.squid-cache.org/],[squid])
AC_PREREQ(2.61)
AC_CONFIG_HEADERS([include/autoconf.h])
AC_CONFIG_AUX_DIR(cfgaux)
AC_CONFIG_SRCDIR([src/main.cc])
AM_INIT_AUTOMAKE([tar-ustar nostdinc subdir-objects dist-xz])
AC_REVISION($Revision$)dnl
AC_PREFIX_DEFAULT(/usr/local/squid)
AM_MAINTAINER_MODE

m4_include([acinclude/ax_with_prog.m4])
m4_include([acinclude/init.m4])
m4_include([acinclude/squid-util.m4])
m4_include([acinclude/compiler-flags.m4])
m4_include([acinclude/os-deps.m4])
m4_include([acinclude/krb5.m4])
m4_include([acinclude/ldap.m4])
m4_include([acinclude/pam.m4])
m4_include([acinclude/pkg.m4])
m4_include([acinclude/tdb.m4])
m4_include([acinclude/lib-checks.m4])
m4_include([acinclude/ax_cxx_compile_stdcxx.m4])
m4_include([acinclude/win32-sspi.m4])

PRESET_CFLAGS="$CFLAGS"
PRESET_CXXFLAGS="$CXXFLAGS"
PRESET_LDFLAGS="$LDFLAGS"

dnl Set default LDFLAGS
AS_IF([test "x$LDFLAGS" = "x"],[LDFLAGS="-g"])

# check for host OS detail
AC_CANONICAL_HOST
AC_MSG_CHECKING([simplified host os])
simple_host_os=`echo $host_os|sed 's/[0-9].*//g;s/-.*//g'`
squid_host_os_version=`echo $host_os|tr -d "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-"`
AS_IF([test -n "$squid_host_os_version"],[
  squid_host_os="`echo $simple_host_os| sed s/$squid_host_os_version//g`"
],[
  squid_host_os="$simple_host_os"
])
AC_MSG_RESULT($squid_host_os (version $squid_host_os_version))
# on windows squid_host_os is either mingw or cygwin, version is 32

AS_IF([test -e /etc/os-release],[
  squid_build_os_release_name=`grep '^PRETTY_NAME=' /etc/os-release | sed 's/^[[^"]]*"//;s/".*$//'`
  AS_IF([test "x$squid_build_os_release_name" = "x"],[
    squid_build_os_release_name=`grep '^NAME=' /etc/os-release | sed 's/^[[^"]]*"//;s/".*$//'`
  ])
  AS_IF([test "x$squid_build_os_release_name" != "x"],[
    AC_MSG_NOTICE([Building on $squid_build_os_release_name])
  ])
])

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX

# AC_USE_SYSTEM_EXTENSIONS should be called before any macros that run the C compiler.
AC_USE_SYSTEM_EXTENSIONS

AC_LANG([C++])

# Some compilers can produce faster executables when its used.
# But building inside a virtual machine environment has been found to
# cause random Illegal Instruction errors due to mis-detection of CPU.
AC_ARG_ENABLE(arch-native,
  AS_HELP_STRING([--enable-arch-native],[Some compilers offer CPU-specific
                 optimizations with the -march=native parameter.
                 This flag enables the optimization, by default disabled,
                 provided that the compiler supports it. Enabling this
                 optimization may cause crashes due to illegal instruction errors
                 when Squid is run on a CPU different from the one it is built on,
                 and in some containerized or virtualized environments]), [
  SQUID_YESNO([$enableval],[--enable-arch-native])
])
AC_MSG_NOTICE([CPU arch native optimization enabled: ${enable_arch_native:=no}])
AS_IF([test "x${enable_arch_native}" = "xyes"],[
  # XXX: Fail if the explicitly requested native optimization is not available.
  # TODO: Make this a tristate yes/no/auto.
  SQUID_CC_CHECK_ARGUMENT([squid_cv_check_marchnative],[-march=native])
])

# If the user did not specify a C++ version.
user_cxx=`echo "$PRESET_CXXFLAGS" | grep -o -E "(-)std="`
AS_IF([test "x$user_cxx" = "x"],[
  # Check for C++17 compiler support
  # May change CXX.
  AX_CXX_COMPILE_STDCXX([17],[noext],[mandatory])
])

# Prerequisite: CXX has been finalized.
# BUILDCXXFLAGS are defined later, after CXXFLAGS have been finalized.
AC_ARG_VAR([BUILDCXX],[path to compiler for building compile-time tools. e.g. cf_gen])
AS_IF([test "x$HOSTCXX" != "x" -a "x$BUILDCXX" = "x"],[
  AC_MSG_WARN([Cross-compiling with HOSTCXX is deprecated. Use BUILDCXX instead.])
  BUILDCXX="$HOSTCXX"
])
AS_IF([test "x$BUILDCXX" = "x"],[
  BUILDCXX="$CXX"
  AS_IF([test "x$squid_cv_check_marchnative" = "xyes"],[
    CXXFLAGS="$CXXFLAGS -march=native"
  ])
])
AC_SUBST(BUILDCXX)

# test for programs
AC_PROG_RANLIB
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_EGREP

AC_PATH_PROG(SH, sh, /bin/sh)
AC_PATH_PROG(FALSE, false, /usr/bin/false)
AC_PATH_PROG(TRUE, true, /usr/bin/true)
AC_PATH_PROG(MV, mv, $FALSE)
AC_PATH_PROG(MKDIR, mkdir, $FALSE)
AC_PATH_PROG(LN, ln, cp)
AC_PATH_PROG(CHMOD, chmod, $FALSE)
AC_PATH_PROG(TR, tr, $FALSE)
AC_PATH_PROG(RM, rm, $FALSE)
dnl Libtool 2.2.6 requires: rm -f
RM="$RM -f"

PKG_PROG_PKG_CONFIG
AS_IF([test "x$PKG_CONFIG" = "x"],[
  AC_MSG_WARN([pkg-config not found. Many optional features with external dependencies will not be enabled by default, usually without further warnings.])
])


AC_PATH_PROG(PERL, perl, none)
AS_IF([test "x$ac_cv_path_PERL" = "xnone"],[
  AC_MSG_FAILURE([Perl is required to compile Squid. Please install Perl and then re-run configure ])
])
AC_PATH_PROG(POD2MAN, pod2man, $FALSE)
AM_CONDITIONAL(ENABLE_POD2MAN_DOC, test "x${ac_cv_path_POD2MAN}" != "x$FALSE")

AC_PATH_PROG(AR, ar, $FALSE)
AR_R="$AR r"
AC_SUBST(AR_R)

AC_PATH_PROG(LINUXDOC, linuxdoc, $FALSE)
AM_CONDITIONAL(ENABLE_RELEASE_DOCS, test "x${ac_cv_path_LINUXDOC}" != "x$FALSE")

SQUID_RELEASE=`echo $VERSION | cut -d. -f1`
AC_SUBST(SQUID_RELEASE)

# pre-define DEFAULT_PREFIX, some modules need it.
AS_IF([test "${prefix}" = "NONE"],[squid_prefix=$ac_default_prefix],[squid_prefix=$prefix])
AC_DEFINE_UNQUOTED(DEFAULT_PREFIX,[$squid_prefix],[The install prefix])

AC_ARG_ENABLE(strict-error-checking,
  AS_HELP_STRING([--disable-strict-error-checking],[By default squid is compiled
                 with all possible static compiler error-checks enabled.
                 This flag disables the behavior]), [
  SQUID_YESNO([$enableval],[--enable-strict-error-checking])
])
AC_MSG_NOTICE([strict error checking enabled: ${enable_strict_error_checking:=yes}])

# LT_INIT requires libtool v2, might as well state it loud
LT_PREREQ([2.2])
LT_INIT([dlopen])
AS_IF([test "x$ac_top_build_prefix" != "x"],[
  # LTDL v3-v7 macros assume the autoconf 2.62 variable top_build_prefix is defined
  # But from autoconf 2.64 its called ac_top_build_prefix and not automatically added to the Makefile
  # This fixes Linux LTDLv3-v7, and BSD LTDL v2.2
  top_build_prefix=${ac_top_build_prefix}
  AC_SUBST(top_build_prefix)
])
LTDL_INIT

dnl LibTool environment is now prepared for setup. Check that it is usable and initialize.
LT_LIB_DLLOAD

# Do we need these unconditionally for "make distcheck" to work?
AC_SUBST(INCLTDL)
AC_SUBST(LIBLTDL)

AC_MSG_CHECKING(whether to use loadable modules)
AS_IF([test "x${enable_shared:=yes}" = "xyes"],[AC_DEFINE(USE_LOADABLE_MODULES,1,[Support Loadable Modules])])
AM_CONDITIONAL(ENABLE_LOADABLE_MODULES, test "x${enable_shared:=yes}" = "xyes")
AC_MSG_RESULT([$enable_shared])

SQUID_CC_GUESS_VARIANT
SQUID_CC_GUESS_OPTIONS

dnl find out the exe extension for this platform.
dnl If it is not empty, use it for CGI as well.
AC_EXEEXT
AC_OBJEXT
AS_IF([test "x$EXEEXT" = "x"],[CGIEXT=".cgi"],[CGIEXT=""])
AC_SUBST(CGIEXT)

AM_CONDITIONAL(ENABLE_WIN32SPECIFIC,[test "x$squid_host_os" = "xmingw"])
AM_CONDITIONAL(ENABLE_WIN32_IPC,[test "x$squid_host_os" = "xmingw"])

AS_CASE(["$squid_host_os"],
  [mingw],[
    CFLAGS="$CFLAGS -mthreads"
    CXXFLAGS="$CXXFLAGS -mthreads -static-libgcc -static-libstdc++"
    dnl Check for Winsock only on MinGW
    SQUID_CHECK_WINSOCK_LIB
    AC_CHECK_HEADERS([ws2tcpip.h winsock2.h windows.h io.h],,,[
#if HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#if HAVE_WINDOWS_H
#include <windows.h>
#endif
    ])
    MINGW_LIBS="-lmingwex"
    AC_SUBST(MINGW_LIBS)
    AC_CHECK_FUNCS([fsync])
  ],

  [freebsd],[
    # FreeBSD places local libraries and packages in /usr/local
    CFLAGS="$CFLAGS -I/usr/local/include"
    CXXFLAGS="$CXXFLAGS -I/usr/local/include"
    LDFLAGS="$LDFLAGS -L/usr/local/lib -Wl,-R/usr/local/lib"
  ]
)

dnl Substitutions
AC_DEFINE_UNQUOTED(CONFIG_HOST_TYPE, "$host",[Host type from configure])

AC_DEFINE_UNQUOTED(SQUID_CONFIGURE_OPTIONS, "$ac_configure_args",
                       [configure command line used to configure Squid])

CACHE_EFFECTIVE_USER="nobody"
AC_ARG_WITH(default-user,
  AS_HELP_STRING([--with-default-user=USER],[System user account for squid permissions. Default: nobody]),
 [ CACHE_EFFECTIVE_USER="$withval" ]
)
AC_SUBST(CACHE_EFFECTIVE_USER)

DEFAULT_LOG_DIR="$localstatedir/logs"
AC_ARG_WITH(logdir,
  AS_HELP_STRING([--with-logdir=PATH],
    [Default location for squid logs. default: PREFIX/var/logs]),[
  AS_CASE([$withval],
    [yes|no],[AC_MSG_ERROR([--with-logdir requires a directory PATH. --with-logdir=PATH])],
    [DEFAULT_LOG_DIR="$withval"]
  )
])
AC_SUBST(DEFAULT_LOG_DIR)

DEFAULT_PID_FILE="$localstatedir/run/@SERVICE_NAME@.pid"
AC_ARG_WITH(pidfile,
  AS_HELP_STRING([--with-pidfile=PATH],
    [Default location for squid pid file. Default: PREFIX/var/run/squid.pid]),[
  AS_CASE([$withval],
    [yes|no],[AC_MSG_ERROR([--with-pidfile requires a file PATH. --with-pidfile=PATH])],
    [DEFAULT_PID_FILE="$withval"]
  )
])
AC_SUBST(DEFAULT_PID_FILE)

DEFAULT_SWAP_DIR="$localstatedir/cache/squid"
AC_ARG_WITH(swapdir,
  AS_HELP_STRING([--with-swapdir=PATH],
    [Default location for squid cache directories. Default: PREFIX/var/cache/squid]),[
  AS_CASE([$withval],
    [yes|no],[AC_MSG_ERROR([--with-swapdir requires a directory PATH. --with-swapdir=PATH])],
    [DEFAULT_SWAP_DIR="$withval"]
  )
])
AC_SUBST(DEFAULT_SWAP_DIR)

dnl Set Default CFLAGS
AS_IF([test "x$PRESET_CFLAGS" = "x"],[
  AS_IF([test "$squid_cv_compiler" = "gcc"],[
    # TODO check if these exceptions are still necessary
    AS_CASE(["$host"],
      [*-sun-sunos*],[
        # sunos has too many warnings for -Wall to be useful
      ],
      [CFLAGS="$squid_cv_cc_option_wall $CFLAGS"]
    )
  ],[
    AS_CASE(["$host"],
      [*mips-sgi-irix6.*],[
        # suggested by Rafael Seidl <rafaels@cthulhu.engr.sgi.com>
        CFLAGS="$squid_cv_cc_option_optimize -OPT:Olimit=0:space=OFF \
                -woff 1009,1014,1110,1116,1183,1185,1188,1204,1230,1233,1355 \
                -Wl,-woff,85,-woff,84,-woff,134 \
                -nostdinc -I/usr/include -D_BSD_SIGNALS $CFLAGS"
        CXXFLAGS="$squid_cv_cc_option_optimize -OPT:Olimit=0:space=OFF \
                  -woff 1009,1014,1110,1116,1183,1185,1188,1204,1230,1233,1355 \
                  -Wl,-woff,85,-woff,84,-woff,134 \
                  -nostdinc -I/usr/include -D_BSD_SIGNALS $CXXFLAGS"
    ])
  ])
])

AC_MSG_CHECKING([compiler name-version])
squid_cv_cc_name=`$CC --version | head -1 | cut -f1 -d" "`
AS_CASE([$squid_cv_cc_name],
  [gcc|clang],[squid_cv_cc_majversion=`$CC -dumpversion | cut -f1 -d.`],
  [squid_cv_cc_majversion="unknown"]
)
squid_cv_cc_simplified="$squid_cv_cc_name-$squid_cv_cc_majversion"
AC_MSG_RESULT($squid_cv_cc_simplified)

# warning flags

# -Wall
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([$squid_cv_cc_option_wall])

# -Wextra
AS_IF([test "$squid_cv_cc_simplified" = "gcc-4"],[
    AC_MSG_NOTICE([skipping -Wextra on $squid_cv_cc_simplified])
],[
    SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wextra])

    # Now disable or configure certain warnings enabled by -Wextra

    # -Wunused-private-field causes a huge number of false positives
    #    in unit tests. Disable that
    SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wno-unused-private-field])

    # ...=5: Do not trust comments about fallthrough cases (GCC).
    SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wimplicit-fallthrough=5])
    AS_IF([test "x$squid_cv_cc_arg_wimplicit_fallthrough_5" != "xyes"], [
        SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wno-implicit-fallthrough])
    ])
])

# useful warnings that may not be included in -Wall -Wextra
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wpointer-arith])
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wwrite-strings])
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wcomments])
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wshadow])
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Wmissing-declarations])
SQUID_CC_ADD_CXXFLAG_WARNING_IF_SUPPORTED([-Woverloaded-virtual])

dnl CentOS (and RHEL) still define ntohs() using deprecated C++ features
SQUID_CC_REQUIRE_ARGUMENT([ac_cv_require_wno_deprecated_register],[-Werror -Wno-deprecated-register],[[#include <arpa/inet.h>]],[[int fox=ntohs(1);]])

AS_IF([test "x$enable_strict_error_checking" != "xno"],[
  SQUID_CFLAGS="$SQUID_CFLAGS $squid_cv_cc_option_werror"
  SQUID_CXXFLAGS="$SQUID_CXXFLAGS $squid_cv_cxx_option_werror"
])

AS_IF([test "x$ac_cv_require_wno_deprecated_register" = "xyes"],[
  SQUID_CXXFLAGS="$SQUID_CXXFLAGS -Wno-deprecated-register"
])

# squid_cv_cc_arg_pipe is set by SQUID_CC_GUESS_OPTIONS
SQUID_CXXFLAGS="$SQUID_CXXFLAGS $squid_cv_cc_arg_pipe"
SQUID_CFLAGS="$SQUID_CFLAGS $squid_cv_cc_arg_pipe"

# possibly include some build info tag into squid -v
SQUID_EMBED_BUILD_INFO

AC_ARG_ENABLE(optimizations,
  AS_HELP_STRING([--disable-optimizations],
                 [Do not compile Squid with compiler optimizations enabled.
                  Optimization is good for production builds, but not
                  good for debugging. During development, use
                  --disable-optimizations to reduce compilation times
                  and allow easier debugging.]), [
  AS_IF([test "x$enableval" = "xno"],[
    AC_MSG_NOTICE([Disabling compiler optimizations (-O flag)])
    CFLAGS="`echo $CFLAGS | sed -e 's/-O[[0-9g]]*//'`"
    CXXFLAGS="`echo $CXXFLAGS | sed -e 's/-O[[0-9g]]*//'`"
  ])
])

dnl Nasty hack to get autoconf 2.64 on Linux to run.
dnl all other uses of RUN_IFELSE are wrapped inside CACHE_CHECK which breaks on 2.64
AC_RUN_IFELSE([AC_LANG_SOURCE([[ int main(int argc, char **argv) { return 0; } ]])],[],[],[:])

AH_TEMPLATE(XMALLOC_STATISTICS,[Define to have malloc statistics])
AC_ARG_ENABLE(xmalloc-statistics,
  AS_HELP_STRING([--enable-xmalloc-statistics],
                 [Show malloc statistics in status page]), [
  SQUID_YESNO([$enableval],[--enable-xmalloc-statistics])
])
SQUID_DEFINE_BOOL(XMALLOC_STATISTICS,${enable_xmalloc_statistics:=no},
    [Show malloc statistics in status page])
AC_MSG_NOTICE([xmalloc stats display: $enable_xmalloc_statistics])

squid_opt_aufs_threads=""
AC_ARG_WITH(aufs-threads,
  AS_HELP_STRING([--with-aufs-threads=N_THREADS],
    [Tune the number of worker threads for the aufs object store.]), [
  AS_CASE([$withval],
    [@<:@0-9@:>@*],[squid_opt_aufs_threads=$withval],
    AC_MSG_ERROR(--with-aufs-threads expects a numeric argument)
  )
])
AS_IF([test "x$squid_opt_aufs_threads" != "x"],[
  AC_MSG_NOTICE([With $squid_opt_aufs_threads aufs threads])
  AC_DEFINE_UNQUOTED(AUFS_IO_THREADS,$squid_opt_aufs_threads,
    [Defines how many threads aufs uses for I/O])
])

AC_DEFUN([LIBATOMIC_CHECKER],[
  AC_MSG_CHECKING(whether linking $1 -latomic works)
  AC_LINK_IFELSE([
    AC_LANG_SOURCE([[
#include <atomic>
#include <cstdint>
      int
      main(int argc, char **) {
          return (
              std::atomic<uint8_t>(uint8_t(argc)).exchange(0) &&
              std::atomic<uint64_t>{}.is_lock_free()
              ) ? 0 : 1;
      }
  ]])],[
    AC_MSG_RESULT(yes)
    libatomic_checker_result="yes"],[
    AC_MSG_RESULT(no)
    libatomic_checker_result="no"
])])

## check for atomics library before anything that might need it
SQUID_STATE_SAVE(LIBATOMIC)
LIBATOMIC_CHECKER(without)
AS_IF([test "x$libatomic_checker_result" = "xno"],[
  LIBS="$LIBS -latomic"
  LIBATOMIC_CHECKER(with)
  AS_IF([test "x$libatomic_checker_result" = "xyes"],[
    ATOMICLIB="-latomic"],[
    AC_MSG_ERROR([Required library libatomic not found.])
])])
SQUID_STATE_ROLLBACK(LIBATOMIC)
AC_SUBST(ATOMICLIB)

SQUID_AUTO_LIB(psapi,[Windows PSAPI.dll],[LIBPSAPI])
SQUID_CHECK_LIB_WORKS(psapi,[
  CPPFLAGS="$LIBPSAPI_CFLAGS $CPPFLAGS"
  LIBS="$LIBPSAPI_PATH $LIBS"
  AC_CHECK_LIB([psapi],[K32GetProcessMemoryInfo],[
    LIBPSAPI_LIBS="-lpsapi"
    AC_CHECK_HEADERS([psapi.h],,,[
#if HAVE_WINDOWS_H
#include <windows.h>
#endif
    ])
  ])
])

AC_SEARCH_LIBS([shm_open], [rt])
AS_IF([test "x$ac_cv_search_shm_open" != "xno"],[
  AC_DEFINE(HAVE_SHM,1,[Support shared memory features])
])

squid_disk_module_candidates=
AC_ARG_ENABLE(disk-io,
  AS_HELP_STRING([--enable-disk-io="list of modules"],
    [Build support for the list of disk I/O modules.
     Set without a value or omitted, all available modules will be built.
     See src/DiskIO for a list of available modules, or
     Programmers Guide section on DiskIO
     for details on how to build your custom disk module]),
  AS_CASE(["$enableval"],
    [yes],[],
    [no|none],[enable_disk_io="no"],
    [
      enable_disk_io="yes"
      squid_disk_module_candidates="$enableval"
  ])
)
AS_IF([test "x${enable_disk_io:=yes}" = "xyes"],[
  SQUID_LOOK_FOR_MODULES([$srcdir/src/DiskIO],[squid_disk_module_candidates])
  AS_IF([test "x$ac_cv_search_shm_open" = "xno"],[
    squid_disk_module_candidates=`echo "$squid_disk_module_candidates" | sed 's/IpcIo//g'`
  ])
])
SQUID_CLEANUP_MODULES_LIST([squid_disk_module_candidates])
SQUID_CHECK_EXISTING_MODULES([$srcdir/src/DiskIO],[squid_disk_module_candidates])
AC_MSG_NOTICE([DiskIO modules built: ${squid_disk_module_candidates:-none}])
SQUID_DEFINE_BOOL(USE_DISKIO,$enable_disk_io,[DiskIO modules are expected to be available.])

dnl Some autoconf.h defines we might enable later...
AC_ARG_WITH(pthreads,AS_HELP_STRING([--without-pthreads],[Disable POSIX Threads]))
AC_ARG_WITH(aio, AS_HELP_STRING([--without-aio],[Do not use POSIX AIO. Default: auto-detect]))
ENABLE_WIN32_AIOPS=0
squid_opt_use_aio=
squid_opt_use_diskthreads=
AIOLIB=

dnl Setup the module paths etc.
DISK_LIBS=
DISK_MODULES=
AH_TEMPLATE(HAVE_DISKIO_MODULE_AIO, [Whether POSIX AIO Disk I/O module is built])
AH_TEMPLATE(HAVE_DISKIO_MODULE_BLOCKING, [Whether Blocking Disk I/O module is built])
AH_TEMPLATE(HAVE_DISKIO_MODULE_DISKDAEMON, [Whether DiskDaemon Disk I/O module is built])
AH_TEMPLATE(HAVE_DISKIO_MODULE_DISKTHREADS, [Whether DiskThreads Disk I/O module is built])
AH_TEMPLATE(HAVE_DISKIO_MODULE_IPCIO, [Whether IpcIo Disk I/O module is built])
AH_TEMPLATE(HAVE_DISKIO_MODULE_MMAPPED, [Whether Mmapped Disk I/O module is built])
for module in $squid_disk_module_candidates none; do
  # maybe not needed
  AS_IF([test "x$module" = "xnone"],[continue])
  AS_IF([! test -d "$srcdir/src/DiskIO/$module"],[AC_MSG_ERROR([disk-io $module does not exist])])
  AS_CASE(["$module"],
    [AIO],[
      dnl Check for POSIX AIO availability
      squid_opt_use_aio="yes"
      AIOLIB=
      AS_IF([test "x$with_aio" != "xno"],[
        have_aio_header=no
        AC_CHECK_HEADERS(aio.h,[have_aio_header=yes])
        dnl On some systems POSIX AIO functions are in librt
        dnl On some systems POSIX AIO functions are in libaio
        AC_CHECK_LIB(rt,aio_read,[AIOLIB="-lrt"],AC_CHECK_LIB(aio,aio_read,[AIOLIB="-laio"],[]))
        dnl Enable AIO if the library and headers are found
        AS_IF([test "x$AIOLIB" != "x" -a "x$have_aio_header" = "xyes"],[
          AC_MSG_NOTICE([Native POSIX AIO support detected.])
          squid_opt_use_aio="yes"
        ],[
          dnl Windows does things differently. We provide wrappers.
          dnl TODO: Windows really needs its own DiskIO module or its Overlaped IO
          AS_IF([test "$squid_host_os" = "mingw"],[
            squid_opt_use_aio="yes"
            AC_MSG_NOTICE([Windows being built. Maybe-enable POSIX AIO.])
          ],[
            squid_opt_use_aio="no"
            AC_MSG_NOTICE([Native POSIX AIO support not detected. AIO automatically disabled.])
          ])
        ])
      ],[
        AC_MSG_NOTICE([POSIX AIO support manually disabled.])
        squid_opt_use_aio="no"
      ])
      dnl Use the POSIX AIO pieces if we actually need them.
      AS_IF([test "x$squid_opt_use_aio" = "xyes"],[
        DISK_MODULES="$DISK_MODULES AIO"
        AC_DEFINE([HAVE_DISKIO_MODULE_AIO],1,[POSIX AIO Disk I/O module is built])
        AS_IF([test "$squid_host_os" = "mingw"],[
          ENABLE_WIN32_AIO=1
          AC_MSG_NOTICE([Replacing AIO DiskIO module with: Windows overlapped I/O support])
        ],[
          AC_MSG_NOTICE([Enabling AIO DiskIO module])
        ])
      ],[
        AC_MSG_NOTICE([AIO DiskIO Module disabled. Missing POSIX AIO support.])
        squid_disk_module_candidates_AIO=no
      ])
    ],

    [Blocking],[
      AC_MSG_NOTICE([Enabling Blocking DiskIO module])
      DISK_MODULES="$DISK_MODULES Blocking"
      AC_DEFINE([HAVE_DISKIO_MODULE_BLOCKING],1,[Blocking Disk I/O module is built])
    ],

    [DiskDaemon],[
      AS_IF([test "$squid_host_os" = "mingw"],[
        AC_MSG_NOTICE([DiskDaemon not supported on MinGW])
        squid_disk_module_candidates_DiskDaemon=no
      ],[
        AC_MSG_NOTICE([Enabling DiskDaemon DiskIO module])
        DISK_MODULES="$DISK_MODULES DiskDaemon"
        AC_DEFINE([HAVE_DISKIO_MODULE_DISKDAEMON],1,[DiskDaemon Disk I/O module is built])
      ])
    ],

    [DiskThreads],[
      squid_opt_use_diskthreads="yes"
      LIBPTHREADS=
      SQUID_STATE_SAVE([diskthreads_state],[SQUID_CFLAGS SQUID_CXXFLAGS])
      AS_IF([test "x$with_pthreads" != "xno"],[
        dnl TODO: this needs to be extended to handle more systems and better
        dnl REF: http://www.openldap.org/lists/openldap-bugs/200006/msg00070.html
        dnl REF: http://autoconf-archive.cryp.to/acx_pthread.html
        AS_CASE(["$squid_host_os"],
          [mingw],[
            ENABLE_WIN32_AIOPS=1
            AC_MSG_NOTICE([Windows threads support automatically enabled])
          ],

          [freebsd],[
            AS_IF([test `echo "$squid_host_os_version" | tr -d .` -lt 70],[
              AC_MSG_NOTICE(pthread library requires FreeBSD 7 or later)
              squid_opt_use_diskthreads="no"
            ],[
              SQUID_CFLAGS="$SQUID_CFLAGS -D_REENTRANT"
              SQUID_CXXFLAGS="$SQUID_CXXFLAGS -D_REENTRANT"
              AS_IF([test "x$GCC" = "xyes" -a "x$PRESET_LDFLAGS" = "x"],[LDFLAGS="$LDFLAGS -pthread"])
            ])
          ],

          [openbsd],[
            AS_IF([test `echo "$squid_host_os_version" | tr -d .` -lt 52],[
              AC_MSG_NOTICE(pthread library requires OpenBSD 5.2 or later)
              squid_opt_use_diskthreads="no"
            ],[
              SQUID_CFLAGS="$SQUID_CFLAGS -D_REENTRANT"
              SQUID_CXXFLAGS="$SQUID_CXXFLAGS -D_REENTRANT"
              LDFLAGS="$LDFLAGS -lpthread"
            ])
          ],

          [solaris],[
            AS_IF([test "x$GCC" = "xyes"],[
              SQUID_CFLAGS="$SQUID_CFLAGS -D_REENTRANT -pthreads"
              SQUID_CXXFLAGS="$SQUID_CXXFLAGS -D_REENTRANT -pthreads"
              AC_CHECK_LIB(pthread, pthread_create ,[LIBPTHREADS="-lpthread"], [
                AC_MSG_NOTICE(pthread library required but cannot be found.)
                squid_opt_use_diskthreads="no"
               ])
            ],[
              dnl test for -lpthread first. libc version is a stub apparently on Solaris.
              SQUID_CFLAGS="$SQUID_CFLAGS -D_REENTRANT -lpthread"
              SQUID_CXXFLAGS="$SQUID_CXXFLAGS -D_REENTRANT -lpthread"
              AC_SEARCH_LIBS([pthread_create],[pthread thread],[
                LIBPTHREADS="" #in LIBS
              ],[
                AC_MSG_NOTICE(pthread library required but cannot be found.)
                squid_opt_use_diskthreads="no"
              ])
            ])
          ],

          [
            SQUID_CFLAGS="$SQUID_CFLAGS -D_REENTRANT"
            SQUID_CXXFLAGS="$SQUID_CXXFLAGS -D_REENTRANT"
            AC_CHECK_LIB(pthread, pthread_create ,[LIBPTHREADS="-lpthread"], [
              AC_MSG_NOTICE(pthread library required but cannot be found.)
              squid_opt_use_diskthreads="no"
            ])
          ]
        )
      ],[
        AC_MSG_NOTICE([Native pthreads support manually disabled.])
        squid_opt_use_diskthreads="no"
      ])
      AS_IF([test "x$squid_opt_use_diskthreads" = "xyes"],[
        AC_MSG_NOTICE([Enabling DiskThreads DiskIO module])
        DISK_MODULES="$DISK_MODULES DiskThreads"
        AC_DEFINE([HAVE_DISKIO_MODULE_DISKTHREADS],1,[DiskThreads Disk I/O module is built])
      ],[
        AC_MSG_NOTICE([Native pthreads support disabled. DiskThreads module automaticaly disabled.])
        SQUID_STATE_ROLLBACK([diskthreads_state])
        squid_disk_module_candidates_DiskThreads=no
      ])
    ],

    [IpcIo],[
      AS_IF([test "x$ac_cv_search_shm_open" = "xno"],[
        AC_MSG_NOTICE([DiskIO IpcIo module requires shared memory support])
        squid_disk_module_candidates_IpcIo=no
      ],[
        AC_MSG_NOTICE([Enabling IpcIo DiskIO module])
        DISK_MODULES="$DISK_MODULES IpcIo"
        AC_DEFINE([HAVE_DISKIO_MODULE_IPCIO],1,[IpcIo Disk I/O module is built])
      ])
    ],

    [Mmapped],[
      dnl TODO: use availability of sys/mman.h and/or mmap to define
      dnl  OR support windows mmap functions
      AS_IF([test "x$squid_host_os" = "xmingw"],[
        AC_MSG_NOTICE([Mmapped DiskIO is not available on Mingw])
        squid_disk_module_candidates_Mmapped=no
      ],[
        AC_MSG_NOTICE([Enabling Mmapped DiskIO module])
        DISK_MODULES="$DISK_MODULES Mmapped"
        AC_DEFINE([HAVE_DISKIO_MODULE_MMAPPED],1,[Mmapped Disk I/O module is built])
      ])
    ],

    [
      AC_MSG_NOTICE([Enabling $module DiskIO module])
      DISK_LIBS="$DISK_LIBS lib${module}.la"
      DISK_MODULES="$DISK_MODULES ${module}"
    ])
done
AC_MSG_NOTICE([IO Modules built: $DISK_MODULES])
AC_SUBST(DISK_MODULES)
AC_SUBST(DISK_LIBS)
AM_CONDITIONAL(ENABLE_DISKIO_AIO, test "x$squid_disk_module_candidates_AIO" = "xyes")
AC_SUBST(AIOLIB)
AM_CONDITIONAL(ENABLE_WIN32_AIO, test "x$squid_disk_module_candidates_AIO" = "xyes" -a "x$ENABLE_WIN32_AIO" = "x1")
AM_CONDITIONAL(ENABLE_DISKIO_BLOCKING, test "x$squid_disk_module_candidates_Blocking" = "xyes")
AM_CONDITIONAL(ENABLE_DISKIO_DISKDAEMON, test "x$squid_disk_module_candidates_DiskDaemon" = "xyes")
AM_CONDITIONAL(ENABLE_DISKIO_DISKTHREADS, test "x$squid_disk_module_candidates_DiskThreads" = "xyes")
AC_SUBST(LIBPTHREADS)
AM_CONDITIONAL(ENABLE_WIN32_AIOPS, test "x$squid_disk_module_candidates_DiskThreads" = "xyes" -a "x$ENABLE_WIN32_AIOPS" = "x1")
AM_CONDITIONAL(ENABLE_DISKIO_IPCIO, test "x$squid_disk_module_candidates_IpcIo" = "xyes")
AM_CONDITIONAL(ENABLE_DISKIO_MMAPPED, test "x$squid_disk_module_candidates_Mmapped" = "xyes")

dnl Check what Storage formats are wanted.
dnl This version will error out with a message saying why if a required DiskIO is missing.
AC_ARG_ENABLE([storeio],
  AS_HELP_STRING([--enable-storeio="list of modules"],
                 [Build support for the list of store I/O modules.
                  The default is only to build the "ufs" module.
                  See src/fs for a list of available modules, or
                  Programmers Guide section <not yet written>
                  for details on how to build your custom store module]), [
  AS_CASE(["$enableval"],
    [yes],[],
    [no|none],[enable_storeio="no"],
    [
      enable_storeio="yes"
      # ufs is really always needed as it has low-level routines
      # if it is a dupe it will be cleaned-up later
      squid_storeio_module_candidates="$enableval ufs"
  ])
])
AS_IF([test "x${enable_storeio:=yes}" = "xyes"],[
  SQUID_LOOK_FOR_MODULES([$srcdir/src/fs],[squid_storeio_module_candidates])
])
SQUID_CLEANUP_MODULES_LIST([squid_storeio_module_candidates])
SQUID_CHECK_EXISTING_MODULES([$srcdir/src/fs],[squid_storeio_module_candidates])
AC_MSG_NOTICE([Store modules built: ${squid_storeio_module_candidates:-none}])

for fs in ${squid_storeio_module_candidates:-none}; do
  AS_CASE([$fs],
    [diskd],[
      AS_IF([test "x$squid_disk_module_candidates_Blocking" != "xyes" -a \
        "x$squid_disk_module_candidates_DiskDaemon" != "xyes"],[
        AC_MSG_ERROR([Storage diskd module requires DiskIO module: Blocking or DiskDaemon])
      ])
    ],
    [aufs],[
      AS_IF([test "x$squid_disk_module_candidates_Blocking" != "xyes" -a \
        "x$squid_disk_module_candidates_DiskThreads" != "xyes"],[
        AC_MSG_ERROR([Storage module aufs requires DiskIO module: Blocking or DiskThreads])
      ])
    ],
    [rock],[
      AS_IF([test "x$squid_disk_module_candidates_IpcIo" != "xyes" -a \
        "x$squid_disk_module_candidates_Blocking" != "xyes"],[
         AC_MSG_ERROR([Storage module Rock requires DiskIO module: Blocking or IpcIo])
      ])
      squid_do_build_rock=true
    ],
    [ufs],[
      AS_IF([test "x$squid_disk_module_candidates_Blocking" != "xyes"],[
        AC_MSG_ERROR([Storage module ufs requires DiskIO module: Blocking])
      ])
      squid_do_build_ufs=true
    ]
  )
done

AM_CONDITIONAL(ENABLE_FS_UFS, test "x$squid_do_build_ufs" = "xtrue")
AM_CONDITIONAL(ENABLE_FS_ROCK, test "x$squid_do_build_rock" = "xtrue")
dnl hack: need to define those even if not used in the build system to
dnl make sure that global FS objects are linked to the squid binary.
AH_TEMPLATE(HAVE_FS_UFS, "Define to 1 if ufs filesystem module is build")
AH_TEMPLATE(HAVE_FS_AUFS, "Define to 1 if aufs filesystem module is build")
AH_TEMPLATE(HAVE_FS_DISKD, "Define to 1 if diskd filesystem module is build")
AH_TEMPLATE(HAVE_FS_ROCK, "Define to 1 if rock filesystem module is build")


dnl got final squid_storeio_module_candidates, build library lists
dnl This list will not be needed when each fs library has its own Makefile
STORE_LIBS_TO_BUILD=
dnl File system libraries to link executables with.
dnl These are the same as STORE_LIBS_TO_BUILD, but with a path
STORE_LIBS_TO_ADD=
for fs in $squid_storeio_module_candidates; do
    STORE_LIBS_TO_BUILD="$STORE_LIBS_TO_BUILD lib${fs}.la"
    STORE_LIBS_TO_ADD="$STORE_LIBS_TO_ADD fs/lib${fs}.la"
    SQUID_TOUPPER_VAR_CONTENTS([fs])
    AC_DEFINE_UNQUOTED(HAVE_FS_${fs}, 1)
done

AC_SUBST(STORE_LIBS_TO_BUILD)
AC_SUBST(STORE_LIBS_TO_ADD)
AC_SUBST(STORE_TESTS)


dnl At lest one removal policy is always needed.
dnl 'lru' removal policy is currently hard-coded by name for tests
dnl so we must set it as default.
REPL_POLICIES="lru"
AC_ARG_ENABLE(removal-policies,
  AS_HELP_STRING([--enable-removal-policies="list of policies"],
                 [Build support for the list of removal policies.
                  The default is only to build the "lru" module.
                  See src/repl for a list of available modules, or
                  Programmers Guide section 9.9 for details on how
                  to build your custom policy]), [
  AS_CASE(["$enableval"],
    [yes],[ SQUID_LOOK_FOR_MODULES([$srcdir/src/repl],[REPL_POLICIES]) ],
    [no],[],
    [ REPL_POLICIES="$enableval" ]
  )
])
SQUID_CLEANUP_MODULES_LIST([REPL_POLICIES])
SQUID_CHECK_EXISTING_MODULES([$srcdir/src/repl],[REPL_POLICIES])
AC_MSG_NOTICE([Removal policies to build: $REPL_POLICIES])
REPL_OBJS="repl/lib`echo \"$REPL_POLICIES\" | sed -e 's% %.a repl/lib%g'`.a"
REPL_LIBS=`echo "$REPL_OBJS" | sed -e 's%repl/%%g'`
AC_SUBST(REPL_POLICIES)
AC_SUBST(REPL_OBJS)
AC_SUBST(REPL_LIBS)

AM_CONDITIONAL(ENABLE_PINGER, false)
AC_ARG_ENABLE(icmp,
  AS_HELP_STRING([--enable-icmp],[Enable ICMP pinging and Network Measurement]),[
  AS_IF([test "x$enableval" = "xyes"],[
    AC_MSG_NOTICE([ICMP enabled])
    AC_DEFINE(USE_ICMP,1,[Define to use Squid ICMP and Network Measurement features (highly recommended!)])
    AM_CONDITIONAL(ENABLE_PINGER, true)
  ])
])

AM_CONDITIONAL(ENABLE_DELAY_POOLS, false)
AC_ARG_ENABLE(delay-pools,
  AS_HELP_STRING([--enable-delay-pools],[Enable delay pools to limit bandwidth usage]),[
  AS_IF([test "x$enableval" = "xyes"],[
    AC_MSG_NOTICE([Delay pools enabled])
    AC_DEFINE([USE_DELAY_POOLS],1,[Traffic management via "delay pools".])
    AM_CONDITIONAL(ENABLE_DELAY_POOLS, true)
  ])
])

dnl disable generic/common adaptation support by default
squid_opt_use_adaptation=no

AC_ARG_ENABLE(icap-client,
  AS_HELP_STRING([--disable-icap-client],[Disable the ICAP client.]),[
  SQUID_YESNO([$enableval],[--enable-icap-client])
])
SQUID_DEFINE_BOOL(ICAP_CLIENT,${enable_icap_client:=yes}, [Enable ICAP client features in Squid])
AS_IF(test "x$enable_icap_client" != "xno", squid_opt_use_adaptation="yes")
AM_CONDITIONAL(ENABLE_ICAP_CLIENT, test "x$enable_icap_client" != "xno")

AC_ARG_ENABLE(ecap,
  AS_HELP_STRING([--enable-ecap],[support loadable content adaptation modules]),[
  SQUID_YESNO([$enableval],[--enable-ecap])],[
  enable_ecap="no"
])
dnl Perform configuration consistency checks for eCAP
AS_IF([test "x$enable_ecap" != "xno"],[
  AS_IF([test "x$enable_shared" != "xyes"],[
    AC_MSG_ERROR([eCAP support requires loadable modules (i.e. --enable-shared or equivalent).])
  ])

  AS_IF([test -n "$PKG_CONFIG"],[
    dnl eCAP support requires libecap.
    dnl This Squid supports libecap v1.0.x.
    dnl Use EXT_ prefix to distinguish external libecap (that we check for
    dnl here) from our own convenience ecap library in Makefiles.
    PKG_CHECK_MODULES([EXT_LIBECAP],[libecap >= 1.0 libecap < 1.1])
  ],[
    AC_MSG_NOTICE([eCAP support requires pkg-config to verify the correct library version. Trouble may follow.])
  ])

  SQUID_STATE_SAVE(squid_ecap_state)
  CPPFLAGS="$EXT_LIBECAP_CFLAGS $CPPFLAGS"
  LIBS="$EXT_LIBECAP_LIBS $LIBS"
  AC_CHECK_HEADERS([ \
    libecap/adapter/service.h \
    libecap/adapter/xaction.h \
    libecap/common/area.h \
    libecap/common/body.h \
    libecap/common/delay.h \
    libecap/common/forward.h \
    libecap/common/header.h \
    libecap/common/memory.h \
    libecap/common/message.h \
    libecap/common/name.h \
    libecap/common/named_values.h \
    libecap/common/names.h \
    libecap/common/options.h \
    libecap/common/registry.h \
    libecap/common/version.h \
    libecap/host/host.h \
    libecap/host/xaction.h \
  ],,,[
/* libecap-1.0.1 headers do not build without autoconf.h magic */
#define HAVE_CONFIG_H
/* libecap/common/delay.h fails to include <string> */
#include <string>
  ])
  AC_MSG_CHECKING([whether -lecap will link])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#if HAVE_LIBECAP_COMMON_NAMES_H
#include <libecap/common/names.h>
#endif
    ]],[[
      const libecap::Name test("test", libecap::Name::NextId());
    ]])
  ],[
    AC_MSG_RESULT(yes)
    squid_opt_use_adaptation=yes
  ],[
    AC_MSG_RESULT(no)
    AS_IF([test "x$enable_ecap" = "xyes"],[
      AC_MSG_ERROR([eCAP library will not link.
                  You may need to rebuild libecap using the same version of GCC as Squid.
                  There have been breaking ABI changes in the libstdc++ STL with GCC 5.])
    ],[
      AC_MSG_NOTICE([eCAP library will not link.
                  You may need to rebuild libecap using the same version of GCC as Squid.
                  There have been breaking ABI changes in the libstdc++ STL with GCC 5.])
      enable_ecap="no"
    ])
  ])
  SQUID_STATE_ROLLBACK(squid_ecap_state)
])
SQUID_DEFINE_BOOL(USE_ECAP,${enable_ecap:=no},[Whether to use eCAP support])
AM_CONDITIONAL(ENABLE_ECAP, test "x$enable_ecap" = "xyes")

dnl enable adaptation if requested by specific adaptation mechanisms
ADAPTATION_LIBS=""
AS_IF([test "x$squid_opt_use_adaptation" = "xyes"],[ADAPTATION_LIBS="adaptation/libadaptation.la"])
SQUID_DEFINE_BOOL(USE_ADAPTATION,${squid_opt_use_adaptation:=no}, [common adaptation support])
AM_CONDITIONAL(ENABLE_ADAPTATION, test "x$squid_opt_use_adaptation" = "xyes")
AC_SUBST(ADAPTATION_LIBS)

AS_IF([test "x$squid_host_os" = "xmingw"],[enable_wccp=no])
AC_ARG_ENABLE(wccp,
  AS_HELP_STRING([--disable-wccp],[Disable Web Cache Coordination Protocol]),[
  SQUID_YESNO([$enableval],[--enable-wccp])
])
SQUID_DEFINE_BOOL(USE_WCCP, ${enable_wccp:=yes}, [Define to enable WCCP])
AC_MSG_NOTICE([Web Cache Coordination Protocol enabled: $enable_wccp])

AS_IF([test "x$squid_host_os" = "xmingw"],[enable_wccpv2=no])
AC_ARG_ENABLE(wccpv2,
  AS_HELP_STRING([--disable-wccpv2],
                 [Disable Web Cache Coordination V2 Protocol]), [
  SQUID_YESNO([$enableval],[--enable-wccpv2])
])
SQUID_DEFINE_BOOL(USE_WCCPv2,${enable_wccpv2:=yes},
            [Define to enable WCCP V2])
AC_MSG_NOTICE([Web Cache Coordination V2 Protocol enabled: $enable_wccpv2])

AC_ARG_ENABLE(snmp,
  AS_HELP_STRING([--disable-snmp],[Disable SNMP monitoring support]), [
  SQUID_YESNO([$enableval],[--enable-snmp])
])
SQUID_DEFINE_BOOL(SQUID_SNMP,${enable_snmp:=yes},
   [Define to enable SNMP monitoring of Squid])
AM_CONDITIONAL(ENABLE_SNMP, [test "x$enable_snmp" = "xyes"])
AS_IF([test "x$enable_snmp" = "xyes"],[SNMPLIB="../lib/snmplib/libsnmplib.la"])
AC_MSG_NOTICE([SNMP support enabled: $enable_snmp])
AC_SUBST(SNMPLIB)

AC_ARG_ENABLE(eui,
  AS_HELP_STRING([--disable-eui],
                 [Disable use of ARP / MAC/ EUI (ether address)]), [
  SQUID_YESNO([$enableval],[--enable-eui])
])
AS_IF([test "x${enable_eui:=yes}" = "xyes"],[
  SQUID_STATE_SAVE(LIBEUI)
  # GLIBC 2.30 deprecates sysctl.h. Test with the same flags that (may) break includes later.
  CFLAGS=$SQUID_CFLAGS
  CXXFLAGS=$SQUID_CXXFLAGS
  AS_CASE(["$squid_host_os"],
    [linux|solaris|freebsd|openbsd|netbsd|cygwin],[:],
    [mingw],[EUILIB="-liphlpapi"],
    [AC_MSG_WARN([EUI support probably will not work on host $host.])]
  )
  # iphlpapi.h check delayed after winsock2.h
  AC_CHECK_HEADERS( \
    windows.h \
    sys/sockio.h \
    sys/param.h,
  [], [], [[
#if HAVE_WINDOWS_H
include <windows.h>
#endif
]]
  )
  AC_CHECK_HEADERS( \
    net/if_arp.h \
    net/route.h,
  [], [], [[
#include <sys/types.h>
#include <sys/socket.h>
]])

  # OpenBSD, FreeBSD and NetBSD requires sys/param.h to be included before sysctl.h and net/if_dl.h
  AC_CHECK_HEADERS( \
    net/if_dl.h \
    sys/sysctl.h,
  [], [], [[
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
  ]])
  AC_CHECK_MEMBER([struct arpreq.arp_pa],[],[
    AS_IF([test "x$squid_host_os" != "xmingw" -a "x$squid_host_os" != "xcygwin"],[
      AC_MSG_NOTICE([OS support for EUI seems incomplete, disabling it])
      enable_eui=no
    ])],[[
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_NET_IF_ARP_H
#include <net/if_arp.h>
#endif
  ]])
  SQUID_STATE_ROLLBACK(LIBEUI)
])
AC_SUBST(EUILIB)
AC_MSG_NOTICE([EUI (MAC address) controls enabled: $enable_eui])
SQUID_DEFINE_BOOL(USE_SQUID_EUI,$enable_eui,
   [Define this to include code which lets you use ethernet addresses. This code uses API initially defined in 4.4-BSD.])
AM_CONDITIONAL(ENABLE_EUI, [test "x$enable_eui" = "xyes" ])


AC_ARG_ENABLE(htcp,
  AS_HELP_STRING([--disable-htcp],[Disable HTCP protocol support]), [
  SQUID_YESNO([$enableval],[--enable-htcp])
])
SQUID_DEFINE_BOOL(USE_HTCP,${enable_htcp:=yes},
   [Define this to include code for the Hypertext Cache Protocol (HTCP)])
AM_CONDITIONAL(ENABLE_HTCP, [test "x$enable_htcp" = "xyes"])
AC_MSG_NOTICE([HTCP support enabled: $enable_htcp])

# Cryptograhic libraries
SQUID_AUTO_LIB(nettle,[Nettle crypto],[LIBNETTLE])
SQUID_CHECK_LIB_WORKS(nettle,[
  PKG_CHECK_MODULES([LIBNETTLE],[nettle >= 3.4],[
    CPPFLAGS="$LIBNETTLE_CFLAGS $CPPFLAGS"
    AC_CHECK_HEADERS(nettle/base64.h nettle/md5.h)
  ],[:])
])

dnl Check for libcrypt
CRYPTLIB=
dnl Some of our helpers use crypt(3) which may be in libc, or in
dnl libcrypt (eg FreeBSD)
AC_CHECK_LIB(crypt, crypt, [CRYPTLIB="-lcrypt"])
dnl Solaris10 provides MD5 natively through libmd5
AC_CHECK_LIB(md5, MD5Init, [CRYPTLIB="$CRYPTLIB -lmd5"])
AC_SUBST(CRYPTLIB)

SQUID_AUTO_LIB(gnutls,[GnuTLS crypto],[LIBGNUTLS])
SQUID_CHECK_LIB_WORKS(gnutls,[
  PKG_CHECK_MODULES([LIBGNUTLS],[gnutls >= 3.4.0],[
    CPPFLAGS="$LIBGNUTLS_CFLAGS $CPPFLAGS"
    AC_CHECK_HEADERS(gnutls/gnutls.h gnutls/x509.h gnutls/abstract.h)
  ],[:])
])

SSLLIB=""
dnl User may specify OpenSSL is needed from a non-standard location
SQUID_OPTIONAL_LIB(openssl,[OpenSSL],[LIBOPENSSL])
AH_TEMPLATE(USE_OPENSSL,[OpenSSL support is available])
## OpenSSL is default disable due to licensing issues on some OS
AS_IF([test "x$with_openssl" = "xyes"],[
  CPPFLAGS="$LIBOPENSSL_CFLAGS $CPPFLAGS"
  AC_CHECK_HEADERS( \
    openssl/asn1.h \
    openssl/bio.h \
    openssl/bn.h \
    openssl/crypto.h \
    openssl/decoder.h \
    openssl/dh.h \
    openssl/err.h \
    openssl/evp.h \
    openssl/lhash.h \
    openssl/md5.h \
    openssl/opensslv.h \
    openssl/rsa.h \
    openssl/ssl.h \
    openssl/x509.h \
    openssl/x509v3.h \
    openssl/engine.h \
    openssl/txt_db.h \
    openssl/pem.h \
  )

  # User may have provided a custom location for OpenSSL. Otherwise...
  SQUID_STATE_SAVE(squid_openssl_state)
  LIBS="$LIBS $LIBOPENSSL_PATH"

  # auto-detect using pkg-config
  PKG_CHECK_MODULES([LIBOPENSSL],[openssl],,[
    ## For some OS pkg-config is broken or unavailable.
    ## Detect libraries the hard way.

    # Windows MinGW has some special libraries ...
    AS_IF([test "x$squid_host_os" = "xmingw"],[
      LIBOPENSSL_LIBS='-lssleay32 -leay32 -lgdi32 $LIBOPENSSL_LIBS'
      AC_MSG_NOTICE([Windows OpenSSL library support: yes -lssleay32 -leay32 -lgdi32])
    ])

    AC_CHECK_LIB(crypto,[CRYPTO_new_ex_data],[LIBOPENSSL_LIBS="-lcrypto $LIBOPENSSL_LIBS"],[
      AC_MSG_ERROR([library 'crypto' is required for OpenSSL])
    ],$LIBOPENSSL_LIBS)
    AC_CHECK_LIB(ssl,[SSL_CTX_new],[LIBOPENSSL_LIBS="-lssl $LIBOPENSSL_LIBS"],[
      AC_MSG_ERROR([library 'ssl' is required for OpenSSL])
    ],$LIBOPENSSL_LIBS)
  ])

  SQUID_STATE_ROLLBACK(squid_openssl_state) #de-pollute LIBS

  AS_IF([test "x$LIBOPENSSL_LIBS" != "x"],[
    CXXFLAGS="$LIBOPENSSL_CFLAGS $CXXFLAGS"
    SSLLIB="$LIBOPENSSL_PATH $LIBOPENSSL_LIBS $SSLLIB"
    AC_DEFINE(USE_OPENSSL,1,[OpenSSL support is available])

    # check for API functions
    SQUID_CHECK_LIBCRYPTO_API
    SQUID_CHECK_LIBSSL_API
    SQUID_CHECK_OPENSSL_TLS_METHODS
    SQUID_STATE_SAVE(check_SSL_CTX_get0_certificate)
    LIBS="$LIBS $SSLLIB"
    AC_CHECK_LIB(ssl, SSL_CTX_get0_certificate, [
      AC_DEFINE(HAVE_SSL_CTX_GET0_CERTIFICATE, 1, [SSL_CTX_get0_certificate is available])
      ], [
          missing_SSL_CTX_get0_certificate=yes
      ])
    SQUID_STATE_ROLLBACK(check_SSL_CTX_get0_certificate)

    # check for other specific broken implementations
    AS_IF([test "x$missing_SSL_CTX_get0_certificate" = "xyes"],SQUID_CHECK_OPENSSL_GETCERTIFICATE_WORKS)
    SQUID_CHECK_OPENSSL_CONST_SSL_METHOD
    SQUID_CHECK_OPENSSL_CONST_CRYPTO_EX_DATA
    SQUID_CHECK_OPENSSL_CONST_SSL_SESSION_CB_ARG
    SQUID_CHECK_OPENSSL_CONST_X509_GET0_SIGNATURE_ARGS
    SQUID_CHECK_OPENSSL_TXTDB
  ])
  AS_IF([test "x$SSLLIB" = "x"],[AC_MSG_ERROR([Required OpenSSL library not found])])
])
AC_MSG_NOTICE([OpenSSL library support: ${with_openssl:=no} ${LIBOPENSSL_PATH} ${LIBOPENSSL_LIBS}])
AM_CONDITIONAL(ENABLE_SSL,[ test "x$with_openssl" = "xyes" ])
AC_SUBST(SSLLIB)

# Kerberos support libraries: MIT
SQUID_AUTO_LIB(mit-krb5,[MIT Kerberos],[LIB_KRB5])
AH_TEMPLATE(USE_APPLE_KRB5,[Apple Kerberos support is available])
AH_TEMPLATE(USE_SOLARIS_KRB5,[Solaris Kerberos support is available])
SQUID_CHECK_LIB_WORKS(mit-krb5,[
  AS_IF([test "x$squid_host_os" = "xsolaris"],[
    # pkg-config not available for Solaris krb5 implementation
    SQUID_CHECK_SOLARIS_KRB5
  ],[
    PKG_CHECK_MODULES([LIBMIT_KRB5],[mit-krb5 mit-krb5-gssapi],[
      AS_IF([test "x$squid_host_os" = "xdarwin"],[
        AC_DEFINE(USE_APPLE_KRB5,1,[Apple Kerberos support is available])
        AC_CHECK_LIB(resolv,[main],[LIBMIT_KRB5_LIBS="$LIBMIT_KRB5_LIBS -lresolv"],[
          AC_MSG_ERROR([library 'resolv' is required for Apple Kerberos])
        ])
      ])
      CPPFLAGS="$LIBMIT_KRB5_CFLAGS $CPPFLAGS"
      LIBS="$LIBMIT_KRB5_PATH $LIBMIT_KRB5_LIBS $LIBS"
      AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h gssapi/gssapi_krb5.h)
      AC_CHECK_HEADERS(gssapi/gssapi_ext.h gssapi/gssapi_generic.h)
      AC_CHECK_HEADERS(krb5.h com_err.h et/com_err.h)
      AC_CHECK_HEADERS(profile.h)
      SQUID_CHECK_KRB5_FUNCS
    ],[:])
  ])
])

# Kerberos support libraries: Heimdal
SQUID_AUTO_LIB(heimdal-krb5,[Heimdal Kerberos],[LIBHEIMDAL_KRB5])
SQUID_CHECK_LIB_WORKS(heimdal-krb5,[
  AS_IF([test "x$LIBMIT_KRB5_LIBS" = "x"],[
    PKG_CHECK_MODULES([LIBHEIMDAL_KRB5],[heimdal-krb5 heimdal-gssapi],[
      CPPFLAGS="$LIBHEIMDAL_KRB5_CFLAGS $CPPFLAGS"
      AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h gssapi/gssapi_krb5.h)
      AC_CHECK_HEADERS(krb5.h com_err.h et/com_err.h)

      LIBS="$LIBHEIMDAL_KRB5_PATH $LIBHEIMDAL_KRB5_LIBS $LIBS"
      SQUID_CHECK_KRB5_HEIMDAL_BROKEN_KRB5_H
      SQUID_CHECK_KRB5_FUNCS
    ],[:])
  ])
])

# Kerberos support libraries: GNU GSS
SQUID_AUTO_LIB(gss,[GNU gss],[LIBGSS])
SQUID_CHECK_LIB_WORKS(gss,[
  AS_IF([test "x$LIBMIT_KRB5_LIBS" = "x" -a "x$LIBHEIMDAL_KRB5_LIBS" = "x"],[
    PKG_CHECK_MODULES([LIBGSS],[gss],[
      CPPFLAGS="$LIBGSS_CFLAGS $CPPFLAGS"
      AC_CHECK_HEADERS(gss.h)
      LIBS="$LIBGSS_PATH $LIBS"
      SQUID_CHECK_WORKING_GSSAPI
      SQUID_DEFINE_BOOL(HAVE_GSSAPI,$squid_cv_working_gssapi,[GSSAPI support])
      SQUID_CHECK_SPNEGO_SUPPORT
      SQUID_DEFINE_BOOL(HAVE_SPNEGO,$squid_cv_have_spnego,[SPNEGO support])
      SQUID_CHECK_WORKING_KRB5
      SQUID_DEFINE_BOOL(HAVE_KRB5,$squid_cv_working_krb5,[KRB5 support])
    ],[:])
  ])
])

SQUID_AUTO_LIB(ldap,[LDAP],[LIBLDAP])
SQUID_CHECK_LIB_WORKS(ldap,[
  PKG_CHECK_MODULES([LIBLDAP],[ldap],[:],[:])
  AS_IF([test "$squid_host_os" = "mingw" -a "x$LIBLDAP_LIBS" = "x"],[
    dnl On MinGW OpenLDAP is not available, try Windows LDAP libraries
    dnl TODO: use AC_CHECK_LIB
    LIBLDAP_LIBS="-lwldap32"
    AC_CHECK_HEADERS(winldap.h)
  ])
  AC_CHECK_HEADERS(ldap.h lber.h)
  AC_CHECK_HEADERS(mozldap/ldap.h)
  SQUID_CHECK_LDAP_API
])

SQUID_AUTO_LIB(sasl,[Cyrus SASL],[LIBSASL])
SQUID_CHECK_LIB_WORKS([sasl],[
  PKG_CHECK_MODULES([LIBSASL],[libsasl2],[:],[:])
  CPPFLAGS="$LIBSASL_CFLAGS $CPPFLAGS"
  LIBS="$LIBSASL_LIBS $LIBS"
  AC_CHECK_HEADERS([sasl/sasl.h sasl.h])
])

SQUID_AUTO_LIB(systemd,[systemd API for start-up notification],[LIBSYSTEMD])
SQUID_CHECK_LIB_WORKS(systemd,[
  LIBS="$LIBS $LIBSYSTEMD_PATH"
  PKG_CHECK_MODULES(LIBSYSTEMD,[libsystemd >= 209],[
    AC_CHECK_HEADERS(systemd/sd-daemon.h)
  ],[:])
])

AC_ARG_ENABLE(forw-via-db,
  AS_HELP_STRING([--enable-forw-via-db],[Enable Forw/Via database]), [
  SQUID_YESNO([$enableval],[--enable-forw-via-db])
])
SQUID_DEFINE_BOOL(USE_FORW_VIA_DB,${enable_forw_via_db:=no},
                      [Enable Forw/Via database])
AC_MSG_NOTICE([Forw/Via database enabled: $enable_forw_via_db])

AC_ARG_ENABLE(cache-digests,
  AS_HELP_STRING([--enable-cache-digests],
   [Use Cache Digests. See https://wiki.squid-cache.org/SquidFaq/CacheDigests]),[
  SQUID_YESNO([$enableval],[--enable-cache-digests])
])
SQUID_DEFINE_BOOL(USE_CACHE_DIGESTS,${enable_cache_digests:=no},
  [Use Cache Digests for locating objects in neighbor caches.])
AC_MSG_NOTICE([Cache Digests enabled: $enable_cache_digests])


################################
# check for netio plugin stuff #
################################
dnl order of these options handling is relevant in case the user
dnl supplies more than one --enable option. Options handled later
dnl override those handled earlier for io loop method manual override
AC_ARG_ENABLE(select,
  AS_HELP_STRING([--disable-select],[Disable select(2) support.]),[
  SQUID_YESNO([$enableval],[--enable-select])
  AS_IF([test "x$enableval" = "xyes"],[squid_opt_io_loop_engine="select"])
])
AC_MSG_NOTICE([enabling select syscall for net I/O: ${enable_select:=auto}])

AC_ARG_ENABLE(poll,
  AS_HELP_STRING([--disable-poll],[Disable poll(2) support.]),[
  SQUID_YESNO([$enableval],[--enable-poll])
  AS_IF([test "x$enableval" = "xyes"],[squid_opt_io_loop_engine="poll"])
])
AC_MSG_NOTICE([enabling poll syscall for net I/O: ${enable_poll:=auto}])

AC_ARG_ENABLE(kqueue,
  AS_HELP_STRING([--disable-kqueue],
                 [Disable kqueue(2) support.]), [
  SQUID_YESNO([$enableval],[--enable-kqueue])
])
AS_IF([test "x${enable_kqueue:=auto}" != "xno"],[
  AC_CHECK_HEADERS([sys/event.h],[],[
    AS_IF([test "x${enable_kqueue}" = "xyes"],[
      AC_MSG_ERROR([kqueue support requires sys/event.h header file.])
    ])
  ])
  AC_CHECK_FUNCS(kqueue,[],[
    AS_IF([test "x${enable_kqueue}" = "xyes"],[
      AC_MSG_ERROR([kqueue support missing in libc library.])
    ])
  ])
  AS_IF([test "x$ac_cv_func_kqueue" = "xyes" -a "x$ac_cv_header_sys_event_h" = "xyes"],[
    squid_opt_io_loop_engine="kqueue"
  ],[
    enable_kqueue="no"
  ])
])
AC_MSG_NOTICE([enabling kqueue for net I/O: ${enable_kqueue:=auto}])

dnl Enable epoll()
AC_ARG_ENABLE(epoll,
  AS_HELP_STRING([--disable-epoll],[Disable Linux epoll(2) support.]),
[
  SQUID_YESNO([$enableval],[--enable-epoll])
AS_IF([test "x$enableval" = "xyes"],[squid_opt_io_loop_engine="epoll"])
])
AC_MSG_NOTICE([enabling epoll syscall for net I/O: ${enable_epoll:=auto}])

# auto-detect and verify epoll header and library present and working
# logic mapping and loop method selection are performed later
AS_IF([test "x$enable_epoll" != "xno"],[
  # check if libs are needed to support epoll
  SQUID_STATE_SAVE(squid_epoll_state)
  AC_SEARCH_LIBS(epoll_ctl,[epoll])
  AS_IF([test "x$ac_cv_search_epoll_ctl" = "xno"],[enable_epoll=no],
    [test "x$ac_cv_search_epoll_ctl" = "xnone required"],[EPOLL_LIBS=""],
    [EPOLL_LIBS=$ac_cv_search_epoll_ctl]
  )
  AC_SUBST(EPOLL_LIBS)
  SQUID_STATE_ROLLBACK(squid_epoll_state) #de-pollute LIBS

  # epoll requires sys/epoll.h
  AC_CHECK_HEADERS([sys/epoll.h])

  dnl Verify that epoll really works
  AS_IF([test "x$ac_cv_search_epoll_ctl" != "xno"], SQUID_CHECK_EPOLL)

  AS_IF([test "x$enable_epoll" = "xyes" -a "x$squid_cv_epoll_works" = "xno"],[
    AC_MSG_ERROR([Epoll does not work. Force-enabling it is not going to help.])
  ])
])

dnl Enable /dev/poll
AC_ARG_ENABLE(devpoll,
  AS_HELP_STRING([--disable-devpoll],[Disable Solaris /dev/poll support.]),[
  SQUID_YESNO([$enableval],[--enable-devpoll])
  AS_IF([test "x$enableval" = "xyes"],[squid_opt_io_loop_engine="devpoll"])
])
AC_MSG_NOTICE([enabling /dev/poll for net I/O: ${enable_devpoll:=auto}])

## auto-detect and verify devpoll header and library present and working
AS_IF([test "x$enable_devpoll" != "xno"],[
  # /dev/poll requires ioctl() and write()
  AC_CHECK_FUNCS(ioctl)
  AC_CHECK_FUNCS(write)

  # /dev/poll requires sys/devpoll.h
  AC_CHECK_HEADERS([sys/devpoll.h],,[
    AS_IF([test "x$enable_devpoll" = "xyes"],[
      AC_MSG_ERROR([--enable-devpoll specified but /dev/poll headers not found])
    ])
    enable_devpoll=no
  ])

  # Verify that /dev/poll really works
  AS_IF([test "x$enable_devpoll" != "xno"], SQUID_CHECK_DEVPOLL)

  AS_IF([test "x$enable_devpoll" = "xyes" -a "x$squid_cv_devpoll_works" = "xno"],[
    AC_MSG_ERROR([/dev/poll does not work. Force-enabling it is not going to help.])
  ])
])

AC_ARG_ENABLE(http-violations,
  AS_HELP_STRING([--disable-http-violations],
                 [This allows you to remove code which is known to
                  violate the HTTP protocol specification.]), [
  SQUID_YESNO([$enableval],[--enable-http-violations])
])
SQUID_DEFINE_BOOL(USE_HTTP_VIOLATIONS, ${enable_http_violations:=yes},
  [Define to enable code which volates the HTTP standard specification])
AC_MSG_NOTICE([HTTP violations support enabled: $enable_http_violations])

# IPFW Transparent Proxy
AC_ARG_ENABLE(ipfw-transparent,
  AS_HELP_STRING([--enable-ipfw-transparent],
                 [Enable Transparent Proxy support for systems
                  using FreeBSD IPFW-style firewalling.]), [
  SQUID_YESNO([$enableval],[--enable-ipfw-transparent])
])
SQUID_DEFINE_BOOL(IPFW_TRANSPARENT,${enable_ipfw_transparent:=no},
  [Enable support for Transparent Proxy on systems using FreeBSD IPFW-style firewalling.])
AC_MSG_NOTICE([FreeBSD IPFW-based transparent proxying enabled: $enable_ipfw_transparent])

# IP-Filter Transparent Proxy
AC_ARG_ENABLE(ipf-transparent,
  AS_HELP_STRING([--enable-ipf-transparent],
     [Enable Transparent Proxy support using IPFilter-style firewalling]), [
  SQUID_YESNO([$enableval],[--enable-ipf-transparent])
])
#will be AC_DEFINEd later, after checking for appropriate infrastructure
#IPF currently broken. Default-disabled for now.
AC_MSG_NOTICE([IPF-based transparent proxying requested: ${enable_ipf_transparent:=no}])

dnl Enable PF Transparent Proxy
AC_ARG_ENABLE(pf-transparent,
  AS_HELP_STRING([--enable-pf-transparent],
    [Enable Transparent Proxy support for systems using PF network address redirection.]), [
  SQUID_YESNO([$enableval],[--enable-pf-transparent])
])
#will be AC_DEFINEd later, after checking for appropriate infrastructure
AC_MSG_NOTICE([PF-based transparent proxying requested: ${enable_pf_transparent:=no}])

dnl Enable /dev/pf support for older PF Transparent Proxy systems (OpenBSD 4.x and older)
AC_ARG_WITH(nat-devpf,
  AS_HELP_STRING([--with-nat-devpf],
    [Enable /dev/pf support for NAT on older OpenBSD and FreeBSD kernels.]), [
  SQUID_YESNO([$withval],[--with-nat-devpf])
])
#will be AC_DEFINEd later, after checking for appropriate infrastructure
AC_MSG_NOTICE([NAT lookups via /dev/pf: ${with_nat_devpf:=no}])

# Linux Netfilter Transparent Proxy
AC_ARG_ENABLE(linux-netfilter,
  AS_HELP_STRING([--enable-linux-netfilter],
                 [Enable Transparent Proxy support for Linux (Netfilter)]), [
  SQUID_YESNO([$enableval],[--enable-linux-netfilter])
])
AC_MSG_NOTICE([Linux Netfilter support requested: ${enable_linux_netfilter:=auto}])
#will be AC_DEFINEd later, after checking for appropriate infrastructure


dnl Look for libnetfilter_conntrack options (needed for QOS netfilter marking)
SQUID_AUTO_LIB(netfilter-conntrack,[Netfilter conntrack],[LIBNETFILTER_CONNTRACK])
SQUID_CHECK_LIB_WORKS(netfilter-conntrack,[
  PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK],[libnetfilter_conntrack],[:],[:])
  CPPFLAGS="$LIBNETFILTER_CONNTRACK_CFLAGS $CPPFLAGS"
  LIBS="$LIBNETFILTER_CONNTRACK_PATH $LIBNETFILTER_CONNTRACK_LIBS $LIBS"
  AC_CHECK_HEADERS([ \
    libnetfilter_conntrack/libnetfilter_conntrack.h \
    libnetfilter_conntrack/libnetfilter_conntrack_tcp.h \
  ])
])

dnl Enable Large file support
buildmodel=""

AC_ARG_WITH(large-files,
  AS_HELP_STRING([--with-large-files],[Enable support for large files (logs etc).]), [
  SQUID_YESNO([$withval],[--with-large-files])
  squid_opt_enable_large_files=$withval
])

dnl UNIX Build environment
dnl AS_HELP_STRING is not suited here because it cannot to specify newlines
AC_ARG_WITH(build-environment,
 AS_HELP_STRING([--with-build-environment=model],
     [The build environment to use. Normally one of
      POSIX_V6_ILP32_OFF32 (32 bits),
      POSIX_V6_ILP32_OFFBIG (32 bits with large file support),
      POSIX_V6_LP64_OFF64 (64 bits),
      POSIX_V6_LPBIG_OFFBIG (large pointers and files),
      XBS5_ILP32_OFF32 i(legacy, 32 bits),
      XBS5_ILP32_OFFBIG (legacy, 32 bits with large file support),
      XBS5_LP64_OFF64 (legacy, 64 bits),
      XBS5_LPBIG_OFFBIG (legacy, large pointers and files)
      or default (The default for your OS)]), [
  AS_CASE(["$withval"],
    [yes|no],[AC_MSG_FAILURE([--with-build-environment expects a build environment string as used by getconf])],
    [buildmodel="$withval"]
  )
])

#hack. Let's early-detect sizeof(long)
AC_CHECK_SIZEOF(long)

AS_IF([test "x$squid_opt_enable_large_files" = "xyes" -a "x$buildmodel" = "x"],[
  for model in POSIX_V6_LPBIG_OFFBIG XBS5_LPBIG_OFFBIG POSIX_V6_LP64_OFF64 XBS5_LP64_OFF64 POSIX_V6_ILP32_OFFBIG XBS5_ILP32_OFFBIG; do
    AS_IF([test "`getconf _$model 2>/dev/null || true`" = 1 -o "`getconf $model 2>/dev/null || true`"],[
      buildmodel=$model
      break
    ])
  done
  AS_IF([test "x$buildmodel" = "x"],[
    AC_MSG_WARN([No suitable build environment found for large files. Trying to use _FILE_OFFSET_BITS=64])
  ])
])
AS_IF([test "x$buildmodel" = "xdefault" -o "x$buildmodel" = "x"],[
  # define _FILE_OFFSET_BITS if requested and needed
  AS_IF([test "x$squid_opt_enable_large_files" = "xyes" -a $ac_cv_sizeof_long -le 4],[
    AC_MSG_NOTICE([Enabling -D_FILE_OFFSET_BITS=64])
    CFLAGS="-D_FILE_OFFSET_BITS=64 $CFLAGS"
    CXXFLAGS="-D_FILE_OFFSET_BITS=64 $CXXFLAGS"
  ])
],[
  AC_MSG_NOTICE([Using $buildmodel build environment])
  AS_IF([ ! test "`getconf _$buildmodel 2>/dev/null || true`" = 1 -o "`getconf $buildmodel 2>/dev/null || true`"],[
    AC_MSG_ERROR([Build environment $buildmodel not known to getconf.])
  ])
  CFLAGS="`getconf ${buildmodel}_CFLAGS` $CFLAGS"
  CXXFLAGS="`getconf ${buildmodel}_CFLAGS` $CXXFLAGS"
  LIBS="`getconf ${buildmodel}_LIBS` $LIBS"
  LDFLAGS="`getconf ${buildmodel}_LDFLAGS` $LDFLAGS"

  AS_IF([test "x$squid_host_os" = "xsolaris"],[
# On Solaris getconf returns for CFLAGS -xarch=generic64, -Xa and -Usun options, and
# for LDFLAGS -xarch=generic64, but:
#   "-Xa" is supported only by Sun cc, so we need to remove it when using gcc
#   For gcc "-xarch=generic64" must be replaced with "-m64"
#   The 'sun' define is needed by ipfilter includes, so we must remove "-Usun"
    AS_IF([test "x$GCC" = "xyes"],[
      AC_MSG_NOTICE([Removing -Xa for gcc/g++ on $host])
      CFLAGS="`echo $CFLAGS | sed -e 's/-Xa//'`"
      CXXFLAGS="`echo $CXXFLAGS | sed -e 's/-Xa//'`"
      AC_MSG_NOTICE([Replacing -xarch=generic64 with -m64 for gcc/g++ on $host])
      CFLAGS="`echo $CFLAGS | sed -e 's/-xarch=generic64/-m64/'`"
      CXXFLAGS="`echo $CXXFLAGS | sed -e 's/-xarch=generic64/-m64/'`"
      LDFLAGS="`echo $LDFLAGS | sed -e 's/-xarch=generic64//'`"
    ])
    AC_MSG_NOTICE([Removing -Usun on $host])
    CFLAGS="`echo $CFLAGS | sed -e 's/-Usun//'`"
    CXXFLAGS="`echo $CXXFLAGS | sed -e 's/-Usun//'`"
  ])
])

AC_ARG_ENABLE(follow-x-forwarded-for,
  AS_HELP_STRING([--disable-follow-x-forwarded-for],
                 [Do not follow the X-Forwarded-For
                 HTTP header to try to find the IP address of the
                 original or indirect client when a request has
                 been forwarded through other proxies.]), [
  SQUID_YESNO([$enableval],[--enable-follow-x-forwarded-for])
])
AC_MSG_NOTICE([Support for X-Forwarded-For enabled: ${enable_follow_x_forwarded_for:=yes}])
SQUID_DEFINE_BOOL(FOLLOW_X_FORWARDED_FOR,$enable_follow_x_forwarded_for,
  [Enable following X-Forwarded-For headers])

dnl Select Default hosts file location
AC_ARG_ENABLE(default-hostsfile,
  AS_HELP_STRING([--enable-default-hostsfile=path],
                 [Select default location for hosts file.
                  See hosts_file directive in squid.conf for details]), [
  # TODO: handle the "yes" case cleanly
  AS_CASE(["$enableval"],
    [no|none],[squid_opt_default_hosts="none"],
    [
      squid_opt_default_hosts=$enableval
      AS_IF([ ! test -f "$enableval"],[
        AC_MSG_WARN([Unable to find file $enableval. I hope you know what you are doing.])
      ])
    ])
])
AC_MSG_NOTICE([Default hosts file set to: ${squid_opt_default_hosts:=/etc/hosts}])
DEFAULT_HOSTS=$squid_opt_default_hosts
AC_SUBST(DEFAULT_HOSTS)

# Select auth schemes modules to build
AC_ARG_ENABLE(auth,
  AS_HELP_STRING([--disable-auth],
                 [Do not support authentication. When supported, the list of schemes
                  and helpers to be enabled is defined elsewhere]), [
  SQUID_YESNO([$enableval],[--enable-auth])
])
AC_MSG_NOTICE([Authentication support enabled: ${enable_auth:=yes}])
SQUID_DEFINE_BOOL(USE_AUTH,$enable_auth,[Enable support for authentication])
AM_CONDITIONAL(ENABLE_AUTH, test "x$enable_auth" != "xno")
AUTH_MODULES=""
require_sspi="no"

AC_ARG_ENABLE(auth-basic,
  AS_HELP_STRING([--enable-auth-basic="list of helpers"],
     [Enable the basic authentication scheme, and build the specified helpers.
      Not providing an explicit list of helpers will attempt build of
      all possible helpers. Default is to do so.
      To disable the basic authentication scheme, use --disable-auth-basic.
      To enable but build no helpers, specify "none".
      To see available helpers, see the src/auth/basic/ directory. ]),[
#nothing to do really
])
m4_include([src/auth/basic/helpers.m4])

AC_ARG_ENABLE(auth-digest,
  AS_HELP_STRING([--enable-auth-digest="list of helpers"],
     [Enable the Digest authentication scheme, and build the specified helpers.
      Not providing an explicit list of helpers will attempt build of
      all possible helpers. Default is to do so.
      To disable the Digest authentication scheme, use --disable-auth-digest.
      To enable but build no helpers, specify "none".
      To see available helpers, see the src/auth/digest/ directory. ]),[
#nothing to do, really
])
m4_include([src/auth/digest/helpers.m4])

AC_ARG_ENABLE(auth-negotiate,
  AS_HELP_STRING([--enable-auth-negotiate="list of helpers"],
     [Enable the Negotiate authentication scheme, and build the specified
      helpers.
      Not providing an explicit list of helpers will attempt build of
      all possible helpers. Default is to do so.
      To disable the Negotiate authentication scheme,
      use --disable-auth-negotiate.
      To enable but build no helpers, specify "none".
      To see available helpers, see the src/auth/negotiate/ directory. ]),[
#nothing to do, really
])
m4_include([src/auth/negotiate/helpers.m4])

AC_ARG_ENABLE(auth-ntlm,
  AS_HELP_STRING([--enable-auth-ntlm="list of helpers"],
     [Enable the NTLM authentication scheme, and build the specified helpers.
      Not providing an explicit list of helpers will attempt build of
      all possible helpers. Default is to do so.
      To disable the NTLM authentication scheme, use --disable-auth-ntlm.
      To enable but build no helpers, specify "none".
      To see available helpers, see the src/auth/ntlm/ directory. ]),[
])
m4_include([src/auth/ntlm/helpers.m4])

dnl Authentication libraries to build
dnl This list will not be needed when each auth library has its own Makefile
dnl this is to be placed AFTER each auth module's handler
AUTH_LIBS_TO_BUILD=
for module in $AUTH_MODULES; do
    AUTH_LIBS_TO_BUILD="$AUTH_LIBS_TO_BUILD ${module}/lib${module}.la"
done
AC_SUBST(AUTH_MODULES)
AC_SUBST(AUTH_LIBS_TO_BUILD)
AM_CONDITIONAL(ENABLE_SSPI, test "x$require_sspi" = "xyes")

dnl Select logging daemon helpers to build
AC_ARG_ENABLE(log-daemon-helpers,
  AS_HELP_STRING([--enable-log-daemon-helpers="list of helpers"],
                 [This option selects which logging daemon helpers to
                  build and install as part of the normal build process
                  For a list of available helpers see the src/log/
                  directory.]),[
#nothing to do, really
])
m4_include([src/log/helpers.m4])

AC_ARG_ENABLE(external-acl-helpers,
  AS_HELP_STRING([--enable-external-acl-helpers="list of helpers"],
                 [Enable external_acl helpers support and the helpers themselves.
                  Default is to build all buildable helpers and enable support.
                  To disable support, use --disable-external-acl-helpers.
                  To build no helpers, specify "none".
                  To see available helpers, see the src/acl/external/
                  directory]), [
#nothing to do, really
])
m4_include([src/acl/external/helpers.m4])

dnl Select url_rewrite helpers to build
AC_ARG_ENABLE(url-rewrite-helpers,
  AS_HELP_STRING([--enable-url-rewrite-helpers="list of helpers"],
                 [This option selects which url_rewrite helpers to
                  build and install as part of the normal build
                  process. The default is to attempt the build of all possible
                  helpers. Use --disable-url-rewrite-helpers to build none.
                  For a list of available helpers see the
                  src/http/url_rewriters/ directory.]),[
])
m4_include([src/http/url_rewriters/helpers.m4])

dnl Select security helpers to build
AC_ARG_ENABLE(security-cert-validators,
  AS_HELP_STRING([--enable-security-cert-validators="list of helpers"],
                 [This option selects which security certificate validator
                  helpers to build and install as part of the normal build
                  process. The default is to attempt the build of all possible
                  helpers. Use --disable-security-cert-validators to
                  build none. For a list of available helpers see the
                  src/security/cert_validators/ directory.]),[
])
m4_include([src/security/cert_validators/helpers.m4])

AC_ARG_ENABLE(security-cert-generators,
  AS_HELP_STRING([--enable-security-cert-generators="list of helpers"],
                 [This option selects which security certificate validator
                  helpers to build and install as part of the normal build
                  process. The default is to attempt the build of all possible
                  helpers. Use --disable-security-cert-genrators to
                  build none. For a list of available helpers see the
                  src/security/cert_generators/ directory.]),[
])
m4_include([src/security/cert_generators/helpers.m4])

dnl Select storeid_rewrite helpers to build
AC_ARG_ENABLE(storeid-rewrite-helpers,
  AS_HELP_STRING([--enable-storeid-rewrite-helpers="list of helpers"],
                 [This option selects which Store-ID rewrite helpers to
                  build and install as part of the normal build
                  process. The default is to attempt the build of all possible
                  helpers. Use --disable-storeid-rewrite-helpers to build none.
                  For a list of available helpers see the
                  src/store/id_rewriters/ directory.]),[
])
m4_include([src/store/id_rewriters/helpers.m4])

AC_ARG_WITH(valgrind-debug,
  AS_HELP_STRING([--with-valgrind-debug],
                 [Include debug instrumentation for use with valgrind]),
[
  SQUID_YESNO([$withval],[--with-valgrind-debug])
  AS_IF([test "x$withval" != "xno"],[
    AC_CHECK_HEADERS(valgrind/memcheck.h,[],[
      AC_MSG_ERROR([Valgrind support requested, needed headers not found.])
    ])
  ])
])
SQUID_DEFINE_BOOL(WITH_VALGRIND,${with_valgrind_debug:=no},
                  [Valgrind memory debugger support])
AC_MSG_NOTICE([Valgrind debug support enabled: $with_valgrind_debug])

dnl Enable WIN32 Service compile mode
AC_ARG_ENABLE(win32-service,
  AS_HELP_STRING([--enable-win32-service],
                 [Compile Squid as a WIN32 Service.
                  Works only on MS-Windows platforms]), [
  SQUID_YESNO([$enableval],[--enable-win32-service])
])
SQUID_DEFINE_BOOL(USE_WIN32_SERVICE,${enable_win32_service:=no},
   [Enable code supporting MS Windows service mode])
AC_MSG_NOTICE([MS Windows service mode enabled: $enable_win32_service])


# Disable "unlinkd" code
AC_ARG_ENABLE(unlinkd,
  AS_HELP_STRING([--disable-unlinkd],[Do not use unlinkd]), [
  SQUID_YESNO([$enableval],[--enable-unlinkd])
])
SQUID_DEFINE_BOOL(USE_UNLINKD,${enable_unlinkd:=yes},
                      [Enable useage of unlinkd])
AM_CONDITIONAL(ENABLE_UNLINKD,test "x$enable_unlinkd" = "xyes")
AC_MSG_NOTICE([unlinkd enabled: $enable_unlinkd])

# Enable backtraces on fatal errors
AC_ARG_ENABLE(stacktraces,
  AS_HELP_STRING([--enable-stacktraces],
                 [Enable automatic call backtrace on fatal errors]), [
  SQUID_YESNO([$enableval],[--enable-stacktraces])
])
SQUID_DEFINE_BOOL(PRINT_STACK_TRACE,${enable_stacktraces:=no},
                      [Print stack traces on fatal errors])
AC_MSG_NOTICE([Automatically print stack trace on fatal errors: $enable_stacktraces])

# Enable X-Accelerator-Vary for Vary support within an accelerator setup
AC_ARG_ENABLE(x-accelerator-vary,
  AS_HELP_STRING([--enable-x-accelerator-vary],
                 [Enable support for the X-Accelerator-Vary
                  HTTP header. Can be used to indicate
                  variance within an accelerator setup.
                  Typically used together with other code
                  that adds custom HTTP headers to the requests.]), [
  SQUID_YESNO([$enableval],[--enable-x-accelerator-vary])
])
SQUID_DEFINE_BOOL(X_ACCELERATOR_VARY,${enable_x_accelerator_vary:=no},
                      [Enable support for the X-Accelerator-Vary HTTP header])
AC_MSG_NOTICE([X-Accelerator-Vary support enabled: $enable_x_accelerator_vary])

SQUID_AUTO_LIB(cppunit,[cppunit test framework],[LIBCPPUNIT])
SQUID_CHECK_LIB_WORKS(cppunit,[
  PKG_CHECK_MODULES([LIBCPPUNIT],[cppunit],[
    squid_cv_cppunit_version="`pkg-config --modversion cppunit`"
    AC_MSG_NOTICE([using system installed cppunit version $squid_cv_cppunit_version])
    AS_UNSET(squid_cv_cppunit_version)

    CXXFLAGS="${CXXFLAGS} ${LIBCPPUNIT_CFLAGS}"
    LIBS="${LIBS} ${LIBCPPUNIT_LIBS}"
    AC_CHECK_HEADERS(cppunit/extensions/HelperMacros.h)
  ],[
    AC_MSG_WARN([cppunit does not appear to be installed. Squid does not require this, but code testing with 'make check' will fail.])
  ])
])

dnl Check for headers
AC_CHECK_HEADERS( \
  arpa/inet.h \
  arpa/nameser.h \
  assert.h \
  bstring.h \
  crypt.h \
  ctype.h \
  direct.h \
  dirent.h \
  errno.h \
  execinfo.h \
  fcntl.h \
  fnmatch.h \
  getopt.h \
  glob.h \
  gnumalloc.h \
  grp.h \
  ipl.h \
  libc.h \
  limits.h \
  linux/posix_types.h \
  linux/types.h \
  malloc.h \
  math.h \
  memory.h \
  mount.h \
  netdb.h \
  netinet/in.h \
  netinet/in_systm.h \
  netinet/tcp.h \
  paths.h \
  poll.h \
  priv.h \
  pwd.h \
  regex.h \
  sched.h \
  siginfo.h \
  signal.h \
  stdarg.h \
  stddef.h \
  stdio.h \
  stdlib.h \
  string.h \
  strings.h \
  sys/bitypes.h \
  sys/file.h \
  sys/ioctl.h \
  sys/ipc.cc \
  sys/param.h \
  sys/prctl.h \
  sys/procctl.h \
  sys/md5.h \
  sys/mman.h \
  sys/msg.h \
  sys/resource.h \
  sys/select.h \
  sys/shm.h \
  sys/socket.h \
  sys/stat.h \
  syscall.h \
  sys/syscall.h \
  sys/time.h \
  sys/types.h \
  sys/uio.h \
  sys/un.h \
  sys/vfs.h \
  sys/wait.h \
  syslog.h \
  time.h \
  unistd.h \
  utime.h \
  varargs.h \
  byteswap.h \
  glib.h \
  stdint.h \
  inttypes.h \
  wchar.h
)

AC_CHECK_HEADERS( \
  linux/netfilter_ipv4.h \
  linux/netfilter_ipv6/ip6_tables.h \
,,,
SQUID_DEFAULT_INCLUDES
#if HAVE_LIMITS_H
#include <limits.h>
#endif
/* Netfilter ip(6)tables v1.4.0 has broken headers */
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
)

dnl *BSD do not include the dependencies for all their net/ and netinet/ files
dnl We must include a few basic type headers for them to work.
AC_CHECK_HEADERS( \
  net/if.h \
  netinet/if_ether.h\
  netinet/icmp6.h \
  netinet/in.h \
  netinet/ip.h \
  netinet/ip6.h \
  netinet/ip_icmp.h \
  netinet/ipl.h \
  net/pf/pfvar.h \
  net/pfvar.h \
  sys/mount.h\
  resolv.h \
,,,
SQUID_BSDNET_INCLUDES)

AC_C_CONST
AC_C_BIGENDIAN

AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[
#if HAVE_TIME_H
#include <time.h>
#endif
])

AC_CHECK_TYPE(struct rusage,AC_DEFINE(HAVE_STRUCT_RUSAGE,1,[The system provides struct rusage]),,[
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
])

AC_CHECK_MEMBERS([struct iphdr.ip_hl],,,[
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#if defined (__linux__) || defined (__CYGWIN__)
#define ip_hl ihl
#endif
#ifndef __linux__
#ifndef __CYGWIN__
#define iphdr ip
#endif
#endif])

dnl Check for typedefs
AC_CHECK_SIZEOF(void *)

# check for a bunch of types
AC_TYPE_INT8_T
AC_TYPE_UINT8_T
AC_TYPE_INT16_T
AC_TYPE_UINT16_T
AC_TYPE_INT32_T
AC_TYPE_UINT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_OFF_T
AC_TYPE_UID_T
AC_CHECK_TYPE([bool])
#need the defines for PRId64
AC_CHECK_SIZEOF(int64_t)
AC_CHECK_SIZEOF(long)
#need the define for overflow checks
AC_CHECK_SIZEOF(off_t)
AC_CHECK_SIZEOF(size_t)

dnl On Solaris 9 x86, gcc may includes a "fixed" set of old system include files
dnl that is incompatible with the updated Solaris header files.
dnl For this reason, we must check if pad128_t and upad128_t are defined.
AC_CHECK_TYPE(pad128_t,
  AC_DEFINE(HAVE_PAD128_T,1,[pad128_t is defined in system headers]),
  ,SQUID_DEFAULT_INCLUDES)

AC_CHECK_TYPE(upad128_t,
  AC_DEFINE(HAVE_UPAD128_T,1,[upad128_t is defined in system headers]),
  ,SQUID_DEFAULT_INCLUDES)

AC_CHECK_TYPE(mode_t, AC_DEFINE(HAVE_MODE_T,1,[mode_t is defined by the system headers]),,SQUID_DEFAULT_INCLUDES)
AC_CHECK_TYPE(fd_mask,  AC_DEFINE(HAVE_FD_MASK,1,[fd_mask is defined by the system headers]),,SQUID_DEFAULT_INCLUDES)

AC_CHECK_TYPE(socklen_t,AC_DEFINE(HAVE_SOCKLEN_T,1,[socklen_t is defined by the system headers]),,[
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stddef.h>
])

AC_CHECK_TYPE(mtyp_t,AC_DEFINE(HAVE_MTYP_T,1,
   [mtyp_t is defined by the system headers]),,[#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>])

AC_CHECK_TYPE(cpu_set_t,
   AC_DEFINE(HAVE_CPU_SET_T,1,[cpu_set_t is defined by the system headers]),,[
#if HAVE_SCHED_H
#include <sched.h>
#endif
])

dnl Check for special functions
AC_FUNC_ALLOCA

SQUID_AUTO_LIB(cap,[Linux capabilities],[LIBCAP])
SQUID_CHECK_LIB_WORKS(cap,[
  PKG_CHECK_MODULES([LIBCAP],[libcap >= 2.09],[:],[:])
  CPPFLAGS="$LIBCAP_CFLAGS $CPPFLAGS"
  LIBS="$LIBCAP_PATH $LIBCAP_LIBS $LIBS"
  SQUID_CHECK_FUNCTIONAL_LIBCAP2
  AC_MSG_NOTICE([libcap headers are ok: $squid_cv_sys_capability_works])
  AS_IF([test "x$squid_cv_sys_capability_works" = "xno"],[LIBCAP_LIBS=""])
])

dnl Check for needed libraries
AC_SEARCH_LIBS([gethostbyname],[nsl resolv bind])
AC_SEARCH_LIBS([res_init],[resolv])
AC_SEARCH_LIBS([__res_search],[resolv])
AC_SEARCH_LIBS([bind],[socket])
AC_SEARCH_LIBS([opcom_stack_trace],[opcom_stack])
AC_SEARCH_LIBS([yp_match], [nsl nss_nis nss_nisplus])

# check that we have unix sockets
SQUID_CHECK_UNIX_SOCKET
SQUID_DEFINE_BOOL(HAVE_UNIXSOCKET,$squid_cv_unixsocket,[System supports unix sockets])

AC_CHECK_LIB(gnumalloc, malloc)
AS_IF([test "x$ac_cv_lib_gnumalloc_malloc" = "xyes"],[
  AC_MSG_NOTICE([Disabling extended malloc functions when using bundled gnumalloc])
  ac_cv_func_mallocblksize=no
  ac_cv_func_mallopt=no
],[
  AS_CASE(["$squid_host_os"],
    [solaris],[AC_MSG_NOTICE([skipping libmalloc check for $host])],
    [freebsd],[AC_MSG_NOTICE([skipping libmalloc check for $host])],
    [AC_CHECK_LIB(malloc, main)]
  )
])

AS_IF([test "$squid_host_os" = "mingw"],[
  AC_MSG_NOTICE([Use MSVCRT for math functions.])
],[
  dnl log() are only used in old C code for now.
  AC_LANG_PUSH([C])
  AC_SEARCH_LIBS([log],[m])
  AC_LANG_POP([C])
])

dnl --with-maxfd present for compatibility with Squid-2.
dnl undocumented in ./configure --help  to encourage using the Squid-3 directive
AC_ARG_WITH(maxfd,,[
  AS_CASE([$withval],
    [@<:@0-9@:>@*],[
      squid_filedescriptors_num=$withval
      AC_MSG_NOTICE([forcing default of $squid_filedescriptors_num filedescriptors (user-forced)])
    ],
    [AC_MSG_ERROR(--with-maxfd expects a numeric argument)]
  )
])

AC_ARG_WITH(filedescriptors,
  AS_HELP_STRING([--with-filedescriptors=NUMBER],
    [Force squid to support NUMBER filedescriptors]),[
  AS_CASE([$withval],
    [@<:@0-9@:>@*],[
      squid_filedescriptors_num=$withval
      AC_MSG_NOTICE([forcing default of $squid_filedescriptors_num filedescriptors (user-forced)])],
    [AC_MSG_ERROR([--with-filedescriptors expects a numeric argument])]
  )
])

SQUID_CHECK_DEFAULT_FD_SETSIZE
SQUID_CHECK_MAXFD


dnl Enable IPv6 support
AC_MSG_CHECKING([whether to enable IPv6])
AC_ARG_ENABLE(ipv6,
  AS_HELP_STRING([--disable-ipv6],[Disable IPv6 support. The default is to probe system capabilities on startup.]), [
  SQUID_YESNO([$enableval],[--enable-ipv6])
])
AC_MSG_RESULT(${enable_ipv6:=yes})
SQUID_DEFINE_BOOL(USE_IPV6,$enable_ipv6,[Enable support for IPv6 ])

AS_IF([test "x$enable_ipv6" = "xyes"],[SQUID_CHECK_SIN6_LEN_IN_SAI])
SQUID_CHECK_SS_LEN_IN_SOCKADDR_STORAGE
SQUID_CHECK_SIN_LEN_IN_SOCKADDR_IN

dnl System-specific library modifications
AH_TEMPLATE(GETTIMEOFDAY_NO_TZP,[Whether gettimeofday takes only one argument])
AS_CASE(["$host"],
  [*-pc-sco3.2*],[
    # -lintl is needed on SCO version 3.2v4.2 for strftime()
    # Robert Side <rside@aiinc.bc.ca>
    # Mon, 18 Jan 1999 17:48:00 GMT
    AC_CHECK_LIB(intl, strftime)
  ],

  [i386-*-solaris2.*],[
    AS_IF([test "x$GCC" = "xyes"],[
      AC_MSG_NOTICE([Removing -O for gcc on $host])
      CFLAGS="`echo $CFLAGS | sed -e 's/-O[[0-9g]]*//'`"
    ])
  ],

  [*-sgi-irix*],[
    AC_MSG_NOTICE([Removing -lsocket for IRIX...])
    LIBS=`echo $LIBS | sed -e s/-lsocket//`
    AC_MSG_NOTICE([Removing -lnsl for IRIX...])
    LIBS=`echo $LIBS | sed -e s/-lnsl//`
    ac_cv_lib_nsl_main=no
  ],

  [*-ibm-aix*],[
    SQUID_CC_REQUIRE_ARGUMENT([ac_cv_require_rtti],[-rtti],[[
#include <assert.h>
#ifndef NULL
#define NULL 0
#endif
class Foo{
public:virtual ~Foo(){}
};
class Bar:public Foo{
public:Bar():Foo(){}
};
      ]],[[
Foo * myFoo=new Bar();
Bar * myBar=dynamic_cast<Bar *>(myFoo);
assert(myBar != NULL);
      ]])
    AS_IF([test "$ac_cv_require_rtti" = "yes"],[
      SQUID_CFLAGS="-rtti $SQUID_CFLAGS"
      SQUID_CXXFLAGS="-rtti $SQUID_CXXFLAGS"
    ])

    AC_LANG_PUSH([C])
    SQUID_CC_REQUIRE_ARGUMENT([ac_cv_require_qcpluscmt],[-qcpluscmt],[[]],[[//c++ cmt]])
    AC_LANG_POP([C])
    AS_IF([test "$ac_cv_require_qcpluscmt" = "yes"],[
      SQUID_CFLAGS="-qcpluscmt $SQUID_CFLAGS"
    ])
  ],

  [*-*-solaris2.[[0-4]]],[AC_DEFINE(GETTIMEOFDAY_NO_TZP,1)],

  [*-sony-newsos[[56]]*],[AC_DEFINE(GETTIMEOFDAY_NO_TZP,1)]
)

dnl This has to be before AC_CHECK_FUNCS
# Disable poll() on certain platforms. Override by setting ac_cv_func_poll
# when running configure.
AS_IF([test "x$ac_cv_func_poll" = "x"],[
  AS_CASE(["$host"],
    [*-hp-hpux*.*],[
      # Duane Wessels
      AC_MSG_NOTICE([disabling poll for $host...])
      ac_cv_func_poll='no'
    ],

    [*-linux-*],[
      # Henrik Nordstrom (hno@squid-cache.org) 19980817
      # poll is problematic on Linux.  We disable it
      # by default until Linux gets it right.
      rev=`uname -r | awk -F. '{printf "%03d%03d",$1,$2}'`
      AS_IF([test $rev -lt 002002],[
          AC_MSG_NOTICE([disabling poll for $host < 2.2...])
          ac_cv_func_poll='no'
      ])
    ],

    [powerpc-ibm-aix4.1.*],[
      # Mike Laster (mlaster@metavillage.com) 19981021
      AC_MSG_NOTICE([disabling poll for $host...])
      ac_cv_func_poll='no'
    ]
  )
])

dnl Check for library functions
AC_CHECK_FUNCS(\
	backtrace_symbols_fd \
	bcopy \
	eui64_aton \
	fchmod \
	getdtablesize \
	getpagesize \
	getpass \
	getrusage \
	getspnam \
	gettimeofday \
	glob \
	mallocblksize \
	mallopt \
	memcpy \
	memmove \
	memrchr \
	memset \
	mkstemp \
	mktime \
	mstats \
	poll \
	prctl \
	procctl \
	pthread_attr_setschedparam \
	pthread_attr_setscope \
	pthread_setschedparam \
	pthread_sigmask \
	putenv \
	regcomp \
	regexec \
	regfree \
	res_init \
	__res_init \
	rint \
	sched_getaffinity \
	sched_setaffinity \
	select \
	seteuid \
	setgroups \
	setpflags \
	setpgrp \
	setsid \
	setresuid \
	sigaction \
	snprintf \
	socketpair \
	sysconf \
	syslog \
	timegm \
	vsnprintf \
)
dnl ... and some we provide local replacements for
AC_REPLACE_FUNCS(\
	initgroups \
	psignal \
	strerror \
	strtoll \
	tempnam \
)

# Magic which checks whether we are forcing a type of comm loop we
# are actually going to (ab)use.
# Mostly ripped from squid-commloops, thanks to adrian and benno

AS_IF([test "x$squid_opt_io_loop_engine" != "x"],
  AC_MSG_NOTICE([choosing user-specified net I/O API $squid_opt_io_loop_engine]),
  [test "x$enable_epoll" != "xno" -a "x$squid_cv_epoll_works" = "xyes"],
  squid_opt_io_loop_engine="epoll",
  [test "x$enable_kqueue" != "xno"],
  squid_opt_io_loop_engine="kqueue",
  [test "x$enable_devpoll" != "xno"],
  squid_opt_io_loop_engine="devpoll",
  [test "x$enable_poll" != "xno" -a "x$ac_cv_func_poll" = "xyes"],
  squid_opt_io_loop_engine="poll",
  [test "x$enable_select" != "xno" -a "x$ac_cv_func_select" = "xyes"],
  squid_opt_io_loop_engine="select",
  [
    AC_MSG_WARN([Eep!  Cannot find epoll, kqueue, /dev/poll, poll or select!])
    AC_MSG_WARN([Will try select and hope for the best.])
    squid_opt_io_loop_engine="select"
  ]
)

AC_MSG_NOTICE([Using ${squid_opt_io_loop_engine} for the IO loop.])

AM_CONDITIONAL(ENABLE_POLL, test "x$squid_opt_io_loop_engine" = "xpoll")
AM_CONDITIONAL(ENABLE_EPOLL, test "x$squid_opt_io_loop_engine" = "xepoll")
AM_CONDITIONAL(ENABLE_SELECT, test "x$squid_opt_io_loop_engine" = "xselect")
AM_CONDITIONAL(ENABLE_KQUEUE, test "x$squid_opt_io_loop_engine" = "xkqueue")
AM_CONDITIONAL(ENABLE_DEVPOLL, test "x$squid_opt_io_loop_engine" = "xdevpoll")

AS_CASE([$squid_opt_io_loop_engine],
  [epoll],[AC_DEFINE(USE_EPOLL,1,[Use epoll() for the IO loop])],
  [devpoll],[AC_DEFINE(USE_DEVPOLL,1,[Use /dev/poll for the IO loop])],
  [poll],[AC_DEFINE(USE_POLL,1,[Use poll() for the IO loop])],
  [kqueue],[AC_DEFINE(USE_KQUEUE,1,[Use kqueue() for the IO loop])],
  [select],[AC_DEFINE(USE_SELECT,1,[Use select() for the IO loop])],
)

AS_IF([test "x$ac_cv_func_sched_getaffinity" = "xyes" -a "x$ac_cv_func_sched_setaffinity" = "xyes"],[
  AC_DEFINE(HAVE_CPU_AFFINITY,1,[Support setting CPU affinity for workers])
])

AC_CHECK_HEADERS(mswsock.h)
AC_MSG_CHECKING([for constant CMSG_SPACE])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  #if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
  #if HAVE_MSWSOCK_H
  #include <mswsock.h>
  #endif

  int a[CMSG_SPACE(int)];
]])], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_CONSTANT_CMSG_SPACE, 1, [Define to 1 if CMSG_SPACE is constant])
], [
  AC_MSG_RESULT(no)
])

AC_CHECK_TYPE(struct cmsghdr,AC_DEFINE(HAVE_CMSGHDR,1,[The system provides struct cmsghdr]),,[
  #if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
  #if HAVE_MSWSOCK_H
  #include <mswsock.h>
  #endif
  #if HAVE_WINSOCK2_H
  #include <winsock2.h>
  #endif
])

AC_CHECK_TYPE(struct iovec,AC_DEFINE(HAVE_IOVEC,1,[The system provides struct iovec]),,[
  #if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
  #if HAVE_WINSOCK2_H
  #include <winsock2.h>
  #endif
  #if HAVE_SYS_UIO_H
  #include <sys/uio.h>
  #endif
])

AC_CHECK_TYPE(struct msghdr,AC_DEFINE(HAVE_MSGHDR,1,[The system provides struct msghdr]),,[
  #if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
  #if HAVE_MSWSOCK_H
  #include <mswsock.h>
  #endif
  #if HAVE_WINSOCK2_H
  #include <winsock2.h>
  #endif
])

AC_CHECK_TYPE(struct sockaddr_un,AC_DEFINE(HAVE_SOCKADDR_UN,1,[The system provides sockaddr_un]),,[
  #if HAVE_SYS_UN_H
  #include <sys/un.h>
  #endif
  #if HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
  #if HAVE_WINSOCK2_H
  #include <winsock2.h>
  #endif
])

dnl IP-Filter support requires ipf header files. These aren't
dnl installed by default, so we need to check for them
AS_IF([test "x$enable_ipf_transparent" != "xno"],[
  SQUID_CHECK_BROKEN_SOLARIS_IPFILTER
  AC_MSG_CHECKING(for availability of IP-Filter header files)
  # hold on to your hats...
  AS_IF(
  [test "x$ac_cv_header_ip_compat_h" = "xyes" -o \
    "x$ac_cv_header_ip_fil_compat_h" = "xyes" -o \
    "x$ac_cv_header_netinet_ip_compat_h" = "xyes" -o \
    "x$ac_cv_header_netinet_ip_fil_compat_h" = "xyes"],
  [have_ipfilter_compat_header="yes"])

  AS_IF(
  [test "x$have_ipfilter_compat_header" = "xyes" -a \
    "x$ac_cv_header_ip_fil_h" = "xyes" -a \
    "x$ac_cv_header_ip_nat_h" = "xyes"],[enable_ipf_transparent="yes"],

  [test "x$have_ipfilter_compat_header" = "xyes" -a \
    "x$ac_cv_header_netinet_ip_fil_h" = "xyes" -a \
    "x$ac_cv_header_netinet_ip_nat_h" = "xyes"],[enable_ipf_transparent="yes"],
  [enable_ipf_transparent="no"])

  AC_MSG_RESULT($IPF_TRANSPARENT)

## On Solaris Ipfilter includes expect that SOLARIS2 is defined with the
## Solaris minor version (8, 9, 10, ...)
  AS_IF([test "x$enable_ipf_transparent" = "xyes" -a "x$squid_host_os" = "xsolaris"],[
    solrev=`uname -r | sh -c 'IFS=. read j n x; echo $n'`
    CFLAGS="-DSOLARIS2=$solrev $CFLAGS"
    CXXFLAGS="-DSOLARIS2=$solrev $CXXFLAGS"
  ])
])
AC_MSG_NOTICE([IPF-based transparent proxying enabled: $enable_ipf_transparent])
SQUID_DEFINE_BOOL(IPF_TRANSPARENT,$enable_ipf_transparent,
    [Enable support for IPF-style transparent proxying])

dnl PF /dev/pf support requires a header file.
AS_IF([test "x$with_nat_devpf" != "xno"],[
  AS_IF([test "x$ac_cv_header_net_pfvar_h" = "xyes" -o \
    "x$ac_cv_header_net_pf_pfvar_h" = "xyes"],[
    AS_IF([test "x$with_nat_devpf" = "xauto"],[with_nat_devpf="no"])
  ],[
    AS_IF([test "x$with_nat_devpf" = "xyes"],[
      AC_MSG_ERROR([PF /dev/pf based NAT requested but needed header not found])
    ])
    with_nat_devpf="no"
  ])
])
SQUID_DEFINE_BOOL(PF_TRANSPARENT,${enable_pf_transparent:=no},
  [Enable support for PF-style transparent proxying])
SQUID_DEFINE_BOOL(USE_NAT_DEVPF,${with_nat_devpf:=no},
  [Enable support for /dev/pf NAT lookups])

AS_IF([test "x$enable_linux_netfilter" != "xno"],[
  AS_IF([test "x$ac_cv_header_linux_netfilter_ipv4_h" = "xyes"],[
    AS_IF([test "x$enable_linux_netfilter" = "xauto"],[enable_linux_netfilter=yes])
  ],[
    AS_IF([test "x$enable_linux_netfilter" = "xauto"],[
      enable_linux_netfilter=no
    ],[
      AC_MSG_ERROR([Linux Netfilter support requested but needed headers not found])
    ])
  ])
])
SQUID_DEFINE_BOOL(LINUX_NETFILTER,$enable_linux_netfilter,
  [Enable support for Transparent Proxy on Linux via Netfilter])

dnl Netfilter TPROXY depends on libcap but the NAT parts can still work.
AC_MSG_NOTICE([Support for Netfilter-based interception proxy requested: $enable_linux_netfilter])
AS_IF([test "x$enable_linux_netfilter" = "xyes" -a "x$with_cap" != "xyes"],[
  AC_MSG_WARN([Missing needed capabilities (libcap 2.09+) for TPROXY])
  AC_MSG_WARN([Linux Transparent Proxy (version 4+) support WILL NOT be enabled])
  AC_MSG_WARN([Reduced support to NAT Interception Proxy])
  # AC_DEFINEd later
])
AS_IF([test "x$with_netfilter_conntrack" = "xyes" -a "x$with_cap" != "xyes"],[
  AC_MSG_WARN([Missing needed capabilities (libcap 2.09+) for netfilter mark support])
  AC_MSG_WARN([Linux netfilter marking support WILL NOT be enabled])
  with_netfilter_conntrack=no
])
AC_MSG_NOTICE([Linux Netfilter Conntrack support enabled: ${with_netfilter_conntrack}])


AC_ARG_ENABLE(zph-qos,
  AS_HELP_STRING([--disable-zph-qos],[Disable ZPH QOS support]), [
  SQUID_YESNO([$enableval],[--enable-zph-qos])
])
SQUID_DEFINE_BOOL(USE_QOS_TOS,${enable_zph_qos:=yes},
          [Enable Zero Penalty Hit QOS. When set, Squid will alter the
           TOS field of HIT responses to help policing network traffic])
AC_MSG_NOTICE([ZPH QOS enabled: $enable_zph_qos])
AS_IF([test "x$enable_zph_qos" = "xyes"],[
  AC_MSG_NOTICE([QOS netfilter mark preservation enabled: $with_netfilter_conntrack])
  SQUID_DEFINE_BOOL(USE_LIBNETFILTERCONNTRACK,${with_netfilter_conntrack:=no},
    [Enable support for QOS netfilter mark preservation])
])

AC_CHECK_LIB(regex, regexec, [REGEXLIB="-lregex"],[REGEXLIB=''])
AC_SUBST(REGEXLIB)

SQUID_DETECT_UDP_SND_BUFSIZE
SQUID_DETECT_UDP_RECV_BUFSIZE
SQUID_DETECT_TCP_SND_BUFSIZE
SQUID_DETECT_TCP_RECV_BUFSIZE

SQUID_CHECK_NEED_SYS_ERRLIST
SQUID_CHECK_MAXPATHLEN

SQUID_CHECK_LIBRESOLV_DNS_TTL_HACK
SQUID_CHECK_RESOLVER_FIELDS

AC_CHECK_HEADERS(sys/statvfs.h)
AS_IF([test "x$ac_cv_header_sys_statvfs_h" = "xyes"],[SQUID_CHECK_WORKING_STATVFS])
AS_IF([test "x$ac_cv_func_statvfs" != "xyes"],[
  AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/vfs.h sys/statfs.h)
  AC_CHECK_FUNCS(statfs)
  SQUID_CHECK_F_FRSIZE_IN_STATFS
])

dnl Squid will not usually attempt to translate templates when building
AC_ARG_ENABLE(translation,
 AS_HELP_STRING([--enable-translation],[Generate the localized error page templates and manuals.
		 Which can also be downloaded from http://www.squid-cache.org/Versions/langpack/.]), [
  SQUID_YESNO([$enableval],[--enable-translation])
])
AS_IF([test "x${enable_translation:=no}" = "xyes"],[
  AX_WITH_PROG([PO2HTML],[po2html])
  AX_WITH_PROG([PO2TEXT],[po2txt])
],[
  PO2HTML="off"
  PO2TEXT="off"
])
AC_SUBST(PO2HTML)
AC_SUBST(PO2TEXT)
AM_CONDITIONAL(ENABLE_TRANSLATION, test "x${enable_translation:=no}" = "xyes")

dnl Squid now has limited locale handling ...
dnl on error pages
AC_ARG_ENABLE(auto-locale,
 AS_HELP_STRING([--disable-auto-locale],[This prevents Squid providing localized error pages based on the
		 clients request headers.
		 When disabled Squid requires explicit language configuration.]), [
  SQUID_YESNO([$enableval],[--enable-auto-locale])
])
AC_MSG_NOTICE([Multi-Language support enabled: ${enable_auto_locale:=yes}])
SQUID_DEFINE_BOOL(USE_ERR_LOCALES,$enable_auto_locale,
   [Use multi-language support on error pages])


dnl Need the debugging version of malloc if available
XTRA_OBJS=''
AS_IF([test "x$ac_cv_lib_malloc_main" = "xyes"],[
  AS_IF([test -r /usr/lib/debug/malloc.o],[XTRA_OBJS="$XTRA_OBJS /usr/lib/debug/malloc.o"])
  AS_IF([test -r /usr/lib/debug/mallocmap.o],[XTRA_OBJS="$XTRA_OBJS /usr/lib/debug/mallocmap.o"]);
])
AC_SUBST(XTRA_OBJS)

AS_IF([test "x$XTRA_LIBS" = "x"],[
  XTRA_LIBS="$LIBS"
  dnl minor cleanup
  XTRA_LIBS=`echo $XTRA_LIBS | sed -e "s/  */ /g"`
  LIBS=''
])
AC_SUBST(XTRA_LIBS)

AC_SUBST(SQUID_CFLAGS)
AC_SUBST(SQUID_CXXFLAGS)

# Prerequisite: CXXFLAGS have been finalized.
AC_ARG_VAR([BUILDCXXFLAGS],[C++ compiler flags for building compile-time tools. e.g. cf_gen])
AS_IF([test "x$BUILDCXXFLAGS" = "x"],[
  # if we are NOT cross-compiling, use the default build flags for cf_gen and friends
  # otherwise rely on the user-provided value
  AS_IF([test "x$squid_cv_check_marchnative" = "xyes"],[
    # always valid for the Build compiler.
    BUILDCXXFLAGS="-march=native"
  ])
  BUILDCXXFLAGS="$BUILDCXXFLAGS $CXXFLAGS"
])
AC_SUBST(BUILDCXXFLAGS)

AC_MSG_NOTICE([BUILD LIBRARIES: $LIBS])
AC_MSG_NOTICE([BUILD EXTRA LIBRARIES: $XTRA_LIBS])
AC_MSG_NOTICE([BUILD OBJECTS: $OBJS])
AC_MSG_NOTICE([BUILD EXTRA OBJECTS: $XTRA_OBJS])
AC_MSG_NOTICE([BUILD C FLAGS: $CFLAGS])
AC_MSG_NOTICE([BUILD EXTRA C FLAGS: $SQUID_CFLAGS])
AC_MSG_NOTICE([BUILD C++ FLAGS: $CXXFLAGS])
AC_MSG_NOTICE([BUILD EXTRA C++ FLAGS: $SQUID_CXXFLAGS])
AC_MSG_NOTICE([BUILD Tools C++ FLAGS: $BUILDCXXFLAGS])

dnl Clean up after OSF/1 core dump bug
rm -f core

AC_CONFIG_FILES([
	Makefile
	compat/Makefile
	contrib/Makefile
	doc/Makefile
	doc/manuals/Makefile
	doc/release-notes/Makefile
	errors/Makefile
	icons/Makefile
	lib/Makefile
	lib/ntlmauth/Makefile
	lib/snmplib/Makefile
	lib/sspi/Makefile
	scripts/Makefile
	src/Makefile
	src/acl/Makefile
	src/acl/external/Makefile
	src/acl/external/AD_group/Makefile
	src/acl/external/delayer/Makefile
	src/acl/external/eDirectory_userip/Makefile
	src/acl/external/file_userip/Makefile
	src/acl/external/kerberos_ldap_group/Makefile
	src/acl/external/kerberos_sid_group/Makefile
	src/acl/external/LDAP_group/Makefile
	src/acl/external/LM_group/Makefile
	src/acl/external/session/Makefile
	src/acl/external/SQL_session/Makefile
	src/acl/external/unix_group/Makefile
	src/acl/external/wbinfo_group/Makefile
	src/acl/external/time_quota/Makefile
	src/adaptation/Makefile
	src/adaptation/icap/Makefile
	src/adaptation/ecap/Makefile
	src/anyp/Makefile
	src/auth/Makefile
	src/auth/basic/Makefile
	src/auth/basic/DB/Makefile
	src/auth/basic/fake/Makefile
	src/auth/basic/getpwnam/Makefile
	src/auth/basic/LDAP/Makefile
	src/auth/basic/NCSA/Makefile
	src/auth/basic/NIS/Makefile
	src/auth/basic/PAM/Makefile
	src/auth/basic/POP3/Makefile
	src/auth/basic/RADIUS/Makefile
	src/auth/basic/SASL/Makefile
	src/auth/basic/SMB/Makefile
	src/auth/basic/SSPI/Makefile
	src/auth/digest/Makefile
	src/auth/digest/eDirectory/Makefile
	src/auth/digest/file/Makefile
	src/auth/digest/LDAP/Makefile
	src/auth/negotiate/Makefile
	src/auth/negotiate/kerberos/Makefile
	src/auth/negotiate/SSPI/Makefile
	src/auth/negotiate/wrapper/Makefile
	src/auth/ntlm/Makefile
	src/auth/ntlm/fake/Makefile
	src/auth/ntlm/SSPI/Makefile
	src/base/Makefile
	src/clients/Makefile
	src/comm/Makefile
	src/debug/Makefile
	src/dns/Makefile
	src/DiskIO/Makefile
	src/DiskIO/AIO/Makefile
	src/DiskIO/Blocking/Makefile
	src/DiskIO/DiskDaemon/Makefile
	src/DiskIO/DiskThreads/Makefile
	src/DiskIO/IpcIo/Makefile
	src/DiskIO/Mmapped/Makefile
	src/error/Makefile
	src/eui/Makefile
	src/format/Makefile
	src/fs/Makefile
	src/ftp/Makefile
	src/helper/Makefile
	src/html/Makefile
	src/http/Makefile
	src/http/one/Makefile
	src/http/url_rewriters/Makefile
	src/http/url_rewriters/fake/Makefile
	src/http/url_rewriters/LFS/Makefile
	src/icmp/Makefile
	src/ip/Makefile
	src/ipc/Makefile
	src/log/Makefile
	src/log/DB/Makefile
	src/log/file/Makefile
	src/mem/Makefile
	src/mgr/Makefile
	src/parser/Makefile
	src/proxyp/Makefile
	src/repl/Makefile
	src/sbuf/Makefile
	src/security/Makefile
	src/security/cert_generators/Makefile
	src/security/cert_generators/file/Makefile
	src/security/cert_validators/Makefile
	src/security/cert_validators/fake/Makefile
	src/servers/Makefile
	src/snmp/Makefile
	src/ssl/Makefile
	src/store/Makefile
	src/store/id_rewriters/Makefile
	src/store/id_rewriters/file/Makefile
	src/time/Makefile
	test-suite/Makefile
	tools/Makefile
	tools/apparmor/Makefile
	tools/helper-mux/Makefile
	tools/systemd/Makefile
	tools/sysvinit/Makefile
])

# must configure libltdl subdir unconditionally for "make distcheck" to work
#AC_CONFIG_SUBDIRS(libltdl)

AC_OUTPUT