diff options
-rw-r--r-- | autotools/m4/ac_check_sendfile.m4 | 63 | ||||
-rw-r--r-- | configure.ac | 2 |
2 files changed, 65 insertions, 0 deletions
diff --git a/autotools/m4/ac_check_sendfile.m4 b/autotools/m4/ac_check_sendfile.m4 new file mode 100644 index 00000000..5ec428d9 --- /dev/null +++ b/autotools/m4/ac_check_sendfile.m4 @@ -0,0 +1,63 @@ +AC_DEFUN([AC_CHECK_SENDFILE],[ + +saved_LIBS="$LIBS" +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Werror-implicit-function-declaration" + +dnl platforms like Solaris need libsendfile, first check if it's there +AC_CHECK_LIB(sendfile, sendfile, + [ + LIBS="-lsendfile $LIBS" + SENDFILE_LIBS="-lsendfile" + AC_SUBST(SENDFILE_LIBS) + ], []) + +ac_sendfile_supported=no +AC_MSG_CHECKING([whether sendfile() is supported and what prototype it has]) + +dnl Linux/Solaris +AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/sendfile.h> + #include <stdio.h>]], + [[sendfile(1, 1, NULL, 0);]])], + [ + AC_DEFINE(HAVE_SENDFILE4_SUPPORT, 1, + [Define this if Linux/Solaris sendfile() is supported]) + AC_MSG_RESULT([Linux/Solaris sendfile()]) + ac_sendfile_supported=yes + ], []) + +dnl FreeBSD-like +if test x$ac_sendfile_supported = xno; then + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h> + #include <stdio.h>]], + [[sendfile(1, 1, 0, 0, NULL, NULL, 0);]])], + [ + AC_DEFINE(HAVE_SENDFILE7_SUPPORT, 1, + [Define this if FreeBSD sendfile() is supported]) + AC_MSG_RESULT([FreeBSD sendfile()]) + ac_sendfile_supported=yes + ], []) +fi + +dnl macOS-like +if test x$ac_sendfile_supported = xno; then + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h> + #include <stdio.h> + #include <sys/uio.h>]], + [[sendfile(1, 1, 0, NULL, NULL, 0);]])], + [ + AC_DEFINE(HAVE_SENDFILE6_SUPPORT, 1, + [Define this if MacOS sendfile() is supported]) + AC_MSG_RESULT([MacOS sendfile()]) + ac_sendfile_supported=yes + ], []) +fi + +if test x$ac_sendfile_supported = xno; then + AC_MSG_RESULT([no sendfile() support, using read/send]) +fi + +CFLAGS="$saved_CFLAGS" +LIBS="$saved_LIBS" + +]) diff --git a/configure.ac b/configure.ac index 989a34fd..bdef7322 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,8 @@ AC_CHECK_FUNCS_ONCE(m4_flatten([ scandirat ])) +AC_CHECK_SENDFILE + AC_ARG_WITH([eprefix], [AS_HELP_STRING([--with-eprefix], [path for Gentoo/Prefix project])]) # ensure eprefix ends with a slash, since the code base expects that case "$with_eprefix" in |