Subject: [PATCH 1/2] gnu: gnulib: Reset the shebangs.

From: Vivien Kraus <[email-masked]>
Date: Tue, 14 Mar 2023 09:58:34 +0100

* gnu/packages/build-tools.scm (gnulib) [phase reset-shebangs]: After
installation, rewrite the /gnu/store shebangs in the distributed build-aux
files.
[inputs, native-inputs]: Add bash-minimal.
[phase let-autogen-execute-gnulib-tool]: Specify a shell to execute
gnulib-tool from autogen.sh.
---
 gnu/packages/build-tools.scm | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 28ab77bbb4..f93a72f2f5 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -973,12 +973,32 @@ (define (find-ucd-files . names)
                    ("NormalizationTest.txt" . "uninorm")
                    ("auxiliary/GraphemeBreakTest.txt" . "unigbrk")
                    ("auxiliary/WordBreakTest.txt" . "uniwbrk")))
-                (delete-file "gen-uni-tables")))))))
-    (inputs ;; Shebangs for some auxiliary build files.
-     (list python perl clisp))
+                (delete-file "gen-uni-tables"))))
+          (add-after 'install 'reset-shebangs
+            (lambda _
+              (for-each
+               (lambda (file)
+                 (false-if-exception
+                  ;; Might fail on binary files, this is not a problem.
+                  (substitute* file
+                    ((#$(file-append (this-package-native-input "bash-minimal")
+                                     "/bin/sh"))
+                     "/bin/sh")
+                    ((#$(file-append (this-package-native-input "python")
+                                     "/bin/python3"))
+                     "/usr/bin/env python3")
+                    ((#$(file-append (this-package-native-input "perl")
+                                     "/bin/perl"))
+                     "/usr/bin/perl")
+                    ((#$(file-append (this-package-native-input "clisp")
+                                     "/bin/clisp"))
+                     "/usr/bin/clisp"))))
+               (find-files (string-append #$output "/src/gnulib"))))))))
+    (inputs ;; Shebang for gnulib-tool
+     (list bash-minimal))
     (native-inputs
      (list
-      python perl clisp
+      bash-minimal python perl clisp
       ;; Unicode data:
       ucd-next
       ;; Programs for the tests:
-- 
2.39.2