xref: /netbsd-src/external/bsd/am-utils/dist/m4/macros/check_field.m4 (revision a53f50b9b44dc9467ccc9c464999b1d1c509cb0c)
1dnl ######################################################################
2dnl FIXED VERSION OF AUTOCONF 2.59 AC_CHECK_MEMBER.  g/cc will fail to check
3dnl a member if the .member is itself a data structure, because you cannot
4dnl compare, in C, a data structure against NULL; you can compare a native
5dnl data type (int, char) or a pointer.  Solution: do what I did in my
6dnl original member checking macro: try to take the address of the member.
7dnl You can always take the address of anything.
8dnl -Erez Zadok, Feb 19, 2005.
9dnl
10
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.
17AC_DEFUN([AC_CHECK_MEMBER2],
18[AS_LITERAL_IF([$1], [],
19	       [AC_FATAL([$0: requires literal arguments])])dnl
20m4_bmatch([$1], [\.], ,
21	 [m4_fatal([$0: Did not see any dot in `$1'])])dnl
22AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl
23dnl Extract the aggregate name, and the member name
24AC_CACHE_CHECK([for $1], ac_Member,
25[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
26[dnl AGGREGATE ac_aggr;
27static m4_bpatsubst([$1], [\..*]) ac_aggr;
28dnl ac_aggr.MEMBER;
29if (&(ac_aggr.m4_bpatsubst([$1], [^[^.]*\.])))
30return 0;])],
31		[AS_VAR_SET(ac_Member, yes)],
32[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
33[dnl AGGREGATE ac_aggr;
34static m4_bpatsubst([$1], [\..*]) ac_aggr;
35dnl sizeof ac_aggr.MEMBER;
36if (sizeof ac_aggr.m4_bpatsubst([$1], [^[^.]*\.]))
37return 0;])],
38		[AS_VAR_SET(ac_Member, yes)],
39		[AS_VAR_SET(ac_Member, no)])])])
40AS_IF([test AS_VAR_GET(ac_Member) = yes], [$2], [$3])dnl
41AS_VAR_POPDEF([ac_Member])dnl
42])# AC_CHECK_MEMBER
43
44
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.
50AC_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])])])
60
61
62
63dnl ######################################################################
64dnl find if structure $1 has field field $2
65AC_DEFUN([AMU_CHECK_FIELD],
66[
67AC_CHECK_MEMBERS2($1, , ,[
68AMU_MOUNT_HEADERS(
69[
70/* now set the typedef */
71#ifdef HAVE_STRUCT_MNTENT
72typedef struct mntent mntent_t;
73#else /* not HAVE_STRUCT_MNTENT */
74# ifdef HAVE_STRUCT_MNTTAB
75typedef struct mnttab mntent_t;
76# endif /*  HAVE_STRUCT_MNTTAB */
77#endif /* not HAVE_STRUCT_MNTENT */
78
79/*
80 * for various filesystem specific mount arguments
81 */
82
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 */
105
106#ifdef HAVE_IFADDRS_H
107# include <ifaddrs.h>
108#endif /* HAVE_IFADDRS_H */
109
110])
111])
112])
113dnl ======================================================================
114