configure.in 82.2 KB
Newer Older
powelld's avatar
powelld committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
fi

dnl ----------------------------- Checking for fdatasync: OS X doesn't have it
AC_CHECK_FUNCS(fdatasync)

dnl ----------------------------- Checking for extended file descriptor handling
# test for epoll_create1
AC_CACHE_CHECK([for epoll_create1 support], [apr_cv_epoll_create1],
[AC_TRY_RUN([
#include <sys/epoll.h>
#include <unistd.h>

int main()
{
    return epoll_create1(0) == -1;
}], [apr_cv_epoll_create1=yes], [apr_cv_epoll_create1=no], [apr_cv_epoll_create1=no])])

if test "$apr_cv_epoll_create1" = "yes"; then
   AC_DEFINE([HAVE_EPOLL_CREATE1], 1, [Define if epoll_create1 function is supported])
fi

# Check for z/OS async i/o support.  
AC_CACHE_CHECK([for asio -> message queue support], [apr_cv_aio_msgq],
[AC_TRY_RUN([
#define _AIO_OS390
#include <aio.h>

int main()
{
    struct aiocb a;

    a.aio_notifytype = AIO_MSGQ;  /* use IPC message queue for notification */

    return aio_cancel(2, NULL) == -1;
}], [apr_cv_aio_msgq=yes], [apr_cv_aio_msgq=no], [apr_cv_aio_msgq=no])])

if test "$apr_cv_aio_msgq" = "yes"; then
   AC_DEFINE([HAVE_AIO_MSGQ], 1, [Define if async i/o supports message q's])
fi

# test for dup3
AC_CACHE_CHECK([for dup3 support], [apr_cv_dup3],
[AC_TRY_RUN([
#include <unistd.h>

int main()
{
    return dup3(STDOUT_FILENO, STDERR_FILENO, 0) == -1;
}], [apr_cv_dup3=yes], [apr_cv_dup3=no], [apr_cv_dup3=no])])

if test "$apr_cv_dup3" = "yes"; then
   AC_DEFINE([HAVE_DUP3], 1, [Define if dup3 function is supported])
fi

# test for accept4
AC_CACHE_CHECK([for accept4 support], [apr_cv_accept4],
[AC_TRY_RUN([
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>

#define A4_SOCK "./apr_accept4_test_socket"

int main()
{
    pid_t pid;
    int fd;
    struct sockaddr_un loc, rem;
    socklen_t rem_sz;

    if ((pid = fork())) {
        int status;

        unlink(A4_SOCK);

        if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
            goto cleanup_failure2;

        loc.sun_family = AF_UNIX;
        strncpy(loc.sun_path, A4_SOCK, sizeof(loc.sun_path) - 1);

        if (bind(fd, (struct sockaddr *) &loc,
                 sizeof(struct sockaddr_un)) == -1)
            goto cleanup_failure;

        if (listen(fd, 5) == -1)
            goto cleanup_failure;

        rem_sz = sizeof(struct sockaddr_un);
        if (accept4(fd, (struct sockaddr *) &rem, &rem_sz, 0) == -1) {
            goto cleanup_failure;
        }
        else {
            close(fd);
            waitpid(pid, &status, 0);
            unlink(A4_SOCK);
            return 0;
        }

cleanup_failure:
        close(fd);
cleanup_failure2:
        kill(pid, SIGKILL);
        waitpid(pid, &status, 0);
        unlink(A4_SOCK);
        return 1;
    }
    else {
        if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
            return 1; /* this will be bad: we'll hang */

        loc.sun_family = AF_UNIX;
        strncpy(loc.sun_path, A4_SOCK, sizeof(loc.sun_path) - 1);

        while(connect(fd, (struct sockaddr *) &loc,
                      sizeof(struct sockaddr_un)) == -1 &&
              (errno==ENOENT || errno==ECONNREFUSED))
            ;

        close(fd);
        return 0;
    }
}], [apr_cv_accept4=yes], [apr_cv_accept4=no], [apr_cv_accept4=no])])

if test "$apr_cv_accept4" = "yes"; then
   AC_DEFINE([HAVE_ACCEPT4], 1, [Define if accept4 function is supported])
fi

AC_CACHE_CHECK([for SOCK_CLOEXEC support], [apr_cv_sock_cloexec],
[AC_TRY_RUN([
#include <sys/types.h>
#include <sys/socket.h>

int main()
{
    return socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0) == -1;
}], [apr_cv_sock_cloexec=yes], [apr_cv_sock_cloexec=no], [apr_cv_sock_cloexec=no])])

if test "$apr_cv_sock_cloexec" = "yes"; then
   AC_DEFINE([HAVE_SOCK_CLOEXEC], 1, [Define if the SOCK_CLOEXEC flag is supported])
fi

dnl ----------------------------- Checking for missing POSIX thread functions
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])

