aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2021-12-13 08:15:01 +0100
committerFabian Groffen <grobian@gentoo.org>2021-12-13 08:15:01 +0100
commitc955d333bbffd02cb6f439489865ac3c37c9ff3b (patch)
tree733113ef87952f58d0d7fcf63b5c72cb5ec4bc3e /autotools
parentqdepends: only print deps enabled by configured USE-flags (diff)
downloadportage-utils-c955d333bbffd02cb6f439489865ac3c37c9ff3b.tar.gz
portage-utils-c955d333bbffd02cb6f439489865ac3c37c9ff3b.tar.bz2
portage-utils-c955d333bbffd02cb6f439489865ac3c37c9ff3b.zip
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 <grobian@gentoo.org>
Diffstat (limited to 'autotools')
-rw-r--r--autotools/m4/ac_check_sendfile.m463
1 files changed, 63 insertions, 0 deletions
diff --git a/autotools/m4/ac_check_sendfile.m4 b/autotools/m4/ac_check_sendfile.m4
new file mode 100644
index 0000000..5ec428d
--- /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"
+
+])