libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit e645f9b1863414d34474131bd64d5c9d97145851
parent 30943d715aa02271e274aa622cf4587c060e139f
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed,  5 Mar 2014 09:37:01 +0000

configure.ac: properly check for epoll support by macro from autoconf archive

Diffstat:
Mconfigure.ac | 43+++++++++++++++++--------------------------
Am4/ax_have_epoll.m4 | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+), 26 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -123,24 +123,10 @@ netbsd*) AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel]) AC_DEFINE_UNQUOTED(HAVE_LISTEN_SHUTDOWN,1,[can use shutdown on listen sockets]) CFLAGS="-fPIC -pipe $CFLAGS" - AC_MSG_CHECKING(whether to support epoll) - AC_ARG_ENABLE([epoll], - AS_HELP_STRING([--disable-epoll], - [disable epoll]), - [enable_epoll=${enableval}], - [enable_epoll=yes]) - AC_MSG_RESULT($enable_epoll) ;; *linux*) AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel]) AC_DEFINE_UNQUOTED(HAVE_LISTEN_SHUTDOWN,1,[can use shutdown on listen sockets]) - AC_MSG_CHECKING(whether to support epoll) - AC_ARG_ENABLE([epoll], - AS_HELP_STRING([--disable-epoll], - [disable epoll]), - [enable_epoll=${enableval}], - [enable_epoll=yes]) - AC_MSG_RESULT($enable_epoll) ;; *cygwin*) AC_DEFINE_UNQUOTED(CYGWIN,1,[This is a Cygwin system]) @@ -195,21 +181,26 @@ AM_CONDITIONAL(USE_MS_LIB_TOOL, [test "x$ac_cv_use_ms_lib_tool" = "xyes"]) AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes" && test "x$enable_static" = "xyes"]) -if test "$enable_epoll" = "yes" -then - AC_CHECK_HEADERS([sys/epoll.h], - [enable_epoll="yes"], - [enable_epoll="no"]) -fi +AC_ARG_ENABLE([[epoll]], + [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])], + [enable_epoll=${enableval}], + [enable_epoll='auto'] + ) -if test "$enable_epoll" = "yes" -then - AC_DEFINE([EPOLL_SUPPORT],[1],[include epoll support]) -else - AC_DEFINE([EPOLL_SUPPORT],[0],[disable epoll support]) +if test "$enable_epoll" != "no"; then + AX_HAVE_EPOLL + if test "${ax_cv_have_epoll}" = "yes"; then + AC_DEFINE([EPOLL_SUPPORT],[1],[define to 1 to enable epoll support]) + enable_epoll='yes' + else + AC_DEFINE([EPOLL_SUPPORT],[0],[define to 0 to disable epoll support]) + if test "$enable_epoll" = "yes"; then + AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]]) + fi + enable_epoll='no' + fi fi - # Check for headers that are ALWAYS required AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h sys/types.h pthread.h],,AC_MSG_ERROR([Compiling libmicrohttpd requires standard UNIX headers files])) diff --git a/m4/ax_have_epoll.m4 b/m4/ax_have_epoll.m4 @@ -0,0 +1,104 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_have_epoll.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_HAVE_EPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# AX_HAVE_EPOLL_PWAIT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# DESCRIPTION +# +# This macro determines whether the system supports the epoll I/O event +# interface. A neat usage example would be: +# +# AX_HAVE_EPOLL( +# [AX_CONFIG_FEATURE_ENABLE(epoll)], +# [AX_CONFIG_FEATURE_DISABLE(epoll)]) +# AX_CONFIG_FEATURE( +# [epoll], [This platform supports epoll(7)], +# [HAVE_EPOLL], [This platform supports epoll(7).]) +# +# The epoll interface was added to the Linux kernel in version 2.5.45, and +# the macro verifies that a kernel newer than this is installed. This +# check is somewhat unreliable if <linux/version.h> doesn't match the +# running kernel, but it is necessary regardless, because glibc comes with +# stubs for the epoll_create(), epoll_wait(), etc. that allow programs to +# compile and link even if the kernel is too old; the problem would then +# be detected only at runtime. +# +# Linux kernel version 2.6.19 adds the epoll_pwait() call in addition to +# epoll_wait(). The availability of that function can be tested with the +# second macro. Generally speaking, it is safe to assume that +# AX_HAVE_EPOLL would succeed if AX_HAVE_EPOLL_PWAIT has, but not the +# other way round. +# +# LICENSE +# +# Copyright (c) 2008 Peter Simons <simons@cryp.to> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 10 + +AC_DEFUN([AX_HAVE_EPOLL], [dnl + ax_have_epoll_cppflags="${CPPFLAGS}" + AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) + AC_MSG_CHECKING([for Linux epoll(7) interface]) + AC_CACHE_VAL([ax_cv_have_epoll], [dnl + AC_LINK_IFELSE([dnl + AC_LANG_PROGRAM([dnl +#include <sys/epoll.h> +#ifdef HAVE_LINUX_VERSION_H +# include <linux/version.h> +# if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45) +# error linux kernel version is too old to have epoll +# endif +#endif +], [dnl +int fd, rc; +struct epoll_event ev; +fd = epoll_create(128); +rc = epoll_wait(fd, &ev, 1, 0);])], + [ax_cv_have_epoll=yes], + [ax_cv_have_epoll=no])]) + CPPFLAGS="${ax_have_epoll_cppflags}" + AS_IF([test "${ax_cv_have_epoll}" = "yes"], + [AC_MSG_RESULT([yes]) +$1],[AC_MSG_RESULT([no]) +$2]) +])dnl + +AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl + ax_have_epoll_cppflags="${CPPFLAGS}" + AC_CHECK_HEADER([linux/version.h], + [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) + AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension]) + AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl + AC_LINK_IFELSE([dnl + AC_LANG_PROGRAM([dnl +#ifdef HAVE_LINUX_VERSION_H +# include <linux/version.h> +# if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) +# error linux kernel version is too old to have epoll_pwait +# endif +#endif +#include <sys/epoll.h> +#include <signal.h> +], [dnl +int fd, rc; +struct epoll_event ev; +fd = epoll_create(128); +rc = epoll_wait(fd, &ev, 1, 0); +rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])], + [ax_cv_have_epoll_pwait=yes], + [ax_cv_have_epoll_pwait=no])]) + CPPFLAGS="${ax_have_epoll_cppflags}" + AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"], + [AC_MSG_RESULT([yes]) +$1],[AC_MSG_RESULT([no]) +$2]) +])dnl