gnulib-common.m4 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. # gnulib-common.m4 serial 63
  2. dnl Copyright (C) 2007-2021 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. #ifdef __has_attribute
  69. # define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
  70. #else
  71. # define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
  72. # define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
  73. # define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
  74. # define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
  75. # define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
  76. # define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
  77. # define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
  78. # define _GL_ATTR_diagnose_if 0
  79. # define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
  80. # define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
  81. # define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
  82. # define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
  83. # define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
  84. # ifdef _ICC
  85. # define _GL_ATTR_may_alias 0
  86. # else
  87. # define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
  88. # endif
  89. # define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
  90. # define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
  91. # define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
  92. # define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
  93. # define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
  94. # define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
  95. # define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
  96. # define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
  97. # define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
  98. # define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
  99. # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
  100. #endif
  101. ]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
  102. [
  103. #if _GL_HAS_ATTRIBUTE (alloc_size)
  104. # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
  105. #else
  106. # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
  107. #endif
  108. #if _GL_HAS_ATTRIBUTE (always_inline)
  109. # define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
  110. #else
  111. # define _GL_ATTRIBUTE_ALWAYS_INLINE
  112. #endif
  113. #if _GL_HAS_ATTRIBUTE (artificial)
  114. # define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
  115. #else
  116. # define _GL_ATTRIBUTE_ARTIFICIAL
  117. #endif
  118. /* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
  119. <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
  120. Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
  121. #if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
  122. # ifndef __SUNPRO_C
  123. # define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
  124. # else
  125. # define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
  126. # endif
  127. #else
  128. # define _GL_ATTRIBUTE_COLD
  129. #endif
  130. #if _GL_HAS_ATTRIBUTE (const)
  131. # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
  132. #else
  133. # define _GL_ATTRIBUTE_CONST
  134. #endif
  135. #if 201710L < __STDC_VERSION__
  136. # define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
  137. #elif _GL_HAS_ATTRIBUTE (deprecated)
  138. # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
  139. #else
  140. # define _GL_ATTRIBUTE_DEPRECATED
  141. #endif
  142. #if _GL_HAS_ATTRIBUTE (error)
  143. # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
  144. # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
  145. #elif _GL_HAS_ATTRIBUTE (diagnose_if)
  146. # define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
  147. # define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
  148. #else
  149. # define _GL_ATTRIBUTE_ERROR(msg)
  150. # define _GL_ATTRIBUTE_WARNING(msg)
  151. #endif
  152. #if _GL_HAS_ATTRIBUTE (externally_visible)
  153. # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
  154. #else
  155. # define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
  156. #endif
  157. /* FALLTHROUGH is special, because it always expands to something. */
  158. #if 201710L < __STDC_VERSION__
  159. # define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
  160. #elif _GL_HAS_ATTRIBUTE (fallthrough)
  161. # define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
  162. #else
  163. # define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
  164. #endif
  165. #if _GL_HAS_ATTRIBUTE (format)
  166. # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
  167. #else
  168. # define _GL_ATTRIBUTE_FORMAT(spec)
  169. #endif
  170. #if _GL_HAS_ATTRIBUTE (leaf)
  171. # define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
  172. #else
  173. # define _GL_ATTRIBUTE_LEAF
  174. #endif
  175. /* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
  176. #if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
  177. # define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
  178. #else
  179. # define _GL_ATTRIBUTE_MAY_ALIAS
  180. #endif
  181. #if 201710L < __STDC_VERSION__
  182. # define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
  183. #elif _GL_HAS_ATTRIBUTE (unused)
  184. # define _GL_ATTRIBUTE_MAYBE_UNUSED __attribute__ ((__unused__))
  185. #else
  186. # define _GL_ATTRIBUTE_MAYBE_UNUSED
  187. #endif
  188. /* Earlier spellings of this macro. */
  189. #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
  190. #define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
  191. #if _GL_HAS_ATTRIBUTE (malloc)
  192. # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
  193. #else
  194. # define _GL_ATTRIBUTE_MALLOC
  195. #endif
  196. #if 201710L < __STDC_VERSION__
  197. # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
  198. #elif _GL_HAS_ATTRIBUTE (warn_unused_result)
  199. # define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
  200. #else
  201. # define _GL_ATTRIBUTE_NODISCARD
  202. #endif
  203. #if _GL_HAS_ATTRIBUTE (noinline)
  204. # define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
  205. #else
  206. # define _GL_ATTRIBUTE_NOINLINE
  207. #endif
  208. #if _GL_HAS_ATTRIBUTE (nonnull)
  209. # define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
  210. #else
  211. # define _GL_ATTRIBUTE_NONNULL(args)
  212. #endif
  213. #if _GL_HAS_ATTRIBUTE (nonstring)
  214. # define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
  215. #else
  216. # define _GL_ATTRIBUTE_NONSTRING
  217. #endif
  218. /* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
  219. #if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
  220. # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
  221. #else
  222. # define _GL_ATTRIBUTE_NOTHROW
  223. #endif
  224. #if _GL_HAS_ATTRIBUTE (packed)
  225. # define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
  226. #else
  227. # define _GL_ATTRIBUTE_PACKED
  228. #endif
  229. #if _GL_HAS_ATTRIBUTE (pure)
  230. # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
  231. #else
  232. # define _GL_ATTRIBUTE_PURE
  233. #endif
  234. #if _GL_HAS_ATTRIBUTE (returns_nonnull)
  235. # define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
  236. #else
  237. # define _GL_ATTRIBUTE_RETURNS_NONNULL
  238. #endif
  239. #if _GL_HAS_ATTRIBUTE (sentinel)
  240. # define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
  241. #else
  242. # define _GL_ATTRIBUTE_SENTINEL(pos)
  243. #endif
  244. ]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
  245. [
  246. /* To support C++ as well as C, use _GL_UNUSED_LABEL with trailing ';'. */
  247. #if !defined __cplusplus || _GL_GNUC_PREREQ (4, 5)
  248. # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_MAYBE_UNUSED
  249. #else
  250. # define _GL_UNUSED_LABEL
  251. #endif
  252. ])
  253. AH_VERBATIM([async_safe],
  254. [/* The _GL_ASYNC_SAFE marker should be attached to functions that are
  255. signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
  256. invoked from such signal handlers. Such functions have some restrictions:
  257. * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
  258. or should be listed as async-signal-safe in POSIX
  259. <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
  260. section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
  261. particular, are NOT async-signal-safe.
  262. * All memory locations (variables and struct fields) that these functions
  263. access must be marked 'volatile'. This holds for both read and write
  264. accesses. Otherwise the compiler might optimize away stores to and
  265. reads from such locations that occur in the program, depending on its
  266. data flow analysis. For example, when the program contains a loop
  267. that is intended to inspect a variable set from within a signal handler
  268. while (!signal_occurred)
  269. ;
  270. the compiler is allowed to transform this into an endless loop if the
  271. variable 'signal_occurred' is not declared 'volatile'.
  272. Additionally, recall that:
  273. * A signal handler should not modify errno (except if it is a handler
  274. for a fatal signal and ends by raising the same signal again, thus
  275. provoking the termination of the process). If it invokes a function
  276. that may clobber errno, it needs to save and restore the value of
  277. errno. */
  278. #define _GL_ASYNC_SAFE
  279. ])
  280. AH_VERBATIM([micro_optimizations],
  281. [/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
  282. n1 and n2 are expressions without side effects, that evaluate to real
  283. numbers (excluding NaN).
  284. It returns
  285. 1 if n1 > n2
  286. 0 if n1 == n2
  287. -1 if n1 < n2
  288. The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
  289. jump with nearly all GCC versions up to GCC 10.
  290. This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
  291. GCC versions up to GCC 9.
  292. The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
  293. avoids conditional jumps in all GCC versions >= 3.4. */
  294. #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
  295. ])
  296. dnl Hint which direction to take regarding cross-compilation guesses:
  297. dnl When a user installs a program on a platform they are not intimately
  298. dnl familiar with, --enable-cross-guesses=conservative is the appropriate
  299. dnl choice. It implements the "If we don't know, assume the worst" principle.
  300. dnl However, when an operating system developer (on a platform which is not
  301. dnl yet known to gnulib) builds packages for their platform, they want to
  302. dnl expose, not hide, possible platform bugs; in this case,
  303. dnl --enable-cross-guesses=risky is the appropriate choice.
  304. dnl Sets the variables
  305. dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
  306. dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
  307. AC_ARG_ENABLE([cross-guesses],
  308. [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
  309. [specify policy for cross-compilation guesses])],
  310. [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
  311. AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
  312. enableval=conservative
  313. fi
  314. gl_cross_guesses="$enableval"],
  315. [gl_cross_guesses=conservative])
  316. if test $gl_cross_guesses = risky; then
  317. gl_cross_guess_normal="guessing yes"
  318. gl_cross_guess_inverted="guessing no"
  319. else
  320. gl_cross_guess_normal="guessing no"
  321. gl_cross_guess_inverted="guessing yes"
  322. fi
  323. dnl Preparation for running test programs:
  324. dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
  325. dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
  326. dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
  327. LIBC_FATAL_STDERR_=1
  328. export LIBC_FATAL_STDERR_
  329. ])
  330. # gl_MODULE_INDICATOR_CONDITION
  331. # expands to a C preprocessor expression that evaluates to 1 or 0, depending
  332. # whether a gnulib module that has been requested shall be considered present
  333. # or not.
  334. m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
  335. # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
  336. # sets the shell variable that indicates the presence of the given module to
  337. # a C preprocessor expression that will evaluate to 1.
  338. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
  339. [
  340. gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
  341. [GNULIB_[]m4_translit([[$1]],
  342. [abcdefghijklmnopqrstuvwxyz./-],
  343. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
  344. [gl_MODULE_INDICATOR_CONDITION])
  345. ])
  346. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
  347. # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
  348. # The shell variable's value is a C preprocessor expression that evaluates
  349. # to 0 or 1.
  350. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
  351. [
  352. m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
  353. [
  354. dnl Simplify the expression VALUE || 1 to 1.
  355. $1=1
  356. ],
  357. [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
  358. [gl_MODULE_INDICATOR_CONDITION])])
  359. ])
  360. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
  361. # modifies the shell variable to include the given condition. The shell
  362. # variable's value is a C preprocessor expression that evaluates to 0 or 1.
  363. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
  364. [
  365. dnl Simplify the expression 1 || CONDITION to 1.
  366. if test "$[]$1" != 1; then
  367. dnl Simplify the expression 0 || CONDITION to CONDITION.
  368. if test "$[]$1" = 0; then
  369. $1=$2
  370. else
  371. $1="($[]$1 || $2)"
  372. fi
  373. fi
  374. ])
  375. # gl_MODULE_INDICATOR([modulename])
  376. # defines a C macro indicating the presence of the given module
  377. # in a location where it can be used.
  378. # | Value | Value |
  379. # | in lib/ | in tests/ |
  380. # --------------------------------------------+---------+-----------+
  381. # Module present among main modules: | 1 | 1 |
  382. # --------------------------------------------+---------+-----------+
  383. # Module present among tests-related modules: | 0 | 1 |
  384. # --------------------------------------------+---------+-----------+
  385. # Module not present at all: | 0 | 0 |
  386. # --------------------------------------------+---------+-----------+
  387. AC_DEFUN([gl_MODULE_INDICATOR],
  388. [
  389. AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
  390. [abcdefghijklmnopqrstuvwxyz./-],
  391. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
  392. [gl_MODULE_INDICATOR_CONDITION],
  393. [Define to a C preprocessor expression that evaluates to 1 or 0,
  394. depending whether the gnulib module $1 shall be considered present.])
  395. ])
  396. # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
  397. # defines a C macro indicating the presence of the given module
  398. # in lib or tests. This is useful to determine whether the module
  399. # should be tested.
  400. # | Value | Value |
  401. # | in lib/ | in tests/ |
  402. # --------------------------------------------+---------+-----------+
  403. # Module present among main modules: | 1 | 1 |
  404. # --------------------------------------------+---------+-----------+
  405. # Module present among tests-related modules: | 1 | 1 |
  406. # --------------------------------------------+---------+-----------+
  407. # Module not present at all: | 0 | 0 |
  408. # --------------------------------------------+---------+-----------+
  409. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
  410. [
  411. AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
  412. [abcdefghijklmnopqrstuvwxyz./-],
  413. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
  414. [Define to 1 when the gnulib module $1 should be tested.])
  415. ])
  416. # gl_ASSERT_NO_GNULIB_POSIXCHECK
  417. # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
  418. # and thereby enables an optimization of configure and config.h.
  419. # Used by Emacs.
  420. AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
  421. [
  422. dnl Override gl_WARN_ON_USE_PREPARE.
  423. dnl But hide this definition from 'aclocal'.
  424. AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
  425. ])
  426. # gl_ASSERT_NO_GNULIB_TESTS
  427. # asserts that there will be no gnulib tests in the scope of the configure.ac
  428. # and thereby enables an optimization of config.h.
  429. # Used by Emacs.
  430. AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
  431. [
  432. dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
  433. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
  434. ])
  435. # Test whether <features.h> exists.
  436. # Set HAVE_FEATURES_H.
  437. AC_DEFUN([gl_FEATURES_H],
  438. [
  439. AC_CHECK_HEADERS_ONCE([features.h])
  440. if test $ac_cv_header_features_h = yes; then
  441. HAVE_FEATURES_H=1
  442. else
  443. HAVE_FEATURES_H=0
  444. fi
  445. AC_SUBST([HAVE_FEATURES_H])
  446. ])
  447. # gl_PROG_CC_C99
  448. # Modifies the value of the shell variable CC in an attempt to make $CC
  449. # understand ISO C99 source code.
  450. AC_DEFUN([gl_PROG_CC_C99],
  451. [
  452. dnl Just use AC_PROG_CC_C99.
  453. dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
  454. dnl value of CC will contain the C99 enabling options twice. But this is only
  455. dnl a cosmetic problem.
  456. dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
  457. dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
  458. m4_version_prereq([2.70],
  459. [AC_REQUIRE([AC_PROG_CC])],
  460. [AC_REQUIRE([AC_PROG_CC_C99])])
  461. ])
  462. # gl_PROG_AR_RANLIB
  463. # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
  464. # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
  465. # the values.
  466. AC_DEFUN([gl_PROG_AR_RANLIB],
  467. [
  468. dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
  469. dnl as "cc", and GCC as "gcc". They have different object file formats and
  470. dnl library formats. In particular, the GNU binutils programs ar and ranlib
  471. dnl produce libraries that work only with gcc, not with cc.
  472. AC_REQUIRE([AC_PROG_CC])
  473. dnl The '][' hides this use from 'aclocal'.
  474. AC_BEFORE([$0], [A][M_PROG_AR])
  475. AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
  476. [
  477. AC_EGREP_CPP([Amsterdam],
  478. [
  479. #ifdef __ACK__
  480. Amsterdam
  481. #endif
  482. ],
  483. [gl_cv_c_amsterdam_compiler=yes],
  484. [gl_cv_c_amsterdam_compiler=no])
  485. ])
  486. dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
  487. dnl building with __ACK__.
  488. if test $gl_cv_c_amsterdam_compiler = yes; then
  489. if test -z "$AR"; then
  490. AR='cc -c.a'
  491. fi
  492. if test -z "$ARFLAGS"; then
  493. ARFLAGS='-o'
  494. fi
  495. else
  496. dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
  497. dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
  498. dnl script on-demand, if not specified by ./configure of course).
  499. dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
  500. dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
  501. dnl because AM_PROG_AR is written so it could re-set AR variable even for
  502. dnl __ACK__. It may seem like its easier to avoid calling the macro here,
  503. dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
  504. dnl default value and automake should usually know them).
  505. dnl
  506. dnl The '][' hides this use from 'aclocal'.
  507. m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
  508. fi
  509. dnl In case the code above has not helped with setting AR/ARFLAGS, use
  510. dnl Automake-documented default values for AR and ARFLAGS, but prefer
  511. dnl ${host}-ar over ar (useful for cross-compiling).
  512. AC_CHECK_TOOL([AR], [ar], [ar])
  513. if test -z "$ARFLAGS"; then
  514. ARFLAGS='cr'
  515. fi
  516. AC_SUBST([AR])
  517. AC_SUBST([ARFLAGS])
  518. if test -z "$RANLIB"; then
  519. if test $gl_cv_c_amsterdam_compiler = yes; then
  520. RANLIB=':'
  521. else
  522. dnl Use the ranlib program if it is available.
  523. AC_PROG_RANLIB
  524. fi
  525. fi
  526. AC_SUBST([RANLIB])
  527. ])
  528. # AC_C_RESTRICT
  529. # This definition is copied from post-2.70 Autoconf and overrides the
  530. # AC_C_RESTRICT macro from autoconf 2.60..2.70.
  531. m4_version_prereq([2.70.1], [], [
  532. AC_DEFUN([AC_C_RESTRICT],
  533. [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
  534. [ac_cv_c_restrict=no
  535. # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
  536. # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
  537. # Put 'restrict' last, because C++ lacks it.
  538. for ac_kw in __restrict__ __restrict _Restrict restrict; do
  539. AC_COMPILE_IFELSE(
  540. [AC_LANG_PROGRAM(
  541. [[typedef int *int_ptr;
  542. int foo (int_ptr $ac_kw ip) { return ip[0]; }
  543. int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
  544. int bar (int ip[$ac_kw]) { return ip[0]; }
  545. ]],
  546. [[int s[1];
  547. int *$ac_kw t = s;
  548. t[0] = 0;
  549. return foo (t) + bar (t);
  550. ]])],
  551. [ac_cv_c_restrict=$ac_kw])
  552. test "$ac_cv_c_restrict" != no && break
  553. done
  554. ])
  555. AH_VERBATIM([restrict],
  556. [/* Define to the equivalent of the C99 'restrict' keyword, or to
  557. nothing if this is not supported. Do not define if restrict is
  558. supported only directly. */
  559. #undef restrict
  560. /* Work around a bug in older versions of Sun C++, which did not
  561. #define __restrict__ or support _Restrict or __restrict__
  562. even though the corresponding Sun C compiler ended up with
  563. "#define restrict _Restrict" or "#define restrict __restrict__"
  564. in the previous line. This workaround can be removed once
  565. we assume Oracle Developer Studio 12.5 (2016) or later. */
  566. #if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
  567. # define _Restrict
  568. # define __restrict__
  569. #endif])
  570. case $ac_cv_c_restrict in
  571. restrict) ;;
  572. no) AC_DEFINE([restrict], []) ;;
  573. *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
  574. esac
  575. ])# AC_C_RESTRICT
  576. ])
  577. # gl_BIGENDIAN
  578. # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
  579. # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
  580. # macros invoke AC_C_BIGENDIAN with arguments.
  581. AC_DEFUN([gl_BIGENDIAN],
  582. [
  583. AC_C_BIGENDIAN
  584. ])
  585. # A temporary file descriptor.
  586. # Must be less than 10, because dash 0.5.8 does not support redirections
  587. # with multi-digit file descriptors.
  588. m4_define([GL_TMP_FD], 9)
  589. # gl_SILENT(command)
  590. # executes command, but without the normal configure output.
  591. # This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
  592. # inside another AC_CACHE_CHECK.
  593. AC_DEFUN([gl_SILENT],
  594. [
  595. exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
  596. $1
  597. exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
  598. ])
  599. # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
  600. # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
  601. # output a spurious "(cached)" mark in the midst of other configure output.
  602. # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
  603. # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
  604. AC_DEFUN([gl_CACHE_VAL_SILENT],
  605. [
  606. gl_SILENT([
  607. AC_CACHE_VAL([$1], [$2])
  608. ])
  609. ])
  610. dnl Expands to some code for use in .c programs that, on native Windows, defines
  611. dnl the Microsoft deprecated alias function names to the underscore-prefixed
  612. dnl actual function names. With this macro, these function names are available
  613. dnl without linking with '-loldnames' and without generating warnings.
  614. dnl Usage: Use it after all system header files are included.
  615. dnl #include <...>
  616. dnl #include <...>
  617. dnl ]GL_MDA_DEFINES[
  618. dnl ...
  619. AC_DEFUN([GL_MDA_DEFINES],[
  620. AC_REQUIRE([_GL_MDA_DEFINES])
  621. [$gl_mda_defines]
  622. ])
  623. AC_DEFUN([_GL_MDA_DEFINES],
  624. [gl_mda_defines='
  625. #if defined _WIN32 && !defined __CYGWIN__
  626. #define access _access
  627. #define chdir _chdir
  628. #define chmod _chmod
  629. #define close _close
  630. #define creat _creat
  631. #define dup _dup
  632. #define dup2 _dup2
  633. #define ecvt _ecvt
  634. #define execl _execl
  635. #define execle _execle
  636. #define execlp _execlp
  637. #define execv _execv
  638. #define execve _execve
  639. #define execvp _execvp
  640. #define execvpe _execvpe
  641. #define fcloseall _fcloseall
  642. #define fcvt _fcvt
  643. #define fdopen _fdopen
  644. #define fileno _fileno
  645. #define gcvt _gcvt
  646. #define getcwd _getcwd
  647. #define getpid _getpid
  648. #define getw _getw
  649. #define isatty _isatty
  650. #define j0 _j0
  651. #define j1 _j1
  652. #define jn _jn
  653. #define lfind _lfind
  654. #define lsearch _lsearch
  655. #define lseek _lseek
  656. #define memccpy _memccpy
  657. #define mkdir _mkdir
  658. #define mktemp _mktemp
  659. #define open _open
  660. #define putenv _putenv
  661. #define putw _putw
  662. #define read _read
  663. #define rmdir _rmdir
  664. #define strdup _strdup
  665. #define swab _swab
  666. #define tempnam _tempnam
  667. #define tzset _tzset
  668. #define umask _umask
  669. #define unlink _unlink
  670. #define utime _utime
  671. #define wcsdup _wcsdup
  672. #define write _write
  673. #define y0 _y0
  674. #define y1 _y1
  675. #define yn _yn
  676. #endif
  677. '
  678. ])