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