dnl ----------------------------- Checking for Shared Memory Support 
echo "${nl}Checking for Shared Memory Support..."

# The real-time POSIX extensions (e.g. shm_*, sem_*) may only
# be available if linking against librt.
AC_SEARCH_LIBS(shm_open, rt)

case $host in
 *-sysv*)
   ac_includes_default="$ac_includes_default
#if HAVE_SYS_MUTEX_H /* needed to define lock_t for sys/shm.h */
# include <sys/mutex.h>
#endif";;
esac

AC_CHECK_HEADERS([sys/types.h sys/mman.h sys/ipc.h sys/mutex.h sys/shm.h sys/file.h kernel/OS.h os2.h windows.h])
AC_CHECK_FUNCS([mmap munmap shm_open shm_unlink shmget shmat shmdt shmctl \
                create_area mprotect])

APR_CHECK_DEFINE(MAP_ANON, sys/mman.h)
AC_CHECK_FILE(/dev/zero)

# Not all systems can mmap /dev/zero (such as HP-UX).  Check for that.
if test "$ac_cv_func_mmap" = "yes" &&
   test "$ac_cv_file__dev_zero" = "yes"; then
    AC_MSG_CHECKING(for mmap that can map /dev/zero)
    AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
    int main()
    {
        int fd;
        void *m;
        fd = open("/dev/zero", O_RDWR);
        if (fd < 0) {
            return 1;
        }
        m = mmap(0, sizeof(void*), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
        if (m == (void *)-1) {  /* aka MAP_FAILED */
            return 2;
        }
        if (munmap(m, sizeof(void*)) < 0) {
            return 3;
        }
        return 0;
    }], [], [ac_cv_file__dev_zero=no], [ac_cv_file__dev_zero=no])

    AC_MSG_RESULT($ac_cv_file__dev_zero)
fi

# Now we determine which one is our anonymous shmem preference.
haveshmgetanon="0"
havemmapzero="0"
havemmapanon="0"
APR_BEGIN_DECISION([anonymous shared memory allocation method])
APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl
             func:shmget func:shmat func:shmdt func:shmctl,
             [haveshmgetanon="1"
              APR_DECIDE(USE_SHMEM_SHMGET_ANON, [SysV IPC shmget()])])
APR_IFALLYES(header:sys/mman.h func:mmap func:munmap file:/dev/zero,
             [havemmapzero="1"
              APR_DECIDE(USE_SHMEM_MMAP_ZERO, 
                  [SVR4-style mmap() on /dev/zero])])
APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
             [havemmapanon="1"
              APR_DECIDE(USE_SHMEM_MMAP_ANON, 
                  [4.4BSD-style mmap() via MAP_ANON])])
APR_IFALLYES(header:os2.h,
             [haveos2shm="1"
              APR_DECIDE(USE_SHMEM_OS2_ANON, [OS/2 DosAllocSharedMem()])])
APR_IFALLYES(header:kernel/OS.h func:create_area,
             [havebeosshm="1"
              APR_DECIDE(USE_SHMEM_BEOS_ANON,
                         [BeOS areas])])
APR_IFALLYES(header:windows.h func:CreateFileMapping,
             [havewin32shm="1"
              APR_DECIDE(USE_SHMEM_WIN32_ANON,
                         [Windows CreateFileMapping()])])
case $host in
    *linux* ) 
        # Linux has problems with MM_SHMT_MMANON even though it reports
        # that it has it.
        # FIXME - find exact 2.3 version that MMANON was fixed in.  It is
        # confirmed fixed in 2.4 series.
        if test $os_pre24linux -eq 1; then
            AC_MSG_WARN([Disabling anon mmap() support for Linux pre-2.4])
            APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_ZERO USE_SHMEM_SHMGET_ANON)
        fi
        ;;
    *hpux11* ) 
        APR_DECISION_OVERRIDE(USE_SHMEM_SHMGET_ANON)
        ;;
esac
APR_END_DECISION
AC_DEFINE_UNQUOTED($ac_decision)

useshmgetanon="0"
usemmapzero="0"
usemmapanon="0"

