1 # serial 4 -*- Autoconf -*-
2 # Copyright (C) 2006-2007, 2009-2010 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 AC_LIBOBJ([getfilecon])
22 gl_CHECK_NEXT_HEADERS([selinux/selinux.h])
23 AC_DEFINE([getfilecon], [rpl_getfilecon],
24 [Always use our getfilecon wrapper.])
25 AC_DEFINE([lgetfilecon], [rpl_lgetfilecon],
26 [Always use our lgetfilecon wrapper.])
27 AC_DEFINE([fgetfilecon], [rpl_fgetfilecon],
28 [Always use our fgetfilecon wrapper.])
31 case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
32 no:*) # already warned
35 AC_MSG_WARN([libselinux was found but selinux/selinux.h is missing.])
36 AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])
39 # Do as if <selinux/selinux.h> does not exist, even if
40 # AC_CHECK_HEADERS_ONCE has already determined that it exists.
41 AC_DEFINE([HAVE_SELINUX_SELINUX_H], [0])
45 AC_DEFUN([gl_LIBSELINUX],
47 AC_REQUIRE([AC_CANONICAL_HOST])
48 AC_REQUIRE([AC_CANONICAL_BUILD])
50 AC_ARG_WITH([selinux],
51 AS_HELP_STRING([--without-selinux], [do not use SELinux, even on systems with SELinux]),
52 [], [with_selinux=maybe])
55 if test "$with_selinux" != no; then
57 AC_SEARCH_LIBS([setfilecon], [selinux],
58 [test "$ac_cv_search_setfilecon" = "none required" ||
59 LIB_SELINUX=$ac_cv_search_setfilecon])
62 AC_SUBST([LIB_SELINUX])
64 # Warn if SELinux is found but libselinux is absent;
65 if test "$ac_cv_search_setfilecon" = no &&
66 test "$host" = "$build" && test -d /selinux; then
67 AC_MSG_WARN([This system supports SELinux but libselinux is missing.])
68 AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])