id: with -Z, show SMACK security context
[platform/upstream/coreutils.git] / m4 / jm-macros.m4
1 #serial 110   -*- autoconf -*-
2
3 dnl Misc type-related macros for coreutils.
4
5 # Copyright (C) 1998-2013 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # Written by Jim Meyering.
21
22 AC_DEFUN([coreutils_MACROS],
23 [
24   AM_MISSING_PROG(HELP2MAN, help2man)
25   AC_SUBST([MAN])
26
27   dnl This macro actually runs replacement code.  See isc-posix.m4.
28   AC_REQUIRE([AC_ISC_POSIX])dnl
29
30   gl_CHECK_ALL_TYPES
31
32   AC_REQUIRE([gl_CHECK_DECLS])
33
34   AC_REQUIRE([gl_PREREQ])
35
36   AC_REQUIRE([AC_FUNC_FSEEKO])
37
38   # By default, argmatch should fail calling usage (EXIT_FAILURE).
39   AC_DEFINE([ARGMATCH_DIE], [usage (EXIT_FAILURE)],
40             [Define to the function xargmatch calls on failures.])
41   AC_DEFINE([ARGMATCH_DIE_DECL], [void usage (int _e)],
42             [Define to the declaration of the xargmatch failure function.])
43
44   # used by shred
45   AC_CHECK_FUNCS_ONCE([directio])
46
47   # Used by install.c.
48   coreutils_saved_libs=$LIBS
49     LIBS="$LIBS $LIB_SELINUX"
50     AC_CHECK_FUNCS([matchpathcon_init_prefix], [],
51     [
52       case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
53         no:*) # SELinux disabled
54           ;;
55         *:no) # SELinux disabled
56           ;;
57         *)
58         AC_MSG_WARN([SELinux enabled, but matchpathcon_init_prefix not found])
59         AC_MSG_WARN([The install utility may run slowly])
60       esac
61     ])
62   LIBS=$coreutils_saved_libs
63
64   # Used by sort.c.
65   AC_CHECK_FUNCS_ONCE([nl_langinfo])
66   # Used by timeout.c
67   AC_CHECK_FUNCS_ONCE([setrlimit prctl])
68
69   # Used by tail.c.
70   AC_CHECK_FUNCS([inotify_init],
71     [AC_DEFINE([HAVE_INOTIFY], [1],
72      [Define to 1 if you have usable inotify support.])])
73
74   AC_CHECK_FUNCS_ONCE([
75     endgrent
76     endpwent
77     fchown
78     fchmod
79     ftruncate
80     iswspace
81     mkfifo
82     mbrlen
83     setgroups
84     sethostname
85     siginterrupt
86     sync
87     sysctl
88     sysinfo
89     tcgetpgrp
90   ])
91
92   # These checks are for Interix, to avoid its getgr* functions, in favor
93   # of these replacements.  The replacement functions are much more efficient
94   # because they do not query the domain controller for user information
95   # when it is not needed.
96   AC_CHECK_FUNCS_ONCE([
97     getgrgid_nomembers
98     getgrnam_nomembers
99     getgrent_nomembers
100   ])
101
102   dnl This can't use AC_REQUIRE; I'm not quite sure why.
103   cu_PREREQ_STAT_PROG
104
105   # for dd.c and shred.c
106   #
107   # Use fdatasync only if declared.  On MacOS X 10.7, fdatasync exists but
108   # is not declared, and is ineffective.
109   LIB_FDATASYNC=
110   AC_SUBST([LIB_FDATASYNC])
111   AC_CHECK_DECLS_ONCE([fdatasync])
112   if test $ac_cv_have_decl_fdatasync = yes; then
113     coreutils_saved_libs=$LIBS
114     AC_SEARCH_LIBS([fdatasync], [rt posix4],
115                    [test "$ac_cv_search_fdatasync" = "none required" ||
116                     LIB_FDATASYNC=$ac_cv_search_fdatasync])
117     AC_CHECK_FUNCS([fdatasync])
118     LIBS=$coreutils_saved_libs
119   fi
120
121   # Check whether libcap is usable -- for ls --color support
122   LIB_CAP=
123   AC_ARG_ENABLE([libcap],
124     AC_HELP_STRING([--disable-libcap], [disable libcap support]))
125   if test "X$enable_libcap" != "Xno"; then
126     AC_CHECK_LIB([cap], [cap_get_file],
127       [AC_CHECK_HEADER([sys/capability.h],
128         [LIB_CAP=-lcap
129          AC_DEFINE([HAVE_CAP], [1], [libcap usability])]
130       )])
131     if test "X$LIB_CAP" = "X"; then
132       if test "X$enable_libcap" = "Xyes"; then
133         AC_MSG_ERROR([libcap library was not found or not usable])
134       else
135         AC_MSG_WARN([libcap library was not found or not usable.])
136         AC_MSG_WARN([AC_PACKAGE_NAME will be built without capability support.])
137       fi
138     fi
139   else
140     AC_MSG_WARN([libcap support disabled by user])
141   fi
142   AC_SUBST([LIB_CAP])
143
144   # Check whether libsmack is available
145   LIB_SMACK=
146   AC_ARG_ENABLE([libsmack],
147     AC_HELP_STRING([--disable-libsmack], [disable libsmack support]))
148   if test "X$enable_libsmack" != "Xno"; then
149     AC_CHECK_LIB([smack], [smack_smackfs_path],
150       [AC_CHECK_HEADER([sys/smack.h],
151         [LIB_SMACK=-lsmack
152          AC_DEFINE([HAVE_SMACK], [1], [libsmack usability])]
153       )])
154     if test "X$LIB_SMACK" = "X"; then
155       if test "X$enable_libsmack" = "Xyes"; then
156         AC_MSG_ERROR([libsmack library was not found or not usable])
157       fi
158     fi
159   else
160     AC_MSG_WARN([libsmack support disabled by user])
161   fi
162   AC_SUBST([LIB_SMACK])
163
164   # See if linking 'seq' requires -lm.
165   # It does on nearly every system.  The single exception (so far) is
166   # BeOS which has all the math functions in the normal runtime library
167   # and doesn't have a separate math library.
168
169   AC_SUBST([SEQ_LIBM])
170   ac_seq_body='
171      static double x, y;
172      x = floor (x);
173      x = rint (x);
174      x = modf (x, &y);'
175   AC_TRY_LINK([#include <math.h>], [$ac_seq_body], ,
176     [ac_seq_save_LIBS="$LIBS"
177      LIBS="$LIBS -lm"
178      AC_TRY_LINK([#include <math.h>], [$ac_seq_body], [SEQ_LIBM=-lm])
179      LIBS="$ac_seq_save_LIBS"
180     ])
181
182   AC_REQUIRE([AM_LANGINFO_CODESET])
183
184   # Accept configure options: --with-tty-group[=GROUP], --without-tty-group
185   # You can determine the group of a TTY via 'stat --format %G /dev/tty'
186   # Omitting this option is equivalent to using --without-tty-group.
187   AC_ARG_WITH([tty-group],
188     AS_HELP_STRING([--with-tty-group[[[=NAME]]]],
189       [group used by system for TTYs, "tty" when not specified]
190       [ (default: do not rely on any group used for TTYs)]),
191     [tty_group_name=$withval],
192     [tty_group_name=no])
193
194   if test "x$tty_group_name" != xno; then
195     if test "x$tty_group_name" = xyes; then
196       tty_group_name=tty
197     fi
198     AC_MSG_NOTICE([TTY group used by system set to "$tty_group_name"])
199     AC_DEFINE_UNQUOTED([TTY_GROUP_NAME], ["$tty_group_name"],
200       [group used by system for TTYs])
201   fi
202 ])
203
204 AC_DEFUN([gl_CHECK_ALL_HEADERS],
205 [
206   AC_CHECK_HEADERS_ONCE([
207     hurd.h
208     paths.h
209     priv.h
210     stropts.h
211     sys/param.h
212     sys/systeminfo.h
213     syslog.h
214   ])
215   AC_CHECK_HEADERS([sys/sysctl.h], [], [],
216     [AC_INCLUDES_DEFAULT
217      [#if HAVE_SYS_PARAM_H
218        #include <sys/param.h>
219       #endif]])
220 ])
221
222 # This macro must be invoked before any tests that run the compiler.
223 AC_DEFUN([gl_CHECK_ALL_TYPES],
224 [
225   dnl Checks for typedefs, structures, and compiler characteristics.
226   AC_REQUIRE([gl_BIGENDIAN])
227   AC_REQUIRE([AC_C_VOLATILE])
228   AC_REQUIRE([AC_C_INLINE])
229   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
230
231   AC_REQUIRE([gl_CHECK_ALL_HEADERS])
232   AC_CHECK_MEMBERS(
233     [struct stat.st_author],,,
234     [$ac_includes_default
235 #include <sys/stat.h>
236   ])
237   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
238
239   AC_REQUIRE([AC_TYPE_GETGROUPS])
240   AC_REQUIRE([AC_TYPE_MBSTATE_T])
241   AC_REQUIRE([AC_TYPE_MODE_T])
242   AC_REQUIRE([AC_TYPE_OFF_T])
243   AC_REQUIRE([AC_TYPE_PID_T])
244   AC_REQUIRE([AC_TYPE_SIZE_T])
245   AC_REQUIRE([AC_TYPE_UID_T])
246   AC_CHECK_TYPE([ino_t], [unsigned long int])
247
248   dnl This relies on the fact that Autoconf's implementation of
249   dnl AC_CHECK_TYPE checks includes unistd.h.
250   AC_CHECK_TYPE([major_t], [unsigned int])
251   AC_CHECK_TYPE([minor_t], [unsigned int])
252
253   AC_REQUIRE([AC_HEADER_MAJOR])
254 ])