gnulib-common.m4 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. # gnulib-common.m4 serial 31
  2. dnl Copyright (C) 2007-2011 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. # gl_COMMON
  7. # is expanded unconditionally through gnulib-tool magic.
  8. AC_DEFUN([gl_COMMON], [
  9. dnl Use AC_REQUIRE here, so that the code is expanded once only.
  10. AC_REQUIRE([gl_00GNULIB])
  11. AC_REQUIRE([gl_COMMON_BODY])
  12. ])
  13. AC_DEFUN([gl_COMMON_BODY], [
  14. AH_VERBATIM([_Noreturn],
  15. [/* The _Noreturn keyword of draft C1X. */
  16. #ifndef _Noreturn
  17. # if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
  18. || 0x5110 <= __SUNPRO_C)
  19. # define _Noreturn __attribute__ ((__noreturn__))
  20. # elif 1200 <= _MSC_VER
  21. # define _Noreturn __declspec (noreturn)
  22. # else
  23. # define _Noreturn
  24. # endif
  25. #endif
  26. ])
  27. AH_VERBATIM([isoc99_inline],
  28. [/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
  29. the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
  30. earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
  31. __APPLE__ && __MACH__ test for MacOS X.
  32. __APPLE_CC__ tests for the Apple compiler and its version.
  33. __STDC_VERSION__ tests for the C99 mode. */
  34. #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
  35. # define __GNUC_STDC_INLINE__ 1
  36. #endif])
  37. AH_VERBATIM([unused_parameter],
  38. [/* Define as a marker that can be attached to declarations that might not
  39. be used. This helps to reduce warnings, such as from
  40. GCC -Wunused-parameter. */
  41. #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
  42. # define _GL_UNUSED __attribute__ ((__unused__))
  43. #else
  44. # define _GL_UNUSED
  45. #endif
  46. /* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
  47. is a misnomer outside of parameter lists. */
  48. #define _UNUSED_PARAMETER_ _GL_UNUSED
  49. /* The __pure__ attribute was added in gcc 2.96. */
  50. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  51. # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
  52. #else
  53. # define _GL_ATTRIBUTE_PURE /* empty */
  54. #endif
  55. /* The __const__ attribute was added in gcc 2.95. */
  56. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
  57. # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
  58. #else
  59. # define _GL_ATTRIBUTE_CONST /* empty */
  60. #endif
  61. ])
  62. dnl Preparation for running test programs:
  63. dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
  64. dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
  65. dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N.
  66. LIBC_FATAL_STDERR_=1
  67. export LIBC_FATAL_STDERR_
  68. ])
  69. # gl_MODULE_INDICATOR_CONDITION
  70. # expands to a C preprocessor expression that evaluates to 1 or 0, depending
  71. # whether a gnulib module that has been requested shall be considered present
  72. # or not.
  73. m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
  74. # gl_MODULE_INDICATOR_SET_VARIABLE([modulename])
  75. # sets the shell variable that indicates the presence of the given module to
  76. # a C preprocessor expression that will evaluate to 1.
  77. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
  78. [
  79. gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
  80. [GNULIB_[]m4_translit([[$1]],
  81. [abcdefghijklmnopqrstuvwxyz./-],
  82. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
  83. [gl_MODULE_INDICATOR_CONDITION])
  84. ])
  85. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable])
  86. # modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION.
  87. # The shell variable's value is a C preprocessor expression that evaluates
  88. # to 0 or 1.
  89. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX],
  90. [
  91. m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1],
  92. [
  93. dnl Simplify the expression VALUE || 1 to 1.
  94. $1=1
  95. ],
  96. [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1],
  97. [gl_MODULE_INDICATOR_CONDITION])])
  98. ])
  99. # gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition])
  100. # modifies the shell variable to include the given condition. The shell
  101. # variable's value is a C preprocessor expression that evaluates to 0 or 1.
  102. AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR],
  103. [
  104. dnl Simplify the expression 1 || CONDITION to 1.
  105. if test "$[]$1" != 1; then
  106. dnl Simplify the expression 0 || CONDITION to CONDITION.
  107. if test "$[]$1" = 0; then
  108. $1=$2
  109. else
  110. $1="($[]$1 || $2)"
  111. fi
  112. fi
  113. ])
  114. # gl_MODULE_INDICATOR([modulename])
  115. # defines a C macro indicating the presence of the given module
  116. # in a location where it can be used.
  117. # | Value | Value |
  118. # | in lib/ | in tests/ |
  119. # --------------------------------------------+---------+-----------+
  120. # Module present among main modules: | 1 | 1 |
  121. # --------------------------------------------+---------+-----------+
  122. # Module present among tests-related modules: | 0 | 1 |
  123. # --------------------------------------------+---------+-----------+
  124. # Module not present at all: | 0 | 0 |
  125. # --------------------------------------------+---------+-----------+
  126. AC_DEFUN([gl_MODULE_INDICATOR],
  127. [
  128. AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]],
  129. [abcdefghijklmnopqrstuvwxyz./-],
  130. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]),
  131. [gl_MODULE_INDICATOR_CONDITION],
  132. [Define to a C preprocessor expression that evaluates to 1 or 0,
  133. depending whether the gnulib module $1 shall be considered present.])
  134. ])
  135. # gl_MODULE_INDICATOR_FOR_TESTS([modulename])
  136. # defines a C macro indicating the presence of the given module
  137. # in lib or tests. This is useful to determine whether the module
  138. # should be tested.
  139. # | Value | Value |
  140. # | in lib/ | in tests/ |
  141. # --------------------------------------------+---------+-----------+
  142. # Module present among main modules: | 1 | 1 |
  143. # --------------------------------------------+---------+-----------+
  144. # Module present among tests-related modules: | 1 | 1 |
  145. # --------------------------------------------+---------+-----------+
  146. # Module not present at all: | 0 | 0 |
  147. # --------------------------------------------+---------+-----------+
  148. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS],
  149. [
  150. AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]],
  151. [abcdefghijklmnopqrstuvwxyz./-],
  152. [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1],
  153. [Define to 1 when the gnulib module $1 should be tested.])
  154. ])
  155. # gl_ASSERT_NO_GNULIB_POSIXCHECK
  156. # asserts that there will never be a need to #define GNULIB_POSIXCHECK.
  157. # and thereby enables an optimization of configure and config.h.
  158. # Used by Emacs.
  159. AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK],
  160. [
  161. dnl Override gl_WARN_ON_USE_PREPARE.
  162. dnl But hide this definition from 'aclocal'.
  163. AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], [])
  164. ])
  165. # gl_ASSERT_NO_GNULIB_TESTS
  166. # asserts that there will be no gnulib tests in the scope of the configure.ac
  167. # and thereby enables an optimization of config.h.
  168. # Used by Emacs.
  169. AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS],
  170. [
  171. dnl Override gl_MODULE_INDICATOR_FOR_TESTS.
  172. AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], [])
  173. ])
  174. # Test whether <features.h> exists.
  175. # Set HAVE_FEATURES_H.
  176. AC_DEFUN([gl_FEATURES_H],
  177. [
  178. AC_CHECK_HEADERS_ONCE([features.h])
  179. if test $ac_cv_header_features_h = yes; then
  180. HAVE_FEATURES_H=1
  181. else
  182. HAVE_FEATURES_H=0
  183. fi
  184. AC_SUBST([HAVE_FEATURES_H])
  185. ])
  186. # m4_foreach_w
  187. # is a backport of autoconf-2.59c's m4_foreach_w.
  188. # Remove this macro when we can assume autoconf >= 2.60.
  189. m4_ifndef([m4_foreach_w],
  190. [m4_define([m4_foreach_w],
  191. [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])])
  192. # AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH])
  193. # ----------------------------------------------------
  194. # Backport of autoconf-2.63b's macro.
  195. # Remove this macro when we can assume autoconf >= 2.64.
  196. m4_ifndef([AS_VAR_IF],
  197. [m4_define([AS_VAR_IF],
  198. [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
  199. # gl_PROG_CC_C99
  200. # Modifies the value of the shell variable CC in an attempt to make $CC
  201. # understand ISO C99 source code.
  202. # This is like AC_PROG_CC_C99, except that
  203. # - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60,
  204. # - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
  205. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00367.html>,
  206. # but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
  207. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00441.html>.
  208. # Remaining problems:
  209. # - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
  210. # to CC twice
  211. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00431.html>.
  212. # - AC_PROG_CC_STDC is likely to change when C1X is an ISO standard.
  213. AC_DEFUN([gl_PROG_CC_C99],
  214. [
  215. dnl Change that version number to the minimum Autoconf version that supports
  216. dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
  217. m4_version_prereq([9.0],
  218. [AC_REQUIRE([AC_PROG_CC_C99])],
  219. [AC_REQUIRE([AC_PROG_CC_STDC])])
  220. ])
  221. # gl_PROG_AR_RANLIB
  222. # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
  223. # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
  224. # the values.
  225. AC_DEFUN([gl_PROG_AR_RANLIB],
  226. [
  227. dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler
  228. dnl as "cc", and GCC as "gcc". They have different object file formats and
  229. dnl library formats. In particular, the GNU binutils programs ar, ranlib
  230. dnl produce libraries that work only with gcc, not with cc.
  231. AC_REQUIRE([AC_PROG_CC])
  232. AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
  233. [
  234. AC_EGREP_CPP([Amsterdam],
  235. [
  236. #ifdef __ACK__
  237. Amsterdam
  238. #endif
  239. ],
  240. [gl_cv_c_amsterdam_compiler=yes],
  241. [gl_cv_c_amsterdam_compiler=no])
  242. ])
  243. if test -z "$AR"; then
  244. if test $gl_cv_c_amsterdam_compiler = yes; then
  245. AR='cc -c.a'
  246. if test -z "$ARFLAGS"; then
  247. ARFLAGS='-o'
  248. fi
  249. else
  250. dnl Use the Automake-documented default values for AR and ARFLAGS,
  251. dnl but prefer ${host}-ar over ar (useful for cross-compiling).
  252. AC_CHECK_TOOL([AR], [ar], [ar])
  253. if test -z "$ARFLAGS"; then
  254. ARFLAGS='cru'
  255. fi
  256. fi
  257. else
  258. if test -z "$ARFLAGS"; then
  259. ARFLAGS='cru'
  260. fi
  261. fi
  262. AC_SUBST([AR])
  263. AC_SUBST([ARFLAGS])
  264. if test -z "$RANLIB"; then
  265. if test $gl_cv_c_amsterdam_compiler = yes; then
  266. RANLIB=':'
  267. else
  268. dnl Use the ranlib program if it is available.
  269. AC_PROG_RANLIB
  270. fi
  271. fi
  272. AC_SUBST([RANLIB])
  273. ])
  274. # AC_PROG_MKDIR_P
  275. # is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix
  276. # for interoperability with automake-1.9.6 from autoconf-2.62.
  277. # Remove this macro when we can assume autoconf >= 2.62 or
  278. # autoconf >= 2.60 && automake >= 1.10.
  279. m4_ifdef([AC_PROG_MKDIR_P], [
  280. dnl For automake-1.9.6 && autoconf < 2.62: Ensure MKDIR_P is AC_SUBSTed.
  281. m4_define([AC_PROG_MKDIR_P],
  282. m4_defn([AC_PROG_MKDIR_P])[
  283. AC_SUBST([MKDIR_P])])], [
  284. dnl For autoconf < 2.60: Backport of AC_PROG_MKDIR_P.
  285. AC_DEFUN_ONCE([AC_PROG_MKDIR_P],
  286. [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
  287. MKDIR_P='$(mkdir_p)'
  288. AC_SUBST([MKDIR_P])])])
  289. # AC_C_RESTRICT
  290. # This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61,
  291. # so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++
  292. # works.
  293. # This definition can be removed once autoconf >= 2.62 can be assumed.
  294. m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.62]),[-1],[
  295. AC_DEFUN([AC_C_RESTRICT],
  296. [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
  297. [ac_cv_c_restrict=no
  298. # The order here caters to the fact that C++ does not require restrict.
  299. for ac_kw in __restrict __restrict__ _Restrict restrict; do
  300. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  301. [[typedef int * int_ptr;
  302. int foo (int_ptr $ac_kw ip) {
  303. return ip[0];
  304. }]],
  305. [[int s[1];
  306. int * $ac_kw t = s;
  307. t[0] = 0;
  308. return foo(t)]])],
  309. [ac_cv_c_restrict=$ac_kw])
  310. test "$ac_cv_c_restrict" != no && break
  311. done
  312. ])
  313. AH_VERBATIM([restrict],
  314. [/* Define to the equivalent of the C99 'restrict' keyword, or to
  315. nothing if this is not supported. Do not define if restrict is
  316. supported directly. */
  317. #undef restrict
  318. /* Work around a bug in Sun C++: it does not support _Restrict, even
  319. though the corresponding Sun C compiler does, which causes
  320. "#define restrict _Restrict" in the previous line. Perhaps some future
  321. version of Sun C++ will work with _Restrict; if so, it'll probably
  322. define __RESTRICT, just as Sun C does. */
  323. #if defined __SUNPRO_CC && !defined __RESTRICT
  324. # define _Restrict
  325. #endif])
  326. case $ac_cv_c_restrict in
  327. restrict) ;;
  328. no) AC_DEFINE([restrict], []) ;;
  329. *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
  330. esac
  331. ])
  332. ])
  333. # gl_BIGENDIAN
  334. # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd.
  335. # Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some
  336. # macros invoke AC_C_BIGENDIAN with arguments.
  337. AC_DEFUN([gl_BIGENDIAN],
  338. [
  339. AC_C_BIGENDIAN
  340. ])
  341. # gl_CACHE_VAL_SILENT(cache-id, command-to-set-it)
  342. # is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not
  343. # output a spurious "(cached)" mark in the midst of other configure output.
  344. # This macro should be used instead of AC_CACHE_VAL when it is not surrounded
  345. # by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
  346. AC_DEFUN([gl_CACHE_VAL_SILENT],
  347. [
  348. saved_as_echo_n="$as_echo_n"
  349. as_echo_n=':'
  350. AC_CACHE_VAL([$1], [$2])
  351. as_echo_n="$saved_as_echo_n"
  352. ])