Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / am-utils / dist / m4 / macros / check_field.m4
blob20010323ea4d2f97e07c09d982d718f83ab8a033
1 dnl ######################################################################
2 dnl FIXED VERSION OF AUTOCONF 2.59 AC_CHECK_MEMBER.  g/cc will fail to check
3 dnl a member if the .member is itself a data structure, because you cannot
4 dnl compare, in C, a data structure against NULL; you can compare a native
5 dnl data type (int, char) or a pointer.  Solution: do what I did in my
6 dnl original member checking macro: try to take the address of the member.
7 dnl You can always take the address of anything.
8 dnl -Erez Zadok, Feb 19, 2005.
9 dnl
11 # AC_CHECK_MEMBER2(AGGREGATE.MEMBER,
12 #                 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
13 #                 [INCLUDES])
14 # ---------------------------------------------------------
15 # AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
16 # variables are not a valid argument.
17 AC_DEFUN([AC_CHECK_MEMBER2],
18 [AS_LITERAL_IF([$1], [],
19                [AC_FATAL([$0: requires literal arguments])])dnl
20 m4_bmatch([$1], [\.], ,
21          [m4_fatal([$0: Did not see any dot in `$1'])])dnl
22 AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl
23 dnl Extract the aggregate name, and the member name
24 AC_CACHE_CHECK([for $1], ac_Member,
25 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
26 [dnl AGGREGATE ac_aggr;
27 static m4_bpatsubst([$1], [\..*]) ac_aggr;
28 dnl ac_aggr.MEMBER;
29 if (&(ac_aggr.m4_bpatsubst([$1], [^[^.]*\.])))
30 return 0;])],
31                 [AS_VAR_SET(ac_Member, yes)],
32 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
33 [dnl AGGREGATE ac_aggr;
34 static m4_bpatsubst([$1], [\..*]) ac_aggr;
35 dnl sizeof ac_aggr.MEMBER;
36 if (sizeof ac_aggr.m4_bpatsubst([$1], [^[^.]*\.]))
37 return 0;])],
38                 [AS_VAR_SET(ac_Member, yes)],
39                 [AS_VAR_SET(ac_Member, no)])])])
40 AS_IF([test AS_VAR_GET(ac_Member) = yes], [$2], [$3])dnl
41 AS_VAR_POPDEF([ac_Member])dnl
42 ])# AC_CHECK_MEMBER
45 # AC_CHECK_MEMBERS2([AGGREGATE.MEMBER, ...],
46 #                  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]
47 #                  [INCLUDES])
48 # ---------------------------------------------------------
49 # The first argument is an m4 list.
50 AC_DEFUN([AC_CHECK_MEMBERS2],
51 [m4_foreach([AC_Member], [$1],
52   [AC_CHECK_MEMBER2(AC_Member,
53          [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Member), 1,
54                             [Define to 1 if `]m4_bpatsubst(AC_Member,
55                                                      [^[^.]*\.])[' is
56                              member of `]m4_bpatsubst(AC_Member, [\..*])['.])
57 $2],
58                  [$3],
59                  [$4])])])
63 dnl ######################################################################
64 dnl find if structure $1 has field field $2
65 AC_DEFUN([AMU_CHECK_FIELD],
67 AC_CHECK_MEMBERS2($1, , ,[
68 AMU_MOUNT_HEADERS(
70 /* now set the typedef */
71 #ifdef HAVE_STRUCT_MNTENT
72 typedef struct mntent mntent_t;
73 #else /* not HAVE_STRUCT_MNTENT */
74 # ifdef HAVE_STRUCT_MNTTAB
75 typedef struct mnttab mntent_t;
76 # endif /*  HAVE_STRUCT_MNTTAB */
77 #endif /* not HAVE_STRUCT_MNTENT */
80  * for various filesystem specific mount arguments
81  */
83 #ifdef HAVE_SYS_FS_EFS_CLNT_H
84 # include <sys/fs/efs_clnt.h>
85 #endif /* HAVE_SYS_FS_EFS_CLNT_H */
86 #ifdef HAVE_SYS_FS_XFS_CLNT_H
87 # include <sys/fs/xfs_clnt.h>
88 #endif /* HAVE_SYS_FS_XFS_CLNT_H */
89 #ifdef HAVE_SYS_FS_UFS_MOUNT_H
90 # include <sys/fs/ufs_mount.h>
91 #endif /* HAVE_SYS_FS_UFS_MOUNT_H */
92 #ifdef HAVE_SYS_FS_AUTOFS_H
93 # include <sys/fs/autofs.h>
94 #endif /* HAVE_SYS_FS_AUTOFS_H */
95 #ifdef HAVE_RPCSVC_AUTOFS_PROT_H
96 # include <rpcsvc/autofs_prot.h>
97 #else  /* not HAVE_RPCSVC_AUTOFS_PROT_H */
98 # ifdef HAVE_SYS_FS_AUTOFS_PROT_H
99 #  include <sys/fs/autofs_prot.h>
100 # endif /* HAVE_SYS_FS_AUTOFS_PROT_H */
101 #endif /* not HAVE_RPCSVC_AUTOFS_PROT_H */
102 #ifdef HAVE_HSFS_HSFS_H
103 # include <hsfs/hsfs.h>
104 #endif /* HAVE_HSFS_HSFS_H */
106 #ifdef HAVE_IFADDRS_H
107 # include <ifaddrs.h>
108 #endif /* HAVE_IFADDRS_H */
113 dnl ======================================================================