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 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
9 ;;; Copyright © 2019 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 texinfo)
48 #:use-module (gnu packages pkg-config)
49 #:use-module (gnu packages xml)
50 #:use-module (guix packages)
51 #:use-module (guix download)
52 #:use-module (guix build-system gnu)
53 #:use-module (guix build-system trivial)
54 #:use-module (guix memoization)
55 #:use-module (guix utils)
56 #:use-module (srfi srfi-1)
57 #:use-module (ice-9 vlist)
58 #:use-module (ice-9 match)
59 #:export (make-gcc-toolchain))
63 ;;; This is the commencement, this is where things start. Before the
64 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
65 ;;; with the initial binaries. This module uses those bootstrap binaries to
66 ;;; actually build up the whole tool chain that make up the implicit inputs of
67 ;;; 'gnu-build-system'.
69 ;;; To avoid circular dependencies, this module should not be imported
70 ;;; directly from anywhere.
72 ;;; Below, we frequently use "inherit" to create modified packages. The
73 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
74 ;;; not want these commencement packages to inherit grafts. By definition,
75 ;;; these packages are not depended on at run time by any of the packages we
76 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
77 ;;; grafts would often lead to extra overhead for users who would end up
78 ;;; downloading those "-boot0" packages just to build package replacements
79 ;;; that are in fact not going to be used.
90 (uri (string-append "mirror://gnu/mes/"
91 "mes-" version ".tar.gz"))
94 "15h4yhaywdc0djpjlin2jz1kzahpqxfki0r0aav1qm9nxxmnp1l0"))))
96 (propagated-inputs '())
98 `(("mescc-tools" ,%bootstrap-mescc-tools)
99 ("nyacc-source" ,(bootstrap-origin
100 (package-source nyacc-0.86)))
102 ("coreutils" , %bootstrap-coreutils&co)
103 ("bootstrap-mes" ,%bootstrap-mes)))
105 `(#:implicit-inputs? #f
106 #:guile ,%bootstrap-guile
107 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
109 (modify-phases %standard-phases
110 (add-after 'unpack 'unpack-seeds
112 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source"))
113 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
114 (with-directory-excursion ".."
115 (mkdir-p "nyacc-source")
116 (invoke "tar" "--strip=1" "-C" "nyacc-source" "-xvf" nyacc-source)
117 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
120 (lambda* (#:key outputs #:allow-other-keys)
121 (let ((out (assoc-ref %outputs "out")))
122 (setenv "GUILE" "mes")
123 (setenv "GUILE_EFFECTIVE_VERSION" "2.2")
124 (setenv "GUILE_LOAD_PATH" "nyacc")
125 (symlink (string-append "../nyacc-source/module") "nyacc")
126 (invoke "bash" "configure.sh"
127 (string-append "--prefix=" out)))))
130 (let ((mes (assoc-ref %build-inputs "bootstrap-mes")))
131 (setenv "MES_PREFIX" (string-append mes "/share/mes"))
132 (setenv "MES_ARENA" "100000000")
133 (setenv "MES_MAX_ARENA" "100000000")
134 (setenv "MES_STACK" "10000000")
135 (invoke "sh" "bootstrap.sh"))))
138 (setenv "DIFF" "sh scripts/diff.scm")
140 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/t")
141 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/63-struct-cell")
142 (invoke "sh" "check.sh")))
145 (invoke "sh" "install.sh"))))))
147 (list (search-path-specification
148 (variable "C_INCLUDE_PATH")
149 (files '("share/mes/include")))
150 (search-path-specification
151 (variable "LIBRARY_PATH")
152 (files '("share/mes/lib")))))))
155 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
156 ;; patches. In a very early and rough form they were presented to the
157 ;; TinyCC developers, who at the time showed no interest in supporting the
158 ;; bootstrappable effort; we will try again later. These patches have been
159 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
160 ;; mature, this package should use the 0.9.27 sources (or later).
161 (let ((version "0.9.26")
163 (commit "c004e9a34fb026bb44d211ab98bb768e79900eef"))
167 (version (string-append version "-" revision "." (string-take commit 7)))
170 (uri (list (string-append "mirror://gnu/guix/mirror"
171 "/tinycc-" commit ".tar.gz")
172 (string-append "https://gitlab.com/janneke/tinycc"
174 "/tinycc-" commit ".tar.gz")))
177 "1hmzn1pq0x22ppd80hyrn5qzqq94mxd0ychzj6vrr2vnj2frjv5b"))))
178 (build-system gnu-build-system)
179 (supported-systems '("i686-linux" "x86_64-linux"))
181 (propagated-inputs '())
184 ("mescc-tools" ,%bootstrap-mescc-tools)
185 ("nyacc-source" ,(bootstrap-origin
186 (package-source nyacc-0.86)))
188 ("coreutils" , %bootstrap-coreutils&co)
189 ("bootstrap-mes" ,%bootstrap-mes)))
191 `(#:implicit-inputs? #f
192 #:guile ,%bootstrap-guile
193 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
195 (modify-phases %standard-phases
196 (add-after 'unpack 'unpack-seeds
197 (lambda* (#:key outputs #:allow-other-keys)
198 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
199 (nyacc-source (assoc-ref %build-inputs "nyacc-source"))
200 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
201 (setenv "PATH" (string-append
203 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
204 (with-directory-excursion ".."
205 (mkdir-p "nyacc-source")
206 (invoke "tar" "--strip=1" "-C" "nyacc-source"
208 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
211 (lambda* (#:key outputs #:allow-other-keys)
212 (let* ((out (assoc-ref %outputs "out"))
213 (dir (with-directory-excursion ".." (getcwd)))
214 (coreutils (assoc-ref %build-inputs "coreutils"))
215 (mes (assoc-ref %build-inputs "mes"))
216 (mescc-tools (assoc-ref %build-inputs "mescc-tools"))
217 (libc (assoc-ref %build-inputs "libc"))
218 (interpreter (if libc
219 ;; also for x86_64-linux, we are still on i686-linux
220 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
221 (string-append mes "/lib/mes-loader"))))
222 (setenv "PATH" (string-append
225 ":" mescc-tools "/bin"))
226 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
228 (setenv "PREFIX" out)
229 (symlink (string-append mes "/share/mes") "mes")
230 (symlink (string-append "../nyacc-source/module") "nyacc")
231 (setenv "MES_PREFIX" "mes")
232 (setenv "MES_ARENA" "100000000")
233 (setenv "MES_MAX_ARENA" "100000000")
234 (setenv "MES_STACK" "10000000")
236 (setenv "GUILE_LOAD_PATH" "nyacc")
237 (invoke "sh" "configure"
239 (string-append "--elfinterp=" interpreter)
244 (substitute* "bootstrap.sh"
246 (invoke "sh" "bootstrap.sh")))
249 (setenv "DIFF" "diff.scm")
250 (setenv "OBJDUMP" "true")
252 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
253 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
254 (setenv "TCC" "./tcc")
255 (invoke "sh" "check.sh")))
258 (invoke "sh" "install.sh"))))))
260 (list (search-path-specification
261 (variable "C_INCLUDE_PATH")
262 (files '("include")))
263 (search-path-specification
264 (variable "LIBRARY_PATH")
265 (files '("lib"))))))))
272 (source (bootstrap-origin
274 (inherit (package-source tcc))
275 (patches (search-patches "tcc-boot-0.9.27.patch")))))
276 (build-system gnu-build-system)
278 (propagated-inputs '())
283 ("coreutils" , %bootstrap-coreutils&co)))
285 `(#:implicit-inputs? #f
286 #:guile ,%bootstrap-guile
288 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
289 ;; with MesCC/M1/hex2-built binaries.
293 (modify-phases %standard-phases
295 (lambda* (#:key outputs #:allow-other-keys)
296 (let* ((out (assoc-ref %outputs "out"))
297 (coreutils (assoc-ref %build-inputs "coreutils"))
298 (mes (assoc-ref %build-inputs "mes"))
299 (tcc (assoc-ref %build-inputs "tcc"))
300 (libc (assoc-ref %build-inputs "libc"))
301 (interpreter (if libc
302 ;; also for x86_64-linux, we are still on i686-linux
303 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
304 (string-append mes "/lib/mes-loader"))))
306 (setenv "PATH" (string-append
309 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
310 (invoke "sh" "configure"
311 (string-append "--cc=tcc")
312 (string-append "--cpu=i386")
313 (string-append "--prefix=" out)
314 (string-append "--elfinterp=" interpreter)
315 (string-append "--crtprefix=" tcc "/lib")
316 (string-append "--sysincludepaths=" tcc "/include")
317 (string-append "--libpaths=" tcc "/lib")))))
319 (lambda* (#:key outputs #:allow-other-keys)
320 (let* ((out (assoc-ref %outputs "out"))
321 (mes (assoc-ref %build-inputs "mes"))
322 (tcc (assoc-ref %build-inputs "tcc"))
323 (libc (assoc-ref %build-inputs "libc"))
324 (interpreter (if libc
325 ;; also for x86_64-linux, we are still on i686-linux
326 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
327 (string-append mes "/lib/mes-loader"))))
332 "-D" "TCC_TARGET_I386=1"
333 "-D" "CONFIG_TCC_STATIC=1"
334 "-D" "CONFIG_USE_LIBGCC=1"
335 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
336 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
337 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
339 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
340 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
341 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
342 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
347 ;; FIXME: add sensible check target (without depending on make)
349 (= 1 (status:exit-val (system* "./tcc" "--help")))))
351 (lambda* (#:key outputs #:allow-other-keys)
352 (let ((out (assoc-ref %outputs "out"))
353 (tcc (assoc-ref %build-inputs "tcc")))
354 (mkdir-p (string-append out "/bin"))
355 (copy-file "tcc" (string-append out "/bin/tcc"))
356 (mkdir-p (string-append out "/lib/tcc"))
357 (copy-recursively (string-append tcc "/include")
358 (string-append out "/include"))
359 (copy-recursively (string-append tcc "/lib")
360 (string-append out "/lib"))
361 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
362 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
363 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
364 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
365 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
368 (define make-mesboot0
371 (name "make-mesboot0")
375 (uri (string-append "mirror://gnu/make/make-"
379 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
380 (supported-systems '("i686-linux" "x86_64-linux"))
382 (propagated-inputs '())
383 (native-inputs `(("tcc" ,tcc-boot)
385 ("bash" ,%bootstrap-coreutils&co)
386 ("coreutils" ,%bootstrap-coreutils&co)))
388 `(#:implicit-inputs? #f
389 #:tests? #f ; check depends on perl
390 #:guile ,%bootstrap-guile
391 #:configure-flags `("CC=tcc -DO_RDONLY=0"
395 (modify-phases %standard-phases
396 (add-after 'configure 'configure-fixup
398 (substitute* "build.sh"
399 (("^REMOTE=.*") "REMOTE=stub\n")
400 (("^extras=.*") "extras=getloadavg.c\n"))
401 (substitute* "make.h"
402 (("^extern long int lseek.*" all) (string-append "// " all)))
404 (delete 'patch-generated-file-shebangs) ; no perl
407 (invoke "sh" "./build.sh")))
409 (lambda* (#:key outputs #:allow-other-keys)
410 (let* ((out (assoc-ref outputs "out"))
411 (bin (string-append out "/bin")))
412 (install-file "make" bin)
415 (define diffutils-mesboot
418 (name "diffutils-mesboot")
422 (uri (string-append "mirror://gnu/diffutils/diffutils-"
426 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
427 (supported-systems '("i686-linux" "x86_64-linux"))
429 (propagated-inputs '())
430 (native-inputs `(("mes" ,mes-boot)
433 ("bash" ,%bootstrap-coreutils&co)
434 ("coreutils" ,%bootstrap-coreutils&co)
435 ("make" ,make-mesboot0)))
437 `(#:implicit-inputs? #f
438 #:guile ,%bootstrap-guile
440 #:tests? #f ; check is naive, also checks non-built PROGRAMS
441 #:strip-binaries? #f ; no strip yet
443 (modify-phases %standard-phases
444 ;; diffutils-2.7 needs more traditional configure
446 (lambda* (#:key outputs #:allow-other-keys)
447 (let ((out (assoc-ref outputs "out"))
448 (bash (assoc-ref %build-inputs "bash")))
449 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
452 (invoke "./configure" (string-append "--prefix=" out)))))
453 (add-before 'configure 'remove-diff3-sdiff
454 (lambda* (#:key outputs #:allow-other-keys)
455 (substitute* "Makefile.in"
456 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
459 (define binutils-mesboot0
462 (name "binutils-mesboot0")
464 (source (bootstrap-origin
467 (uri (string-append "mirror://gnu/binutils/binutils-"
469 (patches (search-patches "binutils-boot-2.20.1a.patch"))
472 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
474 (propagated-inputs '())
475 (native-inputs `(("tcc" ,tcc-boot)
477 ("bash" ,%bootstrap-coreutils&co)
478 ("coreutils" ,%bootstrap-coreutils&co)
479 ("diffutils" ,diffutils-mesboot)
480 ("make" ,make-mesboot0)))
481 (supported-systems '("i686-linux" "x86_64-linux"))
483 `(#:implicit-inputs? #f
484 #:guile ,%bootstrap-guile
485 #:tests? #f ; runtest: command not found
487 #:strip-binaries? #f ; no strip yet
489 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
490 " -D MES_BOOTSTRAP=1"))
491 (bash (assoc-ref %build-inputs "bash")))
492 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
493 ,(string-append "CPPFLAGS=" cppflags)
497 ,(string-append "CC=tcc" cppflags)
501 "--build=i686-unknown-linux-gnu"
502 "--host=i686-unknown-linux-gnu"
503 "--with-sysroot=/"))))))
505 (define gcc-core-mesboot
506 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
507 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
508 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
509 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
510 ;; toolchain triplet "that works".
513 (name "gcc-core-mesboot")
515 (source (bootstrap-origin
518 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
521 (patches (search-patches "gcc-boot-2.95.3.patch"))
524 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
525 (supported-systems '("i686-linux" "x86_64-linux"))
527 (propagated-inputs '())
528 (native-inputs `(("binutils" ,binutils-mesboot0)
531 ("bash" ,%bootstrap-coreutils&co)
532 ("coreutils" ,%bootstrap-coreutils&co)
533 ("diffutils" ,diffutils-mesboot)
534 ("make" ,make-mesboot0)))
537 `(#:implicit-inputs? #f
538 #:guile ,%bootstrap-guile
543 (let ((out (assoc-ref %outputs "out")))
547 "--build=i686-unknown-linux-gnu"
548 "--host=i686-unknown-linux-gnu"
549 ,(string-append "--prefix=" out)))
551 "CC=tcc -static -D __GLIBC_MINOR__=6"
552 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
553 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
556 (string-append "LIBGCC2_INCLUDES=-I "
557 (assoc-ref %build-inputs "tcc")
560 (string-append "BOOT_LDFLAGS="
561 " -B" (assoc-ref %build-inputs "tcc")
563 #:modules ((guix build gnu-build-system)
567 (modify-phases %standard-phases
568 ;; gcc-2.95.3 needs more traditional configure
569 (add-before 'configure 'setenv
570 (lambda* (#:key outputs #:allow-other-keys)
571 (let ((out (assoc-ref outputs "out"))
572 (bash (assoc-ref %build-inputs "bash"))
573 (tcc (assoc-ref %build-inputs "tcc"))
574 (cppflags " -D __GLIBC_MINOR__=6"))
575 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
576 (setenv "CPPFLAGS" cppflags)
577 (setenv "CC" (string-append "tcc" cppflags))
578 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
579 (setenv "CPP" (string-append "tcc -E" cppflags))
580 (with-output-to-file "config.cache"
583 ac_cv_c_float_format='IEEE (little-endian)'
587 (lambda* (#:key configure-flags #:allow-other-keys)
588 (format (current-error-port)
589 "running ./configure ~a\n" (string-join configure-flags))
590 (apply invoke "./configure" configure-flags)))
591 (add-after 'configure 'remove-info
593 ;; no info at this stage
594 (delete-file-recursively "texinfo")
595 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
596 (add-after 'install 'install2
597 (lambda* (#:key outputs #:allow-other-keys)
598 (let* ((tcc (assoc-ref %build-inputs "tcc"))
599 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
600 (out (assoc-ref outputs "out"))
601 (gcc-dir (string-append
602 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
604 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
605 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
606 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
607 (copy-file (string-append tcc "/lib/libtcc1.a")
608 (string-append out "/lib/libtcc1.a"))
609 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
610 (string-append tcc-lib "/libc+gnu.o")
611 (string-append tcc-lib "/libtcc1.o"))
612 (invoke "ar" "r" (string-append out "/lib/libc.a")
613 (string-append tcc-lib "/libc+gnu.o")
614 (string-append tcc-lib "/libtcc1.o"))
615 (invoke "ls" "-ltrF" gcc-dir)
618 (list (search-path-specification
619 (variable "C_INCLUDE_PATH")
622 ;; Needed to get things like GCC's <stddef.h>.
623 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
624 (search-path-specification
625 (variable "LIBRARY_PATH")
626 (files '("lib")))))))
628 (define mesboot-headers
631 (name "mesboot-headers")
632 (supported-systems '("i686-linux" "x86_64-linux"))
634 (propagated-inputs '())
635 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
636 ("headers" ,%bootstrap-linux-libre-headers)))
638 `(#:implicit-inputs? #f
639 #:guile ,%bootstrap-guile
643 (modify-phases %standard-phases
647 (lambda* (#:key outputs #:allow-other-keys)
648 (let* ((out (assoc-ref outputs "out"))
649 (include (string-append out "/include"))
650 (headers (assoc-ref %build-inputs "headers" )))
652 (copy-recursively "include" out)
653 (copy-recursively headers out)
656 (define glibc-mesboot0
657 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
658 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
662 (name "glibc-mesboot0")
664 (source (bootstrap-origin
667 (uri (string-append "mirror://gnu/glibc/glibc-"
670 (patches (search-patches "glibc-boot-2.2.5.patch"))
673 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
674 (supported-systems '("i686-linux" "x86_64-linux"))
676 (propagated-inputs '())
677 (native-inputs `(("binutils" ,binutils-mesboot0)
678 ("gcc" ,gcc-core-mesboot)
680 ("bash" ,%bootstrap-coreutils&co)
681 ("coreutils" ,%bootstrap-coreutils&co)
682 ("diffutils" ,diffutils-mesboot)
683 ("headers" ,mesboot-headers)
684 ("make" ,make-mesboot0)))
687 `(#:implicit-inputs? #f
688 #:guile ,%bootstrap-guile
691 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
692 #:make-flags (list (string-append
694 (assoc-ref %build-inputs "bash")
697 (let ((out (assoc-ref %outputs "out"))
698 (headers (assoc-ref %build-inputs "headers")))
702 "--disable-sanity-checks"
703 "--build=i686-unknown-linux-gnu"
704 "--host=i686-unknown-linux-gnu"
705 (string-append "--with-headers=" headers "/include")
706 "--enable-static-nss"
711 (string-append "--prefix=" out)))
713 (modify-phases %standard-phases
714 (add-before 'configure 'setenv
715 (lambda* (#:key outputs #:allow-other-keys)
716 (let* ((out (assoc-ref outputs "out"))
717 (bash (assoc-ref %build-inputs "bash"))
718 (gcc (assoc-ref %build-inputs "gcc"))
719 (headers (assoc-ref %build-inputs "headers"))
720 (cppflags (string-append
722 " -D MES_BOOTSTRAP=1"
723 " -D BOOTSTRAP_GLIBC=1"))
724 (cflags (string-append " -L " (getcwd))))
725 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
726 (setenv "SHELL" (getenv "CONFIG_SHELL"))
727 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
728 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
730 ;; glibc-2.2.5 needs a more classic invocation of configure
731 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
733 (lambda* (#:key configure-flags #:allow-other-keys)
734 (format (current-error-port)
735 "running ./configure ~a\n" (string-join configure-flags))
736 (apply invoke "./configure" configure-flags))))))))
740 (inherit gcc-core-mesboot)
741 (name "gcc-mesboot0")
742 (native-inputs `(("binutils" ,binutils-mesboot0)
744 ;; Packages are given in an order that's relevant for
745 ;; #include_next purposes.
746 ("libc" ,glibc-mesboot0)
747 ("kernel-headers" ,%bootstrap-linux-libre-headers)
748 ("gcc" ,gcc-core-mesboot)
750 ("bash" ,%bootstrap-coreutils&co)
751 ("coreutils" ,%bootstrap-coreutils&co)
752 ("diffutils" ,diffutils-mesboot)
753 ("make" ,make-mesboot0)))
755 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
757 `(modify-phases ,phases
760 (setenv "CONFIG_SHELL" (which "sh"))
761 (with-output-to-file "config.cache"
764 ac_cv_c_float_format='IEEE (little-endian)'
768 (lambda* (#:key outputs #:allow-other-keys)
769 (let* ((out (assoc-ref outputs "out"))
770 (gcc-dir (string-append
771 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
773 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
774 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
775 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
777 ((#:configure-flags configure-flags)
778 `(let ((out (assoc-ref %outputs "out")))
781 "--build=i686-unknown-linux-gnu"
782 "--host=i686-unknown-linux-gnu"
783 ,(string-append "--prefix=" out))))
784 ((#:make-flags make-flags)
785 `(let ((gcc (assoc-ref %build-inputs "gcc")))
787 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
790 (define binutils-mesboot
792 (inherit binutils-mesboot0)
793 (name "binutils-mesboot")
794 (native-inputs `(("binutils" ,binutils-mesboot0)
795 ("libc" ,glibc-mesboot0)
796 ("gcc" ,gcc-mesboot0)
798 ("bash" ,%bootstrap-coreutils&co)
799 ("coreutils" ,%bootstrap-coreutils&co)
800 ("diffutils" ,diffutils-mesboot)
801 ("kernel-headers" ,%bootstrap-linux-libre-headers)
802 ("make" ,make-mesboot0)))
804 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
805 ((#:configure-flags configure-flags)
806 '(list "--disable-nls"
809 "--build=i686-unknown-linux-gnu"
810 "--host=i686-unknown-linux-gnu"
811 "--with-sysroot=/"))))))
815 (inherit make-mesboot0)
816 (name "make-mesboot")
820 (uri (string-append "mirror://gnu/make/make-"
824 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
825 (native-inputs `(("binutils" ,binutils-mesboot0)
826 ("libc" ,glibc-mesboot0)
827 ("gcc" ,gcc-mesboot0)
828 ("make" ,make-mesboot0)
830 ("bash" ,%bootstrap-coreutils&co)
831 ("coreutils" ,%bootstrap-coreutils&co)
832 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
834 (substitute-keyword-arguments (package-arguments make-mesboot0)
835 ((#:configure-flags configure-flags)
836 `(let ((out (assoc-ref %outputs "out")))
837 `(,(string-append "--prefix=" out))))
839 `(modify-phases ,phases
840 (delete 'configure-fixup)
841 (add-before 'configure 'setenv
843 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
852 (uri (string-append "mirror://gnu/gmp/gmp-" version
855 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
863 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
866 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
875 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
878 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
882 (inherit gcc-mesboot0)
883 (name "gcc-mesboot1")
884 (version (package-version gcc-4.7))
885 (source (bootstrap-origin
886 (origin (inherit (package-source gcc-4.7))
887 (patches (search-patches "gcc-boot-4.7.4.patch")))))
888 (inputs `(("gmp-source" ,(package-source gmp-boot))
889 ("mpfr-source" ,(package-source mpfr-boot))
890 ("mpc-source" ,(package-source mpc-boot))))
891 (native-inputs `(("binutils" ,binutils-mesboot)
893 ("libc" ,glibc-mesboot0)
894 ("kernel-headers" ,%bootstrap-linux-libre-headers)
895 ("gcc" ,gcc-mesboot0)
897 ("bash" ,%bootstrap-coreutils&co)
898 ("coreutils" ,%bootstrap-coreutils&co)
899 ("diffutils" ,diffutils-mesboot)
900 ("make" ,make-mesboot)))
902 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
903 ((#:make-flags make-flags)
904 `(let* ((libc (assoc-ref %build-inputs "libc"))
905 (ldflags (string-append
907 "-Wl,-dynamic-linker "
909 ,(glibc-dynamic-linker "i686-linux"))))
910 (list (string-append "LDFLAGS=" ldflags)
911 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
913 `(modify-phases ,phases
914 ;; c&p from commencement.scm:gcc-boot0
915 (add-after 'unpack 'unpack-gmp&co
916 (lambda* (#:key inputs #:allow-other-keys)
917 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
918 (mpfr (assoc-ref %build-inputs "mpfr-source"))
919 (mpc (assoc-ref %build-inputs "mpc-source")))
921 ;; To reduce the set of pre-built bootstrap inputs, build
922 ;; GMP & co. from GCC.
923 (for-each (lambda (source)
924 (or (invoke "tar" "xvf" source)
925 (error "failed to unpack tarball"
929 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
931 ;; Drop trailing letters, as gmp-6.0.0a unpacks
933 `(symlink ,(string-trim-right
934 (package-full-name lib "-")
936 ,(package-name lib)))
937 (list gmp-boot mpfr-boot mpc-boot))
939 (delete 'remove-info)
942 (setenv "CONFIG_SHELL" (which "sh"))
944 ;; Allow MPFR headers to be found.
945 (setenv "C_INCLUDE_PATH"
946 (string-append (getcwd) "/mpfr/src:"
947 (getenv "C_INCLUDE_PATH")))
949 ;; Set the C++ search path so that C headers can be found as
950 ;; libstdc++ is being compiled.
951 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
954 ((#:configure-flags configure-flags)
955 `(let ((out (assoc-ref %outputs "out"))
956 (glibc (assoc-ref %build-inputs "libc")))
957 (list (string-append "--prefix=" out)
958 "--build=i686-unknown-linux-gnu"
959 "--host=i686-unknown-linux-gnu"
961 (string-append "--with-native-system-header-dir=" glibc "/include")
962 (string-append "--with-build-sysroot=" glibc "/include")
964 "--disable-bootstrap"
965 "--disable-decimal-float"
966 "--disable-libatomic"
967 "--disable-libcilkrts"
970 "--disable-libmudflap"
971 "--disable-libquadmath"
972 "--disable-libsanitizer"
976 "--disable-lto-plugin"
980 "--enable-languages=c,c++"
983 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
985 "--enable-threads=single"
987 ;; No pre-compiled libstdc++ headers, to save space.
988 "--disable-libstdcxx-pch"
991 "--disable-build-with-cxx")))))))
993 (define gcc-mesboot1-wrapper
994 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
995 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
996 ;; --enable-shared will fail.
998 (inherit gcc-mesboot1)
999 (name "gcc-mesboot1-wrapper")
1002 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1003 ("libc" ,glibc-mesboot)
1004 ("gcc" ,gcc-mesboot1)))
1006 `(#:implicit-inputs? #f
1007 #:guile ,%bootstrap-guile
1009 (modify-phases %standard-phases
1014 (lambda* (#:key outputs #:allow-other-keys)
1015 (let* ((out (assoc-ref outputs "out"))
1016 (bash (assoc-ref %build-inputs "bash"))
1017 (libc (assoc-ref %build-inputs "libc"))
1018 (gcc (assoc-ref %build-inputs "gcc"))
1019 (bin (string-append out "/bin")))
1023 (let ((wrapper (string-append bin "/" program)))
1024 (with-output-to-file wrapper
1026 (display (string-append "#! " bash "/bin/bash
1027 exec " gcc "/bin/" program
1028 " -Wl,--dynamic-linker"
1029 ;; also for x86_64-linux, we are still on i686-linux
1030 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1035 (chmod wrapper #o555)))))
1039 "i686-unknown-linux-gnu-gcc"
1040 "i686-unknown-linux-gnu-g++"
1044 (lambda* (#:key outputs #:allow-other-keys)
1045 (let* ((out (assoc-ref outputs "out"))
1046 (bin (string-append out "/bin"))
1047 (program (string-append bin "/gcc")))
1048 (invoke program "--help")))))))))
1050 (define glibc-headers-mesboot
1052 (inherit glibc-mesboot0)
1053 (name "glibc-headers-mesboot")
1055 (source (bootstrap-origin
1058 (uri (string-append "mirror://gnu/glibc/glibc-"
1061 (patches (search-patches "glibc-boot-2.16.0.patch"
1062 "glibc-bootstrap-system-2.16.0.patch"))
1065 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1066 (native-inputs `(("binutils" ,binutils-mesboot)
1067 ("libc" ,glibc-mesboot0)
1068 ("gcc" ,gcc-mesboot1)
1069 ("headers" ,mesboot-headers)
1071 ("bash" ,%bootstrap-coreutils&co)
1072 ("coreutils" ,%bootstrap-coreutils&co)
1073 ("diffutils" ,diffutils-mesboot)
1074 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1075 ("make" ,make-mesboot)))
1078 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1079 ((#:configure-flags configure-flags)
1080 `(let ((out (assoc-ref %outputs "out"))
1081 (headers (assoc-ref %build-inputs "headers")))
1083 (string-append "--prefix=" out)
1084 "--disable-obsolete-rpc"
1085 "--host=i686-unknown-linux-gnu"
1086 (string-append "--with-headers=" headers "/include")
1087 "--enable-static-nss"
1091 "--enable-add-ons=nptl")))
1092 ((#:make-flags make-flags)
1093 `(let ((bash (assoc-ref %build-inputs "bash")))
1094 (list (string-append "SHELL=" bash "/bin/sh")
1095 "install-bootstrap-headers=yes" "install-headers")))
1097 `(modify-phases ,phases
1099 (lambda* (#:key inputs #:allow-other-keys)
1100 (let* ((headers (assoc-ref inputs "headers"))
1101 (libc (assoc-ref inputs "libc"))
1102 (gcc (assoc-ref inputs "gcc"))
1103 (cppflags (string-append
1104 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1105 " -D BOOTSTRAP_GLIBC=1"))
1106 (cflags (string-append " -L " (getcwd)
1107 " -L " libc "/lib")))
1108 (setenv "libc_cv_friendly_stddef" "yes")
1109 (setenv "CONFIG_SHELL" (which "sh"))
1110 (setenv "SHELL" (which "sh"))
1112 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1113 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1115 ;; avoid -fstack-protector
1116 (setenv "libc_cv_ssp" "false")
1117 (substitute* "configure"
1118 (("/bin/pwd") "pwd"))
1121 (lambda* (#:key outputs make-flags #:allow-other-keys)
1122 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1123 (out (assoc-ref outputs "out")))
1124 (apply invoke "make" make-flags)
1125 (copy-recursively kernel-headers out)
1128 (lambda* (#:key configure-flags #:allow-other-keys)
1129 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1132 (apply invoke "../configure" configure-flags)))
1133 (add-after 'configure 'remove-sunrpc
1135 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1136 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1137 (substitute* "sysd-sorted"
1140 ;; 'rpcgen' needs native libc headers to be built.
1141 (substitute* "../Makefile"
1142 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1143 (substitute* "../Makeconfig"
1144 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1145 (substitute* "../elf/Makefile"
1146 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1148 (define glibc-mesboot
1150 (inherit glibc-headers-mesboot)
1151 (name "glibc-mesboot")
1152 (native-inputs `(("binutils" ,binutils-mesboot)
1153 ("libc" ,glibc-mesboot0)
1154 ("headers" ,glibc-headers-mesboot)
1155 ("gcc" ,gcc-mesboot1)
1157 ("bash" ,%bootstrap-coreutils&co)
1158 ("coreutils" ,%bootstrap-coreutils&co)
1159 ("diffutils" ,diffutils-mesboot)
1160 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1161 ("make" ,make-mesboot)))
1164 `(#:validate-runpath? #f ; fails when using --enable-shared
1165 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1166 ((#:make-flags make-flags)
1167 `(let ((bash (assoc-ref %build-inputs "bash")))
1168 (list (string-append "SHELL=" bash "/bin/sh"))))
1170 `(modify-phases ,phases
1172 (lambda* (#:key outputs make-flags #:allow-other-keys)
1173 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1174 (out (assoc-ref outputs "out"))
1175 (install-flags (cons "install" make-flags)))
1176 (apply invoke "make" install-flags)
1177 (copy-recursively kernel-headers out)
1182 (inherit gcc-mesboot1)
1183 (name "gcc-mesboot")
1184 (version (package-version gcc-4.9))
1185 (source (bootstrap-origin (package-source gcc-4.9)))
1186 (native-inputs `(("binutils" ,binutils-mesboot)
1188 ("libc" ,glibc-mesboot)
1189 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1190 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1191 ("gcc" ,gcc-mesboot1)
1193 ("bash" ,%bootstrap-coreutils&co)
1194 ("coreutils" ,%bootstrap-coreutils&co)
1195 ("diffutils" ,diffutils-mesboot)
1196 ("make" ,make-mesboot)))
1198 `(#:validate-runpath? #f
1199 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1200 ((#:configure-flags configure-flags)
1201 `(let ((out (assoc-ref %outputs "out"))
1202 (glibc (assoc-ref %build-inputs "libc")))
1203 (list (string-append "--prefix=" out)
1204 "--build=i686-unknown-linux-gnu"
1205 "--host=i686-unknown-linux-gnu"
1207 "--with-host-libstdcxx=-lsupc++"
1209 (string-append "--with-native-system-header-dir=" glibc "/include")
1210 (string-append "--with-build-sysroot=" glibc "/include")
1212 "--disable-bootstrap"
1213 "--disable-decimal-float"
1214 "--disable-libatomic"
1215 "--disable-libcilkrts"
1218 "--disable-libmudflap"
1219 "--disable-libquadmath"
1220 "--disable-libsanitizer"
1224 "--disable-lto-plugin"
1225 "--disable-multilib"
1228 "--enable-languages=c,c++"
1232 "--enable-threads=single"
1234 ;; No pre-compiled libstdc++ headers, to save space.
1235 "--disable-libstdcxx-pch"
1238 "--disable-build-with-cxx"))))))))
1240 (define gcc-mesboot-wrapper
1241 ;; We need this so gcc-mesboot can be used to create shared binaries that
1242 ;; have the correct interpreter and runpath to libc.
1244 (inherit gcc-mesboot1-wrapper)
1245 (name "gcc-mesboot-wrapper")
1246 (version (package-version gcc-mesboot))
1249 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1250 ("libc" ,glibc-mesboot)
1251 ("gcc" ,gcc-mesboot)))))
1260 (uri (string-append "mirror://gnu/m4/m4-"
1264 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1265 (supported-systems '("i686-linux" "x86_64-linux"))
1266 (native-inputs `(("mes" ,mes-boot)
1270 (modify-phases %standard-phases
1272 (lambda* (#:key outputs #:allow-other-keys)
1273 (let ((out (assoc-ref outputs "out")))
1274 (setenv "CONFIG_SHELL" (string-append
1275 (assoc-ref %build-inputs "bash")
1277 (setenv "CC" "tcc -static")
1278 (setenv "CPP" "tcc -E")
1279 (invoke "./configure" (string-append "--prefix=" out))))))))))
1281 (define (%bootstrap-inputs+toolchain)
1282 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1283 ;; the actual reduced set with bootstrapped toolchain.
1284 (match (%current-system)
1285 ((or "i686-linux" "x86_64-linux")
1286 `(("libc" ,glibc-mesboot)
1287 ("binutils" ,binutils-mesboot)
1288 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1289 ("gcc" ,gcc-mesboot)
1290 ,@(fold alist-delete (%bootstrap-inputs)
1291 '("bootstrap-mescc-tools" "mes"))))
1293 (%bootstrap-inputs))))
1295 (define gnu-make-boot0
1298 (source (bootstrap-origin (package-source gnu-make)))
1301 `(#:guile ,%bootstrap-guile
1302 #:implicit-inputs? #f
1303 #:tests? #f ; cannot run "make check"
1304 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1305 ((#:configure-flags flags ''())
1306 ;; The generated config.status has some problems due to the
1307 ;; bootstrap environment. Disable dependency tracking to work
1309 `(cons "--disable-dependency-tracking" ,flags))
1311 `(modify-phases ,phases
1314 (invoke "./build.sh")))
1316 (lambda* (#:key outputs #:allow-other-keys)
1317 (let* ((out (assoc-ref outputs "out"))
1318 (bin (string-append out "/bin")))
1319 (install-file "make" bin)
1321 (native-inputs '()) ; no need for 'pkg-config'
1322 (inputs (%bootstrap-inputs+toolchain))))
1324 (define diffutils-boot0
1327 (name "diffutils-boot0")
1330 `(("make" ,gnu-make-boot0)
1331 ,@(%bootstrap-inputs+toolchain)))
1333 `(#:tests? #f ; the test suite needs diffutils
1334 #:guile ,%bootstrap-guile
1335 #:implicit-inputs? #f
1336 ,@(package-arguments diffutils)))))
1338 (define findutils-boot0
1341 (name "findutils-boot0")
1342 (source (bootstrap-origin (package-source findutils)))
1344 `(("make" ,gnu-make-boot0)
1345 ("diffutils" ,diffutils-boot0) ; for tests
1346 ,@(%bootstrap-inputs+toolchain)))
1348 `(#:implicit-inputs? #f
1349 #:guile ,%bootstrap-guile
1351 ;; The build system assumes we have done a mistake when time_t is 32-bit
1352 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1353 ,@(if (target-64bit?)
1354 (substitute-keyword-arguments (package-arguments findutils)
1355 ((#:configure-flags flags ''())
1356 `(cons "TIME_T_32_BIT_OK=yes"
1358 (package-arguments findutils))))))
1363 (source (bootstrap-origin (package-source file)))
1366 `(("make" ,gnu-make-boot0)
1367 ,@(%bootstrap-inputs+toolchain)))
1369 `(#:implicit-inputs? #f
1370 #:guile ,%bootstrap-guile
1371 #:strip-binaries? #f
1372 #:validate-runpath? #f))))
1374 (define (%boot0-inputs)
1375 `(("make" ,gnu-make-boot0)
1376 ("diffutils" ,diffutils-boot0)
1377 ("findutils" ,findutils-boot0)
1378 ("file" ,file-boot0)
1379 ,@(%bootstrap-inputs+toolchain)))
1381 (define* (boot-triplet #:optional (system (%current-system)))
1382 ;; Return the triplet used to create the cross toolchain needed in the
1383 ;; first bootstrapping stage.
1384 (nix-system->gnu-triplet system "guix"))
1386 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1387 ;; toolchain actually targets the same OS and arch, but it has the advantage
1388 ;; of being independent of the libc and tools in
1389 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1390 ;; reference to the target libc.
1392 (define binutils-boot0
1395 (source (bootstrap-origin (package-source binutils)))
1396 (name "binutils-cross-boot0")
1398 `(#:guile ,%bootstrap-guile
1399 #:implicit-inputs? #f
1401 #:modules ((guix build gnu-build-system)
1403 (ice-9 ftw)) ; for 'scandir'
1404 #:phases (modify-phases %standard-phases
1405 (add-after 'install 'add-symlinks
1406 (lambda* (#:key outputs #:allow-other-keys)
1407 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1408 ;; triplet prefix, so add symlinks.
1409 (let ((out (assoc-ref outputs "out"))
1410 (triplet-prefix (string-append ,(boot-triplet) "-")))
1411 (define (has-triplet-prefix? name)
1412 (string-prefix? triplet-prefix name))
1413 (define (remove-triplet-prefix name)
1414 (substring name (string-length triplet-prefix)))
1415 (with-directory-excursion (string-append out "/bin")
1416 (for-each (lambda (name)
1417 (symlink name (remove-triplet-prefix name)))
1418 (scandir "." has-triplet-prefix?)))
1421 ,@(substitute-keyword-arguments (package-arguments binutils)
1422 ((#:configure-flags cf)
1423 `(cons ,(string-append "--target=" (boot-triplet))
1425 (inputs (%boot0-inputs))))
1427 (define libstdc++-boot0
1428 ;; GCC's libcc1 is always built as a shared library (the top-level
1429 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1430 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
1431 ;; C++14 features missing in some of our bootstrap compilers.
1432 (let ((lib (make-libstdc++ gcc-4.9)))
1435 (source (bootstrap-origin (package-source lib)))
1436 (name "libstdc++-boot0")
1438 `(#:guile ,%bootstrap-guile
1439 #:implicit-inputs? #f
1441 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1442 #:validate-runpath? #f
1444 ,@(match (%current-system)
1445 ((or "i686-linux" "x86_64-linux")
1446 (substitute-keyword-arguments (package-arguments lib)
1448 `(modify-phases ,phases
1449 (add-after 'unpack 'workaround-wrapper-bug
1450 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1451 ;; fail, which in turn confuses the configure script.
1453 (substitute* "libstdc++-v3/configure"
1454 (("g\\+\\+ -v") "true"))
1456 (_ (package-arguments lib)))))
1457 (inputs (%boot0-inputs))
1458 (native-inputs '()))))
1463 (name "gcc-cross-boot0")
1464 (source (bootstrap-origin (package-source gcc)))
1466 `(#:guile ,%bootstrap-guile
1467 #:implicit-inputs? #f
1468 #:modules ((guix build gnu-build-system)
1473 ,@(substitute-keyword-arguments (package-arguments gcc)
1474 ((#:configure-flags flags)
1475 `(append (list ,(string-append "--target=" (boot-triplet))
1480 ;; Disable features not needed at this stage.
1482 "--enable-languages=c,c++"
1484 ;; libstdc++ cannot be built at this stage
1485 ;; ("Link tests are not allowed after
1486 ;; GCC_NO_EXECUTABLES.").
1487 "--disable-libstdc++-v3"
1490 "--disable-libmudflap"
1491 "--disable-libatomic"
1492 "--disable-libsanitizer"
1496 "--disable-libcilkrts"
1499 "--disable-libquadmath"
1500 "--disable-decimal-float")
1501 (remove (cut string-match
1502 "--(with-system-zlib|enable-languages.*)" <>)
1504 ((#:make-flags flags)
1505 `(let* ((libc (assoc-ref %build-inputs "libc"))
1506 (libc-native (or (assoc-ref %build-inputs "libc-native")
1508 `(,(string-append "LDFLAGS="
1509 "-Wl,-rpath=" libc-native "/lib "
1510 "-Wl,-dynamic-linker "
1511 "-Wl," libc-native ,(glibc-dynamic-linker
1512 (match (%current-system)
1513 ("x86_64-linux" "i686-linux")
1514 (_ (%current-system))))))))
1516 `(modify-phases ,phases
1517 (add-after 'unpack 'unpack-gmp&co
1518 (lambda* (#:key inputs #:allow-other-keys)
1519 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1520 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1521 (mpc (assoc-ref %build-inputs "mpc-source")))
1523 ;; To reduce the set of pre-built bootstrap inputs, build
1524 ;; GMP & co. from GCC.
1525 (for-each (lambda (source)
1526 (invoke "tar" "xvf" source))
1527 (list gmp mpfr mpc))
1529 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1530 ,@(map (lambda (lib)
1531 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1533 `(symlink ,(string-trim-right
1534 (package-full-name lib "-")
1536 ,(package-name lib)))
1537 (list gmp-6.0 mpfr mpc))
1539 ,(match (%current-system)
1540 ((or "i686-linux" "x86_64-linux")
1541 '(add-before 'configure 'fix-libcc1
1542 (lambda* (#:key inputs #:allow-other-keys)
1543 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
1544 ;; to placate the 'validate-runpath' phase.
1545 (substitute* "libcc1/Makefile.in"
1547 (string-append "la_LDFLAGS = -Wl,-rpath="
1548 (assoc-ref inputs "gcc") "/lib")))
1549 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
1550 (substitute* "libcc1/configure"
1551 (("g\\+\\+ -v") "true"))
1553 (_ '(add-before 'configure 'return-true
1555 (add-after 'install 'symlink-libgcc_eh
1556 (lambda* (#:key outputs #:allow-other-keys)
1557 (let ((out (assoc-ref outputs "lib")))
1558 ;; Glibc wants to link against libgcc_eh, so provide
1560 (with-directory-excursion
1561 (string-append out "/lib/gcc/"
1563 "/" ,(package-version gcc))
1564 (symlink "libgcc.a" "libgcc_eh.a"))
1567 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
1568 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
1569 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
1570 ("binutils-cross" ,binutils-boot0)
1572 ;; The libstdc++ that libcc1 links against.
1573 ("libstdc++" ,libstdc++-boot0)
1575 ;; Call it differently so that the builder can check whether
1576 ;; the "libc" input is #f.
1577 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
1578 ,@(alist-delete "libc" (%boot0-inputs))))
1580 ;; No need for the native-inputs to build the documentation at this stage.
1581 (native-inputs `())))
1587 (source (bootstrap-origin (package-source perl)))
1588 (inputs (%boot0-inputs))
1590 `(#:implicit-inputs? #f
1591 #:guile ,%bootstrap-guile
1592 #:validate-runpath? #f
1594 ;; At the very least, this must not depend on GCC & co.
1595 #:disallowed-references ,(list %bootstrap-binutils)
1597 ,@(substitute-keyword-arguments (package-arguments perl)
1599 `(modify-phases ,phases
1600 ;; Pthread support is missing in the bootstrap compiler
1601 ;; (broken spec file), so disable it.
1602 (add-before 'configure 'disable-pthreads
1604 (substitute* "Configure"
1605 (("^libswanted=(.*)pthread" _ before)
1606 (string-append "libswanted=" before)))
1608 ;; Do not configure with '-Dusethreads' since pthread
1609 ;; support is missing.
1610 ((#:configure-flags configure-flags)
1611 `(delete "-Dusethreads" ,configure-flags)))))))
1617 (source (bootstrap-origin (package-source m4)))
1618 (inputs (%boot0-inputs))
1620 `(#:guile ,%bootstrap-guile
1621 #:implicit-inputs? #f
1622 ,@(package-arguments m4)))))
1625 ;; This Bison is needed to build MiG so we need it early in the process.
1626 ;; Recent versions of Linux-Libre headers also depend on this.
1629 (name "bison-boot0")
1630 (propagated-inputs `(("m4" ,m4-boot0)))
1631 (native-inputs `(("perl" ,perl-boot0)))
1632 (inputs (%boot0-inputs)) ;remove Flex...
1634 `(#:tests? #f ;... and thus disable tests
1635 #:implicit-inputs? #f
1636 #:guile ,%bootstrap-guile
1638 ;; Zero timestamps in liby.a; this must be done
1639 ;; explicitly here because the bootstrap Binutils don't
1640 ;; do that (default is "cru".)
1641 #:make-flags `("ARFLAGS=crD"
1642 ,,(match (%current-system)
1643 ;; ranlib: '-D': No such file
1644 ((or "i686-linux" "x86_64-linux")
1647 "RANLIB=ranlib -D"))
1650 ,@(package-arguments bison)))))
1653 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
1656 (native-inputs `(("bison" ,bison-boot0)))
1657 (propagated-inputs `(("m4" ,m4-boot0)))
1658 (inputs (%boot0-inputs))
1660 `(#:implicit-inputs? #f
1661 #:guile ,%bootstrap-guile
1664 (define linux-libre-headers-boot0
1666 "Return Linux-Libre header files for the bootstrap environment."
1667 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
1668 ;; between (gnu packages linux) and this module. Additionally, memoize
1669 ;; the result to play well with further memoization and code that relies
1670 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
1672 (inherit linux-libre-headers)
1674 `(#:guile ,%bootstrap-guile
1675 #:implicit-inputs? #f
1676 ,@(package-arguments linux-libre-headers)))
1678 `(("perl" ,perl-boot0)
1680 ;; Flex and Bison are required since version 4.16.
1681 ("flex" ,flex-boot0)
1682 ("bison" ,bison-boot0)
1683 ,@(%boot0-inputs))))))
1686 (package-with-explicit-inputs %boot0-inputs
1689 (define gnumach-headers-boot0
1690 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
1693 (let* ((mig (package
1694 (inherit (package-with-bootstrap-guile mig))
1695 (native-inputs `(("bison" ,bison-boot0)
1696 ("flex" ,flex-boot0)))
1697 (inputs `(("flex" ,flex-boot0)))
1700 `(,(string-append "LDFLAGS=-Wl,-rpath="
1701 (assoc-ref %build-inputs "flex") "/lib/")))))))
1704 (define hurd-headers-boot0
1705 (let ((hurd-headers (package (inherit hurd-headers)
1706 (native-inputs `(("mig" ,mig-boot0)))
1708 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
1710 (define hurd-minimal-boot0
1711 (let ((hurd-minimal (package (inherit hurd-minimal)
1712 (native-inputs `(("mig" ,mig-boot0)))
1714 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
1716 (define hurd-core-headers-boot0
1718 "Return the Hurd and Mach headers as well as initial Hurd libraries for
1719 the bootstrap environment."
1720 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
1721 (arguments `(#:guile ,%bootstrap-guile
1722 ,@(package-arguments hurd-core-headers)))
1724 `(("gnumach-headers" ,gnumach-headers-boot0)
1725 ("hurd-headers" ,hurd-headers-boot0)
1726 ("hurd-minimal" ,hurd-minimal-boot0)
1727 ,@(%boot0-inputs))))))
1729 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
1731 ("i586-gnu" (hurd-core-headers-boot0))
1732 (_ (linux-libre-headers-boot0))))
1734 (define texinfo-boot0
1735 ;; Texinfo used to build libc's manual.
1736 ;; We build without ncurses because it fails to build at this stage, and
1737 ;; because we don't need the stand-alone Info reader.
1738 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
1742 (inputs `(,@(%boot0-inputs)
1743 ("perl" ,perl-boot0)))
1745 `(#:implicit-inputs? #f
1746 #:guile ,%bootstrap-guile
1748 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
1749 ;; character type in locale" but we don't have a UTF-8 locale at this
1750 ;; stage, so skip them.
1753 (define expat-sans-tests
1756 (inputs (%boot0-inputs))
1758 ;; XXX: Linking 'runtestscpp' fails with things like:
1760 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
1762 ;; Skip tests altogether.
1763 `(#:implicit-inputs? #f
1764 #:guile ,%bootstrap-guile
1766 ,@(substitute-keyword-arguments (package-arguments expat)
1767 ((#:configure-flags flags ''())
1768 ;; Since we're not passing the right -Wl,-rpath flags, build the
1769 ;; static library to avoid RUNPATH validation failure.
1770 `(cons "--disable-shared" ,flags))
1771 ((#:tests? _ #f) #f))))))
1773 (define python-boot0
1775 (inherit python-minimal)
1776 ;; We cannot use Python 3.7 and later here, because they require
1777 ;; pthreads, which is missing on non-x86 platforms at this stage.
1778 ;; Python 3.6 technically supports being built without threading
1779 ;; support, but requires additional patches.
1781 (source (bootstrap-origin
1784 (uri (string-append "https://www.python.org/ftp/python/"
1785 version "/Python-" version ".tar.xz"))
1788 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
1789 (modules '((guix build utils)))
1792 ;; Delete the bundled copy of libexpat.
1793 (delete-file-recursively "Modules/expat")
1794 (substitute* "Modules/Setup.dist"
1795 ;; Link Expat instead of embedding the bundled one.
1796 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
1800 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
1801 (native-inputs '()) ;and pkg-config
1803 `(#:implicit-inputs? #f
1804 #:guile ,%bootstrap-guile
1806 ,@(substitute-keyword-arguments (package-arguments python-minimal)
1807 ;; Disable features that cannot be built at this stage.
1808 ((#:configure-flags _ ''())
1809 `(list "--without-ensurepip"
1810 "--without-threads"))
1811 ;; Clear #:make-flags, such that changes to the regular
1812 ;; Python package won't interfere with this one.
1813 ((#:make-flags _ ''()) ''())
1815 `(modify-phases ,phases
1816 (add-before 'configure 'disable-modules
1818 (substitute* "setup.py"
1819 ;; Disable ctypes, since it requires libffi.
1820 (("extensions\\.append\\(ctypes\\)") "")
1821 ;; Prevent the 'ossaudiodev' extension from being
1822 ;; built, since it requires Linux headers.
1825 (delete 'set-TZDIR)))
1826 ((#:tests? _ #f) #f))))))
1828 (define ld-wrapper-boot0
1830 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
1831 ;; in their RUNPATH, otherwise validate-runpath will fail.
1832 (make-ld-wrapper "ld-wrapper-boot0"
1833 #:target boot-triplet
1834 #:binutils binutils-boot0
1835 #:guile %bootstrap-guile
1836 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
1837 #:guile-for-build %bootstrap-guile)))
1839 (define (%boot1-inputs)
1840 ;; 2nd stage inputs.
1841 `(("gcc" ,gcc-boot0)
1842 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
1843 ("binutils-cross" ,binutils-boot0)
1844 ,@(alist-delete "binutils" (%boot0-inputs))))
1846 (define glibc-final-with-bootstrap-bash
1847 ;; The final libc, "cross-built". If everything went well, the resulting
1848 ;; store path has no dependencies. Actually, the really-final libc is
1849 ;; built just below; the only difference is that this one uses the
1853 (name "glibc-intermediate")
1854 (source (bootstrap-origin (package-source glibc)))
1856 `(#:guile ,%bootstrap-guile
1857 #:implicit-inputs? #f
1859 ,@(substitute-keyword-arguments (package-arguments glibc)
1860 ((#:configure-flags flags)
1861 `(append (list ,(string-append "--host=" (boot-triplet))
1862 ,(string-append "--build="
1863 (nix-system->gnu-triplet)))
1866 `(modify-phases ,phases
1867 (add-before 'configure 'pre-configure
1868 (lambda* (#:key inputs #:allow-other-keys)
1869 ;; Don't clobber CPATH with the bootstrap libc.
1870 (setenv "NATIVE_CPATH" (getenv "CPATH"))
1873 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
1874 ,@(if (hurd-triplet? (%current-system))
1875 `((substitute* "libpthread/Makefile"
1876 (("LDLIBS-pthread.so =.*")
1877 (string-append "LDLIBS-pthread.so = "
1878 (assoc-ref %build-inputs "kernel-headers")
1879 "/lib/libihash.a\n"))))
1882 ;; 'rpcgen' needs native libc headers to be built.
1883 (substitute* "sunrpc/Makefile"
1884 (("sunrpc-CPPFLAGS =.*" all)
1885 (string-append "CPATH = $(NATIVE_CPATH)\n"
1889 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
1891 `(("bison" ,bison-boot0)
1892 ("texinfo" ,texinfo-boot0)
1893 ("perl" ,perl-boot0)
1894 ("python" ,python-boot0)))
1896 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
1897 ;; it in $CPATH, hence the 'pre-configure' phase above.
1900 ;; A native MiG is needed to build Glibc on Hurd.
1901 ,@(if (hurd-triplet? (%current-system))
1902 `(("mig" ,mig-boot0))
1905 ;; A native GCC is needed to build `cross-rpcgen'.
1906 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
1908 ;; Here, we use the bootstrap Bash, which is not satisfactory
1909 ;; because we don't want to depend on bootstrap tools.
1910 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
1912 (define (cross-gcc-wrapper gcc binutils glibc bash)
1913 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
1914 that makes it available under the native tool names."
1915 (package (inherit gcc)
1916 (name (string-append (package-name gcc) "-wrapped"))
1918 (build-system trivial-build-system)
1921 `(#:guile ,%bootstrap-guile
1922 #:modules ((guix build utils))
1924 (use-modules (guix build utils))
1926 (let* ((binutils (assoc-ref %build-inputs "binutils"))
1927 (gcc (assoc-ref %build-inputs "gcc"))
1928 (libc (assoc-ref %build-inputs "libc"))
1929 (bash (assoc-ref %build-inputs "bash"))
1930 (out (assoc-ref %outputs "out"))
1931 (bindir (string-append out "/bin"))
1932 (triplet ,(boot-triplet)))
1933 (define (wrap-program program)
1934 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
1935 ;; needs to be told where to find the crt files and
1936 ;; the dynamic linker.
1937 (call-with-output-file program
1939 (format p "#!~a/bin/bash
1940 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
1944 ,(glibc-dynamic-linker))))
1946 (chmod program #o555))
1949 (with-directory-excursion bindir
1950 (for-each (lambda (tool)
1951 (symlink (string-append binutils "/bin/"
1955 (for-each wrap-program '("gcc" "g++")))
1959 `(("binutils" ,binutils)
1965 (define gcc-boot0-intermediate-wrapped
1967 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
1969 (cross-gcc-wrapper gcc-boot0 binutils-boot0
1970 glibc-final-with-bootstrap-bash
1971 (car (assoc-ref (%boot1-inputs) "bash")))))
1973 (define static-bash-for-glibc
1974 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
1976 (inherit static-bash)
1977 (source (bootstrap-origin (package-source static-bash)))
1978 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
1979 ("libc" ,glibc-final-with-bootstrap-bash)
1980 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
1981 ,@(fold alist-delete (%boot1-inputs)
1984 `(#:implicit-inputs? #f
1985 #:guile ,%bootstrap-guile
1987 ,@(substitute-keyword-arguments (package-arguments static-bash)
1988 ((#:configure-flags flags '())
1989 ;; Add a '-L' flag so that the pseudo-cross-ld of
1990 ;; BINUTILS-BOOT0 can find libc.a.
1992 (list (string-append "LDFLAGS=-static -L"
1993 (assoc-ref %build-inputs
1997 (define gettext-boot0
1998 ;; A minimal gettext used during bootstrap.
2000 (inherit gettext-minimal)
2001 (name "gettext-boot0")
2002 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2003 ;; simplify the dependency chain, we stick to this version here.
2004 (version "0.19.8.1")
2007 (uri (string-append "mirror://gnu/gettext/gettext-"
2011 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2012 (inputs (%boot1-inputs)) ;zero dependencies
2014 `(#:implicit-inputs? #f
2015 #:guile ,%bootstrap-guile
2017 #:phases (modify-phases %standard-phases
2018 ;; Build only the tools.
2019 (add-after 'unpack 'chdir
2021 (chdir "gettext-tools")
2024 ;; Some test programs require pthreads, which we don't have.
2025 (add-before 'configure 'no-test-programs
2027 (substitute* "tests/Makefile.in"
2033 ;; The final glibc, which embeds the statically-linked Bash built above.
2034 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2038 (source (bootstrap-origin (package-source glibc)))
2039 (inputs `(("static-bash" ,static-bash-for-glibc)
2042 (package-inputs glibc-final-with-bootstrap-bash))))
2044 ;; This time we need 'msgfmt' to install all the libc.mo files.
2045 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2046 ("gettext" ,gettext-boot0)))
2049 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2051 ;; The final libc only refers to itself, but the 'debug' output contains
2052 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2053 ;; if 'allowed-references' were per-output.
2055 `(#:allowed-references
2056 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2057 static-bash-for-glibc
2058 (package-outputs glibc-final-with-bootstrap-bash))
2060 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2062 (define gcc-boot0-wrapped
2064 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2066 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2067 (car (assoc-ref (%boot1-inputs) "bash")))))
2069 (define (%boot2-inputs)
2070 ;; 3rd stage inputs.
2071 `(("libc" ,glibc-final)
2072 ("libc:static" ,glibc-final "static")
2073 ("gcc" ,(gcc-boot0-wrapped))
2074 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2076 (define binutils-final
2079 (source (bootstrap-origin (package-source binutils)))
2081 `(#:guile ,%bootstrap-guile
2082 #:implicit-inputs? #f
2083 #:allowed-references ("out" ,glibc-final)
2084 ,@(package-arguments binutils)))
2085 (inputs (%boot2-inputs))))
2088 ;; Intermediate libstdc++ that will allow us to build the final GCC
2089 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2090 (let ((lib (make-libstdc++ gcc)))
2093 (source (bootstrap-origin (package-source lib)))
2095 `(#:guile ,%bootstrap-guile
2096 #:implicit-inputs? #f
2097 #:allowed-references ("out")
2099 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2100 #:validate-runpath? #f
2102 ;; All of the package arguments from 'make-libstdc++
2103 ;; except for the configure-flags.
2104 ,@(package-arguments lib)
2105 #:configure-flags `("--disable-shared"
2106 "--disable-libstdcxx-dual-abi"
2107 "--disable-libstdcxx-threads"
2108 "--disable-libstdcxx-pch"
2109 ,(string-append "--with-gxx-include-dir="
2110 (assoc-ref %outputs "out")
2113 (inputs (%boot2-inputs))
2114 (synopsis "GNU C++ standard library (intermediate)"))))
2117 ;; Zlib used by GCC-FINAL.
2121 `(#:guile ,%bootstrap-guile
2122 #:implicit-inputs? #f
2123 #:allowed-references ("out" ,glibc-final)
2124 ,@(package-arguments zlib)))
2125 (inputs (%boot2-inputs))))
2127 (define ld-wrapper-boot3
2129 ;; A linker wrapper that uses the bootstrap Guile.
2130 (make-ld-wrapper "ld-wrapper-boot3"
2131 #:binutils binutils-final
2132 #:guile %bootstrap-guile
2133 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2134 #:guile-for-build %bootstrap-guile)))
2138 (package (inherit gcc-boot0)
2141 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2142 ;; "debug" output contains disallowed references, notably
2143 ;; linux-libre-headers. Disable the debugging output to work around that.
2144 (outputs (delete "debug" (package-outputs gcc-boot0)))
2147 `(#:guile ,%bootstrap-guile
2148 #:implicit-inputs? #f
2150 #:allowed-references ("out" "lib" ,zlib-final
2151 ,glibc-final ,static-bash-for-glibc)
2153 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2154 ;; reason, but it is not in their RUNPATH. This is a false
2155 ;; positive, so turn it off.
2156 #:validate-runpath? #f
2158 ,@(substitute-keyword-arguments (package-arguments gcc)
2159 ((#:make-flags flags)
2160 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2161 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2163 (if (string-prefix? "LDFLAGS=" flag)
2164 (string-append flag " -L"
2165 (assoc-ref %build-inputs "libstdc++")
2166 "/lib -L" zlib "/lib -Wl,-rpath="
2170 ;; Build again GMP & co. within GCC's build process, because it's hard
2171 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2172 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2174 `(modify-phases ,phases
2175 (add-after 'unpack 'unpack-gmp&co
2176 (lambda* (#:key inputs #:allow-other-keys)
2177 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2178 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2179 (mpc (assoc-ref %build-inputs "mpc-source")))
2181 ;; To reduce the set of pre-built bootstrap inputs, build
2182 ;; GMP & co. from GCC.
2183 (for-each (lambda (source)
2184 (invoke "tar" "xvf" source))
2185 (list gmp mpfr mpc))
2187 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2188 ,@(map (lambda (lib)
2189 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2191 `(symlink ,(string-trim-right
2192 (package-full-name lib "-")
2194 ,(package-name lib)))
2195 (list gmp-6.0 mpfr mpc))
2197 (add-before 'configure 'treat-glibc-as-system-header
2198 (lambda* (#:key inputs #:allow-other-keys)
2199 (let ((libc (assoc-ref inputs "libc")))
2200 ;; Make sure Glibc is treated as a "system header" so
2201 ;; #include_next does the right thing.
2202 (for-each (lambda (var)
2203 (setenv var (string-append libc "/include")))
2204 '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
2207 ;; This time we want Texinfo, so we get the manual. Add
2208 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2209 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2211 (native-inputs `(("texinfo" ,texinfo-boot0)
2212 ("perl" ,perl-boot0) ;for manpages
2213 ("static-bash" ,static-bash-for-glibc)
2214 ,@(package-native-inputs gcc-boot0)))
2216 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2217 ("mpfr-source" ,(package-source mpfr))
2218 ("mpc-source" ,(package-source mpc))
2219 ("ld-wrapper" ,(ld-wrapper-boot3))
2220 ("binutils" ,binutils-final)
2221 ("libstdc++" ,libstdc++)
2222 ("zlib" ,zlib-final)
2223 ,@(%boot2-inputs)))))
2225 (define (%boot3-inputs)
2226 ;; 4th stage inputs.
2227 `(("gcc" ,gcc-final)
2228 ("ld-wrapper" ,(ld-wrapper-boot3))
2229 ,@(alist-delete "gcc" (%boot2-inputs))))
2232 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2233 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2234 ;; on Readline and ncurses.
2235 (let ((bash (static-libgcc-package bash-minimal)))
2238 (source (bootstrap-origin (package-source bash)))
2239 (inputs (%boot3-inputs))
2241 `(#:implicit-inputs? #f
2242 #:guile ,%bootstrap-guile
2244 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2246 ,@(package-arguments bash))))))
2248 (define (%boot4-inputs)
2249 ;; Now use the final Bash.
2250 `(("bash" ,bash-final)
2251 ,@(alist-delete "bash" (%boot3-inputs))))
2254 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2256 (define-public guile-final
2257 ;; This package must be public because other modules refer to it. However,
2258 ;; mark it as hidden so that 'fold-packages' ignores it.
2259 (with-boot4 (hidden-package
2260 (package-with-bootstrap-guile guile-2.2/fixed))))
2262 (define glibc-utf8-locales-final
2263 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2264 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2265 ;; with the full range of Unicode codepoints (remember
2266 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2269 (inherit glibc-utf8-locales)
2271 `(("glibc" ,glibc-final)
2272 ("gzip" ,(with-boot4 gzip))))))
2274 (define-public ld-wrapper
2275 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2276 (make-ld-wrapper "ld-wrapper"
2277 #:binutils binutils-final
2281 (define (%boot5-inputs)
2282 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2283 ;; with an older libc, which cannot load the new locale format. See
2284 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2285 `(("locales" ,glibc-utf8-locales-final)
2289 (package-with-explicit-inputs %boot5-inputs))
2291 (define gnu-make-final
2292 ;; The final GNU Make, which uses the final Guile.
2293 (let ((pkg-config (package
2294 (inherit %pkg-config) ;the native pkg-config
2295 (inputs `(("guile" ,guile-final)
2298 `(#:implicit-inputs? #f
2299 ,@(package-arguments pkg-config))))))
2301 (inherit (package-with-bootstrap-guile gnu-make))
2302 (inputs `(("guile" ,guile-final)
2304 (native-inputs `(("pkg-config" ,pkg-config)))
2306 `(#:implicit-inputs? #f
2307 ,@(package-arguments gnu-make))))))
2310 (define coreutils-final
2311 ;; The final Coreutils. Treat them specially because some packages, such as
2312 ;; Findutils, keep a reference to the Coreutils they were built with.
2313 (with-boot5 (package-with-bootstrap-guile coreutils)
2314 ;; Use the final Guile, linked against the
2315 ;; final libc with working iconv, so that
2316 ;; 'substitute*' works well when touching
2317 ;; test files in Gettext.
2321 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2322 ;; built before gzip.
2323 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2324 (package/inherit grep
2325 (inputs (alist-delete "pcre" (package-inputs grep)))
2326 (native-inputs `(("perl" ,perl-boot0))))))
2328 (define (%boot6-inputs)
2329 ;; Now use the final Coreutils.
2330 `(("coreutils" ,coreutils-final)
2331 ("grep" ,grep-final)
2335 (package-with-explicit-inputs %boot6-inputs))
2339 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2340 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2342 (define-public %final-inputs
2343 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2344 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2345 ;; used for origins that have patches, thereby avoiding circular
2347 (let ((finalize (compose with-boot6
2348 package-with-bootstrap-guile)))
2349 `(,@(map (match-lambda
2351 (list name (finalize package))))
2357 ("diffutils" ,diffutils)
2359 ("findutils" ,findutils)
2362 ("grep" ,grep-final)
2363 ("coreutils" ,coreutils-final)
2364 ("make" ,gnu-make-final)
2365 ("bash" ,bash-final)
2366 ("ld-wrapper" ,ld-wrapper)
2367 ("binutils" ,binutils-final)
2369 ("libc" ,glibc-final)
2370 ("libc:static" ,glibc-final "static")
2371 ("locales" ,glibc-utf8-locales-final))))
2373 (define-public canonical-package
2374 (let ((name->package (fold (lambda (input result)
2376 ((_ package . outputs)
2377 (vhash-cons (package-full-name package)
2380 `(("guile" ,guile-final)
2383 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2384 the implicit inputs of 'gnu-build-system', return that one, otherwise return
2387 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
2388 COREUTILS-FINAL vs. COREUTILS, etc."
2389 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2390 ;; libunistring, GMP, etc.
2391 (match (vhash-assoc (package-full-name package) name->package)
2393 ;; In general we want CANON, except if we're cross-compiling: CANON
2394 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2395 ;; process, with dependencies on things that cannot be
2397 (if (%current-target-system)
2407 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2408 ;; instantiated like this:
2410 ;; (define-public gcc-glibc-2.27-toolchain
2411 ;; (make-gcc-toolchain gcc glibc-2.27))
2413 (define* (make-gcc-toolchain gcc
2416 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2417 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2418 (libc (if libc libc glibc-final)))
2420 (name (string-append (package-name gcc) "-toolchain"))
2421 (version (package-version gcc))
2423 (build-system trivial-build-system)
2425 '(#:modules ((guix build union))
2427 (use-modules (ice-9 match)
2431 (let ((out (assoc-ref %outputs "out")))
2433 (match %build-inputs
2434 (((names . directories) ...)
2435 (union-build out directories)))
2437 (union-build (assoc-ref %outputs "debug")
2438 (list (assoc-ref %build-inputs
2440 (union-build (assoc-ref %outputs "static")
2441 (list (assoc-ref %build-inputs
2445 (native-search-paths (package-native-search-paths gcc))
2446 (search-paths (package-search-paths gcc))
2448 (license (package-license gcc))
2449 (synopsis "Complete GCC tool chain for C/C++ development")
2451 "This package provides a complete GCC tool chain for C/C++ development to
2452 be installed in user profiles. This includes GCC, as well as libc (headers and
2453 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
2454 (home-page "https://gcc.gnu.org/")
2455 (outputs '("out" "debug" "static"))
2457 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2458 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2459 ;; before Binutils' ld in the user's profile.
2460 (inputs `(("gcc" ,gcc)
2461 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2462 ("binutils" ,binutils-final)
2464 ("libc-debug" ,libc "debug")
2465 ("libc-static" ,libc "static"))))))
2467 (define-public gcc-toolchain
2468 (make-gcc-toolchain gcc-final))
2470 (define-public gcc-toolchain-4.8
2471 (make-gcc-toolchain gcc-4.8))
2473 (define-public gcc-toolchain-4.9
2474 (make-gcc-toolchain gcc-4.9))
2476 (define-public gcc-toolchain-5
2477 (make-gcc-toolchain gcc-5))
2479 (define-public gcc-toolchain-6
2480 (make-gcc-toolchain gcc-6))
2482 (define-public gcc-toolchain-7
2485 (define-public gcc-toolchain-8
2486 (make-gcc-toolchain gcc-8))
2488 (define-public gcc-toolchain-9
2489 (make-gcc-toolchain gcc-9))
2491 ;; Provide the Fortran toolchain package only for the version of gfortran that
2492 ;; is used by Guix internally to build Fortran libraries, because combining
2493 ;; code compiled with different versions can cause problems.
2495 (define-public gfortran-toolchain
2496 (package (inherit (make-gcc-toolchain gfortran))
2497 (synopsis "Complete GCC tool chain for Fortran development")
2498 (description "This package provides a complete GCC tool chain for
2499 Fortran development to be installed in user profiles. This includes
2500 gfortran, as well as libc (headers and binaries, plus debugging symbols
2501 in the @code{debug} output), and binutils.")))
2504 ;;; commencement.scm ends here