~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

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
AC_PREREQ([2.59])
AC_INIT([Dovecot],[1.2.9],[dovecot@dovecot.org])
AC_CONFIG_SRCDIR([src])

AM_INIT_AUTOMAKE([foreign])

AM_MAINTAINER_MODE

dnl TEST_WITH(name, value, [plugin])
AC_DEFUN([TEST_WITH], [
  want=want_`echo $1|sed s/-/_/g`
  if test $2 = yes || test $2 = no || test $2 = auto; then
    eval $want=$2
  elif test $2 = plugin; then
    if test "$3" = plugin; then
      eval $want=plugin
    else
      AC_ERROR([--with-$1=plugin not supported])
    fi
  elif `echo $2|grep '^/' >/dev/null`; then
    AC_ERROR([--with-$1=path not supported. You may want to use instead:
CPPFLAGS=-I$2/include LDFLAGS=-L$2/lib ./configure --with-$1])
  else
    AC_ERROR([--with-$1: Unknown value: $2])
  fi
])

AC_ARG_ENABLE(devel-checks,
[  --enable-devel-checks   Enable some extra expensive checks for developers],
	if test x$enableval = xyes; then
		AC_DEFINE(DEBUG,, Build with extra debugging checks)
	fi)

AC_ARG_ENABLE(asserts,
[  --enable-asserts        Enable asserts (default)],
	if test x$enableval = xno; then
		AC_DEFINE(DISABLE_ASSERTS,, Disable asserts)
	fi)

AC_ARG_WITH(mem-align,
[  --with-mem-align=BYTES  Set the memory alignment (default: 8)],
	mem_align=$withval,
	mem_align=8)

AC_ARG_WITH(ioloop,
[  --with-ioloop=IOLOOP    Specify the I/O loop method to use
                          (epoll, kqueue, poll; best for the fastest available;
			   default is best)],
	ioloop=$withval,
	ioloop=best)

AC_ARG_WITH(notify,
[  --with-notify=NOTIFY    Specify the file system notification method to use
                          (inotify, kqueue, dnotify, none;
                           default is detected in the above order)],
	notify=$withval,
	notify=)

AC_ARG_WITH(passwd,
[  --with-passwd           Build with /etc/passwd support (default)],
  TEST_WITH(passwd, $withval),
  want_passwd=yes)

AC_ARG_WITH(nss,
[  --with-nss              Build with NSS module support (auto)],
  TEST_WITH(nss, $withval),
  want_nss=auto)

AC_ARG_WITH(passwd-file,
[  --with-passwd-file      Build with passwd-like file support (default)],
  TEST_WITH(passwd-file, $withval),
  want_passwd_file=yes)

AC_ARG_WITH(shadow,
[  --with-shadow           Build with shadow password support (auto)],
  TEST_WITH(shadow, $withval),
  want_shadow=auto)

AC_ARG_WITH(pam,
[  --with-pam              Build with PAM support (auto)],
  TEST_WITH(pam, $withval),
  want_pam=auto)

AC_ARG_WITH(checkpassword,
[  --with-checkpassword    Build with checkpassword support (default)],
  TEST_WITH(checkpassword, $withval),
  want_checkpassword=yes)

AC_ARG_WITH(bsdauth,
[  --with-bsdauth          Build with BSD authentication support (auto)],
  TEST_WITH(bsdauth, $withval),
  want_bsdauth=auto)

AC_ARG_WITH(gssapi,
[  --with-gssapi=yes|plugin Build with GSSAPI authentication support],
  TEST_WITH(gssapi, $withval, plugin),
  want_gssapi=no)

AC_ARG_WITH(sia,
[  --with-sia              Build with Tru64 SIA support],
  TEST_WITH(sia, $withval),
  want_sia=no)

AC_ARG_WITH(ldap,
[  --with-ldap=yes|plugin  Build with LDAP support],
  TEST_WITH(ldap, $withval, plugin),
  want_ldap=no)

AC_ARG_WITH(vpopmail,
[  --with-vpopmail         Build with vpopmail support (auto)],
	if test x$withval = xno; then
		want_vpopmail=no
	else
		if test x$withval = xyes || test x$withval = xauto; then
			vpopmail_home="`echo ~vpopmail`"
			want_vpopmail=$withval
		else
			vpopmail_home="$withval"
			want_vpopmail=yes
		fi
	fi, [
		want_vpopmail=auto
		vpopmail_home="`echo ~vpopmail`"
	])

AC_ARG_WITH(static-userdb,
[  --with-static-userdb    Build with static userdb support (default)],
  TEST_WITH(static-userdb, $withval),
  want_static_userdb=yes)

AC_ARG_WITH(prefetch-userdb,
[  --with-prefetch-userdb  Build with prefetch userdb support (default)],
  TEST_WITH(prefetch-userdb, $withval),
  want_prefetch_userdb=yes)

AC_ARG_WITH(db,
[  --with-db               Build with Berkeley DB support],
  TEST_WITH(db, $withval),
  want_db=no)

dnl The --with-sql is useful only if Dovecot is being built with all the SQL
dnl drivers as modules. If any SQL driver is built-in, this option is ignored.
AC_ARG_WITH(sql,
[  --with-sql=yes|plugin   Build with generic SQL support],
  TEST_WITH(sql, $withval, plugin),
  want_sql=no)

AC_ARG_WITH(pgsql,
[  --with-pgsql            Build with PostgreSQL driver support],
  TEST_WITH(pgsql, $withval),
  want_pgsql=no)

AC_ARG_WITH(mysql,
[  --with-mysql            Build with MySQL driver support],
  TEST_WITH(mysql, $withval),
  want_mysql=no)

AC_ARG_WITH(sqlite,
[  --with-sqlite           Build with SQLite3 driver support],
  TEST_WITH(sqlite, $withval),
  want_sqlite=no)

AC_ARG_WITH(lucene,
[  --with-lucene           Build with CLucene full text search support],
  TEST_WITH(lucene, $withval),
  want_lucene=no)
AM_CONDITIONAL(BUILD_LUCENE, test "$want_lucene" = "yes")

AC_ARG_WITH(solr,
[  --with-solr             Build with Solr full text search support],
  TEST_WITH(solr, $withval),
  want_solr=no)

AC_ARG_WITH(zlib,
[  --with-zlib             Build with zlib compression support],
  TEST_WITH(zlib, $withval),
  want_zlib=auto)

AC_ARG_WITH(bzlib,
[  --with-bzlib            Build with bzlib compression support],
  TEST_WITH(bzlib, $withval),
  want_bzlib=auto)

AC_ARG_WITH(libcap,
[  --with-libcap           Build with libcap support (Dropping capabilities).],
  TEST_WITH(libcap, $withval),
  want_libcap=auto)

AC_ARG_WITH(ssl,
[  --with-ssl=gnutls|openssl Build with GNUTLS or OpenSSL (default)],
	if test x$withval = xno; then
		want_gnutls=no
		want_openssl=no
	elif test x$withval = xgnutls; then
		want_gnutls=yes
		want_openssl=no
	elif test x$withval = xopenssl; then
		want_gnutls=no
		want_openssl=yes
	elif test x$withval = xyes; then
		want_gnutls=no
		want_openssl=yes
	else
		AC_ERROR([--with-ssl: Invalid value: $withval])
	fi, [
		want_gnutls=no
		want_openssl=auto
	])

AC_ARG_WITH(ssldir,
[  --with-ssldir=DIR       SSL base directory for certificates (/etc/ssl)],
	ssldir="$withval",
	ssldir=/etc/ssl
)
AC_SUBST(ssldir)

AC_ARG_WITH(rundir,
[  --with-rundir=DIR       Runtime data directory (LOCALSTATEDIR/run/dovecot)],
	rundir="$withval",
	rundir=$localstatedir/run/$PACKAGE
)
AC_SUBST(rundir)

AC_ARG_WITH(statedir,
[  --with-statedir=DIR     Permanent data directory (LOCALSTATEDIR/lib/dovecot)],
	statedir="$withval",
	statedir=$localstatedir/lib/$PACKAGE
)
AC_SUBST(statedir)

AC_ARG_WITH(gc,
[  --with-gc               Use Boehm garbage collector],
  TEST_WITH(gc, $withval),
  want_gc=no)

AC_ARG_WITH(storages,
[  --with-storages         Build with specified mail storage formats
                          (maildir mbox dbox cydir)], [
	if test "$withval" = "yes" || test "$withval" = "no"; then
		AC_MSG_ERROR([--with-storages needs storage list as parameter])
	fi
	mail_storages="shared `echo "$withval"|sed 's/,/ /g'`" ],
	mail_storages="shared maildir mbox dbox cydir")
AC_SUBST(mail_storages)

AC_ARG_WITH(sql-drivers,
[  --with-sql-drivers      Build with specified SQL drivers (all)], [
	sql_drivers=`echo "$withval"|sed 's/,/ /g'` ],
	sql_drivers="all")

if test "$sql_drivers" = "all" || test "$sql_drivers" = "yes"; then
  all_sql_drivers=yes
  sql_drivers=
elif test "$sql_drivers" = "no"; then
  # --without-sql-drivers given
  sql_drivers=
fi
not_sql_drivers=

AC_ARG_WITH(moduledir,
[  --with-moduledir=DIR    Base directory for dynamically loadable modules],
	moduledir="$withval",
	moduledir=$libdir/dovecot
)
AC_SUBST(moduledir)

AC_ARG_WITH(docs,
[  --with-docs             Install documentation (default)],
	if test x$withval = xno; then
		want_docs=no
	else
		want_docs=yes
	fi,
	want_docs=yes)
AM_CONDITIONAL(BUILD_DOCS, test "$want_docs" = "yes")

AC_ARG_ENABLE(header-install,
[  --enable-header-install Install development headers],
	if test x$enableval = xno; then
		want_headers=no
	else
		want_headers=yes
	fi,
	want_headers=no)
AM_CONDITIONAL(INSTALL_HEADERS, test "$want_headers" = "yes")

AC_ISC_POSIX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX # lucene plugin needs this
AC_HEADER_STDC
AC_C_INLINE
AC_PROG_LIBTOOL
AM_ICONV

AC_CHECK_HEADERS(strings.h stdint.h unistd.h dirent.h malloc.h inttypes.h \
  sys/uio.h sys/sysmacros.h sys/resource.h sys/select.h libgen.h \
  sys/quota.h sys/fs/ufs_quota.h ufs/ufs/quota.h jfs/quota.h sys/fs/quota_common.h \
  mntent.h sys/mnttab.h sys/event.h sys/time.h sys/mkdev.h linux/dqblk_xfs.h \
  xfs/xqm.h execinfo.h ucontext.h malloc_np.h sys/utsname.h sys/vmount.h \
  sys/utsname.h glob.h)

