summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
Diffstat (limited to 'guix')
-rw-r--r--guix/build/gnu-build-system.scm30
-rw-r--r--guix/build/utils.scm5
2 files changed, 33 insertions, 2 deletions
diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm
index 8636931ed9..17fa7afd8d 100644
--- a/guix/build/gnu-build-system.scm
+++ b/guix/build/gnu-build-system.scm
@@ -106,6 +106,35 @@ working directory."
(and (zero? (system* "tar" "xvf" source))
(chdir (first-subdirectory ".")))))
+;; See <http://bugs.gnu.org/17840>.
+(define* (patch-usr-bin-file #:key native-inputs inputs
+ (patch-/usr/bin/file? #t)
+ #:allow-other-keys)
+ "Patch occurrences of /usr/bin/file in configure, if present."
+ (when patch-/usr/bin/file?
+ (let ((file "configure")
+ (file-command (or (and=> (assoc-ref (or native-inputs inputs) "file")
+ (cut string-append <> "/bin/file"))
+ (which "file"))))
+ (cond ((not (file-exists? file))
+ (format (current-error-port)
+ "patch-usr-bin-file: warning: `~a' not found~%"
+ file))
+ ((not file-command)
+ (format (current-error-port)
+ "patch-usr-bin-file: warning: `file' not found in PATH~%"))
+ (else
+ (let ((st (stat file)))
+ (substitute* file
+ (("/usr/bin/file")
+ (begin
+ (format (current-error-port)
+ "patch-usr-bin-file: ~a: changing `~a' to `~a'~%"
+ file "/usr/bin/file" file-command)
+ file-command)))
+ (set-file-time file st))))))
+ #t)
+
(define* (patch-source-shebangs #:key source #:allow-other-keys)
"Patch shebangs in all source files; this includes non-executable
files such as `.in' templates. Most scripts honor $SHELL and
@@ -353,6 +382,7 @@ makefiles."
(let-syntax ((phases (syntax-rules ()
((_ p ...) `((p . ,p) ...)))))
(phases set-paths unpack
+ patch-usr-bin-file
patch-source-shebangs configure patch-generated-file-shebangs
build check install
patch-shebangs strip)))
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 2f3dc9cad0..d169053c7b 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -582,14 +582,15 @@ When KEEP-MTIME? is true, the atime/mtime of FILE are kept unchanged."
(let ((st (stat file)))
(substitute* file
- (("^ *SHELL[[:blank:]]*=[[:blank:]]*([[:graph:]]*/)([[:graph:]]+)[[:blank:]]*" _ dir shell)
+ (("^ *SHELL[[:blank:]]*=[[:blank:]]*([[:graph:]]*/)([[:graph:]]+)(.*)$"
+ _ dir shell args)
(let* ((old (string-append dir shell))
(new (or (find-shell shell) old)))
(unless (string=? new old)
(format (current-error-port)
"patch-makefile-SHELL: ~a: changing `SHELL' from `~a' to `~a'~%"
file old new))
- (string-append "SHELL = " new "\n"))))
+ (string-append "SHELL = " new args))))
(when keep-mtime?
(set-file-time file st))))