stddef_h.m4 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # stddef_h.m4 serial 12
  2. dnl Copyright (C) 2009-2023 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. dnl A placeholder for <stddef.h>, for platforms that have issues.
  7. AC_DEFUN_ONCE([gl_STDDEF_H],
  8. [
  9. AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
  10. AC_REQUIRE([gt_TYPE_WCHAR_T])
  11. dnl Persuade OpenBSD <stddef.h> to declare max_align_t.
  12. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  13. GL_GENERATE_STDDEF_H=false
  14. dnl Test whether the type max_align_t exists and whether its alignment
  15. dnl "is as great as is supported by the implementation in all contexts".
  16. AC_CACHE_CHECK([for good max_align_t],
  17. [gl_cv_type_max_align_t],
  18. [AC_COMPILE_IFELSE(
  19. [AC_LANG_PROGRAM(
  20. [[#include <stddef.h>
  21. unsigned int s = sizeof (max_align_t);
  22. #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
  23. int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
  24. int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
  25. #endif
  26. typedef struct { char a; max_align_t b; } max_helper;
  27. typedef struct { char a; long b; } long_helper;
  28. typedef struct { char a; double b; } double_helper;
  29. typedef struct { char a; long double b; } long_double_helper;
  30. int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1];
  31. int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1];
  32. int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1];
  33. ]])],
  34. [gl_cv_type_max_align_t=yes],
  35. [gl_cv_type_max_align_t=no])
  36. ])
  37. if test $gl_cv_type_max_align_t = no; then
  38. HAVE_MAX_ALIGN_T=0
  39. GL_GENERATE_STDDEF_H=true
  40. fi
  41. if test $gt_cv_c_wchar_t = no; then
  42. HAVE_WCHAR_T=0
  43. GL_GENERATE_STDDEF_H=true
  44. fi
  45. AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
  46. [gl_cv_decl_null_works],
  47. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
  48. int test[2 * (sizeof NULL == sizeof (void *)) -1];
  49. ]])],
  50. [gl_cv_decl_null_works=yes],
  51. [gl_cv_decl_null_works=no])])
  52. if test $gl_cv_decl_null_works = no; then
  53. REPLACE_NULL=1
  54. GL_GENERATE_STDDEF_H=true
  55. fi
  56. if $GL_GENERATE_STDDEF_H; then
  57. gl_NEXT_HEADERS([stddef.h])
  58. fi
  59. ])
  60. # gl_STDDEF_MODULE_INDICATOR([modulename])
  61. # sets the shell variable that indicates the presence of the given module
  62. # to a C preprocessor expression that will evaluate to 1.
  63. # This macro invocation must not occur in macros that are AC_REQUIREd.
  64. AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
  65. [
  66. dnl Ensure to expand the default settings once only.
  67. gl_STDDEF_H_REQUIRE_DEFAULTS
  68. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  69. ])
  70. # Initializes the default values for AC_SUBSTed shell variables.
  71. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  72. # outside of macros or in macros that are not AC_REQUIREd.
  73. AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS],
  74. [
  75. m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [
  76. ])
  77. m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS])
  78. AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
  79. ])
  80. AC_DEFUN([gl_STDDEF_H_DEFAULTS],
  81. [
  82. dnl Assume proper GNU behavior unless another module says otherwise.
  83. REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
  84. HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T])
  85. HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])
  86. ])