dnl * gcc specific options
if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
	# -Wcast-qual -Wcast-align -Wconversion -Wunreachable-code # too many warnings
	# -Wstrict-prototypes -Wredundant-decls # may give warnings in some systems
	# -Wmissing-format-attribute -Wmissing-noreturn -Wwrite-strings # a couple of warnings
	CFLAGS="$CFLAGS -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast"

	AC_TRY_COMPILE([
	#if __GNUC__ < 4
	#  error old gcc
	#endif
	],,[
	  # gcc4
	  CFLAGS="$CFLAGS -Wstrict-aliasing=2"
	])

	# Use std=gnu99 if we have new enough gcc
	old_cflags=$CFLAGS
	CFLAGS="-std=gnu99"
	AC_TRY_COMPILE([
	],, [
	  CFLAGS="$CFLAGS $old_cflags"
	], [
	  CFLAGS="$old_cflags"
	])
fi

dnl **
dnl ** just some generic stuff...
dnl **

AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(inet_addr, nsl)
AC_SEARCH_LIBS(fdatasync, rt, [
  AC_DEFINE(HAVE_FDATASYNC,, Define if you have fdatasync())
])

if test $want_libcap != no; then
  AC_CHECK_LIB(cap, cap_init, [
    AC_DEFINE(HAVE_LIBCAP,, libcap is installed for cap_init())
    LIBCAP="-lcap"
    AC_SUBST(LIBCAP)
  ], [
    if test "$want_libcap" = "yes"; then
      AC_ERROR([Can't build with libcap support: libcap not found])
    fi
  ])
fi

AC_DEFINE(PACKAGE_WEBPAGE, "http://www.dovecot.org/", Support URL)

dnl * after -lsocket and -lnsl tests, inet_aton() may be in them
AC_CHECK_FUNCS(fcntl flock lockf inet_aton sigaction getpagesize madvise \
               strcasecmp stricmp vsyslog writev pread uname unsetenv \
	       setrlimit setproctitle seteuid setreuid setegid setresgid \
	       strtoull strtoll strtouq strtoq \
	       setpriority quotactl getmntent kqueue kevent backtrace_symbols \
	       walkcontext dirfd clearenv malloc_usable_size glob)

AC_CHECK_LIB(rt, clock_gettime, [
  AC_DEFINE(HAVE_CLOCK_GETTIME,, Define if you have the clock_gettime function)
  LIBS="$LIBS -lrt"
], [
  # OpenBSD
  AC_CHECK_FUNCS(clock_gettime)
])

dnl strtoimax and strtoumax are macros in HP-UX, so inttypes.h must be included
dnl Link instead of just compiling since there's something wrong with Tru64
AC_MSG_CHECKING([for strtoimax])
AC_TRY_LINK([
  #include <inttypes.h>
], [
  strtoimax(0, 0, 0);
], [
  AC_DEFINE(HAVE_STRTOIMAX,, Define if you have strtoimax function)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([for strtoumax])
AC_TRY_LINK([
  #include <inttypes.h>
], [
  strtoumax(0, 0, 0);
], [
  AC_DEFINE(HAVE_STRTOUMAX,, Define if you have strtoumax function)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * I/O loop function
have_ioloop=no

if test "$ioloop" = "best" || test "$ioloop" = "epoll"; then
  AC_CACHE_CHECK([whether we can use epoll],i_cv_epoll_works,[
    AC_TRY_RUN([
      #include <sys/epoll.h>
  
      int main()
      {
	return epoll_create(5) < 1;
      }
    ], [
      i_cv_epoll_works=yes
    ], [
      i_cv_epoll_works=no
    ])
  ])
  if test $i_cv_epoll_works = yes; then
    AC_DEFINE(IOLOOP_EPOLL,, Implement I/O loop with Linux 2.6 epoll())
    have_ioloop=yes
    ioloop=epoll
  else
    if test "$ioloop" = "epoll" ; then
      AC_MSG_ERROR([epoll ioloop requested but epoll_create() is not available])
    fi
  fi
fi

if test "$ioloop" = "best" || test "$ioloop" = "kqueue"; then
    if test "$ac_cv_func_kqueue" = yes && test "$ac_cv_func_kevent" = yes; then
      AC_DEFINE(IOLOOP_KQUEUE,, [Implement I/O loop with BSD kqueue()])
      ioloop=kqueue
      have_ioloop=yes
    elif test "$ioloop" = "kqueue"; then
      AC_MSG_ERROR([kqueue ioloop requested but kqueue() is not available])
    fi
fi

if test "$ioloop" = "best" || test "$ioloop" = "poll"; then
  AC_CHECK_FUNC(poll, [
    AC_DEFINE(IOLOOP_POLL,, Implement I/O loop with poll())
    ioloop=poll
    have_ioloop=yes
  ])
fi

if test "$have_ioloop" = "no"; then
  AC_DEFINE(IOLOOP_SELECT,, Implement I/O loop with select())
  ioloop="select"
fi

have_notify=none

if test "$notify" = "" || test "$notify" = "inotify" ; then
  dnl * inotify?
  AC_CACHE_CHECK([whether we can use inotify],i_cv_inotify_works,[
    AC_TRY_RUN([
      #define _GNU_SOURCE
      #include <sys/ioctl.h>
      #include <fcntl.h>
      #include <sys/inotify.h>
      #include <stdio.h>
    
      int main()
      {
	int wd, fd;
	char * fn = "/tmp";
      
	fd = inotify_init ();
	if (fd < 0)
	  {
	    perror ("inotify_init");
	    return 1;
	  }
  
	wd = inotify_add_watch (fd, fn, IN_ALL_EVENTS);
  
	if (wd < 0)
	  {
	    perror ("inotify_add_watch");
	    return 2;
	  }
  
	inotify_rm_watch (fd, wd);
  
	close (fd);
	return 0;
      }
    ], [
      i_cv_inotify_works=yes
    ], [
      i_cv_inotify_works=no
    ])
  ])
  if test $i_cv_inotify_works = yes; then
    have_notify=inotify
    notify=inotify
    AC_DEFINE(IOLOOP_NOTIFY_INOTIFY,, Use Linux inotify)
  else
    if test "$notify" = "inotify"; then
      AC_MSG_ERROR([inotify requested but not available])
      notify=""
    fi
  fi
fi

if (test "$notify" = "" && test "$ioloop" = kqueue) || test "$notify" = "kqueue"; then
  AC_MSG_CHECKING([if we can use BSD kqueue() notify])
  dnl * BSD kqueue() notify
  if test "$ac_cv_func_kqueue" = yes && test "$ac_cv_func_kevent" = yes ; then
    have_notify=kqueue
    notify=kqueue
    AC_MSG_RESULT("yes")
    AC_DEFINE(IOLOOP_NOTIFY_KQUEUE,,
      Use BSD kqueue directory changes notificaton)
  else 
    AC_MSG_RESULT("no")
    if test "$notfify" = "kqueue" ; then
      AC_MSG_ERROR([kqueue notify requested but kqueue() is not available])
      notify=""
    fi
  fi
fi

if test "$notify" = "" || test "$notify" = "dnotify"; then
  AC_MSG_CHECKING([whether we can use dnotify])
  dnl * dnotify?
  AC_TRY_COMPILE([
    #define _GNU_SOURCE
    #include <fcntl.h>
    #include <signal.h>
    #include <unistd.h>
  ], [
    fcntl(0, F_SETSIG, SIGRTMIN);
    fcntl(0, F_NOTIFY, DN_CREATE | DN_DELETE | DN_RENAME | DN_MULTISHOT);
  ], [
    AC_MSG_RESULT(yes)
    AC_DEFINE(IOLOOP_NOTIFY_DNOTIFY,, Use Linux dnotify)
    have_notify=dnotify
    notify=dnotify
  ], [
    AC_MSG_RESULT(no)
    if test "$notify" = "dnotify"; then
      AC_MSG_ERROR([dnotify requested but not available])
    fi
  ])
fi

if test "$have_notify" = "none"; then
  AC_DEFINE(IOLOOP_NOTIFY_NONE,, No special notify support)
fi

dnl * GLIBC?
AC_TRY_COMPILE([
  #include <stdlib.h>
  #ifdef __GLIBC__
    we have glibc
  #endif
],,, [
  AC_DEFINE(PREAD_WRAPPERS,, Define if pread/pwrite needs _XOPEN_SOURCE 500)
])

dnl * Old glibcs have broken posix_fallocate(). Make sure not to use it.
dnl * It may also be broken in AIX.
AC_CACHE_CHECK([whether posix_fallocate() works],i_cv_posix_fallocate_works,[
  AC_TRY_RUN([
    #define _XOPEN_SOURCE 600
    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>
    #if defined(__GLIBC__) && (__GLIBC__ < 2 || __GLIBC_MINOR__ < 7)
      possibly broken posix_fallocate
    #endif
    int main() {
      int fd = creat("conftest.temp", 0600);
      int ret;
      if (fd == -1) {
	perror("creat()");
	return 2;
      }
      ret = posix_fallocate(fd, 1024, 1024) < 0 ? 1 : 0;
      unlink("conftest.temp");
      return ret;
    }
  ], [
    i_cv_posix_fallocate_works=yes
  ], [
    i_cv_posix_fallocate_works=no
  ])
])
if test $i_cv_posix_fallocate_works = yes; then
  AC_DEFINE(HAVE_POSIX_FALLOCATE,, Define if you have a working posix_fallocate())
fi

dnl * OS specific options
case "$host_os" in
	hpux*)
		CFLAGS="$CFLAGS -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
		# for getting fd_send/fd_recv working:
		LDFLAGS="$LDFLAGS -Wl,+b,:"
		LIBS="-lxnet $LIBS"
		AC_DEFINE(PREAD_BROKEN,, Defint if pread/pwrite implementation is broken)
		;;
	*)
		;;
esac

AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long long)

AC_DEFUN([AC_TYPEOF], [
  dnl * first check if we can get the size with redefining typedefs

  order="$2"
  if test "$2" = ""; then
    order="int long long-long"
  fi

  result=""
  visible="unknown"
  AC_MSG_CHECKING([type of $1])

  if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
    dnl * try with printf() + -Werror
    old_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -Werror"

    for type in $order; do
      case "$type" in
        int)
	  fmt="%d"
	  ;;
        unsigned-int)
	  fmt="%u"
	  ;;
        long)
	  fmt="%ld"
	  ;;
        unsigned-long)
	  fmt="%lu"
	  ;;
        long-long)
	  fmt="%lld"
	  ;;
        unsigned-long-long)
	  fmt="%llu"
	  ;;
	*)
	  fmt=""
	  ;;
      esac

      if test "$fmt" != ""; then
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	  #include <sys/types.h>
	  #include <stdio.h>
	]], [[
	  printf("$fmt", ($1)0);
	]])],[
	  if test "$result" != ""; then
	    dnl * warning check isn't working
	    result=""
	    visible="unknown"
	    break
	  fi
	  result="`echo $type|sed 's/-/ /g'`"
	  visible="$result"
	],[])
      fi
    done
    CFLAGS="$old_CFLAGS"
  fi

  if test "$result" = ""; then
    for type in $order; do
      type="`echo $type|sed 's/-/ /g'`"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
	#include <sys/types.h>
	typedef $type $1;
      ]], [[]])],[
	if test "$result" != ""; then
	  dnl * compiler allows redefining to anything
	  result=""
	  visible="unknown"
	  break
	fi
	result="$type"
	visible="$type"
      ],[])
    done
  fi

  if test "$result" = ""; then
    dnl * check with sizes

    dnl * older autoconfs don't include sys/types.h, so do it manually
    AC_RUN_IFELSE([AC_LANG_SOURCE([[
      #include <stdio.h>
      #include <sys/types.h>
      int main() {
	FILE *f=fopen("conftestval", "w");
	if (!f) exit(1);
	fprintf(f, "%d\n", sizeof($1));
	exit(0);
      }
    ]])],[
      size=`cat conftestval`
      rm -f conftestval

      for type in $order; do
        actype="ac_cv_sizeof_`echo $type|sed 's/-/_/g'`"
        if test "$size" = "`eval echo \\$$actype`"; then
	  result="`echo $type|sed 's/-/ /g'`"
	  visible="`expr $size \* 8`bit (using $result)"
	  break
	fi
      done
      if test "$result" = ""; then
        result=unknown
	visible="`expr $size \* 8`bit (unknown type)"
      fi
    ],[],[])
  fi

  typeof_$1=$result
  AC_MSG_RESULT($visible)
])

