[745] | 1 | # AC_GNU_SOURCE
|
---|
| 2 | # --------------
|
---|
| 3 | AC_DEFUN([AC_GNU_SOURCE],
|
---|
| 4 | [AH_VERBATIM([_GNU_SOURCE],
|
---|
| 5 | [/* Enable GNU extensions on systems that have them. */
|
---|
| 6 | #ifndef _GNU_SOURCE
|
---|
| 7 | # undef _GNU_SOURCE
|
---|
| 8 | #endif])dnl
|
---|
| 9 | AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
|
---|
| 10 | AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
|
---|
| 11 | AC_DEFINE([_GNU_SOURCE])
|
---|
| 12 | ])
|
---|
| 13 |
|
---|
| 14 | # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
|
---|
| 15 | # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
|
---|
| 16 | # --------------------------------------------------------------
|
---|
| 17 | # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
|
---|
| 18 | # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
|
---|
| 19 | # try again with each compiler option in the space-separated OPTION-LIST; if one
|
---|
| 20 | # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
|
---|
| 21 | # else ACTION-IF-UNAVAILABLE.
|
---|
| 22 | AC_DEFUN([_AC_C_STD_TRY],
|
---|
| 23 | [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
|
---|
| 24 | AC_CACHE_VAL(ac_cv_prog_cc_$1,
|
---|
| 25 | [ac_cv_prog_cc_$1=no
|
---|
| 26 | ac_save_CC=$CC
|
---|
| 27 | AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
|
---|
| 28 | for ac_arg in '' $4
|
---|
| 29 | do
|
---|
| 30 | CC="$ac_save_CC $ac_arg"
|
---|
| 31 | _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
|
---|
| 32 | test "x$ac_cv_prog_cc_$1" != "xno" && break
|
---|
| 33 | done
|
---|
| 34 | rm -f conftest.$ac_ext
|
---|
| 35 | CC=$ac_save_CC
|
---|
| 36 | ])# AC_CACHE_VAL
|
---|
| 37 | case "x$ac_cv_prog_cc_$1" in
|
---|
| 38 | x)
|
---|
| 39 | AC_MSG_RESULT([none needed]) ;;
|
---|
| 40 | xno)
|
---|
| 41 | AC_MSG_RESULT([unsupported]) ;;
|
---|
| 42 | *)
|
---|
| 43 | CC="$CC $ac_cv_prog_cc_$1"
|
---|
| 44 | AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
|
---|
| 45 | esac
|
---|
| 46 | AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
|
---|
| 47 | ])# _AC_C_STD_TRY
|
---|
| 48 |
|
---|
| 49 | # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
|
---|
| 50 | # ----------------------------------------------------------------
|
---|
| 51 | # If the C compiler is not in ISO C99 mode by default, try to add an
|
---|
| 52 | # option to output variable CC to make it so. This macro tries
|
---|
| 53 | # various options that select ISO C99 on some system or another. It
|
---|
| 54 | # considers the compiler to be in ISO C99 mode if it handles mixed
|
---|
| 55 | # code and declarations, _Bool, inline and restrict.
|
---|
| 56 | AC_DEFUN([_AC_PROG_CC_C99],
|
---|
| 57 | [_AC_C_STD_TRY([c99],
|
---|
| 58 | [[#include <stdarg.h>
|
---|
| 59 | #include <stdbool.h>
|
---|
| 60 | #include <stdlib.h>
|
---|
| 61 | #include <wchar.h>
|
---|
| 62 | #include <stdio.h>
|
---|
| 63 |
|
---|
| 64 | struct incomplete_array
|
---|
| 65 | {
|
---|
| 66 | int datasize;
|
---|
| 67 | double data[];
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | struct named_init {
|
---|
| 71 | int number;
|
---|
| 72 | const wchar_t *name;
|
---|
| 73 | double average;
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | typedef const char *ccp;
|
---|
| 77 |
|
---|
| 78 | static inline int
|
---|
| 79 | test_restrict(ccp restrict text)
|
---|
| 80 | {
|
---|
| 81 | // See if C++-style comments work.
|
---|
| 82 | // Iterate through items via the restricted pointer.
|
---|
| 83 | // Also check for declarations in for loops.
|
---|
| 84 | for (unsigned int i = 0; *(text+i) != '\0'; ++i)
|
---|
| 85 | continue;
|
---|
| 86 | return 0;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | // Check varargs and va_copy work.
|
---|
| 90 | static void
|
---|
| 91 | test_varargs(const char *format, ...)
|
---|
| 92 | {
|
---|
| 93 | va_list args;
|
---|
| 94 | va_start(args, format);
|
---|
| 95 | va_list args_copy;
|
---|
| 96 | va_copy(args_copy, args);
|
---|
| 97 |
|
---|
| 98 | const char *str;
|
---|
| 99 | int number;
|
---|
| 100 | float fnumber;
|
---|
| 101 |
|
---|
| 102 | while (*format)
|
---|
| 103 | {
|
---|
| 104 | switch (*format++)
|
---|
| 105 | {
|
---|
| 106 | case 's': // string
|
---|
| 107 | str = va_arg(args_copy, const char *);
|
---|
| 108 | break;
|
---|
| 109 | case 'd': // int
|
---|
| 110 | number = va_arg(args_copy, int);
|
---|
| 111 | break;
|
---|
| 112 | case 'f': // float
|
---|
| 113 | fnumber = (float) va_arg(args_copy, double);
|
---|
| 114 | break;
|
---|
| 115 | default:
|
---|
| 116 | break;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | va_end(args_copy);
|
---|
| 120 | va_end(args);
|
---|
| 121 | }
|
---|
| 122 | ]],
|
---|
| 123 | [[
|
---|
| 124 | // Check bool and long long datatypes.
|
---|
| 125 | _Bool success = false;
|
---|
| 126 | long long int bignum = -1234567890LL;
|
---|
| 127 | unsigned long long int ubignum = 1234567890uLL;
|
---|
| 128 |
|
---|
| 129 | // Check restrict.
|
---|
| 130 | if (test_restrict("String literal") != 0)
|
---|
| 131 | success = true;
|
---|
| 132 | char *restrict newvar = "Another string";
|
---|
| 133 |
|
---|
| 134 | // Check varargs.
|
---|
| 135 | test_varargs("s, d' f .", "string", 65, 34.234);
|
---|
| 136 |
|
---|
| 137 | // Check incomplete arrays work.
|
---|
| 138 | struct incomplete_array *ia =
|
---|
| 139 | malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
|
---|
| 140 | ia->datasize = 10;
|
---|
| 141 | for (int i = 0; i < ia->datasize; ++i)
|
---|
| 142 | ia->data[i] = (double) i * 1.234;
|
---|
| 143 |
|
---|
| 144 | // Check named initialisers.
|
---|
| 145 | struct named_init ni = {
|
---|
| 146 | .number = 34,
|
---|
| 147 | .name = L"Test wide string",
|
---|
| 148 | .average = 543.34343,
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | ni.number = 58;
|
---|
| 152 |
|
---|
| 153 | int dynamic_array[ni.number];
|
---|
| 154 | dynamic_array[43] = 543;
|
---|
| 155 |
|
---|
| 156 | // work around unused variable warnings
|
---|
| 157 | return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
|
---|
| 158 | ]],
|
---|
| 159 | dnl Try
|
---|
| 160 | dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
|
---|
| 161 | dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
|
---|
| 162 | dnl Intel ICC -c99
|
---|
| 163 | dnl IRIX -c99
|
---|
| 164 | dnl Solaris (unused because it causes the compiler to assume C99 semantics for
|
---|
| 165 | dnl library functions, and this is invalid before Solaris 10: -xc99)
|
---|
| 166 | dnl Tru64 -c99
|
---|
| 167 | dnl with extended modes being tried first.
|
---|
| 168 | [[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
|
---|
| 169 | ])# _AC_PROG_CC_C99
|
---|
| 170 |
|
---|
| 171 | # AC_PROG_CC_C99
|
---|
| 172 | # --------------
|
---|
| 173 | AC_DEFUN([AC_PROG_CC_C99],
|
---|
| 174 | [ AC_REQUIRE([AC_PROG_CC])dnl
|
---|
| 175 | _AC_PROG_CC_C99
|
---|
| 176 | ])
|
---|
| 177 |
|
---|
| 178 | # AC_USE_SYSTEM_EXTENSIONS
|
---|
| 179 | # ------------------------
|
---|
| 180 | # Enable extensions on systems that normally disable them,
|
---|
| 181 | # typically due to standards-conformance issues.
|
---|
| 182 | m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[
|
---|
| 183 | AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
|
---|
| 184 | [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
|
---|
| 185 | AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
|
---|
| 186 |
|
---|
| 187 | AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
|
---|
| 188 | if test "$MINIX" = yes; then
|
---|
| 189 | AC_DEFINE([_POSIX_SOURCE], [1],
|
---|
| 190 | [Define to 1 if you need to in order for `stat' and other
|
---|
| 191 | things to work.])
|
---|
| 192 | AC_DEFINE([_POSIX_1_SOURCE], [2],
|
---|
| 193 | [Define to 2 if the system does not provide POSIX.1 features
|
---|
| 194 | except with this defined.])
|
---|
| 195 | AC_DEFINE([_MINIX], [1],
|
---|
| 196 | [Define to 1 if on MINIX.])
|
---|
| 197 | fi
|
---|
| 198 |
|
---|
| 199 | AH_VERBATIM([__EXTENSIONS__],
|
---|
| 200 | [/* Enable extensions on AIX 3, Interix. */
|
---|
| 201 | #ifndef _ALL_SOURCE
|
---|
| 202 | # undef _ALL_SOURCE
|
---|
| 203 | #endif
|
---|
| 204 | /* Enable GNU extensions on systems that have them. */
|
---|
| 205 | #ifndef _GNU_SOURCE
|
---|
| 206 | # undef _GNU_SOURCE
|
---|
| 207 | #endif
|
---|
| 208 | /* Enable threading extensions on Solaris. */
|
---|
| 209 | #ifndef _POSIX_PTHREAD_SEMANTICS
|
---|
| 210 | # undef _POSIX_PTHREAD_SEMANTICS
|
---|
| 211 | #endif
|
---|
| 212 | /* Enable extensions on HP NonStop. */
|
---|
| 213 | #ifndef _TANDEM_SOURCE
|
---|
| 214 | # undef _TANDEM_SOURCE
|
---|
| 215 | #endif
|
---|
| 216 | /* Enable general extensions on Solaris. */
|
---|
| 217 | #ifndef __EXTENSIONS__
|
---|
| 218 | # undef __EXTENSIONS__
|
---|
| 219 | #endif
|
---|
| 220 | ])
|
---|
| 221 | AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
|
---|
| 222 | [ac_cv_safe_to_define___extensions__],
|
---|
| 223 | [AC_COMPILE_IFELSE(
|
---|
| 224 | [AC_LANG_PROGRAM([[
|
---|
| 225 | # define __EXTENSIONS__ 1
|
---|
| 226 | ]AC_INCLUDES_DEFAULT])],
|
---|
| 227 | [ac_cv_safe_to_define___extensions__=yes],
|
---|
| 228 | [ac_cv_safe_to_define___extensions__=no])])
|
---|
| 229 | test $ac_cv_safe_to_define___extensions__ = yes &&
|
---|
| 230 | AC_DEFINE([__EXTENSIONS__])
|
---|
| 231 | AC_DEFINE([_ALL_SOURCE])
|
---|
| 232 | AC_DEFINE([_GNU_SOURCE])
|
---|
| 233 | AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
|
---|
| 234 | AC_DEFINE([_TANDEM_SOURCE])
|
---|
| 235 | ])# AC_USE_SYSTEM_EXTENSIONS
|
---|
| 236 | ])
|
---|