getprogname.m4 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # getprogname.m4 - check for getprogname or replacements for it
  2. # Copyright (C) 2016-2017 Free Software Foundation, Inc.
  3. # This file is free software; the Free Software Foundation
  4. # gives unlimited permission to copy and/or distribute it,
  5. # with or without modifications, as long as this notice is preserved.
  6. # serial 4
  7. AC_DEFUN([gl_FUNC_GETPROGNAME],
  8. [
  9. AC_CHECK_FUNCS_ONCE([getprogname getexecname])
  10. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  11. ac_found=0
  12. AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
  13. [#include <errno.h>])
  14. AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
  15. [#include <errno.h>])
  16. AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
  17. # Incur the cost of this test only if none of the above worked.
  18. if test $ac_found = 0; then
  19. # On OpenBSD 5.1, using the global __progname variable appears to be
  20. # the only way to implement getprogname.
  21. AC_CACHE_CHECK([whether __progname is defined in default libraries],
  22. [gl_cv_var___progname],
  23. [
  24. gl_cv_var___progname=
  25. AC_LINK_IFELSE(
  26. [AC_LANG_PROGRAM(
  27. [[extern char *__progname;]],
  28. [[return *__progname;]]
  29. )],
  30. [gl_cv_var___progname=yes]
  31. )
  32. ]
  33. )
  34. if test "$gl_cv_var___progname" = yes; then
  35. AC_DEFINE([HAVE_VAR___PROGNAME], 1,
  36. [Define if you have a global __progname variable])
  37. fi
  38. fi
  39. ])