Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 1672 lines (1433 sloc) 46.837 kb
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
dnl -*- mode: m4-mode -*-
dnl Process this file with autoconf to produce a configure script.

AC_COPYRIGHT([
Copyright (C) 2001-2012 Alvaro Lopez Ortega

This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public
License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
])

dnl require autoconf 2.60
AC_PREREQ([2.60])

dnl Version
m4_define([cherokee_major_version], [1])
m4_define([cherokee_minor_version], [2])
m4_define([cherokee_micro_version], [102])
m4_define([cherokee_version], m4_format('%s.%s.%s', cherokee_major_version, cherokee_minor_version, cherokee_micro_version))

dnl Init autoconf and automake
AC_INIT([cherokee], [cherokee_version], [http://bugs.cherokee-project.com/], [cherokee])
AC_CONFIG_SRCDIR([cherokee/server.c])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([no-define])

dnl Define version
AC_DEFINE(PACKAGE_MAJOR_VERSION, "cherokee_major_version", [Version string])
AC_DEFINE(PACKAGE_MINOR_VERSION, "cherokee_minor_version", [Version string])
AC_DEFINE(PACKAGE_MICRO_VERSION, "cherokee_micro_version", [Version string])

PACKAGE_MAJOR_VERSION="cherokee_major_version"
PACKAGE_MINOR_VERSION="cherokee_minor_version"
PACKAGE_MICRO_VERSION="cherokee_micro_version"
AC_SUBST(PACKAGE_MAJOR_VERSION)
AC_SUBST(PACKAGE_MINOR_VERSION)
AC_SUBST(PACKAGE_MICRO_VERSION)

dnl Define library soname
CHEROKEE_AGE=0
CHEROKEE_CURRENT=0
CHEROKEE_REVISION=1
AC_SUBST(CHEROKEE_AGE)
AC_SUBST(CHEROKEE_CURRENT)
AC_SUBST(CHEROKEE_REVISION)

AC_DEFINE_UNQUOTED(CHEROKEE_CONFIG_ARGS, "$ac_configure_args", [configure arguments])

dnl Check the SVN revision
AC_ARG_ENABLE(beta, AC_HELP_STRING([--enable-beta], [Enable beta development]),
is_beta="$enableval", is_beta="no")

if test x"$is_beta" = "xyes"; then
  dnl Figure revision
  today=`date +'%y%m%d'`
  git_hash=`git log -1 --pretty=tformat:%h`

  PACKAGE_PATCH_VERSION="b${today}_${git_hash}"

  dnl Redefine versions
  PACKAGE_VERSION="$PACKAGE_MAJOR_VERSION.$PACKAGE_MINOR_VERSION.$PACKAGE_MICRO_VERSION$PACKAGE_PATCH_VERSION"
  AC_DEFINE_UNQUOTED(PACKAGE_VERSION, "${PACKAGE_VERSION}", [Package version])

  VERSION="$PACKAGE_MAJOR_VERSION.$PACKAGE_MINOR_VERSION.$PACKAGE_MICRO_VERSION$PACKAGE_PATCH_VERSION"
  AC_DEFINE(VERSION, $VERSION, [Software version])
else

  PACKAGE_PATCH_VERSION=""
fi

dnl Path version
AC_SUBST(PACKAGE_PATCH_VERSION)
AC_DEFINE_UNQUOTED(PACKAGE_PATCH_VERSION, "${PACKAGE_PATCH_VERSION}", [Version string])

dnl Initial CFLAGS
AC_MSG_CHECKING(initial CFLAGS)
AC_MSG_RESULT($CFLAGS)

dnl Check for CPU / vendor / OS
AC_CANONICAL_HOST

os_string="UNIX"
so_suffix=so
mod_suffix=$so_suffix

AC_MSG_CHECKING([host platform characteristics])
case "$host" in
*-*-mingw*|*-*-cygwin*)
so_suffix=DLL
mod_suffix=$so_suffix
os_string="Win32"
          libdl=
          ;;
*-*-linux*)
          libdl="-ldl"
          ;;
*-*-solaris*)
AC_DEFINE(SOLARIS, 1, [It is Solaris])
setenv_is_threadsafe="yes"
          libdl="-ldl"
          ;;
*-*-hpux*)
          libdl="-ldl"
          ;;
*-*-aix*)
          libdl="-ldl"
;;
     *-*-irix6*)
          AC_DEFINE(IRIX, 1, [It is SGI Irix])
          setenv_is_threadsafe="yes"
          libdl="-ldl"
          ;;
*-*-*freebsd*|*-*-*openbsd*|*-*-*netbsd*|*-*-*dragonfly*)
          libdl=
          ;;
*-*-darwin*)
so_suffix=dylib
mod_suffix=so
          libdl="-ldl"
          ;;
*)
AC_MSG_WARN([*** Please add $host to configure.in checks!])
          libdl="-ldl"
          ;;
esac
AC_MSG_RESULT(ok)

AC_MSG_CHECKING([L2 cache line size])
case "$host_cpu" in
i386|i486)
CPU_CACHE_LINE=32
;;
i586|i686)
CPU_CACHE_LINE=64
;;
i786)
CPU_CACHE_LINE=128
;;
athlon)
CPU_CACHE_LINE=64
;;
x86_64)
CPU_CACHE_LINE=64
;;
sparc*)
CPU_CACHE_LINE=64
;;
powerpc)
CPU_CACHE_LINE=128
;;
*)
CPU_CACHE_LINE=128
;;
esac
AC_DEFINE_UNQUOTED(CPU_CACHE_LINE, $CPU_CACHE_LINE, [L2 cache line size])
AC_MSG_RESULT($CPU_CACHE_LINE)

dnl
dnl OS string
dnl
AC_ARG_ENABLE(os_string, AC_HELP_STRING([--enable-os-string=STR], [Set a customized OS type string]), [os_string="$enableval"])
AC_DEFINE_UNQUOTED(OS_TYPE, "${os_string}", [OS type])

AM_CONDITIONAL(PLATFORM_WIN32, test x"$os_string" = "xWin32")

dnl
dnl Tracing
dnl
AC_ARG_ENABLE(trace, AC_HELP_STRING([--enable-trace], [Enable trace facility]),
   [enable_trace="$enableval"
    AC_DEFINE(TRACE_ENABLED, 1, [Trace facility])
   ], [enable_trace="no"])

dnl
dnl Backtraces
dnl
AC_ARG_ENABLE(backtraces, AC_HELP_STRING([--enable-backtraces], [Enable backtraces on error]),
   [enable_backtraces="$enableval"
    AC_DEFINE(BACKTRACES_ENABLED, 1, [Backtracing facility])
   ], [enable_backtraces="no"])

dnl
dnl Dynamic library loading library
dnl
LIBS="$LIBS $libdl"
AC_DEFINE_UNQUOTED(SO_SUFFIX, "${so_suffix}", [Dynamic loading libraries extension])
AC_DEFINE_UNQUOTED(MOD_SUFFIX, "${mod_suffix}", [Dynamic modules extension])

dnl
dnl Libtool options
dnl
if test "$os_string" != "Win32"; then
    # libtool option to control which symbols are exported
    # right now, symbols starting with _ are not exported
    LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
