;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 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>
;;;
;;; This file is part of GNU Guix.
;;;
(define-module (gnu packages make-bootstrap)
#:use-module (guix utils)
#:use-module (guix packages)
- #:use-module (guix licenses)
+ #:use-module ((guix licenses) #:select (gpl3+))
#:use-module (guix build-system trivial)
#:use-module (guix build-system gnu)
#:use-module ((gnu packages) #:select (search-patch))
- #:use-module ((gnu packages commencement) #:select (%final-inputs))
#:use-module (gnu packages base)
#:use-module (gnu packages cross-base)
#:use-module (gnu packages bash)
#:use-module (gnu packages gcc)
#:use-module (gnu packages guile)
#:use-module (gnu packages bdw-gc)
+ #:use-module (gnu packages libunistring)
#:use-module (gnu packages linux)
+ #:use-module (gnu packages hurd)
#:use-module (gnu packages multiprecision)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
(if (%current-target-system)
(let ((target (%current-target-system)))
`(("cross-gcc" ,(cross-gcc target
- (cross-binutils target)
- (cross-bootstrap-libc)))
+ #:xbinutils (cross-binutils target)
+ #:libc (cross-bootstrap-libc)))
("cross-binutils" ,(cross-binutils target))
- ,@%final-inputs))
+ ,@(%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" ,(glibc-for-bootstrap))
+ ("libc:static" ,(glibc-for-bootstrap) "static")
,@(package-inputs gcc)))))
- ,@(fold alist-delete %final-inputs '("libc" "gcc")))))
+ ,@(fold alist-delete (%final-inputs) '("libc" "gcc")))))
(package-with-explicit-inputs p inputs
(current-source-location)
#:native-inputs native-inputs))
-(define %bash-static
- (static-package bash-minimal))
-
(define %static-inputs
;; Packages that are to be used as %BOOTSTRAP-INPUTS.
(let ((coreutils (package (inherit coreutils)
(arguments
(substitute-keyword-arguments (package-arguments bzip2)
((#:phases phases)
- `(alist-cons-before
- 'build 'dash-static
- (lambda _
- (substitute* "Makefile"
- (("^LDFLAGS[[:blank:]]*=.*$")
- "LDFLAGS = -static")))
- ,phases))))))
+ `(modify-phases ,phases
+ (add-before 'build 'dash-static
+ (lambda _
+ (substitute* "Makefile"
+ (("^LDFLAGS[[:blank:]]*=.*$")
+ "LDFLAGS = -static"))
+ #t))))))))
(xz (package (inherit xz)
(arguments
`(#:strip-flags '("--strip-all")
- #:phases (alist-cons-before
- 'configure 'static-executable
- (lambda _
- ;; Ask Libtool for a static executable.
- (substitute* "src/xz/Makefile.in"
- (("^xz_LDADD =")
- "xz_LDADD = -all-static")))
- %standard-phases)))))
+ #:phases (modify-phases %standard-phases
+ (add-before 'configure 'static-executable
+ (lambda _
+ ;; Ask Libtool for a static executable.
+ (substitute* "src/xz/Makefile.in"
+ (("^xz_LDADD =")
+ "xz_LDADD = -all-static"))
+ #t)))))))
(gawk (package (inherit gawk)
(source (origin (inherit (package-source gawk))
(patches (cons (search-patch "gawk-shell.patch")
,@(substitute-keyword-arguments (package-arguments gawk)
((#:phases phases)
- `(alist-cons-before
- 'configure 'no-export-dynamic
- (lambda _
- ;; Since we use `-static', remove
- ;; `-export-dynamic'.
- (substitute* "configure"
- (("-Wl,-export-dynamic") "")))
- ,phases)))))
+ `(modify-phases ,phases
+ (add-before 'configure 'no-export-dynamic
+ (lambda _
+ ;; Since we use `-static', remove
+ ;; `-export-dynamic'.
+ (substitute* "configure"
+ (("-Wl,-export-dynamic") ""))
+ #t)))))))
(inputs (if (%current-target-system)
- `(("bash" ,%bash-static))
+ `(("bash" ,static-bash))
'()))))
+ (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))))))))
+ ;; 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
+ ;; $PATH.
+ (grep (package
+ (inherit grep)
+ (inputs '()) ;remove PCRE, which is optional
+ (arguments
+ (substitute-keyword-arguments (package-arguments grep)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (delete 'fix-egrep-and-fgrep)))))))
(finalize (compose static-package
package-with-relocatable-glibc)))
`(,@(map (match-lambda
("sed" ,sed)
("grep" ,grep)
("gawk" ,gawk)))
- ("bash" ,%bash-static))))
+ ("bash" ,static-bash))))
(define %static-binaries
(package
((#:configure-flags flags _ ...)
flags)))
#:strip-flags '("--strip-all")
- #:phases (alist-cons-before
- 'configure 'all-static
- (lambda _
- ;; The `-all-static' libtool flag can only be passed
- ;; after `configure', since configure tests don't use
- ;; libtool, and only for executables built with libtool.
- (substitute* '("binutils/Makefile.in"
- "gas/Makefile.in"
- "ld/Makefile.in")
- (("^LDFLAGS =(.*)$" line)
- (string-append line
- "\nAM_LDFLAGS = -static -all-static\n"))))
- %standard-phases)))))
+ #:phases (modify-phases %standard-phases
+ (add-before 'configure 'all-static
+ (lambda _
+ ;; The `-all-static' libtool flag can only be passed
+ ;; after `configure', since configure tests don't use
+ ;; libtool, and only for executables built with libtool.
+ (substitute* '("binutils/Makefile.in"
+ "gas/Makefile.in"
+ "ld/Makefile.in")
+ (("^LDFLAGS =(.*)$" line)
+ (string-append line
+ "\nAM_LDFLAGS = -static -all-static\n")))
+ #t)))))))
(define %binutils-static-stripped
;; The subset of Binutils that we need.
#t))))
(inputs `(("binutils" ,%binutils-static)))))
-(define %glibc-stripped
+(define (%glibc-stripped)
;; 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.
(name "glibc-stripped")
(build-system trivial-build-system)
(arguments
- `(#:modules ((guix build utils))
+ `(#:modules ((guix build utils)
+ (guix build make-bootstrap))
#:builder
(begin
- (use-modules (guix build utils))
-
- (setvbuf (current-output-port) _IOLBF)
- (let* ((out (assoc-ref %outputs "out"))
- (libdir (string-append out "/lib"))
- (incdir (string-append out "/include"))
- (libc (assoc-ref %build-inputs "libc"))
- (linux (assoc-ref %build-inputs "linux-headers")))
- (mkdir-p libdir)
- (for-each (lambda (file)
- (let ((target (string-append libdir "/"
- (basename file))))
- (copy-file file target)
- (remove-store-references target)))
- (find-files (string-append libc "/lib")
- "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|util).*\\.so(\\..*)?|libc_nonshared\\.a)$"))
-
- (copy-recursively (string-append libc "/include") incdir)
-
- ;; Copy some of the Linux-Libre headers that glibc headers
- ;; refer to.
- (mkdir (string-append incdir "/linux"))
- (for-each (lambda (file)
- (copy-file (string-append linux "/include/linux/" file)
- (string-append incdir "/linux/"
- (basename file))))
- '("limits.h" "errno.h" "socket.h" "kernel.h"
- "sysctl.h" "param.h" "ioctl.h" "types.h"
- "posix_types.h" "stddef.h"))
-
- (copy-recursively (string-append linux "/include/asm")
- (string-append incdir "/asm"))
- (copy-recursively (string-append linux "/include/asm-generic")
- (string-append incdir "/asm-generic"))
-
- #t))))
- (inputs `(("libc" ,(let ((target (%current-target-system)))
+ (use-modules (guix build make-bootstrap))
+ (make-stripped-libc (assoc-ref %outputs "out")
+ (assoc-ref %build-inputs "libc")
+ (assoc-ref %build-inputs "kernel-headers")))))
+ (inputs `(("kernel-headers"
+ ,(if (or (and (%current-target-system)
+ (hurd-triplet? (%current-target-system)))
+ (string-suffix? "-hurd" (%current-system)))
+ gnumach-headers
+ linux-libre-headers))
+ ("libc" ,(let ((target (%current-target-system)))
(if target
(glibc-for-bootstrap
(parameterize ((%current-target-system #f))
(cross-libc target)))
- glibc)))
- ("linux-headers" ,linux-libre-headers)))
+ glibc)))))
+ (native-inputs '())
+ (propagated-inputs '())
;; Only one output.
(outputs '("out")))))
(remove (cut string-match "--(.*plugin|enable-languages)" <>)
,flags)))
((#:phases phases)
- `(alist-cons-after
- 'pre-configure 'remove-lgcc_s
- (lambda _
- ;; Remove the '-lgcc_s' added to GNU_USER_TARGET_LIB_SPEC in
- ;; the 'pre-configure phase of our main gcc package, because
- ;; that shared library is not present in this static gcc. See
- ;; <https://lists.gnu.org/archive/html/guix-devel/2015-01/msg00008.html>.
- (substitute* (find-files "gcc/config"
- "^gnu-user.*\\.h$")
- ((" -lgcc_s}}") "}}")))
- ,phases)))))
+ `(modify-phases ,phases
+ (add-after 'pre-configure 'remove-lgcc_s
+ (lambda _
+ ;; Remove the '-lgcc_s' added to GNU_USER_TARGET_LIB_SPEC in
+ ;; the 'pre-configure phase of our main gcc package, because
+ ;; that shared library is not present in this static gcc. See
+ ;; <https://lists.gnu.org/archive/html/guix-devel/2015-01/msg00008.html>.
+ (substitute* (cons "gcc/config/rs6000/sysv4.h"
+ (find-files "gcc/config"
+ "^gnu-user.*\\.h$"))
+ ((" -lgcc_s}}") "}}"))
+ #t)))))))
+ (inputs
+ `(("zlib:static" ,zlib "static")
+ ,@(package-inputs gcc)))
(native-inputs
(if (%current-target-system)
`(;; When doing a Canadian cross, we need GMP/MPFR/MPC both
;; etc.) Failing to do that leads to misdetections of
;; declarations by 'gcc/configure', and eventually to
;; duplicate declarations as reported in
- ;; <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>.
+ ;; <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>.
("gmp-native" ,gmp)
("mpfr-native" ,mpfr)
("mpc-native" ,mpc)
(string-append includedir "/c++"))
;; For native builds, check whether the binaries actually work.
- ,(if (%current-target-system)
- '#t
- '(every (lambda (prog)
- (zero? (system* (string-append gcc "/bin/" prog)
- "--version")))
- '("gcc" "g++" "cpp")))))))
+ ,@(if (%current-target-system)
+ '()
+ '((for-each (lambda (prog)
+ (invoke (string-append gcc "/bin/" prog)
+ "--version"))
+ '("gcc" "g++" "cpp"))))
+
+ #t))))
(inputs `(("gcc" ,%gcc-static)))))
(define %guile-static
;; .scm and .go files relative to its installation directory, rather
;; than in hard-coded configure-time paths.
(let* ((patches (cons* (search-patch "guile-relocatable.patch")
- (search-patch "guile-default-utf8.patch")
+ (search-patch "guile-2.2-default-utf8.patch")
(search-patch "guile-linux-syscalls.patch")
- (origin-patches (package-source guile-2.0))))
- (source (origin (inherit (package-source guile-2.0))
+ (origin-patches (package-source guile-2.2))))
+ (source (origin (inherit (package-source guile-2.2))
(patches patches)))
- (guile (package (inherit guile-2.0)
- (name (string-append (package-name guile-2.0) "-static"))
+ (guile (package (inherit guile-2.2)
+ (name (string-append (package-name guile-2.2) "-static"))
(source source)
(synopsis "Statically-linked and relocatable Guile")
;; Remove the 'debug' output (see above for the reason.)
- (outputs (delete "debug" (package-outputs guile-2.0)))
+ (outputs (delete "debug" (package-outputs guile-2.2)))
+
+ (inputs
+ `(("libunistring:static" ,libunistring "static")
+ ,@(package-inputs guile-2.2)))
(propagated-inputs
`(("bdw-gc" ,libgc)
,@(alist-delete "bdw-gc"
- (package-propagated-inputs guile-2.0))))
+ (package-propagated-inputs guile-2.2))))
(arguments
- `(;; When `configure' checks for ltdl availability, it
- ;; doesn't try to link using libtool, and thus fails
- ;; because of a missing -ldl. Work around that.
- #:configure-flags '("LDFLAGS=-ldl")
-
- #:phases (alist-cons-before
- 'configure 'static-guile
- (lambda _
- (substitute* "libguile/Makefile.in"
- ;; Create a statically-linked `guile'
- ;; executable.
- (("^guile_LDFLAGS =")
- "guile_LDFLAGS = -all-static")
-
- ;; Add `-ldl' *after* libguile-2.0.la.
- (("^guile_LDADD =(.*)$" _ ldadd)
- (string-append "guile_LDADD = "
- (string-trim-right ldadd)
- " -ldl\n"))))
- %standard-phases)
-
- ;; There are uses of `dynamic-link' in
- ;; {foreign,coverage}.test that don't fly here.
- #:tests? #f)))))
+ (substitute-keyword-arguments (package-arguments guile-2.2)
+ ((#:configure-flags flags '())
+ ;; When `configure' checks for ltdl availability, it
+ ;; doesn't try to link using libtool, and thus fails
+ ;; because of a missing -ldl. Work around that.
+ ''("LDFLAGS=-ldl"))
+ ((#:phases phases '%standard-phases)
+ `(modify-phases ,phases
+
+ ;; Do not record the absolute file name of 'sh' in
+ ;; (ice-9 popen). This makes 'open-pipe' unusable in
+ ;; a build chroot ('open-pipe*' is fine) but avoids
+ ;; keeping a reference to Bash.
+ (delete 'pre-configure)
+
+ (add-before 'configure 'static-guile
+ (lambda _
+ (substitute* "libguile/Makefile.in"
+ ;; Create a statically-linked `guile'
+ ;; executable.
+ (("^guile_LDFLAGS =")
+ "guile_LDFLAGS = -all-static")
+
+ ;; Add `-ldl' *after* libguile-2.2.la.
+ (("^guile_LDADD =(.*)$" _ ldadd)
+ (string-append "guile_LDADD = "
+ (string-trim-right ldadd)
+ " -ldl\n")))))))
+ ((#:tests? _ #f)
+ ;; There are uses of `dynamic-link' in
+ ;; {foreign,coverage}.test that don't fly here.
+ #f))))))
(package-with-relocatable-glibc (static-package guile))))
(define %guile-static-stripped
(name "guile-static-stripped")
(build-system trivial-build-system)
(arguments
- `(#:modules ((guix build utils))
+ ;; The end result should depend on nothing but itself.
+ `(#:allowed-references ("out")
+ #:modules ((guix build utils))
#:builder
(let ()
(use-modules (guix build utils))
(out (assoc-ref %outputs "out"))
(guile1 (string-append in "/bin/guile"))
(guile2 (string-append out "/bin/guile")))
- (mkdir-p (string-append out "/share/guile/2.0"))
- (copy-recursively (string-append in "/share/guile/2.0")
- (string-append out "/share/guile/2.0"))
+ (mkdir-p (string-append out "/share/guile/2.2"))
+ (copy-recursively (string-append in "/share/guile/2.2")
+ (string-append out "/share/guile/2.2"))
- (mkdir-p (string-append out "/lib/guile/2.0/ccache"))
- (copy-recursively (string-append in "/lib/guile/2.0/ccache")
- (string-append out "/lib/guile/2.0/ccache"))
+ (mkdir-p (string-append out "/lib/guile/2.2/ccache"))
+ (copy-recursively (string-append in "/lib/guile/2.2/ccache")
+ (string-append out "/lib/guile/2.2/ccache"))
(mkdir (string-append out "/bin"))
(copy-file guile1 guile2)
- ;; Does the relocated Guile work?
- (and ,(if (%current-target-system)
- #t
- '(zero? (system* guile2 "--version")))
- (begin
- ;; Strip store references.
- (remove-store-references guile2)
-
- ;; Does the stripped Guile work? If it aborts, it could be
- ;; that it tries to open iconv descriptors and fails because
- ;; libc's iconv data isn't available (see
- ;; `guile-default-utf8.patch'.)
- ,(if (%current-target-system)
- #t
- '(zero? (system* guile2 "--version")))))))))
+ ;; Verify that the relocated Guile works.
+ ,@(if (%current-target-system)
+ '()
+ '((invoke guile2 "--version")))
+
+ ;; Strip store references.
+ (remove-store-references guile2)
+
+ ;; Verify that the stripped Guile works. If it aborts, it could be
+ ;; that it tries to open iconv descriptors and fails because libc's
+ ;; iconv data isn't available (see `guile-default-utf8.patch'.)
+ ,@(if (%current-target-system)
+ '()
+ '((invoke guile2 "--version")))
+
+ #t))))
(inputs `(("guile" ,%guile-static)))
(outputs '("out"))
(synopsis "Minimal statically-linked and relocatable Guile")))
(mkdir out)
(set-path-environment-variable "PATH" '("bin") (list tar xz))
(with-directory-excursion input
- (zero? (system* "tar" "cJvf"
- (string-append out "/"
- ,name "-" ,version
- "-"
- ,(or (%current-target-system)
- (%current-system))
- ".tar.xz")
- "."
- ;; avoid non-determinism in the archive
- "--sort=name" "--mtime=@0"
- "--owner=root:0" "--group=root:0"))))))))))
+ (invoke "tar" "cJvf"
+ (string-append out "/"
+ ,name "-" ,version
+ "-"
+ ,(or (%current-target-system)
+ (%current-system))
+ ".tar.xz")
+ "."
+ ;; avoid non-determinism in the archive
+ "--sort=name" "--mtime=@0"
+ "--owner=root:0" "--group=root:0")))))))))
(define %bootstrap-binaries-tarball
;; A tarball with the statically-linked bootstrap binaries.
;; A tarball with the statically-linked Binutils programs.
(tarball-package %binutils-static-stripped))
-(define %glibc-bootstrap-tarball
+(define (%glibc-bootstrap-tarball)
;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
- (tarball-package %glibc-stripped))
+ (tarball-package (%glibc-stripped)))
(define %gcc-bootstrap-tarball
;; A tarball with a dynamic-linked GCC and its headers.
(inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
("gcc-tarball" ,%gcc-bootstrap-tarball)
("binutils-tarball" ,%binutils-bootstrap-tarball)
- ("glibc-tarball" ,%glibc-bootstrap-tarball)
+ ("glibc-tarball" ,(%glibc-bootstrap-tarball))
("coreutils&co-tarball" ,%bootstrap-binaries-tarball)))
- (synopsis #f)
- (description #f)
+ (synopsis "Tarballs containing all the bootstrap binaries")
+ (description synopsis)
(home-page #f)
(license gpl3+)))