maint: Update after gnulib module 'readutmp' changed
[coreutils.git] / m4 / jm-macros.m4
blob0da7ae143eb69824629957ab864de350728f746a
1 #serial 114   -*- autoconf -*-
3 dnl Misc type-related macros for coreutils.
5 # Copyright (C) 1998-2023 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 <https://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   gl_CHECK_ALL_TYPES
29   AC_REQUIRE([gl_CHECK_DECLS])
31   AC_REQUIRE([gl_PREREQ])
33   AC_REQUIRE([AC_FUNC_FSEEKO])
35   # By default, argmatch should fail calling usage (EXIT_FAILURE).
36   AC_DEFINE([ARGMATCH_DIE], [usage (EXIT_FAILURE)],
37             [Define to the function xargmatch calls on failures.])
38   AC_DEFINE([ARGMATCH_DIE_DECL], [void usage (int _e)],
39             [Define to the declaration of the xargmatch failure function.])
41   # Ensure VLAs are not used.
42   # Note -Wvla is implicitly added by gl_MANYWARN_ALL_GCC
43   AC_DEFINE([GNULIB_NO_VLA], [1], [Define to 1 to disable use of VLAs])
45   # used by shred
46   AC_CHECK_FUNCS_ONCE([directio])
48   coreutils_saved_libs=$LIBS
49     LIBS="$LIBS $LIB_SELINUX"
50     # Used by selinux.c.
51     AC_CHECK_FUNCS([mode_to_security_class], [], [])
52   LIBS=$coreutils_saved_libs
54   # Used by sort.c.
55   AC_CHECK_FUNCS_ONCE([nl_langinfo])
56   # Used by timeout.c
57   AC_CHECK_FUNCS_ONCE([setitimer setrlimit prctl])
59   # Used by tail.c.
60   AC_CHECK_FUNCS([inotify_init],
61     [AC_DEFINE([HAVE_INOTIFY], [1],
62      [Define to 1 if you have usable inotify support.])])
64   AC_CHECK_FUNCS_ONCE([
65     endgrent
66     endpwent
67     fallocate
68     fchown
69     fchmod
70     ftruncate
71     iswspace
72     mkfifo
73     mbrlen
74     setgroups
75     sethostname
76     siginterrupt
77     sync
78     syncfs
79     sysctl
80     sysinfo
81     tcgetpgrp
82   ])
84   # These checks are for Interix, to avoid its getgr* functions, in favor
85   # of these replacements.  The replacement functions are much more efficient
86   # because they do not query the domain controller for user information
87   # when it is not needed.
88   AC_CHECK_FUNCS_ONCE([
89     getgrgid_nomembers
90     getgrnam_nomembers
91     getgrent_nomembers
92   ])
94   dnl This can't use AC_REQUIRE; I'm not quite sure why.
95   cu_PREREQ_STAT_PROG
97   # for dd.c and shred.c
98   #
99   # Use fdatasync only if declared.  On MacOS X 10.7, fdatasync exists but
100   # is not declared, and is ineffective.
101   LIB_FDATASYNC=
102   AC_SUBST([LIB_FDATASYNC])
103   AC_CHECK_DECLS_ONCE([fdatasync])
104   if test $ac_cv_have_decl_fdatasync = yes; then
105     coreutils_saved_libs=$LIBS
106     AC_SEARCH_LIBS([fdatasync], [rt posix4],
107                    [test "$ac_cv_search_fdatasync" = "none required" ||
108                     LIB_FDATASYNC=$ac_cv_search_fdatasync])
109     AC_CHECK_FUNCS([fdatasync])
110     LIBS=$coreutils_saved_libs
111   fi
113   # Check whether libcap is usable -- for ls --color support
114   LIB_CAP=
115   AC_ARG_ENABLE([libcap],
116     AS_HELP_STRING([--disable-libcap], [disable libcap support]))
117   if test "X$enable_libcap" != "Xno"; then
118     AC_CHECK_LIB([cap], [cap_get_file],
119       [AC_CHECK_HEADER([sys/capability.h],
120         [LIB_CAP=-lcap
121          AC_DEFINE([HAVE_CAP], [1], [libcap usability])]
122       )])
123     if test "X$LIB_CAP" = "X"; then
124       if test "X$enable_libcap" = "Xyes"; then
125         AC_MSG_ERROR([libcap library was not found or not usable])
126       else
127         AC_MSG_WARN([libcap library was not found or not usable.])
128         AC_MSG_WARN([AC_PACKAGE_NAME will be built without capability support.])
129       fi
130     fi
131   else
132     AC_MSG_WARN([libcap support disabled by user])
133   fi
134   AC_SUBST([LIB_CAP])
136   # See if linking 'seq' requires -lm.
137   # It does on nearly every system.  The single exception (so far) is
138   # BeOS which has all the math functions in the normal runtime library
139   # and doesn't have a separate math library.
141   AC_SUBST([SEQ_LIBM])
142   jm_break=:
143   for jm_seqlibs in '' '-lm'; do
144     jm_seq_save_LIBS=$LIBS
145     AC_LINK_IFELSE(
146       [AC_LANG_PROGRAM(
147          [[#include <math.h>
148          ]],
149          [[static double x, y;
150            x = floor (x);
151            x = rint (x);
152            x = modf (x, &y);]])],
153       [SEQ_LIBM=$jm_seqlibs
154        jm_break=break])
155     LIBS=$jm_seq_save_LIBS
156     $jm_break
157   done
159   # See is fpsetprec() required to use extended double precision
160   # This is needed on 32 bit FreeBSD to give accurate conversion of:
161   # `numfmt 9223372036854775808`
162   AC_LINK_IFELSE(
163     [AC_LANG_PROGRAM(
164        [[#include <ieeefp.h>
165        ]],
166        [[#ifdef __i386__
167           fpsetprec (FP_PE);
168          #else
169          # error not required on 64 bit
170          #endif
171        ]])],
172     [ac_have_fpsetprec=yes],
173     [ac_have_fpsetprec=no])
174   if test "$ac_have_fpsetprec" = "yes" ; then
175     AC_DEFINE([HAVE_FPSETPREC], 1, [whether fpsetprec is present and required])
176   fi
178   AC_REQUIRE([AM_LANGINFO_CODESET])
180   # Accept configure options: --with-tty-group[=GROUP], --without-tty-group
181   # You can determine the group of a TTY via 'stat --format %G /dev/tty'
182   # Omitting this option is equivalent to using --without-tty-group.
183   AC_ARG_WITH([tty-group],
184     AS_HELP_STRING([--with-tty-group[[[=NAME]]]],
185       [group used by system for TTYs, "tty" when not specified]
186       [ (default: do not rely on any group used for TTYs)]),
187     [tty_group_name=$withval],
188     [tty_group_name=no])
190   if test "x$tty_group_name" != xno; then
191     if test "x$tty_group_name" = xyes; then
192       tty_group_name=tty
193     fi
194     AC_MSG_NOTICE([TTY group used by system set to "$tty_group_name"])
195     AC_DEFINE_UNQUOTED([TTY_GROUP_NAME], ["$tty_group_name"],
196       [group used by system for TTYs])
197   fi
200 AC_DEFUN([gl_CHECK_ALL_HEADERS],
202   AC_CHECK_HEADERS_ONCE([
203     hurd.h
204     linux/falloc.h
205     linux/fs.h
206     paths.h
207     priv.h
208     stropts.h
209     sys/mtio.h
210     sys/param.h
211     sys/systeminfo.h
212     syslog.h
213   ])
214   AC_CHECK_HEADERS([sys/sysctl.h], [], [],
215     [AC_INCLUDES_DEFAULT
216      [#if HAVE_SYS_PARAM_H
217        #include <sys/param.h>
218       #endif]])
221 # This macro must be invoked before any tests that run the compiler.
222 AC_DEFUN([gl_CHECK_ALL_TYPES],
224   dnl Checks for typedefs, structures, and compiler characteristics.
225   AC_REQUIRE([gl_BIGENDIAN])
226   AC_REQUIRE([AC_C_VOLATILE])
227   AC_REQUIRE([AC_C_INLINE])
228   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
230   AC_REQUIRE([gl_CHECK_ALL_HEADERS])
231   AC_CHECK_MEMBERS(
232     [struct stat.st_author],,,
233     [$ac_includes_default
234 #include <sys/stat.h>
235   ])
236   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
238   AC_REQUIRE([AC_TYPE_GETGROUPS])
239   AC_REQUIRE([AC_TYPE_MBSTATE_T])
240   AC_REQUIRE([AC_TYPE_MODE_T])
241   AC_REQUIRE([AC_TYPE_OFF_T])
242   AC_REQUIRE([AC_TYPE_PID_T])
243   AC_REQUIRE([AC_TYPE_SIZE_T])
244   AC_REQUIRE([AC_TYPE_UID_T])
245   AC_CHECK_TYPE([ino_t], [unsigned long int])
247   dnl This relies on the fact that Autoconf's implementation of
248   dnl AC_CHECK_TYPE checks includes unistd.h.
249   AC_CHECK_TYPE([major_t], [unsigned int])
250   AC_CHECK_TYPE([minor_t], [unsigned int])
252   AC_REQUIRE([AC_HEADER_MAJOR])