gnu: commencement: Add gash-core-utils-boot.
[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, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
9 ;;; Copyright © 2019, 2020 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 shells)
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages pkg-config)
50 #:use-module (gnu packages rsync)
51 #:use-module (gnu packages xml)
52 #:use-module (guix packages)
53 #:use-module (guix download)
54 #:use-module (guix build-system gnu)
55 #:use-module (guix build-system guile)
56 #:use-module (guix build-system trivial)
57 #:use-module (guix memoization)
58 #:use-module (guix utils)
59 #:use-module (srfi srfi-1)
60 #:use-module (ice-9 vlist)
61 #:use-module (ice-9 match)
62 #:export (make-gcc-toolchain))
63
64 ;;; Commentary:
65 ;;;
66 ;;; This is the commencement, this is where things start. Before the
67 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
68 ;;; with the initial binaries. This module uses those bootstrap binaries to
69 ;;; actually build up the whole tool chain that make up the implicit inputs of
70 ;;; 'gnu-build-system'.
71 ;;;
72 ;;; To avoid circular dependencies, this module should not be imported
73 ;;; directly from anywhere.
74 ;;;
75 ;;; Below, we frequently use "inherit" to create modified packages. The
76 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
77 ;;; not want these commencement packages to inherit grafts. By definition,
78 ;;; these packages are not depended on at run time by any of the packages we
79 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
80 ;;; grafts would often lead to extra overhead for users who would end up
81 ;;; downloading those "-boot0" packages just to build package replacements
82 ;;; that are in fact not going to be used.
83 ;;;
84 ;;; Code:
85
86 (define %bootstrap-guile+guild
87 ;; This package combines %bootstrap-guile with guild, which is not included
88 ;; in %bootstrap-guile. Guild is needed to build gash-boot and
89 ;; gash-core-utils-boot because it is dependency of the Guile build system.
90 (package
91 (name "guile-bootstrap+guild")
92 (version "2.0")
93 (source (bootstrap-origin (package-source guile-2.0)))
94 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
95 ("tar" ,(bootstrap-executable "tar" (%current-system)))
96 ("xz" ,(bootstrap-executable "xz" (%current-system)))
97 ("guile" ,%bootstrap-guile)))
98 (build-system trivial-build-system)
99 (arguments
100 `(#:guile ,%bootstrap-guile
101 #:modules ((guix build utils))
102 #:builder (begin
103 (use-modules (guix build utils))
104 (let ((guile-source (assoc-ref %build-inputs "source"))
105 (bin (string-append (getcwd) "/bin"))
106 (tar (assoc-ref %build-inputs "tar"))
107 (xz (assoc-ref %build-inputs "xz")))
108 (mkdir-p bin)
109 (setenv "PATH" bin)
110 (with-directory-excursion bin
111 (copy-file tar "tar")
112 (copy-file xz "xz")
113 (setenv "PATH" bin))
114 (let* ((out (assoc-ref %outputs "out"))
115 (out-bin (string-append out "/bin"))
116 (guile (assoc-ref %build-inputs "guile"))
117 (bash (assoc-ref %build-inputs "bash")))
118 (mkdir-p out-bin)
119 (with-directory-excursion out-bin
120 (symlink (string-append guile "/bin/guile")
121 "guile")
122 (invoke "tar" "--strip-components=2"
123 "-xvf" guile-source
124 (string-append "guile-"
125 ,(package-version guile-2.0)
126 "/meta/guild.in"))
127 (copy-file "guild.in" "guild")
128 (substitute* "guild"
129 (("#!/bin/sh") (string-append "#! " bash))
130 (("@installed_guile@") (string-append out-bin "/guile")))
131 (chmod "guild" #o555)))))))
132 (synopsis "Bootstrap Guile plus Guild")
133 (description "Bootstrap Guile with added Guild")
134 (home-page #f)
135 (license (package-license guile-2.0))
136 (native-search-paths
137 (list (search-path-specification
138 (variable "GUILE_LOAD_PATH")
139 (files '("share/guile/site/2.0")))
140 (search-path-specification
141 (variable "GUILE_LOAD_COMPILED_PATH")
142 (files '("lib/guile/2.0/site-ccache")))))))
143
144 (define gash-boot
145 (package
146 (inherit gash)
147 (name "gash-boot")
148 (version "0.2.0")
149 (source (bootstrap-origin
150 (origin (inherit (package-source gash))
151 (modules '((guix build utils)
152 (srfi srfi-26)))
153 (snippet
154 '(begin
155 ;; Remove Guix'y files that we cannot compile.
156 (delete-file "guix.scm")
157 (delete-file-recursively "tests")
158 #t)))))
159 (build-system guile-build-system)
160 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
161 ("tar" ,(bootstrap-executable "tar" (%current-system)))
162 ("xz" ,(bootstrap-executable "xz" (%current-system)))
163 ("guile-source" ,(bootstrap-origin
164 (package-source guile-2.0)))))
165 (inputs `(("guile" ,%bootstrap-guile+guild)))
166 (arguments
167 `(#:implicit-inputs? #f
168 #:guile ,%bootstrap-guile+guild
169 #:phases
170 (modify-phases %standard-phases
171 (add-after 'unpack 'unpack-guile-source
172 (lambda _
173 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
174 (bin (string-append (getcwd) "/zee-bin")))
175 (mkdir-p bin)
176 (with-directory-excursion bin
177 (invoke "tar" "--strip-components=2"
178
179 "-xvf" guile-source
180 (string-append "guile-"
181 ,(package-version guile-2.0)
182 "/meta/guild.in"))
183 (copy-file "guild.in" "guild")
184 (chmod "guild" #o555))
185 #t)))
186 (add-before 'unpack 'set-path
187 (lambda _
188 (let ((bash (assoc-ref %build-inputs "bash"))
189 (tar (assoc-ref %build-inputs "tar"))
190 (xz (assoc-ref %build-inputs "xz"))
191 (bin (string-append (getcwd) "/zee-bin")))
192 (mkdir-p bin)
193 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
194 (copy-file bash (string-append bin "/bash"))
195 (copy-file bash (string-append bin "/sh"))
196 (copy-file tar (string-append bin "/tar"))
197 (copy-file xz (string-append bin "/xz"))
198 #t)))
199 (add-after 'build 'build-scripts
200 (lambda _
201 (let* ((guile (assoc-ref %build-inputs "guile"))
202 (guile (string-append guile "/bin/guile"))
203 (out (assoc-ref %outputs "out"))
204 (effective "2.0")
205 (moddir (string-append out "/share/guile/site/" effective "/"))
206 (godir (string-append out "/lib/guile/" effective "/site-ccache/")))
207 (copy-file "scripts/gash.in" "scripts/gash")
208 (chmod "scripts/gash" #o555)
209 (substitute* "scripts/gash"
210 (("@GUILE@") guile)
211 (("@MODDIR@") moddir)
212 (("@GODIR") godir))
213 #t)))
214 (add-after 'install 'install-scripts
215 (lambda _
216 (let* ((out (assoc-ref %outputs "out"))
217 (bin (string-append out "/bin")))
218 (install-file "scripts/gash" bin)
219 (copy-file "scripts/gash" "scripts/sh")
220 (install-file "scripts/sh" bin)
221 (copy-file "scripts/gash" "scripts/bash")
222 (install-file "scripts/bash" bin)
223 #t))))))))
224
225 (define gash-core-utils-boot
226 (package
227 (inherit gash-core-utils)
228 (name "gash-core-utils-boot")
229 (version "0.0.213-3f6eb")
230 (source (bootstrap-origin
231 (origin
232 (method url-fetch)
233 (uri (string-append "http://lilypond.org/janneke/"
234 "/gash-core-utils-" version ".tar.gz"))
235 (modules '((guix build utils)))
236 (snippet
237 '(begin
238 ;; The Guile build system compiles *.scm; avoid
239 ;; compiling included lalr.
240 (delete-file "guix.scm")
241 (delete-file-recursively "tests")
242 (substitute* "system/base/lalr.scm"
243 (("system/base/lalr.upstream.scm") "lalr.upstream.scm"))
244 #t))
245 (sha256
246 (base32
247 "0601c9hqbjrjjsllr2m3zmkglkd53d97in7a5c22ikd8islddp76")))))
248 (build-system guile-build-system)
249 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
250 ("tar" ,(bootstrap-executable "tar" (%current-system)))
251 ("xz" ,(bootstrap-executable "xz" (%current-system)))
252 ("guile-source" ,(bootstrap-origin
253 (package-source guile-2.0)))
254 ;; We need the 2.0.9 lalr for %bootstrap-guile
255 ("lalr.upstream"
256 ,(origin
257 (method url-fetch)
258 (uri (string-append "http://git.savannah.gnu.org/cgit/guile.git/plain/module/system/base/lalr.upstream.scm?h=v2.0.9"))
259 (file-name "lalr.upstream.scm")
260 (sha256
261 (base32
262 "0h7gyjj8nr2qrgzwma146s7l22scp8bbcqzdy9wqf12bgyhbw7d5"))))))
263 (inputs `(("guile" ,%bootstrap-guile+guild)
264 ("gash" ,gash-boot)))
265 (arguments
266 `(#:implicit-inputs? #f
267 #:guile ,%bootstrap-guile+guild
268 #:not-compiled-file-regexp "upstream\\.scm$"
269 #:phases
270 (modify-phases %standard-phases
271 (add-after 'unpack 'unpack-guile-source
272 (lambda _
273 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
274 (bin (string-append (getcwd) "/zee-bin")))
275 (mkdir-p bin)
276 (with-directory-excursion bin
277 (invoke "tar" "--strip-components=2"
278
279 "-xvf" guile-source
280 (string-append "guile-"
281 ,(package-version guile-2.0)
282 "/meta/guild.in"))
283 (copy-file "guild.in" "guild")
284 (chmod "guild" #o555))
285 #t)))
286 (add-before 'unpack 'set-path
287 (lambda _
288 (let ((bash (assoc-ref %build-inputs "bash"))
289 (tar (assoc-ref %build-inputs "tar"))
290 (xz (assoc-ref %build-inputs "xz"))
291 (bin (string-append (getcwd) "/zee-bin")))
292 (mkdir-p bin)
293 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
294 (copy-file bash (string-append bin "/bash"))
295 (copy-file bash (string-append bin "/sh"))
296 (copy-file tar (string-append bin "/tar"))
297 (copy-file xz (string-append bin "/xz"))
298 #t)))
299 (add-before 'build 'set-env
300 (lambda _
301 (let ((gash (assoc-ref %build-inputs "gash")))
302 (setenv "LANG" "C")
303 (setenv "LC_ALL" "C")
304 (setenv "GUILE_LOAD_PATH"
305 (string-append (getcwd)
306 ":" (getcwd) "/system/base"
307 ":" gash "/share/guile/2.0"))
308 (setenv "GUILE_LOAD_COMPILED_PATH"
309 (string-append ".:" gash "/lib/guile/2.0/site-ccache/"))
310 (format (current-error-port)
311 "GUILE_LOAD_PATH=~s\n" (getenv "GUILE_LOAD_PATH"))
312 #t)))
313 (add-before 'build 'replace-lalr.upstream
314 (lambda _
315 (let ((lalr.upstream (assoc-ref %build-inputs "lalr.upstream")))
316 (copy-file lalr.upstream "system/base/lalr.upstream.scm")
317 #t)))
318 (add-after 'build 'build-scripts
319 (lambda _
320 (let* ((guile (assoc-ref %build-inputs "guile"))
321 (guile (string-append guile "/bin/guile"))
322 (gash (string-append guile "gash"))
323 (out (assoc-ref %outputs "out"))
324 (effective "2.0")
325 (guilemoduledir (string-append gash "/share/guile/site/" effective "/"))
326 (guileobjectdir (string-append gash "/lib/guile/" effective "/site-ccache/"))
327 (gashmoduledir (string-append out "/share/guile/site/" effective "/"))
328 (gashobjectdir (string-append out "/lib/guile/" effective "/site-ccache/"))
329 (bin (string-append out "/bin")))
330 (define (wrap name)
331 (copy-file "command.in" name)
332 (chmod name #o555)
333 (substitute* name
334 (("@GUILE@") guile)
335 (("@guilemoduledir@") guilemoduledir)
336 (("@guileobjectdir") guileobjectdir)
337 (("@gashmoduledir@") gashmoduledir)
338 (("@gashobjectdir") gashobjectdir)
339 (("@command@") name))
340 (install-file name bin))
341 (mkdir-p bin)
342 (with-directory-excursion "bin"
343 (for-each wrap '("awk"
344 "basename"
345 "cat"
346 "chmod"
347 "cmp"
348 "compress"
349 "cp"
350 "cut"
351 "diff"
352 "dirname"
353 "expr"
354 "false"
355 "find"
356 "grep"
357 "gzip"
358 "head"
359 "ln"
360 "ls"
361 "mkdir"
362 "mv"
363 "pwd"
364 "reboot"
365 "rm"
366 "rmdir"
367 "sed"
368 "sleep"
369 "sort"
370 "tar"
371 "test"
372 "touch"
373 "tr"
374 "true"
375 "uname"
376 "uniq"
377 "wc"
378 "which")))
379 (with-directory-excursion bin
380 (copy-file "grep" "fgrep")
381 (copy-file "grep" "egrep")
382 (copy-file "test" "["))
383 #t))))))))
384
385 (define (%boot-gash-inputs)
386 `(("bash" , gash-boot) ; gnu-build-system wants "bash"
387 ("coreutils" , gash-core-utils-boot)
388 ("guile" ,%bootstrap-guile)
389 ("guile+guild" ,%bootstrap-guile+guild)))
390
391 (define mes-boot
392 (package
393 (inherit mes)
394 (name "mes-boot")
395 (version "0.19")
396 (source (origin
397 (method url-fetch)
398 (uri (string-append "mirror://gnu/mes/"
399 "mes-" version ".tar.gz"))
400 (sha256
401 (base32
402 "15h4yhaywdc0djpjlin2jz1kzahpqxfki0r0aav1qm9nxxmnp1l0"))))
403 (inputs '())
404 (propagated-inputs '())
405 (native-inputs
406 `(("mescc-tools" ,%bootstrap-mescc-tools)
407 ("nyacc-source" ,(bootstrap-origin
408 (package-source nyacc-0.86)))
409
410 ("coreutils" , %bootstrap-coreutils&co)
411 ("bootstrap-mes" ,%bootstrap-mes)))
412 (arguments
413 `(#:implicit-inputs? #f
414 #:guile ,%bootstrap-guile
415 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
416 #:phases
417 (modify-phases %standard-phases
418 (add-after 'unpack 'unpack-seeds
419 (lambda _
420 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source"))
421 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
422 (with-directory-excursion ".."
423 (mkdir-p "nyacc-source")
424 (invoke "tar" "--strip=1" "-C" "nyacc-source" "-xvf" nyacc-source)
425 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
426 #t)))
427 (replace 'configure
428 (lambda* (#:key outputs #:allow-other-keys)
429 (let ((out (assoc-ref %outputs "out")))
430 (setenv "GUILE" "mes")
431 (setenv "GUILE_EFFECTIVE_VERSION" "2.2")
432 (setenv "GUILE_LOAD_PATH" "nyacc")
433 (symlink (string-append "../nyacc-source/module") "nyacc")
434 (invoke "bash" "configure.sh"
435 (string-append "--prefix=" out)))))
436 (replace 'build
437 (lambda _
438 (let ((mes (assoc-ref %build-inputs "bootstrap-mes")))
439 (setenv "MES_PREFIX" (string-append mes "/share/mes"))
440 (setenv "MES_ARENA" "100000000")
441 (setenv "MES_MAX_ARENA" "100000000")
442 (setenv "MES_STACK" "10000000")
443 (invoke "sh" "bootstrap.sh"))))
444 (replace 'check
445 (lambda _
446 (setenv "DIFF" "sh scripts/diff.scm")
447 ;; fail fast tests
448 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/t")
449 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/63-struct-cell")
450 (invoke "sh" "check.sh")))
451 (replace 'install
452 (lambda _
453 (invoke "sh" "install.sh"))))))
454 (native-search-paths
455 (list (search-path-specification
456 (variable "C_INCLUDE_PATH")
457 (files '("share/mes/include")))
458 (search-path-specification
459 (variable "LIBRARY_PATH")
460 (files '("share/mes/lib")))))))
461
462 (define tcc-boot0
463 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
464 ;; patches. In a very early and rough form they were presented to the
465 ;; TinyCC developers, who at the time showed no interest in supporting the
466 ;; bootstrappable effort; we will try again later. These patches have been
467 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
468 ;; mature, this package should use the 0.9.27 sources (or later).
469 (let ((version "0.9.26")
470 (revision "6")
471 (commit "c004e9a34fb026bb44d211ab98bb768e79900eef"))
472 (package
473 (inherit tcc)
474 (name "tcc-boot0")
475 (version (string-append version "-" revision "." (string-take commit 7)))
476 (source (origin
477 (method url-fetch)
478 (uri (list (string-append "mirror://gnu/guix/mirror"
479 "/tinycc-" commit ".tar.gz")
480 (string-append "https://gitlab.com/janneke/tinycc"
481 "/-/archive/" commit
482 "/tinycc-" commit ".tar.gz")))
483 (sha256
484 (base32
485 "1hmzn1pq0x22ppd80hyrn5qzqq94mxd0ychzj6vrr2vnj2frjv5b"))))
486 (build-system gnu-build-system)
487 (supported-systems '("i686-linux" "x86_64-linux"))
488 (inputs '())
489 (propagated-inputs '())
490 (native-inputs
491 `(("mes" ,mes-boot)
492 ("mescc-tools" ,%bootstrap-mescc-tools)
493 ("nyacc-source" ,(bootstrap-origin
494 (package-source nyacc-0.86)))
495
496 ("coreutils" , %bootstrap-coreutils&co)
497 ("bootstrap-mes" ,%bootstrap-mes)))
498 (arguments
499 `(#:implicit-inputs? #f
500 #:guile ,%bootstrap-guile
501 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
502 #:phases
503 (modify-phases %standard-phases
504 (add-after 'unpack 'unpack-seeds
505 (lambda* (#:key outputs #:allow-other-keys)
506 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
507 (nyacc-source (assoc-ref %build-inputs "nyacc-source"))
508 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
509 (setenv "PATH" (string-append
510 coreutils "/bin"))
511 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
512 (with-directory-excursion ".."
513 (mkdir-p "nyacc-source")
514 (invoke "tar" "--strip=1" "-C" "nyacc-source"
515 "-xvf" nyacc-source)
516 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
517 #t)))
518 (replace 'configure
519 (lambda* (#:key outputs #:allow-other-keys)
520 (let* ((out (assoc-ref %outputs "out"))
521 (dir (with-directory-excursion ".." (getcwd)))
522 (coreutils (assoc-ref %build-inputs "coreutils"))
523 (mes (assoc-ref %build-inputs "mes"))
524 (mescc-tools (assoc-ref %build-inputs "mescc-tools"))
525 (libc (assoc-ref %build-inputs "libc"))
526 (interpreter (if libc
527 ;; also for x86_64-linux, we are still on i686-linux
528 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
529 (string-append mes "/lib/mes-loader"))))
530 (setenv "PATH" (string-append
531 coreutils "/bin"
532 ":" mes "/bin"
533 ":" mescc-tools "/bin"))
534 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
535
536 (setenv "PREFIX" out)
537 (symlink (string-append mes "/share/mes") "mes")
538 (symlink (string-append "../nyacc-source/module") "nyacc")
539 (setenv "MES_PREFIX" "mes")
540 (setenv "MES_ARENA" "100000000")
541 (setenv "MES_MAX_ARENA" "100000000")
542 (setenv "MES_STACK" "10000000")
543 (setenv "MES" "mes")
544 (setenv "GUILE_LOAD_PATH" "nyacc")
545 (invoke "sh" "configure"
546 "--prefix=$PREFIX"
547 (string-append "--elfinterp=" interpreter)
548 "--crtprefix=."
549 "--tccdir=."))))
550 (replace 'build
551 (lambda _
552 (substitute* "bootstrap.sh"
553 (("^ cmp") "# cmp"))
554 (invoke "sh" "bootstrap.sh")))
555 (replace 'check
556 (lambda _
557 (setenv "DIFF" "diff.scm")
558 (setenv "OBJDUMP" "true")
559 ;; fail fast tests
560 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
561 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
562 (setenv "TCC" "./tcc")
563 (invoke "sh" "check.sh")))
564 (replace 'install
565 (lambda _
566 (invoke "sh" "install.sh"))))))
567 (native-search-paths
568 (list (search-path-specification
569 (variable "C_INCLUDE_PATH")
570 (files '("include")))
571 (search-path-specification
572 (variable "LIBRARY_PATH")
573 (files '("lib"))))))))
574
575 (define tcc-boot
576 (package
577 (inherit tcc-boot0)
578 (name "tcc-boot")
579 (version "0.9.27")
580 (source (bootstrap-origin
581 (origin
582 (inherit (package-source tcc))
583 (patches (search-patches "tcc-boot-0.9.27.patch")))))
584 (build-system gnu-build-system)
585 (inputs '())
586 (propagated-inputs '())
587 (native-inputs
588 `(("mes" ,mes-boot)
589 ("tcc" ,tcc-boot0)
590
591 ("coreutils" , %bootstrap-coreutils&co)))
592 (arguments
593 `(#:implicit-inputs? #f
594 #:guile ,%bootstrap-guile
595
596 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
597 ;; with MesCC/M1/hex2-built binaries.
598 #:strip-binaries? #f
599
600 #:phases
601 (modify-phases %standard-phases
602 (replace 'configure
603 (lambda* (#:key outputs #:allow-other-keys)
604 (let* ((out (assoc-ref %outputs "out"))
605 (coreutils (assoc-ref %build-inputs "coreutils"))
606 (mes (assoc-ref %build-inputs "mes"))
607 (tcc (assoc-ref %build-inputs "tcc"))
608 (libc (assoc-ref %build-inputs "libc"))
609 (interpreter (if libc
610 ;; also for x86_64-linux, we are still on i686-linux
611 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
612 (string-append mes "/lib/mes-loader"))))
613 ;; unpack
614 (setenv "PATH" (string-append
615 coreutils "/bin"
616 ":" tcc "/bin"))
617 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
618 (invoke "sh" "configure"
619 (string-append "--cc=tcc")
620 (string-append "--cpu=i386")
621 (string-append "--prefix=" out)
622 (string-append "--elfinterp=" interpreter)
623 (string-append "--crtprefix=" tcc "/lib")
624 (string-append "--sysincludepaths=" tcc "/include")
625 (string-append "--libpaths=" tcc "/lib")))))
626 (replace 'build
627 (lambda* (#:key outputs #:allow-other-keys)
628 (let* ((out (assoc-ref %outputs "out"))
629 (mes (assoc-ref %build-inputs "mes"))
630 (tcc (assoc-ref %build-inputs "tcc"))
631 (libc (assoc-ref %build-inputs "libc"))
632 (interpreter (if libc
633 ;; also for x86_64-linux, we are still on i686-linux
634 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
635 (string-append mes "/lib/mes-loader"))))
636 (invoke "tcc"
637 "-vvv"
638 "-D" "BOOTSTRAP=1"
639 "-D" "ONE_SOURCE=1"
640 "-D" "TCC_TARGET_I386=1"
641 "-D" "CONFIG_TCC_STATIC=1"
642 "-D" "CONFIG_USE_LIBGCC=1"
643 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
644 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
645 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
646 "/lib:{B}/lib:.\"")
647 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
648 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
649 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
650 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
651 "-o" "tcc"
652 "tcc.c"))))
653 (replace 'check
654 (lambda _
655 ;; FIXME: add sensible check target (without depending on make)
656 ;; ./check.sh ?
657 (= 1 (status:exit-val (system* "./tcc" "--help")))))
658 (replace 'install
659 (lambda* (#:key outputs #:allow-other-keys)
660 (let ((out (assoc-ref %outputs "out"))
661 (tcc (assoc-ref %build-inputs "tcc")))
662 (mkdir-p (string-append out "/bin"))
663 (copy-file "tcc" (string-append out "/bin/tcc"))
664 (mkdir-p (string-append out "/lib/tcc"))
665 (copy-recursively (string-append tcc "/include")
666 (string-append out "/include"))
667 (copy-recursively (string-append tcc "/lib")
668 (string-append out "/lib"))
669 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
670 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
671 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
672 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
673 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
674 #t))))))))
675
676 (define make-mesboot0
677 (package
678 (inherit gnu-make)
679 (name "make-mesboot0")
680 (version "3.80")
681 (source (origin
682 (method url-fetch)
683 (uri (string-append "mirror://gnu/make/make-"
684 version ".tar.gz"))
685 (sha256
686 (base32
687 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
688 (supported-systems '("i686-linux" "x86_64-linux"))
689 (inputs '())
690 (propagated-inputs '())
691 (native-inputs `(("tcc" ,tcc-boot)
692
693 ("bash" ,%bootstrap-coreutils&co)
694 ("coreutils" ,%bootstrap-coreutils&co)))
695 (arguments
696 `(#:implicit-inputs? #f
697 #:tests? #f ; check depends on perl
698 #:guile ,%bootstrap-guile
699 #:configure-flags `("CC=tcc -DO_RDONLY=0"
700 "LD=tcc"
701 "--disable-nls")
702 #:phases
703 (modify-phases %standard-phases
704 (add-after 'configure 'configure-fixup
705 (lambda _
706 (substitute* "build.sh"
707 (("^REMOTE=.*") "REMOTE=stub\n")
708 (("^extras=.*") "extras=getloadavg.c\n"))
709 (substitute* "make.h"
710 (("^extern long int lseek.*" all) (string-append "// " all)))
711 #t))
712 (delete 'patch-generated-file-shebangs) ; no perl
713 (replace 'build
714 (lambda _
715 (invoke "sh" "./build.sh")))
716 (replace 'install
717 (lambda* (#:key outputs #:allow-other-keys)
718 (let* ((out (assoc-ref outputs "out"))
719 (bin (string-append out "/bin")))
720 (install-file "make" bin)
721 #t))))))))
722
723 (define diffutils-mesboot
724 (package
725 (inherit diffutils)
726 (name "diffutils-mesboot")
727 (version "2.7")
728 (source (origin
729 (method url-fetch)
730 (uri (string-append "mirror://gnu/diffutils/diffutils-"
731 version ".tar.gz"))
732 (sha256
733 (base32
734 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
735 (supported-systems '("i686-linux" "x86_64-linux"))
736 (inputs '())
737 (propagated-inputs '())
738 (native-inputs `(("mes" ,mes-boot)
739 ("tcc" ,tcc-boot)
740
741 ("bash" ,%bootstrap-coreutils&co)
742 ("coreutils" ,%bootstrap-coreutils&co)
743 ("make" ,make-mesboot0)))
744 (arguments
745 `(#:implicit-inputs? #f
746 #:guile ,%bootstrap-guile
747 #:parallel-build? #f
748 #:tests? #f ; check is naive, also checks non-built PROGRAMS
749 #:strip-binaries? #f ; no strip yet
750 #:phases
751 (modify-phases %standard-phases
752 ;; diffutils-2.7 needs more traditional configure
753 (replace 'configure
754 (lambda* (#:key outputs #:allow-other-keys)
755 (let ((out (assoc-ref outputs "out"))
756 (bash (assoc-ref %build-inputs "bash")))
757 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
758 (setenv "CC" "tcc")
759 (setenv "LD" "tcc")
760 (invoke "./configure" (string-append "--prefix=" out)))))
761 (add-before 'configure 'remove-diff3-sdiff
762 (lambda* (#:key outputs #:allow-other-keys)
763 (substitute* "Makefile.in"
764 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
765 #t)))))))
766
767 (define binutils-mesboot0
768 (package
769 (inherit binutils)
770 (name "binutils-mesboot0")
771 (version "2.20.1a")
772 (source (bootstrap-origin
773 (origin
774 (method url-fetch)
775 (uri (string-append "mirror://gnu/binutils/binutils-"
776 version ".tar.bz2"))
777 (patches (search-patches "binutils-boot-2.20.1a.patch"))
778 (sha256
779 (base32
780 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
781 (inputs '())
782 (propagated-inputs '())
783 (native-inputs `(("tcc" ,tcc-boot)
784
785 ("bash" ,%bootstrap-coreutils&co)
786 ("coreutils" ,%bootstrap-coreutils&co)
787 ("diffutils" ,diffutils-mesboot)
788 ("make" ,make-mesboot0)))
789 (supported-systems '("i686-linux" "x86_64-linux"))
790 (arguments
791 `(#:implicit-inputs? #f
792 #:guile ,%bootstrap-guile
793 #:tests? #f ; runtest: command not found
794 #:parallel-build? #f
795 #:strip-binaries? #f ; no strip yet
796 #:configure-flags
797 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
798 " -D MES_BOOTSTRAP=1"))
799 (bash (assoc-ref %build-inputs "bash")))
800 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
801 ,(string-append "CPPFLAGS=" cppflags)
802 "AR=tcc -ar"
803 "CXX=false"
804 "RANLIB=true"
805 ,(string-append "CC=tcc" cppflags)
806 "--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 gcc-core-mesboot
814 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
815 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
816 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
817 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
818 ;; toolchain triplet "that works".
819 (package
820 (inherit gcc)
821 (name "gcc-core-mesboot")
822 (version "2.95.3")
823 (source (bootstrap-origin
824 (origin
825 (method url-fetch)
826 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
827 version
828 ".tar.gz"))
829 (patches (search-patches "gcc-boot-2.95.3.patch"))
830 (sha256
831 (base32
832 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
833 (supported-systems '("i686-linux" "x86_64-linux"))
834 (inputs '())
835 (propagated-inputs '())
836 (native-inputs `(("binutils" ,binutils-mesboot0)
837 ("tcc" ,tcc-boot)
838
839 ("bash" ,%bootstrap-coreutils&co)
840 ("coreutils" ,%bootstrap-coreutils&co)
841 ("diffutils" ,diffutils-mesboot)
842 ("make" ,make-mesboot0)))
843 (outputs '("out"))
844 (arguments
845 `(#:implicit-inputs? #f
846 #:guile ,%bootstrap-guile
847 #:tests? #f
848 #:parallel-build? #f
849 #:strip-binaries? #f
850 #:configure-flags
851 (let ((out (assoc-ref %outputs "out")))
852 `("--enable-static"
853 "--disable-shared"
854 "--disable-werror"
855 "--build=i686-unknown-linux-gnu"
856 "--host=i686-unknown-linux-gnu"
857 ,(string-append "--prefix=" out)))
858 #:make-flags (list
859 "CC=tcc -static -D __GLIBC_MINOR__=6"
860 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
861 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
862 "AR=ar"
863 "RANLIB=ranlib"
864 (string-append "LIBGCC2_INCLUDES=-I "
865 (assoc-ref %build-inputs "tcc")
866 "/include")
867 "LANGUAGES=c"
868 (string-append "BOOT_LDFLAGS="
869 " -B" (assoc-ref %build-inputs "tcc")
870 "/lib/"))
871 #:modules ((guix build gnu-build-system)
872 (guix build utils)
873 (srfi srfi-1))
874 #:phases
875 (modify-phases %standard-phases
876 ;; gcc-2.95.3 needs more traditional configure
877 (add-before 'configure 'setenv
878 (lambda* (#:key outputs #:allow-other-keys)
879 (let ((out (assoc-ref outputs "out"))
880 (bash (assoc-ref %build-inputs "bash"))
881 (tcc (assoc-ref %build-inputs "tcc"))
882 (cppflags " -D __GLIBC_MINOR__=6"))
883 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
884 (setenv "CPPFLAGS" cppflags)
885 (setenv "CC" (string-append "tcc" cppflags))
886 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
887 (setenv "CPP" (string-append "tcc -E" cppflags))
888 (with-output-to-file "config.cache"
889 (lambda _
890 (display "
891 ac_cv_c_float_format='IEEE (little-endian)'
892 ")))
893 #t)))
894 (replace 'configure
895 (lambda* (#:key configure-flags #:allow-other-keys)
896 (format (current-error-port)
897 "running ./configure ~a\n" (string-join configure-flags))
898 (apply invoke "./configure" configure-flags)))
899 (add-after 'configure 'remove-info
900 (lambda _
901 ;; no info at this stage
902 (delete-file-recursively "texinfo")
903 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
904 (add-after 'install 'install2
905 (lambda* (#:key outputs #:allow-other-keys)
906 (let* ((tcc (assoc-ref %build-inputs "tcc"))
907 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
908 (out (assoc-ref outputs "out"))
909 (gcc-dir (string-append
910 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
911 (mkdir-p "tmp")
912 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
913 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
914 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
915 (copy-file (string-append tcc "/lib/libtcc1.a")
916 (string-append out "/lib/libtcc1.a"))
917 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
918 (string-append tcc-lib "/libc+gnu.o")
919 (string-append tcc-lib "/libtcc1.o"))
920 (invoke "ar" "r" (string-append out "/lib/libc.a")
921 (string-append tcc-lib "/libc+gnu.o")
922 (string-append tcc-lib "/libtcc1.o"))
923 (invoke "ls" "-ltrF" gcc-dir)
924 #t))))))
925 (native-search-paths
926 (list (search-path-specification
927 (variable "C_INCLUDE_PATH")
928 (files '("include"
929
930 ;; Needed to get things like GCC's <stddef.h>.
931 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
932 (search-path-specification
933 (variable "LIBRARY_PATH")
934 (files '("lib")))))))
935
936 (define mesboot-headers
937 (package
938 (inherit mes-boot)
939 (name "mesboot-headers")
940 (supported-systems '("i686-linux" "x86_64-linux"))
941 (inputs '())
942 (propagated-inputs '())
943 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
944 ("headers" ,%bootstrap-linux-libre-headers)))
945 (arguments
946 `(#:implicit-inputs? #f
947 #:guile ,%bootstrap-guile
948 #:tests? #f
949 #:strip-binaries? #f
950 #:phases
951 (modify-phases %standard-phases
952 (delete 'configure)
953 (delete 'build)
954 (replace 'install
955 (lambda* (#:key outputs #:allow-other-keys)
956 (let* ((out (assoc-ref outputs "out"))
957 (include (string-append out "/include"))
958 (headers (assoc-ref %build-inputs "headers" )))
959 (mkdir-p include)
960 (copy-recursively "include" out)
961 (copy-recursively headers out)
962 #t))))))))
963
964 (define glibc-mesboot0
965 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
966 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
967 ;; gcc.
968 (package
969 (inherit glibc)
970 (name "glibc-mesboot0")
971 (version "2.2.5")
972 (source (bootstrap-origin
973 (origin
974 (method url-fetch)
975 (uri (string-append "mirror://gnu/glibc/glibc-"
976 version
977 ".tar.gz"))
978 (patches (search-patches "glibc-boot-2.2.5.patch"))
979 (sha256
980 (base32
981 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
982 (supported-systems '("i686-linux" "x86_64-linux"))
983 (inputs '())
984 (propagated-inputs '())
985 (native-inputs `(("binutils" ,binutils-mesboot0)
986 ("gcc" ,gcc-core-mesboot)
987
988 ("bash" ,%bootstrap-coreutils&co)
989 ("coreutils" ,%bootstrap-coreutils&co)
990 ("diffutils" ,diffutils-mesboot)
991 ("headers" ,mesboot-headers)
992 ("make" ,make-mesboot0)))
993 (outputs '("out"))
994 (arguments
995 `(#:implicit-inputs? #f
996 #:guile ,%bootstrap-guile
997 #:tests? #f
998 #:strip-binaries? #f
999 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1000 #:make-flags (list (string-append
1001 "SHELL="
1002 (assoc-ref %build-inputs "bash")
1003 "/bin/sh"))
1004 #:configure-flags
1005 (let ((out (assoc-ref %outputs "out"))
1006 (headers (assoc-ref %build-inputs "headers")))
1007 (list
1008 "--disable-shared"
1009 "--enable-static"
1010 "--disable-sanity-checks"
1011 "--build=i686-unknown-linux-gnu"
1012 "--host=i686-unknown-linux-gnu"
1013 (string-append "--with-headers=" headers "/include")
1014 "--enable-static-nss"
1015 "--without-__thread"
1016 "--without-cvs"
1017 "--without-gd"
1018 "--without-tls"
1019 (string-append "--prefix=" out)))
1020 #:phases
1021 (modify-phases %standard-phases
1022 (add-before 'configure 'setenv
1023 (lambda* (#:key outputs #:allow-other-keys)
1024 (let* ((out (assoc-ref outputs "out"))
1025 (bash (assoc-ref %build-inputs "bash"))
1026 (gcc (assoc-ref %build-inputs "gcc"))
1027 (headers (assoc-ref %build-inputs "headers"))
1028 (cppflags (string-append
1029 ;;" -D __STDC__=1"
1030 " -D MES_BOOTSTRAP=1"
1031 " -D BOOTSTRAP_GLIBC=1"))
1032 (cflags (string-append " -L " (getcwd))))
1033 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1034 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1035 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1036 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1037 #t)))
1038 ;; glibc-2.2.5 needs a more classic invocation of configure
1039 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
1040 (replace 'configure
1041 (lambda* (#:key configure-flags #:allow-other-keys)
1042 (format (current-error-port)
1043 "running ./configure ~a\n" (string-join configure-flags))
1044 (apply invoke "./configure" configure-flags))))))))
1045
1046 (define gcc-mesboot0
1047 (package
1048 (inherit gcc-core-mesboot)
1049 (name "gcc-mesboot0")
1050 (native-inputs `(("binutils" ,binutils-mesboot0)
1051
1052 ;; Packages are given in an order that's relevant for
1053 ;; #include_next purposes.
1054 ("libc" ,glibc-mesboot0)
1055 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1056 ("gcc" ,gcc-core-mesboot)
1057
1058 ("bash" ,%bootstrap-coreutils&co)
1059 ("coreutils" ,%bootstrap-coreutils&co)
1060 ("diffutils" ,diffutils-mesboot)
1061 ("make" ,make-mesboot0)))
1062 (arguments
1063 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1064 ((#:phases phases)
1065 `(modify-phases ,phases
1066 (replace 'setenv
1067 (lambda _
1068 (setenv "CONFIG_SHELL" (which "sh"))
1069 (with-output-to-file "config.cache"
1070 (lambda _
1071 (display "
1072 ac_cv_c_float_format='IEEE (little-endian)'
1073 ")))
1074 #t))
1075 (replace 'install2
1076 (lambda* (#:key outputs #:allow-other-keys)
1077 (let* ((out (assoc-ref outputs "out"))
1078 (gcc-dir (string-append
1079 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1080 (mkdir-p "tmp")
1081 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1082 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1083 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1084 #t)))))
1085 ((#:configure-flags configure-flags)
1086 `(let ((out (assoc-ref %outputs "out")))
1087 `("--disable-shared"
1088 "--disable-werror"
1089 "--build=i686-unknown-linux-gnu"
1090 "--host=i686-unknown-linux-gnu"
1091 ,(string-append "--prefix=" out))))
1092 ((#:make-flags make-flags)
1093 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1094 `("RANLIB=true"
1095 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1096 "LANGUAGES=c")))))))
1097
1098 (define binutils-mesboot
1099 (package
1100 (inherit binutils-mesboot0)
1101 (name "binutils-mesboot")
1102 (native-inputs `(("binutils" ,binutils-mesboot0)
1103 ("libc" ,glibc-mesboot0)
1104 ("gcc" ,gcc-mesboot0)
1105
1106 ("bash" ,%bootstrap-coreutils&co)
1107 ("coreutils" ,%bootstrap-coreutils&co)
1108 ("diffutils" ,diffutils-mesboot)
1109 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1110 ("make" ,make-mesboot0)))
1111 (arguments
1112 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1113 ((#:configure-flags configure-flags)
1114 '(list "--disable-nls"
1115 "--disable-shared"
1116 "--disable-werror"
1117 "--build=i686-unknown-linux-gnu"
1118 "--host=i686-unknown-linux-gnu"
1119 "--with-sysroot=/"))))))
1120
1121 (define make-mesboot
1122 (package
1123 (inherit make-mesboot0)
1124 (name "make-mesboot")
1125 (version "3.82")
1126 (source (origin
1127 (method url-fetch)
1128 (uri (string-append "mirror://gnu/make/make-"
1129 version ".tar.gz"))
1130 (sha256
1131 (base32
1132 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1133 (native-inputs `(("binutils" ,binutils-mesboot0)
1134 ("libc" ,glibc-mesboot0)
1135 ("gcc" ,gcc-mesboot0)
1136 ("make" ,make-mesboot0)
1137
1138 ("bash" ,%bootstrap-coreutils&co)
1139 ("coreutils" ,%bootstrap-coreutils&co)
1140 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
1141 (arguments
1142 (substitute-keyword-arguments (package-arguments make-mesboot0)
1143 ((#:configure-flags configure-flags)
1144 `(let ((out (assoc-ref %outputs "out")))
1145 `(,(string-append "--prefix=" out))))
1146 ((#:phases phases)
1147 `(modify-phases ,phases
1148 (delete 'configure-fixup)
1149 (add-before 'configure 'setenv
1150 (lambda _
1151 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1152 #t))))))))
1153
1154 (define gmp-boot
1155 (package
1156 (inherit gmp)
1157 (version "4.3.2")
1158 (source (origin
1159 (method url-fetch)
1160 (uri (string-append "mirror://gnu/gmp/gmp-" version
1161 ".tar.gz"))
1162 (sha256 (base32
1163 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1164
1165 (define mpfr-boot
1166 (package
1167 (inherit mpfr)
1168 (version "2.4.2")
1169 (source (origin
1170 (method url-fetch)
1171 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1172 ".tar.gz"))
1173 (sha256 (base32
1174 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1175
1176 (define mpc-boot
1177 (package
1178 (inherit mpc)
1179 (version "1.0.3")
1180 (source (origin
1181 (method url-fetch)
1182 (uri (string-append
1183 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1184 (sha256
1185 (base32
1186 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1187
1188 (define gcc-mesboot1
1189 (package
1190 (inherit gcc-mesboot0)
1191 (name "gcc-mesboot1")
1192 (version (package-version gcc-4.7))
1193 (source (bootstrap-origin
1194 (origin (inherit (package-source gcc-4.7))
1195 (patches (search-patches "gcc-boot-4.7.4.patch")))))
1196 (inputs `(("gmp-source" ,(package-source gmp-boot))
1197 ("mpfr-source" ,(package-source mpfr-boot))
1198 ("mpc-source" ,(package-source mpc-boot))))
1199 (native-inputs `(("binutils" ,binutils-mesboot)
1200
1201 ("libc" ,glibc-mesboot0)
1202 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1203 ("gcc" ,gcc-mesboot0)
1204
1205 ("bash" ,%bootstrap-coreutils&co)
1206 ("coreutils" ,%bootstrap-coreutils&co)
1207 ("diffutils" ,diffutils-mesboot)
1208 ("make" ,make-mesboot)))
1209 (arguments
1210 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1211 ((#:make-flags make-flags)
1212 `(let* ((libc (assoc-ref %build-inputs "libc"))
1213 (ldflags (string-append
1214 "-B" libc "/lib "
1215 "-Wl,-dynamic-linker "
1216 "-Wl," libc
1217 ,(glibc-dynamic-linker "i686-linux"))))
1218 (list (string-append "LDFLAGS=" ldflags)
1219 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
1220 ((#:phases phases)
1221 `(modify-phases ,phases
1222 ;; c&p from commencement.scm:gcc-boot0
1223 (add-after 'unpack 'unpack-gmp&co
1224 (lambda* (#:key inputs #:allow-other-keys)
1225 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1226 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1227 (mpc (assoc-ref %build-inputs "mpc-source")))
1228
1229 ;; To reduce the set of pre-built bootstrap inputs, build
1230 ;; GMP & co. from GCC.
1231 (for-each (lambda (source)
1232 (or (invoke "tar" "xvf" source)
1233 (error "failed to unpack tarball"
1234 source)))
1235 (list gmp mpfr mpc))
1236
1237 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1238 ,@(map (lambda (lib)
1239 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1240 ;; into gmp-6.0.0.
1241 `(symlink ,(string-trim-right
1242 (package-full-name lib "-")
1243 char-set:letter)
1244 ,(package-name lib)))
1245 (list gmp-boot mpfr-boot mpc-boot))
1246 #t)))
1247 (delete 'remove-info)
1248 (replace 'setenv
1249 (lambda _
1250 (setenv "CONFIG_SHELL" (which "sh"))
1251
1252 ;; Allow MPFR headers to be found.
1253 (setenv "C_INCLUDE_PATH"
1254 (string-append (getcwd) "/mpfr/src:"
1255 (getenv "C_INCLUDE_PATH")))
1256
1257 ;; Set the C++ search path so that C headers can be found as
1258 ;; libstdc++ is being compiled.
1259 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
1260 #t))
1261 (delete 'install2)))
1262 ((#:configure-flags configure-flags)
1263 `(let ((out (assoc-ref %outputs "out"))
1264 (glibc (assoc-ref %build-inputs "libc")))
1265 (list (string-append "--prefix=" out)
1266 "--build=i686-unknown-linux-gnu"
1267 "--host=i686-unknown-linux-gnu"
1268
1269 (string-append "--with-native-system-header-dir=" glibc "/include")
1270 (string-append "--with-build-sysroot=" glibc "/include")
1271
1272 "--disable-bootstrap"
1273 "--disable-decimal-float"
1274 "--disable-libatomic"
1275 "--disable-libcilkrts"
1276 "--disable-libgomp"
1277 "--disable-libitm"
1278 "--disable-libmudflap"
1279 "--disable-libquadmath"
1280 "--disable-libsanitizer"
1281 "--disable-libssp"
1282 "--disable-libvtv"
1283 "--disable-lto"
1284 "--disable-lto-plugin"
1285 "--disable-multilib"
1286 "--disable-plugin"
1287 "--disable-threads"
1288 "--enable-languages=c,c++"
1289
1290 "--enable-static"
1291 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1292 "--disable-shared"
1293 "--enable-threads=single"
1294
1295 ;; No pre-compiled libstdc++ headers, to save space.
1296 "--disable-libstdcxx-pch"
1297
1298 ;; for libcpp ...
1299 "--disable-build-with-cxx")))))))
1300
1301 (define gcc-mesboot1-wrapper
1302 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1303 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1304 ;; --enable-shared will fail.
1305 (package
1306 (inherit gcc-mesboot1)
1307 (name "gcc-mesboot1-wrapper")
1308 (source #f)
1309 (inputs '())
1310 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1311 ("libc" ,glibc-mesboot)
1312 ("gcc" ,gcc-mesboot1)))
1313 (arguments
1314 `(#:implicit-inputs? #f
1315 #:guile ,%bootstrap-guile
1316 #:phases
1317 (modify-phases %standard-phases
1318 (delete 'unpack)
1319 (delete 'configure)
1320 (delete 'install)
1321 (replace 'build
1322 (lambda* (#:key outputs #:allow-other-keys)
1323 (let* ((out (assoc-ref outputs "out"))
1324 (bash (assoc-ref %build-inputs "bash"))
1325 (libc (assoc-ref %build-inputs "libc"))
1326 (gcc (assoc-ref %build-inputs "gcc"))
1327 (bin (string-append out "/bin")))
1328 (mkdir-p bin)
1329 (for-each
1330 (lambda (program)
1331 (let ((wrapper (string-append bin "/" program)))
1332 (with-output-to-file wrapper
1333 (lambda _
1334 (display (string-append "#! " bash "/bin/bash
1335 exec " gcc "/bin/" program
1336 " -Wl,--dynamic-linker"
1337 ;; also for x86_64-linux, we are still on i686-linux
1338 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1339 " -Wl,--rpath"
1340 " -Wl," libc "/lib"
1341 " \"$@\"
1342 "))
1343 (chmod wrapper #o555)))))
1344 '(
1345 "gcc"
1346 "g++"
1347 "i686-unknown-linux-gnu-gcc"
1348 "i686-unknown-linux-gnu-g++"
1349 ))
1350 #t)))
1351 (replace 'check
1352 (lambda* (#:key outputs #:allow-other-keys)
1353 (let* ((out (assoc-ref outputs "out"))
1354 (bin (string-append out "/bin"))
1355 (program (string-append bin "/gcc")))
1356 (invoke program "--help")))))))))
1357
1358 (define glibc-headers-mesboot
1359 (package
1360 (inherit glibc-mesboot0)
1361 (name "glibc-headers-mesboot")
1362 (version "2.16.0")
1363 (source (bootstrap-origin
1364 (origin
1365 (method url-fetch)
1366 (uri (string-append "mirror://gnu/glibc/glibc-"
1367 version
1368 ".tar.gz"))
1369 (patches (search-patches "glibc-boot-2.16.0.patch"
1370 "glibc-bootstrap-system-2.16.0.patch"))
1371 (sha256
1372 (base32
1373 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1374 (native-inputs `(("binutils" ,binutils-mesboot)
1375 ("libc" ,glibc-mesboot0)
1376 ("gcc" ,gcc-mesboot1)
1377 ("headers" ,mesboot-headers)
1378
1379 ("bash" ,%bootstrap-coreutils&co)
1380 ("coreutils" ,%bootstrap-coreutils&co)
1381 ("diffutils" ,diffutils-mesboot)
1382 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1383 ("make" ,make-mesboot)))
1384
1385 (arguments
1386 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1387 ((#:configure-flags configure-flags)
1388 `(let ((out (assoc-ref %outputs "out"))
1389 (headers (assoc-ref %build-inputs "headers")))
1390 (list
1391 (string-append "--prefix=" out)
1392 "--disable-obsolete-rpc"
1393 "--host=i686-unknown-linux-gnu"
1394 (string-append "--with-headers=" headers "/include")
1395 "--enable-static-nss"
1396 "--with-pthread"
1397 "--without-cvs"
1398 "--without-gd"
1399 "--enable-add-ons=nptl")))
1400 ((#:make-flags make-flags)
1401 `(let ((bash (assoc-ref %build-inputs "bash")))
1402 (list (string-append "SHELL=" bash "/bin/sh")
1403 "install-bootstrap-headers=yes" "install-headers")))
1404 ((#:phases phases)
1405 `(modify-phases ,phases
1406 (replace 'setenv
1407 (lambda* (#:key inputs #:allow-other-keys)
1408 (let* ((headers (assoc-ref inputs "headers"))
1409 (libc (assoc-ref inputs "libc"))
1410 (gcc (assoc-ref inputs "gcc"))
1411 (cppflags (string-append
1412 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1413 " -D BOOTSTRAP_GLIBC=1"))
1414 (cflags (string-append " -L " (getcwd)
1415 " -L " libc "/lib")))
1416 (setenv "libc_cv_friendly_stddef" "yes")
1417 (setenv "CONFIG_SHELL" (which "sh"))
1418 (setenv "SHELL" (which "sh"))
1419
1420 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1421 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1422
1423 ;; avoid -fstack-protector
1424 (setenv "libc_cv_ssp" "false")
1425 (substitute* "configure"
1426 (("/bin/pwd") "pwd"))
1427 #t)))
1428 (replace 'install
1429 (lambda* (#:key outputs make-flags #:allow-other-keys)
1430 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1431 (out (assoc-ref outputs "out")))
1432 (apply invoke "make" make-flags)
1433 (copy-recursively kernel-headers out)
1434 #t)))
1435 (replace 'configure
1436 (lambda* (#:key configure-flags #:allow-other-keys)
1437 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1438 (mkdir-p "build")
1439 (chdir "build")
1440 (apply invoke "../configure" configure-flags)))
1441 (add-after 'configure 'remove-sunrpc
1442 (lambda _
1443 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1444 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1445 (substitute* "sysd-sorted"
1446 ((" sunrpc") " ")
1447 ((" nis") " "))
1448 ;; 'rpcgen' needs native libc headers to be built.
1449 (substitute* "../Makefile"
1450 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1451 (substitute* "../Makeconfig"
1452 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1453 (substitute* "../elf/Makefile"
1454 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1455
1456 (define glibc-mesboot
1457 (package
1458 (inherit glibc-headers-mesboot)
1459 (name "glibc-mesboot")
1460 (native-inputs `(("binutils" ,binutils-mesboot)
1461 ("libc" ,glibc-mesboot0)
1462 ("headers" ,glibc-headers-mesboot)
1463 ("gcc" ,gcc-mesboot1)
1464
1465 ("bash" ,%bootstrap-coreutils&co)
1466 ("coreutils" ,%bootstrap-coreutils&co)
1467 ("diffutils" ,diffutils-mesboot)
1468 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1469 ("make" ,make-mesboot)))
1470
1471 (arguments
1472 `(#:validate-runpath? #f ; fails when using --enable-shared
1473 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1474 ((#:make-flags make-flags)
1475 `(let ((bash (assoc-ref %build-inputs "bash")))
1476 (list (string-append "SHELL=" bash "/bin/sh"))))
1477 ((#:phases phases)
1478 `(modify-phases ,phases
1479 (replace 'install
1480 (lambda* (#:key outputs make-flags #:allow-other-keys)
1481 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1482 (out (assoc-ref outputs "out"))
1483 (install-flags (cons "install" make-flags)))
1484 (apply invoke "make" install-flags)
1485 (copy-recursively kernel-headers out)
1486 #t))))))))))
1487
1488 (define gcc-mesboot
1489 (package
1490 (inherit gcc-mesboot1)
1491 (name "gcc-mesboot")
1492 (version (package-version gcc-4.9))
1493 (source (bootstrap-origin (package-source gcc-4.9)))
1494 (native-inputs `(("binutils" ,binutils-mesboot)
1495
1496 ("libc" ,glibc-mesboot)
1497 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1498 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1499 ("gcc" ,gcc-mesboot1)
1500
1501 ("bash" ,%bootstrap-coreutils&co)
1502 ("coreutils" ,%bootstrap-coreutils&co)
1503 ("diffutils" ,diffutils-mesboot)
1504 ("make" ,make-mesboot)))
1505 (arguments
1506 `(#:validate-runpath? #f
1507 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1508 ((#:configure-flags configure-flags)
1509 `(let ((out (assoc-ref %outputs "out"))
1510 (glibc (assoc-ref %build-inputs "libc")))
1511 (list (string-append "--prefix=" out)
1512 "--build=i686-unknown-linux-gnu"
1513 "--host=i686-unknown-linux-gnu"
1514
1515 "--with-host-libstdcxx=-lsupc++"
1516
1517 (string-append "--with-native-system-header-dir=" glibc "/include")
1518 (string-append "--with-build-sysroot=" glibc "/include")
1519
1520 "--disable-bootstrap"
1521 "--disable-decimal-float"
1522 "--disable-libatomic"
1523 "--disable-libcilkrts"
1524 "--disable-libgomp"
1525 "--disable-libitm"
1526 "--disable-libmudflap"
1527 "--disable-libquadmath"
1528 "--disable-libsanitizer"
1529 "--disable-libssp"
1530 "--disable-libvtv"
1531 "--disable-lto"
1532 "--disable-lto-plugin"
1533 "--disable-multilib"
1534 "--disable-plugin"
1535 "--disable-threads"
1536 "--enable-languages=c,c++"
1537
1538 "--enable-static"
1539 "--enable-shared"
1540 "--enable-threads=single"
1541
1542 ;; No pre-compiled libstdc++ headers, to save space.
1543 "--disable-libstdcxx-pch"
1544
1545 ;; for libcpp ...
1546 "--disable-build-with-cxx"))))))))
1547
1548 (define gcc-mesboot-wrapper
1549 ;; We need this so gcc-mesboot can be used to create shared binaries that
1550 ;; have the correct interpreter and runpath to libc.
1551 (package
1552 (inherit gcc-mesboot1-wrapper)
1553 (name "gcc-mesboot-wrapper")
1554 (version (package-version gcc-mesboot))
1555 (source #f)
1556 (inputs '())
1557 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1558 ("libc" ,glibc-mesboot)
1559 ("gcc" ,gcc-mesboot)))))
1560
1561 (define m4-mesboot
1562 (package
1563 (inherit m4)
1564 (name "m4-mesboot")
1565 (version "1.4")
1566 (source (origin
1567 (method url-fetch)
1568 (uri (string-append "mirror://gnu/m4/m4-"
1569 version ".tar.gz"))
1570 (sha256
1571 (base32
1572 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1573 (supported-systems '("i686-linux" "x86_64-linux"))
1574 (native-inputs `(("mes" ,mes-boot)
1575 ("tcc" ,tcc-boot)))
1576 (arguments
1577 `(#:phases
1578 (modify-phases %standard-phases
1579 (replace 'configure
1580 (lambda* (#:key outputs #:allow-other-keys)
1581 (let ((out (assoc-ref outputs "out")))
1582 (setenv "CONFIG_SHELL" (string-append
1583 (assoc-ref %build-inputs "bash")
1584 "/bin/sh"))
1585 (setenv "CC" "tcc -static")
1586 (setenv "CPP" "tcc -E")
1587 (invoke "./configure" (string-append "--prefix=" out))))))))))
1588
1589 (define (%bootstrap-inputs+toolchain)
1590 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1591 ;; the actual reduced set with bootstrapped toolchain.
1592 (match (%current-system)
1593 ((or "i686-linux" "x86_64-linux")
1594 `(("libc" ,glibc-mesboot)
1595 ("binutils" ,binutils-mesboot)
1596 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1597 ("gcc" ,gcc-mesboot)
1598 ,@(fold alist-delete (%bootstrap-inputs)
1599 '("bootstrap-mescc-tools" "mes"))))
1600 (_
1601 (%bootstrap-inputs))))
1602
1603 (define gnu-make-boot0
1604 (package
1605 (inherit gnu-make)
1606 (source (bootstrap-origin (package-source gnu-make)))
1607 (name "make-boot0")
1608 (arguments
1609 `(#:guile ,%bootstrap-guile
1610 #:implicit-inputs? #f
1611 #:tests? #f ; cannot run "make check"
1612 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1613 ((#:configure-flags flags ''())
1614 ;; The generated config.status has some problems due to the
1615 ;; bootstrap environment. Disable dependency tracking to work
1616 ;; around it.
1617 `(cons "--disable-dependency-tracking" ,flags))
1618 ((#:phases phases)
1619 `(modify-phases ,phases
1620 (replace 'build
1621 (lambda _
1622 (invoke "./build.sh")))
1623 (replace 'install
1624 (lambda* (#:key outputs #:allow-other-keys)
1625 (let* ((out (assoc-ref outputs "out"))
1626 (bin (string-append out "/bin")))
1627 (install-file "make" bin)
1628 #t))))))))
1629 (native-inputs '()) ; no need for 'pkg-config'
1630 (inputs (%bootstrap-inputs+toolchain))))
1631
1632 (define diffutils-boot0
1633 (package
1634 (inherit diffutils)
1635 (name "diffutils-boot0")
1636 (native-inputs `())
1637 (inputs
1638 `(("make" ,gnu-make-boot0)
1639 ,@(%bootstrap-inputs+toolchain)))
1640 (arguments
1641 `(#:tests? #f ; the test suite needs diffutils
1642 #:guile ,%bootstrap-guile
1643 #:implicit-inputs? #f
1644 ,@(package-arguments diffutils)))))
1645
1646 (define findutils-boot0
1647 (package
1648 (inherit findutils)
1649 (name "findutils-boot0")
1650 (source (bootstrap-origin (package-source findutils)))
1651 (inputs
1652 `(("make" ,gnu-make-boot0)
1653 ("diffutils" ,diffutils-boot0) ; for tests
1654 ,@(%bootstrap-inputs+toolchain)))
1655 (arguments
1656 `(#:implicit-inputs? #f
1657 #:guile ,%bootstrap-guile
1658
1659 ;; The build system assumes we have done a mistake when time_t is 32-bit
1660 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1661 ,@(if (target-64bit?)
1662 (substitute-keyword-arguments (package-arguments findutils)
1663 ((#:configure-flags flags ''())
1664 `(cons "TIME_T_32_BIT_OK=yes"
1665 ,flags)))
1666 (package-arguments findutils))))))
1667
1668 (define file-boot0
1669 (package
1670 (inherit file)
1671 (source (bootstrap-origin (package-source file)))
1672 (name "file-boot0")
1673 (inputs
1674 `(("make" ,gnu-make-boot0)
1675 ,@(%bootstrap-inputs+toolchain)))
1676 (arguments
1677 `(#:implicit-inputs? #f
1678 #:guile ,%bootstrap-guile
1679 #:strip-binaries? #f
1680 #:validate-runpath? #f))))
1681
1682 (define (%boot0-inputs)
1683 `(("make" ,gnu-make-boot0)
1684 ("diffutils" ,diffutils-boot0)
1685 ("findutils" ,findutils-boot0)
1686 ("file" ,file-boot0)
1687 ,@(%bootstrap-inputs+toolchain)))
1688
1689 (define* (boot-triplet #:optional (system (%current-system)))
1690 ;; Return the triplet used to create the cross toolchain needed in the
1691 ;; first bootstrapping stage.
1692 (nix-system->gnu-triplet system "guix"))
1693
1694 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1695 ;; toolchain actually targets the same OS and arch, but it has the advantage
1696 ;; of being independent of the libc and tools in
1697 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1698 ;; reference to the target libc.
1699
1700 (define binutils-boot0
1701 (package
1702 (inherit binutils)
1703 (source (bootstrap-origin (package-source binutils)))
1704 (name "binutils-cross-boot0")
1705 (arguments
1706 `(#:guile ,%bootstrap-guile
1707 #:implicit-inputs? #f
1708
1709 #:modules ((guix build gnu-build-system)
1710 (guix build utils)
1711 (ice-9 ftw)) ; for 'scandir'
1712 #:phases (modify-phases %standard-phases
1713 (add-after 'install 'add-symlinks
1714 (lambda* (#:key outputs #:allow-other-keys)
1715 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1716 ;; triplet prefix, so add symlinks.
1717 (let ((out (assoc-ref outputs "out"))
1718 (triplet-prefix (string-append ,(boot-triplet) "-")))
1719 (define (has-triplet-prefix? name)
1720 (string-prefix? triplet-prefix name))
1721 (define (remove-triplet-prefix name)
1722 (substring name (string-length triplet-prefix)))
1723 (with-directory-excursion (string-append out "/bin")
1724 (for-each (lambda (name)
1725 (symlink name (remove-triplet-prefix name)))
1726 (scandir "." has-triplet-prefix?)))
1727 #t))))
1728
1729 ,@(substitute-keyword-arguments (package-arguments binutils)
1730 ((#:configure-flags cf)
1731 `(cons ,(string-append "--target=" (boot-triplet))
1732 ,cf)))))
1733 (inputs (%boot0-inputs))))
1734
1735 (define libstdc++-boot0
1736 ;; GCC's libcc1 is always built as a shared library (the top-level
1737 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1738 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
1739 ;; C++14 features missing in some of our bootstrap compilers.
1740 (let ((lib (make-libstdc++ gcc-4.9)))
1741 (package
1742 (inherit lib)
1743 (source (bootstrap-origin (package-source lib)))
1744 (name "libstdc++-boot0")
1745 (arguments
1746 `(#:guile ,%bootstrap-guile
1747 #:implicit-inputs? #f
1748
1749 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1750 #:validate-runpath? #f
1751
1752 ,@(match (%current-system)
1753 ((or "i686-linux" "x86_64-linux")
1754 (substitute-keyword-arguments (package-arguments lib)
1755 ((#:phases phases)
1756 `(modify-phases ,phases
1757 (add-after 'unpack 'workaround-wrapper-bug
1758 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1759 ;; fail, which in turn confuses the configure script.
1760 (lambda _
1761 (substitute* "libstdc++-v3/configure"
1762 (("g\\+\\+ -v") "true"))
1763 #t))))))
1764 (_ (package-arguments lib)))))
1765 (inputs (%boot0-inputs))
1766 (native-inputs '()))))
1767
1768 (define gcc-boot0
1769 (package
1770 (inherit gcc)
1771 (name "gcc-cross-boot0")
1772 (source (bootstrap-origin (package-source gcc)))
1773 (arguments
1774 `(#:guile ,%bootstrap-guile
1775 #:implicit-inputs? #f
1776 #:modules ((guix build gnu-build-system)
1777 (guix build utils)
1778 (ice-9 regex)
1779 (srfi srfi-1)
1780 (srfi srfi-26))
1781 ,@(substitute-keyword-arguments (package-arguments gcc)
1782 ((#:configure-flags flags)
1783 `(append (list ,(string-append "--target=" (boot-triplet))
1784
1785 ;; No libc yet.
1786 "--without-headers"
1787
1788 ;; Disable features not needed at this stage.
1789 "--disable-shared"
1790 "--enable-languages=c,c++"
1791
1792 ;; libstdc++ cannot be built at this stage
1793 ;; ("Link tests are not allowed after
1794 ;; GCC_NO_EXECUTABLES.").
1795 "--disable-libstdc++-v3"
1796
1797 "--disable-threads"
1798 "--disable-libmudflap"
1799 "--disable-libatomic"
1800 "--disable-libsanitizer"
1801 "--disable-libitm"
1802 "--disable-libgomp"
1803 "--disable-libmpx"
1804 "--disable-libcilkrts"
1805 "--disable-libvtv"
1806 "--disable-libssp"
1807 "--disable-libquadmath"
1808 "--disable-decimal-float")
1809 (remove (cut string-match
1810 "--(with-system-zlib|enable-languages.*)" <>)
1811 ,flags)))
1812 ((#:make-flags flags)
1813 `(let* ((libc (assoc-ref %build-inputs "libc"))
1814 (libc-native (or (assoc-ref %build-inputs "libc-native")
1815 libc)))
1816 `(,(string-append "LDFLAGS="
1817 "-Wl,-rpath=" libc-native "/lib "
1818 "-Wl,-dynamic-linker "
1819 "-Wl," libc-native ,(glibc-dynamic-linker
1820 (match (%current-system)
1821 ("x86_64-linux" "i686-linux")
1822 (_ (%current-system))))))))
1823 ((#:phases phases)
1824 `(modify-phases ,phases
1825 (add-after 'unpack 'unpack-gmp&co
1826 (lambda* (#:key inputs #:allow-other-keys)
1827 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1828 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1829 (mpc (assoc-ref %build-inputs "mpc-source")))
1830
1831 ;; To reduce the set of pre-built bootstrap inputs, build
1832 ;; GMP & co. from GCC.
1833 (for-each (lambda (source)
1834 (invoke "tar" "xvf" source))
1835 (list gmp mpfr mpc))
1836
1837 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1838 ,@(map (lambda (lib)
1839 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1840 ;; into gmp-6.0.0.
1841 `(symlink ,(string-trim-right
1842 (package-full-name lib "-")
1843 char-set:letter)
1844 ,(package-name lib)))
1845 (list gmp-6.0 mpfr mpc))
1846 #t)))
1847 ,(match (%current-system)
1848 ((or "i686-linux" "x86_64-linux")
1849 '(add-before 'configure 'fix-libcc1
1850 (lambda* (#:key inputs #:allow-other-keys)
1851 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
1852 ;; to placate the 'validate-runpath' phase.
1853 (substitute* "libcc1/Makefile.in"
1854 (("la_LDFLAGS =")
1855 (string-append "la_LDFLAGS = -Wl,-rpath="
1856 (assoc-ref inputs "gcc") "/lib")))
1857 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
1858 (substitute* "libcc1/configure"
1859 (("g\\+\\+ -v") "true"))
1860 #t)))
1861 (_ '(add-before 'configure 'return-true
1862 (lambda _ #t))))
1863 (add-after 'install 'symlink-libgcc_eh
1864 (lambda* (#:key outputs #:allow-other-keys)
1865 (let ((out (assoc-ref outputs "lib")))
1866 ;; Glibc wants to link against libgcc_eh, so provide
1867 ;; it.
1868 (with-directory-excursion
1869 (string-append out "/lib/gcc/"
1870 ,(boot-triplet)
1871 "/" ,(package-version gcc))
1872 (symlink "libgcc.a" "libgcc_eh.a"))
1873 #t))))))))
1874
1875 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
1876 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
1877 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
1878 ("binutils-cross" ,binutils-boot0)
1879
1880 ;; The libstdc++ that libcc1 links against.
1881 ("libstdc++" ,libstdc++-boot0)
1882
1883 ;; Call it differently so that the builder can check whether
1884 ;; the "libc" input is #f.
1885 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
1886 ,@(alist-delete "libc" (%boot0-inputs))))
1887
1888 ;; No need for the native-inputs to build the documentation at this stage.
1889 (native-inputs `())))
1890
1891 (define perl-boot0
1892 (package
1893 (inherit perl)
1894 (name "perl-boot0")
1895 (source (bootstrap-origin (package-source perl)))
1896 (inputs (%boot0-inputs))
1897 (arguments
1898 `(#:implicit-inputs? #f
1899 #:guile ,%bootstrap-guile
1900 #:validate-runpath? #f
1901
1902 ;; At the very least, this must not depend on GCC & co.
1903 #:disallowed-references ,(list %bootstrap-binutils)
1904
1905 ,@(substitute-keyword-arguments (package-arguments perl)
1906 ((#:phases phases)
1907 `(modify-phases ,phases
1908 ;; Pthread support is missing in the bootstrap compiler
1909 ;; (broken spec file), so disable it.
1910 (add-before 'configure 'disable-pthreads
1911 (lambda _
1912 (substitute* "Configure"
1913 (("^libswanted=(.*)pthread" _ before)
1914 (string-append "libswanted=" before)))
1915 #t))))
1916 ;; Do not configure with '-Dusethreads' since pthread
1917 ;; support is missing.
1918 ((#:configure-flags configure-flags)
1919 `(delete "-Dusethreads" ,configure-flags)))))))
1920
1921 (define m4-boot0
1922 (package
1923 (inherit m4)
1924 (name "m4-boot0")
1925 (source (bootstrap-origin (package-source m4)))
1926 (inputs (%boot0-inputs))
1927 (arguments
1928 `(#:guile ,%bootstrap-guile
1929 #:implicit-inputs? #f
1930 ,@(package-arguments m4)))))
1931
1932 (define bison-boot0
1933 ;; This Bison is needed to build MiG so we need it early in the process.
1934 ;; Recent versions of Linux-Libre headers also depend on this.
1935 (package
1936 (inherit bison)
1937 (name "bison-boot0")
1938 (propagated-inputs `(("m4" ,m4-boot0)))
1939 (native-inputs `(("perl" ,perl-boot0)))
1940 (inputs (%boot0-inputs)) ;remove Flex...
1941 (arguments
1942 `(#:tests? #f ;... and thus disable tests
1943 #:implicit-inputs? #f
1944 #:guile ,%bootstrap-guile
1945
1946 ;; Zero timestamps in liby.a; this must be done
1947 ;; explicitly here because the bootstrap Binutils don't
1948 ;; do that (default is "cru".)
1949 #:make-flags `("ARFLAGS=crD"
1950 ,,(match (%current-system)
1951 ;; ranlib: '-D': No such file
1952 ((or "i686-linux" "x86_64-linux")
1953 "RANLIB=ranlib")
1954 (_
1955 "RANLIB=ranlib -D"))
1956 "V=1")
1957
1958 ,@(package-arguments bison)))))
1959
1960 (define flex-boot0
1961 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
1962 (package
1963 (inherit flex)
1964 (native-inputs `(("bison" ,bison-boot0)))
1965 (propagated-inputs `(("m4" ,m4-boot0)))
1966 (inputs (%boot0-inputs))
1967 (arguments
1968 `(#:implicit-inputs? #f
1969 #:guile ,%bootstrap-guile
1970 #:tests? #f))))
1971
1972 (define rsync-boot0
1973 (package
1974 (inherit rsync)
1975 (native-inputs `(("perl" ,perl-boot0)))
1976 (inputs (%boot0-inputs))
1977 (arguments
1978 `(#:implicit-inputs? #f
1979 #:guile ,%bootstrap-guile))))
1980
1981 (define linux-libre-headers-boot0
1982 (mlambda ()
1983 "Return Linux-Libre header files for the bootstrap environment."
1984 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
1985 ;; between (gnu packages linux) and this module. Additionally, memoize
1986 ;; the result to play well with further memoization and code that relies
1987 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
1988 (package
1989 (inherit linux-libre-headers)
1990 (arguments
1991 `(#:guile ,%bootstrap-guile
1992 #:implicit-inputs? #f
1993 ,@(package-arguments linux-libre-headers)))
1994 (native-inputs
1995 `(("perl" ,perl-boot0)
1996
1997 ;; Flex and Bison are required since version 4.16.
1998 ("flex" ,flex-boot0)
1999 ("bison" ,bison-boot0)
2000
2001 ;; Rsync is required since version 5.3.
2002 ("rsync" ,rsync-boot0)
2003 ,@(%boot0-inputs))))))
2004
2005 (define with-boot0
2006 (package-with-explicit-inputs %boot0-inputs
2007 %bootstrap-guile))
2008
2009 (define gnumach-headers-boot0
2010 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
2011
2012 (define mig-boot0
2013 (let* ((mig (package
2014 (inherit (package-with-bootstrap-guile mig))
2015 (native-inputs `(("bison" ,bison-boot0)
2016 ("flex" ,flex-boot0)))
2017 (inputs `(("flex" ,flex-boot0)))
2018 (arguments
2019 `(#:configure-flags
2020 `(,(string-append "LDFLAGS=-Wl,-rpath="
2021 (assoc-ref %build-inputs "flex") "/lib/")))))))
2022 (with-boot0 mig)))
2023
2024 (define hurd-headers-boot0
2025 (let ((hurd-headers (package (inherit hurd-headers)
2026 (native-inputs `(("mig" ,mig-boot0)))
2027 (inputs '()))))
2028 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
2029
2030 (define hurd-minimal-boot0
2031 (let ((hurd-minimal (package (inherit hurd-minimal)
2032 (native-inputs `(("mig" ,mig-boot0)))
2033 (inputs '()))))
2034 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
2035
2036 (define hurd-core-headers-boot0
2037 (mlambda ()
2038 "Return the Hurd and Mach headers as well as initial Hurd libraries for
2039 the bootstrap environment."
2040 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
2041 (arguments `(#:guile ,%bootstrap-guile
2042 ,@(package-arguments hurd-core-headers)))
2043 (inputs
2044 `(("gnumach-headers" ,gnumach-headers-boot0)
2045 ("hurd-headers" ,hurd-headers-boot0)
2046 ("hurd-minimal" ,hurd-minimal-boot0)
2047 ,@(%boot0-inputs))))))
2048
2049 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
2050 (match system
2051 ("i586-gnu" (hurd-core-headers-boot0))
2052 (_ (linux-libre-headers-boot0))))
2053
2054 (define texinfo-boot0
2055 ;; Texinfo used to build libc's manual.
2056 ;; We build without ncurses because it fails to build at this stage, and
2057 ;; because we don't need the stand-alone Info reader.
2058 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
2059 (package
2060 (inherit texinfo)
2061 (native-inputs '())
2062 (inputs `(,@(%boot0-inputs)
2063 ("perl" ,perl-boot0)))
2064 (arguments
2065 `(#:implicit-inputs? #f
2066 #:guile ,%bootstrap-guile
2067
2068 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
2069 ;; character type in locale" but we don't have a UTF-8 locale at this
2070 ;; stage, so skip them.
2071 #:tests? #f))))
2072
2073 (define expat-sans-tests
2074 (package
2075 (inherit expat)
2076 (inputs (%boot0-inputs))
2077 (arguments
2078 ;; XXX: Linking 'runtestscpp' fails with things like:
2079 ;;
2080 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
2081 ;;
2082 ;; Skip tests altogether.
2083 `(#:implicit-inputs? #f
2084 #:guile ,%bootstrap-guile
2085
2086 ,@(substitute-keyword-arguments (package-arguments expat)
2087 ((#:configure-flags flags ''())
2088 ;; Since we're not passing the right -Wl,-rpath flags, build the
2089 ;; static library to avoid RUNPATH validation failure.
2090 `(cons "--disable-shared" ,flags))
2091 ((#:tests? _ #f) #f))))))
2092
2093 (define python-boot0
2094 (package
2095 (inherit python-minimal)
2096 ;; We cannot use Python 3.7 and later here, because they require
2097 ;; pthreads, which is missing on non-x86 platforms at this stage.
2098 ;; Python 3.6 technically supports being built without threading
2099 ;; support, but requires additional patches.
2100 (version "3.5.9")
2101 (source (bootstrap-origin
2102 (origin
2103 (method url-fetch)
2104 (uri (string-append "https://www.python.org/ftp/python/"
2105 version "/Python-" version ".tar.xz"))
2106 (sha256
2107 (base32
2108 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
2109 (modules '((guix build utils)))
2110 (snippet
2111 '(begin
2112 ;; Delete the bundled copy of libexpat.
2113 (delete-file-recursively "Modules/expat")
2114 (substitute* "Modules/Setup.dist"
2115 ;; Link Expat instead of embedding the bundled one.
2116 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
2117 #t)))))
2118 (inputs
2119 `(,@(%boot0-inputs)
2120 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
2121 (native-inputs '()) ;and pkg-config
2122 (arguments
2123 `(#:implicit-inputs? #f
2124 #:guile ,%bootstrap-guile
2125
2126 ,@(substitute-keyword-arguments (package-arguments python-minimal)
2127 ;; Disable features that cannot be built at this stage.
2128 ((#:configure-flags _ ''())
2129 `(list "--without-ensurepip"
2130 "--without-threads"))
2131 ;; Clear #:make-flags, such that changes to the regular
2132 ;; Python package won't interfere with this one.
2133 ((#:make-flags _ ''()) ''())
2134 ((#:phases phases)
2135 `(modify-phases ,phases
2136 (add-before 'configure 'disable-modules
2137 (lambda _
2138 (substitute* "setup.py"
2139 ;; Disable ctypes, since it requires libffi.
2140 (("extensions\\.append\\(ctypes\\)") "")
2141 ;; Prevent the 'ossaudiodev' extension from being
2142 ;; built, since it requires Linux headers.
2143 (("'linux', ") ""))
2144 #t))
2145 (delete 'set-TZDIR)))
2146 ((#:tests? _ #f) #f))))))
2147
2148 (define ld-wrapper-boot0
2149 (mlambda ()
2150 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
2151 ;; in their RUNPATH, otherwise validate-runpath will fail.
2152 (make-ld-wrapper "ld-wrapper-boot0"
2153 #:target boot-triplet
2154 #:binutils binutils-boot0
2155 #:guile %bootstrap-guile
2156 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
2157 #:guile-for-build %bootstrap-guile)))
2158
2159 (define (%boot1-inputs)
2160 ;; 2nd stage inputs.
2161 `(("gcc" ,gcc-boot0)
2162 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
2163 ("binutils-cross" ,binutils-boot0)
2164 ,@(alist-delete "binutils" (%boot0-inputs))))
2165
2166 (define glibc-final-with-bootstrap-bash
2167 ;; The final libc, "cross-built". If everything went well, the resulting
2168 ;; store path has no dependencies. Actually, the really-final libc is
2169 ;; built just below; the only difference is that this one uses the
2170 ;; bootstrap Bash.
2171 (package
2172 (inherit glibc)
2173 (name "glibc-intermediate")
2174 (source (bootstrap-origin (package-source glibc)))
2175 (arguments
2176 `(#:guile ,%bootstrap-guile
2177 #:implicit-inputs? #f
2178
2179 ,@(substitute-keyword-arguments (package-arguments glibc)
2180 ((#:configure-flags flags)
2181 `(append (list ,(string-append "--host=" (boot-triplet))
2182 ,(string-append "--build="
2183 (nix-system->gnu-triplet)))
2184 ,flags))
2185 ((#:phases phases)
2186 `(modify-phases ,phases
2187 (add-before 'configure 'pre-configure
2188 (lambda* (#:key inputs #:allow-other-keys)
2189 ;; Don't clobber CPATH with the bootstrap libc.
2190 (setenv "NATIVE_CPATH" (getenv "CPATH"))
2191 (unsetenv "CPATH")
2192
2193 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
2194 ,@(if (hurd-triplet? (%current-system))
2195 `((substitute* "libpthread/Makefile"
2196 (("LDLIBS-pthread.so =.*")
2197 (string-append "LDLIBS-pthread.so = "
2198 (assoc-ref %build-inputs "kernel-headers")
2199 "/lib/libihash.a\n"))))
2200 '())
2201
2202 ;; 'rpcgen' needs native libc headers to be built.
2203 (substitute* "sunrpc/Makefile"
2204 (("sunrpc-CPPFLAGS =.*" all)
2205 (string-append "CPATH = $(NATIVE_CPATH)\n"
2206 "export CPATH\n"
2207 all "\n")))
2208 #t)))))))
2209 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2210 (native-inputs
2211 `(("bison" ,bison-boot0)
2212 ("texinfo" ,texinfo-boot0)
2213 ("perl" ,perl-boot0)
2214 ("python" ,python-boot0)))
2215 (inputs
2216 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2217 ;; it in $CPATH, hence the 'pre-configure' phase above.
2218 ,@(%boot1-inputs)
2219
2220 ;; A native MiG is needed to build Glibc on Hurd.
2221 ,@(if (hurd-triplet? (%current-system))
2222 `(("mig" ,mig-boot0))
2223 '())
2224
2225 ;; A native GCC is needed to build `cross-rpcgen'.
2226 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2227
2228 ;; Here, we use the bootstrap Bash, which is not satisfactory
2229 ;; because we don't want to depend on bootstrap tools.
2230 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
2231
2232 (define (cross-gcc-wrapper gcc binutils glibc bash)
2233 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2234 that makes it available under the native tool names."
2235 (package (inherit gcc)
2236 (name (string-append (package-name gcc) "-wrapped"))
2237 (source #f)
2238 (build-system trivial-build-system)
2239 (outputs '("out"))
2240 (arguments
2241 `(#:guile ,%bootstrap-guile
2242 #:modules ((guix build utils))
2243 #:builder (begin
2244 (use-modules (guix build utils))
2245
2246 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2247 (gcc (assoc-ref %build-inputs "gcc"))
2248 (libc (assoc-ref %build-inputs "libc"))
2249 (bash (assoc-ref %build-inputs "bash"))
2250 (out (assoc-ref %outputs "out"))
2251 (bindir (string-append out "/bin"))
2252 (triplet ,(boot-triplet)))
2253 (define (wrap-program program)
2254 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2255 ;; needs to be told where to find the crt files and
2256 ;; the dynamic linker.
2257 (call-with-output-file program
2258 (lambda (p)
2259 (format p "#!~a/bin/bash
2260 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2261 bash
2262 gcc triplet program
2263 libc libc
2264 ,(glibc-dynamic-linker))))
2265
2266 (chmod program #o555))
2267
2268 (mkdir-p bindir)
2269 (with-directory-excursion bindir
2270 (for-each (lambda (tool)
2271 (symlink (string-append binutils "/bin/"
2272 triplet "-" tool)
2273 tool))
2274 '("ar" "ranlib"))
2275 (for-each wrap-program '("gcc" "g++")))
2276
2277 #t))))
2278 (native-inputs
2279 `(("binutils" ,binutils)
2280 ("gcc" ,gcc)
2281 ("libc" ,glibc)
2282 ("bash" ,bash)))
2283 (inputs '())))
2284
2285 (define gcc-boot0-intermediate-wrapped
2286 (mlambda ()
2287 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2288 ;; non-cross names.
2289 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2290 glibc-final-with-bootstrap-bash
2291 (car (assoc-ref (%boot1-inputs) "bash")))))
2292
2293 (define static-bash-for-glibc
2294 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
2295 (package
2296 (inherit static-bash)
2297 (source (bootstrap-origin (package-source static-bash)))
2298 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2299 ("libc" ,glibc-final-with-bootstrap-bash)
2300 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2301 ,@(fold alist-delete (%boot1-inputs)
2302 '("gcc" "libc"))))
2303 (arguments
2304 `(#:implicit-inputs? #f
2305 #:guile ,%bootstrap-guile
2306
2307 ,@(substitute-keyword-arguments (package-arguments static-bash)
2308 ((#:configure-flags flags '())
2309 ;; Add a '-L' flag so that the pseudo-cross-ld of
2310 ;; BINUTILS-BOOT0 can find libc.a.
2311 `(append ,flags
2312 (list (string-append "LDFLAGS=-static -L"
2313 (assoc-ref %build-inputs
2314 "libc:static")
2315 "/lib")))))))))
2316
2317 (define gettext-boot0
2318 ;; A minimal gettext used during bootstrap.
2319 (package
2320 (inherit gettext-minimal)
2321 (name "gettext-boot0")
2322 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2323 ;; simplify the dependency chain, we stick to this version here.
2324 (version "0.19.8.1")
2325 (source (origin
2326 (method url-fetch)
2327 (uri (string-append "mirror://gnu/gettext/gettext-"
2328 version ".tar.gz"))
2329 (sha256
2330 (base32
2331 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2332 (inputs (%boot1-inputs)) ;zero dependencies
2333 (arguments
2334 `(#:implicit-inputs? #f
2335 #:guile ,%bootstrap-guile
2336 #:tests? #f
2337 #:phases (modify-phases %standard-phases
2338 ;; Build only the tools.
2339 (add-after 'unpack 'chdir
2340 (lambda _
2341 (chdir "gettext-tools")
2342 #t))
2343
2344 ;; Some test programs require pthreads, which we don't have.
2345 (add-before 'configure 'no-test-programs
2346 (lambda _
2347 (substitute* "tests/Makefile.in"
2348 (("^PROGRAMS =.*$")
2349 "PROGRAMS =\n"))
2350 #t)))))))
2351
2352 (define glibc-final
2353 ;; The final glibc, which embeds the statically-linked Bash built above.
2354 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2355 (package/inherit
2356 glibc
2357 (name "glibc")
2358 (source (bootstrap-origin (package-source glibc)))
2359 (inputs `(("static-bash" ,static-bash-for-glibc)
2360 ,@(alist-delete
2361 "static-bash"
2362 (package-inputs glibc-final-with-bootstrap-bash))))
2363
2364 ;; This time we need 'msgfmt' to install all the libc.mo files.
2365 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2366 ("gettext" ,gettext-boot0)))
2367
2368 (propagated-inputs
2369 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2370
2371 ;; The final libc only refers to itself, but the 'debug' output contains
2372 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2373 ;; if 'allowed-references' were per-output.
2374 (arguments
2375 `(#:allowed-references
2376 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2377 static-bash-for-glibc
2378 (package-outputs glibc-final-with-bootstrap-bash))
2379
2380 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2381
2382 (define gcc-boot0-wrapped
2383 (mlambda ()
2384 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2385 ;; non-cross names.
2386 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2387 (car (assoc-ref (%boot1-inputs) "bash")))))
2388
2389 (define (%boot2-inputs)
2390 ;; 3rd stage inputs.
2391 `(("libc" ,glibc-final)
2392 ("libc:static" ,glibc-final "static")
2393 ("gcc" ,(gcc-boot0-wrapped))
2394 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2395
2396 (define binutils-final
2397 (package
2398 (inherit binutils)
2399 (source (bootstrap-origin (package-source binutils)))
2400 (arguments
2401 `(#:guile ,%bootstrap-guile
2402 #:implicit-inputs? #f
2403 #:allowed-references ("out" ,glibc-final)
2404 ,@(package-arguments binutils)))
2405 (inputs (%boot2-inputs))))
2406
2407 (define libstdc++
2408 ;; Intermediate libstdc++ that will allow us to build the final GCC
2409 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2410 (let ((lib (make-libstdc++ gcc)))
2411 (package
2412 (inherit lib)
2413 (source (bootstrap-origin (package-source lib)))
2414 (arguments
2415 `(#:guile ,%bootstrap-guile
2416 #:implicit-inputs? #f
2417 #:allowed-references ("out")
2418
2419 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2420 #:validate-runpath? #f
2421
2422 ;; All of the package arguments from 'make-libstdc++
2423 ;; except for the configure-flags.
2424 ,@(package-arguments lib)
2425 #:configure-flags `("--disable-shared"
2426 "--disable-libstdcxx-dual-abi"
2427 "--disable-libstdcxx-threads"
2428 "--disable-libstdcxx-pch"
2429 ,(string-append "--with-gxx-include-dir="
2430 (assoc-ref %outputs "out")
2431 "/include"))))
2432 (outputs '("out"))
2433 (inputs (%boot2-inputs))
2434 (synopsis "GNU C++ standard library (intermediate)"))))
2435
2436 (define zlib-final
2437 ;; Zlib used by GCC-FINAL.
2438 (package
2439 (inherit zlib)
2440 (arguments
2441 `(#:guile ,%bootstrap-guile
2442 #:implicit-inputs? #f
2443 #:allowed-references ("out" ,glibc-final)
2444 ,@(package-arguments zlib)))
2445 (inputs (%boot2-inputs))))
2446
2447 (define ld-wrapper-boot3
2448 (mlambda ()
2449 ;; A linker wrapper that uses the bootstrap Guile.
2450 (make-ld-wrapper "ld-wrapper-boot3"
2451 #:binutils binutils-final
2452 #:guile %bootstrap-guile
2453 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2454 #:guile-for-build %bootstrap-guile)))
2455
2456 (define gcc-final
2457 ;; The final GCC.
2458 (package (inherit gcc-boot0)
2459 (name "gcc")
2460
2461 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2462 ;; "debug" output contains disallowed references, notably
2463 ;; linux-libre-headers. Disable the debugging output to work around that.
2464 (outputs (delete "debug" (package-outputs gcc-boot0)))
2465
2466 (arguments
2467 `(#:guile ,%bootstrap-guile
2468 #:implicit-inputs? #f
2469
2470 #:allowed-references ("out" "lib" ,zlib-final
2471 ,glibc-final ,static-bash-for-glibc)
2472
2473 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2474 ;; reason, but it is not in their RUNPATH. This is a false
2475 ;; positive, so turn it off.
2476 #:validate-runpath? #f
2477
2478 ,@(substitute-keyword-arguments (package-arguments gcc)
2479 ((#:make-flags flags)
2480 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2481 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2482 (map (lambda (flag)
2483 (if (string-prefix? "LDFLAGS=" flag)
2484 (string-append flag " -L"
2485 (assoc-ref %build-inputs "libstdc++")
2486 "/lib -L" zlib "/lib -Wl,-rpath="
2487 zlib "/lib")
2488 flag))
2489 ,flags)))
2490 ;; Build again GMP & co. within GCC's build process, because it's hard
2491 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2492 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2493 ((#:phases phases)
2494 `(modify-phases ,phases
2495 (add-after 'unpack 'unpack-gmp&co
2496 (lambda* (#:key inputs #:allow-other-keys)
2497 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2498 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2499 (mpc (assoc-ref %build-inputs "mpc-source")))
2500
2501 ;; To reduce the set of pre-built bootstrap inputs, build
2502 ;; GMP & co. from GCC.
2503 (for-each (lambda (source)
2504 (invoke "tar" "xvf" source))
2505 (list gmp mpfr mpc))
2506
2507 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2508 ,@(map (lambda (lib)
2509 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2510 ;; into gmp-6.0.0.
2511 `(symlink ,(string-trim-right
2512 (package-full-name lib "-")
2513 char-set:letter)
2514 ,(package-name lib)))
2515 (list gmp-6.0 mpfr mpc))
2516 #t))))))))
2517
2518 ;; This time we want Texinfo, so we get the manual. Add
2519 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2520 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2521 ;; scripts?).
2522 (native-inputs `(("texinfo" ,texinfo-boot0)
2523 ("perl" ,perl-boot0) ;for manpages
2524 ("static-bash" ,static-bash-for-glibc)
2525 ,@(package-native-inputs gcc-boot0)))
2526
2527 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2528 ("mpfr-source" ,(package-source mpfr))
2529 ("mpc-source" ,(package-source mpc))
2530 ("ld-wrapper" ,(ld-wrapper-boot3))
2531 ("binutils" ,binutils-final)
2532 ("libstdc++" ,libstdc++)
2533 ("zlib" ,zlib-final)
2534 ,@(%boot2-inputs)))))
2535
2536 (define (%boot3-inputs)
2537 ;; 4th stage inputs.
2538 `(("gcc" ,gcc-final)
2539 ("ld-wrapper" ,(ld-wrapper-boot3))
2540 ,@(alist-delete "gcc" (%boot2-inputs))))
2541
2542 (define bash-final
2543 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2544 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2545 ;; on Readline and ncurses.
2546 (let ((bash (static-libgcc-package bash-minimal)))
2547 (package
2548 (inherit bash)
2549 (source (bootstrap-origin (package-source bash)))
2550 (inputs (%boot3-inputs))
2551 (arguments
2552 `(#:implicit-inputs? #f
2553 #:guile ,%bootstrap-guile
2554
2555 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2556
2557 ,@(package-arguments bash))))))
2558
2559 (define (%boot4-inputs)
2560 ;; Now use the final Bash.
2561 `(("bash" ,bash-final)
2562 ,@(alist-delete "bash" (%boot3-inputs))))
2563
2564 (define with-boot4
2565 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2566
2567 (define-public guile-final
2568 ;; This package must be public because other modules refer to it. However,
2569 ;; mark it as hidden so that 'fold-packages' ignores it.
2570 (with-boot4 (hidden-package
2571 (package-with-bootstrap-guile guile-2.2/fixed))))
2572
2573 (define glibc-utf8-locales-final
2574 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2575 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2576 ;; with the full range of Unicode codepoints (remember
2577 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2578 ;; function.)
2579 (package
2580 (inherit glibc-utf8-locales)
2581 (native-inputs
2582 `(("glibc" ,glibc-final)
2583 ("gzip" ,(with-boot4 gzip))))))
2584
2585 (define-public ld-wrapper
2586 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2587 (make-ld-wrapper "ld-wrapper"
2588 #:binutils binutils-final
2589 #:guile guile-final
2590 #:bash bash-final))
2591
2592 (define (%boot5-inputs)
2593 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2594 ;; with an older libc, which cannot load the new locale format. See
2595 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2596 `(("locales" ,glibc-utf8-locales-final)
2597 ,@(%boot4-inputs)))
2598
2599 (define with-boot5
2600 (package-with-explicit-inputs %boot5-inputs))
2601
2602 (define gnu-make-final
2603 ;; The final GNU Make, which uses the final Guile.
2604 (let ((pkg-config (package
2605 (inherit %pkg-config) ;the native pkg-config
2606 (inputs `(("guile" ,guile-final)
2607 ,@(%boot5-inputs)))
2608 (arguments
2609 `(#:implicit-inputs? #f
2610 ,@(package-arguments pkg-config))))))
2611 (package
2612 (inherit (package-with-bootstrap-guile gnu-make))
2613 (inputs `(("guile" ,guile-final)
2614 ,@(%boot5-inputs)))
2615 (native-inputs `(("pkg-config" ,pkg-config)))
2616 (arguments
2617 `(#:implicit-inputs? #f
2618 ,@(package-arguments gnu-make))))))
2619
2620
2621 (define coreutils-final
2622 ;; The final Coreutils. Treat them specially because some packages, such as
2623 ;; Findutils, keep a reference to the Coreutils they were built with.
2624 (with-boot5 (package-with-bootstrap-guile coreutils)
2625 ;; Use the final Guile, linked against the
2626 ;; final libc with working iconv, so that
2627 ;; 'substitute*' works well when touching
2628 ;; test files in Gettext.
2629 ))
2630
2631 (define grep-final
2632 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2633 ;; built before gzip.
2634 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2635 (package/inherit grep
2636 (inputs (alist-delete "pcre" (package-inputs grep)))
2637 (native-inputs `(("perl" ,perl-boot0))))))
2638
2639 (define (%boot6-inputs)
2640 ;; Now use the final Coreutils.
2641 `(("coreutils" ,coreutils-final)
2642 ("grep" ,grep-final)
2643 ,@(%boot5-inputs)))
2644
2645 (define with-boot6
2646 (package-with-explicit-inputs %boot6-inputs))
2647
2648 (define sed-final
2649 ;; The final sed.
2650 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2651 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2652
2653 (define-public %final-inputs
2654 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2655 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2656 ;; used for origins that have patches, thereby avoiding circular
2657 ;; dependencies.
2658 (let ((finalize (compose with-boot6
2659 package-with-bootstrap-guile)))
2660 `(,@(map (match-lambda
2661 ((name package)
2662 (list name (finalize package))))
2663 `(("tar" ,tar)
2664 ("gzip" ,gzip)
2665 ("bzip2" ,bzip2)
2666 ("xz" ,xz)
2667 ("file" ,file)
2668 ("diffutils" ,diffutils)
2669 ("patch" ,patch)
2670 ("findutils" ,findutils)
2671 ("gawk" ,gawk)))
2672 ("sed" ,sed-final)
2673 ("grep" ,grep-final)
2674 ("coreutils" ,coreutils-final)
2675 ("make" ,gnu-make-final)
2676 ("bash" ,bash-final)
2677 ("ld-wrapper" ,ld-wrapper)
2678 ("binutils" ,binutils-final)
2679 ("gcc" ,gcc-final)
2680 ("libc" ,glibc-final)
2681 ("libc:static" ,glibc-final "static")
2682 ("locales" ,glibc-utf8-locales-final))))
2683
2684 (define-public canonical-package
2685 (let ((name->package (fold (lambda (input result)
2686 (match input
2687 ((_ package . outputs)
2688 (vhash-cons (package-full-name package)
2689 package result))))
2690 vlist-null
2691 `(("guile" ,guile-final)
2692 ,@%final-inputs))))
2693 (lambda (package)
2694 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2695 the implicit inputs of 'gnu-build-system', return that one, otherwise return
2696 PACKAGE.
2697
2698 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
2699 COREUTILS-FINAL vs. COREUTILS, etc."
2700 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2701 ;; libunistring, GMP, etc.
2702 (match (vhash-assoc (package-full-name package) name->package)
2703 ((_ . canon)
2704 ;; In general we want CANON, except if we're cross-compiling: CANON
2705 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2706 ;; process, with dependencies on things that cannot be
2707 ;; cross-compiled.
2708 (if (%current-target-system)
2709 package
2710 canon))
2711 (_ package)))))
2712
2713 \f
2714 ;;;
2715 ;;; GCC toolchain.
2716 ;;;
2717
2718 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2719 ;; instantiated like this:
2720 ;;
2721 ;; (define-public gcc-glibc-2.27-toolchain
2722 ;; (make-gcc-toolchain gcc glibc-2.27))
2723
2724 (define* (make-gcc-toolchain gcc
2725 #:optional
2726 (libc #f))
2727 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2728 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2729 (libc (if libc libc glibc-final)))
2730 (package
2731 (name (string-append (package-name gcc) "-toolchain"))
2732 (version (package-version gcc))
2733 (source #f)
2734 (build-system trivial-build-system)
2735 (arguments
2736 '(#:modules ((guix build union))
2737 #:builder (begin
2738 (use-modules (ice-9 match)
2739 (srfi srfi-26)
2740 (guix build union))
2741
2742 (let ((out (assoc-ref %outputs "out")))
2743
2744 (match %build-inputs
2745 (((names . directories) ...)
2746 (union-build out directories)))
2747
2748 (union-build (assoc-ref %outputs "debug")
2749 (list (assoc-ref %build-inputs
2750 "libc-debug")))
2751 (union-build (assoc-ref %outputs "static")
2752 (list (assoc-ref %build-inputs
2753 "libc-static")))
2754 #t))))
2755
2756 (native-search-paths (package-native-search-paths gcc))
2757 (search-paths (package-search-paths gcc))
2758
2759 (license (package-license gcc))
2760 (synopsis "Complete GCC tool chain for C/C++ development")
2761 (description
2762 "This package provides a complete GCC tool chain for C/C++ development to
2763 be installed in user profiles. This includes GCC, as well as libc (headers and
2764 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
2765 (home-page "https://gcc.gnu.org/")
2766 (outputs '("out" "debug" "static"))
2767
2768 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2769 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2770 ;; before Binutils' ld in the user's profile.
2771 (inputs `(("gcc" ,gcc)
2772 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2773 ("binutils" ,binutils-final)
2774 ("libc" ,libc)
2775 ("libc-debug" ,libc "debug")
2776 ("libc-static" ,libc "static"))))))
2777
2778 (define-public gcc-toolchain
2779 (make-gcc-toolchain gcc-final))
2780
2781 (define-public gcc-toolchain-4.8
2782 (make-gcc-toolchain gcc-4.8))
2783
2784 (define-public gcc-toolchain-4.9
2785 (make-gcc-toolchain gcc-4.9))
2786
2787 (define-public gcc-toolchain-5
2788 (make-gcc-toolchain gcc-5))
2789
2790 (define-public gcc-toolchain-6
2791 (make-gcc-toolchain gcc-6))
2792
2793 (define-public gcc-toolchain-7
2794 gcc-toolchain)
2795
2796 (define-public gcc-toolchain-8
2797 (make-gcc-toolchain gcc-8))
2798
2799 (define-public gcc-toolchain-9
2800 (make-gcc-toolchain gcc-9))
2801
2802 ;; Provide the Fortran toolchain package only for the version of gfortran that
2803 ;; is used by Guix internally to build Fortran libraries, because combining
2804 ;; code compiled with different versions can cause problems.
2805
2806 (define-public gfortran-toolchain
2807 (package (inherit (make-gcc-toolchain gfortran))
2808 (synopsis "Complete GCC tool chain for Fortran development")
2809 (description "This package provides a complete GCC tool chain for
2810 Fortran development to be installed in user profiles. This includes
2811 gfortran, as well as libc (headers and binaries, plus debugging symbols
2812 in the @code{debug} output), and binutils.")))
2813
2814
2815 ;;; commencement.scm ends here