File: configure.ac

package info (click to toggle)
pure-ftpd 1.0.47-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 3,212 kB
  • sloc: ansic: 29,132; sh: 1,632; makefile: 500; perl: 280
file content (1473 lines) | stat: -rw-r--r-- 41,355 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
dnl AM_ACLOCAL_INCLUDE(m4)

AC_PREREQ(2.65)
AC_INIT([pure-ftpd],[1.0.47],[bugs at pureftpd dot org])
AC_CONFIG_SRCDIR(src/ftpd.c)
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar])
AC_CONFIG_LIBOBJ_DIR(src)

AC_SUBST(VERSION)

ISODATE=`date +%Y-%m-%d`
AC_SUBST(ISODATE)

dnl Checks for programs.
LX_CFLAGS=${CFLAGS-NONE}
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_CC
AM_PROG_CC_C_O
AC_USE_SYSTEM_EXTENSIONS
AC_SEARCH_LIBS([strerror],[cposix])

AX_CHECK_COMPILE_FLAG([-fPIC], [
  AX_CHECK_LINK_FLAG([-fPIC],
    [CFLAGS="$CFLAGS -fPIC"]
  )
])

AS_IF([test "$enable_pie" != "no"],[
  AX_CHECK_COMPILE_FLAG([-fPIE], [
    AX_CHECK_LINK_FLAG([-pie], [
      [CFLAGS="$CFLAGS -fPIE"
       LDFLAGS="$LDFLAGS -pie"]
    ])
  ])
])

AX_CHECK_COMPILE_FLAG([-fwrapv], [CFLAGS="$CFLAGS -fwrapv"])
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CFLAGS="$CFLAGS -fno-strict-overflow"])
AS_IF([echo `(uname -s) 2>/dev/null` | $GREP "CYGWIN" > /dev/null], [
  AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
], [
  AS_IF([test `(uname -s) 2>/dev/null` = "DragonFly"],
    [
      AX_CHECK_COMPILE_FLAG([-fstack-protector], [
        AX_CHECK_LINK_FLAG([-fstack-protector],
          [CFLAGS="$CFLAGS -fstack-protector"]
        )
      ])
    ],
    [
      AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [
        AX_CHECK_LINK_FLAG([-fstack-protector-all],
          [CFLAGS="$CFLAGS -fstack-protector-all"]
        )
      ])
    ]
  )
])

AX_CHECK_COMPILE_FLAG([-Winit-self], [CFLAGS="$CFLAGS -Winit-self"])
AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])

AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
AX_CHECK_COMPILE_FLAG([-Wall], [CWFLAGS="$CWFLAGS -Wall"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wextra], [CWFLAGS="$CWFLAGS -Wextra"])

AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wbad-function-cast], [CWFLAGS="$CWFLAGS -Wbad-function-cast"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-align], [CWFLAGS="$CWFLAGS -Wcast-align"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcast-qual], [CWFLAGS="$CWFLAGS -Wcast-qual"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wchar-subscripts], [CWFLAGS="$CWFLAGS -Wchar-subscripts"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wcomment], [CWFLAGS="$CWFLAGS -Wcomment"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wfloat-equal], [CWFLAGS="$CWFLAGS -Wfloat-equal"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wformat=2], [CWFLAGS="$CWFLAGS -Wformat=2"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wimplicit], [CWFLAGS="$CWFLAGS -Wimplicit"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-declarations], [CWFLAGS="$CWFLAGS -Wmissing-declarations"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wmissing-prototypes], [CWFLAGS="$CWFLAGS -Wmissing-prototypes"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wnormalized=id], [CWFLAGS="$CWFLAGS -Wnormalized=id"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Woverride-init], [CWFLAGS="$CWFLAGS -Woverride-init"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wparentheses], [CWFLAGS="$CWFLAGS -Wparentheses"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wpointer-arith], [CWFLAGS="$CWFLAGS -Wpointer-arith"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wredundant-decls], [CWFLAGS="$CWFLAGS -Wredundant-decls"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wstrict-prototypes], [CWFLAGS="$CWFLAGS -Wstrict-prototypes"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wswitch-enum], [CWFLAGS="$CWFLAGS -Wswitch-enum"])
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wvariable-decl], [CWFLAGS="$CWFLAGS -Wvariable-decl"])

AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"])

if test -d /usr/local/include; then
  CPPFLAGS="$CPPFLAGS -I/usr/local/include"
fi

if test -d /usr/kerberos/include; then
  CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
fi

if test -d /usr/local/lib; then
  LDFLAGS="$LDFLAGS -L/usr/local/lib"
fi

CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"

dnl Checks for header files

AC_SYS_LARGEFILE
AC_HEADER_STDC
AC_HEADER_STAT
AC_HEADER_TIME
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(unistd.h string.h strings.h sys/param.h ioctl.h sys/ioctl.h)
AC_CHECK_HEADERS(sys/vfs.h sys/statvfs.h sys/sendfile.h sys/uio.h)
AC_CHECK_HEADERS(sys/time.h sys/resource.h sys/capability.h)
AC_CHECK_HEADERS(shadow.h getopt.h stddef.h stdint.h)
AC_CHECK_HEADERS(netinet/in_systm.h netinet/in.h sys/pstat.h sys/file.h)
AC_CHECK_HEADERS(sys/mount.h, [], [],
[#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif])
AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/loadavg.h sys/ptrace.h)
AC_CHECK_HEADERS(security/pam_appl.h security/pam_misc.h)
AC_CHECK_HEADERS(security/pam_modules.h security/pam_filter.h)
AC_CHECK_HEADERS(pam/pam_appl.h pam/pam_misc.h pam/pam_modules.h)
AC_CHECK_HEADERS(pam/pam_filter.h)
AC_CHECK_HEADERS(sgtty.h termio.h)
AC_CHECK_HEADERS(locale.h)
AC_CHECK_HEADERS(stdarg.h varargs.h)
AC_CHECK_HEADERS(windows.h io.h)
AC_CHECK_HEADERS(crypt.h)
AC_CHECK_HEADERS(utime.h)
AC_CHECK_HEADERS(openssl/ssl.h openssl/ec.h)
AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h)
AC_CHECK_HEADERS(iconv.h)
AC_SYS_POSIX_TERMIOS