AC_SYS_LARGEFILE
AC_CHECK_TYPES(_Bool)

AC_CHECK_TYPE(uoff_t, [
  have_uoff_t=yes
  AC_DEFINE(HAVE_UOFF_T,, Define if you have a native uoff_t type)
], [
  have_uoff_t=no
])

AC_TYPEOF(off_t, long int long-long)
case "$typeof_off_t" in
  int)
    offt_max=INT_MAX
    uofft_fmt="u"
    if test "$have_uoff_t" != "yes"; then
      AC_DEFINE(UOFF_T_INT,, Define if off_t is int)
    fi
    offt_bits=`expr 8 \* $ac_cv_sizeof_int`
    ;;
  long)
    offt_max=LONG_MAX
    uofft_fmt="lu"
    if test "$have_uoff_t" != "yes"; then
      AC_DEFINE(UOFF_T_LONG,, Define if off_t is long)
    fi
    offt_bits=`expr 8 \* $ac_cv_sizeof_long`
    ;;
  "long long")
    offt_max=LLONG_MAX
    uofft_fmt="llu"
    if test "$have_uoff_t" != "yes"; then
      AC_DEFINE(UOFF_T_LONG_LONG,, Define if off_t is long long)
    fi
    offt_bits=`expr 8 \* $ac_cv_sizeof_long_long`
    ;;
  *)
    AC_MSG_ERROR([Unsupported off_t type])
    ;;
esac

dnl * Do we have struct dirent->d_type
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <dirent.h>
]], [[
  struct dirent d;
  d.d_type = DT_DIR;
]])],[
  AC_DEFINE(HAVE_DIRENT_D_TYPE,, Define if you have struct dirent->d_type)
],[])

dnl * Do we have OFF_T_MAX?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <limits.h>
  #include <sys/types.h>
]], [[
  off_t i = OFF_T_MAX;
]])],[
  :
],[
  AC_DEFINE_UNQUOTED(OFF_T_MAX, $offt_max, Maximum value of off_t)
])

AC_DEFINE_UNQUOTED(PRIuUOFF_T, "$uofft_fmt", printf() format for uoff_t)

dnl * make sure size_t isn't signed. we'd probably work fine with it, but
dnl * it's more likely vulnerable to buffer overflows. Anyway, C99 specifies
dnl * that it's unsigned and only some old systems define it as signed.
AC_CACHE_CHECK([whether size_t is signed],i_cv_signed_size_t,[
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <sys/types.h>
    int main() {
      /* return 0 if we're signed */
      exit((size_t)(int)-1 <= 0 ? 0 : 1);
    }
  ]])],[
    i_cv_signed_size_t=yes

    echo
    echo "Your system's size_t is a signed integer, Dovecot isn't designed to"
    echo "support it. It probably works just fine, but it's less resistant to"
    echo "buffer overflows. If you're not worried about this and still want to"
    echo "compile Dovecot, set ignore_signed_size=1 environment."
  
    if test "$ignore_signed_size" = ""; then
      AC_MSG_ERROR([aborting])
    fi
    echo "..ignoring as requested.."
  ],[
    i_cv_signed_size_t=no
  ],[])
])
dnl Note: we check size_t rather than ssize_t here, because on OSX 10.2
dnl ssize_t = int and size_t = unsigned long. We're mostly concerned about
dnl printf format here, so check the size_t one.
AC_TYPEOF(size_t, unsigned-int unsigned-long unsigned-long-long)
case "$typeof_size_t" in
  "unsigned long")
    ssizet_max=LONG_MAX
    sizet_fmt="lu"
    ;;
  "unsigned long long")
    ssizet_max=LLONG_MAX
    sizet_fmt="llu"
    ;;
  *)
    dnl older systems didn't have ssize_t, default to int
    ssizet_max=INT_MAX
    sizet_fmt="u"

    if test "$typeof_size_t" = ""; then
      AC_DEFINE(size_t, unsigned int, Define to 'unsigned int' if you don't have it)
      AC_DEFINE(ssize_t, int, Define to 'int' if you don't have it)
    fi
    ;;
esac

AC_DEFINE_UNQUOTED(SSIZE_T_MAX, $ssizet_max, Maximum value of ssize_t)
AC_DEFINE_UNQUOTED(PRIuSIZE_T, "$sizet_fmt", printf() format for size_t)

AC_DEFUN([AC_CHECKTYPE2], [
  AC_MSG_CHECKING([for $1])
  AC_CACHE_VAL(i_cv_type_$1,
  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <sys/types.h>
  $2]], [[$1 t;]])],[i_cv_type_$1=yes],[i_cv_type_$1=no])])
  AC_MSG_RESULT($i_cv_type_$1)
])

dnl some systems don't have stdint.h, but still have some of the types
dnl defined elsewhere
AC_CHECK_HEADER(stdint.h, [
  stdint_include="#include <stdint.h>"
])

AC_CHECKTYPE2(uintmax_t, [$stdint_include])
if test $i_cv_type_uintmax_t = yes; then
  AC_DEFINE(HAVE_UINTMAX_T,, Define if you have uintmax_t (C99 type))
fi

dnl use separate check, eg. Solaris 8 has uintmax_t but not uint_fast32_t
AC_CHECKTYPE2(uint_fast32_t, [$stdint_include])
if test $i_cv_type_uint_fast32_t = yes; then
  AC_DEFINE(HAVE_UINT_FAST32_T,, Define if you have uint_fast32_t (C99 type))
fi

AC_CHECKTYPE2(socklen_t, [#include <sys/socket.h>])
if test $i_cv_type_socklen_t = yes; then
  AC_DEFINE(HAVE_SOCKLEN_T,, Define to 'int' if you don't have socklen_t)
fi

AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)

dnl * find random source
AC_MSG_CHECKING([for OpenBSD /dev/arandom])
if test -c /dev/arandom; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(DEV_URANDOM_PATH, "/dev/arandom", Path to /dev/urandom)
  have_random_source=yes
else
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING([for /dev/urandom])
  if test -c /dev/urandom || test -s /dev/urandom; then
    AC_MSG_RESULT(yes)
    AC_DEFINE(DEV_URANDOM_PATH, "/dev/urandom", Path to /dev/urandom)
    have_random_source=yes
  else
    AC_MSG_RESULT(no)
  fi
fi

if test "$have_random_source" != "yes"; then
  AC_CHECK_HEADER(openssl/rand.h, [
    AC_DEFINE(HAVE_OPENSSL_RAND_H,, Define if you have openssl/rand.h)
    LIBS="$LIBS -lcrypto"
  ])
fi

dnl * do we have tm_gmtoff
AC_MSG_CHECKING([for tm_gmtoff])
AC_CACHE_VAL(i_cv_field_tm_gmtoff,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <time.h>]],
[[struct tm *tm; return tm->tm_gmtoff;]])],
[i_cv_field_tm_gmtoff=yes],
[i_cv_field_tm_gmtoff=no])])
if test $i_cv_field_tm_gmtoff = yes; then
	AC_DEFINE(HAVE_TM_GMTOFF,, Define if you have struct tm->tm_gmtoff)
fi
AC_MSG_RESULT($i_cv_field_tm_gmtoff)

dnl * how large time_t values does gmtime() accept?
AC_CACHE_CHECK([how large time_t values gmtime() accepts],i_cv_gmtime_max_time_t,[
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <stdio.h>
    #include <time.h>
    int main() {
      FILE *f;
      int bits;
  
      for (bits = 1; bits < sizeof(time_t)*8; bits++) {
	time_t t = ((time_t)1 << bits) - 1;
	if (gmtime(&t) == NULL) {
	  bits--;
	  break;
	}
      }
      if (bits > 40) {
	/* Solaris 9 breaks after 55 bits. Perhaps other systems break earlier.
	   Let's just do the same as Cyrus folks and limit it to 40 bits. */
	bits = 40;
      }
  
      f = fopen("conftest.temp", "w");
      if (f == NULL) {
	perror("fopen()");
	return 1;
      }
      fprintf(f, "%d", bits);
      fclose(f);
      return 0;
    }
  ]])],[
    i_cv_gmtime_max_time_t=`cat conftest.temp`
    rm -f conftest.temp
  ], [
    printf "check failed, assuming "
    i_cv_gmtime_max_time_t=31
  ],[])
])
AC_DEFINE_UNQUOTED(TIME_T_MAX_BITS, $i_cv_gmtime_max_time_t, max. time_t bits gmtime() can handle)

