123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- AC_DEFUN([_AC_C_C89_TEST_GLOBALS],
- [m4_divert_text([INIT_PREPARE],
- [[
- ac_c_conftest_c89_globals='
- /* Does the compiler advertise C89 conformance?
- Do not test the value of __STDC__, because some compilers set it to 0
- while being otherwise adequately conformant. */
- struct stat;
- /* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */
- struct buf { int x; };
- struct buf * (*rcsopen) (struct buf *, struct stat *, int);
- static char *e (char **p, int i)
- {
- return p[i];
- }
- static char *f (char * (*g) (char **, int), char **p, ...)
- {
- char *s;
- va_list v;
- va_start (v,p);
- s = g (p, va_arg (v,int));
- va_end (v);
- return s;
- }
- /* C89 style stringification. */
- const char *stringified = noexpand_stringify(arbitrary+token=sequence);
- /* C89 style token pasting. Exercises some of the corner cases that
- e.g. old MSVC gets wrong, but not very hard. */
- extern int vA;
- extern int vbee;
- int *pvA = &expand_concat(v,aye);
- int *pvbee = &noexpand_concat(v,bee);
- /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
- function prototypes and stuff, but not \xHH hex character constants.
- These do not provoke an error unfortunately, instead are silently treated
- as an "x". The following induces an error, until -std is added to get
- proper ANSI mode. Curiously \x00 != x always comes out true, for an
- array size at least. It is necessary to write \x00 == 0 to get something
- that is true only with -std. */
- int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];
- /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
- inside strings and character constants. */
- int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];
- int test (int i, double x);
- struct s1 {int (*f) (int a);};
- struct s2 {int (*f) (double a);};
- int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
- int, int);'
- ]])])
- AC_DEFUN([_AC_C_C99_TEST_GLOBALS],
- [m4_divert_text([INIT_PREPARE],
- [[
- ac_c_conftest_c99_globals='
- // Does the compiler advertise C99 conformance?
- extern int puts (const char *);
- extern int printf (const char *, ...);
- extern int dprintf (int, const char *, ...);
- extern void *malloc (size_t);
- extern void free (void *);
- // Check varargs macros. These examples are taken from C99 6.10.3.5.
- // dprintf is used instead of fprintf to avoid needing to declare
- // FILE and stderr.
- static void
- test_varargs_macros (void)
- {
- int x = 1234;
- int y = 5678;
- debug ("Flag");
- debug ("X = %d\n", x);
- showlist (The first, second, and third items.);
- report (x>y, "x is %d but y is %d", x, y);
- }
- // Check long long types.
-
-
- static long long int bignum = -9223372036854775807LL;
- static unsigned long long int ubignum = BIG64;
- struct incomplete_array
- {
- int datasize;
- double data[];
- };
- struct named_init {
- int number;
- const wchar_t *name;
- double average;
- };
- typedef const char *ccp;
- static inline int
- test_restrict (ccp restrict text)
- {
- // See if C++-style comments work.
- // Iterate through items via the restricted pointer.
- // Also check for declarations in for loops.
- for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
- continue;
- return 0;
- }
- // Check varargs and va_copy.
- static bool
- test_varargs (const char *format, ...)
- {
- va_list args;
- va_start (args, format);
- va_list args_copy;
- va_copy (args_copy, args);
- const char *str = "";
- int number = 0;
- float fnumber = 0;
- while (*format)
- {
- switch (*format++)
- {
- case '\''s'\'': // string
- str = va_arg (args_copy, const char *);
- break;
- case '\''d'\'': // int
- number = va_arg (args_copy, int);
- break;
- case '\''f'\'': // float
- fnumber = va_arg (args_copy, double);
- break;
- default:
- break;
- }
- }
- va_end (args_copy);
- va_end (args);
- return *str && number && fnumber;
- }
- '
- ]])])
- AC_DEFUN([_AC_C_C11_TEST_GLOBALS],
- [m4_divert_text([INIT_PREPARE],
- [[
- ac_c_conftest_c11_globals='
- // Does the compiler advertise C11 conformance?
- // Check _Alignas.
- char _Alignas (double) aligned_as_double;
- char _Alignas (0) no_special_alignment;
- extern char aligned_as_int;
- char _Alignas (0) _Alignas (int) aligned_as_int;
- // Check _Alignof.
- enum
- {
- int_alignment = _Alignof (int),
- int_array_alignment = _Alignof (int[100]),
- char_alignment = _Alignof (char)
- };
- _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
- // Check _Noreturn.
- _Noreturn int does_not_return (void) { for (;;) continue; }
- // Check _Static_assert.
- struct test_static_assert
- {
- int x;
- _Static_assert (sizeof (int) <= sizeof (long int),
- "_Static_assert does not work in struct");
- long int y;
- };
- // Check UTF-8 literals.
- char const utf8_literal[] = u8"happens to be ASCII" "another string";
- // Check duplicate typedefs.
- typedef long *long_ptr;
- typedef long int *long_ptr;
- typedef long_ptr long_ptr;
- // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
- struct anonymous
- {
- union {
- struct { int i; int j; };
- struct { int k; long int l; } w;
- };
- int m;
- } v1;
- '
- ]])])
- m4_define([AC_LANG_CALL(C)],
- [AC_LANG_PROGRAM([$1
- m4_if([$2], [main], ,
- [/* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply.
- The 'extern "C"' is for builds by C++ compilers;
- although this is not generally supported in C code supporting it here
- has little cost and some practical benefit (sr 110532). */
- extern "C"
- char $2 (void);])], [return $2 ();])])
- m4_define([AC_LANG_FUNC_LINK_TRY(C)],
- [AC_LANG_PROGRAM(
- [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
- For example, HP-UX 11i <limits.h> declares gettimeofday. */
- /* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char $1 (void); below. */
- /* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply. */
- extern "C"
- char $1 (void);
- /* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
- choke me
- ], [return $1 ();])])
- AC_DEFUN([AC_C_BIGENDIAN],
- [AH_VERBATIM([WORDS_BIGENDIAN],
- [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
- AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
- [ac_cv_c_bigendian=unknown
-
- AC_COMPILE_IFELSE(
- [AC_LANG_SOURCE(
- [[
- not a universal capable compiler
-
- typedef int dummy;
- ]])],
- [
-
-
- ac_arch=
- ac_prev=
- for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
- if test -n "$ac_prev"; then
- case $ac_word in
- i?86 | x86_64 | ppc | ppc64)
- if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
- ac_arch=$ac_word
- else
- ac_cv_c_bigendian=universal
- break
- fi
- ;;
- esac
- ac_prev=
- elif test "x$ac_word" = "x-arch"; then
- ac_prev=arch
- fi
- done])
- if test $ac_cv_c_bigendian = unknown; then
-
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[
-
- ]],
- [[
- && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
- && LITTLE_ENDIAN)
- bogus endian macros
-
- ]])],
- [
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[
-
- ]],
- [[
- not big endian
-
- ]])],
- [ac_cv_c_bigendian=yes],
- [ac_cv_c_bigendian=no])])
- fi
- if test $ac_cv_c_bigendian = unknown; then
-
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[
- ]],
- [[
- bogus endian macros
-
- ]])],
- [
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[
- ]],
- [[
- not big endian
-
- ]])],
- [ac_cv_c_bigendian=yes],
- [ac_cv_c_bigendian=no])])
- fi
- if test $ac_cv_c_bigendian = unknown; then
-
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
- [[
- /* Are we little or big endian? From Harbison&Steele. */
- union
- {
- long int l;
- char c[sizeof (long int)];
- } u;
- u.l = 1;
- return u.c[sizeof (long int) - 1] == 1;
- ]])],
- [ac_cv_c_bigendian=no],
- [ac_cv_c_bigendian=yes],
- [
- AC_LINK_IFELSE(
- [AC_LANG_SOURCE(
- [[unsigned short int ascii_mm[] =
- { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
- unsigned short int ascii_ii[] =
- { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
- int use_ascii (int i) {
- return ascii_mm[i] + ascii_ii[i];
- }
- unsigned short int ebcdic_ii[] =
- { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
- unsigned short int ebcdic_mm[] =
- { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
- int use_ebcdic (int i) {
- return ebcdic_mm[i] + ebcdic_ii[i];
- }
- int
- main (int argc, char **argv)
- {
- /* Intimidate the compiler so that it does not
- optimize the arrays away. */
- char *p = argv[0];
- ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
- ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
- return use_ascii (argc) == use_ebcdic (*p);
- }]])],
- [if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
- ac_cv_c_bigendian=yes
- fi
- if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
- if test "$ac_cv_c_bigendian" = unknown; then
- ac_cv_c_bigendian=no
- else
-
- ac_cv_c_bigendian=unknown
- fi
- fi])])
- fi])
- case $ac_cv_c_bigendian in
- yes)
- m4_default([$1],
- [AC_DEFINE([WORDS_BIGENDIAN], 1)]);;
- no)
- $2 ;;
- universal)
- dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
- dnl this is a necessity for proper config header operation. Warn if
- dnl the user did not specify a config header but is relying on the
- dnl default behavior for universal builds.
- m4_default([$4],
- [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
- [m4_warn([obsolete],
- [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
- AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
- [Define if building universal (internal helper macro)])])
- ;;
- *)
- m4_default([$3],
- [AC_MSG_ERROR([unknown endianness
- presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
- esac
- ])
- AC_DEFUN([AC_C_VARARRAYS],
- [
- AC_CACHE_CHECK([for variable-length arrays],
- ac_cv_c_vararrays,
- [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
- [[
-
- choke me now
-
- ]])],
- [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
- [AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[/* Test for VLA support. This test is partly inspired
- from examples in the C standard. Use at least two VLA
- functions to detect the GCC 3.4.3 bug described in:
- https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
- */
-
- syntax error;
-
- extern int n;
- static int B[100];
- int fvla (int m, int C[m][m]);
- static int
- simple (int count, int all[static count])
- {
- return all[count - 1];
- }
- int
- fvla (int m, int C[m][m])
- {
- typedef int VLA[m][m];
- VLA x;
- int D[m];
- static int (*q)[m] = &B;
- int (*s)[n] = q;
- (void) simple;
- return C && &x[0][0] == &D[0] && &D[0] == s[0];
- }
-
- ]])],
- [ac_cv_c_vararrays=yes],
- [ac_cv_c_vararrays=no])])])
- if test "$ac_cv_c_vararrays" = yes; then
- dnl This is for compatibility with Autoconf 2.61-2.69.
- AC_DEFINE([HAVE_C_VARARRAYS], 1,
- [Define to 1 if C supports variable-length arrays.])
- elif test "$ac_cv_c_vararrays" = no; then
- AC_DEFINE([__STDC_NO_VLA__], 1,
- [Define to 1 if C does not support variable-length arrays, and
- if the compiler does not already define this.])
- fi
- ])
|