if test "x$ac_cv_sys_posix_termios" = "xyes"; then
AC_DEFINE(HAVE_POSIX_TERMIOS,,[Define if you have POSIX termios])
fi

dnl Check for endianness
AC_C_BIGENDIAN

dnl Checks for types

AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UID_T
AC_TYPE_PID_T
AC_TYPE_OFF_T
AC_TYPE_MODE_T
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_CHECK_MEMBER(struct tm.tm_gmtoff, [AC_DEFINE(STRUCT_TM_TM_GMTOFF,,[Define if you have struct tm/tm_gmtoff])],,[
#include <sys/types.h>
#include <$ac_cv_struct_tm>
])

AC_MSG_CHECKING([whether timezone is scalar])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <$ac_cv_struct_tm>    
    ]], [[timezone = 42L]])],[
         AC_MSG_RESULT(yes)
         AC_DEFINE(HAVE_SCALAR_TIMEZONE,,[Define if your timezone is a scalar number])
    ],[    AC_MSG_RESULT(no)    ])   

AC_CHECK_TYPE(nlink_t, , [AC_DEFINE(nlink_t, int, [nlink_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
])


AC_CHECK_TYPE(dev_t, , [AC_DEFINE(dev_t, unsigned int, [dev_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
])


AC_CHECK_TYPE(ino_t, , [AC_DEFINE(ino_t, unsigned long, [ino_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
])

dnl Check for sizes
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(mode_t)

dnl Socket things

AC_CHECK_FUNC(connect, , [AC_CHECK_LIB(socket, connect)])

AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(resolv, gethostbyname)])

AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(nsl, gethostbyname)])

if test "x$ac_cv_lib_nsl_gethostbyname" != "xyes" && test "x$ac_cv_func_gethostbyname" != "xyes" ; then
  AC_CHECK_FUNC(gethostbyname, , [AC_CHECK_LIB(socket, gethostbyname)])
fi

if test "$ac_cv_lib_nsl_gethostbyname" = "$ac_cv_func_gethostbyname" ; then
  AC_MSG_CHECKING([if we can include libnsl + libsocket])
  LIBS="-lnsl -lsocket $LIBS"
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[(void) gethostbyname]])],[my_ac_link_result=yes],[my_ac_link_result=no ])
  if test "$my_ac_link_result" = "no" ; then
    AC_MSG_RESULT([failure])
    AC_MSG_ERROR([unable to use gethostbyname()])
  else
    AC_MSG_RESULT([success])
  fi
fi

AC_CHECK_LIB(sendfile, sendfile)

dnl Types - continued

