Subject: [bug#53920] [PATCH v2] gnu: lesspipe: Update to 2.02.

From: Hartmut Goebel <[email-masked]>
Date: Tue, 22 Feb 2022 10:16:59 +0100

* gnu/packages/less.scm (lesspipe): Update to 2.02.
  [arguments]<phases>{configure} Adjust to updated source.
  {fix-makefile}: New phase.
  {patch-tput-and-file}: rename into …
  {patch-command-paths}: this; patch other relevant scripts.
---
 gnu/packages/less.scm | 58 +++++++++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/gnu/packages/less.scm b/gnu/packages/less.scm
index e23b5d0c24..a9775ecdf0 100644
--- a/gnu/packages/less.scm
+++ b/gnu/packages/less.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2019–2021 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2020, 2021 Michael Rohleder <[email-masked]>
+;;; Copyright © 2022 Hartmut Goebel <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -59,38 +60,53 @@ text editors.")
 (define-public lesspipe
   (package
     (name "lesspipe")
-    (version "1.91")
+    (version "2.02")
     (source (origin
               (method git-fetch)
               (uri (git-reference
                     (url "https://github.com/wofr06/lesspipe")
-                    (commit version)))
+                    (commit (string-append "v" version))))
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "04dqvq6j4h451xqbvxzv6pv679hzzfm39pdm5vg7h3r45gzg0kps"))))
+                "15lcgawwqlpwa3kra44nnyx0jmidjqdq45xcr5q90kz8iqix3ll7"))))
     (build-system gnu-build-system)
     (arguments
      '(#:tests? #f                      ; no tests
-       #:phases (modify-phases %standard-phases
-                  (replace 'configure
-                    (lambda* (#:key outputs #:allow-other-keys)
-                      (let ((out (assoc-ref outputs "out")))
-                        (delete-file "Makefile") ; force generating
-                        (invoke "./configure"
-                                (string-append "--prefix=" out)
-                                "--yes"))))
-                  (add-before 'install 'patch-tput-and-file
-                    (lambda* (#:key inputs #:allow-other-keys)
-                      (substitute* "lesspipe.sh"
-                        (("tput colors")
-                         (string-append (search-input-file inputs "/bin/tput")
-                                        " colors"))
-                        (("file -")
-                         (string-append (search-input-file inputs "/bin/file")
-                                        " -"))))))))
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; configure is a perl script which the standard configure phase
+             ;; fails to execute
+             (invoke "./configure"
+                     (string-append "--prefix=" (assoc-ref outputs "out")))))
+         (add-before 'install 'fix-makefile
+           (lambda _
+               (substitute* "Makefile"
+                 (("\\$\\(DESTDIR\\)/etc") "$(DESTDIR)$(PREFIX)/etc"))))
+         (add-before 'install 'patch-command-paths
+           ;; Depending on the content of the file to be displayed and some
+           ;; settings, lesspipe trees to use a large variety of external
+           ;; commands, e.g. rpm, dpkg, vimcolor.  We only link the essential
+           ;; ones to avoid this package to pull in all these dependencies
+           ;; which might never ever we used.
+           (lambda* (#:key inputs #:allow-other-keys)
+             (let ((file (search-input-file inputs "/bin/file"))
+                   (tput (search-input-file inputs "/bin/tput")))
+               (substitute* "sxw2txt"
+                 (("^use warnings;" line)
+                  (string-append line "use lib '" file "';")))
+               (substitute* "lesscomplete"
+                 (("file -") (string-append file " -")))
+               (substitute* "lesspipe.sh"
+                 (("tput colors")
+                  (string-append tput " colors"))
+                 (("file -")
+                  (string-append file " -")))))))))
     (inputs
-     (list file ncurses))  ; for tput
+     (list file
+           ncurses))  ; for tput
     (native-inputs (list perl))
     (home-page "https://github.com/wofr06/lesspipe")
     (synopsis "Input filter for less")
-- 
2.30.2