5bf46a9e377ae08dfd6ac2d4cd1f4f4963dded4d
[platform/upstream/coreutils.git] / m4 / jm-macros.m4
1 #serial 104   -*- autoconf -*-
2
3 dnl Misc type-related macros for coreutils.
4
5 # Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
6 # Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 # Written by Jim Meyering.
23
24 AC_DEFUN([coreutils_MACROS],
25 [
26   GNU_PACKAGE="GNU $PACKAGE"
27   AC_DEFINE_UNQUOTED(GNU_PACKAGE, "$GNU_PACKAGE",
28     [The concatenation of the strings `GNU ', and PACKAGE.])
29   AC_SUBST(GNU_PACKAGE)
30
31   AM_MISSING_PROG(HELP2MAN, help2man)
32   AC_SUBST(OPTIONAL_BIN_PROGS)
33   AC_SUBST(MAN)
34   AC_SUBST(DF_PROG)
35
36   dnl This macro actually runs replacement code.  See isc-posix.m4.
37   AC_REQUIRE([AC_ISC_POSIX])dnl
38
39   gl_CHECK_ALL_TYPES
40
41   AC_REQUIRE([gl_CHECK_DECLS])
42
43   AC_REQUIRE([gl_PREREQ])
44
45   AC_REQUIRE([AC_FUNC_FSEEKO])
46
47   # By default, argmatch should fail calling usage (1).
48   AC_DEFINE(ARGMATCH_DIE, [usage (1)],
49             [Define to the function xargmatch calls on failures.])
50   AC_DEFINE(ARGMATCH_DIE_DECL, [extern void usage ()],
51             [Define to the declaration of the xargmatch failure function.])
52
53   dnl Used to define SETVBUF in ../src/system.h.
54   AC_FUNC_SETVBUF_REVERSED
55
56   # used by ls
57   AC_REQUIRE([gl_CLOCK_TIME])
58   # used by shred
59   AC_CHECK_FUNCS_ONCE(directio)
60
61   AC_CHECK_FUNCS_ONCE( \
62     endgrent \
63     endpwent \
64     fchown \
65     fchmod \
66     ftruncate \
67     iswspace \
68     mkfifo \
69     mbrlen \
70     setgroups \
71     sethostname \
72     siginterrupt \
73     sync \
74     sysctl \
75     sysinfo \
76     tcgetpgrp \
77   )
78
79   dnl This can't use AC_REQUIRE; I'm not quite sure why.
80   cu_PREREQ_STAT_PROG
81
82   # for dd.c and shred.c
83   coreutils_saved_libs=$LIBS
84     AC_SEARCH_LIBS([fdatasync], [rt posix4],
85                    [test "$ac_cv_search_fdatasync" = "none required" ||
86                     LIB_FDATASYNC=$ac_cv_search_fdatasync])
87     AC_SUBST([LIB_FDATASYNC])
88     AC_CHECK_FUNCS(fdatasync)
89   LIBS=$coreutils_saved_libs
90
91   # See if linking `seq' requires -lm.
92   # It does on nearly every system.  The single exception (so far) is
93   # BeOS which has all the math functions in the normal runtime library
94   # and doesn't have a separate math library.
95
96   AC_SUBST(SEQ_LIBM)
97   ac_seq_body='
98      static double x, y;
99      x = floor (x);
100      x = rint (x);
101      x = modf (x, &y);'
102   AC_TRY_LINK([#include <math.h>], $ac_seq_body, ,
103     [ac_seq_save_LIBS="$LIBS"
104      LIBS="$LIBS -lm"
105      AC_TRY_LINK([#include <math.h>], $ac_seq_body, SEQ_LIBM=-lm)
106      LIBS="$ac_seq_save_LIBS"
107     ])
108
109   AC_REQUIRE([AM_LANGINFO_CODESET])
110
111   # Build df only if there's a point to it.
112   if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
113     DF_PROG='df$(EXEEXT)'
114   fi
115
116   # If any of these functions don't exist (e.g. DJGPP 2.03),
117   # use the corresponding stub.
118   AC_CHECK_FUNC([fchdir], , [AC_LIBOBJ(fchdir-stub)])
119 ])
120
121 AC_DEFUN([gl_CHECK_ALL_HEADERS],
122 [
123   AC_CHECK_HEADERS_ONCE( \
124     hurd.h \
125     paths.h \
126     priv.h \
127     stropts.h \
128     sys/ioctl.h \
129     sys/param.h \
130     sys/resource.h \
131     sys/systeminfo.h \
132     sys/time.h \
133     sys/wait.h \
134     syslog.h \
135     termios.h \
136   )
137   AC_CHECK_HEADERS(sys/sysctl.h, [], [],
138     [AC_INCLUDES_DEFAULT
139      [#if HAVE_SYS_PARAM_H
140        #include <sys/param.h>
141       #endif]])
142 ])
143
144 # This macro must be invoked before any tests that run the compiler.
145 AC_DEFUN([gl_CHECK_ALL_TYPES],
146 [
147   dnl This test must come as early as possible after the compiler configuration
148   dnl tests, because the choice of the file model can (in principle) affect
149   dnl whether functions and headers are available, whether they work, etc.
150   AC_REQUIRE([AC_SYS_LARGEFILE])
151
152   dnl This test must precede tests of compiler characteristics like
153   dnl that for the inline keyword, since it may change the degree to
154   dnl which the compiler supports such features.
155   AC_REQUIRE([AM_C_PROTOTYPES])
156
157   dnl Checks for typedefs, structures, and compiler characteristics.
158   AC_REQUIRE([AC_C_BIGENDIAN])
159   AC_REQUIRE([AC_C_VOLATILE])
160   AC_REQUIRE([AC_C_INLINE])
161   AC_REQUIRE([AC_C_LONG_DOUBLE])
162   AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
163
164   AC_REQUIRE([gl_CHECK_ALL_HEADERS])
165   AC_CHECK_MEMBERS(
166     [struct stat.st_author],,,
167     [$ac_includes_default
168 #include <sys/stat.h>
169   ])
170   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
171
172   AC_REQUIRE([AC_TYPE_GETGROUPS])
173   AC_REQUIRE([AC_TYPE_MBSTATE_T])
174   AC_REQUIRE([AC_TYPE_MODE_T])
175   AC_REQUIRE([AC_TYPE_OFF_T])
176   AC_REQUIRE([AC_TYPE_PID_T])
177   AC_REQUIRE([AC_TYPE_SIZE_T])
178   AC_REQUIRE([AC_TYPE_UID_T])
179   AC_CHECK_TYPE(ino_t, unsigned long int)
180
181   dnl This relies on the fact that Autoconf's implementation of
182   dnl AC_CHECK_TYPE checks includes unistd.h.
183   AC_CHECK_TYPE(major_t, unsigned int)
184   AC_CHECK_TYPE(minor_t, unsigned int)
185
186   AC_REQUIRE([AC_HEADER_MAJOR])
187 ])