gnu: commencement: diffutils-mesboot: Use Gash instead of coretutils&co.
[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 %bootstrap-mes-rewired
392 (package
393 (inherit mes)
394 (name "bootstrap-mes-rewired")
395 (version "0.19")
396 (source #f)
397 (native-inputs `(("mes" ,(@ (gnu packages bootstrap) %bootstrap-mes))
398 ("gash" ,gash-boot)))
399 (inputs '())
400 (propagated-inputs '())
401 (outputs '("out"))
402 (build-system trivial-build-system)
403 (arguments
404 `(#:guile ,%bootstrap-guile
405 #:modules ((guix build utils)
406 (srfi srfi-26))
407 #:builder (begin
408 (use-modules (guix build utils)
409 (srfi srfi-26))
410 (let* ((mes (assoc-ref %build-inputs "mes"))
411 (gash (assoc-ref %build-inputs "gash"))
412 (mes-bin (string-append mes "/bin"))
413 (guile (string-append mes-bin "/mes"))
414 (mes-module (string-append mes "/share/mes/module"))
415 (out (assoc-ref %outputs "out"))
416 (bin (string-append out "/bin"))
417 (mescc (string-append bin "/mescc"))
418 (module (string-append out "/share/mes/module")))
419 (define (rewire file)
420 (substitute* file
421 ((mes) out)
422 (("/gnu/store[^ ]+mes-minimal-[^/)}\"]*") out)
423 (("/gnu/store[^ ]+guile-[^/]*/bin/guile") guile)
424 (("/gnu/store[^ ]+bash-[^/)}\"]*") gash)))
425
426 (mkdir-p bin)
427 (for-each (lambda (file) (install-file file bin))
428 (find-files mes-bin))
429 (mkdir-p module)
430 (copy-recursively (string-append mes-module "/mes")
431 (string-append module "/mes"))
432 (copy-recursively (string-append mes-module "/srfi")
433 (string-append module "/srfi"))
434 (for-each rewire
435 ;; Cannot easily rewire "mes" because it
436 ;; contains NUL characters; would require
437 ;; remove-store-references alike trick
438 (filter (negate (cut string-suffix? "/mes" <>))
439 (find-files bin)))
440 (rewire (string-append module "/mes/boot-0.scm"))
441
442 (delete-file mescc)
443 (with-output-to-file mescc
444 (lambda _
445 (display (string-append
446 "\
447 #! " gash "/bin/sh
448 LANG=C
449 LC_ALL=C
450 export LANG LC_ALL
451
452 MES_PREFIX=${MES_REWIRED_PREFIX-" out "/share/mes}
453 MES=" bin "/mes
454 export MES MES_PREFIX
455
456 MES_ARENA=${MES_REWIRED_ARENA-10000000}
457 MES_MAX_ARENA=${MES_REWIRED_ARENA-10000000}
458 MES_STACK=${MES_REWIRED_STACK-1000000}
459 export MES_ARENA MES_MAX_ARENA MES_STACK
460
461 $MES -e '(mescc)' module/mescc.scm -- \"$@\"
462 "))))
463 (chmod mescc #o555)
464
465 (with-directory-excursion module
466 (chmod "mes/base.mes" #o644)
467 (copy-file "mes/base.mes" "mes/base.mes.orig")
468 (let ((base.mes (open-file "mes/base.mes" "a")))
469 (display "
470 ;; A fixed map, from Mes 0.21, required to bootstrap Mes 0.21
471 (define (map f h . t)
472 (if (or (null? h)
473 (and (pair? t) (null? (car t)))
474 (and (pair? t) (pair? (cdr t)) (null? (cadr t)))) '()
475 (if (null? t) (cons (f (car h)) (map f (cdr h)))
476 (if (null? (cdr t))
477 (cons (f (car h) (caar t)) (map f (cdr h) (cdar t)))
478 (if (null? (cddr t))
479 (cons (f (car h) (caar t) (caadr t)) (map f (cdr h) (cdar t) (cdadr t)))
480 (error 'unsupported (cons* 'map-4: f h t))b )))))
481 " base.mes)
482 (close base.mes))
483
484 (chmod "mes/guile.mes" #o644)
485 (copy-file "mes/guile.mes" "mes/guile.mes.orig")
486 (let ((guile.mes (open-file "mes/guile.mes" "a")))
487 (display "
488 ;; After booting guile.scm; use Mes 0.21; especially: MesCC 0.21
489 (let* ((self (car (command-line)))
490 (prefix (dirname (dirname self))))
491 (set! %moduledir (string-append prefix \"/mes/module/\"))
492 (setenv \"%numbered_arch\" \"true\"))
493
494 " guile.mes)
495 (close guile.mes)))
496 #t))))))
497
498 (define mes-boot
499 (package
500 (inherit mes)
501 (name "mes-boot")
502 (version "0.21-33-g6d493b90d")
503 (source (origin
504 (method url-fetch)
505 (uri (string-append "http://lilypond.org/janneke/mes/"
506 "mes-" version ".tar.gz"))
507 (sha256
508 (base32
509 "0nr74zyam5n82svjwfbcz2mycj88vvsqab12x0mxv1lm6yqxqmmj"))))
510 (inputs '())
511 (propagated-inputs '())
512 (native-inputs
513 `(("nyacc-source" ,(origin (inherit (package-source nyacc))
514 (snippet #f)))
515 ("mes" ,%bootstrap-mes-rewired)
516 ("mescc-tools" ,%bootstrap-mescc-tools)
517 ,@(%boot-gash-inputs)))
518 (arguments
519 `(#:implicit-inputs? #f
520 #:tests? #f
521 #:guile ,%bootstrap-guile
522 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
523 #:phases
524 (modify-phases %standard-phases
525 (add-after 'unpack 'unpack-seeds
526 (lambda _
527 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
528 (with-directory-excursion ".."
529 (invoke "tar" "-xvf" nyacc-source)))))
530 (replace 'configure
531 (lambda* (#:key outputs #:allow-other-keys)
532 (let ((out (assoc-ref %outputs "out"))
533 (gash (assoc-ref %build-inputs "bash"))
534 (mes (assoc-ref %build-inputs "mes"))
535 (dir (with-directory-excursion ".." (getcwd))))
536 (setenv "AR" (string-append "gash " (getcwd) "/scripts/mesar"))
537 (setenv "BASH" (string-append gash "/bin/bash"))
538 (setenv "CC" (string-append mes "/bin/mescc"))
539 (setenv "GUILE_LOAD_PATH"
540 (string-append
541 mes "/share/mes/module"
542 ":" dir "/nyacc-0.99.0/module"
543 ":" (getenv "GUILE_LOAD_PATH")))
544 (invoke "gash" "configure.sh"
545 (string-append "--prefix=" out)
546 (string-append "--host=i686-linux-gnu")))))
547 (replace 'build
548 (lambda _
549 (invoke "sh" "bootstrap.sh")))
550 (delete 'check)
551 (replace 'install
552 (lambda _
553 (substitute* "install.sh" ; show some progress
554 ((" -xf") " -xvf")
555 (("^( *)((cp|mkdir|tar) [^']*[^\\])\n" all space cmd)
556 (string-append space "echo '" cmd "'\n"
557 space cmd "\n")))
558 (invoke "sh" "install.sh")
559 ;; Keep ASCII output, for friendlier comparison and bisection
560 (let* ((out (assoc-ref %outputs "out"))
561 (cache (string-append out "/lib/cache")))
562 (define (objects-in-dir dir)
563 (find-files dir
564 (lambda (name stat)
565 (and (equal? (dirname name) dir)
566 (or (string-suffix? ".o" name)
567 (string-suffix? ".s" name))))))
568 (for-each (lambda (x) (install-file x cache))
569 (append (objects-in-dir ".")
570 (objects-in-dir "mescc-lib"))))
571 #t)))))
572 (native-search-paths
573 (list (search-path-specification
574 (variable "C_INCLUDE_PATH")
575 (files '("include")))
576 (search-path-specification
577 (variable "LIBRARY_PATH")
578 (files '("lib")))
579 (search-path-specification
580 (variable "MES_PREFIX")
581 (separator #f)
582 (files '("")))))))
583
584
585 (define tcc-boot0
586 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
587 ;; patches. In a very early and rough form they were presented to the
588 ;; TinyCC developers, who at the time showed no interest in supporting the
589 ;; bootstrappable effort; we will try again later. These patches have been
590 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
591 ;; mature, this package should use the 0.9.27 sources (or later).
592 (package
593 (inherit tcc)
594 (name "tcc-boot0")
595 (version "0.9.26-1103-g6e62e0e")
596 (source (origin
597 (method url-fetch)
598 (uri (string-append
599 "http://lilypond.org/janneke/mes/20191117/"
600 "/tcc-" version ".tar.gz"))
601 (sha256
602 (base32
603 "1qbybw7mxbgkv3sazvz1v7c8byq998vk8f1h25ik8w3d2l63lxng"))))
604 (build-system gnu-build-system)
605 (supported-systems '("i686-linux" "x86_64-linux"))
606 (inputs '())
607 (propagated-inputs '())
608 (native-inputs
609 `(("mes" ,mes-boot)
610 ("nyacc-source" ,(origin (inherit (package-source nyacc))
611 (snippet #f)))
612 ("mescc-tools" ,%bootstrap-mescc-tools)
613 ,@(%boot-gash-inputs)))
614 (arguments
615 `(#:implicit-inputs? #f
616 #:guile ,%bootstrap-guile
617 #:validate-runpath? #f ; no dynamic executables
618 #:strip-binaries? #f ; no strip yet
619 #:phases
620 (modify-phases %standard-phases
621 (add-after 'unpack 'unpack-seeds
622 (lambda* (#:key outputs #:allow-other-keys)
623 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
624 (with-directory-excursion ".."
625 (invoke "tar" "-xvf" nyacc-source)))))
626 (replace 'configure
627 (lambda* (#:key outputs #:allow-other-keys)
628 (let* ((out (assoc-ref %outputs "out"))
629 (dir (with-directory-excursion ".." (getcwd)))
630 (interpreter "/lib/mes-loader"))
631
632 (setenv "prefix" out)
633 (setenv "GUILE_LOAD_PATH"
634 (string-append dir "/nyacc-0.99.0/module"))
635
636 (substitute* "conftest.c"
637 (("volatile") ""))
638
639 (invoke "sh" "configure"
640 "--cc=mescc"
641 (string-append "--prefix=" out)
642 (string-append "--elfinterp=" interpreter)
643 "--crtprefix=."
644 "--tccdir=."))))
645 (replace 'build
646 (lambda _
647 (substitute* "bootstrap.sh" ; Show some progress
648 (("^( *)((cp|ls|mkdir|rm|[.]/tcc|[.]/[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
649 (string-append space "echo \"" cmd "\"\n"
650 space cmd "\n")))
651 (invoke "sh" "bootstrap.sh")))
652 (replace 'check
653 (lambda _
654 ;; fail fast tests
655 (system* "./tcc" "--help") ; --help exits 1
656 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
657 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
658 ;; TODO: add sensible check target (without depending on make)
659 ;; (invoke "sh" "check.sh")
660 #t))
661 (replace 'install
662 (lambda _
663 (substitute* "install.sh" ; Show some progress
664 (("^( *)((cp|ls|mkdir|rm|tar|./[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
665 (string-append space "echo \"" cmd "\"\n"
666 space cmd "\n")))
667
668 (invoke "sh" "install.sh"))))))
669 (native-search-paths
670 (list (search-path-specification
671 (variable "C_INCLUDE_PATH")
672 (files '("include")))
673 (search-path-specification
674 (variable "LIBRARY_PATH")
675 (files '("lib")))))))
676
677 (define gzip-mesboot
678 ;; The initial gzip. We keep this scripted gzip build before building make
679 ;; to soften the dependency on Gash Core Utils gzip.
680 (package
681 (inherit gzip)
682 (version "1.2.4")
683 (name "gzip-mesboot")
684 (source (origin
685 (method url-fetch)
686 (uri (string-append "mirror://gnu/gzip/gzip-" version ".tar"))
687 (sha256
688 (base32
689 "1rhgk2vvmdvnn6vygf0dja92ryyng00knl0kz5srb77k2kryjb2d"))))
690 (supported-systems '("i686-linux" "x86_64-linux"))
691 (inputs '())
692 (propagated-inputs '())
693 (native-inputs `(("tcc" ,tcc-boot0)
694 ,@(%boot-gash-inputs)))
695 (arguments
696 `(#:implicit-inputs? #f
697 #:guile ,%bootstrap-guile
698 #:strip-binaries? #f ; no strip yet
699 #:phases
700 (modify-phases %standard-phases
701 (delete 'configure)
702 (add-after 'unpack 'scripted-patch
703 (lambda _
704 (substitute* "util.c"
705 (("^char [*]strlwr" all) (string-append all "_tcc_cannot_handle_dupe")))
706 #t))
707 (replace 'build
708 (lambda _
709 (let ((files '("bits" "crypt" "deflate" "getopt" "gzip"
710 "inflate" "lzw" "trees" "unlzh" "unlzw"
711 "unpack" "unzip" "util" "zip")))
712 (define (compile x)
713 (invoke "tcc" "-c" "-D NO_UTIME=1" "-D HAVE_UNISTD_H=1"
714 (string-append x ".c")))
715 (for-each compile files)
716 (apply invoke
717 (cons* "tcc" "-o" "gzip"
718 (map (lambda (x) (string-append x ".o")) files)))
719 (link "gzip" "gunzip"))))
720 (replace 'install
721 (lambda _
722 (let* ((out (assoc-ref %outputs "out"))
723 (bin (string-append out "/bin")))
724 (install-file "gzip" bin)
725 (install-file "gunzip" bin))))
726 (replace 'check
727 (lambda _
728 (invoke "./gzip" "--version")))
729 ;; no gzip yet
730 (delete 'compress-documentation))))))
731
732 (define make-mesboot0
733 ;; The initial make
734 (package
735 (inherit gnu-make)
736 (name "make-mesboot0")
737 (version "3.80")
738 (source (origin
739 (method url-fetch)
740 (uri (string-append "mirror://gnu/make/make-" version ".tar.gz"))
741 (sha256
742 (base32
743 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
744 (supported-systems '("i686-linux" "x86_64-linux"))
745 (inputs '())
746 (propagated-inputs '())
747 (native-inputs `(("tcc" ,tcc-boot0)
748 ,@(%boot-gash-inputs)))
749 (arguments
750 `(#:implicit-inputs? #f
751 #:guile ,%bootstrap-guile
752 #:configure-flags '("CC=tcc"
753 "CPP=tcc -E"
754 "LD=tcc"
755 "--build=i686-unknown-linux-gnu"
756 "--host=i686-unknown-linux-gnu"
757 "--disable-nls")
758 #:modules ((guix build gnu-build-system)
759 (guix build utils)
760 (srfi srfi-1))
761 #:strip-binaries? #f ; no strip yet
762 #:phases
763 (modify-phases %standard-phases
764 (add-after 'unpack 'scripted-patch
765 (lambda _
766 (substitute* "build.sh.in"
767 (("@LIBOBJS@") "getloadavg.o")
768 (("@REMOTE@") "stub"))
769 #t))
770 (add-after 'configure 'configure-fixup
771 (lambda _
772 (substitute* "make.h"
773 (("^extern long int lseek.*" all) (string-append "// " all)))
774 #t))
775 (replace 'build
776 (lambda _
777 (invoke "sh" "./build.sh")))
778 (replace 'check ; proper check needs awk
779 (lambda _
780 (invoke "./make" "--version")))
781 (replace 'install
782 (lambda _
783 (let* ((out (assoc-ref %outputs "out"))
784 (bin (string-append out "/bin")))
785 (install-file "make" bin)))))))))
786
787 (define (%boot-tcc0-inputs)
788 `(("make" ,make-mesboot0)
789 ("tcc" ,tcc-boot0)
790 ,@(%boot-gash-inputs)))
791
792 (define bzip2-mesboot
793 ;; The initial bzip2
794 (package
795 (inherit bzip2)
796 (name "bzip2-mesboot")
797 (version (package-version bzip2))
798 (source (bootstrap-origin (package-source bzip2)))
799 (supported-systems '("i686-linux" "x86_64-linux"))
800 (inputs '())
801 (propagated-inputs '())
802 (native-inputs (%boot-tcc0-inputs))
803 (outputs '("out"))
804 (arguments
805 `(#:implicit-inputs? #f
806 #:guile ,%bootstrap-guile
807 #:parallel-build? #f
808 #:tests? #f ; check is naive, also checks non-built PROGRAMS
809 #:strip-binaries? #f ; no strip yet
810 #:make-flags (list "CC=tcc -I ." "AR=tcc -ar" "bzip2"
811 (string-append "PREFIX="
812 (assoc-ref %outputs "out")))
813 #:phases
814 (modify-phases %standard-phases
815 (add-after 'unpack 'scripted-patch
816 (lambda _
817 (substitute* "Makefile"
818 (("\tln " all)
819 (string-append "\t#" all)))
820 (substitute* "bzip2.c"
821 (("struct utimbuf uTimBuf;" all)
822 (string-append "// " all))
823 (("uTimBuf[.]" all)
824 (string-append "// " all))
825 (("retVal = utime [(] dstName, &uTimBuf [)];" all)
826 (string-append "retVal = 0; // " all)))
827 #t))
828 (replace 'configure
829 (lambda _
830 (with-output-to-file "utime.h"
831 (lambda _ (display "
832 #define fchown(filedes, owner, group) 0
833 #define fchmod(filedes, mode) 0
834 ")))
835 #t))
836 (replace 'check
837 (lambda _
838 (invoke "./bzip2" "--help")))
839 ;; FIXME: no compressing gzip yet
840 (delete 'compress-documentation))))))
841
842 (define bash-mesboot0
843 ;; The initial Bash
844 (package
845 (inherit static-bash)
846 (name "bash-mesboot0")
847 (version "2.05b")
848 (source (origin
849 (method url-fetch)
850 (uri (string-append "mirror://gnu/bash/bash-"
851 version ".tar.gz"))
852 (sha256
853 (base32
854 "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs"))))
855 (inputs '())
856 (propagated-inputs '())
857 (native-inputs (%boot-tcc0-inputs))
858 (outputs '("out"))
859 (arguments
860 `(#:implicit-inputs? #f
861 #:guile ,%bootstrap-guile
862 #:parallel-build? #f
863 #:strip-binaries? #f ; no strip yet
864 #:configure-flags
865 (list "--build=i686-unknown-linux-gnu"
866 "--host=i686-unknown-linux-gnu"
867
868 "--without-bash-malloc"
869 "--disable-readline"
870 "--disable-history"
871 "--disable-help-builtin"
872 "--disable-progcomp"
873 "--disable-net-redirections"
874 "--disable-nls"
875
876 ;; Pretend 'dlopen' is missing so we don't build loadable
877 ;; modules and related code.
878 "ac_cv_func_dlopen=no")
879 #:make-flags '("bash")
880 #:phases
881 (modify-phases %standard-phases
882 (add-before 'configure 'setenv
883 (lambda _
884 (let* ((gash (assoc-ref %build-inputs "bash"))
885 (shell (string-append gash "/bin/gash")))
886 (setenv "CONFIG_SHELL" shell)
887 (setenv "SHELL" shell)
888 (setenv "CC" "tcc")
889 (setenv "LD" "tcc")
890 (setenv "AR" "tcc -ar")
891 (setenv "CFLAGS" "-D _POSIX_VERSION=1")
892 #t)))
893 (add-after 'unpack 'scripted-patch
894 (lambda _
895 (substitute* "Makefile.in"
896 (("mksyntax\\.c\n") "mksyntax.c -lgetopt\n")
897 (("buildversion[.]o\n") "buildversion.o -lgetopt\n")
898 ;; No size in Gash
899 (("\tsize ") "#\tsize"))
900 (substitute* "lib/sh/oslib.c"
901 (("int name, namelen;") "char *name; int namelen;"))
902 (substitute* "lib/sh/snprintf.c"
903 (("^#if (defined [(]HAVE_LOCALE_H[)])" all define) (string-append "#if 0 //" define)))
904 (substitute* "configure"
905 ((" egrep") " grep"))
906 #t))
907 (replace 'configure
908 (lambda* (#:key configure-flags #:allow-other-keys)
909 (let ((configure-flags (filter (lambda (x)
910 (and (not (string-prefix? "CONFIG_SHELL=" x))
911 (not (string-prefix? "SHELL=" x))))
912 configure-flags)))
913 (format (current-error-port)
914 "running ./configure ~a\n" (string-join configure-flags)))
915 (apply invoke (cons "./configure" configure-flags))))
916 (add-after 'configure 'configure-fixups
917 (lambda _
918 (substitute* "config.h"
919 (("#define GETCWD_BROKEN 1") "#undef GETCWD_BROKEN"))
920 (let ((config.h (open-file "config.h" "a")))
921 (display (string-append "
922 // tcc: error: undefined symbol 'enable_hostname_completion'
923 #define enable_hostname_completion(on_or_off) 0
924
925 // /gnu/store/cq0cmv35s9dhilx14zaghlc08gpc0hwr-tcc-boot0-0.9.26-6.c004e9a/lib/libc.a: error: 'sigprocmask' defined twice
926 #define HAVE_POSIX_SIGNALS 1
927 #define endpwent(x) 0
928 ")
929 config.h)
930 (close config.h))
931 #t))
932 (replace 'check
933 (lambda _
934 (invoke "./bash" "--version")))
935 (replace 'install
936 (lambda _
937 (let* ((out (assoc-ref %outputs "out"))
938 (bin (string-append out "/bin")))
939 (mkdir-p bin)
940 (copy-file "bash" (string-append bin "/bash"))
941 (copy-file "bash" (string-append bin "/sh"))
942 #t))))))))
943
944 (define tcc-boot
945 ;; The final tcc.
946 (package
947 (inherit tcc-boot0)
948 (name "tcc-boot")
949 (version "0.9.27")
950 (source (origin
951 (inherit (package-source tcc))
952 ;; `patches' needs XZ
953 ;; (patches (search-patches "tcc-boot-0.9.27.patch"))
954 ))
955 (build-system gnu-build-system)
956 (inputs '())
957 (propagated-inputs '())
958 (native-inputs `(;;("boot-patch" ,(search-patch "tcc-boot-0.9.27.patch"))
959 ("bzip2" ,bzip2-mesboot)
960 ,@(%boot-tcc0-inputs)))
961 (arguments
962 `(#:implicit-inputs? #f
963 #:guile ,%bootstrap-guile
964 #:validate-runpath? #f ; no dynamic executables
965 #:strip-binaries? #f ; no strip yet
966 #:phases
967 (modify-phases %standard-phases
968 ;; tar xvf ..bz2 gives
969 ;; bzip2: PANIC -- internal consistency error
970 (replace 'unpack
971 (lambda* (#:key source #:allow-other-keys)
972 (copy-file source "tarball.tar.bz2")
973 (invoke "bzip2" "-d" "tarball.tar.bz2")
974 (invoke "tar" "xvf" "tarball.tar")
975 (chdir (string-append "tcc-" ,version))
976 #t))
977 ;; no patch yet
978 ;; (add-after 'unpack 'apply-boot-patch
979 ;; (lambda* (#:key inputs #:allow-other-keys)
980 ;; (let ((patch-file (assoc-ref inputs "boot-patch")))
981 ;; (invoke "patch" "-p1" "-i" patch-file))))
982 (add-after 'unpack 'scripted-patch
983 (lambda* (#:key inputs #:allow-other-keys)
984 (substitute* "libtcc.c"
985 (("s->alacarte_link = 1;" all)
986 (string-append all "
987 s->static_link = 1;")))
988 #t))
989 (replace 'configure
990 (lambda* (#:key outputs #:allow-other-keys)
991 (let* ((out (assoc-ref %outputs "out"))
992 (tcc (assoc-ref %build-inputs "tcc"))
993 (libc (assoc-ref %build-inputs "libc"))
994 (interpreter "/mes/loader"))
995 (invoke "sh" "configure"
996 (string-append "--cc=tcc")
997 (string-append "--cpu=i386")
998 (string-append "--prefix=" out)
999 (string-append "--elfinterp=" interpreter)
1000 (string-append "--crtprefix=" tcc "/lib")
1001 (string-append "--sysincludepaths=" tcc "/include")
1002 (string-append "--libpaths=" tcc "/lib")))))
1003 (replace 'build
1004 (lambda* (#:key outputs #:allow-other-keys)
1005 (let* ((out (assoc-ref %outputs "out"))
1006 (tcc (assoc-ref %build-inputs "tcc"))
1007 (libc (assoc-ref %build-inputs "libc"))
1008 (interpreter "/mes/loader"))
1009 (invoke
1010 "tcc"
1011 "-vvv"
1012 "-D" "BOOTSTRAP=1"
1013 "-D" "ONE_SOURCE=1"
1014 "-D" "TCC_TARGET_I386=1"
1015 "-D" "CONFIG_TCC_STATIC=1"
1016 "-D" "CONFIG_USE_LIBGCC=1"
1017 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
1018 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
1019 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
1020 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
1021 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
1022 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\""
1023 tcc "/include" ":/include:{B}/include\"")
1024 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
1025 "-o" "tcc"
1026 "tcc.c"))))
1027 (replace 'check
1028 (lambda _
1029 ;; FIXME: add sensible check target (without depending on make)
1030 ;; ./check.sh ?
1031 (= 1 (status:exit-val (system* "./tcc" "--help")))))
1032 (replace 'install
1033 (lambda* (#:key outputs #:allow-other-keys)
1034 (let ((out (assoc-ref %outputs "out"))
1035 (tcc (assoc-ref %build-inputs "tcc")))
1036 (and
1037 (mkdir-p (string-append out "/bin"))
1038 (copy-file "tcc" (string-append out "/bin/tcc"))
1039 (mkdir-p (string-append out "/lib/tcc"))
1040 (copy-recursively (string-append tcc "/include")
1041 (string-append out "/include"))
1042 (copy-recursively (string-append tcc "/lib")
1043 (string-append out "/lib"))
1044 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
1045 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
1046 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
1047 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
1048 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
1049 #t)))))))))
1050
1051 (define diffutils-mesboot
1052 ;; The initial diffutils.
1053 (package
1054 (inherit diffutils)
1055 (name "diffutils-mesboot")
1056 (version "2.7")
1057 (source (origin
1058 (method url-fetch)
1059 (uri (string-append "mirror://gnu/diffutils/diffutils-"
1060 version ".tar.gz"))
1061 (sha256
1062 (base32
1063 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
1064 (supported-systems '("i686-linux" "x86_64-linux"))
1065 (inputs '())
1066 (propagated-inputs '())
1067 (native-inputs (%boot-tcc0-inputs))
1068 (arguments
1069 `(#:implicit-inputs? #f
1070 #:guile ,%bootstrap-guile
1071 #:parallel-build? #f
1072 #:tests? #f ; check is naive, also checks non-built PROGRAMS
1073 #:strip-binaries? #f ; no strip yet
1074 #:phases
1075 (modify-phases %standard-phases
1076 (add-before 'configure 'remove-diff3-sdiff
1077 (lambda* (#:key outputs #:allow-other-keys)
1078 (substitute* "Makefile.in"
1079 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))))
1080 (replace 'configure ; needs classic invocation of configure
1081 (lambda* (#:key configure-flags #:allow-other-keys)
1082 (let* ((out (assoc-ref %outputs "out"))
1083 (bash (assoc-ref %build-inputs "bash"))
1084 (shell (string-append bash "/bin/bash")))
1085 (setenv "CONFIG_SHELL" shell)
1086 (setenv "CC" "tcc")
1087 (setenv "LD" "tcc")
1088 (format (current-error-port)
1089 "running ./configure ~a\n" (string-join configure-flags))
1090 (apply invoke (cons "./configure" configure-flags)))))
1091 (replace 'install
1092 (lambda _
1093 (let* ((out (assoc-ref %outputs "out"))
1094 (bin (string-append out "/bin")))
1095 (mkdir-p bin)
1096 (install-file "cmp" bin)
1097 (install-file "diff" bin)
1098 #t))))))))
1099
1100 (define binutils-mesboot0
1101 (package
1102 (inherit binutils)
1103 (name "binutils-mesboot0")
1104 (version "2.20.1a")
1105 (source (bootstrap-origin
1106 (origin
1107 (method url-fetch)
1108 (uri (string-append "mirror://gnu/binutils/binutils-"
1109 version ".tar.bz2"))
1110 (patches (search-patches "binutils-boot-2.20.1a.patch"))
1111 (sha256
1112 (base32
1113 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
1114 (inputs '())
1115 (propagated-inputs '())
1116 (native-inputs `(("tcc" ,tcc-boot)
1117
1118 ("bash" ,%bootstrap-coreutils&co)
1119 ("coreutils" ,%bootstrap-coreutils&co)
1120 ("diffutils" ,diffutils-mesboot)
1121 ("make" ,make-mesboot0)))
1122 (supported-systems '("i686-linux" "x86_64-linux"))
1123 (arguments
1124 `(#:implicit-inputs? #f
1125 #:guile ,%bootstrap-guile
1126 #:tests? #f ; runtest: command not found
1127 #:parallel-build? #f
1128 #:strip-binaries? #f ; no strip yet
1129 #:configure-flags
1130 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
1131 " -D MES_BOOTSTRAP=1"))
1132 (bash (assoc-ref %build-inputs "bash")))
1133 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
1134 ,(string-append "CPPFLAGS=" cppflags)
1135 "AR=tcc -ar"
1136 "CXX=false"
1137 "RANLIB=true"
1138 ,(string-append "CC=tcc" cppflags)
1139 "--disable-nls"
1140 "--disable-shared"
1141 "--disable-werror"
1142 "--build=i686-unknown-linux-gnu"
1143 "--host=i686-unknown-linux-gnu"
1144 "--with-sysroot=/"))))))
1145
1146 (define gcc-core-mesboot
1147 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
1148 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
1149 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
1150 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
1151 ;; toolchain triplet "that works".
1152 (package
1153 (inherit gcc)
1154 (name "gcc-core-mesboot")
1155 (version "2.95.3")
1156 (source (bootstrap-origin
1157 (origin
1158 (method url-fetch)
1159 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
1160 version
1161 ".tar.gz"))
1162 (patches (search-patches "gcc-boot-2.95.3.patch"))
1163 (sha256
1164 (base32
1165 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
1166 (supported-systems '("i686-linux" "x86_64-linux"))
1167 (inputs '())
1168 (propagated-inputs '())
1169 (native-inputs `(("binutils" ,binutils-mesboot0)
1170 ("tcc" ,tcc-boot)
1171
1172 ("bash" ,%bootstrap-coreutils&co)
1173 ("coreutils" ,%bootstrap-coreutils&co)
1174 ("diffutils" ,diffutils-mesboot)
1175 ("make" ,make-mesboot0)))
1176 (outputs '("out"))
1177 (arguments
1178 `(#:implicit-inputs? #f
1179 #:guile ,%bootstrap-guile
1180 #:tests? #f
1181 #:parallel-build? #f
1182 #:strip-binaries? #f
1183 #:configure-flags
1184 (let ((out (assoc-ref %outputs "out")))
1185 `("--enable-static"
1186 "--disable-shared"
1187 "--disable-werror"
1188 "--build=i686-unknown-linux-gnu"
1189 "--host=i686-unknown-linux-gnu"
1190 ,(string-append "--prefix=" out)))
1191 #:make-flags (list
1192 "CC=tcc -static -D __GLIBC_MINOR__=6"
1193 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
1194 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
1195 "AR=ar"
1196 "RANLIB=ranlib"
1197 (string-append "LIBGCC2_INCLUDES=-I "
1198 (assoc-ref %build-inputs "tcc")
1199 "/include")
1200 "LANGUAGES=c"
1201 (string-append "BOOT_LDFLAGS="
1202 " -B" (assoc-ref %build-inputs "tcc")
1203 "/lib/"))
1204 #:modules ((guix build gnu-build-system)
1205 (guix build utils)
1206 (srfi srfi-1))
1207 #:phases
1208 (modify-phases %standard-phases
1209 ;; gcc-2.95.3 needs more traditional configure
1210 (add-before 'configure 'setenv
1211 (lambda* (#:key outputs #:allow-other-keys)
1212 (let ((out (assoc-ref outputs "out"))
1213 (bash (assoc-ref %build-inputs "bash"))
1214 (tcc (assoc-ref %build-inputs "tcc"))
1215 (cppflags " -D __GLIBC_MINOR__=6"))
1216 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1217 (setenv "CPPFLAGS" cppflags)
1218 (setenv "CC" (string-append "tcc" cppflags))
1219 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
1220 (setenv "CPP" (string-append "tcc -E" cppflags))
1221 (with-output-to-file "config.cache"
1222 (lambda _
1223 (display "
1224 ac_cv_c_float_format='IEEE (little-endian)'
1225 ")))
1226 #t)))
1227 (replace 'configure
1228 (lambda* (#:key configure-flags #:allow-other-keys)
1229 (format (current-error-port)
1230 "running ./configure ~a\n" (string-join configure-flags))
1231 (apply invoke "./configure" configure-flags)))
1232 (add-after 'configure 'remove-info
1233 (lambda _
1234 ;; no info at this stage
1235 (delete-file-recursively "texinfo")
1236 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
1237 (add-after 'install 'install2
1238 (lambda* (#:key outputs #:allow-other-keys)
1239 (let* ((tcc (assoc-ref %build-inputs "tcc"))
1240 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
1241 (out (assoc-ref outputs "out"))
1242 (gcc-dir (string-append
1243 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1244 (mkdir-p "tmp")
1245 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1246 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1247 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1248 (copy-file (string-append tcc "/lib/libtcc1.a")
1249 (string-append out "/lib/libtcc1.a"))
1250 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
1251 (string-append tcc-lib "/libc+gnu.o")
1252 (string-append tcc-lib "/libtcc1.o"))
1253 (invoke "ar" "r" (string-append out "/lib/libc.a")
1254 (string-append tcc-lib "/libc+gnu.o")
1255 (string-append tcc-lib "/libtcc1.o"))
1256 (invoke "ls" "-ltrF" gcc-dir)
1257 #t))))))
1258 (native-search-paths
1259 (list (search-path-specification
1260 (variable "C_INCLUDE_PATH")
1261 (files '("include"
1262
1263 ;; Needed to get things like GCC's <stddef.h>.
1264 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
1265 (search-path-specification
1266 (variable "LIBRARY_PATH")
1267 (files '("lib")))))))
1268
1269 (define mesboot-headers
1270 (package
1271 (inherit mes-boot)
1272 (name "mesboot-headers")
1273 (supported-systems '("i686-linux" "x86_64-linux"))
1274 (inputs '())
1275 (propagated-inputs '())
1276 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
1277 ("headers" ,%bootstrap-linux-libre-headers)))
1278 (arguments
1279 `(#:implicit-inputs? #f
1280 #:guile ,%bootstrap-guile
1281 #:tests? #f
1282 #:strip-binaries? #f
1283 #:phases
1284 (modify-phases %standard-phases
1285 (delete 'configure)
1286 (delete 'build)
1287 (replace 'install
1288 (lambda* (#:key outputs #:allow-other-keys)
1289 (let* ((out (assoc-ref outputs "out"))
1290 (include (string-append out "/include"))
1291 (headers (assoc-ref %build-inputs "headers" )))
1292 (mkdir-p include)
1293 (copy-recursively "include" out)
1294 (copy-recursively headers out)
1295 #t))))))))
1296
1297 (define glibc-mesboot0
1298 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
1299 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
1300 ;; gcc.
1301 (package
1302 (inherit glibc)
1303 (name "glibc-mesboot0")
1304 (version "2.2.5")
1305 (source (bootstrap-origin
1306 (origin
1307 (method url-fetch)
1308 (uri (string-append "mirror://gnu/glibc/glibc-"
1309 version
1310 ".tar.gz"))
1311 (patches (search-patches "glibc-boot-2.2.5.patch"))
1312 (sha256
1313 (base32
1314 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
1315 (supported-systems '("i686-linux" "x86_64-linux"))
1316 (inputs '())
1317 (propagated-inputs '())
1318 (native-inputs `(("binutils" ,binutils-mesboot0)
1319 ("gcc" ,gcc-core-mesboot)
1320
1321 ("bash" ,%bootstrap-coreutils&co)
1322 ("coreutils" ,%bootstrap-coreutils&co)
1323 ("diffutils" ,diffutils-mesboot)
1324 ("headers" ,mesboot-headers)
1325 ("make" ,make-mesboot0)))
1326 (outputs '("out"))
1327 (arguments
1328 `(#:implicit-inputs? #f
1329 #:guile ,%bootstrap-guile
1330 #:tests? #f
1331 #:strip-binaries? #f
1332 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1333 #:make-flags (list (string-append
1334 "SHELL="
1335 (assoc-ref %build-inputs "bash")
1336 "/bin/sh"))
1337 #:configure-flags
1338 (let ((out (assoc-ref %outputs "out"))
1339 (headers (assoc-ref %build-inputs "headers")))
1340 (list
1341 "--disable-shared"
1342 "--enable-static"
1343 "--disable-sanity-checks"
1344 "--build=i686-unknown-linux-gnu"
1345 "--host=i686-unknown-linux-gnu"
1346 (string-append "--with-headers=" headers "/include")
1347 "--enable-static-nss"
1348 "--without-__thread"
1349 "--without-cvs"
1350 "--without-gd"
1351 "--without-tls"
1352 (string-append "--prefix=" out)))
1353 #:phases
1354 (modify-phases %standard-phases
1355 (add-before 'configure 'setenv
1356 (lambda* (#:key outputs #:allow-other-keys)
1357 (let* ((out (assoc-ref outputs "out"))
1358 (bash (assoc-ref %build-inputs "bash"))
1359 (gcc (assoc-ref %build-inputs "gcc"))
1360 (headers (assoc-ref %build-inputs "headers"))
1361 (cppflags (string-append
1362 ;;" -D __STDC__=1"
1363 " -D MES_BOOTSTRAP=1"
1364 " -D BOOTSTRAP_GLIBC=1"))
1365 (cflags (string-append " -L " (getcwd))))
1366 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1367 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1368 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1369 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1370 #t)))
1371 ;; glibc-2.2.5 needs a more classic invocation of configure
1372 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
1373 (replace 'configure
1374 (lambda* (#:key configure-flags #:allow-other-keys)
1375 (format (current-error-port)
1376 "running ./configure ~a\n" (string-join configure-flags))
1377 (apply invoke "./configure" configure-flags))))))))
1378
1379 (define gcc-mesboot0
1380 (package
1381 (inherit gcc-core-mesboot)
1382 (name "gcc-mesboot0")
1383 (native-inputs `(("binutils" ,binutils-mesboot0)
1384
1385 ;; Packages are given in an order that's relevant for
1386 ;; #include_next purposes.
1387 ("libc" ,glibc-mesboot0)
1388 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1389 ("gcc" ,gcc-core-mesboot)
1390
1391 ("bash" ,%bootstrap-coreutils&co)
1392 ("coreutils" ,%bootstrap-coreutils&co)
1393 ("diffutils" ,diffutils-mesboot)
1394 ("make" ,make-mesboot0)))
1395 (arguments
1396 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1397 ((#:phases phases)
1398 `(modify-phases ,phases
1399 (replace 'setenv
1400 (lambda _
1401 (setenv "CONFIG_SHELL" (which "sh"))
1402 (with-output-to-file "config.cache"
1403 (lambda _
1404 (display "
1405 ac_cv_c_float_format='IEEE (little-endian)'
1406 ")))
1407 #t))
1408 (replace 'install2
1409 (lambda* (#:key outputs #:allow-other-keys)
1410 (let* ((out (assoc-ref outputs "out"))
1411 (gcc-dir (string-append
1412 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1413 (mkdir-p "tmp")
1414 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1415 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1416 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1417 #t)))))
1418 ((#:configure-flags configure-flags)
1419 `(let ((out (assoc-ref %outputs "out")))
1420 `("--disable-shared"
1421 "--disable-werror"
1422 "--build=i686-unknown-linux-gnu"
1423 "--host=i686-unknown-linux-gnu"
1424 ,(string-append "--prefix=" out))))
1425 ((#:make-flags make-flags)
1426 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1427 `("RANLIB=true"
1428 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1429 "LANGUAGES=c")))))))
1430
1431 (define binutils-mesboot
1432 (package
1433 (inherit binutils-mesboot0)
1434 (name "binutils-mesboot")
1435 (native-inputs `(("binutils" ,binutils-mesboot0)
1436 ("libc" ,glibc-mesboot0)
1437 ("gcc" ,gcc-mesboot0)
1438
1439 ("bash" ,%bootstrap-coreutils&co)
1440 ("coreutils" ,%bootstrap-coreutils&co)
1441 ("diffutils" ,diffutils-mesboot)
1442 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1443 ("make" ,make-mesboot0)))
1444 (arguments
1445 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1446 ((#:configure-flags configure-flags)
1447 '(list "--disable-nls"
1448 "--disable-shared"
1449 "--disable-werror"
1450 "--build=i686-unknown-linux-gnu"
1451 "--host=i686-unknown-linux-gnu"
1452 "--with-sysroot=/"))))))
1453
1454 (define make-mesboot
1455 (package
1456 (inherit make-mesboot0)
1457 (name "make-mesboot")
1458 (version "3.82")
1459 (source (origin
1460 (method url-fetch)
1461 (uri (string-append "mirror://gnu/make/make-"
1462 version ".tar.gz"))
1463 (sha256
1464 (base32
1465 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1466 (native-inputs `(("binutils" ,binutils-mesboot0)
1467 ("libc" ,glibc-mesboot0)
1468 ("gcc" ,gcc-mesboot0)
1469 ("make" ,make-mesboot0)
1470
1471 ("bash" ,%bootstrap-coreutils&co)
1472 ("coreutils" ,%bootstrap-coreutils&co)
1473 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
1474 (arguments
1475 (substitute-keyword-arguments (package-arguments make-mesboot0)
1476 ((#:configure-flags configure-flags)
1477 `(let ((out (assoc-ref %outputs "out")))
1478 `(,(string-append "--prefix=" out))))
1479 ((#:phases phases)
1480 `(modify-phases ,phases
1481 (delete 'configure-fixup)
1482 (add-before 'configure 'setenv
1483 (lambda _
1484 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1485 #t))))))))
1486
1487 (define gmp-boot
1488 (package
1489 (inherit gmp)
1490 (version "4.3.2")
1491 (source (origin
1492 (method url-fetch)
1493 (uri (string-append "mirror://gnu/gmp/gmp-" version
1494 ".tar.gz"))
1495 (sha256 (base32
1496 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1497
1498 (define mpfr-boot
1499 (package
1500 (inherit mpfr)
1501 (version "2.4.2")
1502 (source (origin
1503 (method url-fetch)
1504 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1505 ".tar.gz"))
1506 (sha256 (base32
1507 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1508
1509 (define mpc-boot
1510 (package
1511 (inherit mpc)
1512 (version "1.0.3")
1513 (source (origin
1514 (method url-fetch)
1515 (uri (string-append
1516 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1517 (sha256
1518 (base32
1519 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1520
1521 (define gcc-mesboot1
1522 (package
1523 (inherit gcc-mesboot0)
1524 (name "gcc-mesboot1")
1525 (version (package-version gcc-4.7))
1526 (source (bootstrap-origin
1527 (origin (inherit (package-source gcc-4.7))
1528 (patches (search-patches "gcc-boot-4.7.4.patch")))))
1529 (inputs `(("gmp-source" ,(package-source gmp-boot))
1530 ("mpfr-source" ,(package-source mpfr-boot))
1531 ("mpc-source" ,(package-source mpc-boot))))
1532 (native-inputs `(("binutils" ,binutils-mesboot)
1533
1534 ("libc" ,glibc-mesboot0)
1535 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1536 ("gcc" ,gcc-mesboot0)
1537
1538 ("bash" ,%bootstrap-coreutils&co)
1539 ("coreutils" ,%bootstrap-coreutils&co)
1540 ("diffutils" ,diffutils-mesboot)
1541 ("make" ,make-mesboot)))
1542 (arguments
1543 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1544 ((#:make-flags make-flags)
1545 `(let* ((libc (assoc-ref %build-inputs "libc"))
1546 (ldflags (string-append
1547 "-B" libc "/lib "
1548 "-Wl,-dynamic-linker "
1549 "-Wl," libc
1550 ,(glibc-dynamic-linker "i686-linux"))))
1551 (list (string-append "LDFLAGS=" ldflags)
1552 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
1553 ((#:phases phases)
1554 `(modify-phases ,phases
1555 ;; c&p from commencement.scm:gcc-boot0
1556 (add-after 'unpack 'unpack-gmp&co
1557 (lambda* (#:key inputs #:allow-other-keys)
1558 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1559 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1560 (mpc (assoc-ref %build-inputs "mpc-source")))
1561
1562 ;; To reduce the set of pre-built bootstrap inputs, build
1563 ;; GMP & co. from GCC.
1564 (for-each (lambda (source)
1565 (or (invoke "tar" "xvf" source)
1566 (error "failed to unpack tarball"
1567 source)))
1568 (list gmp mpfr mpc))
1569
1570 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1571 ,@(map (lambda (lib)
1572 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1573 ;; into gmp-6.0.0.
1574 `(symlink ,(string-trim-right
1575 (package-full-name lib "-")
1576 char-set:letter)
1577 ,(package-name lib)))
1578 (list gmp-boot mpfr-boot mpc-boot))
1579 #t)))
1580 (delete 'remove-info)
1581 (replace 'setenv
1582 (lambda _
1583 (setenv "CONFIG_SHELL" (which "sh"))
1584
1585 ;; Allow MPFR headers to be found.
1586 (setenv "C_INCLUDE_PATH"
1587 (string-append (getcwd) "/mpfr/src:"
1588 (getenv "C_INCLUDE_PATH")))
1589
1590 ;; Set the C++ search path so that C headers can be found as
1591 ;; libstdc++ is being compiled.
1592 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
1593 #t))
1594 (delete 'install2)))
1595 ((#:configure-flags configure-flags)
1596 `(let ((out (assoc-ref %outputs "out"))
1597 (glibc (assoc-ref %build-inputs "libc")))
1598 (list (string-append "--prefix=" out)
1599 "--build=i686-unknown-linux-gnu"
1600 "--host=i686-unknown-linux-gnu"
1601
1602 (string-append "--with-native-system-header-dir=" glibc "/include")
1603 (string-append "--with-build-sysroot=" glibc "/include")
1604
1605 "--disable-bootstrap"
1606 "--disable-decimal-float"
1607 "--disable-libatomic"
1608 "--disable-libcilkrts"
1609 "--disable-libgomp"
1610 "--disable-libitm"
1611 "--disable-libmudflap"
1612 "--disable-libquadmath"
1613 "--disable-libsanitizer"
1614 "--disable-libssp"
1615 "--disable-libvtv"
1616 "--disable-lto"
1617 "--disable-lto-plugin"
1618 "--disable-multilib"
1619 "--disable-plugin"
1620 "--disable-threads"
1621 "--enable-languages=c,c++"
1622
1623 "--enable-static"
1624 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1625 "--disable-shared"
1626 "--enable-threads=single"
1627
1628 ;; No pre-compiled libstdc++ headers, to save space.
1629 "--disable-libstdcxx-pch"
1630
1631 ;; for libcpp ...
1632 "--disable-build-with-cxx")))))))
1633
1634 (define gcc-mesboot1-wrapper
1635 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1636 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1637 ;; --enable-shared will fail.
1638 (package
1639 (inherit gcc-mesboot1)
1640 (name "gcc-mesboot1-wrapper")
1641 (source #f)
1642 (inputs '())
1643 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1644 ("libc" ,glibc-mesboot)
1645 ("gcc" ,gcc-mesboot1)))
1646 (arguments
1647 `(#:implicit-inputs? #f
1648 #:guile ,%bootstrap-guile
1649 #:phases
1650 (modify-phases %standard-phases
1651 (delete 'unpack)
1652 (delete 'configure)
1653 (delete 'install)
1654 (replace 'build
1655 (lambda* (#:key outputs #:allow-other-keys)
1656 (let* ((out (assoc-ref outputs "out"))
1657 (bash (assoc-ref %build-inputs "bash"))
1658 (libc (assoc-ref %build-inputs "libc"))
1659 (gcc (assoc-ref %build-inputs "gcc"))
1660 (bin (string-append out "/bin")))
1661 (mkdir-p bin)
1662 (for-each
1663 (lambda (program)
1664 (let ((wrapper (string-append bin "/" program)))
1665 (with-output-to-file wrapper
1666 (lambda _
1667 (display (string-append "#! " bash "/bin/bash
1668 exec " gcc "/bin/" program
1669 " -Wl,--dynamic-linker"
1670 ;; also for x86_64-linux, we are still on i686-linux
1671 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1672 " -Wl,--rpath"
1673 " -Wl," libc "/lib"
1674 " \"$@\"
1675 "))
1676 (chmod wrapper #o555)))))
1677 '(
1678 "gcc"
1679 "g++"
1680 "i686-unknown-linux-gnu-gcc"
1681 "i686-unknown-linux-gnu-g++"
1682 ))
1683 #t)))
1684 (replace 'check
1685 (lambda* (#:key outputs #:allow-other-keys)
1686 (let* ((out (assoc-ref outputs "out"))
1687 (bin (string-append out "/bin"))
1688 (program (string-append bin "/gcc")))
1689 (invoke program "--help")))))))))
1690
1691 (define glibc-headers-mesboot
1692 (package
1693 (inherit glibc-mesboot0)
1694 (name "glibc-headers-mesboot")
1695 (version "2.16.0")
1696 (source (bootstrap-origin
1697 (origin
1698 (method url-fetch)
1699 (uri (string-append "mirror://gnu/glibc/glibc-"
1700 version
1701 ".tar.gz"))
1702 (patches (search-patches "glibc-boot-2.16.0.patch"
1703 "glibc-bootstrap-system-2.16.0.patch"))
1704 (sha256
1705 (base32
1706 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1707 (native-inputs `(("binutils" ,binutils-mesboot)
1708 ("libc" ,glibc-mesboot0)
1709 ("gcc" ,gcc-mesboot1)
1710 ("headers" ,mesboot-headers)
1711
1712 ("bash" ,%bootstrap-coreutils&co)
1713 ("coreutils" ,%bootstrap-coreutils&co)
1714 ("diffutils" ,diffutils-mesboot)
1715 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1716 ("make" ,make-mesboot)))
1717
1718 (arguments
1719 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1720 ((#:configure-flags configure-flags)
1721 `(let ((out (assoc-ref %outputs "out"))
1722 (headers (assoc-ref %build-inputs "headers")))
1723 (list
1724 (string-append "--prefix=" out)
1725 "--disable-obsolete-rpc"
1726 "--host=i686-unknown-linux-gnu"
1727 (string-append "--with-headers=" headers "/include")
1728 "--enable-static-nss"
1729 "--with-pthread"
1730 "--without-cvs"
1731 "--without-gd"
1732 "--enable-add-ons=nptl")))
1733 ((#:make-flags make-flags)
1734 `(let ((bash (assoc-ref %build-inputs "bash")))
1735 (list (string-append "SHELL=" bash "/bin/sh")
1736 "install-bootstrap-headers=yes" "install-headers")))
1737 ((#:phases phases)
1738 `(modify-phases ,phases
1739 (replace 'setenv
1740 (lambda* (#:key inputs #:allow-other-keys)
1741 (let* ((headers (assoc-ref inputs "headers"))
1742 (libc (assoc-ref inputs "libc"))
1743 (gcc (assoc-ref inputs "gcc"))
1744 (cppflags (string-append
1745 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1746 " -D BOOTSTRAP_GLIBC=1"))
1747 (cflags (string-append " -L " (getcwd)
1748 " -L " libc "/lib")))
1749 (setenv "libc_cv_friendly_stddef" "yes")
1750 (setenv "CONFIG_SHELL" (which "sh"))
1751 (setenv "SHELL" (which "sh"))
1752
1753 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1754 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1755
1756 ;; avoid -fstack-protector
1757 (setenv "libc_cv_ssp" "false")
1758 (substitute* "configure"
1759 (("/bin/pwd") "pwd"))
1760 #t)))
1761 (replace 'install
1762 (lambda* (#:key outputs make-flags #:allow-other-keys)
1763 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1764 (out (assoc-ref outputs "out")))
1765 (apply invoke "make" make-flags)
1766 (copy-recursively kernel-headers out)
1767 #t)))
1768 (replace 'configure
1769 (lambda* (#:key configure-flags #:allow-other-keys)
1770 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1771 (mkdir-p "build")
1772 (chdir "build")
1773 (apply invoke "../configure" configure-flags)))
1774 (add-after 'configure 'remove-sunrpc
1775 (lambda _
1776 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1777 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1778 (substitute* "sysd-sorted"
1779 ((" sunrpc") " ")
1780 ((" nis") " "))
1781 ;; 'rpcgen' needs native libc headers to be built.
1782 (substitute* "../Makefile"
1783 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1784 (substitute* "../Makeconfig"
1785 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1786 (substitute* "../elf/Makefile"
1787 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1788
1789 (define glibc-mesboot
1790 (package
1791 (inherit glibc-headers-mesboot)
1792 (name "glibc-mesboot")
1793 (native-inputs `(("binutils" ,binutils-mesboot)
1794 ("libc" ,glibc-mesboot0)
1795 ("headers" ,glibc-headers-mesboot)
1796 ("gcc" ,gcc-mesboot1)
1797
1798 ("bash" ,%bootstrap-coreutils&co)
1799 ("coreutils" ,%bootstrap-coreutils&co)
1800 ("diffutils" ,diffutils-mesboot)
1801 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1802 ("make" ,make-mesboot)))
1803
1804 (arguments
1805 `(#:validate-runpath? #f ; fails when using --enable-shared
1806 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1807 ((#:make-flags make-flags)
1808 `(let ((bash (assoc-ref %build-inputs "bash")))
1809 (list (string-append "SHELL=" bash "/bin/sh"))))
1810 ((#:phases phases)
1811 `(modify-phases ,phases
1812 (replace 'install
1813 (lambda* (#:key outputs make-flags #:allow-other-keys)
1814 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1815 (out (assoc-ref outputs "out"))
1816 (install-flags (cons "install" make-flags)))
1817 (apply invoke "make" install-flags)
1818 (copy-recursively kernel-headers out)
1819 #t))))))))))
1820
1821 (define gcc-mesboot
1822 (package
1823 (inherit gcc-mesboot1)
1824 (name "gcc-mesboot")
1825 (version (package-version gcc-4.9))
1826 (source (bootstrap-origin (package-source gcc-4.9)))
1827 (native-inputs `(("binutils" ,binutils-mesboot)
1828
1829 ("libc" ,glibc-mesboot)
1830 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1831 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1832 ("gcc" ,gcc-mesboot1)
1833
1834 ("bash" ,%bootstrap-coreutils&co)
1835 ("coreutils" ,%bootstrap-coreutils&co)
1836 ("diffutils" ,diffutils-mesboot)
1837 ("make" ,make-mesboot)))
1838 (arguments
1839 `(#:validate-runpath? #f
1840 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1841 ((#:configure-flags configure-flags)
1842 `(let ((out (assoc-ref %outputs "out"))
1843 (glibc (assoc-ref %build-inputs "libc")))
1844 (list (string-append "--prefix=" out)
1845 "--build=i686-unknown-linux-gnu"
1846 "--host=i686-unknown-linux-gnu"
1847
1848 "--with-host-libstdcxx=-lsupc++"
1849
1850 (string-append "--with-native-system-header-dir=" glibc "/include")
1851 (string-append "--with-build-sysroot=" glibc "/include")
1852
1853 "--disable-bootstrap"
1854 "--disable-decimal-float"
1855 "--disable-libatomic"
1856 "--disable-libcilkrts"
1857 "--disable-libgomp"
1858 "--disable-libitm"
1859 "--disable-libmudflap"
1860 "--disable-libquadmath"
1861 "--disable-libsanitizer"
1862 "--disable-libssp"
1863 "--disable-libvtv"
1864 "--disable-lto"
1865 "--disable-lto-plugin"
1866 "--disable-multilib"
1867 "--disable-plugin"
1868 "--disable-threads"
1869 "--enable-languages=c,c++"
1870
1871 "--enable-static"
1872 "--enable-shared"
1873 "--enable-threads=single"
1874
1875 ;; No pre-compiled libstdc++ headers, to save space.
1876 "--disable-libstdcxx-pch"
1877
1878 ;; for libcpp ...
1879 "--disable-build-with-cxx"))))))))
1880
1881 (define gcc-mesboot-wrapper
1882 ;; We need this so gcc-mesboot can be used to create shared binaries that
1883 ;; have the correct interpreter and runpath to libc.
1884 (package
1885 (inherit gcc-mesboot1-wrapper)
1886 (name "gcc-mesboot-wrapper")
1887 (version (package-version gcc-mesboot))
1888 (source #f)
1889 (inputs '())
1890 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1891 ("libc" ,glibc-mesboot)
1892 ("gcc" ,gcc-mesboot)))))
1893
1894 (define m4-mesboot
1895 (package
1896 (inherit m4)
1897 (name "m4-mesboot")
1898 (version "1.4")
1899 (source (origin
1900 (method url-fetch)
1901 (uri (string-append "mirror://gnu/m4/m4-"
1902 version ".tar.gz"))
1903 (sha256
1904 (base32
1905 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1906 (supported-systems '("i686-linux" "x86_64-linux"))
1907 (native-inputs `(("mes" ,mes-boot)
1908 ("tcc" ,tcc-boot)))
1909 (arguments
1910 `(#:phases
1911 (modify-phases %standard-phases
1912 (replace 'configure
1913 (lambda* (#:key outputs #:allow-other-keys)
1914 (let ((out (assoc-ref outputs "out")))
1915 (setenv "CONFIG_SHELL" (string-append
1916 (assoc-ref %build-inputs "bash")
1917 "/bin/sh"))
1918 (setenv "CC" "tcc -static")
1919 (setenv "CPP" "tcc -E")
1920 (invoke "./configure" (string-append "--prefix=" out))))))))))
1921
1922 (define (%bootstrap-inputs+toolchain)
1923 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1924 ;; the actual reduced set with bootstrapped toolchain.
1925 (match (%current-system)
1926 ((or "i686-linux" "x86_64-linux")
1927 `(("libc" ,glibc-mesboot)
1928 ("binutils" ,binutils-mesboot)
1929 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1930 ("gcc" ,gcc-mesboot)
1931 ,@(fold alist-delete (%bootstrap-inputs)
1932 '("bootstrap-mescc-tools" "mes"))))
1933 (_
1934 (%bootstrap-inputs))))
1935
1936 (define gnu-make-boot0
1937 (package
1938 (inherit gnu-make)
1939 (source (bootstrap-origin (package-source gnu-make)))
1940 (name "make-boot0")
1941 (arguments
1942 `(#:guile ,%bootstrap-guile
1943 #:implicit-inputs? #f
1944 #:tests? #f ; cannot run "make check"
1945 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1946 ((#:configure-flags flags ''())
1947 ;; The generated config.status has some problems due to the
1948 ;; bootstrap environment. Disable dependency tracking to work
1949 ;; around it.
1950 `(cons "--disable-dependency-tracking" ,flags))
1951 ((#:phases phases)
1952 `(modify-phases ,phases
1953 (replace 'build
1954 (lambda _
1955 (invoke "./build.sh")))
1956 (replace 'install
1957 (lambda* (#:key outputs #:allow-other-keys)
1958 (let* ((out (assoc-ref outputs "out"))
1959 (bin (string-append out "/bin")))
1960 (install-file "make" bin)
1961 #t))))))))
1962 (native-inputs '()) ; no need for 'pkg-config'
1963 (inputs (%bootstrap-inputs+toolchain))))
1964
1965 (define diffutils-boot0
1966 (package
1967 (inherit diffutils)
1968 (name "diffutils-boot0")
1969 (native-inputs `())
1970 (inputs
1971 `(("make" ,gnu-make-boot0)
1972 ,@(%bootstrap-inputs+toolchain)))
1973 (arguments
1974 `(#:tests? #f ; the test suite needs diffutils
1975 #:guile ,%bootstrap-guile
1976 #:implicit-inputs? #f
1977 ,@(package-arguments diffutils)))))
1978
1979 (define findutils-boot0
1980 (package
1981 (inherit findutils)
1982 (name "findutils-boot0")
1983 (source (bootstrap-origin (package-source findutils)))
1984 (inputs
1985 `(("make" ,gnu-make-boot0)
1986 ("diffutils" ,diffutils-boot0) ; for tests
1987 ,@(%bootstrap-inputs+toolchain)))
1988 (arguments
1989 `(#:implicit-inputs? #f
1990 #:guile ,%bootstrap-guile
1991
1992 ;; The build system assumes we have done a mistake when time_t is 32-bit
1993 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1994 ,@(if (target-64bit?)
1995 (substitute-keyword-arguments (package-arguments findutils)
1996 ((#:configure-flags flags ''())
1997 `(cons "TIME_T_32_BIT_OK=yes"
1998 ,flags)))
1999 (package-arguments findutils))))))
2000
2001 (define file-boot0
2002 (package
2003 (inherit file)
2004 (source (bootstrap-origin (package-source file)))
2005 (name "file-boot0")
2006 (inputs
2007 `(("make" ,gnu-make-boot0)
2008 ,@(%bootstrap-inputs+toolchain)))
2009 (arguments
2010 `(#:implicit-inputs? #f
2011 #:guile ,%bootstrap-guile
2012 #:strip-binaries? #f
2013 #:validate-runpath? #f))))
2014
2015 (define (%boot0-inputs)
2016 `(("make" ,gnu-make-boot0)
2017 ("diffutils" ,diffutils-boot0)
2018 ("findutils" ,findutils-boot0)
2019 ("file" ,file-boot0)
2020 ,@(%bootstrap-inputs+toolchain)))
2021
2022 (define* (boot-triplet #:optional (system (%current-system)))
2023 ;; Return the triplet used to create the cross toolchain needed in the
2024 ;; first bootstrapping stage.
2025 (nix-system->gnu-triplet system "guix"))
2026
2027 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
2028 ;; toolchain actually targets the same OS and arch, but it has the advantage
2029 ;; of being independent of the libc and tools in
2030 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
2031 ;; reference to the target libc.
2032
2033 (define binutils-boot0
2034 (package
2035 (inherit binutils)
2036 (source (bootstrap-origin (package-source binutils)))
2037 (name "binutils-cross-boot0")
2038 (arguments
2039 `(#:guile ,%bootstrap-guile
2040 #:implicit-inputs? #f
2041
2042 #:modules ((guix build gnu-build-system)
2043 (guix build utils)
2044 (ice-9 ftw)) ; for 'scandir'
2045 #:phases (modify-phases %standard-phases
2046 (add-after 'install 'add-symlinks
2047 (lambda* (#:key outputs #:allow-other-keys)
2048 ;; The cross-gcc invokes 'as', 'ld', etc, without the
2049 ;; triplet prefix, so add symlinks.
2050 (let ((out (assoc-ref outputs "out"))
2051 (triplet-prefix (string-append ,(boot-triplet) "-")))
2052 (define (has-triplet-prefix? name)
2053 (string-prefix? triplet-prefix name))
2054 (define (remove-triplet-prefix name)
2055 (substring name (string-length triplet-prefix)))
2056 (with-directory-excursion (string-append out "/bin")
2057 (for-each (lambda (name)
2058 (symlink name (remove-triplet-prefix name)))
2059 (scandir "." has-triplet-prefix?)))
2060 #t))))
2061
2062 ,@(substitute-keyword-arguments (package-arguments binutils)
2063 ((#:configure-flags cf)
2064 `(cons ,(string-append "--target=" (boot-triplet))
2065 ,cf)))))
2066 (inputs (%boot0-inputs))))
2067
2068 (define libstdc++-boot0
2069 ;; GCC's libcc1 is always built as a shared library (the top-level
2070 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
2071 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
2072 ;; C++14 features missing in some of our bootstrap compilers.
2073 (let ((lib (make-libstdc++ gcc-4.9)))
2074 (package
2075 (inherit lib)
2076 (source (bootstrap-origin (package-source lib)))
2077 (name "libstdc++-boot0")
2078 (arguments
2079 `(#:guile ,%bootstrap-guile
2080 #:implicit-inputs? #f
2081
2082 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2083 #:validate-runpath? #f
2084
2085 ,@(match (%current-system)
2086 ((or "i686-linux" "x86_64-linux")
2087 (substitute-keyword-arguments (package-arguments lib)
2088 ((#:phases phases)
2089 `(modify-phases ,phases
2090 (add-after 'unpack 'workaround-wrapper-bug
2091 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
2092 ;; fail, which in turn confuses the configure script.
2093 (lambda _
2094 (substitute* "libstdc++-v3/configure"
2095 (("g\\+\\+ -v") "true"))
2096 #t))))))
2097 (_ (package-arguments lib)))))
2098 (inputs (%boot0-inputs))
2099 (native-inputs '()))))
2100
2101 (define gcc-boot0
2102 (package
2103 (inherit gcc)
2104 (name "gcc-cross-boot0")
2105 (source (bootstrap-origin (package-source gcc)))
2106 (arguments
2107 `(#:guile ,%bootstrap-guile
2108 #:implicit-inputs? #f
2109 #:modules ((guix build gnu-build-system)
2110 (guix build utils)
2111 (ice-9 regex)
2112 (srfi srfi-1)
2113 (srfi srfi-26))
2114 ,@(substitute-keyword-arguments (package-arguments gcc)
2115 ((#:configure-flags flags)
2116 `(append (list ,(string-append "--target=" (boot-triplet))
2117
2118 ;; No libc yet.
2119 "--without-headers"
2120
2121 ;; Disable features not needed at this stage.
2122 "--disable-shared"
2123 "--enable-languages=c,c++"
2124
2125 ;; libstdc++ cannot be built at this stage
2126 ;; ("Link tests are not allowed after
2127 ;; GCC_NO_EXECUTABLES.").
2128 "--disable-libstdc++-v3"
2129
2130 "--disable-threads"
2131 "--disable-libmudflap"
2132 "--disable-libatomic"
2133 "--disable-libsanitizer"
2134 "--disable-libitm"
2135 "--disable-libgomp"
2136 "--disable-libmpx"
2137 "--disable-libcilkrts"
2138 "--disable-libvtv"
2139 "--disable-libssp"
2140 "--disable-libquadmath"
2141 "--disable-decimal-float")
2142 (remove (cut string-match
2143 "--(with-system-zlib|enable-languages.*)" <>)
2144 ,flags)))
2145 ((#:make-flags flags)
2146 `(let* ((libc (assoc-ref %build-inputs "libc"))
2147 (libc-native (or (assoc-ref %build-inputs "libc-native")
2148 libc)))
2149 `(,(string-append "LDFLAGS="
2150 "-Wl,-rpath=" libc-native "/lib "
2151 "-Wl,-dynamic-linker "
2152 "-Wl," libc-native ,(glibc-dynamic-linker
2153 (match (%current-system)
2154 ("x86_64-linux" "i686-linux")
2155 (_ (%current-system))))))))
2156 ((#:phases phases)
2157 `(modify-phases ,phases
2158 (add-after 'unpack 'unpack-gmp&co
2159 (lambda* (#:key inputs #:allow-other-keys)
2160 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2161 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2162 (mpc (assoc-ref %build-inputs "mpc-source")))
2163
2164 ;; To reduce the set of pre-built bootstrap inputs, build
2165 ;; GMP & co. from GCC.
2166 (for-each (lambda (source)
2167 (invoke "tar" "xvf" source))
2168 (list gmp mpfr mpc))
2169
2170 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2171 ,@(map (lambda (lib)
2172 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2173 ;; into gmp-6.0.0.
2174 `(symlink ,(string-trim-right
2175 (package-full-name lib "-")
2176 char-set:letter)
2177 ,(package-name lib)))
2178 (list gmp-6.0 mpfr mpc))
2179 #t)))
2180 ,(match (%current-system)
2181 ((or "i686-linux" "x86_64-linux")
2182 '(add-before 'configure 'fix-libcc1
2183 (lambda* (#:key inputs #:allow-other-keys)
2184 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
2185 ;; to placate the 'validate-runpath' phase.
2186 (substitute* "libcc1/Makefile.in"
2187 (("la_LDFLAGS =")
2188 (string-append "la_LDFLAGS = -Wl,-rpath="
2189 (assoc-ref inputs "gcc") "/lib")))
2190 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
2191 (substitute* "libcc1/configure"
2192 (("g\\+\\+ -v") "true"))
2193 #t)))
2194 (_ '(add-before 'configure 'return-true
2195 (lambda _ #t))))
2196 (add-after 'install 'symlink-libgcc_eh
2197 (lambda* (#:key outputs #:allow-other-keys)
2198 (let ((out (assoc-ref outputs "lib")))
2199 ;; Glibc wants to link against libgcc_eh, so provide
2200 ;; it.
2201 (with-directory-excursion
2202 (string-append out "/lib/gcc/"
2203 ,(boot-triplet)
2204 "/" ,(package-version gcc))
2205 (symlink "libgcc.a" "libgcc_eh.a"))
2206 #t))))))))
2207
2208 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2209 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
2210 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
2211 ("binutils-cross" ,binutils-boot0)
2212
2213 ;; The libstdc++ that libcc1 links against.
2214 ("libstdc++" ,libstdc++-boot0)
2215
2216 ;; Call it differently so that the builder can check whether
2217 ;; the "libc" input is #f.
2218 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
2219 ,@(alist-delete "libc" (%boot0-inputs))))
2220
2221 ;; No need for the native-inputs to build the documentation at this stage.
2222 (native-inputs `())))
2223
2224 (define perl-boot0
2225 (package
2226 (inherit perl)
2227 (name "perl-boot0")
2228 (source (bootstrap-origin (package-source perl)))
2229 (inputs (%boot0-inputs))
2230 (arguments
2231 `(#:implicit-inputs? #f
2232 #:guile ,%bootstrap-guile
2233 #:validate-runpath? #f
2234
2235 ;; At the very least, this must not depend on GCC & co.
2236 #:disallowed-references ,(list %bootstrap-binutils)
2237
2238 ,@(substitute-keyword-arguments (package-arguments perl)
2239 ((#:phases phases)
2240 `(modify-phases ,phases
2241 ;; Pthread support is missing in the bootstrap compiler
2242 ;; (broken spec file), so disable it.
2243 (add-before 'configure 'disable-pthreads
2244 (lambda _
2245 (substitute* "Configure"
2246 (("^libswanted=(.*)pthread" _ before)
2247 (string-append "libswanted=" before)))
2248 #t))))
2249 ;; Do not configure with '-Dusethreads' since pthread
2250 ;; support is missing.
2251 ((#:configure-flags configure-flags)
2252 `(delete "-Dusethreads" ,configure-flags)))))))
2253
2254 (define m4-boot0
2255 (package
2256 (inherit m4)
2257 (name "m4-boot0")
2258 (source (bootstrap-origin (package-source m4)))
2259 (inputs (%boot0-inputs))
2260 (arguments
2261 `(#:guile ,%bootstrap-guile
2262 #:implicit-inputs? #f
2263 ,@(package-arguments m4)))))
2264
2265 (define bison-boot0
2266 ;; This Bison is needed to build MiG so we need it early in the process.
2267 ;; Recent versions of Linux-Libre headers also depend on this.
2268 (package
2269 (inherit bison)
2270 (name "bison-boot0")
2271 (propagated-inputs `(("m4" ,m4-boot0)))
2272 (native-inputs `(("perl" ,perl-boot0)))
2273 (inputs (%boot0-inputs)) ;remove Flex...
2274 (arguments
2275 `(#:tests? #f ;... and thus disable tests
2276 #:implicit-inputs? #f
2277 #:guile ,%bootstrap-guile
2278
2279 ;; Zero timestamps in liby.a; this must be done
2280 ;; explicitly here because the bootstrap Binutils don't
2281 ;; do that (default is "cru".)
2282 #:make-flags `("ARFLAGS=crD"
2283 ,,(match (%current-system)
2284 ;; ranlib: '-D': No such file
2285 ((or "i686-linux" "x86_64-linux")
2286 "RANLIB=ranlib")
2287 (_
2288 "RANLIB=ranlib -D"))
2289 "V=1")
2290
2291 ,@(package-arguments bison)))))
2292
2293 (define flex-boot0
2294 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
2295 (package
2296 (inherit flex)
2297 (native-inputs `(("bison" ,bison-boot0)))
2298 (propagated-inputs `(("m4" ,m4-boot0)))
2299 (inputs (%boot0-inputs))
2300 (arguments
2301 `(#:implicit-inputs? #f
2302 #:guile ,%bootstrap-guile
2303 #:tests? #f))))
2304
2305 (define rsync-boot0
2306 (package
2307 (inherit rsync)
2308 (native-inputs `(("perl" ,perl-boot0)))
2309 (inputs (%boot0-inputs))
2310 (arguments
2311 `(#:implicit-inputs? #f
2312 #:guile ,%bootstrap-guile))))
2313
2314 (define linux-libre-headers-boot0
2315 (mlambda ()
2316 "Return Linux-Libre header files for the bootstrap environment."
2317 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
2318 ;; between (gnu packages linux) and this module. Additionally, memoize
2319 ;; the result to play well with further memoization and code that relies
2320 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
2321 (package
2322 (inherit linux-libre-headers)
2323 (arguments
2324 `(#:guile ,%bootstrap-guile
2325 #:implicit-inputs? #f
2326 ,@(package-arguments linux-libre-headers)))
2327 (native-inputs
2328 `(("perl" ,perl-boot0)
2329
2330 ;; Flex and Bison are required since version 4.16.
2331 ("flex" ,flex-boot0)
2332 ("bison" ,bison-boot0)
2333
2334 ;; Rsync is required since version 5.3.
2335 ("rsync" ,rsync-boot0)
2336 ,@(%boot0-inputs))))))
2337
2338 (define with-boot0
2339 (package-with-explicit-inputs %boot0-inputs
2340 %bootstrap-guile))
2341
2342 (define gnumach-headers-boot0
2343 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
2344
2345 (define mig-boot0
2346 (let* ((mig (package
2347 (inherit (package-with-bootstrap-guile mig))
2348 (native-inputs `(("bison" ,bison-boot0)
2349 ("flex" ,flex-boot0)))
2350 (inputs `(("flex" ,flex-boot0)))
2351 (arguments
2352 `(#:configure-flags
2353 `(,(string-append "LDFLAGS=-Wl,-rpath="
2354 (assoc-ref %build-inputs "flex") "/lib/")))))))
2355 (with-boot0 mig)))
2356
2357 (define hurd-headers-boot0
2358 (let ((hurd-headers (package (inherit hurd-headers)
2359 (native-inputs `(("mig" ,mig-boot0)))
2360 (inputs '()))))
2361 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
2362
2363 (define hurd-minimal-boot0
2364 (let ((hurd-minimal (package (inherit hurd-minimal)
2365 (native-inputs `(("mig" ,mig-boot0)))
2366 (inputs '()))))
2367 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
2368
2369 (define hurd-core-headers-boot0
2370 (mlambda ()
2371 "Return the Hurd and Mach headers as well as initial Hurd libraries for
2372 the bootstrap environment."
2373 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
2374 (arguments `(#:guile ,%bootstrap-guile
2375 ,@(package-arguments hurd-core-headers)))
2376 (inputs
2377 `(("gnumach-headers" ,gnumach-headers-boot0)
2378 ("hurd-headers" ,hurd-headers-boot0)
2379 ("hurd-minimal" ,hurd-minimal-boot0)
2380 ,@(%boot0-inputs))))))
2381
2382 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
2383 (match system
2384 ("i586-gnu" (hurd-core-headers-boot0))
2385 (_ (linux-libre-headers-boot0))))
2386
2387 (define texinfo-boot0
2388 ;; Texinfo used to build libc's manual.
2389 ;; We build without ncurses because it fails to build at this stage, and
2390 ;; because we don't need the stand-alone Info reader.
2391 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
2392 (package
2393 (inherit texinfo)
2394 (native-inputs '())
2395 (inputs `(,@(%boot0-inputs)
2396 ("perl" ,perl-boot0)))
2397 (arguments
2398 `(#:implicit-inputs? #f
2399 #:guile ,%bootstrap-guile
2400
2401 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
2402 ;; character type in locale" but we don't have a UTF-8 locale at this
2403 ;; stage, so skip them.
2404 #:tests? #f))))
2405
2406 (define expat-sans-tests
2407 (package
2408 (inherit expat)
2409 (inputs (%boot0-inputs))
2410 (arguments
2411 ;; XXX: Linking 'runtestscpp' fails with things like:
2412 ;;
2413 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
2414 ;;
2415 ;; Skip tests altogether.
2416 `(#:implicit-inputs? #f
2417 #:guile ,%bootstrap-guile
2418
2419 ,@(substitute-keyword-arguments (package-arguments expat)
2420 ((#:configure-flags flags ''())
2421 ;; Since we're not passing the right -Wl,-rpath flags, build the
2422 ;; static library to avoid RUNPATH validation failure.
2423 `(cons "--disable-shared" ,flags))
2424 ((#:tests? _ #f) #f))))))
2425
2426 (define python-boot0
2427 (package
2428 (inherit python-minimal)
2429 ;; We cannot use Python 3.7 and later here, because they require
2430 ;; pthreads, which is missing on non-x86 platforms at this stage.
2431 ;; Python 3.6 technically supports being built without threading
2432 ;; support, but requires additional patches.
2433 (version "3.5.9")
2434 (source (bootstrap-origin
2435 (origin
2436 (method url-fetch)
2437 (uri (string-append "https://www.python.org/ftp/python/"
2438 version "/Python-" version ".tar.xz"))
2439 (sha256
2440 (base32
2441 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
2442 (modules '((guix build utils)))
2443 (snippet
2444 '(begin
2445 ;; Delete the bundled copy of libexpat.
2446 (delete-file-recursively "Modules/expat")
2447 (substitute* "Modules/Setup.dist"
2448 ;; Link Expat instead of embedding the bundled one.
2449 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
2450 #t)))))
2451 (inputs
2452 `(,@(%boot0-inputs)
2453 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
2454 (native-inputs '()) ;and pkg-config
2455 (arguments
2456 `(#:implicit-inputs? #f
2457 #:guile ,%bootstrap-guile
2458
2459 ,@(substitute-keyword-arguments (package-arguments python-minimal)
2460 ;; Disable features that cannot be built at this stage.
2461 ((#:configure-flags _ ''())
2462 `(list "--without-ensurepip"
2463 "--without-threads"))
2464 ;; Clear #:make-flags, such that changes to the regular
2465 ;; Python package won't interfere with this one.
2466 ((#:make-flags _ ''()) ''())
2467 ((#:phases phases)
2468 `(modify-phases ,phases
2469 (add-before 'configure 'disable-modules
2470 (lambda _
2471 (substitute* "setup.py"
2472 ;; Disable ctypes, since it requires libffi.
2473 (("extensions\\.append\\(ctypes\\)") "")
2474 ;; Prevent the 'ossaudiodev' extension from being
2475 ;; built, since it requires Linux headers.
2476 (("'linux', ") ""))
2477 #t))
2478 (delete 'set-TZDIR)))
2479 ((#:tests? _ #f) #f))))))
2480
2481 (define ld-wrapper-boot0
2482 (mlambda ()
2483 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
2484 ;; in their RUNPATH, otherwise validate-runpath will fail.
2485 (make-ld-wrapper "ld-wrapper-boot0"
2486 #:target boot-triplet
2487 #:binutils binutils-boot0
2488 #:guile %bootstrap-guile
2489 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
2490 #:guile-for-build %bootstrap-guile)))
2491
2492 (define (%boot1-inputs)
2493 ;; 2nd stage inputs.
2494 `(("gcc" ,gcc-boot0)
2495 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
2496 ("binutils-cross" ,binutils-boot0)
2497 ,@(alist-delete "binutils" (%boot0-inputs))))
2498
2499 (define glibc-final-with-bootstrap-bash
2500 ;; The final libc, "cross-built". If everything went well, the resulting
2501 ;; store path has no dependencies. Actually, the really-final libc is
2502 ;; built just below; the only difference is that this one uses the
2503 ;; bootstrap Bash.
2504 (package
2505 (inherit glibc)
2506 (name "glibc-intermediate")
2507 (source (bootstrap-origin (package-source glibc)))
2508 (arguments
2509 `(#:guile ,%bootstrap-guile
2510 #:implicit-inputs? #f
2511
2512 ,@(substitute-keyword-arguments (package-arguments glibc)
2513 ((#:configure-flags flags)
2514 `(append (list ,(string-append "--host=" (boot-triplet))
2515 ,(string-append "--build="
2516 (nix-system->gnu-triplet)))
2517 ,flags))
2518 ((#:phases phases)
2519 `(modify-phases ,phases
2520 (add-before 'configure 'pre-configure
2521 (lambda* (#:key inputs #:allow-other-keys)
2522 ;; Don't clobber CPATH with the bootstrap libc.
2523 (setenv "NATIVE_CPATH" (getenv "CPATH"))
2524 (unsetenv "CPATH")
2525
2526 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
2527 ,@(if (hurd-triplet? (%current-system))
2528 `((substitute* "libpthread/Makefile"
2529 (("LDLIBS-pthread.so =.*")
2530 (string-append "LDLIBS-pthread.so = "
2531 (assoc-ref %build-inputs "kernel-headers")
2532 "/lib/libihash.a\n"))))
2533 '())
2534
2535 ;; 'rpcgen' needs native libc headers to be built.
2536 (substitute* "sunrpc/Makefile"
2537 (("sunrpc-CPPFLAGS =.*" all)
2538 (string-append "CPATH = $(NATIVE_CPATH)\n"
2539 "export CPATH\n"
2540 all "\n")))
2541 #t)))))))
2542 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2543 (native-inputs
2544 `(("bison" ,bison-boot0)
2545 ("texinfo" ,texinfo-boot0)
2546 ("perl" ,perl-boot0)
2547 ("python" ,python-boot0)))
2548 (inputs
2549 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2550 ;; it in $CPATH, hence the 'pre-configure' phase above.
2551 ,@(%boot1-inputs)
2552
2553 ;; A native MiG is needed to build Glibc on Hurd.
2554 ,@(if (hurd-triplet? (%current-system))
2555 `(("mig" ,mig-boot0))
2556 '())
2557
2558 ;; A native GCC is needed to build `cross-rpcgen'.
2559 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2560
2561 ;; Here, we use the bootstrap Bash, which is not satisfactory
2562 ;; because we don't want to depend on bootstrap tools.
2563 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
2564
2565 (define (cross-gcc-wrapper gcc binutils glibc bash)
2566 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2567 that makes it available under the native tool names."
2568 (package (inherit gcc)
2569 (name (string-append (package-name gcc) "-wrapped"))
2570 (source #f)
2571 (build-system trivial-build-system)
2572 (outputs '("out"))
2573 (arguments
2574 `(#:guile ,%bootstrap-guile
2575 #:modules ((guix build utils))
2576 #:builder (begin
2577 (use-modules (guix build utils))
2578
2579 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2580 (gcc (assoc-ref %build-inputs "gcc"))
2581 (libc (assoc-ref %build-inputs "libc"))
2582 (bash (assoc-ref %build-inputs "bash"))
2583 (out (assoc-ref %outputs "out"))
2584 (bindir (string-append out "/bin"))
2585 (triplet ,(boot-triplet)))
2586 (define (wrap-program program)
2587 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2588 ;; needs to be told where to find the crt files and
2589 ;; the dynamic linker.
2590 (call-with-output-file program
2591 (lambda (p)
2592 (format p "#!~a/bin/bash
2593 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2594 bash
2595 gcc triplet program
2596 libc libc
2597 ,(glibc-dynamic-linker))))
2598
2599 (chmod program #o555))
2600
2601 (mkdir-p bindir)
2602 (with-directory-excursion bindir
2603 (for-each (lambda (tool)
2604 (symlink (string-append binutils "/bin/"
2605 triplet "-" tool)
2606 tool))
2607 '("ar" "ranlib"))
2608 (for-each wrap-program '("gcc" "g++")))
2609
2610 #t))))
2611 (native-inputs
2612 `(("binutils" ,binutils)
2613 ("gcc" ,gcc)
2614 ("libc" ,glibc)
2615 ("bash" ,bash)))
2616 (inputs '())))
2617
2618 (define gcc-boot0-intermediate-wrapped
2619 (mlambda ()
2620 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2621 ;; non-cross names.
2622 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2623 glibc-final-with-bootstrap-bash
2624 (car (assoc-ref (%boot1-inputs) "bash")))))
2625
2626 (define static-bash-for-glibc
2627 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
2628 (package
2629 (inherit static-bash)
2630 (source (bootstrap-origin (package-source static-bash)))
2631 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2632 ("libc" ,glibc-final-with-bootstrap-bash)
2633 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2634 ,@(fold alist-delete (%boot1-inputs)
2635 '("gcc" "libc"))))
2636 (arguments
2637 `(#:implicit-inputs? #f
2638 #:guile ,%bootstrap-guile
2639
2640 ,@(substitute-keyword-arguments (package-arguments static-bash)
2641 ((#:configure-flags flags '())
2642 ;; Add a '-L' flag so that the pseudo-cross-ld of
2643 ;; BINUTILS-BOOT0 can find libc.a.
2644 `(append ,flags
2645 (list (string-append "LDFLAGS=-static -L"
2646 (assoc-ref %build-inputs
2647 "libc:static")
2648 "/lib")))))))))
2649
2650 (define gettext-boot0
2651 ;; A minimal gettext used during bootstrap.
2652 (package
2653 (inherit gettext-minimal)
2654 (name "gettext-boot0")
2655 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2656 ;; simplify the dependency chain, we stick to this version here.
2657 (version "0.19.8.1")
2658 (source (origin
2659 (method url-fetch)
2660 (uri (string-append "mirror://gnu/gettext/gettext-"
2661 version ".tar.gz"))
2662 (sha256
2663 (base32
2664 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2665 (inputs (%boot1-inputs)) ;zero dependencies
2666 (arguments
2667 `(#:implicit-inputs? #f
2668 #:guile ,%bootstrap-guile
2669 #:tests? #f
2670 #:phases (modify-phases %standard-phases
2671 ;; Build only the tools.
2672 (add-after 'unpack 'chdir
2673 (lambda _
2674 (chdir "gettext-tools")
2675 #t))
2676
2677 ;; Some test programs require pthreads, which we don't have.
2678 (add-before 'configure 'no-test-programs
2679 (lambda _
2680 (substitute* "tests/Makefile.in"
2681 (("^PROGRAMS =.*$")
2682 "PROGRAMS =\n"))
2683 #t)))))))
2684
2685 (define glibc-final
2686 ;; The final glibc, which embeds the statically-linked Bash built above.
2687 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2688 (package/inherit
2689 glibc
2690 (name "glibc")
2691 (source (bootstrap-origin (package-source glibc)))
2692 (inputs `(("static-bash" ,static-bash-for-glibc)
2693 ,@(alist-delete
2694 "static-bash"
2695 (package-inputs glibc-final-with-bootstrap-bash))))
2696
2697 ;; This time we need 'msgfmt' to install all the libc.mo files.
2698 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2699 ("gettext" ,gettext-boot0)))
2700
2701 (propagated-inputs
2702 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2703
2704 ;; The final libc only refers to itself, but the 'debug' output contains
2705 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2706 ;; if 'allowed-references' were per-output.
2707 (arguments
2708 `(#:allowed-references
2709 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2710 static-bash-for-glibc
2711 (package-outputs glibc-final-with-bootstrap-bash))
2712
2713 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2714
2715 (define gcc-boot0-wrapped
2716 (mlambda ()
2717 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2718 ;; non-cross names.
2719 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2720 (car (assoc-ref (%boot1-inputs) "bash")))))
2721
2722 (define (%boot2-inputs)
2723 ;; 3rd stage inputs.
2724 `(("libc" ,glibc-final)
2725 ("libc:static" ,glibc-final "static")
2726 ("gcc" ,(gcc-boot0-wrapped))
2727 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2728
2729 (define binutils-final
2730 (package
2731 (inherit binutils)
2732 (source (bootstrap-origin (package-source binutils)))
2733 (arguments
2734 `(#:guile ,%bootstrap-guile
2735 #:implicit-inputs? #f
2736 #:allowed-references ("out" ,glibc-final)
2737 ,@(package-arguments binutils)))
2738 (inputs (%boot2-inputs))))
2739
2740 (define libstdc++
2741 ;; Intermediate libstdc++ that will allow us to build the final GCC
2742 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2743 (let ((lib (make-libstdc++ gcc)))
2744 (package
2745 (inherit lib)
2746 (source (bootstrap-origin (package-source lib)))
2747 (arguments
2748 `(#:guile ,%bootstrap-guile
2749 #:implicit-inputs? #f
2750 #:allowed-references ("out")
2751
2752 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2753 #:validate-runpath? #f
2754
2755 ;; All of the package arguments from 'make-libstdc++
2756 ;; except for the configure-flags.
2757 ,@(package-arguments lib)
2758 #:configure-flags `("--disable-shared"
2759 "--disable-libstdcxx-dual-abi"
2760 "--disable-libstdcxx-threads"
2761 "--disable-libstdcxx-pch"
2762 ,(string-append "--with-gxx-include-dir="
2763 (assoc-ref %outputs "out")
2764 "/include"))))
2765 (outputs '("out"))
2766 (inputs (%boot2-inputs))
2767 (synopsis "GNU C++ standard library (intermediate)"))))
2768
2769 (define zlib-final
2770 ;; Zlib used by GCC-FINAL.
2771 (package
2772 (inherit zlib)
2773 (arguments
2774 `(#:guile ,%bootstrap-guile
2775 #:implicit-inputs? #f
2776 #:allowed-references ("out" ,glibc-final)
2777 ,@(package-arguments zlib)))
2778 (inputs (%boot2-inputs))))
2779
2780 (define ld-wrapper-boot3
2781 (mlambda ()
2782 ;; A linker wrapper that uses the bootstrap Guile.
2783 (make-ld-wrapper "ld-wrapper-boot3"
2784 #:binutils binutils-final
2785 #:guile %bootstrap-guile
2786 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2787 #:guile-for-build %bootstrap-guile)))
2788
2789 (define gcc-final
2790 ;; The final GCC.
2791 (package (inherit gcc-boot0)
2792 (name "gcc")
2793
2794 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2795 ;; "debug" output contains disallowed references, notably
2796 ;; linux-libre-headers. Disable the debugging output to work around that.
2797 (outputs (delete "debug" (package-outputs gcc-boot0)))
2798
2799 (arguments
2800 `(#:guile ,%bootstrap-guile
2801 #:implicit-inputs? #f
2802
2803 #:allowed-references ("out" "lib" ,zlib-final
2804 ,glibc-final ,static-bash-for-glibc)
2805
2806 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2807 ;; reason, but it is not in their RUNPATH. This is a false
2808 ;; positive, so turn it off.
2809 #:validate-runpath? #f
2810
2811 ,@(substitute-keyword-arguments (package-arguments gcc)
2812 ((#:make-flags flags)
2813 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2814 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2815 (map (lambda (flag)
2816 (if (string-prefix? "LDFLAGS=" flag)
2817 (string-append flag " -L"
2818 (assoc-ref %build-inputs "libstdc++")
2819 "/lib -L" zlib "/lib -Wl,-rpath="
2820 zlib "/lib")
2821 flag))
2822 ,flags)))
2823 ;; Build again GMP & co. within GCC's build process, because it's hard
2824 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2825 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2826 ((#:phases phases)
2827 `(modify-phases ,phases
2828 (add-after 'unpack 'unpack-gmp&co
2829 (lambda* (#:key inputs #:allow-other-keys)
2830 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2831 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2832 (mpc (assoc-ref %build-inputs "mpc-source")))
2833
2834 ;; To reduce the set of pre-built bootstrap inputs, build
2835 ;; GMP & co. from GCC.
2836 (for-each (lambda (source)
2837 (invoke "tar" "xvf" source))
2838 (list gmp mpfr mpc))
2839
2840 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2841 ,@(map (lambda (lib)
2842 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2843 ;; into gmp-6.0.0.
2844 `(symlink ,(string-trim-right
2845 (package-full-name lib "-")
2846 char-set:letter)
2847 ,(package-name lib)))
2848 (list gmp-6.0 mpfr mpc))
2849 #t))))))))
2850
2851 ;; This time we want Texinfo, so we get the manual. Add
2852 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2853 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2854 ;; scripts?).
2855 (native-inputs `(("texinfo" ,texinfo-boot0)
2856 ("perl" ,perl-boot0) ;for manpages
2857 ("static-bash" ,static-bash-for-glibc)
2858 ,@(package-native-inputs gcc-boot0)))
2859
2860 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2861 ("mpfr-source" ,(package-source mpfr))
2862 ("mpc-source" ,(package-source mpc))
2863 ("ld-wrapper" ,(ld-wrapper-boot3))
2864 ("binutils" ,binutils-final)
2865 ("libstdc++" ,libstdc++)
2866 ("zlib" ,zlib-final)
2867 ,@(%boot2-inputs)))))
2868
2869 (define (%boot3-inputs)
2870 ;; 4th stage inputs.
2871 `(("gcc" ,gcc-final)
2872 ("ld-wrapper" ,(ld-wrapper-boot3))
2873 ,@(alist-delete "gcc" (%boot2-inputs))))
2874
2875 (define bash-final
2876 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2877 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2878 ;; on Readline and ncurses.
2879 (let ((bash (static-libgcc-package bash-minimal)))
2880 (package
2881 (inherit bash)
2882 (source (bootstrap-origin (package-source bash)))
2883 (inputs (%boot3-inputs))
2884 (arguments
2885 `(#:implicit-inputs? #f
2886 #:guile ,%bootstrap-guile
2887
2888 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2889
2890 ,@(package-arguments bash))))))
2891
2892 (define (%boot4-inputs)
2893 ;; Now use the final Bash.
2894 `(("bash" ,bash-final)
2895 ,@(alist-delete "bash" (%boot3-inputs))))
2896
2897 (define with-boot4
2898 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2899
2900 (define-public guile-final
2901 ;; This package must be public because other modules refer to it. However,
2902 ;; mark it as hidden so that 'fold-packages' ignores it.
2903 (with-boot4 (hidden-package
2904 (package-with-bootstrap-guile guile-2.2/fixed))))
2905
2906 (define glibc-utf8-locales-final
2907 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2908 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2909 ;; with the full range of Unicode codepoints (remember
2910 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2911 ;; function.)
2912 (package
2913 (inherit glibc-utf8-locales)
2914 (native-inputs
2915 `(("glibc" ,glibc-final)
2916 ("gzip" ,(with-boot4 gzip))))))
2917
2918 (define-public ld-wrapper
2919 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2920 (make-ld-wrapper "ld-wrapper"
2921 #:binutils binutils-final
2922 #:guile guile-final
2923 #:bash bash-final))
2924
2925 (define (%boot5-inputs)
2926 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2927 ;; with an older libc, which cannot load the new locale format. See
2928 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2929 `(("locales" ,glibc-utf8-locales-final)
2930 ,@(%boot4-inputs)))
2931
2932 (define with-boot5
2933 (package-with-explicit-inputs %boot5-inputs))
2934
2935 (define gnu-make-final
2936 ;; The final GNU Make, which uses the final Guile.
2937 (let ((pkg-config (package
2938 (inherit %pkg-config) ;the native pkg-config
2939 (inputs `(("guile" ,guile-final)
2940 ,@(%boot5-inputs)))
2941 (arguments
2942 `(#:implicit-inputs? #f
2943 ,@(package-arguments pkg-config))))))
2944 (package
2945 (inherit (package-with-bootstrap-guile gnu-make))
2946 (inputs `(("guile" ,guile-final)
2947 ,@(%boot5-inputs)))
2948 (native-inputs `(("pkg-config" ,pkg-config)))
2949 (arguments
2950 `(#:implicit-inputs? #f
2951 ,@(package-arguments gnu-make))))))
2952
2953
2954 (define coreutils-final
2955 ;; The final Coreutils. Treat them specially because some packages, such as
2956 ;; Findutils, keep a reference to the Coreutils they were built with.
2957 (with-boot5 (package-with-bootstrap-guile coreutils)
2958 ;; Use the final Guile, linked against the
2959 ;; final libc with working iconv, so that
2960 ;; 'substitute*' works well when touching
2961 ;; test files in Gettext.
2962 ))
2963
2964 (define grep-final
2965 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2966 ;; built before gzip.
2967 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2968 (package/inherit grep
2969 (inputs (alist-delete "pcre" (package-inputs grep)))
2970 (native-inputs `(("perl" ,perl-boot0))))))
2971
2972 (define (%boot6-inputs)
2973 ;; Now use the final Coreutils.
2974 `(("coreutils" ,coreutils-final)
2975 ("grep" ,grep-final)
2976 ,@(%boot5-inputs)))
2977
2978 (define with-boot6
2979 (package-with-explicit-inputs %boot6-inputs))
2980
2981 (define sed-final
2982 ;; The final sed.
2983 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2984 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2985
2986 (define-public %final-inputs
2987 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2988 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2989 ;; used for origins that have patches, thereby avoiding circular
2990 ;; dependencies.
2991 (let ((finalize (compose with-boot6
2992 package-with-bootstrap-guile)))
2993 `(,@(map (match-lambda
2994 ((name package)
2995 (list name (finalize package))))
2996 `(("tar" ,tar)
2997 ("gzip" ,gzip)
2998 ("bzip2" ,bzip2)
2999 ("xz" ,xz)
3000 ("file" ,file)
3001 ("diffutils" ,diffutils)
3002 ("patch" ,patch)
3003 ("findutils" ,findutils)
3004 ("gawk" ,gawk)))
3005 ("sed" ,sed-final)
3006 ("grep" ,grep-final)
3007 ("coreutils" ,coreutils-final)
3008 ("make" ,gnu-make-final)
3009 ("bash" ,bash-final)
3010 ("ld-wrapper" ,ld-wrapper)
3011 ("binutils" ,binutils-final)
3012 ("gcc" ,gcc-final)
3013 ("libc" ,glibc-final)
3014 ("libc:static" ,glibc-final "static")
3015 ("locales" ,glibc-utf8-locales-final))))
3016
3017 (define-public canonical-package
3018 (let ((name->package (fold (lambda (input result)
3019 (match input
3020 ((_ package . outputs)
3021 (vhash-cons (package-full-name package)
3022 package result))))
3023 vlist-null
3024 `(("guile" ,guile-final)
3025 ,@%final-inputs))))
3026 (lambda (package)
3027 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
3028 the implicit inputs of 'gnu-build-system', return that one, otherwise return
3029 PACKAGE.
3030
3031 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
3032 COREUTILS-FINAL vs. COREUTILS, etc."
3033 ;; XXX: This doesn't handle dependencies of the final inputs, such as
3034 ;; libunistring, GMP, etc.
3035 (match (vhash-assoc (package-full-name package) name->package)
3036 ((_ . canon)
3037 ;; In general we want CANON, except if we're cross-compiling: CANON
3038 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
3039 ;; process, with dependencies on things that cannot be
3040 ;; cross-compiled.
3041 (if (%current-target-system)
3042 package
3043 canon))
3044 (_ package)))))
3045
3046 \f
3047 ;;;
3048 ;;; GCC toolchain.
3049 ;;;
3050
3051 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
3052 ;; instantiated like this:
3053 ;;
3054 ;; (define-public gcc-glibc-2.27-toolchain
3055 ;; (make-gcc-toolchain gcc glibc-2.27))
3056
3057 (define* (make-gcc-toolchain gcc
3058 #:optional
3059 (libc #f))
3060 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
3061 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
3062 (libc (if libc libc glibc-final)))
3063 (package
3064 (name (string-append (package-name gcc) "-toolchain"))
3065 (version (package-version gcc))
3066 (source #f)
3067 (build-system trivial-build-system)
3068 (arguments
3069 '(#:modules ((guix build union))
3070 #:builder (begin
3071 (use-modules (ice-9 match)
3072 (srfi srfi-26)
3073 (guix build union))
3074
3075 (let ((out (assoc-ref %outputs "out")))
3076
3077 (match %build-inputs
3078 (((names . directories) ...)
3079 (union-build out directories)))
3080
3081 (union-build (assoc-ref %outputs "debug")
3082 (list (assoc-ref %build-inputs
3083 "libc-debug")))
3084 (union-build (assoc-ref %outputs "static")
3085 (list (assoc-ref %build-inputs
3086 "libc-static")))
3087 #t))))
3088
3089 (native-search-paths (package-native-search-paths gcc))
3090 (search-paths (package-search-paths gcc))
3091
3092 (license (package-license gcc))
3093 (synopsis "Complete GCC tool chain for C/C++ development")
3094 (description
3095 "This package provides a complete GCC tool chain for C/C++ development to
3096 be installed in user profiles. This includes GCC, as well as libc (headers and
3097 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
3098 (home-page "https://gcc.gnu.org/")
3099 (outputs '("out" "debug" "static"))
3100
3101 ;; The main raison d'être of this "meta-package" is (1) to conveniently
3102 ;; install everything that we need, and (2) to make sure ld-wrapper comes
3103 ;; before Binutils' ld in the user's profile.
3104 (inputs `(("gcc" ,gcc)
3105 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
3106 ("binutils" ,binutils-final)
3107 ("libc" ,libc)
3108 ("libc-debug" ,libc "debug")
3109 ("libc-static" ,libc "static"))))))
3110
3111 (define-public gcc-toolchain
3112 (make-gcc-toolchain gcc-final))
3113
3114 (define-public gcc-toolchain-4.8
3115 (make-gcc-toolchain gcc-4.8))
3116
3117 (define-public gcc-toolchain-4.9
3118 (make-gcc-toolchain gcc-4.9))
3119
3120 (define-public gcc-toolchain-5
3121 (make-gcc-toolchain gcc-5))
3122
3123 (define-public gcc-toolchain-6
3124 (make-gcc-toolchain gcc-6))
3125
3126 (define-public gcc-toolchain-7
3127 gcc-toolchain)
3128
3129 (define-public gcc-toolchain-8
3130 (make-gcc-toolchain gcc-8))
3131
3132 (define-public gcc-toolchain-9
3133 (make-gcc-toolchain gcc-9))
3134
3135 ;; Provide the Fortran toolchain package only for the version of gfortran that
3136 ;; is used by Guix internally to build Fortran libraries, because combining
3137 ;; code compiled with different versions can cause problems.
3138
3139 (define-public gfortran-toolchain
3140 (package (inherit (make-gcc-toolchain gfortran))
3141 (synopsis "Complete GCC tool chain for Fortran development")
3142 (description "This package provides a complete GCC tool chain for
3143 Fortran development to be installed in user profiles. This includes
3144 gfortran, as well as libc (headers and binaries, plus debugging symbols
3145 in the @code{debug} output), and binutils.")))
3146
3147
3148 ;;; commencement.scm ends here