gnulib-common.m4 16 KB

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