969b25898622bae3893b39476b86342bccbae19c
[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)
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 #include <mntent.h>
65 #if !defined MOUNTED
66 # if defined _PATH_MOUNTED      /* GNU libc  */
67 #  define MOUNTED _PATH_MOUNTED
68 # endif
69 # if defined MNT_MNTTAB /* HP-UX.  */
70 #  define MOUNTED MNT_MNTTAB
71 # endif
72 # if defined MNTTABNAME /* Dynix.  */
73 #  define MOUNTED MNTTABNAME
74 # endif
75 #endif
76 ],
77                     [ struct mntent *mnt = 0; char *table = MOUNTED; ],
78                     fu_cv_sys_mounted_getmntent1=yes,
79                     fu_cv_sys_mounted_getmntent1=no)])
80     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
81     if test $fu_cv_sys_mounted_getmntent1 = yes; then
82       ac_list_mounted_fs=found
83       AC_DEFINE(MOUNTED_GETMNTENT1, 1,
84   [Define if there is a function named getmntent for reading the list
85    of mounted filesystems, and that function takes a single argument.
86    (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
87     fi
88   fi
89
90   if test -z "$ac_list_mounted_fs"; then
91     # SVR4
92     AC_MSG_CHECKING([for two-argument getmntent function])
93     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
94     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
95       fu_cv_sys_mounted_getmntent2=yes,
96       fu_cv_sys_mounted_getmntent2=no)])
97     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
98     if test $fu_cv_sys_mounted_getmntent2 = yes; then
99       ac_list_mounted_fs=found
100       AC_DEFINE(MOUNTED_GETMNTENT2, 1,
101   [Define if there is a function named getmntent for reading the list of
102    mounted filesystems, and that function takes two arguments.  (SVR4)])
103     fi
104   fi
105
106 fi
107
108 if test -z "$ac_list_mounted_fs"; then
109   # DEC Alpha running OSF/1.
110   AC_MSG_CHECKING([for getfsstat function])
111   AC_CACHE_VAL(fu_cv_sys_mounted_getsstat,
112   [AC_TRY_LINK([
113 #include <sys/types.h>
114 #include <sys/mount.h>
115 #include <sys/fs_types.h>],
116   [struct statfs *stats;
117   int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); ],
118     fu_cv_sys_mounted_getsstat=yes,
119     fu_cv_sys_mounted_getsstat=no)])
120   AC_MSG_RESULT($fu_cv_sys_mounted_getsstat)
121   if test $fu_cv_sys_mounted_getsstat = yes; then
122     ac_list_mounted_fs=found
123     AC_DEFINE(MOUNTED_GETFSSTAT, 1,
124               [Define if there is a function named getfsstat for reading the
125    list of mounted filesystems.  (DEC Alpha running OSF/1)])
126   fi
127 fi
128
129 if test -z "$ac_list_mounted_fs"; then
130   # AIX.
131   AC_MSG_CHECKING([for mntctl function and struct vmount])
132   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
133   [AC_TRY_CPP([#include <fshelp.h>],
134     fu_cv_sys_mounted_vmount=yes,
135     fu_cv_sys_mounted_vmount=no)])
136   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
137   if test $fu_cv_sys_mounted_vmount = yes; then
138     ac_list_mounted_fs=found
139     AC_DEFINE(MOUNTED_VMOUNT, 1,
140         [Define if there is a function named mntctl that can be used to read
141    the list of mounted filesystems, and there is a system header file
142    that declares `struct vmount.'  (AIX)])
143   fi
144 fi
145
146 if test -z "$ac_list_mounted_fs"; then
147   # SVR3
148   AC_MSG_CHECKING([for FIXME existence of three headers])
149   AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
150     [AC_TRY_CPP([
151 #include <sys/statfs.h>
152 #include <sys/fstyp.h>
153 #include <mnttab.h>],
154                 fu_cv_sys_mounted_fread_fstyp=yes,
155                 fu_cv_sys_mounted_fread_fstyp=no)])
156   AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
157   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
158     ac_list_mounted_fs=found
159     AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
160 [Define if (like SVR2) there is no specific function for reading the
161    list of mounted filesystems, and your system has these header files:
162    <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
163   fi
164 fi
165
166 if test -z "$ac_list_mounted_fs"; then
167   # 4.4BSD and DEC OSF/1.
168   AC_MSG_CHECKING([for getmntinfo function])
169   AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
170     [
171       ok=
172       if test $ac_cv_func_getmntinfo = yes; then
173         AC_EGREP_HEADER(f_type;, sys/mount.h,
174                         ok=yes)
175       fi
176       test -n "$ok" \
177           && fu_cv_sys_mounted_getmntinfo=yes \
178           || fu_cv_sys_mounted_getmntinfo=no
179     ])
180   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
181   if test $fu_cv_sys_mounted_getmntinfo = yes; then
182     ac_list_mounted_fs=found
183     AC_DEFINE(MOUNTED_GETMNTINFO, 1,
184               [Define if there is a function named getmntinfo for reading the
185    list of mounted filesystems.  (4.4BSD)])
186   fi
187 fi
188
189 if test -z "$ac_list_mounted_fs"; then
190   # Ultrix
191   AC_MSG_CHECKING([for getmnt function])
192   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
193     [AC_TRY_CPP([
194 #include <sys/fs_types.h>
195 #include <sys/mount.h>],
196                 fu_cv_sys_mounted_getmnt=yes,
197                 fu_cv_sys_mounted_getmnt=no)])
198   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
199   if test $fu_cv_sys_mounted_getmnt = yes; then
200     ac_list_mounted_fs=found
201     AC_DEFINE(MOUNTED_GETMNT, 1,
202       [Define if there is a function named getmnt for reading the list of
203    mounted filesystems.  (Ultrix)])
204   fi
205 fi
206
207 if test -z "$ac_list_mounted_fs"; then
208   # BeOS
209   AC_CHECK_FUNCS(next_dev fs_stat_dev)
210   AC_CHECK_HEADERS(fs_info.h)
211   AC_MSG_CHECKING([for BEOS mounted file system support functions])
212   if test $ac_cv_header_fs_info_h = yes \
213       && test $ac_cv_func_next_dev = yes \
214         && test $ac_cv_func_fs_stat_dev = yes; then
215     fu_result=yes
216   else
217     fu_result=no
218   fi
219   AC_MSG_RESULT($fu_result)
220   if test $fu_result = yes; then
221     ac_list_mounted_fs=found
222     AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
223       [Define if there are functions named next_dev and fs_stat_dev for
224    reading the list of mounted filesystems.  (BeOS)])
225   fi
226 fi
227
228 if test -z "$ac_list_mounted_fs"; then
229   # SVR2
230   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
231   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
232     [AC_TRY_CPP([#include <mnttab.h>],
233                 fu_cv_sys_mounted_fread=yes,
234                 fu_cv_sys_mounted_fread=no)])
235   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
236   if test $fu_cv_sys_mounted_fread = yes; then
237     ac_list_mounted_fs=found
238     AC_DEFINE(MOUNTED_FREAD, 1,
239               [Define if there is no specific function for reading the list of
240    mounted filesystems.  fread will be used to read /etc/mnttab.  (SVR2) ])
241   fi
242 fi
243
244 if test -z "$ac_list_mounted_fs"; then
245   AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
246   # FIXME -- no need to abort building the whole package
247   # Can't build mountlist.c or anything that needs its functions
248 fi
249
250 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
251
252   ])