Merge from coreutils.
[gnulib.git] / m4 / jm-macros.m4
1 #serial 75   -*- autoconf -*-
2
3 dnl Misc type-related macros for coreutils.
4
5 # Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 # Written by Jim Meyering.
23
24 AC_DEFUN([gl_MACROS],
25 [
26   AC_PREREQ(2.58)
27
28   GNU_PACKAGE="GNU $PACKAGE"
29   AC_DEFINE_UNQUOTED(GNU_PACKAGE, "$GNU_PACKAGE",
30     [The concatenation of the strings `GNU ', and PACKAGE.])
31   AC_SUBST(GNU_PACKAGE)
32
33   AM_MISSING_PROG(HELP2MAN, help2man)
34   AC_SUBST(OPTIONAL_BIN_PROGS)
35   AC_SUBST(MAN)
36   AC_SUBST(DF_PROG)
37
38   dnl This macro actually runs replacement code.  See isc-posix.m4.
39   AC_REQUIRE([AC_ISC_POSIX])dnl
40
41   gl_CHECK_ALL_TYPES
42
43   AC_REQUIRE([gl_HOST_OS])
44   AC_REQUIRE([gl_ASSERT])
45   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
46   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])
47   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
48   AC_REQUIRE([gl_CHECK_DECLS])
49
50   AC_REQUIRE([gl_PREREQ])
51
52   AC_REQUIRE([gl_FUNC_DIRFD])
53   AC_REQUIRE([AC_FUNC_ACL])
54   AC_REQUIRE([gl_FUNC_LCHOWN])
55   AC_REQUIRE([fetish_FUNC_RMDIR_NOTEMPTY])
56   AC_REQUIRE([gl_FUNC_CHOWN])
57   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
58   AC_REQUIRE([AC_FUNC_STRERROR_R])
59   AC_REQUIRE([gl_FUNC_GROUP_MEMBER])
60   AC_REQUIRE([gl_AFS])
61   AC_REQUIRE([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK])
62   AC_REQUIRE([gl_FUNC_FPENDING])
63
64   # This is for od and stat, and any other program that
65   # uses the PRI.MAX macros from inttypes.h.
66   AC_REQUIRE([gt_INTTYPES_PRI])
67
68   AC_REQUIRE([gl_FUNC_GETGROUPS])
69
70   AC_REQUIRE([AC_FUNC_FSEEKO])
71   AC_REQUIRE([AC_FUNC_ALLOCA])
72
73   AC_CONFIG_LIBOBJ_DIR([lib])
74   AC_FUNC_GETLOADAVG([lib])
75
76   AC_REQUIRE([gl_SYS_PROC_UPTIME])
77   AC_REQUIRE([gl_FUNC_FTRUNCATE])
78
79   # raise is used by at least sort and ls.
80   AC_REPLACE_FUNCS(raise)
81
82   # By default, argmatch should fail calling usage (1).
83   AC_DEFINE(ARGMATCH_DIE, [usage (1)],
84             [Define to the function xargmatch calls on failures.])
85   AC_DEFINE(ARGMATCH_DIE_DECL, [extern void usage ()],
86             [Define to the declaration of the xargmatch failure function.])
87
88   dnl Used to define SETVBUF in sys2.h.
89   dnl This evokes the following warning from autoconf:
90   dnl ...: warning: AC_TRY_RUN called without default to allow cross compiling
91   AC_FUNC_SETVBUF_REVERSED
92
93   # used by sleep and shred
94   AC_REQUIRE([gl_CLOCK_TIME])
95   AC_CHECK_FUNCS_ONCE(gettimeofday)
96   AC_FUNC_GETTIMEOFDAY_CLOBBER
97   # used by shred
98   AC_CHECK_FUNCS_ONCE(directio)
99
100   AC_REQUIRE([AC_FUNC_CLOSEDIR_VOID])
101
102   AC_CHECK_FUNCS_ONCE( \
103     endgrent \
104     endpwent \
105     ftruncate \
106     gethrtime \
107     hasmntopt \
108     isascii \
109     iswspace \
110     lchown \
111     listmntent \
112     localeconv \
113     memcpy \
114     mempcpy \
115     mkfifo \
116     realpath \
117     sethostname \
118     strchr \
119     strerror \
120     strrchr \
121     sysctl \
122     sysinfo \
123     tcgetpgrp \
124     wcrtomb \
125     tzset \
126   )
127
128   AC_FUNC_STRTOD
129
130   AC_REQUIRE([cu_PREREQ_STAT_PROG])
131   AC_REQUIRE([GL_FUNC_GETCWD_PATH_MAX])
132   AC_REQUIRE([GL_FUNC_READDIR])
133
134   # for dd.c and shred.c
135   fetish_saved_libs=$LIBS
136     AC_SEARCH_LIBS([fdatasync], [rt posix4],
137                    [test "$ac_cv_search_fdatasync" = "none required" ||
138                     LIB_FDATASYNC=$ac_cv_search_fdatasync])
139     AC_SUBST([LIB_FDATASYNC])
140     AC_CHECK_FUNCS(fdatasync)
141   LIBS=$fetish_saved_libs
142
143   # See if linking `seq' requires -lm.
144   # It does on nearly every system.  The single exception (so far) is
145   # BeOS which has all the math functions in the normal runtime library
146   # and doesn't have a separate math library.
147
148   AC_SUBST(SEQ_LIBM)
149   ac_seq_body='
150      static double x, y;
151      x = floor (x);
152      x = rint (x);
153      x = modf (x, &y);'
154   AC_TRY_LINK([#include <math.h>], $ac_seq_body, ,
155     [ac_seq_save_LIBS="$LIBS"
156      LIBS="$LIBS -lm"
157      AC_TRY_LINK([#include <math.h>], $ac_seq_body, SEQ_LIBM=-lm)
158      LIBS="$ac_seq_save_LIBS"
159     ])
160
161   AM_LANGINFO_CODESET
162   gl_GLIBC21
163   AM_ICONV
164   gl_FUNC_UNLINK_BUSY_TEXT
165
166   # These tests are for df.
167   AC_REQUIRE([gl_FSUSAGE])
168   AC_REQUIRE([gl_MOUNTLIST])
169   if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
170     DF_PROG='df$(EXEEXT)'
171   fi
172   AC_REQUIRE([gl_AC_DOS])
173   AC_REQUIRE([AC_FUNC_CANONICALIZE_FILE_NAME])
174
175   # If any of these functions don't exist (e.g. DJGPP 2.03),
176   # use the corresponding stub.
177   AC_CHECK_FUNC([fchdir], , [AC_LIBOBJ(fchdir-stub)])
178
179   AC_REQUIRE([gl_FUNC_FREE])
180 ])
181
182 # These tests must be run before any use of AC_CHECK_TYPE,
183 # because that macro compiles code that tests e.g., HAVE_UNISTD_H.
184 # See the definition of ac_includes_default in `configure'.
185 AC_DEFUN([gl_CHECK_ALL_HEADERS],
186 [
187   AC_CHECK_HEADERS_ONCE( \
188     errno.h  \
189     fcntl.h \
190     float.h \
191     hurd.h \
192     limits.h \
193     memory.h \
194     mntent.h \
195     mnttab.h \
196     netdb.h \
197     paths.h \
198     stdlib.h \
199     stddef.h \
200     stdint.h \
201     string.h \
202     sys/filsys.h \
203     sys/fs/s5param.h \
204     sys/fs_types.h \
205     sys/fstyp.h \
206     sys/ioctl.h \
207     sys/mntent.h \
208     sys/param.h \
209     sys/resource.h \
210     sys/socket.h \
211     sys/statfs.h \
212     sys/statvfs.h \
213     sys/systeminfo.h \
214     sys/time.h \
215     sys/timeb.h \
216     sys/vfs.h \
217     sys/wait.h \
218     syslog.h \
219     termios.h \
220     unistd.h \
221     utime.h \
222   )
223   AC_CHECK_HEADERS(sys/mount.h sys/sysctl.h, [], [],
224     [AC_INCLUDES_DEFAULT
225      [#if HAVE_SYS_PARAM_H
226        #include <sys/param.h>
227       #endif]])
228 ])
229
230 # This macro must be invoked before any tests that run the compiler.
231 AC_DEFUN([gl_CHECK_ALL_TYPES],
232 [
233   dnl This test must come as early as possible after the compiler configuration
234   dnl tests, because the choice of the file model can (in principle) affect
235   dnl whether functions and headers are available, whether they work, etc.
236   AC_REQUIRE([AC_SYS_LARGEFILE])
237
238   dnl This test must precede tests of compiler characteristics like
239   dnl that for the inline keyword, since it may change the degree to
240   dnl which the compiler supports such features.
241   AC_REQUIRE([AM_C_PROTOTYPES])
242
243   dnl Checks for typedefs, structures, and compiler characteristics.
244   AC_REQUIRE([AC_C_BIGENDIAN])
245   AC_REQUIRE([AC_C_CONST])
246   AC_REQUIRE([AC_C_VOLATILE])
247   AC_REQUIRE([AC_C_INLINE])
248   AC_REQUIRE([AC_C_LONG_DOUBLE])
249
250   AC_REQUIRE([gl_CHECK_ALL_HEADERS])
251   AC_REQUIRE([AC_HEADER_DIRENT])
252   AC_REQUIRE([AC_HEADER_STDC])
253   AC_CHECK_MEMBERS(
254     [struct stat.st_author,
255      struct stat.st_blksize],,,
256     [$ac_includes_default
257 #include <sys/stat.h>
258   ])
259   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
260
261   AC_REQUIRE([AC_HEADER_STAT])
262   AC_REQUIRE([AC_STRUCT_ST_MTIM_NSEC])
263   AC_REQUIRE([AC_STRUCT_ST_DM_MODE])
264
265   AC_REQUIRE([AC_TYPE_GETGROUPS])
266   AC_REQUIRE([AC_TYPE_MODE_T])
267   AC_REQUIRE([AC_TYPE_OFF_T])
268   AC_REQUIRE([AC_TYPE_PID_T])
269   AC_REQUIRE([AC_TYPE_SIGNAL])
270   AC_REQUIRE([AC_TYPE_SIZE_T])
271   AC_REQUIRE([AC_TYPE_UID_T])
272   AC_CHECK_TYPE(ino_t, unsigned long int)
273
274   gt_TYPE_SSIZE_T
275
276   dnl This relies on the fact that autoconf 2.14a's implementation of
277   dnl AC_CHECK_TYPE checks includes unistd.h.
278   AC_CHECK_TYPE(major_t, unsigned int)
279   AC_CHECK_TYPE(minor_t, unsigned int)
280
281   AC_REQUIRE([gl_AC_TYPE_UINT32_T])
282   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
283   AC_REQUIRE([gl_AC_TYPE_UINTPTR_T])
284   AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG])
285
286   AC_REQUIRE([AC_HEADER_MAJOR])
287   AC_REQUIRE([AC_HEADER_DIRENT])
288
289 ])