libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

c_backported.m4 (16830B)


      1 # Backported macros from autoconf git master + a few custom patches
      2 
      3 # This file is part of Autoconf.			-*- Autoconf -*-
      4 # Programming languages support.
      5 # Copyright (C) 2001-2017, 2020-2023 Free Software Foundation, Inc.
      6 
      7 # This file is part of Autoconf.  This program is free
      8 # software; you can redistribute it and/or modify it under the
      9 # terms of the GNU General Public License as published by the
     10 # Free Software Foundation, either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This program is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # Under Section 7 of GPL version 3, you are granted additional
     19 # permissions described in the Autoconf Configure Script Exception,
     20 # version 3.0, as published by the Free Software Foundation.
     21 #
     22 # You should have received a copy of the GNU General Public License
     23 # and a copy of the Autoconf Configure Script Exception along with
     24 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
     25 # respectively.  If not, see <https://www.gnu.org/licenses/>.
     26 
     27 # Written by David MacKenzie, with help from
     28 # Akim Demaille, Paul Eggert,
     29 # François Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
     30 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
     31 
     32 # ---- Backported macros only ----
     33 
     34 AC_DEFUN([_AC_C_C89_TEST_GLOBALS],
     35 [m4_divert_text([INIT_PREPARE],
     36 [[# Test code for whether the C compiler supports C89 (global declarations)
     37 ac_c_conftest_c89_globals='
     38 /* Does the compiler advertise C89 conformance?
     39    Do not test the value of __STDC__, because some compilers set it to 0
     40    while being otherwise adequately conformant. */
     41 #if !defined __STDC__
     42 # error "Compiler does not advertise C89 conformance"
     43 #endif
     44 
     45 #include <stddef.h>
     46 #include <stdarg.h>
     47 struct stat;
     48 /* Most of the following tests are stolen from RCS 5.7 src/conf.sh.  */
     49 struct buf { int x; };
     50 struct buf * (*rcsopen) (struct buf *, struct stat *, int);
     51 static char *e (char **p, int i)
     52 {
     53   return p[i];
     54 }
     55 static char *f (char * (*g) (char **, int), char **p, ...)
     56 {
     57   char *s;
     58   va_list v;
     59   va_start (v,p);
     60   s = g (p, va_arg (v,int));
     61   va_end (v);
     62   return s;
     63 }
     64 
     65 /* C89 style stringification. */
     66 #define noexpand_stringify(a) #a
     67 const char *stringified = noexpand_stringify(arbitrary+token=sequence);
     68 
     69 /* C89 style token pasting.  Exercises some of the corner cases that
     70    e.g. old MSVC gets wrong, but not very hard. */
     71 #define noexpand_concat(a,b) a##b
     72 #define expand_concat(a,b) noexpand_concat(a,b)
     73 extern int vA;
     74 extern int vbee;
     75 #define aye A
     76 #define bee B
     77 int *pvA = &expand_concat(v,aye);
     78 int *pvbee = &noexpand_concat(v,bee);
     79 
     80 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
     81    function prototypes and stuff, but not \xHH hex character constants.
     82    These do not provoke an error unfortunately, instead are silently treated
     83    as an "x".  The following induces an error, until -std is added to get
     84    proper ANSI mode.  Curiously \x00 != x always comes out true, for an
     85    array size at least.  It is necessary to write \x00 == 0 to get something
     86    that is true only with -std.  */
     87 int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];
     88 
     89 /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
     90    inside strings and character constants.  */
     91 #define FOO(x) '\''x'\''
     92 int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];
     93 
     94 int test (int i, double x);
     95 struct s1 {int (*f) (int a);};
     96 struct s2 {int (*f) (double a);};
     97 int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
     98                int, int);'
     99 ]])])
    100 
    101 
    102 AC_DEFUN([_AC_C_C99_TEST_GLOBALS],
    103 [m4_divert_text([INIT_PREPARE],
    104 [[# Test code for whether the C compiler supports C99 (global declarations)
    105 ac_c_conftest_c99_globals='
    106 // Does the compiler advertise C99 conformance?
    107 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
    108 # error "Compiler does not advertise C99 conformance"
    109 #endif
    110 
    111 #include <stdbool.h>
    112 extern int puts (const char *);
    113 extern int printf (const char *, ...);
    114 extern int dprintf (int, const char *, ...);
    115 extern void *malloc (size_t);
    116 extern void free (void *);
    117 
    118 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
    119 // dprintf is used instead of fprintf to avoid needing to declare
    120 // FILE and stderr.
    121 #define debug(...) dprintf (2, __VA_ARGS__)
    122 #define showlist(...) puts (#__VA_ARGS__)
    123 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
    124 static void
    125 test_varargs_macros (void)
    126 {
    127   int x = 1234;
    128   int y = 5678;
    129   debug ("Flag");
    130   debug ("X = %d\n", x);
    131   showlist (The first, second, and third items.);
    132   report (x>y, "x is %d but y is %d", x, y);
    133 }
    134 
    135 // Check long long types.
    136 #define BIG64 18446744073709551615ull
    137 #define BIG32 4294967295ul
    138 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
    139 #if !BIG_OK
    140   #error "your preprocessor is broken"
    141 #endif
    142 #if BIG_OK
    143 #else
    144   #error "your preprocessor is broken"
    145 #endif
    146 static long long int bignum = -9223372036854775807LL;
    147 static unsigned long long int ubignum = BIG64;
    148 
    149 struct incomplete_array
    150 {
    151   int datasize;
    152   double data[];
    153 };
    154 
    155 struct named_init {
    156   int number;
    157   const wchar_t *name;
    158   double average;
    159 };
    160 
    161 typedef const char *ccp;
    162 
    163 static inline int
    164 test_restrict (ccp restrict text)
    165 {
    166   // See if C++-style comments work.
    167   // Iterate through items via the restricted pointer.
    168   // Also check for declarations in for loops.
    169   for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
    170     continue;
    171   return 0;
    172 }
    173 
    174 // Check varargs and va_copy.
    175 static bool
    176 test_varargs (const char *format, ...)
    177 {
    178   va_list args;
    179   va_start (args, format);
    180   va_list args_copy;
    181   va_copy (args_copy, args);
    182 
    183   const char *str = "";
    184   int number = 0;
    185   float fnumber = 0;
    186 
    187   while (*format)
    188     {
    189       switch (*format++)
    190 	{
    191 	case '\''s'\'': // string
    192 	  str = va_arg (args_copy, const char *);
    193 	  break;
    194 	case '\''d'\'': // int
    195 	  number = va_arg (args_copy, int);
    196 	  break;
    197 	case '\''f'\'': // float
    198 	  fnumber = va_arg (args_copy, double);
    199 	  break;
    200 	default:
    201 	  break;
    202 	}
    203     }
    204   va_end (args_copy);
    205   va_end (args);
    206 
    207   return *str && number && fnumber;
    208 }
    209 '
    210 ]])])
    211 
    212 
    213 AC_DEFUN([_AC_C_C11_TEST_GLOBALS],
    214 [m4_divert_text([INIT_PREPARE],
    215 [[# Test code for whether the C compiler supports C11 (global declarations)
    216 ac_c_conftest_c11_globals='
    217 // Does the compiler advertise C11 conformance?
    218 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
    219 # error "Compiler does not advertise C11 conformance"
    220 #endif
    221 
    222 // Check _Alignas.
    223 char _Alignas (double) aligned_as_double;
    224 char _Alignas (0) no_special_alignment;
    225 extern char aligned_as_int;
    226 char _Alignas (0) _Alignas (int) aligned_as_int;
    227 
    228 // Check _Alignof.
    229 enum
    230 {
    231   int_alignment = _Alignof (int),
    232   int_array_alignment = _Alignof (int[100]),
    233   char_alignment = _Alignof (char)
    234 };
    235 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
    236 
    237 // Check _Noreturn.
    238 _Noreturn int does_not_return (void) { for (;;) continue; }
    239 
    240 // Check _Static_assert.
    241 struct test_static_assert
    242 {
    243   int x;
    244   _Static_assert (sizeof (int) <= sizeof (long int),
    245                   "_Static_assert does not work in struct");
    246   long int y;
    247 };
    248 
    249 // Check UTF-8 literals.
    250 #define u8 syntax error!
    251 char const utf8_literal[] = u8"happens to be ASCII" "another string";
    252 
    253 // Check duplicate typedefs.
    254 typedef long *long_ptr;
    255 typedef long int *long_ptr;
    256 typedef long_ptr long_ptr;
    257 
    258 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
    259 struct anonymous
    260 {
    261   union {
    262     struct { int i; int j; };
    263     struct { int k; long int l; } w;
    264   };
    265   int m;
    266 } v1;
    267 '
    268 ]])])
    269 
    270 
    271 # AC_LANG_CALL(C)(PROLOGUE, FUNCTION)
    272 # -----------------------------------
    273 # Avoid conflicting decl of main.
    274 m4_define([AC_LANG_CALL(C)],
    275 [AC_LANG_PROGRAM([$1
    276 m4_if([$2], [main], ,
    277 [/* Override any GCC internal prototype to avoid an error.
    278    Use char because int might match the return type of a GCC
    279    builtin and then its argument prototype would still apply.
    280    The 'extern "C"' is for builds by C++ compilers;
    281    although this is not generally supported in C code supporting it here
    282    has little cost and some practical benefit (sr 110532).  */
    283 #ifdef __cplusplus
    284 extern "C"
    285 #endif
    286 char $2 (void);])], [return $2 ();])])
    287 
    288 
    289 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
    290 # ----------------------------------
    291 # Don't include <ctype.h> because on OSF/1 3.0 it includes
    292 # <sys/types.h> which includes <sys/select.h> which contains a
    293 # prototype for select.  Similarly for bzero.
    294 #
    295 # This test used to merely assign f=$1 in main(), but that was
    296 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
    297 # presumably on the basis that there's no need to do that store if the
    298 # program is about to exit.  Conversely, the AIX linker optimizes an
    299 # unused external declaration that initializes f=$1.  So this test
    300 # program has both an external initialization of f, and a use of f in
    301 # main that affects the exit status.
    302 #
    303 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
    304 [AC_LANG_PROGRAM(
    305 [/* Define $1 to an innocuous variant, in case <limits.h> declares $1.
    306    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
    307 #define $1 innocuous_$1
    308 
    309 /* System header to define __stub macros and hopefully few prototypes,
    310    which can conflict with char $1 (void); below.  */
    311 
    312 #include <limits.h>
    313 #undef $1
    314 
    315 /* Override any GCC internal prototype to avoid an error.
    316    Use char because int might match the return type of a GCC
    317    builtin and then its argument prototype would still apply.  */
    318 #ifdef __cplusplus
    319 extern "C"
    320 #endif
    321 char $1 (void);
    322 /* The GNU C library defines this for functions which it implements
    323     to always fail with ENOSYS.  Some functions are actually named
    324     something starting with __ and the normal name is an alias.  */
    325 #if defined __stub_$1 || defined __stub___$1
    326 choke me
    327 #endif
    328 ], [return $1 ();])])
    329 
    330 
    331 # AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN],
    332 #                 [ACTION-IF-UNIVERSAL])
    333 # -------------------------------------------------------------------------
    334 AC_DEFUN([AC_C_BIGENDIAN],
    335 [AH_VERBATIM([WORDS_BIGENDIAN],
    336 [/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
    337    significant byte first (like Motorola and SPARC, unlike Intel). */
    338 #if defined AC_APPLE_UNIVERSAL_BUILD
    339 # if defined __BIG_ENDIAN__
    340 #  define WORDS_BIGENDIAN 1
    341 # endif
    342 #else
    343 # ifndef WORDS_BIGENDIAN
    344 #  undef WORDS_BIGENDIAN
    345 # endif
    346 #endif])dnl
    347  AC_CACHE_CHECK([whether byte ordering is bigendian], [ac_cv_c_bigendian],
    348    [ac_cv_c_bigendian=unknown
    349     # See if we're dealing with a universal compiler.
    350     AC_COMPILE_IFELSE(
    351 	 [AC_LANG_SOURCE(
    352 	    [[#ifndef __APPLE_CC__
    353 	       not a universal capable compiler
    354 	     #endif
    355 	     typedef int dummy;
    356 	    ]])],
    357 	 [
    358 	# Check for potential -arch flags.  It is not universal unless
    359 	# there are at least two -arch flags with different values.
    360 	ac_arch=
    361 	ac_prev=
    362 	for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
    363 	 if test -n "$ac_prev"; then
    364 	   case $ac_word in
    365 	     i?86 | x86_64 | ppc | ppc64)
    366 	       if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
    367 		 ac_arch=$ac_word
    368 	       else
    369 		 ac_cv_c_bigendian=universal
    370 		 break
    371 	       fi
    372 	       ;;
    373 	   esac
    374 	   ac_prev=
    375 	 elif test "x$ac_word" = "x-arch"; then
    376 	   ac_prev=arch
    377 	 fi
    378        done])
    379     if test $ac_cv_c_bigendian = unknown; then
    380       # See if sys/param.h defines the BYTE_ORDER macro.
    381       AC_COMPILE_IFELSE(
    382 	[AC_LANG_PROGRAM(
    383 	   [[#include <sys/types.h>
    384 	     #include <sys/param.h>
    385 	   ]],
    386 	   [[#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \\
    387 		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
    388 		     && LITTLE_ENDIAN)
    389 	      bogus endian macros
    390 	     #endif
    391 	   ]])],
    392 	[# It does; now see whether it defined to BIG_ENDIAN or not.
    393 	 AC_COMPILE_IFELSE(
    394 	   [AC_LANG_PROGRAM(
    395 	      [[#include <sys/types.h>
    396 		#include <sys/param.h>
    397 	      ]],
    398 	      [[#if BYTE_ORDER != BIG_ENDIAN
    399 		 not big endian
    400 		#endif
    401 	      ]])],
    402 	   [ac_cv_c_bigendian=yes],
    403 	   [ac_cv_c_bigendian=no])])
    404     fi
    405     if test $ac_cv_c_bigendian = unknown; then
    406       # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
    407       AC_COMPILE_IFELSE(
    408 	[AC_LANG_PROGRAM(
    409 	   [[#include <limits.h>
    410 	   ]],
    411 	   [[#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
    412 	      bogus endian macros
    413 	     #endif
    414 	   ]])],
    415 	[# It does; now see whether it defined to _BIG_ENDIAN or not.
    416 	 AC_COMPILE_IFELSE(
    417 	   [AC_LANG_PROGRAM(
    418 	      [[#include <limits.h>
    419 	      ]],
    420 	      [[#ifndef _BIG_ENDIAN
    421 		 not big endian
    422 		#endif
    423 	      ]])],
    424 	   [ac_cv_c_bigendian=yes],
    425 	   [ac_cv_c_bigendian=no])])
    426     fi
    427     if test $ac_cv_c_bigendian = unknown; then
    428       # Compile a test program.
    429       AC_RUN_IFELSE(
    430 	[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
    431 	   [[
    432 	     /* Are we little or big endian?  From Harbison&Steele.  */
    433 	     union
    434 	     {
    435 	       long int l;
    436 	       char c[sizeof (long int)];
    437 	     } u;
    438 	     u.l = 1;
    439 	     return u.c[sizeof (long int) - 1] == 1;
    440 	   ]])],
    441 	[ac_cv_c_bigendian=no],
    442 	[ac_cv_c_bigendian=yes],
    443 	[# Try to guess by grepping values from an object file.
    444 	 AC_LINK_IFELSE(
    445 	   [AC_LANG_SOURCE(
    446 	      [[unsigned short int ascii_mm[] =
    447 		  { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
    448 		unsigned short int ascii_ii[] =
    449 		  { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
    450 		int use_ascii (int i) {
    451 		  return ascii_mm[i] + ascii_ii[i];
    452 		}
    453 		unsigned short int ebcdic_ii[] =
    454 		  { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
    455 		unsigned short int ebcdic_mm[] =
    456 		  { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
    457 		int use_ebcdic (int i) {
    458 		  return ebcdic_mm[i] + ebcdic_ii[i];
    459 		}
    460 		int
    461 		main (int argc, char **argv)
    462 		{
    463 		  /* Intimidate the compiler so that it does not
    464 		     optimize the arrays away.  */
    465 		  char *p = argv[0];
    466 		  ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
    467 		  ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
    468 		  return use_ascii (argc) == use_ebcdic (*p);
    469 		}]])],
    470 	   [if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
    471 	      ac_cv_c_bigendian=yes
    472 	    fi
    473 	    if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
    474 	      if test "$ac_cv_c_bigendian" = unknown; then
    475 		ac_cv_c_bigendian=no
    476 	      else
    477 		# finding both strings is unlikely to happen, but who knows?
    478 		ac_cv_c_bigendian=unknown
    479 	      fi
    480 	    fi])])
    481     fi])
    482  case $ac_cv_c_bigendian in #(
    483    yes)
    484      m4_default([$1],
    485        [AC_DEFINE([WORDS_BIGENDIAN], 1)]);; #(
    486    no)
    487      $2 ;; #(
    488    universal)
    489 dnl Note that AC_APPLE_UNIVERSAL_BUILD sorts less than WORDS_BIGENDIAN;
    490 dnl this is a necessity for proper config header operation.  Warn if
    491 dnl the user did not specify a config header but is relying on the
    492 dnl default behavior for universal builds.
    493      m4_default([$4],
    494        [AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
    495 	 [m4_warn([obsolete],
    496 	   [AC_C_BIGENDIAN should be used with AC_CONFIG_HEADERS])])])dnl
    497 	AC_DEFINE([AC_APPLE_UNIVERSAL_BUILD],1,
    498 	  [Define if building universal (internal helper macro)])])
    499      ;; #(
    500    *)
    501      m4_default([$3],
    502        [AC_MSG_ERROR([unknown endianness
    503  presetting ac_cv_c_bigendian=no (or yes) will help])]) ;;
    504  esac
    505 ])# AC_C_BIGENDIAN
    506 
    507 
    508 # AC_C_VARARRAYS
    509 # --------------
    510 # Check whether the C compiler supports variable-length arrays.
    511 AC_DEFUN([AC_C_VARARRAYS],
    512 [
    513   AC_CACHE_CHECK([for variable-length arrays],
    514     ac_cv_c_vararrays,
    515     [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
    516 [[	#ifndef __STDC_NO_VLA__
    517 	#error __STDC_NO_VLA__ not defined
    518 	choke me now
    519 	#endif
    520 ]])],
    521        [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
    522        [AC_COMPILE_IFELSE(
    523 	  [AC_LANG_PROGRAM(
    524 	     [[/* Test for VLA support.  This test is partly inspired
    525 		  from examples in the C standard.  Use at least two VLA
    526 		  functions to detect the GCC 3.4.3 bug described in:
    527 		  https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
    528 		  */
    529 	       #ifdef __STDC_NO_VLA__
    530 		syntax error;
    531 	       #else
    532 		 extern int n;
    533 		 static int B[100];
    534 		 int fvla (int m, int C[m][m]);
    535 
    536 		 static int
    537 		 simple (int count, int all[static count])
    538 		 {
    539 		   return all[count - 1];
    540 		 }
    541 
    542 		 int
    543 		 fvla (int m, int C[m][m])
    544 		 {
    545 		   typedef int VLA[m][m];
    546 		   VLA x;
    547 		   int D[m];
    548 		   static int (*q)[m] = &B;
    549 		   int (*s)[n] = q;
    550 		   (void) simple;
    551 		   return C && &x[0][0] == &D[0] && &D[0] == s[0];
    552 		 }
    553 	       #endif
    554 	       ]])],
    555 	  [ac_cv_c_vararrays=yes],
    556 	  [ac_cv_c_vararrays=no])])])
    557   if test "$ac_cv_c_vararrays" = yes; then
    558     dnl This is for compatibility with Autoconf 2.61-2.69.
    559     AC_DEFINE([HAVE_C_VARARRAYS], 1,
    560       [Define to 1 if C supports variable-length arrays.])
    561   elif test "$ac_cv_c_vararrays" = no; then
    562     AC_DEFINE([__STDC_NO_VLA__], 1,
    563       [Define to 1 if C does not support variable-length arrays, and
    564        if the compiler does not already define this.])
    565   fi
    566 ])
    567