AC_CHECK_TYPE(socklen_t, , [AC_DEFINE(socklen_t, int, [socklen_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NETINET_IN_SYSTM_H
# include <netinet/in_systm.h>
#endif
#include <netinet/in.h>
])

AC_CHECK_TYPE(in_port_t, , [AC_DEFINE(in_port_t, unsigned short, [in_port_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NETINET_IN_SYSTM_H
# include <netinet/in_systm.h>
#endif
#include <netinet/in.h>
])

AC_CHECK_TYPE(sig_atomic_t, , [AC_DEFINE(sig_atomic_t, signed char, [sig_atomic_t type])],
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <signal.h>
])

dnl Compiler characteristics

AC_PROG_GCC_TRADITIONAL
AC_C_CONST
AC_C_INLINE

dnl Options

AM_WITH_DMALLOC

AC_ARG_ENABLE(pie,
[AS_HELP_STRING(--enable-pie,Produce position independent executables @<:@default=yes@:>@)],
 enable_pie=$enableval, enable_pie="maybe")

AC_ARG_ENABLE(ssp,
[AS_HELP_STRING(--disable-ssp,Don't compile with -fstack-protector)],
[AS_IF([test "x$enableval" = "xno"], [
    nxflags=""
    for flag in `echo $CFLAGS`; do
      case "$flag" in
       -fstack-protector*) ;;
        *) AS_VAR_APPEND([nxflags], [" $flag"]) ;;
      esac
    done
    CFLAGS="$nxflags"
  ])
])

AC_ARG_WITH(standalone,
[AS_HELP_STRING(--without-standalone,Don't compile the standalone server code)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(NO_STANDALONE,,[without standalone])
    no_standalone=yes
  fi ])

AC_ARG_WITH(inetd,
[AS_HELP_STRING(--without-inetd,Don't support super-servers (like inetd))],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(NO_INETD,,[without inetd])
    no_inetd=yes
  fi ])

if test "x$no_standalone" = "xyes" && test "x$no_inetd" = "xyes" ; then
  AC_MSG_ERROR(You can't disable both standalone and inetd mode.)
fi

AC_ARG_WITH(capabilities,
[AS_HELP_STRING(--without-capabilities,Don't use Linux capabilities (default=detect))],
[ if test "x$withval" = "xno" ; then
    no_capabilities=1
  fi ])
  
if test -z "$no_capabilities" ; then
  AC_CHECK_LIB(cap, cap_init, , )
  if test "x$ac_cv_lib_cap_cap_init" = "xyes"; then
    if test "x$ac_cv_header_sys_capability_h" = "xyes"; then
      AC_DEFINE(USE_CAPABILITIES,,[use capabilities])
    fi
  fi
fi

AC_ARG_WITH(shadow,
[AS_HELP_STRING(--without-shadow,Don't use shadow passwords (default=detect))],
[ if test "x$withval" = "xno" ; then
    no_shadow=1
  fi ])
  
if test -z "$no_shadow" && test "x$ac_cv_header_shadow_h" = "xyes" ; then
  AC_CHECK_FUNC(getspnam, AC_DEFINE(USE_SHADOW,,[use shadow passwords]),
    AC_CHECK_LIB(shadow, getspnam, AC_DEFINE(USE_SHADOW),
      AC_MSG_WARN(shadow.h was found, but getspnam() isn't available)
    )
  )
fi

AC_ARG_WITH(usernames,
[AS_HELP_STRING(--without-usernames,Use only numerical UIDs/GIDs)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(NO_FTP_USERS,,[without usernames])
  fi ])

AC_ARG_WITH(iplogging,
[AS_HELP_STRING(--without-iplogging,Never log remote IP addresses (privacy))],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(DONT_LOG_IP,,[without iplogging])
  fi ])

AC_ARG_WITH(humor,
[AS_HELP_STRING(--without-humor,Disable humor (enabled by default))],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(DISABLE_HUMOR,,[without humor])
  fi ])

AC_ARG_WITH(longoptions,
[AS_HELP_STRING(--without-longoptions,Ignored - just for backward compatibility)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(NO_GETOPT_LONG,,[without longoptions])
  fi ])

AC_ARG_WITH(ascii,
[AS_HELP_STRING(--without-ascii,Don't support 7-bits (ASCII) transfers)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(WITHOUT_ASCII,,[without ascii])
  fi ])

AC_ARG_WITH(globbing,
[AS_HELP_STRING(--without-globbing,Don't include globbing code)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(DISABLE_GLOBBING,,[without globbing])
  fi ])

AC_ARG_WITH(nonalnum,
[AS_HELP_STRING(--without-nonalnum,Only allow basic alphanumeric characters in file names)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(PARANOID_FILE_NAMES,,[disallow non-alphanumeric characters])
  fi ])

AC_ARG_WITH(unicode,
[AS_HELP_STRING(--without-unicode,Disable non-latin characters in file names)],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(DISABLE_UNICODE_CONTROL_CHARS,,[disallow unicode control chars])
  fi ])

AC_ARG_WITH(sendfile,
[AS_HELP_STRING(--without-sendfile,Don't use zero-copy optimizations (for network FS))],
[ if test "x$withval" = "xno" ; then
    AC_DEFINE(DISABLE_SENDFILE,,[without sendfile])
  fi ])

AC_ARG_WITH(privsep,
[AS_HELP_STRING(--without-privsep,Disable privilege separation)],
[ if test "x$withval" = "xno" ; then
    without_privsep=yes
  fi ])

AC_ARG_WITH(boring,
[AS_HELP_STRING(--with-boring,Display only boring messages)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(BORING_MODE,,[display only boring messages])
    AC_DEFINE(DISABLE_HUMOR)
  fi ])

AC_ARG_WITH(brokenrealpath,
[AS_HELP_STRING(--with-brokenrealpath,If your libc has a broken realpath() call)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(USE_BUILTIN_REALPATH,,[realpath() is broken])
  fi ])

AC_ARG_WITH(minimal,
[AS_HELP_STRING(--with-minimal,Build only a small minimal server)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(MINIMAL,,[with minimal])
    AC_DEFINE(NO_GETOPT_LONG)
    AC_DEFINE(DISABLE_HUMOR)
    AC_DEFINE(NO_FTP_USERS)
    AC_DEFINE(WITHOUT_ASCII)    
    AC_DEFINE(BORING_MODE)
    CFLAGS="$CFLAGS -Os -fomit-frame-pointer -fno-unroll-loops "
    LDFLAGS="$LDFLAGS -s "
  fi ])

AC_ARG_WITH(paranoidmsg,
[AS_HELP_STRING(--with-paranoidmsg,Use paranoid but not admin-friendly messages)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(PARANOID_MESSAGES,,[with paranoidmsg])
  fi ])

AC_ARG_WITH(sysquotas,
[AS_HELP_STRING(--with-sysquotas,Use system (not virtual) quotas)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(SYSTEM_QUOTAS,,[with sysquotas])
  fi ])

AC_ARG_WITH(altlog,
[AS_HELP_STRING(--with-altlog,Support alternative log format (Apache-like))],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(WITH_ALTLOG,,[with altlog]) 
  fi ])

AC_ARG_WITH(puredb,
[AS_HELP_STRING(--with-puredb,Support virtual (FTP-only) users)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(WITH_PUREDB,,[with puredb])
  fi ])

AC_ARG_WITH(extauth,
[AS_HELP_STRING(--with-extauth,Support external authentication modules)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(WITH_EXTAUTH,,[with extauth (*BETA*)])
  fi ])

AC_ARG_WITH(pam,
[AS_HELP_STRING(--with-pam,Enable PAM support (default=disabled))],
[ if test "x$withval" = "xyes" ; then
    with_pam="yes"
  fi ])

if test "x`uname`" = "xDarwin"; then
  if test "x$with_pam" = "x"; then
    with_pam="yes"
  fi
fi

if test "x$with_pam" = "xyes" ; then
  if test "x$ac_cv_header_security_pam_appl_h" != "xyes" &&
     test "x$ac_cv_header_pam_pam_appl_h" != "xyes"; then
    AC_MSG_ERROR(PAM headers not found.)  
  else
    AC_CHECK_LIB(dl, dlopen, , )
    LIBS="$LIBS -lpam"
    AC_DEFINE(USE_PAM,,[use pam])
    AC_CHECK_FUNCS(pam_getenvlist)
    AC_MSG_CHECKING([whether pam_strerror takes only one argument])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#include <security/pam_appl.h>
        ]], [[(void)pam_strerror((pam_handle_t *)NULL, -1)]])],[AC_MSG_RESULT(no)],[
            AC_DEFINE(HAVE_OLD_PAM,,[obsolete pam])
            AC_MSG_RESULT(yes)
        ])   
  fi
fi  

AC_MSG_CHECKING([whether syslog names are available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define SYSLOG_NAMES 1
#include <stdio.h>
#include <syslog.h>
]], [[
 (void) facilitynames
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_SYSLOG_NAMES,,[define if syslog names are available])
],[
  AC_MSG_RESULT(no)
])  


AC_MSG_CHECKING([whether struct addrinfo is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
]], [[
do {
 struct addrinfo a;
 (void) a.ai_flags;
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_STRUCT_ADDRINFO,,[define if you have struct addrinfo])
],[
  AC_MSG_RESULT(no)
])  


AC_MSG_CHECKING([whether sin_len is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
]], [[
do {
 struct sockaddr_in a;
 (void) a.sin_len;
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_SIN_LEN,,[define if you have sin_len])
],[
  AC_MSG_RESULT(no)
])  


AC_MSG_CHECKING([whether __ss_family is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
]], [[
do {
 struct sockaddr_storage a;
 (void) a.__ss_family;
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE___SS_FAMILY,,[define if you have __ss_family])
],[
  AC_MSG_RESULT(no)
])  


AC_MSG_CHECKING([whether ss_len is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
]], [[
do {
 struct sockaddr_storage a;
 (void) a.ss_len;
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_SS_LEN,,[define if you have ss_len])
],[
  AC_MSG_RESULT(no)
])  


AC_MSG_CHECKING([whether __ss_len is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
]], [[
do {
 struct sockaddr_storage a;
 (void) a.__ss_len;
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE___SS_LEN,,[define if you have __ss_len])
],[
  AC_MSG_RESULT(no)
])  



AC_MSG_CHECKING([if a linuxish sendfile is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h>
#endif
]], [[
do {
 int fd = 0;
 off_t *off = NULL;
 size_t cnt = (size_t) 0;
 
 (void) sendfile(fd, fd, off, cnt);
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(SENDFILE_LINUX,,[define if you have a linuxish sendfile])
],[
  AC_MSG_RESULT(no)
])  

AC_MSG_CHECKING([if a linuxish sendfile64 is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h>
#endif
]], [[
do {
 int fd = 0;
 off_t *off = NULL;
 size_t cnt = (size_t) 0;
 
 (void) sendfile64(fd, fd, off, cnt);
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(SENDFILE64_LINUX,,[define if you have a linuxish sendfile64])
],[
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([if a freebsdish sendfile is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h>
#endif
]], [[
do {
 int fd = 0;
 off_t off = (off_t) 0;
 size_t cnt = (size_t) 0;
 struct sf_hdtr *hdtr = NULL;
 
 (void) sendfile(fd, fd, off, cnt, hdtr, &off, 42);
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(SENDFILE_FREEBSD,,[define if you have a freebsdish sendfile])
],[
  AC_MSG_RESULT(no)
])

AC_MSG_CHECKING([if a hpuxish sendfile is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/socket.h>
#include <stdio.h>
]], [[
do {
 int fd = 0;
 off_t off = (off_t) 0;
 bsize_t nbytes = (size_t) 0;
 const struct iovec *hdtrl = NULL;
 
 (void) sendfile(fd, fd, off, nbytes, hdtrl, 42);
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(SENDFILE_HPUX,,[define if you have a hpuxish sendfile])
],[
  AC_MSG_RESULT(no)
])

AC_CHECK_FUNC(sendfilev, , [AC_CHECK_LIB(sendfile, sendfilev)])

AC_MSG_CHECKING([if a solarisish sendfilev is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h>
#endif
]], [[
do {
 int fd = 0, sfvcnt = 0;
 const struct sendfilevec vec;
 size_t xferred;
 
 (void) sendfilev(fd, &vec, sfvcnt, &xferred);
} while(0)
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(SENDFILEV_SOLARIS,,[define if you have a solarisish sendfilev])
],[
  AC_MSG_RESULT(no)
])


AC_ARG_WITH(cookie,
[AS_HELP_STRING(--with-cookie,Support 'fortune' cookies (-F option))],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(COOKIE,,[with cookie])
  fi ])

AC_ARG_WITH(throttling,
[AS_HELP_STRING(--with-throttling,Support bandwidth throttling (disabled by default))],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(THROTTLING,,[with throttling])
  fi ])

AC_ARG_WITH(ratios,
[AS_HELP_STRING(--with-ratios,Support for upload/download ratios)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(RATIOS,,[with ratios])
  fi ])

AC_ARG_WITH(quotas,
[AS_HELP_STRING(--with-quotas,Support .ftpquota files)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(QUOTAS,,[with quotas])
  fi ])

AC_ARG_WITH(ftpwho,
[AS_HELP_STRING(--with-ftpwho,Support for pure-ftpwho)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(FTPWHO,,[with ftpwho])
  fi ])

AC_ARG_WITH(welcomemsg,
[AS_HELP_STRING(--with-welcomemsg,Support welcome.msg backward compatibility (deprecated))],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(WITH_WELCOME_MSG,,[with welcomemsg])
  fi ])

AC_ARG_WITH(uploadscript,
[AS_HELP_STRING(--with-uploadscript,Allow running an external script after an upload (experimental))],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(WITH_UPLOAD_SCRIPT,,[with uploadscript])
  fi ])

AC_ARG_WITH(virtualhosts,
[AS_HELP_STRING(--with-virtualhosts,Handle virtual servers on different IP addresses)],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(WITH_VIRTUAL_HOSTS,,[with virtualhosts])
  fi ])

AC_ARG_WITH(virtualchroot,
[AS_HELP_STRING(--with-virtualchroot,Enable the ability to follow symlinks outside a chroot jail)],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(WITH_VIRTUAL_CHROOT,,[with virtual chroot])
  fi ])

AC_ARG_WITH(diraliases,
[AS_HELP_STRING(--with-diraliases,Enable directory aliases)],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(WITH_DIRALIASES,,[with directory aliases])
  fi ])

AC_ARG_WITH(nonroot,
[AS_HELP_STRING(--with-nonroot,[Compile a limited server designed to be started as a regular user. Only enable this option as a last resort if you really don't have root privileges on the server host.])],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(NON_ROOT_FTP,,[with nonroot])
      AC_DEFINE(WITH_VIRTUAL_CHROOT)      
      non_root_ftp=yes
      without_privsep=yes
  fi ])

if test "x$without_privsep" = "xyes" ; then
  AC_DEFINE(WITHOUT_PRIVSEP,,[disable privilege separation])
fi

AC_ARG_WITH(peruserlimits,
[AS_HELP_STRING(--with-peruserlimits,Support per-user concurrency limits)],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(PER_USER_LIMITS,,[with per-user limits])
      AC_DEFINE(FTPWHO)
  fi ])

AC_ARG_WITH(implicittls,
[AS_HELP_STRING(--with-implicittls,Implicit TLS (port 990) - DO NOT USE unless you know what you are doing)],
[ if test "x$withval" = "xyes" ; then
      AC_DEFINE(IMPLICIT_TLS,,[with implicit TLS])
      with_tls="yes"
  fi ])

AC_ARG_WITH(debug,
[AS_HELP_STRING(--with-debug,For maintainers only - please do not use)],
[ if test "x$withval" = "xyes" ; then
    if test "$LX_CFLAGS" = "NONE"; then
      nxflags=""
      for flag in `echo $CFLAGS`; do
        case "$flag" in
          -O*) ;;
          -g*) ;;
          *) nxflags="$nxflags $flag"
        esac
      done
      CFLAGS="$nxflags -O0 -g3 $CWFLAGS"
    fi
    CPPFLAGS="$CPPFLAGS -DDEBUG=1"
  fi ])

AC_ARG_WITH(everything,
[AS_HELP_STRING(--with-everything,Build a big server with almost everything)],
[ if test "x$withval" = "xyes" ; then
    AC_DEFINE(WITH_ALTLOG)
    AC_DEFINE(COOKIE)
    AC_DEFINE(THROTTLING)
    AC_DEFINE(RATIOS)
    AC_DEFINE(QUOTAS)    
    AC_DEFINE(WITH_UPLOAD_SCRIPT)
    AC_DEFINE(WITH_VIRTUAL_HOSTS)
    AC_DEFINE(WITH_PUREDB)
    AC_DEFINE(WITH_EXTAUTH)
    AC_DEFINE(FTPWHO)
    AC_DEFINE(WITH_DIRALIASES)
    AC_DEFINE(PER_USER_LIMITS)
    with_bonjour='yes'
  fi ])

AC_ARG_WITH(language,
[AS_HELP_STRING(--with-language=,< english | german | romanian | french |
french-funny | polish | spanish | danish | dutch | italian |
brazilian-portuguese | slovak | korean | swedish | norwegian | russian |
traditional-chinese | simplified-chinese | czech | turkish | hungarian |
catalan>)],
[ if test "x$withval" = "xenglish" ; then
    AC_DEFINE(MESSAGES_EN,,[english])
  elif test "x$withval" = "xgerman" ; then
    AC_DEFINE(MESSAGES_DE,,[german])  
  elif test "x$withval" = "xromanian" ; then
    AC_DEFINE(MESSAGES_RO,,[romanian])
  elif test "x$withval" = "xfrench" ; then
    AC_DEFINE(MESSAGES_FR,,[french])
  elif test "x$withval" = "xfrench-funny" ; then
    AC_DEFINE(MESSAGES_FR_FUNNY,,[french-funny])    
  elif test "x$withval" = "xpolish" ; then  
    AC_DEFINE(MESSAGES_PL,,[polish])
  elif test "x$withval" = "xspanish" ; then
    AC_DEFINE(MESSAGES_ES,,[spanish])
  elif test "x$withval" = "xdanish" ; then
    AC_DEFINE(MESSAGES_DA,,[danish])
  elif test "x$withval" = "xdutch" ; then
    AC_DEFINE(MESSAGES_NL,,[dutch])
  elif test "x$withval" = "xitalian" ; then
    AC_DEFINE(MESSAGES_IT,,[italian])
  elif test "x$withval" = "xbrazilian-portuguese" ; then
    AC_DEFINE(MESSAGES_PT_BR,,[brazilian portuguese])
  elif test "x$withval" = "xslovak" ; then
    AC_DEFINE(MESSAGES_SK,,[slovak])
  elif test "x$withval" = "xkorean" ; then
    AC_DEFINE(MESSAGES_KR,,[korean])
  elif test "x$withval" = "xswedish" ; then
    AC_DEFINE(MESSAGES_SV,,[swedish])
  elif test "x$withval" = "xnorwegian" ; then
    AC_DEFINE(MESSAGES_NO,,[norwegian])
  elif test "x$withval" = "xrussian" ; then
    AC_DEFINE(MESSAGES_RU,,[russian])
  elif test "x$withval" = "xtraditional-chinese" ; then
    AC_DEFINE(MESSAGES_ZH_TW,,[traditional chinese])
  elif test "x$withval" = "xsimplified-chinese" ; then
    AC_DEFINE(MESSAGES_ZH_CN,,[simplified chinese])
  elif test "x$withval" = "xczech" ; then
    AC_DEFINE(MESSAGES_CS_CZ,,[czech])
  elif test "x$withval" = "xturkish" ; then
    AC_DEFINE(MESSAGES_TR,,[turkish])
  elif test "x$withval" = "xhungarian" ; then
    AC_DEFINE(MESSAGES_HU,,[hungarian])
  elif test "x$withval" = "xcatalan" ; then
    AC_DEFINE(MESSAGES_CA_ES,,[catalan])
  else 
    AC_MSG_WARN(--with-language=$withval is not recognized)
  fi ])



dnl Checks for libraries.

AC_CHECK_LIB(crypt, crypt, , )

AC_CHECK_LIB(sodium, crypto_pwhash_scryptsalsa208sha256_str)

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_FUNC_MEMCMP
AC_FUNC_STRFTIME
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_FUNC_GETLOADAVG(src)
AC_FUNC_GETGROUPS
AC_FUNC_WAIT3
AC_FUNC_UTIME_NULL
AC_FUNC_STRTOD
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_MKTIME
AC_FUNC_LSTAT
AC_FUNC_FORK
AC_FUNC_ERROR_AT_LINE
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_CHOWN
AC_C_VOLATILE


AC_CHECK_FUNCS(initgroups setrlimit waitpid setproctitle getopt_long)
AC_CHECK_FUNCS(seteuid setreuid setresuid setegid setregid setresgid)
AC_CHECK_FUNCS(statvfs statfs putenv setenv unsetenv getpagesize realpath)
AC_CHECK_FUNCS(pread posix_fadvise ptrace)
AC_CHECK_FUNCS(strtoull strtoq)
AC_CHECK_FUNCS(strlcpy strlcat)
AC_CHECK_FUNCS(memset munmap strdup fileno mapviewoffile madvise)
AC_CHECK_FUNCS(getaddrinfo getnameinfo inet_ntop inet_pton)
AC_CHECK_FUNCS(setusershell setgroups snprintf vsnprintf vfprintf gethostname)
AC_CHECK_FUNCS(setlocale timegm)
AC_CHECK_FUNCS(tzset utime utimes mknod mkfifo)
AC_CHECK_FUNCS(random srandomdev arc4random arc4random_stir arc4random_addrandom)
AC_CHECK_FUNCS(closefrom explicit_bzero getpwnam_shadow)

AC_MSG_CHECKING([whether statvfs64() is defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
]], [[
for (;;) {
 struct statvfs64 a;
 if (statvfs64(".", &a) == 0 || a.f_bsize != 0) {
   break;
 }
} 
]])],[
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_STATVFS64,,[define if you have statvfs64])
],[
  AC_MSG_RESULT(no)
])  

