Debian Codegraph @

m4/getprogname.m4

raw
1 # getprogname.m4
2 # serial 8
3 dnl Copyright (C) 2016-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 # Check for getprogname or replacements for it
10
11 AC_DEFUN([gl_FUNC_GETPROGNAME],
12 [
13 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 gl_CHECK_FUNCS_ANDROID([getprogname], [[#include <stdlib.h>]])
16 if test $ac_cv_func_getprogname = no; then
17 HAVE_GETPROGNAME=0
18 case "$gl_cv_onwards_func_getprogname" in
19 future*) REPLACE_GETPROGNAME=1 ;;
20 esac
21 fi
22 AC_CHECK_DECLS([program_invocation_name],
23 [],
24 [HAVE_DECL_PROGRAM_INVOCATION_NAME=0],
25 [[#include <errno.h>]])
26 ])
27
28 AC_DEFUN([gl_PREREQ_GETPROGNAME],
29 [
30 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
31 AC_CHECK_FUNCS_ONCE([getexecname])
32 ac_found=0
33 AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
34 [#include <errno.h>])
35 AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
36 [#include <errno.h>])
37 AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
38
39 # Incur the cost of this test only if none of the above worked.
40 if test $ac_found = 0; then
41 # On OpenBSD 5.1, using the global __progname variable appears to be
42 # the only way to implement getprogname.
43 AC_CACHE_CHECK([whether __progname is defined in default libraries],
44 [gl_cv_var___progname],
45 [
46 gl_cv_var___progname=
47 AC_LINK_IFELSE(
48 [AC_LANG_PROGRAM(
49 [[extern char *__progname;]],
50 [[return *__progname;]]
51 )],
52 [gl_cv_var___progname=yes]
53 )
54 ]
55 )
56 if test "$gl_cv_var___progname" = yes; then
57 AC_DEFINE([HAVE_VAR___PROGNAME], 1,
58 [Define if you have a global __progname variable])
59 fi
60 fi
61 ])