AC_CACHE_CHECK([whether time_t is signed],i_cv_signed_time_t,[
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <sys/types.h>
    int main() {
      /* return 0 if we're signed */
      exit((time_t)(int)-1 <= 0 ? 0 : 1);
    }
  ]])],[
    i_cv_signed_time_t=yes
  ], [
    i_cv_signed_time_t=no
  ])
])
if test $i_cv_signed_time_t = yes; then
  AC_DEFINE(TIME_T_SIGNED,, Define if your time_t is signed)
fi

dnl Our implementation of AC_C_FLEXIBLE_ARRAY_MEMBER.
dnl Use it until autoconf 2.61+ becomes more widely used
AC_MSG_CHECKING([if we can use C99-like flexible array members])
AC_TRY_COMPILE([
  struct foo {
    int x;
    char y[];
  };
], [
  struct foo foo;
], [
  flexible_value=""
  AC_MSG_RESULT(yes)
], [
  flexible_value=1
  AC_MSG_RESULT(no)
])
AC_DEFINE_UNQUOTED(FLEXIBLE_ARRAY_MEMBER, $flexible_value, How to define flexible array members in structs)

dnl * do we have struct iovec
AC_MSG_CHECKING([for struct iovec])
AC_CACHE_VAL(i_cv_struct_iovec,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>]],
[[struct iovec *iovec;]])],
[i_cv_struct_iovec=yes],
[i_cv_struct_iovec=no])])

if test $i_cv_struct_iovec = yes; then
	AC_DEFINE(HAVE_STRUCT_IOVEC,, Define if you have struct iovec)
fi
AC_MSG_RESULT($i_cv_struct_iovec)

dnl * is dev_t an integer or something else?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <sys/types.h>
  struct test { dev_t a; };
  static struct test t = { 0 };
]], [[]])],[],[
  AC_DEFINE(DEV_T_STRUCT,, Define if your dev_t is a structure instead of integer type)

  dnl we can't initialize structures, so don't warn about them either
  if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
    CFLAGS=`echo $CFLAGS|sed 's/ -W\b//'`
  fi
])

dnl * Do we have RLIMIT_AS?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <sys/types.h>
  #include <sys/time.h>
  #include <sys/resource.h>
]], [[
  struct rlimit r;
  getrlimit(RLIMIT_AS, &r);
]])],[
  AC_DEFINE(HAVE_RLIMIT_AS,, Define if you have RLIMIT_AS for setrlimit())
],[])

dnl * Do we have RLIMIT_NPROC?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <sys/types.h>
  #include <sys/time.h>
  #include <sys/resource.h>
]], [[
  struct rlimit r;
  getrlimit(RLIMIT_NPROC, &r);
]])],[
  AC_DEFINE(HAVE_RLIMIT_NPROC,, Define if you have RLIMIT_NPROC for setrlimit())
],[])

dnl * Do we have RLIMIT_CORE?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  #include <sys/types.h>
  #include <sys/time.h>
  #include <sys/resource.h>
]], [[
  struct rlimit r;
  getrlimit(RLIMIT_CORE, &r);
]])],[
  AC_DEFINE(HAVE_RLIMIT_CORE,, Define if you have RLIMIT_CORE for getrlimit())
],[])

AC_MSG_CHECKING([PR_SET_DUMPABLE])
AC_TRY_LINK([
  #include <sys/prctl.h>
], [
  prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
], [
  AC_DEFINE(HAVE_PR_SET_DUMPABLE,, Define if you have prctl(PR_SET_DUMPABLE))
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Linux compatible mremap()
AC_MSG_CHECKING([Linux compatible mremap()])
AC_TRY_LINK([
  #include <unistd.h>
  #define __USE_GNU
  #include <sys/mman.h>
], [
  mremap(0, 0, 0, MREMAP_MAYMOVE);
], [
  AC_DEFINE(HAVE_LINUX_MREMAP,, Define if you have Linux-compatible mremap())
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * If mmap() plays nicely with write()
AC_CACHE_CHECK([whether shared mmaps get updated by write()s],i_cv_mmap_plays_with_write,[
  AC_TRY_RUN([
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    int main() {
      /* return 0 if we're signed */
      int f = open("conftest.mmap", O_RDWR|O_CREAT|O_TRUNC, 0600);
      void *mem;
      if (f == -1) {
	perror("open()");
	return 1;
      }
      unlink("conftest.mmap");
  
      write(f, "1", 2);
      mem = mmap(NULL, 2, PROT_READ|PROT_WRITE, MAP_SHARED, f, 0);
      if (mem == MAP_FAILED) {
	perror("mmap()");
	return 1;
      }
      strcpy(mem, "2");
      msync(mem, 2, MS_SYNC);
      lseek(f, 0, SEEK_SET);
      write(f, "3", 2);
    
      return strcmp(mem, "3") == 0 ? 0 : 1;
    }
  ], [
    i_cv_mmap_plays_with_write=yes
  ], [
    i_cv_mmap_plays_with_write=no
  ])
])
if test $i_cv_mmap_plays_with_write = no; then
  AC_DEFINE(MMAP_CONFLICTS_WRITE,, [Define if shared mmaps don't get updated by write()s])
fi

dnl * see if fd passing works
AC_CACHE_CHECK([whether fd passing works],i_cv_fd_passing,[
  for i in 1 2; do
    old_cflags="$CFLAGS"
    CFLAGS="$CFLAGS -I$srcdir/src/lib $srcdir/src/lib/fdpass.c"
    if test $i = 2; then
      CFLAGS="$CFLAGS -DBUGGY_CMSG_MACROS"
    fi
  
    AC_TRY_RUN([
      #include <sys/types.h>
      #include <sys/socket.h>
      #include <sys/wait.h>
      #include <sys/stat.h>
      #include <unistd.h>
      #include <fcntl.h>
      #include "fdpass.h"
      
      int nopen(void)
      {
	      int i, n;
	      struct stat sb;
	      for (i = n = 0; i < 256; i++)
		  if (fstat(i, &sb) == 0) n++;
	      return n;
      }
      int main(void)
      {
	      int fd[2], send_fd, recv_fd, status, n1, n2;
	      struct stat st, st2;
	      char data;
      
	      send_fd = creat("conftest.fdpass", 0600);
	      if (send_fd == -1) return 2;
	      unlink("conftest.fdpass");
	      if (fstat(send_fd, &st) < 0) return 2;
	      if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) return 2;
	      n1 = nopen();
      
	      switch (fork()) {
	      case -1:
		      return 2;
	      case 0:
		      alarm(1);
		      if (fd_send(fd[0], send_fd, &data, 1) != 1) return 2;
		      return 0;
	      default:
		      alarm(2);
		      if (wait(&status) == -1)
			return 2;
		      if (status != 0)
			return status;
		      if (fd_read(fd[1], &data, 1, &recv_fd) != 1) return 1;
		      if (fstat(recv_fd, &st2) < 0) return 2;
		      /* nopen check is for making sure that only a single fd
		         was received */
		      n2 = nopen();
		      return st.st_ino == st2.st_ino && n2 == n1 + 1 ? 0 : 1;
	      }
      }
    ], [
      CFLAGS=$old_cflags
      if test $i = 2; then
	i_cv_fd_passing=buggy_cmsg_macros
      else
        i_cv_fd_passing=yes
      fi
      break
    ], [
      dnl no, try with BUGGY_CMSG_MACROS
      CFLAGS=$old_cflags
      i_cv_fd_passing=no
    ])
  done
]);

case "$host_os" in
darwin[[1-9]].*)
	if test "$i_cv_fd_passing" = "yes"; then
		i_cv_fd_passing=buggy_cmsg_macros
	fi
	;;
esac

if test $i_cv_fd_passing = buggy_cmsg_macros; then
  AC_DEFINE(BUGGY_CMSG_MACROS,, Define if you have buggy CMSG macros)
fi

dnl * Solaris compatible sendfile()
AC_CHECK_LIB(sendfile, sendfile, [
  LIBS="$LIBS -lsendfile"
  AC_DEFINE(HAVE_SOLARIS_SENDFILE,, Define if you have Solaris-compatible sendfile())
], [
  dnl * Linux compatible sendfile() - don't check if Solaris one was found.
  dnl * This seems to pass with Solaris for some reason..
  AC_MSG_CHECKING([Linux compatible sendfile()])
  AC_TRY_LINK([
    #undef _FILE_OFFSET_BITS
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/sendfile.h>
  ], [
    sendfile(0, 0, (void *) 0, 0);
  ], [
    AC_DEFINE(HAVE_LINUX_SENDFILE,, Define if you have Linux-compatible sendfile())
    AC_MSG_RESULT(yes)
  ], [
    AC_MSG_RESULT(no)
  ])

  dnl * FreeBSD compatible sendfile()
  AC_MSG_CHECKING([FreeBSD compatible sendfile()])
  AC_TRY_LINK([
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/uio.h>
  ], [
    struct sf_hdtr hdtr;
    sendfile(0, 0, 0, 0, &hdtr, (void *) 0, 0);
  ], [
    AC_DEFINE(HAVE_FREEBSD_SENDFILE,, Define if you have FreeBSD-compatible sendfile())
    AC_MSG_RESULT(yes)
  ], [
    AC_MSG_RESULT(no)
  ])
])

dnl * Check for crypt() if unistd.h compiles with _XOPEN_SOURCE + _XPG6
dnl * Add other macros there too "just in case".
AC_MSG_CHECKING([if we should use _XPG6 macro for crypt()])
AC_TRY_COMPILE([
  #define _XOPEN_SOURCE 4
  #define _XOPEN_SOURCE_EXTENDED 1
  #define _XOPEN_VERSION 4
  #define _XPG4_2
  #define _XPG6
  #include <unistd.h>
], [
  crypt("a", "b");
], [
  AC_DEFINE(CRYPT_USE_XPG6,, Define if _XPG6 macro is needed for crypt())
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([if struct stat has st_?tim timespec fields])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <unistd.h>
], [
  struct stat st;
  unsigned long x = st.st_mtim.tv_nsec;

  return 0;
], [
  AC_DEFINE(HAVE_STAT_XTIM,, Define if you have st_?tim timespec fields in struct stat)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([if struct stat has st_?timespec fields])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <unistd.h>
], [
  struct stat st;
  unsigned long x = st.st_mtimespec.tv_nsec;

  return 0;
], [
  AC_DEFINE(HAVE_STAT_XTIMESPEC,, Define if you have st_?timespec fields in struct stat)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if statvfs() can be used to find out block device for files
AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include <sys/statvfs.h>
], [
  struct statvfs buf;
  char *p = buf.f_mntfromname;

  statvfs(".", &buf);
], [
  AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if statvfs() can be used to find out block device for files
AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include <sys/statvfs.h>
], [
  struct statvfs buf;
  char *p = buf.f_mntfromname;

  statvfs(".", &buf);
], [
  AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if statfs() can be used to find out block device for files
AC_MSG_CHECKING([if statfs.f_mntfromname exists])
AC_TRY_COMPILE([
  #include <sys/param.h>
  #include <sys/mount.h>
], [
  struct statfs buf;
  char *p = buf.f_mntfromname;

  statfs(".", &buf);
], [
  AC_DEFINE(HAVE_STATFS_MNTFROMNAME,, Define if you have statfs.f_mntfromname)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if we have struct dqblk.dqb_curblocks
AC_MSG_CHECKING([if struct dqblk.dqb_curblocks exists])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include "$srcdir/src/plugins/quota/quota-fs.h"
], [
  struct dqblk dqblk;
  unsigned int x = dqblk.dqb_curblocks;
], [
  AC_DEFINE(HAVE_STRUCT_DQBLK_CURBLOCKS,, Define if struct sqblk.dqb_curblocks exists)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if we have struct dqblk.dqb_curspace
AC_MSG_CHECKING([if struct dqblk.dqb_curspace exists])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include "$srcdir/src/plugins/quota/quota-fs.h"
], [
  struct dqblk dqblk;
  unsigned int x = dqblk.dqb_curspace;
], [
  AC_DEFINE(HAVE_STRUCT_DQBLK_CURSPACE,, Define if struct sqblk.dqb_curspace exists)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl * Check if we have Q_QUOTACTL ioctl (Solaris)
AC_MSG_CHECKING([if struct Q_QUOTACTL ioctl exists])
AC_TRY_COMPILE([
  #include <sys/types.h>
  #include <sys/fs/ufs_quota.h>
], [
  struct quotctl ctl;
  ioctl(0, Q_QUOTACTL, &ctl);
], [
  AC_DEFINE(HAVE_Q_QUOTACTL,, Define if Q_QUOTACTL exists)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
])

dnl ***
dnl *** C99 vsnprintf()?
dnl ***

AC_CACHE_CHECK([for C99 vsnprintf()],i_cv_c99_vsnprintf,[
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
  #include <stdio.h>
  #include <stdarg.h>
  static int f(const char *fmt, ...) {
    va_list args;
    char buf[13];
    int ret;

    va_start(args, fmt);
    ret = vsnprintf(buf, 11, fmt, args) != 12 || buf[11-1] != '\0';
    va_end(args);
    return ret;
  }
  int main() {
    return f("hello %s%d", "world", 1);
  }]])],
  [i_cv_c99_vsnprintf=yes],
  [i_cv_c99_vsnprintf=no])
])
if test $i_cv_c99_vsnprintf = no; then
  AC_DEFINE(HAVE_OLD_VSNPRINTF,, Define if you don't have C99 compatible vsnprintf() call)
fi

dnl ***
dnl *** va_copy checks (from GLIB)
dnl ***

AC_CACHE_CHECK([for an implementation of va_copy()],lib_cv_va_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	va_copy (args2, args1);
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv_va_copy=yes],
	[lib_cv_va_copy=no],[])
])
AC_CACHE_CHECK([for an implementation of __va_copy()],lib_cv___va_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	__va_copy (args2, args1);
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv___va_copy=yes],
	[lib_cv___va_copy=no],[])
])

