gnu: emacs-svg-icon: Fix grammar.
[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, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
9 ;;; Copyright © 2019, 2020 Marius Bakke <mbakke@fastmail.com>
10 ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
11 ;;; Copyright © 2020 Guy Fleury Iteriteka <gfleury@disroot.org>
12 ;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages commencement)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages bootstrap)
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages bash)
34 #:use-module (gnu packages c)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages m4)
37 #:use-module (gnu packages gawk)
38 #:use-module (gnu packages bison)
39 #:use-module (gnu packages flex)
40 #:use-module (gnu packages guile)
41 #:use-module (gnu packages gettext)
42 #:use-module (gnu packages multiprecision)
43 #:use-module (gnu packages compression)
44 #:use-module (gnu packages mes)
45 #:use-module (gnu packages perl)
46 #:use-module (gnu packages python)
47 #:use-module (gnu packages linux)
48 #:use-module (gnu packages hurd)
49 #:use-module (gnu packages shells)
50 #:use-module (gnu packages texinfo)
51 #:use-module (gnu packages pkg-config)
52 #:use-module (gnu packages rsync)
53 #:use-module (gnu packages xml)
54 #:use-module (guix packages)
55 #:use-module (guix download)
56 #:use-module (guix build-system gnu)
57 #:use-module (guix build-system trivial)
58 #:use-module ((guix licenses) #:prefix license:)
59 #:use-module (guix memoization)
60 #:use-module (guix utils)
61 #:use-module (srfi srfi-1)
62 #:use-module (ice-9 vlist)
63 #:use-module (ice-9 match)
64 #:export (make-gcc-toolchain))
65
66 ;;; Commentary:
67 ;;;
68 ;;; This is the commencement, this is where things start. Before the
69 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
70 ;;; with the initial binaries. This module uses those bootstrap binaries to
71 ;;; actually build up the whole tool chain that make up the implicit inputs of
72 ;;; 'gnu-build-system'.
73 ;;;
74 ;;; To avoid circular dependencies, this module should not be imported
75 ;;; directly from anywhere.
76 ;;;
77 ;;; Below, we frequently use "inherit" to create modified packages. The
78 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
79 ;;; not want these commencement packages to inherit grafts. By definition,
80 ;;; these packages are not depended on at run time by any of the packages we
81 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
82 ;;; grafts would often lead to extra overhead for users who would end up
83 ;;; downloading those "-boot0" packages just to build package replacements
84 ;;; that are in fact not going to be used.
85 ;;;
86 ;;; Code:
87
88 (define bootar
89 (package
90 (name "bootar")
91 (version "1a")
92 (source (origin
93 (method url-fetch)
94 (uri (list (string-append
95 "mirror://gnu/guix/mirror/bootar-" version ".ses")
96 (string-append
97 "https://files.ngyro.com/bootar/bootar-"
98 version ".ses")))
99 (sha256
100 (base32
101 "0mvp6vgx0q316fvy3z2lddlc5xgq5np3bm1fypgvj6dnayibg9np"))))
102 (build-system gnu-build-system)
103 (arguments
104 `(#:implicit-inputs? #f
105 #:tests? #f
106 #:guile ,%bootstrap-guile
107 #:imported-modules ((guix build gnu-bootstrap)
108 ,@%gnu-build-system-modules)
109 #:phases
110 (begin
111 (use-modules (guix build gnu-bootstrap))
112 (modify-phases %standard-phases
113 (replace 'unpack
114 (lambda* (#:key inputs #:allow-other-keys)
115 (let* ((source (assoc-ref inputs "source"))
116 (guile-dir (assoc-ref inputs "guile"))
117 (guile (string-append guile-dir "/bin/guile")))
118 (invoke guile "--no-auto-compile" source)
119 (chdir "bootar")
120 #t)))
121 (replace 'configure (bootstrap-configure ,version "." "scripts"))
122 (replace 'build (bootstrap-build "."))
123 (replace 'install (bootstrap-install "." "scripts"))))))
124 (inputs `(("guile" ,%bootstrap-guile)))
125 (home-page "https://git.ngyro.com/bootar")
126 (synopsis "Tar decompression and extraction in Guile Scheme")
127 (description "Bootar is a simple Tar extractor written in Guile
128 Scheme. It supports running 'tar xvf' on uncompressed tarballs or
129 tarballs that are compressed with BZip2, GZip, or XZ. It also provides
130 standalone scripts for 'bzip2', 'gzip', and 'xz' that each support
131 decompression to standard output.
132
133 What makes this special is that Bootar is distributed as a
134 self-extracting Scheme (SES) program. That is, a little script that
135 outputs the source code of Bootar. This makes it possible to go from
136 pure Scheme to Tar and decompression in one easy step.")
137 (license license:gpl3+)))
138
139 (define gash-boot
140 (package
141 (inherit gash)
142 (name "gash-boot")
143 (source (origin
144 (inherit (package-source gash))
145 (snippet #f))) ;discard snippet for Guile 3.0 support
146 (arguments
147 `(#:implicit-inputs? #f
148 #:tests? #f
149 #:guile ,%bootstrap-guile
150 #:imported-modules ((guix build gnu-bootstrap)
151 ,@%gnu-build-system-modules)
152 #:phases
153 (begin
154 (use-modules (guix build gnu-bootstrap))
155 (modify-phases %standard-phases
156 (replace 'configure
157 (bootstrap-configure ,(package-version gash) "gash" "scripts"))
158 (replace 'build (bootstrap-build "gash"))
159 (replace 'install (bootstrap-install "gash" "scripts"))
160 (add-after 'install 'install-symlinks
161 (lambda* (#:key outputs #:allow-other-keys)
162 (let ((out (assoc-ref outputs "out")))
163 (symlink (string-append out "/bin/gash")
164 (string-append out "/bin/sh"))
165 (symlink (string-append out "/bin/gash")
166 (string-append out "/bin/bash"))
167 #t)))))))
168 (inputs `(("guile" ,%bootstrap-guile)))
169 (native-inputs `(("bootar" ,bootar)))))
170
171 (define gash-utils-boot
172 (package
173 (inherit gash-utils)
174 (name "gash-utils-boot")
175 (source (origin
176 (inherit (package-source gash-utils))
177 (patches '())
178 (snippet #f))) ;discard snippet for Guile 3.0 support
179 (arguments
180 `(#:implicit-inputs? #f
181 #:tests? #f
182 #:guile ,%bootstrap-guile
183 #:imported-modules ((guix build gnu-bootstrap)
184 ,@%gnu-build-system-modules)
185 #:phases
186 (begin
187 (use-modules (guix build gnu-bootstrap))
188 (modify-phases %standard-phases
189 (add-after 'unpack 'set-load-path
190 (lambda* (#:key inputs #:allow-other-keys)
191 (let ((gash (assoc-ref inputs "gash")))
192 (add-to-load-path (string-append gash "/share/guile/site/"
193 (effective-version))))
194 #t))
195 (add-before 'configure 'pre-configure
196 (lambda _
197 (format #t "Creating gash/commands/testb.scm~%")
198 (copy-file "gash/commands/test.scm"
199 "gash/commands/testb.scm")
200 (substitute* "gash/commands/testb.scm"
201 (("gash commands test") "gash commands testb")
202 (("apply test [(]cdr") "apply test/bracket (cdr"))
203 (for-each (lambda (script)
204 (let ((target (string-append "scripts/"
205 script ".in")))
206 (format #t "Creating scripts/~a~%" target)
207 (copy-file "scripts/template.in" target)
208 (substitute* target
209 (("@UTILITY@") script))))
210 '("awk" "basename" "cat" "chmod" "cmp" "command"
211 "compress" "cp" "cut" "diff" "dirname" "expr"
212 "false" "find" "grep" "head" "ln" "ls" "mkdir"
213 "mv" "printf" "pwd" "reboot" "rm" "rmdir"
214 "sed" "sleep" "sort" "tar" "test" "touch" "tr"
215 "true" "uname" "uniq" "wc" "which"))
216 (format #t "Creating scripts/[.in~%")
217 (copy-file "scripts/template.in" "scripts/[.in")
218 (substitute* "scripts/[.in"
219 (("@UTILITY@") "testb"))
220 (delete-file "scripts/template.in")
221 #t))
222 (replace 'configure
223 (bootstrap-configure ,(package-version gash-utils)
224 "gash" "scripts"))
225 (replace 'build (bootstrap-build "gash"))
226 (replace 'install (bootstrap-install "gash" "scripts"))
227 ;; XXX: The scripts should add Gash to their load paths and
228 ;; this phase should not exist.
229 (add-after 'install 'copy-gash
230 (lambda* (#:key inputs outputs #:allow-other-keys)
231 (let* ((out (assoc-ref outputs "out"))
232 (moddir (string-append out "/share/guile/site/"
233 (effective-version)))
234 (godir (string-append out "/lib/guile/"
235 (effective-version)
236 "/site-ccache"))
237 (gash (assoc-ref inputs "gash"))
238 (gash-moddir (string-append gash "/share/guile/site/"
239 (effective-version)))
240 (gash-godir (string-append gash "/lib/guile/"
241 (effective-version)
242 "/site-ccache")))
243 (copy-file (string-append gash-moddir "/gash/compat.scm")
244 (string-append moddir "/gash/compat.scm"))
245 (copy-recursively (string-append gash-moddir "/gash/compat")
246 (string-append moddir "/gash/compat"))
247 (copy-file (string-append gash-godir "/gash/compat.go")
248 (string-append godir "/gash/compat.go"))
249 (copy-recursively (string-append gash-godir "/gash/compat")
250 (string-append godir "/gash/compat"))
251 #t)))))))
252 (inputs `(("gash" ,gash-boot)
253 ("guile" ,%bootstrap-guile)))
254 (native-inputs `(("bootar" ,bootar)))))
255
256 (define (%boot-gash-inputs)
257 `(("bash" , gash-boot) ; gnu-build-system wants "bash"
258 ("coreutils" , gash-utils-boot)
259 ("bootar" ,bootar)
260 ("guile" ,%bootstrap-guile)))
261
262 (define %bootstrap-mes-rewired
263 (package
264 (inherit mes)
265 (name "bootstrap-mes-rewired")
266 (version "0.19")
267 (source #f)
268 (native-inputs `(("mes" ,%bootstrap-mes)
269 ("gash" ,gash-boot)))
270 (inputs '())
271 (propagated-inputs '())
272 (outputs '("out"))
273 (build-system trivial-build-system)
274 (arguments
275 `(#:guile ,%bootstrap-guile
276 #:modules ((guix build utils))
277
278 #:builder (begin
279 (use-modules (guix build utils)
280 (srfi srfi-26))
281
282 (let* ((mes (assoc-ref %build-inputs "mes"))
283 (gash (assoc-ref %build-inputs "gash"))
284 (mes-bin (string-append mes "/bin"))
285 (guile (string-append mes-bin "/mes"))
286 (mes-module (string-append mes "/share/mes/module"))
287 (out (assoc-ref %outputs "out"))
288 (bin (string-append out "/bin"))
289 (mescc (string-append bin "/mescc"))
290 (module (string-append out "/share/mes/module")))
291 (define (rewire file)
292 (substitute* file
293 ((mes) out)
294 (("/gnu/store[^ ]+mes-minimal-[^/)}\"]*") out)
295 (("/gnu/store[^ ]+guile-[^/]*/bin/guile") guile)
296 (("/gnu/store[^ ]+bash-[^/)}\"]*") gash)))
297
298 (mkdir-p bin)
299 (for-each (lambda (file) (install-file file bin))
300 (find-files mes-bin))
301 (mkdir-p module)
302 (copy-recursively (string-append mes-module "/mes")
303 (string-append module "/mes"))
304 (copy-recursively (string-append mes-module "/srfi")
305 (string-append module "/srfi"))
306 (for-each rewire
307 ;; Cannot easily rewire "mes" because it
308 ;; contains NUL characters; would require
309 ;; remove-store-references alike trick
310 (filter (negate (cut string-suffix? "/mes" <>))
311 (find-files bin)))
312 (rewire (string-append module "/mes/boot-0.scm"))
313
314 (delete-file mescc)
315 (with-output-to-file mescc
316 (lambda _
317 (display (string-append
318 "\
319 #! " gash "/bin/sh
320 LANG=C
321 LC_ALL=C
322 export LANG LC_ALL
323
324 MES_PREFIX=${MES_REWIRED_PREFIX-" out "/share/mes}
325 MES=" bin "/mes
326 export MES MES_PREFIX
327
328 MES_ARENA=${MES_REWIRED_ARENA-10000000}
329 MES_MAX_ARENA=${MES_REWIRED_ARENA-10000000}
330 MES_STACK=${MES_REWIRED_STACK-1000000}
331 export MES_ARENA MES_MAX_ARENA MES_STACK
332
333 $MES -e '(mescc)' module/mescc.scm -- \"$@\"
334 "))))
335 (chmod mescc #o555)
336
337 (with-directory-excursion module
338 (chmod "mes/base.mes" #o644)
339 (copy-file "mes/base.mes" "mes/base.mes.orig")
340 (let ((base.mes (open-file "mes/base.mes" "a")))
341 (display "
342 ;; A fixed map, from Mes 0.21, required to bootstrap Mes 0.21
343 (define (map f h . t)
344 (if (or (null? h)
345 (and (pair? t) (null? (car t)))
346 (and (pair? t) (pair? (cdr t)) (null? (cadr t)))) '()
347 (if (null? t) (cons (f (car h)) (map f (cdr h)))
348 (if (null? (cdr t))
349 (cons (f (car h) (caar t)) (map f (cdr h) (cdar t)))
350 (if (null? (cddr t))
351 (cons (f (car h) (caar t) (caadr t)) (map f (cdr h) (cdar t) (cdadr t)))
352 (error 'unsupported (cons* 'map-4: f h t))b )))))
353 " base.mes)
354 (close base.mes))
355
356 (chmod "mes/guile.mes" #o644)
357 (copy-file "mes/guile.mes" "mes/guile.mes.orig")
358 (let ((guile.mes (open-file "mes/guile.mes" "a")))
359 (display "
360 ;; After booting guile.scm; use Mes 0.21; especially: MesCC 0.21
361 (let* ((self (car (command-line)))
362 (prefix (dirname (dirname self))))
363 (set! %moduledir (string-append prefix \"/mes/module/\"))
364 (setenv \"%numbered_arch\" \"true\"))
365
366 " guile.mes)
367 (close guile.mes)))
368 #t))))))
369
370 (define mes-boot
371 (package
372 (inherit mes)
373 (name "mes-boot")
374 (version "0.22")
375 (source (origin
376 (method url-fetch)
377 (uri (string-append "mirror://gnu/mes/"
378 "mes-" version ".tar.gz"))
379 (sha256
380 (base32
381 "0p1jsrrmcbc0zrvbvnjbb6iyxr0in71km293q8qj6gnar6bw09av"))))
382 (inputs '())
383 (propagated-inputs '())
384 (native-inputs
385 `(("nyacc-source" ,(origin (inherit (package-source nyacc-0.99))
386 (snippet #f)))
387 ("mes" ,%bootstrap-mes-rewired)
388 ("mescc-tools" ,%bootstrap-mescc-tools)
389 ,@(%boot-gash-inputs)))
390 (arguments
391 `(#:implicit-inputs? #f
392 #:tests? #f
393 #:guile ,%bootstrap-guile
394 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
395 #:phases
396 (modify-phases %standard-phases
397 (add-after 'unpack 'unpack-seeds
398 (lambda _
399 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
400 (with-directory-excursion ".."
401 (invoke "tar" "-xvf" nyacc-source)))))
402 (replace 'configure
403 (lambda* (#:key outputs #:allow-other-keys)
404 (let ((out (assoc-ref %outputs "out"))
405 (gash (assoc-ref %build-inputs "bash"))
406 (mes (assoc-ref %build-inputs "mes"))
407 (dir (with-directory-excursion ".." (getcwd))))
408 (setenv "AR" (string-append "gash " (getcwd) "/scripts/mesar"))
409 (setenv "BASH" (string-append gash "/bin/bash"))
410 (setenv "CC" (string-append mes "/bin/mescc"))
411 (setenv "GUILE_LOAD_PATH"
412 (string-append
413 mes "/share/mes/module"
414 ":" dir "/nyacc-0.99.0/module"))
415 (invoke "gash" "configure.sh"
416 (string-append "--prefix=" out)
417 (string-append "--host=i686-linux-gnu")))))
418 (replace 'build
419 (lambda _
420 (invoke "sh" "bootstrap.sh")))
421 (delete 'check)
422 (replace 'install
423 (lambda _
424 (substitute* "install.sh" ; show some progress
425 ((" -xf") " -xvf")
426 (("^( *)((cp|mkdir|tar) [^']*[^\\])\n" all space cmd)
427 (string-append space "echo '" cmd "'\n"
428 space cmd "\n")))
429 (invoke "sh" "install.sh")
430 ;; Keep ASCII output, for friendlier comparison and bisection
431 (let* ((out (assoc-ref %outputs "out"))
432 (cache (string-append out "/lib/cache")))
433 (define (objects-in-dir dir)
434 (find-files dir
435 (lambda (name stat)
436 (and (equal? (dirname name) dir)
437 (or (string-suffix? ".o" name)
438 (string-suffix? ".s" name))))))
439 (for-each (lambda (x) (install-file x cache))
440 (append (objects-in-dir ".")
441 (objects-in-dir "mescc-lib"))))
442 #t)))))
443 (native-search-paths
444 (list (search-path-specification
445 (variable "C_INCLUDE_PATH")
446 (files '("include")))
447 (search-path-specification
448 (variable "LIBRARY_PATH")
449 (files '("lib")))
450 (search-path-specification
451 (variable "MES_PREFIX")
452 (separator #f)
453 (files '("")))))))
454
455
456 (define tcc-boot0
457 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
458 ;; patches. In a very early and rough form they were presented to the
459 ;; TinyCC developers, who at the time showed no interest in supporting the
460 ;; bootstrappable effort; we will try again later. These patches have been
461 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
462 ;; mature, this package should use the 0.9.27 sources (or later).
463 (package
464 (inherit tcc)
465 (name "tcc-boot0")
466 (version "0.9.26-1103-g6e62e0e")
467 (source (origin
468 (method url-fetch)
469 (uri (string-append
470 "http://lilypond.org/janneke/mes/20191117/"
471 "/tcc-" version ".tar.gz"))
472 (sha256
473 (base32
474 "1qbybw7mxbgkv3sazvz1v7c8byq998vk8f1h25ik8w3d2l63lxng"))))
475 (build-system gnu-build-system)
476 (supported-systems '("i686-linux" "x86_64-linux"))
477 (inputs '())
478 (propagated-inputs '())
479 (native-inputs
480 `(("mes" ,mes-boot)
481 ("nyacc-source" ,(origin (inherit (package-source nyacc-0.99))
482 (snippet #f)))
483 ("mescc-tools" ,%bootstrap-mescc-tools)
484 ,@(%boot-gash-inputs)))
485 (arguments
486 `(#:implicit-inputs? #f
487 #:guile ,%bootstrap-guile
488 #:validate-runpath? #f ; no dynamic executables
489 #:strip-binaries? #f ; no strip yet
490 #:phases
491 (modify-phases %standard-phases
492 (add-after 'unpack 'unpack-seeds
493 (lambda* (#:key outputs #:allow-other-keys)
494 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
495 (with-directory-excursion ".."
496 (invoke "tar" "-xvf" nyacc-source)))))
497 (replace 'configure
498 (lambda* (#:key outputs #:allow-other-keys)
499 (let* ((out (assoc-ref %outputs "out"))
500 (dir (with-directory-excursion ".." (getcwd)))
501 (interpreter "/lib/mes-loader"))
502
503 (setenv "prefix" out)
504 (setenv "GUILE_LOAD_PATH"
505 (string-append dir "/nyacc-0.99.0/module"))
506
507 (substitute* "conftest.c"
508 (("volatile") ""))
509
510 (invoke "sh" "configure"
511 "--cc=mescc"
512 (string-append "--prefix=" out)
513 (string-append "--elfinterp=" interpreter)
514 "--crtprefix=."
515 "--tccdir=."))))
516 (replace 'build
517 (lambda _
518 (substitute* "bootstrap.sh" ; Show some progress
519 (("^( *)((cp|ls|mkdir|rm|[.]/tcc|[.]/[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
520 (string-append space "echo \"" cmd "\"\n"
521 space cmd "\n")))
522 (invoke "sh" "bootstrap.sh")))
523 (replace 'check
524 (lambda _
525 ;; fail fast tests
526 (system* "./tcc" "--help") ; --help exits 1
527 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
528 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
529 ;; TODO: add sensible check target (without depending on make)
530 ;; (invoke "sh" "check.sh")
531 #t))
532 (replace 'install
533 (lambda _
534 (substitute* "install.sh" ; Show some progress
535 (("^( *)((cp|ls|mkdir|rm|tar|./[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
536 (string-append space "echo \"" cmd "\"\n"
537 space cmd "\n")))
538
539 (invoke "sh" "install.sh"))))))
540 (native-search-paths
541 (list (search-path-specification
542 (variable "C_INCLUDE_PATH")
543 (files '("include")))
544 (search-path-specification
545 (variable "LIBRARY_PATH")
546 (files '("lib")))))))
547
548 (define gzip-mesboot
549 ;; The initial gzip. We keep this scripted gzip build before building make
550 ;; to soften the dependency on Gash Core Utils gzip.
551 (package
552 (inherit gzip)
553 (version "1.2.4")
554 (name "gzip-mesboot")
555 (source (origin
556 (method url-fetch)
557 (uri (string-append "mirror://gnu/gzip/gzip-" version ".tar"))
558 (sha256
559 (base32
560 "1rhgk2vvmdvnn6vygf0dja92ryyng00knl0kz5srb77k2kryjb2d"))))
561 (supported-systems '("i686-linux" "x86_64-linux"))
562 (inputs '())
563 (propagated-inputs '())
564 (native-inputs `(("tcc" ,tcc-boot0)
565 ,@(%boot-gash-inputs)))
566 (arguments
567 `(#:implicit-inputs? #f
568 #:guile ,%bootstrap-guile
569 #:strip-binaries? #f ; no strip yet
570 #:phases
571 (modify-phases %standard-phases
572 (delete 'configure)
573 (add-after 'unpack 'scripted-patch
574 (lambda _
575 (substitute* "util.c"
576 (("^char [*]strlwr" all) (string-append all "_tcc_cannot_handle_dupe")))
577 #t))
578 (replace 'build
579 (lambda _
580 (let ((files '("bits" "crypt" "deflate" "getopt" "gzip"
581 "inflate" "lzw" "trees" "unlzh" "unlzw"
582 "unpack" "unzip" "util" "zip")))
583 (define (compile x)
584 (invoke "tcc" "-c" "-D NO_UTIME=1" "-D HAVE_UNISTD_H=1"
585 (string-append x ".c")))
586 (for-each compile files)
587 (apply invoke
588 (cons* "tcc" "-o" "gzip"
589 (map (lambda (x) (string-append x ".o")) files)))
590 (link "gzip" "gunzip"))))
591 (replace 'install
592 (lambda _
593 (let* ((out (assoc-ref %outputs "out"))
594 (bin (string-append out "/bin")))
595 (install-file "gzip" bin)
596 (install-file "gunzip" bin))))
597 (replace 'check
598 (lambda _
599 (invoke "./gzip" "--version")))
600 ;; no gzip yet
601 (delete 'compress-documentation))))))
602
603 (define gnu-make-mesboot0
604 ;; The initial make
605 (package
606 (inherit gnu-make)
607 (name "make-mesboot0")
608 (version "3.80")
609 (source (origin
610 (method url-fetch)
611 (uri (string-append "mirror://gnu/make/make-" version ".tar.gz"))
612 (sha256
613 (base32
614 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
615 (supported-systems '("i686-linux" "x86_64-linux"))
616 (inputs '())
617 (propagated-inputs '())
618 (native-inputs `(("tcc" ,tcc-boot0)
619 ,@(%boot-gash-inputs)))
620 (arguments
621 `(#:implicit-inputs? #f
622 #:guile ,%bootstrap-guile
623 #:configure-flags '("CC=tcc"
624 "CPP=tcc -E"
625 "LD=tcc"
626 "--build=i686-unknown-linux-gnu"
627 "--host=i686-unknown-linux-gnu"
628 "--disable-nls")
629 #:modules ((guix build gnu-build-system)
630 (guix build utils)
631 (srfi srfi-1))
632 #:strip-binaries? #f ; no strip yet
633 #:phases
634 (modify-phases %standard-phases
635 (add-after 'unpack 'scripted-patch
636 (lambda _
637 (substitute* "build.sh.in"
638 (("@LIBOBJS@") "getloadavg.o")
639 (("@REMOTE@") "stub"))
640 #t))
641 (add-after 'configure 'configure-fixup
642 (lambda _
643 (substitute* "make.h"
644 (("^extern long int lseek.*" all) (string-append "// " all)))
645 #t))
646 (replace 'build
647 (lambda _
648 (invoke "sh" "./build.sh")))
649 (replace 'check ; proper check needs awk
650 (lambda _
651 (invoke "./make" "--version")))
652 (replace 'install
653 (lambda _
654 (let* ((out (assoc-ref %outputs "out"))
655 (bin (string-append out "/bin")))
656 (install-file "make" bin)))))))))
657
658 (define (%boot-tcc0-inputs)
659 `(("make" ,gnu-make-mesboot0)
660 ("tcc" ,tcc-boot0)
661 ,@(%boot-gash-inputs)))
662
663 (define bzip2-mesboot
664 ;; The initial bzip2
665 (package
666 (inherit bzip2)
667 (name "bzip2-mesboot")
668 (version (package-version bzip2))
669 (source (bootstrap-origin (package-source bzip2)))
670 (supported-systems '("i686-linux" "x86_64-linux"))
671 (inputs '())
672 (propagated-inputs '())
673 (native-inputs (%boot-tcc0-inputs))
674 (outputs '("out"))
675 (arguments
676 `(#:implicit-inputs? #f
677 #:guile ,%bootstrap-guile
678 #:parallel-build? #f
679 #:tests? #f ; check is naive, also checks non-built PROGRAMS
680 #:strip-binaries? #f ; no strip yet
681 #:make-flags (list "CC=tcc -I ." "AR=tcc -ar" "bzip2"
682 (string-append "PREFIX="
683 (assoc-ref %outputs "out")))
684 #:phases
685 (modify-phases %standard-phases
686 (add-after 'unpack 'scripted-patch
687 (lambda _
688 (substitute* "Makefile"
689 (("\tln " all)
690 (string-append "\t#" all)))
691 (substitute* "bzip2.c"
692 (("struct utimbuf uTimBuf;" all)
693 (string-append "// " all))
694 (("uTimBuf[.]" all)
695 (string-append "// " all))
696 (("retVal = utime [(] dstName, &uTimBuf [)];" all)
697 (string-append "retVal = 0; // " all)))
698 #t))
699 (replace 'configure
700 (lambda _
701 (with-output-to-file "utime.h"
702 (lambda _ (display "
703 #define fchown(filedes, owner, group) 0
704 #define fchmod(filedes, mode) 0
705 ")))
706 #t))
707 (replace 'check
708 (lambda _
709 (invoke "./bzip2" "--help")))
710 ;; FIXME: no compressing gzip yet
711 (delete 'compress-documentation))))))
712
713 (define bash-mesboot0
714 ;; The initial Bash
715 (package
716 (inherit static-bash)
717 (name "bash-mesboot0")
718 (version "2.05b")
719 (source (origin
720 (method url-fetch)
721 (uri (string-append "mirror://gnu/bash/bash-"
722 version ".tar.gz"))
723 (sha256
724 (base32
725 "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs"))))
726 (inputs '())
727 (propagated-inputs '())
728 (native-inputs (%boot-tcc0-inputs))
729 (outputs '("out"))
730 (arguments
731 `(#:implicit-inputs? #f
732 #:guile ,%bootstrap-guile
733 #:parallel-build? #f
734 #:strip-binaries? #f ; no strip yet
735 #:configure-flags
736 (list "--build=i686-unknown-linux-gnu"
737 "--host=i686-unknown-linux-gnu"
738
739 "--without-bash-malloc"
740 "--disable-readline"
741 "--disable-history"
742 "--disable-help-builtin"
743 "--disable-progcomp"
744 "--disable-net-redirections"
745 "--disable-nls"
746
747 ;; Pretend 'dlopen' is missing so we don't build loadable
748 ;; modules and related code.
749 "ac_cv_func_dlopen=no")
750 #:make-flags '("bash")
751 #:phases
752 (modify-phases %standard-phases
753 (add-before 'configure 'setenv
754 (lambda _
755 (let* ((gash (assoc-ref %build-inputs "bash"))
756 (shell (string-append gash "/bin/gash")))
757 (setenv "CONFIG_SHELL" shell)
758 (setenv "SHELL" shell)
759 (setenv "CC" "tcc")
760 (setenv "LD" "tcc")
761 (setenv "AR" "tcc -ar")
762 (setenv "CFLAGS" "-D _POSIX_VERSION=1")
763 #t)))
764 (add-after 'unpack 'scripted-patch
765 (lambda _
766 (substitute* "Makefile.in"
767 (("mksyntax\\.c\n") "mksyntax.c -lgetopt\n")
768 (("buildversion[.]o\n") "buildversion.o -lgetopt\n")
769 ;; No size in Gash
770 (("\tsize ") "#\tsize"))
771 (substitute* "lib/sh/oslib.c"
772 (("int name, namelen;") "char *name; int namelen;"))
773 (substitute* "lib/sh/snprintf.c"
774 (("^#if (defined [(]HAVE_LOCALE_H[)])" all define) (string-append "#if 0 //" define)))
775 (substitute* "configure"
776 ((" egrep") " grep"))
777 #t))
778 (replace 'configure
779 (lambda* (#:key configure-flags #:allow-other-keys)
780 (let ((configure-flags (filter (lambda (x)
781 (and (not (string-prefix? "CONFIG_SHELL=" x))
782 (not (string-prefix? "SHELL=" x))))
783 configure-flags)))
784 (format (current-error-port)
785 "running ./configure ~a\n" (string-join configure-flags)))
786 (apply invoke (cons "./configure" configure-flags))))
787 (add-after 'configure 'configure-fixups
788 (lambda _
789 (substitute* "config.h"
790 (("#define GETCWD_BROKEN 1") "#undef GETCWD_BROKEN"))
791 (let ((config.h (open-file "config.h" "a")))
792 (display (string-append
793 ;; XXX TODO: remove nested ,(string-append ...) and
794 ;; store file name on next rebuild cycle
795 ,(string-append "
796 // tcc: error: undefined symbol 'enable_hostname_completion'
797 #define enable_hostname_completion(on_or_off) 0
798
799 // /gnu/store/" "cq0cmv35s9dhilx14zaghlc08gpc0hwr-tcc-boot0-0.9.26-6.c004e9a/lib/libc.a: error: 'sigprocmask' defined twice
800 #define HAVE_POSIX_SIGNALS 1
801 #define endpwent(x) 0
802 "))
803 config.h)
804 (close config.h))
805 #t))
806 (replace 'check
807 (lambda _
808 (invoke "./bash" "--version")))
809 (replace 'install
810 (lambda _
811 (let* ((out (assoc-ref %outputs "out"))
812 (bin (string-append out "/bin")))
813 (mkdir-p bin)
814 (copy-file "bash" (string-append bin "/bash"))
815 (copy-file "bash" (string-append bin "/sh"))
816 #t))))))))
817
818 (define tcc-boot
819 ;; The final tcc.
820 (package
821 (inherit tcc-boot0)
822 (name "tcc-boot")
823 (version "0.9.27")
824 (source (origin
825 (inherit (package-source tcc))
826 ;; `patches' needs XZ
827 ;; (patches (search-patches "tcc-boot-0.9.27.patch"))
828 ))
829 (build-system gnu-build-system)
830 (inputs '())
831 (propagated-inputs '())
832 (native-inputs `(;;("boot-patch" ,(search-patch "tcc-boot-0.9.27.patch"))
833 ("bzip2" ,bzip2-mesboot)
834 ,@(%boot-tcc0-inputs)))
835 (arguments
836 `(#:implicit-inputs? #f
837 #:guile ,%bootstrap-guile
838 #:validate-runpath? #f ; no dynamic executables
839 #:strip-binaries? #f ; no strip yet
840 #:phases
841 (modify-phases %standard-phases
842 ;; tar xvf ..bz2 gives
843 ;; bzip2: PANIC -- internal consistency error
844 (replace 'unpack
845 (lambda* (#:key source #:allow-other-keys)
846 (copy-file source "tarball.tar.bz2")
847 (invoke "bzip2" "-d" "tarball.tar.bz2")
848 (invoke "tar" "xvf" "tarball.tar")
849 (chdir (string-append "tcc-" ,version))
850 #t))
851 ;; no patch yet
852 ;; (add-after 'unpack 'apply-boot-patch
853 ;; (lambda* (#:key inputs #:allow-other-keys)
854 ;; (let ((patch-file (assoc-ref inputs "boot-patch")))
855 ;; (invoke "patch" "-p1" "-i" patch-file))))
856 (add-after 'unpack 'scripted-patch
857 (lambda* (#:key inputs #:allow-other-keys)
858 (substitute* "libtcc.c"
859 (("s->alacarte_link = 1;" all)
860 (string-append all "
861 s->static_link = 1;")))
862 #t))
863 (replace 'configure
864 (lambda* (#:key outputs #:allow-other-keys)
865 (let* ((out (assoc-ref %outputs "out"))
866 (tcc (assoc-ref %build-inputs "tcc"))
867 (libc (assoc-ref %build-inputs "libc"))
868 (interpreter "/mes/loader"))
869 (invoke "sh" "configure"
870 (string-append "--cc=tcc")
871 (string-append "--cpu=i386")
872 (string-append "--prefix=" out)
873 (string-append "--elfinterp=" interpreter)
874 (string-append "--crtprefix=" tcc "/lib")
875 (string-append "--sysincludepaths=" tcc "/include")
876 (string-append "--libpaths=" tcc "/lib")))))
877 (replace 'build
878 (lambda* (#:key outputs #:allow-other-keys)
879 (let* ((out (assoc-ref %outputs "out"))
880 (tcc (assoc-ref %build-inputs "tcc"))
881 (libc (assoc-ref %build-inputs "libc"))
882 (interpreter "/mes/loader"))
883 (invoke
884 "tcc"
885 "-vvv"
886 "-D" "BOOTSTRAP=1"
887 "-D" "ONE_SOURCE=1"
888 "-D" "TCC_TARGET_I386=1"
889 "-D" "CONFIG_TCC_STATIC=1"
890 "-D" "CONFIG_USE_LIBGCC=1"
891 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
892 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
893 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
894 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
895 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
896 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\""
897 tcc "/include" ":/include:{B}/include\"")
898 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
899 "-o" "tcc"
900 "tcc.c"))))
901 (replace 'check
902 (lambda _
903 ;; FIXME: add sensible check target (without depending on make)
904 ;; ./check.sh ?
905 (= 1 (status:exit-val (system* "./tcc" "--help")))))
906 (replace 'install
907 (lambda* (#:key outputs #:allow-other-keys)
908 (let ((out (assoc-ref %outputs "out"))
909 (tcc (assoc-ref %build-inputs "tcc")))
910 (and
911 (mkdir-p (string-append out "/bin"))
912 (copy-file "tcc" (string-append out "/bin/tcc"))
913 (mkdir-p (string-append out "/lib/tcc"))
914 (copy-recursively (string-append tcc "/include")
915 (string-append out "/include"))
916 (copy-recursively (string-append tcc "/lib")
917 (string-append out "/lib"))
918 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
919 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
920 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
921 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
922 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
923 #t)))))))))
924
925 (define diffutils-mesboot
926 ;; The initial diffutils.
927 (package
928 (inherit diffutils)
929 (name "diffutils-mesboot")
930 (version "2.7")
931 (source (origin
932 (method url-fetch)
933 (uri (string-append "mirror://gnu/diffutils/diffutils-"
934 version ".tar.gz"))
935 (sha256
936 (base32
937 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
938 (supported-systems '("i686-linux" "x86_64-linux"))
939 (inputs '())
940 (propagated-inputs '())
941 (native-inputs (%boot-tcc0-inputs))
942 (arguments
943 `(#:implicit-inputs? #f
944 #:guile ,%bootstrap-guile
945 #:parallel-build? #f
946 #:tests? #f ; check is naive, also checks non-built PROGRAMS
947 #:strip-binaries? #f ; no strip yet
948 #:phases
949 (modify-phases %standard-phases
950 (add-before 'configure 'remove-diff3-sdiff
951 (lambda* (#:key outputs #:allow-other-keys)
952 (substitute* "Makefile.in"
953 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))))
954 (replace 'configure ; needs classic invocation of configure
955 (lambda* (#:key configure-flags #:allow-other-keys)
956 (let* ((out (assoc-ref %outputs "out"))
957 (bash (assoc-ref %build-inputs "bash"))
958 (shell (string-append bash "/bin/bash")))
959 (setenv "CONFIG_SHELL" shell)
960 (setenv "CC" "tcc")
961 (setenv "LD" "tcc")
962 (format (current-error-port)
963 "running ./configure ~a\n" (string-join configure-flags))
964 (apply invoke (cons "./configure" configure-flags)))))
965 (replace 'install
966 (lambda _
967 (let* ((out (assoc-ref %outputs "out"))
968 (bin (string-append out "/bin")))
969 (mkdir-p bin)
970 (install-file "cmp" bin)
971 (install-file "diff" bin)
972 #t))))))))
973
974 (define patch-mesboot
975 ;; The initial patch.
976 (package
977 (inherit patch)
978 (name "patch-mesboot")
979 (version "2.5.9")
980 (source (origin
981 (method url-fetch)
982 (uri (string-append "mirror://gnu/patch/patch-"
983 version ".tar.gz"))
984 (sha256
985 (base32
986 "12nv7jx3gxfp50y11nxzlnmqqrpicjggw6pcsq0wyavkkm3cddgc"))))
987 (supported-systems '("i686-linux" "x86_64-linux"))
988 (inputs '())
989 (propagated-inputs '())
990 (native-inputs (%boot-tcc0-inputs))
991 (arguments
992 `(#:implicit-inputs? #f
993 #:guile ,%bootstrap-guile
994 #:parallel-build? #f
995 #:tests? #f ; check is naive, also checks non-built PROGRAMS
996 #:strip-binaries? #f ; no strip yet
997 #:configure-flags '("AR=tcc -ar" "CC=tcc" "LD-tcc")
998 #:phases
999 (modify-phases %standard-phases
1000 (add-after 'unpack 'scripted-patch
1001 (lambda _
1002 ;; avoid another segfault
1003 (substitute* "pch.c"
1004 (("while [(]p_end >= 0[)]" all)
1005 "p_end = -1;\nwhile (0)"))
1006 #t))
1007 ;; FIXME: no compressing gzip yet
1008 (delete 'compress-documentation))))))
1009
1010 (define sed-mesboot0
1011 ;; The initial sed.
1012 (package
1013 (inherit sed)
1014 (name "sed-mesboot0")
1015 (version "1.18")
1016 (source (origin
1017 (method url-fetch)
1018 (uri (string-append "mirror://gnu/sed/sed-"
1019 version ".tar.gz"))
1020 (sha256
1021 (base32
1022 "1hyv7i82jd0q18xcql51ylc8jwadp3gb3irgcqlis3v61p35jsv2"))))
1023 (supported-systems '("i686-linux" "x86_64-linux"))
1024 (inputs '())
1025 (propagated-inputs '())
1026 (native-inputs (%boot-tcc0-inputs))
1027 (arguments
1028 `(#:implicit-inputs? #f
1029 #:guile ,%bootstrap-guile
1030 #:parallel-build? #f
1031 #:configure-flags '("CC=tcc")
1032 #:make-flags '("CC=tcc" "extra_objs=" "DEFS=-D HAVE_BCOPY")
1033 #:strip-binaries? #f ; no strip yet
1034 #:phases
1035 (modify-phases %standard-phases
1036 (add-after 'unpack 'scripted-patch
1037 (lambda _
1038 (let* ((out (assoc-ref %outputs "out"))
1039 (bash (assoc-ref %build-inputs "bash"))
1040 (shell (string-append bash "/bin/bash")))
1041 (substitute* "configure"
1042 (("/bin/sh") shell))
1043 #t)))
1044 (replace 'check
1045 (lambda _
1046 (invoke "./sed" "--version")))
1047 (replace 'install
1048 (lambda _
1049 (let* ((out (assoc-ref %outputs "out"))
1050 (bin (string-append out "/bin")))
1051 (install-file "sed" bin)
1052 #t))))))))
1053
1054 (define (%boot-tcc-inputs)
1055 `(("bash" ,bash-mesboot0)
1056 ("bzip2" ,bzip2-mesboot)
1057 ("diffutils" ,diffutils-mesboot)
1058 ("gzip" ,gzip-mesboot)
1059 ("patch" ,patch-mesboot)
1060 ("sed" ,sed-mesboot0)
1061 ("tcc" ,tcc-boot)
1062 ,@(alist-delete "tcc" (%boot-tcc0-inputs))))
1063
1064 (define binutils-mesboot0
1065 ;; The initial Binutils
1066 (package
1067 (inherit binutils)
1068 (name "binutils-mesboot0")
1069 (version "2.14")
1070 (source (origin
1071 (method url-fetch)
1072 (uri (string-append "mirror://gnu/binutils/binutils-"
1073 version ".tar.gz"))
1074 (sha256
1075 (base32
1076 "1w8xp7k44bkijr974x9918i4p1sw4g2fcd5mxvspkjpg38m214ds"))))
1077 (inputs '())
1078 (propagated-inputs '())
1079 (native-inputs (%boot-tcc-inputs))
1080 (supported-systems '("i686-linux" "x86_64-linux"))
1081 (arguments
1082 `(#:implicit-inputs? #f
1083 #:guile ,%bootstrap-guile
1084 #:tests? #f ; runtest: command not found
1085 #:parallel-build? #f
1086 #:strip-binaries? #f ; no strip yet
1087 #:configure-flags
1088 (let ((out (assoc-ref %outputs "out")))
1089 `("--disable-nls"
1090 "--disable-shared"
1091 "--disable-werror"
1092 "--build=i386-unknown-linux"
1093 "--host=i386-unknown-linux"
1094 "--target=i386-unknown-linux"
1095 "--with-sysroot=/"
1096 ,(string-append "--prefix=" out)))
1097 #:phases
1098 (modify-phases %standard-phases
1099 (add-before 'configure 'setenv
1100 (lambda _
1101 (let* ((out (assoc-ref %outputs "out"))
1102 (bash (assoc-ref %build-inputs "bash"))
1103 (shell (string-append bash "/bin/bash")))
1104 (setenv "CONFIG_SHELL" shell)
1105 (setenv "SHELL" shell)
1106 (setenv "AR" "tcc -ar")
1107 (setenv "RANLIB" "true")
1108 (setenv "CC" "tcc -D __GLIBC_MINOR__=6")
1109 #t)))
1110 (add-after 'unpack 'scripted-patch
1111 (lambda* (#:key inputs #:allow-other-keys)
1112 (substitute* "bfd/configure"
1113 (("^sed -e '/SRC-POTFILES.*" all)
1114 "echo -e 'all:\\n\\ttrue\\n\\ninstall:\\n\\ttrue\\n' > po/Makefile\n"))
1115 #t))
1116 (replace 'configure ; needs classic invocation of configure
1117 (lambda* (#:key configure-flags #:allow-other-keys)
1118 (format (current-error-port)
1119 "running ./configure ~a\n" (string-join configure-flags))
1120 (apply system* "./configure" configure-flags)
1121 (substitute* "config.status"
1122 (("[.]//dev/null") "/dev/null"))
1123 (invoke "sh" "./config.status"))))))))
1124
1125 (define gcc-core-mesboot0
1126 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
1127 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
1128 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
1129 ;; with gcc-2.95.3, binutils (2.14.0, 2.20.1a) and glibc-2.2.5 we found a
1130 ;; GNU toolchain triplet "that works".
1131 (package
1132 (inherit gcc)
1133 (name "gcc-core-mesboot0")
1134 (version "2.95.3")
1135 (source (origin
1136 (method url-fetch)
1137 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
1138 version
1139 ".tar.gz"))
1140 ;; `patches' needs XZ
1141 ;; (patches (search-patches "gcc-boot-2.95.3.patch"))
1142 (sha256
1143 (base32
1144 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an"))))
1145 (supported-systems '("i686-linux" "x86_64-linux"))
1146 (inputs '())
1147 (propagated-inputs '())
1148 (native-inputs `(("boot-patch" ,(search-patch "gcc-boot-2.95.3.patch"))
1149 ("binutils" ,binutils-mesboot0)
1150 ,@(%boot-tcc-inputs)))
1151 (outputs '("out"))
1152 (arguments
1153 `(#:implicit-inputs? #f
1154 #:guile ,%bootstrap-guile
1155 #:tests? #f
1156 #:parallel-build? #f
1157 #:strip-binaries? #f
1158 #:configure-flags
1159 (let ((out (assoc-ref %outputs "out")))
1160 `("--enable-static"
1161 "--disable-shared"
1162 "--disable-werror"
1163 "--build=i686-unknown-linux-gnu"
1164 "--host=i686-unknown-linux-gnu"
1165 ,(string-append "--prefix=" out)))
1166 #:make-flags
1167 `("CC=tcc -static -D __GLIBC_MINOR__=6"
1168 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
1169 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
1170 "AR=ar"
1171 "RANLIB=ranlib"
1172 ,(string-append "LIBGCC2_INCLUDES=-I "
1173 (assoc-ref %build-inputs "tcc")
1174 "/include")
1175 "LANGUAGES=c"
1176 ,(string-append "BOOT_LDFLAGS="
1177 " -B" (assoc-ref %build-inputs "tcc")
1178 "/lib/"))
1179 #:modules ((guix build gnu-build-system)
1180 (guix build utils)
1181 (srfi srfi-1))
1182 #:phases
1183 (modify-phases %standard-phases
1184 (add-after 'unpack 'apply-boot-patch
1185 (lambda* (#:key inputs #:allow-other-keys)
1186 (let ((patch-file (assoc-ref inputs "boot-patch")))
1187 (system* "patch" "--force" "-p1" "-i" patch-file)
1188 #t)))
1189 (add-before 'configure 'setenv
1190 (lambda* (#:key outputs #:allow-other-keys)
1191 (let* ((out (assoc-ref outputs "out"))
1192 (bash (assoc-ref %build-inputs "bash"))
1193 (shell (string-append bash "/bin/bash"))
1194 (tcc (assoc-ref %build-inputs "tcc"))
1195 (cppflags " -D __GLIBC_MINOR__=6"))
1196 (setenv "CONFIG_SHELL" shell)
1197 (setenv "CPPFLAGS" cppflags)
1198 (setenv "CC" (string-append "tcc" cppflags))
1199 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
1200 (setenv "CPP" (string-append "tcc -E" cppflags))
1201 (with-output-to-file "config.cache"
1202 (lambda _
1203 (display "
1204 ac_cv_c_float_format='IEEE (little-endian)'
1205 "))))))
1206 ;; gcc-2.95.3
1207 (replace 'configure ; needs classic invocation of configure
1208 (lambda* (#:key configure-flags #:allow-other-keys)
1209 (format (current-error-port)
1210 "running ./configure ~a\n" (string-join configure-flags))
1211 (apply invoke "./configure" configure-flags)))
1212 (add-after 'configure 'remove-info
1213 (lambda _
1214 ;; no info at this stage
1215 (delete-file-recursively "texinfo")
1216 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
1217 (add-after 'install 'install2
1218 (lambda* (#:key outputs #:allow-other-keys)
1219 (let* ((tcc (assoc-ref %build-inputs "tcc"))
1220 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
1221 (out (assoc-ref outputs "out"))
1222 (gcc-dir (string-append
1223 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1224 (mkdir-p "tmp")
1225 (with-directory-excursion "tmp"
1226 (invoke "ar" "x" (string-append "../gcc/libgcc2.a"))
1227 (invoke "ar" "x" (string-append tcc "/lib/libtcc1.a"))
1228 (apply invoke "ar" "r" (string-append gcc-dir "/libgcc.a")
1229 (find-files "." "\\.o")))
1230 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1231 (copy-file (string-append tcc "/lib/libtcc1.a")
1232 (string-append out "/lib/libtcc1.a"))
1233 (invoke "ar" "x" (string-append tcc "/lib/libtcc1.a"))
1234 (invoke "ar" "x" (string-append tcc "/lib/libc.a"))
1235 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
1236 "libc.o" "libtcc1.o")
1237 #t))))))
1238 (native-search-paths
1239 (list (search-path-specification
1240 (variable "C_INCLUDE_PATH")
1241 (files '("include"
1242
1243 ;; Needed to get things like GCC's <stddef.h>.
1244 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
1245 (search-path-specification
1246 (variable "LIBRARY_PATH")
1247 (files '("lib")))))))
1248
1249 (define (%boot-mesboot-core-inputs)
1250 `(("binutils" ,binutils-mesboot0)
1251 ("gawk" ,gawk-mesboot0)
1252 ("gcc" ,gcc-core-mesboot0)
1253 ,@(alist-delete "tcc" (%boot-tcc-inputs))))
1254
1255 (define mesboot-headers
1256 (package
1257 (inherit mes-boot)
1258 (name "mesboot-headers")
1259 (supported-systems '("i686-linux" "x86_64-linux"))
1260 (inputs '())
1261 (propagated-inputs '())
1262 (native-inputs `(("kernel-headers" ,%bootstrap-linux-libre-headers)
1263 ,@(%boot-tcc-inputs)))
1264 (arguments
1265 `(#:implicit-inputs? #f
1266 #:guile ,%bootstrap-guile
1267 #:tests? #f
1268 #:strip-binaries? #f
1269 #:phases
1270 (modify-phases %standard-phases
1271 (delete 'configure)
1272 (delete 'build)
1273 (replace 'install
1274 (lambda* (#:key outputs #:allow-other-keys)
1275 (let* ((out (assoc-ref outputs "out"))
1276 (include (string-append out "/include"))
1277 (headers (assoc-ref %build-inputs "kernel-headers")))
1278 (mkdir-p include)
1279 (copy-recursively "include" out)
1280 (copy-recursively headers out)
1281 #t))))))))
1282
1283 (define gawk-mesboot0
1284 ;; The initial Gawk.
1285 (package
1286 (inherit gawk)
1287 (name "gawk-mesboot0")
1288 (version "3.0.0")
1289 (source (origin
1290 (method url-fetch)
1291 (uri (string-append "mirror://gnu/gawk/gawk-"
1292 version ".tar.gz"))
1293 (sha256
1294 (base32
1295 "087s7vpc8zawn3l7bwv9f44bf59rc398hvaiid63klw6fkbvabr3"))))
1296 (supported-systems '("i686-linux" "x86_64-linux"))
1297 (inputs '())
1298 (propagated-inputs '())
1299 (native-inputs (%boot-tcc-inputs))
1300 (arguments
1301 `(#:implicit-inputs? #f
1302 #:guile ,%bootstrap-guile
1303 #:configure-flags '("--build=i686-unknown-linux-gnu"
1304 "--host=i686-unknown-linux-gnu"
1305 "--disable-nls")
1306 #:make-flags '("gawk")
1307 #:parallel-build? #f
1308 #:parallel-tests? #f
1309 #:strip-binaries? #f ; no strip yet
1310 #:phases
1311 (modify-phases %standard-phases
1312 (add-after 'unpack 'scripted-patch
1313 (lambda _
1314 (substitute* "Makefile.in"
1315 (("date ") "echo today ")
1316 ((" autoheader") "true")
1317 ((" -lm ") " "))
1318 (substitute* "test/Makefile.in"
1319 (("^bigtest:.*") "bigtest: basic\n")
1320 (("( |\t)(childin|convfmt|fflush|longwrds|math|negexp)" all sep) sep))))
1321 (add-before 'configure 'setenv
1322 (lambda _
1323 (let* ((out (assoc-ref %outputs "out"))
1324 (bash (assoc-ref %build-inputs "bash"))
1325 (shell (string-append bash "/bin/bash")))
1326 (setenv "CONFIG_SHELL" shell)
1327 (setenv "SHELL" shell)
1328 (setenv "CC" "tcc")
1329 (setenv "CPP" "tcc -E")
1330 (setenv "LD" "tcc")
1331 (setenv "ac_cv_func_getpgrp_void" "yes")
1332 (setenv "ac_cv_func_tzset" "yes"))
1333 #t))
1334 (replace 'configure ; needs classic invocation of configure
1335 (lambda* (#:key configure-flags #:allow-other-keys)
1336 (let* ((out (assoc-ref %outputs "out"))
1337 (configure-flags
1338 `(,@configure-flags
1339 ,(string-append "--prefix=" out))))
1340 (format (current-error-port) "running ./configure ~a\n" (string-join configure-flags))
1341 (system* "touch" "configure") ; aclocal.m4 is newer than configure
1342 (apply invoke (cons "./configure" configure-flags)))))
1343 (replace 'install
1344 (lambda* (#:key outputs #:allow-other-keys)
1345 (let* ((out (assoc-ref outputs "out"))
1346 (bin (string-append out "/bin")))
1347 (install-file "gawk" bin)
1348 (symlink "gawk" (string-append bin "/awk"))
1349 #t))))))))
1350
1351 (define glibc-mesboot0
1352 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
1353 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
1354 ;; gcc.
1355 (package
1356 (inherit glibc)
1357 (name "glibc-mesboot0")
1358 (version "2.2.5")
1359 (source (origin
1360 (method url-fetch)
1361 (uri (string-append "mirror://gnu/glibc/glibc-"
1362 version
1363 ".tar.gz"))
1364 ;; Patch needs XZ
1365 ;; (patches (search-patches "glibc-boot-2.2.5.patch"))
1366 (sha256
1367 (base32
1368 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q"))))
1369 (supported-systems '("i686-linux" "x86_64-linux"))
1370 (inputs '())
1371 (propagated-inputs '())
1372 (native-inputs `(("boot-patch" ,(search-patch "glibc-boot-2.2.5.patch"))
1373 ("system-patch" ,(search-patch "glibc-bootstrap-system-2.2.5.patch"))
1374 ("headers" ,mesboot-headers)
1375 ,@(%boot-mesboot-core-inputs)))
1376 (outputs '("out"))
1377 (arguments
1378 `(#:implicit-inputs? #f
1379 #:guile ,%bootstrap-guile
1380 #:tests? #f
1381 #:strip-binaries? #f
1382 #:validate-runpath? #f ; no dynamic executables
1383 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1384 #:make-flags (list (string-append
1385 "SHELL="
1386 (assoc-ref %build-inputs "bash")
1387 "/bin/sh"))
1388 #:configure-flags
1389 (let ((out (assoc-ref %outputs "out"))
1390 (headers (assoc-ref %build-inputs "headers")))
1391 `("--disable-shared"
1392 "--enable-static"
1393 "--disable-sanity-checks"
1394 "--build=i686-unknown-linux-gnu"
1395 "--host=i686-unknown-linux-gnu"
1396 ,(string-append "--with-headers=" headers "/include")
1397 "--enable-static-nss"
1398 "--without-__thread"
1399 "--without-cvs"
1400 "--without-gd"
1401 "--without-tls"
1402 ,(string-append "--prefix=" out)))
1403 #:phases
1404 (modify-phases %standard-phases
1405 (add-after 'unpack 'apply-boot-patch
1406 (lambda* (#:key inputs #:allow-other-keys)
1407 (and (let ((patch (assoc-ref inputs "boot-patch")))
1408 (invoke "patch" "--force" "-p1" "-i" patch))
1409 (let ((patch (assoc-ref inputs "system-patch")))
1410 (invoke "patch" "--force" "-p1" "-i" patch)))))
1411 (add-before 'configure 'setenv
1412 (lambda* (#:key outputs #:allow-other-keys)
1413 (let* ((out (assoc-ref outputs "out"))
1414 (bash (assoc-ref %build-inputs "bash"))
1415 (shell (string-append bash "/bin/bash"))
1416 (gcc (assoc-ref %build-inputs "gcc"))
1417 (headers (assoc-ref %build-inputs "headers"))
1418 (cppflags (string-append
1419 ;;" -D __STDC__=1"
1420 " -D MES_BOOTSTRAP=1"
1421 " -D BOOTSTRAP_GLIBC=1"))
1422 (cflags (string-append " -L " (getcwd))))
1423 (setenv "CONFIG_SHELL" shell)
1424 (setenv "SHELL" shell)
1425 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1426 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1427 #t)))
1428 (replace 'configure ; needs classic invocation of configure
1429 (lambda* (#:key configure-flags #:allow-other-keys)
1430 (format (current-error-port)
1431 "running ./configure ~a\n" (string-join configure-flags))
1432 (apply invoke "./configure" configure-flags)))
1433 (add-after 'configure 'fixup-configure
1434 (lambda _
1435 (let* ((out (assoc-ref %outputs "out"))
1436 (bash (assoc-ref %build-inputs "bash"))
1437 (shell (string-append bash "/bin/bash")))
1438 (substitute* "config.make"
1439 (("INSTALL = scripts/") "INSTALL = $(..)./scripts/"))
1440 (substitute* "config.make"
1441 (("INSTALL = scripts/") "INSTALL = $(..)./scripts/")
1442 (("BASH = ") (string-append
1443 "SHELL = " shell "
1444 BASH = ")))
1445 #t))))))))
1446
1447 (define gcc-mesboot0
1448 (package
1449 (inherit gcc-core-mesboot0)
1450 (name "gcc-mesboot0")
1451 (native-inputs `(("boot-patch" ,(search-patch "gcc-boot-2.95.3.patch"))
1452 ;; Packages are given in an order that's relevant for
1453 ;; #include_next purposes.
1454 ("libc" ,glibc-mesboot0)
1455 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1456 ,@(%boot-mesboot-core-inputs)))
1457 (arguments
1458 (substitute-keyword-arguments (package-arguments gcc-core-mesboot0)
1459 ((#:phases phases)
1460 `(modify-phases ,phases
1461 (replace 'setenv
1462 (lambda _
1463 (setenv "CONFIG_SHELL" (which "sh"))
1464 (with-output-to-file "config.cache"
1465 (lambda _
1466 (display "
1467 ac_cv_c_float_format='IEEE (little-endian)'
1468 ")))
1469 #t))
1470 (replace 'install2
1471 (lambda* (#:key outputs #:allow-other-keys)
1472 (let* ((out (assoc-ref outputs "out"))
1473 (gcc-dir (string-append
1474 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1475 (and
1476 (mkdir-p "tmp")
1477 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1478 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1479 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))))))))
1480 ((#:configure-flags configure-flags)
1481 `(let ((out (assoc-ref %outputs "out")))
1482 `("--disable-shared"
1483 "--disable-werror"
1484 "--build=i686-unknown-linux-gnu"
1485 "--host=i686-unknown-linux-gnu"
1486 ,(string-append "--prefix=" out))))
1487 ((#:make-flags make-flags)
1488 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1489 `("RANLIB=true"
1490 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1491 "LANGUAGES=c")))))))
1492
1493 (define (%boot-mesboot0-inputs)
1494 `(("gcc" ,gcc-mesboot0)
1495 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1496 ("libc" ,glibc-mesboot0)
1497 ,@(alist-delete "gcc" (%boot-mesboot-core-inputs))))
1498
1499 (define tar-mesboot
1500 ;; Initial tar with support for xz compression.
1501 (package
1502 (inherit tar)
1503 (name "tar-mesboot")
1504 (version "1.22")
1505 (source (origin
1506 (method url-fetch)
1507 (uri (string-append "mirror://gnu/tar/tar-"
1508 version ".tar.gz"))
1509 (sha256
1510 (base32
1511 "19nvix64y95n5v6rr5g9g3fn08zz85cb5anzd7csfv4a4sz9lw4y"))))
1512 (supported-systems '("i686-linux" "x86_64-linux"))
1513 (inputs '())
1514 (propagated-inputs '())
1515 (native-inputs (%boot-mesboot0-inputs))
1516 (arguments
1517 `(#:implicit-inputs? #f
1518 #:guile ,%bootstrap-guile
1519 #:parallel-build? #f
1520 #:tests? #f ; check is naive, also checks non-built PROGRAMS
1521 #:strip-binaries? #f ; no strip yet
1522 #:configure-flags '("--build=i686-unknown-linux-gnu"
1523 "--host=i686-unknown-linux-gnu"
1524 "--disable-nls")
1525 #:phases
1526 (modify-phases %standard-phases
1527 (replace 'configure
1528 (lambda* (#:key configure-flags #:allow-other-keys)
1529 (let* ((out (assoc-ref %outputs "out"))
1530 (bash (assoc-ref %build-inputs "bash"))
1531 (shell (string-append bash "/bin/bash")))
1532 (setenv "CONFIG_SHELL" shell)
1533 (setenv "SHELL" shell)
1534 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1535 (setenv "gl_cv_func_rename_dest_works" "yes")
1536 (format (current-error-port)
1537 "running ./configure ~a\n" (string-join configure-flags))
1538 (apply invoke (cons "./configure" configure-flags)))))
1539 (add-after 'unpack 'scripted-patch
1540 (lambda _
1541 (let* ((bash (assoc-ref %build-inputs "bash"))
1542 (shell (string-append bash "/bin/bash")))
1543 (substitute* "configure"
1544 ((" /bin/sh") shell)))
1545 (substitute* "Makefile.in"
1546 (("^SUBDIRS = doc") "SUBDIRS ="))
1547 #t))
1548 (replace 'install
1549 (lambda _
1550 (let* ((out (assoc-ref %outputs "out"))
1551 (bin (string-append out "/bin")))
1552 (install-file "src/tar" bin)
1553 #t))))))))
1554
1555 (define grep-mesboot
1556 ;; The initial grep.
1557 (package
1558 (inherit grep)
1559 (name "grep-mesboot")
1560 (version "2.0")
1561 (source (origin
1562 (method url-fetch)
1563 (uri (string-append "mirror://gnu/grep/grep-"
1564 version ".tar.gz"))
1565 (sha256
1566 (base32
1567 "1w862l80lgc5mxvpiy4cfwk761d6xxavn0m3xd2l7xs2kmzvp6lq"))))
1568 (supported-systems '("i686-linux" "x86_64-linux"))
1569 (inputs '())
1570 (propagated-inputs '())
1571 (native-inputs (%boot-mesboot0-inputs))
1572 (arguments
1573 `(#:implicit-inputs? #f
1574 #:guile ,%bootstrap-guile
1575 #:parallel-build? #f
1576 #:phases
1577 (modify-phases %standard-phases
1578 (add-before 'configure 'patch-configure
1579 (lambda _
1580 (let* ((bash (assoc-ref %build-inputs "bash"))
1581 (shell (string-append bash "/bin/bash")))
1582 (substitute* "configure"
1583 ((" [|][|] ./config.status") " || sh ./config.status")))))
1584 (replace 'install
1585 (lambda _
1586 (let* ((out (assoc-ref %outputs "out"))
1587 (bin (string-append out "/bin")))
1588 (install-file "grep" bin)
1589 (symlink "grep" (string-append bin "/egrep"))
1590 (symlink "grep" (string-append bin "/fgrep"))
1591 #t))))))))
1592
1593 (define binutils-mesboot1
1594 (package
1595 (inherit binutils-mesboot0)
1596 (name "binutils-mesboot1")
1597 (native-inputs (%boot-mesboot0-inputs))
1598 (arguments
1599 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1600 ((#:configure-flags configure-flags)
1601 '(let ((out (assoc-ref %outputs "out")))
1602 `("--disable-nls"
1603 "--disable-shared"
1604 "--disable-werror"
1605 "--build=i686-unknown-linux-gnu"
1606 "--host=i686-unknown-linux-gnu"
1607 "--with-sysroot=/"
1608 ,(string-append "--prefix=" out))))
1609 ((#:phases phases)
1610 `(modify-phases ,phases
1611 (replace 'setenv
1612 (lambda _
1613 (let* ((out (assoc-ref %outputs "out"))
1614 (bash (assoc-ref %build-inputs "bash"))
1615 (shell (string-append bash "/bin/bash")))
1616 (setenv "CONFIG_SHELL" shell)
1617 #t)))))))))
1618
1619 (define coreutils-mesboot0
1620 (package
1621 (inherit coreutils)
1622 (name "coreutils-mesboot0")
1623 ;; The latest .gz release of Coreutils is 8.13; which does not build with gcc-2.95.3:
1624 ;; randperm.c: In function `sparse_swap':
1625 ;; randperm.c:117: invalid lvalue in unary `&'
1626 (version "5.0") ; 2003-04
1627 (source (origin
1628 (method url-fetch)
1629 (uri (string-append "mirror://gnu/coreutils/coreutils-"
1630 version ".tar.gz"))
1631 (sha256
1632 (base32
1633 "10wq6k66i8adr4k08p0xmg87ff4ypiazvwzlmi7myib27xgffz62"))))
1634 (native-inputs (%boot-mesboot0-inputs))
1635 (supported-systems '("i686-linux" "x86_64-linux"))
1636 (inputs '())
1637 (propagated-inputs '())
1638 (arguments
1639 `(#:implicit-inputs? #f
1640 #:tests? #f ; WARNING: `perl' is needed, ...
1641 #:parallel-build? #f
1642 #:strip-binaries? #f ; strip: unrecognized option `--only-keep-debug'
1643 #:guile ,%bootstrap-guile
1644 #:configure-flags
1645 '("--disable-doc"
1646 "LIBS=-lc -lnss_files -lnss_dns -lresolv"
1647 "ac_cv_func_gethostbyname=no"
1648 "gl_cv_func_rename_dest_works=yes")))))
1649
1650 (define gnu-make-mesboot
1651 (package
1652 (inherit gnu-make)
1653 (name "make-mesboot")
1654 (version "3.82")
1655 (source (origin
1656 (method url-fetch)
1657 (uri (string-append "mirror://gnu/make/make-"
1658 version ".tar.gz"))
1659 (sha256
1660 (base32
1661 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1662 (native-inputs (%boot-mesboot0-inputs))
1663 (supported-systems '("i686-linux" "x86_64-linux"))
1664 (inputs '())
1665 (propagated-inputs '())
1666 (arguments
1667 `(#:implicit-inputs? #f
1668 #:parallel-build? #f
1669 #:guile ,%bootstrap-guile
1670 #:configure-flags '("LIBS=-lc -lnss_files -lnss_dns -lresolv")
1671 #:phases
1672 (modify-phases %standard-phases
1673 (replace 'check
1674 (lambda _
1675 (invoke "./make" "--version")))
1676 (replace 'install
1677 (lambda* (#:key outputs #:allow-other-keys)
1678 (let* ((out (assoc-ref outputs "out"))
1679 (bin (string-append out "/bin")))
1680 (install-file "make" bin)
1681 #t))))))))
1682
1683 (define gawk-mesboot
1684 (package
1685 (inherit gawk)
1686 (name "gawk-mesboot")
1687 (version "3.1.8")
1688 (source (origin
1689 (method url-fetch)
1690 (uri (string-append "mirror://gnu/gawk/gawk-"
1691 version ".tar.gz"))
1692 (sha256
1693 (base32
1694 "03d5y7jabq7p2s7ys9alay9446mm7i5g2wvy8nlicardgb6b6ii1"))))
1695 (native-inputs `(,@(%boot-mesboot0-inputs)
1696 ("mesboot-headers" ,mesboot-headers)))
1697 (supported-systems '("i686-linux" "x86_64-linux"))
1698 (inputs '())
1699 (propagated-inputs '())
1700 (arguments
1701 `(#:implicit-inputs? #f
1702 #:parallel-build? #f
1703 #:guile ,%bootstrap-guile
1704 #:configure-flags '("ac_cv_func_connect=no")
1705 #:make-flags '("gawk")
1706 #:phases
1707 (modify-phases %standard-phases
1708 (replace 'check
1709 (lambda _
1710 (invoke "./gawk" "--version")))
1711 (replace 'install
1712 (lambda* (#:key outputs #:allow-other-keys)
1713 (let* ((out (assoc-ref outputs "out"))
1714 (bin (string-append out "/bin")))
1715 (install-file "gawk" bin)
1716 (symlink "gawk" (string-append bin "/awk"))
1717 #t))))))))
1718
1719 (define sed-mesboot
1720 (package
1721 (inherit sed)
1722 (name "sed-mesboot")
1723 (version "4.0.6") ; 2003-04
1724 (source (origin
1725 (method url-fetch)
1726 (uri (string-append "mirror://gnu/sed/sed-"
1727 version ".tar.gz"))
1728 (sha256
1729 (base32
1730 "0861ij94cqc4vaaki6r2wlapwcmhpx4ggp4r70f46mb21a8fkvf1"))))
1731 (native-inputs (%boot-mesboot0-inputs))
1732 (supported-systems '("i686-linux" "x86_64-linux"))
1733 (inputs '())
1734 (propagated-inputs '())
1735 (arguments
1736 `(#:implicit-inputs? #f
1737 #:parallel-build? #f
1738 #:guile ,%bootstrap-guile
1739 #:tests? #f ; 8to7 fails
1740 #:phases
1741 (modify-phases %standard-phases
1742 (add-after 'unpack '/bin/sh
1743 (lambda _
1744 (let* ((bash (assoc-ref %build-inputs "bash"))
1745 (shell (string-append bash "/bin/bash")))
1746 (substitute* "testsuite/Makefile.tests"
1747 (("^SHELL = /bin/sh")
1748 (string-append "SHELL = " shell)))
1749 #t))))))))
1750
1751 (define bash-mesboot
1752 (package
1753 (inherit bash-mesboot0)
1754 (version "4.4")
1755 (name "bash-mesboot")
1756 (source (origin
1757 (method url-fetch)
1758 (uri (string-append "mirror://gnu/bash/bash-"
1759 version ".tar.gz"))
1760 (sha256
1761 (base32
1762 "1jyz6snd63xjn6skk7za6psgidsd53k05cr3lksqybi0q6936syq"))))
1763 (inputs '())
1764 (propagated-inputs '())
1765 (native-inputs (%boot-mesboot0-inputs))
1766 (outputs '("out"))
1767 (arguments
1768 `(#:implicit-inputs? #f
1769 #:guile ,%bootstrap-guile
1770 #:parallel-build? #f
1771 #:configure-flags
1772 '("--build=i686-unknown-linux-gnu"
1773 "--host=i686-unknown-linux-gnu"
1774
1775 "--without-bash-malloc"
1776 "--disable-readline"
1777 "--disable-history"
1778 "--disable-help-builtin"
1779 "--disable-progcomp"
1780 "--disable-net-redirections"
1781 "--disable-nls"
1782
1783 ;; Pretend 'dlopen' is missing so we don't build loadable
1784 ;; modules and related code.
1785 "ac_cv_func_dlopen=no")
1786 #:make-flags '("bash")
1787 #:phases
1788 (modify-phases %standard-phases
1789 (add-after 'unpack 'scripted-patch
1790 (lambda _
1791 (substitute* "shell.c"
1792 ((";;") ";"))
1793 #t))
1794 (add-before 'configure 'setenv
1795 (lambda _
1796 (setenv "AWK" "gawk")
1797 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1798 (setenv "gl_cv_func_rename_dest_works" "yes")
1799 #t))
1800 (add-after 'configure 'configure-fixups
1801 (lambda _
1802 (let ((config.h (open-file "config.h" "a")))
1803 (display (string-append "
1804 #define enable_hostname_completion(on_or_off) 0
1805 ")
1806 config.h)
1807 (close config.h))
1808 #t))
1809 (replace 'check
1810 (lambda _
1811 (invoke "./bash" "--version")))
1812 (replace 'install
1813 (lambda _
1814 (let* ((out (assoc-ref %outputs "out"))
1815 (bin (string-append out "/bin")))
1816 (mkdir-p bin)
1817 (copy-file "bash" (string-append bin "/bash"))
1818 (copy-file "bash" (string-append bin "/sh"))
1819 #t))))))))
1820
1821 (define (%boot-mesboot1-inputs)
1822 `(("bash" ,bash-mesboot)
1823 ("binutils" ,binutils-mesboot1)
1824 ("coreutils" ,coreutils-mesboot0)
1825 ("gawk" ,gawk-mesboot)
1826 ("grep" ,grep-mesboot)
1827 ("make" ,gnu-make-mesboot)
1828 ("sed" ,sed-mesboot)
1829 ("tar" ,tar-mesboot)
1830 ,@(fold alist-delete (%boot-mesboot0-inputs)
1831 '("bash" "binutils" "bootar" "coreutils" "gash"
1832 "gawk" "grep" "guile" "make" "sed" "tar"))))
1833
1834 (define gmp-boot
1835 (package
1836 (inherit gmp)
1837 (version "4.3.2")
1838 (source (origin
1839 (method url-fetch)
1840 (uri (string-append "mirror://gnu/gmp/gmp-" version
1841 ".tar.gz"))
1842 (sha256 (base32
1843 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1844
1845 (define mpfr-boot
1846 (package
1847 (inherit mpfr)
1848 (version "2.4.2")
1849 (source (origin
1850 (method url-fetch)
1851 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1852 ".tar.gz"))
1853 (sha256 (base32
1854 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1855
1856 (define mpc-boot
1857 (package
1858 (inherit mpc)
1859 (version "1.0.3")
1860 (source (origin
1861 (method url-fetch)
1862 (uri (string-append
1863 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1864 (sha256
1865 (base32
1866 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1867
1868 (define gcc-core-mesboot1
1869 ;; GCC 4.6.4 is the latest modular distribution. This package is not
1870 ;; stricly needed, but very helpful for development because it builds
1871 ;; relatively fast. If this configures and builds then gcc-mesboot1 also
1872 ;; builds.
1873 (package
1874 (inherit gcc-mesboot0)
1875 (name "gcc-core-mesboot1")
1876 (version "4.6.4")
1877 (source (origin
1878 (method url-fetch)
1879 (uri (string-append "mirror://gnu/gcc/gcc-"
1880 version "/gcc-core-" version ".tar.gz"))
1881 (sha256
1882 (base32
1883 "173kdb188qg79pcz073cj9967rs2vzanyjdjyxy9v0xb0p5sad75"))
1884 ;; Patch needs XZ
1885 ;; (patches (search-patches "gcc-boot-4.6.4.patch"))
1886 ))
1887 (inputs `(("gmp-source" ,(package-source gmp-boot))
1888 ("mpfr-source" ,(package-source mpfr-boot))
1889 ("mpc-source" ,(package-source mpc-boot))))
1890 (native-inputs `(("boot-patch" ,(search-patch "gcc-boot-4.6.4.patch"))
1891 ,@(%boot-mesboot1-inputs)))
1892 (arguments
1893 `(#:implicit-inputs? #f
1894 #:guile ,%bootstrap-guile
1895 #:tests? #f
1896 #:modules ((guix build gnu-build-system)
1897 (guix build utils)
1898 (srfi srfi-1))
1899 #:parallel-build? #f ; for debugging
1900 #:make-flags
1901 (let* ((libc (assoc-ref %build-inputs "libc"))
1902 (ldflags (string-append
1903 "-B" libc "/lib "
1904 "-Wl,-dynamic-linker "
1905 "-Wl," libc
1906 ,(glibc-dynamic-linker "i686-linux"))))
1907 (list (string-append "LDFLAGS=" ldflags)
1908 (string-append "LDFLAGS_FOR_TARGET=" ldflags)))
1909 #:configure-flags
1910 (let ((out (assoc-ref %outputs "out"))
1911 (glibc (assoc-ref %build-inputs "libc")))
1912 (list (string-append "--prefix=" out)
1913 "--build=i686-unknown-linux-gnu"
1914 "--host=i686-unknown-linux-gnu"
1915 (string-append "--with-native-system-header-dir=" glibc "/include")
1916 (string-append "--with-build-sysroot=" glibc "/include")
1917 "--disable-bootstrap"
1918 "--disable-decimal-float"
1919 "--disable-libatomic"
1920 "--disable-libcilkrts"
1921 "--disable-libgomp"
1922 "--disable-libitm"
1923 "--disable-libmudflap"
1924 "--disable-libquadmath"
1925 "--disable-libsanitizer"
1926 "--disable-libssp"
1927 "--disable-libvtv"
1928 "--disable-lto"
1929 "--disable-lto-plugin"
1930 "--disable-multilib"
1931 "--disable-plugin"
1932 "--disable-threads"
1933 "--enable-languages=c"
1934 "--enable-static"
1935 "--disable-shared"
1936 "--enable-threads=single"
1937 "--disable-libstdcxx-pch"
1938 "--disable-build-with-cxx"))
1939 #:phases
1940 (modify-phases %standard-phases
1941 (add-after 'unpack 'apply-boot-patch
1942 (lambda* (#:key inputs #:allow-other-keys)
1943 (let ((patch-file (assoc-ref inputs "boot-patch")))
1944 (format (current-error-port) "patch file=~s\n" patch-file)
1945 (system* "patch" "--force" "-p1" "-i" patch-file))
1946 #t))
1947 ;; c&p from commencement.scm:gcc-boot0
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 (or (invoke "tar" "xvf" source)
1958 (error "failed to unpack tarball"
1959 source)))
1960 (list gmp mpfr mpc))
1961
1962 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1963 ,@(map (lambda (lib)
1964 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1965 ;; into gmp-6.0.0.
1966 `(symlink ,(string-trim-right
1967 (package-full-name lib "-")
1968 char-set:letter)
1969 ,(package-name lib)))
1970 (list gmp-boot mpfr-boot mpc-boot))
1971 #t)))
1972 (add-before 'configure 'setenv
1973 (lambda* (#:key outputs #:allow-other-keys)
1974 (let* ((out (assoc-ref outputs "out"))
1975 (binutils (assoc-ref %build-inputs "binutils"))
1976 (bash (assoc-ref %build-inputs "bash"))
1977 (gcc (assoc-ref %build-inputs "gcc"))
1978 (glibc (assoc-ref %build-inputs "libc"))
1979 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
1980 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1981 (setenv "C_INCLUDE_PATH" (string-append
1982 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include"
1983 ":" kernel-headers "/include"
1984 ":" glibc "/include"
1985 ":" (getcwd) "/mpfr/src"))
1986 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
1987 ":" gcc "/lib"))
1988 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
1989 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
1990 #t))))))))
1991
1992 (define gcc-mesboot1
1993 (package
1994 (inherit gcc-core-mesboot1)
1995 (name "gcc-mesboot1")
1996 (version "4.6.4")
1997 (native-inputs
1998 `(("gcc-g++"
1999 ,(origin
2000 (method url-fetch)
2001 (uri (string-append "mirror://gnu/gcc/gcc-"
2002 version "/gcc-g++-" version ".tar.gz"))
2003 (sha256
2004 (base32
2005 "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9"))))
2006 ,@(package-native-inputs gcc-core-mesboot1)))
2007 (arguments
2008 (substitute-keyword-arguments (package-arguments gcc-core-mesboot1)
2009 ((#:configure-flags configure-flags)
2010 `(let ((out (assoc-ref %outputs "out")))
2011 `("--enable-languages=c,c++"
2012 ,@(filter
2013 (negate (lambda (x) (string-prefix? "--enable-languages=" x)))
2014 ,configure-flags))))
2015 ((#:phases phases)
2016 `(modify-phases ,phases
2017 (add-before 'unpack 'unpack-g++
2018 (lambda _
2019 (let ((source-g++ (assoc-ref %build-inputs "gcc-g++")))
2020 (invoke "tar" "xvf" source-g++))
2021 #t))
2022 (replace 'setenv
2023 (lambda _
2024 (setenv "CONFIG_SHELL" (which "sh"))
2025
2026 ;; Allow MPFR headers to be found.
2027 (setenv "C_INCLUDE_PATH"
2028 (string-append (getcwd) "/mpfr/src:"
2029 (getenv "C_INCLUDE_PATH")))
2030
2031 ;; Set the C++ search path so that C headers can be found as
2032 ;; libstdc++ is being compiled.
2033 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
2034 #t))))))))
2035
2036 (define (%boot-mesboot2-inputs)
2037 `(("gcc" ,gcc-mesboot1)
2038 ,@(alist-delete "gcc" (%boot-mesboot1-inputs))))
2039
2040 (define xz-mesboot
2041 ;; Finally, we can build xz.
2042 (package
2043 (inherit xz)
2044 (name "xz-mesboot")
2045 (version "5.0.0")
2046 (source (bootstrap-origin
2047 (origin
2048 (method url-fetch)
2049 (uri (list (string-append "http://tukaani.org/xz/xz-" version
2050 ".tar.gz")
2051 (string-append "http://multiprecision.org/guix/xz-"
2052 version ".tar.gz")))
2053 (sha256
2054 (base32
2055 "0kf40ggbs1vaaj5s9k4csycahzqcf65n20pa6lngqhm6j0cj3agb")))))
2056 (supported-systems '("i686-linux" "x86_64-linux"))
2057 (inputs '())
2058 (outputs '("out"))
2059 (propagated-inputs '())
2060 (native-inputs (%boot-mesboot2-inputs))
2061 (arguments
2062 `(#:implicit-inputs? #f
2063 #:guile ,%bootstrap-guile
2064 #:parallel-build? #f
2065 #:configure-flags
2066 `("--disable-assembler"
2067 "--disable-shared"
2068 "--enable-small"
2069 "--disable-threads"
2070 "--disable-xzdec"
2071 "--disable-lzmadec"
2072 "--disable-lzmainfo"
2073 "--disable-lzma-links"
2074 "--disable-scripts"
2075 "--disable-doc"
2076 "--disable-nls"
2077 "--disable-symbol-versions"
2078 ;; configure disqualifies BASH, CPP, GCC and GREP
2079 ;; all of which seem fine for the build
2080 "ac_cv_prog_cc_c99=-std=gnu9x"
2081 "ac_cv_path_GREP=grep"
2082 "gl_cv_posix_shell=bash"
2083 "ac_cv_have_decl_optreset=no"
2084 "CPPFLAGS=-D__GNUC__=1")))))
2085
2086 (define hello-mesboot
2087 ;; Check for Scheme-only bootstrap.
2088 (package
2089 (inherit hello)
2090 (name "hello-mesboot")
2091 (supported-systems '("i686-linux" "x86_64-linux"))
2092 (inputs '())
2093 (propagated-inputs '())
2094 (native-inputs (%boot-mesboot2-inputs))
2095 (arguments
2096 `(#:implicit-inputs? #f
2097 #:guile ,%bootstrap-guile
2098 #:parallel-build? #f
2099 ;; checking for grep that handles long lines and -e...
2100 ;; configure: error: no acceptable grep could be found
2101 #:configure-flags '("ac_cv_path_GREP=grep")
2102 #:phases
2103 (modify-phases %standard-phases
2104 (replace 'check
2105 (lambda _
2106 (invoke "./hello"))))))))
2107
2108 (define binutils-mesboot
2109 (package
2110 (inherit binutils)
2111 (name "binutils-mesboot")
2112 (version "2.20.1a")
2113 (source (bootstrap-origin
2114 (origin
2115 (method url-fetch)
2116 (uri (string-append "mirror://gnu/binutils/binutils-"
2117 version ".tar.bz2"))
2118 (patches (search-patches "binutils-boot-2.20.1a.patch"))
2119 (sha256
2120 (base32
2121 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
2122 (inputs '())
2123 (propagated-inputs '())
2124 (native-inputs `(("xz" ,xz-mesboot)
2125 ,@(%boot-mesboot2-inputs)))
2126 (supported-systems '("i686-linux" "x86_64-linux"))
2127 (arguments
2128 `(#:implicit-inputs? #f
2129 #:guile ,%bootstrap-guile
2130 #:tests? #f ; runtest: command not found
2131 #:parallel-build? #f
2132 #:strip-binaries? #f ; no strip yet
2133 #:configure-flags
2134 `("CC=gcc"
2135 "CXX=false"
2136 "RANLIB=true"
2137 "--disable-doc"
2138 "--disable-nls"
2139 "--disable-shared"
2140 "--disable-werror"
2141 "--build=i686-unknown-linux-gnu"
2142 "--host=i686-unknown-linux-gnu"
2143 "--with-sysroot=/"
2144 ;; checking for grep that handles long lines and -e
2145 "ac_cv_path_GREP=grep")
2146 ;; FIXME: ac_cv_path_GREP=grep doesn't seem to be forwarded to
2147 ;; cascading configure's?
2148 #:make-flags '("ac_cv_path_GREP=grep")
2149 #:phases
2150 (modify-phases %standard-phases
2151 (add-after 'unpack 'scripted-patch
2152 (lambda _
2153 ;; sed-mesboot0 cannot build these
2154 (copy-file "binutils/Makefile.in" "binutils/Makefile.in.orig")
2155 (substitute* "binutils/Makefile.in"
2156 ;; binutils/binutils uses an amazingly complex install
2157 ;; command, using FOR, SED, READ, IF, ECHO, SED, SED, AWK,
2158 ;; READ, and then LIBTOOL (to do something like
2159 ;; `mkdir $DESTDIR$bindir; cp readline $DESTDIR$bindir ...')
2160
2161 ;; Some tool [debugme!] cannot handle two escaped newlines
2162 ;; (bash?), and the install stops after $(am__EXEEXT_11)
2163 ;; ("objcopy"), so $(am__EXEEXT_13) ("readelf") and others do
2164 ;; not get installed. Remove the stray newline:
2165 (("^\t@BUILD_NLMCONV@ @BUILD_SRCONV@ @BUILD_DLLTOOL@ @BUILD_WINDRES@ .*") ""))
2166 (substitute* "opcodes/Makefile.in"
2167 (("^SUBDIRS = [.] po") "SUBDIRS = ."))
2168 (substitute* "binutils/Makefile.in"
2169 (("^SUBDIRS = doc po") "SUBDIRS ="))
2170 (substitute* "gas/Makefile.in"
2171 (("^SUBDIRS = doc po") "SUBDIRS ="))
2172 (substitute* "gprof/Makefile.in"
2173 (("^SUBDIRS = po") "SUBDIRS ="))
2174 (substitute* "ld/Makefile.in"
2175 (("^SUBDIRS = po") "SUBDIRS ="))
2176 #t)))))))
2177
2178 (define (%boot-mesboot3-inputs)
2179 `(("binutils" ,binutils-mesboot)
2180 ("xz" ,xz-mesboot)
2181 ,@(alist-delete "binutils" (%boot-mesboot2-inputs))))
2182
2183 (define glibc-headers-mesboot
2184 (package
2185 (inherit glibc-mesboot0)
2186 (name "glibc-headers-mesboot")
2187 (version "2.16.0")
2188 (source (bootstrap-origin
2189 (origin
2190 (method url-fetch)
2191 (uri (string-append "mirror://gnu/glibc/glibc-"
2192 version
2193 ".tar.gz"))
2194 (patches (search-patches "glibc-boot-2.16.0.patch"
2195 "glibc-bootstrap-system-2.16.0.patch"))
2196 (sha256
2197 (base32
2198 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
2199 (native-inputs `(("headers" ,mesboot-headers)
2200 ,@(%boot-mesboot3-inputs)))
2201 (arguments
2202 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
2203 ((#:configure-flags configure-flags)
2204 `(let ((out (assoc-ref %outputs "out"))
2205 (headers (assoc-ref %build-inputs "headers")))
2206 (list
2207 (string-append "--prefix=" out)
2208 "--disable-obsolete-rpc"
2209 "--host=i686-unknown-linux-gnu"
2210 (string-append "--with-headers=" headers "/include")
2211 "--enable-static-nss"
2212 "--with-pthread"
2213 "--without-cvs"
2214 "--without-gd"
2215 "--enable-add-ons=nptl"
2216 ;; avoid: configure: error: confusing output from nm -u
2217 "libc_cv_predef_stack_protector=no")))
2218 ((#:make-flags make-flags)
2219 '(list "install-bootstrap-headers=yes" "install-headers"))
2220 ((#:phases phases)
2221 `(modify-phases ,phases
2222 (delete 'apply-boot-patch)
2223 (delete 'fixup-configure)
2224 (delete 'set-path)
2225 (replace 'unpack
2226 (lambda* (#:key source #:allow-other-keys)
2227 (invoke "tar" "xvf" source)
2228 (chdir (string-append "glibc-" ,version))
2229 #t))
2230 (replace 'setenv
2231 (lambda* (#:key inputs #:allow-other-keys)
2232 (let* ((headers (assoc-ref inputs "headers"))
2233 (libc (assoc-ref inputs "libc"))
2234 (gcc (assoc-ref inputs "gcc"))
2235 (cppflags (string-append
2236 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
2237 " -D BOOTSTRAP_GLIBC=1"))
2238 (cflags (string-append " -L " (getcwd)
2239 " -L " libc "/lib")))
2240 (setenv "libc_cv_friendly_stddef" "yes")
2241 (setenv "CONFIG_SHELL" (which "sh"))
2242 (setenv "SHELL" (which "sh"))
2243
2244 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
2245 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
2246 (setenv "LD" "gcc")
2247
2248 ;; avoid -fstack-protector
2249 (setenv "libc_cv_ssp" "false")
2250 (substitute* "configure"
2251 (("/bin/pwd") "pwd"))
2252 #t)))
2253 (replace 'install
2254 (lambda* (#:key outputs make-flags #:allow-other-keys)
2255 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
2256 (out (assoc-ref outputs "out")))
2257 (and (apply invoke "make" make-flags)
2258 (copy-recursively kernel-headers out)
2259 #t))))
2260 (replace 'configure
2261 (lambda* (#:key configure-flags #:allow-other-keys)
2262 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
2263 (mkdir-p "build")
2264 (chdir "build")
2265 (apply invoke "../configure" configure-flags)))
2266 (add-after 'configure 'remove-sunrpc
2267 (lambda _
2268 (let* ((out (assoc-ref %outputs "out"))
2269 (bash (assoc-ref %build-inputs "bash"))
2270 (shell (string-append bash "/bin/bash")))
2271
2272 (let ((Makefile (open-file "Makefile" "a")))
2273 (display (string-append "
2274
2275 SHELL := " shell "
2276 ")
2277 Makefile)
2278 (close Makefile))
2279 (substitute* "../Makefile"
2280 (("^SHELL := /bin/sh") (string-append "SHELL := " shell)))
2281 (substitute* "../Makeconfig"
2282 (("^SHELL := /bin/sh") (string-append "SHELL := " shell)))
2283 (substitute* "../elf/Makefile"
2284 (("^SHELL := /bin/sh") (string-append "SHELL := " shell)))
2285 (invoke "make" (string-append (getcwd) "/sysd-sorted" ))
2286 (substitute* "sysd-sorted"
2287 ((" sunrpc") " ")
2288 ((" nis") " "))
2289 #t)))))))))
2290
2291 (define glibc-mesboot
2292 (package
2293 (inherit glibc-headers-mesboot)
2294 (name "glibc-mesboot")
2295 (native-inputs `(("headers" ,glibc-headers-mesboot)
2296 ,@(%boot-mesboot3-inputs)))
2297 (arguments
2298 `(#:validate-runpath? #f ; fails when using --enable-shared
2299 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
2300 ((#:make-flags make-flags)
2301 `(let ((bash (assoc-ref %build-inputs "bash")))
2302 (list (string-append "SHELL=" bash "/bin/sh"))))
2303 ((#:phases phases)
2304 `(modify-phases ,phases
2305 (replace 'install
2306 (lambda* (#:key outputs make-flags #:allow-other-keys)
2307 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
2308 (out (assoc-ref outputs "out"))
2309 (install-flags (cons "install" make-flags)))
2310 (and (apply invoke "make" install-flags)
2311 (copy-recursively kernel-headers out)
2312 #t)))))))))))
2313
2314 (define (%boot-mesboot4-inputs)
2315 `(("libc" ,glibc-mesboot)
2316 ,@(alist-delete "libc" (%boot-mesboot3-inputs))))
2317
2318 (define gcc-mesboot1-wrapper
2319 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
2320 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
2321 ;; --enable-shared will fail.
2322 (package
2323 (inherit gcc-mesboot1)
2324 (name "gcc-mesboot1-wrapper")
2325 (source #f)
2326 (inputs '())
2327 (native-inputs `(("bash" ,bash-mesboot)
2328 ("coreutils" ,coreutils-mesboot0)
2329 ("libc" ,glibc-mesboot)
2330 ("gcc" ,gcc-mesboot1)))
2331 (arguments
2332 `(#:implicit-inputs? #f
2333 #:guile ,%bootstrap-guile
2334 #:phases
2335 (modify-phases %standard-phases
2336 (delete 'unpack)
2337 (delete 'configure)
2338 (delete 'install)
2339 (replace 'build
2340 (lambda* (#:key outputs #:allow-other-keys)
2341 (let* ((out (assoc-ref outputs "out"))
2342 (bash (assoc-ref %build-inputs "bash"))
2343 (libc (assoc-ref %build-inputs "libc"))
2344 (gcc (assoc-ref %build-inputs "gcc"))
2345 (bin (string-append out "/bin")))
2346 (mkdir-p bin)
2347 (for-each
2348 (lambda (program)
2349 (let ((wrapper (string-append bin "/" program)))
2350 (with-output-to-file wrapper
2351 (lambda _
2352 (display (string-append "#! " bash "/bin/bash
2353 exec " gcc "/bin/" program
2354 " -Wl,--dynamic-linker"
2355 ;; also for x86_64-linux, we are still on i686-linux
2356 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
2357 " -Wl,--rpath"
2358 " -Wl," libc "/lib"
2359 " \"$@\"
2360 "))
2361 (chmod wrapper #o555)))))
2362 '("cpp"
2363 "gcc"
2364 "g++"
2365 "i686-unknown-linux-gnu-cpp"
2366 "i686-unknown-linux-gnu-gcc"
2367 "i686-unknown-linux-gnu-g++"))
2368 #t)))
2369 (replace 'check
2370 (lambda* (#:key outputs #:allow-other-keys)
2371 (let* ((out (assoc-ref outputs "out"))
2372 (bin (string-append out "/bin"))
2373 (program (string-append bin "/gcc")))
2374 (invoke program "--help")))))))))
2375
2376 (define gcc-mesboot
2377 (package
2378 (inherit gcc-mesboot1)
2379 (name "gcc-mesboot")
2380 (version (package-version gcc-4.9))
2381 (source (bootstrap-origin (package-source gcc-4.9)))
2382 (native-inputs `(("gcc-wrapper" ,gcc-mesboot1-wrapper)
2383 ("gcc" ,gcc-mesboot1)
2384 ("headers" ,glibc-headers-mesboot)
2385 ,@(%boot-mesboot4-inputs)))
2386 (arguments
2387 `(#:validate-runpath? #f
2388 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
2389 ((#:configure-flags configure-flags)
2390 `(let ((out (assoc-ref %outputs "out"))
2391 (glibc (assoc-ref %build-inputs "libc")))
2392 (list (string-append "--prefix=" out)
2393 "--build=i686-unknown-linux-gnu"
2394 "--host=i686-unknown-linux-gnu"
2395
2396 "--with-host-libstdcxx=-lsupc++"
2397
2398 (string-append "--with-native-system-header-dir=" glibc "/include")
2399 (string-append "--with-build-sysroot=" glibc "/include")
2400
2401 "--disable-bootstrap"
2402 "--disable-decimal-float"
2403 "--disable-libatomic"
2404 "--disable-libcilkrts"
2405 "--disable-libgomp"
2406 "--disable-libitm"
2407 "--disable-libmudflap"
2408 "--disable-libquadmath"
2409 "--disable-libsanitizer"
2410 "--disable-libssp"
2411 "--disable-libvtv"
2412 "--disable-lto"
2413 "--disable-lto-plugin"
2414 "--disable-multilib"
2415 "--disable-plugin"
2416 "--disable-threads"
2417 "--enable-languages=c,c++"
2418
2419 "--enable-static"
2420 "--enable-shared"
2421 "--enable-threads=single"
2422
2423 ;; No pre-compiled libstdc++ headers, to save space.
2424 "--disable-libstdcxx-pch"
2425
2426 ;; for libcpp ...
2427 "--disable-build-with-cxx")))
2428 ((#:phases phases)
2429 `(modify-phases ,phases
2430 (delete 'apply-boot-patch)
2431 (delete 'unpack-g++) ; sadly, gcc-4.9.4 does not provide
2432 ; modular core/language downloads
2433 (replace 'setenv
2434 (lambda* (#:key outputs #:allow-other-keys)
2435 (let* ((out (assoc-ref outputs "out"))
2436 (binutils (assoc-ref %build-inputs "binutils"))
2437 (bash (assoc-ref %build-inputs "bash"))
2438 (gcc (assoc-ref %build-inputs "gcc"))
2439 (glibc (assoc-ref %build-inputs "libc"))
2440 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
2441 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
2442 (setenv "C_INCLUDE_PATH" (string-append
2443 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.6.4/include"
2444 ":" kernel-headers "/include"
2445 ":" glibc "/include"
2446 ":" (getcwd) "/mpfr/src"))
2447 (setenv "CPLUS_INCLUDE_PATH" (string-append
2448 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.6.4/include"
2449 ":" kernel-headers "/include"
2450 ":" glibc "/include"
2451 ":" (getcwd) "/mpfr/src"))
2452 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
2453 ":" gcc "/lib"))
2454 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
2455 (format (current-error-port) "CPLUS_INCLUDE_PATH=~a\n" (getenv "CPLUS_INCLUDE_PATH"))
2456 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
2457 #t))))))))))
2458
2459 (define gcc-mesboot-wrapper
2460 ;; We need this so gcc-mesboot can be used to create shared binaries that
2461 ;; have the correct interpreter and runpath to libc.
2462 (package
2463 (inherit gcc-mesboot1-wrapper)
2464 (name "gcc-mesboot-wrapper")
2465 (version (package-version gcc-mesboot))
2466 (source #f)
2467 (inputs '())
2468 (native-inputs `(("bash" ,bash-mesboot)
2469 ("coreutils" ,coreutils-mesboot0)
2470 ("libc" ,glibc-mesboot)
2471 ("gcc" ,gcc-mesboot)))))
2472
2473 (define (%boot-mesboot5-inputs)
2474 `(("gcc-wrapper" ,gcc-mesboot-wrapper)
2475 ("gcc" ,gcc-mesboot)
2476 ,@(fold alist-delete (%boot-mesboot4-inputs) '("gcc" "gcc-wrapper"))))
2477
2478 (define coreutils-mesboot
2479 (package
2480 (inherit coreutils)
2481 (name "coreutils-mesboot")
2482 (source (bootstrap-origin (package-source coreutils)))
2483 (native-inputs (%boot-mesboot5-inputs))
2484 (supported-systems '("i686-linux" "x86_64-linux"))
2485 (inputs '())
2486 (propagated-inputs '())
2487 (arguments
2488 `(#:implicit-inputs? #f
2489 #:guile ,%bootstrap-guile
2490 #:tests? #f))))
2491
2492 (define (%boot-mesboot6-inputs)
2493 `(("coreutils" ,coreutils-mesboot)
2494 ,@(fold alist-delete (%boot-mesboot5-inputs)
2495 '("coreutils" "kernel-headers"))))
2496
2497 (define (%bootstrap-inputs+toolchain)
2498 ;; The traditional bootstrap-inputs. For the i686-linux, x86_64-linux
2499 ;; Scheme-only bootstrap the actual reduced set with bootstrapped toolchain.
2500 (match (%current-system)
2501 ((or "i686-linux" "x86_64-linux")
2502 (%boot-mesboot6-inputs))
2503 (_
2504 (%bootstrap-inputs))))
2505
2506 (define gnu-make-boot0
2507 (package
2508 (inherit gnu-make)
2509 (source (bootstrap-origin (package-source gnu-make)))
2510 (name "make-boot0")
2511 (arguments
2512 `(#:guile ,%bootstrap-guile
2513 #:implicit-inputs? #f
2514 #:tests? #f ; cannot run "make check"
2515 ,@(substitute-keyword-arguments (package-arguments gnu-make)
2516 ((#:configure-flags flags ''())
2517 ;; The generated config.status has some problems due to the
2518 ;; bootstrap environment. Disable dependency tracking to work
2519 ;; around it.
2520 `(cons "--disable-dependency-tracking" ,flags))
2521 ((#:phases phases)
2522 `(modify-phases ,phases
2523 (replace 'build
2524 (lambda _
2525 (invoke "./build.sh")))
2526 (replace 'install
2527 (lambda* (#:key outputs #:allow-other-keys)
2528 (let* ((out (assoc-ref outputs "out"))
2529 (bin (string-append out "/bin")))
2530 (install-file "make" bin)
2531 #t))))))))
2532 (native-inputs '()) ; no need for 'pkg-config'
2533 (inputs (%bootstrap-inputs+toolchain))))
2534
2535 (define bzip2-boot0
2536 (package
2537 (inherit bzip2)
2538 (name "bzip2-boot0")
2539 (native-inputs `())
2540 (inputs
2541 `(("diffutils" ,diffutils-boot0)
2542 ("make" ,gnu-make-boot0)
2543 ,@(%bootstrap-inputs+toolchain)))
2544 (arguments
2545 `(#:guile ,%bootstrap-guile
2546 #:implicit-inputs? #f
2547 ,@(package-arguments bzip2)))))
2548
2549 (define coreutils-boot0
2550 (package
2551 (inherit coreutils)
2552 (source (bootstrap-origin (package-source coreutils)))
2553 (name "coreutils-boot0")
2554 (native-inputs `())
2555 (inputs
2556 `(("make" ,gnu-make-boot0)
2557 ,@(%bootstrap-inputs+toolchain)))
2558 (arguments
2559 `(#:tests? #f
2560 #:implicit-inputs? #f
2561 #:guile ,%bootstrap-guile
2562 ,@(package-arguments coreutils)))))
2563
2564 (define diffutils-boot0
2565 (package
2566 (inherit diffutils)
2567 (name "diffutils-boot0")
2568 (native-inputs `())
2569 (inputs
2570 `(("make" ,gnu-make-boot0)
2571 ,@(%bootstrap-inputs+toolchain)))
2572 (arguments
2573 `(#:tests? #f ; the test suite needs diffutils
2574 #:guile ,%bootstrap-guile
2575 #:implicit-inputs? #f
2576 ,@(match (%current-system)
2577 ((or "arm-linux" "aarch64-linux")
2578 (substitute-keyword-arguments (package-arguments diffutils)
2579 ((#:configure-flags flags ''())
2580 ;; The generated config.status has some problems due to the
2581 ;; bootstrap environment. Disable dependency tracking to work
2582 ;; around it.
2583 `(cons "--disable-dependency-tracking" ,flags))))
2584 (_ '()))))))
2585
2586 (define findutils-boot0
2587 (package
2588 (inherit findutils)
2589 (name "findutils-boot0")
2590 (source (bootstrap-origin (package-source findutils)))
2591 (inputs
2592 `(("make" ,gnu-make-boot0)
2593 ("diffutils" ,diffutils-boot0) ; for tests
2594 ,@(%bootstrap-inputs+toolchain)))
2595 (arguments
2596 `(#:implicit-inputs? #f
2597 #:guile ,%bootstrap-guile
2598
2599 ;; The build system assumes we have done a mistake when time_t is 32-bit
2600 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
2601 ,@(substitute-keyword-arguments (package-arguments findutils)
2602 ((#:configure-flags flags ''())
2603 `(append
2604 ,(if (target-64bit?)
2605 ''("TIME_T_32_BIT_OK=yes")
2606 ''())
2607 ,(match (%current-system)
2608 ((or "arm-linux" "aarch64-linux")
2609 ''("--disable-dependency-tracking"))
2610 (_ ''()))
2611 ,flags)))))))
2612
2613 (define file
2614 (package
2615 (inherit (@ (gnu packages file) file))
2616 (arguments
2617 `(#:configure-flags
2618 `("--disable-bzlib"
2619 ,,@(match (%current-system)
2620 ((or "arm-linux" "aarch64-linux")
2621 '("--disable-dependency-tracking"))
2622 (_ '())))))))
2623
2624 (define file-boot0
2625 (package
2626 (inherit file)
2627 (source (bootstrap-origin (package-source file)))
2628 (name "file-boot0")
2629 (inputs
2630 `(("make" ,gnu-make-boot0)
2631 ,@(%bootstrap-inputs+toolchain)))
2632 (arguments
2633 `(#:tests? #f ; merge test fails
2634 #:implicit-inputs? #f
2635 #:guile ,%bootstrap-guile
2636 #:configure-flags '("--disable-bzlib")
2637 #:strip-binaries? #f
2638 #:validate-runpath? #f
2639 ,@(package-arguments file)))))
2640
2641 (define gawk-boot0
2642 (package
2643 (inherit patch)
2644 (source (bootstrap-origin (package-source gawk)))
2645 (name "gawk-boot0")
2646 (native-inputs '())
2647 (inputs
2648 `(("make" ,gnu-make-boot0)
2649 ,@(%bootstrap-inputs+toolchain)))
2650 (arguments
2651 `(#:tests? #f
2652 #:implicit-inputs? #f
2653 #:guile ,%bootstrap-guile
2654 #:strip-binaries? #f
2655 #:validate-runpath? #f))))
2656
2657 (define patch-boot0
2658 (package
2659 (inherit patch)
2660 (source (bootstrap-origin (package-source patch)))
2661 (name "patch-boot0")
2662 (native-inputs '())
2663 (inputs
2664 `(("make" ,gnu-make-boot0)
2665 ,@(%bootstrap-inputs+toolchain)))
2666 (arguments
2667 `(#:tests? #f ; merge test fails
2668 #:implicit-inputs? #f
2669 #:guile ,%bootstrap-guile
2670 #:strip-binaries? #f
2671 #:validate-runpath? #f))))
2672
2673 (define sed-boot0
2674 (package
2675 (inherit sed)
2676 (name "sed-boot0")
2677 (source (bootstrap-origin (package-source sed)))
2678 (native-inputs '())
2679 (inputs
2680 `(("make" ,gnu-make-boot0)
2681 ,@(%bootstrap-inputs+toolchain)))
2682 (arguments
2683 `(#:implicit-inputs? #f
2684 #:tests? #f
2685 #:guile ,%bootstrap-guile
2686 ,@(package-arguments sed)))))
2687
2688 (define tar-boot0
2689 (package
2690 (inherit tar)
2691 (name "tar-boot0")
2692 (source (bootstrap-origin (package-source tar)))
2693 (native-inputs '())
2694 (inputs
2695 `(("make" ,gnu-make-boot0)
2696 ,@(%bootstrap-inputs+toolchain)))
2697 (arguments
2698 `(#:implicit-inputs? #f
2699 #:tests? #f
2700 #:guile ,%bootstrap-guile
2701 ,@(package-arguments tar)))))
2702
2703 (define (%boot0-inputs)
2704 `(,@(match (%current-system)
2705 ((or "i686-linux" "x86_64-linux")
2706 `(("bzip2" ,bzip2-boot0)
2707 ("coreutils" ,coreutils-boot0)
2708 ("gawk" ,gawk-boot0)
2709 ("patch" ,patch-boot0)
2710 ("sed" ,sed-boot0)
2711 ("tar" ,tar-boot0)))
2712 (_ '()))
2713 ("make" ,gnu-make-boot0)
2714 ("diffutils" ,diffutils-boot0)
2715 ("findutils" ,findutils-boot0)
2716 ("file" ,file-boot0)
2717 ,@(%bootstrap-inputs+toolchain)))
2718
2719 (define* (boot-triplet #:optional (system (%current-system)))
2720 ;; Return the triplet used to create the cross toolchain needed in the
2721 ;; first bootstrapping stage.
2722 (nix-system->gnu-triplet system "guix"))
2723
2724 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
2725 ;; toolchain actually targets the same OS and arch, but it has the advantage
2726 ;; of being independent of the libc and tools in
2727 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
2728 ;; reference to the target libc.
2729
2730 (define binutils-boot0
2731 (package
2732 (inherit binutils)
2733 (source (bootstrap-origin (package-source binutils)))
2734 (name "binutils-cross-boot0")
2735 (arguments
2736 `(#:guile ,%bootstrap-guile
2737 #:implicit-inputs? #f
2738
2739 #:modules ((guix build gnu-build-system)
2740 (guix build utils)
2741 (ice-9 ftw)) ; for 'scandir'
2742 #:phases (modify-phases %standard-phases
2743 (add-after 'install 'add-symlinks
2744 (lambda* (#:key outputs #:allow-other-keys)
2745 ;; The cross-gcc invokes 'as', 'ld', etc, without the
2746 ;; triplet prefix, so add symlinks.
2747 (let ((out (assoc-ref outputs "out"))
2748 (triplet-prefix (string-append ,(boot-triplet) "-")))
2749 (define (has-triplet-prefix? name)
2750 (string-prefix? triplet-prefix name))
2751 (define (remove-triplet-prefix name)
2752 (substring name (string-length triplet-prefix)))
2753 (with-directory-excursion (string-append out "/bin")
2754 (for-each (lambda (name)
2755 (symlink name (remove-triplet-prefix name)))
2756 (scandir "." has-triplet-prefix?)))
2757 #t))))
2758
2759 ,@(substitute-keyword-arguments (package-arguments binutils)
2760 ((#:configure-flags cf)
2761 `(cons ,(string-append "--target=" (boot-triplet))
2762 ,cf)))))
2763 (inputs (%boot0-inputs))))
2764
2765 (define libstdc++-boot0
2766 ;; GCC's libcc1 is always built as a shared library (the top-level
2767 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
2768 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
2769 ;; C++14 features missing in some of our bootstrap compilers.
2770 (let ((lib (make-libstdc++ gcc-4.9)))
2771 (package
2772 (inherit lib)
2773 (source (bootstrap-origin (package-source lib)))
2774 (name "libstdc++-boot0")
2775 (arguments
2776 `(#:guile ,%bootstrap-guile
2777 #:implicit-inputs? #f
2778
2779 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2780 #:validate-runpath? #f
2781
2782 ,@(match (%current-system)
2783 ((or "i686-linux" "x86_64-linux")
2784 (substitute-keyword-arguments (package-arguments lib)
2785 ((#:phases phases)
2786 `(modify-phases ,phases
2787 (add-after 'unpack 'workaround-wrapper-bug
2788 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
2789 ;; fail, which in turn confuses the configure script.
2790 (lambda _
2791 (substitute* "libstdc++-v3/configure"
2792 (("g\\+\\+ -v") "true"))
2793 #t))))))
2794 (_ (package-arguments lib)))))
2795 (inputs (%boot0-inputs))
2796 (native-inputs '()))))
2797
2798 (define gcc-boot0
2799 (package
2800 (inherit gcc)
2801 (name "gcc-cross-boot0")
2802 (source (bootstrap-origin (package-source gcc)))
2803 (arguments
2804 `(#:guile ,%bootstrap-guile
2805 #:implicit-inputs? #f
2806 #:modules ((guix build gnu-build-system)
2807 (guix build utils)
2808 (ice-9 regex)
2809 (srfi srfi-1)
2810 (srfi srfi-26))
2811 ,@(substitute-keyword-arguments (package-arguments gcc)
2812 ((#:configure-flags flags)
2813 `(append (list ,(string-append "--target=" (boot-triplet))
2814
2815 ;; No libc yet.
2816 "--without-headers"
2817
2818 ;; Disable features not needed at this stage.
2819 "--disable-shared"
2820 "--enable-languages=c,c++"
2821
2822 ;; boot-triplet inserts "guix" in the triplet.
2823 ,@(if (equal? "powerpc64le-guix-linux-gnu" (boot-triplet))
2824 ;; On POWER9 (little endian) glibc needs the
2825 ;; 128-bit long double type.
2826 '("--with-long-double-128")
2827 '())
2828
2829 ;; libstdc++ cannot be built at this stage
2830 ;; ("Link tests are not allowed after
2831 ;; GCC_NO_EXECUTABLES.").
2832 "--disable-libstdc++-v3"
2833
2834 "--disable-threads"
2835 "--disable-libmudflap"
2836 "--disable-libatomic"
2837 "--disable-libsanitizer"
2838 "--disable-libitm"
2839 "--disable-libgomp"
2840 "--disable-libmpx"
2841 "--disable-libcilkrts"
2842 "--disable-libvtv"
2843 "--disable-libssp"
2844 "--disable-libquadmath"
2845 "--disable-decimal-float")
2846 (remove (cut string-match
2847 "--(with-system-zlib|enable-languages.*)" <>)
2848 ,flags)))
2849 ((#:make-flags flags)
2850 `(let* ((libc (assoc-ref %build-inputs "libc"))
2851 (libc-native (or (assoc-ref %build-inputs "libc-native")
2852 libc)))
2853 `(,(string-append "LDFLAGS="
2854 "-Wl,-rpath=" libc-native "/lib "
2855 "-Wl,-dynamic-linker "
2856 "-Wl," libc-native ,(glibc-dynamic-linker
2857 (match (%current-system)
2858 ("x86_64-linux" "i686-linux")
2859 (_ (%current-system))))))))
2860 ((#:phases phases)
2861 `(modify-phases ,phases
2862 (add-after 'unpack 'unpack-gmp&co
2863 (lambda* (#:key inputs #:allow-other-keys)
2864 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2865 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2866 (mpc (assoc-ref %build-inputs "mpc-source")))
2867
2868 ;; To reduce the set of pre-built bootstrap inputs, build
2869 ;; GMP & co. from GCC.
2870 (for-each (lambda (source)
2871 (invoke "tar" "xvf" source))
2872 (list gmp mpfr mpc))
2873
2874 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2875 ,@(map (lambda (lib)
2876 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2877 ;; into gmp-6.0.0.
2878 `(symlink ,(string-trim-right
2879 (package-full-name lib "-")
2880 char-set:letter)
2881 ,(package-name lib)))
2882 (list gmp-6.0 mpfr mpc))
2883 #t)))
2884 ,(match (%current-system)
2885 ((or "i686-linux" "x86_64-linux")
2886 '(add-before 'configure 'fix-libcc1
2887 (lambda* (#:key inputs #:allow-other-keys)
2888 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
2889 ;; to placate the 'validate-runpath' phase.
2890 (substitute* "libcc1/Makefile.in"
2891 (("la_LDFLAGS =")
2892 (string-append "la_LDFLAGS = -Wl,-rpath="
2893 (assoc-ref inputs "gcc") "/lib")))
2894 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
2895 (substitute* "libcc1/configure"
2896 (("g\\+\\+ -v") "true"))
2897 #t)))
2898 (_ '(add-before 'configure 'return-true
2899 (lambda _ #t))))
2900 (add-after 'install 'symlink-libgcc_eh
2901 (lambda* (#:key outputs #:allow-other-keys)
2902 (let ((out (assoc-ref outputs "lib")))
2903 ;; Glibc wants to link against libgcc_eh, so provide
2904 ;; it.
2905 (with-directory-excursion
2906 (string-append out "/lib/gcc/"
2907 ,(boot-triplet)
2908 "/" ,(package-version gcc))
2909 (symlink "libgcc.a" "libgcc_eh.a"))
2910 #t))))))))
2911
2912 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2913 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
2914 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
2915 ("binutils-cross" ,binutils-boot0)
2916
2917 ;; The libstdc++ that libcc1 links against.
2918 ("libstdc++" ,libstdc++-boot0)
2919
2920 ;; Call it differently so that the builder can check whether
2921 ;; the "libc" input is #f.
2922 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
2923 ,@(alist-delete "libc" (%boot0-inputs))))
2924
2925 ;; No need for the native-inputs to build the documentation at this stage.
2926 (native-inputs `())))
2927
2928 (define perl-boot0
2929 (package
2930 (inherit perl)
2931 (name "perl-boot0")
2932 (source (bootstrap-origin (package-source perl)))
2933 (inputs (%boot0-inputs))
2934 (arguments
2935 `(#:implicit-inputs? #f
2936 #:guile ,%bootstrap-guile
2937 #:validate-runpath? #f
2938
2939 ;; At the very least, this must not depend on GCC & co.
2940 #:disallowed-references ,(list %bootstrap-binutils)
2941
2942 ,@(substitute-keyword-arguments (package-arguments perl)
2943 ((#:phases phases)
2944 `(modify-phases ,phases
2945 ;; Pthread support is missing in the bootstrap compiler
2946 ;; (broken spec file), so disable it.
2947 (add-before 'configure 'disable-pthreads
2948 (lambda _
2949 (substitute* "Configure"
2950 (("^libswanted=(.*)pthread" _ before)
2951 (string-append "libswanted=" before)))
2952 #t))))
2953 ;; Do not configure with '-Dusethreads' since pthread
2954 ;; support is missing.
2955 ((#:configure-flags configure-flags)
2956 `(delete "-Dusethreads" ,configure-flags)))))))
2957
2958 (define m4-boot0
2959 (package
2960 (inherit m4)
2961 (name "m4-boot0")
2962 (source (bootstrap-origin (package-source m4)))
2963 (inputs (%boot0-inputs))
2964 (arguments
2965 `(#:guile ,%bootstrap-guile
2966 #:implicit-inputs? #f
2967 ,@(package-arguments m4)))))
2968
2969 (define bison-boot0
2970 ;; This Bison is needed to build MiG so we need it early in the process.
2971 ;; Recent versions of Linux-Libre headers also depend on this.
2972 (package
2973 (inherit bison)
2974 (name "bison-boot0")
2975 (propagated-inputs `(("m4" ,m4-boot0)))
2976 (native-inputs `(("perl" ,perl-boot0)))
2977 (inputs (%boot0-inputs)) ;remove Flex...
2978 (arguments
2979 `(#:tests? #f ;... and thus disable tests
2980 #:implicit-inputs? #f
2981 #:guile ,%bootstrap-guile
2982
2983 ;; Zero timestamps in liby.a; this must be done
2984 ;; explicitly here because the bootstrap Binutils don't
2985 ;; do that (default is "cru".)
2986 #:make-flags `("ARFLAGS=crD"
2987 ,,(match (%current-system)
2988 ;; ranlib: '-D': No such file
2989 ((or "i686-linux" "x86_64-linux")
2990 "RANLIB=ranlib")
2991 (_
2992 "RANLIB=ranlib -D"))
2993 "V=1")
2994
2995 ,@(package-arguments bison)))))
2996
2997 (define flex-boot0
2998 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
2999 (package
3000 (inherit flex)
3001 (native-inputs `(("bison" ,bison-boot0)))
3002 (propagated-inputs `(("m4" ,m4-boot0)))
3003 (inputs (%boot0-inputs))
3004 (arguments
3005 `(#:implicit-inputs? #f
3006 #:guile ,%bootstrap-guile
3007 #:tests? #f))))
3008
3009 (define rsync-boot0
3010 (package
3011 (inherit rsync)
3012 (native-inputs `(("perl" ,perl-boot0)))
3013 (inputs (%boot0-inputs))
3014 (arguments
3015 `(#:implicit-inputs? #f
3016 #:guile ,%bootstrap-guile))))
3017
3018 (define-syntax define/system-dependent
3019 (lambda (s)
3020 "Bind IDENTIFIER to EXP, where the value of EXP is known to depend on
3021 '%current-system'. The definition ensures that (1) EXP is \"thunked\" so that
3022 it sees the right value of '%current-system', and (2) that its result is
3023 memoized as a function of '%current-system'."
3024 (syntax-case s ()
3025 ((_ identifier exp)
3026 (with-syntax ((memoized (datum->syntax #'identifier
3027 (symbol-append
3028 (syntax->datum #'identifier)
3029 '/memoized))))
3030 #'(begin
3031 (define memoized
3032 (mlambda (system) exp))
3033 (define-syntax identifier
3034 (identifier-syntax (memoized (%current-system))))))))))
3035
3036 (define/system-dependent linux-libre-headers-boot0
3037 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
3038 ;; between (gnu packages linux) and this module. Additionally, memoize
3039 ;; the result to play well with further memoization and code that relies
3040 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
3041 (package
3042 (inherit linux-libre-headers)
3043 (arguments
3044 `(#:guile ,%bootstrap-guile
3045 #:implicit-inputs? #f
3046 ,@(package-arguments linux-libre-headers)))
3047 (native-inputs
3048 `(("perl" ,perl-boot0)
3049
3050 ;; Flex and Bison are required since version 4.16.
3051 ("flex" ,flex-boot0)
3052 ("bison" ,bison-boot0)
3053
3054 ;; Rsync is required since version 5.3.
3055 ("rsync" ,rsync-boot0)
3056 ,@(%boot0-inputs)))))
3057
3058 (define with-boot0
3059 (package-with-explicit-inputs %boot0-inputs
3060 %bootstrap-guile))
3061
3062 (define gnumach-headers-boot0
3063 (with-boot0
3064 (package-with-bootstrap-guile
3065 (package
3066 (inherit gnumach-headers)
3067 (version "1.8-116-g28b53508")
3068 (source (bootstrap-origin
3069 (origin
3070 (method url-fetch)
3071 (uri (string-append "https://lilypond.org/janneke/hurd/"
3072 "gnumach-" version ".tar.gz"))
3073 (sha256
3074 (base32
3075 "006i0zgwy81vxarpfm12vip4q6i5mgmi5mmy5ldvxp5hx9h3l0zg")))))
3076 (native-inputs '())))))
3077
3078 (define mig-boot0
3079 (let* ((mig (package
3080 (inherit (package-with-bootstrap-guile mig))
3081 (native-inputs `(("bison" ,bison-boot0)
3082 ("flex" ,flex-boot0)))
3083 (inputs `(("flex" ,flex-boot0)))
3084 (arguments
3085 `(#:configure-flags
3086 `(,(string-append "LDFLAGS=-Wl,-rpath="
3087 (assoc-ref %build-inputs "flex") "/lib/")))))))
3088 (with-boot0 mig)))
3089
3090 (define hurd-version-boot0 "0.9-229-ga1efcee8")
3091 (define hurd-source-boot0
3092 (let ((version hurd-version-boot0))
3093 (bootstrap-origin
3094 (origin
3095 (method url-fetch)
3096 (uri (string-append "https://lilypond.org/janneke/hurd/"
3097 "hurd-v" version ".tar.gz"))
3098 (sha256
3099 (base32
3100 "0bq2q2jisxcy0kgcm6rz0z2fddwxxm7azsama7li28a2m08kdpzy"))))))
3101
3102 (define hurd-headers-boot0
3103 (let ((hurd-headers (package (inherit hurd-headers)
3104 (version hurd-version-boot0)
3105 (source hurd-source-boot0)
3106 (native-inputs `(("mig" ,mig-boot0)))
3107 (inputs '()))))
3108 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
3109
3110 (define hurd-minimal-boot0
3111 (let ((hurd-minimal (package (inherit hurd-minimal)
3112 (version hurd-version-boot0)
3113 (source hurd-source-boot0)
3114 (native-inputs `(("mig" ,mig-boot0)))
3115 (inputs '()))))
3116 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
3117
3118 (define/system-dependent hurd-core-headers-boot0
3119 ;; Return the Hurd and Mach headers as well as initial Hurd libraries for
3120 ;; the bootstrap environment.
3121 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
3122 (arguments `(#:guile ,%bootstrap-guile
3123 ,@(package-arguments hurd-core-headers)))
3124 (inputs
3125 `(("gnumach-headers" ,gnumach-headers-boot0)
3126 ("hurd-headers" ,hurd-headers-boot0)
3127 ("hurd-minimal" ,hurd-minimal-boot0)
3128 ,@(%boot0-inputs)))))
3129
3130 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
3131 (match system
3132 ("i586-gnu" hurd-core-headers-boot0)
3133 (_ linux-libre-headers-boot0)))
3134
3135 (define texinfo-boot0
3136 ;; Texinfo used to build libc's manual.
3137 ;; We build without ncurses because it fails to build at this stage, and
3138 ;; because we don't need the stand-alone Info reader.
3139 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
3140 (package
3141 (inherit texinfo)
3142 (native-inputs '())
3143 (inputs `(,@(%boot0-inputs)
3144 ("perl" ,perl-boot0)))
3145 (arguments
3146 `(#:implicit-inputs? #f
3147 #:guile ,%bootstrap-guile
3148
3149 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
3150 ;; character type in locale" but we don't have a UTF-8 locale at this
3151 ;; stage, so skip them.
3152 #:tests? #f))))
3153
3154 (define expat-sans-tests
3155 (package
3156 (inherit expat)
3157 (inputs (%boot0-inputs))
3158 (arguments
3159 ;; XXX: Linking 'runtestscpp' fails with things like:
3160 ;;
3161 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
3162 ;;
3163 ;; Skip tests altogether.
3164 `(#:implicit-inputs? #f
3165 #:guile ,%bootstrap-guile
3166
3167 ,@(substitute-keyword-arguments (package-arguments expat)
3168 ((#:configure-flags flags ''())
3169 ;; Since we're not passing the right -Wl,-rpath flags, build the
3170 ;; static library to avoid RUNPATH validation failure.
3171 `(cons "--disable-shared" ,flags))
3172 ((#:tests? _ #f) #f))))))
3173
3174 (define python-boot0
3175 (package
3176 (inherit python-minimal)
3177 ;; We cannot use Python 3.7 and later here, because they require
3178 ;; pthreads, which is missing on non-x86 platforms at this stage.
3179 ;; Python 3.6 technically supports being built without threading
3180 ;; support, but requires additional patches.
3181 (version "3.5.9")
3182 (source (bootstrap-origin
3183 (origin
3184 (method url-fetch)
3185 (uri (string-append "https://www.python.org/ftp/python/"
3186 version "/Python-" version ".tar.xz"))
3187 (sha256
3188 (base32
3189 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
3190 (modules '((guix build utils)))
3191 (snippet
3192 '(begin
3193 ;; Delete the bundled copy of libexpat.
3194 (delete-file-recursively "Modules/expat")
3195 (substitute* "Modules/Setup.dist"
3196 ;; Link Expat instead of embedding the bundled one.
3197 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
3198 #t)))))
3199 (inputs
3200 `(,@(%boot0-inputs)
3201 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
3202 (native-inputs '()) ;and pkg-config
3203 (arguments
3204 `(#:implicit-inputs? #f
3205 #:guile ,%bootstrap-guile
3206
3207 ,@(substitute-keyword-arguments (package-arguments python-minimal)
3208 ;; Disable features that cannot be built at this stage.
3209 ((#:configure-flags _ ''())
3210 `(list "--without-ensurepip"
3211 "--without-threads"))
3212 ;; Clear #:make-flags, such that changes to the regular
3213 ;; Python package won't interfere with this one.
3214 ((#:make-flags _ ''()) ''())
3215 ((#:phases phases)
3216 ;; Remove the 'apply-alignment-patch' phase if present to avoid
3217 ;; rebuilding this package. TODO: for the next rebuild cycle,
3218 ;; consider inlining all the arguments instead of inheriting to
3219 ;; make it easier to patch Python without risking a full rebuild.
3220 ;; Or better yet, change to 'python-on-guile'.
3221 `(modify-phases ,@(list (match phases
3222 (('modify-phases original-phases
3223 changes ...
3224 ('add-after unpack apply-alignment-patch _))
3225 `(modify-phases ,original-phases ,@changes))
3226 (_ phases)))
3227 (add-before 'configure 'disable-modules
3228 (lambda _
3229 (substitute* "setup.py"
3230 ;; Disable ctypes, since it requires libffi.
3231 (("extensions\\.append\\(ctypes\\)") "")
3232 ;; Prevent the 'ossaudiodev' extension from being
3233 ;; built, since it requires Linux headers.
3234 (("'linux', ") ""))
3235 #t))
3236 (delete 'set-TZDIR)
3237 ,@(if (hurd-system?)
3238 `((add-before 'build 'fix-regen
3239 (lambda* (#:key inputs #:allow-other-keys)
3240 (let ((libc (assoc-ref inputs "libc")))
3241 (substitute* "Lib/plat-generic/regen"
3242 (("/usr/include/") (string-append libc "/include/")))
3243 #t))))
3244 '())))
3245 ((#:tests? _ #f) #f))))))
3246
3247 (define/system-dependent ld-wrapper-boot0
3248 ;; The first 'ld' wrapper, defined with 'define/system-dependent' because
3249 ;; its calls '%boot0-inputs', whose result depends on (%current-system)
3250 ;;
3251 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
3252 ;; in their RUNPATH, otherwise validate-runpath will fail.
3253 (make-ld-wrapper "ld-wrapper-boot0"
3254 #:target boot-triplet
3255 #:binutils binutils-boot0
3256 #:guile %bootstrap-guile
3257 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
3258 #:guile-for-build %bootstrap-guile))
3259
3260 (define (%boot1-inputs)
3261 ;; 2nd stage inputs.
3262 `(("gcc" ,gcc-boot0)
3263 ("ld-wrapper-cross" ,ld-wrapper-boot0)
3264 ("binutils-cross" ,binutils-boot0)
3265 ,@(alist-delete "binutils" (%boot0-inputs))))
3266
3267 (define glibc-final-with-bootstrap-bash
3268 ;; The final libc, "cross-built". If everything went well, the resulting
3269 ;; store path has no dependencies. Actually, the really-final libc is
3270 ;; built just below; the only difference is that this one uses the
3271 ;; bootstrap Bash.
3272 (package
3273 (inherit glibc)
3274 (name "glibc-intermediate")
3275 (source (bootstrap-origin (package-source glibc)))
3276 (arguments
3277 `(#:guile ,%bootstrap-guile
3278 #:implicit-inputs? #f
3279
3280 ,@(substitute-keyword-arguments (package-arguments glibc)
3281 ((#:configure-flags flags)
3282 `(append (list ,(string-append "--host=" (boot-triplet))
3283 ,(string-append "--build="
3284 (nix-system->gnu-triplet))
3285 ,(if (hurd-system?) "--disable-werror"
3286 ""))
3287 ,flags))
3288 ((#:phases phases)
3289 `(modify-phases ,phases
3290 (add-before 'configure 'pre-configure
3291 (lambda* (#:key inputs #:allow-other-keys)
3292 ;; Don't clobber CPATH with the bootstrap libc.
3293 (setenv "NATIVE_CPATH" (getenv "CPATH"))
3294 (unsetenv "CPATH")
3295
3296 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
3297 ,@(if (hurd-system?)
3298 '((substitute* '("sysdeps/mach/Makefile"
3299 "sysdeps/mach/hurd/Makefile")
3300 (("LDLIBS-pthread.so =.*")
3301 (string-append "LDLIBS-pthread.so = "
3302 (assoc-ref %build-inputs "kernel-headers")
3303 "/lib/libihash.a\n"))))
3304 '())
3305
3306 ;; 'rpcgen' needs native libc headers to be built.
3307 (substitute* "sunrpc/Makefile"
3308 (("sunrpc-CPPFLAGS =.*" all)
3309 (string-append "CPATH = $(NATIVE_CPATH)\n"
3310 "export CPATH\n"
3311 all "\n")))
3312 #t)))))))
3313 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
3314 (native-inputs
3315 `(("bison" ,bison-boot0)
3316 ("texinfo" ,texinfo-boot0)
3317 ("perl" ,perl-boot0)
3318 ("python" ,python-boot0)
3319 ,@(if (target-powerpc?)
3320 `(("powerpc64le-patch" ,@(search-patches
3321 "glibc-ldd-powerpc.patch")))
3322 '())))
3323 (inputs
3324 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
3325 ;; it in $CPATH, hence the 'pre-configure' phase above.
3326 ,@(%boot1-inputs)
3327
3328 ;; A native MiG is needed to build Glibc on Hurd.
3329 ,@(if (hurd-system?)
3330 `(("mig" ,mig-boot0))
3331 '())
3332
3333 ;; A native GCC is needed to build `cross-rpcgen'.
3334 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
3335
3336 ;; Here, we use the bootstrap Bash, which is not satisfactory
3337 ;; because we don't want to depend on bootstrap tools.
3338 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
3339
3340 (define (cross-gcc-wrapper gcc binutils glibc bash)
3341 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
3342 that makes it available under the native tool names."
3343 (package (inherit gcc)
3344 (name (string-append (package-name gcc) "-wrapped"))
3345 (source #f)
3346 (build-system trivial-build-system)
3347 (outputs '("out"))
3348 (arguments
3349 `(#:guile ,%bootstrap-guile
3350 #:modules ((guix build utils))
3351 #:builder (begin
3352 (use-modules (guix build utils))
3353
3354 (let* ((binutils (assoc-ref %build-inputs "binutils"))
3355 (gcc (assoc-ref %build-inputs "gcc"))
3356 (libc (assoc-ref %build-inputs "libc"))
3357 (bash (assoc-ref %build-inputs "bash"))
3358 (out (assoc-ref %outputs "out"))
3359 (bindir (string-append out "/bin"))
3360 (triplet ,(boot-triplet)))
3361 (define (wrap-program program)
3362 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
3363 ;; needs to be told where to find the crt files and
3364 ;; the dynamic linker.
3365 (call-with-output-file program
3366 (lambda (p)
3367 (format p "#!~a/bin/bash
3368 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
3369 bash
3370 gcc triplet program
3371 libc libc
3372 ,(glibc-dynamic-linker))))
3373
3374 (chmod program #o555))
3375
3376 (mkdir-p bindir)
3377 (with-directory-excursion bindir
3378 (for-each (lambda (tool)
3379 (symlink (string-append binutils "/bin/"
3380 triplet "-" tool)
3381 tool))
3382 '("ar" "ranlib"))
3383 (for-each wrap-program '("gcc" "g++")))
3384
3385 #t))))
3386 (native-inputs
3387 `(("binutils" ,binutils)
3388 ("gcc" ,gcc)
3389 ("libc" ,glibc)
3390 ("bash" ,bash)))
3391 (inputs '())))
3392
3393 (define/system-dependent gcc-boot0-intermediate-wrapped
3394 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
3395 ;; non-cross names.
3396 (cross-gcc-wrapper gcc-boot0 binutils-boot0
3397 glibc-final-with-bootstrap-bash
3398 (car (assoc-ref (%boot1-inputs) "bash"))))
3399
3400 (define static-bash-for-glibc
3401 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
3402 (package
3403 (inherit static-bash)
3404 (source (bootstrap-origin (package-source static-bash)))
3405 (inputs `(("gcc" ,gcc-boot0-intermediate-wrapped)
3406 ("libc" ,glibc-final-with-bootstrap-bash)
3407 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
3408 ,@(fold alist-delete (%boot1-inputs)
3409 '("gcc" "libc"))))
3410 (arguments
3411 `(#:implicit-inputs? #f
3412 #:guile ,%bootstrap-guile
3413
3414 ,@(substitute-keyword-arguments (package-arguments static-bash)
3415 ((#:configure-flags flags '())
3416 ;; Add a '-L' flag so that the pseudo-cross-ld of
3417 ;; BINUTILS-BOOT0 can find libc.a.
3418 `(append ,flags
3419 (list (string-append "LDFLAGS=-static -L"
3420 (assoc-ref %build-inputs
3421 "libc:static")
3422 "/lib")))))))))
3423
3424 (define gettext-boot0
3425 ;; A minimal gettext used during bootstrap.
3426 (package
3427 (inherit gettext-minimal)
3428 (name "gettext-boot0")
3429 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
3430 ;; simplify the dependency chain, we stick to this version here.
3431 (version "0.19.8.1")
3432 (source (origin
3433 (method url-fetch)
3434 (uri (string-append "mirror://gnu/gettext/gettext-"
3435 version ".tar.gz"))
3436 (sha256
3437 (base32
3438 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
3439 (inputs (%boot1-inputs)) ;zero dependencies
3440 (arguments
3441 `(#:implicit-inputs? #f
3442 #:guile ,%bootstrap-guile
3443 #:tests? #f
3444 #:phases (modify-phases %standard-phases
3445 ;; Build only the tools.
3446 (add-after 'unpack 'chdir
3447 (lambda _
3448 (chdir "gettext-tools")
3449 #t))
3450
3451 ;; Some test programs require pthreads, which we don't have.
3452 (add-before 'configure 'no-test-programs
3453 (lambda _
3454 (substitute* "tests/Makefile.in"
3455 (("^PROGRAMS =.*$")
3456 "PROGRAMS =\n"))
3457 #t)))))))
3458
3459 (define glibc-final
3460 ;; The final glibc, which embeds the statically-linked Bash built above.
3461 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
3462 (package/inherit
3463 glibc
3464 (name "glibc")
3465 (source (bootstrap-origin (package-source glibc)))
3466 (inputs `(("static-bash" ,static-bash-for-glibc)
3467 ,@(alist-delete
3468 "static-bash"
3469 (package-inputs glibc-final-with-bootstrap-bash))))
3470
3471 ;; This time we need 'msgfmt' to install all the libc.mo files.
3472 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
3473 ,@(if (target-powerpc?)
3474 `(("powerpc64le-patch" ,@(search-patches
3475 "glibc-ldd-powerpc.patch")))
3476 '())
3477 ("gettext" ,gettext-boot0)))
3478
3479 (propagated-inputs
3480 (package-propagated-inputs glibc-final-with-bootstrap-bash))
3481
3482 ;; The final libc only refers to itself, but the 'debug' output contains
3483 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
3484 ;; if 'allowed-references' were per-output.
3485 (arguments
3486 `(#:allowed-references
3487 ((,gcc-boot0 "lib")
3488 ,(kernel-headers-boot0)
3489 ,static-bash-for-glibc
3490 ,@(if (hurd-system?)
3491 `(,gnumach-headers-boot0
3492 ,hurd-headers-boot0)
3493 '())
3494 ,@(package-outputs glibc-final-with-bootstrap-bash))
3495 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
3496
3497 (define/system-dependent gcc-boot0-wrapped
3498 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
3499 ;; non-cross names.
3500 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
3501 (car (assoc-ref (%boot1-inputs) "bash"))))
3502
3503 (define (%boot2-inputs)
3504 ;; 3rd stage inputs.
3505 `(("libc" ,glibc-final)
3506 ("libc:static" ,glibc-final "static")
3507 ("gcc" ,gcc-boot0-wrapped)
3508 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
3509
3510 (define binutils-final
3511 (package
3512 (inherit binutils)
3513 (source (bootstrap-origin (package-source binutils)))
3514 (arguments
3515 `(#:guile ,%bootstrap-guile
3516 #:implicit-inputs? #f
3517 #:allowed-references
3518 ,@(match (%current-system)
3519 ((? target-powerpc?)
3520 `(("out" ,glibc-final ,static-bash-for-glibc)))
3521 (_
3522 `(("out" ,glibc-final))))
3523 ,@(package-arguments binutils)))
3524 (inputs
3525 (match (%current-system)
3526 ((? target-powerpc?)
3527 `(("bash" ,static-bash-for-glibc)
3528 ,@(%boot2-inputs)))
3529 (_ (%boot2-inputs))))))
3530
3531 (define libstdc++
3532 ;; Intermediate libstdc++ that will allow us to build the final GCC
3533 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
3534 (let ((lib (make-libstdc++ gcc)))
3535 (package
3536 (inherit lib)
3537 (source (bootstrap-origin (package-source lib)))
3538 (arguments
3539 `(#:guile ,%bootstrap-guile
3540 #:implicit-inputs? #f
3541 #:allowed-references ("out")
3542
3543 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
3544 #:validate-runpath? #f
3545
3546 ;; All of the package arguments from 'make-libstdc++
3547 ;; except for the configure-flags.
3548 ,@(package-arguments lib)
3549 #:configure-flags `("--disable-shared"
3550 "--disable-libstdcxx-dual-abi"
3551 "--disable-libstdcxx-threads"
3552 "--disable-libstdcxx-pch"
3553 ,(string-append "--with-gxx-include-dir="
3554 (assoc-ref %outputs "out")
3555 "/include"))))
3556 (outputs '("out"))
3557 (inputs (%boot2-inputs))
3558 (synopsis "GNU C++ standard library (intermediate)"))))
3559
3560 (define zlib-final
3561 ;; Zlib used by GCC-FINAL.
3562 (package
3563 (inherit zlib)
3564 (arguments
3565 `(#:guile ,%bootstrap-guile
3566 #:implicit-inputs? #f
3567 #:allowed-references ("out" ,glibc-final)
3568 ,@(package-arguments zlib)))
3569 (inputs (%boot2-inputs))))
3570
3571 (define/system-dependent ld-wrapper-boot3
3572 ;; A linker wrapper that uses the bootstrap Guile.
3573 (make-ld-wrapper "ld-wrapper-boot3"
3574 #:binutils binutils-final
3575 #:guile %bootstrap-guile
3576 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
3577 #:guile-for-build %bootstrap-guile))
3578
3579 (define gcc-final
3580 ;; The final GCC.
3581 (package (inherit gcc-boot0)
3582 (name "gcc")
3583
3584 ;; XXX: Currently #:allowed-references applies to all the outputs but the
3585 ;; "debug" output contains disallowed references, notably
3586 ;; linux-libre-headers. Disable the debugging output to work around that.
3587 (outputs (delete "debug" (package-outputs gcc-boot0)))
3588
3589 (arguments
3590 `(#:guile ,%bootstrap-guile
3591 #:implicit-inputs? #f
3592
3593 #:allowed-references ("out" "lib" ,zlib-final
3594 ,glibc-final ,static-bash-for-glibc)
3595
3596 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
3597 ;; reason, but it is not in their RUNPATH. This is a false
3598 ;; positive, so turn it off.
3599 #:validate-runpath? #f
3600
3601 ,@(substitute-keyword-arguments (package-arguments gcc)
3602 ((#:make-flags flags)
3603 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
3604 `(let ((zlib (assoc-ref %build-inputs "zlib")))
3605 (map (lambda (flag)
3606 (if (string-prefix? "LDFLAGS=" flag)
3607 (string-append flag " -L"
3608 (assoc-ref %build-inputs "libstdc++")
3609 "/lib -L" zlib "/lib -Wl,-rpath="
3610 zlib "/lib")
3611 flag))
3612 ,flags)))
3613 ;; Build again GMP & co. within GCC's build process, because it's hard
3614 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
3615 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
3616 ((#:phases phases)
3617 `(modify-phases ,phases
3618 (add-after 'unpack 'unpack-gmp&co
3619 (lambda* (#:key inputs #:allow-other-keys)
3620 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
3621 (mpfr (assoc-ref %build-inputs "mpfr-source"))
3622 (mpc (assoc-ref %build-inputs "mpc-source")))
3623
3624 ;; To reduce the set of pre-built bootstrap inputs, build
3625 ;; GMP & co. from GCC.
3626 (for-each (lambda (source)
3627 (invoke "tar" "xvf" source))
3628 (list gmp mpfr mpc))
3629
3630 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
3631 ,@(map (lambda (lib)
3632 ;; Drop trailing letters, as gmp-6.0.0a unpacks
3633 ;; into gmp-6.0.0.
3634 `(symlink ,(string-trim-right
3635 (package-full-name lib "-")
3636 char-set:letter)
3637 ,(package-name lib)))
3638 (list gmp-6.0 mpfr mpc))
3639 #t))))))))
3640
3641 ;; This time we want Texinfo, so we get the manual. Add
3642 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
3643 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
3644 ;; scripts?).
3645 (native-inputs `(("texinfo" ,texinfo-boot0)
3646 ("perl" ,perl-boot0) ;for manpages
3647 ("static-bash" ,static-bash-for-glibc)
3648 ,@(package-native-inputs gcc-boot0)))
3649
3650 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
3651 ("mpfr-source" ,(package-source mpfr))
3652 ("mpc-source" ,(package-source mpc))
3653 ("ld-wrapper" ,ld-wrapper-boot3)
3654 ("binutils" ,binutils-final)
3655 ("libstdc++" ,libstdc++)
3656 ("zlib" ,zlib-final)
3657 ,@(%boot2-inputs)))))
3658
3659 (define (%boot3-inputs)
3660 ;; 4th stage inputs.
3661 `(("gcc" ,gcc-final)
3662 ("ld-wrapper" ,ld-wrapper-boot3)
3663 ,@(alist-delete "gcc" (%boot2-inputs))))
3664
3665 (define bash-final
3666 ;; Link with `-static-libgcc' to make sure we don't retain a reference
3667 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
3668 ;; on Readline and ncurses.
3669 (let ((bash (static-libgcc-package bash-minimal)))
3670 (package
3671 (inherit bash)
3672 (source (bootstrap-origin (package-source bash)))
3673 (inputs (%boot3-inputs))
3674 (arguments
3675 `(#:implicit-inputs? #f
3676 #:guile ,%bootstrap-guile
3677
3678 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
3679
3680 ,@(package-arguments bash))))))
3681
3682 (define (%boot4-inputs)
3683 ;; Now use the final Bash.
3684 `(("bash" ,bash-final)
3685 ,@(alist-delete "bash" (%boot3-inputs))))
3686
3687 (define with-boot4
3688 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
3689
3690 (define-public guile-final
3691 ;; This package must be public because other modules refer to it. However,
3692 ;; mark it as hidden so that 'fold-packages' ignores it.
3693 (with-boot4 (hidden-package
3694 (package-with-bootstrap-guile guile-3.0/fixed))))
3695
3696 (define glibc-utf8-locales-final
3697 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
3698 ;; by the build processes afterwards so their 'scm_to_locale_string' works
3699 ;; with the full range of Unicode codepoints (remember
3700 ;; 'scm_to_locale_string' is called every time a string is passed to a C
3701 ;; function.)
3702 (package
3703 (inherit glibc-utf8-locales)
3704 (native-inputs
3705 `(("glibc" ,glibc-final)
3706 ("gzip" ,(with-boot4 gzip))))))
3707
3708 (define-public ld-wrapper
3709 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
3710 (make-ld-wrapper "ld-wrapper"
3711 #:binutils binutils-final
3712 #:guile guile-final
3713 #:bash bash-final))
3714
3715 (define (%boot5-inputs)
3716 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
3717 ;; with an older libc, which cannot load the new locale format. See
3718 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
3719 `(("locales" ,glibc-utf8-locales-final)
3720 ,@(%boot4-inputs)))
3721
3722 (define with-boot5
3723 (package-with-explicit-inputs %boot5-inputs))
3724
3725 (define gnu-make-final
3726 ;; The final GNU Make, which uses the final Guile.
3727 (let ((pkg-config (package
3728 (inherit %pkg-config) ;the native pkg-config
3729 (inputs `(("guile" ,guile-final)
3730 ,@(%boot5-inputs)))
3731 (arguments
3732 `(#:implicit-inputs? #f
3733 ,@(package-arguments pkg-config))))))
3734 (package
3735 (inherit (package-with-bootstrap-guile gnu-make))
3736 (inputs `(("guile" ,guile-final)
3737 ,@(%boot5-inputs)))
3738 (native-inputs `(("pkg-config" ,pkg-config)))
3739 (arguments
3740 `(#:implicit-inputs? #f
3741 ,@(package-arguments gnu-make))))))
3742
3743
3744 (define coreutils-final
3745 ;; The final Coreutils. Treat them specially because some packages, such as
3746 ;; Findutils, keep a reference to the Coreutils they were built with.
3747 (with-boot5 (package-with-bootstrap-guile
3748 (package
3749 (inherit coreutils-minimal)
3750 (name "coreutils")))
3751 ;; Use the final Guile, linked against the
3752 ;; final libc with working iconv, so that
3753 ;; 'substitute*' works well when touching
3754 ;; test files in Gettext.
3755 ))
3756
3757 (define grep-final
3758 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
3759 ;; built before gzip.
3760 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
3761 (package/inherit grep
3762 (inputs (alist-delete "pcre" (package-inputs grep)))
3763 (native-inputs `(("perl" ,perl-boot0))))))
3764
3765 (define (%boot6-inputs)
3766 ;; Now use the final Coreutils.
3767 `(("coreutils" ,coreutils-final)
3768 ("grep" ,grep-final)
3769 ,@(%boot5-inputs)))
3770
3771 (define with-boot6
3772 (package-with-explicit-inputs %boot6-inputs))
3773
3774 (define sed-final
3775 ;; The final sed.
3776 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
3777 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
3778
3779 (define-public %final-inputs
3780 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
3781 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
3782 ;; used for origins that have patches, thereby avoiding circular
3783 ;; dependencies.
3784 (let ((finalize (compose with-boot6
3785 package-with-bootstrap-guile)))
3786 `(,@(map (match-lambda
3787 ((name package)
3788 (list name (finalize package))))
3789 `(("tar" ,tar)
3790 ("gzip" ,gzip)
3791 ("bzip2" ,bzip2)
3792 ("xz" ,xz)
3793 ("file" ,file)
3794 ("diffutils" ,diffutils)
3795 ("patch" ,patch)
3796 ("findutils" ,findutils)
3797 ("gawk" ,gawk)))
3798 ("sed" ,sed-final)
3799 ("grep" ,grep-final)
3800 ("coreutils" ,coreutils-final)
3801 ("make" ,gnu-make-final)
3802 ("bash" ,bash-final)
3803 ("ld-wrapper" ,ld-wrapper)
3804 ("binutils" ,binutils-final)
3805 ("gcc" ,gcc-final)
3806 ("libc" ,glibc-final)
3807 ("libc:static" ,glibc-final "static")
3808 ("locales" ,glibc-utf8-locales-final))))
3809
3810 (define-public canonical-package
3811 (let ((name->package (fold (lambda (input result)
3812 (match input
3813 ((_ package . outputs)
3814 (vhash-cons (package-full-name package)
3815 package result))))
3816 vlist-null
3817 `(("guile" ,guile-final)
3818 ,@%final-inputs))))
3819 (lambda (package)
3820 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
3821 the implicit inputs of 'gnu-build-system', return that one, otherwise return
3822 PACKAGE.
3823
3824 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
3825 COREUTILS-FINAL vs. COREUTILS, etc."
3826 ;; XXX: This doesn't handle dependencies of the final inputs, such as
3827 ;; libunistring, GMP, etc.
3828 (match (vhash-assoc (package-full-name package) name->package)
3829 ((_ . canon)
3830 ;; In general we want CANON, except if we're cross-compiling: CANON
3831 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
3832 ;; process, with dependencies on things that cannot be
3833 ;; cross-compiled.
3834 (if (%current-target-system)
3835 package
3836 canon))
3837 (_ package)))))
3838
3839 \f
3840 ;;;
3841 ;;; GCC toolchain.
3842 ;;;
3843
3844 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
3845 ;; instantiated like this:
3846 ;;
3847 ;; (define-public gcc-glibc-2.27-toolchain
3848 ;; (make-gcc-toolchain gcc glibc-2.27))
3849
3850 (define* (make-gcc-toolchain gcc
3851 #:optional
3852 (libc #f))
3853 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
3854 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
3855 (libc (if libc libc glibc-final)))
3856 (package
3857 (name (string-append (package-name gcc) "-toolchain"))
3858 (version (package-version gcc))
3859 (source #f)
3860 (build-system trivial-build-system)
3861 (arguments
3862 '(#:modules ((guix build union))
3863 #:builder (begin
3864 (use-modules (ice-9 match)
3865 (srfi srfi-1)
3866 (srfi srfi-26)
3867 (guix build union))
3868
3869 (let ((out (assoc-ref %outputs "out")))
3870 (union-build out
3871 (filter-map (match-lambda
3872 (("libc-debug" . _) #f)
3873 (("libc-static" . _) #f)
3874 ((_ . directory) directory))
3875 %build-inputs))
3876
3877 (union-build (assoc-ref %outputs "debug")
3878 (list (assoc-ref %build-inputs
3879 "libc-debug")))
3880 (union-build (assoc-ref %outputs "static")
3881 (list (assoc-ref %build-inputs
3882 "libc-static")))
3883 #t))))
3884
3885 (native-search-paths
3886 (append (package-native-search-paths gcc)
3887 (package-native-search-paths libc))) ;GUIX_LOCPATH
3888 (search-paths
3889 (append (package-search-paths gcc)
3890 (package-search-paths libc)))
3891
3892 (license (package-license gcc))
3893 (synopsis "Complete GCC tool chain for C/C++ development")
3894 (description
3895 "This package provides a complete GCC tool chain for C/C++ development to
3896 be installed in user profiles. This includes GCC, as well as libc (headers and
3897 binaries, plus debugging symbols in the @code{debug} output), and Binutils. GCC
3898 is the GNU Compiler Collection.")
3899 (home-page "https://gcc.gnu.org/")
3900 (outputs '("out" "debug" "static"))
3901
3902 ;; The main raison d'être of this "meta-package" is (1) to conveniently
3903 ;; install everything that we need, and (2) to make sure ld-wrapper comes
3904 ;; before Binutils' ld in the user's profile.
3905 (inputs `(("gcc" ,gcc)
3906 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
3907 ("binutils" ,binutils-final)
3908 ("libc" ,libc)
3909 ("libc-debug" ,libc "debug")
3910 ("libc-static" ,libc "static"))))))
3911
3912 (define-public gcc-toolchain
3913 (make-gcc-toolchain gcc-final))
3914
3915 (define-public gcc-toolchain-4.8
3916 (make-gcc-toolchain gcc-4.8))
3917
3918 (define-public gcc-toolchain-4.9
3919 (make-gcc-toolchain gcc-4.9))
3920
3921 (define-public gcc-toolchain-5
3922 (make-gcc-toolchain gcc-5))
3923
3924 (define-public gcc-toolchain-6
3925 (make-gcc-toolchain gcc-6))
3926
3927 (define-public gcc-toolchain-7
3928 gcc-toolchain)
3929
3930 (define-public gcc-toolchain-8
3931 (make-gcc-toolchain gcc-8))
3932
3933 (define-public gcc-toolchain-9
3934 (make-gcc-toolchain gcc-9))
3935
3936 (define-public gcc-toolchain-10
3937 (make-gcc-toolchain gcc-10))
3938
3939 (define-public gcc-toolchain-aka-gcc
3940 ;; It's natural for users to try "guix install gcc". This package
3941 ;; automatically "redirects" them to 'gcc-toolchain'.
3942 (deprecated-package "gcc" gcc-toolchain-10))
3943
3944
3945 (define-public gdc-toolchain-10
3946 (package (inherit (make-gcc-toolchain gdc-10))
3947 (synopsis "Complete GCC tool chain for D lang development")
3948 (description "This package provides a complete GCC tool chain for
3949 D lang development to be installed in user profiles. This includes
3950 gdc, as well as libc (headers and binaries, plus debugging symbols
3951 in the @code{debug} output), and binutils.")))
3952
3953 ;; Provide the Fortran toolchain package only for the version of gfortran that
3954 ;; is used by Guix internally to build Fortran libraries, because combining
3955 ;; code compiled with different versions can cause problems.
3956
3957 (define-public gfortran-toolchain
3958 (package (inherit (make-gcc-toolchain gfortran))
3959 (synopsis "Complete GCC tool chain for Fortran development")
3960 (description "This package provides a complete GCC tool chain for
3961 Fortran development to be installed in user profiles. This includes
3962 gfortran, as well as libc (headers and binaries, plus debugging symbols
3963 in the @code{debug} output), and binutils.")))
3964
3965
3966 ;;; commencement.scm ends here