else
    LIBTOOL_EXPORT_OPTIONS=
fi
AC_SUBST(LIBTOOL_EXPORT_OPTIONS)

dnl Set the Version
AM_INIT_AUTOMAKE(cherokee, $VERSION)
AM_MAINTAINER_MODE

AM_CONFIG_HEADER(config.h)
AC_SUBST(VERSION)

dnl Initialize Libtool
m4_ifdef([LT_INIT],
  [LT_INIT([dlopen shared static win32-dll])],
  [AC_LIBTOOL_DLOPEN
   AC_LIBTOOL_WIN32_DLL
   ])

dnl Paths
AC_PROG_CC
AC_PROG_CC_STDC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AM_PROG_LIBTOOL

AC_PATH_PROG(cherokeepath, cherokee)

AC_FUNC_CLOSEDIR_VOID
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_VPRINTF

AC_C_CONST
AC_C_BIGENDIAN
AC_C_INLINE
if test "$ac_cv_c_inline" != no; then
  AC_DEFINE(HAVE_INLINE, 1, [Compile supports inline])
fi

dnl
dnl Check for headers
dnl
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(endian.h machine/endian.h sys/machine.h sys/endian.h sys/isa_defs.h sys/utsname.h sys/poll.h poll.h )
AC_CHECK_HEADERS(sys/socket.h sys/un.h netinet/in.h arpa/inet.h netinet/tcp.h sys/ioctl.h fcntl.h sys/ofcntl.h sys/time.h)
AC_CHECK_HEADERS(sys/resource.h resource.h unistd.h syslog.h stdint.h inttypes.h error.h pwd.h sys/uio.h)
AC_CHECK_HEADERS(pthread.h netdb.h stdarg.h sys/filio.h sys/varargs.h sys/select.h sys/mman.h sys/uio.h grp.h winsock.h)
AC_CHECK_HEADERS(winsock.h winsock2.h sched.h execinfo.h)

AC_SYS_LARGEFILE

AC_SIZE_T
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_STRUCT_ST_RDEV
AC_CHECK_TYPE(ino_t, unsigned)
AC_CHECK_TYPE(loff_t, off_t)
AC_CHECK_TYPE(offset_t, loff_t)
AC_CHECK_TYPE(ssize_t, int)
AC_CHECK_TYPE(wchar_t, unsigned short)

AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(unsigned long long)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(off_t)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(sig_atomic_t)
AC_CHECK_SIZEOF(time_t)

