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