1 # serial 5 -*- Autoconf -*-
2 # Copyright (C) 2006-2007, 2009-2020 Free Software Foundation, Inc.
3 # This file is free software; the Free Software Foundation
4 # gives unlimited permission to copy and/or distribute it,
5 # with or without modifications, as long as this notice is preserved.
8 # Provide <selinux/selinux.h>, if necessary.
9 # If it is already present, provide wrapper functions to guard against
10 # misbehavior from getfilecon, lgetfilecon, and fgetfilecon.
12 AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H],
14 AC_REQUIRE([gl_LIBSELINUX])
15 if test "$with_selinux" != no; then
16 AC_CHECK_HEADERS([selinux/selinux.h])
18 if test "$ac_cv_header_selinux_selinux_h" = yes; then
19 # We do have <selinux/selinux.h>, so do compile getfilecon.c
20 # and arrange to use its wrappers.
21 gl_CHECK_NEXT_HEADERS([selinux/selinux.h])
22 AC_DEFINE([getfilecon], [rpl_getfilecon],
23 [Always use our getfilecon wrapper.])
24 AC_DEFINE([lgetfilecon], [rpl_lgetfilecon],
25 [Always use our lgetfilecon wrapper.])
26 AC_DEFINE([fgetfilecon], [rpl_fgetfilecon],
27 [Always use our fgetfilecon wrapper.])
30 case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
31 no:*) # already warned
34 AC_MSG_WARN([libselinux was found but selinux/selinux.h is missing.])
35 AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])
38 # Do as if <selinux/selinux.h> does not exist, even if
39 # AC_CHECK_HEADERS_ONCE has already determined that it exists.
40 AC_DEFINE([HAVE_SELINUX_SELINUX_H], [0])
44 AC_DEFUN([gl_LIBSELINUX],
46 AC_REQUIRE([AC_CANONICAL_HOST])
47 AC_REQUIRE([AC_CANONICAL_BUILD])
49 AC_ARG_WITH([selinux],
50 AS_HELP_STRING([--without-selinux], [do not use SELinux, even on systems with SELinux]),
51 [], [with_selinux=maybe])
54 if test "$with_selinux" != no; then
56 AC_SEARCH_LIBS([setfilecon], [selinux],
57 [test "$ac_cv_search_setfilecon" = "none required" ||
58 LIB_SELINUX=$ac_cv_search_setfilecon])
61 AC_SUBST([LIB_SELINUX])
63 # Warn if SELinux is found but libselinux is absent;
64 if test "$ac_cv_search_setfilecon" = no; then
65 if test "$host" = "$build" && test -d /selinux; then
66 AC_MSG_WARN([This system supports SELinux but libselinux is missing.])
67 AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])