gnulib-common.m4 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. # gnulib-common.m4 serial 76
  2. dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_PREREQ([2.62])
  7. # gl_COMMON
  8. # is expanded unconditionally through gnulib-tool magic.
  9. AC_DEFUN([gl_COMMON], [
  10. dnl Use AC_REQUIRE here, so that the code is expanded once only.
  11. AC_REQUIRE([gl_00GNULIB])
  12. AC_REQUIRE([gl_COMMON_BODY])
  13. AC_REQUIRE([gl_ZZGNULIB])
  14. ])
  15. AC_DEFUN([gl_COMMON_BODY], [
  16. AH_VERBATIM([_GL_GNUC_PREREQ],
  17. [/* True if the compiler says it groks GNU C version MAJOR.MINOR. */
  18. #if defined __GNUC__ && defined __GNUC_MINOR__
  19. # define _GL_GNUC_PREREQ(major, minor) \
  20. ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__))
  21. #else
  22. # define _GL_GNUC_PREREQ(major, minor) 0
  23. #endif
  24. ])
  25. AH_VERBATIM([_Noreturn],
  26. [/* The _Noreturn keyword of C11. */
  27. #ifndef _Noreturn
  28. # if (defined __cplusplus \
  29. && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
  30. || (defined _MSC_VER && 1900 <= _MSC_VER)) \
  31. && 0)
  32. /* [[noreturn]] is not practically usable, because with it the syntax
  33. extern _Noreturn void func (...);
  34. would not be valid; such a declaration would only be valid with 'extern'
  35. and '_Noreturn' swapped, or without the 'extern' keyword. However, some
  36. AIX system header files and several gnulib header files use precisely
  37. this syntax with 'extern'. */
  38. # define _Noreturn [[noreturn]]
  39. # elif ((!defined __cplusplus || defined __clang__) \
  40. && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
  41. || (!defined __STRICT_ANSI__ \
  42. && (_GL_GNUC_PREREQ (4, 7) \
  43. || (defined __apple_build_version__ \
  44. ? 6000000 <= __apple_build_version__ \
  45. : 3 < __clang_major__ + (5 <= __clang_minor__))))))
  46. /* _Noreturn works as-is. */
  47. # elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
  48. # define _Noreturn __attribute__ ((__noreturn__))
  49. # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
  50. # define _Noreturn __declspec (noreturn)
  51. # else
  52. # define _Noreturn
  53. # endif
  54. #endif
  55. ])
  56. AH_VERBATIM([isoc99_inline],
  57. [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
  58. the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
  59. earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
  60. __APPLE__ && __MACH__ test for Mac OS X.
  61. __APPLE_CC__ tests for the Apple compiler and its version.
  62. __STDC_VERSION__ tests for the C99 mode. */
  63. #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
  64. # define __GNUC_STDC_INLINE__ 1
  65. #endif])
  66. AH_VERBATIM([attribute],
  67. [/* Attributes. */
  68. #if (defined __has_attribute \
  69. && (!defined __clang_minor__ \
  70. || (defined __apple_build_version__ \
  71. ? 6000000 <= __apple_build_version__ \
  72. : 5 <= __clang_major__)))
  73. # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
  74. #else
  75. # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
  76. # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
  77. # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
  78. # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
  79. # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
  80. # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
  81. # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
  82. # define _GL_ATTR_diagnose_if 0
  83. # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
  84. # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
  85. # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
  86. # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
  87. # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
  88. # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
  89. # ifdef _ICC
  90. # define _GL_ATTR_may_alias 0
  91. # else
  92. # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
  93. # endif
  94. # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
  95. # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
  96. # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
  97. # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
  98. # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
  99. # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
  100. # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
  101. # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
  102. # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
  103. # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
  104. #endif
  105. /* Disable GCC -Wpedantic if using __has_c_attribute and this is not C23+. */
  106. #if (defined __has_c_attribute && _GL_GNUC_PREREQ (4, 6) \
  107. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)
  108. # pragma GCC diagnostic ignored "-Wpedantic"
  109. #endif
  110. ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's alignas instead.
  111. [
  112. /* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
  113. is the size of the returned memory block.
  114. _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
  115. by the Nth argument of the function is the size of the returned memory block.
  116. */
  117. /* Applies to: function, pointer to function, function types. */
  118. #if _GL_HAS_ATTRIBUTE (alloc_size)
  119. # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
  120. #else
  121. # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
  122. #endif
  123. /* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
  124. function and report an error if it cannot do so. */
  125. /* Applies to: function. */
  126. #if _GL_HAS_ATTRIBUTE (always_inline)
  127. # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
  128. #else
  129. # define _GL_ATTRIBUTE_ALWAYS_INLINE
  130. #endif
  131. /* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
  132. in stack traces when debugging. The compiler should omit the function from
  133. stack traces. */
  134. /* Applies to: function. */
  135. #if _GL_HAS_ATTRIBUTE (artificial)
  136. # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
  137. #else
  138. # define _GL_ATTRIBUTE_ARTIFICIAL
  139. #endif
  140. /* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
  141. /* Applies to: functions. */
  142. /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
  143. <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
  144. Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
  145. #if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
  146. # ifndef __SUNPRO_C
  147. # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
  148. # else
  149. # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
  150. # endif
  151. #else
  152. # define _GL_ATTRIBUTE_COLD
  153. #endif
  154. /* _GL_ATTRIBUTE_CONST declares that it is OK for a compiler to omit duplicate
  155. calls to the function with the same arguments.
  156. This attribute is safe for a function that neither depends on nor affects
  157. observable state, and always returns exactly once - e.g., does not loop
  158. forever, and does not call longjmp.
  159. (This attribute is stricter than _GL_ATTRIBUTE_PURE.) */
  160. /* Applies to: functions. */
  161. #if _GL_HAS_ATTRIBUTE (const)
  162. # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
  163. #else
  164. # define _GL_ATTRIBUTE_CONST
  165. #endif
  166. /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
  167. that can be freed by passing them as the Ith argument to the
  168. function F.
  169. _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
  170. can be freed via 'free'; it can be used only after declaring 'free'. */
  171. /* Applies to: functions. Cannot be used on inline functions. */
  172. #if _GL_GNUC_PREREQ (11, 0)
  173. # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
  174. #else
  175. # define _GL_ATTRIBUTE_DEALLOC(f, i)
  176. #endif
  177. /* If gnulib's <string.h> or <wchar.h> has already defined this macro, continue
  178. to use this earlier definition, since <stdlib.h> may not have been included
  179. yet. */
  180. #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
  181. # if defined __cplusplus && defined __GNUC__ && !defined __clang__
  182. /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
  183. # define _GL_ATTRIBUTE_DEALLOC_FREE \
  184. _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
  185. # else
  186. # define _GL_ATTRIBUTE_DEALLOC_FREE \
  187. _GL_ATTRIBUTE_DEALLOC (free, 1)
  188. # endif
  189. #endif
  190. /* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
  191. The compiler may warn if the entity is used. */
  192. /* Applies to:
  193. - function, variable,
  194. - struct, union, struct/union member,
  195. - enumeration, enumeration item,
  196. - typedef,
  197. in C++ also: namespace, class, template specialization. */
  198. #ifdef __has_c_attribute
  199. # if __has_c_attribute (__deprecated__)
  200. # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
  201. # endif
  202. #endif
  203. #if !defined _GL_ATTRIBUTE_DEPRECATED && _GL_HAS_ATTRIBUTE (deprecated)
  204. # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
  205. #endif
  206. #ifndef _GL_ATTRIBUTE_DEPRECATED
  207. # define _GL_ATTRIBUTE_DEPRECATED
  208. #endif
  209. /* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
  210. the function call is not optimized away.
  211. _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
  212. the function call is not optimized away. */
  213. /* Applies to: functions. */
  214. #if _GL_HAS_ATTRIBUTE (error)
  215. # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
  216. # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
  217. #elif _GL_HAS_ATTRIBUTE (diagnose_if)
  218. # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
  219. # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
  220. #else
  221. # define _GL_ATTRIBUTE_ERROR(msg)
  222. # define _GL_ATTRIBUTE_WARNING(msg)
  223. #endif
  224. /* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
  225. visible to debuggers etc., even with '-fwhole-program'. */
  226. /* Applies to: functions, variables. */
  227. #if _GL_HAS_ATTRIBUTE (externally_visible)
  228. # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
  229. #else
  230. # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
  231. #endif
  232. /* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
  233. the control flow falls through to the immediately following 'case' or
  234. 'default' label. The compiler should not warn in this case. */
  235. /* Applies to: Empty statement (;), inside a 'switch' statement. */
  236. /* Always expands to something. */
  237. #ifdef __has_c_attribute
  238. # if __has_c_attribute (__fallthrough__)
  239. # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
  240. # endif
  241. #endif
  242. #if !defined _GL_ATTRIBUTE_FALLTHROUGH && _GL_HAS_ATTRIBUTE (fallthrough)
  243. # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
  244. #endif
  245. #ifndef _GL_ATTRIBUTE_FALLTHROUGH
  246. # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
  247. #endif
  248. /* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
  249. declares that the STRING-INDEXth function argument is a format string of
  250. style ARCHETYPE, which is one of:
  251. printf, gnu_printf
  252. scanf, gnu_scanf,
  253. strftime, gnu_strftime,
  254. strfmon,
  255. or the same thing prefixed and suffixed with '__'.
  256. If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
  257. are suitable for the format string. */
  258. /* Applies to: functions. */
  259. #if _GL_HAS_ATTRIBUTE (format)
  260. # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
  261. #else
  262. # define _GL_ATTRIBUTE_FORMAT(spec)
  263. #endif
  264. /* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
  265. compilation unit, it executes code from that unit only by return or by
  266. exception handling. This declaration lets the compiler optimize that unit
  267. more aggressively. */
  268. /* Applies to: functions. */
  269. #if _GL_HAS_ATTRIBUTE (leaf)
  270. # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
  271. #else
  272. # define _GL_ATTRIBUTE_LEAF
  273. #endif
  274. /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
  275. allocated memory. */
  276. /* Applies to: functions. */
  277. #if _GL_HAS_ATTRIBUTE (malloc)
  278. # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
  279. #else
  280. # define _GL_ATTRIBUTE_MALLOC
  281. #endif
  282. /* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
  283. same storage as pointers to other types. Thus this declaration disables
  284. strict aliasing optimization. */
  285. /* Applies to: types. */
  286. /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
  287. #if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
  288. # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
  289. #else
  290. # define _GL_ATTRIBUTE_MAY_ALIAS
  291. #endif
  292. /* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
  293. the entity is not used. The compiler should not warn if the entity is not
  294. used. */
  295. /* Applies to:
  296. - function, variable,
  297. - struct, union, struct/union member,
  298. - enumeration, enumeration item,
  299. - typedef,
  300. in C++ also: class. */
  301. /* In C++ and C23, this is spelled [[__maybe_unused__]].
  302. GCC's syntax is __attribute__ ((__unused__)).
  303. clang supports both syntaxes. */
  304. #ifdef __has_c_attribute
  305. # if __has_c_attribute (__maybe_unused__)
  306. # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
  307. # endif
  308. #endif
  309. #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
  310. # define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
  311. #endif
  312. /* Alternative spelling of this macro, for convenience and for
  313. compatibility with glibc/include/libc-symbols.h. */
  314. #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
  315. /* Earlier spellings of this macro. */
  316. #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
  317. /* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
  318. discard the return value. The compiler may warn if the caller does not use
  319. the return value, unless the caller uses something like ignore_value. */
  320. /* Applies to: function, enumeration, class. */
  321. #ifdef __has_c_attribute
  322. # if __has_c_attribute (__nodiscard__)
  323. # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
  324. # endif
  325. #endif
  326. #if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE (warn_unused_result)
  327. # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
  328. #endif
  329. #ifndef _GL_ATTRIBUTE_NODISCARD
  330. # define _GL_ATTRIBUTE_NODISCARD
  331. #endif
  332. /* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
  333. function. */
  334. /* Applies to: functions. */
  335. #if _GL_HAS_ATTRIBUTE (noinline)
  336. # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
  337. #else
  338. # define _GL_ATTRIBUTE_NOINLINE
  339. #endif
  340. /* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
  341. must not be NULL.
  342. _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
  343. null. */
  344. /* Applies to: functions. */
  345. #if _GL_HAS_ATTRIBUTE (nonnull)
  346. # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
  347. #else
  348. # define _GL_ATTRIBUTE_NONNULL(args)
  349. #endif
  350. /* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
  351. not meant to be NUL-terminated. */
  352. /* Applies to: struct/union members and variables that are arrays of element
  353. type '[[un]signed] char'. */
  354. #if _GL_HAS_ATTRIBUTE (nonstring)
  355. # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
  356. #else
  357. # define _GL_ATTRIBUTE_NONSTRING
  358. #endif
  359. /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
  360. /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
  361. */
  362. /* Applies to: functions. */
  363. #if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
  364. # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
  365. #else
  366. # define _GL_ATTRIBUTE_NOTHROW
  367. #endif
  368. /* _GL_ATTRIBUTE_PACKED declares:
  369. For struct members: The member has the smallest possible alignment.
  370. For struct, union, class: All members have the smallest possible alignment,
  371. minimizing the memory required. */
  372. /* Applies to: struct members, struct, union,
  373. in C++ also: class. */
  374. #if _GL_HAS_ATTRIBUTE (packed)
  375. # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
  376. #else
  377. # define _GL_ATTRIBUTE_PACKED
  378. #endif
  379. /* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
  380. calls to the function with the same arguments if observable state is not
  381. changed between calls.
  382. This attribute is safe for a function that does not affect
  383. observable state, and always returns exactly once.
  384. (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
  385. /* Applies to: functions. */
  386. #if _GL_HAS_ATTRIBUTE (pure)
  387. # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
  388. #else
  389. # define _GL_ATTRIBUTE_PURE
  390. #endif
  391. /* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
  392. a non-NULL pointer. */
  393. /* Applies to: functions. */
  394. #if _GL_HAS_ATTRIBUTE (returns_nonnull)
  395. # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
  396. #else
  397. # define _GL_ATTRIBUTE_RETURNS_NONNULL
  398. #endif
  399. /* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
  400. trailing NULL argument.
  401. _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
  402. _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
  403. /* Applies to: functions. */
  404. #if _GL_HAS_ATTRIBUTE (sentinel)
  405. # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
  406. #else
  407. # define _GL_ATTRIBUTE_SENTINEL(pos)
  408. #endif
  409. /* A helper macro. Don't use it directly. */
  410. #if _GL_HAS_ATTRIBUTE (unused)
  411. # define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  412. #else
  413. # define _GL_ATTRIBUTE_UNUSED
  414. #endif
  415. ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
  416. [
  417. /* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
  418. immediately preceding label is not used. The compiler should not warn
  419. if the label is not used. */
  420. /* Applies to: label (both in C and C++). */
  421. /* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
  422. syntax. But clang does. */
  423. #if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
  424. # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
  425. #else
  426. # define _GL_UNUSED_LABEL
  427. #endif
  428. ])
  429. AH_VERBATIM([async_safe],
  430. [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
  431. signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
  432. invoked from such signal handlers. Such functions have some restrictions:
  433. * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
  434. or should be listed as async-signal-safe in POSIX
  435. <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
  436. section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
  437. particular, are NOT async-signal-safe.
  438. * All memory locations (variables and struct fields) that these functions
  439. access must be marked 'volatile'. This holds for both read and write
  440. accesses. Otherwise the compiler might optimize away stores to and
  441. reads from such locations that occur in the program, depending on its
  442. data flow analysis. For example, when the program contains a loop
  443. that is intended to inspect a variable set from within a signal handler
  444. while (!signal_occurred)
  445. ;
  446. the compiler is allowed to transform this into an endless loop if the
  447. variable 'signal_occurred' is not declared 'volatile'.
  448. Additionally, recall that:
  449. * A signal handler should not modify errno (except if it is a handler
  450. for a fatal signal and ends by raising the same signal again, thus
  451. provoking the termination of the process). If it invokes a function
  452. that may clobber errno, it needs to save and restore the value of
  453. errno. */
  454. #define _GL_ASYNC_SAFE
  455. ])
  456. AH_VERBATIM([micro_optimizations],
  457. [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
  458. n1 and n2 are expressions without side effects, that evaluate to real
  459. numbers (excluding NaN).
  460. It returns
  461. 1 if n1 > n2
  462. 0 if n1 == n2
  463. -1 if n1 < n2
  464. The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
  465. jump with nearly all GCC versions up to GCC 10.
  466. This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
  467. GCC versions up to GCC 9.
  468. The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
  469. avoids conditional jumps in all GCC versions >= 3.4. */
  470. #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
  471. ])
  472. dnl Hint which direction to take regarding cross-compilation guesses:
  473. dnl When a user installs a program on a platform they are not intimately
  474. dnl familiar with, --enable-cross-guesses=conservative is the appropriate
  475. dnl choice. It implements the "If we don't know, assume the worst" principle.
  476. dnl However, when an operating system developer (on a platform which is not
  477. dnl yet known to gnulib) builds packages for their platform, they want to
  478. dnl expose, not hide, possible platform bugs; in this case,
  479. dnl --enable-cross-guesses=risky is the appropriate choice.
  480. dnl Sets the variables
  481. dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
  482. dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
  483. AC_ARG_ENABLE([cross-guesses],
  484. [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
  485. [specify policy for cross-compilation guesses])],
  486. [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
  487. AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
  488. enableval=conservative
  489. fi
  490. gl_cross_guesses="$enableval"],
  491. [gl_cross_guesses=conservative])
  492. if test $gl_cross_guesses = risky; then
  493. gl_cross_guess_normal="guessing yes"
  494. gl_cross_guess_inverted="guessing no"
  495. else
  496. gl_cross_guess_normal="guessing no"
  497. gl_cross_guess_inverted="guessing yes"
  498. fi
  499. dnl Preparation for running test programs:
  500. dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
  501. dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
  502. dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
  503. LIBC_FATAL_STDERR_=1
  504. export LIBC_FATAL_STDERR_
  505. ])
  506. # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
  507. # gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
  508. # initializes the shell variable that indicates the presence of the given module
  509. # as a C preprocessor expression.
  510. AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
  511. [
  512. GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
  513. AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
  514. ])
  515. # gl_MODULE_INDICATOR_CONDITION
  516. # expands to a C preprocessor expression that evaluates to 1 or 0, depending
  517. # whether a gnulib module that has been requested shall be considered present
  518. # or not.
  519. m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
  520. # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
  521. # sets the shell variable that indicates the presence of the given module to
  522. # a C preprocessor expression that will evaluate to 1.
  523. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
  524. [
  525. gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
  526. [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
  527. [abcdefghijklmnopqrstuvwxyz./-],
  528. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
  529. [gl_MODULE_INDICATOR_CONDITION])
  530. ])
  531. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
  532. # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
  533. # The shell variable's value is a C preprocessor expression that evaluates
  534. # to 0 or 1.
  535. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
  536. [
  537. m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
  538. [
  539. dnl Simplify the expression VALUE || 1 to 1.
  540. $1=1
  541. ],
  542. [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
  543. [gl_MODULE_INDICATOR_CONDITION])])
  544. ])
  545. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
  546. # modifies the shell variable to include the given condition. The shell
  547. # variable's value is a C preprocessor expression that evaluates to 0 or 1.
  548. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
  549. [
  550. dnl Simplify the expression 1 || CONDITION to 1.
  551. if test "$[]$1" != 1; then
  552. dnl Simplify the expression 0 || CONDITION to CONDITION.
  553. if test "$[]$1" = 0; then
  554. $1=$2
  555. else
  556. $1="($[]$1 || $2)"
  557. fi
  558. fi
  559. ])
  560. # gl_MODULE_INDICATOR([modulename])
  561. # defines a C macro indicating the presence of the given module
  562. # in a location where it can be used.
  563. # | Value | Value |
  564. # | in lib/ | in tests/ |
  565. # --------------------------------------------+---------+-----------+
  566. # Module present among main modules: | 1 | 1 |
  567. # --------------------------------------------+---------+-----------+
  568. # Module present among tests-related modules: | 0 | 1 |
  569. # --------------------------------------------+---------+-----------+
  570. # Module not present at all: | 0 | 0 |
  571. # --------------------------------------------+---------+-----------+
  572. AC_DEFUN([gl_MODULE_INDICATOR],
  573. [
  574. AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
  575. [abcdefghijklmnopqrstuvwxyz./-],
  576. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
  577. [gl_MODULE_INDICATOR_CONDITION],
  578. [Define to a C preprocessor expression that evaluates to 1 or 0,
  579. depending whether the gnulib module $1 shall be considered present.])
  580. ])
  581. # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
  582. # defines a C macro indicating the presence of the given module
  583. # in lib or tests. This is useful to determine whether the module
  584. # should be tested.
  585. # | Value | Value |
  586. # | in lib/ | in tests/ |
  587. # --------------------------------------------+---------+-----------+
  588. # Module present among main modules: | 1 | 1 |
  589. # --------------------------------------------+---------+-----------+
  590. # Module present among tests-related modules: | 1 | 1 |
  591. # --------------------------------------------+---------+-----------+
  592. # Module not present at all: | 0 | 0 |
  593. # --------------------------------------------+---------+-----------+
  594. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
  595. [
  596. AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
  597. [abcdefghijklmnopqrstuvwxyz./-],
  598. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
  599. [Define to 1 when the gnulib module $1 should be tested.])
  600. ])
  601. # gl_ASSERT_NO_GNULIB_POSIXCHECK
  602. # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
  603. # and thereby enables an optimization of configure and config.h.
  604. # Used by Emacs.
  605. AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
  606. [
  607. dnl Override gl_WARN_ON_USE_PREPARE.
  608. dnl But hide this definition from 'aclocal'.
  609. AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
  610. ])
  611. # gl_ASSERT_NO_GNULIB_TESTS
  612. # asserts that there will be no gnulib tests in the scope of the configure.ac
  613. # and thereby enables an optimization of config.h.
  614. # Used by Emacs.
  615. AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
  616. [
  617. dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
  618. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
  619. ])
  620. # Test whether <features.h> exists.
  621. # Set HAVE_FEATURES_H.
  622. AC_DEFUN([gl_FEATURES_H],
  623. [
  624. AC_CHECK_HEADERS_ONCE([features.h])
  625. if test $ac_cv_header_features_h = yes; then
  626. HAVE_FEATURES_H=1
  627. else
  628. HAVE_FEATURES_H=0
  629. fi
  630. AC_SUBST([HAVE_FEATURES_H])
  631. ])
  632. # gl_PROG_CC_C99
  633. # Modifies the value of the shell variable CC in an attempt to make $CC
  634. # understand ISO C99 source code.
  635. AC_DEFUN([gl_PROG_CC_C99],
  636. [
  637. dnl Just use AC_PROG_CC_C99.
  638. dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
  639. dnl value of CC will contain the C99 enabling options twice. But this is only
  640. dnl a cosmetic problem.
  641. dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
  642. dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
  643. m4_version_prereq([2.70],
  644. [AC_REQUIRE([AC_PROG_CC])],
  645. [AC_REQUIRE([AC_PROG_CC_C99])])
  646. ])
  647. # gl_PROG_AR_RANLIB
  648. # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
  649. # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
  650. # the values.
  651. AC_DEFUN([gl_PROG_AR_RANLIB],
  652. [
  653. dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
  654. dnl as "cc", and GCC as "gcc". They have different object file formats and
  655. dnl library formats. In particular, the GNU binutils programs ar and ranlib
  656. dnl produce libraries that work only with gcc, not with cc.
  657. AC_REQUIRE([AC_PROG_CC])
  658. dnl The '][' hides this use from 'aclocal'.
  659. AC_BEFORE([$0], [A][M_PROG_AR])
  660. AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
  661. [
  662. AC_EGREP_CPP([Amsterdam],
  663. [
  664. #ifdef __ACK__
  665. Amsterdam
  666. #endif
  667. ],
  668. [gl_cv_c_amsterdam_compiler=yes],
  669. [gl_cv_c_amsterdam_compiler=no])
  670. ])
  671. dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
  672. dnl building with __ACK__.
  673. if test $gl_cv_c_amsterdam_compiler = yes; then
  674. if test -z "$AR"; then
  675. AR='cc -c.a'
  676. fi
  677. if test -z "$ARFLAGS"; then
  678. ARFLAGS='-o'
  679. fi
  680. else
  681. dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
  682. dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
  683. dnl script on-demand, if not specified by ./configure of course).
  684. dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
  685. dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
  686. dnl because AM_PROG_AR is written so it could re-set AR variable even for
  687. dnl __ACK__. It may seem like its easier to avoid calling the macro here,
  688. dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
  689. dnl default value and automake should usually know them).
  690. dnl
  691. dnl The '][' hides this use from 'aclocal'.
  692. m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
  693. fi
  694. dnl In case the code above has not helped with setting AR/ARFLAGS, use
  695. dnl Automake-documented default values for AR and ARFLAGS, but prefer
  696. dnl ${host}-ar over ar (useful for cross-compiling).
  697. AC_CHECK_TOOL([AR], [ar], [ar])
  698. if test -z "$ARFLAGS"; then
  699. ARFLAGS='cr'
  700. fi
  701. AC_SUBST([AR])
  702. AC_SUBST([ARFLAGS])
  703. if test -z "$RANLIB"; then
  704. if test $gl_cv_c_amsterdam_compiler = yes; then
  705. RANLIB=':'
  706. else
  707. dnl Use the ranlib program if it is available.
  708. AC_PROG_RANLIB
  709. fi
  710. fi
  711. AC_SUBST([RANLIB])
  712. ])
  713. # AC_C_RESTRICT
  714. # This definition is copied from post-2.70 Autoconf and overrides the
  715. # AC_C_RESTRICT macro from autoconf 2.60..2.70.
  716. m4_version_prereq([2.70.1], [], [
  717. AC_DEFUN([AC_C_RESTRICT],
  718. [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
  719. [ac_cv_c_restrict=no
  720. # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
  721. # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
  722. # Put 'restrict' last, because C++ lacks it.
  723. for ac_kw in __restrict__ __restrict _Restrict restrict; do
  724. AC_COMPILE_IFELSE(
  725. [AC_LANG_PROGRAM(
  726. [[typedef int *int_ptr;
  727. int foo (int_ptr $ac_kw ip) { return ip[0]; }
  728. int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
  729. int bar (int ip[$ac_kw]) { return ip[0]; }
  730. ]],
  731. [[int s[1];
  732. int *$ac_kw t = s;
  733. t[0] = 0;
  734. return foo (t) + bar (t);
  735. ]])],
  736. [ac_cv_c_restrict=$ac_kw])
  737. test "$ac_cv_c_restrict" != no && break
  738. done
  739. ])
  740. AH_VERBATIM([restrict],
  741. [/* Define to the equivalent of the C99 'restrict' keyword, or to
  742. nothing if this is not supported. Do not define if restrict is
  743. supported only directly. */
  744. #undef restrict
  745. /* Work around a bug in older versions of Sun C++, which did not
  746. #define __restrict__ or support _Restrict or __restrict__
  747. even though the corresponding Sun C compiler ended up with
  748. "#define restrict _Restrict" or "#define restrict __restrict__"
  749. in the previous line. This workaround can be removed once
  750. we assume Oracle Developer Studio 12.5 (2016) or later. */
  751. #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
  752. # define _Restrict
  753. # define __restrict__
  754. #endif])
  755. case $ac_cv_c_restrict in
  756. restrict) ;;
  757. no) AC_DEFINE([restrict], []) ;;
  758. *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
  759. esac
  760. ])# AC_C_RESTRICT
  761. ])
  762. # gl_BIGENDIAN
  763. # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
  764. # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
  765. # macros invoke AC_C_BIGENDIAN with arguments.
  766. AC_DEFUN([gl_BIGENDIAN],
  767. [
  768. AC_C_BIGENDIAN
  769. ])
  770. # A temporary file descriptor.
  771. # Must be less than 10, because dash 0.5.8 does not support redirections
  772. # with multi-digit file descriptors.
  773. m4_define([GL_TMP_FD], 9)
  774. # gl_SILENT(command)
  775. # executes command, but without the normal configure output.
  776. # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
  777. # inside another AC_CACHE_CHECK.
  778. AC_DEFUN([gl_SILENT],
  779. [
  780. exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
  781. $1
  782. exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
  783. ])
  784. # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
  785. # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
  786. # output a spurious "(cached)" mark in the midst of other configure output.
  787. # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
  788. # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
  789. AC_DEFUN([gl_CACHE_VAL_SILENT],
  790. [
  791. gl_SILENT([
  792. AC_CACHE_VAL([$1], [$2])
  793. ])
  794. ])
  795. # gl_CONDITIONAL(conditional, condition)
  796. # is like AM_CONDITIONAL(conditional, condition), except that it does not
  797. # produce an error
  798. # configure: error: conditional "..." was never defined.
  799. # Usually this means the macro was only invoked conditionally.
  800. # when only invoked conditionally. Instead, in that case, both the _TRUE
  801. # and the _FALSE case are disabled.
  802. AC_DEFUN([gl_CONDITIONAL],
  803. [
  804. pushdef([AC_CONFIG_COMMANDS_PRE], [:])dnl
  805. AM_CONDITIONAL([$1], [$2])
  806. popdef([AC_CONFIG_COMMANDS_PRE])dnl
  807. if test -z "${[$1]_TRUE}" && test -z "${[$1]_FALSE}"; then
  808. [$1]_TRUE='#'
  809. [$1]_FALSE='#'
  810. fi
  811. ])
  812. # gl_CC_ALLOW_WARNINGS
  813. # sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
  814. # that reverts a preceding '-Werror' option, if available.
  815. # This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
  816. # and empty otherwise.
  817. AC_DEFUN([gl_CC_ALLOW_WARNINGS],
  818. [
  819. AC_REQUIRE([AC_PROG_CC])
  820. AC_CACHE_CHECK([for C compiler option to allow warnings],
  821. [gl_cv_cc_wallow],
  822. [rm -f conftest*
  823. echo 'int dummy;' > conftest.c
  824. AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
  825. AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
  826. dnl Test the number of error output lines, because AIX xlc accepts the
  827. dnl option '-Wno-error', just to produce a warning
  828. dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
  829. dnl afterwards.
  830. if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
  831. gl_cv_cc_wallow='-Wno-error'
  832. else
  833. gl_cv_cc_wallow=none
  834. fi
  835. rm -f conftest*
  836. ])
  837. case "$gl_cv_cc_wallow" in
  838. none) GL_CFLAG_ALLOW_WARNINGS='' ;;
  839. *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
  840. esac
  841. AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
  842. ])
  843. # gl_CXX_ALLOW_WARNINGS
  844. # sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
  845. # that reverts a preceding '-Werror' option, if available.
  846. AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
  847. [
  848. dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
  849. if test -n "$CXX" && test "$CXX" != no; then
  850. AC_CACHE_CHECK([for C++ compiler option to allow warnings],
  851. [gl_cv_cxx_wallow],
  852. [rm -f conftest*
  853. echo 'int dummy;' > conftest.cc
  854. AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
  855. AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
  856. dnl Test the number of error output lines, because AIX xlC accepts the
  857. dnl option '-Wno-error', just to produce a warning
  858. dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
  859. dnl afterwards.
  860. if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
  861. gl_cv_cxx_wallow='-Wno-error'
  862. else
  863. gl_cv_cxx_wallow=none
  864. fi
  865. rm -f conftest*
  866. ])
  867. case "$gl_cv_cxx_wallow" in
  868. none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
  869. *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
  870. esac
  871. else
  872. GL_CXXFLAG_ALLOW_WARNINGS=''
  873. fi
  874. AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
  875. ])
  876. # gl_CC_GNULIB_WARNINGS
  877. # sets and substitutes a variable GL_CFLAG_GNULIB_WARNINGS, to a $(CC) option
  878. # set that enables or disables warnings as suitable for the Gnulib coding style.
  879. AC_DEFUN([gl_CC_GNULIB_WARNINGS],
  880. [
  881. AC_REQUIRE([gl_CC_ALLOW_WARNINGS])
  882. dnl Assume that the compiler supports -Wno-* options only if it also supports
  883. dnl -Wno-error.
  884. GL_CFLAG_GNULIB_WARNINGS=''
  885. if test -n "$GL_CFLAG_ALLOW_WARNINGS"; then
  886. dnl Enable these warning options:
  887. dnl
  888. dnl GCC clang
  889. dnl -Wno-cast-qual >= 3 >= 3.9
  890. dnl -Wno-conversion >= 3 >= 3.9
  891. dnl -Wno-float-conversion >= 4.9 >= 3.9
  892. dnl -Wno-float-equal >= 3 >= 3.9
  893. dnl -Wimplicit-fallthrough >= 7 >= 3.9
  894. dnl -Wno-pedantic >= 4.8 >= 3.9
  895. dnl -Wno-sign-compare >= 3 >= 3.9
  896. dnl -Wno-sign-conversion >= 4.3 >= 3.9
  897. dnl -Wno-type-limits >= 4.3 >= 3.9
  898. dnl -Wno-undef >= 3 >= 3.9
  899. dnl -Wno-unsuffixed-float-constants >= 4.5
  900. dnl -Wno-unused-function >= 3 >= 3.9
  901. dnl -Wno-unused-parameter >= 3 >= 3.9
  902. dnl
  903. cat > conftest.c <<\EOF
  904. #if __GNUC__ >= 3 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
  905. -Wno-cast-qual
  906. -Wno-conversion
  907. -Wno-float-equal
  908. -Wno-sign-compare
  909. -Wno-undef
  910. -Wno-unused-function
  911. -Wno-unused-parameter
  912. #endif
  913. #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
  914. -Wno-float-conversion
  915. #endif
  916. #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
  917. -Wimplicit-fallthrough
  918. #endif
  919. #if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
  920. -Wno-pedantic
  921. #endif
  922. #if __GNUC__ + (__GNUC_MINOR__ >= 3) > 4 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
  923. -Wno-sign-conversion
  924. -Wno-type-limits
  925. #endif
  926. #if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
  927. -Wno-unsuffixed-float-constants
  928. #endif
  929. EOF
  930. gl_command="$CC $CFLAGS $CPPFLAGS -E conftest.c > conftest.out"
  931. if AC_TRY_EVAL([gl_command]); then
  932. gl_options=`grep -v '#' conftest.out`
  933. for word in $gl_options; do
  934. GL_CFLAG_GNULIB_WARNINGS="$GL_CFLAG_GNULIB_WARNINGS $word"
  935. done
  936. fi
  937. rm -f conftest.c conftest.out
  938. fi
  939. AC_SUBST([GL_CFLAG_GNULIB_WARNINGS])
  940. ])
  941. dnl gl_CONDITIONAL_HEADER([foo.h])
  942. dnl takes a shell variable GL_GENERATE_FOO_H (with value true or false) as input
  943. dnl and produces
  944. dnl - an AC_SUBSTed variable FOO_H that is either a file name or empty, based
  945. dnl on whether GL_GENERATE_FOO_H is true or false,
  946. dnl - an Automake conditional GL_GENERATE_FOO_H that evaluates to the value of
  947. dnl the shell variable GL_GENERATE_FOO_H.
  948. AC_DEFUN([gl_CONDITIONAL_HEADER],
  949. [
  950. m4_pushdef([gl_header_name], AS_TR_SH(m4_toupper($1)))
  951. m4_pushdef([gl_generate_var], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
  952. m4_pushdef([gl_generate_cond], [GL_GENERATE_]AS_TR_SH(m4_toupper($1)))
  953. case "$gl_generate_var" in
  954. false) gl_header_name='' ;;
  955. true)
  956. dnl It is OK to use a .h file in lib/ from within tests/, but not vice
  957. dnl versa.
  958. if test -z "$gl_header_name"; then
  959. gl_header_name="${gl_source_base_prefix}$1"
  960. fi
  961. ;;
  962. *) echo "*** gl_generate_var is not set correctly" 1>&2; exit 1 ;;
  963. esac
  964. AC_SUBST(gl_header_name)
  965. gl_CONDITIONAL(gl_generate_cond, [$gl_generate_var])
  966. m4_popdef([gl_generate_cond])
  967. m4_popdef([gl_generate_var])
  968. m4_popdef([gl_header_name])
  969. ])
  970. dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
  971. dnl is like AC_CHECK_FUNCS([func]), taking into account a portability problem
  972. dnl on Android.
  973. dnl Namely, if func was added to Android API level, say, 28, then the libc.so
  974. dnl has the symbol func always, whereas the header file <foo.h> declares func
  975. dnl conditionally:
  976. dnl #if __ANDROID_API__ >= 28
  977. dnl ... func (...) __INTRODUCED_IN(28);
  978. dnl #endif
  979. dnl Thus, when compiling with "clang -target armv7a-unknown-linux-android28",
  980. dnl the function func is declared and exists in libc.
  981. dnl Whereas when compiling with "clang -target armv7a-unknown-linux-android27",
  982. dnl the function func is not declared but exists in libc. We need to treat this
  983. dnl case like the case where func does not exist.
  984. AC_DEFUN([gl_CHECK_FUNCS_ANDROID],
  985. [
  986. AC_CHECK_DECL([$1], , , [$2])
  987. if test $ac_cv_have_decl_[$1] = yes; then
  988. AC_CHECK_FUNCS([$1])
  989. else
  990. ac_cv_func_[$1]=no
  991. fi
  992. ])
  993. dnl Expands to some code for use in .c programs that, on native Windows, defines
  994. dnl the Microsoft deprecated alias function names to the underscore-prefixed
  995. dnl actual function names. With this macro, these function names are available
  996. dnl without linking with '-loldnames' and without generating warnings.
  997. dnl Usage: Use it after all system header files are included.
  998. dnl #include <...>
  999. dnl #include <...>
  1000. dnl ]GL_MDA_DEFINES[
  1001. dnl ...
  1002. AC_DEFUN([GL_MDA_DEFINES],[
  1003. AC_REQUIRE([_GL_MDA_DEFINES])
  1004. [$gl_mda_defines]
  1005. ])
  1006. AC_DEFUN([_GL_MDA_DEFINES],
  1007. [gl_mda_defines='
  1008. #if defined _WIN32 && !defined __CYGWIN__
  1009. #define access _access
  1010. #define chdir _chdir
  1011. #define chmod _chmod
  1012. #define close _close
  1013. #define creat _creat
  1014. #define dup _dup
  1015. #define dup2 _dup2
  1016. #define ecvt _ecvt
  1017. #define execl _execl
  1018. #define execle _execle
  1019. #define execlp _execlp
  1020. #define execv _execv
  1021. #define execve _execve
  1022. #define execvp _execvp
  1023. #define execvpe _execvpe
  1024. #define fcloseall _fcloseall
  1025. #define fcvt _fcvt
  1026. #define fdopen _fdopen
  1027. #define fileno _fileno
  1028. #define gcvt _gcvt
  1029. #define getcwd _getcwd
  1030. #define getpid _getpid
  1031. #define getw _getw
  1032. #define isatty _isatty
  1033. #define j0 _j0
  1034. #define j1 _j1
  1035. #define jn _jn
  1036. #define lfind _lfind
  1037. #define lsearch _lsearch
  1038. #define lseek _lseek
  1039. #define memccpy _memccpy
  1040. #define mkdir _mkdir
  1041. #define mktemp _mktemp
  1042. #define open _open
  1043. #define putenv _putenv
  1044. #define putw _putw
  1045. #define read _read
  1046. #define rmdir _rmdir
  1047. #define strdup _strdup
  1048. #define swab _swab
  1049. #define tempnam _tempnam
  1050. #define tzset _tzset
  1051. #define umask _umask
  1052. #define unlink _unlink
  1053. #define utime _utime
  1054. #define wcsdup _wcsdup
  1055. #define write _write
  1056. #define y0 _y0
  1057. #define y1 _y1
  1058. #define yn _yn
  1059. #endif
  1060. '
  1061. ])