if test "x$lib_cv_va_copy" = "xyes"; then
  va_copy_func=va_copy
else if test "x$lib_cv___va_copy" = "xyes"; then
  va_copy_func=__va_copy
fi
fi

if test -n "$va_copy_func"; then
  AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,[A 'va_copy' style function])
fi

AC_CACHE_CHECK([whether va_lists can be copied by value],lib_cv_va_val_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	args2 = args1;
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv_va_val_copy=yes],
	[lib_cv_va_val_copy=no],[])
])

if test "x$lib_cv_va_val_copy" = "xno"; then
  AC_DEFINE(VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values])
fi

dnl * dynamic modules?
have_modules=no
AC_CHECK_FUNC(dlopen, [
  have_modules=yes
  MODULE_LIBS="-export-dynamic"
], [
  AC_CHECK_LIB(dl, dlopen, [
    have_modules=yes
    MODULE_LIBS="-export-dynamic -ldl"
    DLLIB=-ldl
  ])
])

dnl **
dnl ** AIX mntctl
dnl **

if test $ac_cv_header_sys_vmount_h = yes; then
  AC_MSG_CHECKING([for reasonable mntctl buffer size])
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/vmount.h>
    int main() {
      int size,count; char *m;
      FILE *f=fopen("conftestval", "w");
      if (!f) exit(1);
      if ((count=mntctl(MCTL_QUERY,sizeof(size),&size))!=0 || !(m=malloc(size)) ||
          (count=mntctl(MCTL_QUERY,size,m))<=0) exit(1);
        fprintf(f, "%d\n",(size * (count + 5))/count & ~1); /* 5 mounts more */
        exit(0);
    }
  ]])],[
    size=`cat conftestval`
    rm -f conftestval
    AC_DEFINE_UNQUOTED(STATIC_MTAB_SIZE,$size, reasonable mntctl buffer size)
    AC_MSG_RESULT($size)
  ],[
    AC_MSG_RESULT(default)
  ])
fi


dnl **
dnl ** SSL
dnl **

have_ssl=no

