Blame m4/getprogname.m4

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