case $ac_decision in
    USE_SHMEM_SHMGET_ANON )
        useshmgetanon="1"
        ;;
    USE_SHMEM_MMAP_ZERO )
        usemmapzero="1"
        ;;
    USE_SHMEM_MMAP_ANON )
        usemmapanon="1"
        ;;
esac

AC_SUBST(useshmgetanon)
AC_SUBST(usemmapzero)
AC_SUBST(usemmapanon)
AC_SUBST(haveshmgetanon)
AC_SUBST(havemmapzero)
AC_SUBST(havemmapanon)

# Now we determine which one is our name-based shmem preference.
havemmaptmp="0"
havemmapshm="0"
haveshmget="0"
havebeosarea="0"
haveos2shm="0"
havewin32shm="0"
APR_BEGIN_DECISION([namebased memory allocation method])
APR_IFALLYES(header:sys/mman.h func:mmap func:munmap,
             [havemmaptmp="1"
              APR_DECIDE(USE_SHMEM_MMAP_TMP, 
                  [Classical mmap() on temporary file])])
APR_IFALLYES(header:sys/mman.h func:mmap func:munmap func:shm_open dnl
             func:shm_unlink,
             [havemmapshm="1"
              APR_DECIDE(USE_SHMEM_MMAP_SHM, 
                  [mmap() via POSIX.1 shm_open() on temporary file])])
APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl
             func:shmget func:shmat func:shmdt func:shmctl,
             [haveshmget="1"
              APR_DECIDE(USE_SHMEM_SHMGET, [SysV IPC shmget()])])
APR_IFALLYES(header:kernel/OS.h func:create_area,
             [havebeosshm="1"
              APR_DECIDE(USE_SHMEM_BEOS, [BeOS areas])])
APR_IFALLYES(header:os2.h,
             [haveos2shm="1"
              APR_DECIDE(USE_SHMEM_OS2, [OS/2 DosAllocSharedMem()])])
APR_IFALLYES(header:windows.h,
             [havewin32shm="1"
              APR_DECIDE(USE_SHMEM_WIN32, [Windows shared memory])])
AC_ARG_ENABLE(posix-shm,
[  --enable-posix-shm      Use POSIX shared memory (shm_open) if available],
[
if test "$havemmapshm" = "1"; then
  APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_SHM)
fi
])
case $host in
    *linux* ) 
        # Linux pre-2.4 had problems with MM_SHMT_MMANON even though
        # it reports that it has it.
        if test $os_pre24linux -eq 1; then
            APR_DECISION_OVERRIDE(USE_SHMEM_MMAP_TMP USE_SHMEM_MMAP_SHM dnl
                                  USE_SHMEM_SHMGET)
        fi
        ;;
esac
APR_END_DECISION
AC_DEFINE_UNQUOTED($ac_decision)

usemmaptmp="0"
usemmapshm="0"
useshmget="0"
usebeosarea="0"
useos2shm="0"
usewin32shm="0"

case $ac_decision in
    USE_SHMEM_MMAP_TMP )
        usemmaptmp="1"
        ;;
    USE_SHMEM_MMAP_SHM )
        usemmapshm="1"
        ;;
    USE_SHMEM_SHMGET )
        useshmget="1"
        ;;
    USE_SHMEM_BEOS )
        usebeosarea="1"
        ;;
    USE_SHMEM_OS2 )
        useos2shm="1"
        ;;
    USE_SHMEM_WIN32 )
        usewin32shm="1"
        ;;
esac

# Do we have any shared memory support?
if test "$usemmaptmp$usemmapshm$usemmapzero$useshmget$usemmapanon$usebeosarea$useos2shm$usewin32shm" = "00000000"; then
  sharedmem="0"
else
  sharedmem="1"
fi

AC_SUBST(usemmaptmp)
AC_SUBST(usemmapshm)
AC_SUBST(useshmget)
AC_SUBST(usebeosarea)
AC_SUBST(useos2shm)
AC_SUBST(usewin32shm)
AC_SUBST(havemmaptmp)
AC_SUBST(havemmapshm)
AC_SUBST(haveshmget)
AC_SUBST(havebeosarea)
AC_SUBST(haveos2shm)
AC_SUBST(havewin32shm)
AC_SUBST(sharedmem)

dnl ----------------------------- Checks for Any required Functions
dnl Checks for library functions. (N.B. poll is further down)

AC_FUNC_ALLOCA

AC_CHECK_FUNCS([calloc setsid isinf isnan \
                getenv putenv setenv unsetenv \
                writev getifaddrs utime utimes])
