aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2025-05-06 09:42:40 +0100
committerIain Sandoe <iain@sandoe.co.uk>2025-05-06 14:37:48 +0100
commit67e79da5a3c0deb93cd6df1557affb6994440357 (patch)
tree229ec2efef1072670a207ca3f8f57b3c2c8f2610
parentf4fa41cd5ccbcc1a45e68c15bda2461e8d7215b9 (diff)
downloadgcc-67e79da5a3c0deb93cd6df1557affb6994440357.zip
gcc-67e79da5a3c0deb93cd6df1557affb6994440357.tar.gz
gcc-67e79da5a3c0deb93cd6df1557affb6994440357.tar.bz2
libgcobol: Fix bootstrap for targets without program_invocation_short_name
program_invocation_short_name is not widely available, however getprogname() appears to be a suitable replacement. Amend the library configuration to look for both. Use program_invocation_short_name in preference to getprogname() when it is available. If neither is found fall back to a constant string. libgcobol/ChangeLog: * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Check for program_invocation_short_name and and getprogname(). * libgcobol.cc (default_exception_handler): When the platform has program_invocation_short_name, use it otherwise fall back to using getprogname() or a constant string (if neither interface is available). Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
-rw-r--r--libgcobol/config.h.in10
-rwxr-xr-xlibgcobol/configure81
-rw-r--r--libgcobol/configure.ac14
-rw-r--r--libgcobol/libgcobol.cc15
4 files changed, 114 insertions, 6 deletions
diff --git a/libgcobol/config.h.in b/libgcobol/config.h.in
index fdf5e3e..ee3dd6b 100644
--- a/libgcobol/config.h.in
+++ b/libgcobol/config.h.in
@@ -6,9 +6,16 @@
/* Define to 1 if you have the <complex.h> header file. */
#undef HAVE_COMPLEX_H
+/* Define to 1 if you have the declaration of `program_invocation_short_name',
+ and to 0 if you don't. */
+#undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
+/* Define to 1 if you have the <errno.h> header file. */
+#undef HAVE_ERRNO_H
+
/* Define to 1 if you have the <fenv.h> header file. */
#undef HAVE_FENV_H
@@ -21,6 +28,9 @@
/* Define to 1 if you have the <fptrap.h> header file. */
#undef HAVE_FPTRAP_H
+/* Define to 1 if you have the `getprogname' function. */
+#undef HAVE_GETPROGNAME
+
/* Define if you have the iconv() function and it works. */
#undef HAVE_ICONV
diff --git a/libgcobol/configure b/libgcobol/configure
index 6821591..06e7544 100755
--- a/libgcobol/configure
+++ b/libgcobol/configure
@@ -2380,6 +2380,52 @@ $as_echo "$ac_res" >&6; }
} # ac_fn_cxx_check_header_compile
+# ac_fn_cxx_check_decl LINENO SYMBOL VAR INCLUDES
+# -----------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_cxx_check_decl ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ as_decl_name=`echo $2|sed 's/ *(.*//'`
+ as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+ (void) $as_decl_use;
+#else
+ (void) $as_decl_name;
+#endif
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_cxx_check_decl
+
# ac_fn_cxx_check_func LINENO FUNC VAR
# ------------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
@@ -2796,6 +2842,8 @@ as_fn_append ac_header_list " fenv.h"
as_fn_append ac_header_list " fptrap.h"
as_fn_append ac_header_list " complex.h"
as_fn_append ac_header_list " stdlib.h"
+as_fn_append ac_header_list " errno.h"
+as_fn_append ac_func_list " getprogname"
as_fn_append ac_func_list " random_r"
as_fn_append ac_func_list " srandom_r"
as_fn_append ac_func_list " initstate_r"
@@ -11750,7 +11798,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11753 "configure"
+#line 11801 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11856,7 +11904,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11859 "configure"
+#line 11907 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -17016,7 +17064,29 @@ done
-# These are GLIBC
+
+
+# Look for a way to represent the program name
+# First, check the GLIBC case
+ac_fn_cxx_check_decl "$LINENO" "program_invocation_short_name" "ac_cv_have_decl_program_invocation_short_name" "
+#if HAVE_ERRNO_H
+# define _GNU_SOURCE
+# include <errno.h>
+#endif
+
+"
+if test "x$ac_cv_have_decl_program_invocation_short_name" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME $ac_have_decl
+_ACEOF
+
+
+# Check an alternate
@@ -17036,6 +17106,11 @@ done
+# These are GLIBC
+
+
+
+
diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac
index 4bb6905..e254763 100644
--- a/libgcobol/configure.ac
+++ b/libgcobol/configure.ac
@@ -188,7 +188,19 @@ esac
AC_SUBST(extra_ldflags_libgcobol)
AC_CHECK_HEADERS_ONCE(floatingpoint.h ieeefp.h fenv.h fptrap.h \
-complex.h stdlib.h)
+complex.h stdlib.h errno.h)
+
+# Look for a way to represent the program name
+# First, check the GLIBC case
+AC_CHECK_DECLS([program_invocation_short_name], , ,[
+#if HAVE_ERRNO_H
+# define _GNU_SOURCE
+# include <errno.h>
+#endif
+])
+
+# Check an alternate
+AC_CHECK_FUNCS_ONCE(getprogname)
# These are GLIBC
AC_CHECK_FUNCS_ONCE(random_r srandom_r initstate_r setstate_r)
diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc
index 2fefd14..d5fa5b1 100644
--- a/libgcobol/libgcobol.cc
+++ b/libgcobol/libgcobol.cc
@@ -50,6 +50,9 @@
#include <signal.h>
#include <syslog.h>
#include <unistd.h>
+#if __has_include(<errno.h>)
+# include <errno.h> // for program_invocation_short_name
+#endif
#include "config.h"
#include "libgcobol-fp.h"
@@ -11179,10 +11182,18 @@ match_declarative( bool enabled,
static void
default_exception_handler( ec_type_t ec )
{
- extern char *program_invocation_short_name;
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+ /* Declared in errno.h, when available. */
+ const char *ident = program_invocation_short_name;
+#elif defined (HAVE_GETPROGNAME)
+ /* Declared in stdlib.h. */
+ const char *ident = getprogname();
+#else
+ /* Avoid a NULL entry. */
+ const char *ident = "unnamed_COBOL_program";
+#endif
static bool first_time = true;
static int priority = LOG_INFO, option = LOG_PERROR, facility = LOG_USER;
- const char *ident = program_invocation_short_name;
ec_disposition_t disposition = ec_category_fatal_e;
if( first_time ) {