Subject: [PATCH 3/3] gnu: grub: build from git source.

From: Denis 'GNUtoo' Carikli <[email-masked]>
Date: Tue, 11 Feb 2025 18:14:55 +0100

* gnu/packages/bootloaders.scm (grub)
  [source]: Switch to git-fetch, don't overwrite grub-core/extra_deps.lst.
  [native-inputs]: Add autoconf, automake, gnulib-2022-02-12, python.
  [arguments]<phases>: Add 'bootstrap phase.

Signed-off-by: Denis 'GNUtoo' Carikli <[email-masked]>
Change-Id: I894e7dcac719a4d20dc82685af7a31110a023b50
---
 gnu/packages/bootloaders.scm | 59 ++++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 13 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index b5cfacca4bc..86fff61ad7d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -15,7 +15,7 @@
 ;;; Copyright © 2020, 2021 Pierre Langlois <[email-masked]>
 ;;; Copyright © 2021 Vincent Legoll <[email-masked]>
 ;;; Copyright © 2021 Brice Waegeneire <[email-masked]>
-;;; Copyright © 2022, 2023 Denis 'GNUtoo' Carikli <[email-masked]>
+;;; Copyright © 2022-2023, 2025 Denis 'GNUtoo' Carikli <[email-masked]>
 ;;; Copyright © 2021 Stefan <[email-masked]>
 ;;; Copyright © 2022, 2023, 2024 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2023 Herman Rimm <[email-masked]>
@@ -40,7 +40,9 @@
 (define-module (gnu packages bootloaders)
   #:use-module (gnu packages)
   #:use-module (gnu packages assembly)
+  #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
+  #:use-module (gnu packages build-tools)
   #:use-module (gnu packages disk)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages cdrom)
@@ -112,22 +114,20 @@ (define-public grub
     (name "grub")
     (version "2.12")
     (source (origin
-              (method url-fetch)
-              (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://git.savannah.gnu.org/git/grub.git")
+                    (commit (string-append "grub-" version))))
               (sha256
                (base32
-                "1ahgzvvvwdxx7rl08pv5dyqlgp76jxz0q2cflxvsdsn4yy8p7jgk"))
+                "05x4sli80ybpi38pj0313pg2ip2dd4lflz64hymvnzzn2sq63awm"))
+              (file-name (git-file-name name version))
               (patches (search-patches
                         "grub-efi-fat-serial-number.patch"
                         "grub-setup-root.patch"))
               (modules '((guix build utils)))
               (snippet
                #~(begin
-                   ;; Add file missing from the release tarball.
-                   (call-with-output-file "grub-core/extra_deps.lst"
-                     (lambda (port)
-                       (display "depends bli part_gpt\n" port)))
-
                    ;; Use exit code 77, not 99, to tell Automake that a test
                    ;; is skipped.
                    (substitute* (find-files "tests" "\\.in$")
@@ -156,7 +156,36 @@ (define-public grub
 
            #:phases
            #~(modify-phases %standard-phases
-               (add-after 'unpack 'patch-stuff
+            ;; We need to run before the patch-stuff phase, otherwise we
+            ;; have this error:
+            ;;    starting phase `patch-stuff'
+            ;;    error: in phase 'patch-stuff': uncaught exception:
+            ;;    system-error "stat" "~A: ~S"
+            ;;    ("No such file or directory" "grub-core/Makefile.in") (2)
+            (add-after 'unpack 'bootstrap
+              (lambda _
+                ;; The bootstrap script calls gnulib-tool{,.py} from the path
+                ;; passed to --gnulib-srcdir, so we need to put Guix version
+                ;; of these scripts there.
+                (copy-recursively
+                 (string-append #$gnulib-2022-02-12 "/src/gnulib") "gnulib")
+                (delete-file "gnulib/gnulib-tool")
+                (delete-file "gnulib/gnulib-tool.py")
+                (copy-file
+                 (string-append #$gnulib-2022-02-12 "/bin/gnulib-tool")
+                 "gnulib/gnulib-tool")
+                (copy-file
+                 (string-append #$gnulib-2022-02-12 "/bin/gnulib-tool.py")
+                 "gnulib/gnulib-tool.py")
+                ;; We run very early so we need to patch the sheebang now as
+                ;; bootstrap will run autogen.sh.
+                (patch-shebang "autogen.sh")
+                (invoke
+                 "bash"
+                 "./bootstrap"
+                 "--no-git"
+                 "--gnulib-srcdir=gnulib")))
+               (add-after 'bootstrap 'patch-stuff
                  (lambda* (#:key native-inputs inputs #:allow-other-keys)
                    (substitute* "grub-core/Makefile.in"
                      (("/bin/sh") (which "sh")))
@@ -270,12 +299,16 @@ (define-public grub
                  (list fuse-2)
                  '())))
     (native-inputs
-     (append (list pkg-config
+     (append (list autoconf
+                   automake
                    bison
                    flex
-                   texinfo
-                   help2man
                    freetype       ;native version needed for build-grub-mkfont
+                   gnulib-2022-02-12
+                   help2man
+                   pkg-config
+                   python         ;to run gentpl.py during autoconf.sh
+                   texinfo
 
                    ;; Dependencies of the test suite.
                    parted
-- 
2.46.0