AC_CHECK_FUNCS(setrlimit, [ have_setrlimit="1" ], [ have_setrlimit="0" ]) 
AC_CHECK_FUNCS(getrlimit, [ have_getrlimit="1" ], [ have_getrlimit="0" ]) 
sendfile="0"
AC_CHECK_LIB(sendfile, sendfilev)
AC_CHECK_FUNCS(sendfile send_file sendfilev, [ sendfile="1" ])

dnl THIS MUST COME AFTER THE THREAD TESTS - FreeBSD doesn't always have a
dnl threaded poll() and we don't want to use sendfile on early FreeBSD 
dnl systems if we are also using threads.

AC_ARG_WITH(sendfile, [  --with-sendfile         Override decision to use sendfile],
  [ if test "$withval" = "yes"; then
        sendfile="1"
    else
        sendfile="0"
    fi ], [
    orig_sendfile=$sendfile
    case $host in
        *freebsd*)
            # FreeBSD < 4.2 has issues with threads+sendfile
            if test $os_version -le "401999"; then
                if test "$threads" = "1"; then
                    sendfile="0"
                fi
            fi
            ;;
        *alpha*-dec-osf* )
            sendfile="0"
            ;;
        s390-*-linux-gnu)
            # disable sendfile support for 2.2 on S/390
            if test $os_pre24linux -eq 1; then
                AC_MSG_WARN([Disabled sendfile support for Linux 2.2 on S/390])
                sendfile="0"
            fi
            ;;
        *aix*)
            # compiler-independent check for 64-bit build
            AC_CHECK_SIZEOF(void*, 4)
            if test "x$ac_cv_sizeof_voidp" = "x8"; then
                # sendfile not working for 64-bit build
                sendfile="0"
            fi
            ;;
    esac       
    if test "$orig_sendfile" != "$sendfile"; then
      echo "sendfile support disabled to avoid system problem"
    fi ] )
AC_SUBST(sendfile)

AC_CHECK_FUNCS(sigaction, [ have_sigaction="1" ], [ have_sigaction="0" ]) 
AC_DECL_SYS_SIGLIST

AC_CHECK_FUNCS(fork, [ fork="1" ], [ fork="0" ])
APR_CHECK_INET_ADDR
APR_CHECK_INET_NETWORK
AC_SUBST(apr_inaddr_none)
AC_CHECK_FUNC(_getch)
AC_CHECK_FUNCS(strerror_r, [ strerror_r="1" ], [ strerror_r="0" ])
if test "$strerror_r" = "1"; then
  APR_CHECK_STRERROR_R_RC
fi
AC_CHECK_FUNCS(mmap, [ mmap="1" ], [ mmap="0" ])
if test "$native_mmap_emul" = "1"; then
    mmap="1"
fi
AC_CHECK_FUNCS(memmove, [ have_memmove="1" ], [have_memmove="0" ])
AC_CHECK_FUNCS([getpass getpassphrase gmtime_r localtime_r])
case $host in
    *-hp-hpux*)
        dnl mkstemp is limited to 26 temporary files (a-z); use APR replacement
        ;;
    *)
        AC_CHECK_FUNCS(mkstemp)
        ;;
esac

AC_SUBST(fork)
AC_SUBST(have_inet_addr)
AC_SUBST(tcp_nodelay_inherited)
AC_SUBST(o_nonblock_inherited)
AC_SUBST(have_inet_network)
AC_SUBST(have_sigaction)
AC_SUBST(have_setrlimit)
AC_SUBST(have_getrlimit)
AC_SUBST(mmap)
AC_SUBST(have_memmove)

APR_CHECK_SIGWAIT_ONE_ARG

dnl ----------------------------- Checks for Any required Headers
AC_HEADER_STDC

APR_FLAG_HEADERS(
    ByteOrder.h		\
    conio.h		\
    crypt.h		\
    ctype.h		\
    dir.h		\
    dirent.h		\
    dl.h		\
    dlfcn.h		\
    errno.h		\
    fcntl.h		\
    grp.h		\
    io.h		\
    limits.h		\
    mach-o/dyld.h	\
    malloc.h		\
    memory.h		\
    netdb.h		\
    osreldate.h		\
    poll.h		\
    process.h		\
    pwd.h		\
    semaphore.h		\
    signal.h		\
    stdarg.h		\
    stddef.h		\
    stdio.h		\
    stdlib.h		\
    string.h		\
    strings.h		\
    sysapi.h		\
    sysgtime.h		\
    termios.h		\
    time.h		\
    tpfeq.h		\
    tpfio.h		\
    unistd.h		\
    unix.h		\
    windows.h		\
    winsock2.h		\
    arpa/inet.h		\
    kernel/OS.h		\
    net/errno.h		\
    netinet/in.h	\
    netinet/sctp.h      \
    netinet/sctp_uio.h  \
    sys/file.h		\
    sys/ioctl.h         \
    sys/mman.h		\
    sys/param.h         \
    sys/poll.h		\
    sys/resource.h	\
    sys/select.h	\
    sys/sem.h		\
    sys/sendfile.h	\
    sys/signal.h	\
    sys/socket.h	\
    sys/sockio.h	\
    sys/stat.h          \
    sys/sysctl.h	\
    sys/syslimits.h	\
    sys/time.h		\
    sys/types.h		\
    sys/uio.h		\
    sys/un.h		\
    sys/wait.h)

# IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
# being included by itself.  Check for <netinet/tcp.h> manually,
# including another header file first.
AC_CACHE_CHECK([for netinet/tcp.h], [apr_cv_hdr_netinet_tcp_h],
[AC_TRY_CPP(
[#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <netinet/tcp.h>
], [apr_cv_hdr_netinet_tcp_h=yes], [apr_cv_hdr_netinet_tcp_h=no])])
if test "$apr_cv_hdr_netinet_tcp_h" = "yes"; then
   netinet_tcph=1
   AC_DEFINE([HAVE_NETINET_TCP_H], 1, [Defined if netinet/tcp.h is present])
else
   netinet_tcph=0
fi

AC_SUBST(arpa_ineth)
AC_SUBST(conioh)
AC_SUBST(ctypeh)
AC_SUBST(crypth)
AC_SUBST(errnoh)
AC_SUBST(direnth)
AC_SUBST(fcntlh)
AC_SUBST(ioh)
AC_SUBST(limitsh)
AC_SUBST(netdbh)
AC_SUBST(sys_syslimitsh)
AC_SUBST(netinet_inh)
AC_SUBST(netinet_sctph)
AC_SUBST(netinet_sctp_uioh)
AC_SUBST(netinet_tcph)
AC_SUBST(stdargh)
AC_SUBST(stdioh)
AC_SUBST(stdlibh)
AC_SUBST(stringh)
AC_SUBST(stringsh)
AC_SUBST(sys_ioctlh)
AC_SUBST(sys_sendfileh)
AC_SUBST(sys_signalh)
AC_SUBST(sys_socketh)
AC_SUBST(sys_sockioh)
AC_SUBST(sys_typesh)
AC_SUBST(sys_timeh)
AC_SUBST(sys_uioh)
AC_SUBST(sys_unh)
AC_SUBST(timeh)
AC_SUBST(unistdh)
AC_SUBST(signalh)
AC_SUBST(sys_waith)
AC_SUBST(processh)
AC_SUBST(pthreadh)
AC_SUBST(semaphoreh)
AC_SUBST(windowsh)
AC_SUBST(winsock2h)

# Checking for h_errno in <netdb.h>
if test "$netdbh" = "1"; then
  APR_CHECK_H_ERRNO_FLAG
  if test "$ac_cv_h_errno_cflags" = "no"; then
    AC_MSG_ERROR([can not find h_errno in netdb.h])
  fi
fi

AC_ARG_ENABLE(allocator-uses-mmap,
  [  --enable-allocator-uses-mmap    Use mmap in apr_allocator instead of malloc ],
  [ if test "$enableval" = "yes"; then
        APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
                     [AC_DEFINE(APR_ALLOCATOR_USES_MMAP, 1,
                                [Define if apr_allocator should use mmap]) ],
		     [AC_MSG_ERROR([mmap()/MAP_ANON not supported]) ]
		    )
    fi ]
)

AC_ARG_ENABLE(allocator-guard-pages,
  [  --enable-allocator-guard-pages  Use guard pages in apr_allocator
                                  (implies --enable-allocator-uses-mmap) ] ,
  [ if test "$enableval" = "yes"; then
        APR_IFALLYES(header:sys/mman.h func:mmap func:munmap func:mprotect define:MAP_ANON,
                     [AC_DEFINE(APR_ALLOCATOR_GUARD_PAGES, 1,
                                [Define if apr_allocator should use guard pages]) ],
                     [AC_MSG_ERROR([mmap()/MAP_ANON/mprotect() not supported]) ]
                   )
    fi ]
)


