Blame m4/getprogname.m4

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