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