AC_ARG_ENABLE(pool-concurrency-check,
  [  --enable-pool-concurrency-check Check for concurrent usage of memory pools],
  [ if test "$enableval" = "yes"; then
    AC_DEFINE(APR_POOL_CONCURRENCY_CHECK, 1,
               [Define if pool functions should abort if concurrent usage is detected])
    fi ]
)

dnl ----------------------------- Checks for standard typedefs
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_CHECK_TYPE(ssize_t, int)
AC_C_INLINE
AC_C_CONST
AC_FUNC_SETPGRP

APR_CHECK_SOCKLEN_T

dnl Checks for pointer size
AC_CHECK_SIZEOF(void*, 4)

if test "x$ac_cv_sizeof_voidp" != "x"; then
    voidp_size=$ac_cv_sizeof_voidp
else
    AC_ERROR([Cannot determine size of void*])
fi

dnl Checks for integer size
AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(long long, 8)

if test "$ac_cv_sizeof_short" = "2"; then
    short_value=short
fi
if test "$ac_cv_sizeof_int" = "4"; then
    int_value=int
fi
# Now we need to find what apr_int64_t (sizeof == 8) will be.
# The first match is our preference.
if test "$ac_cv_sizeof_int" = "8"; then
    int64_literal='#define APR_INT64_C(val) (val)'
    uint64_literal='#define APR_UINT64_C(val) (val##U)'
    int64_t_fmt='#define APR_INT64_T_FMT "d"'
    uint64_t_fmt='#define APR_UINT64_T_FMT "u"'
    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "x"'
    int64_value="int"
    long_value=int
    int64_strfn="strtoi"
elif test "$ac_cv_sizeof_long" = "8"; then
    int64_literal='#define APR_INT64_C(val) (val##L)'
    uint64_literal='#define APR_UINT64_C(val) (val##UL)'
    int64_t_fmt='#define APR_INT64_T_FMT "ld"'
    uint64_t_fmt='#define APR_UINT64_T_FMT "lu"'
    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "lx"'
    int64_value="long"
    long_value=long
    int64_strfn="strtol"
elif test "$ac_cv_sizeof_long_long" = "8"; then
    int64_literal='#define APR_INT64_C(val) (val##LL)'
    uint64_literal='#define APR_UINT64_C(val) (val##ULL)'
    # Linux, Solaris, FreeBSD all support ll with printf.
    # BSD 4.4 originated 'q'.  Solaris is more popular and 
    # doesn't support 'q'.  Solaris wins.  Exceptions can
    # go to the OS-dependent section.
    int64_t_fmt='#define APR_INT64_T_FMT "lld"'
    uint64_t_fmt='#define APR_UINT64_T_FMT "llu"'
    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "llx"'
    int64_value="long long"
    long_value="long long"
    int64_strfn="strtoll"
elif test "$ac_cv_sizeof_longlong" = "8"; then
    int64_literal='#define APR_INT64_C(val) (val##LL)'
    uint64_literal='#define APR_UINT64_C(val) (val##ULL)'
    int64_t_fmt='#define APR_INT64_T_FMT "qd"'
    uint64_t_fmt='#define APR_UINT64_T_FMT "qu"'
    uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "qx"'
    int64_value="__int64"
    long_value="__int64"
    int64_strfn="strtoll"
else
    # int64_literal may be overriden if your compiler thinks you have
    # a 64-bit value but APR does not agree.
    AC_ERROR([could not detect a 64-bit integer type])
fi

