Ensure automatic ordering between gl_LOCK and gl_ARGP.
[gnulib.git] / m4 / ls-mntd-fs.m4
1 #serial 20
2 # How to list mounted file systems.
3
4 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5 # Foundation, Inc.
6 #
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10
11 dnl From Jim Meyering.
12 dnl
13 dnl This is not pretty.  I've just taken the autoconf code and wrapped
14 dnl it in an AC_DEFUN and made some other fixes.
15 dnl
16
17 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
18 # through Autoconf 2.59.  We can remove this once we assume Autoconf 2.60
19 # or later.
20 AC_DEFUN([AC_FUNC_GETMNTENT],
21 [# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
22 # -lseq on Dynix/PTX, -lgen on Unixware.
23 AC_SEARCH_LIBS(getmntent, [sun seq gen], [AC_CHECK_FUNCS(getmntent)])
24 ])
25
26 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
27 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
28   [
29 AC_CHECK_FUNCS(listmntent getmntinfo)
30 AC_CHECK_HEADERS_ONCE(sys/param.h)
31
32 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
33 # NGROUPS (as the array dimension for a struct member) without a definition.
34 AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include <grp.h>])
35
36 AC_CHECK_HEADERS(sys/mount.h, [], [],
37   [AC_INCLUDES_DEFAULT
38    [#if HAVE_SYS_PARAM_H
39      #include <sys/param.h>
40     #endif]])
41
42 AC_CHECK_HEADERS(mntent.h sys/fs_types.h)
43     getfsstat_includes="\
44 $ac_includes_default
45 #if HAVE_SYS_PARAM_H
46 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
47 #endif
48 #if HAVE_SYS_UCRED_H
49 # include <grp.h> /* needed for definition of NGROUPS */
50 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
51 #endif
52 #if HAVE_SYS_MOUNT_H
53 # include <sys/mount.h>
54 #endif
55 #if HAVE_SYS_FS_TYPES_H
56 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
57 #endif
58 "
59 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
60
61 # Determine how to get the list of mounted file systems.
62 ac_list_mounted_fs=
63
64 # If the getmntent function is available but not in the standard library,
65 # make sure LIBS contains the appropriate -l option.
66 AC_FUNC_GETMNTENT
67
68 # This test must precede the ones for getmntent because Unicos-9 is
69 # reported to have the getmntent function, but its support is incompatible
70 # with other getmntent implementations.
71
72 # NOTE: Normally, I wouldn't use a check for system type as I've done for
73 # `CRAY' below since that goes against the whole autoconf philosophy.  But
74 # I think there is too great a chance that some non-Cray system has a
75 # function named listmntent to risk the false positive.
76
77 if test -z "$ac_list_mounted_fs"; then
78   # Cray UNICOS 9
79   AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
80   AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
81     [fu_cv_sys_mounted_cray_listmntent=no
82       AC_EGREP_CPP(yes,
83         [#ifdef _CRAY
84 yes
85 #endif
86         ], [test $ac_cv_func_listmntent = yes \
87             && fu_cv_sys_mounted_cray_listmntent=yes]
88       )
89     ]
90   )
91   AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
92   if test $fu_cv_sys_mounted_cray_listmntent = yes; then
93     ac_list_mounted_fs=found
94     AC_DEFINE(MOUNTED_LISTMNTENT, 1,
95       [Define if there is a function named listmntent that can be used to
96        list all mounted file systems.  (UNICOS)])
97   fi
98 fi
99
100 if test -z "$ac_list_mounted_fs"; then
101   # AIX.
102   AC_MSG_CHECKING([for mntctl function and struct vmount])
103   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
104   [AC_TRY_CPP([#include <fshelp.h>],
105     fu_cv_sys_mounted_vmount=yes,
106     fu_cv_sys_mounted_vmount=no)])
107   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
108   if test $fu_cv_sys_mounted_vmount = yes; then
109     ac_list_mounted_fs=found
110     AC_DEFINE(MOUNTED_VMOUNT, 1,
111         [Define if there is a function named mntctl that can be used to read
112          the list of mounted file systems, and there is a system header file
113          that declares `struct vmount.'  (AIX)])
114   fi
115 fi
116
117 if test $ac_cv_func_getmntent = yes; then
118
119   # This system has the getmntent function.
120   # Determine whether it's the one-argument variant or the two-argument one.
121
122   if test -z "$ac_list_mounted_fs"; then
123     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
124     AC_MSG_CHECKING([for one-argument getmntent function])
125     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
126                  [AC_TRY_COMPILE([
127 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
128 #include <stdio.h>
129
130 #include <mntent.h>
131 #if !defined MOUNTED
132 # if defined _PATH_MOUNTED      /* GNU libc  */
133 #  define MOUNTED _PATH_MOUNTED
134 # endif
135 # if defined MNT_MNTTAB /* HP-UX.  */
136 #  define MOUNTED MNT_MNTTAB
137 # endif
138 # if defined MNTTABNAME /* Dynix.  */
139 #  define MOUNTED MNTTABNAME
140 # endif
141 #endif
142 ],
143                     [ struct mntent *mnt = 0; char *table = MOUNTED; ],
144                     fu_cv_sys_mounted_getmntent1=yes,
145                     fu_cv_sys_mounted_getmntent1=no)])
146     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
147     if test $fu_cv_sys_mounted_getmntent1 = yes; then
148       ac_list_mounted_fs=found
149       AC_DEFINE(MOUNTED_GETMNTENT1, 1,
150         [Define if there is a function named getmntent for reading the list
151          of mounted file systems, and that function takes a single argument.
152          (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
153     fi
154   fi
155
156   if test -z "$ac_list_mounted_fs"; then
157     # SVR4
158     AC_MSG_CHECKING([for two-argument getmntent function])
159     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
160     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
161       fu_cv_sys_mounted_getmntent2=yes,
162       fu_cv_sys_mounted_getmntent2=no)])
163     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
164     if test $fu_cv_sys_mounted_getmntent2 = yes; then
165       ac_list_mounted_fs=found
166       AC_DEFINE(MOUNTED_GETMNTENT2, 1,
167         [Define if there is a function named getmntent for reading the list of
168          mounted file systems, and that function takes two arguments.  (SVR4)])
169     fi
170   fi
171
172 fi
173
174 if test -z "$ac_list_mounted_fs"; then
175   # DEC Alpha running OSF/1, and Apple Darwin 1.3.
176   # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
177
178   AC_MSG_CHECKING([for getfsstat function])
179   AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
180   [AC_TRY_LINK([
181 #include <sys/types.h>
182 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
183 # define FS_TYPE(Ent) ((Ent).f_fstypename)
184 #else
185 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
186 #endif
187 ]$getfsstat_includes
188 ,
189   [struct statfs *stats;
190    int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
191    char *t = FS_TYPE (*stats); ],
192     fu_cv_sys_mounted_getfsstat=yes,
193     fu_cv_sys_mounted_getfsstat=no)])
194   AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
195   if test $fu_cv_sys_mounted_getfsstat = yes; then
196     ac_list_mounted_fs=found
197     AC_DEFINE(MOUNTED_GETFSSTAT, 1,
198               [Define if there is a function named getfsstat for reading the
199                list of mounted file systems.  (DEC Alpha running OSF/1)])
200   fi
201 fi
202
203 if test -z "$ac_list_mounted_fs"; then
204   # SVR3
205   AC_MSG_CHECKING([for FIXME existence of three headers])
206   AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
207     [AC_TRY_CPP([
208 #include <sys/statfs.h>
209 #include <sys/fstyp.h>
210 #include <mnttab.h>],
211                 fu_cv_sys_mounted_fread_fstyp=yes,
212                 fu_cv_sys_mounted_fread_fstyp=no)])
213   AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
214   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
215     ac_list_mounted_fs=found
216     AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
217       [Define if (like SVR2) there is no specific function for reading the
218        list of mounted file systems, and your system has these header files:
219        <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
220   fi
221 fi
222
223 if test -z "$ac_list_mounted_fs"; then
224   # 4.4BSD and DEC OSF/1.
225   AC_MSG_CHECKING([for getmntinfo function])
226   AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
227     [
228       test "$ac_cv_func_getmntinfo" = yes \
229           && fu_cv_sys_mounted_getmntinfo=yes \
230           || fu_cv_sys_mounted_getmntinfo=no
231     ])
232   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
233   if test $fu_cv_sys_mounted_getmntinfo = yes; then
234     ac_list_mounted_fs=found
235     AC_DEFINE(MOUNTED_GETMNTINFO, 1,
236               [Define if there is a function named getmntinfo for reading the
237                list of mounted file systems.  (4.4BSD, Darwin)])
238   fi
239 fi
240
241 if test -z "$ac_list_mounted_fs"; then
242   # Ultrix
243   AC_MSG_CHECKING([for getmnt function])
244   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
245     [AC_TRY_CPP([
246 #include <sys/fs_types.h>
247 #include <sys/mount.h>],
248                 fu_cv_sys_mounted_getmnt=yes,
249                 fu_cv_sys_mounted_getmnt=no)])
250   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
251   if test $fu_cv_sys_mounted_getmnt = yes; then
252     ac_list_mounted_fs=found
253     AC_DEFINE(MOUNTED_GETMNT, 1,
254       [Define if there is a function named getmnt for reading the list of
255        mounted file systems.  (Ultrix)])
256   fi
257 fi
258
259 if test -z "$ac_list_mounted_fs"; then
260   # BeOS
261   AC_CHECK_FUNCS(next_dev fs_stat_dev)
262   AC_CHECK_HEADERS(fs_info.h)
263   AC_MSG_CHECKING([for BEOS mounted file system support functions])
264   if test $ac_cv_header_fs_info_h = yes \
265       && test $ac_cv_func_next_dev = yes \
266         && test $ac_cv_func_fs_stat_dev = yes; then
267     fu_result=yes
268   else
269     fu_result=no
270   fi
271   AC_MSG_RESULT($fu_result)
272   if test $fu_result = yes; then
273     ac_list_mounted_fs=found
274     AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
275       [Define if there are functions named next_dev and fs_stat_dev for
276        reading the list of mounted file systems.  (BeOS)])
277   fi
278 fi
279
280 if test -z "$ac_list_mounted_fs"; then
281   # SVR2
282   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
283   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
284     [AC_TRY_CPP([#include <mnttab.h>],
285                 fu_cv_sys_mounted_fread=yes,
286                 fu_cv_sys_mounted_fread=no)])
287   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
288   if test $fu_cv_sys_mounted_fread = yes; then
289     ac_list_mounted_fs=found
290     AC_DEFINE(MOUNTED_FREAD, 1,
291               [Define if there is no specific function for reading the list of
292                mounted file systems.  fread will be used to read /etc/mnttab.
293                (SVR2) ])
294   fi
295 fi
296
297 if test -z "$ac_list_mounted_fs"; then
298   AC_MSG_ERROR([could not determine how to read list of mounted file systems])
299   # FIXME -- no need to abort building the whole package
300   # Can't build mountlist.c or anything that needs its functions
301 fi
302
303 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
304
305   ])