79bcb069e16f35c7e9be72bfc16c1d7713b9e588
[gnulib.git] / m4 / ls-mntd-fs.m4
1 #serial 1
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 dnl CAUTION: This is very fragile.  It relies on several checks that
9 dnl are still in fileutils' configure.in:
10 dnl FIXME: add AC_REQUIRE uses to pull in all definitions required
11 dnl for all uses of $ac_cv_func_* and $ac_cv_header_* variables below.
12 dnl
13
14 AC_DEFUN(jm_LIST_MOUNTED_FILESYSTEMS,
15   [
16 # Determine how to get the list of mounted filesystems.
17 list_mounted_fs=
18
19 # If the getmntent function is available but not in the standard library,
20 # make sure LIBS contains -lsun (on Irix4) or -lseq (on PTX).
21 AC_FUNC_GETMNTENT
22
23 # This test must precede the ones for getmntent because Unicos-9 is
24 # reported to have the getmntent function, but its support is incompatible
25 # with other getmntent implementations.
26
27 # NOTE: Normally, I wouldn't use a check for system type as I've done for
28 # `CRAY' below since that goes against the whole autoconf philosophy.  But
29 # I think there is too great a chance that some non-Cray system has a
30 # function named listmntent to risk the false positive.
31
32 if test -z "$list_mounted_fs"; then
33   # Cray UNICOS 9
34   AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
35   AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
36     [fu_cv_sys_mounted_cray_listmntent=no
37       AC_EGREP_CPP(yes,
38         [#ifdef _CRAY
39 yes
40 #endif
41         ], [test $ac_cv_func_listmntent = yes \
42             && fu_cv_sys_mounted_cray_listmntent=yes]
43       )
44     ]
45   )
46   AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
47   if test $fu_cv_sys_mounted_cray_listmntent = yes; then
48     list_mounted_fs=found
49     AC_DEFINE(MOUNTED_LISTMNTENT)
50   fi
51 fi
52
53 if test $ac_cv_func_getmntent = yes; then
54
55   # This system has the getmntent function.
56   # Determine whether it's the one-argument variant or the two-argument one.
57
58   if test -z "$list_mounted_fs"; then
59     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
60     AC_MSG_CHECKING([for one-argument getmntent function])
61     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
62                  [test $ac_cv_header_mntent_h = yes \
63                    && fu_cv_sys_mounted_getmntent1=yes \
64                    || fu_cv_sys_mounted_getmntent1=no])
65     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
66     if test $fu_cv_sys_mounted_getmntent1 = yes; then
67       list_mounted_fs=found
68       AC_DEFINE(MOUNTED_GETMNTENT1)
69     fi
70   fi
71
72   if test -z "$list_mounted_fs"; then
73     # SVR4
74     AC_MSG_CHECKING([for two-argument getmntent function])
75     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
76     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
77       fu_cv_sys_mounted_getmntent2=yes,
78       fu_cv_sys_mounted_getmntent2=no)])
79     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
80     if test $fu_cv_sys_mounted_getmntent2 = yes; then
81       list_mounted_fs=found
82       AC_DEFINE(MOUNTED_GETMNTENT2)
83     fi
84   fi
85
86   if test -z "$list_mounted_fs"; then
87     AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
88   fi
89
90 fi
91
92 if test -z "$list_mounted_fs"; then
93   # DEC Alpha running OSF/1.
94   AC_MSG_CHECKING([for getfsstat function])
95   AC_CACHE_VAL(fu_cv_sys_mounted_getsstat,
96   [AC_TRY_LINK([
97 #include <sys/types.h>
98 #include <sys/mount.h>
99 #include <sys/fs_types.h>],
100   [struct statfs *stats;
101   int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); ],
102     fu_cv_sys_mounted_getsstat=yes,
103     fu_cv_sys_mounted_getsstat=no)])
104   AC_MSG_RESULT($fu_cv_sys_mounted_getsstat)
105   if test $fu_cv_sys_mounted_getsstat = yes; then
106     list_mounted_fs=found
107     AC_DEFINE(MOUNTED_GETFSSTAT)
108   fi
109 fi
110
111 if test -z "$list_mounted_fs"; then
112   # AIX.
113   AC_MSG_CHECKING([for mntctl function and struct vmount])
114   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
115   [AC_TRY_CPP([#include <fshelp.h>],
116     fu_cv_sys_mounted_vmount=yes,
117     fu_cv_sys_mounted_vmount=no)])
118   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
119   if test $fu_cv_sys_mounted_vmount = yes; then
120     list_mounted_fs=found
121     AC_DEFINE(MOUNTED_VMOUNT)
122   fi
123 fi
124
125 if test -z "$list_mounted_fs"; then
126   # SVR3
127   AC_MSG_CHECKING([for FIXME existence of three headers])
128   AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
129     [AC_TRY_CPP([
130 #include <sys/statfs.h>
131 #include <sys/fstyp.h>
132 #include <mnttab.h>],
133                 fu_cv_sys_mounted_fread_fstyp=yes,
134                 fu_cv_sys_mounted_fread_fstyp=no)])
135   AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
136   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
137     list_mounted_fs=found
138     AC_DEFINE(MOUNTED_FREAD_FSTYP)
139   fi
140 fi
141
142 if test -z "$list_mounted_fs"; then
143   # 4.4BSD and DEC OSF/1.
144   AC_MSG_CHECKING([for getmntinfo function])
145   AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
146     [
147       ok=
148       if test $ac_cv_func_getmntinfo = yes; then
149         AC_EGREP_HEADER(f_type;, sys/mount.h,
150                         ok=yes)
151       fi
152       test -n "$ok" \
153           && fu_cv_sys_mounted_getmntinfo=yes \
154           || fu_cv_sys_mounted_getmntinfo=no
155     ])
156   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
157   if test $fu_cv_sys_mounted_getmntinfo = yes; then
158     list_mounted_fs=found
159     AC_DEFINE(MOUNTED_GETMNTINFO)
160   fi
161 fi
162
163 # FIXME: add a test for netbsd-1.1 here
164
165 if test -z "$list_mounted_fs"; then
166   # Ultrix
167   AC_MSG_CHECKING([for getmnt function])
168   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
169     [AC_TRY_CPP([
170 #include <sys/fs_types.h>
171 #include <sys/mount.h>],
172                 fu_cv_sys_mounted_getmnt=yes,
173                 fu_cv_sys_mounted_getmnt=no)])
174   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
175   if test $fu_cv_sys_mounted_getmnt = yes; then
176     list_mounted_fs=found
177     AC_DEFINE(MOUNTED_GETMNT)
178   fi
179 fi
180
181 if test -z "$list_mounted_fs"; then
182   # SVR2
183   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
184   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
185     [AC_TRY_CPP([#include <mnttab.h>],
186                 fu_cv_sys_mounted_fread=yes,
187                 fu_cv_sys_mounted_fread=no)])
188   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
189   if test $fu_cv_sys_mounted_fread = yes; then
190     list_mounted_fs=found
191     AC_DEFINE(MOUNTED_FREAD)
192   fi
193 fi
194
195 if test -z "$list_mounted_fs"; then
196   AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
197   # FIXME -- no need to abort building the whole package
198   # Can't build mountlist.c or anything that needs its functions
199 fi
200
201   ])