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