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