AC_MSG_CHECKING(whether snprintf is C99 conformant)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

int main(void)
{
    char buf[4];
    
    (void) fprintf(fopen("conftestval", "w"), "%d\n",
        (int) snprintf(buf, sizeof buf, "12345678"));
    return 0;
}
]])],[CONF_SNPRINTF_TYPE=`cat conftestval`
],[],[CONF_SNPRINTF_TYPE=8])
AC_MSG_RESULT(done)
if test "x$CONF_SNPRINTF_TYPE" = "x" ; then
  AC_MSG_WARN(your operating system doesn't implement snprintf)
else
  AC_DEFINE_UNQUOTED(CONF_SNPRINTF_TYPE, $CONF_SNPRINTF_TYPE, [return value of an overflowed snprintf])
fi


AC_MSG_CHECKING(whether getgroups 0 is sane)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

int main(void)
{
    return getgroups(0, NULL) <= 0;
}
]])],[
AC_MSG_RESULT(yes)
AC_DEFINE(SAFE_GETGROUPS_0,,[Define is getgroups(0, NULL) works on your system])
],[AC_MSG_RESULT(no)
],[AC_MSG_RESULT(suppose that it doesnt)])

AC_MSG_CHECKING(whether realpath likes unreadable directories)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif

#ifndef PATH_MAX
# define PATH_MAX MAXPATHLEN
#endif

