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