From c955d333bbffd02cb6f439489865ac3c37c9ff3b Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Mon, 13 Dec 2021 08:15:01 +0100 Subject: configure: add check for existence of sendfile() This is based on https://gist.github.com/bmanojlovic/6529848, but adapted to make the Solaris case a little bit less of a guess. Signed-off-by: Fabian Groffen --- autotools/m4/ac_check_sendfile.m4 | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 autotools/m4/ac_check_sendfile.m4 (limited to 'autotools') 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 + #include ]], + [[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 + #include ]], + [[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 + #include + #include ]], + [[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" + +]) -- cgit v1.2.3-65-gdbad