environ.m4 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # environ.m4 serial 8
  2. dnl Copyright (C) 2001-2004, 2006-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. AC_DEFUN_ONCE([gl_ENVIRON],
  7. [
  8. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  9. dnl Persuade glibc <unistd.h> to declare environ.
  10. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  11. AC_CHECK_HEADERS_ONCE([unistd.h])
  12. gt_CHECK_VAR_DECL(
  13. [#if HAVE_UNISTD_H
  14. #include <unistd.h>
  15. #endif
  16. /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
  17. #include <stdlib.h>
  18. ],
  19. [environ])
  20. if test $gt_cv_var_environ_declaration != yes; then
  21. HAVE_DECL_ENVIRON=0
  22. fi
  23. ])
  24. # Check if a variable is properly declared.
  25. # gt_CHECK_VAR_DECL(includes,variable)
  26. AC_DEFUN([gt_CHECK_VAR_DECL],
  27. [
  28. define([gt_cv_var], [gt_cv_var_]$2[_declaration])
  29. AC_CACHE_CHECK([if $2 is properly declared], [gt_cv_var],
  30. [AC_COMPILE_IFELSE(
  31. [AC_LANG_PROGRAM(
  32. [[$1
  33. typedef struct { int foo; } foo_t;
  34. extern foo_t $2;]],
  35. [[$2.foo = 1;]])],
  36. [gt_cv_var=no],
  37. [gt_cv_var=yes])])
  38. if test $gt_cv_var = yes; then
  39. AC_DEFINE([HAVE_]m4_translit($2, [a-z], [A-Z])[_DECL], 1,
  40. [Define if you have the declaration of $2.])
  41. fi
  42. undefine([gt_cv_var])
  43. ])