gnu: Add cl-ana.statistical-learning.
[jackhill/guix/guix.git] / gnu / packages / make-bootstrap.scm
index 6523f36..b8d1b2a 100644 (file)
@@ -1,9 +1,10 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
-;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
-;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2018, 2019 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,6 +24,7 @@
 (define-module (gnu packages make-bootstrap)
   #:use-module (guix utils)
   #:use-module (guix packages)
+  #:use-module (guix memoization)
   #:use-module ((guix licenses) #:select (gpl3+))
   #:use-module (guix build-system trivial)
   #:use-module (guix build-system gnu)
@@ -38,6 +40,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 +50,8 @@
             %glibc-bootstrap-tarball
             %gcc-bootstrap-tarball
             %guile-bootstrap-tarball
+            %mescc-tools-bootstrap-tarball
+            %mes-bootstrap-tarball
             %bootstrap-tarballs
 
             %guile-static-stripped))
 ;;;
 ;;; Code:
 
-(define* (glibc-for-bootstrap #:optional (base glibc))
-  "Return a libc deriving from BASE whose `system' and `popen' functions looks
+(define glibc-for-bootstrap
+  (mlambdaq (base)
+    "Return a libc deriving from BASE whose `system' and `popen' functions looks
 for `sh' in $PATH, and without nscd, and with static NSS modules."
-  (package (inherit base)
-    (source (origin (inherit (package-source base))
-              (patches (cons (search-patch "glibc-bootstrap-system.patch")
-                             (origin-patches (package-source base))))))
-    (arguments
-     (substitute-keyword-arguments (package-arguments base)
-       ((#:configure-flags flags)
-        ;; Arrange so that getaddrinfo & co. do not contact the nscd,
-        ;; and can use statically-linked NSS modules.
-        `(cons* "--disable-nscd" "--disable-build-nscd"
-                "--enable-static-nss"
-                ,flags))))
-
-    ;; Remove the 'debug' output to allow bit-reproducible builds (when the
-    ;; 'debug' output is used, ELF files end up with a .gnu_debuglink, which
-    ;; includes a CRC of the corresponding debugging symbols; those symbols
-    ;; contain store file names, so the CRC changes at every rebuild.)
-    (outputs (delete "debug" (package-outputs base)))))
+    (package
+      (inherit base)
+      (source (origin (inherit (package-source base))
+                      (patches (cons (search-patch "glibc-bootstrap-system.patch")
+                                     (origin-patches (package-source base))))))
+      (arguments
+       (substitute-keyword-arguments (package-arguments base)
+         ((#:configure-flags flags)
+          ;; Arrange so that getaddrinfo & co. do not contact the nscd,
+          ;; and can use statically-linked NSS modules.
+          `(cons* "--disable-nscd" "--disable-build-nscd"
+                  "--enable-static-nss"
+                  ,flags))))
+
+      ;; Remove the 'debug' output to allow bit-reproducible builds (when the
+      ;; 'debug' output is used, ELF files end up with a .gnu_debuglink, which
+      ;; includes a CRC of the corresponding debugging symbols; those symbols
+      ;; contain store file names, so the CRC changes at every rebuild.)
+      (outputs (delete "debug" (package-outputs base))))))
+
+(define gcc-for-bootstrap
+  (mlambdaq (glibc)
+    "Return a variant of GCC that uses the bootstrap variant of GLIBC."
+    (package
+      (inherit gcc)
+      (outputs '("out")) ;all in one so libgcc_s is easily found
+      (native-search-paths
+       ;; Set CPLUS_INCLUDE_PATH so GCC is able to find the libc
+       ;; C++ headers.
+       (cons (search-path-specification
+              (variable "CPLUS_INCLUDE_PATH")
+              (files '("include")))
+             (package-native-search-paths gcc)))
+      (inputs
+       `( ;; Distinguish the name so we can refer to it below.
+         ("bootstrap-libc" ,(glibc-for-bootstrap glibc))
+         ("libc:static" ,(glibc-for-bootstrap glibc) "static")
+         ,@(package-inputs gcc)))
+      (arguments
+       (substitute-keyword-arguments (package-arguments gcc)
+         ((#:phases phases)
+          `(modify-phases ,phases
+             (add-before 'configure 'treat-glibc-as-system-header
+               (lambda* (#:key inputs #:allow-other-keys)
+                 (let ((libc (assoc-ref inputs "bootstrap-libc")))
+                   ;; GCCs build processes requires that the libc
+                   ;; we're building against is on the system header
+                   ;; search path.
+                   (for-each (lambda (var)
+                               (setenv var (string-append libc "/include")))
+                             '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
+                   #t))))))))))
 
 (define (package-with-relocatable-glibc p)
   "Return a variant of P that uses the libc as defined by
 `glibc-for-bootstrap'."
 
-  (define (cross-bootstrap-libc)
-    (let ((target (%current-target-system)))
-      (glibc-for-bootstrap
-       ;; `cross-libc' already returns a cross libc, so clear
-       ;; %CURRENT-TARGET-SYSTEM.
-       (parameterize ((%current-target-system #f))
-         (cross-libc target)))))
+  (define (cross-bootstrap-libc target)
+    (glibc-for-bootstrap
+     ;; `cross-libc' already returns a cross libc, so clear
+     ;; %CURRENT-TARGET-SYSTEM.
+     (parameterize ((%current-target-system #f))
+       (cross-libc target))))
 
   ;; Standard inputs with the above libc and corresponding GCC.
 
   (define (inputs)
     (if (%current-target-system)                ; is this package cross built?
-        `(("cross-libc" ,(cross-bootstrap-libc)))
+        `(("cross-libc"
+           ,(cross-bootstrap-libc (%current-target-system))))
         '()))
 
   (define (native-inputs)
     (if (%current-target-system)
-        (let ((target (%current-target-system)))
-          `(("cross-gcc"      ,(cross-gcc target
-                                          #:xbinutils (cross-binutils target)
-                                          #:libc (cross-bootstrap-libc)))
+        (let* ((target (%current-target-system))
+               (xgcc (cross-gcc
+                      target
+                      #:xbinutils (cross-binutils target)
+                      #:libc (cross-bootstrap-libc target))))
+          `(("cross-gcc" ,(package
+                            (inherit xgcc)
+                            (search-paths
+                             ;; Ensure the cross libc headers appears on the
+                             ;; C++ system header search path.
+                             (cons (search-path-specification
+                                    (variable "CROSS_CPLUS_INCLUDE_PATH")
+                                    (files '("include")))
+                                   (package-search-paths gcc)))))
             ("cross-binutils" ,(cross-binutils target))
             ,@(%final-inputs)))
-        `(("libc" ,(glibc-for-bootstrap))
-          ("libc:static" ,(glibc-for-bootstrap) "static")
-          ("gcc" ,(package (inherit gcc)
-                    (outputs '("out")) ; all in one so libgcc_s is easily found
-                    (inputs
-                     `(("libc" ,(glibc-for-bootstrap))
-                       ("libc:static" ,(glibc-for-bootstrap) "static")
-                       ,@(package-inputs gcc)))))
+        `(("libc" ,(glibc-for-bootstrap glibc))
+          ("libc:static" ,(glibc-for-bootstrap glibc) "static")
+          ("gcc" ,(gcc-for-bootstrap glibc))
           ,@(fold alist-delete (%final-inputs) '("libc" "gcc")))))
 
   (package-with-explicit-inputs p inputs
                                 (current-source-location)
                                 #:native-inputs native-inputs))
 
+(define static-bash-for-bootstrap
+  (package
+    (inherit static-bash)
+    (source (origin
+              (inherit (package-source static-bash))
+              (patches
+               (cons (search-patch "bash-reproducible-linux-pgrp-pipe.patch")
+                     (origin-patches (package-source static-bash))))))))
+
 (define %static-inputs
   ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
   (let ((coreutils (package (inherit coreutils)
@@ -131,7 +185,15 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                            "--disable-silent-rules"
                            "--enable-no-install-program=stdbuf,libstdbuf.so"
                            "CFLAGS=-Os -g0"        ; smaller, please
-                           "LDFLAGS=-static -pthread")
+                           "LDFLAGS=-static -pthread"
+
+                           ;; Work around a cross-compilation bug whereby libcoreutils.a
+                           ;; would provide '__mktime_internal', which conflicts with the
+                           ;; one in libc.a.
+                           ,@(if (%current-target-system)
+                                 `("gl_cv_func_working_mktime=yes")
+                                 '()))
+
                          #:tests? #f   ; signal-related Gnulib tests fail
                          ,@(package-arguments coreutils)))
 
@@ -156,6 +218,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                                "LDFLAGS = -static"))
                             #t))))))))
         (xz (package (inherit xz)
+              (outputs '("out"))
               (arguments
                `(#:strip-flags '("--strip-all")
                  #:phases (modify-phases %standard-phases
@@ -189,21 +252,26 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                                  (("-Wl,-export-dynamic") ""))
                                #t)))))))
                 (inputs (if (%current-target-system)
-                            `(("bash" ,static-bash))
+                            `(("bash" ,static-bash-for-bootstrap))
                             '()))))
        (tar (package (inherit tar)
               (arguments
-                (substitute-keyword-arguments (package-arguments tar)
-                  ((#:phases phases)
-                   `(modify-phases ,phases
-                      (replace 'set-shell-file-name
-                        (lambda _
-                          ;; Do not use "/bin/sh" to run programs; see
-                          ;; <http://lists.gnu.org/archive/html/guix-devel/2016-09/msg02272.html>.
-                          (substitute* "src/system.c"
-                            (("/bin/sh") "sh")
-                            (("execv ") "execvp "))
-                          #t))))))))
+                `(;; Work around a cross-compilation bug whereby libgnu.a would provide
+                  ;; '__mktime_internal', which conflicts with the one in libc.a.
+                  ,@(if (%current-target-system)
+                        `(#:configure-flags '("gl_cv_func_working_mktime=yes"))
+                        '())
+                  ,@(substitute-keyword-arguments (package-arguments tar)
+                      ((#:phases phases)
+                       `(modify-phases ,phases
+                          (replace 'set-shell-file-name
+                            (lambda _
+                              ;; Do not use "/bin/sh" to run programs; see
+                              ;; <http://lists.gnu.org/archive/html/guix-devel/2016-09/msg02272.html>.
+                              (substitute* "src/system.c"
+                                (("/bin/sh") "sh")
+                                (("execv ") "execvp "))
+                              #t)))))))))
         ;; We don't want to retain a reference to /gnu/store in the bootstrap
         ;; versions of egrep/fgrep, so we remove the custom phase added since
         ;; grep@2.25. The effect is 'egrep' and 'fgrep' look for 'grep' in
@@ -230,7 +298,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                ("sed" ,sed)
                ("grep" ,grep)
                ("gawk" ,gawk)))
-      ("bash" ,static-bash))))
+      ("bash" ,static-bash-for-bootstrap))))
 
 (define %static-binaries
   (package
@@ -379,7 +447,7 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
   ;; GNU libc's essential shared libraries, dynamic linker, and headers,
   ;; with all references to store directories stripped.  As a result,
   ;; libc.so is unusable and need to be patched for proper relocation.
-  (let ((glibc (glibc-for-bootstrap)))
+  (let ((glibc (glibc-for-bootstrap glibc)))
     (package (inherit glibc)
       (name "glibc-stripped")
       (build-system trivial-build-system)
@@ -404,6 +472,8 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                                 (parameterize ((%current-target-system #f))
                                   (cross-libc target)))
                                glibc)))))
+      (native-inputs '())
+      (propagated-inputs '())
 
       ;; Only one output.
       (outputs '("out")))))
@@ -533,6 +603,98 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
            #t))))
     (inputs `(("gcc" ,%gcc-static)))))
 
+;; Two packages: first build static, bare minimum content.
+(define %mescc-tools-static
+  ;; A statically linked MesCC Tools.
+  (package
+    (inherit mescc-tools-0.5.2)
+    (name "mescc-tools-static")
+    (arguments
+     `(#:system "i686-linux"
+       ,@(substitute-keyword-arguments (package-arguments mescc-tools)
+           ((#:make-flags flags)
+            `(cons "CC=gcc -static" ,flags)))))))
+
+;; ... next remove store references.
+(define %mescc-tools-static-stripped
+  ;; A statically linked Mescc Tools with store references removed, for
+  ;; bootstrap.
+  (package
+    (inherit %mescc-tools-static)
+    (name (string-append (package-name %mescc-tools-static) "-stripped"))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((in  (assoc-ref %build-inputs "mescc-tools"))
+                (out (assoc-ref %outputs "out"))
+                (bin (string-append out "/bin")))
+           (mkdir-p bin)
+           (for-each (lambda (file)
+                       (let ((target (string-append bin "/" file)))
+                         (format #t "copying `~a'...~%" file)
+                         (copy-file (string-append in "/bin/" file)
+                                    target)
+                         (remove-store-references target)))
+                     '( "M1" "blood-elf" "hex2"))
+           #t))))
+    (inputs `(("mescc-tools" ,%mescc-tools-static)))))
+
+;; Two packages: first build static, bare minimum content.
+(define-public %mes-minimal
+  ;; A minimal Mes without documentation.
+  (let ((triplet "i686-unknown-linux-gnu"))
+    (package
+      (inherit mes-0.19)
+      (name "mes-minimal")
+      (native-inputs
+       `(("guile" ,guile-2.2)))
+      (arguments
+       `(#:system "i686-linux"
+         #:strip-binaries? #f
+         #:configure-flags '("--mes")
+         #:phases
+         (modify-phases %standard-phases
+           (delete 'patch-shebangs)
+           (add-after 'install 'strip-install
+             (lambda _
+               (let* ((out (assoc-ref %outputs "out"))
+                      (share (string-append out "/share")))
+                 (delete-file-recursively (string-append out "/lib/guile"))
+                 (delete-file-recursively (string-append share "/guile"))
+                 (delete-file-recursively (string-append share "/mes/scaffold"))
+
+                 (for-each delete-file
+                           (find-files
+                            (string-append share "/mes/lib")
+                            "\\.(h|c)")))))))))))
+
+;; next remove store references.
+(define %mes-minimal-stripped
+  ;; A minimal Mes with store references removed, for bootstrap.
+  (package
+    (inherit %mes-minimal)
+    (name (string-append (package-name %mes-minimal) "-stripped"))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let ((in  (assoc-ref %build-inputs "mes"))
+               (out (assoc-ref %outputs "out")))
+
+           (copy-recursively in out)
+           (for-each (lambda (dir)
+                       (for-each remove-store-references
+                                 (find-files (string-append out "/" dir)
+                                             ".*")))
+                     '("bin" "share/mes"))
+           #t))))
+    (inputs `(("mes" ,%mes-minimal)))))
+
 (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
@@ -591,6 +753,10 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                      ((#:tests? _ #f)
                       ;; There are uses of `dynamic-link' in
                       ;; {foreign,coverage}.test that don't fly here.
+                      #f)
+                     ((#:parallel-build? _ #f)
+                      ;; Work around the fact that the Guile build system is
+                      ;; not deterministic when parallel-build is enabled.
                       #f))))))
     (package-with-relocatable-glibc (static-package guile))))
 
@@ -700,6 +866,14 @@ 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 %mescc-tools-bootstrap-tarball
+  ;; A tarball with statically-linked MesCC binary seed.
+  (tarball-package %mescc-tools-static-stripped))
+
+(define %mes-bootstrap-tarball
+  ;; A tarball with Mes binary seed.
+  (tarball-package %mes-minimal-stripped))
+
 (define %bootstrap-tarballs
   ;; A single derivation containing all the bootstrap tarballs, for
   ;; convenience.
@@ -728,9 +902,15 @@ for `sh' in $PATH, and without nscd, and with static NSS modules."
                    %build-inputs)
          #t)))
     (inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
-              ("gcc-tarball" ,%gcc-bootstrap-tarball)
-              ("binutils-tarball" ,%binutils-bootstrap-tarball)
-              ("glibc-tarball" ,(%glibc-bootstrap-tarball))
+              ,@(match (or (%current-target-system) (%current-system))
+                  ((or "i686-linux" "x86_64-linux")
+                   `(("bootstrap-mescc-tools" ,%mescc-tools-bootstrap-tarball)
+                     ("bootstrap-mes" ,%mes-bootstrap-tarball)
+                     ("bootstrap-linux-libre-headers"
+                      ,%linux-libre-headers-bootstrap-tarball)))
+                  (_ `(("gcc-tarball" ,%gcc-bootstrap-tarball)
+                       ("binutils-tarball" ,%binutils-bootstrap-tarball)
+                       ("glibc-tarball" ,(%glibc-bootstrap-tarball)))))
               ("coreutils&co-tarball" ,%bootstrap-binaries-tarball)))
     (synopsis "Tarballs containing all the bootstrap binaries")
     (description synopsis)