int main(void)
{
    char x[PATH_MAX];
    
    if (mkdir("x", 0300) != 0) {
        return 1;
    }
    if (mkdir("x/y", 0300) != 0) {
        rmdir("x");
        return 2;
    }    
    if (chdir("x") != 0) {
        rmdir("x/y");    
        rmdir("x");
        return 3;
    }
    if (realpath("y", x) == NULL) {
        rmdir("y");
        rmdir("../x");
        return 4;
    }
    rmdir("y");
    rmdir("../x");
    
    return 0;    
}
]])],[
AC_MSG_RESULT(yes)
AC_DEFINE(REALPATH_WORKS_WITH_UNREADABLE_DIRECTORIES,,
[Define if realpath() works on unreadable directories])
],[AC_MSG_RESULT(no)
AC_DEFINE(USE_BUILTIN_REALPATH)
],[AC_MSG_RESULT(no)
AC_DEFINE(USE_BUILTIN_REALPATH)])

AC_MSG_CHECKING(whether you already have a standard MD5 implementation)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <md5.h>

int main(void)
{
    MD5_CTX ctx;
    char b[33];
    
    MD5Init(&ctx);
    MD5Update(&ctx, (const unsigned char *) "test", 4U);
    MD5End(&ctx, b);
    b[32] = 0;

    return strcasecmp(b, "098f6bcd4621d373cade4e832627b4f6");
}
]])],[
AC_MSG_RESULT(yes)
AC_DEFINE(USE_SYSTEM_CRYPT_MD5,,[Define if you already have standard
MD5 functions])
],[AC_MSG_RESULT(no)
],[AC_MSG_RESULT(assuming no)])

