* configure.ac: Accept and validate --program-prefix
with --enable-single-binary={symlinks,hardlinks}.
* src/coreutils.c: Also match the prefixed name.
Note this is done before the standard name match
so edge cases like --prefix=un are handled wrt "link" and "unlink".
* NEWS: Mention the Build-related change.
---
 NEWS            |  3 +++
 configure.ac    | 33 ++++++++++++++++++++++++++-------
 src/coreutils.c |  6 ++++++
 3 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index 2aaddbed7..c63e5cffe 100644
--- a/NEWS
+++ b/NEWS
@@ -520,6 +520,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   The configure option '--disable-libsmack' is consolidated to
   '--without-libsmack'.  The option '--disable-libsmack' is now deprecated.
 
+  The configure options --enable-single-binary=symlinks and =hardlinks
+  now support --program-prefix, e.g. --program-prefix=gnu.
+
 
 * Noteworthy changes in release 9.12 (2026-09-14) [stable]
 
diff --git a/configure.ac b/configure.ac
index c1fb9a032..5f23e6d1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,13 +131,6 @@ AC_ARG_ENABLE([single-binary-exceptions],
   [gl_single_binary_exceptions=$enableval],
   [gl_single_binary_exceptions=]
 )
-if test "$gl_single_binary" = 'symlinks' ||
-   test "$gl_single_binary" = 'hardlinks'; then
-  if ! test "`echo ls | sed \"$program_transform_name\"`" = 'ls'; then
-    AC_MSG_ERROR([program name transformations are not currently supported
-                  with --enable-single-binary=$gl_single_binary.])
-  fi
-fi
 AM_CONDITIONAL([SINGLE_BINARY], [test "$gl_single_binary" != no])
 AM_CONDITIONAL([SINGLE_BINARY_HARD], [test "$gl_single_binary" = hardlinks])
 
@@ -914,6 +907,32 @@ if test "$gl_single_binary" != no; then
     esac
   done
 
+  if test "$gl_single_binary" != shebangs; then
+    case $program_prefix in
+      -*) AC_MSG_ERROR([--program-prefix must not start with '-'
+                        with --enable-single-binary=$gl_single_binary]) ;;
+      NONE) cu_prefix= ;;
+      *) cu_prefix=$program_prefix ;;
+    esac
+    # Check the installed names of the dispatcher and all its links.
+    cu_names=$(printf '%s\n' coreutils $single_binary_progs |
+               sed 's/^ginstall$/install/')
+    cu_expected=$(for p in $cu_names; do printf '%s\n' "$cu_prefix$p"; done)
+    # Undo the quoting of '\' and '$' for make.
+    cu_transform=$(printf '%s\n' "$program_transform_name" |
+                   sed 's/\([[\\$]]\)\1/\1/g')
+    if test "$(printf '%s\n' "$cu_names" | sed "$cu_transform")" \
+         != "$cu_expected"; then
+      AC_MSG_ERROR([only --program-prefix is supported for renaming programs
+                    with --enable-single-binary=$gl_single_binary.])
+    fi
+    if test -n "$cu_prefix"; then
+      cu_quoted_prefix=$(printf '%s\n' "$cu_prefix" | sed 's/[[\\"]]/\\&/g')
+      AC_DEFINE_UNQUOTED([SINGLE_BINARY_PROGRAM_PREFIX], ["$cu_quoted_prefix"],
+        [Prefix to try on multi-call symlink or hardlink names.])
+    fi
+  fi
+
   # single_binary_libs holds the list of libs required by the selected
   # programs, such as for example -lrt.
   single_binary_libs=`
diff --git a/src/coreutils.c b/src/coreutils.c
index 66b658e25..07179b912 100644
--- a/src/coreutils.c
+++ b/src/coreutils.c
@@ -176,6 +176,12 @@ main (int argc, char **argv)
   char *prog_name = last_component (invocation);
   int optc;
 
+#ifdef SINGLE_BINARY_PROGRAM_PREFIX
+  char const *prefix = SINGLE_BINARY_PROGRAM_PREFIX;
+  if (STRPREFIX (prog_name, prefix))
+    launch_program (prog_name + strlen (prefix), argc, argv);
+#endif
+
   /* A built-in selected by argv[0] takes precedence over argv[1].  */
   launch_program (prog_name, argc, argv);
 
-- 
2.56.0


Reply via email to