2
0

curl-reentrant.m4 13 KB

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