Imported Upstream version 2.6.0
[debian/amanda] / config / amanda / funcs.m4
1 # SYNOPSIS
2 #
3 #   AMANDA_FUNC_SELECT_ARG_TYPE
4
5 # OVERVIEW
6 #
7 #   Figure out the select() argument type.  DEFINEs SELECT_ARG_TYPE.
8 #
9 AC_DEFUN([AMANDA_FUNC_SELECT_ARG_TYPE],
10     [
11         AC_REQUIRE([AC_HEADER_TIME])
12         AC_CHECK_HEADERS(
13             sys/time.h \
14             sys/types.h \
15             sys/select.h \
16             sys/socket.h \
17             unistd.h \
18         )
19
20         AC_CACHE_CHECK(
21             [for select() argument type],
22             amanda_cv_select_arg_type,
23             [
24                 rm -f conftest.c
25                 cat <<EOF >conftest.$ac_ext
26 #include "confdefs.h"
27 #ifdef TIME_WITH_SYS_TIME
28 #  include <sys/time.h>
29 #  include <time.h>
30 #else
31 #  ifdef HAVE_SYS_TIME_H
32 #    include <sys/time.h>
33 #  else
34 #    include <time.h>
35 #  endif
36 #endif
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
39 #endif
40 #ifdef HAVE_SYS_SELECT_H
41 #  include <sys/select.h>
42 #endif
43 #ifdef HAVE_SYS_SOCKET_H
44 #  include <sys/socket.h>
45 #endif
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49
50 int main()
51 {
52 #ifdef FD_SET_POINTER
53         (void)select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, 0);
54 #else
55         (void)select(0, (int *) 0, (int *) 0, (int *) 0, 0);
56 #endif
57         return 0;
58 }
59 EOF
60
61                 # Figure out the select argument type by first trying to
62                 # compile with the fd_set argument.  If the compile fails,
63                 # then we know to use the int.  If it suceeds, then try to
64                 # use the int.  If the int fails, then use fd_set.  If
65                 # both suceeed, then do a line count on the number of
66                 # lines that the compiler spit out, assuming that the
67                 # compile outputing more lines had more errors.
68                 amanda_cv_select_arg_type=no
69                 select_compile="${CC-cc} -c $CFLAGS $CPPFLAGS"
70                 $select_compile -DFD_SET_POINTER conftest.$ac_ext 1>conftest.fd_set 2>&1
71                 if test $? -ne 0; then
72                     amanda_cv_select_arg_type=int
73                 fi
74                 if test "$amanda_cv_select_arg_type" = no; then
75                     $select_compile conftest.$ac_ext 1>conftest.int 2>&1
76                     if test $? -ne 0; then
77                         amanda_cv_select_arg_type=fd_set
78                     fi
79                 fi
80                 if test "$amanda_cv_select_arg_type" = no; then
81                     wc_fdset=`wc -l <conftest.fd_set`
82                     wc_int=`wc -l <conftest.int`
83                     if test "$wc_fdset" -le "$wc_int"; then
84                         amanda_cv_select_arg_type=fd_set
85                     else
86                         amanda_cv_select_arg_type=int
87                     fi
88                 fi
89                 rm -f conftest*
90             ]
91         )
92         AC_DEFINE_UNQUOTED(SELECT_ARG_TYPE,$amanda_cv_select_arg_type,[Define to type of select arguments. ])
93     ]
94 )
95
96 # SYNOPSIS
97 #
98 #   AMANDA_FUNC_SETSOCKOPT_SO_SNDTIMEO
99 #
100 # OVERVIEW
101 #
102 #   Check if setsockopt can use the SO_SNDTIMEO option.
103 #   This defines HAVE_SO_SNDTIMEO if setsockopt works with SO_SNDTIMEO.
104 #
105 AC_DEFUN([AMANDA_FUNC_SETSOCKOPT_SO_SNDTIMEO],
106     [
107         AC_REQUIRE([AC_HEADER_TIME])
108         AC_CHECK_HEADERS(
109             time.h
110             sys/time.h
111         )
112
113         AC_CACHE_CHECK(
114             [for setsockopt SO_SNDTIMEO option],
115             amanda_cv_setsockopt_SO_SNDTIMEO,
116             [
117                 AC_TRY_RUN(
118                     [
119 #include <sys/types.h>
120 #include <sys/socket.h>
121 #ifdef TIME_WITH_SYS_TIME
122 #  include <sys/time.h>
123 #  include <time.h>
124 #else
125 #  ifdef HAVE_SYS_TIME_H
126 #    include <sys/time.h>
127 #  else
128 #    include <time.h>
129 #  endif
130 #endif
131
132 main() {
133 #ifdef SO_SNDTIMEO
134     int sock = socket(AF_INET, SOCK_STREAM, 0);
135     struct timeval timeout;
136     timeout.tv_sec = 1;
137     timeout.tv_usec = 0;
138     return (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
139              (void *)&timeout, sizeof(timeout)));
140 #else
141     return -1;
142 #endif
143 }
144                     ],
145                     amanda_cv_setsockopt_SO_SNDTIMEO=yes,
146                     amanda_cv_setsockopt_SO_SNDTIMEO=no,
147                     amanda_cv_setsockopt_SO_SNDTIMEO=no
148                 )
149             ]
150         )
151         if test "$amanda_cv_setsockopt_SO_SNDTIMEO" = yes; then
152             AC_DEFINE(HAVE_SO_SNDTIMEO,1,[Define if SO_SNDTIMEO is available. ])
153         fi
154     ]
155 )
156
157 # SYNOPSIS
158 #
159 #   AMANDA_FUNC_GETTIMEOFDAY_ARGS
160 #
161 # OVERVIEW
162 #
163 #   Check for the one or two argument version of gettimeofday.  DEFINEs
164 #   HAVE_TWO_ARG_GETTIMEOFDAY if the two argument version is present.
165 #
166 AC_DEFUN([AMANDA_FUNC_GETTIMEOFDAY_ARGS],
167     [
168         AC_REQUIRE([AC_HEADER_TIME])
169         AC_CHECK_HEADERS(
170             time.h
171             sys/time.h
172         )
173
174         AC_CACHE_CHECK(
175             [for gettimeofday number of arguments],
176             amanda_cv_gettimeofday_args,
177             [
178                 AC_TRY_COMPILE(
179                     [
180 #ifdef TIME_WITH_SYS_TIME
181 #  include <sys/time.h>
182 #  include <time.h>
183 #else
184 #  ifdef HAVE_SYS_TIME_H
185 #    include <sys/time.h>
186 #  else
187 #    include <time.h>
188 #  endif
189 #endif
190                     ],
191                     [
192                         struct timeval val;
193                         struct timezone zone;
194                         gettimeofday(&val, &zone);
195                     ],
196                     amanda_cv_gettimeofday_args=2,
197                     amanda_cv_gettimeofday_args=1
198                 )
199             ]
200         )
201         if test "$amanda_cv_gettimeofday_args" = 2; then
202             AC_DEFINE(HAVE_TWO_ARG_GETTIMEOFDAY,1,[Define if gettimeofday takes two arguments. ])
203         fi
204     ]
205 )
206
207 # SYNOPSIS
208 #
209 #   ICE_CHECK_DECL (FUNCTION, HEADER-FILE...)
210 #
211 # OVERVIEW
212 #
213 #   If FUNCTION is available, define `HAVE_FUNCTION'.  If it is declared
214 #   in one of the headers named in the whitespace-separated list 
215 #   HEADER_FILE, define `HAVE_FUNCTION_DECL` (in all capitals).
216 #
217 AC_DEFUN([ICE_CHECK_DECL],
218 [
219 ice_have_$1=no
220 AC_CHECK_FUNCS($1, ice_have_$1=yes)
221 if test "${ice_have_$1}" = yes; then
222 AC_MSG_CHECKING(for $1 declaration in $2)
223 AC_CACHE_VAL(ice_cv_have_$1_decl,
224 [
225 ice_cv_have_$1_decl=no
226 changequote(,)dnl
227 ice_re_params='[a-zA-Z_][a-zA-Z0-9_]*'
228 ice_re_word='(^|[^a-zA-Z0-9_])'
229 changequote([,])dnl
230 for header in $2; do
231 # Check for ordinary declaration
232 AC_EGREP_HEADER([${ice_re_word}$1[      ]*\(], $header, 
233         ice_cv_have_$1_decl=yes)
234 if test "$ice_cv_have_$1_decl" = yes; then
235         break
236 fi
237 # Check for "fixed" declaration like "getpid _PARAMS((int))"
238 AC_EGREP_HEADER([${ice_re_word}$1[      ]*$ice_re_params\(\(], $header, 
239         ice_cv_have_$1_decl=yes)
240 if test "$ice_cv_have_$1_decl" = yes; then
241         break
242 fi
243 done
244 ])
245 AC_MSG_RESULT($ice_cv_have_$1_decl)
246 if test "$ice_cv_have_$1_decl" = yes; then
247 AC_DEFINE_UNQUOTED([HAVE_]translit($1,[a-z],[A-Z])[_DECL],1,[Define if $1 is declared. ])
248 fi
249 fi
250 ])dnl
251
252 # SYNOPSIS
253 #
254 #   AMANDA_FUNC_SETPGID
255 #
256 # OVERVIEW
257 #
258 #   Search for the function HAVE_SETPGID, and run an ICE_CHECK_DECL on it if so.
259 #
260 AC_DEFUN([AMANDA_FUNC_SETPGID],
261 [
262     AC_CHECK_FUNC(setpgid, [
263         AC_DEFINE(HAVE_SETPGID,1,[Define if setpgid() is available. ])
264         ICE_CHECK_DECL(setpgid,sys/types.h unistd.h)
265     ])
266 ])