mhd_sys_extentions.m4 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. # SYNOPSIS
  2. #
  3. # MHD_SYS_EXT([VAR-ADD-CPPFLAGS])
  4. #
  5. # DESCRIPTION
  6. #
  7. # This macro checks system headers and add defines that enable maximum
  8. # number of exposed system interfaces. Macro verifies that added defines
  9. # will not break basic headers, some defines are also checked against
  10. # real recognition by headers.
  11. # If VAR-ADD-CPPFLAGS is specified, defines will be added to this variable
  12. # in form suitable for CPPFLAGS. Otherwise defines will be added to
  13. # configuration header (usually 'config.h').
  14. #
  15. # Example usage:
  16. #
  17. # MHD_SYS_EXT
  18. #
  19. # or
  20. #
  21. # MHD_SYS_EXT([CPPFLAGS])
  22. #
  23. # Macro is not enforced to be called before AC_COMPILE_IFELSE, but it
  24. # advisable to call macro before any compile and header tests since
  25. # additional defines can change results of those tests.
  26. #
  27. # Defined in command line macros are always honored and cache variables
  28. # used in all checks so if any test will not work correctly on some
  29. # platform, user may simply fix it by giving correct defines in CPPFLAGS
  30. # or by giving cache variable in configure parameters, for example:
  31. #
  32. # ./configure CPPFLAGS='-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED'
  33. #
  34. # or
  35. #
  36. # ./configure mhd_cv_define__xopen_source_sevenh_works=no
  37. #
  38. # This simplify building from source on exotic platforms as patching
  39. # of configure.ac is not required to change results of tests.
  40. #
  41. # LICENSE
  42. #
  43. # Copyright (c) 2016, 2017 Karlson2k (Evgeny Grin) <k2k@narod.ru>
  44. #
  45. # Copying and distribution of this file, with or without modification, are
  46. # permitted in any medium without royalty provided the copyright notice
  47. # and this notice are preserved. This file is offered as-is, without any
  48. # warranty.
  49. #serial 2
  50. AC_DEFUN([MHD_SYS_EXT],[dnl
  51. AC_PREREQ([2.64])dnl for AS_VAR_IF, AS_VAR_SET_IF, m4_ifnblank
  52. AC_LANG_PUSH([C])dnl Use C language for simplicity
  53. mhd_mse_sys_ext_defines=""
  54. mhd_mse_sys_ext_flags=""
  55. dnl Check platform-specific extensions.
  56. dnl Use compiler-based test for determinig target.
  57. dnl Always add _GNU_SOURCE if headers allow.
  58. MHD_CHECK_DEF_AND_ACCEPT([[_GNU_SOURCE]], [],
  59. [[${mhd_mse_sys_ext_defines}]], [mhd_cv_macro_add__gnu_source="no"],
  60. [mhd_cv_macro_add__gnu_source="yes"],
  61. [mhd_cv_macro_add__gnu_source="no"]
  62. )
  63. AS_VAR_IF([mhd_cv_macro_add__gnu_source], ["yes"],
  64. [
  65. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_GNU_SOURCE]])
  66. ]
  67. )
  68. dnl __BSD_VISIBLE is actually a small hack for FreeBSD.
  69. dnl Funny that it's used in some Android versions too.
  70. AC_CACHE_CHECK([[whether to try __BSD_VISIBLE macro]],
  71. [[mhd_cv_macro_try___bsd_visible]], [dnl
  72. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  73. /* Warning: test with inverted logic! */
  74. #ifdef __FreeBSD__
  75. #error Target FreeBSD
  76. choke me now;
  77. #endif /* __FreeBSD__ */
  78. #ifdef __ANDROID__
  79. #include <android/api-level.h>
  80. #ifndef __ANDROID_API_O__
  81. #error Target is Android NDK before R14
  82. choke me now;
  83. #endif /* ! __ANDROID_API_O__ */
  84. #endif /* __ANDROID__ */
  85. ]],[])],
  86. [[mhd_cv_macro_try___bsd_visible="no"]],
  87. [[mhd_cv_macro_try___bsd_visible="yes"]]
  88. )
  89. ])
  90. AS_VAR_IF([[mhd_cv_macro_try___bsd_visible]], [["yes"]],
  91. [dnl
  92. AC_CACHE_CHECK([[whether __BSD_VISIBLE is already defined]],
  93. [[mhd_cv_macro___bsd_visible_defined]], [dnl
  94. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  95. ${mhd_mse_sys_ext_defines}
  96. /* Warning: test with inverted logic! */
  97. #ifdef __BSD_VISIBLE
  98. #error __BSD_VISIBLE is defined
  99. choke me now;
  100. #endif
  101. ]],[])
  102. ],
  103. [[mhd_cv_macro___bsd_visible_defined="no"]],
  104. [[mhd_cv_macro___bsd_visible_defined="yes"]]
  105. )
  106. ])
  107. AS_VAR_IF([[mhd_cv_macro___bsd_visible_defined]], [["yes"]], [[:]],
  108. [dnl
  109. MHD_CHECK_ACCEPT_DEFINE(
  110. [[__BSD_VISIBLE]], [], [[${mhd_mse_sys_ext_defines}]],
  111. [
  112. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[__BSD_VISIBLE]])
  113. ]
  114. )dnl
  115. ])
  116. ])
  117. dnl _DARWIN_C_SOURCE enables additional functionality on Darwin.
  118. MHD_CHECK_DEFINED_MSG([[__APPLE__]], [[${mhd_mse_sys_ext_defines}]],
  119. [[whether to try _DARWIN_C_SOURCE macro]],
  120. [dnl
  121. MHD_CHECK_DEF_AND_ACCEPT(
  122. [[_DARWIN_C_SOURCE]], [], [[${mhd_mse_sys_ext_defines}]], [],
  123. [
  124. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_DARWIN_C_SOURCE]])
  125. ]
  126. )dnl
  127. ])
  128. dnl __EXTENSIONS__ unlocks almost all interfaces on Solaris.
  129. MHD_CHECK_DEFINED_MSG([[__sun]], [[${mhd_mse_sys_ext_defines}]],
  130. [[whether to try __EXTENSIONS__ macro]],
  131. [dnl
  132. MHD_CHECK_DEF_AND_ACCEPT(
  133. [[__EXTENSIONS__]], [], [[${mhd_mse_sys_ext_defines}]], [],
  134. [
  135. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[__EXTENSIONS__]])
  136. ]
  137. )dnl
  138. ])
  139. dnl _NETBSD_SOURCE switch on almost all headers definitions on NetBSD.
  140. MHD_CHECK_DEFINED_MSG([[__NetBSD__]], [[${mhd_mse_sys_ext_defines}]],
  141. [[whether to try _NETBSD_SOURCE macro]],
  142. [dnl
  143. MHD_CHECK_DEF_AND_ACCEPT(
  144. [[_NETBSD_SOURCE]], [], [[${mhd_mse_sys_ext_defines}]], [],
  145. [
  146. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_NETBSD_SOURCE]])
  147. ]
  148. )dnl
  149. ])
  150. dnl _BSD_SOURCE currently used only on OpenBSD to unhide functions.
  151. MHD_CHECK_DEFINED_MSG([[__OpenBSD__]], [[${mhd_mse_sys_ext_defines}]],
  152. [[whether to try _BSD_SOURCE macro]],
  153. [dnl
  154. MHD_CHECK_DEF_AND_ACCEPT(
  155. [[_BSD_SOURCE]], [], [[${mhd_mse_sys_ext_defines}]], [],
  156. [
  157. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_BSD_SOURCE]])
  158. ]
  159. )dnl
  160. ])
  161. dnl _TANDEM_SOURCE unhides most functions on NonStop OS
  162. dnl (which comes from Tandem Computers decades ago).
  163. MHD_CHECK_DEFINED_MSG([[__TANDEM]], [[${mhd_mse_sys_ext_defines}]],
  164. [[whether to try _TANDEM_SOURCE macro]],
  165. [dnl
  166. MHD_CHECK_DEF_AND_ACCEPT(
  167. [[_TANDEM_SOURCE]], [], [[${mhd_mse_sys_ext_defines}]], [],
  168. [
  169. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_TANDEM_SOURCE]])
  170. ]
  171. )dnl
  172. ])
  173. dnl _ALL_SOURCE makes visible POSIX and non-POSIX symbols
  174. dnl on z/OS, AIX and Interix.
  175. AC_CACHE_CHECK([[whether to try _ALL_SOURCE macro]],
  176. [[mhd_cv_macro_try__all_source]], [dnl
  177. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  178. #if !defined(__TOS_MVS__) && !defined (__INTERIX)
  179. #error Target is not z/OS, AIX or Interix
  180. choke me now;
  181. #endif
  182. ]],[])],
  183. [[mhd_cv_macro_try__all_source="yes"]],
  184. [[mhd_cv_macro_try__all_source="no"]]
  185. )
  186. ])
  187. AS_VAR_IF([[mhd_cv_macro_try__all_source]], [["yes"]],
  188. [dnl
  189. MHD_CHECK_DEF_AND_ACCEPT(
  190. [[_ALL_SOURCE]], [], [[${mhd_mse_sys_ext_defines}]], [],
  191. [
  192. _MHD_SYS_EXT_VAR_ADD_FLAG([[mhd_mse_sys_ext_defines]], [[mhd_mse_sys_ext_flags]], [[_ALL_SOURCE]])
  193. ]
  194. )dnl
  195. ])
  196. mhd_mse_xopen_features=""
  197. mhd_mse_xopen_defines=""
  198. mhd_mse_xopen_flags=""
  199. AC_CACHE_CHECK([[whether _XOPEN_SOURCE is already defined]],
  200. [[mhd_cv_macro__xopen_source_defined]], [
  201. _MHD_CHECK_DEFINED([[_XOPEN_SOURCE]], [[${mhd_mse_sys_ext_defines}]],
  202. [[mhd_cv_macro__xopen_source_defined="yes"]],
  203. [[mhd_cv_macro__xopen_source_defined="no"]]
  204. )
  205. ]
  206. )
  207. AS_VAR_IF([[mhd_cv_macro__xopen_source_defined]], [["no"]],
  208. [
  209. dnl Some platforms (namely: Solaris) use '==' checks instead of '>='
  210. dnl for _XOPEN_SOURCE, resulting that unknown for platform values are
  211. dnl interpreted as oldest and platform expose reduced number of
  212. dnl interfaces. Next checks will ensure that platform recognise
  213. dnl requested mode instead of blindly define high number that can
  214. dnl be simply ignored by platform.
  215. _MHD_CHECK_POSIX2008([[mhd_mse_xopen_defines]],
  216. [[mhd_mse_xopen_flags]],
  217. [[${mhd_mse_sys_ext_defines}]],
  218. [mhd_mse_xopen_features="${mhd_cv_headers_posix2008}"],
  219. [
  220. _MHD_CHECK_POSIX2001([[mhd_mse_xopen_defines]],
  221. [[mhd_mse_xopen_flags]],
  222. [[${mhd_mse_sys_ext_defines}]],
  223. [mhd_mse_xopen_features="${mhd_cv_headers_posix2001}"],
  224. [
  225. _MHD_CHECK_SUSV2([[mhd_mse_xopen_defines]],
  226. [[mhd_mse_xopen_flags]],
  227. [[${mhd_mse_sys_ext_defines}]],
  228. [mhd_mse_xopen_features="${mhd_cv_headers_susv2}"],
  229. [mhd_mse_xopen_features="${mhd_cv_headers_susv2}"]
  230. )
  231. ]
  232. )
  233. ]
  234. )
  235. ]
  236. )
  237. AS_IF([[test "x${mhd_cv_macro__xopen_source_defined}" = "xno" && \
  238. test "x${mhd_cv_macro__xopen_source_def_fiveh}" = "xno" || \
  239. test "x${mhd_mse_xopen_features}" = "xnot available" ]],
  240. [
  241. _MHD_XOPEN_VAR_ADD([mhd_mse_xopen_defines], [mhd_mse_xopen_flags], [${mhd_mse_sys_ext_defines}])
  242. ]
  243. )
  244. mhd_mse_sys_features_src="
  245. #ifdef __APPLE__
  246. #include <sys/socket.h>
  247. #else
  248. #error No useful system features.
  249. choke me now;
  250. #endif
  251. int main()
  252. {
  253. #ifdef __APPLE__
  254. #ifndef sendfile
  255. (void) sendfile;
  256. #endif
  257. #endif
  258. return 0;
  259. }
  260. "
  261. AC_CACHE_CHECK([[for useful system-specific features]],
  262. [[mhd_cv_headers_useful_features_present]], [dnl
  263. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  264. ${mhd_mse_sys_ext_defines}
  265. ${mhd_mse_sys_features_src}
  266. ]])],
  267. [[mhd_cv_headers_useful_features_present="yes"]],
  268. [[mhd_cv_headers_useful_features_present="no"]]
  269. )dnl
  270. ])
  271. AS_VAR_IF([[mhd_cv_headers_useful_features_present]], [["yes"]],
  272. [
  273. AS_IF([[test "x${mhd_mse_xopen_flags}" = "x"]], [[:]],
  274. [
  275. AC_CACHE_CHECK([[whether useful system-specific features works with ${mhd_mse_xopen_flags}]],
  276. [[mhd_cv_headers_useful_features_works_xopen]], [dnl
  277. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  278. ${mhd_mse_sys_ext_defines}
  279. ${mhd_mse_xopen_defines}
  280. ${mhd_mse_sys_features_src}
  281. ]])],
  282. [[mhd_cv_headers_useful_features_works_xopen="yes"]],
  283. [[mhd_cv_headers_useful_features_works_xopen="no"]]
  284. )dnl
  285. ])dnl
  286. ]
  287. )dnl
  288. ]
  289. )
  290. AS_IF([[test "x${mhd_cv_headers_useful_features_present}" = "xyes" && \
  291. test "x${mhd_cv_headers_useful_features_works_xopen}" = "xno" && \
  292. test "x${mhd_mse_xopen_flags}" != "x"]],
  293. [
  294. _MHD_VAR_CONTAIN([[mhd_mse_xopen_features]], [[, activated by _XOPEN_SOURCE]],
  295. [
  296. AC_MSG_WARN([[_XOPEN_SOURCE macro is required to activate all headers symbols, however some useful system-specific features does not work with _XOPEN_SOURCE. ]dnl
  297. [_XOPEN_SOURCE macro will not be used.]])
  298. ]
  299. )
  300. AS_UNSET([[mhd_mse_xopen_defines]])
  301. AS_UNSET([[mhd_mse_xopen_flags]])
  302. AS_UNSET([[mhd_mse_xopen_values]])
  303. ]
  304. )
  305. dnl Discard temporal source variables
  306. AS_UNSET([[mhd_mse_sys_features_src]])
  307. AS_UNSET([[mhd_mse_xopen_defines]])
  308. AS_UNSET([[mhd_mse_sys_ext_defines]])
  309. dnl Determined all required defines.
  310. AC_MSG_CHECKING([[for final set of defined symbols]])
  311. m4_ifblank([$1], [dnl
  312. AH_TEMPLATE([[_XOPEN_SOURCE]], [Define to maximum value supported by system headers])dnl
  313. AH_TEMPLATE([[_XOPEN_SOURCE_EXTENDED]], [Define to 1 if _XOPEN_SOURCE is defined to value less than 500 ]dnl
  314. [and system headers requre this symbol])dnl
  315. AH_TEMPLATE([[_XOPEN_VERSION]], [Define to maximum value supported by system headers if _XOPEN_SOURCE ]dnl
  316. [is defined to value less than 500 and headers do not support _XOPEN_SOURCE_EXTENDED])dnl
  317. AH_TEMPLATE([[_GNU_SOURCE]], [Define to 1 to enable GNU-related header features])dnl
  318. AH_TEMPLATE([[__BSD_VISIBLE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  319. AH_TEMPLATE([[_DARWIN_C_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  320. AH_TEMPLATE([[__EXTENSIONS__]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  321. AH_TEMPLATE([[_NETBSD_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  322. AH_TEMPLATE([[_BSD_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  323. AH_TEMPLATE([[_TANDEM_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  324. AH_TEMPLATE([[_ALL_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  325. ])
  326. for mhd_mse_Flag in ${mhd_mse_sys_ext_flags} ${mhd_mse_xopen_flags}
  327. do
  328. m4_ifnblank([$1], [dnl
  329. AS_VAR_APPEND([$1],[[" -D$mhd_mse_Flag"]])
  330. ], [dnl
  331. AS_CASE([[$mhd_mse_Flag]], [[*=*]],
  332. [dnl
  333. AC_DEFINE_UNQUOTED([[`echo $mhd_mse_Flag | cut -f 1 -d =`]],
  334. [[`echo $mhd_mse_Flag | cut -f 2 -d = -s`]])
  335. ], [dnl
  336. AC_DEFINE_UNQUOTED([[$mhd_mse_Flag]])
  337. ])
  338. ])
  339. done
  340. AS_UNSET([[mhd_mse_Flag]])
  341. dnl Trim whitespaces
  342. mhd_mse_result=`echo ${mhd_mse_sys_ext_flags} ${mhd_mse_xopen_flags}`
  343. AC_MSG_RESULT([[${mhd_mse_result}]])
  344. AS_UNSET([[mhd_mse_result]])
  345. AS_UNSET([[mhd_mse_xopen_flags]])
  346. AS_UNSET([[mhd_mse_sys_ext_flags]])
  347. AC_LANG_POP([C])
  348. ])
  349. #
  350. # _MHD_SYS_EXT_VAR_ADD_FLAG(DEFINES_VAR, FLAGS_VAR,
  351. # FLAG, [FLAG-VALUE = 1])
  352. #
  353. # Internal macro, only to be used from MHD_SYS_EXT, _MHD_XOPEN_VAR_ADD
  354. m4_define([_MHD_SYS_EXT_VAR_ADD_FLAG], [dnl
  355. m4_ifnblank([$4],[dnl
  356. ]m4_normalize([$1])[="[$]{]m4_normalize([$1])[}[#define ]m4_normalize($3) ]m4_normalize([$4])[
  357. "
  358. AS_IF([test "x[$]{]m4_normalize([$2])[}" = "x"],
  359. []m4_normalize([$2])[="]m4_normalize([$3])[=]m4_normalize([$4])["],
  360. []m4_normalize([$2])[="[$]{]m4_normalize([$2])[} ]m4_normalize([$3])[=]m4_normalize([$4])["]
  361. )dnl
  362. ], [dnl
  363. ]m4_normalize([$1])[="[$]{]m4_normalize([$1])[}[#define ]m4_normalize($3) 1
  364. "
  365. AS_IF([test "x[$]{]m4_normalize([$2])[}" = "x"],
  366. []m4_normalize([$2])[="]m4_normalize([$3])["],
  367. []m4_normalize([$2])[="[$]{]m4_normalize([$2])[} ]m4_normalize([$3])["]
  368. )dnl
  369. ])dnl
  370. ])
  371. #
  372. # _MHD_VAR_IF(VAR, VALUE, [IF-EQ], [IF-NOT-EQ])
  373. #
  374. # Same as AS_VAR_IF, except that it expands to nothing if
  375. # both IF-EQ and IF-NOT-EQ are empty.
  376. m4_define([_MHD_VAR_IF],[dnl
  377. m4_ifnblank([$3$4],[dnl
  378. AS_VAR_IF([$1],[$2],[$3],[$4])])])
  379. #
  380. # _MHD_STRING_CONTAIN(VAR, MATCH, [IF-MATCH], [IF-NOT-MATCH])
  381. #
  382. AC_DEFUN([_MHD_VAR_CONTAIN],[dnl
  383. AC_REQUIRE([AC_PROG_FGREP])dnl
  384. AS_IF([[`echo "${]$1[}" | $FGREP ']$2[' >/dev/null 2>&1`]], [$3], [$4])
  385. ])
  386. #
  387. # _MHD_STRING_CONTAIN_BRE(VAR, BRE, [IF-MATCH], [IF-NOT-MATCH])
  388. #
  389. AC_DEFUN([_MHD_VAR_CONTAIN_BRE],[dnl
  390. AC_REQUIRE([AC_PROG_GREP])dnl
  391. AS_IF([[`echo "${]$1[}" | $GREP ']$2[' >/dev/null 2>&1`]], [$3], [$4])
  392. ])
  393. # SYNOPSIS
  394. #
  395. # _MHD_CHECK_POSIX2008(DEFINES_VAR, FLAGS_VAR,
  396. # [EXT_DEFINES],
  397. # [ACTION-IF-AVAILABLE],
  398. # [ACTION-IF-NOT-AVAILABLE])
  399. #
  400. #
  401. AC_DEFUN([_MHD_CHECK_POSIX2008], [dnl
  402. AC_CACHE_CHECK([headers for POSIX.1-2008/SUSv4 features],
  403. [[mhd_cv_headers_posix2008]], [dnl
  404. _MHD_CHECK_POSIX_FEATURES_SINGLE([
  405. _MHD_BASIC_INCLUDES
  406. [
  407. /* Check will be passed if ALL features are avalable
  408. * and failed if ANY feature is not avalable. */
  409. int main()
  410. {
  411. #ifndef stpncpy
  412. (void) stpncpy;
  413. #endif
  414. #ifndef strnlen
  415. (void) strnlen;
  416. #endif
  417. #if !defined(__NetBSD__) && !defined(__OpenBSD__)
  418. /* NetBSD and OpenBSD didn't implement wcsnlen() for some reason. */
  419. #ifndef wcsnlen
  420. (void) wcsnlen;
  421. #endif
  422. #endif
  423. #ifdef __CYGWIN__
  424. /* The only depend function on Cygwin, but missing on some other platforms */
  425. #ifndef strndup
  426. (void) strndup;
  427. #endif
  428. #endif
  429. #ifndef __sun
  430. /* illumos forget to uncomment some _XPG7 macros. */
  431. #ifndef renameat
  432. (void) renameat;
  433. #endif
  434. #ifndef getline
  435. (void) getline;
  436. #endif
  437. #endif /* ! __sun */
  438. /* gmtime_r() becomes mandatory only in POSIX.1-2008. */
  439. #ifndef gmtime_r
  440. (void) gmtime_r;
  441. #endif
  442. /* unsetenv() actually defined in POSIX.1-2001 so it
  443. * must be present with _XOPEN_SOURCE == 700 too. */
  444. #ifndef unsetenv
  445. (void) unsetenv;
  446. #endif
  447. return 0;
  448. }
  449. ]],
  450. [$3], [[700]],
  451. [[mhd_cv_headers_posix2008]]dnl
  452. )
  453. ]
  454. )
  455. _MHD_VAR_CONTAIN_BRE([[mhd_cv_headers_posix2008]], [[^available]],
  456. [
  457. _MHD_VAR_CONTAIN([[mhd_cv_headers_posix2008]], [[does not work with _XOPEN_SOURCE]], [[:]],
  458. [_MHD_SYS_EXT_VAR_ADD_FLAG([$1],[$2],[[_XOPEN_SOURCE]],[[700]])]
  459. )
  460. $4
  461. ],
  462. [$5]
  463. )
  464. ])
  465. # SYNOPSIS
  466. #
  467. # _MHD_CHECK_POSIX2001(DEFINES_VAR, FLAGS_VAR,
  468. # [EXT_DEFINES],
  469. # [ACTION-IF-AVAILABLE],
  470. # [ACTION-IF-NOT-AVAILABLE])
  471. #
  472. #
  473. AC_DEFUN([_MHD_CHECK_POSIX2001], [dnl
  474. AC_CACHE_CHECK([headers for POSIX.1-2001/SUSv3 features],
  475. [[mhd_cv_headers_posix2001]], [
  476. _MHD_CHECK_POSIX_FEATURES_SINGLE([
  477. _MHD_BASIC_INCLUDES
  478. [
  479. /* Check will be passed if ALL features are available
  480. * and failed if ANY feature is not available. */
  481. int main()
  482. {
  483. #ifndef setenv
  484. (void) setenv;
  485. #endif
  486. #ifndef __NetBSD__
  487. #ifndef vsscanf
  488. (void) vsscanf;
  489. #endif
  490. #endif
  491. /* Availability of next features varies, but they all must be present
  492. * on platform with support for _XOPEN_SOURCE = 600. */
  493. /* vsnprintf() should be available with _XOPEN_SOURCE >= 500, but some platforms
  494. * provide it only with _POSIX_C_SOURCE >= 200112 (autodefined when
  495. * _XOPEN_SOURCE >= 600) where specification of vsnprintf() is aligned with
  496. * ISO C99 while others platforms defined it with even earlier standards. */
  497. #ifndef vsnprintf
  498. (void) vsnprintf;
  499. #endif
  500. /* On platforms that prefer POSIX over X/Open, fseeko() is available
  501. * with _POSIX_C_SOURCE >= 200112 (autodefined when _XOPEN_SOURCE >= 600).
  502. * On other platforms it should be available with _XOPEN_SOURCE >= 500. */
  503. #ifndef fseeko
  504. (void) fseeko;
  505. #endif
  506. /* F_GETOWN must be defined with _XOPEN_SOURCE >= 600, but some platforms
  507. * define it with _XOPEN_SOURCE >= 500. */
  508. #ifndef F_GETOWN
  509. #error F_GETOWN is not defined
  510. choke me now;
  511. #endif
  512. return 0;
  513. }
  514. ]],
  515. [$3],[[600]],[[mhd_cv_headers_posix2001]]dnl
  516. )
  517. ]
  518. )
  519. _MHD_VAR_CONTAIN_BRE([[mhd_cv_headers_posix2001]], [[^available]],
  520. [
  521. _MHD_VAR_CONTAIN([[mhd_cv_headers_posix2001]], [[does not work with _XOPEN_SOURCE]], [[:]],
  522. [_MHD_SYS_EXT_VAR_ADD_FLAG([$1],[$2],[[_XOPEN_SOURCE]],[[600]])]
  523. )
  524. $4
  525. ],
  526. [$5]
  527. )
  528. ])
  529. # SYNOPSIS
  530. #
  531. # _MHD_CHECK_SUSV2(DEFINES_VAR, FLAGS_VAR,
  532. # [EXT_DEFINES],
  533. # [ACTION-IF-AVAILABLE],
  534. # [ACTION-IF-NOT-AVAILABLE])
  535. #
  536. #
  537. AC_DEFUN([_MHD_CHECK_SUSV2], [dnl
  538. AC_CACHE_CHECK([headers for SUSv2/XPG5 features],
  539. [[mhd_cv_headers_susv2]], [
  540. _MHD_CHECK_POSIX_FEATURES_SINGLE([
  541. _MHD_BASIC_INCLUDES
  542. [
  543. /* Check will be passed if ALL features are available
  544. * and failed if ANY feature is not available. */
  545. int main()
  546. {
  547. /* It's not easy to write reliable test for _XOPEN_SOURCE = 500 as
  548. * platforms not always precisely follow this standard and some
  549. * functions are already deprecated in later standards. */
  550. /* Availability of next features varies, but they all must be present
  551. * on platform with correct support for _XOPEN_SOURCE = 500. */
  552. /* Mandatory with _XOPEN_SOURCE >= 500 but as XSI extension available
  553. * with much older standards. */
  554. #ifndef ftruncate
  555. (void) ftruncate;
  556. #endif
  557. /* Added with _XOPEN_SOURCE >= 500 but was available in some standards
  558. * before. XSI extension. */
  559. #ifndef pread
  560. (void) pread;
  561. #endif
  562. #ifndef __APPLE__
  563. /* Actually comes from XPG4v2 and must be available
  564. * with _XOPEN_SOURCE >= 500 as well. */
  565. #ifndef symlink
  566. (void) symlink;
  567. #endif
  568. /* Actually comes from XPG4v2 and must be available
  569. * with _XOPEN_SOURCE >= 500 as well. XSI extension. */
  570. #ifndef strdup
  571. (void) strdup;
  572. #endif
  573. #endif /* ! __APPLE__ */
  574. return 0;
  575. }
  576. ]],
  577. [$3],[[500]],[[mhd_cv_headers_susv2]]dnl
  578. )
  579. ]
  580. )
  581. _MHD_VAR_CONTAIN_BRE([[mhd_cv_headers_susv2]], [[^available]],
  582. [
  583. _MHD_VAR_CONTAIN([[mhd_cv_headers_susv2]], [[does not work with _XOPEN_SOURCE]], [[:]],
  584. [_MHD_SYS_EXT_VAR_ADD_FLAG([$1],[$2],[[_XOPEN_SOURCE]],[[500]])]
  585. )
  586. $4
  587. ],
  588. [$5]
  589. )
  590. ])
  591. # SYNOPSIS
  592. #
  593. # _MHD_CHECK_POSIX_FEATURES_SINGLE(FEATURES_TEST,
  594. # EXT_DEFINES,
  595. # _XOPEN_SOURCE-VALUE,
  596. # VAR-RESULT)
  597. AC_DEFUN([_MHD_CHECK_POSIX_FEATURES_SINGLE], [dnl
  598. AS_VAR_PUSHDEF([avail_Var], [mhd_cpsxfs_tmp_features_available])dnl
  599. AS_VAR_PUSHDEF([ext_Var], [mhd_cpsxfs_tmp_extentions_allowed])dnl
  600. AS_VAR_PUSHDEF([xopen_Var], [mhd_cpsxfs_tmp_src_xopen_allowed])dnl
  601. AS_VAR_PUSHDEF([dislb_Var], [mhd_cpsxfs_tmp_features_disableable])dnl
  602. AS_UNSET([avail_Var])
  603. AS_UNSET([ext_Var])
  604. AS_UNSET([xopen_Var])
  605. AS_UNSET([dislb_Var])
  606. _MHD_CHECK_POSIX_FEATURES([$1], [$2], [$3], [avail_Var], [ext_Var], [xopen_Var], [dislb_Var])
  607. AS_VAR_IF([avail_Var], ["yes"],
  608. [
  609. AS_VAR_IF([dislb_Var], ["yes"],
  610. [
  611. AS_VAR_IF([ext_Var], ["required"],
  612. [
  613. AS_VAR_IF([xopen_Var], ["allowed"],
  614. [
  615. AS_VAR_SET(m4_normalize([$4]), ["available, activated by extension macro, works with _XOPEN_SOURCE=]m4_normalize([$3])["])
  616. ],
  617. [
  618. AS_VAR_SET(m4_normalize([$4]), ["available, activated by extension macro, does not work with _XOPEN_SOURCE=]m4_normalize([$3])["])
  619. ]
  620. )
  621. ],
  622. [
  623. AS_VAR_IF([ext_Var], ["allowed"],
  624. [
  625. AS_VAR_IF([xopen_Var], ["required"],
  626. [
  627. AS_VAR_SET(m4_normalize([$4]), ["available, activated by _XOPEN_SOURCE=]m4_normalize([$3])[, works with extension macro"])
  628. ],
  629. [
  630. AS_VAR_IF([xopen_Var], ["allowed"],
  631. [
  632. AS_VAR_SET(m4_normalize([$4]), ["available, works with _XOPEN_SOURCE=]m4_normalize([$3])[, works with extension macro"])
  633. ],
  634. [
  635. AS_VAR_SET(m4_normalize([$4]), ["available, works with extension macro, does not work with _XOPEN_SOURCE=]m4_normalize([$3])["])
  636. ]
  637. )
  638. ]
  639. )
  640. ],
  641. [
  642. AS_VAR_IF([xopen_Var], ["required"],
  643. [
  644. AS_VAR_SET(m4_normalize([$4]), ["available, activated by _XOPEN_SOURCE=]m4_normalize([$3])[, does not work with extension macro"])
  645. ],
  646. [
  647. AS_VAR_IF([xopen_Var], ["allowed"],
  648. [
  649. AS_VAR_SET(m4_normalize([$4]), ["available, works with _XOPEN_SOURCE=]m4_normalize([$3])[, does not work with extension macro"])
  650. ],
  651. [
  652. AS_VAR_SET(m4_normalize([$4]), ["available, does not work with _XOPEN_SOURCE=]m4_normalize([$3])[, does not work with extension macro"])
  653. ]
  654. )
  655. ]
  656. )
  657. ]
  658. )
  659. ]
  660. )
  661. ],
  662. [
  663. AS_VAR_SET(m4_normalize([$4]), ["available, works always"])
  664. ]
  665. )
  666. ],
  667. [
  668. AS_VAR_SET(m4_normalize([$4]), ["not available"])
  669. ]
  670. )
  671. AS_UNSET([dislb_Var])
  672. AS_UNSET([xopen_Var])
  673. AS_UNSET([ext_Var])
  674. AS_UNSET([avail_Var])
  675. AS_VAR_POPDEF([dislb_Var])dnl
  676. AS_VAR_POPDEF([xopen_Var])dnl
  677. AS_VAR_POPDEF([ext_Var])dnl
  678. AS_VAR_POPDEF([avail_Var])dnl
  679. ])
  680. # SYNOPSIS
  681. #
  682. # _MHD_CHECK_POSIX_FEATURES(FEATURES_TEST, EXT_DEFINES, _XOPEN_SOURCE-VALUE,
  683. # [VAR-FEATURES-AVAILABLE-YES_NO],
  684. # [VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED],
  685. # [VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED],
  686. # [VAR-FEATURES-DISABLEABLE-YES_NO])
  687. AC_DEFUN([_MHD_CHECK_POSIX_FEATURES], [dnl
  688. AS_VAR_PUSHDEF([src_Var], [mhd_cpsxf_tmp_src_variable])dnl
  689. AS_VAR_PUSHDEF([defs_Var], [mhd_cpsxf_tmp_defs_variable])dnl
  690. AS_VAR_SET([src_Var],["
  691. $1
  692. "])
  693. dnl To reduce 'configure' size
  694. AS_VAR_SET([defs_Var],["
  695. $2
  696. "])
  697. dnl To reduce 'configure' size
  698. dnl Some platforms enable most features when no
  699. dnl specific mode is requested by macro.
  700. dnl Check whether features test works without _XOPEN_SOURCE and
  701. dnl with disabled extensions (undefined most of
  702. dnl predefined macros for specific requested mode).
  703. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  704. _MHD_UNDEF_ALL_EXT
  705. $src_Var
  706. ])],
  707. [dnl
  708. _AS_ECHO_LOG([[Checked features work with undefined all extensions and without _XOPEN_SOURCE]])
  709. AS_VAR_SET(m4_normalize([$4]),["yes"]) # VAR-FEATURES-AVAILABLE-YES_NO
  710. dnl Check whether features will work extensions
  711. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  712. $defs_Var
  713. $src_Var
  714. ])],
  715. [dnl
  716. _AS_ECHO_LOG([[Checked features work with extensions]])
  717. AS_VAR_SET(m4_normalize([$5]),["allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  718. dnl Check whether features will work with _XOPEN_SOURCE
  719. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  720. $defs_Var
  721. [#define _XOPEN_SOURCE ]]m4_normalize([$3])[
  722. $src_Var
  723. ])],
  724. [dnl
  725. _AS_ECHO_LOG([Checked features work with extensions and with _XOPEN_SOURCE=]m4_normalize([$3])[])
  726. AS_VAR_SET(m4_normalize([$6]),["allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  727. dnl Check whether features could be disabled
  728. dnl Request oldest POSIX mode and strict ANSI mode
  729. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  730. _MHD_UNDEF_ALL_EXT
  731. [#define _POSIX_C_SOURCE 1]
  732. [#define _ANSI_SOURCE 1]
  733. $src_Var
  734. ])],
  735. [dnl
  736. _AS_ECHO_LOG([[Checked features work with disabled extensions, with _POSIX_C_SOURCE=1 and _ANSI_SOURCE=1]])
  737. AS_VAR_SET(m4_normalize([$7]),["no"]) # VAR-FEATURES-DISABLEABLE-YES_NO
  738. ],
  739. [dnl
  740. _AS_ECHO_LOG([[Checked features DO NOT work with disabled extensions, with _POSIX_C_SOURCE=1 and _ANSI_SOURCE=1]])
  741. AS_VAR_SET(m4_normalize([$7]),["yes"]) # VAR-FEATURES-DISABLEABLE-YES_NO
  742. ]
  743. )
  744. ],
  745. [dnl
  746. _AS_ECHO_LOG([Checked features DO NOT work with extensions and with _XOPEN_SOURCE=]m4_normalize([$3])[])
  747. AS_VAR_SET(m4_normalize([$6]),["not allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  748. AS_VAR_SET(m4_normalize([$7]),["yes"]) # VAR-FEATURES-DISABLEABLE-YES_NO
  749. ]
  750. )
  751. ],
  752. [dnl
  753. _AS_ECHO_LOG([[Checked features DO NOT work with extensions]])
  754. AS_VAR_SET(m4_normalize([$7]),["yes"]) # VAR-FEATURES-DISABLEABLE-YES_NO
  755. dnl Check whether features work with _XOPEN_SOURCE
  756. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  757. [#define _XOPEN_SOURCE ]m4_normalize($3)
  758. $src_Var
  759. ])],
  760. [dnl
  761. _AS_ECHO_LOG([Checked features work with _XOPEN_SOURCE=]m4_normalize([$3])[])
  762. dnl Check default state (without enabling/disabling)
  763. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  764. $src_Var
  765. ])],
  766. [dnl
  767. _AS_ECHO_LOG([[Checked features work by default]])
  768. AS_VAR_SET(m4_normalize([$6]),["allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  769. ],
  770. [dnl
  771. _AS_ECHO_LOG([[Checked features DO NOT by default]])
  772. AS_VAR_SET(m4_normalize([$6]),["required"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  773. ]
  774. )
  775. dnl Check whether features work with _XOPEN_SOURCE and extensions
  776. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  777. $defs_Var
  778. [#define _XOPEN_SOURCE] ]m4_normalize([$3])[
  779. $src_Var
  780. ])],
  781. [dnl
  782. _AS_ECHO_LOG([[Checked features work with _XOPEN_SOURCE and extensions]])
  783. AS_VAR_SET(m4_normalize([$5]),["allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  784. ],
  785. [dnl
  786. _AS_ECHO_LOG([[Checked features DO NOT work with _XOPEN_SOURCE and extensions]])
  787. AS_VAR_SET(m4_normalize([$5]),["not allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  788. ]
  789. )
  790. ],
  791. [dnl
  792. _AS_ECHO_LOG([Checked features DO NOT work with _XOPEN_SOURCE=]m4_normalize([$3])[])
  793. AS_VAR_SET(m4_normalize([$5]),["not allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  794. AS_VAR_SET(m4_normalize([$6]),["not allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  795. ]
  796. )
  797. ]
  798. )
  799. ],
  800. [dnl
  801. _AS_ECHO_LOG([[Checked features DO NOT work with undefined all extensions and without _XOPEN_SOURCE]])
  802. dnl Let's find the way to enable POSIX features
  803. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  804. $defs_Var
  805. $src_Var
  806. ])],
  807. [dnl
  808. _AS_ECHO_LOG([[Checked features work with extensions]])
  809. AS_VAR_SET(m4_normalize([$4]),["yes"]) # VAR-FEATURES-AVAILABLE-YES_NO
  810. AS_VAR_SET(m4_normalize([$7]),["yes"]) # VAR-FEATURES-DISABLEABLE-YES_NO
  811. dnl Check default state (without enabling/disabling)
  812. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  813. $src_Var
  814. ])],
  815. [dnl
  816. _AS_ECHO_LOG([[Checked features work by default]])
  817. AS_VAR_SET(m4_normalize([$5]),["allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  818. ],
  819. [dnl
  820. _AS_ECHO_LOG([[Checked features DO NOT by default]])
  821. AS_VAR_SET(m4_normalize([$5]),["required"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  822. ]
  823. )
  824. dnl Check whether features work with extensions and _XOPEN_SOURCE
  825. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  826. $defs_Var
  827. [#define _XOPEN_SOURCE] ]m4_normalize([$3])[
  828. $src_Var
  829. ])],
  830. [dnl
  831. _AS_ECHO_LOG([Checked features work with extensions and _XOPEN_SOURCE=]m4_normalize([$3])[])
  832. AS_VAR_SET(m4_normalize([$6]),["allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  833. ],
  834. [dnl
  835. _AS_ECHO_LOG([Checked features DO NOT work with extensions and _XOPEN_SOURCE=]m4_normalize([$3])[])
  836. AS_VAR_SET(m4_normalize([$6]),["not allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  837. ]
  838. )
  839. ],
  840. [dnl
  841. _AS_ECHO_LOG([[Checked features DO NOT work with extensions]])
  842. dnl Check whether features work with _XOPEN_SOURCE
  843. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  844. [#define _XOPEN_SOURCE] ]m4_normalize([$3])[
  845. $src_Var
  846. ])],
  847. [dnl
  848. _AS_ECHO_LOG([Checked features work with _XOPEN_SOURCE=]m4_normalize([$3])[])
  849. AS_VAR_SET(m4_normalize([$4]),["yes"]) # VAR-FEATURES-AVAILABLE-YES_NO
  850. dnl Check default state (without enabling/disabling)
  851. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  852. $src_Var
  853. ])],
  854. [dnl
  855. _AS_ECHO_LOG([[Checked features work by default]])
  856. AS_VAR_SET(m4_normalize([$6]),["allowed"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  857. ],
  858. [dnl
  859. _AS_ECHO_LOG([[Checked features DO NOT by default]])
  860. AS_VAR_SET(m4_normalize([$6]),["required"]) # VAR-XOPEN-REQUIRED_NOT-ALLOWED_ALLOWED
  861. ]
  862. )
  863. dnl Check whether features work with _XOPEN_SOURCE and extensions
  864. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  865. $defs_Var
  866. [#define _XOPEN_SOURCE] ]m4_normalize([$3])[
  867. $src_Var
  868. ])],
  869. [dnl
  870. _AS_ECHO_LOG([Checked features work with _XOPEN_SOURCE=]m4_normalize([$3])[ and extensions])
  871. AS_VAR_SET(m4_normalize([$5]),["allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  872. ],
  873. [dnl
  874. _AS_ECHO_LOG([Checked features DO NOT work with _XOPEN_SOURCE=]m4_normalize([$3])[ and extensions])
  875. AS_VAR_SET(m4_normalize([$5]),["not allowed"]) # VAR-EXTENSIONS-REQUIRED_NOT-ALLOWED_ALLOWED
  876. ]
  877. )
  878. ],
  879. [dnl
  880. _AS_ECHO_LOG([Checked features DO NOT work with _XOPEN_SOURCE=]m4_normalize([$3])[])
  881. AS_VAR_SET(m4_normalize([$4]),["no"]) # VAR-FEATURES-AVAILABLE-YES_NO
  882. ]
  883. )
  884. ]
  885. )
  886. ]
  887. )
  888. AS_UNSET([defs_Var])
  889. AS_UNSET([src_Var])
  890. AS_VAR_POPDEF([defs_Var])dnl
  891. AS_VAR_POPDEF([src_Var])dnl
  892. ])
  893. #
  894. # MHD_CHECK_HEADER_PRESENCE(headername.h)
  895. #
  896. # Check only by preprocessor whether header file is present.
  897. AC_DEFUN([MHD_CHECK_HEADER_PRESENCE], [dnl
  898. AC_PREREQ([2.64])dnl for AS_VAR_PUSHDEF, AS_VAR_SET
  899. AS_VAR_PUSHDEF([mhd_cache_Var],[mhd_cv_header_[]$1[]_present])dnl
  900. AC_CACHE_CHECK([for presence of $1], [mhd_cache_Var], [dnl
  901. dnl Hack autoconf to get pure result of only single header presence
  902. cat > conftest.$ac_ext <<_ACEOF
  903. @%:@include <[]$1[]>
  904. _ACEOF
  905. AC_PREPROC_IFELSE([],
  906. [AS_VAR_SET([mhd_cache_Var],[["yes"]])],
  907. [AS_VAR_SET([mhd_cache_Var],[["no"]])]
  908. )
  909. rm -f conftest.$ac_ext
  910. ])
  911. AS_VAR_POPDEF([mhd_cache_Var])dnl
  912. ])
  913. #
  914. # MHD_CHECK_HEADERS_PRESENCE(oneheader.h otherheader.h ...)
  915. #
  916. # Check each specified header in whitespace-separated list for presence.
  917. AC_DEFUN([MHD_CHECK_HEADERS_PRESENCE], [dnl
  918. AC_PREREQ([2.60])dnl for m4_foreach_w
  919. m4_foreach_w([mhd_chk_Header], [$1],
  920. [MHD_CHECK_HEADER_PRESENCE(m4_defn([mhd_chk_Header]))]
  921. )dnl
  922. ])
  923. #
  924. # MHD_CHECK_HEADERS_PRESENCE_COMPACT(oneheader.h otherheader.h ...)
  925. #
  926. # Same as MHD_CHECK_HEADERS_PRESENCE, but a bit slower and produce more compact 'configure'.
  927. AC_DEFUN([MHD_CHECK_HEADERS_PRESENCE_COMPACT], [dnl
  928. for mhd_chk_Header in $1 ; do
  929. MHD_CHECK_HEADER_PRESENCE([[${mhd_chk_Header}]])
  930. done
  931. ])
  932. #
  933. # MHD_CHECK_BASIC_HEADERS_PRESENCE
  934. #
  935. # Check basic headers for presence.
  936. AC_DEFUN([MHD_CHECK_BASIC_HEADERS_PRESENCE], [dnl
  937. MHD_CHECK_HEADERS_PRESENCE([stdio.h wchar.h stdlib.h string.h strings.h stdint.h fcntl.h sys/types.h time.h unistd.h])
  938. ])
  939. #
  940. # _MHD_SET_BASIC_INCLUDES
  941. #
  942. # Internal preparatory macro.
  943. AC_DEFUN([_MHD_SET_BASIC_INCLUDES], [dnl
  944. AC_REQUIRE([MHD_CHECK_BASIC_HEADERS_PRESENCE])dnl
  945. AS_IF([[test -z "$mhd_basic_headers_includes"]], [dnl
  946. AS_VAR_IF([mhd_cv_header_stdio_h_present], [["yes"]],
  947. [[mhd_basic_headers_includes="\
  948. #include <stdio.h>
  949. " ]],[[mhd_basic_headers_includes=""]]
  950. )
  951. AS_VAR_IF([mhd_cv_header_sys_types_h_present], [["yes"]],
  952. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  953. #include <sys/types.h>
  954. " ]]
  955. )
  956. AS_VAR_IF([mhd_cv_header_wchar_h_present], [["yes"]],
  957. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  958. #include <wchar.h>
  959. " ]]
  960. )
  961. AS_VAR_IF([mhd_cv_header_stdlib_h_present], [["yes"]],
  962. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  963. #include <stdlib.h>
  964. " ]]
  965. )
  966. AS_VAR_IF([mhd_cv_header_string_h_present], [["yes"]],
  967. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  968. #include <string.h>
  969. " ]]
  970. )
  971. AS_VAR_IF([mhd_cv_header_strings_h_present], [["yes"]],
  972. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  973. #include <strings.h>
  974. " ]]
  975. )
  976. AS_VAR_IF([mhd_cv_header_stdint_h_present], [["yes"]],
  977. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  978. #include <stdint.h>
  979. " ]]
  980. )
  981. AS_VAR_IF([mhd_cv_header_fcntl_h_present], [["yes"]],
  982. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  983. #include <fcntl.h>
  984. " ]]
  985. )
  986. AS_VAR_IF([mhd_cv_header_time_h_present], [["yes"]],
  987. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  988. #include <time.h>
  989. " ]]
  990. )
  991. AS_VAR_IF([mhd_cv_header_unistd_h_present], [["yes"]],
  992. [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
  993. #include <unistd.h>
  994. " ]]
  995. )
  996. ])dnl
  997. ])
  998. #
  999. # _MHD_BASIC_INCLUDES
  1000. #
  1001. # Internal macro. Output set of basic includes.
  1002. AC_DEFUN([_MHD_BASIC_INCLUDES], [AC_REQUIRE([_MHD_SET_BASIC_INCLUDES])dnl
  1003. [ /* Start of MHD basic test includes */
  1004. $mhd_basic_headers_includes /* End of MHD basic test includes */
  1005. ]])
  1006. #
  1007. # MHD_CHECK_BASIC_HEADERS([PROLOG], [ACTION-IF-OK], [ACTION-IF-FAIL])
  1008. #
  1009. # Check whether basic headers can be compiled with specified prolog.
  1010. AC_DEFUN([MHD_CHECK_BASIC_HEADERS], [dnl
  1011. AC_COMPILE_IFELSE([dnl
  1012. AC_LANG_PROGRAM([m4_n([$1])dnl
  1013. _MHD_BASIC_INCLUDES
  1014. ], [[int i = 1; i++; if(i) return i]])
  1015. ], [$2], [$3])
  1016. ])
  1017. #
  1018. # _MHD_SET_UNDEF_ALL_EXT
  1019. #
  1020. # Internal preparatory macro.
  1021. AC_DEFUN([_MHD_SET_UNDEF_ALL_EXT], [m4_divert_text([INIT_PREPARE],[dnl
  1022. [mhd_undef_all_extensions="
  1023. #ifdef _GNU_SOURCE
  1024. #undef _GNU_SOURCE
  1025. #endif
  1026. #ifdef _XOPEN_SOURCE
  1027. #undef _XOPEN_SOURCE
  1028. #endif
  1029. #ifdef _XOPEN_SOURCE_EXTENDED
  1030. #undef _XOPEN_SOURCE_EXTENDED
  1031. #endif
  1032. #ifdef _XOPEN_VERSION
  1033. #undef _XOPEN_VERSION
  1034. #endif
  1035. #ifdef _POSIX_C_SOURCE
  1036. #undef _POSIX_C_SOURCE
  1037. #endif
  1038. #ifdef _POSIX_SOURCE
  1039. #undef _POSIX_SOURCE
  1040. #endif
  1041. #ifdef _DEFAULT_SOURCE
  1042. #undef _DEFAULT_SOURCE
  1043. #endif
  1044. #ifdef _BSD_SOURCE
  1045. #undef _BSD_SOURCE
  1046. #endif
  1047. #ifdef _SVID_SOURCE
  1048. #undef _SVID_SOURCE
  1049. #endif
  1050. #ifdef __EXTENSIONS__
  1051. #undef __EXTENSIONS__
  1052. #endif
  1053. #ifdef _ALL_SOURCE
  1054. #undef _ALL_SOURCE
  1055. #endif
  1056. #ifdef _TANDEM_SOURCE
  1057. #undef _TANDEM_SOURCE
  1058. #endif
  1059. #ifdef _DARWIN_C_SOURCE
  1060. #undef _DARWIN_C_SOURCE
  1061. #endif
  1062. #ifdef __BSD_VISIBLE
  1063. #undef __BSD_VISIBLE
  1064. #endif
  1065. #ifdef _NETBSD_SOURCE
  1066. #undef _NETBSD_SOURCE
  1067. #endif
  1068. "
  1069. ]])])
  1070. #
  1071. # _MHD_UNDEF_ALL_EXT
  1072. #
  1073. # Output prolog that undefine all known extension and visibility macros.
  1074. AC_DEFUN([_MHD_UNDEF_ALL_EXT], [dnl
  1075. AC_REQUIRE([_MHD_SET_UNDEF_ALL_EXT])dnl
  1076. $mhd_undef_all_extensions
  1077. ])
  1078. #
  1079. # _MHD_CHECK_DEFINED(SYMBOL, [PROLOG],
  1080. # [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED])
  1081. #
  1082. # Silently checks for defined symbols.
  1083. AC_DEFUN([_MHD_CHECK_DEFINED], [dnl
  1084. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  1085. m4_n([$2])dnl
  1086. [#ifndef ]$1[
  1087. #error ]$1[ is not defined
  1088. choke me now;
  1089. #endif
  1090. ]],[])
  1091. ], [m4_default_nblank([$3])], [m4_default_nblank([$4])]
  1092. )
  1093. ])
  1094. #
  1095. # MHD_CHECK_DEFINED(SYMBOL, [PROLOG],
  1096. # [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED],
  1097. # [MESSAGE])
  1098. #
  1099. # Cache-check for defined symbols with printing results.
  1100. AC_DEFUN([MHD_CHECK_DEFINED], [dnl
  1101. AS_VAR_PUSHDEF([mhd_cache_Var],[mhd_cv_macro_[]m4_tolower(m4_normalize($1))_defined])dnl
  1102. AC_CACHE_CHECK([dnl
  1103. m4_ifnblank([$5], [$5], [whether ]m4_normalize([$1])[ is already defined])],
  1104. [mhd_cache_Var], [dnl
  1105. _MHD_CHECK_DEFINED(m4_normalize([$1]), [$2],
  1106. [mhd_cache_Var="yes"],
  1107. [mhd_cache_Var="no"]
  1108. )
  1109. ])
  1110. _MHD_VAR_IF([mhd_cache_Var], [["yes"]], [$3], [$4])
  1111. AS_VAR_POPDEF([mhd_cache_Var])dnl
  1112. ])
  1113. #
  1114. # MHD_CHECK_DEFINED_MSG(SYMBOL, [PROLOG], [MESSAGE]
  1115. # [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED])
  1116. #
  1117. # Cache-check for defined symbols with printing results.
  1118. # Reordered arguments for better readability.
  1119. AC_DEFUN([MHD_CHECK_DEFINED_MSG],[dnl
  1120. MHD_CHECK_DEFINED([$1],[$2],[$4],[$5],[$3])])
  1121. #
  1122. # MHD_CHECK_ACCEPT_DEFINE(DEFINE-SYMBOL, [DEFINE-VALUE = 1], [PROLOG],
  1123. # [ACTION-IF-ACCEPTED], [ACTION-IF-NOT-ACCEPTED],
  1124. # [MESSAGE])
  1125. #
  1126. # Cache-check whether specific defined symbol do not break basic headers.
  1127. AC_DEFUN([MHD_CHECK_ACCEPT_DEFINE], [dnl
  1128. AC_PREREQ([2.64])dnl for AS_VAR_PUSHDEF, AS_VAR_SET, m4_ifnblank
  1129. AS_VAR_PUSHDEF([mhd_cache_Var],
  1130. [mhd_cv_define_[]m4_tolower(m4_normalize($1))[]_accepted[]m4_ifnblank([$2],[_[]$2])])dnl
  1131. AC_CACHE_CHECK([dnl
  1132. m4_ifnblank([$6],[$6],[whether headers accept $1[]m4_ifnblank([$2],[[ with value ]$2])])],
  1133. [mhd_cache_Var], [dnl
  1134. MHD_CHECK_BASIC_HEADERS([
  1135. m4_n([$3])[#define ]$1 m4_default_nblank($2,[[1]])],
  1136. [mhd_cache_Var="yes"], [mhd_cache_Var="no"]
  1137. )
  1138. ])
  1139. _MHD_VAR_IF([mhd_cache_Var], [["yes"]], [$4], [$5])
  1140. AS_VAR_POPDEF([mhd_cache_Var])dnl
  1141. ])
  1142. #
  1143. # MHD_CHECK_DEF_AND_ACCEPT(DEFINE-SYMBOL, [DEFINE-VALUE = 1], [PROLOG],
  1144. # [ACTION-IF-DEFINED],
  1145. # [ACTION-IF-ACCEPTED], [ACTION-IF-NOT-ACCEPTED])
  1146. #
  1147. # Combination of MHD_CHECK_DEFINED_ECHO and MHD_CHECK_ACCEPT_DEFINE.
  1148. # First check whether symbol is already defined and, if not defined,
  1149. # checks whether it can be defined.
  1150. AC_DEFUN([MHD_CHECK_DEF_AND_ACCEPT], [dnl
  1151. MHD_CHECK_DEFINED([$1], [$3], [$4], [dnl
  1152. MHD_CHECK_ACCEPT_DEFINE([$1], [$2], [$3], [$5], [$6])dnl
  1153. ])dnl
  1154. ])
  1155. #
  1156. # _MHD_XOPEN_VAR_ADD(DEFINES_VAR, FLAGS_VAR, [PROLOG])
  1157. #
  1158. # Internal macro. Only to be used in MHD_SYS_EXT.
  1159. AC_DEFUN([_MHD_XOPEN_VAR_ADD], [dnl
  1160. MHD_CHECK_DEF_AND_ACCEPT([[_XOPEN_SOURCE]], [[1]], [$3],
  1161. [
  1162. AC_CACHE_CHECK([[whether predefined value of _XOPEN_SOURCE is more or equal 500]],
  1163. [[mhd_cv_macro__xopen_source_def_fiveh]], [dnl
  1164. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  1165. m4_n([$3])dnl
  1166. [#if _XOPEN_SOURCE+0 < 500
  1167. #error Value of _XOPEN_SOURCE is less than 500
  1168. choke me now;
  1169. #endif
  1170. ]],[[int i = 0; i++; if(i) return i]])],
  1171. [[mhd_cv_macro__xopen_source_def_fiveh="yes"]],
  1172. [[mhd_cv_macro__xopen_source_def_fiveh="no"]]
  1173. )dnl
  1174. ]
  1175. )dnl
  1176. ],
  1177. [_MHD_SYS_EXT_VAR_ADD_FLAG([$1], [$2], [[_XOPEN_SOURCE]], [[1]])]
  1178. )
  1179. AS_IF([[test "x${mhd_cv_define__xopen_source_accepted_1}" = "xyes" || \
  1180. test "x${mhd_cv_macro__xopen_source_def_fiveh}" = "xno"]],
  1181. [
  1182. MHD_CHECK_DEF_AND_ACCEPT([[_XOPEN_SOURCE_EXTENDED]], [],
  1183. [
  1184. m4_n([$3])], [],
  1185. [dnl
  1186. _MHD_SYS_EXT_VAR_ADD_FLAG([$1],[$2],[[_XOPEN_SOURCE_EXTENDED]])
  1187. ], [dnl
  1188. MHD_CHECK_DEFINED([[_XOPEN_VERSION]],
  1189. [
  1190. m4_n([$3])], [],
  1191. [dnl
  1192. AC_CACHE_CHECK([[for value of _XOPEN_VERSION accepted by headers]],
  1193. [mhd_cv_define__xopen_version_accepted], [dnl
  1194. MHD_CHECK_BASIC_HEADERS([
  1195. m4_n([$3])
  1196. [#define _XOPEN_VERSION 4]],
  1197. [[mhd_cv_define__xopen_version_accepted="4"]],
  1198. [
  1199. MHD_CHECK_BASIC_HEADERS([
  1200. m4_n([$3])
  1201. [#define _XOPEN_VERSION 3]],
  1202. [[mhd_cv_define__xopen_version_accepted="3"]],
  1203. [[mhd_cv_define__xopen_version_accepted="no"]]
  1204. )
  1205. ])
  1206. ])
  1207. AS_VAR_IF([mhd_cv_define__xopen_version_accepted], [["no"]],
  1208. [[:]],
  1209. [dnl
  1210. _MHD_SYS_EXT_VAR_ADD_FLAG([$1],[$2],[[_XOPEN_VERSION]],
  1211. [[${mhd_cv_define__xopen_version_accepted}]]dnl
  1212. )
  1213. ])
  1214. ])
  1215. ])
  1216. ]
  1217. )dnl
  1218. ])