1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
9 ;;; Copyright © 2019, 2020 Marius Bakke <mbakke@fastmail.com>
11 ;;; This file is part of GNU Guix.
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26 (define-module (gnu packages commencement)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bash)
31 #:use-module (gnu packages c)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages m4)
34 #:use-module (gnu packages file)
35 #:use-module (gnu packages gawk)
36 #:use-module (gnu packages bison)
37 #:use-module (gnu packages flex)
38 #:use-module (gnu packages guile)
39 #:use-module (gnu packages gettext)
40 #:use-module (gnu packages multiprecision)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages mes)
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages python)
45 #:use-module (gnu packages linux)
46 #:use-module (gnu packages hurd)
47 #:use-module (gnu packages shells)
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages pkg-config)
50 #:use-module (gnu packages rsync)
51 #:use-module (gnu packages xml)
52 #:use-module (guix packages)
53 #:use-module (guix download)
54 #:use-module (guix build-system gnu)
55 #:use-module (guix build-system guile)
56 #:use-module (guix build-system trivial)
57 #:use-module (guix memoization)
58 #:use-module (guix utils)
59 #:use-module (srfi srfi-1)
60 #:use-module (ice-9 vlist)
61 #:use-module (ice-9 match)
62 #:export (make-gcc-toolchain))
66 ;;; This is the commencement, this is where things start. Before the
67 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
68 ;;; with the initial binaries. This module uses those bootstrap binaries to
69 ;;; actually build up the whole tool chain that make up the implicit inputs of
70 ;;; 'gnu-build-system'.
72 ;;; To avoid circular dependencies, this module should not be imported
73 ;;; directly from anywhere.
75 ;;; Below, we frequently use "inherit" to create modified packages. The
76 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
77 ;;; not want these commencement packages to inherit grafts. By definition,
78 ;;; these packages are not depended on at run time by any of the packages we
79 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
80 ;;; grafts would often lead to extra overhead for users who would end up
81 ;;; downloading those "-boot0" packages just to build package replacements
82 ;;; that are in fact not going to be used.
86 (define %bootstrap-guile+guild
87 ;; This package combines %bootstrap-guile with guild, which is not included
88 ;; in %bootstrap-guile. Guild is needed to build gash-boot and
89 ;; gash-core-utils-boot because it is dependency of the Guile build system.
91 (name "guile-bootstrap+guild")
93 (source (bootstrap-origin (package-source guile-2.0)))
94 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
95 ("tar" ,(bootstrap-executable "tar" (%current-system)))
96 ("xz" ,(bootstrap-executable "xz" (%current-system)))
97 ("guile" ,%bootstrap-guile)))
98 (build-system trivial-build-system)
100 `(#:guile ,%bootstrap-guile
101 #:modules ((guix build utils))
103 (use-modules (guix build utils))
104 (let ((guile-source (assoc-ref %build-inputs "source"))
105 (bin (string-append (getcwd) "/bin"))
106 (tar (assoc-ref %build-inputs "tar"))
107 (xz (assoc-ref %build-inputs "xz")))
110 (with-directory-excursion bin
111 (copy-file tar "tar")
114 (let* ((out (assoc-ref %outputs "out"))
115 (out-bin (string-append out "/bin"))
116 (guile (assoc-ref %build-inputs "guile"))
117 (bash (assoc-ref %build-inputs "bash")))
119 (with-directory-excursion out-bin
120 (symlink (string-append guile "/bin/guile")
122 (invoke "tar" "--strip-components=2"
124 (string-append "guile-"
125 ,(package-version guile-2.0)
127 (copy-file "guild.in" "guild")
129 (("#!/bin/sh") (string-append "#! " bash))
130 (("@installed_guile@") (string-append out-bin "/guile")))
131 (chmod "guild" #o555)))))))
132 (synopsis "Bootstrap Guile plus Guild")
133 (description "Bootstrap Guile with added Guild")
135 (license (package-license guile-2.0))
137 (list (search-path-specification
138 (variable "GUILE_LOAD_PATH")
139 (files '("share/guile/site/2.0")))
140 (search-path-specification
141 (variable "GUILE_LOAD_COMPILED_PATH")
142 (files '("lib/guile/2.0/site-ccache")))))))
149 (source (bootstrap-origin
150 (origin (inherit (package-source gash))
151 (modules '((guix build utils)
155 ;; Remove Guix'y files that we cannot compile.
156 (delete-file "guix.scm")
157 (delete-file-recursively "tests")
159 (build-system guile-build-system)
160 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
161 ("tar" ,(bootstrap-executable "tar" (%current-system)))
162 ("xz" ,(bootstrap-executable "xz" (%current-system)))
163 ("guile-source" ,(bootstrap-origin
164 (package-source guile-2.0)))))
165 (inputs `(("guile" ,%bootstrap-guile+guild)))
167 `(#:implicit-inputs? #f
168 #:guile ,%bootstrap-guile+guild
170 (modify-phases %standard-phases
171 (add-after 'unpack 'unpack-guile-source
173 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
174 (bin (string-append (getcwd) "/zee-bin")))
176 (with-directory-excursion bin
177 (invoke "tar" "--strip-components=2"
180 (string-append "guile-"
181 ,(package-version guile-2.0)
183 (copy-file "guild.in" "guild")
184 (chmod "guild" #o555))
186 (add-before 'unpack 'set-path
188 (let ((bash (assoc-ref %build-inputs "bash"))
189 (tar (assoc-ref %build-inputs "tar"))
190 (xz (assoc-ref %build-inputs "xz"))
191 (bin (string-append (getcwd) "/zee-bin")))
193 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
194 (copy-file bash (string-append bin "/bash"))
195 (copy-file bash (string-append bin "/sh"))
196 (copy-file tar (string-append bin "/tar"))
197 (copy-file xz (string-append bin "/xz"))
199 (add-after 'build 'build-scripts
201 (let* ((guile (assoc-ref %build-inputs "guile"))
202 (guile (string-append guile "/bin/guile"))
203 (out (assoc-ref %outputs "out"))
205 (moddir (string-append out "/share/guile/site/" effective "/"))
206 (godir (string-append out "/lib/guile/" effective "/site-ccache/")))
207 (copy-file "scripts/gash.in" "scripts/gash")
208 (chmod "scripts/gash" #o555)
209 (substitute* "scripts/gash"
211 (("@MODDIR@") moddir)
214 (add-after 'install 'install-scripts
216 (let* ((out (assoc-ref %outputs "out"))
217 (bin (string-append out "/bin")))
218 (install-file "scripts/gash" bin)
219 (copy-file "scripts/gash" "scripts/sh")
220 (install-file "scripts/sh" bin)
221 (copy-file "scripts/gash" "scripts/bash")
222 (install-file "scripts/bash" bin)
225 (define gash-core-utils-boot
227 (inherit gash-core-utils)
228 (name "gash-core-utils-boot")
229 (version "0.0.213-3f6eb")
230 (source (bootstrap-origin
233 (uri (string-append "http://lilypond.org/janneke/"
234 "/gash-core-utils-" version ".tar.gz"))
235 (modules '((guix build utils)))
238 ;; The Guile build system compiles *.scm; avoid
239 ;; compiling included lalr.
240 (delete-file "guix.scm")
241 (delete-file-recursively "tests")
242 (substitute* "system/base/lalr.scm"
243 (("system/base/lalr.upstream.scm") "lalr.upstream.scm"))
247 "0601c9hqbjrjjsllr2m3zmkglkd53d97in7a5c22ikd8islddp76")))))
248 (build-system guile-build-system)
249 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
250 ("tar" ,(bootstrap-executable "tar" (%current-system)))
251 ("xz" ,(bootstrap-executable "xz" (%current-system)))
252 ("guile-source" ,(bootstrap-origin
253 (package-source guile-2.0)))
254 ;; We need the 2.0.9 lalr for %bootstrap-guile
258 (uri (string-append "http://git.savannah.gnu.org/cgit/guile.git/plain/module/system/base/lalr.upstream.scm?h=v2.0.9"))
259 (file-name "lalr.upstream.scm")
262 "0h7gyjj8nr2qrgzwma146s7l22scp8bbcqzdy9wqf12bgyhbw7d5"))))))
263 (inputs `(("guile" ,%bootstrap-guile+guild)
264 ("gash" ,gash-boot)))
266 `(#:implicit-inputs? #f
267 #:guile ,%bootstrap-guile+guild
268 #:not-compiled-file-regexp "upstream\\.scm$"
270 (modify-phases %standard-phases
271 (add-after 'unpack 'unpack-guile-source
273 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
274 (bin (string-append (getcwd) "/zee-bin")))
276 (with-directory-excursion bin
277 (invoke "tar" "--strip-components=2"
280 (string-append "guile-"
281 ,(package-version guile-2.0)
283 (copy-file "guild.in" "guild")
284 (chmod "guild" #o555))
286 (add-before 'unpack 'set-path
288 (let ((bash (assoc-ref %build-inputs "bash"))
289 (tar (assoc-ref %build-inputs "tar"))
290 (xz (assoc-ref %build-inputs "xz"))
291 (bin (string-append (getcwd) "/zee-bin")))
293 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
294 (copy-file bash (string-append bin "/bash"))
295 (copy-file bash (string-append bin "/sh"))
296 (copy-file tar (string-append bin "/tar"))
297 (copy-file xz (string-append bin "/xz"))
299 (add-before 'build 'set-env
301 (let ((gash (assoc-ref %build-inputs "gash")))
303 (setenv "LC_ALL" "C")
304 (setenv "GUILE_LOAD_PATH"
305 (string-append (getcwd)
306 ":" (getcwd) "/system/base"
307 ":" gash "/share/guile/2.0"))
308 (setenv "GUILE_LOAD_COMPILED_PATH"
309 (string-append ".:" gash "/lib/guile/2.0/site-ccache/"))
310 (format (current-error-port)
311 "GUILE_LOAD_PATH=~s\n" (getenv "GUILE_LOAD_PATH"))
313 (add-before 'build 'replace-lalr.upstream
315 (let ((lalr.upstream (assoc-ref %build-inputs "lalr.upstream")))
316 (copy-file lalr.upstream "system/base/lalr.upstream.scm")
318 (add-after 'build 'build-scripts
320 (let* ((guile (assoc-ref %build-inputs "guile"))
321 (guile (string-append guile "/bin/guile"))
322 (gash (string-append guile "gash"))
323 (out (assoc-ref %outputs "out"))
325 (guilemoduledir (string-append gash "/share/guile/site/" effective "/"))
326 (guileobjectdir (string-append gash "/lib/guile/" effective "/site-ccache/"))
327 (gashmoduledir (string-append out "/share/guile/site/" effective "/"))
328 (gashobjectdir (string-append out "/lib/guile/" effective "/site-ccache/"))
329 (bin (string-append out "/bin")))
331 (copy-file "command.in" name)
335 (("@guilemoduledir@") guilemoduledir)
336 (("@guileobjectdir") guileobjectdir)
337 (("@gashmoduledir@") gashmoduledir)
338 (("@gashobjectdir") gashobjectdir)
339 (("@command@") name))
340 (install-file name bin))
342 (with-directory-excursion "bin"
343 (for-each wrap '("awk"
379 (with-directory-excursion bin
380 (copy-file "grep" "fgrep")
381 (copy-file "grep" "egrep")
382 (copy-file "test" "["))
385 (define (%boot-gash-inputs)
386 `(("bash" , gash-boot) ; gnu-build-system wants "bash"
387 ("coreutils" , gash-core-utils-boot)
388 ("guile" ,%bootstrap-guile)
389 ("guile+guild" ,%bootstrap-guile+guild)))
391 (define %bootstrap-mes-rewired
394 (name "bootstrap-mes-rewired")
397 (native-inputs `(("mes" ,(@ (gnu packages bootstrap) %bootstrap-mes))
398 ("gash" ,gash-boot)))
400 (propagated-inputs '())
402 (build-system trivial-build-system)
404 `(#:guile ,%bootstrap-guile
405 #:modules ((guix build utils)
408 (use-modules (guix build utils)
410 (let* ((mes (assoc-ref %build-inputs "mes"))
411 (gash (assoc-ref %build-inputs "gash"))
412 (mes-bin (string-append mes "/bin"))
413 (guile (string-append mes-bin "/mes"))
414 (mes-module (string-append mes "/share/mes/module"))
415 (out (assoc-ref %outputs "out"))
416 (bin (string-append out "/bin"))
417 (mescc (string-append bin "/mescc"))
418 (module (string-append out "/share/mes/module")))
419 (define (rewire file)
422 (("/gnu/store[^ ]+mes-minimal-[^/)}\"]*") out)
423 (("/gnu/store[^ ]+guile-[^/]*/bin/guile") guile)
424 (("/gnu/store[^ ]+bash-[^/)}\"]*") gash)))
427 (for-each (lambda (file) (install-file file bin))
428 (find-files mes-bin))
430 (copy-recursively (string-append mes-module "/mes")
431 (string-append module "/mes"))
432 (copy-recursively (string-append mes-module "/srfi")
433 (string-append module "/srfi"))
435 ;; Cannot easily rewire "mes" because it
436 ;; contains NUL characters; would require
437 ;; remove-store-references alike trick
438 (filter (negate (cut string-suffix? "/mes" <>))
440 (rewire (string-append module "/mes/boot-0.scm"))
443 (with-output-to-file mescc
445 (display (string-append
452 MES_PREFIX=${MES_REWIRED_PREFIX-" out "/share/mes}
454 export MES MES_PREFIX
456 MES_ARENA=${MES_REWIRED_ARENA-10000000}
457 MES_MAX_ARENA=${MES_REWIRED_ARENA-10000000}
458 MES_STACK=${MES_REWIRED_STACK-1000000}
459 export MES_ARENA MES_MAX_ARENA MES_STACK
461 $MES -e '(mescc)' module/mescc.scm -- \"$@\"
465 (with-directory-excursion module
466 (chmod "mes/base.mes" #o644)
467 (copy-file "mes/base.mes" "mes/base.mes.orig")
468 (let ((base.mes (open-file "mes/base.mes" "a")))
470 ;; A fixed map, from Mes 0.21, required to bootstrap Mes 0.21
471 (define (map f h . t)
473 (and (pair? t) (null? (car t)))
474 (and (pair? t) (pair? (cdr t)) (null? (cadr t)))) '()
475 (if (null? t) (cons (f (car h)) (map f (cdr h)))
477 (cons (f (car h) (caar t)) (map f (cdr h) (cdar t)))
479 (cons (f (car h) (caar t) (caadr t)) (map f (cdr h) (cdar t) (cdadr t)))
480 (error 'unsupported (cons* 'map-4: f h t))b )))))
484 (chmod "mes/guile.mes" #o644)
485 (copy-file "mes/guile.mes" "mes/guile.mes.orig")
486 (let ((guile.mes (open-file "mes/guile.mes" "a")))
488 ;; After booting guile.scm; use Mes 0.21; especially: MesCC 0.21
489 (let* ((self (car (command-line)))
490 (prefix (dirname (dirname self))))
491 (set! %moduledir (string-append prefix \"/mes/module/\"))
492 (setenv \"%numbered_arch\" \"true\"))
502 (version "0.21-33-g6d493b90d")
505 (uri (string-append "http://lilypond.org/janneke/mes/"
506 "mes-" version ".tar.gz"))
509 "0nr74zyam5n82svjwfbcz2mycj88vvsqab12x0mxv1lm6yqxqmmj"))))
511 (propagated-inputs '())
513 `(("nyacc-source" ,(origin (inherit (package-source nyacc))
515 ("mes" ,%bootstrap-mes-rewired)
516 ("mescc-tools" ,%bootstrap-mescc-tools)
517 ,@(%boot-gash-inputs)))
519 `(#:implicit-inputs? #f
521 #:guile ,%bootstrap-guile
522 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
524 (modify-phases %standard-phases
525 (add-after 'unpack 'unpack-seeds
527 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
528 (with-directory-excursion ".."
529 (invoke "tar" "-xvf" nyacc-source)))))
531 (lambda* (#:key outputs #:allow-other-keys)
532 (let ((out (assoc-ref %outputs "out"))
533 (gash (assoc-ref %build-inputs "bash"))
534 (mes (assoc-ref %build-inputs "mes"))
535 (dir (with-directory-excursion ".." (getcwd))))
536 (setenv "AR" (string-append "gash " (getcwd) "/scripts/mesar"))
537 (setenv "BASH" (string-append gash "/bin/bash"))
538 (setenv "CC" (string-append mes "/bin/mescc"))
539 (setenv "GUILE_LOAD_PATH"
541 mes "/share/mes/module"
542 ":" dir "/nyacc-0.99.0/module"
543 ":" (getenv "GUILE_LOAD_PATH")))
544 (invoke "gash" "configure.sh"
545 (string-append "--prefix=" out)
546 (string-append "--host=i686-linux-gnu")))))
549 (invoke "sh" "bootstrap.sh")))
553 (substitute* "install.sh" ; show some progress
555 (("^( *)((cp|mkdir|tar) [^']*[^\\])\n" all space cmd)
556 (string-append space "echo '" cmd "'\n"
558 (invoke "sh" "install.sh")
559 ;; Keep ASCII output, for friendlier comparison and bisection
560 (let* ((out (assoc-ref %outputs "out"))
561 (cache (string-append out "/lib/cache")))
562 (define (objects-in-dir dir)
565 (and (equal? (dirname name) dir)
566 (or (string-suffix? ".o" name)
567 (string-suffix? ".s" name))))))
568 (for-each (lambda (x) (install-file x cache))
569 (append (objects-in-dir ".")
570 (objects-in-dir "mescc-lib"))))
573 (list (search-path-specification
574 (variable "C_INCLUDE_PATH")
575 (files '("include")))
576 (search-path-specification
577 (variable "LIBRARY_PATH")
579 (search-path-specification
580 (variable "MES_PREFIX")
586 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
587 ;; patches. In a very early and rough form they were presented to the
588 ;; TinyCC developers, who at the time showed no interest in supporting the
589 ;; bootstrappable effort; we will try again later. These patches have been
590 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
591 ;; mature, this package should use the 0.9.27 sources (or later).
595 (version "0.9.26-1103-g6e62e0e")
599 "http://lilypond.org/janneke/mes/20191117/"
600 "/tcc-" version ".tar.gz"))
603 "1qbybw7mxbgkv3sazvz1v7c8byq998vk8f1h25ik8w3d2l63lxng"))))
604 (build-system gnu-build-system)
605 (supported-systems '("i686-linux" "x86_64-linux"))
607 (propagated-inputs '())
610 ("nyacc-source" ,(origin (inherit (package-source nyacc))
612 ("mescc-tools" ,%bootstrap-mescc-tools)
613 ,@(%boot-gash-inputs)))
615 `(#:implicit-inputs? #f
616 #:guile ,%bootstrap-guile
617 #:validate-runpath? #f ; no dynamic executables
618 #:strip-binaries? #f ; no strip yet
620 (modify-phases %standard-phases
621 (add-after 'unpack 'unpack-seeds
622 (lambda* (#:key outputs #:allow-other-keys)
623 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
624 (with-directory-excursion ".."
625 (invoke "tar" "-xvf" nyacc-source)))))
627 (lambda* (#:key outputs #:allow-other-keys)
628 (let* ((out (assoc-ref %outputs "out"))
629 (dir (with-directory-excursion ".." (getcwd)))
630 (interpreter "/lib/mes-loader"))
632 (setenv "prefix" out)
633 (setenv "GUILE_LOAD_PATH"
634 (string-append dir "/nyacc-0.99.0/module"))
636 (substitute* "conftest.c"
639 (invoke "sh" "configure"
641 (string-append "--prefix=" out)
642 (string-append "--elfinterp=" interpreter)
647 (substitute* "bootstrap.sh" ; Show some progress
648 (("^( *)((cp|ls|mkdir|rm|[.]/tcc|[.]/[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
649 (string-append space "echo \"" cmd "\"\n"
651 (invoke "sh" "bootstrap.sh")))
655 (system* "./tcc" "--help") ; --help exits 1
656 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
657 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
658 ;; TODO: add sensible check target (without depending on make)
659 ;; (invoke "sh" "check.sh")
663 (substitute* "install.sh" ; Show some progress
664 (("^( *)((cp|ls|mkdir|rm|tar|./[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
665 (string-append space "echo \"" cmd "\"\n"
668 (invoke "sh" "install.sh"))))))
670 (list (search-path-specification
671 (variable "C_INCLUDE_PATH")
672 (files '("include")))
673 (search-path-specification
674 (variable "LIBRARY_PATH")
675 (files '("lib")))))))
678 ;; The initial gzip. We keep this scripted gzip build before building make
679 ;; to soften the dependency on Gash Core Utils gzip.
683 (name "gzip-mesboot")
686 (uri (string-append "mirror://gnu/gzip/gzip-" version ".tar"))
689 "1rhgk2vvmdvnn6vygf0dja92ryyng00knl0kz5srb77k2kryjb2d"))))
690 (supported-systems '("i686-linux" "x86_64-linux"))
692 (propagated-inputs '())
693 (native-inputs `(("tcc" ,tcc-boot0)
694 ,@(%boot-gash-inputs)))
696 `(#:implicit-inputs? #f
697 #:guile ,%bootstrap-guile
698 #:strip-binaries? #f ; no strip yet
700 (modify-phases %standard-phases
702 (add-after 'unpack 'scripted-patch
704 (substitute* "util.c"
705 (("^char [*]strlwr" all) (string-append all "_tcc_cannot_handle_dupe")))
709 (let ((files '("bits" "crypt" "deflate" "getopt" "gzip"
710 "inflate" "lzw" "trees" "unlzh" "unlzw"
711 "unpack" "unzip" "util" "zip")))
713 (invoke "tcc" "-c" "-D NO_UTIME=1" "-D HAVE_UNISTD_H=1"
714 (string-append x ".c")))
715 (for-each compile files)
717 (cons* "tcc" "-o" "gzip"
718 (map (lambda (x) (string-append x ".o")) files)))
719 (link "gzip" "gunzip"))))
722 (let* ((out (assoc-ref %outputs "out"))
723 (bin (string-append out "/bin")))
724 (install-file "gzip" bin)
725 (install-file "gunzip" bin))))
728 (invoke "./gzip" "--version")))
730 (delete 'compress-documentation))))))
732 (define make-mesboot0
736 (name "make-mesboot0")
740 (uri (string-append "mirror://gnu/make/make-" version ".tar.gz"))
743 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
744 (supported-systems '("i686-linux" "x86_64-linux"))
746 (propagated-inputs '())
747 (native-inputs `(("tcc" ,tcc-boot0)
748 ,@(%boot-gash-inputs)))
750 `(#:implicit-inputs? #f
751 #:guile ,%bootstrap-guile
752 #:configure-flags '("CC=tcc"
755 "--build=i686-unknown-linux-gnu"
756 "--host=i686-unknown-linux-gnu"
758 #:modules ((guix build gnu-build-system)
761 #:strip-binaries? #f ; no strip yet
763 (modify-phases %standard-phases
764 (add-after 'unpack 'scripted-patch
766 (substitute* "build.sh.in"
767 (("@LIBOBJS@") "getloadavg.o")
768 (("@REMOTE@") "stub"))
770 (add-after 'configure 'configure-fixup
772 (substitute* "make.h"
773 (("^extern long int lseek.*" all) (string-append "// " all)))
777 (invoke "sh" "./build.sh")))
778 (replace 'check ; proper check needs awk
780 (invoke "./make" "--version")))
783 (let* ((out (assoc-ref %outputs "out"))
784 (bin (string-append out "/bin")))
785 (install-file "make" bin)))))))))
787 (define (%boot-tcc0-inputs)
788 `(("make" ,make-mesboot0)
790 ,@(%boot-gash-inputs)))
792 (define bzip2-mesboot
796 (name "bzip2-mesboot")
797 (version (package-version bzip2))
798 (source (bootstrap-origin (package-source bzip2)))
799 (supported-systems '("i686-linux" "x86_64-linux"))
801 (propagated-inputs '())
802 (native-inputs (%boot-tcc0-inputs))
805 `(#:implicit-inputs? #f
806 #:guile ,%bootstrap-guile
808 #:tests? #f ; check is naive, also checks non-built PROGRAMS
809 #:strip-binaries? #f ; no strip yet
810 #:make-flags (list "CC=tcc -I ." "AR=tcc -ar" "bzip2"
811 (string-append "PREFIX="
812 (assoc-ref %outputs "out")))
814 (modify-phases %standard-phases
815 (add-after 'unpack 'scripted-patch
817 (substitute* "Makefile"
819 (string-append "\t#" all)))
820 (substitute* "bzip2.c"
821 (("struct utimbuf uTimBuf;" all)
822 (string-append "// " all))
824 (string-append "// " all))
825 (("retVal = utime [(] dstName, &uTimBuf [)];" all)
826 (string-append "retVal = 0; // " all)))
830 (with-output-to-file "utime.h"
832 #define fchown(filedes, owner, group) 0
833 #define fchmod(filedes, mode) 0
838 (invoke "./bzip2" "--help")))
839 ;; FIXME: no compressing gzip yet
840 (delete 'compress-documentation))))))
842 (define bash-mesboot0
845 (inherit static-bash)
846 (name "bash-mesboot0")
850 (uri (string-append "mirror://gnu/bash/bash-"
854 "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs"))))
856 (propagated-inputs '())
857 (native-inputs (%boot-tcc0-inputs))
860 `(#:implicit-inputs? #f
861 #:guile ,%bootstrap-guile
863 #:strip-binaries? #f ; no strip yet
865 (list "--build=i686-unknown-linux-gnu"
866 "--host=i686-unknown-linux-gnu"
868 "--without-bash-malloc"
871 "--disable-help-builtin"
873 "--disable-net-redirections"
876 ;; Pretend 'dlopen' is missing so we don't build loadable
877 ;; modules and related code.
878 "ac_cv_func_dlopen=no")
879 #:make-flags '("bash")
881 (modify-phases %standard-phases
882 (add-before 'configure 'setenv
884 (let* ((gash (assoc-ref %build-inputs "bash"))
885 (shell (string-append gash "/bin/gash")))
886 (setenv "CONFIG_SHELL" shell)
887 (setenv "SHELL" shell)
890 (setenv "AR" "tcc -ar")
891 (setenv "CFLAGS" "-D _POSIX_VERSION=1")
893 (add-after 'unpack 'scripted-patch
895 (substitute* "Makefile.in"
896 (("mksyntax\\.c\n") "mksyntax.c -lgetopt\n")
897 (("buildversion[.]o\n") "buildversion.o -lgetopt\n")
899 (("\tsize ") "#\tsize"))
900 (substitute* "lib/sh/oslib.c"
901 (("int name, namelen;") "char *name; int namelen;"))
902 (substitute* "lib/sh/snprintf.c"
903 (("^#if (defined [(]HAVE_LOCALE_H[)])" all define) (string-append "#if 0 //" define)))
904 (substitute* "configure"
905 ((" egrep") " grep"))
908 (lambda* (#:key configure-flags #:allow-other-keys)
909 (let ((configure-flags (filter (lambda (x)
910 (and (not (string-prefix? "CONFIG_SHELL=" x))
911 (not (string-prefix? "SHELL=" x))))
913 (format (current-error-port)
914 "running ./configure ~a\n" (string-join configure-flags)))
915 (apply invoke (cons "./configure" configure-flags))))
916 (add-after 'configure 'configure-fixups
918 (substitute* "config.h"
919 (("#define GETCWD_BROKEN 1") "#undef GETCWD_BROKEN"))
920 (let ((config.h (open-file "config.h" "a")))
921 (display (string-append "
922 // tcc: error: undefined symbol 'enable_hostname_completion'
923 #define enable_hostname_completion(on_or_off) 0
925 // /gnu/store/cq0cmv35s9dhilx14zaghlc08gpc0hwr-tcc-boot0-0.9.26-6.c004e9a/lib/libc.a: error: 'sigprocmask' defined twice
926 #define HAVE_POSIX_SIGNALS 1
927 #define endpwent(x) 0
934 (invoke "./bash" "--version")))
937 (let* ((out (assoc-ref %outputs "out"))
938 (bin (string-append out "/bin")))
940 (copy-file "bash" (string-append bin "/bash"))
941 (copy-file "bash" (string-append bin "/sh"))
951 (inherit (package-source tcc))
952 ;; `patches' needs XZ
953 ;; (patches (search-patches "tcc-boot-0.9.27.patch"))
955 (build-system gnu-build-system)
957 (propagated-inputs '())
958 (native-inputs `(;;("boot-patch" ,(search-patch "tcc-boot-0.9.27.patch"))
959 ("bzip2" ,bzip2-mesboot)
960 ,@(%boot-tcc0-inputs)))
962 `(#:implicit-inputs? #f
963 #:guile ,%bootstrap-guile
964 #:validate-runpath? #f ; no dynamic executables
965 #:strip-binaries? #f ; no strip yet
967 (modify-phases %standard-phases
968 ;; tar xvf ..bz2 gives
969 ;; bzip2: PANIC -- internal consistency error
971 (lambda* (#:key source #:allow-other-keys)
972 (copy-file source "tarball.tar.bz2")
973 (invoke "bzip2" "-d" "tarball.tar.bz2")
974 (invoke "tar" "xvf" "tarball.tar")
975 (chdir (string-append "tcc-" ,version))
978 ;; (add-after 'unpack 'apply-boot-patch
979 ;; (lambda* (#:key inputs #:allow-other-keys)
980 ;; (let ((patch-file (assoc-ref inputs "boot-patch")))
981 ;; (invoke "patch" "-p1" "-i" patch-file))))
982 (add-after 'unpack 'scripted-patch
983 (lambda* (#:key inputs #:allow-other-keys)
984 (substitute* "libtcc.c"
985 (("s->alacarte_link = 1;" all)
987 s->static_link = 1;")))
990 (lambda* (#:key outputs #:allow-other-keys)
991 (let* ((out (assoc-ref %outputs "out"))
992 (tcc (assoc-ref %build-inputs "tcc"))
993 (libc (assoc-ref %build-inputs "libc"))
994 (interpreter "/mes/loader"))
995 (invoke "sh" "configure"
996 (string-append "--cc=tcc")
997 (string-append "--cpu=i386")
998 (string-append "--prefix=" out)
999 (string-append "--elfinterp=" interpreter)
1000 (string-append "--crtprefix=" tcc "/lib")
1001 (string-append "--sysincludepaths=" tcc "/include")
1002 (string-append "--libpaths=" tcc "/lib")))))
1004 (lambda* (#:key outputs #:allow-other-keys)
1005 (let* ((out (assoc-ref %outputs "out"))
1006 (tcc (assoc-ref %build-inputs "tcc"))
1007 (libc (assoc-ref %build-inputs "libc"))
1008 (interpreter "/mes/loader"))
1014 "-D" "TCC_TARGET_I386=1"
1015 "-D" "CONFIG_TCC_STATIC=1"
1016 "-D" "CONFIG_USE_LIBGCC=1"
1017 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
1018 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
1019 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
1020 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
1021 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
1022 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\""
1023 tcc "/include" ":/include:{B}/include\"")
1024 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
1029 ;; FIXME: add sensible check target (without depending on make)
1031 (= 1 (status:exit-val (system* "./tcc" "--help")))))
1033 (lambda* (#:key outputs #:allow-other-keys)
1034 (let ((out (assoc-ref %outputs "out"))
1035 (tcc (assoc-ref %build-inputs "tcc")))
1037 (mkdir-p (string-append out "/bin"))
1038 (copy-file "tcc" (string-append out "/bin/tcc"))
1039 (mkdir-p (string-append out "/lib/tcc"))
1040 (copy-recursively (string-append tcc "/include")
1041 (string-append out "/include"))
1042 (copy-recursively (string-append tcc "/lib")
1043 (string-append out "/lib"))
1044 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
1045 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
1046 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
1047 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
1048 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
1051 (define diffutils-mesboot
1052 ;; The initial diffutils.
1055 (name "diffutils-mesboot")
1059 (uri (string-append "mirror://gnu/diffutils/diffutils-"
1063 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
1064 (supported-systems '("i686-linux" "x86_64-linux"))
1066 (propagated-inputs '())
1067 (native-inputs (%boot-tcc0-inputs))
1069 `(#:implicit-inputs? #f
1070 #:guile ,%bootstrap-guile
1071 #:parallel-build? #f
1072 #:tests? #f ; check is naive, also checks non-built PROGRAMS
1073 #:strip-binaries? #f ; no strip yet
1075 (modify-phases %standard-phases
1076 (add-before 'configure 'remove-diff3-sdiff
1077 (lambda* (#:key outputs #:allow-other-keys)
1078 (substitute* "Makefile.in"
1079 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))))
1080 (replace 'configure ; needs classic invocation of configure
1081 (lambda* (#:key configure-flags #:allow-other-keys)
1082 (let* ((out (assoc-ref %outputs "out"))
1083 (bash (assoc-ref %build-inputs "bash"))
1084 (shell (string-append bash "/bin/bash")))
1085 (setenv "CONFIG_SHELL" shell)
1088 (format (current-error-port)
1089 "running ./configure ~a\n" (string-join configure-flags))
1090 (apply invoke (cons "./configure" configure-flags)))))
1093 (let* ((out (assoc-ref %outputs "out"))
1094 (bin (string-append out "/bin")))
1096 (install-file "cmp" bin)
1097 (install-file "diff" bin)
1100 (define binutils-mesboot0
1103 (name "binutils-mesboot0")
1105 (source (bootstrap-origin
1108 (uri (string-append "mirror://gnu/binutils/binutils-"
1109 version ".tar.bz2"))
1110 (patches (search-patches "binutils-boot-2.20.1a.patch"))
1113 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
1115 (propagated-inputs '())
1116 (native-inputs `(("tcc" ,tcc-boot)
1118 ("bash" ,%bootstrap-coreutils&co)
1119 ("coreutils" ,%bootstrap-coreutils&co)
1120 ("diffutils" ,diffutils-mesboot)
1121 ("make" ,make-mesboot0)))
1122 (supported-systems '("i686-linux" "x86_64-linux"))
1124 `(#:implicit-inputs? #f
1125 #:guile ,%bootstrap-guile
1126 #:tests? #f ; runtest: command not found
1127 #:parallel-build? #f
1128 #:strip-binaries? #f ; no strip yet
1130 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
1131 " -D MES_BOOTSTRAP=1"))
1132 (bash (assoc-ref %build-inputs "bash")))
1133 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
1134 ,(string-append "CPPFLAGS=" cppflags)
1138 ,(string-append "CC=tcc" cppflags)
1142 "--build=i686-unknown-linux-gnu"
1143 "--host=i686-unknown-linux-gnu"
1144 "--with-sysroot=/"))))))
1146 (define gcc-core-mesboot
1147 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
1148 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
1149 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
1150 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
1151 ;; toolchain triplet "that works".
1154 (name "gcc-core-mesboot")
1156 (source (bootstrap-origin
1159 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
1162 (patches (search-patches "gcc-boot-2.95.3.patch"))
1165 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
1166 (supported-systems '("i686-linux" "x86_64-linux"))
1168 (propagated-inputs '())
1169 (native-inputs `(("binutils" ,binutils-mesboot0)
1172 ("bash" ,%bootstrap-coreutils&co)
1173 ("coreutils" ,%bootstrap-coreutils&co)
1174 ("diffutils" ,diffutils-mesboot)
1175 ("make" ,make-mesboot0)))
1178 `(#:implicit-inputs? #f
1179 #:guile ,%bootstrap-guile
1181 #:parallel-build? #f
1182 #:strip-binaries? #f
1184 (let ((out (assoc-ref %outputs "out")))
1188 "--build=i686-unknown-linux-gnu"
1189 "--host=i686-unknown-linux-gnu"
1190 ,(string-append "--prefix=" out)))
1192 "CC=tcc -static -D __GLIBC_MINOR__=6"
1193 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
1194 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
1197 (string-append "LIBGCC2_INCLUDES=-I "
1198 (assoc-ref %build-inputs "tcc")
1201 (string-append "BOOT_LDFLAGS="
1202 " -B" (assoc-ref %build-inputs "tcc")
1204 #:modules ((guix build gnu-build-system)
1208 (modify-phases %standard-phases
1209 ;; gcc-2.95.3 needs more traditional configure
1210 (add-before 'configure 'setenv
1211 (lambda* (#:key outputs #:allow-other-keys)
1212 (let ((out (assoc-ref outputs "out"))
1213 (bash (assoc-ref %build-inputs "bash"))
1214 (tcc (assoc-ref %build-inputs "tcc"))
1215 (cppflags " -D __GLIBC_MINOR__=6"))
1216 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1217 (setenv "CPPFLAGS" cppflags)
1218 (setenv "CC" (string-append "tcc" cppflags))
1219 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
1220 (setenv "CPP" (string-append "tcc -E" cppflags))
1221 (with-output-to-file "config.cache"
1224 ac_cv_c_float_format='IEEE (little-endian)'
1228 (lambda* (#:key configure-flags #:allow-other-keys)
1229 (format (current-error-port)
1230 "running ./configure ~a\n" (string-join configure-flags))
1231 (apply invoke "./configure" configure-flags)))
1232 (add-after 'configure 'remove-info
1234 ;; no info at this stage
1235 (delete-file-recursively "texinfo")
1236 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
1237 (add-after 'install 'install2
1238 (lambda* (#:key outputs #:allow-other-keys)
1239 (let* ((tcc (assoc-ref %build-inputs "tcc"))
1240 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
1241 (out (assoc-ref outputs "out"))
1242 (gcc-dir (string-append
1243 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1245 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1246 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1247 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1248 (copy-file (string-append tcc "/lib/libtcc1.a")
1249 (string-append out "/lib/libtcc1.a"))
1250 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
1251 (string-append tcc-lib "/libc+gnu.o")
1252 (string-append tcc-lib "/libtcc1.o"))
1253 (invoke "ar" "r" (string-append out "/lib/libc.a")
1254 (string-append tcc-lib "/libc+gnu.o")
1255 (string-append tcc-lib "/libtcc1.o"))
1256 (invoke "ls" "-ltrF" gcc-dir)
1258 (native-search-paths
1259 (list (search-path-specification
1260 (variable "C_INCLUDE_PATH")
1263 ;; Needed to get things like GCC's <stddef.h>.
1264 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
1265 (search-path-specification
1266 (variable "LIBRARY_PATH")
1267 (files '("lib")))))))
1269 (define mesboot-headers
1272 (name "mesboot-headers")
1273 (supported-systems '("i686-linux" "x86_64-linux"))
1275 (propagated-inputs '())
1276 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
1277 ("headers" ,%bootstrap-linux-libre-headers)))
1279 `(#:implicit-inputs? #f
1280 #:guile ,%bootstrap-guile
1282 #:strip-binaries? #f
1284 (modify-phases %standard-phases
1288 (lambda* (#:key outputs #:allow-other-keys)
1289 (let* ((out (assoc-ref outputs "out"))
1290 (include (string-append out "/include"))
1291 (headers (assoc-ref %build-inputs "headers" )))
1293 (copy-recursively "include" out)
1294 (copy-recursively headers out)
1297 (define glibc-mesboot0
1298 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
1299 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
1303 (name "glibc-mesboot0")
1305 (source (bootstrap-origin
1308 (uri (string-append "mirror://gnu/glibc/glibc-"
1311 (patches (search-patches "glibc-boot-2.2.5.patch"))
1314 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
1315 (supported-systems '("i686-linux" "x86_64-linux"))
1317 (propagated-inputs '())
1318 (native-inputs `(("binutils" ,binutils-mesboot0)
1319 ("gcc" ,gcc-core-mesboot)
1321 ("bash" ,%bootstrap-coreutils&co)
1322 ("coreutils" ,%bootstrap-coreutils&co)
1323 ("diffutils" ,diffutils-mesboot)
1324 ("headers" ,mesboot-headers)
1325 ("make" ,make-mesboot0)))
1328 `(#:implicit-inputs? #f
1329 #:guile ,%bootstrap-guile
1331 #:strip-binaries? #f
1332 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1333 #:make-flags (list (string-append
1335 (assoc-ref %build-inputs "bash")
1338 (let ((out (assoc-ref %outputs "out"))
1339 (headers (assoc-ref %build-inputs "headers")))
1343 "--disable-sanity-checks"
1344 "--build=i686-unknown-linux-gnu"
1345 "--host=i686-unknown-linux-gnu"
1346 (string-append "--with-headers=" headers "/include")
1347 "--enable-static-nss"
1348 "--without-__thread"
1352 (string-append "--prefix=" out)))
1354 (modify-phases %standard-phases
1355 (add-before 'configure 'setenv
1356 (lambda* (#:key outputs #:allow-other-keys)
1357 (let* ((out (assoc-ref outputs "out"))
1358 (bash (assoc-ref %build-inputs "bash"))
1359 (gcc (assoc-ref %build-inputs "gcc"))
1360 (headers (assoc-ref %build-inputs "headers"))
1361 (cppflags (string-append
1363 " -D MES_BOOTSTRAP=1"
1364 " -D BOOTSTRAP_GLIBC=1"))
1365 (cflags (string-append " -L " (getcwd))))
1366 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1367 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1368 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1369 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1371 ;; glibc-2.2.5 needs a more classic invocation of configure
1372 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
1374 (lambda* (#:key configure-flags #:allow-other-keys)
1375 (format (current-error-port)
1376 "running ./configure ~a\n" (string-join configure-flags))
1377 (apply invoke "./configure" configure-flags))))))))
1379 (define gcc-mesboot0
1381 (inherit gcc-core-mesboot)
1382 (name "gcc-mesboot0")
1383 (native-inputs `(("binutils" ,binutils-mesboot0)
1385 ;; Packages are given in an order that's relevant for
1386 ;; #include_next purposes.
1387 ("libc" ,glibc-mesboot0)
1388 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1389 ("gcc" ,gcc-core-mesboot)
1391 ("bash" ,%bootstrap-coreutils&co)
1392 ("coreutils" ,%bootstrap-coreutils&co)
1393 ("diffutils" ,diffutils-mesboot)
1394 ("make" ,make-mesboot0)))
1396 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1398 `(modify-phases ,phases
1401 (setenv "CONFIG_SHELL" (which "sh"))
1402 (with-output-to-file "config.cache"
1405 ac_cv_c_float_format='IEEE (little-endian)'
1409 (lambda* (#:key outputs #:allow-other-keys)
1410 (let* ((out (assoc-ref outputs "out"))
1411 (gcc-dir (string-append
1412 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1414 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1415 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1416 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1418 ((#:configure-flags configure-flags)
1419 `(let ((out (assoc-ref %outputs "out")))
1420 `("--disable-shared"
1422 "--build=i686-unknown-linux-gnu"
1423 "--host=i686-unknown-linux-gnu"
1424 ,(string-append "--prefix=" out))))
1425 ((#:make-flags make-flags)
1426 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1428 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1429 "LANGUAGES=c")))))))
1431 (define binutils-mesboot
1433 (inherit binutils-mesboot0)
1434 (name "binutils-mesboot")
1435 (native-inputs `(("binutils" ,binutils-mesboot0)
1436 ("libc" ,glibc-mesboot0)
1437 ("gcc" ,gcc-mesboot0)
1439 ("bash" ,%bootstrap-coreutils&co)
1440 ("coreutils" ,%bootstrap-coreutils&co)
1441 ("diffutils" ,diffutils-mesboot)
1442 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1443 ("make" ,make-mesboot0)))
1445 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1446 ((#:configure-flags configure-flags)
1447 '(list "--disable-nls"
1450 "--build=i686-unknown-linux-gnu"
1451 "--host=i686-unknown-linux-gnu"
1452 "--with-sysroot=/"))))))
1454 (define make-mesboot
1456 (inherit make-mesboot0)
1457 (name "make-mesboot")
1461 (uri (string-append "mirror://gnu/make/make-"
1465 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1466 (native-inputs `(("binutils" ,binutils-mesboot0)
1467 ("libc" ,glibc-mesboot0)
1468 ("gcc" ,gcc-mesboot0)
1469 ("make" ,make-mesboot0)
1471 ("bash" ,%bootstrap-coreutils&co)
1472 ("coreutils" ,%bootstrap-coreutils&co)
1473 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
1475 (substitute-keyword-arguments (package-arguments make-mesboot0)
1476 ((#:configure-flags configure-flags)
1477 `(let ((out (assoc-ref %outputs "out")))
1478 `(,(string-append "--prefix=" out))))
1480 `(modify-phases ,phases
1481 (delete 'configure-fixup)
1482 (add-before 'configure 'setenv
1484 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1493 (uri (string-append "mirror://gnu/gmp/gmp-" version
1496 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1504 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1507 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1516 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1519 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1521 (define gcc-mesboot1
1523 (inherit gcc-mesboot0)
1524 (name "gcc-mesboot1")
1525 (version (package-version gcc-4.7))
1526 (source (bootstrap-origin
1527 (origin (inherit (package-source gcc-4.7))
1528 (patches (search-patches "gcc-boot-4.7.4.patch")))))
1529 (inputs `(("gmp-source" ,(package-source gmp-boot))
1530 ("mpfr-source" ,(package-source mpfr-boot))
1531 ("mpc-source" ,(package-source mpc-boot))))
1532 (native-inputs `(("binutils" ,binutils-mesboot)
1534 ("libc" ,glibc-mesboot0)
1535 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1536 ("gcc" ,gcc-mesboot0)
1538 ("bash" ,%bootstrap-coreutils&co)
1539 ("coreutils" ,%bootstrap-coreutils&co)
1540 ("diffutils" ,diffutils-mesboot)
1541 ("make" ,make-mesboot)))
1543 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1544 ((#:make-flags make-flags)
1545 `(let* ((libc (assoc-ref %build-inputs "libc"))
1546 (ldflags (string-append
1548 "-Wl,-dynamic-linker "
1550 ,(glibc-dynamic-linker "i686-linux"))))
1551 (list (string-append "LDFLAGS=" ldflags)
1552 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
1554 `(modify-phases ,phases
1555 ;; c&p from commencement.scm:gcc-boot0
1556 (add-after 'unpack 'unpack-gmp&co
1557 (lambda* (#:key inputs #:allow-other-keys)
1558 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1559 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1560 (mpc (assoc-ref %build-inputs "mpc-source")))
1562 ;; To reduce the set of pre-built bootstrap inputs, build
1563 ;; GMP & co. from GCC.
1564 (for-each (lambda (source)
1565 (or (invoke "tar" "xvf" source)
1566 (error "failed to unpack tarball"
1568 (list gmp mpfr mpc))
1570 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1571 ,@(map (lambda (lib)
1572 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1574 `(symlink ,(string-trim-right
1575 (package-full-name lib "-")
1577 ,(package-name lib)))
1578 (list gmp-boot mpfr-boot mpc-boot))
1580 (delete 'remove-info)
1583 (setenv "CONFIG_SHELL" (which "sh"))
1585 ;; Allow MPFR headers to be found.
1586 (setenv "C_INCLUDE_PATH"
1587 (string-append (getcwd) "/mpfr/src:"
1588 (getenv "C_INCLUDE_PATH")))
1590 ;; Set the C++ search path so that C headers can be found as
1591 ;; libstdc++ is being compiled.
1592 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
1594 (delete 'install2)))
1595 ((#:configure-flags configure-flags)
1596 `(let ((out (assoc-ref %outputs "out"))
1597 (glibc (assoc-ref %build-inputs "libc")))
1598 (list (string-append "--prefix=" out)
1599 "--build=i686-unknown-linux-gnu"
1600 "--host=i686-unknown-linux-gnu"
1602 (string-append "--with-native-system-header-dir=" glibc "/include")
1603 (string-append "--with-build-sysroot=" glibc "/include")
1605 "--disable-bootstrap"
1606 "--disable-decimal-float"
1607 "--disable-libatomic"
1608 "--disable-libcilkrts"
1611 "--disable-libmudflap"
1612 "--disable-libquadmath"
1613 "--disable-libsanitizer"
1617 "--disable-lto-plugin"
1618 "--disable-multilib"
1621 "--enable-languages=c,c++"
1624 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1626 "--enable-threads=single"
1628 ;; No pre-compiled libstdc++ headers, to save space.
1629 "--disable-libstdcxx-pch"
1632 "--disable-build-with-cxx")))))))
1634 (define gcc-mesboot1-wrapper
1635 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1636 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1637 ;; --enable-shared will fail.
1639 (inherit gcc-mesboot1)
1640 (name "gcc-mesboot1-wrapper")
1643 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1644 ("libc" ,glibc-mesboot)
1645 ("gcc" ,gcc-mesboot1)))
1647 `(#:implicit-inputs? #f
1648 #:guile ,%bootstrap-guile
1650 (modify-phases %standard-phases
1655 (lambda* (#:key outputs #:allow-other-keys)
1656 (let* ((out (assoc-ref outputs "out"))
1657 (bash (assoc-ref %build-inputs "bash"))
1658 (libc (assoc-ref %build-inputs "libc"))
1659 (gcc (assoc-ref %build-inputs "gcc"))
1660 (bin (string-append out "/bin")))
1664 (let ((wrapper (string-append bin "/" program)))
1665 (with-output-to-file wrapper
1667 (display (string-append "#! " bash "/bin/bash
1668 exec " gcc "/bin/" program
1669 " -Wl,--dynamic-linker"
1670 ;; also for x86_64-linux, we are still on i686-linux
1671 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1676 (chmod wrapper #o555)))))
1680 "i686-unknown-linux-gnu-gcc"
1681 "i686-unknown-linux-gnu-g++"
1685 (lambda* (#:key outputs #:allow-other-keys)
1686 (let* ((out (assoc-ref outputs "out"))
1687 (bin (string-append out "/bin"))
1688 (program (string-append bin "/gcc")))
1689 (invoke program "--help")))))))))
1691 (define glibc-headers-mesboot
1693 (inherit glibc-mesboot0)
1694 (name "glibc-headers-mesboot")
1696 (source (bootstrap-origin
1699 (uri (string-append "mirror://gnu/glibc/glibc-"
1702 (patches (search-patches "glibc-boot-2.16.0.patch"
1703 "glibc-bootstrap-system-2.16.0.patch"))
1706 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1707 (native-inputs `(("binutils" ,binutils-mesboot)
1708 ("libc" ,glibc-mesboot0)
1709 ("gcc" ,gcc-mesboot1)
1710 ("headers" ,mesboot-headers)
1712 ("bash" ,%bootstrap-coreutils&co)
1713 ("coreutils" ,%bootstrap-coreutils&co)
1714 ("diffutils" ,diffutils-mesboot)
1715 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1716 ("make" ,make-mesboot)))
1719 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1720 ((#:configure-flags configure-flags)
1721 `(let ((out (assoc-ref %outputs "out"))
1722 (headers (assoc-ref %build-inputs "headers")))
1724 (string-append "--prefix=" out)
1725 "--disable-obsolete-rpc"
1726 "--host=i686-unknown-linux-gnu"
1727 (string-append "--with-headers=" headers "/include")
1728 "--enable-static-nss"
1732 "--enable-add-ons=nptl")))
1733 ((#:make-flags make-flags)
1734 `(let ((bash (assoc-ref %build-inputs "bash")))
1735 (list (string-append "SHELL=" bash "/bin/sh")
1736 "install-bootstrap-headers=yes" "install-headers")))
1738 `(modify-phases ,phases
1740 (lambda* (#:key inputs #:allow-other-keys)
1741 (let* ((headers (assoc-ref inputs "headers"))
1742 (libc (assoc-ref inputs "libc"))
1743 (gcc (assoc-ref inputs "gcc"))
1744 (cppflags (string-append
1745 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1746 " -D BOOTSTRAP_GLIBC=1"))
1747 (cflags (string-append " -L " (getcwd)
1748 " -L " libc "/lib")))
1749 (setenv "libc_cv_friendly_stddef" "yes")
1750 (setenv "CONFIG_SHELL" (which "sh"))
1751 (setenv "SHELL" (which "sh"))
1753 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1754 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1756 ;; avoid -fstack-protector
1757 (setenv "libc_cv_ssp" "false")
1758 (substitute* "configure"
1759 (("/bin/pwd") "pwd"))
1762 (lambda* (#:key outputs make-flags #:allow-other-keys)
1763 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1764 (out (assoc-ref outputs "out")))
1765 (apply invoke "make" make-flags)
1766 (copy-recursively kernel-headers out)
1769 (lambda* (#:key configure-flags #:allow-other-keys)
1770 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1773 (apply invoke "../configure" configure-flags)))
1774 (add-after 'configure 'remove-sunrpc
1776 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1777 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1778 (substitute* "sysd-sorted"
1781 ;; 'rpcgen' needs native libc headers to be built.
1782 (substitute* "../Makefile"
1783 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1784 (substitute* "../Makeconfig"
1785 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1786 (substitute* "../elf/Makefile"
1787 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1789 (define glibc-mesboot
1791 (inherit glibc-headers-mesboot)
1792 (name "glibc-mesboot")
1793 (native-inputs `(("binutils" ,binutils-mesboot)
1794 ("libc" ,glibc-mesboot0)
1795 ("headers" ,glibc-headers-mesboot)
1796 ("gcc" ,gcc-mesboot1)
1798 ("bash" ,%bootstrap-coreutils&co)
1799 ("coreutils" ,%bootstrap-coreutils&co)
1800 ("diffutils" ,diffutils-mesboot)
1801 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1802 ("make" ,make-mesboot)))
1805 `(#:validate-runpath? #f ; fails when using --enable-shared
1806 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1807 ((#:make-flags make-flags)
1808 `(let ((bash (assoc-ref %build-inputs "bash")))
1809 (list (string-append "SHELL=" bash "/bin/sh"))))
1811 `(modify-phases ,phases
1813 (lambda* (#:key outputs make-flags #:allow-other-keys)
1814 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1815 (out (assoc-ref outputs "out"))
1816 (install-flags (cons "install" make-flags)))
1817 (apply invoke "make" install-flags)
1818 (copy-recursively kernel-headers out)
1823 (inherit gcc-mesboot1)
1824 (name "gcc-mesboot")
1825 (version (package-version gcc-4.9))
1826 (source (bootstrap-origin (package-source gcc-4.9)))
1827 (native-inputs `(("binutils" ,binutils-mesboot)
1829 ("libc" ,glibc-mesboot)
1830 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1831 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1832 ("gcc" ,gcc-mesboot1)
1834 ("bash" ,%bootstrap-coreutils&co)
1835 ("coreutils" ,%bootstrap-coreutils&co)
1836 ("diffutils" ,diffutils-mesboot)
1837 ("make" ,make-mesboot)))
1839 `(#:validate-runpath? #f
1840 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1841 ((#:configure-flags configure-flags)
1842 `(let ((out (assoc-ref %outputs "out"))
1843 (glibc (assoc-ref %build-inputs "libc")))
1844 (list (string-append "--prefix=" out)
1845 "--build=i686-unknown-linux-gnu"
1846 "--host=i686-unknown-linux-gnu"
1848 "--with-host-libstdcxx=-lsupc++"
1850 (string-append "--with-native-system-header-dir=" glibc "/include")
1851 (string-append "--with-build-sysroot=" glibc "/include")
1853 "--disable-bootstrap"
1854 "--disable-decimal-float"
1855 "--disable-libatomic"
1856 "--disable-libcilkrts"
1859 "--disable-libmudflap"
1860 "--disable-libquadmath"
1861 "--disable-libsanitizer"
1865 "--disable-lto-plugin"
1866 "--disable-multilib"
1869 "--enable-languages=c,c++"
1873 "--enable-threads=single"
1875 ;; No pre-compiled libstdc++ headers, to save space.
1876 "--disable-libstdcxx-pch"
1879 "--disable-build-with-cxx"))))))))
1881 (define gcc-mesboot-wrapper
1882 ;; We need this so gcc-mesboot can be used to create shared binaries that
1883 ;; have the correct interpreter and runpath to libc.
1885 (inherit gcc-mesboot1-wrapper)
1886 (name "gcc-mesboot-wrapper")
1887 (version (package-version gcc-mesboot))
1890 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1891 ("libc" ,glibc-mesboot)
1892 ("gcc" ,gcc-mesboot)))))
1901 (uri (string-append "mirror://gnu/m4/m4-"
1905 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1906 (supported-systems '("i686-linux" "x86_64-linux"))
1907 (native-inputs `(("mes" ,mes-boot)
1911 (modify-phases %standard-phases
1913 (lambda* (#:key outputs #:allow-other-keys)
1914 (let ((out (assoc-ref outputs "out")))
1915 (setenv "CONFIG_SHELL" (string-append
1916 (assoc-ref %build-inputs "bash")
1918 (setenv "CC" "tcc -static")
1919 (setenv "CPP" "tcc -E")
1920 (invoke "./configure" (string-append "--prefix=" out))))))))))
1922 (define (%bootstrap-inputs+toolchain)
1923 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1924 ;; the actual reduced set with bootstrapped toolchain.
1925 (match (%current-system)
1926 ((or "i686-linux" "x86_64-linux")
1927 `(("libc" ,glibc-mesboot)
1928 ("binutils" ,binutils-mesboot)
1929 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1930 ("gcc" ,gcc-mesboot)
1931 ,@(fold alist-delete (%bootstrap-inputs)
1932 '("bootstrap-mescc-tools" "mes"))))
1934 (%bootstrap-inputs))))
1936 (define gnu-make-boot0
1939 (source (bootstrap-origin (package-source gnu-make)))
1942 `(#:guile ,%bootstrap-guile
1943 #:implicit-inputs? #f
1944 #:tests? #f ; cannot run "make check"
1945 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1946 ((#:configure-flags flags ''())
1947 ;; The generated config.status has some problems due to the
1948 ;; bootstrap environment. Disable dependency tracking to work
1950 `(cons "--disable-dependency-tracking" ,flags))
1952 `(modify-phases ,phases
1955 (invoke "./build.sh")))
1957 (lambda* (#:key outputs #:allow-other-keys)
1958 (let* ((out (assoc-ref outputs "out"))
1959 (bin (string-append out "/bin")))
1960 (install-file "make" bin)
1962 (native-inputs '()) ; no need for 'pkg-config'
1963 (inputs (%bootstrap-inputs+toolchain))))
1965 (define diffutils-boot0
1968 (name "diffutils-boot0")
1971 `(("make" ,gnu-make-boot0)
1972 ,@(%bootstrap-inputs+toolchain)))
1974 `(#:tests? #f ; the test suite needs diffutils
1975 #:guile ,%bootstrap-guile
1976 #:implicit-inputs? #f
1977 ,@(package-arguments diffutils)))))
1979 (define findutils-boot0
1982 (name "findutils-boot0")
1983 (source (bootstrap-origin (package-source findutils)))
1985 `(("make" ,gnu-make-boot0)
1986 ("diffutils" ,diffutils-boot0) ; for tests
1987 ,@(%bootstrap-inputs+toolchain)))
1989 `(#:implicit-inputs? #f
1990 #:guile ,%bootstrap-guile
1992 ;; The build system assumes we have done a mistake when time_t is 32-bit
1993 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1994 ,@(if (target-64bit?)
1995 (substitute-keyword-arguments (package-arguments findutils)
1996 ((#:configure-flags flags ''())
1997 `(cons "TIME_T_32_BIT_OK=yes"
1999 (package-arguments findutils))))))
2004 (source (bootstrap-origin (package-source file)))
2007 `(("make" ,gnu-make-boot0)
2008 ,@(%bootstrap-inputs+toolchain)))
2010 `(#:implicit-inputs? #f
2011 #:guile ,%bootstrap-guile
2012 #:strip-binaries? #f
2013 #:validate-runpath? #f))))
2015 (define (%boot0-inputs)
2016 `(("make" ,gnu-make-boot0)
2017 ("diffutils" ,diffutils-boot0)
2018 ("findutils" ,findutils-boot0)
2019 ("file" ,file-boot0)
2020 ,@(%bootstrap-inputs+toolchain)))
2022 (define* (boot-triplet #:optional (system (%current-system)))
2023 ;; Return the triplet used to create the cross toolchain needed in the
2024 ;; first bootstrapping stage.
2025 (nix-system->gnu-triplet system "guix"))
2027 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
2028 ;; toolchain actually targets the same OS and arch, but it has the advantage
2029 ;; of being independent of the libc and tools in
2030 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
2031 ;; reference to the target libc.
2033 (define binutils-boot0
2036 (source (bootstrap-origin (package-source binutils)))
2037 (name "binutils-cross-boot0")
2039 `(#:guile ,%bootstrap-guile
2040 #:implicit-inputs? #f
2042 #:modules ((guix build gnu-build-system)
2044 (ice-9 ftw)) ; for 'scandir'
2045 #:phases (modify-phases %standard-phases
2046 (add-after 'install 'add-symlinks
2047 (lambda* (#:key outputs #:allow-other-keys)
2048 ;; The cross-gcc invokes 'as', 'ld', etc, without the
2049 ;; triplet prefix, so add symlinks.
2050 (let ((out (assoc-ref outputs "out"))
2051 (triplet-prefix (string-append ,(boot-triplet) "-")))
2052 (define (has-triplet-prefix? name)
2053 (string-prefix? triplet-prefix name))
2054 (define (remove-triplet-prefix name)
2055 (substring name (string-length triplet-prefix)))
2056 (with-directory-excursion (string-append out "/bin")
2057 (for-each (lambda (name)
2058 (symlink name (remove-triplet-prefix name)))
2059 (scandir "." has-triplet-prefix?)))
2062 ,@(substitute-keyword-arguments (package-arguments binutils)
2063 ((#:configure-flags cf)
2064 `(cons ,(string-append "--target=" (boot-triplet))
2066 (inputs (%boot0-inputs))))
2068 (define libstdc++-boot0
2069 ;; GCC's libcc1 is always built as a shared library (the top-level
2070 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
2071 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
2072 ;; C++14 features missing in some of our bootstrap compilers.
2073 (let ((lib (make-libstdc++ gcc-4.9)))
2076 (source (bootstrap-origin (package-source lib)))
2077 (name "libstdc++-boot0")
2079 `(#:guile ,%bootstrap-guile
2080 #:implicit-inputs? #f
2082 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2083 #:validate-runpath? #f
2085 ,@(match (%current-system)
2086 ((or "i686-linux" "x86_64-linux")
2087 (substitute-keyword-arguments (package-arguments lib)
2089 `(modify-phases ,phases
2090 (add-after 'unpack 'workaround-wrapper-bug
2091 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
2092 ;; fail, which in turn confuses the configure script.
2094 (substitute* "libstdc++-v3/configure"
2095 (("g\\+\\+ -v") "true"))
2097 (_ (package-arguments lib)))))
2098 (inputs (%boot0-inputs))
2099 (native-inputs '()))))
2104 (name "gcc-cross-boot0")
2105 (source (bootstrap-origin (package-source gcc)))
2107 `(#:guile ,%bootstrap-guile
2108 #:implicit-inputs? #f
2109 #:modules ((guix build gnu-build-system)
2114 ,@(substitute-keyword-arguments (package-arguments gcc)
2115 ((#:configure-flags flags)
2116 `(append (list ,(string-append "--target=" (boot-triplet))
2121 ;; Disable features not needed at this stage.
2123 "--enable-languages=c,c++"
2125 ;; libstdc++ cannot be built at this stage
2126 ;; ("Link tests are not allowed after
2127 ;; GCC_NO_EXECUTABLES.").
2128 "--disable-libstdc++-v3"
2131 "--disable-libmudflap"
2132 "--disable-libatomic"
2133 "--disable-libsanitizer"
2137 "--disable-libcilkrts"
2140 "--disable-libquadmath"
2141 "--disable-decimal-float")
2142 (remove (cut string-match
2143 "--(with-system-zlib|enable-languages.*)" <>)
2145 ((#:make-flags flags)
2146 `(let* ((libc (assoc-ref %build-inputs "libc"))
2147 (libc-native (or (assoc-ref %build-inputs "libc-native")
2149 `(,(string-append "LDFLAGS="
2150 "-Wl,-rpath=" libc-native "/lib "
2151 "-Wl,-dynamic-linker "
2152 "-Wl," libc-native ,(glibc-dynamic-linker
2153 (match (%current-system)
2154 ("x86_64-linux" "i686-linux")
2155 (_ (%current-system))))))))
2157 `(modify-phases ,phases
2158 (add-after 'unpack 'unpack-gmp&co
2159 (lambda* (#:key inputs #:allow-other-keys)
2160 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2161 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2162 (mpc (assoc-ref %build-inputs "mpc-source")))
2164 ;; To reduce the set of pre-built bootstrap inputs, build
2165 ;; GMP & co. from GCC.
2166 (for-each (lambda (source)
2167 (invoke "tar" "xvf" source))
2168 (list gmp mpfr mpc))
2170 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2171 ,@(map (lambda (lib)
2172 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2174 `(symlink ,(string-trim-right
2175 (package-full-name lib "-")
2177 ,(package-name lib)))
2178 (list gmp-6.0 mpfr mpc))
2180 ,(match (%current-system)
2181 ((or "i686-linux" "x86_64-linux")
2182 '(add-before 'configure 'fix-libcc1
2183 (lambda* (#:key inputs #:allow-other-keys)
2184 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
2185 ;; to placate the 'validate-runpath' phase.
2186 (substitute* "libcc1/Makefile.in"
2188 (string-append "la_LDFLAGS = -Wl,-rpath="
2189 (assoc-ref inputs "gcc") "/lib")))
2190 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
2191 (substitute* "libcc1/configure"
2192 (("g\\+\\+ -v") "true"))
2194 (_ '(add-before 'configure 'return-true
2196 (add-after 'install 'symlink-libgcc_eh
2197 (lambda* (#:key outputs #:allow-other-keys)
2198 (let ((out (assoc-ref outputs "lib")))
2199 ;; Glibc wants to link against libgcc_eh, so provide
2201 (with-directory-excursion
2202 (string-append out "/lib/gcc/"
2204 "/" ,(package-version gcc))
2205 (symlink "libgcc.a" "libgcc_eh.a"))
2208 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2209 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
2210 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
2211 ("binutils-cross" ,binutils-boot0)
2213 ;; The libstdc++ that libcc1 links against.
2214 ("libstdc++" ,libstdc++-boot0)
2216 ;; Call it differently so that the builder can check whether
2217 ;; the "libc" input is #f.
2218 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
2219 ,@(alist-delete "libc" (%boot0-inputs))))
2221 ;; No need for the native-inputs to build the documentation at this stage.
2222 (native-inputs `())))
2228 (source (bootstrap-origin (package-source perl)))
2229 (inputs (%boot0-inputs))
2231 `(#:implicit-inputs? #f
2232 #:guile ,%bootstrap-guile
2233 #:validate-runpath? #f
2235 ;; At the very least, this must not depend on GCC & co.
2236 #:disallowed-references ,(list %bootstrap-binutils)
2238 ,@(substitute-keyword-arguments (package-arguments perl)
2240 `(modify-phases ,phases
2241 ;; Pthread support is missing in the bootstrap compiler
2242 ;; (broken spec file), so disable it.
2243 (add-before 'configure 'disable-pthreads
2245 (substitute* "Configure"
2246 (("^libswanted=(.*)pthread" _ before)
2247 (string-append "libswanted=" before)))
2249 ;; Do not configure with '-Dusethreads' since pthread
2250 ;; support is missing.
2251 ((#:configure-flags configure-flags)
2252 `(delete "-Dusethreads" ,configure-flags)))))))
2258 (source (bootstrap-origin (package-source m4)))
2259 (inputs (%boot0-inputs))
2261 `(#:guile ,%bootstrap-guile
2262 #:implicit-inputs? #f
2263 ,@(package-arguments m4)))))
2266 ;; This Bison is needed to build MiG so we need it early in the process.
2267 ;; Recent versions of Linux-Libre headers also depend on this.
2270 (name "bison-boot0")
2271 (propagated-inputs `(("m4" ,m4-boot0)))
2272 (native-inputs `(("perl" ,perl-boot0)))
2273 (inputs (%boot0-inputs)) ;remove Flex...
2275 `(#:tests? #f ;... and thus disable tests
2276 #:implicit-inputs? #f
2277 #:guile ,%bootstrap-guile
2279 ;; Zero timestamps in liby.a; this must be done
2280 ;; explicitly here because the bootstrap Binutils don't
2281 ;; do that (default is "cru".)
2282 #:make-flags `("ARFLAGS=crD"
2283 ,,(match (%current-system)
2284 ;; ranlib: '-D': No such file
2285 ((or "i686-linux" "x86_64-linux")
2288 "RANLIB=ranlib -D"))
2291 ,@(package-arguments bison)))))
2294 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
2297 (native-inputs `(("bison" ,bison-boot0)))
2298 (propagated-inputs `(("m4" ,m4-boot0)))
2299 (inputs (%boot0-inputs))
2301 `(#:implicit-inputs? #f
2302 #:guile ,%bootstrap-guile
2308 (native-inputs `(("perl" ,perl-boot0)))
2309 (inputs (%boot0-inputs))
2311 `(#:implicit-inputs? #f
2312 #:guile ,%bootstrap-guile))))
2314 (define linux-libre-headers-boot0
2316 "Return Linux-Libre header files for the bootstrap environment."
2317 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
2318 ;; between (gnu packages linux) and this module. Additionally, memoize
2319 ;; the result to play well with further memoization and code that relies
2320 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
2322 (inherit linux-libre-headers)
2324 `(#:guile ,%bootstrap-guile
2325 #:implicit-inputs? #f
2326 ,@(package-arguments linux-libre-headers)))
2328 `(("perl" ,perl-boot0)
2330 ;; Flex and Bison are required since version 4.16.
2331 ("flex" ,flex-boot0)
2332 ("bison" ,bison-boot0)
2334 ;; Rsync is required since version 5.3.
2335 ("rsync" ,rsync-boot0)
2336 ,@(%boot0-inputs))))))
2339 (package-with-explicit-inputs %boot0-inputs
2342 (define gnumach-headers-boot0
2343 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
2346 (let* ((mig (package
2347 (inherit (package-with-bootstrap-guile mig))
2348 (native-inputs `(("bison" ,bison-boot0)
2349 ("flex" ,flex-boot0)))
2350 (inputs `(("flex" ,flex-boot0)))
2353 `(,(string-append "LDFLAGS=-Wl,-rpath="
2354 (assoc-ref %build-inputs "flex") "/lib/")))))))
2357 (define hurd-headers-boot0
2358 (let ((hurd-headers (package (inherit hurd-headers)
2359 (native-inputs `(("mig" ,mig-boot0)))
2361 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
2363 (define hurd-minimal-boot0
2364 (let ((hurd-minimal (package (inherit hurd-minimal)
2365 (native-inputs `(("mig" ,mig-boot0)))
2367 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
2369 (define hurd-core-headers-boot0
2371 "Return the Hurd and Mach headers as well as initial Hurd libraries for
2372 the bootstrap environment."
2373 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
2374 (arguments `(#:guile ,%bootstrap-guile
2375 ,@(package-arguments hurd-core-headers)))
2377 `(("gnumach-headers" ,gnumach-headers-boot0)
2378 ("hurd-headers" ,hurd-headers-boot0)
2379 ("hurd-minimal" ,hurd-minimal-boot0)
2380 ,@(%boot0-inputs))))))
2382 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
2384 ("i586-gnu" (hurd-core-headers-boot0))
2385 (_ (linux-libre-headers-boot0))))
2387 (define texinfo-boot0
2388 ;; Texinfo used to build libc's manual.
2389 ;; We build without ncurses because it fails to build at this stage, and
2390 ;; because we don't need the stand-alone Info reader.
2391 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
2395 (inputs `(,@(%boot0-inputs)
2396 ("perl" ,perl-boot0)))
2398 `(#:implicit-inputs? #f
2399 #:guile ,%bootstrap-guile
2401 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
2402 ;; character type in locale" but we don't have a UTF-8 locale at this
2403 ;; stage, so skip them.
2406 (define expat-sans-tests
2409 (inputs (%boot0-inputs))
2411 ;; XXX: Linking 'runtestscpp' fails with things like:
2413 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
2415 ;; Skip tests altogether.
2416 `(#:implicit-inputs? #f
2417 #:guile ,%bootstrap-guile
2419 ,@(substitute-keyword-arguments (package-arguments expat)
2420 ((#:configure-flags flags ''())
2421 ;; Since we're not passing the right -Wl,-rpath flags, build the
2422 ;; static library to avoid RUNPATH validation failure.
2423 `(cons "--disable-shared" ,flags))
2424 ((#:tests? _ #f) #f))))))
2426 (define python-boot0
2428 (inherit python-minimal)
2429 ;; We cannot use Python 3.7 and later here, because they require
2430 ;; pthreads, which is missing on non-x86 platforms at this stage.
2431 ;; Python 3.6 technically supports being built without threading
2432 ;; support, but requires additional patches.
2434 (source (bootstrap-origin
2437 (uri (string-append "https://www.python.org/ftp/python/"
2438 version "/Python-" version ".tar.xz"))
2441 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
2442 (modules '((guix build utils)))
2445 ;; Delete the bundled copy of libexpat.
2446 (delete-file-recursively "Modules/expat")
2447 (substitute* "Modules/Setup.dist"
2448 ;; Link Expat instead of embedding the bundled one.
2449 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
2453 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
2454 (native-inputs '()) ;and pkg-config
2456 `(#:implicit-inputs? #f
2457 #:guile ,%bootstrap-guile
2459 ,@(substitute-keyword-arguments (package-arguments python-minimal)
2460 ;; Disable features that cannot be built at this stage.
2461 ((#:configure-flags _ ''())
2462 `(list "--without-ensurepip"
2463 "--without-threads"))
2464 ;; Clear #:make-flags, such that changes to the regular
2465 ;; Python package won't interfere with this one.
2466 ((#:make-flags _ ''()) ''())
2468 `(modify-phases ,phases
2469 (add-before 'configure 'disable-modules
2471 (substitute* "setup.py"
2472 ;; Disable ctypes, since it requires libffi.
2473 (("extensions\\.append\\(ctypes\\)") "")
2474 ;; Prevent the 'ossaudiodev' extension from being
2475 ;; built, since it requires Linux headers.
2478 (delete 'set-TZDIR)))
2479 ((#:tests? _ #f) #f))))))
2481 (define ld-wrapper-boot0
2483 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
2484 ;; in their RUNPATH, otherwise validate-runpath will fail.
2485 (make-ld-wrapper "ld-wrapper-boot0"
2486 #:target boot-triplet
2487 #:binutils binutils-boot0
2488 #:guile %bootstrap-guile
2489 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
2490 #:guile-for-build %bootstrap-guile)))
2492 (define (%boot1-inputs)
2493 ;; 2nd stage inputs.
2494 `(("gcc" ,gcc-boot0)
2495 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
2496 ("binutils-cross" ,binutils-boot0)
2497 ,@(alist-delete "binutils" (%boot0-inputs))))
2499 (define glibc-final-with-bootstrap-bash
2500 ;; The final libc, "cross-built". If everything went well, the resulting
2501 ;; store path has no dependencies. Actually, the really-final libc is
2502 ;; built just below; the only difference is that this one uses the
2506 (name "glibc-intermediate")
2507 (source (bootstrap-origin (package-source glibc)))
2509 `(#:guile ,%bootstrap-guile
2510 #:implicit-inputs? #f
2512 ,@(substitute-keyword-arguments (package-arguments glibc)
2513 ((#:configure-flags flags)
2514 `(append (list ,(string-append "--host=" (boot-triplet))
2515 ,(string-append "--build="
2516 (nix-system->gnu-triplet)))
2519 `(modify-phases ,phases
2520 (add-before 'configure 'pre-configure
2521 (lambda* (#:key inputs #:allow-other-keys)
2522 ;; Don't clobber CPATH with the bootstrap libc.
2523 (setenv "NATIVE_CPATH" (getenv "CPATH"))
2526 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
2527 ,@(if (hurd-triplet? (%current-system))
2528 `((substitute* "libpthread/Makefile"
2529 (("LDLIBS-pthread.so =.*")
2530 (string-append "LDLIBS-pthread.so = "
2531 (assoc-ref %build-inputs "kernel-headers")
2532 "/lib/libihash.a\n"))))
2535 ;; 'rpcgen' needs native libc headers to be built.
2536 (substitute* "sunrpc/Makefile"
2537 (("sunrpc-CPPFLAGS =.*" all)
2538 (string-append "CPATH = $(NATIVE_CPATH)\n"
2542 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2544 `(("bison" ,bison-boot0)
2545 ("texinfo" ,texinfo-boot0)
2546 ("perl" ,perl-boot0)
2547 ("python" ,python-boot0)))
2549 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2550 ;; it in $CPATH, hence the 'pre-configure' phase above.
2553 ;; A native MiG is needed to build Glibc on Hurd.
2554 ,@(if (hurd-triplet? (%current-system))
2555 `(("mig" ,mig-boot0))
2558 ;; A native GCC is needed to build `cross-rpcgen'.
2559 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2561 ;; Here, we use the bootstrap Bash, which is not satisfactory
2562 ;; because we don't want to depend on bootstrap tools.
2563 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
2565 (define (cross-gcc-wrapper gcc binutils glibc bash)
2566 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2567 that makes it available under the native tool names."
2568 (package (inherit gcc)
2569 (name (string-append (package-name gcc) "-wrapped"))
2571 (build-system trivial-build-system)
2574 `(#:guile ,%bootstrap-guile
2575 #:modules ((guix build utils))
2577 (use-modules (guix build utils))
2579 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2580 (gcc (assoc-ref %build-inputs "gcc"))
2581 (libc (assoc-ref %build-inputs "libc"))
2582 (bash (assoc-ref %build-inputs "bash"))
2583 (out (assoc-ref %outputs "out"))
2584 (bindir (string-append out "/bin"))
2585 (triplet ,(boot-triplet)))
2586 (define (wrap-program program)
2587 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2588 ;; needs to be told where to find the crt files and
2589 ;; the dynamic linker.
2590 (call-with-output-file program
2592 (format p "#!~a/bin/bash
2593 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2597 ,(glibc-dynamic-linker))))
2599 (chmod program #o555))
2602 (with-directory-excursion bindir
2603 (for-each (lambda (tool)
2604 (symlink (string-append binutils "/bin/"
2608 (for-each wrap-program '("gcc" "g++")))
2612 `(("binutils" ,binutils)
2618 (define gcc-boot0-intermediate-wrapped
2620 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2622 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2623 glibc-final-with-bootstrap-bash
2624 (car (assoc-ref (%boot1-inputs) "bash")))))
2626 (define static-bash-for-glibc
2627 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
2629 (inherit static-bash)
2630 (source (bootstrap-origin (package-source static-bash)))
2631 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2632 ("libc" ,glibc-final-with-bootstrap-bash)
2633 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2634 ,@(fold alist-delete (%boot1-inputs)
2637 `(#:implicit-inputs? #f
2638 #:guile ,%bootstrap-guile
2640 ,@(substitute-keyword-arguments (package-arguments static-bash)
2641 ((#:configure-flags flags '())
2642 ;; Add a '-L' flag so that the pseudo-cross-ld of
2643 ;; BINUTILS-BOOT0 can find libc.a.
2645 (list (string-append "LDFLAGS=-static -L"
2646 (assoc-ref %build-inputs
2650 (define gettext-boot0
2651 ;; A minimal gettext used during bootstrap.
2653 (inherit gettext-minimal)
2654 (name "gettext-boot0")
2655 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2656 ;; simplify the dependency chain, we stick to this version here.
2657 (version "0.19.8.1")
2660 (uri (string-append "mirror://gnu/gettext/gettext-"
2664 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2665 (inputs (%boot1-inputs)) ;zero dependencies
2667 `(#:implicit-inputs? #f
2668 #:guile ,%bootstrap-guile
2670 #:phases (modify-phases %standard-phases
2671 ;; Build only the tools.
2672 (add-after 'unpack 'chdir
2674 (chdir "gettext-tools")
2677 ;; Some test programs require pthreads, which we don't have.
2678 (add-before 'configure 'no-test-programs
2680 (substitute* "tests/Makefile.in"
2686 ;; The final glibc, which embeds the statically-linked Bash built above.
2687 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2691 (source (bootstrap-origin (package-source glibc)))
2692 (inputs `(("static-bash" ,static-bash-for-glibc)
2695 (package-inputs glibc-final-with-bootstrap-bash))))
2697 ;; This time we need 'msgfmt' to install all the libc.mo files.
2698 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2699 ("gettext" ,gettext-boot0)))
2702 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2704 ;; The final libc only refers to itself, but the 'debug' output contains
2705 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2706 ;; if 'allowed-references' were per-output.
2708 `(#:allowed-references
2709 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2710 static-bash-for-glibc
2711 (package-outputs glibc-final-with-bootstrap-bash))
2713 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2715 (define gcc-boot0-wrapped
2717 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2719 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2720 (car (assoc-ref (%boot1-inputs) "bash")))))
2722 (define (%boot2-inputs)
2723 ;; 3rd stage inputs.
2724 `(("libc" ,glibc-final)
2725 ("libc:static" ,glibc-final "static")
2726 ("gcc" ,(gcc-boot0-wrapped))
2727 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2729 (define binutils-final
2732 (source (bootstrap-origin (package-source binutils)))
2734 `(#:guile ,%bootstrap-guile
2735 #:implicit-inputs? #f
2736 #:allowed-references ("out" ,glibc-final)
2737 ,@(package-arguments binutils)))
2738 (inputs (%boot2-inputs))))
2741 ;; Intermediate libstdc++ that will allow us to build the final GCC
2742 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2743 (let ((lib (make-libstdc++ gcc)))
2746 (source (bootstrap-origin (package-source lib)))
2748 `(#:guile ,%bootstrap-guile
2749 #:implicit-inputs? #f
2750 #:allowed-references ("out")
2752 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2753 #:validate-runpath? #f
2755 ;; All of the package arguments from 'make-libstdc++
2756 ;; except for the configure-flags.
2757 ,@(package-arguments lib)
2758 #:configure-flags `("--disable-shared"
2759 "--disable-libstdcxx-dual-abi"
2760 "--disable-libstdcxx-threads"
2761 "--disable-libstdcxx-pch"
2762 ,(string-append "--with-gxx-include-dir="
2763 (assoc-ref %outputs "out")
2766 (inputs (%boot2-inputs))
2767 (synopsis "GNU C++ standard library (intermediate)"))))
2770 ;; Zlib used by GCC-FINAL.
2774 `(#:guile ,%bootstrap-guile
2775 #:implicit-inputs? #f
2776 #:allowed-references ("out" ,glibc-final)
2777 ,@(package-arguments zlib)))
2778 (inputs (%boot2-inputs))))
2780 (define ld-wrapper-boot3
2782 ;; A linker wrapper that uses the bootstrap Guile.
2783 (make-ld-wrapper "ld-wrapper-boot3"
2784 #:binutils binutils-final
2785 #:guile %bootstrap-guile
2786 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2787 #:guile-for-build %bootstrap-guile)))
2791 (package (inherit gcc-boot0)
2794 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2795 ;; "debug" output contains disallowed references, notably
2796 ;; linux-libre-headers. Disable the debugging output to work around that.
2797 (outputs (delete "debug" (package-outputs gcc-boot0)))
2800 `(#:guile ,%bootstrap-guile
2801 #:implicit-inputs? #f
2803 #:allowed-references ("out" "lib" ,zlib-final
2804 ,glibc-final ,static-bash-for-glibc)
2806 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2807 ;; reason, but it is not in their RUNPATH. This is a false
2808 ;; positive, so turn it off.
2809 #:validate-runpath? #f
2811 ,@(substitute-keyword-arguments (package-arguments gcc)
2812 ((#:make-flags flags)
2813 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2814 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2816 (if (string-prefix? "LDFLAGS=" flag)
2817 (string-append flag " -L"
2818 (assoc-ref %build-inputs "libstdc++")
2819 "/lib -L" zlib "/lib -Wl,-rpath="
2823 ;; Build again GMP & co. within GCC's build process, because it's hard
2824 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2825 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2827 `(modify-phases ,phases
2828 (add-after 'unpack 'unpack-gmp&co
2829 (lambda* (#:key inputs #:allow-other-keys)
2830 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2831 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2832 (mpc (assoc-ref %build-inputs "mpc-source")))
2834 ;; To reduce the set of pre-built bootstrap inputs, build
2835 ;; GMP & co. from GCC.
2836 (for-each (lambda (source)
2837 (invoke "tar" "xvf" source))
2838 (list gmp mpfr mpc))
2840 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2841 ,@(map (lambda (lib)
2842 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2844 `(symlink ,(string-trim-right
2845 (package-full-name lib "-")
2847 ,(package-name lib)))
2848 (list gmp-6.0 mpfr mpc))
2851 ;; This time we want Texinfo, so we get the manual. Add
2852 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2853 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2855 (native-inputs `(("texinfo" ,texinfo-boot0)
2856 ("perl" ,perl-boot0) ;for manpages
2857 ("static-bash" ,static-bash-for-glibc)
2858 ,@(package-native-inputs gcc-boot0)))
2860 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2861 ("mpfr-source" ,(package-source mpfr))
2862 ("mpc-source" ,(package-source mpc))
2863 ("ld-wrapper" ,(ld-wrapper-boot3))
2864 ("binutils" ,binutils-final)
2865 ("libstdc++" ,libstdc++)
2866 ("zlib" ,zlib-final)
2867 ,@(%boot2-inputs)))))
2869 (define (%boot3-inputs)
2870 ;; 4th stage inputs.
2871 `(("gcc" ,gcc-final)
2872 ("ld-wrapper" ,(ld-wrapper-boot3))
2873 ,@(alist-delete "gcc" (%boot2-inputs))))
2876 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2877 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2878 ;; on Readline and ncurses.
2879 (let ((bash (static-libgcc-package bash-minimal)))
2882 (source (bootstrap-origin (package-source bash)))
2883 (inputs (%boot3-inputs))
2885 `(#:implicit-inputs? #f
2886 #:guile ,%bootstrap-guile
2888 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2890 ,@(package-arguments bash))))))
2892 (define (%boot4-inputs)
2893 ;; Now use the final Bash.
2894 `(("bash" ,bash-final)
2895 ,@(alist-delete "bash" (%boot3-inputs))))
2898 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2900 (define-public guile-final
2901 ;; This package must be public because other modules refer to it. However,
2902 ;; mark it as hidden so that 'fold-packages' ignores it.
2903 (with-boot4 (hidden-package
2904 (package-with-bootstrap-guile guile-2.2/fixed))))
2906 (define glibc-utf8-locales-final
2907 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2908 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2909 ;; with the full range of Unicode codepoints (remember
2910 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2913 (inherit glibc-utf8-locales)
2915 `(("glibc" ,glibc-final)
2916 ("gzip" ,(with-boot4 gzip))))))
2918 (define-public ld-wrapper
2919 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2920 (make-ld-wrapper "ld-wrapper"
2921 #:binutils binutils-final
2925 (define (%boot5-inputs)
2926 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2927 ;; with an older libc, which cannot load the new locale format. See
2928 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2929 `(("locales" ,glibc-utf8-locales-final)
2933 (package-with-explicit-inputs %boot5-inputs))
2935 (define gnu-make-final
2936 ;; The final GNU Make, which uses the final Guile.
2937 (let ((pkg-config (package
2938 (inherit %pkg-config) ;the native pkg-config
2939 (inputs `(("guile" ,guile-final)
2942 `(#:implicit-inputs? #f
2943 ,@(package-arguments pkg-config))))))
2945 (inherit (package-with-bootstrap-guile gnu-make))
2946 (inputs `(("guile" ,guile-final)
2948 (native-inputs `(("pkg-config" ,pkg-config)))
2950 `(#:implicit-inputs? #f
2951 ,@(package-arguments gnu-make))))))
2954 (define coreutils-final
2955 ;; The final Coreutils. Treat them specially because some packages, such as
2956 ;; Findutils, keep a reference to the Coreutils they were built with.
2957 (with-boot5 (package-with-bootstrap-guile coreutils)
2958 ;; Use the final Guile, linked against the
2959 ;; final libc with working iconv, so that
2960 ;; 'substitute*' works well when touching
2961 ;; test files in Gettext.
2965 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2966 ;; built before gzip.
2967 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2968 (package/inherit grep
2969 (inputs (alist-delete "pcre" (package-inputs grep)))
2970 (native-inputs `(("perl" ,perl-boot0))))))
2972 (define (%boot6-inputs)
2973 ;; Now use the final Coreutils.
2974 `(("coreutils" ,coreutils-final)
2975 ("grep" ,grep-final)
2979 (package-with-explicit-inputs %boot6-inputs))
2983 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2984 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2986 (define-public %final-inputs
2987 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2988 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2989 ;; used for origins that have patches, thereby avoiding circular
2991 (let ((finalize (compose with-boot6
2992 package-with-bootstrap-guile)))
2993 `(,@(map (match-lambda
2995 (list name (finalize package))))
3001 ("diffutils" ,diffutils)
3003 ("findutils" ,findutils)
3006 ("grep" ,grep-final)
3007 ("coreutils" ,coreutils-final)
3008 ("make" ,gnu-make-final)
3009 ("bash" ,bash-final)
3010 ("ld-wrapper" ,ld-wrapper)
3011 ("binutils" ,binutils-final)
3013 ("libc" ,glibc-final)
3014 ("libc:static" ,glibc-final "static")
3015 ("locales" ,glibc-utf8-locales-final))))
3017 (define-public canonical-package
3018 (let ((name->package (fold (lambda (input result)
3020 ((_ package . outputs)
3021 (vhash-cons (package-full-name package)
3024 `(("guile" ,guile-final)
3027 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
3028 the implicit inputs of 'gnu-build-system', return that one, otherwise return
3031 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
3032 COREUTILS-FINAL vs. COREUTILS, etc."
3033 ;; XXX: This doesn't handle dependencies of the final inputs, such as
3034 ;; libunistring, GMP, etc.
3035 (match (vhash-assoc (package-full-name package) name->package)
3037 ;; In general we want CANON, except if we're cross-compiling: CANON
3038 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
3039 ;; process, with dependencies on things that cannot be
3041 (if (%current-target-system)
3051 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
3052 ;; instantiated like this:
3054 ;; (define-public gcc-glibc-2.27-toolchain
3055 ;; (make-gcc-toolchain gcc glibc-2.27))
3057 (define* (make-gcc-toolchain gcc
3060 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
3061 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
3062 (libc (if libc libc glibc-final)))
3064 (name (string-append (package-name gcc) "-toolchain"))
3065 (version (package-version gcc))
3067 (build-system trivial-build-system)
3069 '(#:modules ((guix build union))
3071 (use-modules (ice-9 match)
3075 (let ((out (assoc-ref %outputs "out")))
3077 (match %build-inputs
3078 (((names . directories) ...)
3079 (union-build out directories)))
3081 (union-build (assoc-ref %outputs "debug")
3082 (list (assoc-ref %build-inputs
3084 (union-build (assoc-ref %outputs "static")
3085 (list (assoc-ref %build-inputs
3089 (native-search-paths (package-native-search-paths gcc))
3090 (search-paths (package-search-paths gcc))
3092 (license (package-license gcc))
3093 (synopsis "Complete GCC tool chain for C/C++ development")
3095 "This package provides a complete GCC tool chain for C/C++ development to
3096 be installed in user profiles. This includes GCC, as well as libc (headers and
3097 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
3098 (home-page "https://gcc.gnu.org/")
3099 (outputs '("out" "debug" "static"))
3101 ;; The main raison d'être of this "meta-package" is (1) to conveniently
3102 ;; install everything that we need, and (2) to make sure ld-wrapper comes
3103 ;; before Binutils' ld in the user's profile.
3104 (inputs `(("gcc" ,gcc)
3105 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
3106 ("binutils" ,binutils-final)
3108 ("libc-debug" ,libc "debug")
3109 ("libc-static" ,libc "static"))))))
3111 (define-public gcc-toolchain
3112 (make-gcc-toolchain gcc-final))
3114 (define-public gcc-toolchain-4.8
3115 (make-gcc-toolchain gcc-4.8))
3117 (define-public gcc-toolchain-4.9
3118 (make-gcc-toolchain gcc-4.9))
3120 (define-public gcc-toolchain-5
3121 (make-gcc-toolchain gcc-5))
3123 (define-public gcc-toolchain-6
3124 (make-gcc-toolchain gcc-6))
3126 (define-public gcc-toolchain-7
3129 (define-public gcc-toolchain-8
3130 (make-gcc-toolchain gcc-8))
3132 (define-public gcc-toolchain-9
3133 (make-gcc-toolchain gcc-9))
3135 ;; Provide the Fortran toolchain package only for the version of gfortran that
3136 ;; is used by Guix internally to build Fortran libraries, because combining
3137 ;; code compiled with different versions can cause problems.
3139 (define-public gfortran-toolchain
3140 (package (inherit (make-gcc-toolchain gfortran))
3141 (synopsis "Complete GCC tool chain for Fortran development")
3142 (description "This package provides a complete GCC tool chain for
3143 Fortran development to be installed in user profiles. This includes
3144 gfortran, as well as libc (headers and binaries, plus debugging symbols
3145 in the @code{debug} output), and binutils.")))
3148 ;;; commencement.scm ends here