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