Subject: [PATCH 3/6] bootstrap: Add %bootstrap-mes.

From: Jan Nieuwenhuizen <[email-masked]>
Date: Sun, 14 Oct 2018 10:58:54 +0200

* gnu/packages/make-bootstrap.scm (%mes-stripped): New variable.
(%mes-bootstrap-tarball): New variable.
* gnu/packages/bootstrap.scm (%bootstrap-mes): New variable.
---
 gnu/packages/bootstrap.scm      | 59 +++++++++++++++++++++++++++++++++
 gnu/packages/make-bootstrap.scm | 35 +++++++++++++++++++
 gnu/packages/mes.scm            |  1 -
 3 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index 82d229569..f33fc061e 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -49,6 +49,7 @@
             %bootstrap-gcc
             %bootstrap-glibc
             %bootstrap-inputs
+            %bootstrap-mes
             %mescc-tools-seed
             %mes-seed
             %srfi-43
@@ -610,6 +611,64 @@ exec ~a/bin/.gcc-wrapped -B~a/lib \
     (home-page #f)
     (license gpl3+)))
 
+(define %bootstrap-mes
+  ;; The initial Mes.  Uses binaries from a tarball typically built by
+  ;; %MES-BOOTSTRAP-TARBALL.
+  (package
+    (name "bootstrap-mes")
+    (version "0")
+    (source #f)
+    (build-system trivial-build-system)
+    (arguments
+     `(#:guile ,%bootstrap-guile
+       #:modules ((guix build utils))
+       #:builder
+       (let ((out     (assoc-ref %outputs "out"))
+             (tar     (assoc-ref %build-inputs "tar"))
+             (xz      (assoc-ref %build-inputs "xz"))
+             (tarball (assoc-ref %build-inputs "tarball")))
+         (use-modules (guix build utils)
+                      (ice-9 popen))
+
+         (mkdir out)
+         (copy-file tarball "binaries.tar.xz")
+         (invoke xz "-d" "binaries.tar.xz")
+         (let ((builddir (getcwd))
+               (bindir   (string-append out "/bin")))
+           (with-directory-excursion out
+             (invoke tar "xvf"
+                     (string-append builddir "/binaries.tar")))))))
+    (inputs
+     `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
+       ("xz"  ,(search-bootstrap-binary "xz" (%current-system)))
+       ("tarball" ,(bootstrap-origin
+                    (origin
+                      (method url-fetch)
+                      (uri (string-append
+                            "http://lilypond.org/janneke/mes/"
+                            (match (%current-system)
+                              ("x86_64-linux" "mes-stripped-0.18-0.08f04f5-x86_64-linux.tar.xz")
+                              ("i686-linux" "mes-stripped-0.18-0.08f04f5-i686-linux.tar.xz"))))
+                      (sha256
+                       (match (%current-system)
+                         ("x86_64-linux"
+                          (base32
+                           "14sbcm79ml4rgygxvx1135827g3ggfx1c1vchk77z26yibbdw9nh"))
+                         ("i686-linux"
+                          (base32
+                           "1p116ya9n52852bryh34n7db4mhvi98qifmmwygl7nbyc4dz92jy")))))))))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "C_INCLUDE_PATH")
+            (files '("share/mes/include")))
+           (search-path-specification
+            (variable "LIBRARY_PATH")
+            (files '("share/mes/lib")))))
+    (synopsis "Bootstrap binaries of Mes")
+    (description synopsis)
+    (home-page #f)
+    (license gpl3+)))
+
 (define %mescc-tools-seed ; todo: add tarballs to alpha.gnu.org/pub/mes/bootstrap/
   (let ((commit "dc4e20e74924a5c80a2b7a77b4d7b927234fa71c"))
     (origin
diff --git a/gnu/packages/make-bootstrap.scm b/gnu/packages/make-bootstrap.scm
index 3553737f1..7bfba3c14 100644
--- a/gnu/packages/make-bootstrap.scm
+++ b/gnu/packages/make-bootstrap.scm
@@ -38,6 +38,7 @@
   #:use-module (gnu packages libunistring)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages hurd)
+  #:use-module (gnu packages mes)
   #:use-module (gnu packages multiprecision)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
@@ -47,6 +48,7 @@
             %glibc-bootstrap-tarball
             %gcc-bootstrap-tarball
             %guile-bootstrap-tarball
+            %mes-bootstrap-tarball
             %bootstrap-tarballs
 
             %guile-static-stripped))
@@ -533,6 +535,35 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
            #t))))
     (inputs `(("gcc" ,%gcc-static)))))
 
+(define %mes-stripped
+  ;; The subset of Mes files needed for bootstrap.
+  (package
+    (inherit mes)
+    (name "mes-stripped")
+    (build-system trivial-build-system)
+    (source #f)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (srfi srfi-1)
+                      (srfi srfi-26)
+                      (guix build utils))
+
+         (setvbuf (current-output-port) _IOLBF)
+         (let* ((out        (assoc-ref %outputs "out"))
+                (libdir     (string-append out "/lib"))
+                (mes        (assoc-ref %build-inputs "mes")))
+
+           (copy-recursively (string-append mes "/lib") libdir)
+           (copy-recursively (string-append mes "/share/mes/lib") libdir)
+           (for-each remove-store-references
+                     (remove (lambda (file) (or (string-suffix? ".h" file)
+                                                (string-suffix? ".c" file)))
+                             (find-files out ".*")))
+           #t))))
+    (inputs `(("mes" ,mes)))))
+
 (define %guile-static
   ;; A statically-linked Guile that is relocatable--i.e., it can search
   ;; .scm and .go files relative to its installation directory, rather
@@ -700,6 +731,10 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
   ;; A tarball with the statically-linked, relocatable Guile.
   (tarball-package %guile-static-stripped))
 
+(define %mes-bootstrap-tarball
+  ;; A tarball with Mes ASCII Seed and binary Mes C Library.
+  (tarball-package %mes-stripped))
+
 (define %bootstrap-tarballs
   ;; A single derivation containing all the bootstrap tarballs, for
   ;; convenience.
diff --git a/gnu/packages/mes.scm b/gnu/packages/mes.scm
index 4f98cd24f..c4cb118e3 100644
--- a/gnu/packages/mes.scm
+++ b/gnu/packages/mes.scm
@@ -21,7 +21,6 @@
 (define-module (gnu packages mes)
   #:use-module (gnu packages)
   #:use-module (gnu packages base)
-  #:use-module (gnu packages commencement)
   #:use-module (gnu packages cross-base)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages graphviz)
-- 
2.18.0