acinclude.m4 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. dnl Check for how to set a socket to non-blocking state. There seems to exist
  2. dnl four known different ways, with the one used almost everywhere being POSIX
  3. dnl and XPG3, while the other different ways for different systems (old BSD,
  4. dnl Windows and Amiga).
  5. dnl
  6. dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
  7. dnl O_NONBLOCK define is found but does not work. This condition is attempted
  8. dnl to get caught in this script by using an excessive number of #ifdefs...
  9. dnl
  10. AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
  11. [
  12. AC_MSG_CHECKING([non-blocking sockets style])
  13. AC_TRY_COMPILE([
  14. /* headers for O_NONBLOCK test */
  15. #include <sys/types.h>
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. ],[
  19. /* try to compile O_NONBLOCK */
  20. #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  21. # if defined(__SVR4) || defined(__srv4__)
  22. # define PLATFORM_SOLARIS
  23. # else
  24. # define PLATFORM_SUNOS4
  25. # endif
  26. #endif
  27. #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
  28. # define PLATFORM_AIX_V3
  29. #endif
  30. #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
  31. #error "O_NONBLOCK does not work on this platform"
  32. #endif
  33. int socket;
  34. int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
  35. ],[
  36. dnl the O_NONBLOCK test was fine
  37. nonblock="O_NONBLOCK"
  38. AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
  39. ],[
  40. dnl the code was bad, try a different program now, test 2
  41. AC_TRY_COMPILE([
  42. /* headers for FIONBIO test */
  43. #include <unistd.h>
  44. #include <stropts.h>
  45. ],[
  46. /* FIONBIO source test (old-style unix) */
  47. int socket;
  48. int flags = ioctl(socket, FIONBIO, &flags);
  49. ],[
  50. dnl FIONBIO test was good
  51. nonblock="FIONBIO"
  52. AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
  53. ],[
  54. dnl FIONBIO test was also bad
  55. dnl the code was bad, try a different program now, test 3
  56. AC_TRY_COMPILE([
  57. /* headers for ioctlsocket test (cygwin?) */
  58. #include <windows.h>
  59. ],[
  60. /* ioctlsocket source code */
  61. int socket;
  62. unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
  63. ],[
  64. dnl ioctlsocket test was good
  65. nonblock="ioctlsocket"
  66. AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
  67. ],[
  68. dnl ioctlsocket didnt compile!, go to test 4
  69. AC_TRY_LINK([
  70. /* headers for IoctlSocket test (Amiga?) */
  71. #include <sys/ioctl.h>
  72. ],[
  73. /* IoctlSocket source code */
  74. int socket;
  75. int flags = IoctlSocket(socket, FIONBIO, (long)1);
  76. ],[
  77. dnl ioctlsocket test was good
  78. nonblock="IoctlSocket"
  79. AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
  80. ],[
  81. dnl Ioctlsocket didnt compile, do test 5!
  82. AC_TRY_COMPILE([
  83. /* headers for SO_NONBLOCK test (BeOS) */
  84. #include <socket.h>
  85. ],[
  86. /* SO_NONBLOCK source code */
  87. long b = 1;
  88. int socket;
  89. int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
  90. ],[
  91. dnl the SO_NONBLOCK test was good
  92. nonblock="SO_NONBLOCK"
  93. AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
  94. ],[
  95. dnl test 5 didnt compile!
  96. nonblock="nada"
  97. AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
  98. ])
  99. dnl end of fifth test
  100. ])
  101. dnl end of forth test
  102. ])
  103. dnl end of third test
  104. ])
  105. dnl end of second test
  106. ])
  107. dnl end of non-blocking try-compile test
  108. AC_MSG_RESULT($nonblock)
  109. if test "$nonblock" = "nada"; then
  110. AC_MSG_WARN([non-block sockets disabled])
  111. fi
  112. ])
  113. dnl Check for struct sockaddr_storage. Most IPv6-enabled hosts have it, but
  114. dnl AIX 4.3 is one known exception.
  115. AC_DEFUN([TYPE_SOCKADDR_STORAGE],
  116. [
  117. AC_CHECK_TYPE([struct sockaddr_storage],
  118. AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
  119. [if struct sockaddr_storage is defined]), ,
  120. [
  121. #ifdef HAVE_SYS_TYPES_H
  122. #include <sys/types.h>
  123. #endif
  124. #ifdef HAVE_SYS_SOCKET_H
  125. #include <sys/socket.h>
  126. #endif
  127. #ifdef HAVE_NETINET_IN_H
  128. #include <netinet/in.h>
  129. #endif
  130. #ifdef HAVE_ARPA_INET_H
  131. #include <arpa/inet.h>
  132. #endif
  133. ])
  134. ])
  135. dnl Check for socklen_t: historically on BSD it is an int, and in
  136. dnl POSIX 1g it is a type of its own, but some platforms use different
  137. dnl types for the argument to getsockopt, getpeername, etc. So we
  138. dnl have to test to find something that will work.
  139. AC_DEFUN([TYPE_SOCKLEN_T],
  140. [
  141. AC_CHECK_TYPE([socklen_t], ,[
  142. AC_MSG_CHECKING([for socklen_t equivalent])
  143. AC_CACHE_VAL([curl_cv_socklen_t_equiv],
  144. [
  145. # Systems have either "struct sockaddr *" or
  146. # "void *" as the second argument to getpeername
  147. curl_cv_socklen_t_equiv=
  148. for arg2 in "struct sockaddr" void; do
  149. for t in int size_t unsigned long "unsigned long"; do
  150. AC_TRY_COMPILE([
  151. #ifdef HAVE_SYS_TYPES_H
  152. #include <sys/types.h>
  153. #endif
  154. #ifdef HAVE_SYS_SOCKET_H
  155. #include <sys/socket.h>
  156. #endif
  157. int getpeername (int, $arg2 *, $t *);
  158. ],[
  159. $t len;
  160. getpeername(0,0,&len);
  161. ],[
  162. curl_cv_socklen_t_equiv="$t"
  163. break
  164. ])
  165. done
  166. done
  167. if test "x$curl_cv_socklen_t_equiv" = x; then
  168. AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
  169. fi
  170. ])
  171. AC_MSG_RESULT($curl_cv_socklen_t_equiv)
  172. AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
  173. [type to use in place of socklen_t if not defined])],
  174. [#include <sys/types.h>
  175. #include <sys/socket.h>])
  176. ])
  177. dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
  178. dnl and a few other things.
  179. AC_DEFUN([TYPE_IN_ADDR_T],
  180. [
  181. AC_CHECK_TYPE([in_addr_t], ,[
  182. AC_MSG_CHECKING([for in_addr_t equivalent])
  183. AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
  184. [
  185. curl_cv_in_addr_t_equiv=
  186. for t in "unsigned long" int size_t unsigned long; do
  187. AC_TRY_COMPILE([
  188. #ifdef HAVE_SYS_TYPES_H
  189. #include <sys/types.h>
  190. #endif
  191. #ifdef HAVE_SYS_SOCKET_H
  192. #include <sys/socket.h>
  193. #endif
  194. #ifdef HAVE_ARPA_INET_H
  195. #include <arpa/inet.h>
  196. #endif
  197. ],[
  198. $t data = inet_addr ("1.2.3.4");
  199. ],[
  200. curl_cv_in_addr_t_equiv="$t"
  201. break
  202. ])
  203. done
  204. if test "x$curl_cv_in_addr_t_equiv" = x; then
  205. AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
  206. fi
  207. ])
  208. AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
  209. AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
  210. [type to use in place of in_addr_t if not defined])],
  211. [#include <sys/types.h>
  212. #include <sys/socket.h>
  213. #include <arpa/inet.h>])
  214. ])
  215. dnl ************************************************************
  216. dnl check for "localhost", if it doesn't exist, we can't do the
  217. dnl gethostbyname_r tests!
  218. dnl
  219. AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
  220. AC_MSG_CHECKING([if "localhost" resolves])
  221. AC_TRY_RUN([
  222. #include <string.h>
  223. #include <sys/types.h>
  224. #include <netdb.h>
  225. int
  226. main () {
  227. struct hostent *h;
  228. h = gethostbyname("localhost");
  229. exit (h == NULL ? 1 : 0); }],[
  230. AC_MSG_RESULT(yes)],[
  231. AC_MSG_RESULT(no)
  232. AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
  233. ]
  234. )
  235. ])
  236. dnl ************************************************************
  237. dnl check for working getaddrinfo() that works with AI_NUMERICHOST
  238. dnl
  239. AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
  240. AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
  241. AC_TRY_RUN( [
  242. #include <netdb.h>
  243. #include <sys/types.h>
  244. #include <sys/socket.h>
  245. int main(void)
  246. {
  247. struct addrinfo hints, *ai;
  248. int error;
  249. memset(&hints, 0, sizeof(hints));
  250. hints.ai_flags = AI_NUMERICHOST;
  251. hints.ai_family = AF_UNSPEC;
  252. hints.ai_socktype = SOCK_STREAM;
  253. error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
  254. if (error) {
  255. return 1;
  256. }
  257. return 0;
  258. }
  259. ],[
  260. ac_cv_working_getaddrinfo="yes"
  261. ],[
  262. ac_cv_working_getaddrinfo="no"
  263. ],[
  264. ac_cv_working_getaddrinfo="yes"
  265. ])])
  266. if test "$ac_cv_working_getaddrinfo" = "yes"; then
  267. AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
  268. AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
  269. IPV6_ENABLED=1
  270. AC_SUBST(IPV6_ENABLED)
  271. fi
  272. ])
  273. dnl ************************************************************
  274. dnl check for working NI_WITHSCOPEID in getnameinfo()
  275. dnl
  276. AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID],[
  277. AC_CACHE_CHECK(for working NI_WITHSCOPEID, ac_cv_working_ni_withscopeid,[
  278. AC_RUN_IFELSE([[
  279. #include <stdio.h>
  280. #include <sys/types.h>
  281. #include <sys/socket.h>
  282. #include <netdb.h>
  283. int main()
  284. {
  285. #ifdef NI_WITHSCOPEID
  286. struct sockaddr_storage ss;
  287. int sslen = sizeof(ss);
  288. int rc;
  289. char hbuf[NI_MAXHOST];
  290. int fd = socket(AF_INET6, SOCK_STREAM, 0);
  291. if(fd < 0) {
  292. perror("socket()");
  293. return 1; /* couldn't create socket of either kind */
  294. }
  295. rc = getsockname(fd, (struct sockaddr *)&ss, &sslen);
  296. if(rc) {
  297. perror("getsockname()");
  298. return 2;
  299. }
  300. rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf),
  301. NULL, 0,
  302. NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID);
  303. if(rc) {
  304. printf("rc = %s\n", gai_strerror(rc));
  305. return 3;
  306. }
  307. return 0; /* everything works fine, use NI_WITHSCOPEID! */
  308. #else
  309. return 4; /* we don't seem to have the definition, don't use it */
  310. #endif
  311. }
  312. ]],
  313. dnl program worked:
  314. [ ac_cv_working_ni_withscopeid="yes" ],
  315. dnl program failed:
  316. [ ac_cv_working_ni_withscopeid="no" ],
  317. dnl we cross-compile, check the headers using the preprocessor
  318. [
  319. AC_EGREP_CPP(WORKS,
  320. [
  321. #include <stdio.h>
  322. #include <sys/types.h>
  323. #include <sys/socket.h>
  324. #include <netdb.h>
  325. #ifdef NI_WITHSCOPEID
  326. WORKS
  327. #endif
  328. ],
  329. ac_cv_working_ni_withscopeid="yes",
  330. ac_cv_working_ni_withscopeid="no" )
  331. ]
  332. ) dnl end of AC_RUN_IFELSE
  333. ]) dnl end of AC_CACHE_CHECK
  334. if test "$ac_cv_working_ni_withscopeid" = "yes"; then
  335. AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
  336. [Define if NI_WITHSCOPEID exists and works])
  337. fi
  338. ]) dnl end of AC_DEFUN
  339. AC_DEFUN([CURL_CHECK_LOCALTIME_R],
  340. [
  341. dnl check for localtime_r
  342. AC_CHECK_FUNCS(localtime_r,[
  343. AC_MSG_CHECKING(whether localtime_r is declared)
  344. AC_EGREP_CPP(localtime_r,[
  345. #include <time.h>],[
  346. AC_MSG_RESULT(yes)],[
  347. AC_MSG_RESULT(no)
  348. AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
  349. AC_EGREP_CPP(localtime_r,[
  350. #define _REENTRANT
  351. #include <time.h>],[
  352. AC_DEFINE(NEED_REENTRANT)
  353. AC_MSG_RESULT(yes)],
  354. AC_MSG_RESULT(no))])])
  355. ])
  356. dnl
  357. dnl This function checks for strerror_r(). If it isn't found at first, it
  358. dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
  359. dnl in order to find this function.
  360. dnl
  361. dnl If the function is found, it will then proceed to check how the function
  362. dnl actually works: glibc-style or POSIX-style.
  363. dnl
  364. dnl glibc:
  365. dnl char *strerror_r(int errnum, char *buf, size_t n);
  366. dnl
  367. dnl What this one does is to return the error string (no surprises there),
  368. dnl but it doesn't usually copy anything into buf! The 'buf' and 'n'
  369. dnl parameters are only meant as an optional working area, in case strerror_r
  370. dnl needs it. A quick test on a few systems shows that it's generally not
  371. dnl touched at all.
  372. dnl
  373. dnl POSIX:
  374. dnl int strerror_r(int errnum, char *buf, size_t n);
  375. dnl
  376. AC_DEFUN([CURL_CHECK_STRERROR_R],
  377. [
  378. AC_CHECK_FUNCS(strerror_r)
  379. if test "x$ac_cv_func_strerror_r" = "xyes"; then
  380. AC_MSG_CHECKING(whether strerror_r is declared)
  381. AC_EGREP_CPP(strerror_r,[
  382. #include <string.h>],[
  383. AC_MSG_RESULT(yes)],[
  384. AC_MSG_RESULT(no)
  385. AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
  386. AC_EGREP_CPP(strerror_r,[
  387. #define _REENTRANT
  388. #include <string.h>],[
  389. CPPFLAGS="-D_REENTRANT $CPPFLAGS"
  390. AC_MSG_RESULT(yes)],
  391. AC_MSG_RESULT(no)
  392. AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
  393. ) dnl with _THREAD_SAFE
  394. ]) dnl plain cpp for it
  395. dnl determine if this strerror_r() is glibc or POSIX
  396. AC_MSG_CHECKING([for a glibc strerror_r API])
  397. AC_TRY_RUN([
  398. #include <string.h>
  399. #include <errno.h>
  400. int
  401. main () {
  402. char buffer[1024]; /* big enough to play with */
  403. char *string =
  404. strerror_r(EACCES, buffer, sizeof(buffer));
  405. /* this should've returned a string */
  406. if(!string || !string[0])
  407. return 99;
  408. return 0;
  409. }
  410. ],
  411. GLIBC_STRERROR_R="1"
  412. AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
  413. AC_MSG_RESULT([yes]),
  414. AC_MSG_RESULT([no]),
  415. dnl Use an inferior method of strerror_r detection while cross-compiling
  416. AC_EGREP_CPP(yes, [
  417. #include <features.h>
  418. #ifdef __GLIBC__
  419. yes
  420. #endif
  421. ],
  422. dnl looks like glibc, so assume a glibc-style strerror_r()
  423. GLIBC_STRERROR_R="1"
  424. AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
  425. AC_MSG_RESULT([yes]),
  426. AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
  427. ) dnl while cross-compiling
  428. )
  429. if test -z "$GLIBC_STRERROR_R"; then
  430. AC_MSG_CHECKING([for a POSIX strerror_r API])
  431. AC_TRY_RUN([
  432. #include <string.h>
  433. #include <errno.h>
  434. int
  435. main () {
  436. char buffer[1024]; /* big enough to play with */
  437. int error =
  438. strerror_r(EACCES, buffer, sizeof(buffer));
  439. /* This should've returned zero, and written an error string in the
  440. buffer.*/
  441. if(!buffer[0] || error)
  442. return 99;
  443. return 0;
  444. }
  445. ],
  446. AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
  447. AC_MSG_RESULT([yes]),
  448. AC_MSG_RESULT([no]) ,
  449. dnl cross-compiling!
  450. AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
  451. )
  452. fi dnl if not using glibc API
  453. fi dnl we have a strerror_r
  454. ])
  455. AC_DEFUN([CURL_CHECK_INET_NTOA_R],
  456. [
  457. dnl determine if function definition for inet_ntoa_r exists.
  458. AC_CHECK_FUNCS(inet_ntoa_r,[
  459. AC_MSG_CHECKING(whether inet_ntoa_r is declared)
  460. AC_EGREP_CPP(inet_ntoa_r,[
  461. #include <arpa/inet.h>],[
  462. AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
  463. AC_MSG_RESULT(yes)],[
  464. AC_MSG_RESULT(no)
  465. AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
  466. AC_EGREP_CPP(inet_ntoa_r,[
  467. #define _REENTRANT
  468. #include <arpa/inet.h>],[
  469. AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
  470. AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
  471. AC_MSG_RESULT(yes)],
  472. AC_MSG_RESULT(no))])])
  473. ])
  474. AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
  475. [
  476. dnl check for number of arguments to gethostbyaddr_r. it might take
  477. dnl either 5, 7, or 8 arguments.
  478. AC_CHECK_FUNCS(gethostbyaddr_r,[
  479. AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
  480. AC_TRY_COMPILE([
  481. #include <sys/types.h>
  482. #include <netdb.h>],[
  483. char * address;
  484. int length;
  485. int type;
  486. struct hostent h;
  487. struct hostent_data hdata;
  488. int rc;
  489. rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
  490. AC_MSG_RESULT(yes)
  491. AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
  492. ac_cv_gethostbyaddr_args=5],[
  493. AC_MSG_RESULT(no)
  494. AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
  495. AC_TRY_COMPILE([
  496. #define _REENTRANT
  497. #include <sys/types.h>
  498. #include <netdb.h>],[
  499. char * address;
  500. int length;
  501. int type;
  502. struct hostent h;
  503. struct hostent_data hdata;
  504. int rc;
  505. rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
  506. AC_MSG_RESULT(yes)
  507. AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
  508. AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
  509. ac_cv_gethostbyaddr_args=5],[
  510. AC_MSG_RESULT(no)
  511. AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
  512. AC_TRY_COMPILE([
  513. #include <sys/types.h>
  514. #include <netdb.h>],[
  515. char * address;
  516. int length;
  517. int type;
  518. struct hostent h;
  519. char buffer[8192];
  520. int h_errnop;
  521. struct hostent * hp;
  522. hp = gethostbyaddr_r(address, length, type, &h,
  523. buffer, 8192, &h_errnop);],[
  524. AC_MSG_RESULT(yes)
  525. AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
  526. ac_cv_gethostbyaddr_args=7],[
  527. AC_MSG_RESULT(no)
  528. AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
  529. AC_TRY_COMPILE([
  530. #include <sys/types.h>
  531. #include <netdb.h>],[
  532. char * address;
  533. int length;
  534. int type;
  535. struct hostent h;
  536. char buffer[8192];
  537. int h_errnop;
  538. struct hostent * hp;
  539. int rc;
  540. rc = gethostbyaddr_r(address, length, type, &h,
  541. buffer, 8192, &hp, &h_errnop);],[
  542. AC_MSG_RESULT(yes)
  543. AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
  544. ac_cv_gethostbyaddr_args=8],[
  545. AC_MSG_RESULT(no)
  546. have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
  547. ])
  548. AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
  549. [
  550. dnl check for number of arguments to gethostbyname_r. it might take
  551. dnl either 3, 5, or 6 arguments.
  552. AC_CHECK_FUNCS(gethostbyname_r,[
  553. AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
  554. AC_TRY_COMPILE([
  555. #include <string.h>
  556. #include <sys/types.h>
  557. #include <netdb.h>
  558. #undef NULL
  559. #define NULL (void *)0
  560. int
  561. gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
  562. struct hostent_data data;
  563. gethostbyname_r(NULL, NULL, NULL);],[
  564. AC_MSG_RESULT(yes)
  565. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
  566. ac_cv_gethostbyname_args=3],[
  567. AC_MSG_RESULT(no)
  568. AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
  569. AC_TRY_COMPILE([
  570. #define _REENTRANT
  571. #include <string.h>
  572. #include <sys/types.h>
  573. #include <netdb.h>
  574. #undef NULL
  575. #define NULL (void *)0
  576. int
  577. gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
  578. struct hostent_data data;
  579. gethostbyname_r(NULL, NULL, NULL);],[
  580. AC_MSG_RESULT(yes)
  581. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
  582. AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
  583. ac_cv_gethostbyname_args=3],[
  584. AC_MSG_RESULT(no)
  585. AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
  586. AC_TRY_COMPILE([
  587. #include <sys/types.h>
  588. #include <netdb.h>
  589. #undef NULL
  590. #define NULL (void *)0
  591. struct hostent *
  592. gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
  593. gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
  594. AC_MSG_RESULT(yes)
  595. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
  596. ac_cv_gethostbyname_args=5],[
  597. AC_MSG_RESULT(no)
  598. AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
  599. AC_TRY_COMPILE([
  600. #include <sys/types.h>
  601. #include <netdb.h>
  602. #undef NULL
  603. #define NULL (void *)0
  604. int
  605. gethostbyname_r(const char *, struct hostent *, char *, size_t,
  606. struct hostent **, int *);],[
  607. gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
  608. AC_MSG_RESULT(yes)
  609. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
  610. ac_cv_gethostbyname_args=6],[
  611. AC_MSG_RESULT(no)
  612. have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
  613. [ac_cv_gethostbyname_args=0])],
  614. [ac_cv_gethostbyname_args=0])],
  615. [ac_cv_gethostbyname_args=0])],
  616. [ac_cv_gethostbyname_args=0])])
  617. if test "$ac_cv_func_gethostbyname_r" = "yes"; then
  618. if test "$ac_cv_gethostbyname_args" = "0"; then
  619. dnl there's a gethostbyname_r() function, but we don't know how
  620. dnl many arguments it wants!
  621. AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
  622. fi
  623. fi
  624. ])
  625. dnl We create a function for detecting which compiler we use and then set as
  626. dnl pendantic compiler options as possible for that particular compiler. The
  627. dnl options are only used for debug-builds.
  628. AC_DEFUN([CURL_CC_DEBUG_OPTS],
  629. [
  630. if test "$GCC" = "yes"; then
  631. dnl figure out gcc version!
  632. AC_MSG_CHECKING([gcc version])
  633. gccver=`$CC -dumpversion`
  634. num1=`echo $gccver | cut -d . -f1`
  635. num2=`echo $gccver | cut -d . -f2`
  636. gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
  637. AC_MSG_RESULT($gccver)
  638. AC_MSG_CHECKING([if this is icc in disguise])
  639. AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
  640. dnl action if the text is found, this it has not been replaced by the
  641. dnl cpp
  642. ICC="no"
  643. AC_MSG_RESULT([no]),
  644. dnl the text was not found, it was replaced by the cpp
  645. ICC="yes"
  646. AC_MSG_RESULT([yes])
  647. )
  648. if test "$ICC" = "yes"; then
  649. dnl this is icc, not gcc.
  650. dnl ICC warnings we ignore:
  651. dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
  652. dnl "invalid format string conversion"
  653. dnl * 279 warns on static conditions in while expressions
  654. dnl * 981 warns on "operands are evaluated in unspecified order"
  655. dnl * 1418 "external definition with no prior declaration"
  656. dnl * 1419 warns on "external declaration in primary source file"
  657. dnl which we know and do on purpose.
  658. WARN="-wd279,269,981,1418,1419"
  659. if test "$gccnum" -gt "600"; then
  660. dnl icc 6.0 and older doesn't have the -Wall flag
  661. WARN="-Wall $WARN"
  662. fi
  663. else dnl $ICC = yes
  664. dnl this is a set of options we believe *ALL* gcc versions support:
  665. WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
  666. dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
  667. if test "$gccnum" -ge "207"; then
  668. dnl gcc 2.7 or later
  669. WARN="$WARN -Wmissing-declarations"
  670. fi
  671. if test "$gccnum" -gt "295"; then
  672. dnl only if the compiler is newer than 2.95 since we got lots of
  673. dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
  674. dnl gcc 2.95.4 on FreeBSD 4.9!
  675. WARN="$WARN -Wundef -Wno-long-long -Wsign-compare"
  676. fi
  677. if test "$gccnum" -ge "296"; then
  678. dnl gcc 2.96 or later
  679. WARN="$WARN -Wfloat-equal"
  680. fi
  681. if test "$gccnum" -gt "296"; then
  682. dnl this option does not exist in 2.96
  683. WARN="$WARN -Wno-format-nonliteral"
  684. fi
  685. dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
  686. dnl on i686-Linux as it gives us heaps with false positives.
  687. dnl Also, on gcc 4.0.X it is totally unbearable and complains all
  688. dnl over making it unusable for generic purposes. Let's not use it.
  689. if test "$gccnum" -ge "303"; then
  690. dnl gcc 3.3 and later
  691. WARN="$WARN -Wendif-labels -Wstrict-prototypes"
  692. fi
  693. if test "$gccnum" -ge "304"; then
  694. # try these on gcc 3.4
  695. WARN="$WARN -Wdeclaration-after-statement"
  696. fi
  697. for flag in $CPPFLAGS; do
  698. case "$flag" in
  699. -I*)
  700. dnl Include path, provide a -isystem option for the same dir
  701. dnl to prevent warnings in those dirs. The -isystem was not very
  702. dnl reliable on earlier gcc versions.
  703. add=`echo $flag | sed 's/^-I/-isystem /g'`
  704. WARN="$WARN $add"
  705. ;;
  706. esac
  707. done
  708. fi dnl $ICC = no
  709. CFLAGS="$CFLAGS $WARN"
  710. AC_MSG_NOTICE([Added this set of compiler options: $WARN])
  711. else dnl $GCC = yes
  712. AC_MSG_NOTICE([Added no extra compiler options])
  713. fi dnl $GCC = yes
  714. dnl strip off optimizer flags
  715. NEWFLAGS=""
  716. for flag in $CFLAGS; do
  717. case "$flag" in
  718. -O*)
  719. dnl echo "cut off $flag"
  720. ;;
  721. *)
  722. NEWFLAGS="$NEWFLAGS $flag"
  723. ;;
  724. esac
  725. done
  726. CFLAGS=$NEWFLAGS
  727. ]) dnl end of AC_DEFUN()
  728. dnl Determine the name of the library to pass to dlopen() based on the name
  729. dnl that would normally be given to AC_CHECK_LIB. The preprocessor symbol
  730. dnl given is set to the quoted library file name.
  731. dnl The standard dynamic library file name is first generated, based on the
  732. dnl current system type, then a search is performed for that file on the
  733. dnl standard dynamic library path. If it is a symbolic link, the destination
  734. dnl of the link is used as the file name, after stripping off any minor
  735. dnl version numbers. If a library file can't be found, a guess is made.
  736. dnl This macro assumes AC_PROG_LIBTOOL has been called and requires perl
  737. dnl to be available in the PATH, or $PERL to be set to its location.
  738. dnl
  739. dnl CURL_DLLIB_NAME(VARIABLE, library_name)
  740. dnl e.g. CURL_DLLIB_NAME(LDAP_NAME, ldap) on a Linux system might result
  741. dnl in LDAP_NAME holding the string "libldap.so.2".
  742. AC_DEFUN([CURL_DLLIB_NAME],
  743. [
  744. AC_MSG_CHECKING([name of dynamic library $2])
  745. dnl The shared library extension variable name changes from version to
  746. dnl version of libtool. Try a few names then just set one statically.
  747. test -z "$shared_ext" && shared_ext="$shrext_cmds"
  748. test -z "$shared_ext" && shared_ext="$shrext"
  749. test -z "$shared_ext" && shared_ext=".so"
  750. dnl Create the library link name of the correct form for this platform
  751. LIBNAME_LINK_SPEC=`echo "$library_names_spec" | $SED 's/^.* //'`
  752. DLGUESSLIB=`name=$2 eval echo "$libname_spec"`
  753. DLGUESSFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$LIBNAME_LINK_SPEC"`
  754. dnl Synthesize a likely dynamic library name in case we can't find an actual one
  755. SO_NAME_SPEC="$soname_spec"
  756. dnl soname_spec undefined when identical to the 1st entry in library_names_spec
  757. test -z "$SO_NAME_SPEC" && SO_NAME_SPEC=`echo "$library_names_spec" | $SED 's/ .*$//'`
  758. DLGUESSSOFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$SO_NAME_SPEC"`
  759. if test "$cross_compiling" = yes; then
  760. dnl Can't look at filesystem when cross-compiling
  761. AC_DEFINE_UNQUOTED($1, "$DLGUESSSOFILE", [$2 dynamic library file])
  762. AC_MSG_RESULT([$DLGUESSSOFILE (guess while cross-compiling)])
  763. else
  764. DLFOUNDFILE=""
  765. if test "$sys_lib_dlsearch_path_spec" ; then
  766. dnl Search for the link library name and see what it points to.
  767. for direc in $sys_lib_dlsearch_path_spec ; do
  768. DLTRYFILE="$direc/$DLGUESSFILE"
  769. dnl Find where the symbolic link for this name points
  770. changequote(<<, >>)dnl
  771. <<
  772. DLFOUNDFILE=`${PERL:-perl} -e 'use File::Basename; (basename(readlink($ARGV[0])) =~ /^(.*[^\d]\.\d+)[\d\.]*$/ && print ${1}) || exit 1;' "$DLTRYFILE" 2>&5`
  773. >>
  774. changequote([, ])dnl
  775. if test "$?" -eq "0"; then
  776. dnl Found the file link
  777. break
  778. fi
  779. done
  780. fi
  781. if test -z "$DLFOUNDFILE" ; then
  782. dnl Couldn't find a link library, so guess at a name.
  783. DLFOUNDFILE="$DLGUESSSOFILE"
  784. fi
  785. AC_DEFINE_UNQUOTED($1, "$DLFOUNDFILE", [$2 dynamic library file])
  786. AC_MSG_RESULT($DLFOUNDFILE)
  787. fi
  788. ])