5 # AX_CHECK_CAPSICUM([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
9 # This macro searches for an installed Capsicum header and library,
11 # - AC_DEFINE([HAVE_CAPSICUM]) is called.
12 # - AC_DEFINE([HAVE_SYS_CAPSICUM_H]) is called if <sys/capsicum.h>
13 # is present (otherwise <sys/capability.h> must be used).
14 # - CAPSICUM_LIB is set to the -l option needed to link Capsicum support,
15 # and AC_SUBST([CAPSICUM_LIB]) is called.
16 # - The shell commands in ACTION-IF-FOUND are run. The default
17 # ACTION-IF-FOUND prepends ${CAPSICUM_LIB} into LIBS. If you don't
18 # want to modify LIBS and don't need to run any other commands either,
19 # use a colon as ACTION-IF-FOUND.
21 # If Capsicum support isn't found:
22 # - The shell commands in ACTION-IF-NOT-FOUND are run. The default
23 # ACTION-IF-NOT-FOUND calls AC_MSG_WARN to print a warning that
24 # Capsicum support wasn't found.
26 # You should use autoheader to include a definition for the symbols above
29 # Sample usage in a C/C++ source is as follows:
31 # #ifdef HAVE_CAPSICUM
32 # # ifdef HAVE_SYS_CAPSICUM_H
33 # # include <sys/capsicum.h>
35 # # include <sys/capability.h>
37 # #endif /* HAVE_CAPSICUM */
41 # Copyright (c) 2014 Google Inc.
42 # Copyright (c) 2015 Lasse Collin <lasse.collin@tukaani.org>
44 # Copying and distribution of this file, with or without modification,
45 # are permitted in any medium without royalty provided the copyright
46 # notice and this notice are preserved. This file is offered as-is,
47 # without any warranty.
51 AC_DEFUN([AX_CHECK_CAPSICUM], [
52 # On FreeBSD >= 11.x and Linux, Capsicum is uses <sys/capsicum.h>.
53 # If this header is found, it is assumed to be the right one.
54 capsicum_header_found=no
55 AC_CHECK_HEADERS([sys/capsicum.h], [capsicum_header_found=yes])
56 if test "$capsicum_header_found" = no ; then
57 # On FreeBSD 10.x Capsicum uses <sys/capability.h>. Such a header exists
58 # on Linux too but it describes POSIX.1e capabilities. Look for the
59 # declaration of cap_rights_limit to check if <sys/capability.h> is
61 AC_CHECK_DECL([cap_rights_limit], [capsicum_header_found=yes], [],
62 [#include <sys/capability.h>])
67 if test "$capsicum_header_found" = yes ; then
69 # FreeBSD >= 10.x has Capsicum functions in libc.
70 AC_LINK_IFELSE([AC_LANG_CALL([], [cap_rights_limit])],
71 [capsicum_lib_found=yes], [])
72 # Linux has Capsicum functions in libcaprights.
73 AC_CHECK_LIB([caprights], [cap_rights_limit],
74 [CAPSICUM_LIB=-lcaprights
75 capsicum_lib_found=yes], [])
78 AC_SUBST([CAPSICUM_LIB])
80 if test "$capsicum_lib_found" = yes ; then
81 AC_DEFINE([HAVE_CAPSICUM], [1], [Define to 1 if Capsicum is available.])
82 m4_default([$1], [LIBS="${CAPSICUM_LIB} $LIBS"])
84 m4_default([$2], [AC_MSG_WARN([Capsicum support not found])])