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