AC_MSG_CHECKING(whether you already have a standard SHA1 implementation)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sha1.h>

int main(void)
{
    SHA1_CTX ctx;
    char b[41];
    
    SHA1Init(&ctx);
    SHA1Update(&ctx, (const unsigned char *) "test", 4U);
    SHA1End(&ctx, b);
    b[40] = 0;
    
    return strcasecmp(b, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3");
}
]])],[
AC_MSG_RESULT(yes)
AC_DEFINE(USE_SYSTEM_CRYPT_SHA1,,[Define if you already have standard
SHA1 functions])
],[AC_MSG_RESULT(no)
],[AC_MSG_RESULT(assuming no)])

AC_MSG_CHECKING([whether we are inside a Virtuozzo virtual host])
if test -d /proc/vz; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(VIRTUOZZO,,[Define if you are inside a Virtuozzo virtual
host])
else
  AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(default TCP send buffer size)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void)
{
    int fd,val=0,len=sizeof(int);
    if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) return 1;
        if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) return 1;
    if (val <= 0) return 1;
        fprintf (fopen("conftestval", "w"), "%d\n", val);
    return 0;
}
]])],[CONF_TCP_SO_SNDBUF=`cat conftestval`],[CONF_TCP_SO_SNDBUF=65536],[CONF_TCP_SO_SNDBUF=65536])
AC_MSG_RESULT($CONF_TCP_SO_SNDBUF)

