4b619c3740052f382b9142b1e06b8f862c3cc0a9
[platform/upstream/curl.git] / m4 / curl-reentrant.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 #***************************************************************************
23
24 # File version for 'aclocal' use. Keep it a single number.
25 # serial 8
26
27 dnl Note 1
28 dnl ------
29 dnl None of the CURL_CHECK_NEED_REENTRANT_* macros shall use HAVE_FOO_H to
30 dnl conditionally include header files. These macros are used early in the
31 dnl configure process much before header file availability is known.
32
33
34 dnl CURL_CHECK_NEED_REENTRANT_ERRNO
35 dnl -------------------------------------------------
36 dnl Checks if the preprocessor _REENTRANT definition
37 dnl makes errno available as a preprocessor macro.
38
39 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_ERRNO], [
40   AC_COMPILE_IFELSE([
41     AC_LANG_PROGRAM([[
42 #include <errno.h>
43     ]],[[
44       if(0 != errno)
45         return 1;
46     ]])
47   ],[
48     tmp_errno="yes"
49   ],[
50     tmp_errno="no"
51   ])
52   if test "$tmp_errno" = "yes"; then
53     AC_COMPILE_IFELSE([
54       AC_LANG_PROGRAM([[
55 #include <errno.h>
56       ]],[[
57 #ifdef errno
58         int dummy=1;
59 #else
60         force compilation error
61 #endif
62       ]])
63     ],[
64       tmp_errno="errno_macro_defined"
65     ],[
66       AC_COMPILE_IFELSE([
67         AC_LANG_PROGRAM([[
68 #define _REENTRANT
69 #include <errno.h>
70         ]],[[
71 #ifdef errno
72           int dummy=1;
73 #else
74           force compilation error
75 #endif
76         ]])
77       ],[
78         tmp_errno="errno_macro_needs_reentrant"
79         tmp_need_reentrant="yes"
80       ])
81     ])
82   fi
83 ])
84
85
86 dnl CURL_CHECK_NEED_REENTRANT_GMTIME_R
87 dnl -------------------------------------------------
88 dnl Checks if the preprocessor _REENTRANT definition
89 dnl makes function gmtime_r compiler visible.
90
91 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GMTIME_R], [
92   AC_LINK_IFELSE([
93     AC_LANG_FUNC_LINK_TRY([gmtime_r])
94   ],[
95     tmp_gmtime_r="yes"
96   ],[
97     tmp_gmtime_r="no"
98   ])
99   if test "$tmp_gmtime_r" = "yes"; then
100     AC_EGREP_CPP([gmtime_r],[
101 #include <sys/types.h>
102 #include <time.h>
103     ],[
104       tmp_gmtime_r="proto_declared"
105     ],[
106       AC_EGREP_CPP([gmtime_r],[
107 #define _REENTRANT
108 #include <sys/types.h>
109 #include <time.h>
110       ],[
111         tmp_gmtime_r="proto_needs_reentrant"
112         tmp_need_reentrant="yes"
113       ])
114     ])
115   fi
116 ])
117
118
119 dnl CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
120 dnl -------------------------------------------------
121 dnl Checks if the preprocessor _REENTRANT definition
122 dnl makes function localtime_r compiler visible.
123
124 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_LOCALTIME_R], [
125   AC_LINK_IFELSE([
126     AC_LANG_FUNC_LINK_TRY([localtime_r])
127   ],[
128     tmp_localtime_r="yes"
129   ],[
130     tmp_localtime_r="no"
131   ])
132   if test "$tmp_localtime_r" = "yes"; then
133     AC_EGREP_CPP([localtime_r],[
134 #include <sys/types.h>
135 #include <time.h>
136     ],[
137       tmp_localtime_r="proto_declared"
138     ],[
139       AC_EGREP_CPP([localtime_r],[
140 #define _REENTRANT
141 #include <sys/types.h>
142 #include <time.h>
143       ],[
144         tmp_localtime_r="proto_needs_reentrant"
145         tmp_need_reentrant="yes"
146       ])
147     ])
148   fi
149 ])
150
151
152 dnl CURL_CHECK_NEED_REENTRANT_STRERROR_R
153 dnl -------------------------------------------------
154 dnl Checks if the preprocessor _REENTRANT definition
155 dnl makes function strerror_r compiler visible.
156
157 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRERROR_R], [
158   AC_LINK_IFELSE([
159     AC_LANG_FUNC_LINK_TRY([strerror_r])
160   ],[
161     tmp_strerror_r="yes"
162   ],[
163     tmp_strerror_r="no"
164   ])
165   if test "$tmp_strerror_r" = "yes"; then
166     AC_EGREP_CPP([strerror_r],[
167 #include <sys/types.h>
168 #include <string.h>
169     ],[
170       tmp_strerror_r="proto_declared"
171     ],[
172       AC_EGREP_CPP([strerror_r],[
173 #define _REENTRANT
174 #include <sys/types.h>
175 #include <string.h>
176       ],[
177         tmp_strerror_r="proto_needs_reentrant"
178         tmp_need_reentrant="yes"
179       ])
180     ])
181   fi
182 ])
183
184
185 dnl CURL_CHECK_NEED_REENTRANT_STRTOK_R
186 dnl -------------------------------------------------
187 dnl Checks if the preprocessor _REENTRANT definition
188 dnl makes function strtok_r compiler visible.
189
190 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRTOK_R], [
191   AC_LINK_IFELSE([
192     AC_LANG_FUNC_LINK_TRY([strtok_r])
193   ],[
194     tmp_strtok_r="yes"
195   ],[
196     tmp_strtok_r="no"
197   ])
198   if test "$tmp_strtok_r" = "yes"; then
199     AC_EGREP_CPP([strtok_r],[
200 #include <sys/types.h>
201 #include <string.h>
202     ],[
203       tmp_strtok_r="proto_declared"
204     ],[
205       AC_EGREP_CPP([strtok_r],[
206 #define _REENTRANT
207 #include <sys/types.h>
208 #include <string.h>
209       ],[
210         tmp_strtok_r="proto_needs_reentrant"
211         tmp_need_reentrant="yes"
212       ])
213     ])
214   fi
215 ])
216
217
218 dnl CURL_CHECK_NEED_REENTRANT_INET_NTOA_R
219 dnl -------------------------------------------------
220 dnl Checks if the preprocessor _REENTRANT definition
221 dnl makes function inet_ntoa_r compiler visible.
222
223 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_INET_NTOA_R], [
224   AC_LINK_IFELSE([
225     AC_LANG_FUNC_LINK_TRY([inet_ntoa_r])
226   ],[
227     tmp_inet_ntoa_r="yes"
228   ],[
229     tmp_inet_ntoa_r="no"
230   ])
231   if test "$tmp_inet_ntoa_r" = "yes"; then
232     AC_EGREP_CPP([inet_ntoa_r],[
233 #include <sys/types.h>
234 #include <sys/socket.h>
235 #include <netinet/in.h>
236 #include <arpa/inet.h>
237     ],[
238       tmp_inet_ntoa_r="proto_declared"
239     ],[
240       AC_EGREP_CPP([inet_ntoa_r],[
241 #define _REENTRANT
242 #include <sys/types.h>
243 #include <sys/socket.h>
244 #include <netinet/in.h>
245 #include <arpa/inet.h>
246       ],[
247         tmp_inet_ntoa_r="proto_needs_reentrant"
248         tmp_need_reentrant="yes"
249       ])
250     ])
251   fi
252 ])
253
254
255 dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
256 dnl -------------------------------------------------
257 dnl Checks if the preprocessor _REENTRANT definition
258 dnl makes function gethostbyaddr_r compiler visible.
259
260 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R], [
261   AC_LINK_IFELSE([
262     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
263   ],[
264     tmp_gethostbyaddr_r="yes"
265   ],[
266     tmp_gethostbyaddr_r="no"
267   ])
268   if test "$tmp_gethostbyaddr_r" = "yes"; then
269     AC_EGREP_CPP([gethostbyaddr_r],[
270 #include <sys/types.h>
271 #include <netdb.h>
272     ],[
273       tmp_gethostbyaddr_r="proto_declared"
274     ],[
275       AC_EGREP_CPP([gethostbyaddr_r],[
276 #define _REENTRANT
277 #include <sys/types.h>
278 #include <netdb.h>
279       ],[
280         tmp_gethostbyaddr_r="proto_needs_reentrant"
281         tmp_need_reentrant="yes"
282       ])
283     ])
284   fi
285 ])
286
287
288 dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
289 dnl -------------------------------------------------
290 dnl Checks if the preprocessor _REENTRANT definition
291 dnl makes function gethostbyname_r compiler visible.
292
293 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R], [
294   AC_LINK_IFELSE([
295     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
296   ],[
297     tmp_gethostbyname_r="yes"
298   ],[
299     tmp_gethostbyname_r="no"
300   ])
301   if test "$tmp_gethostbyname_r" = "yes"; then
302     AC_EGREP_CPP([gethostbyname_r],[
303 #include <sys/types.h>
304 #include <netdb.h>
305     ],[
306       tmp_gethostbyname_r="proto_declared"
307     ],[
308       AC_EGREP_CPP([gethostbyname_r],[
309 #define _REENTRANT
310 #include <sys/types.h>
311 #include <netdb.h>
312       ],[
313         tmp_gethostbyname_r="proto_needs_reentrant"
314         tmp_need_reentrant="yes"
315       ])
316     ])
317   fi
318 ])
319
320
321 dnl CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
322 dnl -------------------------------------------------
323 dnl Checks if the preprocessor _REENTRANT definition
324 dnl makes function getprotobyname_r compiler visible.
325
326 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R], [
327   AC_LINK_IFELSE([
328     AC_LANG_FUNC_LINK_TRY([getprotobyname_r])
329   ],[
330     tmp_getprotobyname_r="yes"
331   ],[
332     tmp_getprotobyname_r="no"
333   ])
334   if test "$tmp_getprotobyname_r" = "yes"; then
335     AC_EGREP_CPP([getprotobyname_r],[
336 #include <sys/types.h>
337 #include <netdb.h>
338     ],[
339       tmp_getprotobyname_r="proto_declared"
340     ],[
341       AC_EGREP_CPP([getprotobyname_r],[
342 #define _REENTRANT
343 #include <sys/types.h>
344 #include <netdb.h>
345       ],[
346         tmp_getprotobyname_r="proto_needs_reentrant"
347         tmp_need_reentrant="yes"
348       ])
349     ])
350   fi
351 ])
352
353
354 dnl CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
355 dnl -------------------------------------------------
356 dnl Checks if the preprocessor _REENTRANT definition
357 dnl makes function getservbyport_r compiler visible.
358
359 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R], [
360   AC_LINK_IFELSE([
361     AC_LANG_FUNC_LINK_TRY([getservbyport_r])
362   ],[
363     tmp_getservbyport_r="yes"
364   ],[
365     tmp_getservbyport_r="no"
366   ])
367   if test "$tmp_getservbyport_r" = "yes"; then
368     AC_EGREP_CPP([getservbyport_r],[
369 #include <sys/types.h>
370 #include <netdb.h>
371     ],[
372       tmp_getservbyport_r="proto_declared"
373     ],[
374       AC_EGREP_CPP([getservbyport_r],[
375 #define _REENTRANT
376 #include <sys/types.h>
377 #include <netdb.h>
378       ],[
379         tmp_getservbyport_r="proto_needs_reentrant"
380         tmp_need_reentrant="yes"
381       ])
382     ])
383   fi
384 ])
385
386
387 dnl CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
388 dnl -------------------------------------------------
389 dnl Checks if the preprocessor _REENTRANT definition
390 dnl makes several _r functions compiler visible.
391 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
392
393 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
394   if test "$tmp_need_reentrant" = "no"; then
395     CURL_CHECK_NEED_REENTRANT_GMTIME_R
396   fi
397   if test "$tmp_need_reentrant" = "no"; then
398     CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
399   fi
400   if test "$tmp_need_reentrant" = "no"; then
401     CURL_CHECK_NEED_REENTRANT_STRERROR_R
402   fi
403   if test "$tmp_need_reentrant" = "no"; then
404     CURL_CHECK_NEED_REENTRANT_STRTOK_R
405   fi
406   if test "$tmp_need_reentrant" = "no"; then
407     CURL_CHECK_NEED_REENTRANT_INET_NTOA_R
408   fi
409   if test "$tmp_need_reentrant" = "no"; then
410     CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
411   fi
412   if test "$tmp_need_reentrant" = "no"; then
413     CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
414   fi
415   if test "$tmp_need_reentrant" = "no"; then
416     CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
417   fi
418   if test "$tmp_need_reentrant" = "no"; then
419     CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
420   fi
421 ])
422
423
424 dnl CURL_CHECK_NEED_REENTRANT_SYSTEM
425 dnl -------------------------------------------------
426 dnl Checks if the preprocessor _REENTRANT definition
427 dnl must be unconditionally done for this platform.
428 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
429
430 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [
431   case $host_os in
432     solaris*)
433       tmp_need_reentrant="yes"
434       ;;
435     *)
436       tmp_need_reentrant="no"
437       ;;
438   esac
439 ])
440
441
442 dnl CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
443 dnl -------------------------------------------------
444 dnl Checks if the preprocessor _THREAD_SAFE definition
445 dnl must be unconditionally done for this platform.
446 dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
447
448 AC_DEFUN([CURL_CHECK_NEED_THREAD_SAFE_SYSTEM], [
449   case $host_os in
450     aix[[123]].* | aix4.[[012]].*)
451       dnl aix 4.2 and older
452       tmp_need_thread_safe="no"
453       ;;
454     aix*)
455       dnl AIX 4.3 and newer
456       tmp_need_thread_safe="yes"
457       ;;
458     *)
459       tmp_need_thread_safe="no"
460       ;;
461   esac
462 ])
463
464
465 dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
466 dnl -------------------------------------------------
467 dnl This macro ensures that configuration tests done
468 dnl after this will execute with preprocessor symbol
469 dnl _REENTRANT defined. This macro also ensures that
470 dnl the generated config file defines NEED_REENTRANT
471 dnl and that in turn setup.h will define _REENTRANT.
472 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
473
474 AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
475 AC_DEFINE(NEED_REENTRANT, 1,
476   [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
477 cat >>confdefs.h <<_EOF
478 #ifndef _REENTRANT
479 #  define _REENTRANT
480 #endif
481 _EOF
482 ])
483
484
485 dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
486 dnl -------------------------------------------------
487 dnl This macro ensures that configuration tests done
488 dnl after this will execute with preprocessor symbol
489 dnl _THREAD_SAFE defined. This macro also ensures that
490 dnl the generated config file defines NEED_THREAD_SAFE
491 dnl and that in turn setup.h will define _THREAD_SAFE.
492 dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
493
494 AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE], [
495 AC_DEFINE(NEED_THREAD_SAFE, 1,
496   [Define to 1 if _THREAD_SAFE preprocessor symbol must be defined.])
497 cat >>confdefs.h <<_EOF
498 #ifndef _THREAD_SAFE
499 #  define _THREAD_SAFE
500 #endif
501 _EOF
502 ])
503
504
505 dnl CURL_CONFIGURE_REENTRANT
506 dnl -------------------------------------------------
507 dnl This first checks if the preprocessor _REENTRANT
508 dnl symbol is already defined. If it isn't currently
509 dnl defined a set of checks are performed to verify
510 dnl if its definition is required to make visible to
511 dnl the compiler a set of *_r functions. Finally, if
512 dnl _REENTRANT is already defined or needed it takes
513 dnl care of making adjustments necessary to ensure
514 dnl that it is defined equally for further configure
515 dnl tests and generated config file.
516
517 AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
518   AC_PREREQ([2.50])dnl
519   #
520   AC_MSG_CHECKING([if _REENTRANT is already defined])
521   AC_COMPILE_IFELSE([
522     AC_LANG_PROGRAM([[
523     ]],[[
524 #ifdef _REENTRANT
525       int dummy=1;
526 #else
527       force compilation error
528 #endif
529     ]])
530   ],[
531     AC_MSG_RESULT([yes])
532     tmp_reentrant_initially_defined="yes"
533   ],[
534     AC_MSG_RESULT([no])
535     tmp_reentrant_initially_defined="no"
536   ])
537   #
538   if test "$tmp_reentrant_initially_defined" = "no"; then
539     AC_MSG_CHECKING([if _REENTRANT is actually needed])
540     CURL_CHECK_NEED_REENTRANT_SYSTEM
541     if test "$tmp_need_reentrant" = "no"; then
542       CURL_CHECK_NEED_REENTRANT_ERRNO
543     fi
544     if test "$tmp_need_reentrant" = "no"; then
545       CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
546     fi
547     if test "$tmp_need_reentrant" = "yes"; then
548       AC_MSG_RESULT([yes])
549     else
550       AC_MSG_RESULT([no])
551     fi
552   fi
553   #
554   AC_MSG_CHECKING([if _REENTRANT is onwards defined])
555   if test "$tmp_reentrant_initially_defined" = "yes" ||
556     test "$tmp_need_reentrant" = "yes"; then
557     CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
558     AC_MSG_RESULT([yes])
559   else
560     AC_MSG_RESULT([no])
561   fi
562   #
563 ])
564
565
566 dnl CURL_CONFIGURE_THREAD_SAFE
567 dnl -------------------------------------------------
568 dnl This first checks if the preprocessor _THREAD_SAFE
569 dnl symbol is already defined. If it isn't currently
570 dnl defined a set of checks are performed to verify
571 dnl if its definition is required. Finally, if
572 dnl _THREAD_SAFE is already defined or needed it takes
573 dnl care of making adjustments necessary to ensure
574 dnl that it is defined equally for further configure
575 dnl tests and generated config file.
576
577 AC_DEFUN([CURL_CONFIGURE_THREAD_SAFE], [
578   AC_PREREQ([2.50])dnl
579   #
580   AC_MSG_CHECKING([if _THREAD_SAFE is already defined])
581   AC_COMPILE_IFELSE([
582     AC_LANG_PROGRAM([[
583     ]],[[
584 #ifdef _THREAD_SAFE
585       int dummy=1;
586 #else
587       force compilation error
588 #endif
589     ]])
590   ],[
591     AC_MSG_RESULT([yes])
592     tmp_thread_safe_initially_defined="yes"
593   ],[
594     AC_MSG_RESULT([no])
595     tmp_thread_safe_initially_defined="no"
596   ])
597   #
598   if test "$tmp_thread_safe_initially_defined" = "no"; then
599     AC_MSG_CHECKING([if _THREAD_SAFE is actually needed])
600     CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
601     if test "$tmp_need_thread_safe" = "yes"; then
602       AC_MSG_RESULT([yes])
603     else
604       AC_MSG_RESULT([no])
605     fi
606   fi
607   #
608   AC_MSG_CHECKING([if _THREAD_SAFE is onwards defined])
609   if test "$tmp_thread_safe_initially_defined" = "yes" ||
610     test "$tmp_need_thread_safe" = "yes"; then
611     CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
612     AC_MSG_RESULT([yes])
613   else
614     AC_MSG_RESULT([no])
615   fi
616   #
617 ])
618