gnu: commencement: Rationalize search path handling.
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
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>
10 ;;;
11 ;;; This file is part of GNU Guix.
12 ;;;
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.
17 ;;;
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.
22 ;;;
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/>.
25
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))
60
61 ;;; Commentary:
62 ;;;
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'.
68 ;;;
69 ;;; To avoid circular dependencies, this module should not be imported
70 ;;; directly from anywhere.
71 ;;;
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.
80 ;;;
81 ;;; Code:
82
83 (define mes-boot
84 (package
85 (inherit mes)
86 (name "mes-boot")
87 (version "0.19")
88 (source (origin
89 (method url-fetch)
90 (uri (string-append "mirror://gnu/mes/"
91 "mes-" version ".tar.gz"))
92 (sha256
93 (base32
94 "15h4yhaywdc0djpjlin2jz1kzahpqxfki0r0aav1qm9nxxmnp1l0"))))
95 (inputs '())
96 (propagated-inputs '())
97 (native-inputs
98 `(("mescc-tools" ,%bootstrap-mescc-tools)
99 ("nyacc-source" ,(bootstrap-origin
100 (package-source nyacc-0.86)))
101
102 ("coreutils" , %bootstrap-coreutils&co)
103 ("bootstrap-mes" ,%bootstrap-mes)))
104 (arguments
105 `(#:implicit-inputs? #f
106 #:guile ,%bootstrap-guile
107 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
108 #:phases
109 (modify-phases %standard-phases
110 (add-after 'unpack 'unpack-seeds
111 (lambda _
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"))
118 #t)))
119 (replace 'configure
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)))))
128 (replace 'build
129 (lambda _
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"))))
136 (replace 'check
137 (lambda _
138 (setenv "DIFF" "sh scripts/diff.scm")
139 ;; fail fast tests
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")))
143 (replace 'install
144 (lambda _
145 (invoke "sh" "install.sh"))))))
146 (native-search-paths
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")))))))
153
154 (define tcc-boot0
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")
162 (revision "6")
163 (commit "c004e9a34fb026bb44d211ab98bb768e79900eef"))
164 (package
165 (inherit tcc)
166 (name "tcc-boot0")
167 (version (string-append version "-" revision "." (string-take commit 7)))
168 (source (origin
169 (method url-fetch)
170 (uri (list (string-append "mirror://gnu/guix/mirror"
171 "/tinycc-" commit ".tar.gz")
172 (string-append "https://gitlab.com/janneke/tinycc"
173 "/-/archive/" commit
174 "/tinycc-" commit ".tar.gz")))
175 (sha256
176 (base32
177 "1hmzn1pq0x22ppd80hyrn5qzqq94mxd0ychzj6vrr2vnj2frjv5b"))))
178 (build-system gnu-build-system)
179 (supported-systems '("i686-linux" "x86_64-linux"))
180 (inputs '())
181 (propagated-inputs '())
182 (native-inputs
183 `(("mes" ,mes-boot)
184 ("mescc-tools" ,%bootstrap-mescc-tools)
185 ("nyacc-source" ,(bootstrap-origin
186 (package-source nyacc-0.86)))
187
188 ("coreutils" , %bootstrap-coreutils&co)
189 ("bootstrap-mes" ,%bootstrap-mes)))
190 (arguments
191 `(#:implicit-inputs? #f
192 #:guile ,%bootstrap-guile
193 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
194 #:phases
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
202 coreutils "/bin"))
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"
207 "-xvf" nyacc-source)
208 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
209 #t)))
210 (replace 'configure
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
223 coreutils "/bin"
224 ":" mes "/bin"
225 ":" mescc-tools "/bin"))
226 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
227
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")
235 (setenv "MES" "mes")
236 (setenv "GUILE_LOAD_PATH" "nyacc")
237 (invoke "sh" "configure"
238 "--prefix=$PREFIX"
239 (string-append "--elfinterp=" interpreter)
240 "--crtprefix=."
241 "--tccdir=."))))
242 (replace 'build
243 (lambda _
244 (substitute* "bootstrap.sh"
245 (("^ cmp") "# cmp"))
246 (invoke "sh" "bootstrap.sh")))
247 (replace 'check
248 (lambda _
249 (setenv "DIFF" "diff.scm")
250 (setenv "OBJDUMP" "true")
251 ;; fail fast tests
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")))
256 (replace 'install
257 (lambda _
258 (invoke "sh" "install.sh"))))))
259 (native-search-paths
260 (list (search-path-specification
261 (variable "C_INCLUDE_PATH")
262 (files '("include")))
263 (search-path-specification
264 (variable "LIBRARY_PATH")
265 (files '("lib"))))))))
266
267 (define tcc-boot
268 (package
269 (inherit tcc-boot0)
270 (name "tcc-boot")
271 (version "0.9.27")
272 (source (bootstrap-origin
273 (origin
274 (inherit (package-source tcc))
275 (patches (search-patches "tcc-boot-0.9.27.patch")))))
276 (build-system gnu-build-system)
277 (inputs '())
278 (propagated-inputs '())
279 (native-inputs
280 `(("mes" ,mes-boot)
281 ("tcc" ,tcc-boot0)
282
283 ("coreutils" , %bootstrap-coreutils&co)))
284 (arguments
285 `(#:implicit-inputs? #f
286 #:guile ,%bootstrap-guile
287
288 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
289 ;; with MesCC/M1/hex2-built binaries.
290 #:strip-binaries? #f
291
292 #:phases
293 (modify-phases %standard-phases
294 (replace 'configure
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"))))
305 ;; unpack
306 (setenv "PATH" (string-append
307 coreutils "/bin"
308 ":" tcc "/bin"))
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")))))
318 (replace 'build
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"))))
328 (invoke "tcc"
329 "-vvv"
330 "-D" "BOOTSTRAP=1"
331 "-D" "ONE_SOURCE=1"
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
338 "/lib:{B}/lib:.\"")
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\"")
343 "-o" "tcc"
344 "tcc.c"))))
345 (replace 'check
346 (lambda _
347 ;; FIXME: add sensible check target (without depending on make)
348 ;; ./check.sh ?
349 (= 1 (status:exit-val (system* "./tcc" "--help")))))
350 (replace 'install
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"))
366 #t))))))))
367
368 (define make-mesboot0
369 (package
370 (inherit gnu-make)
371 (name "make-mesboot0")
372 (version "3.80")
373 (source (origin
374 (method url-fetch)
375 (uri (string-append "mirror://gnu/make/make-"
376 version ".tar.gz"))
377 (sha256
378 (base32
379 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
380 (supported-systems '("i686-linux" "x86_64-linux"))
381 (inputs '())
382 (propagated-inputs '())
383 (native-inputs `(("tcc" ,tcc-boot)
384
385 ("bash" ,%bootstrap-coreutils&co)
386 ("coreutils" ,%bootstrap-coreutils&co)))
387 (arguments
388 `(#:implicit-inputs? #f
389 #:tests? #f ; check depends on perl
390 #:guile ,%bootstrap-guile
391 #:configure-flags `("CC=tcc -DO_RDONLY=0"
392 "LD=tcc"
393 "--disable-nls")
394 #:phases
395 (modify-phases %standard-phases
396 (add-after 'configure 'configure-fixup
397 (lambda _
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)))
403 #t))
404 (delete 'patch-generated-file-shebangs) ; no perl
405 (replace 'build
406 (lambda _
407 (invoke "sh" "./build.sh")))
408 (replace 'install
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)
413 #t))))))))
414
415 (define diffutils-mesboot
416 (package
417 (inherit diffutils)
418 (name "diffutils-mesboot")
419 (version "2.7")
420 (source (origin
421 (method url-fetch)
422 (uri (string-append "mirror://gnu/diffutils/diffutils-"
423 version ".tar.gz"))
424 (sha256
425 (base32
426 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
427 (supported-systems '("i686-linux" "x86_64-linux"))
428 (inputs '())
429 (propagated-inputs '())
430 (native-inputs `(("mes" ,mes-boot)
431 ("tcc" ,tcc-boot)
432
433 ("bash" ,%bootstrap-coreutils&co)
434 ("coreutils" ,%bootstrap-coreutils&co)
435 ("make" ,make-mesboot0)))
436 (arguments
437 `(#:implicit-inputs? #f
438 #:guile ,%bootstrap-guile
439 #:parallel-build? #f
440 #:tests? #f ; check is naive, also checks non-built PROGRAMS
441 #:strip-binaries? #f ; no strip yet
442 #:phases
443 (modify-phases %standard-phases
444 ;; diffutils-2.7 needs more traditional configure
445 (replace '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"))
450 (setenv "CC" "tcc")
451 (setenv "LD" "tcc")
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"))
457 #t)))))))
458
459 (define binutils-mesboot0
460 (package
461 (inherit binutils)
462 (name "binutils-mesboot0")
463 (version "2.20.1a")
464 (source (bootstrap-origin
465 (origin
466 (method url-fetch)
467 (uri (string-append "mirror://gnu/binutils/binutils-"
468 version ".tar.bz2"))
469 (patches (search-patches "binutils-boot-2.20.1a.patch"))
470 (sha256
471 (base32
472 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
473 (inputs '())
474 (propagated-inputs '())
475 (native-inputs `(("tcc" ,tcc-boot)
476
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"))
482 (arguments
483 `(#:implicit-inputs? #f
484 #:guile ,%bootstrap-guile
485 #:tests? #f ; runtest: command not found
486 #:parallel-build? #f
487 #:strip-binaries? #f ; no strip yet
488 #:configure-flags
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)
494 "AR=tcc -ar"
495 "CXX=false"
496 "RANLIB=true"
497 ,(string-append "CC=tcc" cppflags)
498 "--disable-nls"
499 "--disable-shared"
500 "--disable-werror"
501 "--build=i686-unknown-linux-gnu"
502 "--host=i686-unknown-linux-gnu"
503 "--with-sysroot=/"))))))
504
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".
511 (package
512 (inherit gcc)
513 (name "gcc-core-mesboot")
514 (version "2.95.3")
515 (source (bootstrap-origin
516 (origin
517 (method url-fetch)
518 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
519 version
520 ".tar.gz"))
521 (patches (search-patches "gcc-boot-2.95.3.patch"))
522 (sha256
523 (base32
524 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
525 (supported-systems '("i686-linux" "x86_64-linux"))
526 (inputs '())
527 (propagated-inputs '())
528 (native-inputs `(("binutils" ,binutils-mesboot0)
529 ("tcc" ,tcc-boot)
530
531 ("bash" ,%bootstrap-coreutils&co)
532 ("coreutils" ,%bootstrap-coreutils&co)
533 ("diffutils" ,diffutils-mesboot)
534 ("make" ,make-mesboot0)))
535 (outputs '("out"))
536 (arguments
537 `(#:implicit-inputs? #f
538 #:guile ,%bootstrap-guile
539 #:tests? #f
540 #:parallel-build? #f
541 #:strip-binaries? #f
542 #:configure-flags
543 (let ((out (assoc-ref %outputs "out")))
544 `("--enable-static"
545 "--disable-shared"
546 "--disable-werror"
547 "--build=i686-unknown-linux-gnu"
548 "--host=i686-unknown-linux-gnu"
549 ,(string-append "--prefix=" out)))
550 #:make-flags (list
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"
554 "AR=ar"
555 "RANLIB=ranlib"
556 (string-append "LIBGCC2_INCLUDES=-I "
557 (assoc-ref %build-inputs "tcc")
558 "/include")
559 "LANGUAGES=c"
560 (string-append "BOOT_LDFLAGS="
561 " -B" (assoc-ref %build-inputs "tcc")
562 "/lib/"))
563 #:modules ((guix build gnu-build-system)
564 (guix build utils)
565 (srfi srfi-1))
566 #:phases
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"
581 (lambda _
582 (display "
583 ac_cv_c_float_format='IEEE (little-endian)'
584 ")))
585 #t)))
586 (replace 'configure
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
592 (lambda _
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")))
603 (mkdir-p "tmp")
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)
616 #t))))))
617 (native-search-paths
618 (list (search-path-specification
619 (variable "C_INCLUDE_PATH")
620 (files '("include"
621
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")))))))
627
628 (define mesboot-headers
629 (package
630 (inherit mes-boot)
631 (name "mesboot-headers")
632 (supported-systems '("i686-linux" "x86_64-linux"))
633 (inputs '())
634 (propagated-inputs '())
635 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
636 ("headers" ,%bootstrap-linux-libre-headers)))
637 (arguments
638 `(#:implicit-inputs? #f
639 #:guile ,%bootstrap-guile
640 #:tests? #f
641 #:strip-binaries? #f
642 #:phases
643 (modify-phases %standard-phases
644 (delete 'configure)
645 (delete 'build)
646 (replace 'install
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" )))
651 (mkdir-p include)
652 (copy-recursively "include" out)
653 (copy-recursively headers out)
654 #t))))))))
655
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
659 ;; gcc.
660 (package
661 (inherit glibc)
662 (name "glibc-mesboot0")
663 (version "2.2.5")
664 (source (bootstrap-origin
665 (origin
666 (method url-fetch)
667 (uri (string-append "mirror://gnu/glibc/glibc-"
668 version
669 ".tar.gz"))
670 (patches (search-patches "glibc-boot-2.2.5.patch"))
671 (sha256
672 (base32
673 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
674 (supported-systems '("i686-linux" "x86_64-linux"))
675 (inputs '())
676 (propagated-inputs '())
677 (native-inputs `(("binutils" ,binutils-mesboot0)
678 ("gcc" ,gcc-core-mesboot)
679
680 ("bash" ,%bootstrap-coreutils&co)
681 ("coreutils" ,%bootstrap-coreutils&co)
682 ("diffutils" ,diffutils-mesboot)
683 ("headers" ,mesboot-headers)
684 ("make" ,make-mesboot0)))
685 (outputs '("out"))
686 (arguments
687 `(#:implicit-inputs? #f
688 #:guile ,%bootstrap-guile
689 #:tests? #f
690 #:strip-binaries? #f
691 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
692 #:make-flags (list (string-append
693 "SHELL="
694 (assoc-ref %build-inputs "bash")
695 "/bin/sh"))
696 #:configure-flags
697 (let ((out (assoc-ref %outputs "out"))
698 (headers (assoc-ref %build-inputs "headers")))
699 (list
700 "--disable-shared"
701 "--enable-static"
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"
707 "--without-__thread"
708 "--without-cvs"
709 "--without-gd"
710 "--without-tls"
711 (string-append "--prefix=" out)))
712 #:phases
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
721 ;;" -D __STDC__=1"
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))
729 #t)))
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
732 (replace 'configure
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))))))))
737
738 (define gcc-mesboot0
739 (package
740 (inherit gcc-core-mesboot)
741 (name "gcc-mesboot0")
742 (native-inputs `(("binutils" ,binutils-mesboot0)
743
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)
749
750 ("bash" ,%bootstrap-coreutils&co)
751 ("coreutils" ,%bootstrap-coreutils&co)
752 ("diffutils" ,diffutils-mesboot)
753 ("make" ,make-mesboot0)))
754 (arguments
755 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
756 ((#:phases phases)
757 `(modify-phases ,phases
758 (replace 'setenv
759 (lambda _
760 (setenv "CONFIG_SHELL" (which "sh"))
761 (with-output-to-file "config.cache"
762 (lambda _
763 (display "
764 ac_cv_c_float_format='IEEE (little-endian)'
765 ")))
766 #t))
767 (replace 'install2
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")))
772 (mkdir-p "tmp")
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"))
776 #t)))))
777 ((#:configure-flags configure-flags)
778 `(let ((out (assoc-ref %outputs "out")))
779 `("--disable-shared"
780 "--disable-werror"
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")))
786 `("RANLIB=true"
787 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
788 "LANGUAGES=c")))))))
789
790 (define binutils-mesboot
791 (package
792 (inherit binutils-mesboot0)
793 (name "binutils-mesboot")
794 (native-inputs `(("binutils" ,binutils-mesboot0)
795 ("libc" ,glibc-mesboot0)
796 ("gcc" ,gcc-mesboot0)
797
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)))
803 (arguments
804 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
805 ((#:configure-flags configure-flags)
806 '(list "--disable-nls"
807 "--disable-shared"
808 "--disable-werror"
809 "--build=i686-unknown-linux-gnu"
810 "--host=i686-unknown-linux-gnu"
811 "--with-sysroot=/"))))))
812
813 (define make-mesboot
814 (package
815 (inherit make-mesboot0)
816 (name "make-mesboot")
817 (version "3.82")
818 (source (origin
819 (method url-fetch)
820 (uri (string-append "mirror://gnu/make/make-"
821 version ".tar.gz"))
822 (sha256
823 (base32
824 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
825 (native-inputs `(("binutils" ,binutils-mesboot0)
826 ("libc" ,glibc-mesboot0)
827 ("gcc" ,gcc-mesboot0)
828 ("make" ,make-mesboot0)
829
830 ("bash" ,%bootstrap-coreutils&co)
831 ("coreutils" ,%bootstrap-coreutils&co)
832 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
833 (arguments
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))))
838 ((#:phases phases)
839 `(modify-phases ,phases
840 (delete 'configure-fixup)
841 (add-before 'configure 'setenv
842 (lambda _
843 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
844 #t))))))))
845
846 (define gmp-boot
847 (package
848 (inherit gmp)
849 (version "4.3.2")
850 (source (origin
851 (method url-fetch)
852 (uri (string-append "mirror://gnu/gmp/gmp-" version
853 ".tar.gz"))
854 (sha256 (base32
855 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
856
857 (define mpfr-boot
858 (package
859 (inherit mpfr)
860 (version "2.4.2")
861 (source (origin
862 (method url-fetch)
863 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
864 ".tar.gz"))
865 (sha256 (base32
866 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
867
868 (define mpc-boot
869 (package
870 (inherit mpc)
871 (version "1.0.3")
872 (source (origin
873 (method url-fetch)
874 (uri (string-append
875 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
876 (sha256
877 (base32
878 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
879
880 (define gcc-mesboot1
881 (package
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)
892
893 ("libc" ,glibc-mesboot0)
894 ("kernel-headers" ,%bootstrap-linux-libre-headers)
895 ("gcc" ,gcc-mesboot0)
896
897 ("bash" ,%bootstrap-coreutils&co)
898 ("coreutils" ,%bootstrap-coreutils&co)
899 ("diffutils" ,diffutils-mesboot)
900 ("make" ,make-mesboot)))
901 (arguments
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
906 "-B" libc "/lib "
907 "-Wl,-dynamic-linker "
908 "-Wl," libc
909 ,(glibc-dynamic-linker "i686-linux"))))
910 (list (string-append "LDFLAGS=" ldflags)
911 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
912 ((#:phases phases)
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")))
920
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"
926 source)))
927 (list gmp mpfr mpc))
928
929 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
930 ,@(map (lambda (lib)
931 ;; Drop trailing letters, as gmp-6.0.0a unpacks
932 ;; into gmp-6.0.0.
933 `(symlink ,(string-trim-right
934 (package-full-name lib "-")
935 char-set:letter)
936 ,(package-name lib)))
937 (list gmp-boot mpfr-boot mpc-boot))
938 #t)))
939 (delete 'remove-info)
940 (replace 'setenv
941 (lambda _
942 (setenv "CONFIG_SHELL" (which "sh"))
943
944 ;; Allow MPFR headers to be found.
945 (setenv "C_INCLUDE_PATH"
946 (string-append (getcwd) "/mpfr/src:"
947 (getenv "C_INCLUDE_PATH")))
948
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"))
952 #t))
953 (delete 'install2)))
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"
960
961 (string-append "--with-native-system-header-dir=" glibc "/include")
962 (string-append "--with-build-sysroot=" glibc "/include")
963
964 "--disable-bootstrap"
965 "--disable-decimal-float"
966 "--disable-libatomic"
967 "--disable-libcilkrts"
968 "--disable-libgomp"
969 "--disable-libitm"
970 "--disable-libmudflap"
971 "--disable-libquadmath"
972 "--disable-libsanitizer"
973 "--disable-libssp"
974 "--disable-libvtv"
975 "--disable-lto"
976 "--disable-lto-plugin"
977 "--disable-multilib"
978 "--disable-plugin"
979 "--disable-threads"
980 "--enable-languages=c,c++"
981
982 "--enable-static"
983 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
984 "--disable-shared"
985 "--enable-threads=single"
986
987 ;; No pre-compiled libstdc++ headers, to save space.
988 "--disable-libstdcxx-pch"
989
990 ;; for libcpp ...
991 "--disable-build-with-cxx")))))))
992
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.
997 (package
998 (inherit gcc-mesboot1)
999 (name "gcc-mesboot1-wrapper")
1000 (source #f)
1001 (inputs '())
1002 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1003 ("libc" ,glibc-mesboot)
1004 ("gcc" ,gcc-mesboot1)))
1005 (arguments
1006 `(#:implicit-inputs? #f
1007 #:guile ,%bootstrap-guile
1008 #:phases
1009 (modify-phases %standard-phases
1010 (delete 'unpack)
1011 (delete 'configure)
1012 (delete 'install)
1013 (replace 'build
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")))
1020 (mkdir-p bin)
1021 (for-each
1022 (lambda (program)
1023 (let ((wrapper (string-append bin "/" program)))
1024 (with-output-to-file wrapper
1025 (lambda _
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")
1031 " -Wl,--rpath"
1032 " -Wl," libc "/lib"
1033 " \"$@\"
1034 "))
1035 (chmod wrapper #o555)))))
1036 '(
1037 "gcc"
1038 "g++"
1039 "i686-unknown-linux-gnu-gcc"
1040 "i686-unknown-linux-gnu-g++"
1041 ))
1042 #t)))
1043 (replace 'check
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")))))))))
1049
1050 (define glibc-headers-mesboot
1051 (package
1052 (inherit glibc-mesboot0)
1053 (name "glibc-headers-mesboot")
1054 (version "2.16.0")
1055 (source (bootstrap-origin
1056 (origin
1057 (method url-fetch)
1058 (uri (string-append "mirror://gnu/glibc/glibc-"
1059 version
1060 ".tar.gz"))
1061 (patches (search-patches "glibc-boot-2.16.0.patch"
1062 "glibc-bootstrap-system-2.16.0.patch"))
1063 (sha256
1064 (base32
1065 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1066 (native-inputs `(("binutils" ,binutils-mesboot)
1067 ("libc" ,glibc-mesboot0)
1068 ("gcc" ,gcc-mesboot1)
1069 ("headers" ,mesboot-headers)
1070
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)))
1076
1077 (arguments
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")))
1082 (list
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"
1088 "--with-pthread"
1089 "--without-cvs"
1090 "--without-gd"
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")))
1096 ((#:phases phases)
1097 `(modify-phases ,phases
1098 (replace 'setenv
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"))
1111
1112 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1113 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1114
1115 ;; avoid -fstack-protector
1116 (setenv "libc_cv_ssp" "false")
1117 (substitute* "configure"
1118 (("/bin/pwd") "pwd"))
1119 #t)))
1120 (replace 'install
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)
1126 #t)))
1127 (replace 'configure
1128 (lambda* (#:key configure-flags #:allow-other-keys)
1129 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1130 (mkdir-p "build")
1131 (chdir "build")
1132 (apply invoke "../configure" configure-flags)))
1133 (add-after 'configure 'remove-sunrpc
1134 (lambda _
1135 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1136 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1137 (substitute* "sysd-sorted"
1138 ((" sunrpc") " ")
1139 ((" nis") " "))
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"))))))))))))
1147
1148 (define glibc-mesboot
1149 (package
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)
1156
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)))
1162
1163 (arguments
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"))))
1169 ((#:phases phases)
1170 `(modify-phases ,phases
1171 (replace 'install
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)
1178 #t))))))))))
1179
1180 (define gcc-mesboot
1181 (package
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)
1187
1188 ("libc" ,glibc-mesboot)
1189 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1190 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1191 ("gcc" ,gcc-mesboot1)
1192
1193 ("bash" ,%bootstrap-coreutils&co)
1194 ("coreutils" ,%bootstrap-coreutils&co)
1195 ("diffutils" ,diffutils-mesboot)
1196 ("make" ,make-mesboot)))
1197 (arguments
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"
1206
1207 "--with-host-libstdcxx=-lsupc++"
1208
1209 (string-append "--with-native-system-header-dir=" glibc "/include")
1210 (string-append "--with-build-sysroot=" glibc "/include")
1211
1212 "--disable-bootstrap"
1213 "--disable-decimal-float"
1214 "--disable-libatomic"
1215 "--disable-libcilkrts"
1216 "--disable-libgomp"
1217 "--disable-libitm"
1218 "--disable-libmudflap"
1219 "--disable-libquadmath"
1220 "--disable-libsanitizer"
1221 "--disable-libssp"
1222 "--disable-libvtv"
1223 "--disable-lto"
1224 "--disable-lto-plugin"
1225 "--disable-multilib"
1226 "--disable-plugin"
1227 "--disable-threads"
1228 "--enable-languages=c,c++"
1229
1230 "--enable-static"
1231 "--enable-shared"
1232 "--enable-threads=single"
1233
1234 ;; No pre-compiled libstdc++ headers, to save space.
1235 "--disable-libstdcxx-pch"
1236
1237 ;; for libcpp ...
1238 "--disable-build-with-cxx"))))))))
1239
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.
1243 (package
1244 (inherit gcc-mesboot1-wrapper)
1245 (name "gcc-mesboot-wrapper")
1246 (version (package-version gcc-mesboot))
1247 (source #f)
1248 (inputs '())
1249 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1250 ("libc" ,glibc-mesboot)
1251 ("gcc" ,gcc-mesboot)))))
1252
1253 (define m4-mesboot
1254 (package
1255 (inherit m4)
1256 (name "m4-mesboot")
1257 (version "1.4")
1258 (source (origin
1259 (method url-fetch)
1260 (uri (string-append "mirror://gnu/m4/m4-"
1261 version ".tar.gz"))
1262 (sha256
1263 (base32
1264 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1265 (supported-systems '("i686-linux" "x86_64-linux"))
1266 (native-inputs `(("mes" ,mes-boot)
1267 ("tcc" ,tcc-boot)))
1268 (arguments
1269 `(#:phases
1270 (modify-phases %standard-phases
1271 (replace 'configure
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")
1276 "/bin/sh"))
1277 (setenv "CC" "tcc -static")
1278 (setenv "CPP" "tcc -E")
1279 (invoke "./configure" (string-append "--prefix=" out))))))))))
1280
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"))))
1292 (_
1293 (%bootstrap-inputs))))
1294
1295 (define gnu-make-boot0
1296 (package
1297 (inherit gnu-make)
1298 (source (bootstrap-origin (package-source gnu-make)))
1299 (name "make-boot0")
1300 (arguments
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
1308 ;; around it.
1309 `(cons "--disable-dependency-tracking" ,flags))
1310 ((#:phases phases)
1311 `(modify-phases ,phases
1312 (replace 'build
1313 (lambda _
1314 (invoke "./build.sh")))
1315 (replace 'install
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)
1320 #t))))))))
1321 (native-inputs '()) ; no need for 'pkg-config'
1322 (inputs (%bootstrap-inputs+toolchain))))
1323
1324 (define diffutils-boot0
1325 (package
1326 (inherit diffutils)
1327 (name "diffutils-boot0")
1328 (native-inputs `())
1329 (inputs
1330 `(("make" ,gnu-make-boot0)
1331 ,@(%bootstrap-inputs+toolchain)))
1332 (arguments
1333 `(#:tests? #f ; the test suite needs diffutils
1334 #:guile ,%bootstrap-guile
1335 #:implicit-inputs? #f
1336 ,@(package-arguments diffutils)))))
1337
1338 (define findutils-boot0
1339 (package
1340 (inherit findutils)
1341 (name "findutils-boot0")
1342 (source (bootstrap-origin (package-source findutils)))
1343 (inputs
1344 `(("make" ,gnu-make-boot0)
1345 ("diffutils" ,diffutils-boot0) ; for tests
1346 ,@(%bootstrap-inputs+toolchain)))
1347 (arguments
1348 `(#:implicit-inputs? #f
1349 #:guile ,%bootstrap-guile
1350
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"
1357 ,flags)))
1358 (package-arguments findutils))))))
1359
1360 (define file-boot0
1361 (package
1362 (inherit file)
1363 (source (bootstrap-origin (package-source file)))
1364 (name "file-boot0")
1365 (inputs
1366 `(("make" ,gnu-make-boot0)
1367 ,@(%bootstrap-inputs+toolchain)))
1368 (arguments
1369 `(#:implicit-inputs? #f
1370 #:guile ,%bootstrap-guile
1371 #:strip-binaries? #f
1372 #:validate-runpath? #f))))
1373
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)))
1380
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"))
1385
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.
1391
1392 (define binutils-boot0
1393 (package
1394 (inherit binutils)
1395 (source (bootstrap-origin (package-source binutils)))
1396 (name "binutils-cross-boot0")
1397 (arguments
1398 `(#:guile ,%bootstrap-guile
1399 #:implicit-inputs? #f
1400
1401 #:modules ((guix build gnu-build-system)
1402 (guix build utils)
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?)))
1419 #t))))
1420
1421 ,@(substitute-keyword-arguments (package-arguments binutils)
1422 ((#:configure-flags cf)
1423 `(cons ,(string-append "--target=" (boot-triplet))
1424 ,cf)))))
1425 (inputs (%boot0-inputs))))
1426
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)))
1433 (package
1434 (inherit lib)
1435 (source (bootstrap-origin (package-source lib)))
1436 (name "libstdc++-boot0")
1437 (arguments
1438 `(#:guile ,%bootstrap-guile
1439 #:implicit-inputs? #f
1440
1441 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1442 #:validate-runpath? #f
1443
1444 ,@(match (%current-system)
1445 ((or "i686-linux" "x86_64-linux")
1446 (substitute-keyword-arguments (package-arguments lib)
1447 ((#:phases phases)
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.
1452 (lambda _
1453 (substitute* "libstdc++-v3/configure"
1454 (("g\\+\\+ -v") "true"))
1455 #t))))))
1456 (_ (package-arguments lib)))))
1457 (inputs (%boot0-inputs))
1458 (native-inputs '()))))
1459
1460 (define gcc-boot0
1461 (package
1462 (inherit gcc)
1463 (name "gcc-cross-boot0")
1464 (source (bootstrap-origin (package-source gcc)))
1465 (arguments
1466 `(#:guile ,%bootstrap-guile
1467 #:implicit-inputs? #f
1468 #:modules ((guix build gnu-build-system)
1469 (guix build utils)
1470 (ice-9 regex)
1471 (srfi srfi-1)
1472 (srfi srfi-26))
1473 ,@(substitute-keyword-arguments (package-arguments gcc)
1474 ((#:configure-flags flags)
1475 `(append (list ,(string-append "--target=" (boot-triplet))
1476
1477 ;; No libc yet.
1478 "--without-headers"
1479
1480 ;; Disable features not needed at this stage.
1481 "--disable-shared"
1482 "--enable-languages=c,c++"
1483
1484 ;; libstdc++ cannot be built at this stage
1485 ;; ("Link tests are not allowed after
1486 ;; GCC_NO_EXECUTABLES.").
1487 "--disable-libstdc++-v3"
1488
1489 "--disable-threads"
1490 "--disable-libmudflap"
1491 "--disable-libatomic"
1492 "--disable-libsanitizer"
1493 "--disable-libitm"
1494 "--disable-libgomp"
1495 "--disable-libmpx"
1496 "--disable-libcilkrts"
1497 "--disable-libvtv"
1498 "--disable-libssp"
1499 "--disable-libquadmath"
1500 "--disable-decimal-float")
1501 (remove (cut string-match
1502 "--(with-system-zlib|enable-languages.*)" <>)
1503 ,flags)))
1504 ((#:make-flags flags)
1505 `(let* ((libc (assoc-ref %build-inputs "libc"))
1506 (libc-native (or (assoc-ref %build-inputs "libc-native")
1507 libc)))
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))))))))
1515 ((#:phases phases)
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")))
1522
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))
1528
1529 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1530 ,@(map (lambda (lib)
1531 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1532 ;; into gmp-6.0.0.
1533 `(symlink ,(string-trim-right
1534 (package-full-name lib "-")
1535 char-set:letter)
1536 ,(package-name lib)))
1537 (list gmp-6.0 mpfr mpc))
1538 #t)))
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"
1546 (("la_LDFLAGS =")
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"))
1552 #t)))
1553 (_ '(add-before 'configure 'return-true
1554 (lambda _ #t))))
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
1559 ;; it.
1560 (with-directory-excursion
1561 (string-append out "/lib/gcc/"
1562 ,(boot-triplet)
1563 "/" ,(package-version gcc))
1564 (symlink "libgcc.a" "libgcc_eh.a"))
1565 #t))))))))
1566
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)
1571
1572 ;; The libstdc++ that libcc1 links against.
1573 ("libstdc++" ,libstdc++-boot0)
1574
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))))
1579
1580 ;; No need for the native-inputs to build the documentation at this stage.
1581 (native-inputs `())))
1582
1583 (define perl-boot0
1584 (package
1585 (inherit perl)
1586 (name "perl-boot0")
1587 (source (bootstrap-origin (package-source perl)))
1588 (inputs (%boot0-inputs))
1589 (arguments
1590 `(#:implicit-inputs? #f
1591 #:guile ,%bootstrap-guile
1592 #:validate-runpath? #f
1593
1594 ;; At the very least, this must not depend on GCC & co.
1595 #:disallowed-references ,(list %bootstrap-binutils)
1596
1597 ,@(substitute-keyword-arguments (package-arguments perl)
1598 ((#:phases phases)
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
1603 (lambda _
1604 (substitute* "Configure"
1605 (("^libswanted=(.*)pthread" _ before)
1606 (string-append "libswanted=" before)))
1607 #t))))
1608 ;; Do not configure with '-Dusethreads' since pthread
1609 ;; support is missing.
1610 ((#:configure-flags configure-flags)
1611 `(delete "-Dusethreads" ,configure-flags)))))))
1612
1613 (define m4-boot0
1614 (package
1615 (inherit m4)
1616 (name "m4-boot0")
1617 (source (bootstrap-origin (package-source m4)))
1618 (inputs (%boot0-inputs))
1619 (arguments
1620 `(#:guile ,%bootstrap-guile
1621 #:implicit-inputs? #f
1622 ,@(package-arguments m4)))))
1623
1624 (define bison-boot0
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.
1627 (package
1628 (inherit bison)
1629 (name "bison-boot0")
1630 (propagated-inputs `(("m4" ,m4-boot0)))
1631 (native-inputs `(("perl" ,perl-boot0)))
1632 (inputs (%boot0-inputs)) ;remove Flex...
1633 (arguments
1634 `(#:tests? #f ;... and thus disable tests
1635 #:implicit-inputs? #f
1636 #:guile ,%bootstrap-guile
1637
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")
1645 "RANLIB=ranlib")
1646 (_
1647 "RANLIB=ranlib -D"))
1648 "V=1")
1649
1650 ,@(package-arguments bison)))))
1651
1652 (define flex-boot0
1653 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
1654 (package
1655 (inherit flex)
1656 (native-inputs `(("bison" ,bison-boot0)))
1657 (propagated-inputs `(("m4" ,m4-boot0)))
1658 (inputs (%boot0-inputs))
1659 (arguments
1660 `(#:implicit-inputs? #f
1661 #:guile ,%bootstrap-guile
1662 #:tests? #f))))
1663
1664 (define linux-libre-headers-boot0
1665 (mlambda ()
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>.
1671 (package
1672 (inherit linux-libre-headers)
1673 (arguments
1674 `(#:guile ,%bootstrap-guile
1675 #:implicit-inputs? #f
1676 ,@(package-arguments linux-libre-headers)))
1677 (native-inputs
1678 `(("perl" ,perl-boot0)
1679
1680 ;; Flex and Bison are required since version 4.16.
1681 ("flex" ,flex-boot0)
1682 ("bison" ,bison-boot0)
1683 ,@(%boot0-inputs))))))
1684
1685 (define with-boot0
1686 (package-with-explicit-inputs %boot0-inputs
1687 %bootstrap-guile))
1688
1689 (define gnumach-headers-boot0
1690 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
1691
1692 (define mig-boot0
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)))
1698 (arguments
1699 `(#:configure-flags
1700 `(,(string-append "LDFLAGS=-Wl,-rpath="
1701 (assoc-ref %build-inputs "flex") "/lib/")))))))
1702 (with-boot0 mig)))
1703
1704 (define hurd-headers-boot0
1705 (let ((hurd-headers (package (inherit hurd-headers)
1706 (native-inputs `(("mig" ,mig-boot0)))
1707 (inputs '()))))
1708 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
1709
1710 (define hurd-minimal-boot0
1711 (let ((hurd-minimal (package (inherit hurd-minimal)
1712 (native-inputs `(("mig" ,mig-boot0)))
1713 (inputs '()))))
1714 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
1715
1716 (define hurd-core-headers-boot0
1717 (mlambda ()
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)))
1723 (inputs
1724 `(("gnumach-headers" ,gnumach-headers-boot0)
1725 ("hurd-headers" ,hurd-headers-boot0)
1726 ("hurd-minimal" ,hurd-minimal-boot0)
1727 ,@(%boot0-inputs))))))
1728
1729 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
1730 (match system
1731 ("i586-gnu" (hurd-core-headers-boot0))
1732 (_ (linux-libre-headers-boot0))))
1733
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.
1739 (package
1740 (inherit texinfo)
1741 (native-inputs '())
1742 (inputs `(,@(%boot0-inputs)
1743 ("perl" ,perl-boot0)))
1744 (arguments
1745 `(#:implicit-inputs? #f
1746 #:guile ,%bootstrap-guile
1747
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.
1751 #:tests? #f))))
1752
1753 (define expat-sans-tests
1754 (package
1755 (inherit expat)
1756 (inputs (%boot0-inputs))
1757 (arguments
1758 ;; XXX: Linking 'runtestscpp' fails with things like:
1759 ;;
1760 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
1761 ;;
1762 ;; Skip tests altogether.
1763 `(#:implicit-inputs? #f
1764 #:guile ,%bootstrap-guile
1765
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))))))
1772
1773 (define python-boot0
1774 (package
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.
1780 (version "3.5.9")
1781 (source (bootstrap-origin
1782 (origin
1783 (method url-fetch)
1784 (uri (string-append "https://www.python.org/ftp/python/"
1785 version "/Python-" version ".tar.xz"))
1786 (sha256
1787 (base32
1788 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
1789 (modules '((guix build utils)))
1790 (snippet
1791 '(begin
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"))
1797 #t)))))
1798 (inputs
1799 `(,@(%boot0-inputs)
1800 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
1801 (native-inputs '()) ;and pkg-config
1802 (arguments
1803 `(#:implicit-inputs? #f
1804 #:guile ,%bootstrap-guile
1805
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 _ ''()) ''())
1814 ((#:phases phases)
1815 `(modify-phases ,phases
1816 (add-before 'configure 'disable-modules
1817 (lambda _
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.
1823 (("'linux', ") ""))
1824 #t))
1825 (delete 'set-TZDIR)))
1826 ((#:tests? _ #f) #f))))))
1827
1828 (define ld-wrapper-boot0
1829 (mlambda ()
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)))
1838
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))))
1845
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
1850 ;; bootstrap Bash.
1851 (package
1852 (inherit glibc)
1853 (name "glibc-intermediate")
1854 (source (bootstrap-origin (package-source glibc)))
1855 (arguments
1856 `(#:guile ,%bootstrap-guile
1857 #:implicit-inputs? #f
1858
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)))
1864 ,flags))
1865 ((#:phases phases)
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"))
1871 (unsetenv "CPATH")
1872
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"))))
1880 '())
1881
1882 ;; 'rpcgen' needs native libc headers to be built.
1883 (substitute* "sunrpc/Makefile"
1884 (("sunrpc-CPPFLAGS =.*" all)
1885 (string-append "CPATH = $(NATIVE_CPATH)\n"
1886 "export CPATH\n"
1887 all "\n")))
1888 #t)))))))
1889 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
1890 (native-inputs
1891 `(("bison" ,bison-boot0)
1892 ("texinfo" ,texinfo-boot0)
1893 ("perl" ,perl-boot0)
1894 ("python" ,python-boot0)))
1895 (inputs
1896 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
1897 ;; it in $CPATH, hence the 'pre-configure' phase above.
1898 ,@(%boot1-inputs)
1899
1900 ;; A native MiG is needed to build Glibc on Hurd.
1901 ,@(if (hurd-triplet? (%current-system))
1902 `(("mig" ,mig-boot0))
1903 '())
1904
1905 ;; A native GCC is needed to build `cross-rpcgen'.
1906 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
1907
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"))))))
1911
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"))
1917 (source #f)
1918 (build-system trivial-build-system)
1919 (outputs '("out"))
1920 (arguments
1921 `(#:guile ,%bootstrap-guile
1922 #:modules ((guix build utils))
1923 #:builder (begin
1924 (use-modules (guix build utils))
1925
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
1938 (lambda (p)
1939 (format p "#!~a/bin/bash
1940 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
1941 bash
1942 gcc triplet program
1943 libc libc
1944 ,(glibc-dynamic-linker))))
1945
1946 (chmod program #o555))
1947
1948 (mkdir-p bindir)
1949 (with-directory-excursion bindir
1950 (for-each (lambda (tool)
1951 (symlink (string-append binutils "/bin/"
1952 triplet "-" tool)
1953 tool))
1954 '("ar" "ranlib"))
1955 (for-each wrap-program '("gcc" "g++")))
1956
1957 #t))))
1958 (native-inputs
1959 `(("binutils" ,binutils)
1960 ("gcc" ,gcc)
1961 ("libc" ,glibc)
1962 ("bash" ,bash)))
1963 (inputs '())))
1964
1965 (define gcc-boot0-intermediate-wrapped
1966 (mlambda ()
1967 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
1968 ;; non-cross names.
1969 (cross-gcc-wrapper gcc-boot0 binutils-boot0
1970 glibc-final-with-bootstrap-bash
1971 (car (assoc-ref (%boot1-inputs) "bash")))))
1972
1973 (define static-bash-for-glibc
1974 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
1975 (package
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)
1982 '("gcc" "libc"))))
1983 (arguments
1984 `(#:implicit-inputs? #f
1985 #:guile ,%bootstrap-guile
1986
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.
1991 `(append ,flags
1992 (list (string-append "LDFLAGS=-static -L"
1993 (assoc-ref %build-inputs
1994 "libc:static")
1995 "/lib")))))))))
1996
1997 (define gettext-boot0
1998 ;; A minimal gettext used during bootstrap.
1999 (package
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")
2005 (source (origin
2006 (method url-fetch)
2007 (uri (string-append "mirror://gnu/gettext/gettext-"
2008 version ".tar.gz"))
2009 (sha256
2010 (base32
2011 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2012 (inputs (%boot1-inputs)) ;zero dependencies
2013 (arguments
2014 `(#:implicit-inputs? #f
2015 #:guile ,%bootstrap-guile
2016 #:tests? #f
2017 #:phases (modify-phases %standard-phases
2018 ;; Build only the tools.
2019 (add-after 'unpack 'chdir
2020 (lambda _
2021 (chdir "gettext-tools")
2022 #t))
2023
2024 ;; Some test programs require pthreads, which we don't have.
2025 (add-before 'configure 'no-test-programs
2026 (lambda _
2027 (substitute* "tests/Makefile.in"
2028 (("^PROGRAMS =.*$")
2029 "PROGRAMS =\n"))
2030 #t)))))))
2031
2032 (define glibc-final
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.
2035 (package/inherit
2036 glibc
2037 (name "glibc")
2038 (source (bootstrap-origin (package-source glibc)))
2039 (inputs `(("static-bash" ,static-bash-for-glibc)
2040 ,@(alist-delete
2041 "static-bash"
2042 (package-inputs glibc-final-with-bootstrap-bash))))
2043
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)))
2047
2048 (propagated-inputs
2049 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2050
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.
2054 (arguments
2055 `(#:allowed-references
2056 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2057 static-bash-for-glibc
2058 (package-outputs glibc-final-with-bootstrap-bash))
2059
2060 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2061
2062 (define gcc-boot0-wrapped
2063 (mlambda ()
2064 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2065 ;; non-cross names.
2066 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2067 (car (assoc-ref (%boot1-inputs) "bash")))))
2068
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"))))
2075
2076 (define binutils-final
2077 (package
2078 (inherit binutils)
2079 (source (bootstrap-origin (package-source binutils)))
2080 (arguments
2081 `(#:guile ,%bootstrap-guile
2082 #:implicit-inputs? #f
2083 #:allowed-references ("out" ,glibc-final)
2084 ,@(package-arguments binutils)))
2085 (inputs (%boot2-inputs))))
2086
2087 (define libstdc++
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)))
2091 (package
2092 (inherit lib)
2093 (source (bootstrap-origin (package-source lib)))
2094 (arguments
2095 `(#:guile ,%bootstrap-guile
2096 #:implicit-inputs? #f
2097 #:allowed-references ("out")
2098
2099 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2100 #:validate-runpath? #f
2101
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")
2111 "/include"))))
2112 (outputs '("out"))
2113 (inputs (%boot2-inputs))
2114 (synopsis "GNU C++ standard library (intermediate)"))))
2115
2116 (define zlib-final
2117 ;; Zlib used by GCC-FINAL.
2118 (package
2119 (inherit zlib)
2120 (arguments
2121 `(#:guile ,%bootstrap-guile
2122 #:implicit-inputs? #f
2123 #:allowed-references ("out" ,glibc-final)
2124 ,@(package-arguments zlib)))
2125 (inputs (%boot2-inputs))))
2126
2127 (define ld-wrapper-boot3
2128 (mlambda ()
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)))
2135
2136 (define gcc-final
2137 ;; The final GCC.
2138 (package (inherit gcc-boot0)
2139 (name "gcc")
2140
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)))
2145
2146 (arguments
2147 `(#:guile ,%bootstrap-guile
2148 #:implicit-inputs? #f
2149
2150 #:allowed-references ("out" "lib" ,zlib-final
2151 ,glibc-final ,static-bash-for-glibc)
2152
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
2157
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")))
2162 (map (lambda (flag)
2163 (if (string-prefix? "LDFLAGS=" flag)
2164 (string-append flag " -L"
2165 (assoc-ref %build-inputs "libstdc++")
2166 "/lib -L" zlib "/lib -Wl,-rpath="
2167 zlib "/lib")
2168 flag))
2169 ,flags)))
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'.)
2173 ((#:phases phases)
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")))
2180
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))
2186
2187 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2188 ,@(map (lambda (lib)
2189 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2190 ;; into gmp-6.0.0.
2191 `(symlink ,(string-trim-right
2192 (package-full-name lib "-")
2193 char-set:letter)
2194 ,(package-name lib)))
2195 (list gmp-6.0 mpfr mpc))
2196 #t)))
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"))
2205 #t))))))))
2206
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
2210 ;; scripts?).
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)))
2215
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)))))
2224
2225 (define (%boot3-inputs)
2226 ;; 4th stage inputs.
2227 `(("gcc" ,gcc-final)
2228 ("ld-wrapper" ,(ld-wrapper-boot3))
2229 ,@(alist-delete "gcc" (%boot2-inputs))))
2230
2231 (define bash-final
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)))
2236 (package
2237 (inherit bash)
2238 (source (bootstrap-origin (package-source bash)))
2239 (inputs (%boot3-inputs))
2240 (arguments
2241 `(#:implicit-inputs? #f
2242 #:guile ,%bootstrap-guile
2243
2244 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2245
2246 ,@(package-arguments bash))))))
2247
2248 (define (%boot4-inputs)
2249 ;; Now use the final Bash.
2250 `(("bash" ,bash-final)
2251 ,@(alist-delete "bash" (%boot3-inputs))))
2252
2253 (define with-boot4
2254 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2255
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))))
2261
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
2267 ;; function.)
2268 (package
2269 (inherit glibc-utf8-locales)
2270 (native-inputs
2271 `(("glibc" ,glibc-final)
2272 ("gzip" ,(with-boot4 gzip))))))
2273
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
2278 #:guile guile-final
2279 #:bash bash-final))
2280
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)
2286 ,@(%boot4-inputs)))
2287
2288 (define with-boot5
2289 (package-with-explicit-inputs %boot5-inputs))
2290
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)
2296 ,@(%boot5-inputs)))
2297 (arguments
2298 `(#:implicit-inputs? #f
2299 ,@(package-arguments pkg-config))))))
2300 (package
2301 (inherit (package-with-bootstrap-guile gnu-make))
2302 (inputs `(("guile" ,guile-final)
2303 ,@(%boot5-inputs)))
2304 (native-inputs `(("pkg-config" ,pkg-config)))
2305 (arguments
2306 `(#:implicit-inputs? #f
2307 ,@(package-arguments gnu-make))))))
2308
2309
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.
2318 ))
2319
2320 (define grep-final
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))))))
2327
2328 (define (%boot6-inputs)
2329 ;; Now use the final Coreutils.
2330 `(("coreutils" ,coreutils-final)
2331 ("grep" ,grep-final)
2332 ,@(%boot5-inputs)))
2333
2334 (define with-boot6
2335 (package-with-explicit-inputs %boot6-inputs))
2336
2337 (define sed-final
2338 ;; The final sed.
2339 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2340 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2341
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
2346 ;; dependencies.
2347 (let ((finalize (compose with-boot6
2348 package-with-bootstrap-guile)))
2349 `(,@(map (match-lambda
2350 ((name package)
2351 (list name (finalize package))))
2352 `(("tar" ,tar)
2353 ("gzip" ,gzip)
2354 ("bzip2" ,bzip2)
2355 ("xz" ,xz)
2356 ("file" ,file)
2357 ("diffutils" ,diffutils)
2358 ("patch" ,patch)
2359 ("findutils" ,findutils)
2360 ("gawk" ,gawk)))
2361 ("sed" ,sed-final)
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)
2368 ("gcc" ,gcc-final)
2369 ("libc" ,glibc-final)
2370 ("libc:static" ,glibc-final "static")
2371 ("locales" ,glibc-utf8-locales-final))))
2372
2373 (define-public canonical-package
2374 (let ((name->package (fold (lambda (input result)
2375 (match input
2376 ((_ package . outputs)
2377 (vhash-cons (package-full-name package)
2378 package result))))
2379 vlist-null
2380 `(("guile" ,guile-final)
2381 ,@%final-inputs))))
2382 (lambda (package)
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
2385 PACKAGE.
2386
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)
2392 ((_ . canon)
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
2396 ;; cross-compiled.
2397 (if (%current-target-system)
2398 package
2399 canon))
2400 (_ package)))))
2401
2402 \f
2403 ;;;
2404 ;;; GCC toolchain.
2405 ;;;
2406
2407 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2408 ;; instantiated like this:
2409 ;;
2410 ;; (define-public gcc-glibc-2.27-toolchain
2411 ;; (make-gcc-toolchain gcc glibc-2.27))
2412
2413 (define* (make-gcc-toolchain gcc
2414 #:optional
2415 (libc #f))
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)))
2419 (package
2420 (name (string-append (package-name gcc) "-toolchain"))
2421 (version (package-version gcc))
2422 (source #f)
2423 (build-system trivial-build-system)
2424 (arguments
2425 '(#:modules ((guix build union))
2426 #:builder (begin
2427 (use-modules (ice-9 match)
2428 (srfi srfi-26)
2429 (guix build union))
2430
2431 (let ((out (assoc-ref %outputs "out")))
2432
2433 (match %build-inputs
2434 (((names . directories) ...)
2435 (union-build out directories)))
2436
2437 (union-build (assoc-ref %outputs "debug")
2438 (list (assoc-ref %build-inputs
2439 "libc-debug")))
2440 (union-build (assoc-ref %outputs "static")
2441 (list (assoc-ref %build-inputs
2442 "libc-static")))
2443 #t))))
2444
2445 (native-search-paths (package-native-search-paths gcc))
2446 (search-paths (package-search-paths gcc))
2447
2448 (license (package-license gcc))
2449 (synopsis "Complete GCC tool chain for C/C++ development")
2450 (description
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"))
2456
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)
2463 ("libc" ,libc)
2464 ("libc-debug" ,libc "debug")
2465 ("libc-static" ,libc "static"))))))
2466
2467 (define-public gcc-toolchain
2468 (make-gcc-toolchain gcc-final))
2469
2470 (define-public gcc-toolchain-4.8
2471 (make-gcc-toolchain gcc-4.8))
2472
2473 (define-public gcc-toolchain-4.9
2474 (make-gcc-toolchain gcc-4.9))
2475
2476 (define-public gcc-toolchain-5
2477 (make-gcc-toolchain gcc-5))
2478
2479 (define-public gcc-toolchain-6
2480 (make-gcc-toolchain gcc-6))
2481
2482 (define-public gcc-toolchain-7
2483 gcc-toolchain)
2484
2485 (define-public gcc-toolchain-8
2486 (make-gcc-toolchain gcc-8))
2487
2488 (define-public gcc-toolchain-9
2489 (make-gcc-toolchain gcc-9))
2490
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.
2494
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.")))
2502
2503
2504 ;;; commencement.scm ends here