AC_CACHE_CHECK([for long long],samba_cv_have_longlong,[
AC_TRY_RUN([#include <stdio.h>
main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }],
samba_cv_have_longlong=yes,samba_cv_have_longlong=no,samba_cv_have_longlong=cross)])
if test x"$samba_cv_have_longlong" = x"yes"; then
    AC_DEFINE(HAVE_LONGLONG,1,[Whether the host supports long long'])
fi

AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_FORK

AC_CHECK_FUNCS(gmtime gmtime_r localtime localtime_r getrlimit getdtablesize readdir readdir_r flockfile funlockfile strnstr backtrace random srandom srandomdev)

FW_CHECK_PWD
FW_CHECK_GRP

AC_CHECK_MEMBER(struct tm.tm_gmtoff,
                AC_DEFINE([HAVE_STRUCT_TM_GMTOFF],[1],[gmtoff in struct tm]),,[#include <time.h>])

AH_BOTTOM([
/* Give us an unsigned 32-bit data type. */
#if SIZEOF_UNSIGNED_LONG==4
#define UWORD32 unsigned long
#elif SIZEOF_UNSIGNED_INT==4
#define UWORD32 unsigned int
#else
#error I do not know what to use for a UWORD32.
#endif
])


dnl Find socket()
dnl Likely combinations:
dnl -lsocket [ -lnsl_s | -lnsl ]
dnl -linet
AC_CHECK_LIB(ws2_32, main)
AC_CHECK_LIB(advapi32, main)

AC_CHECK_FUNC(socket, :, [
AC_CHECK_LIB(socket, main)
AC_CHECK_LIB(net, main)
AC_CHECK_LIB(nsl_s, main)
AC_CHECK_LIB(nsl, main)
AC_CHECK_LIB(inet, socket)
AC_CHECK_LIB(gen, main)
])

AC_SEARCH_LIBS(accept, socket)
AC_SEARCH_LIBS(bind, socket)
AC_SEARCH_LIBS(listen, socket)
AC_SEARCH_LIBS(setsockopt, socket)

dnl
dnl Check for fd events inspect functions
dnl
AC_CHECK_FUNC(poll, have_poll=yes)
AC_CHECK_FUNC(kqueue, have_kqueue=yes)
AC_CHECK_FUNC(select, have_select=yes)

if test "x-$have_select" != "x-yes" -a "x-$ac_cv_header_winsock2_h" = "x-yes"; then
     AC_MSG_CHECKING([for select in ws2_32])
     AC_TRY_LINK([#include <winsock2.h>],
[select(0,0,0,0,0)],
[AC_MSG_RESULT(yes)
have_win32_select=yes],
[AC_MSG_RESULT(no)])
fi

dnl
dnl Epoll
dnl
AC_CHECK_HEADER(sys/epoll.h, have_epoll_include=yes, have_epoll_include=no)

AC_ARG_ENABLE(epoll, AC_HELP_STRING([--disable-epoll],[Disable epoll() support]),
wants_epoll="$enableval", wants_epoll="yes")

have_epoll=no
if test "x$have_epoll_include" = "xyes" && test "x$wants_epoll" = "xyes"; then
  AC_MSG_CHECKING(for epoll system call)

     AC_RUN_IFELSE([
#include <stdint.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/epoll.h>
#include <unistd.h>

int epoll_create (int size) {
return (syscall(__NR_epoll_create, size));
}

int main (int argc, char **argv) {
int epfd;
epfd = epoll_create(256);
exit (epfd == -1 ? 1 : 0);
}
],
have_epoll=yes,
have_epoll=no,
have_epoll=yes)
AC_MSG_RESULT($have_epoll)
fi

dnl
dnl Solaris 10: Event ports
dnl
AC_CHECK_HEADER(port.h, have_port_include=yes, have_port_include=no)

have_port=no
if test "x$have_port_include" = "xyes"; then
     AC_MSG_CHECKING(for event ports support)

     AC_RUN_IFELSE([
#include <stdint.h>
#include <unistd.h>
#include <port.h>

int main (int argc, char **argv) {
int port;
port = port_create();
exit (port < 0 ? 1 : 0);
}
],
have_port=yes,
have_port=no,
have_port=cross)
AC_MSG_RESULT($have_port)
fi



if test "$have_epoll" = yes; then
AC_DEFINE(HAVE_EPOLL, 1, [Have epoll])
fi
AM_CONDITIONAL(COMPILE_EPOLL, test x"$have_epoll" = "xyes")

if test "$have_kqueue" = yes; then
AC_DEFINE(HAVE_KQUEUE, 1, [Have kqueue])
fi
AM_CONDITIONAL(COMPILE_KQUEUE, test x"$have_kqueue" = "xyes")

if test "$have_port" = yes; then
AC_DEFINE(HAVE_PORT, 1, [Have event ports])
fi
AM_CONDITIONAL(COMPILE_PORT, test x"$have_port" = "xyes")

if test "$have_poll" = yes; then
AC_DEFINE(HAVE_POLL, 1, [Have poll])
fi
AM_CONDITIONAL(COMPILE_POLL, test x"$have_poll" = "xyes")

if test "$have_win32_select" = yes; then
AC_DEFINE(HAVE_WIN32_SELECT, 1, [Have Win32 select])
fi
AM_CONDITIONAL(COMPILE_WIN32_SELECT, test x"$have_win32_select" = "xyes")

if test "$have_select" = yes; then
     AC_DEFINE(HAVE_SELECT, 1, [Have select])
fi
AM_CONDITIONAL(COMPILE_SELECT, test x"$have_select" = "xyes" -a x"$have_win32_select" != "xyes")


dnl
dnl Check for inet_pton. We have our own, but on Solaris the version in
dnl libresolv is more lenient in ways that Solaris's internal DNS resolution
dnl code requires, so if we use our own *and* link with libresolv (which may
dnl be forced by Perl) DNS resolution fails.
dnl
AC_SEARCH_LIBS(inet_pton, [socket nsl resolv])
AC_CHECK_FUNCS(inet_pton inet_ntop inet_addr)

AC_SEARCH_LIBS(gethostbyname, [socket nsl resolv])
AC_CHECK_FUNCS(gethostbyname gethostbyname_r)

AC_CHECK_HEADER(sys/utsname.h)
AC_CHECK_FUNCS(gethostname uname)

dnl
dnl Check for inet_addr
dnl
AC_SEARCH_LIBS(inet_addr, xnet)
AC_CHECK_FUNCS(inet_addr)

dnl
dnl TCP_CORK
dnl
HYDRA_TCP_CORK
HYDRA_TCP_NOPUSH

dnl
dnl Check for GNU getopt_long()
dnl
AC_CHECK_HEADERS(getopt.h)
AC_CHECK_FUNC(getopt_long, have_getopt_long="yes")
AM_CONDITIONAL(HAVE_GETOPT_LONG, test "x$have_getopt_long" = "xyes")


dnl
dnl Pthread
dnl
with_pthread="yes"
have_pthread="no"
AC_ARG_ENABLE(pthread, AC_HELP_STRING([--disable-pthread],[Disable threading support]),
with_pthread="$enableval", with_pthread="yes")

AM_CONDITIONAL(USE_PTHREAD, test "x$with_pthread" = "xyes")
if test "x$with_pthread" = "xyes"
then
dnl
     dnl Basic checkings (c&p'ed from squid)
dnl
AC_MSG_CHECKING([for special a pthread case])

oldcflags="$CFLAGS"
     CFLAGS="$CFLAGS -D_REENTRANT"
PTHREAD_CFLAGS="-D_REENTRANT"

case "$host" in
     i386-unknown-freebsd*)
           if test "$GCC" = "yes" ; then
              if test -z "$PRESET_LDFLAGS"; then
                PTHREAD_LIBS="-pthread"
have_pthread="yes"
              fi
           fi
AC_MSG_RESULT([-pthread])
           ;;
       *-solaris2.*)
           if test "$GCC" = "yes" ; then
              CFLAGS="$CFLAGS -pthreads"
              PTHREAD_CFLAGS="-pthreads"
AC_MSG_RESULT([-pthreads])
           else
              CFLAGS="$CFLAGS -mt"
              PTHREAD_CFLAGS="-mt"
AC_MSG_RESULT([-mt])
           fi
have_pthread="yes"
           ;;
*)
AC_MSG_RESULT([no])
  ;;
     esac

if test "$have_pthread" != "yes"; then
        AC_CHECK_LIB(pthread, main, have_pthread=yes, have_pthread=no)
if test "$have_pthread" = "yes"; then
PTHREAD_LIBS="-lpthread"
fi
     fi

dnl
dnl More detailed checks on the pthread support
dnl
AC_MSG_CHECKING([for pthread_rwlock_t support])

have_pthread_rwlock_t=yes
AC_TRY_COMPILE([#include <pthread.h>],
[pthread_rwlock_t rwlock; pthread_rwlock_init( &rwlock, NULL);],
compiled=yes, compiled=no)

if test "$compiled" = "yes"; then
AC_MSG_RESULT([ok])
else
dnl Didn't find rwlock_t.
dnl Try defining _XOPEN_SOURCE=500
dnl
oldcflags2="$CFLAGS"
CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500"

AC_TRY_COMPILE([#include <pthread.h>],
[pthread_rwlock_t rwlock; pthread_rwlock_init( &rwlock, NULL);],
compiled=yes, compiled=no)

if test "$compiled" = "yes"; then
AC_MSG_RESULT([-D_XOPEN_SOURCE=500])
PTHREAD_CFLAGS="-D_XOPEN_SOURCE=500"
else
have_pthread_rwlock_t=no
AC_MSG_RESULT([no])
fi

CFLAGS="$oldcflags2"
fi

if test "$have_pthread_rwlock_t" = "yes"; then
AC_DEFINE(HAVE_PTHREAD_RWLOCK_T, 1, [Define if your pthread library includes pthread_rwlock_t])
else
AC_MSG_ERROR([pthread_rwlock_t support missing])
fi

AC_CHECK_FUNC(pthread_attr_setschedpolicy, have_pthread_attr_setschedpolicy=yes)
if test x"$have_pthread_attr_setschedpolicy" = "xyes"; then
AC_DEFINE(HAVE_PTHREAD_SETSCHEDPOLICY, 1, [Pthread support pthread_attr_setschedpolicy])
fi

save_LIBS="$LIBS"
LIBS="$LIBS $PTHREAD_LIBS"

AC_CHECK_FUNCS(pthread_mutexattr_settype pthread_mutexattr_setkind_np)

dnl
dnl Yield
dnl
AC_CHECK_FUNCS(sched_yield, , [
AC_CHECK_LIB(rt, sched_yield, [
AC_DEFINE(HAVE_SCHED_YIELD)
PTHREAD_LIBS="$PTHREAD_LIBS -lrt"
],[
AC_CHECK_LIB(posix4, sched_yield, [
AC_DEFINE(HAVE_SCHED_YIELD)
       PTHREAD_LIBS="$PTHREAD_LIBS -lposix4"
    ])])
     ])

LIBS="$save_LIBS"
CFLAGS="$oldcflags"
fi

if test "$have_pthread" = "yes"; then
AC_DEFINE(HAVE_PTHREAD, 1, [Have pthread support])
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_LIBS)
fi


dnl
dnl Is setenv() threadsafe?
dnl
if test "$setenv_is_threadsafe" = "yes"; then
AC_DEFINE(SETENV_IS_THREADSAFE, 1, [setenv function is thread safe])
fi

dnl
dnl Check for vsyslog
dnl
AC_CHECK_FUNCS(syslog vsyslog strsep strcasestr memmove strerror bcopy strlcat)

dnl
dnl Check for Glib (usually Linux)
dnl
AC_PREPROC_IFELSE([
#include <features.h>
#ifndef __GLIBC__
    chokeme
#endif
], [
    AC_DEFINE([HAVE_GLIBC], [1], [Define to 1 if you have glibc.])
    AC_DEFINE([_GNU_SOURCE], [1], [Define to 1 if you have glibc.])
])

dnl
dnl Does this platform require array notation to assign to a va_list?
dnl If cross-compiling, we assume va_list is "normal". If this breaks
dnl you, set ac_cv_valistisarray=true and maybe define HAVE_VA_LIST_AS_ARRAY
dnl also just to be sure.
dnl
AC_MSG_CHECKING(whether va_list assignments need array notation)
AC_CACHE_VAL(ac_cv_valistisarray,
        [AC_TRY_RUN([#include <stdlib.h>
#include <stdarg.h>
void foo(int i, ...) {
va_list ap1, ap2;
va_start(ap1, i);
ap2 = ap1;
if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); }
va_end(ap1); va_end(ap2);
}
int main()
{ foo(0, 123); return(0); }],
[ac_cv_valistisarray=false],
[ac_cv_valistisarray=true],
[ac_cv_valistisarray=false])])

if test "$ac_cv_valistisarray" = true ; then
AC_DEFINE(HAVE_VA_LIST_AS_ARRAY,,[va_list works copying an array])
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi


dnl
dnl Check if the global variable `timezone' exists. If so, define
dnl HAVE_INT_TIMEZONE.
dnl
AC_STRUCT_TIMEZONE

AC_MSG_CHECKING(for global timezone)
AC_TRY_LINK([#include <time.h>],
[int res; res = timezone / 60;],
[AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_INT_TIMEZONE,, [Set to 1 if you have the global variable timezone])],
AC_MSG_RESULT(no))


dnl
dnl Check for RTDL constants (from Haskell code)
dnl
dnl ** check for libdl & RTLD_NEXT
dnl ** sometimes RTLD_NEXT is hidden in #ifdefs we really don't wan to set
AC_MSG_CHECKING(for RTLD_NEXT from dlfcn.h)
AC_EGREP_CPP(yes,
[
 #include <dlfcn.h>
 #ifdef RTLD_NEXT
        yes
 #endif
], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_RTLDNEXT,,[Have RTDL_NEXT])
  HaveRtldNext=YES
], [
  AC_MSG_RESULT(no)
  HaveRtldNext=NO
  ])
AC_SUBST(HaveRtldNext)

dnl ** RTLD_LOCAL isn't available on cygwin or openbsd
AC_MSG_CHECKING(for RTLD_LOCAL from dlfcn.h)
AC_EGREP_CPP(yes,
[
 #include <dlfcn.h>
 #ifdef RTLD_LOCAL
        yes
 #endif
], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_RTLDLOCAL,,[Have RTDL_LOCAL])
  HaveRtldLocal=YES
], [
  AC_MSG_RESULT(no)
  HaveRtldLocal=NO
  ])
AC_SUBST(HaveRtldLocal)

dnl ** RTLD_GLOBAL isn't available on openbsd
AC_MSG_CHECKING(for RTLD_GLOBAL from dlfcn.h)
AC_EGREP_CPP(yes,
[
 #include <dlfcn.h>
 #ifdef RTLD_GLOBAL
        yes
 #endif
], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_RTLDGLOBAL,,[Have RTDL_GLOBAL])
  HaveRtldGlobal=YES
], [
  AC_MSG_RESULT(no)
  HaveRtldGlobal=NO
  ])
AC_SUBST(HaveRtldGlobal)

dnl ** RTLD_NOW isn't available on openbsd
AC_MSG_CHECKING(for RTLD_NOW from dlfcn.h)
AC_EGREP_CPP(yes,
[
 #include <dlfcn.h>
 #ifdef RTLD_NOW
        yes
 #endif
], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_RTLDNOW,,[Have RTDL_NOW])
  HaveRtldNow=YES
], [
  AC_MSG_RESULT(no)
  HaveRtldNow=NO
  ])
AC_SUBST(HaveRtldNow)


dnl
dnl Check of off64_t
dnl
AC_CACHE_CHECK([for off64_t],samba_cv_HAVE_OFF64_T,[
AC_TRY_RUN([
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include <stdio.h>
#include <sys/stat.h>
main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
samba_cv_HAVE_OFF64_T=yes,samba_cv_HAVE_OFF64_T=no,samba_cv_HAVE_OFF64_T=cross)])
if test x"$samba_cv_HAVE_OFF64_T" = x"yes"; then
    AC_DEFINE(HAVE_OFF64_T,1,[Whether off64_t is available])
fi


dnl
dnl SYSV Semaphores
dnl
AC_CHECK_HEADER(sys/sem.h, sysv_sem=yes, sysv_sem=no)

if test "x$sysv_sem" = "xyes"; then
   AC_CHECK_FUNC(semget, , sysv_sem=no)
   AC_CHECK_FUNC(semop, , sysv_sem=no)
   AC_CHECK_FUNC(semctl, , sysv_sem=no)
fi

if test "x$sysv_sem" = xyes; then
   AC_DEFINE(HAVE_SYSV_SEMAPHORES, 1, [Define to 1 to use SYSV semaphores])
fi
AM_CONDITIONAL(USE_SYSV_SEMAPHORES, test "x$sysv_sem" = xyes)

dnl union semun
dnl
AC_MSG_CHECKING([for union semun])
AC_CACHE_VAL(ac_cv_struct_semun, [
   AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>;
     ],[
union semun semdat;
],
ac_cv_struct_semun=yes,
ac_cv_struct_semun=no
     )
])
AC_MSG_RESULT($ac_cv_struct_semun)
if test "$ac_cv_struct_semun" = "yes"; then
AC_DEFINE(HAVE_SEMUN, 1, [Define if sys/sem.h defines struct semun])
fi


# From etr_socket_nsl.m4
ETR_SOCKET_NSL

# From sendfile_samba.m4
SENDFILE_CHECK

# readdir_r()
LIBWWW_READDIR_R_TYPE


dnl
dnl IPv6 Support
dnl I got this mostly from Apache's tests
dnl

AC_ARG_ENABLE(ipv6,
  AC_HELP_STRING([--disable-ipv6], [Disable IPv6 support]),
  [ if test "$enableval" = "no"; then
       disabled_ipv6=1
    fi ],
  [ disabled_ipv6=0 ] )

AC_SEARCH_LIBS(getaddrinfo, socket inet6)
AC_SEARCH_LIBS(getnameinfo, socket inet6)
AC_SEARCH_LIBS(gai_strerror, socket inet6)
AC_CHECK_FUNC(gai_strerror)

APR_CHECK_WORKING_GETADDRINFO
APR_CHECK_WORKING_GETNAMEINFO

AC_ACME_SOCKADDR_UN
AC_ACME_SOCKADDR_IN6
AC_ACME_SOCKADDR_STORAGE

AC_MSG_CHECKING(if the system supports IPv6)
have_ipv6="no"

if test "$disabled_ipv6" = 1; then
    AC_MSG_RESULT([no -- disabled by user])
else
    if test "x$ac_cv_acme_sockaddr_in6" = "xyes"; then
        if test "x$ac_cv_working_getaddrinfo" = "xyes"; then
            if test "x$ac_cv_working_getnameinfo" = "xyes"; then
                have_ipv6="yes"
                AC_MSG_RESULT([yes])
  AC_DEFINE(HAVE_IPV6, 1, [Define if you have IPv6 support.])
            else
                AC_MSG_RESULT([no -- no getnameinfo])
            fi
        else
            AC_MSG_RESULT([no -- no working getaddrinfo])
        fi
    else
        AC_MSG_RESULT([no -- no sockaddr_in6])
    fi
fi

dnl
dnl Test whether SO_RCVTIMEO is broken
dnl
AC_CACHE_CHECK([whether setsockopt(SO_RCVTIMEO) is broken],
  ac_cv_so_rcvtimeo_broken, [dnl
    AC_RUN_IFELSE([AC_LANG_SOURCE([[
#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_SOCKET_H)
#include <sys/socket.h>
#endif

#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif

int main(void) {
        int fd;
        int ret;
        struct timeval new_tv;

        /* Open the socket (INET/TCP).*/
        fd = socket(AF_INET, SOCK_STREAM, 0);

        /* set the timeout for the incoming queue */
        /* 1 second for example */
        new_tv.tv_sec = 1;
        new_tv.tv_usec = 0;

        ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &new_tv, sizeof(new_tv));
        return ret;
}
]])],[ac_cv_so_rcvtimeo_broken=no],[ac_cv_so_rcvtimeo_broken=yes],[ac_cv_so_rcvtimeo_broken=cross])])
if test x"$ac_cv_so_rcvtimeo_broken" = x"yes"; then
  AC_DEFINE(HAVE_BROKEN_SO_RCVTIMEO, 1, [Define if setsockopt(SO_RCVTIMEO) is broken])
fi


dnl
dnl Look for socklen_t
dnl
AC_MSG_CHECKING([for socklen_t])
AC_TRY_COMPILE(
 [#include <sys/types.h>
  #include <sys/socket.h>],
 [socklen_t len = 42; return 0;],
 ac_cv_type_socklen_t=yes,
 ac_cv_type_socklen_t=no
)

if test $ac_cv_type_socklen_t != yes; then
  AC_DEFINE(socklen_t, int, [Substitute for socklen_t])
  AC_MSG_RESULT(int)
else
  AC_MSG_RESULT(yes)
fi

dnl
dnl Check of __func__ and co..
dnl
AC_MSG_CHECKING([whether our compiler supports __func__])
AC_TRY_COMPILE([],
 [const char *cp = __func__;],
 AC_MSG_RESULT([yes]),
 AC_MSG_RESULT([no])
 AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
 AC_TRY_COMPILE([],
   [const char *cp = __FUNCTION__;],
   AC_MSG_RESULT([yes])
   AC_DEFINE(__func__, __FUNCTION__,
         [Define to appropriate substitue if compiler doesnt have __func__]),
   AC_MSG_RESULT([no])
   AC_DEFINE(__func__, __FILE__,
         [Define to appropriate substitue if compiler doesnt have __func__])))


dnl
dnl Temporal directory
dnl
AC_ARG_ENABLE(tmpdir, AC_HELP_STRING([--enable-tmpdir=DIR],[default directory for temporary files]))

AC_MSG_CHECKING(directory to use for temporary files)
if test -n "$enable_tmpdir"; then
        tmpdir="$enable_tmpdir"
elif test -n "$TMPDIR"; then
        tmpdir="$TMPDIR"
elif test -n "$TMP"; then
        tmpdir="$TMP"
elif test -n "$TEMP"; then
        tmpdir="$TEMP"
elif test -d "c:/"; then
        tmpdir="c:/"
else
        tmpdir="/tmp"
fi

dnl No temp dir
if ! test -d $tmpdir ; then
   AC_MSG_ERROR($tmpdir does not exist)
fi

dnl Handle MacOS X messy tmp dirs
case "$tmpdir" in
  /var/folders*)
     tmpdir='/tmp'
;;
esac

AC_MSG_RESULT($tmpdir)
AC_DEFINE_UNQUOTED(TMPDIR, "$tmpdir", [Temporal directory])


dnl
dnl Check for pcre library
dnl
have_pcre="built-in"

AC_ARG_ENABLE(internal_pcre,
AC_HELP_STRING([--enable-internal-pcre],[Enable internal PCRE]),
use_internal_pcre="$enableval", use_internal_pcre="no")

if test "x$use_internal_pcre" != "xyes"; then
  AC_CHECK_LIB(pcre, pcre_compile, have_pcre_lib=yes, have_pcre_lib=no)
  AC_CHECK_HEADER(pcre.h, have_pcre_include=yes, have_pcre_include=no)
  if test "$have_pcre_lib $have_pcre_include" = "yes yes"; then
     have_pcre="yes"
  fi
fi

AM_CONDITIONAL(USE_INTERNAL_PCRE, test "x$have_pcre" = "xbuilt-in")

dnl
dnl PAM
dnl
AC_ARG_ENABLE(pam, AC_HELP_STRING([--disable-pam],[Disable PAM support]), use_pam="$enableval", use_pam="yes")
if test "x$use_pam" = "xyes"; then
     AC_CHECK_LIB(pam, pam_start, have_pam_lib=yes, have_pam_lib=no)
     AC_CHECK_LIB(pam, _pam_dispatch, have_pam_dispatch=yes, have_pam_dispatch=no)
     AC_CHECK_HEADER(security/pam_modules.h, have_pam_include=yes, have_pam_include=no, [[
#ifdef HAVE_SECURITY_PAM_MODULES_H
# include <security/pam_modules.h>
#endif
]])
     AC_CHECK_HEADERS(security/_pam_macros.h security/pam_appl.h)
fi

if test "$use_pam $have_pam_lib $have_pam_include" = "yes yes yes"; then
   have_pam="yes"
else
   have_pam="no"
fi
AM_CONDITIONAL(HAVE_PAM, test "x$have_pam" = "xyes")

if test "$have_pam_dispatch" = "yes"; then
AC_DEFINE(HAVE_PAM_DISPATCH, 1, [Have _pam_dispatch function])
fi

dnl
dnl crypt()
dnl
AC_CHECK_HEADERS(crypt.h)

AC_CHECK_FUNC(crypt, system_crypt="yes", system_crypt="no")
AC_CHECK_LIB(crypt, crypt, have_crypt_lib="yes", have_crypt_lib="no")
if test "x$have_crypt_lib" = "xyes"; then
CRYPT_LIBS="-lcrypt"
AC_SUBST(CRYPT_LIBS)
fi

use_crypt="no"
if test "$system_crypt $have_crypt_lib" != "no no"; then
   use_crypt="yes"
   AC_DEFINE(HAVE_CRYPT, 1, [Have crypt function])
fi

dnl
dnl crypt_r()
dnl
AC_CHECK_FUNC(crypt_r, system_crypt_r="yes", system_crypt_r="no")
AC_CHECK_LIB(crypt, crypt_r, have_crypt_r_lib="yes", have_crypt_r_lib="no")

use_crypt_r="no"
if test "$system_crypt_r $have_crypt_r_lib" != "no no"; then
   use_crypt_r="yes"
   AC_DEFINE(HAVE_CRYPT_R, 1, [Have crypt_r function])
fi

dnl
dnl crypt_r and pthread
dnl
if test "$use_crypt_r" = "yes"; then
   dnl
   dnl crypt_r style
   dnl
   AC_MSG_CHECKING([crypt_r style])
   crypt_r_style=none

   # pthread.h is needed on AIX
   AC_TRY_COMPILE([#include <pthread.h>
                   #include <crypt.h>],
    [CRYPTD buffer;],
crypt_r_style=cryptd)

   if test "$crypt_r_style" = "none"; then
      AC_TRY_COMPILE([#include <crypt.h>],
[struct crypt_data buffer;],
crypt_r_style=struct_crypt_data)
   fi

   if test "$crypt_r_style" = "none"; then
      AC_TRY_COMPILE([#define _GNU_SOURCE
#include <crypt.h>],
[struct crypt_data buffer;],
[crypt_r_style=struct_crypt_data
CRYPT_CFLAGS="-D_GNU_SOURCE"
AC_SUBST(CRYPT_CFLAGS)])
   fi

   AC_MSG_RESULT([$crypt_r_style])

   if test "$crypt_r_style" = "cryptd"; then
     AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
   fi

   if test "$crypt_r_style" = "struct_crypt_data"; then
     AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
   fi

   if test "$crypt_r_style" = "none"; then
     AC_MSG_ERROR([Unable to detect data struct is used by crypt_r])
   fi
fi

AM_CONDITIONAL(USE_CRYPT, test "x$use_crypt x$use_crypt_r" != "xno xno")


dnl
dnl OpenSSL
dnl
AC_ARG_WITH(libssl,
    AC_HELP_STRING([--with-libssl@<:@=DIR@:>@],[Include libssl/OpenSSL support (default yes)]),
    [WITH_OPENSSL=$withval],[WITH_OPENSSL=yes])

have_openssl=no

if test "$WITH_OPENSSL" != "no"; then
    if test "$WITH_OPENSSL" != "yes"; then
        LIBSSL_CFLAGS="-I$WITH_OPENSSL/include"
        LIBSSL_LIBS="-L$WITH_OPENSSL/lib"
    fi

    AC_CHECK_LIB(crypto, BN_init)
    AC_CHECK_HEADERS([openssl/engine.h])
    AC_CHECK_LIB(ssl, SSL_accept, [have_openssl=yes], [have_openssl=no], $LIBSSL_LIBS)

    if test "$have_openssl" = "yes"; then
        LIBSSL_LIBS="$LIBSSL_LIBS -lssl"

AC_SUBST(LIBSSL_LIBS)
AC_SUBST(LIBSSL_CFLAGS)

AC_DEFINE(HAVE_OPENSSL, 1, [Have OpenSSL library])
    fi
fi
AC_MSG_CHECKING(for libssl)
AC_MSG_RESULT([$have_openssl])

AM_CONDITIONAL(USE_OPENSSL, test "x$have_openssl" = "xyes")


dnl
dnl Native Language Support
dnl
AM_PO_SUBDIRS

if test "x$USE_NLS" = "xyes"; then
   AC_CHECK_PROG(HAVE_MSGFMT, msgfmt,yes,no)

   if test "x$HAVE_MSGFMT" = "xno"; then
      AC_MSG_ERROR([msgfmt not found. You need to install the 'gettext' package, or pass --enable-nls=no to configure.])
   fi
fi

AM_CONDITIONAL(NLS_ENABLED, test "x$USE_NLS" = "xyes")
AC_CONFIG_FILES([po/admin/Makefile.in])

dnl
dnl LDAP
dnl
AC_ARG_WITH([ldap],
        AC_HELP_STRING([--with-ldap=@<:@ARG@:>@],
            [use OpenLDAP development library @<:@default=yes@:>@, optionally specify path to dev libs]
        ),
        [
        if test "$withval" = "no"; then
            want_ldap="no"
        elif test "$withval" = "yes"; then
            want_ldap="yes"
        else
            want_ldap="yes"
            LDAP_CONFIG="$withval"
        fi
        ],
        [want_ldap="yes"]
)

if test "$want_ldap" = "yes"; then
       AC_CHECK_LIB(ldap, ldap_init, have_ldap_lib=yes, have_ldap_lib=no)
       AC_CHECK_HEADER(ldap.h, have_ldap_include=yes, have_ldap_include=no)

AC_CHECK_LIB(ldap, ldap_start_tls_s, [
AC_DEFINE(LDAP_HAVE_START_TLS_S,, Define if you have ldap_start_tls_s)
   ])

       if test "$have_ldap_lib $have_ldap_include" = "yes yes"; then
          have_ldap="yes"
       else
          have_ldap="no"
       fi
else
       have_ldap="no"
fi

AM_CONDITIONAL(HAVE_LDAP, test "x$have_ldap" = "xyes")


dnl
dnl Check for MySQL: Execution of a string containing multiple
dnl statements was introduced in the MySQL release 5.0.0
dnl
AX_LIB_MYSQL(5.0.0)


dnl
dnl GeoIP library
dnl
AC_ARG_WITH([geoip],
        AC_HELP_STRING([--with-geoip=@<:@ARG@:>@],
            [use the GeoIP library @<:@default=yes@:>@, optionally specify path to dev libs]
        ),
        [
        if test "$withval" = "no"; then
            want_geoip="no"
        elif test "$withval" = "yes"; then
            want_geoip="yes"
        else
            want_geoip="yes"
CPPFLAGS="${CPPFLAGS} -I${withval}/include"
LDFLAGS="-L${withval}/lib ${LDFLAGS}"
        fi
        ],
        [want_geoip="yes"]
)

if test "x$want_geoip" = "xyes"; then
   AC_CHECK_LIB(GeoIP, GeoIP_new, have_geoip_lib=yes, have_geoip_lib=no)
   AC_CHECK_HEADERS(GeoIP.h, have_geoip_include=yes, have_geoip_include=no)
fi

have_geoip="no"
if test "$have_geoip_lib $have_geoip_include" = "yes yes"; then
   have_geoip="yes"
fi

AM_CONDITIONAL(HAVE_GEOIP, test "x$have_geoip" = "xyes")


dnl
dnl FFMpeg library
dnl
AC_ARG_WITH([ffmpeg],
        AC_HELP_STRING([--with-ffmpeg=@<:@ARG@:>@],
            [use the FFMpeg library @<:@default=yes@:>@, optionally specify path to dev libs]
        ),
        [
        if test "$withval" = "no"; then
            want_ffmpeg="no"
        elif test "$withval" = "yes"; then
            want_ffmpeg="yes"
        else
            want_ffmpeg="yes"
            FFMPEG_CONFIG="$withval"
        fi
        ],
        [want_ffmpeg="yes"]
)

if test "x$want_ffmpeg" = "xyes"; then
   AC_CHECK_LIB([avformat], [main], [
FFMPEG_LIBS="-lavformat -lavcodec -lavutil"
    have_ffmpeg_lib=yes
   ],[have_ffmpeg_lib=no])

   AC_CHECK_LIB([bz2], [BZ2_bzdopen], [
FFMPEG_LIBS="$FFMPEG_LIBS -lbz2"
   ])

   AC_CHECK_LIB([m], [cos], [
FFMPEG_LIBS="$FFMPEG_LIBS -lm"
   ])

   AC_CHECK_HEADERS([libavformat/avformat.h], [
      have_ffmpeg_include=yes
   ],[have_ffmpeg_include=no])
fi

have_ffmpeg="no"
if test "$have_ffmpeg_lib $have_ffmpeg_include" = "yes yes"; then
   have_ffmpeg="yes"
   AC_SUBST(FFMPEG_LIBS)
   AC_SUBST(FFMPEG_CFLAGS)
   AC_DEFINE([USE_FFMPEG], 1, [Whether to use FFMpeg])
fi

AM_CONDITIONAL(HAVE_FFMPEG, test "x$have_ffmpeg" = "xyes")


dnl
dnl WWW root directory, and user/group
dnl
AC_ARG_WITH(wwwroot, AC_HELP_STRING([--with-wwwroot=DIR], [Set the WWW root directory]),
WWW_ROOT="$withval", [
   dnl MacOS X
   if test -d "/Library/WebServer/Documents"; then
WWW_ROOT="/Library/WebServer/Documents"
   dnl Some Linux
   elif test -d "/srv/www/htdocs"; then
WWW_ROOT="/srv/www/htdocs"
   dnl Default
   else
WWW_ROOT="$localstatedir/www"
   fi
])
AC_SUBST(WWW_ROOT)

AC_ARG_WITH(cgiroot, AC_HELP_STRING([--with-cgiroot=DIR], [Set the CGI directory]),
CGI_ROOT="$withval", [
   dnl MacOS X
   if test -d "/Library/WebServer/CGI-Executables"; then
CGI_ROOT="/Library/WebServer/CGI-Executables"
   dnl Some Linux
   elif test -d "/srv/www/cgi-bin"; then
CGI_ROOT="/srv/www/cgi-bin"
   dnl Default
   else
CGI_ROOT="$prefix/lib/cgi-bin"
   fi
])
AC_SUBST(CGI_ROOT)

AC_ARG_WITH(wwwuser, AC_HELP_STRING([--with-wwwuser=USER], [Set default execution user]),
WWW_USER="$withval", WWW_USER="")
AC_SUBST(WWW_USER)

AC_ARG_WITH(wwwgroup, AC_HELP_STRING([--with-wwwgroup=GROUP], [Set default execution group]),
WWW_GROUP="$withval", WWW_GROUP="")
AC_SUBST(WWW_GROUP)


dnl
dnl PHP fcgi
dnl
AC_ARG_WITH(php, AC_HELP_STRING([--with-php=/path/to/php], [Path to php-fpm or php-cgi]),
PHPCGI="$withval", PHPCGI="")

dnl If no php, try to find it
if test "x$PHPCGI" = "x"; then
  for bin in php-fpm php-cgi php; do
    for p in /usr/lib/cgi-bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /opt/local/sbin /opt/local/bin /usr/gnu/sbin /usr/gnu/bin; do
if test -x "$p/$bin"; then
        PHPCGI="$p/$bin"
        break
fi
    done
    if test "x$PHPCGI" != x; then
break
    fi
  done
fi

dnl Try in the $PATH
if test "x$PHPCGI" = "x"; then
   AC_PATH_PROGS(PHPCGI, [php-fpm php-cgi])
fi

dnl Last, desperate option
if test "x$PHPCGI" = "x"; then
   PHPCGI="php-cgi"
fi

AC_SUBST(PHPCGI)

dnl Ensures it support FastCGI
AC_MSG_CHECKING([$PHPCGI supports FastCGI])
if test "x$PHPCGI" = "x"; then
   AC_MSG_RESULT([no])
else
   $PHPCGI -v -d session.save_path=/tmp | grep 'fcgi' >/dev/null 2>/dev/null
   if test $? != 0; then
      PHPCGI=""
      AC_MSG_RESULT([no, use --with-php])
   else
      AC_MSG_RESULT([yes])
   fi
fi

dnl
dnl Python
dnl
wants_admin="yes"
have_python="yes"

AC_ARG_WITH([python], AC_HELP_STRING([--with-python=/path/to/python],[Path to Python interpreter]),
PYTHON="$withval",
[
   AC_PATH_PROGS(PYTHON, python python2 python2.7 python2.6 python2.5 python2.4)
])

if test "x$PYTHON" != "x"; then
   AC_MSG_CHECKING([Python 2.x interpreter])
   v=`$PYTHON -c 'import sys; print (sys.version_info[[0]])'`
   if test "x$v" != "x2"; then
     have_python="no"
     wants_admin="no"
AC_MSG_RESULT([no])
AC_MSG_WARN([
*** Cherokee-admin requires Python 2.x. Please, use the --with-python
*** parameter to specify a Python 2.4, 2.5, 2.6 or 2.7 interpreter.
*** BEWARE: Cherokee-admin support has been disabled.])
   else
     AC_MSG_RESULT([yes])
   fi
else
    have_python="no"
    wants_admin="no"
    AC_MSG_WARN([
*** Python must be installed on your system but python interpreter couldn't
*** be found in path. Please check that python is in path, or install it.
*** BEWARE: Cherokee-admin support has been disabled.])
fi

dnl
dnl Cherokee admin
dnl
if test "x$wants_admin" = "xyes"; then
   AC_ARG_ENABLE(admin,
AC_HELP_STRING([--disable-admin],[Disable Cherokee-admin installation]),
wants_admin="$enableval", wants_admin="yes")
fi
AM_CONDITIONAL(INSTALL_ADMIN, test "x$wants_admin" != "xno")

dnl
dnl Clean files generated from *.pre
dnl
pres="constants.h cherokee.conf.sample performance.conf.sample http-cherokee.xml admin/configured.py contrib/cherokee"

AC_MSG_NOTICE([Deleting .pre files])
rm -f $pres

dnl
dnl Options
dnl
use_static_module=""
AC_ARG_ENABLE(static-module,
AC_HELP_STRING([--enable-static-module=MODULE][]),
[use_static_module="$use_static_module $enableval "],[])

modules="error_redir error_nn server_info file dirlist cgi fcgi scgi uwsgi proxy redir common ssi secdownload empty_gif drop admin custom_error dbslayer streaming gzip deflate ncsa combined custom pam ldap mysql htpasswd plain htdigest authlist round_robin ip_hash failover directory extensions request header exists fullpath method from bind tls geoip url_arg v_or wildcard rehost target_ip evhost post_track post_report libssl render_rrd rrd not and or"

# Remove modules that will not be compiles
#
if test "x$have_pam" != "xyes"; then
modules=`echo $modules | sed s/pam//`
fi
if test "x$have_ldap" != "xyes"; then
modules=`echo $modules | sed s/ldap//`
fi
if test "x$have_mysql" != "xyes"; then
modules=`echo $modules | sed s/mysql//`
modules=`echo $modules | sed s/dbslayer//`
fi
if test "x$have_geoip" != "xyes"; then
modules=`echo $modules | sed s/geoip//`
fi
if test "$use_crypt" != "yes"; then
modules=`echo $modules | sed s/htpasswd//`
fi
if test "$have_openssl" != "yes"; then
modules=`echo $modules | sed s/libssl//`
fi
if test "x$have_ffmpeg" != "xyes"; then
modules=`echo $modules | sed s/streaming//`
fi

add_calls=""
init_calls=""
headers=""
ext_defs=""

for mod in $modules; do
AC_MSG_CHECKING([module "$mod"])

if echo $use_static_module | grep -w $mod >/dev/null || echo $use_static_module | grep all >/dev/null; then
ext_defs="$ext_defs \n extern cherokee_plugin_info_t cherokee_${mod}_info;"

headers="$headers \n void PLUGIN_INIT_NAME($mod) (cherokee_plugin_loader_t *loader);"
add_calls="$add_calls \n add_static_entry (loader, \"$mod\", PLUGIN_INFO_PTR($mod));"
init_calls="$init_calls \n PLUGIN_INIT_NAME($mod)(loader);"

AC_MSG_RESULT([static])
else
AC_MSG_RESULT([dynamic])
fi
done

AC_MSG_CHECKING([loader.autoconf files])
mkdir cherokee 2>/dev/null
printf "$ext_defs\n" > cherokee/loader.autoconf.h
printf "$headers \n\n $add_calls \n\n $init_calls\n" > cherokee/loader.autoconf.inc
AC_MSG_RESULT([done])

dnl
dnl Static/Dynamic modules
dnl
conf_h="cherokee/loader.autoconf.h"
AM_CONDITIONAL(STATIC_HANDLER_SERVER_INFO, grep server_info $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_FILE, grep file $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_ADMIN, grep admin $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_DIRLIST, grep dirlist $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_CGI, grep cgi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_FCGI, grep fcgi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_SCGI, grep scgi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_UWSGI, grep uwsgi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_REDIR, grep redir $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_ERROR_REDIR, grep error_redir $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_ERROR_NN, grep error_nn $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_COMMON, grep common $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_CGI, grep cgi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_PROXY, grep proxy $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_SSI, grep ssi $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_SECDOWNLOAD, grep secdownload $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_EMPTY_GIF, grep empty_gif $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_DROP, grep drop $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_CUSTOM_ERROR, grep custom_error $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_DBSLAYER, grep dbslayer $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_STREAMING, grep streaming $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_RENDER_RRD, grep render_rrd $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_ENCODER_GZIP, grep gzip $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_ENCODER_DEFLATE, grep deflate $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_LOGGER_NCSA, grep ncsa $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_LOGGER_COMBINED, grep combined $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_LOGGER_CUSTOM, grep custom $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_PAM, grep pam $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_LDAP, grep ldap $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_MYSQL, grep mysql $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_HTPASSWD, grep htpasswd $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_PLAIN, grep plain $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_HTDIGEST, grep htdigest $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VALIDATOR_AUTHLIST, grep authlist $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_BALANCER_ROUND_ROBIN, grep round_robin $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_BALANCER_IP_HASH, grep ip_hash $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_BALANCER_FAILOVER, grep failover $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_CRYPTOR_LIBSSL, grep libssl $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_DIRECTORY, grep directory $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_EXTENSIONS, grep extensions $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_REQUEST, grep request $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_HEADER, grep header $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_EXISTS, grep exists $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_FULL_PATH, grep fullpath $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_BIND, grep bind $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_TLS, grep tls $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_METHOD, grep method $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_FROM, grep from $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_GEOIP, grep geoip $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_URL_ARG, grep url_arg $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VRULE_OR, grep v_or $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VRULE_WILDCARD, grep wildcard $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VRULE_REHOST, grep rehost $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_VRULE_TARGET_IP, grep target_ip $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_GEN_EVHOST, grep evhost $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_POST_TRACK, grep post_track $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_POST_REPORT, grep post_report $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_COLLECTOR_RRD, grep rrd $conf_h >/dev/null)
# These must be at the end
AM_CONDITIONAL(STATIC_RULE_NOT, grep _not_ $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_AND, grep _and_ $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_OR, grep _or_ $conf_h >/dev/null)

AC_OUTPUT([
Makefile
cget/Makefile
cherokee-config
cherokee.pc
cherokee.spec
org.cherokee.webserver.plist
cherokee/Makefile
contrib/Makefile
icons/Makefile
m4/Makefile
qa/Makefile
doc/Makefile
themes/Makefile
themes/default/Makefile
themes/firefox3/Makefile
themes/white/Makefile
themes/plain/Makefile
packages/Makefile
packages/osx/Makefile
packages/osx/Info.plist
packages/osx/Description.plist
packages/windows/Makefile
packages/windows/cherokee.nsi
www/Makefile
dbslayer/Makefile
admin/Makefile
admin/icons/Makefile
admin/market/Makefile
admin/plugins/Makefile
admin/wizards/Makefile
admin/static/Makefile
admin/static/js/Makefile
admin/static/css/Makefile
admin/static/images/Makefile
admin/static/images/flags/Makefile
admin/static/images/wizards/Makefile
admin/static/images/other/Makefile
admin/CTK/Makefile
admin/CTK/CTK/Makefile
admin/CTK/static/css/Makefile
admin/CTK/static/images/Makefile
admin/CTK/static/js/Makefile
admin/CTK/static/Makefile
po/Makefile
])


methods=""
if test "$have_epoll" = yes; then methods="${methods}epoll "; fi
if test "$have_kqueue" = yes; then methods="${methods}kqueue "; fi
if test "$have_poll" = yes; then methods="${methods}poll "; fi
if test "$have_port" = yes; then methods="${methods}port "; fi
if test "$have_win32_select" = yes; then methods="${methods}win32 "; fi
if test "$have_select" = yes; then methods="${methods}select"; fi

if test "$use_crypt_r" = "yes"; then
crypt_type="multithread"
elif test "$use_crypt" = "yes"; then
crypt_type="single thread"
else
crypt_type="no"
fi

echo
echo ============================
echo "Install prefix $prefix"
echo "CFLAGS $CFLAGS"
echo "trace $enable_trace"
echo "backtracing $enable_backtraces"
echo "sendfile() $with_sendfile_support"
echo "IPv6 support $have_ipv6"
i=1
for m in $methods; do
echo "Polling method $i $m"
i=`expr $i + 1`
done
echo "Threading support $have_pthread"
echo "OpenSSL support $have_openssl"
echo "PCRE library $have_pcre"
echo "Compatible PAM $have_pam"
echo "Python $have_python"
echo "LDAP $have_ldap"
echo "MySQL $have_mysql"
echo "GeoIP $have_geoip"
echo "FFMpeg $have_ffmpeg"
echo "crypt support $crypt_type"
if test "x$is_beta" = "xyes"; then
echo "Beta release $PACKAGE_PATCH_VERSION"
fi
echo
eval eval echo "Installation dir $bindir"
echo ============================
echo
if test "x$cherokeepath" != "x" ; then
echo Warning: You have an old copy of Cherokee at $cherokeepath.
echo
fi

cat <<THEEND
+------------------------------------------------------------------+
| License: |
| This software is subject to the GPL License, available in this |
| distribution in the file COPYING. Please, remember that any copy |
| distribution or modification of the software is subject to it. |
+------------------------------------------------------------------+

Thank you for using Cherokee.
THEEND
Something went wrong with that request. Please try again.