AC_DEFINE_UNQUOTED(CONF_TCP_SO_SNDBUF, $CONF_TCP_SO_SNDBUF, [default TCP send buffer])

AC_MSG_CHECKING(default TCP receive buffer size)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void)
{
    int fd,val=0,len=sizeof(int);
    if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) return 1;
        if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) return 1;
    if (val <= 0) return 1;
        fprintf (fopen("conftestval", "w"), "%d\n", val);
    return 0;
}
]])],[CONF_TCP_SO_RCVBUF=`cat conftestval`],[CONF_TCP_SO_RCVBUF=65536],[CONF_TCP_SO_RCVBUF=65536])
AC_MSG_RESULT($CONF_TCP_SO_RCVBUF)

AC_DEFINE_UNQUOTED(CONF_TCP_SO_RCVBUF, $CONF_TCP_SO_RCVBUF, [defaut TCP receive buffer])


AC_ARG_WITH(ldap,
[AS_HELP_STRING(--with-ldap,Users database is an LDAP directory (see doc))],
[ if test "x$withval" != "xno" ; then
    if test "x$withval" != "x" && test "x$withval" != "xyes" ; then
      LD_RUN_PATH="${withval}/lib${LD_RUN_PATH:+:}${LD_RUN_PATH}"
      LDFLAGS="$LDFLAGS -L${withval}/lib"
      CPPFLAGS="$CPPFLAGS -I${withval}/include"
    fi
    with_ldap="yes"
    AC_DEFINE(WITH_LDAP,,[with ldap])
    AC_CHECK_LIB(resolv, res_query)
    AC_CHECK_LIB(lber, ber_init, , 
    [AC_MSG_ERROR(liblber is needed for LDAP support)])
    AC_CHECK_LIB(ldap, ldap_init, ,
     [AC_MSG_WARN(Initial check for -lldap failed! May need -lssl -lcrypto) 
      AC_CHECK_LIB(ldap, ldap_bind, [ldap_ssl_libs=true], 
      [AC_MSG_ERROR(libldap is needed for LDAP support)], -lssl -lcrypto)
     ])
    if test "x$ldap_ssl_libs" = "xtrue" ; then
      LDAP_SSL_LIBS='-lssl -lcrypto'
    fi
  fi ])

AC_SUBST(LDAP_SSL_LIBS)

