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