2
0

curl-reentrant.m4 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2021, 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 https://curl.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. #***************************************************************************
  22. # File version for 'aclocal' use. Keep it a single number.
  23. # serial 10
  24. dnl Note 1
  25. dnl ------
  26. dnl None of the CURL_CHECK_NEED_REENTRANT_* macros shall use HAVE_FOO_H to
  27. dnl conditionally include header files. These macros are used early in the
  28. dnl configure process much before header file availability is known.
  29. dnl CURL_CHECK_NEED_REENTRANT_ERRNO
  30. dnl -------------------------------------------------
  31. dnl Checks if the preprocessor _REENTRANT definition
  32. dnl makes errno available as a preprocessor macro.
  33. AC_DEFUN([CURL_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. dnl CURL_CHECK_NEED_REENTRANT_GMTIME_R
  79. dnl -------------------------------------------------
  80. dnl Checks if the preprocessor _REENTRANT definition
  81. dnl makes function gmtime_r compiler visible.
  82. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GMTIME_R], [
  83. AC_LINK_IFELSE([
  84. AC_LANG_FUNC_LINK_TRY([gmtime_r])
  85. ],[
  86. tmp_gmtime_r="yes"
  87. ],[
  88. tmp_gmtime_r="no"
  89. ])
  90. if test "$tmp_gmtime_r" = "yes"; then
  91. AC_EGREP_CPP([gmtime_r],[
  92. #include <sys/types.h>
  93. #include <time.h>
  94. ],[
  95. tmp_gmtime_r="proto_declared"
  96. ],[
  97. AC_EGREP_CPP([gmtime_r],[
  98. #define _REENTRANT
  99. #include <sys/types.h>
  100. #include <time.h>
  101. ],[
  102. tmp_gmtime_r="proto_needs_reentrant"
  103. tmp_need_reentrant="yes"
  104. ])
  105. ])
  106. fi
  107. ])
  108. dnl CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
  109. dnl -------------------------------------------------
  110. dnl Checks if the preprocessor _REENTRANT definition
  111. dnl makes function localtime_r compiler visible.
  112. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_LOCALTIME_R], [
  113. AC_LINK_IFELSE([
  114. AC_LANG_FUNC_LINK_TRY([localtime_r])
  115. ],[
  116. tmp_localtime_r="yes"
  117. ],[
  118. tmp_localtime_r="no"
  119. ])
  120. if test "$tmp_localtime_r" = "yes"; then
  121. AC_EGREP_CPP([localtime_r],[
  122. #include <sys/types.h>
  123. #include <time.h>
  124. ],[
  125. tmp_localtime_r="proto_declared"
  126. ],[
  127. AC_EGREP_CPP([localtime_r],[
  128. #define _REENTRANT
  129. #include <sys/types.h>
  130. #include <time.h>
  131. ],[
  132. tmp_localtime_r="proto_needs_reentrant"
  133. tmp_need_reentrant="yes"
  134. ])
  135. ])
  136. fi
  137. ])
  138. dnl CURL_CHECK_NEED_REENTRANT_STRERROR_R
  139. dnl -------------------------------------------------
  140. dnl Checks if the preprocessor _REENTRANT definition
  141. dnl makes function strerror_r compiler visible.
  142. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRERROR_R], [
  143. AC_LINK_IFELSE([
  144. AC_LANG_FUNC_LINK_TRY([strerror_r])
  145. ],[
  146. tmp_strerror_r="yes"
  147. ],[
  148. tmp_strerror_r="no"
  149. ])
  150. if test "$tmp_strerror_r" = "yes"; then
  151. AC_EGREP_CPP([strerror_r],[
  152. #include <sys/types.h>
  153. #include <string.h>
  154. ],[
  155. tmp_strerror_r="proto_declared"
  156. ],[
  157. AC_EGREP_CPP([strerror_r],[
  158. #define _REENTRANT
  159. #include <sys/types.h>
  160. #include <string.h>
  161. ],[
  162. tmp_strerror_r="proto_needs_reentrant"
  163. tmp_need_reentrant="yes"
  164. ])
  165. ])
  166. fi
  167. ])
  168. dnl CURL_CHECK_NEED_REENTRANT_STRTOK_R
  169. dnl -------------------------------------------------
  170. dnl Checks if the preprocessor _REENTRANT definition
  171. dnl makes function strtok_r compiler visible.
  172. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRTOK_R], [
  173. AC_LINK_IFELSE([
  174. AC_LANG_FUNC_LINK_TRY([strtok_r])
  175. ],[
  176. tmp_strtok_r="yes"
  177. ],[
  178. tmp_strtok_r="no"
  179. ])
  180. if test "$tmp_strtok_r" = "yes"; then
  181. AC_EGREP_CPP([strtok_r],[
  182. #include <sys/types.h>
  183. #include <string.h>
  184. ],[
  185. tmp_strtok_r="proto_declared"
  186. ],[
  187. AC_EGREP_CPP([strtok_r],[
  188. #define _REENTRANT
  189. #include <sys/types.h>
  190. #include <string.h>
  191. ],[
  192. tmp_strtok_r="proto_needs_reentrant"
  193. tmp_need_reentrant="yes"
  194. ])
  195. ])
  196. fi
  197. ])
  198. dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
  199. dnl -------------------------------------------------
  200. dnl Checks if the preprocessor _REENTRANT definition
  201. dnl makes function gethostbyname_r compiler visible.
  202. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R], [
  203. AC_LINK_IFELSE([
  204. AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
  205. ],[
  206. tmp_gethostbyname_r="yes"
  207. ],[
  208. tmp_gethostbyname_r="no"
  209. ])
  210. if test "$tmp_gethostbyname_r" = "yes"; then
  211. AC_EGREP_CPP([gethostbyname_r],[
  212. #include <sys/types.h>
  213. #include <netdb.h>
  214. ],[
  215. tmp_gethostbyname_r="proto_declared"
  216. ],[
  217. AC_EGREP_CPP([gethostbyname_r],[
  218. #define _REENTRANT
  219. #include <sys/types.h>
  220. #include <netdb.h>
  221. ],[
  222. tmp_gethostbyname_r="proto_needs_reentrant"
  223. tmp_need_reentrant="yes"
  224. ])
  225. ])
  226. fi
  227. ])
  228. dnl CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
  229. dnl -------------------------------------------------
  230. dnl Checks if the preprocessor _REENTRANT definition
  231. dnl makes function getprotobyname_r compiler visible.
  232. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R], [
  233. AC_LINK_IFELSE([
  234. AC_LANG_FUNC_LINK_TRY([getprotobyname_r])
  235. ],[
  236. tmp_getprotobyname_r="yes"
  237. ],[
  238. tmp_getprotobyname_r="no"
  239. ])
  240. if test "$tmp_getprotobyname_r" = "yes"; then
  241. AC_EGREP_CPP([getprotobyname_r],[
  242. #include <sys/types.h>
  243. #include <netdb.h>
  244. ],[
  245. tmp_getprotobyname_r="proto_declared"
  246. ],[
  247. AC_EGREP_CPP([getprotobyname_r],[
  248. #define _REENTRANT
  249. #include <sys/types.h>
  250. #include <netdb.h>
  251. ],[
  252. tmp_getprotobyname_r="proto_needs_reentrant"
  253. tmp_need_reentrant="yes"
  254. ])
  255. ])
  256. fi
  257. ])
  258. dnl CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
  259. dnl -------------------------------------------------
  260. dnl Checks if the preprocessor _REENTRANT definition
  261. dnl makes several _r functions compiler visible.
  262. dnl Internal macro for CURL_CONFIGURE_REENTRANT.
  263. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
  264. if test "$tmp_need_reentrant" = "no"; then
  265. CURL_CHECK_NEED_REENTRANT_GMTIME_R
  266. fi
  267. if test "$tmp_need_reentrant" = "no"; then
  268. CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
  269. fi
  270. if test "$tmp_need_reentrant" = "no"; then
  271. CURL_CHECK_NEED_REENTRANT_STRERROR_R
  272. fi
  273. if test "$tmp_need_reentrant" = "no"; then
  274. CURL_CHECK_NEED_REENTRANT_STRTOK_R
  275. fi
  276. if test "$tmp_need_reentrant" = "no"; then
  277. CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
  278. fi
  279. if test "$tmp_need_reentrant" = "no"; then
  280. CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
  281. fi
  282. ])
  283. dnl CURL_CHECK_NEED_REENTRANT_SYSTEM
  284. dnl -------------------------------------------------
  285. dnl Checks if the preprocessor _REENTRANT definition
  286. dnl must be unconditionally done for this platform.
  287. dnl Internal macro for CURL_CONFIGURE_REENTRANT.
  288. AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [
  289. case $host_os in
  290. solaris*)
  291. tmp_need_reentrant="yes"
  292. ;;
  293. *)
  294. tmp_need_reentrant="no"
  295. ;;
  296. esac
  297. ])
  298. dnl CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
  299. dnl -------------------------------------------------
  300. dnl Checks if the preprocessor _THREAD_SAFE definition
  301. dnl must be unconditionally done for this platform.
  302. dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
  303. AC_DEFUN([CURL_CHECK_NEED_THREAD_SAFE_SYSTEM], [
  304. case $host_os in
  305. aix[[123]].* | aix4.[[012]].*)
  306. dnl aix 4.2 and older
  307. tmp_need_thread_safe="no"
  308. ;;
  309. aix*)
  310. dnl AIX 4.3 and newer
  311. tmp_need_thread_safe="yes"
  312. ;;
  313. *)
  314. tmp_need_thread_safe="no"
  315. ;;
  316. esac
  317. ])
  318. dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
  319. dnl -------------------------------------------------
  320. dnl This macro ensures that configuration tests done
  321. dnl after this will execute with preprocessor symbol
  322. dnl _REENTRANT defined. This macro also ensures that
  323. dnl the generated config file defines NEED_REENTRANT
  324. dnl and that in turn curl_setup.h will define _REENTRANT.
  325. dnl Internal macro for CURL_CONFIGURE_REENTRANT.
  326. AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
  327. AC_DEFINE(NEED_REENTRANT, 1,
  328. [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
  329. cat >>confdefs.h <<_EOF
  330. #ifndef _REENTRANT
  331. # define _REENTRANT
  332. #endif
  333. _EOF
  334. ])
  335. dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
  336. dnl -------------------------------------------------
  337. dnl This macro ensures that configuration tests done
  338. dnl after this will execute with preprocessor symbol
  339. dnl _THREAD_SAFE defined. This macro also ensures that
  340. dnl the generated config file defines NEED_THREAD_SAFE
  341. dnl and that in turn curl_setup.h will define _THREAD_SAFE.
  342. dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
  343. AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE], [
  344. AC_DEFINE(NEED_THREAD_SAFE, 1,
  345. [Define to 1 if _THREAD_SAFE preprocessor symbol must be defined.])
  346. cat >>confdefs.h <<_EOF
  347. #ifndef _THREAD_SAFE
  348. # define _THREAD_SAFE
  349. #endif
  350. _EOF
  351. ])
  352. dnl CURL_CONFIGURE_REENTRANT
  353. dnl -------------------------------------------------
  354. dnl This first checks if the preprocessor _REENTRANT
  355. dnl symbol is already defined. If it isn't currently
  356. dnl defined a set of checks are performed to verify
  357. dnl if its definition is required to make visible to
  358. dnl the compiler a set of *_r functions. Finally, if
  359. dnl _REENTRANT is already defined or needed it takes
  360. dnl care of making adjustments necessary to ensure
  361. dnl that it is defined equally for further configure
  362. dnl tests and generated config file.
  363. AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
  364. AC_PREREQ([2.50])dnl
  365. #
  366. AC_MSG_CHECKING([if _REENTRANT is already defined])
  367. AC_COMPILE_IFELSE([
  368. AC_LANG_PROGRAM([[
  369. ]],[[
  370. #ifdef _REENTRANT
  371. int dummy=1;
  372. #else
  373. force compilation error
  374. #endif
  375. ]])
  376. ],[
  377. AC_MSG_RESULT([yes])
  378. tmp_reentrant_initially_defined="yes"
  379. ],[
  380. AC_MSG_RESULT([no])
  381. tmp_reentrant_initially_defined="no"
  382. ])
  383. #
  384. if test "$tmp_reentrant_initially_defined" = "no"; then
  385. AC_MSG_CHECKING([if _REENTRANT is actually needed])
  386. CURL_CHECK_NEED_REENTRANT_SYSTEM
  387. if test "$tmp_need_reentrant" = "no"; then
  388. CURL_CHECK_NEED_REENTRANT_ERRNO
  389. fi
  390. if test "$tmp_need_reentrant" = "no"; then
  391. CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
  392. fi
  393. if test "$tmp_need_reentrant" = "yes"; then
  394. AC_MSG_RESULT([yes])
  395. else
  396. AC_MSG_RESULT([no])
  397. fi
  398. fi
  399. #
  400. AC_MSG_CHECKING([if _REENTRANT is onwards defined])
  401. if test "$tmp_reentrant_initially_defined" = "yes" ||
  402. test "$tmp_need_reentrant" = "yes"; then
  403. CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
  404. AC_MSG_RESULT([yes])
  405. else
  406. AC_MSG_RESULT([no])
  407. fi
  408. #
  409. ])
  410. dnl CURL_CONFIGURE_THREAD_SAFE
  411. dnl -------------------------------------------------
  412. dnl This first checks if the preprocessor _THREAD_SAFE
  413. dnl symbol is already defined. If it isn't currently
  414. dnl defined a set of checks are performed to verify
  415. dnl if its definition is required. Finally, if
  416. dnl _THREAD_SAFE is already defined or needed it takes
  417. dnl care of making adjustments necessary to ensure
  418. dnl that it is defined equally for further configure
  419. dnl tests and generated config file.
  420. AC_DEFUN([CURL_CONFIGURE_THREAD_SAFE], [
  421. AC_PREREQ([2.50])dnl
  422. #
  423. AC_MSG_CHECKING([if _THREAD_SAFE is already defined])
  424. AC_COMPILE_IFELSE([
  425. AC_LANG_PROGRAM([[
  426. ]],[[
  427. #ifdef _THREAD_SAFE
  428. int dummy=1;
  429. #else
  430. force compilation error
  431. #endif
  432. ]])
  433. ],[
  434. AC_MSG_RESULT([yes])
  435. tmp_thread_safe_initially_defined="yes"
  436. ],[
  437. AC_MSG_RESULT([no])
  438. tmp_thread_safe_initially_defined="no"
  439. ])
  440. #
  441. if test "$tmp_thread_safe_initially_defined" = "no"; then
  442. AC_MSG_CHECKING([if _THREAD_SAFE is actually needed])
  443. CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
  444. if test "$tmp_need_thread_safe" = "yes"; then
  445. AC_MSG_RESULT([yes])
  446. else
  447. AC_MSG_RESULT([no])
  448. fi
  449. fi
  450. #
  451. AC_MSG_CHECKING([if _THREAD_SAFE is onwards defined])
  452. if test "$tmp_thread_safe_initially_defined" = "yes" ||
  453. test "$tmp_need_thread_safe" = "yes"; then
  454. CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
  455. AC_MSG_RESULT([yes])
  456. else
  457. AC_MSG_RESULT([no])
  458. fi
  459. #
  460. ])