AC_ARG_WITH(mysql,
[AS_HELP_STRING(--with-mysql,Users database is a MySQL database (see doc))],
[ if test "x$withval" != "xno" ; then
    if test "x$withval" != "x" && test "x$withval" != "xyes" ; then
      LD_RUN_PATH="${withval}/lib${LD_RUN_PATH:+:}${LD_RUN_PATH}"    
      LDFLAGS="$LDFLAGS -L${withval}/lib -L${withval}/lib/mysql -L${withval}/mysql/lib"
      CPPFLAGS="$CPPFLAGS -I${withval}/include -I${withval}/include/mysql -I${withval}/mysql/include"
    else
      CFLAGS="$CFLAGS `mariadb_config --cflags 2> /dev/null || mysql_config --cflags`"
      LDFLAGS="$LDFLAGS `mariadb_config --libs 2> /dev/null || mysql_config --libs`"
    fi
    AC_CHECK_LIB(m, floor)
    AC_CHECK_LIB(z, gzclose)
    with_mysql="yes"
    AC_DEFINE(WITH_MYSQL,,[with mysql])
    AC_CHECK_FUNC(mysql_init, , [
      AC_CHECK_LIB(mariadb, mysql_init, , [
        AC_CHECK_LIB(mysqlclient, mysql_init, ,
          [AC_MSG_ERROR(libmysqlclient is needed for MySQL support)])
      ])
    ])
    AC_MSG_CHECKING(whether mysql clients can run)
    AC_RUN_IFELSE([AC_LANG_SOURCE([[
      #include <stdio.h>
      #include <mysql.h>    
      int main(void)
      {
          MYSQL *a = mysql_init(NULL);
          return 0;
      }
      ]])],[],[
        AC_MSG_RESULT(no)
        AC_MSG_ERROR(Your MySQL client libraries aren't properly installed)
    ],[])
    AC_MSG_RESULT(yes)
  fi ])

AC_ARG_WITH(pgsql,
[AS_HELP_STRING(--with-pgsql,Users database is a PostgreSQL database (see doc))],
[ if test "x$withval" != "xno" ; then
    if test "x$withval" != "x" && test "x$withval" != "xyes" ; then
      LD_RUN_PATH="${withval}/lib${LD_RUN_PATH:+:}${LD_RUN_PATH}"
      LDFLAGS="$LDFLAGS -L${withval}/lib -L${withval}/lib/pgsql -L${withval}/lib/postgresql -L${withval}/pgsql/lib -L${withval}/postgresql/lib"
      CPPFLAGS="$CPPFLAGS -I${withval}/include -I${withval}/include/pgsql -I${withval}/include/postgresql -I${withval}/pgsql/include -I${withval}/postgresql/include"
    else
      LD_RUN_PATH="`pg_config --libdir`${LD_RUN_PATH:+:}${LD_RUN_PATH}"
      CPPFLAGS="$CPPFLAGS -I`pg_config --includedir`"
      LDFLAGS="$LDFLAGS -L`pg_config --libdir`"
    fi
    AC_CHECK_LIB(m, floor)
    AC_CHECK_LIB(z, gzclose)
    with_pgsql="yes"
    AC_DEFINE(WITH_PGSQL,,[with pgsql])
    AC_CHECK_LIB(pq, PQconnectdb, ,
      [AC_MSG_ERROR(libpq is needed for PostgreSQL support)])        
    AC_MSG_CHECKING(whether postgresql clients can run)
    AC_RUN_IFELSE([AC_LANG_SOURCE([[
      #include <stdio.h>
      #include <libpq-fe.h>
      int main(void)
      {
          PGconn *a = PQconnectdb("");
          return 0;
      }
      ]])],[],[
        AC_MSG_RESULT(no)
        AC_MSG_ERROR(Your PostgreSQL client libraries aren't properly installed)      
    ],[])    
    AC_MSG_RESULT(yes)
  fi ])

AC_ARG_WITH(tls,
[AS_HELP_STRING(--with-tls,Enable TLS support)],
[ if test "x$withval" = "xyes" ; then
    with_tls="yes"
  fi ])

if test "x$with_tls" = "xyes" ; then
  if test "x$ac_cv_header_openssl_ssl_h" != "xyes" ; then
    AC_MSG_ERROR(OpenSSL headers not found.)  
  fi
  AC_CHECK_LIB(crypto, DH_new)
  AC_CHECK_LIB(ssl, SSL_accept)
  AC_CHECK_FUNCS(DH_get_2048_256)
  AC_DEFINE(WITH_TLS,,[Enable TLS])
fi

AC_ARG_WITH(certfile,
[AS_HELP_STRING(--with-certfile=,certificate file (default: /etc/ssl/private/pure-ftpd.pem))],
[ if test "x$withval" != "x" ; then
    certfile="$withval"
    AC_SUBST(certfile)
    CPPFLAGS="$CPPFLAGS -DTLS_CERTIFICATE_FILE='\"$certfile\"'"
    if test ! -e "$certfile"; then
      AC_MSG_WARN(No certificate is installed in $certfile yet)
    fi
  fi ])

AC_ARG_WITH(rfc2640,
[AS_HELP_STRING(--with-rfc2640,Enable RFC 2640 (UTF-8 encoding for file names) support (needs iconv))],
[ if test "x$withval" = "xyes" ; then
    with_rfc2640="yes"
  fi ])

if test "x$with_rfc2640" = "xyes" ; then
  if test "x$ac_cv_header_iconv_h" != "xyes" ; then
    AC_MSG_ERROR(iconv headers not found.)  
  fi
  AC_CHECK_LIB(iconv, iconv_open)
  AC_CHECK_LIB(iconv, libiconv_open)
  AC_DEFINE(WITH_RFC2640,,[Enable RFC2640 (UTF-8) support])
fi

AC_ARG_WITH(bonjour,
[AS_HELP_STRING(--with-bonjour,Enable Bonjour support on MacOS X)],
[ if test "x$withval" = "xyes" ; then
    with_bonjour="yes"
  fi ])

if test "x$with_bonjour" = "xyes" ; then
  if test "x$ac_cv_header_CoreFoundation_CoreFoundation_h" = "xyes" ; then
    AC_DEFINE(WITH_BONJOUR,,[Enable Bonjour on MacOS X])
    BONJOUR_LDADD='-framework CoreFoundation -framework CoreServices'
  fi
fi

AC_SUBST(BONJOUR_LDADD)

if test "x$sysconfdir" = 'xNONE' || test "x$sysconfdir" = 'x'; then
  CONFDIR='/etc'
else
  if test "x$sysconfdir" = 'x${prefix}/etc'; then
    if test "x$prefix" = 'xNONE' || test "x$prefix" = 'x/usr'; then
      CONFDIR='/etc'
    else
      CONFDIR="$sysconfdir"
    fi
  else
    CONFDIR="$sysconfdir"
  fi
fi  

if test "x$localstatedir" = 'xNONE' || test "x$localstatedir" = 'x'; then
  LOCALSTATEDIR='/var'
else
  if test "x$localstatedir" = 'x${prefix}/var'; then
    if test "x$prefix" = 'xNONE' || test "x$prefix" = 'x/usr' || test "x$localstatedir" = 'x${prefix}/var' ; then
      LOCALSTATEDIR='/var'
    else
      LOCALSTATEDIR="$localstatedir"
    fi
  else
    LOCALSTATEDIR="$localstatedir"
  fi
fi  

if test -r /dev/urandom; then
  AC_MSG_NOTICE([You have /dev/urandom - Great])
  AC_DEFINE(HAVE_DEV_URANDOM,,[Define if you have /dev/urandom])
fi
if test -r /dev/random; then
  AC_MSG_NOTICE([You have /dev/random - Great])
  AC_DEFINE(HAVE_DEV_RANDOM,,[Define if you have /dev/random])
fi

CONFDIR=`eval echo "$CONFDIR"`
LOCALSTATEDIR=`eval echo "$LOCALSTATEDIR"`

sysconfdir="$CONFDIR"
AC_SUBST(sysconfdir)
localstatedir="$LOCALSTATEDIR"
AC_SUBST(localstatedir)

CPPFLAGS="$CPPFLAGS -DCONFDIR=\\\"$sysconfdir\\\""
CPPFLAGS="$CPPFLAGS -DSTATEDIR=\\\"$localstatedir\\\""

AC_SUBST(CONFDIR)
AC_SUBST(LOCALSTATEDIR)

AH_VERBATIM([NDEBUG], [/* Never ever ignore assertions */
#ifdef NDEBUG
#/**/undef/**/ NDEBUG
#endif])

AC_CONFIG_FILES(Makefile src/Makefile pam/Makefile man/Makefile
gui/Makefile m4/Makefile pure-ftpd.conf puredb/Makefile
puredb/src/Makefile
man/pure-ftpd.8 man/pure-ftpwho.8 man/pure-mrtginfo.8 man/pure-uploadscript.8
man/pure-statsdecode.8 man/pure-quotacheck.8 man/pure-pw.8 man/pure-pwconvert.8
man/pure-authd.8)

AC_OUTPUT

AC_MSG_NOTICE([+--------------------------------------------------------+])
AC_MSG_NOTICE([| You can subscribe to the Pure-FTPd users mailing-list  |])
AC_MSG_NOTICE([| to ask for help and to stay informed of new releases.  |])
AC_MSG_NOTICE([| Go to http://www.pureftpd.org/ml/ now!                 |])
AC_MSG_NOTICE([+--------------------------------------------------------+])