stack-trace: Use libasan as an alternative to libbacktrace.
[gnulib.git] / m4 / getprogname.m4
blobb24f44805556dd6a18ea129742c49ea6e462c3dc
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.
8 # Check for getprogname or replacements for it
10 AC_DEFUN([gl_FUNC_GETPROGNAME],
12   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14   gl_CHECK_FUNCS_ANDROID([getprogname], [[#include <stdlib.h>]])
15   if test $ac_cv_func_getprogname = no; then
16     HAVE_GETPROGNAME=0
17     case "$gl_cv_onwards_func_getprogname" in
18       future*) REPLACE_GETPROGNAME=1 ;;
19     esac
20   fi
21   AC_CHECK_DECLS([program_invocation_name],
22     [],
23     [HAVE_DECL_PROGRAM_INVOCATION_NAME=0],
24     [[#include <errno.h>]])
27 AC_DEFUN([gl_PREREQ_GETPROGNAME],
29   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
30   AC_CHECK_FUNCS_ONCE([getexecname])
31   ac_found=0
32   AC_CHECK_DECLS([program_invocation_name], [ac_found=1], [],
33     [#include <errno.h>])
34   AC_CHECK_DECLS([program_invocation_short_name], [ac_found=1], [],
35     [#include <errno.h>])
36   AC_CHECK_DECLS([__argv], [ac_found=1], [], [#include <stdlib.h>])
38   # Incur the cost of this test only if none of the above worked.
39   if test $ac_found = 0; then
40     # On OpenBSD 5.1, using the global __progname variable appears to be
41     # the only way to implement getprogname.
42     AC_CACHE_CHECK([whether __progname is defined in default libraries],
43       [gl_cv_var___progname],
44       [
45         gl_cv_var___progname=
46         AC_LINK_IFELSE(
47           [AC_LANG_PROGRAM(
48             [[extern char *__progname;]],
49             [[return *__progname;]]
50           )],
51           [gl_cv_var___progname=yes]
52         )
53       ]
54     )
55     if test "$gl_cv_var___progname" = yes; then
56       AC_DEFINE([HAVE_VAR___PROGNAME], 1,
57         [Define if you have a global __progname variable])
58     fi
59   fi