# If present, allow the C99 macro INT64_C to override our conversion.
#
# HP-UX's ANSI C compiler provides this without any includes, so we
# will first look for INT64_C without adding stdint.h
AC_CACHE_CHECK([for INT64_C], [apr_cv_define_INT64_C], [
AC_EGREP_CPP(YES_IS_DEFINED,
[#ifdef INT64_C
YES_IS_DEFINED
#endif], [apr_cv_define_INT64_C=yes], [
    # Now check for INT64_C in stdint.h
    AC_EGREP_CPP(YES_IS_DEFINED, [#include <stdint.h>
#ifdef INT64_C
YES_IS_DEFINED
#endif], [apr_cv_define_INT64_C=yes], [apr_cv_define_INT64_C=no])])])

if test "$apr_cv_define_INT64_C" = "yes"; then
    int64_literal='#define APR_INT64_C(val) INT64_C(val)'
    uint64_literal='#define APR_UINT64_C(val) UINT64_C(val)'
    stdint=1
else
    stdint=0
fi

if test "$ac_cv_type_size_t" = "yes"; then
    size_t_value="size_t"
else
    size_t_value="apr_int32_t"
fi
if test "$ac_cv_type_ssize_t" = "yes"; then
    ssize_t_value="ssize_t"
else
    ssize_t_value="apr_int32_t"
fi
if test "$ac_cv_socklen_t" = "yes"; then
    socklen_t_value="socklen_t"
    case $host in
        *-hp-hpux*)
            if test "$ac_cv_sizeof_long" = "8"; then
                # 64-bit HP-UX requires 32-bit socklens in
                # kernel, but user-space declarations say
                # 64-bit (socklen_t == size_t == long).
                # This will result in many compile warnings,
                # but we're functionally busted otherwise.
                socklen_t_value="int"
            fi
            ;;
    esac
else
    socklen_t_value="int"
fi

APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], pid_t, 8)

if test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_short"; then
    pid_t_fmt='#define APR_PID_T_FMT "hd"'
elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_int"; then
    pid_t_fmt='#define APR_PID_T_FMT "d"'
elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long"; then
    pid_t_fmt='#define APR_PID_T_FMT "ld"'
elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long_long"; then
    pid_t_fmt='#define APR_PID_T_FMT APR_INT64_T_FMT'
else
    pid_t_fmt='#error Can not determine the proper size for pid_t'
fi

# Basically, we have tried to figure out the correct format strings
# for APR types which vary between platforms, but we don't always get
# it right.
case $host in
   s390*linux*)
       # uniquely, the 31-bit Linux/s390 uses "unsigned long int"
       # for size_t rather than "unsigned int":
       size_t_fmt="lu"
       ssize_t_fmt="ld"
       ;;
   *-os2*)
       size_t_fmt="lu"
       ;;
   *-solaris*)
       if test "$ac_cv_sizeof_long" = "8"; then
         pid_t_fmt='#define APR_PID_T_FMT "d"'
       else
         pid_t_fmt='#define APR_PID_T_FMT "ld"'
       fi
       ;;
   *aix4*|*aix5*)
       ssize_t_fmt="ld"
       size_t_fmt="lu"
       ;;
    *beos*)
        ssize_t_fmt="ld"
        size_t_fmt="ld"
        ;;
    *apple-darwin*)
        osver=`uname -r`
        case $osver in
           [[0-7]].*)
              ssize_t_fmt="d"
              ;;
           *)
              ssize_t_fmt="ld"
              ;;
        esac
        size_t_fmt="lu"
        ;;
    *-mingw*)
        int64_t_fmt='#define APR_INT64_T_FMT "I64d"'
        uint64_t_fmt='#define APR_UINT64_T_FMT "I64u"'
        uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "I64x"'
        int64_value="__int64"
        long_value="__int64"
        int64_strfn="_strtoi64"
        ;; 
esac

APR_CHECK_TYPES_COMPATIBLE(ssize_t, int, [ssize_t_fmt="d"])
APR_CHECK_TYPES_COMPATIBLE(ssize_t, long, [ssize_t_fmt="ld"])
APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned int, [size_t_fmt="u"])
APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned long, [size_t_fmt="lu"])

APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], ssize_t, 8)

AC_MSG_CHECKING([which format to use for apr_ssize_t])
if test -n "$ssize_t_fmt"; then
    AC_MSG_RESULT(%$ssize_t_fmt)
elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then
    ssize_t_fmt="d"
    AC_MSG_RESULT(%d)
elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then
    ssize_t_fmt="ld"
    AC_MSG_RESULT(%ld)
else
    AC_ERROR([could not determine the proper format for apr_ssize_t])
fi

ssize_t_fmt="#define APR_SSIZE_T_FMT \"$ssize_t_fmt\""

APR_CHECK_SIZEOF_EXTENDED([#include <stddef.h>], size_t, 8)

AC_MSG_CHECKING([which format to use for apr_size_t])
if test -n "$size_t_fmt"; then
    AC_MSG_RESULT(%$size_t_fmt)
elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then
    size_t_fmt="d"
    AC_MSG_RESULT(%d)
elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then
    size_t_fmt="ld"
    AC_MSG_RESULT(%ld)
else
    AC_ERROR([could not determine the proper format for apr_size_t])
fi

size_t_fmt="#define APR_SIZE_T_FMT \"$size_t_fmt\""

APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], off_t, 8)

if test "${ac_cv_sizeof_off_t}${apr_cv_use_lfs64}" = "4yes"; then
    # Enable LFS
    aprlfs=1
    AC_CHECK_FUNCS([mmap64 sendfile64 sendfilev64 readdir64_r])
    case $host in
        *-hp-hpux*)
            dnl mkstemp64 is limited to 26 temporary files (a-z); use APR replacement
            ;;
        *)
            AC_CHECK_FUNCS(mkstemp64)
            ;;
    esac
