update nearly all FSF copyright year lists to include 2009
[gnulib.git] / m4 / selinux-selinux-h.m4
1 # serial 3   -*- Autoconf -*-
2 # Copyright (C) 2006-2007, 2009 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.
6
7 # From Jim Meyering
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.
11
12 AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H],
13 [
14   AC_REQUIRE([gl_LIBSELINUX])
15   AC_CHECK_HEADERS([selinux/selinux.h])
16
17   if test "$ac_cv_header_selinux_selinux_h" = yes; then
18     # We do have <selinux/selinux.h>, so do compile getfilecon.c
19     # and arrange to use its wrappers.
20     AC_LIBOBJ([getfilecon])
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.])
28   fi
29
30   case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
31     no:*) # already warned
32       ;;
33     *:no)
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.])
36   esac
37 ])
38
39 AC_DEFUN([gl_LIBSELINUX],
40 [
41   AC_REQUIRE([AC_CANONICAL_HOST])
42   AC_REQUIRE([AC_CANONICAL_BUILD])
43   LIB_SELINUX=
44   gl_save_LIBS=$LIBS
45   AC_SEARCH_LIBS([setfilecon], [selinux],
46                  [test "$ac_cv_search_setfilecon" = "none required" ||
47                   LIB_SELINUX=$ac_cv_search_setfilecon])
48   AC_SUBST([LIB_SELINUX])
49   LIBS=$gl_save_LIBS
50
51   # Warn if SELinux is found but libselinux is absent;
52   if test "$ac_cv_search_setfilecon" = no &&
53      test "$host" = "$build" && test -d /selinux; then
54     AC_MSG_WARN([This system supports SELinux but libselinux is missing.])
55     AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])
56   fi
57 ])