acinclude.m4 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. dnl ##############################################################################
  2. dnl # LIBZMQ_CONFIG_LIBTOOL #
  3. dnl # Configure libtool. Requires AC_CANONICAL_HOST #
  4. dnl ##############################################################################
  5. AC_DEFUN([LIBZMQ_CONFIG_LIBTOOL], [{
  6. AC_REQUIRE([AC_CANONICAL_HOST])
  7. # Libtool configuration for different targets
  8. case "${host_os}" in
  9. *mingw*|*cygwin*|*msys*)
  10. # Disable static build by default
  11. AC_DISABLE_STATIC
  12. ;;
  13. *)
  14. # Everything else with static enabled
  15. AC_ENABLE_STATIC
  16. ;;
  17. esac
  18. }])
  19. dnl ##############################################################################
  20. dnl # LIBZMQ_CHECK_LANG_ICC([action-if-found], [action-if-not-found]) #
  21. dnl # Check if the current language is compiled using ICC #
  22. dnl # Adapted from http://software.intel.com/en-us/forums/showthread.php?t=67984 #
  23. dnl ##############################################################################
  24. AC_DEFUN([LIBZMQ_CHECK_LANG_ICC],
  25. [AC_CACHE_CHECK([whether we are using Intel _AC_LANG compiler],
  26. [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler],
  27. [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  28. [[#ifndef __INTEL_COMPILER
  29. error if not ICC
  30. #endif
  31. ]])],
  32. [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="yes" ; $1],
  33. [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="no" ; $2])
  34. ])])
  35. dnl ##############################################################################
  36. dnl # LIBZMQ_CHECK_LANG_SUN_STUDIO([action-if-found], [action-if-not-found]) #
  37. dnl # Check if the current language is compiled using Sun Studio #
  38. dnl ##############################################################################
  39. AC_DEFUN([LIBZMQ_CHECK_LANG_SUN_STUDIO],
  40. [AC_CACHE_CHECK([whether we are using Sun Studio _AC_LANG compiler],
  41. [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler],
  42. [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  43. [[#if !defined(__SUNPRO_CC) && !defined(__SUNPRO_C)
  44. error if not sun studio
  45. #endif
  46. ]])],
  47. [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="yes" ; $1],
  48. [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="no" ; $2])
  49. ])])
  50. dnl ##############################################################################
  51. dnl # LIBZMQ_CHECK_LANG_CLANG([action-if-found], [action-if-not-found]) #
  52. dnl # Check if the current language is compiled using clang #
  53. dnl ##############################################################################
  54. AC_DEFUN([LIBZMQ_CHECK_LANG_CLANG],
  55. [AC_CACHE_CHECK([whether we are using clang _AC_LANG compiler],
  56. [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler],
  57. [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  58. [[#ifndef __clang__
  59. error if not clang
  60. #endif
  61. ]])],
  62. [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="yes" ; $1],
  63. [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="no" ; $2])
  64. ])])
  65. dnl ##############################################################################
  66. dnl # LIBZMQ_CHECK_LANG_GCC4([action-if-found], [action-if-not-found]) #
  67. dnl # Check if the current language is compiled using clang #
  68. dnl ##############################################################################
  69. AC_DEFUN([LIBZMQ_CHECK_LANG_GCC4],
  70. [AC_CACHE_CHECK([whether we are using gcc >= 4 _AC_LANG compiler],
  71. [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler],
  72. [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  73. [[#if (!defined __GNUC__ || __GNUC__ < 4)
  74. error if not gcc4 or higher
  75. #endif
  76. ]])],
  77. [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler="yes" ; $1],
  78. [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler="no" ; $2])
  79. ])])
  80. dnl ##############################################################################
  81. dnl # LIBZMQ_CHECK_DOC_BUILD #
  82. dnl # Check whether to build documentation and install man-pages #
  83. dnl ##############################################################################
  84. AC_DEFUN([LIBZMQ_CHECK_DOC_BUILD], [{
  85. # Man pages are built/installed if asciidoc and xmlto are present
  86. # --with-docs=no overrides this
  87. AC_ARG_WITH([docs],
  88. AS_HELP_STRING([--without-docs],
  89. [Don't build and install man pages [default=build]]),
  90. [with_docs=$withval])
  91. AC_ARG_WITH([documentation], [AS_HELP_STRING([--without-documentation],
  92. [Don't build and install man pages [default=build] DEPRECATED: use --without-docs])])
  93. if test "x$with_documentation" = "xno"; then
  94. AC_MSG_WARN([--without-documentation is DEPRECATED and will be removed in the next release, use --without-docs])
  95. fi
  96. if test "x$with_docs" = "xno" || test "x$with_documentation" = "xno"; then
  97. libzmq_build_doc="no"
  98. libzmq_install_man="no"
  99. else
  100. # Determine whether or not documentation should be built and installed.
  101. libzmq_build_doc="yes"
  102. libzmq_install_man="yes"
  103. # Check for asciidoc and xmlto and don't build the docs if these are not installed.
  104. AC_CHECK_PROG(libzmq_have_asciidoc, asciidoc, yes, no)
  105. AC_CHECK_PROG(libzmq_have_xmlto, xmlto, yes, no)
  106. if test "x$libzmq_have_asciidoc" = "xno" -o "x$libzmq_have_xmlto" = "xno"; then
  107. libzmq_build_doc="no"
  108. # Tarballs built with 'make dist' ship with prebuilt documentation.
  109. if ! test -f doc/zmq.7; then
  110. libzmq_install_man="no"
  111. AC_MSG_WARN([You are building an unreleased version of 0MQ and asciidoc or xmlto are not installed.])
  112. AC_MSG_WARN([Documentation will not be built and manual pages will not be installed.])
  113. fi
  114. fi
  115. # Do not install man pages if on mingw
  116. if test "x$libzmq_on_mingw" = "xyes"; then
  117. libzmq_install_man="no"
  118. fi
  119. fi
  120. AC_MSG_CHECKING([whether to build documentation])
  121. AC_MSG_RESULT([$libzmq_build_doc])
  122. AC_MSG_CHECKING([whether to install manpages])
  123. AC_MSG_RESULT([$libzmq_install_man])
  124. AM_CONDITIONAL(BUILD_DOC, test "x$libzmq_build_doc" = "xyes")
  125. AM_CONDITIONAL(INSTALL_MAN, test "x$libzmq_install_man" = "xyes")
  126. }])
  127. dnl ##############################################################################
  128. dnl # LIBZMQ_CHECK_LANG_COMPILER([action-if-found], [action-if-not-found]) #
  129. dnl # Check that compiler for the current language actually works #
  130. dnl ##############################################################################
  131. AC_DEFUN([LIBZMQ_CHECK_LANG_COMPILER], [{
  132. # Test that compiler for the current language actually works
  133. AC_CACHE_CHECK([whether the _AC_LANG compiler works],
  134. [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works],
  135. [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
  136. [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="yes" ; $1],
  137. [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="no" ; $2])
  138. ])
  139. if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works" != "xyes"; then
  140. AC_MSG_ERROR([Unable to find a working _AC_LANG compiler])
  141. fi
  142. }])
  143. dnl ##############################################################################
  144. dnl # LIBZMQ_CHECK_COMPILERS #
  145. dnl # Check compiler characteristics. This is so that we can AC_REQUIRE checks #
  146. dnl ##############################################################################
  147. AC_DEFUN([LIBZMQ_CHECK_COMPILERS], [{
  148. # For that the compiler works and try to come up with the type
  149. AC_LANG_PUSH([C])
  150. LIBZMQ_CHECK_LANG_COMPILER
  151. LIBZMQ_CHECK_LANG_ICC
  152. LIBZMQ_CHECK_LANG_SUN_STUDIO
  153. LIBZMQ_CHECK_LANG_CLANG
  154. LIBZMQ_CHECK_LANG_GCC4
  155. AC_LANG_POP([C])
  156. AC_LANG_PUSH(C++)
  157. LIBZMQ_CHECK_LANG_COMPILER
  158. LIBZMQ_CHECK_LANG_ICC
  159. LIBZMQ_CHECK_LANG_SUN_STUDIO
  160. LIBZMQ_CHECK_LANG_CLANG
  161. LIBZMQ_CHECK_LANG_GCC4
  162. AC_LANG_POP([C++])
  163. # Set GCC and GXX variables correctly
  164. if test "x$GCC" = "xyes"; then
  165. if test "xyes" = "x$libzmq_cv_c_intel_compiler"; then
  166. GCC="no"
  167. fi
  168. fi
  169. if test "x$GXX" = "xyes"; then
  170. if test "xyes" = "x$libzmq_cv_cxx_intel_compiler"; then
  171. GXX="no"
  172. fi
  173. fi
  174. }])
  175. dnl ############################################################################
  176. dnl # LIBZMQ_CHECK_LANG_FLAG([flag], [action-if-found], [action-if-not-found]) #
  177. dnl # Check if the compiler supports given flag. Works for C and C++ #
  178. dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no #
  179. dnl ############################################################################
  180. AC_DEFUN([LIBZMQ_CHECK_LANG_FLAG], [{
  181. AC_REQUIRE([AC_PROG_GREP])
  182. AC_MSG_CHECKING([whether _AC_LANG compiler supports $1])
  183. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
  184. ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"
  185. case "x[]_AC_LANG_ABBREV" in
  186. xc)
  187. libzmq_cv_check_lang_flag_save_CFLAGS="$CFLAGS"
  188. CFLAGS="$CFLAGS $1"
  189. ;;
  190. xcxx)
  191. libzmq_cv_check_lang_flag_save_CPPFLAGS="$CPPFLAGS"
  192. CPPFLAGS="$CPPFLAGS $1"
  193. ;;
  194. *)
  195. AC_MSG_WARN([testing compiler characteristic on an unknown language])
  196. ;;
  197. esac
  198. AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
  199. # This hack exist for ICC, which outputs unknown options as remarks
  200. # Remarks are not turned into errors even with -Werror on
  201. [if ($GREP 'ignoring unknown' conftest.err ||
  202. $GREP 'not supported' conftest.err) >/dev/null 2>&1; then
  203. eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"
  204. else
  205. eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="yes"
  206. fi],
  207. [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"])
  208. case "x[]_AC_LANG_ABBREV" in
  209. xc)
  210. CFLAGS="$libzmq_cv_check_lang_flag_save_CFLAGS"
  211. ;;
  212. xcxx)
  213. CPPFLAGS="$libzmq_cv_check_lang_flag_save_CPPFLAGS"
  214. ;;
  215. *)
  216. # nothing to restore
  217. ;;
  218. esac
  219. # Restore the werror flag
  220. ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
  221. # Call the action as the flags are restored
  222. AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
  223. [AC_MSG_RESULT(yes) ; $2], [AC_MSG_RESULT(no) ; $3])
  224. }])
  225. dnl ####################################################################################
  226. dnl # LIBZMQ_CHECK_LANG_FLAG_PREPEND([flag], [action-if-found], [action-if-not-found]) #
  227. dnl # Check if the compiler supports given flag. Works for C and C++ #
  228. dnl # This macro prepends the flag to CFLAGS or CPPFLAGS accordingly #
  229. dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no #
  230. dnl ####################################################################################
  231. AC_DEFUN([LIBZMQ_CHECK_LANG_FLAG_PREPEND], [{
  232. LIBZMQ_CHECK_LANG_FLAG([$1])
  233. case "x[]_AC_LANG_ABBREV" in
  234. xc)
  235. AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
  236. [CFLAGS="$1 $CFLAGS"; $2], $3)
  237. ;;
  238. xcxx)
  239. AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
  240. [CPPFLAGS="$1 $CPPFLAGS"; $2], $3)
  241. ;;
  242. esac
  243. }])
  244. dnl ##############################################################################
  245. dnl # LIBZMQ_CHECK_ENABLE_DEBUG([action-if-found], [action-if-not-found]) #
  246. dnl # Check whether to enable debug build and set compiler flags accordingly #
  247. dnl ##############################################################################
  248. AC_DEFUN([LIBZMQ_CHECK_ENABLE_DEBUG], [{
  249. # Require compiler specifics
  250. AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
  251. # This flag is checked also in
  252. AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],
  253. [enable debugging information [default=disabled]])])
  254. AC_MSG_CHECKING(whether to enable debugging information)
  255. if test "x$enable_debug" = "xyes"; then
  256. # GCC, clang and ICC
  257. if test "x$GCC" = "xyes" -o \
  258. "x$libzmq_cv_c_intel_compiler" = "xyes" -o \
  259. "x$libzmq_cv_c_clang_compiler" = "xyes"; then
  260. CFLAGS="-g -O0 "
  261. elif test "x$libzmq_cv_c_sun_studio_compiler" = "xyes"; then
  262. CFLAGS="-g0 "
  263. fi
  264. # GCC, clang and ICC
  265. if test "x$GXX" = "xyes" -o \
  266. "x$libzmq_cv_cxx_intel_compiler" = "xyes" -o \
  267. "x$libzmq_cv_cxx_clang_compiler" = "xyes"; then
  268. CPPFLAGS="-g -O0 "
  269. CXXFLAGS="-g -O0 "
  270. # Sun studio
  271. elif test "x$libzmq_cv_cxx_sun_studio_compiler" = "xyes"; then
  272. CPPFLAGS="-g0 "
  273. CXXFLAGS="-g0 "
  274. fi
  275. if test "x$ZMQ_ORIG_CFLAGS" != "xnone"; then
  276. CFLAGS="${CFLAGS} ${ZMQ_ORIG_CFLAGS}"
  277. fi
  278. if test "x$ZMQ_ORIG_CPPFLAGS" != "xnone"; then
  279. CPPFLAGS="${CPPFLAGS} ${ZMQ_ORIG_CPPFLAGS}"
  280. fi
  281. if test "x$ZMQ_ORIG_CXXFLAGS" != "xnone"; then
  282. CXXFLAGS="${CXXFLAGS} ${ZMQ_ORIG_CXXFLAGS}"
  283. fi
  284. AC_MSG_RESULT(yes)
  285. else
  286. AC_MSG_RESULT(no)
  287. fi
  288. }])
  289. dnl ##############################################################################
  290. dnl # LIBZMQ_WITH_GCOV([action-if-found], [action-if-not-found]) #
  291. dnl # Check whether to build with code coverage #
  292. dnl ##############################################################################
  293. AC_DEFUN([LIBZMQ_WITH_GCOV], [{
  294. # Require compiler specifics
  295. AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
  296. AC_ARG_WITH(gcov, [AS_HELP_STRING([--with-gcov=yes/no],
  297. [with GCC Code Coverage reporting.])],
  298. [ZMQ_GCOV="$withval"])
  299. AC_MSG_CHECKING(whether to enable code coverage)
  300. if test "x$ZMQ_GCOV" = "xyes"; then
  301. if test "x$GXX" != "xyes"; then
  302. AC_MSG_ERROR([--with-gcov=yes works only with GCC])
  303. fi
  304. CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
  305. if test "x${ZMQ_ORIG_CPPFLAGS}" != "xnone"; then
  306. CFLAGS="${CFLAGS} ${ZMQ_ORIG_CFLAGS}"
  307. fi
  308. CPPFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
  309. if test "x${ZMQ_ORIG_CPPFLAGS}" != "xnone"; then
  310. CPPFLAGS="${CPPFLAGS} ${ZMQ_ORIG_CPPFLAGS}"
  311. fi
  312. CXXFLAGS="-fprofile-arcs"
  313. if test "x${ZMQ_ORIG_CXXFLAGS}" != "xnone"; then
  314. CXXFLAGS="${CXXFLAGS} ${ZMQ_ORIG_CXXFLAGS}"
  315. fi
  316. LIBS="-lgcov ${LIBS}"
  317. fi
  318. AS_IF([test "x$ZMQ_GCOV" = "xyes"],
  319. [AC_MSG_RESULT(yes) ; $1], [AC_MSG_RESULT(no) ; $2])
  320. }])
  321. dnl ##############################################################################
  322. dnl # LIBZMQ_CHECK_WITH_FLAG([flags], [macro]) #
  323. dnl # Runs a normal autoconf check with compiler flags #
  324. dnl ##############################################################################
  325. AC_DEFUN([LIBZMQ_CHECK_WITH_FLAG], [{
  326. libzmq_check_with_flag_save_CFLAGS="$CFLAGS"
  327. libzmq_check_with_flag_save_CPPFLAGS="$CPPFLAGS"
  328. CFLAGS="$CFLAGS $1"
  329. CPPFLAGS="$CPPFLAGS $1"
  330. # Execute the macro
  331. $2
  332. CFLAGS="$libzmq_check_with_flag_save_CFLAGS"
  333. CPPFLAGS="$libzmq_check_with_flag_save_CPPFLAGS"
  334. }])
  335. dnl ##############################################################################
  336. dnl # LIBZMQ_LANG_WALL([action-if-found], [action-if-not-found]) #
  337. dnl # How to define -Wall for the current compiler #
  338. dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]__wall_flag variable to found style #
  339. dnl ##############################################################################
  340. AC_DEFUN([LIBZMQ_LANG_WALL], [{
  341. AC_MSG_CHECKING([how to enable additional warnings for _AC_LANG compiler])
  342. libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag=""
  343. # C compilers
  344. case "x[]_AC_LANG_ABBREV" in
  345. xc)
  346. # GCC, clang and ICC
  347. if test "x$GCC" = "xyes" -o \
  348. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
  349. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
  350. libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall"
  351. # Sun studio
  352. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  353. libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-v"
  354. fi
  355. ;;
  356. xcxx)
  357. # GCC, clang and ICC
  358. if test "x$GXX" = "xyes" -o \
  359. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
  360. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
  361. libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall"
  362. # Sun studio
  363. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  364. libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="+w"
  365. fi
  366. ;;
  367. *)
  368. ;;
  369. esac
  370. # Call the action
  371. if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" != "x"; then
  372. AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag])
  373. $1
  374. else
  375. AC_MSG_RESULT([not found])
  376. $2
  377. fi
  378. }])
  379. dnl ####################################################################
  380. dnl # LIBZMQ_LANG_STRICT([action-if-found], [action-if-not-found]) #
  381. dnl # Check how to turn on strict standards compliance #
  382. dnl ####################################################################
  383. AC_DEFUN([LIBZMQ_LANG_STRICT], [{
  384. AC_MSG_CHECKING([how to enable strict standards compliance in _AC_LANG compiler])
  385. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag=""
  386. # C compilers
  387. case "x[]_AC_LANG_ABBREV" in
  388. xc)
  389. # GCC, clang and ICC
  390. if test "x$GCC" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
  391. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic"
  392. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
  393. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi"
  394. # Sun studio
  395. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  396. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-Xc"
  397. fi
  398. ;;
  399. xcxx)
  400. # GCC, clang and ICC
  401. if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
  402. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic"
  403. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
  404. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi"
  405. # Sun studio
  406. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  407. libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-compat=5"
  408. fi
  409. ;;
  410. *)
  411. ;;
  412. esac
  413. # Call the action
  414. if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag" != "x"; then
  415. AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag])
  416. $1
  417. else
  418. AC_MSG_RESULT([not found])
  419. $2
  420. fi
  421. }])
  422. dnl ########################################################################
  423. dnl # LIBZMQ_LANG_WERROR([action-if-found], [action-if-not-found]) #
  424. dnl # Check how to turn warnings to errors #
  425. dnl ########################################################################
  426. AC_DEFUN([LIBZMQ_LANG_WERROR], [{
  427. AC_MSG_CHECKING([how to turn warnings to errors in _AC_LANG compiler])
  428. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag=""
  429. # C compilers
  430. case "x[]_AC_LANG_ABBREV" in
  431. xc)
  432. # GCC, clang and ICC
  433. if test "x$GCC" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
  434. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror"
  435. # Sun studio
  436. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  437. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all"
  438. fi
  439. ;;
  440. xcxx)
  441. # GCC, clang and ICC
  442. if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
  443. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror"
  444. # Sun studio
  445. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  446. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all"
  447. fi
  448. ;;
  449. *)
  450. ;;
  451. esac
  452. # Call the action
  453. if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag" != "x"; then
  454. AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag])
  455. $1
  456. else
  457. AC_MSG_RESULT([not found])
  458. $2
  459. fi
  460. }])
  461. dnl ################################################################################
  462. dnl # LIBZMQ_CHECK_LANG_PRAGMA([pragma], [action-if-found], [action-if-not-found]) #
  463. dnl # Check if the compiler supports given pragma #
  464. dnl ################################################################################
  465. AC_DEFUN([LIBZMQ_CHECK_LANG_PRAGMA], [{
  466. # Need to know how to enable all warnings
  467. LIBZMQ_LANG_WALL
  468. AC_MSG_CHECKING([whether _AC_LANG compiler supports pragma $1])
  469. # Save flags
  470. libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
  471. ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"
  472. if test "x[]_AC_LANG_ABBREV" = "xc"; then
  473. libzmq_cv_check_lang_pragma_save_CFLAGS="$CFLAGS"
  474. CFLAGS="$CFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
  475. elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
  476. libzmq_cv_check_lang_pragma_save_CPPFLAGS="$CPPFLAGS"
  477. CPPFLAGS="$CPPFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
  478. else
  479. AC_MSG_WARN([testing compiler characteristic on an unknown language])
  480. fi
  481. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#pragma $1]])],
  482. [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="yes" ; AC_MSG_RESULT(yes)],
  483. [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="no" ; AC_MSG_RESULT(no)])
  484. if test "x[]_AC_LANG_ABBREV" = "xc"; then
  485. CFLAGS="$libzmq_cv_check_lang_pragma_save_CFLAGS"
  486. elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
  487. CPPFLAGS="$libzmq_cv_check_lang_pragma_save_CPPFLAGS"
  488. fi
  489. ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
  490. # Call the action as the flags are restored
  491. AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)[ = "xyes"],
  492. [$2], [$3])
  493. }])
  494. dnl ################################################################################
  495. dnl # LIBZMQ_CHECK_LANG_VISIBILITY([action-if-found], [action-if-not-found]) #
  496. dnl # Check if the compiler supports dso visibility #
  497. dnl ################################################################################
  498. AC_DEFUN([LIBZMQ_CHECK_LANG_VISIBILITY], [{
  499. libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag=""
  500. if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
  501. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes" -o \
  502. "x$libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler" = "xyes"; then
  503. LIBZMQ_CHECK_LANG_FLAG([-fvisibility=hidden],
  504. [libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag="-fvisibility=hidden"])
  505. elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
  506. LIBZMQ_CHECK_LANG_FLAG([-xldscope=hidden],
  507. [libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag="-xldscope=hidden"])
  508. fi
  509. AC_MSG_CHECKING(whether _AC_LANG compiler supports dso visibility)
  510. AS_IF([test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag" != "x"],
  511. [AC_MSG_RESULT(yes) ; $1], [AC_MSG_RESULT(no) ; $2])
  512. }])
  513. dnl ################################################################################
  514. dnl # LIBZMQ_CHECK_SOCK_CLOEXEC([action-if-found], [action-if-not-found]) #
  515. dnl # Check if SOCK_CLOEXEC is supported #
  516. dnl ################################################################################
  517. AC_DEFUN([LIBZMQ_CHECK_SOCK_CLOEXEC], [{
  518. AC_CACHE_CHECK([whether SOCK_CLOEXEC is supported], [libzmq_cv_sock_cloexec],
  519. [AC_TRY_RUN([/* SOCK_CLOEXEC test */
  520. #include <sys/types.h>
  521. #include <sys/socket.h>
  522. int main (int argc, char *argv [])
  523. {
  524. int s = socket (PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
  525. return (s == -1);
  526. }
  527. ],
  528. [libzmq_cv_sock_cloexec="yes"],
  529. [libzmq_cv_sock_cloexec="no"],
  530. [libzmq_cv_sock_cloexec="not during cross-compile"]
  531. )]
  532. )
  533. AS_IF([test "x$libzmq_cv_sock_cloexec" = "xyes"], [$1], [$2])
  534. }])
  535. dnl ################################################################################
  536. dnl # LIBZMQ_CHECK_O_CLOEXEC([action-if-found], [action-if-not-found]) #
  537. dnl # Check if O_CLOEXEC is supported #
  538. dnl ################################################################################
  539. AC_DEFUN([LIBZMQ_CHECK_O_CLOEXEC], [{
  540. AC_CACHE_CHECK([whether O_CLOEXEC is supported], [libzmq_cv_o_cloexec],
  541. [AC_TRY_RUN([/* O_CLOEXEC test */
  542. #include <sys/types.h>
  543. #include <sys/stat.h>
  544. #include <fcntl.h>
  545. int main (int argc, char *argv [])
  546. {
  547. int s = open ("/dev/null", O_CLOEXEC | O_RDONLY);
  548. return (s == -1);
  549. }
  550. ],
  551. [libzmq_cv_o_cloexec="yes"],
  552. [libzmq_cv_o_cloexec="no"],
  553. [libzmq_cv_o_cloexec="not during cross-compile"]
  554. )]
  555. )
  556. AS_IF([test "x$libzmq_cv_o_cloexec" = "xyes"], [$1], [$2])
  557. }])
  558. dnl ################################################################################
  559. dnl # LIBZMQ_CHECK_EVENTFD_CLOEXEC([action-if-found], [action-if-not-found]) #
  560. dnl # Check if EFD_CLOEXEC is supported #
  561. dnl ################################################################################
  562. AC_DEFUN([LIBZMQ_CHECK_EVENTFD_CLOEXEC], [{
  563. AC_CACHE_CHECK([whether EFD_CLOEXEC is supported], [libzmq_cv_efd_cloexec],
  564. [AC_TRY_RUN([/* EFD_CLOEXEC test */
  565. #include <sys/eventfd.h>
  566. int main (int argc, char *argv [])
  567. {
  568. int s = eventfd (0, EFD_CLOEXEC);
  569. return (s == -1);
  570. }
  571. ],
  572. [libzmq_cv_efd_cloexec="yes"],
  573. [libzmq_cv_efd_cloexec="no"],
  574. [libzmq_cv_efd_cloexec="not during cross-compile"]
  575. )]
  576. )
  577. AS_IF([test "x$libzmq_cv_efd_cloexec" = "xyes"], [$1], [$2])
  578. }])
  579. dnl ################################################################################
  580. dnl # LIBZMQ_CHECK_ATOMIC_INSTRINSICS([action-if-found], [action-if-not-found]) #
  581. dnl # Check if compiler supoorts __atomic_Xxx intrinsics #
  582. dnl ################################################################################
  583. AC_DEFUN([LIBZMQ_CHECK_ATOMIC_INTRINSICS], [{
  584. AC_MSG_CHECKING(whether compiler supports __atomic_Xxx intrinsics)
  585. AC_LINK_IFELSE([AC_LANG_SOURCE([
  586. /* atomic intrinsics test */
  587. int v = 0;
  588. int main (int, char **)
  589. {
  590. int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
  591. return t;
  592. }
  593. ])],
  594. [AC_MSG_RESULT(yes) ; GCC_ATOMIC_BUILTINS_SUPPORTED=1 libzmq_cv_has_atomic_instrisics="yes" ; $1])
  595. if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != x1; then
  596. save_LIBS=$LIBS
  597. LIBS="$LIBS -latomic"
  598. AC_LINK_IFELSE([AC_LANG_SOURCE([
  599. /* atomic intrinsics test */
  600. int v = 0;
  601. int main (int, char **)
  602. {
  603. int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
  604. return t;
  605. }
  606. ])],
  607. [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" PKGCFG_LIBS_PRIVATE="$PKGCFG_LIBS_PRIVATE -latomic" ; $1],
  608. [AC_MSG_RESULT(no) ; libzmq_cv_has_atomic_instrisics="no" LIBS=$save_LIBS ; $2])
  609. fi
  610. }])
  611. dnl ################################################################################
  612. dnl # LIBZMQ_CHECK_SO_BINDTODEVICE([action-if-found], [action-if-not-found]) #
  613. dnl # Check if SO_BINDTODEVICE is supported #
  614. dnl ################################################################################
  615. AC_DEFUN([LIBZMQ_CHECK_SO_BINDTODEVICE], [{
  616. AC_CACHE_CHECK([whether SO_BINDTODEVICE is supported], [libzmq_cv_so_bindtodevice],
  617. [AC_TRY_RUN([/* SO_BINDTODEVICE test */
  618. #include <sys/socket.h>
  619. int main (int argc, char *argv [])
  620. {
  621. /* Actually making the setsockopt() call requires CAP_NET_RAW */
  622. #ifndef SO_BINDTODEVICE
  623. return 1;
  624. #else
  625. return 0;
  626. #endif
  627. }
  628. ],
  629. [libzmq_cv_so_bindtodevice="yes"],
  630. [libzmq_cv_so_bindtodevice="no"],
  631. [libzmq_cv_so_bindtodevice="not during cross-compile"]
  632. )]
  633. )
  634. AS_IF([test "x$libzmq_cv_so_bindtodevice" = "xyes"], [$1], [$2])
  635. }])
  636. dnl ################################################################################
  637. dnl # LIBZMQ_CHECK_SO_KEEPALIVE([action-if-found], [action-if-not-found]) #
  638. dnl # Check if SO_KEEPALIVE is supported #
  639. dnl ################################################################################
  640. AC_DEFUN([LIBZMQ_CHECK_SO_KEEPALIVE], [{
  641. AC_CACHE_CHECK([whether SO_KEEPALIVE is supported], [libzmq_cv_so_keepalive],
  642. [AC_TRY_RUN([/* SO_KEEPALIVE test */
  643. #include <sys/types.h>
  644. #include <sys/socket.h>
  645. int main (int argc, char *argv [])
  646. {
  647. int s, rc, opt = 1;
  648. return (
  649. ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
  650. ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1)
  651. );
  652. }
  653. ],
  654. [libzmq_cv_so_keepalive="yes"],
  655. [libzmq_cv_so_keepalive="no"],
  656. [libzmq_cv_so_keepalive="not during cross-compile"]
  657. )]
  658. )
  659. AS_IF([test "x$libzmq_cv_so_keepalive" = "xyes"], [$1], [$2])
  660. }])
  661. dnl ################################################################################
  662. dnl # LIBZMQ_CHECK_TCP_KEEPCNT([action-if-found], [action-if-not-found]) #
  663. dnl # Check if TCP_KEEPCNT is supported #
  664. dnl ################################################################################
  665. AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPCNT], [{
  666. AC_CACHE_CHECK([whether TCP_KEEPCNT is supported], [libzmq_cv_tcp_keepcnt],
  667. [AC_TRY_RUN([/* TCP_KEEPCNT test */
  668. #include <sys/types.h>
  669. #include <sys/socket.h>
  670. #include <netinet/in.h>
  671. #include <netinet/tcp.h>
  672. int main (int argc, char *argv [])
  673. {
  674. int s, rc, opt = 1;
  675. return (
  676. ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
  677. ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
  678. ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPCNT, (char*) &opt, sizeof (int))) == -1)
  679. );
  680. }
  681. ],
  682. [libzmq_cv_tcp_keepcnt="yes"],
  683. [libzmq_cv_tcp_keepcnt="no"],
  684. [libzmq_cv_tcp_keepcnt="not during cross-compile"]
  685. )]
  686. )
  687. AS_IF([test "x$libzmq_cv_tcp_keepcnt" = "xyes"], [$1], [$2])
  688. }])
  689. dnl ################################################################################
  690. dnl # LIBZMQ_CHECK_TCP_KEEPIDLE([action-if-found], [action-if-not-found]) #
  691. dnl # Check if TCP_KEEPIDLE is supported #
  692. dnl ################################################################################
  693. AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPIDLE], [{
  694. AC_CACHE_CHECK([whether TCP_KEEPIDLE is supported], [libzmq_cv_tcp_keepidle],
  695. [AC_TRY_RUN([/* TCP_KEEPIDLE test */
  696. #include <sys/types.h>
  697. #include <sys/socket.h>
  698. #include <netinet/in.h>
  699. #include <netinet/tcp.h>
  700. int main (int argc, char *argv [])
  701. {
  702. int s, rc, opt = 1;
  703. return (
  704. ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
  705. ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
  706. ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPIDLE, (char*) &opt, sizeof (int))) == -1)
  707. );
  708. }
  709. ],
  710. [libzmq_cv_tcp_keepidle="yes"],
  711. [libzmq_cv_tcp_keepidle="no"],
  712. [libzmq_cv_tcp_keepidle="not during cross-compile"]
  713. )]
  714. )
  715. AS_IF([test "x$libzmq_cv_tcp_keepidle" = "xyes"], [$1], [$2])
  716. }])
  717. dnl ################################################################################
  718. dnl # LIBZMQ_CHECK_TCP_KEEPINTVL([action-if-found], [action-if-not-found]) #
  719. dnl # Check if TCP_KEEPINTVL is supported #
  720. dnl ################################################################################
  721. AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPINTVL], [{
  722. AC_CACHE_CHECK([whether TCP_KEEPINTVL is supported], [libzmq_cv_tcp_keepintvl],
  723. [AC_TRY_RUN([/* TCP_KEEPINTVL test */
  724. #include <sys/types.h>
  725. #include <sys/socket.h>
  726. #include <netinet/in.h>
  727. #include <netinet/tcp.h>
  728. int main (int argc, char *argv [])
  729. {
  730. int s, rc, opt = 1;
  731. return (
  732. ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
  733. ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
  734. ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPINTVL, (char*) &opt, sizeof (int))) == -1)
  735. );
  736. }
  737. ],
  738. [libzmq_cv_tcp_keepintvl="yes"],
  739. [libzmq_cv_tcp_keepintvl="no"],
  740. [libzmq_cv_tcp_keepintvl="not during cross-compile"]
  741. )]
  742. )
  743. AS_IF([test "x$libzmq_cv_tcp_keepintvl" = "xyes"], [$1], [$2])
  744. }])
  745. dnl ################################################################################
  746. dnl # LIBZMQ_CHECK_TCP_KEEPALIVE([action-if-found], [action-if-not-found]) #
  747. dnl # Check if TCP_KEEPALIVE is supported #
  748. dnl ################################################################################
  749. AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPALIVE], [{
  750. AC_CACHE_CHECK([whether TCP_KEEPALIVE is supported], [libzmq_cv_tcp_keepalive],
  751. [AC_TRY_RUN([/* TCP_KEEPALIVE test */
  752. #include <sys/types.h>
  753. #include <sys/socket.h>
  754. #include <netinet/in.h>
  755. #include <netinet/tcp.h>
  756. int main (int argc, char *argv [])
  757. {
  758. int s, rc, opt = 1;
  759. return (
  760. ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
  761. ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
  762. ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPALIVE, (char*) &opt, sizeof (int))) == -1)
  763. );
  764. }
  765. ],
  766. [libzmq_cv_tcp_keepalive="yes"],
  767. [libzmq_cv_tcp_keepalive="no"],
  768. [libzmq_cv_tcp_keepalive="not during cross-compile"]
  769. )]
  770. )
  771. AS_IF([test "x$libzmq_cv_tcp_keepalive" = "xyes"], [$1], [$2])
  772. }])
  773. dnl ################################################################################
  774. dnl # LIBZMQ_CHECK_GETRANDOM([action-if-found], [action-if-not-found]) #
  775. dnl # Checks if getrandom is supported #
  776. dnl ################################################################################
  777. AC_DEFUN([LIBZMQ_CHECK_GETRANDOM], [{
  778. AC_CACHE_CHECK([whether getrandom is supported], [libzmq_cv_getrandom],
  779. [AC_TRY_RUN([/* thread-local storage test */
  780. #include <sys/random.h>
  781. int main (int argc, char *argv [])
  782. {
  783. char buf[4];
  784. int rc = getrandom(buf, 4, 0);
  785. return rc == -1 ? 1 : 0;
  786. }
  787. ],
  788. [libzmq_cv_getrandom="yes"],
  789. [libzmq_cv_getrandom="no"],
  790. [libzmq_cv_getrandom="not during cross-compile"]
  791. )]
  792. )
  793. AS_IF([test "x$libzmq_cv_getrandom" = "xyes"], [$1], [$2])
  794. }])
  795. dnl ################################################################################
  796. dnl # LIBZMQ_CHECK_POLLER_KQUEUE([action-if-found], [action-if-not-found]) #
  797. dnl # Checks kqueue polling system #
  798. dnl ################################################################################
  799. AC_DEFUN([LIBZMQ_CHECK_POLLER_KQUEUE], [{
  800. AC_LINK_IFELSE([
  801. AC_LANG_PROGRAM([
  802. #include <sys/types.h>
  803. #include <sys/event.h>
  804. #include <sys/time.h>
  805. ],[[
  806. struct kevent t_kev;
  807. kqueue();
  808. ]])],
  809. [$1], [$2]
  810. )
  811. }])
  812. dnl ################################################################################
  813. dnl # LIBZMQ_CHECK_POLLER_EPOLL_RUN([action-if-found], [action-if-not-found]) #
  814. dnl # LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([action-if-found], [action-if-not-found]) #
  815. dnl # Checks epoll polling system can actually run #
  816. dnl # For cross-compile, only requires that epoll can link #
  817. dnl ################################################################################
  818. AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL], [{
  819. AC_RUN_IFELSE([
  820. AC_LANG_PROGRAM([
  821. #include <sys/epoll.h>
  822. ],[[
  823. struct epoll_event t_ev;
  824. int r;
  825. r = epoll_create(10);
  826. return(r < 0);
  827. ]])],
  828. [$1],[$2],[
  829. AC_LINK_IFELSE([
  830. AC_LANG_PROGRAM([
  831. #include <sys/epoll.h>
  832. ],[[
  833. struct epoll_event t_ev;
  834. epoll_create(10);
  835. ]])],
  836. [$1], [$2]
  837. )
  838. ]
  839. )
  840. }])
  841. AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC], [{
  842. AC_RUN_IFELSE([
  843. AC_LANG_PROGRAM([
  844. #include <sys/epoll.h>
  845. ],[[
  846. struct epoll_event t_ev;
  847. int r;
  848. r = epoll_create1(EPOLL_CLOEXEC);
  849. return(r < 0);
  850. ]])],
  851. [$1],[$2],[
  852. AC_LINK_IFELSE([
  853. AC_LANG_PROGRAM([
  854. #include <sys/epoll.h>
  855. ],[[
  856. struct epoll_event t_ev;
  857. epoll_create1(EPOLL_CLOEXEC);
  858. ]])],
  859. [$1], [$2]
  860. )
  861. ]
  862. )
  863. }])
  864. dnl ################################################################################
  865. dnl # LIBZMQ_CHECK_POLLER_DEVPOLL([action-if-found], [action-if-not-found]) #
  866. dnl # Checks devpoll polling system #
  867. dnl ################################################################################
  868. AC_DEFUN([LIBZMQ_CHECK_POLLER_DEVPOLL], [{
  869. AC_LINK_IFELSE([
  870. AC_LANG_PROGRAM([
  871. #include <sys/devpoll.h>
  872. ],[[
  873. struct pollfd t_devpoll;
  874. int fd = open("/dev/poll", O_RDWR);
  875. ]])],
  876. [$1], [$2]
  877. )
  878. }])
  879. dnl ################################################################################
  880. dnl # LIBZMQ_CHECK_POLLER_POLLSET([action-if-found], [action-if-not-found]) #
  881. dnl # Checks pollset polling system #
  882. dnl ################################################################################
  883. AC_DEFUN([LIBZMQ_CHECK_POLLER_POLLSET], [{
  884. AC_LINK_IFELSE([
  885. AC_LANG_PROGRAM([
  886. #include <sys/poll.h>
  887. #include <sys/pollset.h>
  888. ],[[
  889. pollset_t ps = pollset_create(-1);
  890. ]])],
  891. [$1], [$2]
  892. )
  893. }])
  894. dnl ################################################################################
  895. dnl # LIBZMQ_CHECK_POLLER_POLL([action-if-found], [action-if-not-found]) #
  896. dnl # Checks poll polling system #
  897. dnl ################################################################################
  898. AC_DEFUN([LIBZMQ_CHECK_POLLER_POLL], [{
  899. AC_LINK_IFELSE([
  900. AC_LANG_PROGRAM([
  901. #include <poll.h>
  902. ],[[
  903. struct pollfd t_poll;
  904. poll(&t_poll, 1, 1);
  905. ]])],
  906. [$1], [$2]
  907. )
  908. }])
  909. dnl ################################################################################
  910. dnl # LIBZMQ_CHECK_POLLER_SELECT([action-if-found], [action-if-not-found]) #
  911. dnl # Checks select polling system #
  912. dnl ################################################################################
  913. AC_DEFUN([LIBZMQ_CHECK_POLLER_SELECT], [{
  914. AC_LINK_IFELSE([
  915. AC_LANG_PROGRAM([
  916. #ifdef ZMQ_HAVE_WINDOWS
  917. #include "winsock2.h"
  918. #elif defined ZMQ_HAVE_OPENVMS
  919. #include <sys/types.h>
  920. #include <sys/time.h>
  921. #else
  922. #include <sys/select.h>
  923. #endif
  924. ],[[
  925. fd_set t_rfds;
  926. struct timeval tv;
  927. FD_ZERO(&t_rfds);
  928. FD_SET(0, &t_rfds);
  929. tv.tv_sec = 5;
  930. tv.tv_usec = 0;
  931. select(1, &t_rfds, 0, 0, &tv);
  932. ]])],
  933. [$1],[$2]
  934. )
  935. }])
  936. dnl ################################################################################
  937. dnl # LIBZMQ_CHECK_POLLER([action-if-found], [action-if-not-found]) #
  938. dnl # Choose polling system #
  939. dnl ################################################################################
  940. AC_DEFUN([LIBZMQ_CHECK_POLLER], [{
  941. # Allow user to override poller autodetection
  942. AC_ARG_WITH([poller],
  943. [AS_HELP_STRING([--with-poller],
  944. [choose I/O thread polling system manually. Valid values are 'kqueue', 'epoll', 'devpoll', 'pollset', 'poll', 'select', 'wepoll', or 'auto'. [default=auto]])])
  945. # Allow user to override poller autodetection
  946. AC_ARG_WITH([api_poller],
  947. [AS_HELP_STRING([--with-api-poller],
  948. [choose zmq_poll(er)_* API polling system manually. Valid values are 'poll', 'select', or 'auto'. [default=auto]])])
  949. if test "x$with_poller" = "x"; then
  950. pollers=auto
  951. else
  952. pollers=$with_poller
  953. fi
  954. if test "$pollers" = "auto"; then
  955. # We search for pollers in this order
  956. pollers="kqueue epoll devpoll pollset poll select"
  957. fi
  958. # try to find suitable polling system. the order of testing is:
  959. AC_MSG_NOTICE([Choosing I/O thread polling system from '$pollers'...])
  960. poller_found=0
  961. for poller in $pollers; do
  962. case "$poller" in
  963. kqueue)
  964. LIBZMQ_CHECK_POLLER_KQUEUE([
  965. AC_MSG_NOTICE([Using 'kqueue' I/O thread polling system])
  966. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_KQUEUE, 1, [Use 'kqueue' I/O thread polling system])
  967. poller_found=1
  968. ])
  969. ;;
  970. epoll)
  971. case "$host_os" in
  972. solaris*|sunos*)
  973. # Recent illumos and Solaris systems did add epoll()
  974. # syntax, but it does not fully satisfy expectations
  975. # that ZMQ has from Linux systems. Unless you undertake
  976. # to fix the integration, do not disable this exception
  977. # and use select() or poll() on Solarish OSes for now.
  978. AC_MSG_NOTICE([NOT using 'epoll' I/O thread polling system on '$host_os']) ;;
  979. *)
  980. LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([
  981. AC_MSG_NOTICE([Using 'epoll' I/O thread polling system with CLOEXEC])
  982. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
  983. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL_CLOEXEC, 1, [Use 'epoll' I/O thread polling system with CLOEXEC])
  984. poller_found=1
  985. ],[
  986. LIBZMQ_CHECK_POLLER_EPOLL([
  987. AC_MSG_NOTICE([Using 'epoll' I/O thread polling system with CLOEXEC])
  988. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
  989. poller_found=1
  990. ])
  991. ])
  992. ;;
  993. esac
  994. ;;
  995. devpoll)
  996. LIBZMQ_CHECK_POLLER_DEVPOLL([
  997. AC_MSG_NOTICE([Using 'devpoll' I/O thread polling system])
  998. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_DEVPOLL, 1, [Use 'devpoll' I/O thread polling system])
  999. poller_found=1
  1000. ])
  1001. ;;
  1002. pollset)
  1003. LIBZMQ_CHECK_POLLER_POLLSET([
  1004. AC_MSG_NOTICE([Using 'pollset' I/O thread polling system])
  1005. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_POLLSET, 1, [Use 'pollset' I/O thread polling system])
  1006. poller_found=1
  1007. ])
  1008. ;;
  1009. poll)
  1010. LIBZMQ_CHECK_POLLER_POLL([
  1011. AC_MSG_NOTICE([Using 'poll' I/O thread polling system])
  1012. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_POLL, 1, [Use 'poll' I/O thread polling system])
  1013. poller_found=1
  1014. ])
  1015. ;;
  1016. select)
  1017. LIBZMQ_CHECK_POLLER_SELECT([
  1018. AC_MSG_NOTICE([Using 'select' I/O thread polling system])
  1019. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_SELECT, 1, [Use 'select' I/O thread polling system])
  1020. poller_found=1
  1021. ])
  1022. ;;
  1023. wepoll)
  1024. # wepoll can only be manually selected
  1025. AC_MSG_NOTICE([Using 'wepoll' I/O thread polling system])
  1026. AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
  1027. poller_found=1
  1028. ;;
  1029. esac
  1030. test $poller_found -eq 1 && break
  1031. done
  1032. if test $poller_found -eq 0; then
  1033. AC_MSG_ERROR([None of '$pollers' are valid pollers on this platform])
  1034. fi
  1035. if test "x$with_api_poller" = "x"; then
  1036. with_api_poller=auto
  1037. fi
  1038. if test "x$with_api_poller" = "xauto"; then
  1039. if test $poller = "select"; then
  1040. api_poller=select
  1041. elif test $poller = "wepoll"; then
  1042. api_poller=select
  1043. else
  1044. api_poller=poll
  1045. fi
  1046. else
  1047. api_poller=$with_api_poller
  1048. fi
  1049. if test "$api_poller" = "select"; then
  1050. AC_MSG_NOTICE([Using 'select' zmq_poll(er)_* API polling system])
  1051. AC_DEFINE(ZMQ_POLL_BASED_ON_SELECT, 1, [Use 'select' zmq_poll(er)_* API polling system])
  1052. elif test "$api_poller" = "poll"; then
  1053. AC_MSG_NOTICE([Using 'poll' zmq_poll(er)_* API polling system])
  1054. AC_DEFINE(ZMQ_POLL_BASED_ON_POLL, 1, [Use 'poll' zmq_poll(er)_* API polling system])
  1055. else
  1056. AC_MSG_ERROR([Invalid API poller '$api_poller' specified])
  1057. fi
  1058. }])
  1059. dnl ##############################################################################
  1060. dnl # LIBZMQ_CHECK_CACHELINE #
  1061. dnl # Check cacheline size for alignment purposes #
  1062. dnl ##############################################################################
  1063. AC_DEFUN([LIBZMQ_CHECK_CACHELINE], [{
  1064. zmq_cacheline_size=64
  1065. AC_CHECK_TOOL(libzmq_getconf, getconf)
  1066. if ! test "x$libzmq_getconf" = "x"; then
  1067. zmq_cacheline_size=$($libzmq_getconf LEVEL1_DCACHE_LINESIZE 2>/dev/null || echo 64)
  1068. if test "x$zmq_cacheline_size" = "x0" -o "x$zmq_cacheline_size" = "x-1"; then
  1069. # getconf on some architectures does not know the size, try to fallback to
  1070. # the value the kernel knows on Linux
  1071. zmq_cacheline_size=$(cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size 2>/dev/null || echo 64)
  1072. fi
  1073. fi
  1074. AC_MSG_NOTICE([Using "$zmq_cacheline_size" bytes alignment for lock-free data structures])
  1075. AC_DEFINE_UNQUOTED(ZMQ_CACHELINE_SIZE, $zmq_cacheline_size, [Using "$zmq_cacheline_size" bytes alignment for lock-free data structures])
  1076. }])
  1077. dnl ################################################################################
  1078. dnl # LIBZMQ_CHECK_CV_IMPL([action-if-found], [action-if-not-found]) #
  1079. dnl # Choose condition variable implementation #
  1080. dnl ################################################################################
  1081. AC_DEFUN([LIBZMQ_CHECK_CV_IMPL], [{
  1082. # Allow user to override condition variable autodetection
  1083. AC_ARG_WITH([cv-impl],
  1084. [AS_HELP_STRING([--with-cv-impl],
  1085. [choose condition variable implementation manually. Valid values are 'stl11', 'pthread', 'none', or 'auto'. [default=auto]])])
  1086. if test "x$with_cv_impl" = "x"; then
  1087. cv_impl=auto
  1088. else
  1089. cv_impl=$with_cv_impl
  1090. fi
  1091. case $host_os in
  1092. vxworks*)
  1093. cv_impl="vxworks"
  1094. AC_DEFINE(ZMQ_USE_CV_IMPL_VXWORKS, 1, [Use vxworks condition variable implementation.])
  1095. ;;
  1096. esac
  1097. if test "$cv_impl" = "auto" || test "$cv_impl" = "stl11"; then
  1098. AC_LANG_PUSH([C++])
  1099. AC_CHECK_HEADERS(condition_variable, [stl11="yes"
  1100. AC_DEFINE(ZMQ_USE_CV_IMPL_STL11, 1, [Use stl11 condition variable implementation.])],
  1101. [stl11="no"])
  1102. AC_LANG_POP([C++])
  1103. if test "$cv_impl" = "stl11" && test "x$stl11" = "xno"; then
  1104. AC_MSG_ERROR([--with-cv-impl set to stl11 but cannot find condition_variable])
  1105. fi
  1106. fi
  1107. if test "$cv_impl" = "pthread" || test "x$stl11" = "xno"; then
  1108. AC_DEFINE(ZMQ_USE_CV_IMPL_PTHREADS, 1, [Use pthread condition variable implementation.])
  1109. fi
  1110. if test "$cv_impl" = "none"; then
  1111. AC_DEFINE(ZMQ_USE_CV_IMPL_NONE, 1, [Use no condition variable implementation.])
  1112. fi
  1113. AC_MSG_NOTICE([Using "$cv_impl" condition variable implementation.])
  1114. }])