build: update gnulib submodule to latest
[coreutils.git] / m4 / jm-macros.m4
blob51c533a42ab442f90cc010f8a509b65bcf522af6
1 #serial 110   -*- autoconf -*-
3 dnl Misc type-related macros for coreutils.
5 # Copyright (C) 1998-2015 Free Software Foundation, Inc.
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.
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.
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/>.
20 # Written by Jim Meyering.
22 AC_DEFUN([coreutils_MACROS],
24   AM_MISSING_PROG(HELP2MAN, help2man)
25   AC_SUBST([MAN])
27   dnl This macro actually runs replacement code.  See isc-posix.m4.
28   AC_REQUIRE([AC_ISC_POSIX])dnl
30   gl_CHECK_ALL_TYPES
32   AC_REQUIRE([gl_CHECK_DECLS])
34   AC_REQUIRE([gl_PREREQ])
36   AC_REQUIRE([AC_FUNC_FSEEKO])
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.])
44   # used by shred
45   AC_CHECK_FUNCS_ONCE([directio])
47   coreutils_saved_libs=$LIBS
48     LIBS="$LIBS $LIB_SELINUX"
49     # Used by selinux.c.
50     AC_CHECK_FUNCS([mode_to_security_class], [], [])
51     # Used by install.c.
52     AC_CHECK_FUNCS([matchpathcon_init_prefix], [],
53     [
54       if test "$with_selinux" != no; then
55         case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in
56           no:*) # SELinux disabled
57             ;;
58           *:no) # SELinux disabled
59             ;;
60           *)
61           AC_MSG_WARN([SELinux enabled, but matchpathcon_init_prefix not found])
62           AC_MSG_WARN([The install utility may run slowly])
63         esac
64       fi
65     ])
66   LIBS=$coreutils_saved_libs
68   # Used by sort.c.
69   AC_CHECK_FUNCS_ONCE([nl_langinfo])
70   # Used by timeout.c
71   AC_CHECK_FUNCS_ONCE([setrlimit prctl])
73   # Used by tail.c.
74   AC_CHECK_FUNCS([inotify_init],
75     [AC_DEFINE([HAVE_INOTIFY], [1],
76      [Define to 1 if you have usable inotify support.])])
78   AC_CHECK_FUNCS_ONCE([
79     endgrent
80     endpwent
81     fallocate
82     fchown
83     fchmod
84     ftruncate
85     iswspace
86     mkfifo
87     mbrlen
88     setgroups
89     sethostname
90     siginterrupt
91     sync
92     syncfs
93     sysctl
94     sysinfo
95     tcgetpgrp
96   ])
98   # These checks are for Interix, to avoid its getgr* functions, in favor
99   # of these replacements.  The replacement functions are much more efficient
100   # because they do not query the domain controller for user information
101   # when it is not needed.
102   AC_CHECK_FUNCS_ONCE([
103     getgrgid_nomembers
104     getgrnam_nomembers
105     getgrent_nomembers
106   ])
108   dnl This can't use AC_REQUIRE; I'm not quite sure why.
109   cu_PREREQ_STAT_PROG
111   # for dd.c and shred.c
112   #
113   # Use fdatasync only if declared.  On MacOS X 10.7, fdatasync exists but
114   # is not declared, and is ineffective.
115   LIB_FDATASYNC=
116   AC_SUBST([LIB_FDATASYNC])
117   AC_CHECK_DECLS_ONCE([fdatasync])
118   if test $ac_cv_have_decl_fdatasync = yes; then
119     coreutils_saved_libs=$LIBS
120     AC_SEARCH_LIBS([fdatasync], [rt posix4],
121                    [test "$ac_cv_search_fdatasync" = "none required" ||
122                     LIB_FDATASYNC=$ac_cv_search_fdatasync])
123     AC_CHECK_FUNCS([fdatasync])
124     LIBS=$coreutils_saved_libs
125   fi
127   # Check whether libcap is usable -- for ls --color support
128   LIB_CAP=
129   AC_ARG_ENABLE([libcap],
130     AC_HELP_STRING([--disable-libcap], [disable libcap support]))
131   if test "X$enable_libcap" != "Xno"; then
132     AC_CHECK_LIB([cap], [cap_get_file],
133       [AC_CHECK_HEADER([sys/capability.h],
134         [LIB_CAP=-lcap
135          AC_DEFINE([HAVE_CAP], [1], [libcap usability])]
136       )])
137     if test "X$LIB_CAP" = "X"; then
138       if test "X$enable_libcap" = "Xyes"; then
139         AC_MSG_ERROR([libcap library was not found or not usable])
140       else
141         AC_MSG_WARN([libcap library was not found or not usable.])
142         AC_MSG_WARN([AC_PACKAGE_NAME will be built without capability support.])
143       fi
144     fi
145   else
146     AC_MSG_WARN([libcap support disabled by user])
147   fi
148   AC_SUBST([LIB_CAP])
150   # See if linking 'seq' requires -lm.
151   # It does on nearly every system.  The single exception (so far) is
152   # BeOS which has all the math functions in the normal runtime library
153   # and doesn't have a separate math library.
155   AC_SUBST([SEQ_LIBM])
156   ac_seq_body='
157      static double x, y;
158      x = floor (x);
159      x = rint (x);
160      x = modf (x, &y);'
161   AC_TRY_LINK([#include <math.h>], [$ac_seq_body], ,
162     [ac_seq_save_LIBS="$LIBS"
163      LIBS="$LIBS -lm"
164      AC_TRY_LINK([#include <math.h>], [$ac_seq_body], [SEQ_LIBM=-lm])
165      LIBS="$ac_seq_save_LIBS"
166     ])
169   # See is fpsetprec() required to use extended double precision
170   # This is needed on 32 bit FreeBSD to give accurate conversion of:
171   # `numfmt 9223372036854775808`
172   AC_TRY_LINK([#include <ieeefp.h>],
173     [#ifdef __i386__
174       fpsetprec(FP_PE);
175      #else
176      # error not required on 64 bit
177      #endif
178     ], [ac_have_fpsetprec=yes], [ac_have_fpsetprec=no])
179   if test "$ac_have_fpsetprec" = "yes" ; then
180     AC_DEFINE([HAVE_FPSETPREC], 1, [whether fpsetprec is present and required])
181   fi
183   AC_REQUIRE([AM_LANGINFO_CODESET])
185   # Accept configure options: --with-tty-group[=GROUP], --without-tty-group
186   # You can determine the group of a TTY via 'stat --format %G /dev/tty'
187   # Omitting this option is equivalent to using --without-tty-group.
188   AC_ARG_WITH([tty-group],
189     AS_HELP_STRING([--with-tty-group[[[=NAME]]]],
190       [group used by system for TTYs, "tty" when not specified]
191       [ (default: do not rely on any group used for TTYs)]),
192     [tty_group_name=$withval],
193     [tty_group_name=no])
195   if test "x$tty_group_name" != xno; then
196     if test "x$tty_group_name" = xyes; then
197       tty_group_name=tty
198     fi
199     AC_MSG_NOTICE([TTY group used by system set to "$tty_group_name"])
200     AC_DEFINE_UNQUOTED([TTY_GROUP_NAME], ["$tty_group_name"],
201       [group used by system for TTYs])
202   fi
205 AC_DEFUN([gl_CHECK_ALL_HEADERS],
207   AC_CHECK_HEADERS_ONCE([
208     hurd.h
209     linux/falloc.h
210     paths.h
211     priv.h
212     stropts.h
213     sys/param.h
214     sys/systeminfo.h
215     syslog.h
216   ])
217   AC_CHECK_HEADERS([sys/sysctl.h], [], [],
218     [AC_INCLUDES_DEFAULT
219      [#if HAVE_SYS_PARAM_H
220        #include <sys/param.h>
221       #endif]])
224 # This macro must be invoked before any tests that run the compiler.
225 AC_DEFUN([gl_CHECK_ALL_TYPES],
227   dnl Checks for typedefs, structures, and compiler characteristics.
228   AC_REQUIRE([gl_BIGENDIAN])
229   AC_REQUIRE([AC_C_VOLATILE])
230   AC_REQUIRE([AC_C_INLINE])
231   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
233   AC_REQUIRE([gl_CHECK_ALL_HEADERS])
234   AC_CHECK_MEMBERS(
235     [struct stat.st_author],,,
236     [$ac_includes_default
237 #include <sys/stat.h>
238   ])
239   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
241   AC_REQUIRE([AC_TYPE_GETGROUPS])
242   AC_REQUIRE([AC_TYPE_MBSTATE_T])
243   AC_REQUIRE([AC_TYPE_MODE_T])
244   AC_REQUIRE([AC_TYPE_OFF_T])
245   AC_REQUIRE([AC_TYPE_PID_T])
246   AC_REQUIRE([AC_TYPE_SIZE_T])
247   AC_REQUIRE([AC_TYPE_UID_T])
248   AC_CHECK_TYPE([ino_t], [unsigned long int])
250   dnl This relies on the fact that Autoconf's implementation of
251   dnl AC_CHECK_TYPE checks includes unistd.h.
252   AC_CHECK_TYPE([major_t], [unsigned int])
253   AC_CHECK_TYPE([minor_t], [unsigned int])
255   AC_REQUIRE([AC_HEADER_MAJOR])