elif test "${ac_cv_sizeof_off_t}" != "${ac_cv_sizeof_size_t}"; then
    # unsure of using -gt above is as portable, can can't forsee where
    # off_t can legitimately be smaller than size_t
    aprlfs=1
else
    aprlfs=0     
fi

AC_MSG_CHECKING([which type to use for apr_off_t])
if test "${ac_cv_sizeof_off_t}${apr_cv_use_lfs64}" = "4yes"; then
    # LFS is go!
    off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
    off_t_value='off64_t'
    off_t_strfn='apr_strtoi64'
elif test "${ac_cv_sizeof_off_t}x${ac_cv_sizeof_long}" = "4x4"; then
    # Special case: off_t may change size with _FILE_OFFSET_BITS
    # on 32-bit systems with LFS support.  To avoid compatibility
    # issues when other packages do define _FILE_OFFSET_BITS,
    # hard-code apr_off_t to long.
    off_t_value=long
    off_t_fmt='#define APR_OFF_T_FMT "ld"'
    off_t_strfn='strtol'
elif test "$ac_cv_type_off_t" = "yes"; then
    off_t_value=off_t
    # off_t is more commonly a long than an int; prefer that case
    # where int and long are the same size.
    if test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long"; then
        off_t_fmt='#define APR_OFF_T_FMT "ld"'
        off_t_strfn='strtol'
    elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_int"; then
        off_t_fmt='#define APR_OFF_T_FMT "d"'
        off_t_strfn='strtoi'
    elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long_long"; then
        off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
        off_t_strfn='apr_strtoi64'
    else
        AC_ERROR([could not determine the size of off_t])
    fi
    # Per OS tuning...
    case $host in
    *-mingw*)
        off_t_value=apr_int64_t
        off_t_fmt='#define APR_OFF_T_FMT "I64d"'
        off_t_strfn='_strtoi64'
        ;;
    esac
else
   # Fallback on int
   off_t_value=apr_int32_t
   off_t_fmt=d
   off_t_strfn='strtoi'
fi
AC_MSG_RESULT($off_t_value)

# Regardless of whether _LARGEFILE64_SOURCE is used, on some
# platforms _FILE_OFFSET_BITS will affect the size of ino_t and hence
# the build-time ABI may be different from the apparent ABI when using
# APR with another package which *does* define _FILE_OFFSET_BITS.
# (Exactly as per the case above with off_t where LFS is *not* used)
#
# To be safe, hard-code apr_ino_t as 'unsigned long' or 'unsigned int'
# iff that is exactly the size of ino_t here; otherwise use ino_t as existing
# releases did.  To be correct, apr_ino_t should have been made an
# ino64_t as apr_off_t is off64_t, but this can't be done now without
# breaking ABI.

# Per OS tuning...
case $host in
*mingw*)
    ino_t_value=apr_int64_t
    ;;
*)
    ino_t_value=ino_t
    APR_CHECK_SIZEOF_EXTENDED(AC_INCLUDES_DEFAULT, ino_t, $ac_cv_sizeof_long)
    if test $ac_cv_sizeof_ino_t = 4; then
        if test $ac_cv_sizeof_long = 4; then
            ino_t_value="unsigned long"
        else
            ino_t_value="unsigned int"
        fi
    fi
    ;;
esac
AC_MSG_NOTICE([using $ino_t_value for ino_t])

# Checks for endianness
AC_C_BIGENDIAN
if test $ac_cv_c_bigendian = yes; then
    bigendian=1
else
    bigendian=0
fi

APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>
#include <sys/uio.h>],struct iovec,0)
if test "$ac_cv_sizeof_struct_iovec" = "0"; then
    have_iovec=0
else
    have_iovec=1
fi

AC_SUBST(voidp_size)
AC_SUBST(short_value)
AC_SUBST(int_value)
AC_SUBST(long_value)
AC_SUBST(int64_value)
AC_SUBST(off_t_value)
AC_SUBST(size_t_value)
AC_SUBST(ssize_t_value)
AC_SUBST(socklen_t_value)
AC_SUBST(int64_t_fmt) 
AC_SUBST(uint64_t_fmt) 
AC_SUBST(uint64_t_hex_fmt) 
AC_SUBST(ssize_t_fmt) 
AC_SUBST(size_t_fmt)