|
| 1 | +# =========================================================================== |
| 2 | +# https://www.gnu.org/software/autoconf-archive/ax_have_epoll.html |
| 3 | +# =========================================================================== |
| 4 | +# |
| 5 | +# SYNOPSIS |
| 6 | +# |
| 7 | +# AX_HAVE_EPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
| 8 | +# AX_HAVE_EPOLL_PWAIT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
| 9 | +# |
| 10 | +# DESCRIPTION |
| 11 | +# |
| 12 | +# This macro determines whether the system supports the epoll I/O event |
| 13 | +# interface. A neat usage example would be: |
| 14 | +# |
| 15 | +# AX_HAVE_EPOLL( |
| 16 | +# [AX_CONFIG_FEATURE_ENABLE(epoll)], |
| 17 | +# [AX_CONFIG_FEATURE_DISABLE(epoll)]) |
| 18 | +# AX_CONFIG_FEATURE( |
| 19 | +# [epoll], [This platform supports epoll(7)], |
| 20 | +# [HAVE_EPOLL], [This platform supports epoll(7).]) |
| 21 | +# |
| 22 | +# The epoll interface was added to the Linux kernel in version 2.5.45, and |
| 23 | +# the macro verifies that a kernel newer than this is installed. This |
| 24 | +# check is somewhat unreliable if <linux/version.h> doesn't match the |
| 25 | +# running kernel, but it is necessary regardless, because glibc comes with |
| 26 | +# stubs for the epoll_create(), epoll_wait(), etc. that allow programs to |
| 27 | +# compile and link even if the kernel is too old; the problem would then |
| 28 | +# be detected only at runtime. |
| 29 | +# |
| 30 | +# Linux kernel version 2.6.19 adds the epoll_pwait() call in addition to |
| 31 | +# epoll_wait(). The availability of that function can be tested with the |
| 32 | +# second macro. Generally speaking, it is safe to assume that |
| 33 | +# AX_HAVE_EPOLL would succeed if AX_HAVE_EPOLL_PWAIT has, but not the |
| 34 | +# other way round. |
| 35 | +# |
| 36 | +# LICENSE |
| 37 | +# |
| 38 | +# Copyright (c) 2008 Peter Simons <simons@cryp.to> |
| 39 | +# |
| 40 | +# Copying and distribution of this file, with or without modification, are |
| 41 | +# permitted in any medium without royalty provided the copyright notice |
| 42 | +# and this notice are preserved. This file is offered as-is, without any |
| 43 | +# warranty. |
| 44 | + |
| 45 | +#serial 11 |
| 46 | + |
| 47 | +AC_DEFUN([AX_HAVE_EPOLL], [dnl |
| 48 | + ax_have_epoll_cppflags="${CPPFLAGS}" |
| 49 | + AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) |
| 50 | + AC_MSG_CHECKING([for Linux epoll(7) interface]) |
| 51 | + AC_CACHE_VAL([ax_cv_have_epoll], [dnl |
| 52 | + AC_LINK_IFELSE([dnl |
| 53 | + AC_LANG_PROGRAM([dnl |
| 54 | +#include <sys/epoll.h> |
| 55 | +#ifdef HAVE_LINUX_VERSION_H |
| 56 | +# include <linux/version.h> |
| 57 | +# if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45) |
| 58 | +# error linux kernel version is too old to have epoll |
| 59 | +# endif |
| 60 | +#endif |
| 61 | +], [dnl |
| 62 | +int fd, rc; |
| 63 | +struct epoll_event ev; |
| 64 | +fd = epoll_create(128); |
| 65 | +rc = epoll_wait(fd, &ev, 1, 0);])], |
| 66 | + [ax_cv_have_epoll=yes], |
| 67 | + [ax_cv_have_epoll=no])]) |
| 68 | + CPPFLAGS="${ax_have_epoll_cppflags}" |
| 69 | + AS_IF([test "${ax_cv_have_epoll}" = "yes"], |
| 70 | + [AC_MSG_RESULT([yes]) |
| 71 | +$1],[AC_MSG_RESULT([no]) |
| 72 | +$2]) |
| 73 | +])dnl |
| 74 | + |
| 75 | +AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl |
| 76 | + ax_have_epoll_cppflags="${CPPFLAGS}" |
| 77 | + AC_CHECK_HEADER([linux/version.h], |
| 78 | + [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) |
| 79 | + AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension]) |
| 80 | + AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl |
| 81 | + AC_LINK_IFELSE([dnl |
| 82 | + AC_LANG_PROGRAM([dnl |
| 83 | +#ifdef HAVE_LINUX_VERSION_H |
| 84 | +# include <linux/version.h> |
| 85 | +# if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) |
| 86 | +# error linux kernel version is too old to have epoll_pwait |
| 87 | +# endif |
| 88 | +#endif |
| 89 | +#include <sys/epoll.h> |
| 90 | +#include <signal.h> |
| 91 | +], [dnl |
| 92 | +int fd, rc; |
| 93 | +struct epoll_event ev; |
| 94 | +fd = epoll_create(128); |
| 95 | +rc = epoll_wait(fd, &ev, 1, 0); |
| 96 | +rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])], |
| 97 | + [ax_cv_have_epoll_pwait=yes], |
| 98 | + [ax_cv_have_epoll_pwait=no])]) |
| 99 | + CPPFLAGS="${ax_have_epoll_cppflags}" |
| 100 | + AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"], |
| 101 | + [AC_MSG_RESULT([yes]) |
| 102 | +$1],[AC_MSG_RESULT([no]) |
| 103 | +$2]) |
| 104 | +])dnl |
0 commit comments