gnulib-common.m4 26 KB

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