|
| 1 | +# SYNOPSIS |
| 2 | +# |
| 3 | +# AX_CHECK_CAP([action-if-found[, action-if-not-found]]) |
| 4 | +# |
| 5 | +# DESCRIPTION |
| 6 | +# |
| 7 | +# Look for libcap in a number of default locations, or in a provided location |
| 8 | +# (via --with-libcap=). Sets |
| 9 | +# CAP_CFLAGS |
| 10 | +# CAP_LDFLAGS |
| 11 | +# CAP_LIBS |
| 12 | +# |
| 13 | +# and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately |
| 14 | +# |
| 15 | +# LICENSE |
| 16 | +# |
| 17 | +# Copyright (c) 2025 PPP Project |
| 18 | +# |
| 19 | +# Copying and distribution of this file, with or without modification, are |
| 20 | +# permitted in any medium without royalty provided the copyright notice |
| 21 | +# and this notice are preserved. This file is offered as-is, without any |
| 22 | +# warranty. |
| 23 | + |
| 24 | +#serial 1 |
| 25 | + |
| 26 | +AC_DEFUN([AX_CHECK_CAP], [ |
| 27 | + AC_ARG_WITH([libcap], |
| 28 | + [AS_HELP_STRING([--with-libcap=yes|no|DIR], |
| 29 | + [With libcap (capabilities) support for fine-grained privilege management])]) |
| 30 | +
|
| 31 | + AS_CASE(["$with_libcap"], |
| 32 | + [ye|y], [with_libcap=yes], |
| 33 | + [n], [with_libcap=no]) |
| 34 | +
|
| 35 | + AS_IF([test "x$with_libcap" != "xno"], [ |
| 36 | + AS_CASE(["$with_libcap"], |
| 37 | + [""|yes], [PKG_CHECK_MODULES([CAP], [libcap], [capdirs=], |
| 38 | + [capdirs="/usr/local /usr/lib /usr"])], |
| 39 | + [capdirs="$with_libcap"]) |
| 40 | +
|
| 41 | + AS_IF([test -n "$capdirs"], [ |
| 42 | + CAP_LIBS="-lcap" |
| 43 | + for capdir in $capdirs; do |
| 44 | + AC_MSG_CHECKING([for sys/capability.h in $capdir]) |
| 45 | + if test -f "$capdir/include/sys/capability.h"; then |
| 46 | + CAP_CFLAGS="-I$capdir/include" |
| 47 | + CAP_LDFLAGS="-L$capdir/lib" |
| 48 | + AC_MSG_RESULT([yes]) |
| 49 | + break |
| 50 | + else |
| 51 | + AC_MSG_RESULT([no]) |
| 52 | + fi |
| 53 | + done |
| 54 | + ]) |
| 55 | +
|
| 56 | + # try the preprocessor and linker with our new flags, |
| 57 | + # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS |
| 58 | +
|
| 59 | + AC_MSG_CHECKING([if compiling and linking against libcap works]) |
| 60 | +
|
| 61 | + save_LIBS="$LIBS" |
| 62 | + save_LDFLAGS="$LDFLAGS" |
| 63 | + save_CPPFLAGS="$CPPFLAGS" |
| 64 | + LDFLAGS="$LDFLAGS $CAP_LDFLAGS" |
| 65 | + LIBS="$CAP_LIBS $LIBS" |
| 66 | + CPPFLAGS="$CAP_CFLAGS $CPPFLAGS" |
| 67 | + AC_LINK_IFELSE( |
| 68 | + [AC_LANG_PROGRAM( |
| 69 | + [#include <sys/capability.h>], |
| 70 | + [cap_t cap = cap_get_pid(0);])], |
| 71 | + [ |
| 72 | + AC_MSG_RESULT([yes]) |
| 73 | + with_libcap=yes |
| 74 | + $1 |
| 75 | + ], [ |
| 76 | + AC_MSG_RESULT([no]) |
| 77 | + with_libcap="no" |
| 78 | + $2 |
| 79 | + ]) |
| 80 | + CPPFLAGS="$save_CPPFLAGS" |
| 81 | + LDFLAGS="$save_LDFLAGS" |
| 82 | + LIBS="$save_LIBS" |
| 83 | +
|
| 84 | + AC_SUBST([CAP_CFLAGS]) |
| 85 | + AC_SUBST([CAP_LIBS]) |
| 86 | + AC_SUBST([CAP_LDFLAGS]) |
| 87 | + ]) |
| 88 | + AM_CONDITIONAL(WITH_LIBCAP, test "x${with_libcap}" = "xyes") |
| 89 | +]) |
0 commit comments