Use the 3-argument forms of AC_DEFINE* macros.
[gnulib.git] / m4 / ls-mntd-fs.m4
1 #serial 2
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, 1,
50       [Define if there is a function named listmntent that can be used to
51    list all mounted filesystems. (UNICOS)])
52   fi
53 fi
54
55 if test $ac_cv_func_getmntent = yes; then
56
57   # This system has the getmntent function.
58   # Determine whether it's the one-argument variant or the two-argument one.
59
60   if test -z "$list_mounted_fs"; then
61     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
62     AC_MSG_CHECKING([for one-argument getmntent function])
63     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
64                  [test $ac_cv_header_mntent_h = yes \
65                    && fu_cv_sys_mounted_getmntent1=yes \
66                    || fu_cv_sys_mounted_getmntent1=no])
67     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
68     if test $fu_cv_sys_mounted_getmntent1 = yes; then
69       list_mounted_fs=found
70       AC_DEFINE(MOUNTED_GETMNTENT1, 1,
71   [Define if there is a function named getmntent for reading the list
72    of mounted filesystems, and that function takes a single argument.
73    (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
74     fi
75   fi
76
77   if test -z "$list_mounted_fs"; then
78     # SVR4
79     AC_MSG_CHECKING([for two-argument getmntent function])
80     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
81     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
82       fu_cv_sys_mounted_getmntent2=yes,
83       fu_cv_sys_mounted_getmntent2=no)])
84     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
85     if test $fu_cv_sys_mounted_getmntent2 = yes; then
86       list_mounted_fs=found
87       AC_DEFINE(MOUNTED_GETMNTENT2, 1,
88   [Define if there is a function named getmntent for reading the list of
89    mounted filesystems, and that function takes two arguments.  (SVR4)])
90     fi
91   fi
92
93   if test -z "$list_mounted_fs"; then
94     AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
95   fi
96
97 fi
98
99 if test -z "$list_mounted_fs"; then
100   # DEC Alpha running OSF/1.
101   AC_MSG_CHECKING([for getfsstat function])
102   AC_CACHE_VAL(fu_cv_sys_mounted_getsstat,
103   [AC_TRY_LINK([
104 #include <sys/types.h>
105 #include <sys/mount.h>
106 #include <sys/fs_types.h>],
107   [struct statfs *stats;
108   int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); ],
109     fu_cv_sys_mounted_getsstat=yes,
110     fu_cv_sys_mounted_getsstat=no)])
111   AC_MSG_RESULT($fu_cv_sys_mounted_getsstat)
112   if test $fu_cv_sys_mounted_getsstat = yes; then
113     list_mounted_fs=found
114     AC_DEFINE(MOUNTED_GETFSSTAT, 1,
115               [Define if there is a function named getfsstat for reading the
116    list of mounted filesystems.  (DEC Alpha running OSF/1)])
117   fi
118 fi
119
120 if test -z "$list_mounted_fs"; then
121   # AIX.
122   AC_MSG_CHECKING([for mntctl function and struct vmount])
123   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
124   [AC_TRY_CPP([#include <fshelp.h>],
125     fu_cv_sys_mounted_vmount=yes,
126     fu_cv_sys_mounted_vmount=no)])
127   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
128   if test $fu_cv_sys_mounted_vmount = yes; then
129     list_mounted_fs=found
130     AC_DEFINE(MOUNTED_VMOUNT, 1,
131         [Define if there is a function named mntctl that can be used to read
132    the list of mounted filesystems, and there is a system header file
133    that declares \`struct vmount.'  (AIX)])
134   fi
135 fi
136
137 if test -z "$list_mounted_fs"; then
138   # SVR3
139   AC_MSG_CHECKING([for FIXME existence of three headers])
140   AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
141     [AC_TRY_CPP([
142 #include <sys/statfs.h>
143 #include <sys/fstyp.h>
144 #include <mnttab.h>],
145                 fu_cv_sys_mounted_fread_fstyp=yes,
146                 fu_cv_sys_mounted_fread_fstyp=no)])
147   AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
148   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
149     list_mounted_fs=found
150     AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
151 [Define if (like SVR2) there is no specific function for reading the
152    list of mounted filesystems, and your system has these header files:
153    <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
154   fi
155 fi
156
157 if test -z "$list_mounted_fs"; then
158   # 4.4BSD and DEC OSF/1.
159   AC_MSG_CHECKING([for getmntinfo function])
160   AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
161     [
162       ok=
163       if test $ac_cv_func_getmntinfo = yes; then
164         AC_EGREP_HEADER(f_type;, sys/mount.h,
165                         ok=yes)
166       fi
167       test -n "$ok" \
168           && fu_cv_sys_mounted_getmntinfo=yes \
169           || fu_cv_sys_mounted_getmntinfo=no
170     ])
171   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
172   if test $fu_cv_sys_mounted_getmntinfo = yes; then
173     list_mounted_fs=found
174     AC_DEFINE(MOUNTED_GETMNTINFO, 1,
175               [Define if there is a function named getmntinfo for reading the
176    list of mounted filesystems.  (4.4BSD)])
177   fi
178 fi
179
180 # FIXME: add a test for netbsd-1.1 here
181
182 if test -z "$list_mounted_fs"; then
183   # Ultrix
184   AC_MSG_CHECKING([for getmnt function])
185   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
186     [AC_TRY_CPP([
187 #include <sys/fs_types.h>
188 #include <sys/mount.h>],
189                 fu_cv_sys_mounted_getmnt=yes,
190                 fu_cv_sys_mounted_getmnt=no)])
191   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
192   if test $fu_cv_sys_mounted_getmnt = yes; then
193     list_mounted_fs=found
194     AC_DEFINE(MOUNTED_GETMNT, 1,
195       [Define if there is a function named getmnt for reading the list of
196    mounted filesystems.  (Ultrix)])
197   fi
198 fi
199
200 if test -z "$list_mounted_fs"; then
201   # SVR2
202   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
203   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
204     [AC_TRY_CPP([#include <mnttab.h>],
205                 fu_cv_sys_mounted_fread=yes,
206                 fu_cv_sys_mounted_fread=no)])
207   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
208   if test $fu_cv_sys_mounted_fread = yes; then
209     list_mounted_fs=found
210     AC_DEFINE(MOUNTED_FREAD, 1,
211               [Define if there is no specific function for reading the list of
212    mounted filesystems.  fread will be used to read /etc/mnttab.  (SVR2) ])
213   fi
214 fi
215
216 if test -z "$list_mounted_fs"; then
217   AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
218   # FIXME -- no need to abort building the whole package
219   # Can't build mountlist.c or anything that needs its functions
220 fi
221
222   ])