if test $want_openssl != no && test $have_ssl = no; then
  if pkg-config --exists openssl 2>/dev/null; then
    PKG_CHECK_MODULES(SSL, openssl)
    CFLAGS="$CFLAGS $SSL_CFLAGS"
    have_openssl=yes
  else
    # openssl 0.9.8 wants -ldl and it's required if there's only .a lib
    AC_CHECK_LIB(ssl, SSL_read, [
      AC_CHECK_HEADERS(openssl/ssl.h openssl/err.h, [
        SSL_LIBS="-lssl -lcrypto $DLLIB"
        AC_SUBST(SSL_LIBS)
	have_openssl=yes
      ], [
	if test $want_openssl = yes; then
	  AC_ERROR([Can't build with OpenSSL: openssl/ssl.h or openssl/err.h not found])
	fi
      ])
    ], [
      if test $want_openssl = yes; then
        AC_ERROR([Can't build with OpenSSL: libssl not found])
      fi
    ], -lcrypto $DLLIB)
  fi
  if test "$have_openssl" = "yes"; then
    AC_DEFINE(HAVE_OPENSSL,, Build with OpenSSL support)
    have_ssl="yes (OpenSSL)"

    AC_CHECK_LIB(ssl, SSL_get_current_compression, [
      AC_DEFINE(HAVE_SSL_COMPRESSION,, Build with OpenSSL compression)
    ],, $SSL_LIBS)
  fi
fi

if test $want_gnutls != no && test $have_ssl = no; then
  AC_CHECK_LIB(gnutls, gnutls_global_init, [
    AC_CHECK_HEADER(gnutls/gnutls.h, [
      AC_DEFINE(HAVE_GNUTLS,, Build with GNUTLS support)
      SSL_LIBS="-lgnutls -lgcrypt"
      AC_SUBST(SSL_LIBS)
      have_ssl="yes (GNUTLS)"
      have_gnutls=yes
    ], [
      if test $want_gnutls = yes; then
	AC_ERROR([Can't build with GNUTLS: gnutls/gnutls.h not found])
      fi
    ])
  ], [
    if test $want_gnutls = yes; then
      AC_ERROR([Can't build with GNUTLS: libgnutls not found])
    fi
  ], -lgcrypt)
fi

if test "$have_ssl" != "no"; then
	AC_DEFINE(HAVE_SSL,, Build with SSL/TLS support)
fi

dnl **
dnl ** Garbage Collector
dnl ** 

if test $want_gc != no; then
  AC_CHECK_LIB(gc, GC_malloc, [
    AC_CHECK_HEADERS(gc/gc.h gc.h)
    AC_DEFINE(USE_GC,, Define if you want to use Boehm GC)
    LIBS="$LIBS -lgc"
  ], [
    if test $want_gc = yes; then
      AC_ERROR([Can't build with GC: libgc not found])
    fi
  ])
fi

dnl **
dnl ** userdb and passdb checks
dnl **

userdb=""
passdb=""
not_userdb=""
not_passdb=""

if test $want_static_userdb != no; then
        AC_DEFINE(USERDB_STATIC,, Build with static userdb support)
	userdb="$userdb static"
else
	not_userdb="$not_userdb static"
fi

if test $want_prefetch_userdb != no; then
        AC_DEFINE(USERDB_PREFETCH,, Build with prefetch userdb support)
	userdb="$userdb prefetch"
else
	not_userdb="$not_userdb prefetch"
fi

if test $want_passwd != no; then
        AC_DEFINE(USERDB_PASSWD,, Build with passwd support)
        AC_DEFINE(PASSDB_PASSWD,, Build with passwd support)
	userdb="$userdb passwd"
	passdb="$passdb passwd"
else
	not_passdb="$not_passdb passwd"
	not_userdb="$not_userdb passwd"
fi

if test $want_passwd_file != no; then
        AC_DEFINE(USERDB_PASSWD_FILE,, Build with passwd-file support)
        AC_DEFINE(PASSDB_PASSWD_FILE,, Build with passwd-file support)
	userdb="$userdb passwd-file"
	passdb="$passdb passwd-file"
else
	not_passdb="$not_passdb passwd-file"
	not_userdb="$not_userdb passwd-file"
fi

have_shadow=no
if test $want_shadow != no; then
  AC_CHECK_FUNC(getspnam, [
    AC_CHECK_HEADER(shadow.h, [
      AC_DEFINE(PASSDB_SHADOW,, Build with shadow support)
      have_shadow=yes
    ], [
      if test $want_shadow = yes; then
        AC_ERROR([Can't build with shadow support: shadow.h not found])
      fi
    ])
  ], [
    if test $want_shadow = yes; then
      AC_ERROR([Can't build with shadow support: getspnam() not found])
    fi
  ])
fi
if test $have_shadow = no; then
  not_passdb="$not_passdb shadow"
else
  passdb="$passdb shadow"
fi

if test $want_pam != no; then
	AC_CHECK_LIB(pam, pam_start, [
		have_pam=no
		AC_CHECK_HEADER(security/pam_appl.h, [
			AC_DEFINE(HAVE_SECURITY_PAM_APPL_H,,
				  Define if you have security/pam_appl.h)
			have_pam=yes
		])

		AC_CHECK_HEADER(pam/pam_appl.h, [
			AC_DEFINE(HAVE_PAM_PAM_APPL_H,,
				  Define if you have pam/pam_appl.h)
			have_pam=yes
		])
	], [
	  if test $want_pam = yes; then
	    AC_ERROR([Can't build with PAM support: libpam not found])
	  fi
	])
fi

if test "$have_pam" = "yes"; then
  AUTH_LIBS="$AUTH_LIBS -lpam"
  AC_DEFINE(PASSDB_PAM,, Build with PAM support)
  passdb="$passdb pam"

  AC_CHECK_LIB(pam, pam_setcred, [
    AC_DEFINE(HAVE_PAM_SETCRED,, Define if you have pam_setcred())
  ])
elif test $want_pam = yes; then
  AC_ERROR([Can't build with PAM support: pam_appl.h not found])
else
  not_passdb="$not_passdb pam"
fi

if test $want_checkpassword != no; then
        AC_DEFINE(PASSDB_CHECKPASSWORD,, Build with checkpassword passdb support)
        AC_DEFINE(USERDB_CHECKPASSWORD,, Build with checkpassword userdb support)
	passdb="$passdb checkpassword"
	userdb="$userdb checkpassword"
else
	not_passdb="$not_passdb checkpassword"
	not_userdb="$not_userdb checkpassword"
fi

have_bsdauth=no
if test $want_bsdauth != no; then
	AC_CHECK_FUNC(auth_userokay, [
		AC_DEFINE(PASSDB_BSDAUTH,, Build with BSD authentication support)
		have_bsdauth=yes
	], [
	  if test $want_bsdauth = yes; then
	    AC_ERROR([Can't build with BSD authentication support: auth_userokay() not found])
	  fi
	])
fi
if test $have_bsdauth = no; then
  not_passdb="$not_passdb bsdauth"
else
  passdb="$passdb bsdauth"
fi

have_gssapi=no
if test $want_gssapi != no; then
	AC_CHECK_PROG(KRB5CONFIG, krb5-config, YES, NO)
	if test $KRB5CONFIG = YES; then
		if ! krb5-config --version gssapi 2>/dev/null > /dev/null; then
		  # krb5-config doesn't support gssapi.
		  KRB5_LIBS="`krb5-config --libs`"
		  KRB5_CFLAGS=`krb5-config --cflags`
		  AC_CHECK_LIB(gss, gss_acquire_cred, [
		    # Solaris
		    KRB5_LIBS="$KRB5_LIBS -lgss"
		  ], [
		    # failed
		    KRB5_LIBS=
		  ], $KRB5_LIBS)
		else
		  KRB5_LIBS=`krb5-config --libs gssapi`
		  KRB5_CFLAGS=`krb5-config --cflags gssapi`
		fi
		if test "$KRB5_LIBS" != ""; then
			AC_SUBST(KRB5_LIBS)
			AC_SUBST(KRB5_CFLAGS)
			
			# Although krb5-config exists, all systems still don't
			# have gssapi.h
			old_CFLAGS=$CFLAGS
			CFLAGS="$CFLAGS $KRB5_CFLAGS"
			AC_CHECK_HEADER([gssapi/gssapi.h], [
				AC_DEFINE(HAVE_GSSAPI_GSSAPI_H,, GSSAPI headers in gssapi/gssapi.h)
				have_gssapi=yes
			])
			AC_CHECK_HEADER([gssapi.h], [
				AC_DEFINE(HAVE_GSSAPI_H,, GSSAPI headers in gssapi.h)
				have_gssapi=yes
			])
			if test $have_gssapi != no; then
				if test $want_gssapi = plugin; then
					have_gssapi=plugin
				fi
				AC_DEFINE(HAVE_GSSAPI,, Build with GSSAPI support)
				AC_CHECK_HEADERS(gssapi/gssapi_ext.h gssapi_krb5.h gssapi/gssapi_krb5.h)
				AC_CHECK_LIB(gss, __gss_userok, [
					AC_DEFINE(HAVE___GSS_USEROK,,
						Define if you have __gss_userok())
					KRB5_LIBS="$KRB5_LIBS -lgss"
				],, $KRB5_LIBS)

				# MIT has a #define for Heimdal acceptor_identity, but it's way too
				# difficult to test for it..
				old_LIBS=$LIBS
				LIBS="$LIBS $KRB5_LIBS"
				AC_CHECK_FUNCS(gsskrb5_register_acceptor_identity krb5_gss_register_acceptor_identity)

				# does the kerberos library support SPNEGO?
				AC_CACHE_CHECK([whether GSSAPI supports SPNEGO],i_cv_gssapi_spnego,[
				  AC_TRY_RUN([
				    #ifdef HAVE_GSSAPI_H
				    #  include <gssapi.h>
				    #else
				    #  include <gssapi/gssapi.h>
				    #endif
				    #include <krb5.h>
				    #include <string.h>
				    int main(void) {
				      OM_uint32 minor_status;
				      gss_OID_set mech_set;
				      unsigned char spnego_oid[] = { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 };
				      unsigned int i;
    
				      gss_indicate_mechs(&minor_status, &mech_set);
				      for (i = 0; i < mech_set->count; i++) {
					if (mech_set->elements[i].length == 6 &&
					    memcmp(mech_set->elements[i].elements,
						   spnego_oid, 6) == 0)
					      return 0;
				      }
				      return 1;
				    }
				  ], [
				    i_cv_gssapi_spnego=yes
				  ], [
				    i_cv_gssapi_spnego=no
				  ])
				])
				if test "$i_cv_gssapi_spnego" = "yes"; then
				  AC_DEFINE(HAVE_GSSAPI_SPNEGO,, GSSAPI supports SPNEGO)
				fi
				LIBS=$old_LIBS

				if test $want_gssapi != plugin; then
				  AUTH_LIBS="$AUTH_LIBS $KRB5_LIBS"
				  AUTH_CFLAGS="$AUTH_CFLAGS $KRB5_CFLAGS"
				  AC_DEFINE(BUILTIN_GSSAPI,, GSSAPI support is built in)
				else
				  have_gssapi_plugin=yes
				fi
			else
			  if test $want_gssapi != auto; then
			    AC_ERROR([Can't build with GSSAPI support: gssapi.h not found])
			  fi
			fi
			CFLAGS=$old_CFLAGS
		fi
	else
	  if test $want_gssapi != auto; then
	    AC_ERROR([Can't build with GSSAPI support: krb5-config not found])
	  fi
	fi
fi
AM_CONDITIONAL(GSSAPI_PLUGIN, test "$have_gssapi_plugin" = "yes")

have_sia=no
if test $want_sia != no; then
	AC_CHECK_FUNC(sia_validate_user, [
		AC_DEFINE(PASSDB_SIA,, Build with Tru64 SIA support)
		AUTH_LIBS="$AUTH_LIBS -depth_ring_search"
		have_sia=yes
	], [
	  if test $want_sia = yes; then
	    AC_ERROR([Can't build with SIA support: sia_validate_user() not found])
	  fi
	])
fi

if test $have_sia = no; then
  not_passdb="$not_passdb sia"
else
  passdb="$passdb sia"
fi

have_ldap=no
if test $want_ldap != no; then
	AC_CHECK_LIB(ldap, ldap_init, [
		AC_CHECK_HEADER(ldap.h, [
			AC_CHECK_LIB(ldap, ldap_initialize, [
				AC_DEFINE(LDAP_HAVE_INITIALIZE,, Define if you have ldap_initialize)
			])
			AC_CHECK_LIB(ldap, ldap_start_tls_s, [
				AC_DEFINE(LDAP_HAVE_START_TLS_S,, Define if you have ldap_start_tls_s)
			])
			LDAP_LIBS="-lldap -llber"
			AC_SUBST(LDAP_LIBS)
			if test $want_ldap != plugin; then
				AUTH_LIBS="$AUTH_LIBS $LDAP_LIBS"
		        	AC_DEFINE(BUILTIN_LDAP,, LDAP support is built in)
			fi

        		AC_DEFINE(USERDB_LDAP,, Build with LDAP support)
		        AC_DEFINE(PASSDB_LDAP,, Build with LDAP support)
			AC_CHECK_HEADERS(sasl.h sasl/sasl.h)
			have_ldap=yes
		], [
		  if test $want_ldap != auto; then
		    AC_ERROR([Can't build with LDAP support: ldap.h not found])
		  fi
		])
	], [
	  if test $want_ldap != auto; then
	    AC_ERROR([Can't build with LDAP support: libldap not found])
	  fi
	])
fi

if test $have_ldap = no; then
  not_passdb="$not_passdb ldap"
  not_userdb="$not_userdb ldap"
else
  userdb="$userdb ldap"
  passdb="$passdb ldap"
  if test $want_ldap = plugin; then
    have_ldap_plugin=yes
    userdb="$userdb (plugin)"
    passdb="$passdb (plugin)"
  fi
fi
AM_CONDITIONAL(LDAP_PLUGIN, test "$have_ldap_plugin" = "yes")

dict_drivers=client

if test $want_db != no; then
	AC_MSG_CHECKING([db_env_create in -ldb])
	old_LIBS=$LIBS
	LIBS="$LIBS -ldb"
	AC_TRY_LINK([
		#include <db.h>
	], [
		db_env_create(0, 0);
	], [
		AC_MSG_RESULT(yes)
		AC_CHECK_HEADER(db.h, [
        		DICT_LIBS="$DICT_LIBS -ldb"
			dict_drivers="$dict_drivers db"
			AC_DEFINE(BUILD_DB,, Build with Berkeley DB support)
		], [
		  if test $want_db = yes; then
		    AC_ERROR([Can't build with db support: db.h not found])
		  fi
		])
	], [
		AC_MSG_RESULT(no)
		if test $want_db = yes; then
		  AC_ERROR([Can't build with db support: libdb not found])
		fi
	])
	LIBS=$old_LIBS
fi

if test $want_pgsql != no; then
  AC_CHECK_PROG(PG_CONFIG, pg_config, YES, NO)
  if test $PG_CONFIG = NO; then
    # based on code from PHP
    for i in /usr /usr/local /usr/local/pgsql; do
      for j in include include/pgsql include/postgres include/postgresql ""; do
	if test -r "$i/$j/libpq-fe.h"; then
	  PGSQL_INCLUDE=$i/$j
	fi
      done
      for lib in lib lib64; do
	for j in $lib $lib/pgsql $lib/postgres $lib/postgresql ""; do
	  if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
	    PGSQL_LIBDIR=$i/$j
	  fi
	done
      done
    done
  else
    PGSQL_INCLUDE="`pg_config --includedir`"
    PGSQL_LIBDIR="`pg_config --libdir`"  
  fi

  old_LIBS=$LIBS
  if test "$PGSQL_LIBDIR" != ""; then
    LIBS="$LIBS -L$PGSQL_LIBDIR"
  fi

  AC_CHECK_LIB(pq, PQconnectdb, [
	  AC_CHECK_LIB(pq, PQescapeStringConn, [
		  AC_DEFINE(HAVE_PQESCAPE_STRING_CONN,, Define if libpq has PQescapeStringConn function)
	  ])
	  old_CPPFLAGS=$CPPFLAGS
	  if test "$PGSQL_INCLUDE" != ""; then
		  CPPFLAGS="$CPPFLAGS -I $PGSQL_INCLUDE"
	  fi
	  AC_CHECK_HEADER(libpq-fe.h, [
		  if test "$PGSQL_INCLUDE" != ""; then
			  PGSQL_CFLAGS="$PGSQL_CFLAGS -I$PGSQL_INCLUDE"
		  fi
		  if test "$PGSQL_LIBDIR" != ""; then
			  PGSQL_LIBS="$PGSQL_LIBS -L$PGSQL_LIBDIR"
		  fi
		  PGSQL_LIBS="$PGSQL_LIBS -lpq"
		  AC_DEFINE(HAVE_PGSQL,, Build with PostgreSQL support)
		  found_sql_drivers="$found_sql_drivers pgsql"

		  if test "$all_sql_drivers" = "yes"; then
		    sql_drivers="$sql_drivers pgsql"
		  fi
	  ], [
	    if test $want_pgsql = yes; then
	      AC_ERROR([Can't build with PostgreSQL support: libpq-fe.h not found])
	    fi
	  ])
	  CPPFLAGS=$old_CPPFLAGS
  ], [
    if test $want_pgsql = yes; then
      AC_ERROR([Can't build with PostgreSQL support: libpq not found])
    fi
  ])
  LIBS=$old_LIBS
fi

if test $want_mysql != no; then
	# based on code from PHP
	for i in /usr /usr/local /usr/local/mysql; do
		for j in include include/mysql ""; do
			if test -r "$i/$j/mysql.h"; then
				MYSQL_INCLUDE=$i/$j
			fi
		done
		for j in lib lib/mysql lib64 lib64/mysql ""; do
			if test -f "$i/$j/libmysqlclient.so" || test -f "$i/$j/libmysqlclient.a"; then
				MYSQL_LIBDIR=$i/$j
			fi
		done
	done

	old_LIBS=$LIBS
	if test "$MYSQL_LIBDIR" != ""; then
		LIBS="$LIBS -L$MYSQL_LIBDIR"
	fi

	mysql_lib=""
	LIBS="$LIBS -lz -lm"
	AC_CHECK_LIB(mysqlclient, mysql_init, [
		old_CPPFLAGS=$CPPFLAGS
		if test "$MYSQL_INCLUDE" != ""; then
			CPPFLAGS="$CPPFLAGS -I $MYSQL_INCLUDE"
		fi
		AC_CHECK_HEADER(mysql.h, [
			if test "$MYSQL_INCLUDE" != ""; then
				MYSQL_CFLAGS="$MYSQL_CFLAGS -I$MYSQL_INCLUDE"
			fi
			if test "$MYSQL_LIBDIR" != ""; then
				MYSQL_LIBS="$MYSQL_LIBS -L$MYSQL_LIBDIR"
			fi
			MYSQL_LIBS="$MYSQL_LIBS -lmysqlclient -lz -lm"

			AC_CHECK_LIB(mysqlclient, mysql_ssl_set, [
				AC_DEFINE(HAVE_MYSQL_SSL,, Define if your MySQL library has SSL functions)
				if test "x$have_openssl" = "yes"; then
				  ssl_define="#define HAVE_OPENSSL"
				else
				  ssl_define=""
				fi
				AC_TRY_COMPILE([
				  $ssl_define
				  #include <mysql.h>
				], [
				  mysql_set_ssl(0, 0, 0, 0, 0, 0);
				], [
					AC_DEFINE(HAVE_MYSQL_SSL_CIPHER,, Define if your MySQL library supports setting cipher)
				])
			])
			
			AC_DEFINE(HAVE_MYSQL,, Build with MySQL support)
			found_sql_drivers="$found_sql_drivers mysql"
		], [
		  if test $want_mysql = yes; then
		    AC_ERROR([Can't build with MySQL support: mysql.h not found])
		  fi
		])
		CPPFLAGS=$old_CPPFLAGS
	], [
	  if test $want_mysql = yes; then
	    AC_ERROR([Can't build with MySQL support: libmysqlclient not found])
	  fi
	])

	LIBS=$old_LIBS
fi

if test $want_sqlite != no; then
	AC_CHECK_LIB(sqlite3, sqlite3_open, [
		AC_CHECK_HEADER(sqlite3.h, [
			SQLITE_LIBS="$SQLITE_LIBS -lsqlite3 -lz"

			AC_DEFINE(HAVE_SQLITE,, Build with SQLite3 support)
			found_sql_drivers="$found_sql_drivers sqlite"
		], [
		  if test $want_sqlite = yes; then
		    AC_ERROR([Can't build with SQLite support: sqlite3.h not found])
		  fi
		])
	], [
	  if test $want_sqlite = yes; then
	    AC_ERROR([Can't build with SQLite support: libsqlite3 not found])
	  fi
	])
fi
	
SQL_CFLAGS="$MYSQL_CFLAGS $PGSQL_CFLAGS $SQLITE_CFLAGS"
if test "$want_sql" != "plugin"; then
	SQL_LIBS="$MYSQL_LIBS $PGSQL_LIBS $SQLITE_LIBS"
else
	AC_DEFINE(SQL_DRIVER_PLUGINS,, Build SQL drivers as plugins)
fi

if test "$found_sql_drivers" != "" || test "$want_sql" != "no"; then
	if test "$all_sql_drivers" = "yes"; then
	  sql_drivers="$found_sql_drivers"
	fi

	AC_DEFINE(PASSDB_SQL,, Build with SQL support)
	AC_DEFINE(USERDB_SQL,, Build with SQL support)
	AUTH_LIBS="$AUTH_LIBS $SQL_LIBS"
	passdb="$passdb sql"
	userdb="$userdb sql"
else
	not_passdb="$not_passdb sql"
	not_userdb="$not_userdb sql"
fi

have_vpopmail=no
if test $want_vpopmail != no; then
	vpop_etc="$vpopmail_home/etc"
	AC_MSG_CHECKING([for vpopmail configuration at $vpop_etc/lib_deps])
	if ! test -f $vpop_etc/lib_deps; then
		AC_MSG_RESULT(not found)
		vpop_etc="$vpopmail_home"
		AC_MSG_CHECKING([for vpopmail configuration at $vpop_etc/lib_deps])
	fi
	if test -f $vpop_etc/lib_deps; then
		AUTH_CFLAGS="$AUTH_CFLAGS `cat $vpop_etc/inc_deps` $CFLAGS"
		AUTH_LIBS="$AUTH_LIBS `cat $vpop_etc/lib_deps`"
		AC_DEFINE(USERDB_VPOPMAIL,, Build with vpopmail support)
		AC_DEFINE(PASSDB_VPOPMAIL,, Build with vpopmail support)
		AC_MSG_RESULT(found)
		have_vpopmail=yes
	else
		AC_MSG_RESULT(not found)
		if test $want_vpopmail = yes; then
		  AC_ERROR([Can't build with vpopmail support: $vpop_etc/lib_deps not found])
		fi
	fi
fi

if test $have_vpopmail = no; then
  not_passdb="$not_passdb vpopmail"
  not_userdb="$not_userdb vpopmail"
else
  userdb="$userdb vpopmail"
  passdb="$passdb vpopmail"
fi

AC_CHECK_FUNC(crypt,, [
  AC_CHECK_LIB(crypt, crypt, [
    AUTH_LIBS="-lcrypt $AUTH_LIBS"
  ], [
    AC_MSG_ERROR([crypt() wasn't found])
  ])
])

if test $have_modules = yes; then
  AC_DEFINE(HAVE_MODULES,, Define if you have dynamic module support)
  AC_SUBST(MODULE_LIBS)

  # shrext_cmds comes from libtool.m4
  module=yes eval MODULE_SUFFIX=$shrext_cmds
  if test "$MODULE_SUFFIX" = ""; then
    # too old libtool?
    MODULE_SUFFIX=.so
  fi
  AC_DEFINE_UNQUOTED(MODULE_SUFFIX,"$MODULE_SUFFIX",Dynamic module suffix)
  AC_SUBST(MODULE_SUFFIX)
fi

have_nss=no
if test $want_nss != no; then
  if test $have_modules != yes; then
    if test $want_nss = yes; then
      AC_ERROR([Can't build with NSS support: Dynamic modules not supported])
    fi
  else
    AC_TRY_COMPILE([
      #include <nss.h>
    ], [
      enum nss_status status = NSS_STATUS_TRYAGAIN;
    ], [
      AC_DEFINE(USERDB_NSS,, Build with NSS module support)
      have_nss=yes
    ], [
      if test $want_nss = yes; then
        AC_ERROR([Can't build with NSS support: nss.h not found or not usable])
      fi
    ])
  fi
fi

if test $have_nss = no; then
  not_userdb="$not_userdb nss"
else
  userdb="$userdb nss"
fi

AC_SUBST(AUTH_CFLAGS)
AC_SUBST(AUTH_LIBS)
AC_SUBST(SQL_CFLAGS)
AC_SUBST(SQL_LIBS)
AC_SUBST(MYSQL_CFLAGS)
AC_SUBST(MYSQL_LIBS)
AC_SUBST(PGSQL_CFLAGS)
AC_SUBST(PGSQL_LIBS)
AC_SUBST(SQLITE_CFLAGS)
AC_SUBST(SQLITE_LIBS)

AC_SUBST(DICT_LIBS)
AC_SUBST(dict_drivers)

dnl **
dnl ** Endianess
dnl **

dnl At least Apple's gcc supports __BIG_ENDIAN__ and __LITTLE_ENDIAN__
dnl defines. Use them if possible to allow cross-compiling.
AC_MSG_CHECKING([if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined])
AC_TRY_COMPILE([
  #if !(__BIG_ENDIAN__ || __LITTLE_ENDIAN__)
  #error nope
  #endif
], [
], [
  AC_DEFINE(WORDS_BIGENDIAN, __BIG_ENDIAN__, Define if your CPU is big endian)
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
  AC_C_BIGENDIAN
])

dnl **
dnl ** IPv6 support
dnl **

have_ipv6=no
AC_MSG_CHECKING([for IPv6])
AC_CACHE_VAL(i_cv_type_in6_addr,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>]],
[[struct in6_addr i;]])],
[i_cv_type_in6_addr=yes],
[i_cv_type_in6_addr=no])])
if test $i_cv_type_in6_addr = yes; then
	AC_DEFINE(HAVE_IPV6,, Build with IPv6 support)
	have_ipv6=yes
fi
AC_MSG_RESULT($i_cv_type_in6_addr)

dnl **
dnl ** storage classes
dnl **

maildir_libs='$(top_builddir)/src/lib-storage/index/maildir/libstorage_maildir.a'
mbox_libs='$(top_builddir)/src/lib-storage/index/mbox/libstorage_mbox.a'
dbox_libs='$(top_builddir)/src/lib-storage/index/dbox/libstorage_dbox.a'
cydir_libs='$(top_builddir)/src/lib-storage/index/cydir/libstorage_cydir.a'
raw_libs='$(top_builddir)/src/lib-storage/index/raw/libstorage_raw.a'
shared_libs='$(top_builddir)/src/lib-storage/index/shared/libstorage_shared.a'

REGISTER_LIBS='$(top_builddir)/src/lib-storage/register/libstorage-register.a '\
'$(top_builddir)/src/lib-storage/list/libstorage_list.a'

CORE_LIBS='$(top_builddir)/src/lib-storage/index/libstorage_index.a '\
'$(top_builddir)/src/lib-storage/libstorage.a '\
'$(top_builddir)/src/lib-index/libindex.a '\
'$(top_builddir)/src/lib-imap/libimap.a '\
'$(top_builddir)/src/lib-mail/libmail.a '\
'$(top_builddir)/src/lib-auth/libauth.a '\
'$(top_builddir)/src/lib-charset/libcharset.a '\
'$(top_builddir)/src/lib/liblib.a'

mail_storages="$mail_storages raw"
# drop duplicates
mail_storages=`(for i in $mail_storages; do echo $i; done)|sort|uniq|xargs echo`
STORAGE_LIBS=
for storage in $mail_storages; do
  STORAGE_LIBS="$STORAGE_LIBS `eval echo \\$${storage}_libs`"
done
STORAGE_LIBS="$REGISTER_LIBS $STORAGE_LIBS $CORE_LIBS"
AC_SUBST(STORAGE_LIBS)
AC_DEFINE_UNQUOTED(MAIL_STORAGES, "$mail_storages", List of compiled in mail storages)

dnl **
dnl ** SQL drivers
dnl **

build_pgsql=no
build_mysql=no
build_sqlite=no
for driver in $sql_drivers; do
  if test "$driver" = "pgsql"; then
    AC_DEFINE(BUILD_PGSQL,, Built-in PostgreSQL support)
    build_pgsql=yes
  elif test "$driver" = "mysql"; then
    AC_DEFINE(BUILD_MYSQL,, Built-in MySQL support)
    build_mysql=yes
  elif test "$driver" = "sqlite"; then
    AC_DEFINE(BUILD_SQLITE,, Built-in SQLite support)
    build_sqlite=yes
  fi
done
if test $build_pgsql = no; then
  not_sql_drivers="$not_sql_drivers pgsql"
fi
if test $build_mysql = no; then
  not_sql_drivers="$not_sql_drivers mysql"
fi
if test $build_sqlite = no; then
  not_sql_drivers="$not_sql_drivers sqlite"
fi

AC_SUBST(sql_drivers)
AM_CONDITIONAL(BUILD_PGSQL, test "$build_pgsql" = "yes")
AM_CONDITIONAL(BUILD_MYSQL, test "$build_mysql" = "yes")
AM_CONDITIONAL(BUILD_SQLITE, test "$build_sqlite" = "yes")
AM_CONDITIONAL(SQL_PLUGINS, test "$want_sql" = "plugin")

dnl **
dnl ** Plugins
dnl **

if test "$want_zlib" != "no"; then
  AC_CHECK_HEADER(zlib.h, [
    have_zlib=yes
    have_zlib_plugin=yes
    AC_DEFINE(HAVE_ZLIB,, Define if you have zlib library)
  ], [
    if test "$want_zlib" = "yes"; then
      AC_ERROR([Can't build with zlib support: zlib.h not found])
    fi
  ])
fi
AM_CONDITIONAL(BUILD_ZLIB, test "$have_zlib" = "yes")

if test "$want_bzlib" != "no"; then
  AC_CHECK_HEADER(bzlib.h, [
    AC_CHECK_LIB(bz2, BZ2_bzdopen, [
      have_bzlib=yes
      have_zlib_plugin=yes
      AC_DEFINE(HAVE_BZLIB,, Define if you have bzlib library)
    ], [
      if test "$want_bzlib" = "yes"; then
	AC_ERROR([Can't build with bzlib support: libbz2 not found])
      fi
    ])
  ], [
    if test "$want_bzlib" = "yes"; then
      AC_ERROR([Can't build with bzlib support: bzlib.h not found])
    fi
  ])
fi
AM_CONDITIONAL(BUILD_BZLIB, test "$have_bzlib" = "yes")
AM_CONDITIONAL(BUILD_ZLIB_PLUGIN, test "$have_zlib_plugin" = "yes")

RPCGEN=${RPCGEN-rpcgen}
if ! $RPCGEN -c /dev/null > /dev/null; then
  RPCGEN=
fi
AC_SUBST(RPCGEN)

have_rquota=no
if test -f /usr/include/rpcsvc/rquota.x && test -n "$RPCGEN"; then
  AC_DEFINE(HAVE_RQUOTA,, Define if you wish to retrieve quota of NFS mounted mailboxes)
  have_rquota=yes
fi
AM_CONDITIONAL(HAVE_RQUOTA, test "$have_rquota" = "yes")

if test "$want_solr" != "no"; then
  AC_CHECK_PROG(CURLCONFIG, curl-config, YES, NO)
  if test $CURLCONFIG = YES; then
    CURL_CFLAGS=`curl-config --cflags`
    CURL_LIBS=`curl-config --libs`
    
    dnl libcurl found, also need libexpat
    AC_CHECK_LIB(expat, XML_Parse, [
      AC_CHECK_HEADER(expat.h, [
        AC_SUBST(CURL_CFLAGS)
        AC_SUBST(CURL_LIBS)
	have_solr=yes
      ], [
	if test $want_solr = yes; then
	  AC_ERROR([Can't build with Solr support: expat.h not found])
	fi
      ])
    ], [
      if test $want_solr = yes; then
	AC_ERROR([Can't build with Solr support: libexpat not found])
      fi
    ])
  else
    if test $want_solr = yes; then
      AC_ERROR([Can't build with Solr support: curl-config not found])
    fi
  fi
fi
AM_CONDITIONAL(BUILD_SOLR, test "$have_solr" = "yes")

dnl **
dnl ** capabilities
dnl **

capability_banner="IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE"
capability="$capability_banner SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH"
AC_DEFINE_UNQUOTED(CAPABILITY_STRING, "$capability", IMAP capabilities)
AC_DEFINE_UNQUOTED(CAPABILITY_BANNER_STRING, "$capability_banner", IMAP capabilities advertised in banner) 

CFLAGS="$CFLAGS $EXTRA_CFLAGS"

if test "$docdir" = ""; then
  dnl docdir supported only by autoconf v2.59c and later
  docdir='${datadir}/doc/${PACKAGE_TARNAME}'
fi
AC_SUBST(docdir)

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
doc/Makefile
doc/wiki/Makefile
src/Makefile
src/lib/Makefile
src/lib-sql/Makefile
src/lib-auth/Makefile
src/lib-charset/Makefile
src/lib-dict/Makefile
src/lib-imap/Makefile
src/lib-index/Makefile
src/lib-mail/Makefile
src/lib-ntlm/Makefile
src/lib-otp/Makefile
src/lib-settings/Makefile
src/lib-storage/Makefile
src/lib-storage/list/Makefile
src/lib-storage/index/Makefile
src/lib-storage/index/maildir/Makefile
src/lib-storage/index/mbox/Makefile
src/lib-storage/index/dbox/Makefile
src/lib-storage/index/cydir/Makefile
src/lib-storage/index/raw/Makefile
src/lib-storage/index/shared/Makefile
src/lib-storage/register/Makefile
src/auth/Makefile
src/deliver/Makefile
src/dict/Makefile
src/imap/Makefile
src/imap-login/Makefile
src/login-common/Makefile
src/master/Makefile
src/pop3/Makefile
src/pop3-login/Makefile
src/tests/Makefile
src/util/Makefile
src/plugins/Makefile
src/plugins/acl/Makefile
src/plugins/imap-acl/Makefile
src/plugins/autocreate/Makefile
src/plugins/convert/Makefile
src/plugins/expire/Makefile
src/plugins/fts/Makefile
src/plugins/fts-lucene/Makefile
src/plugins/fts-solr/Makefile
src/plugins/fts-squat/Makefile
src/plugins/lazy-expunge/Makefile
src/plugins/listescape/Makefile
src/plugins/mail-log/Makefile
src/plugins/mbox-snarf/Makefile
src/plugins/quota/Makefile
src/plugins/imap-quota/Makefile
src/plugins/trash/Makefile
src/plugins/virtual/Makefile
src/plugins/zlib/Makefile
stamp.h
dovecot-config.in])

AC_OUTPUT

if test "$want_sql" = "plugin"; then
  sql_drivers="$sql_drivers (plugins)"
fi

not_passdb=`echo "$not_passdb"|sed 's/ / -/g'`
not_userdb=`echo "$not_userdb"|sed 's/ / -/g'`
not_sql_drivers=`echo "$not_sql_drivers"|sed 's/ / -/g'`

echo
echo "Install prefix . : $prefix"
echo "File offsets ... : ${offt_bits}bit"
echo "I/O polling .... : $ioloop"
echo "I/O notifys .... : $have_notify"
echo "SSL ............ : $have_ssl"
echo "GSSAPI ......... : $have_gssapi"
echo "passdbs ........ :$passdb"
if test "$not_passdb" != ""; then
  echo "                 :$not_passdb"
fi
echo "userdbs ........ :$userdb"
if test "$not_userdb" != ""; then
  echo "                 :$not_userdb"
fi
echo "SQL drivers .... :$sql_drivers"
if test "$not_sql_drivers" != ""; then
  echo "                 :$not_sql_drivers"
fi