bootstrap: Avoid failure when gnulib-tool removed gettext.m4.
[gnulib.git] / m4 / selinux-selinux-h.m4
blob91fdc434f2e5bc5de2b351f441eb4375ea31c092
1 # selinux-selinux-h.m4
2 # serial 8   -*- Autoconf -*-
3 dnl Copyright (C) 2006-2007, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # From Jim Meyering
9 # Provide <selinux/selinux.h>, if necessary.
10 # If it is already present, provide wrapper functions to guard against
11 # misbehavior from getfilecon, lgetfilecon, and fgetfilecon.
13 AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H],
15   AC_REQUIRE([gl_LIBSELINUX])
16   if test "$with_selinux" != no; then
17     AC_CHECK_HEADERS([selinux/selinux.h])
19     if test $ac_cv_header_selinux_selinux_h = yes; then
20       HAVE_SELINUX_SELINUX_H=1
21     else
22       HAVE_SELINUX_SELINUX_H=0
23     fi
25     if test "$ac_cv_header_selinux_selinux_h" = yes; then
26       # We do have <selinux/selinux.h>, so do compile getfilecon.c
27       # and arrange to use its wrappers.
28       gl_CHECK_NEXT_HEADERS([selinux/selinux.h])
29       AC_DEFINE([getfilecon], [rpl_getfilecon],
30                 [Always use our getfilecon wrapper.])
31       AC_DEFINE([getfilecon_raw], [rpl_getfilecon_raw],
32                 [Always use our getfilecon_raw wrapper.])
33       AC_DEFINE([lgetfilecon], [rpl_lgetfilecon],
34                 [Always use our lgetfilecon wrapper.])
35       AC_DEFINE([lgetfilecon_raw], [rpl_lgetfilecon_raw],
36                 [Always use our lgetfilecon_raw wrapper.])
37       AC_DEFINE([fgetfilecon], [rpl_fgetfilecon],
38                 [Always use our fgetfilecon wrapper.])
39       AC_DEFINE([fgetfilecon_raw], [rpl_fgetfilecon_raw],
40                 [Always use our fgetfilecon_raw wrapper.])
41     fi
43     case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
44       no:*) # already warned
45         ;;
46       *:no)
47         AC_MSG_WARN([libselinux was found but selinux/selinux.h is missing.])
48         AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])
49     esac
50   else
51     # Do as if <selinux/selinux.h> does not exist, even if
52     # AC_CHECK_HEADERS_ONCE has already determined that it exists.
53     HAVE_SELINUX_SELINUX_H=0
54   fi
55   AC_SUBST([HAVE_SELINUX_SELINUX_H])
58 AC_DEFUN([gl_LIBSELINUX],
60   AC_REQUIRE([AC_CANONICAL_HOST])
61   AC_REQUIRE([AC_CANONICAL_BUILD])
63   AC_ARG_WITH([selinux],
64     AS_HELP_STRING([[--without-selinux]], [do not use SELinux, even on systems with SELinux]),
65     [], [with_selinux=maybe])
67   LIB_SELINUX=
68   if test "$with_selinux" != no; then
69     gl_saved_LIBS=$LIBS
70     AC_SEARCH_LIBS([setfilecon], [selinux],
71                    [test "$ac_cv_search_setfilecon" = "none required" ||
72                     LIB_SELINUX=$ac_cv_search_setfilecon])
73     LIBS=$gl_saved_LIBS
74   fi
75   AC_SUBST([LIB_SELINUX])
77   # Warn if SELinux is found but libselinux is absent;
78   if test "$ac_cv_search_setfilecon" = no; then
79     if test "$host" = "$build" && test -d /selinux; then
80       AC_MSG_WARN([This system supports SELinux but libselinux is missing.])
81       AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.])
82     fi
83     with_selinux=no
84   fi