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