Assume <string.h> exists,
[gnulib.git] / m4 / jm-macros.m4
1 #serial 68   -*- autoconf -*-
2
3 m4_undefine([AC_LANG_SOURCE(C)])
4 dnl The following is identical to the definition in c.m4
5 dnl from the autoconf cvs repository on 2003-03-07.
6 dnl FIXME: remove this code once we upgrade to autoconf-2.58.
7
8 # We can't use '#line $LINENO "configure"' here, since
9 # Sun c89 (Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09)
10 # rejects $LINENO greater than 32767, and some configure scripts
11 # are longer than 32767 lines.
12 m4_define([AC_LANG_SOURCE(C)],
13 [/* confdefs.h.  */
14 _ACEOF
15 cat confdefs.h >>conftest.$ac_ext
16 cat >>conftest.$ac_ext <<_ACEOF
17 /* end confdefs.h.  */
18 $1])
19
20
21 dnl Misc type-related macros for fileutils, sh-utils, textutils.
22
23 AC_DEFUN([jm_MACROS],
24 [
25   AC_PREREQ(2.57)
26
27   GNU_PACKAGE="GNU $PACKAGE"
28   AC_DEFINE_UNQUOTED(GNU_PACKAGE, "$GNU_PACKAGE",
29     [The concatenation of the strings `GNU ', and PACKAGE.])
30   AC_SUBST(GNU_PACKAGE)
31
32   AM_MISSING_PROG(HELP2MAN, help2man)
33   AC_SUBST(OPTIONAL_BIN_PROGS)
34   AC_SUBST(MAN)
35   AC_SUBST(DF_PROG)
36
37   dnl This macro actually runs replacement code.  See isc-posix.m4.
38   AC_REQUIRE([AC_ISC_POSIX])dnl
39
40   jm_CHECK_ALL_TYPES
41
42   AC_REQUIRE([UTILS_HOST_OS])
43   AC_REQUIRE([jm_ASSERT])
44   AC_REQUIRE([jm_CHECK_TYPE_STRUCT_UTIMBUF])
45   AC_REQUIRE([jm_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])
46   AC_REQUIRE([jm_CHECK_TYPE_STRUCT_DIRENT_D_INO])
47   AC_REQUIRE([jm_CHECK_DECLS])
48
49   AC_REQUIRE([jm_PREREQ])
50
51   AC_REQUIRE([UTILS_FUNC_DIRFD])
52   AC_REQUIRE([AC_FUNC_ACL])
53   AC_REQUIRE([AC_FUNC_FTW])
54   AC_REQUIRE([jm_FUNC_LCHOWN])
55   AC_REQUIRE([fetish_FUNC_RMDIR_NOTEMPTY])
56   AC_REQUIRE([jm_FUNC_CHOWN])
57   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
58   AC_REQUIRE([AC_FUNC_STRERROR_R])
59   AC_REQUIRE([jm_FUNC_GROUP_MEMBER])
60   AC_REQUIRE([jm_AFS])
61   AC_REQUIRE([jm_AC_FUNC_LINK_FOLLOWS_SYMLINK])
62   AC_REQUIRE([jm_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([jm_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([jm_SYS_PROC_UPTIME])
77   AC_REQUIRE([jm_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(gettimeofday)
96   AC_FUNC_GETTIMEOFDAY_CLOBBER
97
98   AC_REQUIRE([AC_FUNC_CLOSEDIR_VOID])
99
100   AC_CHECK_FUNCS( \
101     endgrent \
102     endpwent \
103     fdatasync \
104     ftruncate \
105     gethrtime \
106     hasmntopt \
107     isascii \
108     iswspace \
109     lchown \
110     listmntent \
111     localeconv \
112     memcpy \
113     mempcpy \
114     mkfifo \
115     realpath \
116     sethostname \
117     strchr \
118     strerror \
119     strrchr \
120     sysctl \
121     sysinfo \
122     wcrtomb \
123     tzset \
124   )
125
126   # for test.c
127   AC_CHECK_FUNCS(setreuid setregid)
128
129   AC_FUNC_STRTOD
130   AC_REQUIRE([UTILS_SYS_OPEN_MAX])
131   AC_REQUIRE([GL_FUNC_GETCWD_PATH_MAX])
132   AC_REQUIRE([GL_FUNC_READDIR])
133
134   # See if linking `seq' requires -lm.
135   # It does on nearly every system.  The single exception (so far) is
136   # BeOS which has all the math functions in the normal runtime library
137   # and doesn't have a separate math library.
138
139   AC_SUBST(SEQ_LIBM)
140   ac_seq_body='
141      static double x, y;
142      x = floor (x);
143      x = rint (x);
144      x = modf (x, &y);'
145   AC_TRY_LINK([#include <math.h>], $ac_seq_body, ,
146     [ac_seq_save_LIBS="$LIBS"
147      LIBS="$LIBS -lm"
148      AC_TRY_LINK([#include <math.h>], $ac_seq_body, SEQ_LIBM=-lm)
149      LIBS="$ac_seq_save_LIBS"
150     ])
151
152   AM_LANGINFO_CODESET
153   jm_GLIBC21
154   AM_ICONV
155   jm_FUNC_UNLINK_BUSY_TEXT
156
157   # These tests are for df.
158   AC_REQUIRE([gl_FSUSAGE])
159   AC_REQUIRE([gl_MOUNTLIST])
160   if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
161     DF_PROG='df$(EXEEXT)'
162   fi
163   AC_REQUIRE([jm_AC_DOS])
164   AC_REQUIRE([AC_FUNC_CANONICALIZE_FILE_NAME])
165
166   # If any of these functions don't exist (e.g. DJGPP 2.03),
167   # use the corresponding stub.
168   AC_CHECK_FUNC([fchdir], , [AC_LIBOBJ(fchdir-stub)])
169   AC_CHECK_FUNC([fchown], , [AC_LIBOBJ(fchown-stub)])
170 ])
171
172 # These tests must be run before any use of AC_CHECK_TYPE,
173 # because that macro compiles code that tests e.g., HAVE_UNISTD_H.
174 # See the definition of ac_includes_default in `configure'.
175 AC_DEFUN([jm_CHECK_ALL_HEADERS],
176 [
177   AC_CHECK_HEADERS( \
178     errno.h  \
179     fcntl.h \
180     float.h \
181     hurd.h \
182     limits.h \
183     memory.h \
184     mntent.h \
185     mnttab.h \
186     netdb.h \
187     paths.h \
188     stdlib.h \
189     stddef.h \
190     stdint.h \
191     string.h \
192     sys/filsys.h \
193     sys/fs/s5param.h \
194     sys/fs_types.h \
195     sys/fstyp.h \
196     sys/ioctl.h \
197     sys/mntent.h \
198     sys/mount.h \
199     sys/param.h \
200     sys/resource.h \
201     sys/socket.h \
202     sys/statfs.h \
203     sys/statvfs.h \
204     sys/sysctl.h \
205     sys/systeminfo.h \
206     sys/time.h \
207     sys/timeb.h \
208     sys/vfs.h \
209     sys/wait.h \
210     syslog.h \
211     termios.h \
212     unistd.h \
213     utime.h \
214     values.h \
215   )
216 ])
217
218 # This macro must be invoked before any tests that run the compiler.
219 AC_DEFUN([jm_CHECK_ALL_TYPES],
220 [
221   dnl This test must come as early as possible after the compiler configuration
222   dnl tests, because the choice of the file model can (in principle) affect
223   dnl whether functions and headers are available, whether they work, etc.
224   AC_REQUIRE([AC_SYS_LARGEFILE])
225
226   dnl This test must precede tests of compiler characteristics like
227   dnl that for the inline keyword, since it may change the degree to
228   dnl which the compiler supports such features.
229   AC_REQUIRE([AM_C_PROTOTYPES])
230
231   dnl Checks for typedefs, structures, and compiler characteristics.
232   AC_REQUIRE([AC_C_BIGENDIAN])
233   AC_REQUIRE([AC_C_CONST])
234   AC_REQUIRE([AC_C_VOLATILE])
235   AC_REQUIRE([AC_C_INLINE])
236   AC_REQUIRE([AC_C_LONG_DOUBLE])
237
238   AC_REQUIRE([jm_CHECK_ALL_HEADERS])
239   AC_REQUIRE([AC_HEADER_DIRENT])
240   AC_REQUIRE([AC_HEADER_STDC])
241   AC_CHECK_MEMBERS(
242     [struct stat.st_author,
243      struct stat.st_blksize],,,
244     [$ac_includes_default
245 #include <sys/stat.h>
246   ])
247   AC_REQUIRE([AC_STRUCT_ST_BLOCKS])
248
249   AC_REQUIRE([AC_HEADER_STAT])
250   AC_REQUIRE([AC_STRUCT_ST_MTIM_NSEC])
251   AC_REQUIRE([AC_STRUCT_ST_DM_MODE])
252
253   AC_REQUIRE([AC_TYPE_GETGROUPS])
254   AC_REQUIRE([AC_TYPE_MODE_T])
255   AC_REQUIRE([AC_TYPE_OFF_T])
256   AC_REQUIRE([AC_TYPE_PID_T])
257   AC_REQUIRE([AC_TYPE_SIGNAL])
258   AC_REQUIRE([AC_TYPE_SIZE_T])
259   AC_REQUIRE([AC_TYPE_UID_T])
260   AC_CHECK_TYPE(ino_t, unsigned long)
261
262   gt_TYPE_SSIZE_T
263
264   dnl This relies on the fact that autoconf 2.14a's implementation of
265   dnl AC_CHECK_TYPE checks includes unistd.h.
266   AC_CHECK_TYPE(major_t, unsigned int)
267   AC_CHECK_TYPE(minor_t, unsigned int)
268
269   AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
270   AC_REQUIRE([jm_AC_TYPE_UNSIGNED_LONG_LONG])
271
272   AC_REQUIRE([AC_HEADER_MAJOR])
273   AC_REQUIRE([AC_HEADER_DIRENT])
274
275 ])