Blame m4/getprogname.m4

Packit 8f70b4
# getprogname.m4 - check for getprogname or replacements for it
Packit 8f70b4
Packit 8f70b4
# Copyright (C) 2016-2018 Free Software Foundation, Inc.
Packit 8f70b4
# This file is free software; the Free Software Foundation
Packit 8f70b4
# gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
# with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
# serial 4
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_GETPROGNAME],
Packit 8f70b4
[
Packit 8f70b4
  AC_CHECK_FUNCS_ONCE([getprogname getexecname])
Packit 8f70b4
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
Packit 8f70b4
  ac_found=0
Packit 8f70b4
  AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
Packit 8f70b4
    [#include <errno.h>])
Packit 8f70b4
  AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
Packit 8f70b4
    [#include <errno.h>])
Packit 8f70b4
  AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
Packit 8f70b4
Packit 8f70b4
  # Incur the cost of this test only if none of the above worked.
Packit 8f70b4
  if test $ac_found = 0; then
Packit 8f70b4
    # On OpenBSD 5.1, using the global __progname variable appears to be
Packit 8f70b4
    # the only way to implement getprogname.
Packit 8f70b4
    AC_CACHE_CHECK([whether __progname is defined in default libraries],
Packit 8f70b4
      [gl_cv_var___progname],
Packit 8f70b4
      [
Packit 8f70b4
        gl_cv_var___progname=
Packit 8f70b4
        AC_LINK_IFELSE(
Packit 8f70b4
          [AC_LANG_PROGRAM(
Packit 8f70b4
            [[extern char *__progname;]],
Packit 8f70b4
            [[return *__progname;]]
Packit 8f70b4
          )],
Packit 8f70b4
          [gl_cv_var___progname=yes]
Packit 8f70b4
        )
Packit 8f70b4
      ]
Packit 8f70b4
    )
Packit 8f70b4
    if test "$gl_cv_var___progname" = yes; then
Packit 8f70b4
      AC_DEFINE([HAVE_VAR___PROGNAME], 1,
Packit 8f70b4
        [Define if you have a global __progname variable])
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
])