Add file version serial number that might be used by 'aclocal' and others.
[platform/upstream/c-ares.git] / m4 / cares-reentrant.m4
1 #***************************************************************************
2 # $Id$
3 #
4 # Copyright (C) 2008 by Daniel Stenberg et al
5 #
6 # Permission to use, copy, modify, and distribute this software and its
7 # documentation for any purpose and without fee is hereby granted, provided
8 # that the above copyright notice appear in all copies and that both that
9 # copyright notice and this permission notice appear in supporting
10 # documentation, and that the name of M.I.T. not be used in advertising or
11 # publicity pertaining to distribution of the software without specific,
12 # written prior permission.  M.I.T. makes no representations about the
13 # suitability of this software for any purpose.  It is provided "as is"
14 # without express or implied warranty.
15 #
16 #***************************************************************************
17
18 # File version for 'aclocal' use.
19 # serial 1.1
20
21 dnl Note 1
22 dnl ------
23 dnl None of the CARES_CHECK_NEED_REENTRANT_* macros shall use HAVE_FOO_H to
24 dnl conditionally include header files. These macros are used early in the
25 dnl configure process much before header file availability is known.
26
27
28 dnl CARES_CHECK_NEED_REENTRANT_GMTIME_R
29 dnl -------------------------------------------------
30 dnl Checks if the preprocessor _REENTRANT definition
31 dnl makes function gmtime_r compiler visible.
32
33 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GMTIME_R], [
34   AC_LINK_IFELSE([
35     AC_LANG_FUNC_LINK_TRY([gmtime_r])
36   ],[
37     tmp_gmtime_r="yes"
38   ],[
39     tmp_gmtime_r="no"
40   ])
41   if test "$tmp_gmtime_r" = "yes"; then
42     AC_EGREP_CPP([gmtime_r],[
43 #include <sys/types.h>
44 #include <time.h>
45     ],[
46       tmp_gmtime_r="proto_declared"
47     ],[
48       AC_EGREP_CPP([gmtime_r],[
49 #define _REENTRANT
50 #include <sys/types.h>
51 #include <time.h>
52       ],[
53         tmp_gmtime_r="proto_needs_reentrant"
54         tmp_need_reentrant="yes"
55       ])
56     ])
57   fi
58 ])
59
60
61 dnl CARES_CHECK_NEED_REENTRANT_LOCALTIME_R
62 dnl -------------------------------------------------
63 dnl Checks if the preprocessor _REENTRANT definition
64 dnl makes function localtime_r compiler visible.
65
66 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_LOCALTIME_R], [
67   AC_LINK_IFELSE([
68     AC_LANG_FUNC_LINK_TRY([localtime_r])
69   ],[
70     tmp_localtime_r="yes"
71   ],[
72     tmp_localtime_r="no"
73   ])
74   if test "$tmp_localtime_r" = "yes"; then
75     AC_EGREP_CPP([localtime_r],[
76 #include <sys/types.h>
77 #include <time.h>
78     ],[
79       tmp_localtime_r="proto_declared"
80     ],[
81       AC_EGREP_CPP([localtime_r],[
82 #define _REENTRANT
83 #include <sys/types.h>
84 #include <time.h>
85       ],[
86         tmp_localtime_r="proto_needs_reentrant"
87         tmp_need_reentrant="yes"
88       ])
89     ])
90   fi
91 ])
92
93
94 dnl CARES_CHECK_NEED_REENTRANT_STRERROR_R
95 dnl -------------------------------------------------
96 dnl Checks if the preprocessor _REENTRANT definition
97 dnl makes function strerror_r compiler visible.
98
99 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_STRERROR_R], [
100   AC_LINK_IFELSE([
101     AC_LANG_FUNC_LINK_TRY([strerror_r])
102   ],[
103     tmp_strerror_r="yes"
104   ],[
105     tmp_strerror_r="no"
106   ])
107   if test "$tmp_strerror_r" = "yes"; then
108     AC_EGREP_CPP([strerror_r],[
109 #include <sys/types.h>
110 #include <string.h>
111     ],[
112       tmp_strerror_r="proto_declared"
113     ],[
114       AC_EGREP_CPP([strerror_r],[
115 #define _REENTRANT
116 #include <sys/types.h>
117 #include <string.h>
118       ],[
119         tmp_strerror_r="proto_needs_reentrant"
120         tmp_need_reentrant="yes"
121       ])
122     ])
123   fi
124 ])
125
126
127 dnl CARES_CHECK_NEED_REENTRANT_STRTOK_R
128 dnl -------------------------------------------------
129 dnl Checks if the preprocessor _REENTRANT definition
130 dnl makes function strtok_r compiler visible.
131
132 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_STRTOK_R], [
133   AC_LINK_IFELSE([
134     AC_LANG_FUNC_LINK_TRY([strtok_r])
135   ],[
136     tmp_strtok_r="yes"
137   ],[
138     tmp_strtok_r="no"
139   ])
140   if test "$tmp_strtok_r" = "yes"; then
141     AC_EGREP_CPP([strtok_r],[
142 #include <sys/types.h>
143 #include <string.h>
144     ],[
145       tmp_strtok_r="proto_declared"
146     ],[
147       AC_EGREP_CPP([strtok_r],[
148 #define _REENTRANT
149 #include <sys/types.h>
150 #include <string.h>
151       ],[
152         tmp_strtok_r="proto_needs_reentrant"
153         tmp_need_reentrant="yes"
154       ])
155     ])
156   fi
157 ])
158
159
160 dnl CARES_CHECK_NEED_REENTRANT_INET_NTOA_R
161 dnl -------------------------------------------------
162 dnl Checks if the preprocessor _REENTRANT definition
163 dnl makes function inet_ntoa_r compiler visible.
164
165 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_INET_NTOA_R], [
166   AC_LINK_IFELSE([
167     AC_LANG_FUNC_LINK_TRY([inet_ntoa_r])
168   ],[
169     tmp_inet_ntoa_r="yes"
170   ],[
171     tmp_inet_ntoa_r="no"
172   ])
173   if test "$tmp_inet_ntoa_r" = "yes"; then
174     AC_EGREP_CPP([inet_ntoa_r],[
175 #include <sys/types.h>
176 #include <sys/socket.h>
177 #include <netinet/in.h>
178 #include <arpa/inet.h>
179     ],[
180       tmp_inet_ntoa_r="proto_declared"
181     ],[
182       AC_EGREP_CPP([inet_ntoa_r],[
183 #define _REENTRANT
184 #include <sys/types.h>
185 #include <sys/socket.h>
186 #include <netinet/in.h>
187 #include <arpa/inet.h>
188       ],[
189         tmp_inet_ntoa_r="proto_needs_reentrant"
190         tmp_need_reentrant="yes"
191       ])
192     ])
193   fi
194 ])
195
196
197 dnl CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
198 dnl -------------------------------------------------
199 dnl Checks if the preprocessor _REENTRANT definition
200 dnl makes function gethostbyaddr_r compiler visible.
201
202 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R], [
203   AC_LINK_IFELSE([
204     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
205   ],[
206     tmp_gethostbyaddr_r="yes"
207   ],[
208     tmp_gethostbyaddr_r="no"
209   ])
210   if test "$tmp_gethostbyaddr_r" = "yes"; then
211     AC_EGREP_CPP([gethostbyaddr_r],[
212 #include <sys/types.h>
213 #include <netdb.h>
214     ],[
215       tmp_gethostbyaddr_r="proto_declared"
216     ],[
217       AC_EGREP_CPP([gethostbyaddr_r],[
218 #define _REENTRANT
219 #include <sys/types.h>
220 #include <netdb.h>
221       ],[
222         tmp_gethostbyaddr_r="proto_needs_reentrant"
223         tmp_need_reentrant="yes"
224       ])
225     ])
226   fi
227 ])
228
229
230 dnl CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
231 dnl -------------------------------------------------
232 dnl Checks if the preprocessor _REENTRANT definition
233 dnl makes function gethostbyname_r compiler visible.
234
235 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R], [
236   AC_LINK_IFELSE([
237     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
238   ],[
239     tmp_gethostbyname_r="yes"
240   ],[
241     tmp_gethostbyname_r="no"
242   ])
243   if test "$tmp_gethostbyname_r" = "yes"; then
244     AC_EGREP_CPP([gethostbyname_r],[
245 #include <sys/types.h>
246 #include <netdb.h>
247     ],[
248       tmp_gethostbyname_r="proto_declared"
249     ],[
250       AC_EGREP_CPP([gethostbyname_r],[
251 #define _REENTRANT
252 #include <sys/types.h>
253 #include <netdb.h>
254       ],[
255         tmp_gethostbyname_r="proto_needs_reentrant"
256         tmp_need_reentrant="yes"
257       ])
258     ])
259   fi
260 ])
261
262
263 dnl CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
264 dnl -------------------------------------------------
265 dnl Checks if the preprocessor _REENTRANT definition
266 dnl makes function getprotobyname_r compiler visible.
267
268 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R], [
269   AC_LINK_IFELSE([
270     AC_LANG_FUNC_LINK_TRY([getprotobyname_r])
271   ],[
272     tmp_getprotobyname_r="yes"
273   ],[
274     tmp_getprotobyname_r="no"
275   ])
276   if test "$tmp_getprotobyname_r" = "yes"; then
277     AC_EGREP_CPP([getprotobyname_r],[
278 #include <sys/types.h>
279 #include <netdb.h>
280     ],[
281       tmp_getprotobyname_r="proto_declared"
282     ],[
283       AC_EGREP_CPP([getprotobyname_r],[
284 #define _REENTRANT
285 #include <sys/types.h>
286 #include <netdb.h>
287       ],[
288         tmp_getprotobyname_r="proto_needs_reentrant"
289         tmp_need_reentrant="yes"
290       ])
291     ])
292   fi
293 ])
294
295
296 dnl CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
297 dnl -------------------------------------------------
298 dnl Checks if the preprocessor _REENTRANT definition
299 dnl makes function getservbyport_r compiler visible.
300
301 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R], [
302   AC_LINK_IFELSE([
303     AC_LANG_FUNC_LINK_TRY([getservbyport_r])
304   ],[
305     tmp_getservbyport_r="yes"
306   ],[
307     tmp_getservbyport_r="no"
308   ])
309   if test "$tmp_getservbyport_r" = "yes"; then
310     AC_EGREP_CPP([getservbyport_r],[
311 #include <sys/types.h>
312 #include <netdb.h>
313     ],[
314       tmp_getservbyport_r="proto_declared"
315     ],[
316       AC_EGREP_CPP([getservbyport_r],[
317 #define _REENTRANT
318 #include <sys/types.h>
319 #include <netdb.h>
320       ],[
321         tmp_getservbyport_r="proto_needs_reentrant"
322         tmp_need_reentrant="yes"
323       ])
324     ])
325   fi
326 ])
327
328
329 dnl CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R
330 dnl -------------------------------------------------
331 dnl Checks if the preprocessor _REENTRANT definition
332 dnl makes several _r functions compiler visible.
333 dnl Internal macro for CARES_CONFIGURE_REENTRANT.
334
335 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
336   #
337   tmp_need_reentrant="no"
338   #
339   if test "$tmp_need_reentrant" = "no"; then
340     CARES_CHECK_NEED_REENTRANT_GMTIME_R
341   fi
342   if test "$tmp_need_reentrant" = "no"; then
343     CARES_CHECK_NEED_REENTRANT_LOCALTIME_R
344   fi
345   if test "$tmp_need_reentrant" = "no"; then
346     CARES_CHECK_NEED_REENTRANT_STRERROR_R
347   fi
348   if test "$tmp_need_reentrant" = "no"; then
349     CARES_CHECK_NEED_REENTRANT_STRTOK_R
350   fi
351   if test "$tmp_need_reentrant" = "no"; then
352     CARES_CHECK_NEED_REENTRANT_INET_NTOA_R
353   fi
354   if test "$tmp_need_reentrant" = "no"; then
355     CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
356   fi
357   if test "$tmp_need_reentrant" = "no"; then
358     CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
359   fi
360   if test "$tmp_need_reentrant" = "no"; then
361     CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
362   fi
363   if test "$tmp_need_reentrant" = "no"; then
364     CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
365   fi
366 ])
367
368
369 dnl CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
370 dnl -------------------------------------------------
371 dnl This macro ensures that configuration tests done
372 dnl after this will execute with preprocessor symbol
373 dnl _REENTRANT defined. This macro also ensures that
374 dnl the generated config file defines NEED_REENTRANT
375 dnl and that in turn setup.h will define _REENTRANT.
376 dnl Internal macro for CARES_CONFIGURE_REENTRANT.
377
378 AC_DEFUN([CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
379 AC_DEFINE(NEED_REENTRANT, 1,
380   [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
381 cat >>confdefs.h <<_EOF
382 #ifndef _REENTRANT
383 #  define _REENTRANT
384 #endif
385 _EOF
386 ])
387
388
389 dnl CARES_CONFIGURE_REENTRANT
390 dnl -------------------------------------------------
391 dnl This first checks if the preprocessor _REENTRANT
392 dnl symbol is already defined. If it isn't currently
393 dnl defined a set of checks are performed to verify
394 dnl if its definition is required to make visible to
395 dnl the compiler a set of *_r functions. Finally, if
396 dnl _REENTRANT is already defined or needed it takes
397 dnl care of making adjustments necessary to ensure
398 dnl that it is defined equally for further configure
399 dnl tests and generated config file.
400
401 AC_DEFUN([CARES_CONFIGURE_REENTRANT], [
402   AC_PREREQ([2.57])dnl
403   #
404   AC_MSG_CHECKING([if _REENTRANT is already defined])
405   AC_COMPILE_IFELSE([
406     AC_LANG_PROGRAM([[
407     ]],[[
408 #ifdef _REENTRANT
409       int dummy=1;
410 #else
411       force compilation error
412 #endif
413     ]])
414   ],[
415     AC_MSG_RESULT([yes])
416     tmp_reentrant_initially_defined="yes"
417   ],[
418     AC_MSG_RESULT([no])
419     tmp_reentrant_initially_defined="no"
420   ])
421   #
422   if test "$tmp_reentrant_initially_defined" = "no"; then
423     AC_MSG_CHECKING([if _REENTRANT is actually needed])
424     CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R
425     if test "$tmp_need_reentrant" = "yes"; then
426       AC_MSG_RESULT([yes])
427     else
428       AC_MSG_RESULT([no])
429     fi
430   fi
431   #
432   AC_MSG_CHECKING([if _REENTRANT is onwards defined])
433   if test "$tmp_reentrant_initially_defined" = "yes" ||
434     test "$tmp_need_reentrant" = "yes"; then
435     CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
436     AC_MSG_RESULT([yes])
437   else
438     AC_MSG_RESULT([no])
439   fi
440   #
441 ])
442