1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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 ((guix licenses)
28 #:select (gpl3+ lgpl2.0+ public-domain))
29 #:use-module (gnu packages)
30 #:use-module (gnu packages bootstrap)
31 #:use-module (gnu packages base)
32 #:use-module (gnu packages bash)
33 #:use-module (gnu packages c)
34 #:use-module (gnu packages gcc)
35 #:use-module (gnu packages m4)
36 #:use-module (gnu packages file)
37 #:use-module (gnu packages gawk)
38 #:use-module (gnu packages bison)
39 #:use-module (gnu packages flex)
40 #:use-module (gnu packages guile)
41 #:use-module (gnu packages gettext)
42 #:use-module (gnu packages multiprecision)
43 #:use-module (gnu packages compression)
44 #:use-module (gnu packages mes)
45 #:use-module (gnu packages perl)
46 #:use-module (gnu packages python)
47 #:use-module (gnu packages linux)
48 #:use-module (gnu packages hurd)
49 #:use-module (gnu packages texinfo)
50 #:use-module (gnu packages pkg-config)
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 trivial)
56 #:use-module (guix memoization)
57 #:use-module (guix utils)
58 #:use-module (srfi srfi-1)
59 #:use-module (srfi srfi-26)
60 #:use-module (ice-9 vlist)
61 #:use-module (ice-9 match)
62 #:use-module (ice-9 regex)
63 #:export (make-gcc-toolchain))
67 ;;; This is the commencement, this is where things start. Before the
68 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
69 ;;; with the initial binaries. This module uses those bootstrap binaries to
70 ;;; actually build up the whole tool chain that make up the implicit inputs of
71 ;;; 'gnu-build-system'.
73 ;;; To avoid circular dependencies, this module should not be imported
74 ;;; directly from anywhere.
76 ;;; Below, we frequently use "inherit" to create modified packages. The
77 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
78 ;;; not want these commencement packages to inherit grafts. By definition,
79 ;;; these packages are not depended on at run time by any of the packages we
80 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
81 ;;; grafts would often lead to extra overhead for users who would end up
82 ;;; downloading those "-boot0" packages just to build package replacements
83 ;;; that are in fact not going to be used.
94 (uri (string-append "mirror://gnu/mes/"
95 "mes-" version ".tar.gz"))
98 "15h4yhaywdc0djpjlin2jz1kzahpqxfki0r0aav1qm9nxxmnp1l0"))))
100 (propagated-inputs '())
102 `(("mescc-tools" ,%bootstrap-mescc-tools)
103 ("nyacc-source" ,(bootstrap-origin
104 (package-source nyacc-0.86)))
106 ("coreutils" , %bootstrap-coreutils&co)
107 ("bootstrap-mes" ,%bootstrap-mes)))
109 `(#:implicit-inputs? #f
110 #:guile ,%bootstrap-guile
111 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
113 (modify-phases %standard-phases
114 (add-after 'unpack 'unpack-seeds
116 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source"))
117 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
118 (with-directory-excursion ".."
119 (mkdir-p "nyacc-source")
120 (invoke "tar" "--strip=1" "-C" "nyacc-source" "-xvf" nyacc-source)
121 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
124 (lambda* (#:key outputs #:allow-other-keys)
125 (let ((out (assoc-ref %outputs "out")))
126 (setenv "GUILE" "mes")
127 (setenv "GUILE_EFFECTIVE_VERSION" "2.2")
128 (setenv "GUILE_LOAD_PATH" "nyacc")
129 (symlink (string-append "../nyacc-source/module") "nyacc")
130 (invoke "bash" "configure.sh"
131 (string-append "--prefix=" out)))))
134 (let ((mes (assoc-ref %build-inputs "bootstrap-mes")))
135 (setenv "MES_PREFIX" (string-append mes "/share/mes"))
136 (setenv "MES_ARENA" "100000000")
137 (setenv "MES_MAX_ARENA" "100000000")
138 (setenv "MES_STACK" "10000000")
139 (invoke "sh" "bootstrap.sh"))))
142 (setenv "DIFF" "sh scripts/diff.scm")
144 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/t")
145 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/63-struct-cell")
146 (invoke "sh" "check.sh")))
149 (invoke "sh" "install.sh"))))))
151 ;; Use the language-specific variables rather than 'CPATH' because they
152 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
153 ;; The intent is to allow headers that are in the search path to be
154 ;; treated as "system headers" (headers exempt from warnings) just like
155 ;; the typical /usr/include headers on an FHS system.
156 (list (search-path-specification
157 (variable "C_INCLUDE_PATH")
158 (files '("share/mes/include")))
159 (search-path-specification
160 (variable "LIBRARY_PATH")
161 (files '("share/mes/lib")))))))
164 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
165 ;; patches. In a very early and rough form they were presented to the
166 ;; TinyCC developers, who at the time showed no interest in supporting the
167 ;; bootstrappable effort; we will try again later. These patches have been
168 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
169 ;; mature, this package should use the 0.9.27 sources (or later).
170 (let ((version "0.9.26")
172 (commit "c004e9a34fb026bb44d211ab98bb768e79900eef"))
176 (version (string-append version "-" revision "." (string-take commit 7)))
179 (uri (list (string-append "mirror://gnu/guix/mirror"
180 "/tinycc-" commit ".tar.gz")
181 (string-append "https://gitlab.com/janneke/tinycc"
183 "/tinycc-" commit ".tar.gz")))
186 "1hmzn1pq0x22ppd80hyrn5qzqq94mxd0ychzj6vrr2vnj2frjv5b"))))
187 (build-system gnu-build-system)
188 (supported-systems '("i686-linux" "x86_64-linux"))
190 (propagated-inputs '())
193 ("mescc-tools" ,%bootstrap-mescc-tools)
194 ("nyacc-source" ,(bootstrap-origin
195 (package-source nyacc-0.86)))
197 ("coreutils" , %bootstrap-coreutils&co)
198 ("bootstrap-mes" ,%bootstrap-mes)))
200 `(#:implicit-inputs? #f
201 #:guile ,%bootstrap-guile
202 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
204 (modify-phases %standard-phases
205 (add-after 'unpack 'unpack-seeds
206 (lambda* (#:key outputs #:allow-other-keys)
207 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
208 (nyacc-source (assoc-ref %build-inputs "nyacc-source"))
209 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
210 (setenv "PATH" (string-append
212 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
213 (with-directory-excursion ".."
214 (mkdir-p "nyacc-source")
215 (invoke "tar" "--strip=1" "-C" "nyacc-source"
217 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
220 (lambda* (#:key outputs #:allow-other-keys)
221 (let* ((out (assoc-ref %outputs "out"))
222 (dir (with-directory-excursion ".." (getcwd)))
223 (coreutils (assoc-ref %build-inputs "coreutils"))
224 (mes (assoc-ref %build-inputs "mes"))
225 (mescc-tools (assoc-ref %build-inputs "mescc-tools"))
226 (libc (assoc-ref %build-inputs "libc"))
227 (interpreter (if libc
228 ;; also for x86_64-linux, we are still on i686-linux
229 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
230 (string-append mes "/lib/mes-loader"))))
231 (setenv "PATH" (string-append
234 ":" mescc-tools "/bin"))
235 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
237 (setenv "PREFIX" out)
238 (symlink (string-append mes "/share/mes") "mes")
239 (symlink (string-append "../nyacc-source/module") "nyacc")
240 (setenv "MES_PREFIX" "mes")
241 (setenv "MES_ARENA" "100000000")
242 (setenv "MES_MAX_ARENA" "100000000")
243 (setenv "MES_STACK" "10000000")
245 (setenv "GUILE_LOAD_PATH" "nyacc")
246 (invoke "sh" "configure"
248 (string-append "--elfinterp=" interpreter)
253 (substitute* "bootstrap.sh"
255 (invoke "sh" "bootstrap.sh")))
258 (setenv "DIFF" "diff.scm")
259 (setenv "OBJDUMP" "true")
261 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
262 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
263 (setenv "TCC" "./tcc")
264 (invoke "sh" "check.sh")))
267 (invoke "sh" "install.sh"))))))
269 ;; Use the language-specific variables rather than 'CPATH' because they
270 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
271 ;; The intent is to allow headers that are in the search path to be
272 ;; treated as "system headers" (headers exempt from warnings) just like
273 ;; the typical /usr/include headers on an FHS system.
274 (list (search-path-specification
275 (variable "C_INCLUDE_PATH")
276 (files '("include")))
277 (search-path-specification
278 (variable "LIBRARY_PATH")
279 (files '("lib"))))))))
286 (source (bootstrap-origin
288 (inherit (package-source tcc))
289 (patches (search-patches "tcc-boot-0.9.27.patch")))))
290 (build-system gnu-build-system)
292 (propagated-inputs '())
297 ("coreutils" , %bootstrap-coreutils&co)))
299 `(#:implicit-inputs? #f
300 #:guile ,%bootstrap-guile
302 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
303 ;; with MesCC/M1/hex2-built binaries.
307 (modify-phases %standard-phases
309 (lambda* (#:key outputs #:allow-other-keys)
310 (let* ((out (assoc-ref %outputs "out"))
311 (coreutils (assoc-ref %build-inputs "coreutils"))
312 (mes (assoc-ref %build-inputs "mes"))
313 (tcc (assoc-ref %build-inputs "tcc"))
314 (libc (assoc-ref %build-inputs "libc"))
315 (interpreter (if libc
316 ;; also for x86_64-linux, we are still on i686-linux
317 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
318 (string-append mes "/lib/mes-loader"))))
320 (setenv "PATH" (string-append
323 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
324 (invoke "sh" "configure"
325 (string-append "--cc=tcc")
326 (string-append "--cpu=i386")
327 (string-append "--prefix=" out)
328 (string-append "--elfinterp=" interpreter)
329 (string-append "--crtprefix=" tcc "/lib")
330 (string-append "--sysincludepaths=" tcc "/include")
331 (string-append "--libpaths=" tcc "/lib")))))
333 (lambda* (#:key outputs #:allow-other-keys)
334 (let* ((out (assoc-ref %outputs "out"))
335 (mes (assoc-ref %build-inputs "mes"))
336 (tcc (assoc-ref %build-inputs "tcc"))
337 (libc (assoc-ref %build-inputs "libc"))
338 (interpreter (if libc
339 ;; also for x86_64-linux, we are still on i686-linux
340 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
341 (string-append mes "/lib/mes-loader"))))
346 "-D" "TCC_TARGET_I386=1"
347 "-D" "CONFIG_TCC_STATIC=1"
348 "-D" "CONFIG_USE_LIBGCC=1"
349 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
350 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
351 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
353 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
354 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
355 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
356 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
361 ;; FIXME: add sensible check target (without depending on make)
363 (= 1 (status:exit-val (system* "./tcc" "--help")))))
365 (lambda* (#:key outputs #:allow-other-keys)
366 (let ((out (assoc-ref %outputs "out"))
367 (tcc (assoc-ref %build-inputs "tcc")))
368 (mkdir-p (string-append out "/bin"))
369 (copy-file "tcc" (string-append out "/bin/tcc"))
370 (mkdir-p (string-append out "/lib/tcc"))
371 (copy-recursively (string-append tcc "/include")
372 (string-append out "/include"))
373 (copy-recursively (string-append tcc "/lib")
374 (string-append out "/lib"))
375 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
376 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
377 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
378 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
379 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
382 (define make-mesboot0
385 (name "make-mesboot0")
389 (uri (string-append "mirror://gnu/make/make-"
393 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
394 (supported-systems '("i686-linux" "x86_64-linux"))
396 (propagated-inputs '())
397 (native-inputs `(("tcc" ,tcc-boot)
399 ("bash" ,%bootstrap-coreutils&co)
400 ("coreutils" ,%bootstrap-coreutils&co)))
402 `(#:implicit-inputs? #f
403 #:tests? #f ; check depends on perl
404 #:guile ,%bootstrap-guile
405 #:configure-flags `("CC=tcc -DO_RDONLY=0"
409 (modify-phases %standard-phases
410 (add-after 'configure 'configure-fixup
412 (substitute* "build.sh"
413 (("^REMOTE=.*") "REMOTE=stub\n")
414 (("^extras=.*") "extras=getloadavg.c\n"))
415 (substitute* "make.h"
416 (("^extern long int lseek.*" all) (string-append "// " all)))
418 (delete 'patch-generated-file-shebangs) ; no perl
421 (invoke "sh" "./build.sh")))
423 (lambda* (#:key outputs #:allow-other-keys)
424 (let* ((out (assoc-ref outputs "out"))
425 (bin (string-append out "/bin")))
426 (install-file "make" bin)
429 (define diffutils-mesboot
432 (name "diffutils-mesboot")
436 (uri (string-append "mirror://gnu/diffutils/diffutils-"
440 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
441 (supported-systems '("i686-linux" "x86_64-linux"))
443 (propagated-inputs '())
444 (native-inputs `(("mes" ,mes-boot)
447 ("bash" ,%bootstrap-coreutils&co)
448 ("coreutils" ,%bootstrap-coreutils&co)
449 ("make" ,make-mesboot0)))
451 `(#:implicit-inputs? #f
452 #:guile ,%bootstrap-guile
454 #:tests? #f ; check is naive, also checks non-built PROGRAMS
455 #:strip-binaries? #f ; no strip yet
457 (modify-phases %standard-phases
458 ;; diffutils-2.7 needs more traditional configure
460 (lambda* (#:key outputs #:allow-other-keys)
461 (let ((out (assoc-ref outputs "out"))
462 (bash (assoc-ref %build-inputs "bash")))
463 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
466 (invoke "./configure" (string-append "--prefix=" out)))))
467 (add-before 'configure 'remove-diff3-sdiff
468 (lambda* (#:key outputs #:allow-other-keys)
469 (substitute* "Makefile.in"
470 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
473 (define binutils-mesboot0
476 (name "binutils-mesboot0")
478 (source (bootstrap-origin
481 (uri (string-append "mirror://gnu/binutils/binutils-"
483 (patches (search-patches "binutils-boot-2.20.1a.patch"))
486 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
488 (propagated-inputs '())
489 (native-inputs `(("tcc" ,tcc-boot)
491 ("bash" ,%bootstrap-coreutils&co)
492 ("coreutils" ,%bootstrap-coreutils&co)
493 ("diffutils" ,diffutils-mesboot)
494 ("make" ,make-mesboot0)))
495 (supported-systems '("i686-linux" "x86_64-linux"))
497 `(#:implicit-inputs? #f
498 #:guile ,%bootstrap-guile
499 #:tests? #f ; runtest: command not found
501 #:strip-binaries? #f ; no strip yet
503 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
504 " -D MES_BOOTSTRAP=1"))
505 (bash (assoc-ref %build-inputs "bash")))
506 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
507 ,(string-append "CPPFLAGS=" cppflags)
511 ,(string-append "CC=tcc" cppflags)
515 "--build=i686-unknown-linux-gnu"
516 "--host=i686-unknown-linux-gnu"
517 "--with-sysroot=/"))))))
519 (define gcc-core-mesboot
520 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
521 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
522 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
523 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
524 ;; toolchain triplet "that works".
527 (name "gcc-core-mesboot")
529 (source (bootstrap-origin
532 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
535 (patches (search-patches "gcc-boot-2.95.3.patch"))
538 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
539 (supported-systems '("i686-linux" "x86_64-linux"))
541 (propagated-inputs '())
542 (native-inputs `(("binutils" ,binutils-mesboot0)
545 ("bash" ,%bootstrap-coreutils&co)
546 ("coreutils" ,%bootstrap-coreutils&co)
547 ("diffutils" ,diffutils-mesboot)
548 ("make" ,make-mesboot0)))
551 `(#:implicit-inputs? #f
552 #:guile ,%bootstrap-guile
557 (let ((out (assoc-ref %outputs "out")))
561 "--build=i686-unknown-linux-gnu"
562 "--host=i686-unknown-linux-gnu"
563 ,(string-append "--prefix=" out)))
565 "CC=tcc -static -D __GLIBC_MINOR__=6"
566 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
567 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
570 (string-append "LIBGCC2_INCLUDES=-I "
571 (assoc-ref %build-inputs "tcc")
574 (string-append "BOOT_LDFLAGS="
575 " -B" (assoc-ref %build-inputs "tcc")
577 #:modules ((guix build gnu-build-system)
581 (modify-phases %standard-phases
582 ;; gcc-2.95.3 needs more traditional configure
583 (add-before 'configure 'setenv
584 (lambda* (#:key outputs #:allow-other-keys)
585 (let ((out (assoc-ref outputs "out"))
586 (bash (assoc-ref %build-inputs "bash"))
587 (tcc (assoc-ref %build-inputs "tcc"))
588 (cppflags " -D __GLIBC_MINOR__=6"))
589 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
590 (setenv "CPPFLAGS" cppflags)
591 (setenv "CC" (string-append "tcc" cppflags))
592 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
593 (setenv "CPP" (string-append "tcc -E" cppflags))
594 (with-output-to-file "config.cache"
597 ac_cv_c_float_format='IEEE (little-endian)'
601 (lambda* (#:key configure-flags #:allow-other-keys)
602 (format (current-error-port)
603 "running ./configure ~a\n" (string-join configure-flags))
604 (apply invoke "./configure" configure-flags)))
605 (add-after 'configure 'remove-info
607 ;; no info at this stage
608 (delete-file-recursively "texinfo")
609 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
610 (add-after 'install 'install2
611 (lambda* (#:key outputs #:allow-other-keys)
612 (let* ((tcc (assoc-ref %build-inputs "tcc"))
613 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
614 (out (assoc-ref outputs "out"))
615 (gcc-dir (string-append
616 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
618 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
619 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
620 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
621 (copy-file (string-append tcc "/lib/libtcc1.a")
622 (string-append out "/lib/libtcc1.a"))
623 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
624 (string-append tcc-lib "/libc+gnu.o")
625 (string-append tcc-lib "/libtcc1.o"))
626 (invoke "ar" "r" (string-append out "/lib/libc.a")
627 (string-append tcc-lib "/libc+gnu.o")
628 (string-append tcc-lib "/libtcc1.o"))
629 (invoke "ls" "-ltrF" gcc-dir)
630 (copy-recursively (string-append tcc "/include")
631 (string-append out "/include"))
634 ;; Use the language-specific variables rather than 'CPATH' because they
635 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
636 ;; The intent is to allow headers that are in the search path to be
637 ;; treated as "system headers" (headers exempt from warnings) just like
638 ;; the typical /usr/include headers on an FHS system.
639 (list (search-path-specification
640 (variable "C_INCLUDE_PATH")
641 (files '("include" "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
642 (search-path-specification
643 (variable "LIBRARY_PATH")
644 (files '("lib")))))))
646 (define mesboot-headers
649 (name "mesboot-headers")
650 (supported-systems '("i686-linux" "x86_64-linux"))
652 (propagated-inputs '())
653 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
654 ("headers" ,%bootstrap-linux-libre-headers)))
656 `(#:implicit-inputs? #f
657 #:guile ,%bootstrap-guile
661 (modify-phases %standard-phases
665 (lambda* (#:key outputs #:allow-other-keys)
666 (let* ((out (assoc-ref outputs "out"))
667 (include (string-append out "/include"))
668 (headers (assoc-ref %build-inputs "headers" )))
670 (copy-recursively "include" out)
671 (copy-recursively headers out)
674 ;; Use the language-specific variables rather than 'CPATH' because they
675 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
676 ;; The intent is to allow headers that are in the search path to be
677 ;; treated as "system headers" (headers exempt from warnings) just like
678 ;; the typical /usr/include headers on an FHS system.
679 (list (search-path-specification
680 (variable "C_INCLUDE_PATH")
681 (files '("include")))))))
683 (define glibc-mesboot0
684 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
685 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
689 (name "glibc-mesboot0")
691 (source (bootstrap-origin
694 (uri (string-append "mirror://gnu/glibc/glibc-"
697 (patches (search-patches "glibc-boot-2.2.5.patch"))
700 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
701 (supported-systems '("i686-linux" "x86_64-linux"))
703 (propagated-inputs '())
704 (native-inputs `(("binutils" ,binutils-mesboot0)
705 ("gcc" ,gcc-core-mesboot)
707 ("bash" ,%bootstrap-coreutils&co)
708 ("coreutils" ,%bootstrap-coreutils&co)
709 ("diffutils" ,diffutils-mesboot)
710 ("headers" ,mesboot-headers)
711 ("make" ,make-mesboot0)))
714 `(#:implicit-inputs? #f
715 #:guile ,%bootstrap-guile
718 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
719 #:make-flags (list (string-append
721 (assoc-ref %build-inputs "bash")
724 (let ((out (assoc-ref %outputs "out"))
725 (headers (assoc-ref %build-inputs "headers")))
729 "--disable-sanity-checks"
730 "--build=i686-unknown-linux-gnu"
731 "--host=i686-unknown-linux-gnu"
732 (string-append "--with-headers=" headers "/include")
733 "--enable-static-nss"
738 (string-append "--prefix=" out)))
740 (modify-phases %standard-phases
741 (add-before 'configure 'setenv
742 (lambda* (#:key outputs #:allow-other-keys)
743 (let* ((out (assoc-ref outputs "out"))
744 (bash (assoc-ref %build-inputs "bash"))
745 (gcc (assoc-ref %build-inputs "gcc"))
746 (headers (assoc-ref %build-inputs "headers"))
747 (cppflags (string-append
749 " -D MES_BOOTSTRAP=1"
750 " -D BOOTSTRAP_GLIBC=1"))
751 (cflags (string-append " -L " (getcwd))))
752 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
753 (setenv "SHELL" (getenv "CONFIG_SHELL"))
754 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
755 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
757 ;; glibc-2.2.5 needs a more classic invocation of configure
758 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
760 (lambda* (#:key configure-flags #:allow-other-keys)
761 (format (current-error-port)
762 "running ./configure ~a\n" (string-join configure-flags))
763 (apply invoke "./configure" configure-flags))))))
765 ;; Use the language-specific variables rather than 'CPATH' because they
766 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
767 ;; The intent is to allow headers that are in the search path to be
768 ;; treated as "system headers" (headers exempt from warnings) just like
769 ;; the typical /usr/include headers on an FHS system.
770 (list (search-path-specification
771 (variable "C_INCLUDE_PATH")
772 (files '("include")))
773 (search-path-specification
774 (variable "CPLUS_INCLUDE_PATH")
775 (files '("include")))
776 (search-path-specification
777 (variable "LIBRARY_PATH")
778 (files '("lib")))))))
782 (inherit gcc-core-mesboot)
783 (name "gcc-mesboot0")
784 (native-inputs `(("binutils" ,binutils-mesboot0)
785 ("gcc" ,gcc-core-mesboot)
786 ("libc" ,glibc-mesboot0)
788 ("bash" ,%bootstrap-coreutils&co)
789 ("coreutils" ,%bootstrap-coreutils&co)
790 ("diffutils" ,diffutils-mesboot)
791 ("kernel-headers" ,%bootstrap-linux-libre-headers)
792 ("make" ,make-mesboot0)))
794 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
796 `(modify-phases ,phases
798 (lambda* (#:key outputs #:allow-other-keys)
799 (let ((out (assoc-ref outputs "out"))
800 (bash (assoc-ref %build-inputs "bash"))
801 (gcc (assoc-ref %build-inputs "gcc"))
802 (glibc (assoc-ref %build-inputs "libc"))
803 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
804 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
805 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
806 (setenv "C_INCLUDE_PATH" (string-append
807 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include"
808 ":" kernel-headers "/include"
809 ":" glibc "/include"))
810 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
811 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
812 ;; FIXME: add glibc dirs to paths manually
813 (setenv "LIBRARY_PATH" (string-join
814 (list (string-append glibc "/lib")
815 (getenv "LIBRARY_PATH"))
817 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
818 (with-output-to-file "config.cache"
821 ac_cv_c_float_format='IEEE (little-endian)'
825 (lambda* (#:key outputs #:allow-other-keys)
826 (let* ((out (assoc-ref outputs "out"))
827 (gcc-dir (string-append
828 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
830 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
831 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
832 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
834 ((#:configure-flags configure-flags)
835 `(let ((out (assoc-ref %outputs "out")))
838 "--build=i686-unknown-linux-gnu"
839 "--host=i686-unknown-linux-gnu"
840 ,(string-append "--prefix=" out))))
841 ((#:make-flags make-flags)
842 `(let ((gcc (assoc-ref %build-inputs "gcc")))
844 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
847 (define binutils-mesboot
849 (inherit binutils-mesboot0)
850 (name "binutils-mesboot")
851 (native-inputs `(("binutils" ,binutils-mesboot0)
852 ("libc" ,glibc-mesboot0)
853 ("gcc" ,gcc-mesboot0)
855 ("bash" ,%bootstrap-coreutils&co)
856 ("coreutils" ,%bootstrap-coreutils&co)
857 ("diffutils" ,diffutils-mesboot)
858 ("kernel-headers" ,%bootstrap-linux-libre-headers)
859 ("make" ,make-mesboot0)))
861 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
862 ((#:configure-flags configure-flags)
863 '(list "--disable-nls"
866 "--build=i686-unknown-linux-gnu"
867 "--host=i686-unknown-linux-gnu"
868 "--with-sysroot=/"))))))
872 (inherit make-mesboot0)
873 (name "make-mesboot")
877 (uri (string-append "mirror://gnu/make/make-"
881 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
882 (native-inputs `(("binutils" ,binutils-mesboot0)
883 ("libc" ,glibc-mesboot0)
884 ("gcc" ,gcc-mesboot0)
885 ("make" ,make-mesboot0)
887 ("bash" ,%bootstrap-coreutils&co)
888 ("coreutils" ,%bootstrap-coreutils&co)
889 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
891 (substitute-keyword-arguments (package-arguments make-mesboot0)
892 ((#:configure-flags configure-flags)
893 `(let ((out (assoc-ref %outputs "out")))
894 `(,(string-append "--prefix=" out))))
896 `(modify-phases ,phases
897 (delete 'configure-fixup)
898 (add-before 'configure 'setenv
900 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
909 (uri (string-append "mirror://gnu/gmp/gmp-" version
912 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
920 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
923 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
932 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
935 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
939 (inherit gcc-mesboot0)
940 (name "gcc-mesboot1")
942 (source (bootstrap-origin
943 (origin (inherit (package-source gcc-4.7))
944 (patches (search-patches "gcc-boot-4.7.4.patch")))))
945 (inputs `(("gmp-source" ,(package-source gmp-boot))
946 ("mpfr-source" ,(package-source mpfr-boot))
947 ("mpc-source" ,(package-source mpc-boot))))
948 (native-inputs `(("binutils" ,binutils-mesboot)
949 ("gcc" ,gcc-mesboot0)
950 ("libc" ,glibc-mesboot0)
952 ("bash" ,%bootstrap-coreutils&co)
953 ("coreutils" ,%bootstrap-coreutils&co)
954 ("diffutils" ,diffutils-mesboot)
955 ("kernel-headers" ,%bootstrap-linux-libre-headers)
956 ("make" ,make-mesboot)))
958 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
959 ((#:make-flags make-flags)
960 `(let* ((libc (assoc-ref %build-inputs "libc"))
961 (ldflags (string-append
963 "-Wl,-dynamic-linker "
965 ,(glibc-dynamic-linker "i686-linux"))))
966 (list (string-append "LDFLAGS=" ldflags)
967 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
969 `(modify-phases ,phases
970 ;; c&p from commencement.scm:gcc-boot0
971 (add-after 'unpack 'unpack-gmp&co
972 (lambda* (#:key inputs #:allow-other-keys)
973 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
974 (mpfr (assoc-ref %build-inputs "mpfr-source"))
975 (mpc (assoc-ref %build-inputs "mpc-source")))
977 ;; To reduce the set of pre-built bootstrap inputs, build
978 ;; GMP & co. from GCC.
979 (for-each (lambda (source)
980 (or (invoke "tar" "xvf" source)
981 (error "failed to unpack tarball"
985 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
987 ;; Drop trailing letters, as gmp-6.0.0a unpacks
989 `(symlink ,(string-trim-right
990 (package-full-name lib "-")
992 ,(package-name lib)))
993 (list gmp-boot mpfr-boot mpc-boot))
995 (delete 'remove-info)
997 (lambda* (#:key outputs #:allow-other-keys)
998 (let* ((out (assoc-ref outputs "out"))
999 (binutils (assoc-ref %build-inputs "binutils"))
1000 (bash (assoc-ref %build-inputs "bash"))
1001 (gcc (assoc-ref %build-inputs "gcc"))
1002 (glibc (assoc-ref %build-inputs "libc"))
1003 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
1004 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1005 (setenv "C_INCLUDE_PATH" (string-append
1006 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include"
1007 ":" kernel-headers "/include"
1008 ":" glibc "/include"
1009 ":" (getcwd) "/mpfr/src"))
1010 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
1012 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
1013 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
1015 (delete 'install2)))
1016 ((#:configure-flags configure-flags)
1017 `(let ((out (assoc-ref %outputs "out"))
1018 (glibc (assoc-ref %build-inputs "libc")))
1019 (list (string-append "--prefix=" out)
1020 "--build=i686-unknown-linux-gnu"
1021 "--host=i686-unknown-linux-gnu"
1023 (string-append "--with-native-system-header-dir=" glibc "/include")
1024 (string-append "--with-build-sysroot=" glibc "/include")
1026 "--disable-bootstrap"
1027 "--disable-decimal-float"
1028 "--disable-libatomic"
1029 "--disable-libcilkrts"
1032 "--disable-libmudflap"
1033 "--disable-libquadmath"
1034 "--disable-libsanitizer"
1038 "--disable-lto-plugin"
1039 "--disable-multilib"
1042 "--enable-languages=c,c++"
1045 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1047 "--enable-threads=single"
1049 ;; No pre-compiled libstdc++ headers, to save space.
1050 "--disable-libstdcxx-pch"
1053 "--disable-build-with-cxx")))))))
1055 (define gcc-mesboot1-wrapper
1056 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1057 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1058 ;; --enable-shared will fail.
1060 (inherit gcc-mesboot1)
1061 (name "gcc-mesboot1-wrapper")
1064 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1065 ("libc" ,glibc-mesboot)
1066 ("gcc" ,gcc-mesboot1)))
1068 `(#:implicit-inputs? #f
1069 #:guile ,%bootstrap-guile
1071 (modify-phases %standard-phases
1076 (lambda* (#:key outputs #:allow-other-keys)
1077 (let* ((out (assoc-ref outputs "out"))
1078 (bash (assoc-ref %build-inputs "bash"))
1079 (libc (assoc-ref %build-inputs "libc"))
1080 (gcc (assoc-ref %build-inputs "gcc"))
1081 (bin (string-append out "/bin")))
1085 (let ((wrapper (string-append bin "/" program)))
1086 (with-output-to-file wrapper
1088 (display (string-append "#! " bash "/bin/bash
1089 exec " gcc "/bin/" program
1090 " -Wl,--dynamic-linker"
1091 ;; also for x86_64-linux, we are still on i686-linux
1092 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1097 (chmod wrapper #o555)))))
1101 "i686-unknown-linux-gnu-gcc"
1102 "i686-unknown-linux-gnu-g++"
1106 (lambda* (#:key outputs #:allow-other-keys)
1107 (let* ((out (assoc-ref outputs "out"))
1108 (bin (string-append out "/bin"))
1109 (program (string-append bin "/gcc")))
1110 (invoke program "--help")))))))))
1112 (define glibc-headers-mesboot
1114 (inherit glibc-mesboot0)
1115 (name "glibc-headers-mesboot")
1117 (source (bootstrap-origin
1120 (uri (string-append "mirror://gnu/glibc/glibc-"
1123 (patches (search-patches "glibc-boot-2.16.0.patch"
1124 "glibc-bootstrap-system-2.16.0.patch"))
1127 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1128 (native-inputs `(("binutils" ,binutils-mesboot)
1129 ("libc" ,glibc-mesboot0)
1130 ("gcc" ,gcc-mesboot1)
1131 ("headers" ,mesboot-headers)
1133 ("bash" ,%bootstrap-coreutils&co)
1134 ("coreutils" ,%bootstrap-coreutils&co)
1135 ("diffutils" ,diffutils-mesboot)
1136 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1137 ("make" ,make-mesboot)))
1140 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1141 ((#:configure-flags configure-flags)
1142 `(let ((out (assoc-ref %outputs "out"))
1143 (headers (assoc-ref %build-inputs "headers")))
1145 (string-append "--prefix=" out)
1146 "--disable-obsolete-rpc"
1147 "--host=i686-unknown-linux-gnu"
1148 (string-append "--with-headers=" headers "/include")
1149 "--enable-static-nss"
1153 "--enable-add-ons=nptl")))
1154 ((#:make-flags make-flags)
1155 `(let ((bash (assoc-ref %build-inputs "bash")))
1156 (list (string-append "SHELL=" bash "/bin/sh")
1157 "install-bootstrap-headers=yes" "install-headers")))
1159 `(modify-phases ,phases
1161 (lambda* (#:key outputs #:allow-other-keys)
1162 (let* ((out (assoc-ref outputs "out"))
1163 (headers (assoc-ref %build-inputs "headers"))
1164 (bash (assoc-ref %build-inputs "bash"))
1165 (coreutils (assoc-ref %build-inputs "coreutils"))
1166 (libc (assoc-ref %build-inputs "libc"))
1167 (gcc (assoc-ref %build-inputs "gcc"))
1168 (cppflags (string-append
1169 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1170 " -D BOOTSTRAP_GLIBC=1"))
1171 (cflags (string-append " -L " (getcwd)
1172 " -L " libc "/lib")))
1173 (setenv "libc_cv_friendly_stddef" "yes")
1174 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1175 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1176 (format (current-error-port) "CONFIG_SHELL=~s\n" (getenv "CONFIG_SHELL"))
1178 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1179 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1181 ;; avoid -fstack-protector
1182 (setenv "libc_cv_ssp" "false")
1183 (substitute* "configure"
1184 (("/bin/pwd") (string-append coreutils "/bin/pwd")))
1185 (setenv "C_INCLUDE_PATH" (string-append libc "/include"
1186 headers "/include"))
1187 (setenv "LIBRARY_PATH" (string-append libc "/lib"))
1190 (lambda* (#:key outputs make-flags #:allow-other-keys)
1191 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1192 (out (assoc-ref outputs "out")))
1193 (apply invoke "make" make-flags)
1194 (copy-recursively kernel-headers out)
1197 (lambda* (#:key configure-flags #:allow-other-keys)
1198 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1201 (apply invoke "../configure" configure-flags)))
1202 (add-after 'configure 'remove-sunrpc
1204 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1205 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1206 (substitute* "sysd-sorted"
1209 ;; 'rpcgen' needs native libc headers to be built.
1210 (substitute* "../Makefile"
1211 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1212 (substitute* "../Makeconfig"
1213 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1214 (substitute* "../elf/Makefile"
1215 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1217 (define glibc-mesboot
1219 (inherit glibc-headers-mesboot)
1220 (name "glibc-mesboot")
1221 (native-inputs `(("binutils" ,binutils-mesboot)
1222 ("libc" ,glibc-mesboot0)
1223 ("headers" ,glibc-headers-mesboot)
1224 ("gcc" ,gcc-mesboot1)
1226 ("bash" ,%bootstrap-coreutils&co)
1227 ("coreutils" ,%bootstrap-coreutils&co)
1228 ("diffutils" ,diffutils-mesboot)
1229 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1230 ("make" ,make-mesboot)))
1233 `(#:validate-runpath? #f ; fails when using --enable-shared
1234 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1235 ((#:make-flags make-flags)
1236 `(let ((bash (assoc-ref %build-inputs "bash")))
1237 (list (string-append "SHELL=" bash "/bin/sh"))))
1239 `(modify-phases ,phases
1241 (lambda* (#:key outputs make-flags #:allow-other-keys)
1242 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1243 (out (assoc-ref outputs "out"))
1244 (install-flags (cons "install" make-flags)))
1245 (apply invoke "make" install-flags)
1246 (copy-recursively kernel-headers out)
1248 (native-search-paths ;; FIXME: move to glibc-mesboot0
1249 ;; Use the language-specific variables rather than 'CPATH' because they
1250 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
1251 ;; The intent is to allow headers that are in the search path to be
1252 ;; treated as "system headers" (headers exempt from warnings) just like
1253 ;; the typical /usr/include headers on an FHS system.
1254 (list (search-path-specification
1255 (variable "C_INCLUDE_PATH")
1256 (files '("include")))
1257 (search-path-specification
1258 (variable "CPLUS_INCLUDE_PATH")
1259 (files '("include")))
1260 (search-path-specification
1261 (variable "LIBRARY_PATH")
1262 (files '("lib")))))))
1266 (inherit gcc-mesboot1)
1267 (name "gcc-mesboot")
1269 (source (bootstrap-origin (package-source gcc-4.9)))
1270 (native-inputs `(("binutils" ,binutils-mesboot)
1271 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1272 ("gcc" ,gcc-mesboot1)
1273 ("libc" ,glibc-mesboot)
1275 ("bash" ,%bootstrap-coreutils&co)
1276 ("coreutils" ,%bootstrap-coreutils&co)
1277 ("diffutils" ,diffutils-mesboot)
1278 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1279 ("make" ,make-mesboot)))
1281 `(#:validate-runpath? #f
1282 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1283 ((#:configure-flags configure-flags)
1284 `(let ((out (assoc-ref %outputs "out"))
1285 (glibc (assoc-ref %build-inputs "libc")))
1286 (list (string-append "--prefix=" out)
1287 "--build=i686-unknown-linux-gnu"
1288 "--host=i686-unknown-linux-gnu"
1290 "--with-host-libstdcxx=-lsupc++"
1292 (string-append "--with-native-system-header-dir=" glibc "/include")
1293 (string-append "--with-build-sysroot=" glibc "/include")
1295 "--disable-bootstrap"
1296 "--disable-decimal-float"
1297 "--disable-libatomic"
1298 "--disable-libcilkrts"
1301 "--disable-libmudflap"
1302 "--disable-libquadmath"
1303 "--disable-libsanitizer"
1307 "--disable-lto-plugin"
1308 "--disable-multilib"
1311 "--enable-languages=c,c++"
1315 "--enable-threads=single"
1317 ;; No pre-compiled libstdc++ headers, to save space.
1318 "--disable-libstdcxx-pch"
1321 "--disable-build-with-cxx")))
1323 `(modify-phases ,phases
1325 (lambda* (#:key outputs #:allow-other-keys)
1326 (let* ((out (assoc-ref outputs "out"))
1327 (binutils (assoc-ref %build-inputs "binutils"))
1328 (bash (assoc-ref %build-inputs "bash"))
1329 (gcc (assoc-ref %build-inputs "gcc"))
1330 (glibc (assoc-ref %build-inputs "libc"))
1331 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
1332 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1333 (setenv "C_INCLUDE_PATH" (string-append
1334 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.7.4/include"
1335 ":" kernel-headers "/include"
1336 ":" glibc "/include"
1337 ":" (getcwd) "/mpfr/src"))
1338 (setenv "CPLUS_INCLUDE_PATH" (string-append
1339 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.7.4/include"
1340 ":" kernel-headers "/include"
1341 ":" glibc "/include"
1342 ":" (getcwd) "/mpfr/src"))
1343 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
1345 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
1346 (format (current-error-port) "CPLUS_INCLUDE_PATH=~a\n" (getenv "CPLUS_INCLUDE_PATH"))
1347 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
1350 (define gcc-mesboot-wrapper
1351 ;; We need this so gcc-mesboot can be used to create shared binaries that
1352 ;; have the correct interpreter and runpath to libc.
1354 (inherit gcc-mesboot1-wrapper)
1355 (name "gcc-mesboot-wrapper")
1356 (version (package-version gcc-mesboot))
1359 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1360 ("libc" ,glibc-mesboot)
1361 ("gcc" ,gcc-mesboot)))))
1370 (uri (string-append "mirror://gnu/m4/m4-"
1374 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1375 (supported-systems '("i686-linux" "x86_64-linux"))
1376 (native-inputs `(("mes" ,mes-boot)
1380 (modify-phases %standard-phases
1382 (lambda* (#:key outputs #:allow-other-keys)
1383 (let ((out (assoc-ref outputs "out")))
1384 (setenv "CONFIG_SHELL" (string-append
1385 (assoc-ref %build-inputs "bash")
1387 (setenv "CC" "tcc -static")
1388 (setenv "CPP" "tcc -E")
1389 (invoke "./configure" (string-append "--prefix=" out))))))))))
1391 (define (%bootstrap-inputs+toolchain)
1392 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1393 ;; the actual reduced set with bootstrapped toolchain.
1394 (match (%current-system)
1395 ((or "i686-linux" "x86_64-linux")
1396 `(("libc" ,glibc-mesboot)
1397 ("binutils" ,binutils-mesboot)
1398 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1399 ("gcc" ,gcc-mesboot)
1400 ,@(fold alist-delete (%bootstrap-inputs)
1401 '("bootstrap-mescc-tools" "mes"))))
1403 (%bootstrap-inputs))))
1405 (define gnu-make-boot0
1408 (source (bootstrap-origin (package-source gnu-make)))
1411 `(#:guile ,%bootstrap-guile
1412 #:implicit-inputs? #f
1413 #:tests? #f ; cannot run "make check"
1414 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1415 ((#:configure-flags flags ''())
1416 ;; The generated config.status has some problems due to the
1417 ;; bootstrap environment. Disable dependency tracking to work
1419 `(cons "--disable-dependency-tracking" ,flags))
1421 `(modify-phases ,phases
1424 (invoke "./build.sh")))
1426 (lambda* (#:key outputs #:allow-other-keys)
1427 (let* ((out (assoc-ref outputs "out"))
1428 (bin (string-append out "/bin")))
1429 (install-file "make" bin)
1431 (native-inputs '()) ; no need for 'pkg-config'
1432 (inputs (%bootstrap-inputs+toolchain))))
1434 (define diffutils-boot0
1437 (name "diffutils-boot0")
1440 `(("make" ,gnu-make-boot0)
1441 ,@(%bootstrap-inputs+toolchain)))
1443 `(#:tests? #f ; the test suite needs diffutils
1444 #:guile ,%bootstrap-guile
1445 #:implicit-inputs? #f
1446 ,@(package-arguments diffutils)))))
1448 (define findutils-boot0
1451 (name "findutils-boot0")
1452 (source (bootstrap-origin (package-source findutils)))
1454 `(("make" ,gnu-make-boot0)
1455 ("diffutils" ,diffutils-boot0) ; for tests
1456 ,@(%bootstrap-inputs+toolchain)))
1458 `(#:implicit-inputs? #f
1459 #:guile ,%bootstrap-guile
1461 ;; The build system assumes we have done a mistake when time_t is 32-bit
1462 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1463 ,@(if (target-64bit?)
1464 (substitute-keyword-arguments (package-arguments findutils)
1465 ((#:configure-flags flags ''())
1466 `(cons "TIME_T_32_BIT_OK=yes"
1468 (package-arguments findutils))))))
1473 (source (bootstrap-origin (package-source file)))
1476 `(("make" ,gnu-make-boot0)
1477 ,@(%bootstrap-inputs+toolchain)))
1479 `(#:implicit-inputs? #f
1480 #:guile ,%bootstrap-guile
1481 #:strip-binaries? #f
1482 #:validate-runpath? #f))))
1484 (define (%boot0-inputs)
1485 `(("make" ,gnu-make-boot0)
1486 ("diffutils" ,diffutils-boot0)
1487 ("findutils" ,findutils-boot0)
1488 ("file" ,file-boot0)
1489 ,@(%bootstrap-inputs+toolchain)))
1491 (define* (boot-triplet #:optional (system (%current-system)))
1492 ;; Return the triplet used to create the cross toolchain needed in the
1493 ;; first bootstrapping stage.
1494 (nix-system->gnu-triplet system "guix"))
1496 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1497 ;; toolchain actually targets the same OS and arch, but it has the advantage
1498 ;; of being independent of the libc and tools in
1499 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1500 ;; reference to the target libc.
1502 (define binutils-boot0
1505 (source (bootstrap-origin (package-source binutils)))
1506 (name "binutils-cross-boot0")
1508 `(#:guile ,%bootstrap-guile
1509 #:implicit-inputs? #f
1511 #:modules ((guix build gnu-build-system)
1513 (ice-9 ftw)) ; for 'scandir'
1514 #:phases (modify-phases %standard-phases
1515 (add-after 'install 'add-symlinks
1516 (lambda* (#:key outputs #:allow-other-keys)
1517 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1518 ;; triplet prefix, so add symlinks.
1519 (let ((out (assoc-ref outputs "out"))
1520 (triplet-prefix (string-append ,(boot-triplet) "-")))
1521 (define (has-triplet-prefix? name)
1522 (string-prefix? triplet-prefix name))
1523 (define (remove-triplet-prefix name)
1524 (substring name (string-length triplet-prefix)))
1525 (with-directory-excursion (string-append out "/bin")
1526 (for-each (lambda (name)
1527 (symlink name (remove-triplet-prefix name)))
1528 (scandir "." has-triplet-prefix?)))
1531 ,@(substitute-keyword-arguments (package-arguments binutils)
1532 ((#:configure-flags cf)
1533 `(cons ,(string-append "--target=" (boot-triplet))
1535 (inputs (%boot0-inputs))))
1537 (define libstdc++-boot0
1538 ;; GCC's libcc1 is always built as a shared library (the top-level
1539 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1540 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
1541 ;; C++14 features missing in some of our bootstrap compilers.
1542 (let ((lib (make-libstdc++ gcc-4.9)))
1545 (source (bootstrap-origin (package-source lib)))
1546 (name "libstdc++-boot0")
1548 `(#:guile ,%bootstrap-guile
1549 #:implicit-inputs? #f
1551 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1552 #:validate-runpath? #f
1554 ,@(match (%current-system)
1555 ((or "i686-linux" "x86_64-linux")
1556 (substitute-keyword-arguments (package-arguments lib)
1558 `(modify-phases ,phases
1559 (add-after 'unpack 'workaround-wrapper-bug
1560 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1561 ;; fail, which in turn confuses the configure script.
1563 (substitute* "libstdc++-v3/configure"
1564 (("g\\+\\+ -v") "true"))
1566 (_ (package-arguments lib)))))
1567 (inputs (%boot0-inputs))
1568 (native-inputs '()))))
1573 (name "gcc-cross-boot0")
1574 (source (bootstrap-origin (package-source gcc)))
1576 `(#:guile ,%bootstrap-guile
1577 #:implicit-inputs? #f
1578 #:modules ((guix build gnu-build-system)
1583 ,@(substitute-keyword-arguments (package-arguments gcc)
1584 ((#:configure-flags flags)
1585 `(append (list ,(string-append "--target=" (boot-triplet))
1590 ;; Disable features not needed at this stage.
1592 "--enable-languages=c,c++"
1594 ;; libstdc++ cannot be built at this stage
1595 ;; ("Link tests are not allowed after
1596 ;; GCC_NO_EXECUTABLES.").
1597 "--disable-libstdc++-v3"
1600 "--disable-libmudflap"
1601 "--disable-libatomic"
1602 "--disable-libsanitizer"
1606 "--disable-libcilkrts"
1609 "--disable-libquadmath"
1610 "--disable-decimal-float")
1611 (remove (cut string-match
1612 "--(with-system-zlib|enable-languages.*)" <>)
1614 ((#:make-flags flags)
1615 `(let* ((libc (assoc-ref %build-inputs "libc"))
1616 (libc-native (or (assoc-ref %build-inputs "libc-native")
1618 `(,(string-append "LDFLAGS="
1619 "-Wl,-rpath=" libc-native "/lib "
1620 "-Wl,-dynamic-linker "
1621 "-Wl," libc-native ,(glibc-dynamic-linker
1622 (match (%current-system)
1623 ("x86_64-linux" "i686-linux")
1624 (_ (%current-system))))))))
1626 `(modify-phases ,phases
1627 (add-after 'unpack 'unpack-gmp&co
1628 (lambda* (#:key inputs #:allow-other-keys)
1629 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1630 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1631 (mpc (assoc-ref %build-inputs "mpc-source")))
1633 ;; To reduce the set of pre-built bootstrap inputs, build
1634 ;; GMP & co. from GCC.
1635 (for-each (lambda (source)
1636 (invoke "tar" "xvf" source))
1637 (list gmp mpfr mpc))
1639 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1640 ,@(map (lambda (lib)
1641 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1643 `(symlink ,(string-trim-right
1644 (package-full-name lib "-")
1646 ,(package-name lib)))
1647 (list gmp-6.0 mpfr mpc))
1649 ,(match (%current-system)
1650 ((or "i686-linux" "x86_64-linux")
1651 '(add-before 'configure 'fix-libcc1
1652 (lambda* (#:key inputs #:allow-other-keys)
1653 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
1654 ;; to placate the 'validate-runpath' phase.
1655 (substitute* "libcc1/Makefile.in"
1657 (string-append "la_LDFLAGS = -Wl,-rpath="
1658 (assoc-ref inputs "gcc") "/lib")))
1659 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
1660 (substitute* "libcc1/configure"
1661 (("g\\+\\+ -v") "true"))
1663 (_ '(add-before 'configure 'return-true
1665 (add-after 'install 'symlink-libgcc_eh
1666 (lambda* (#:key outputs #:allow-other-keys)
1667 (let ((out (assoc-ref outputs "lib")))
1668 ;; Glibc wants to link against libgcc_eh, so provide
1670 (with-directory-excursion
1671 (string-append out "/lib/gcc/"
1673 "/" ,(package-version gcc))
1674 (symlink "libgcc.a" "libgcc_eh.a"))
1677 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
1678 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
1679 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
1680 ("binutils-cross" ,binutils-boot0)
1682 ;; The libstdc++ that libcc1 links against.
1683 ("libstdc++" ,libstdc++-boot0)
1685 ;; Call it differently so that the builder can check whether
1686 ;; the "libc" input is #f.
1687 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
1688 ,@(alist-delete "libc" (%boot0-inputs))))
1690 ;; No need for the native-inputs to build the documentation at this stage.
1691 (native-inputs `())))
1697 (source (bootstrap-origin (package-source perl)))
1698 (inputs (%boot0-inputs))
1700 `(#:implicit-inputs? #f
1701 #:guile ,%bootstrap-guile
1702 #:validate-runpath? #f
1704 ;; At the very least, this must not depend on GCC & co.
1705 #:disallowed-references ,(list %bootstrap-binutils)
1707 ,@(substitute-keyword-arguments (package-arguments perl)
1709 `(modify-phases ,phases
1710 ;; Pthread support is missing in the bootstrap compiler
1711 ;; (broken spec file), so disable it.
1712 (add-before 'configure 'disable-pthreads
1714 (substitute* "Configure"
1715 (("^libswanted=(.*)pthread" _ before)
1716 (string-append "libswanted=" before)))
1718 ;; Do not configure with '-Dusethreads' since pthread
1719 ;; support is missing.
1720 ((#:configure-flags configure-flags)
1721 `(delete "-Dusethreads" ,configure-flags)))))))
1727 (source (bootstrap-origin (package-source m4)))
1728 (inputs (%boot0-inputs))
1730 `(#:guile ,%bootstrap-guile
1731 #:implicit-inputs? #f
1732 ,@(package-arguments m4)))))
1735 ;; This Bison is needed to build MiG so we need it early in the process.
1736 ;; Recent versions of Linux-Libre headers also depend on this.
1739 (name "bison-boot0")
1740 (propagated-inputs `(("m4" ,m4-boot0)))
1741 (native-inputs `(("perl" ,perl-boot0)))
1742 (inputs (%boot0-inputs)) ;remove Flex...
1744 `(#:tests? #f ;... and thus disable tests
1745 #:implicit-inputs? #f
1746 #:guile ,%bootstrap-guile
1748 ;; Zero timestamps in liby.a; this must be done
1749 ;; explicitly here because the bootstrap Binutils don't
1750 ;; do that (default is "cru".)
1751 #:make-flags `("ARFLAGS=crD"
1752 ,,(match (%current-system)
1753 ;; ranlib: '-D': No such file
1754 ((or "i686-linux" "x86_64-linux")
1757 "RANLIB=ranlib -D"))
1760 ,@(package-arguments bison)))))
1763 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
1766 (native-inputs `(("bison" ,bison-boot0)))
1767 (propagated-inputs `(("m4" ,m4-boot0)))
1768 (inputs (%boot0-inputs))
1770 `(#:implicit-inputs? #f
1771 #:guile ,%bootstrap-guile
1774 (define linux-libre-headers-boot0
1776 "Return Linux-Libre header files for the bootstrap environment."
1777 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
1778 ;; between (gnu packages linux) and this module. Additionally, memoize
1779 ;; the result to play well with further memoization and code that relies
1780 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
1782 (inherit linux-libre-headers)
1784 `(#:guile ,%bootstrap-guile
1785 #:implicit-inputs? #f
1786 ,@(package-arguments linux-libre-headers)))
1788 `(("perl" ,perl-boot0)
1790 ;; Flex and Bison are required since version 4.16.
1791 ("flex" ,flex-boot0)
1792 ("bison" ,bison-boot0)
1793 ,@(%boot0-inputs))))))
1796 (package-with-explicit-inputs %boot0-inputs
1799 (define gnumach-headers-boot0
1800 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
1803 (let* ((mig (package
1804 (inherit (package-with-bootstrap-guile mig))
1805 (native-inputs `(("bison" ,bison-boot0)
1806 ("flex" ,flex-boot0)))
1807 (inputs `(("flex" ,flex-boot0)))
1810 `(,(string-append "LDFLAGS=-Wl,-rpath="
1811 (assoc-ref %build-inputs "flex") "/lib/")))))))
1814 (define hurd-headers-boot0
1815 (let ((hurd-headers (package (inherit hurd-headers)
1816 (native-inputs `(("mig" ,mig-boot0)))
1818 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
1820 (define hurd-minimal-boot0
1821 (let ((hurd-minimal (package (inherit hurd-minimal)
1822 (native-inputs `(("mig" ,mig-boot0)))
1824 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
1826 (define hurd-core-headers-boot0
1828 "Return the Hurd and Mach headers as well as initial Hurd libraries for
1829 the bootstrap environment."
1830 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
1831 (arguments `(#:guile ,%bootstrap-guile
1832 ,@(package-arguments hurd-core-headers)))
1834 `(("gnumach-headers" ,gnumach-headers-boot0)
1835 ("hurd-headers" ,hurd-headers-boot0)
1836 ("hurd-minimal" ,hurd-minimal-boot0)
1837 ,@(%boot0-inputs))))))
1839 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
1841 ("i586-gnu" (hurd-core-headers-boot0))
1842 (_ (linux-libre-headers-boot0))))
1844 (define texinfo-boot0
1845 ;; Texinfo used to build libc's manual.
1846 ;; We build without ncurses because it fails to build at this stage, and
1847 ;; because we don't need the stand-alone Info reader.
1848 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
1852 (inputs `(,@(%boot0-inputs)
1853 ("perl" ,perl-boot0)))
1855 `(#:implicit-inputs? #f
1856 #:guile ,%bootstrap-guile
1858 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
1859 ;; character type in locale" but we don't have a UTF-8 locale at this
1860 ;; stage, so skip them.
1863 (define expat-sans-tests
1866 (inputs (%boot0-inputs))
1868 ;; XXX: Linking 'runtestscpp' fails with things like:
1870 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
1872 ;; Skip tests altogether.
1873 `(#:implicit-inputs? #f
1874 #:guile ,%bootstrap-guile
1876 ,@(substitute-keyword-arguments (package-arguments expat)
1877 ((#:configure-flags flags ''())
1878 ;; Since we're not passing the right -Wl,-rpath flags, build the
1879 ;; static library to avoid RUNPATH validation failure.
1880 `(cons "--disable-shared" ,flags))
1881 ((#:tests? _ #f) #f))))))
1883 (define python-boot0
1885 (inherit python-minimal)
1886 ;; We cannot use Python 3.7 and later here, because they require
1887 ;; pthreads, which is missing on non-x86 platforms at this stage.
1888 ;; Python 3.6 technically supports being built without threading
1889 ;; support, but requires additional patches.
1891 (source (bootstrap-origin
1894 (uri (string-append "https://www.python.org/ftp/python/"
1895 version "/Python-" version ".tar.xz"))
1898 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
1899 (modules '((guix build utils)))
1902 ;; Delete the bundled copy of libexpat.
1903 (delete-file-recursively "Modules/expat")
1904 (substitute* "Modules/Setup.dist"
1905 ;; Link Expat instead of embedding the bundled one.
1906 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
1910 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
1911 (native-inputs '()) ;and pkg-config
1913 `(#:implicit-inputs? #f
1914 #:guile ,%bootstrap-guile
1916 ,@(substitute-keyword-arguments (package-arguments python-minimal)
1917 ;; Disable features that cannot be built at this stage.
1918 ((#:configure-flags _ ''())
1919 `(list "--without-ensurepip"
1920 "--without-threads"))
1921 ;; Clear #:make-flags, such that changes to the regular
1922 ;; Python package won't interfere with this one.
1923 ((#:make-flags _ ''()) ''())
1925 `(modify-phases ,phases
1926 (add-before 'configure 'disable-modules
1928 (substitute* "setup.py"
1929 ;; Disable ctypes, since it requires libffi.
1930 (("extensions\\.append\\(ctypes\\)") "")
1931 ;; Prevent the 'ossaudiodev' extension from being
1932 ;; built, since it requires Linux headers.
1935 (delete 'set-TZDIR)))
1936 ((#:tests? _ #f) #f))))))
1938 (define ld-wrapper-boot0
1940 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
1941 ;; in their RUNPATH, otherwise validate-runpath will fail.
1942 (make-ld-wrapper "ld-wrapper-boot0"
1943 #:target boot-triplet
1944 #:binutils binutils-boot0
1945 #:guile %bootstrap-guile
1946 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
1947 #:guile-for-build %bootstrap-guile)))
1949 (define (%boot1-inputs)
1950 ;; 2nd stage inputs.
1951 `(("gcc" ,gcc-boot0)
1952 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
1953 ("binutils-cross" ,binutils-boot0)
1954 ,@(alist-delete "binutils" (%boot0-inputs))))
1956 (define glibc-final-with-bootstrap-bash
1957 ;; The final libc, "cross-built". If everything went well, the resulting
1958 ;; store path has no dependencies. Actually, the really-final libc is
1959 ;; built just below; the only difference is that this one uses the
1963 (name "glibc-intermediate")
1964 (source (bootstrap-origin (package-source glibc)))
1966 `(#:guile ,%bootstrap-guile
1967 #:implicit-inputs? #f
1969 ,@(substitute-keyword-arguments (package-arguments glibc)
1970 ((#:configure-flags flags)
1971 `(append (list ,(string-append "--host=" (boot-triplet))
1972 ,(string-append "--build="
1973 (nix-system->gnu-triplet)))
1976 `(modify-phases ,phases
1977 (add-before 'configure 'pre-configure
1978 (lambda* (#:key inputs #:allow-other-keys)
1979 ;; Don't clobber CPATH with the bootstrap libc.
1980 (setenv "NATIVE_CPATH" (getenv "CPATH"))
1983 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
1984 ,@(if (hurd-triplet? (%current-system))
1985 `((substitute* "libpthread/Makefile"
1986 (("LDLIBS-pthread.so =.*")
1987 (string-append "LDLIBS-pthread.so = "
1988 (assoc-ref %build-inputs "kernel-headers")
1989 "/lib/libihash.a\n"))))
1992 ;; 'rpcgen' needs native libc headers to be built.
1993 (substitute* "sunrpc/Makefile"
1994 (("sunrpc-CPPFLAGS =.*" all)
1995 (string-append "CPATH = $(NATIVE_CPATH)\n"
1999 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2001 `(("bison" ,bison-boot0)
2002 ("texinfo" ,texinfo-boot0)
2003 ("perl" ,perl-boot0)
2004 ("python" ,python-boot0)))
2006 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2007 ;; it in $CPATH, hence the 'pre-configure' phase above.
2010 ;; A native MiG is needed to build Glibc on Hurd.
2011 ,@(if (hurd-triplet? (%current-system))
2012 `(("mig" ,mig-boot0))
2015 ;; A native GCC is needed to build `cross-rpcgen'.
2016 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2018 ;; Here, we use the bootstrap Bash, which is not satisfactory
2019 ;; because we don't want to depend on bootstrap tools.
2020 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
2022 (define (cross-gcc-wrapper gcc binutils glibc bash)
2023 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2024 that makes it available under the native tool names."
2025 (package (inherit gcc)
2026 (name (string-append (package-name gcc) "-wrapped"))
2028 (build-system trivial-build-system)
2031 `(#:guile ,%bootstrap-guile
2032 #:modules ((guix build utils))
2034 (use-modules (guix build utils))
2036 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2037 (gcc (assoc-ref %build-inputs "gcc"))
2038 (libc (assoc-ref %build-inputs "libc"))
2039 (bash (assoc-ref %build-inputs "bash"))
2040 (out (assoc-ref %outputs "out"))
2041 (bindir (string-append out "/bin"))
2042 (triplet ,(boot-triplet)))
2043 (define (wrap-program program)
2044 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2045 ;; needs to be told where to find the crt files and
2046 ;; the dynamic linker.
2047 (call-with-output-file program
2049 (format p "#!~a/bin/bash
2050 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2054 ,(glibc-dynamic-linker))))
2056 (chmod program #o555))
2059 (with-directory-excursion bindir
2060 (for-each (lambda (tool)
2061 (symlink (string-append binutils "/bin/"
2065 (for-each wrap-program '("gcc" "g++")))
2069 `(("binutils" ,binutils)
2075 (define gcc-boot0-intermediate-wrapped
2077 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2079 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2080 glibc-final-with-bootstrap-bash
2081 (car (assoc-ref (%boot1-inputs) "bash")))))
2083 (define static-bash-for-glibc
2084 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
2086 (inherit static-bash)
2087 (source (bootstrap-origin (package-source static-bash)))
2088 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2089 ("libc" ,glibc-final-with-bootstrap-bash)
2090 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2091 ,@(fold alist-delete (%boot1-inputs)
2094 `(#:implicit-inputs? #f
2095 #:guile ,%bootstrap-guile
2097 ,@(substitute-keyword-arguments (package-arguments static-bash)
2098 ((#:configure-flags flags '())
2099 ;; Add a '-L' flag so that the pseudo-cross-ld of
2100 ;; BINUTILS-BOOT0 can find libc.a.
2102 (list (string-append "LDFLAGS=-static -L"
2103 (assoc-ref %build-inputs
2107 (define gettext-boot0
2108 ;; A minimal gettext used during bootstrap.
2110 (inherit gettext-minimal)
2111 (name "gettext-boot0")
2112 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2113 ;; simplify the dependency chain, we stick to this version here.
2114 (version "0.19.8.1")
2117 (uri (string-append "mirror://gnu/gettext/gettext-"
2121 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2122 (inputs (%boot1-inputs)) ;zero dependencies
2124 `(#:implicit-inputs? #f
2125 #:guile ,%bootstrap-guile
2127 #:phases (modify-phases %standard-phases
2128 ;; Build only the tools.
2129 (add-after 'unpack 'chdir
2131 (chdir "gettext-tools")
2134 ;; Some test programs require pthreads, which we don't have.
2135 (add-before 'configure 'no-test-programs
2137 (substitute* "tests/Makefile.in"
2143 ;; The final glibc, which embeds the statically-linked Bash built above.
2144 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2148 (source (bootstrap-origin (package-source glibc)))
2149 (inputs `(("static-bash" ,static-bash-for-glibc)
2152 (package-inputs glibc-final-with-bootstrap-bash))))
2154 ;; This time we need 'msgfmt' to install all the libc.mo files.
2155 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2156 ("gettext" ,gettext-boot0)))
2159 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2161 ;; The final libc only refers to itself, but the 'debug' output contains
2162 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2163 ;; if 'allowed-references' were per-output.
2165 `(#:allowed-references
2166 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2167 static-bash-for-glibc
2168 (package-outputs glibc-final-with-bootstrap-bash))
2170 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2172 (define gcc-boot0-wrapped
2174 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2176 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2177 (car (assoc-ref (%boot1-inputs) "bash")))))
2179 (define (%boot2-inputs)
2180 ;; 3rd stage inputs.
2181 `(("libc" ,glibc-final)
2182 ("libc:static" ,glibc-final "static")
2183 ("gcc" ,(gcc-boot0-wrapped))
2184 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2186 (define binutils-final
2189 (source (bootstrap-origin (package-source binutils)))
2191 `(#:guile ,%bootstrap-guile
2192 #:implicit-inputs? #f
2193 #:allowed-references ("out" ,glibc-final)
2194 ,@(package-arguments binutils)))
2195 (inputs (%boot2-inputs))))
2198 ;; Intermediate libstdc++ that will allow us to build the final GCC
2199 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2200 (let ((lib (make-libstdc++ gcc)))
2203 (source (bootstrap-origin (package-source lib)))
2205 `(#:guile ,%bootstrap-guile
2206 #:implicit-inputs? #f
2207 #:allowed-references ("out")
2209 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2210 #:validate-runpath? #f
2212 ;; All of the package arguments from 'make-libstdc++
2213 ;; except for the configure-flags.
2214 ,@(package-arguments lib)
2215 #:configure-flags `("--disable-shared"
2216 "--disable-libstdcxx-dual-abi"
2217 "--disable-libstdcxx-threads"
2218 "--disable-libstdcxx-pch"
2219 ,(string-append "--with-gxx-include-dir="
2220 (assoc-ref %outputs "out")
2223 (inputs (%boot2-inputs))
2224 (synopsis "GNU C++ standard library (intermediate)"))))
2227 ;; Zlib used by GCC-FINAL.
2231 `(#:guile ,%bootstrap-guile
2232 #:implicit-inputs? #f
2233 #:allowed-references ("out" ,glibc-final)
2234 ,@(package-arguments zlib)))
2235 (inputs (%boot2-inputs))))
2237 (define ld-wrapper-boot3
2239 ;; A linker wrapper that uses the bootstrap Guile.
2240 (make-ld-wrapper "ld-wrapper-boot3"
2241 #:binutils binutils-final
2242 #:guile %bootstrap-guile
2243 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2244 #:guile-for-build %bootstrap-guile)))
2248 (package (inherit gcc-boot0)
2251 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2252 ;; "debug" output contains disallowed references, notably
2253 ;; linux-libre-headers. Disable the debugging output to work around that.
2254 (outputs (delete "debug" (package-outputs gcc-boot0)))
2257 `(#:guile ,%bootstrap-guile
2258 #:implicit-inputs? #f
2260 #:allowed-references ("out" "lib" ,zlib-final
2261 ,glibc-final ,static-bash-for-glibc)
2263 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2264 ;; reason, but it is not in their RUNPATH. This is a false
2265 ;; positive, so turn it off.
2266 #:validate-runpath? #f
2268 ,@(substitute-keyword-arguments (package-arguments gcc)
2269 ((#:make-flags flags)
2270 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2271 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2273 (if (string-prefix? "LDFLAGS=" flag)
2274 (string-append flag " -L"
2275 (assoc-ref %build-inputs "libstdc++")
2276 "/lib -L" zlib "/lib -Wl,-rpath="
2280 ;; Build again GMP & co. within GCC's build process, because it's hard
2281 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2282 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2284 `(modify-phases ,phases
2285 (add-after 'unpack 'unpack-gmp&co
2286 (lambda* (#:key inputs #:allow-other-keys)
2287 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2288 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2289 (mpc (assoc-ref %build-inputs "mpc-source")))
2291 ;; To reduce the set of pre-built bootstrap inputs, build
2292 ;; GMP & co. from GCC.
2293 (for-each (lambda (source)
2294 (invoke "tar" "xvf" source))
2295 (list gmp mpfr mpc))
2297 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2298 ,@(map (lambda (lib)
2299 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2301 `(symlink ,(string-trim-right
2302 (package-full-name lib "-")
2304 ,(package-name lib)))
2305 (list gmp-6.0 mpfr mpc))
2307 (add-before 'configure 'treat-glibc-as-system-header
2308 (lambda* (#:key inputs #:allow-other-keys)
2309 (let ((libc (assoc-ref inputs "libc")))
2310 ;; Make sure Glibc is treated as a "system header" so
2311 ;; #include_next does the right thing.
2312 (for-each (lambda (var)
2313 (setenv var (string-append libc "/include")))
2314 '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
2317 ;; This time we want Texinfo, so we get the manual. Add
2318 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2319 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2321 (native-inputs `(("texinfo" ,texinfo-boot0)
2322 ("perl" ,perl-boot0) ;for manpages
2323 ("static-bash" ,static-bash-for-glibc)
2324 ,@(package-native-inputs gcc-boot0)))
2326 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2327 ("mpfr-source" ,(package-source mpfr))
2328 ("mpc-source" ,(package-source mpc))
2329 ("ld-wrapper" ,(ld-wrapper-boot3))
2330 ("binutils" ,binutils-final)
2331 ("libstdc++" ,libstdc++)
2332 ("zlib" ,zlib-final)
2333 ,@(%boot2-inputs)))))
2335 (define (%boot3-inputs)
2336 ;; 4th stage inputs.
2337 `(("gcc" ,gcc-final)
2338 ("ld-wrapper" ,(ld-wrapper-boot3))
2339 ,@(alist-delete "gcc" (%boot2-inputs))))
2342 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2343 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2344 ;; on Readline and ncurses.
2345 (let ((bash (static-libgcc-package bash-minimal)))
2348 (source (bootstrap-origin (package-source bash)))
2349 (inputs (%boot3-inputs))
2351 `(#:implicit-inputs? #f
2352 #:guile ,%bootstrap-guile
2354 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2356 ,@(package-arguments bash))))))
2358 (define (%boot4-inputs)
2359 ;; Now use the final Bash.
2360 `(("bash" ,bash-final)
2361 ,@(alist-delete "bash" (%boot3-inputs))))
2364 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2366 (define-public guile-final
2367 ;; This package must be public because other modules refer to it. However,
2368 ;; mark it as hidden so that 'fold-packages' ignores it.
2369 (with-boot4 (hidden-package
2370 (package-with-bootstrap-guile guile-2.2/fixed))))
2372 (define glibc-utf8-locales-final
2373 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2374 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2375 ;; with the full range of Unicode codepoints (remember
2376 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2379 (inherit glibc-utf8-locales)
2381 `(("glibc" ,glibc-final)
2382 ("gzip" ,(with-boot4 gzip))))))
2384 (define-public ld-wrapper
2385 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2386 (make-ld-wrapper "ld-wrapper"
2387 #:binutils binutils-final
2391 (define (%boot5-inputs)
2392 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2393 ;; with an older libc, which cannot load the new locale format. See
2394 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2395 `(("locales" ,glibc-utf8-locales-final)
2399 (package-with-explicit-inputs %boot5-inputs))
2401 (define gnu-make-final
2402 ;; The final GNU Make, which uses the final Guile.
2403 (let ((pkg-config (package
2404 (inherit %pkg-config) ;the native pkg-config
2405 (inputs `(("guile" ,guile-final)
2408 `(#:implicit-inputs? #f
2409 ,@(package-arguments pkg-config))))))
2411 (inherit (package-with-bootstrap-guile gnu-make))
2412 (inputs `(("guile" ,guile-final)
2414 (native-inputs `(("pkg-config" ,pkg-config)))
2416 `(#:implicit-inputs? #f
2417 ,@(package-arguments gnu-make))))))
2420 (define coreutils-final
2421 ;; The final Coreutils. Treat them specially because some packages, such as
2422 ;; Findutils, keep a reference to the Coreutils they were built with.
2423 (with-boot5 (package-with-bootstrap-guile coreutils)
2424 ;; Use the final Guile, linked against the
2425 ;; final libc with working iconv, so that
2426 ;; 'substitute*' works well when touching
2427 ;; test files in Gettext.
2431 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2432 ;; built before gzip.
2433 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2434 (package/inherit grep
2435 (inputs (alist-delete "pcre" (package-inputs grep)))
2436 (native-inputs `(("perl" ,perl-boot0))))))
2438 (define (%boot6-inputs)
2439 ;; Now use the final Coreutils.
2440 `(("coreutils" ,coreutils-final)
2441 ("grep" ,grep-final)
2445 (package-with-explicit-inputs %boot6-inputs))
2449 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2450 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2452 (define-public %final-inputs
2453 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2454 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2455 ;; used for origins that have patches, thereby avoiding circular
2457 (let ((finalize (compose with-boot6
2458 package-with-bootstrap-guile)))
2459 `(,@(map (match-lambda
2461 (list name (finalize package))))
2467 ("diffutils" ,diffutils)
2469 ("findutils" ,findutils)
2472 ("grep" ,grep-final)
2473 ("coreutils" ,coreutils-final)
2474 ("make" ,gnu-make-final)
2475 ("bash" ,bash-final)
2476 ("ld-wrapper" ,ld-wrapper)
2477 ("binutils" ,binutils-final)
2479 ("libc" ,glibc-final)
2480 ("libc:static" ,glibc-final "static")
2481 ("locales" ,glibc-utf8-locales-final))))
2483 (define-public canonical-package
2484 (let ((name->package (fold (lambda (input result)
2486 ((_ package . outputs)
2487 (vhash-cons (package-full-name package)
2490 `(("guile" ,guile-final)
2493 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2494 the implicit inputs of 'gnu-build-system', return that one, otherwise return
2497 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
2498 COREUTILS-FINAL vs. COREUTILS, etc."
2499 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2500 ;; libunistring, GMP, etc.
2501 (match (vhash-assoc (package-full-name package) name->package)
2503 ;; In general we want CANON, except if we're cross-compiling: CANON
2504 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2505 ;; process, with dependencies on things that cannot be
2507 (if (%current-target-system)
2517 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2518 ;; instantiated like this:
2520 ;; (define-public gcc-glibc-2.27-toolchain
2521 ;; (make-gcc-toolchain gcc glibc-2.27))
2523 (define* (make-gcc-toolchain gcc
2526 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2527 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2528 (libc (if libc libc glibc-final)))
2530 (name (string-append (package-name gcc) "-toolchain"))
2531 (version (package-version gcc))
2533 (build-system trivial-build-system)
2535 '(#:modules ((guix build union))
2537 (use-modules (ice-9 match)
2541 (let ((out (assoc-ref %outputs "out")))
2543 (match %build-inputs
2544 (((names . directories) ...)
2545 (union-build out directories)))
2547 (union-build (assoc-ref %outputs "debug")
2548 (list (assoc-ref %build-inputs
2550 (union-build (assoc-ref %outputs "static")
2551 (list (assoc-ref %build-inputs
2555 (native-search-paths (package-native-search-paths gcc))
2556 (search-paths (package-search-paths gcc))
2558 (license (package-license gcc))
2559 (synopsis "Complete GCC tool chain for C/C++ development")
2561 "This package provides a complete GCC tool chain for C/C++ development to
2562 be installed in user profiles. This includes GCC, as well as libc (headers and
2563 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
2564 (home-page "https://gcc.gnu.org/")
2565 (outputs '("out" "debug" "static"))
2567 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2568 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2569 ;; before Binutils' ld in the user's profile.
2570 (inputs `(("gcc" ,gcc)
2571 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2572 ("binutils" ,binutils-final)
2574 ("libc-debug" ,libc "debug")
2575 ("libc-static" ,libc "static"))))))
2577 (define-public gcc-toolchain
2578 (make-gcc-toolchain gcc-final))
2580 (define-public gcc-toolchain-4.8
2581 (make-gcc-toolchain gcc-4.8))
2583 (define-public gcc-toolchain-4.9
2584 (make-gcc-toolchain gcc-4.9))
2586 (define-public gcc-toolchain-5
2587 (make-gcc-toolchain gcc-5))
2589 (define-public gcc-toolchain-6
2590 (make-gcc-toolchain gcc-6))
2592 (define-public gcc-toolchain-7
2595 (define-public gcc-toolchain-8
2596 (make-gcc-toolchain gcc-8))
2598 (define-public gcc-toolchain-9
2599 (make-gcc-toolchain gcc-9))
2601 ;; Provide the Fortran toolchain package only for the version of gfortran that
2602 ;; is used by Guix internally to build Fortran libraries, because combining
2603 ;; code compiled with different versions can cause problems.
2605 (define-public gfortran-toolchain
2606 (package (inherit (make-gcc-toolchain gfortran))
2607 (synopsis "Complete GCC tool chain for Fortran development")
2608 (description "This package provides a complete GCC tool chain for
2609 Fortran development to be installed in user profiles. This includes
2610 gfortran, as well as libc (headers and binaries, plus debugging symbols
2611 in the @code{debug} output), and binutils.")))
2614 ;;; commencement.scm ends here