ff9e85245d8527dc428e66f42398139cf16437bb
[debian/amanda] / config / amanda / types.m4
1 # SYNOPSIS
2 #
3 #   AMANDA_CHECK_TYPE(type, replacement-type, header)
4 #
5 # OVERVIEW
6
7 #   Like AC_CHECK_TYPE, where action-if-not-found DEFINEs $1 to $2.
8 #
9 #   'header' must be a single header name, or blank to use the default
10 #   headers.
11 #
12 AC_DEFUN([AMANDA_CHECK_TYPE], [
13     AC_REQUIRE([AC_HEADER_STDC])
14     AC_CHECK_TYPE($1, [], [
15         AC_DEFINE($1, $2, [Type for $1, if it is not defined by the system])
16     ], ifelse($3, [], [], [
17 #ifdef STDC_HEADERS
18 #include <stdlib.h>
19 #include <stddef.h>
20 #endif
21 #include <$3>
22         ])
23     )
24 ])
25 #
26 # SYNOPSIS
27 #
28 #   AMANDA_TYPE_PID_T
29 #
30 # OVERVIEW
31 #
32 #   Check whether pid_t is a long, int, or short.  DEFINE PRINTF_PID_T to the
33 #   corresponding printf format.
34 #
35 AC_DEFUN([AMANDA_TYPE_PID_T], [
36         AC_REQUIRE([AC_HEADER_STDC])
37         AC_REQUIRE([AC_TYPE_PID_T])
38         AC_CACHE_CHECK([for pid_t type], amanda_cv_pid_type,
39             [
40                 amanda_cv_pid_type=unknown
41                 if test "$ac_cv_type_pid_t" = no; then
42                     amanda_cv_pid_type=int
43                 fi
44                 for TEST_amanda_cv_pid_type in long short int; do
45                     if test $amanda_cv_pid_type = unknown; then
46                         AC_EGREP_CPP(typedef.*${TEST_amanda_cv_pid_type}.*pid_t,
47                             [
48 #include <sys/types.h>
49 #if STDC_HEADERS
50 #include <stdlib.h>
51 #include <stddef.h>
52 #endif
53                             ],
54                         amanda_cv_pid_type=$TEST_amanda_cv_pid_type)
55                     fi
56                     if test $amanda_cv_pid_type = unknown; then
57                         AC_EGREP_CPP(ZZZZ.*${TEST_amanda_cv_pid_type},
58                             [
59 #include <sys/types.h>
60 #if STDC_HEADERS
61 #include <stdlib.h>
62 #include <stddef.h>
63 #endif
64                                 ZZZZ pid_t
65                         ],
66                         amanda_cv_pid_type=$TEST_amanda_cv_pid_type)
67                     fi
68                 done
69                 if test $amanda_cv_pid_type = unknown; then
70                     amanda_cv_pid_type=int
71                 fi
72             ]
73         )
74         case $amanda_cv_pid_type in
75             int)        AC_DEFINE_UNQUOTED(PRINTF_PID_T,"%d",[Define to printf formatting string to print a PID. ]) ;;
76             long)       AC_DEFINE_UNQUOTED(PRINTF_PID_T,"%ld") ;;
77             short)      AC_DEFINE_UNQUOTED(PRINTF_PID_T,"%d") ;;
78         esac
79     ]
80 )
81
82 # SYNOPSIS
83 #
84 #   CF_WAIT
85 #
86 # OVERVIEW
87 #
88 # Test for the presence of <sys/wait.h>, 'union wait', arg-type of 'wait()'.
89 # by T.E.Dickey" , Jim Spath <jspath@mail.bcpl.lib.md.us>
90 #
91 #   DEFINEs WAIT_USES_UNION if 'union wait' is found.  Note that many systems
92 #   support *both* 'union wait' and 'int' using a transparent union.
93 #
94 #   Original comments:
95 #
96 #     FIXME: These tests should have been in autoconf 1.11!
97 #
98 #     Note that we cannot simply grep for 'union wait' in the wait.h file,
99 #     because some Posix systems turn this on only when a BSD variable is
100 #     defined. Since I'm trying to do without special defines, I'll live
101 #     with the default behavior of the include-file.
102 #
103 #     I do _2_ compile checks, because we may have union-wait, but the
104 #     prototype for 'wait()' may want an int.
105 #
106 #     Don't use HAVE_UNION_WAIT, because the autoconf documentation implies
107 #     that if we've got union-wait, we'll automatically use it.
108 #
109 # Garrett Wollman adds:
110 #       The tests described above don't quite do the right thing,
111 #       since some systems have hacks which allow `union wait' to
112 #       still work even though `int' is preferred (and generates
113 #       fewer warnings).  Since all of these systems use prototypes,
114 #       we can use the prototype of wait(2) to disambiguate them.
115 #
116 # Alexandre Oliva adds:
117 #     A single compile check is enough.  If we don't have union wait,
118 #     it's obvious that the test will fail, and that we must use int.
119 #     If we do, the prototype (on STDC systems) and WIFEXITED will tell
120 #     whether we're supposed to be using union wait instead of int.
121 #
122 AC_DEFUN([CF_WAIT], [
123     AC_REQUIRE([AC_TYPE_PID_T])
124     AC_HAVE_HEADERS(sys/wait.h wait.h)
125     AC_CACHE_CHECK([whether wait uses union wait], [cf_cv_arg_union_wait], [
126         AC_TRY_COMPILE([
127 #include <sys/types.h>
128
129 #if HAVE_SYS_WAIT_H
130 # include <sys/wait.h>
131 #else
132 # if HAVE_WAIT_H
133 #  include <wait.h>
134 # endif
135 #endif
136
137 #ifdef __STDC__
138 pid_t wait(union wait *);
139 #endif
140 ], [
141   union wait x; int i;
142   wait(&x); i = WIFEXITED(x)
143 ], [cf_cv_arg_union_wait=yes], [cf_cv_arg_union_wait=no])])
144     if test $cf_cv_arg_union_wait = yes; then
145             AC_DEFINE(WAIT_USES_UNION,1,
146                 [Defined if wait() puts the status in a union wait instead of int. ])
147     fi
148 ])
149
150 # SYNOPSIS
151 #
152 #   CF_WAIT_INT
153 #
154 # OVERVIEW
155 #
156 # Test for the presence of <sys/wait.h>, 'union wait', arg-type of 'wait()'.
157 # by T.E.Dickey" , Jim Spath <jspath@mail.bcpl.lib.md.us>
158 #
159 #   DEFINEs WAIT_USES_INT if an int result type is found.
160 #
161 AC_DEFUN([CF_WAIT_INT], [
162     AC_REQUIRE([AC_TYPE_PID_T])
163     AC_HAVE_HEADERS(sys/wait.h wait.h)
164     AC_CACHE_CHECK([whether wait uses int], [cf_cv_arg_int], [
165         AC_TRY_COMPILE([
166 #include <sys/types.h>
167
168 #if HAVE_SYS_WAIT_H
169 # include <sys/wait.h>
170 #else
171 # if HAVE_WAIT_H
172 #  include <wait.h>
173 # endif
174 #endif
175
176 #ifdef __STDC__
177 pid_t wait(int *);
178 #endif
179 ], [
180   int x; int i;
181   wait(&x); i = WIFEXITED(x)
182 ], [cf_cv_arg_int=yes], [cf_cv_arg_int=no])])
183 if test $cf_cv_arg_int = yes; then
184         AC_DEFINE(WAIT_USES_INT,1,
185             [Defined if wait() puts the status in a int instead of a union wait. ])
186 fi
187 ])
188