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