gnu: commencement: tcc-boot0: Use Gash instead of coretutils&co.
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
CommitLineData
bdb36958 1;;; GNU Guix --- Functional package management for GNU
558b0bbe 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
bdb36958
LC
3;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
13f7f2fd 5;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
5fe2c549 6;;; Copyright © 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
53bfec7b 7;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
d3aec6bd 8;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
429243a4 9;;; Copyright © 2019, 2020 Marius Bakke <mbakke@fastmail.com>
bdb36958
LC
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)
b2fd8f63 27 #:use-module (gnu packages)
bdb36958
LC
28 #:use-module (gnu packages bootstrap)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bash)
0b652851 31 #:use-module (gnu packages c)
bdb36958 32 #:use-module (gnu packages gcc)
2d5d63d7 33 #:use-module (gnu packages m4)
c00a9fbf 34 #:use-module (gnu packages file)
bdb36958 35 #:use-module (gnu packages gawk)
2d5d63d7 36 #:use-module (gnu packages bison)
d75acc29 37 #:use-module (gnu packages flex)
bdb36958 38 #:use-module (gnu packages guile)
6162b95d 39 #:use-module (gnu packages gettext)
bdb36958
LC
40 #:use-module (gnu packages multiprecision)
41 #:use-module (gnu packages compression)
0b652851 42 #:use-module (gnu packages mes)
bdb36958 43 #:use-module (gnu packages perl)
5f3f7039 44 #:use-module (gnu packages python)
bdb36958 45 #:use-module (gnu packages linux)
d75acc29 46 #:use-module (gnu packages hurd)
d3aec6bd 47 #:use-module (gnu packages shells)
bdb36958
LC
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages pkg-config)
429243a4 50 #:use-module (gnu packages rsync)
5f3f7039 51 #:use-module (gnu packages xml)
bdb36958
LC
52 #:use-module (guix packages)
53 #:use-module (guix download)
54 #:use-module (guix build-system gnu)
d3aec6bd 55 #:use-module (guix build-system guile)
bdb36958 56 #:use-module (guix build-system trivial)
8102cf0b 57 #:use-module (guix memoization)
bdb36958
LC
58 #:use-module (guix utils)
59 #:use-module (srfi srfi-1)
bdb36958 60 #:use-module (ice-9 vlist)
d75acc29 61 #:use-module (ice-9 match)
6869b663 62 #:export (make-gcc-toolchain))
bdb36958
LC
63
64;;; Commentary:
65;;;
66;;; This is the commencement, this is where things start. Before the
67;;; commencement, of course, there's the 'bootstrap' module, which provides us
68;;; with the initial binaries. This module uses those bootstrap binaries to
69;;; actually build up the whole tool chain that make up the implicit inputs of
70;;; 'gnu-build-system'.
71;;;
72;;; To avoid circular dependencies, this module should not be imported
73;;; directly from anywhere.
74;;;
a1df45e9
CM
75;;; Below, we frequently use "inherit" to create modified packages. The
76;;; reason why we use "inherit" instead of "package/inherit" is because we do
77;;; not want these commencement packages to inherit grafts. By definition,
78;;; these packages are not depended on at run time by any of the packages we
79;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
80;;; grafts would often lead to extra overhead for users who would end up
81;;; downloading those "-boot0" packages just to build package replacements
82;;; that are in fact not going to be used.
83;;;
bdb36958
LC
84;;; Code:
85
899c8f3a
JN
86(define %bootstrap-guile+guild
87 ;; This package combines %bootstrap-guile with guild, which is not included
88 ;; in %bootstrap-guile. Guild is needed to build gash-boot and
89 ;; gash-core-utils-boot because it is dependency of the Guile build system.
90 (package
91 (name "guile-bootstrap+guild")
92 (version "2.0")
93 (source (bootstrap-origin (package-source guile-2.0)))
94 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
95 ("tar" ,(bootstrap-executable "tar" (%current-system)))
96 ("xz" ,(bootstrap-executable "xz" (%current-system)))
97 ("guile" ,%bootstrap-guile)))
98 (build-system trivial-build-system)
99 (arguments
100 `(#:guile ,%bootstrap-guile
101 #:modules ((guix build utils))
102 #:builder (begin
103 (use-modules (guix build utils))
104 (let ((guile-source (assoc-ref %build-inputs "source"))
105 (bin (string-append (getcwd) "/bin"))
106 (tar (assoc-ref %build-inputs "tar"))
107 (xz (assoc-ref %build-inputs "xz")))
108 (mkdir-p bin)
109 (setenv "PATH" bin)
110 (with-directory-excursion bin
111 (copy-file tar "tar")
112 (copy-file xz "xz")
113 (setenv "PATH" bin))
114 (let* ((out (assoc-ref %outputs "out"))
115 (out-bin (string-append out "/bin"))
116 (guile (assoc-ref %build-inputs "guile"))
117 (bash (assoc-ref %build-inputs "bash")))
118 (mkdir-p out-bin)
119 (with-directory-excursion out-bin
120 (symlink (string-append guile "/bin/guile")
121 "guile")
122 (invoke "tar" "--strip-components=2"
123 "-xvf" guile-source
124 (string-append "guile-"
125 ,(package-version guile-2.0)
126 "/meta/guild.in"))
127 (copy-file "guild.in" "guild")
128 (substitute* "guild"
129 (("#!/bin/sh") (string-append "#! " bash))
130 (("@installed_guile@") (string-append out-bin "/guile")))
131 (chmod "guild" #o555)))))))
132 (synopsis "Bootstrap Guile plus Guild")
133 (description "Bootstrap Guile with added Guild")
134 (home-page #f)
d3aec6bd
JN
135 (license (package-license guile-2.0))
136 (native-search-paths
137 (list (search-path-specification
138 (variable "GUILE_LOAD_PATH")
139 (files '("share/guile/site/2.0")))
140 (search-path-specification
141 (variable "GUILE_LOAD_COMPILED_PATH")
142 (files '("lib/guile/2.0/site-ccache")))))))
143
144(define gash-boot
145 (package
146 (inherit gash)
147 (name "gash-boot")
148 (version "0.2.0")
149 (source (bootstrap-origin
150 (origin (inherit (package-source gash))
151 (modules '((guix build utils)
152 (srfi srfi-26)))
153 (snippet
154 '(begin
155 ;; Remove Guix'y files that we cannot compile.
156 (delete-file "guix.scm")
157 (delete-file-recursively "tests")
158 #t)))))
159 (build-system guile-build-system)
160 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
161 ("tar" ,(bootstrap-executable "tar" (%current-system)))
162 ("xz" ,(bootstrap-executable "xz" (%current-system)))
163 ("guile-source" ,(bootstrap-origin
164 (package-source guile-2.0)))))
165 (inputs `(("guile" ,%bootstrap-guile+guild)))
166 (arguments
167 `(#:implicit-inputs? #f
168 #:guile ,%bootstrap-guile+guild
169 #:phases
170 (modify-phases %standard-phases
171 (add-after 'unpack 'unpack-guile-source
172 (lambda _
173 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
174 (bin (string-append (getcwd) "/zee-bin")))
175 (mkdir-p bin)
176 (with-directory-excursion bin
177 (invoke "tar" "--strip-components=2"
178
179 "-xvf" guile-source
180 (string-append "guile-"
181 ,(package-version guile-2.0)
182 "/meta/guild.in"))
183 (copy-file "guild.in" "guild")
184 (chmod "guild" #o555))
185 #t)))
186 (add-before 'unpack 'set-path
187 (lambda _
188 (let ((bash (assoc-ref %build-inputs "bash"))
189 (tar (assoc-ref %build-inputs "tar"))
190 (xz (assoc-ref %build-inputs "xz"))
191 (bin (string-append (getcwd) "/zee-bin")))
192 (mkdir-p bin)
193 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
194 (copy-file bash (string-append bin "/bash"))
195 (copy-file bash (string-append bin "/sh"))
196 (copy-file tar (string-append bin "/tar"))
197 (copy-file xz (string-append bin "/xz"))
198 #t)))
199 (add-after 'build 'build-scripts
200 (lambda _
201 (let* ((guile (assoc-ref %build-inputs "guile"))
202 (guile (string-append guile "/bin/guile"))
203 (out (assoc-ref %outputs "out"))
204 (effective "2.0")
205 (moddir (string-append out "/share/guile/site/" effective "/"))
206 (godir (string-append out "/lib/guile/" effective "/site-ccache/")))
207 (copy-file "scripts/gash.in" "scripts/gash")
208 (chmod "scripts/gash" #o555)
209 (substitute* "scripts/gash"
210 (("@GUILE@") guile)
211 (("@MODDIR@") moddir)
212 (("@GODIR") godir))
213 #t)))
214 (add-after 'install 'install-scripts
215 (lambda _
216 (let* ((out (assoc-ref %outputs "out"))
217 (bin (string-append out "/bin")))
218 (install-file "scripts/gash" bin)
219 (copy-file "scripts/gash" "scripts/sh")
220 (install-file "scripts/sh" bin)
221 (copy-file "scripts/gash" "scripts/bash")
222 (install-file "scripts/bash" bin)
223 #t))))))))
899c8f3a 224
9f5a22b9
JN
225(define gash-core-utils-boot
226 (package
227 (inherit gash-core-utils)
228 (name "gash-core-utils-boot")
229 (version "0.0.213-3f6eb")
230 (source (bootstrap-origin
231 (origin
232 (method url-fetch)
233 (uri (string-append "http://lilypond.org/janneke/"
234 "/gash-core-utils-" version ".tar.gz"))
235 (modules '((guix build utils)))
236 (snippet
237 '(begin
238 ;; The Guile build system compiles *.scm; avoid
239 ;; compiling included lalr.
240 (delete-file "guix.scm")
241 (delete-file-recursively "tests")
242 (substitute* "system/base/lalr.scm"
243 (("system/base/lalr.upstream.scm") "lalr.upstream.scm"))
244 #t))
245 (sha256
246 (base32
247 "0601c9hqbjrjjsllr2m3zmkglkd53d97in7a5c22ikd8islddp76")))))
248 (build-system guile-build-system)
249 (native-inputs `(("bash" ,(bootstrap-executable "bash" (%current-system)))
250 ("tar" ,(bootstrap-executable "tar" (%current-system)))
251 ("xz" ,(bootstrap-executable "xz" (%current-system)))
252 ("guile-source" ,(bootstrap-origin
253 (package-source guile-2.0)))
254 ;; We need the 2.0.9 lalr for %bootstrap-guile
255 ("lalr.upstream"
256 ,(origin
257 (method url-fetch)
258 (uri (string-append "http://git.savannah.gnu.org/cgit/guile.git/plain/module/system/base/lalr.upstream.scm?h=v2.0.9"))
259 (file-name "lalr.upstream.scm")
260 (sha256
261 (base32
262 "0h7gyjj8nr2qrgzwma146s7l22scp8bbcqzdy9wqf12bgyhbw7d5"))))))
263 (inputs `(("guile" ,%bootstrap-guile+guild)
264 ("gash" ,gash-boot)))
265 (arguments
266 `(#:implicit-inputs? #f
267 #:guile ,%bootstrap-guile+guild
268 #:not-compiled-file-regexp "upstream\\.scm$"
269 #:phases
270 (modify-phases %standard-phases
271 (add-after 'unpack 'unpack-guile-source
272 (lambda _
273 (let ((guile-source (assoc-ref %build-inputs "guile-source"))
274 (bin (string-append (getcwd) "/zee-bin")))
275 (mkdir-p bin)
276 (with-directory-excursion bin
277 (invoke "tar" "--strip-components=2"
278
279 "-xvf" guile-source
280 (string-append "guile-"
281 ,(package-version guile-2.0)
282 "/meta/guild.in"))
283 (copy-file "guild.in" "guild")
284 (chmod "guild" #o555))
285 #t)))
286 (add-before 'unpack 'set-path
287 (lambda _
288 (let ((bash (assoc-ref %build-inputs "bash"))
289 (tar (assoc-ref %build-inputs "tar"))
290 (xz (assoc-ref %build-inputs "xz"))
291 (bin (string-append (getcwd) "/zee-bin")))
292 (mkdir-p bin)
293 (setenv "PATH" (string-append bin ":" (getenv "PATH")))
294 (copy-file bash (string-append bin "/bash"))
295 (copy-file bash (string-append bin "/sh"))
296 (copy-file tar (string-append bin "/tar"))
297 (copy-file xz (string-append bin "/xz"))
298 #t)))
299 (add-before 'build 'set-env
300 (lambda _
301 (let ((gash (assoc-ref %build-inputs "gash")))
302 (setenv "LANG" "C")
303 (setenv "LC_ALL" "C")
304 (setenv "GUILE_LOAD_PATH"
305 (string-append (getcwd)
306 ":" (getcwd) "/system/base"
307 ":" gash "/share/guile/2.0"))
308 (setenv "GUILE_LOAD_COMPILED_PATH"
309 (string-append ".:" gash "/lib/guile/2.0/site-ccache/"))
310 (format (current-error-port)
311 "GUILE_LOAD_PATH=~s\n" (getenv "GUILE_LOAD_PATH"))
312 #t)))
313 (add-before 'build 'replace-lalr.upstream
314 (lambda _
315 (let ((lalr.upstream (assoc-ref %build-inputs "lalr.upstream")))
316 (copy-file lalr.upstream "system/base/lalr.upstream.scm")
317 #t)))
318 (add-after 'build 'build-scripts
319 (lambda _
320 (let* ((guile (assoc-ref %build-inputs "guile"))
321 (guile (string-append guile "/bin/guile"))
322 (gash (string-append guile "gash"))
323 (out (assoc-ref %outputs "out"))
324 (effective "2.0")
325 (guilemoduledir (string-append gash "/share/guile/site/" effective "/"))
326 (guileobjectdir (string-append gash "/lib/guile/" effective "/site-ccache/"))
327 (gashmoduledir (string-append out "/share/guile/site/" effective "/"))
328 (gashobjectdir (string-append out "/lib/guile/" effective "/site-ccache/"))
329 (bin (string-append out "/bin")))
330 (define (wrap name)
331 (copy-file "command.in" name)
332 (chmod name #o555)
333 (substitute* name
334 (("@GUILE@") guile)
335 (("@guilemoduledir@") guilemoduledir)
336 (("@guileobjectdir") guileobjectdir)
337 (("@gashmoduledir@") gashmoduledir)
338 (("@gashobjectdir") gashobjectdir)
339 (("@command@") name))
340 (install-file name bin))
341 (mkdir-p bin)
342 (with-directory-excursion "bin"
343 (for-each wrap '("awk"
344 "basename"
345 "cat"
346 "chmod"
347 "cmp"
348 "compress"
349 "cp"
350 "cut"
351 "diff"
352 "dirname"
353 "expr"
354 "false"
355 "find"
356 "grep"
357 "gzip"
358 "head"
359 "ln"
360 "ls"
361 "mkdir"
362 "mv"
363 "pwd"
364 "reboot"
365 "rm"
366 "rmdir"
367 "sed"
368 "sleep"
369 "sort"
370 "tar"
371 "test"
372 "touch"
373 "tr"
374 "true"
375 "uname"
376 "uniq"
377 "wc"
378 "which")))
379 (with-directory-excursion bin
380 (copy-file "grep" "fgrep")
381 (copy-file "grep" "egrep")
382 (copy-file "test" "["))
383 #t))))))))
384
385(define (%boot-gash-inputs)
386 `(("bash" , gash-boot) ; gnu-build-system wants "bash"
387 ("coreutils" , gash-core-utils-boot)
388 ("guile" ,%bootstrap-guile)
389 ("guile+guild" ,%bootstrap-guile+guild)))
390
da2ae09b
JN
391(define %bootstrap-mes-rewired
392 (package
393 (inherit mes)
394 (name "bootstrap-mes-rewired")
395 (version "0.19")
396 (source #f)
397 (native-inputs `(("mes" ,(@ (gnu packages bootstrap) %bootstrap-mes))
398 ("gash" ,gash-boot)))
399 (inputs '())
400 (propagated-inputs '())
401 (outputs '("out"))
402 (build-system trivial-build-system)
403 (arguments
404 `(#:guile ,%bootstrap-guile
405 #:modules ((guix build utils)
406 (srfi srfi-26))
407 #:builder (begin
408 (use-modules (guix build utils)
409 (srfi srfi-26))
410 (let* ((mes (assoc-ref %build-inputs "mes"))
411 (gash (assoc-ref %build-inputs "gash"))
412 (mes-bin (string-append mes "/bin"))
413 (guile (string-append mes-bin "/mes"))
414 (mes-module (string-append mes "/share/mes/module"))
415 (out (assoc-ref %outputs "out"))
416 (bin (string-append out "/bin"))
417 (mescc (string-append bin "/mescc"))
418 (module (string-append out "/share/mes/module")))
419 (define (rewire file)
420 (substitute* file
421 ((mes) out)
422 (("/gnu/store[^ ]+mes-minimal-[^/)}\"]*") out)
423 (("/gnu/store[^ ]+guile-[^/]*/bin/guile") guile)
424 (("/gnu/store[^ ]+bash-[^/)}\"]*") gash)))
425
426 (mkdir-p bin)
427 (for-each (lambda (file) (install-file file bin))
428 (find-files mes-bin))
429 (mkdir-p module)
430 (copy-recursively (string-append mes-module "/mes")
431 (string-append module "/mes"))
432 (copy-recursively (string-append mes-module "/srfi")
433 (string-append module "/srfi"))
434 (for-each rewire
435 ;; Cannot easily rewire "mes" because it
436 ;; contains NUL characters; would require
437 ;; remove-store-references alike trick
438 (filter (negate (cut string-suffix? "/mes" <>))
439 (find-files bin)))
440 (rewire (string-append module "/mes/boot-0.scm"))
441
442 (delete-file mescc)
443 (with-output-to-file mescc
444 (lambda _
445 (display (string-append
446 "\
447#! " gash "/bin/sh
448LANG=C
449LC_ALL=C
450export LANG LC_ALL
451
452MES_PREFIX=${MES_REWIRED_PREFIX-" out "/share/mes}
453MES=" bin "/mes
454export MES MES_PREFIX
455
456MES_ARENA=${MES_REWIRED_ARENA-10000000}
457MES_MAX_ARENA=${MES_REWIRED_ARENA-10000000}
458MES_STACK=${MES_REWIRED_STACK-1000000}
459export MES_ARENA MES_MAX_ARENA MES_STACK
460
461$MES -e '(mescc)' module/mescc.scm -- \"$@\"
462"))))
463 (chmod mescc #o555)
464
465 (with-directory-excursion module
466 (chmod "mes/base.mes" #o644)
467 (copy-file "mes/base.mes" "mes/base.mes.orig")
468 (let ((base.mes (open-file "mes/base.mes" "a")))
469 (display "
470;; A fixed map, from Mes 0.21, required to bootstrap Mes 0.21
471(define (map f h . t)
472 (if (or (null? h)
473 (and (pair? t) (null? (car t)))
474 (and (pair? t) (pair? (cdr t)) (null? (cadr t)))) '()
475 (if (null? t) (cons (f (car h)) (map f (cdr h)))
476 (if (null? (cdr t))
477 (cons (f (car h) (caar t)) (map f (cdr h) (cdar t)))
478 (if (null? (cddr t))
479 (cons (f (car h) (caar t) (caadr t)) (map f (cdr h) (cdar t) (cdadr t)))
c9c1cbf6 480 (error 'unsupported (cons* 'map-4: f h t))b )))))
da2ae09b
JN
481" base.mes)
482 (close base.mes))
483
484 (chmod "mes/guile.mes" #o644)
485 (copy-file "mes/guile.mes" "mes/guile.mes.orig")
486 (let ((guile.mes (open-file "mes/guile.mes" "a")))
487 (display "
488;; After booting guile.scm; use Mes 0.21; especially: MesCC 0.21
489(let* ((self (car (command-line)))
490 (prefix (dirname (dirname self))))
491 (set! %moduledir (string-append prefix \"/mes/module/\"))
492 (setenv \"%numbered_arch\" \"true\"))
493
494" guile.mes)
495 (close guile.mes)))
496 #t))))))
497
0b652851 498(define mes-boot
9a45a24f
LC
499 (package
500 (inherit mes)
501 (name "mes-boot")
c9c1cbf6 502 (version "0.21-33-g6d493b90d")
9a45a24f
LC
503 (source (origin
504 (method url-fetch)
c9c1cbf6 505 (uri (string-append "http://lilypond.org/janneke/mes/"
9a45a24f
LC
506 "mes-" version ".tar.gz"))
507 (sha256
508 (base32
c9c1cbf6 509 "0nr74zyam5n82svjwfbcz2mycj88vvsqab12x0mxv1lm6yqxqmmj"))))
9a45a24f
LC
510 (inputs '())
511 (propagated-inputs '())
512 (native-inputs
c9c1cbf6
JN
513 `(("nyacc-source" ,(origin (inherit (package-source nyacc))
514 (snippet #f)))
515 ("mes" ,%bootstrap-mes-rewired)
516 ("mescc-tools" ,%bootstrap-mescc-tools)
517 ,@(%boot-gash-inputs)))
9a45a24f
LC
518 (arguments
519 `(#:implicit-inputs? #f
c9c1cbf6 520 #:tests? #f
9a45a24f
LC
521 #:guile ,%bootstrap-guile
522 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
523 #:phases
524 (modify-phases %standard-phases
525 (add-after 'unpack 'unpack-seeds
526 (lambda _
c9c1cbf6 527 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
9a45a24f 528 (with-directory-excursion ".."
c9c1cbf6 529 (invoke "tar" "-xvf" nyacc-source)))))
9a45a24f
LC
530 (replace 'configure
531 (lambda* (#:key outputs #:allow-other-keys)
c9c1cbf6
JN
532 (let ((out (assoc-ref %outputs "out"))
533 (gash (assoc-ref %build-inputs "bash"))
534 (mes (assoc-ref %build-inputs "mes"))
535 (dir (with-directory-excursion ".." (getcwd))))
536 (setenv "AR" (string-append "gash " (getcwd) "/scripts/mesar"))
537 (setenv "BASH" (string-append gash "/bin/bash"))
538 (setenv "CC" (string-append mes "/bin/mescc"))
539 (setenv "GUILE_LOAD_PATH"
540 (string-append
541 mes "/share/mes/module"
542 ":" dir "/nyacc-0.99.0/module"
543 ":" (getenv "GUILE_LOAD_PATH")))
544 (invoke "gash" "configure.sh"
545 (string-append "--prefix=" out)
546 (string-append "--host=i686-linux-gnu")))))
9a45a24f
LC
547 (replace 'build
548 (lambda _
c9c1cbf6
JN
549 (invoke "sh" "bootstrap.sh")))
550 (delete 'check)
9a45a24f
LC
551 (replace 'install
552 (lambda _
c9c1cbf6
JN
553 (substitute* "install.sh" ; show some progress
554 ((" -xf") " -xvf")
555 (("^( *)((cp|mkdir|tar) [^']*[^\\])\n" all space cmd)
556 (string-append space "echo '" cmd "'\n"
557 space cmd "\n")))
558 (invoke "sh" "install.sh")
559 ;; Keep ASCII output, for friendlier comparison and bisection
560 (let* ((out (assoc-ref %outputs "out"))
561 (cache (string-append out "/lib/cache")))
562 (define (objects-in-dir dir)
563 (find-files dir
564 (lambda (name stat)
565 (and (equal? (dirname name) dir)
566 (or (string-suffix? ".o" name)
567 (string-suffix? ".s" name))))))
568 (for-each (lambda (x) (install-file x cache))
569 (append (objects-in-dir ".")
570 (objects-in-dir "mescc-lib"))))
571 #t)))))
9a45a24f 572 (native-search-paths
9a45a24f
LC
573 (list (search-path-specification
574 (variable "C_INCLUDE_PATH")
c9c1cbf6 575 (files '("include")))
9a45a24f
LC
576 (search-path-specification
577 (variable "LIBRARY_PATH")
c9c1cbf6
JN
578 (files '("lib")))
579 (search-path-specification
580 (variable "MES_PREFIX")
581 (separator #f)
582 (files '("")))))))
583
0b652851
JN
584
585(define tcc-boot0
586 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
587 ;; patches. In a very early and rough form they were presented to the
588 ;; TinyCC developers, who at the time showed no interest in supporting the
589 ;; bootstrappable effort; we will try again later. These patches have been
590 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
591 ;; mature, this package should use the 0.9.27 sources (or later).
5dedce04
JN
592 (package
593 (inherit tcc)
594 (name "tcc-boot0")
595 (version "0.9.26-1103-g6e62e0e")
596 (source (origin
597 (method url-fetch)
598 (uri (string-append
599 "http://lilypond.org/janneke/mes/20191117/"
600 "/tcc-" version ".tar.gz"))
601 (sha256
602 (base32
603 "1qbybw7mxbgkv3sazvz1v7c8byq998vk8f1h25ik8w3d2l63lxng"))))
604 (build-system gnu-build-system)
605 (supported-systems '("i686-linux" "x86_64-linux"))
606 (inputs '())
607 (propagated-inputs '())
608 (native-inputs
609 `(("mes" ,mes-boot)
610 ("nyacc-source" ,(origin (inherit (package-source nyacc))
611 (snippet #f)))
612 ("mescc-tools" ,%bootstrap-mescc-tools)
613 ,@(%boot-gash-inputs)))
614 (arguments
615 `(#:implicit-inputs? #f
616 #:guile ,%bootstrap-guile
617 #:validate-runpath? #f ; no dynamic executables
618 #:strip-binaries? #f ; no strip yet
619 #:phases
620 (modify-phases %standard-phases
621 (add-after 'unpack 'unpack-seeds
622 (lambda* (#:key outputs #:allow-other-keys)
623 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source")))
624 (with-directory-excursion ".."
625 (invoke "tar" "-xvf" nyacc-source)))))
626 (replace 'configure
627 (lambda* (#:key outputs #:allow-other-keys)
628 (let* ((out (assoc-ref %outputs "out"))
629 (dir (with-directory-excursion ".." (getcwd)))
630 (interpreter "/lib/mes-loader"))
631
632 (setenv "prefix" out)
633 (setenv "GUILE_LOAD_PATH"
634 (string-append dir "/nyacc-0.99.0/module"))
0b652851 635
5dedce04
JN
636 (substitute* "conftest.c"
637 (("volatile") ""))
638
639 (invoke "sh" "configure"
640 "--cc=mescc"
641 (string-append "--prefix=" out)
642 (string-append "--elfinterp=" interpreter)
643 "--crtprefix=."
644 "--tccdir=."))))
645 (replace 'build
646 (lambda _
647 (substitute* "bootstrap.sh" ; Show some progress
648 (("^( *)((cp|ls|mkdir|rm|[.]/tcc|[.]/[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
649 (string-append space "echo \"" cmd "\"\n"
650 space cmd "\n")))
651 (invoke "sh" "bootstrap.sh")))
652 (replace 'check
653 (lambda _
654 ;; fail fast tests
655 (system* "./tcc" "--help") ; --help exits 1
656 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
657 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
658 ;; TODO: add sensible check target (without depending on make)
659 ;; (invoke "sh" "check.sh")
660 #t))
661 (replace 'install
662 (lambda _
663 (substitute* "install.sh" ; Show some progress
664 (("^( *)((cp|ls|mkdir|rm|tar|./[$][{PROGRAM_PREFIX[}]tcc) [^\"]*[^\\])\n" all space cmd)
665 (string-append space "echo \"" cmd "\"\n"
666 space cmd "\n")))
0b652851 667
5dedce04
JN
668 (invoke "sh" "install.sh"))))))
669 (native-search-paths
670 (list (search-path-specification
671 (variable "C_INCLUDE_PATH")
672 (files '("include")))
673 (search-path-specification
674 (variable "LIBRARY_PATH")
675 (files '("lib")))))))
0b652851
JN
676
677(define tcc-boot
9a45a24f
LC
678 (package
679 (inherit tcc-boot0)
680 (name "tcc-boot")
681 (version "0.9.27")
682 (source (bootstrap-origin
683 (origin
0b652851 684 (inherit (package-source tcc))
9a45a24f
LC
685 (patches (search-patches "tcc-boot-0.9.27.patch")))))
686 (build-system gnu-build-system)
687 (inputs '())
688 (propagated-inputs '())
689 (native-inputs
690 `(("mes" ,mes-boot)
691 ("tcc" ,tcc-boot0)
0b652851 692
9a45a24f
LC
693 ("coreutils" , %bootstrap-coreutils&co)))
694 (arguments
695 `(#:implicit-inputs? #f
696 #:guile ,%bootstrap-guile
697
698 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
699 ;; with MesCC/M1/hex2-built binaries.
700 #:strip-binaries? #f
701
702 #:phases
703 (modify-phases %standard-phases
704 (replace 'configure
705 (lambda* (#:key outputs #:allow-other-keys)
706 (let* ((out (assoc-ref %outputs "out"))
707 (coreutils (assoc-ref %build-inputs "coreutils"))
708 (mes (assoc-ref %build-inputs "mes"))
709 (tcc (assoc-ref %build-inputs "tcc"))
710 (libc (assoc-ref %build-inputs "libc"))
711 (interpreter (if libc
712 ;; also for x86_64-linux, we are still on i686-linux
713 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
714 (string-append mes "/lib/mes-loader"))))
715 ;; unpack
716 (setenv "PATH" (string-append
717 coreutils "/bin"
718 ":" tcc "/bin"))
719 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
720 (invoke "sh" "configure"
721 (string-append "--cc=tcc")
722 (string-append "--cpu=i386")
723 (string-append "--prefix=" out)
724 (string-append "--elfinterp=" interpreter)
725 (string-append "--crtprefix=" tcc "/lib")
726 (string-append "--sysincludepaths=" tcc "/include")
727 (string-append "--libpaths=" tcc "/lib")))))
728 (replace 'build
729 (lambda* (#:key outputs #:allow-other-keys)
730 (let* ((out (assoc-ref %outputs "out"))
731 (mes (assoc-ref %build-inputs "mes"))
732 (tcc (assoc-ref %build-inputs "tcc"))
733 (libc (assoc-ref %build-inputs "libc"))
734 (interpreter (if libc
735 ;; also for x86_64-linux, we are still on i686-linux
736 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
737 (string-append mes "/lib/mes-loader"))))
738 (invoke "tcc"
739 "-vvv"
740 "-D" "BOOTSTRAP=1"
741 "-D" "ONE_SOURCE=1"
742 "-D" "TCC_TARGET_I386=1"
743 "-D" "CONFIG_TCC_STATIC=1"
744 "-D" "CONFIG_USE_LIBGCC=1"
745 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
746 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
747 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
748 "/lib:{B}/lib:.\"")
749 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
750 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
751 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
752 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
753 "-o" "tcc"
754 "tcc.c"))))
755 (replace 'check
756 (lambda _
757 ;; FIXME: add sensible check target (without depending on make)
758 ;; ./check.sh ?
759 (= 1 (status:exit-val (system* "./tcc" "--help")))))
760 (replace 'install
761 (lambda* (#:key outputs #:allow-other-keys)
762 (let ((out (assoc-ref %outputs "out"))
763 (tcc (assoc-ref %build-inputs "tcc")))
764 (mkdir-p (string-append out "/bin"))
765 (copy-file "tcc" (string-append out "/bin/tcc"))
766 (mkdir-p (string-append out "/lib/tcc"))
767 (copy-recursively (string-append tcc "/include")
768 (string-append out "/include"))
769 (copy-recursively (string-append tcc "/lib")
770 (string-append out "/lib"))
771 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
772 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
773 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
774 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
775 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
776 #t))))))))
0b652851
JN
777
778(define make-mesboot0
9a45a24f
LC
779 (package
780 (inherit gnu-make)
781 (name "make-mesboot0")
782 (version "3.80")
783 (source (origin
784 (method url-fetch)
785 (uri (string-append "mirror://gnu/make/make-"
786 version ".tar.gz"))
787 (sha256
788 (base32
789 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
790 (supported-systems '("i686-linux" "x86_64-linux"))
791 (inputs '())
792 (propagated-inputs '())
793 (native-inputs `(("tcc" ,tcc-boot)
0b652851 794
9a45a24f
LC
795 ("bash" ,%bootstrap-coreutils&co)
796 ("coreutils" ,%bootstrap-coreutils&co)))
797 (arguments
798 `(#:implicit-inputs? #f
799 #:tests? #f ; check depends on perl
800 #:guile ,%bootstrap-guile
801 #:configure-flags `("CC=tcc -DO_RDONLY=0"
802 "LD=tcc"
803 "--disable-nls")
804 #:phases
805 (modify-phases %standard-phases
806 (add-after 'configure 'configure-fixup
807 (lambda _
808 (substitute* "build.sh"
809 (("^REMOTE=.*") "REMOTE=stub\n")
810 (("^extras=.*") "extras=getloadavg.c\n"))
811 (substitute* "make.h"
812 (("^extern long int lseek.*" all) (string-append "// " all)))
813 #t))
814 (delete 'patch-generated-file-shebangs) ; no perl
815 (replace 'build
816 (lambda _
817 (invoke "sh" "./build.sh")))
818 (replace 'install
819 (lambda* (#:key outputs #:allow-other-keys)
820 (let* ((out (assoc-ref outputs "out"))
821 (bin (string-append out "/bin")))
822 (install-file "make" bin)
823 #t))))))))
0b652851
JN
824
825(define diffutils-mesboot
9a45a24f
LC
826 (package
827 (inherit diffutils)
828 (name "diffutils-mesboot")
829 (version "2.7")
830 (source (origin
831 (method url-fetch)
832 (uri (string-append "mirror://gnu/diffutils/diffutils-"
833 version ".tar.gz"))
834 (sha256
835 (base32
836 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
837 (supported-systems '("i686-linux" "x86_64-linux"))
838 (inputs '())
839 (propagated-inputs '())
840 (native-inputs `(("mes" ,mes-boot)
841 ("tcc" ,tcc-boot)
0b652851 842
9a45a24f
LC
843 ("bash" ,%bootstrap-coreutils&co)
844 ("coreutils" ,%bootstrap-coreutils&co)
845 ("make" ,make-mesboot0)))
846 (arguments
847 `(#:implicit-inputs? #f
848 #:guile ,%bootstrap-guile
849 #:parallel-build? #f
850 #:tests? #f ; check is naive, also checks non-built PROGRAMS
851 #:strip-binaries? #f ; no strip yet
852 #:phases
853 (modify-phases %standard-phases
854 ;; diffutils-2.7 needs more traditional configure
855 (replace 'configure
856 (lambda* (#:key outputs #:allow-other-keys)
857 (let ((out (assoc-ref outputs "out"))
858 (bash (assoc-ref %build-inputs "bash")))
859 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
860 (setenv "CC" "tcc")
861 (setenv "LD" "tcc")
862 (invoke "./configure" (string-append "--prefix=" out)))))
863 (add-before 'configure 'remove-diff3-sdiff
864 (lambda* (#:key outputs #:allow-other-keys)
865 (substitute* "Makefile.in"
866 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
867 #t)))))))
0b652851
JN
868
869(define binutils-mesboot0
9a45a24f
LC
870 (package
871 (inherit binutils)
872 (name "binutils-mesboot0")
873 (version "2.20.1a")
874 (source (bootstrap-origin
875 (origin
0b652851
JN
876 (method url-fetch)
877 (uri (string-append "mirror://gnu/binutils/binutils-"
878 version ".tar.bz2"))
879 (patches (search-patches "binutils-boot-2.20.1a.patch"))
880 (sha256
881 (base32
9a45a24f
LC
882 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
883 (inputs '())
884 (propagated-inputs '())
885 (native-inputs `(("tcc" ,tcc-boot)
0b652851 886
9a45a24f
LC
887 ("bash" ,%bootstrap-coreutils&co)
888 ("coreutils" ,%bootstrap-coreutils&co)
889 ("diffutils" ,diffutils-mesboot)
890 ("make" ,make-mesboot0)))
891 (supported-systems '("i686-linux" "x86_64-linux"))
892 (arguments
893 `(#:implicit-inputs? #f
894 #:guile ,%bootstrap-guile
895 #:tests? #f ; runtest: command not found
896 #:parallel-build? #f
897 #:strip-binaries? #f ; no strip yet
898 #:configure-flags
899 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
900 " -D MES_BOOTSTRAP=1"))
901 (bash (assoc-ref %build-inputs "bash")))
902 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
903 ,(string-append "CPPFLAGS=" cppflags)
904 "AR=tcc -ar"
905 "CXX=false"
906 "RANLIB=true"
907 ,(string-append "CC=tcc" cppflags)
908 "--disable-nls"
909 "--disable-shared"
910 "--disable-werror"
911 "--build=i686-unknown-linux-gnu"
912 "--host=i686-unknown-linux-gnu"
913 "--with-sysroot=/"))))))
0b652851
JN
914
915(define gcc-core-mesboot
916 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
917 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
918 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
919 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
920 ;; toolchain triplet "that works".
9a45a24f
LC
921 (package
922 (inherit gcc)
923 (name "gcc-core-mesboot")
924 (version "2.95.3")
925 (source (bootstrap-origin
926 (origin
0b652851
JN
927 (method url-fetch)
928 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
929 version
930 ".tar.gz"))
931 (patches (search-patches "gcc-boot-2.95.3.patch"))
932 (sha256
933 (base32
9a45a24f
LC
934 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
935 (supported-systems '("i686-linux" "x86_64-linux"))
936 (inputs '())
937 (propagated-inputs '())
938 (native-inputs `(("binutils" ,binutils-mesboot0)
939 ("tcc" ,tcc-boot)
0b652851 940
9a45a24f
LC
941 ("bash" ,%bootstrap-coreutils&co)
942 ("coreutils" ,%bootstrap-coreutils&co)
943 ("diffutils" ,diffutils-mesboot)
944 ("make" ,make-mesboot0)))
945 (outputs '("out"))
946 (arguments
947 `(#:implicit-inputs? #f
948 #:guile ,%bootstrap-guile
949 #:tests? #f
950 #:parallel-build? #f
951 #:strip-binaries? #f
952 #:configure-flags
953 (let ((out (assoc-ref %outputs "out")))
954 `("--enable-static"
955 "--disable-shared"
956 "--disable-werror"
957 "--build=i686-unknown-linux-gnu"
958 "--host=i686-unknown-linux-gnu"
959 ,(string-append "--prefix=" out)))
960 #:make-flags (list
961 "CC=tcc -static -D __GLIBC_MINOR__=6"
962 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
963 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
964 "AR=ar"
965 "RANLIB=ranlib"
966 (string-append "LIBGCC2_INCLUDES=-I "
967 (assoc-ref %build-inputs "tcc")
968 "/include")
969 "LANGUAGES=c"
970 (string-append "BOOT_LDFLAGS="
971 " -B" (assoc-ref %build-inputs "tcc")
972 "/lib/"))
973 #:modules ((guix build gnu-build-system)
974 (guix build utils)
975 (srfi srfi-1))
976 #:phases
977 (modify-phases %standard-phases
978 ;; gcc-2.95.3 needs more traditional configure
979 (add-before 'configure 'setenv
980 (lambda* (#:key outputs #:allow-other-keys)
981 (let ((out (assoc-ref outputs "out"))
982 (bash (assoc-ref %build-inputs "bash"))
983 (tcc (assoc-ref %build-inputs "tcc"))
984 (cppflags " -D __GLIBC_MINOR__=6"))
985 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
986 (setenv "CPPFLAGS" cppflags)
987 (setenv "CC" (string-append "tcc" cppflags))
988 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
989 (setenv "CPP" (string-append "tcc -E" cppflags))
990 (with-output-to-file "config.cache"
991 (lambda _
992 (display "
0b652851 993ac_cv_c_float_format='IEEE (little-endian)'
2b5e412b 994")))
9a45a24f
LC
995 #t)))
996 (replace 'configure
997 (lambda* (#:key configure-flags #:allow-other-keys)
998 (format (current-error-port)
999 "running ./configure ~a\n" (string-join configure-flags))
1000 (apply invoke "./configure" configure-flags)))
1001 (add-after 'configure 'remove-info
1002 (lambda _
1003 ;; no info at this stage
1004 (delete-file-recursively "texinfo")
1005 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
1006 (add-after 'install 'install2
1007 (lambda* (#:key outputs #:allow-other-keys)
1008 (let* ((tcc (assoc-ref %build-inputs "tcc"))
1009 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
1010 (out (assoc-ref outputs "out"))
1011 (gcc-dir (string-append
1012 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1013 (mkdir-p "tmp")
1014 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1015 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1016 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1017 (copy-file (string-append tcc "/lib/libtcc1.a")
1018 (string-append out "/lib/libtcc1.a"))
1019 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
1020 (string-append tcc-lib "/libc+gnu.o")
1021 (string-append tcc-lib "/libtcc1.o"))
1022 (invoke "ar" "r" (string-append out "/lib/libc.a")
1023 (string-append tcc-lib "/libc+gnu.o")
1024 (string-append tcc-lib "/libtcc1.o"))
1025 (invoke "ls" "-ltrF" gcc-dir)
9a45a24f
LC
1026 #t))))))
1027 (native-search-paths
9a45a24f
LC
1028 (list (search-path-specification
1029 (variable "C_INCLUDE_PATH")
558b0bbe
LC
1030 (files '("include"
1031
1032 ;; Needed to get things like GCC's <stddef.h>.
1033 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
9a45a24f
LC
1034 (search-path-specification
1035 (variable "LIBRARY_PATH")
1036 (files '("lib")))))))
0b652851
JN
1037
1038(define mesboot-headers
9a45a24f
LC
1039 (package
1040 (inherit mes-boot)
1041 (name "mesboot-headers")
1042 (supported-systems '("i686-linux" "x86_64-linux"))
1043 (inputs '())
1044 (propagated-inputs '())
1045 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
1046 ("headers" ,%bootstrap-linux-libre-headers)))
1047 (arguments
1048 `(#:implicit-inputs? #f
1049 #:guile ,%bootstrap-guile
1050 #:tests? #f
1051 #:strip-binaries? #f
1052 #:phases
1053 (modify-phases %standard-phases
1054 (delete 'configure)
1055 (delete 'build)
1056 (replace 'install
1057 (lambda* (#:key outputs #:allow-other-keys)
1058 (let* ((out (assoc-ref outputs "out"))
1059 (include (string-append out "/include"))
1060 (headers (assoc-ref %build-inputs "headers" )))
1061 (mkdir-p include)
1062 (copy-recursively "include" out)
1063 (copy-recursively headers out)
558b0bbe 1064 #t))))))))
0b652851
JN
1065
1066(define glibc-mesboot0
1067 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
1068 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
1069 ;; gcc.
9a45a24f
LC
1070 (package
1071 (inherit glibc)
1072 (name "glibc-mesboot0")
1073 (version "2.2.5")
1074 (source (bootstrap-origin
1075 (origin
0b652851
JN
1076 (method url-fetch)
1077 (uri (string-append "mirror://gnu/glibc/glibc-"
1078 version
1079 ".tar.gz"))
1080 (patches (search-patches "glibc-boot-2.2.5.patch"))
1081 (sha256
1082 (base32
9a45a24f
LC
1083 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
1084 (supported-systems '("i686-linux" "x86_64-linux"))
1085 (inputs '())
1086 (propagated-inputs '())
1087 (native-inputs `(("binutils" ,binutils-mesboot0)
1088 ("gcc" ,gcc-core-mesboot)
0b652851 1089
9a45a24f
LC
1090 ("bash" ,%bootstrap-coreutils&co)
1091 ("coreutils" ,%bootstrap-coreutils&co)
1092 ("diffutils" ,diffutils-mesboot)
1093 ("headers" ,mesboot-headers)
1094 ("make" ,make-mesboot0)))
1095 (outputs '("out"))
1096 (arguments
1097 `(#:implicit-inputs? #f
1098 #:guile ,%bootstrap-guile
1099 #:tests? #f
1100 #:strip-binaries? #f
1101 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1102 #:make-flags (list (string-append
1103 "SHELL="
1104 (assoc-ref %build-inputs "bash")
1105 "/bin/sh"))
1106 #:configure-flags
1107 (let ((out (assoc-ref %outputs "out"))
1108 (headers (assoc-ref %build-inputs "headers")))
1109 (list
1110 "--disable-shared"
1111 "--enable-static"
1112 "--disable-sanity-checks"
1113 "--build=i686-unknown-linux-gnu"
1114 "--host=i686-unknown-linux-gnu"
1115 (string-append "--with-headers=" headers "/include")
1116 "--enable-static-nss"
1117 "--without-__thread"
1118 "--without-cvs"
1119 "--without-gd"
1120 "--without-tls"
1121 (string-append "--prefix=" out)))
1122 #:phases
1123 (modify-phases %standard-phases
1124 (add-before 'configure 'setenv
1125 (lambda* (#:key outputs #:allow-other-keys)
1126 (let* ((out (assoc-ref outputs "out"))
1127 (bash (assoc-ref %build-inputs "bash"))
1128 (gcc (assoc-ref %build-inputs "gcc"))
1129 (headers (assoc-ref %build-inputs "headers"))
1130 (cppflags (string-append
1131 ;;" -D __STDC__=1"
1132 " -D MES_BOOTSTRAP=1"
1133 " -D BOOTSTRAP_GLIBC=1"))
1134 (cflags (string-append " -L " (getcwd))))
1135 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1136 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1137 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1138 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1139 #t)))
1140 ;; glibc-2.2.5 needs a more classic invocation of configure
1141 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
1142 (replace 'configure
1143 (lambda* (#:key configure-flags #:allow-other-keys)
1144 (format (current-error-port)
1145 "running ./configure ~a\n" (string-join configure-flags))
558b0bbe 1146 (apply invoke "./configure" configure-flags))))))))
0b652851
JN
1147
1148(define gcc-mesboot0
9a45a24f
LC
1149 (package
1150 (inherit gcc-core-mesboot)
1151 (name "gcc-mesboot0")
1152 (native-inputs `(("binutils" ,binutils-mesboot0)
558b0bbe
LC
1153
1154 ;; Packages are given in an order that's relevant for
1155 ;; #include_next purposes.
9a45a24f 1156 ("libc" ,glibc-mesboot0)
558b0bbe
LC
1157 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1158 ("gcc" ,gcc-core-mesboot)
0b652851 1159
9a45a24f
LC
1160 ("bash" ,%bootstrap-coreutils&co)
1161 ("coreutils" ,%bootstrap-coreutils&co)
1162 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1163 ("make" ,make-mesboot0)))
1164 (arguments
1165 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1166 ((#:phases phases)
1167 `(modify-phases ,phases
1168 (replace 'setenv
558b0bbe
LC
1169 (lambda _
1170 (setenv "CONFIG_SHELL" (which "sh"))
1171 (with-output-to-file "config.cache"
1172 (lambda _
1173 (display "
0b652851
JN
1174ac_cv_c_float_format='IEEE (little-endian)'
1175")))
558b0bbe 1176 #t))
9a45a24f
LC
1177 (replace 'install2
1178 (lambda* (#:key outputs #:allow-other-keys)
1179 (let* ((out (assoc-ref outputs "out"))
1180 (gcc-dir (string-append
1181 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1182 (mkdir-p "tmp")
1183 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1184 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1185 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1186 #t)))))
1187 ((#:configure-flags configure-flags)
1188 `(let ((out (assoc-ref %outputs "out")))
1189 `("--disable-shared"
1190 "--disable-werror"
1191 "--build=i686-unknown-linux-gnu"
1192 "--host=i686-unknown-linux-gnu"
1193 ,(string-append "--prefix=" out))))
1194 ((#:make-flags make-flags)
1195 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1196 `("RANLIB=true"
1197 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1198 "LANGUAGES=c")))))))
0b652851
JN
1199
1200(define binutils-mesboot
9a45a24f
LC
1201 (package
1202 (inherit binutils-mesboot0)
1203 (name "binutils-mesboot")
1204 (native-inputs `(("binutils" ,binutils-mesboot0)
1205 ("libc" ,glibc-mesboot0)
1206 ("gcc" ,gcc-mesboot0)
0b652851 1207
9a45a24f
LC
1208 ("bash" ,%bootstrap-coreutils&co)
1209 ("coreutils" ,%bootstrap-coreutils&co)
1210 ("diffutils" ,diffutils-mesboot)
1211 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1212 ("make" ,make-mesboot0)))
1213 (arguments
1214 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1215 ((#:configure-flags configure-flags)
1216 '(list "--disable-nls"
1217 "--disable-shared"
1218 "--disable-werror"
1219 "--build=i686-unknown-linux-gnu"
1220 "--host=i686-unknown-linux-gnu"
1221 "--with-sysroot=/"))))))
0b652851
JN
1222
1223(define make-mesboot
9a45a24f
LC
1224 (package
1225 (inherit make-mesboot0)
1226 (name "make-mesboot")
1227 (version "3.82")
1228 (source (origin
1229 (method url-fetch)
1230 (uri (string-append "mirror://gnu/make/make-"
1231 version ".tar.gz"))
1232 (sha256
1233 (base32
1234 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1235 (native-inputs `(("binutils" ,binutils-mesboot0)
1236 ("libc" ,glibc-mesboot0)
1237 ("gcc" ,gcc-mesboot0)
1238 ("make" ,make-mesboot0)
0b652851 1239
9a45a24f
LC
1240 ("bash" ,%bootstrap-coreutils&co)
1241 ("coreutils" ,%bootstrap-coreutils&co)
1242 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
1243 (arguments
1244 (substitute-keyword-arguments (package-arguments make-mesboot0)
1245 ((#:configure-flags configure-flags)
1246 `(let ((out (assoc-ref %outputs "out")))
1247 `(,(string-append "--prefix=" out))))
1248 ((#:phases phases)
1249 `(modify-phases ,phases
1250 (delete 'configure-fixup)
1251 (add-before 'configure 'setenv
1252 (lambda _
1253 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1254 #t))))))))
0b652851
JN
1255
1256(define gmp-boot
1257 (package
1258 (inherit gmp)
1259 (version "4.3.2")
1260 (source (origin
1261 (method url-fetch)
1262 (uri (string-append "mirror://gnu/gmp/gmp-" version
1263 ".tar.gz"))
1264 (sha256 (base32
1265 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1266
1267(define mpfr-boot
1268 (package
1269 (inherit mpfr)
1270 (version "2.4.2")
1271 (source (origin
1272 (method url-fetch)
1273 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1274 ".tar.gz"))
1275 (sha256 (base32
1276 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1277
1278(define mpc-boot
1279 (package
1280 (inherit mpc)
1281 (version "1.0.3")
1282 (source (origin
1283 (method url-fetch)
1284 (uri (string-append
1285 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1286 (sha256
1287 (base32
1288 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1289
1290(define gcc-mesboot1
9a45a24f
LC
1291 (package
1292 (inherit gcc-mesboot0)
1293 (name "gcc-mesboot1")
a1caea07 1294 (version (package-version gcc-4.7))
9a45a24f
LC
1295 (source (bootstrap-origin
1296 (origin (inherit (package-source gcc-4.7))
1297 (patches (search-patches "gcc-boot-4.7.4.patch")))))
1298 (inputs `(("gmp-source" ,(package-source gmp-boot))
1299 ("mpfr-source" ,(package-source mpfr-boot))
1300 ("mpc-source" ,(package-source mpc-boot))))
1301 (native-inputs `(("binutils" ,binutils-mesboot)
558b0bbe 1302
9a45a24f 1303 ("libc" ,glibc-mesboot0)
558b0bbe
LC
1304 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1305 ("gcc" ,gcc-mesboot0)
0b652851 1306
9a45a24f
LC
1307 ("bash" ,%bootstrap-coreutils&co)
1308 ("coreutils" ,%bootstrap-coreutils&co)
1309 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1310 ("make" ,make-mesboot)))
1311 (arguments
1312 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1313 ((#:make-flags make-flags)
1314 `(let* ((libc (assoc-ref %build-inputs "libc"))
1315 (ldflags (string-append
1316 "-B" libc "/lib "
1317 "-Wl,-dynamic-linker "
1318 "-Wl," libc
1319 ,(glibc-dynamic-linker "i686-linux"))))
1320 (list (string-append "LDFLAGS=" ldflags)
1321 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
1322 ((#:phases phases)
1323 `(modify-phases ,phases
1324 ;; c&p from commencement.scm:gcc-boot0
1325 (add-after 'unpack 'unpack-gmp&co
1326 (lambda* (#:key inputs #:allow-other-keys)
1327 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1328 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1329 (mpc (assoc-ref %build-inputs "mpc-source")))
0b652851 1330
9a45a24f
LC
1331 ;; To reduce the set of pre-built bootstrap inputs, build
1332 ;; GMP & co. from GCC.
1333 (for-each (lambda (source)
1334 (or (invoke "tar" "xvf" source)
1335 (error "failed to unpack tarball"
1336 source)))
1337 (list gmp mpfr mpc))
0b652851 1338
9a45a24f
LC
1339 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1340 ,@(map (lambda (lib)
1341 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1342 ;; into gmp-6.0.0.
1343 `(symlink ,(string-trim-right
1344 (package-full-name lib "-")
1345 char-set:letter)
1346 ,(package-name lib)))
1347 (list gmp-boot mpfr-boot mpc-boot))
1348 #t)))
1349 (delete 'remove-info)
1350 (replace 'setenv
558b0bbe
LC
1351 (lambda _
1352 (setenv "CONFIG_SHELL" (which "sh"))
1353
1354 ;; Allow MPFR headers to be found.
1355 (setenv "C_INCLUDE_PATH"
1356 (string-append (getcwd) "/mpfr/src:"
1357 (getenv "C_INCLUDE_PATH")))
1358
1359 ;; Set the C++ search path so that C headers can be found as
1360 ;; libstdc++ is being compiled.
1361 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
1362 #t))
9a45a24f
LC
1363 (delete 'install2)))
1364 ((#:configure-flags configure-flags)
1365 `(let ((out (assoc-ref %outputs "out"))
1366 (glibc (assoc-ref %build-inputs "libc")))
1367 (list (string-append "--prefix=" out)
1368 "--build=i686-unknown-linux-gnu"
1369 "--host=i686-unknown-linux-gnu"
0b652851 1370
9a45a24f
LC
1371 (string-append "--with-native-system-header-dir=" glibc "/include")
1372 (string-append "--with-build-sysroot=" glibc "/include")
0b652851 1373
9a45a24f
LC
1374 "--disable-bootstrap"
1375 "--disable-decimal-float"
1376 "--disable-libatomic"
1377 "--disable-libcilkrts"
1378 "--disable-libgomp"
1379 "--disable-libitm"
1380 "--disable-libmudflap"
1381 "--disable-libquadmath"
1382 "--disable-libsanitizer"
1383 "--disable-libssp"
1384 "--disable-libvtv"
1385 "--disable-lto"
1386 "--disable-lto-plugin"
1387 "--disable-multilib"
1388 "--disable-plugin"
1389 "--disable-threads"
1390 "--enable-languages=c,c++"
0b652851 1391
9a45a24f
LC
1392 "--enable-static"
1393 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1394 "--disable-shared"
1395 "--enable-threads=single"
0b652851 1396
9a45a24f
LC
1397 ;; No pre-compiled libstdc++ headers, to save space.
1398 "--disable-libstdcxx-pch"
0b652851 1399
9a45a24f
LC
1400 ;; for libcpp ...
1401 "--disable-build-with-cxx")))))))
0b652851
JN
1402
1403(define gcc-mesboot1-wrapper
1404 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1405 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1406 ;; --enable-shared will fail.
9a45a24f
LC
1407 (package
1408 (inherit gcc-mesboot1)
1409 (name "gcc-mesboot1-wrapper")
1410 (source #f)
1411 (inputs '())
1412 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1413 ("libc" ,glibc-mesboot)
1414 ("gcc" ,gcc-mesboot1)))
1415 (arguments
1416 `(#:implicit-inputs? #f
1417 #:guile ,%bootstrap-guile
1418 #:phases
1419 (modify-phases %standard-phases
1420 (delete 'unpack)
1421 (delete 'configure)
1422 (delete 'install)
1423 (replace 'build
1424 (lambda* (#:key outputs #:allow-other-keys)
1425 (let* ((out (assoc-ref outputs "out"))
1426 (bash (assoc-ref %build-inputs "bash"))
1427 (libc (assoc-ref %build-inputs "libc"))
1428 (gcc (assoc-ref %build-inputs "gcc"))
1429 (bin (string-append out "/bin")))
1430 (mkdir-p bin)
1431 (for-each
1432 (lambda (program)
1433 (let ((wrapper (string-append bin "/" program)))
1434 (with-output-to-file wrapper
1435 (lambda _
1436 (display (string-append "#! " bash "/bin/bash
0b652851
JN
1437exec " gcc "/bin/" program
1438" -Wl,--dynamic-linker"
eb443459
JN
1439;; also for x86_64-linux, we are still on i686-linux
1440" -Wl," libc ,(glibc-dynamic-linker "i686-linux")
0b652851
JN
1441" -Wl,--rpath"
1442" -Wl," libc "/lib"
1443" \"$@\"
1444"))
9a45a24f
LC
1445 (chmod wrapper #o555)))))
1446 '(
1447 "gcc"
1448 "g++"
1449 "i686-unknown-linux-gnu-gcc"
1450 "i686-unknown-linux-gnu-g++"
1451 ))
1452 #t)))
1453 (replace 'check
1454 (lambda* (#:key outputs #:allow-other-keys)
1455 (let* ((out (assoc-ref outputs "out"))
1456 (bin (string-append out "/bin"))
1457 (program (string-append bin "/gcc")))
1458 (invoke program "--help")))))))))
0b652851
JN
1459
1460(define glibc-headers-mesboot
9a45a24f
LC
1461 (package
1462 (inherit glibc-mesboot0)
1463 (name "glibc-headers-mesboot")
1464 (version "2.16.0")
1465 (source (bootstrap-origin
1466 (origin
0b652851
JN
1467 (method url-fetch)
1468 (uri (string-append "mirror://gnu/glibc/glibc-"
1469 version
1470 ".tar.gz"))
1471 (patches (search-patches "glibc-boot-2.16.0.patch"
1472 "glibc-bootstrap-system-2.16.0.patch"))
1473 (sha256
1474 (base32
9a45a24f
LC
1475 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1476 (native-inputs `(("binutils" ,binutils-mesboot)
1477 ("libc" ,glibc-mesboot0)
1478 ("gcc" ,gcc-mesboot1)
1479 ("headers" ,mesboot-headers)
0b652851 1480
9a45a24f
LC
1481 ("bash" ,%bootstrap-coreutils&co)
1482 ("coreutils" ,%bootstrap-coreutils&co)
1483 ("diffutils" ,diffutils-mesboot)
1484 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1485 ("make" ,make-mesboot)))
0b652851 1486
9a45a24f
LC
1487 (arguments
1488 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1489 ((#:configure-flags configure-flags)
1490 `(let ((out (assoc-ref %outputs "out"))
1491 (headers (assoc-ref %build-inputs "headers")))
1492 (list
1493 (string-append "--prefix=" out)
1494 "--disable-obsolete-rpc"
1495 "--host=i686-unknown-linux-gnu"
1496 (string-append "--with-headers=" headers "/include")
1497 "--enable-static-nss"
1498 "--with-pthread"
1499 "--without-cvs"
1500 "--without-gd"
1501 "--enable-add-ons=nptl")))
1502 ((#:make-flags make-flags)
1503 `(let ((bash (assoc-ref %build-inputs "bash")))
1504 (list (string-append "SHELL=" bash "/bin/sh")
1505 "install-bootstrap-headers=yes" "install-headers")))
1506 ((#:phases phases)
1507 `(modify-phases ,phases
1508 (replace 'setenv
558b0bbe
LC
1509 (lambda* (#:key inputs #:allow-other-keys)
1510 (let* ((headers (assoc-ref inputs "headers"))
1511 (libc (assoc-ref inputs "libc"))
1512 (gcc (assoc-ref inputs "gcc"))
9a45a24f
LC
1513 (cppflags (string-append
1514 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1515 " -D BOOTSTRAP_GLIBC=1"))
1516 (cflags (string-append " -L " (getcwd)
1517 " -L " libc "/lib")))
1518 (setenv "libc_cv_friendly_stddef" "yes")
558b0bbe
LC
1519 (setenv "CONFIG_SHELL" (which "sh"))
1520 (setenv "SHELL" (which "sh"))
0b652851 1521
9a45a24f
LC
1522 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1523 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
0b652851 1524
9a45a24f
LC
1525 ;; avoid -fstack-protector
1526 (setenv "libc_cv_ssp" "false")
1527 (substitute* "configure"
558b0bbe 1528 (("/bin/pwd") "pwd"))
9a45a24f
LC
1529 #t)))
1530 (replace 'install
1531 (lambda* (#:key outputs make-flags #:allow-other-keys)
1532 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1533 (out (assoc-ref outputs "out")))
1534 (apply invoke "make" make-flags)
1535 (copy-recursively kernel-headers out)
1536 #t)))
1537 (replace 'configure
1538 (lambda* (#:key configure-flags #:allow-other-keys)
1539 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1540 (mkdir-p "build")
1541 (chdir "build")
1542 (apply invoke "../configure" configure-flags)))
1543 (add-after 'configure 'remove-sunrpc
1544 (lambda _
1545 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1546 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1547 (substitute* "sysd-sorted"
1548 ((" sunrpc") " ")
1549 ((" nis") " "))
1550 ;; 'rpcgen' needs native libc headers to be built.
1551 (substitute* "../Makefile"
1552 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1553 (substitute* "../Makeconfig"
1554 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1555 (substitute* "../elf/Makefile"
1556 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
0b652851
JN
1557
1558(define glibc-mesboot
9a45a24f
LC
1559 (package
1560 (inherit glibc-headers-mesboot)
1561 (name "glibc-mesboot")
1562 (native-inputs `(("binutils" ,binutils-mesboot)
1563 ("libc" ,glibc-mesboot0)
1564 ("headers" ,glibc-headers-mesboot)
1565 ("gcc" ,gcc-mesboot1)
0b652851 1566
9a45a24f
LC
1567 ("bash" ,%bootstrap-coreutils&co)
1568 ("coreutils" ,%bootstrap-coreutils&co)
1569 ("diffutils" ,diffutils-mesboot)
1570 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1571 ("make" ,make-mesboot)))
0b652851 1572
9a45a24f
LC
1573 (arguments
1574 `(#:validate-runpath? #f ; fails when using --enable-shared
1575 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1576 ((#:make-flags make-flags)
1577 `(let ((bash (assoc-ref %build-inputs "bash")))
1578 (list (string-append "SHELL=" bash "/bin/sh"))))
1579 ((#:phases phases)
1580 `(modify-phases ,phases
1581 (replace 'install
1582 (lambda* (#:key outputs make-flags #:allow-other-keys)
1583 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1584 (out (assoc-ref outputs "out"))
1585 (install-flags (cons "install" make-flags)))
1586 (apply invoke "make" install-flags)
1587 (copy-recursively kernel-headers out)
558b0bbe 1588 #t))))))))))
0b652851
JN
1589
1590(define gcc-mesboot
9a45a24f
LC
1591 (package
1592 (inherit gcc-mesboot1)
1593 (name "gcc-mesboot")
a1caea07 1594 (version (package-version gcc-4.9))
9a45a24f
LC
1595 (source (bootstrap-origin (package-source gcc-4.9)))
1596 (native-inputs `(("binutils" ,binutils-mesboot)
558b0bbe
LC
1597
1598 ("libc" ,glibc-mesboot)
1599 ("kernel-headers" ,%bootstrap-linux-libre-headers)
9a45a24f
LC
1600 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1601 ("gcc" ,gcc-mesboot1)
0b652851 1602
9a45a24f
LC
1603 ("bash" ,%bootstrap-coreutils&co)
1604 ("coreutils" ,%bootstrap-coreutils&co)
1605 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1606 ("make" ,make-mesboot)))
1607 (arguments
1608 `(#:validate-runpath? #f
1609 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1610 ((#:configure-flags configure-flags)
1611 `(let ((out (assoc-ref %outputs "out"))
1612 (glibc (assoc-ref %build-inputs "libc")))
1613 (list (string-append "--prefix=" out)
1614 "--build=i686-unknown-linux-gnu"
1615 "--host=i686-unknown-linux-gnu"
0b652851 1616
9a45a24f 1617 "--with-host-libstdcxx=-lsupc++"
0b652851 1618
9a45a24f
LC
1619 (string-append "--with-native-system-header-dir=" glibc "/include")
1620 (string-append "--with-build-sysroot=" glibc "/include")
0b652851 1621
9a45a24f
LC
1622 "--disable-bootstrap"
1623 "--disable-decimal-float"
1624 "--disable-libatomic"
1625 "--disable-libcilkrts"
1626 "--disable-libgomp"
1627 "--disable-libitm"
1628 "--disable-libmudflap"
1629 "--disable-libquadmath"
1630 "--disable-libsanitizer"
1631 "--disable-libssp"
1632 "--disable-libvtv"
1633 "--disable-lto"
1634 "--disable-lto-plugin"
1635 "--disable-multilib"
1636 "--disable-plugin"
1637 "--disable-threads"
1638 "--enable-languages=c,c++"
0b652851 1639
9a45a24f
LC
1640 "--enable-static"
1641 "--enable-shared"
1642 "--enable-threads=single"
0b652851 1643
9a45a24f
LC
1644 ;; No pre-compiled libstdc++ headers, to save space.
1645 "--disable-libstdcxx-pch"
0b652851 1646
9a45a24f 1647 ;; for libcpp ...
558b0bbe 1648 "--disable-build-with-cxx"))))))))
0b652851
JN
1649
1650(define gcc-mesboot-wrapper
1651 ;; We need this so gcc-mesboot can be used to create shared binaries that
1652 ;; have the correct interpreter and runpath to libc.
9a45a24f
LC
1653 (package
1654 (inherit gcc-mesboot1-wrapper)
1655 (name "gcc-mesboot-wrapper")
1656 (version (package-version gcc-mesboot))
1657 (source #f)
1658 (inputs '())
1659 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1660 ("libc" ,glibc-mesboot)
1661 ("gcc" ,gcc-mesboot)))))
0b652851
JN
1662
1663(define m4-mesboot
9a45a24f
LC
1664 (package
1665 (inherit m4)
1666 (name "m4-mesboot")
1667 (version "1.4")
1668 (source (origin
1669 (method url-fetch)
1670 (uri (string-append "mirror://gnu/m4/m4-"
1671 version ".tar.gz"))
1672 (sha256
1673 (base32
1674 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1675 (supported-systems '("i686-linux" "x86_64-linux"))
1676 (native-inputs `(("mes" ,mes-boot)
1677 ("tcc" ,tcc-boot)))
1678 (arguments
1679 `(#:phases
1680 (modify-phases %standard-phases
1681 (replace 'configure
1682 (lambda* (#:key outputs #:allow-other-keys)
1683 (let ((out (assoc-ref outputs "out")))
1684 (setenv "CONFIG_SHELL" (string-append
1685 (assoc-ref %build-inputs "bash")
1686 "/bin/sh"))
1687 (setenv "CC" "tcc -static")
1688 (setenv "CPP" "tcc -E")
1689 (invoke "./configure" (string-append "--prefix=" out))))))))))
0b652851 1690
c3629044 1691(define (%bootstrap-inputs+toolchain)
0b652851
JN
1692 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1693 ;; the actual reduced set with bootstrapped toolchain.
1380be3c
LC
1694 (match (%current-system)
1695 ((or "i686-linux" "x86_64-linux")
1696 `(("libc" ,glibc-mesboot)
1697 ("binutils" ,binutils-mesboot)
1698 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1699 ("gcc" ,gcc-mesboot)
1700 ,@(fold alist-delete (%bootstrap-inputs)
1701 '("bootstrap-mescc-tools" "mes"))))
1702 (_
1703 (%bootstrap-inputs))))
c3629044 1704
bdb36958 1705(define gnu-make-boot0
9a45a24f
LC
1706 (package
1707 (inherit gnu-make)
1708 (source (bootstrap-origin (package-source gnu-make)))
1709 (name "make-boot0")
1710 (arguments
1711 `(#:guile ,%bootstrap-guile
1712 #:implicit-inputs? #f
1713 #:tests? #f ; cannot run "make check"
1714 ,@(substitute-keyword-arguments (package-arguments gnu-make)
cdba9148
MB
1715 ((#:configure-flags flags ''())
1716 ;; The generated config.status has some problems due to the
1717 ;; bootstrap environment. Disable dependency tracking to work
1718 ;; around it.
1719 `(cons "--disable-dependency-tracking" ,flags))
9a45a24f
LC
1720 ((#:phases phases)
1721 `(modify-phases ,phases
1722 (replace 'build
1723 (lambda _
1724 (invoke "./build.sh")))
1725 (replace 'install
1726 (lambda* (#:key outputs #:allow-other-keys)
1727 (let* ((out (assoc-ref outputs "out"))
1728 (bin (string-append out "/bin")))
1729 (install-file "make" bin)
1730 #t))))))))
1731 (native-inputs '()) ; no need for 'pkg-config'
1732 (inputs (%bootstrap-inputs+toolchain))))
bdb36958
LC
1733
1734(define diffutils-boot0
99b73d0f
LC
1735 (package
1736 (inherit diffutils)
1737 (name "diffutils-boot0")
1738 (native-inputs `())
1739 (inputs
1740 `(("make" ,gnu-make-boot0)
1741 ,@(%bootstrap-inputs+toolchain)))
1742 (arguments
1743 `(#:tests? #f ; the test suite needs diffutils
1744 #:guile ,%bootstrap-guile
1745 #:implicit-inputs? #f
1746 ,@(package-arguments diffutils)))))
bdb36958
LC
1747
1748(define findutils-boot0
99b73d0f
LC
1749 (package
1750 (inherit findutils)
1751 (name "findutils-boot0")
1752 (source (bootstrap-origin (package-source findutils)))
1753 (inputs
1754 `(("make" ,gnu-make-boot0)
1755 ("diffutils" ,diffutils-boot0) ; for tests
1756 ,@(%bootstrap-inputs+toolchain)))
1757 (arguments
1758 `(#:implicit-inputs? #f
1759 #:guile ,%bootstrap-guile
717867a6
MB
1760
1761 ;; The build system assumes we have done a mistake when time_t is 32-bit
1762 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1763 ,@(if (target-64bit?)
1764 (substitute-keyword-arguments (package-arguments findutils)
1765 ((#:configure-flags flags ''())
1766 `(cons "TIME_T_32_BIT_OK=yes"
1767 ,flags)))
1768 (package-arguments findutils))))))
bdb36958 1769
c00a9fbf 1770(define file-boot0
99b73d0f
LC
1771 (package
1772 (inherit file)
1773 (source (bootstrap-origin (package-source file)))
1774 (name "file-boot0")
1775 (inputs
1776 `(("make" ,gnu-make-boot0)
1777 ,@(%bootstrap-inputs+toolchain)))
1778 (arguments
1779 `(#:implicit-inputs? #f
1780 #:guile ,%bootstrap-guile
1781 #:strip-binaries? #f
1782 #:validate-runpath? #f))))
c00a9fbf 1783
a2b2070b 1784(define (%boot0-inputs)
bdb36958
LC
1785 `(("make" ,gnu-make-boot0)
1786 ("diffutils" ,diffutils-boot0)
1787 ("findutils" ,findutils-boot0)
c00a9fbf 1788 ("file" ,file-boot0)
c3629044 1789 ,@(%bootstrap-inputs+toolchain)))
bdb36958 1790
bdb36958
LC
1791(define* (boot-triplet #:optional (system (%current-system)))
1792 ;; Return the triplet used to create the cross toolchain needed in the
1793 ;; first bootstrapping stage.
1794 (nix-system->gnu-triplet system "guix"))
1795
1796;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1797;; toolchain actually targets the same OS and arch, but it has the advantage
c3629044
JN
1798;; of being independent of the libc and tools in
1799;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1800;; reference to the target libc.
bdb36958
LC
1801
1802(define binutils-boot0
99b73d0f
LC
1803 (package
1804 (inherit binutils)
1805 (source (bootstrap-origin (package-source binutils)))
1806 (name "binutils-cross-boot0")
1807 (arguments
1808 `(#:guile ,%bootstrap-guile
1809 #:implicit-inputs? #f
1810
1811 #:modules ((guix build gnu-build-system)
1812 (guix build utils)
1813 (ice-9 ftw)) ; for 'scandir'
1814 #:phases (modify-phases %standard-phases
1815 (add-after 'install 'add-symlinks
1816 (lambda* (#:key outputs #:allow-other-keys)
1817 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1818 ;; triplet prefix, so add symlinks.
1819 (let ((out (assoc-ref outputs "out"))
1820 (triplet-prefix (string-append ,(boot-triplet) "-")))
1821 (define (has-triplet-prefix? name)
1822 (string-prefix? triplet-prefix name))
1823 (define (remove-triplet-prefix name)
1824 (substring name (string-length triplet-prefix)))
1825 (with-directory-excursion (string-append out "/bin")
1826 (for-each (lambda (name)
1827 (symlink name (remove-triplet-prefix name)))
1828 (scandir "." has-triplet-prefix?)))
1829 #t))))
1830
1831 ,@(substitute-keyword-arguments (package-arguments binutils)
1832 ((#:configure-flags cf)
1833 `(cons ,(string-append "--target=" (boot-triplet))
1834 ,cf)))))
1835 (inputs (%boot0-inputs))))
bdb36958 1836
b810a850
LC
1837(define libstdc++-boot0
1838 ;; GCC's libcc1 is always built as a shared library (the top-level
1839 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1840 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
809b0a90 1841 ;; C++14 features missing in some of our bootstrap compilers.
99b73d0f 1842 (let ((lib (make-libstdc++ gcc-4.9)))
b810a850
LC
1843 (package
1844 (inherit lib)
99b73d0f 1845 (source (bootstrap-origin (package-source lib)))
b810a850
LC
1846 (name "libstdc++-boot0")
1847 (arguments
1848 `(#:guile ,%bootstrap-guile
1849 #:implicit-inputs? #f
1850
1851 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1852 #:validate-runpath? #f
1853
d536c39e 1854 ,@(match (%current-system)
eb443459 1855 ((or "i686-linux" "x86_64-linux")
d536c39e
JN
1856 (substitute-keyword-arguments (package-arguments lib)
1857 ((#:phases phases)
1858 `(modify-phases ,phases
a6facf94
MB
1859 (add-after 'unpack 'workaround-wrapper-bug
1860 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1861 ;; fail, which in turn confuses the configure script.
1862 (lambda _
1863 (substitute* "libstdc++-v3/configure"
1864 (("g\\+\\+ -v") "true"))
1865 #t))))))
d536c39e 1866 (_ (package-arguments lib)))))
a2b2070b 1867 (inputs (%boot0-inputs))
b810a850
LC
1868 (native-inputs '()))))
1869
bdb36958 1870(define gcc-boot0
99b73d0f
LC
1871 (package
1872 (inherit gcc)
1873 (name "gcc-cross-boot0")
1874 (source (bootstrap-origin (package-source gcc)))
1875 (arguments
1876 `(#:guile ,%bootstrap-guile
1877 #:implicit-inputs? #f
1878 #:modules ((guix build gnu-build-system)
1879 (guix build utils)
1880 (ice-9 regex)
1881 (srfi srfi-1)
1882 (srfi srfi-26))
1883 ,@(substitute-keyword-arguments (package-arguments gcc)
1884 ((#:configure-flags flags)
1885 `(append (list ,(string-append "--target=" (boot-triplet))
1886
1887 ;; No libc yet.
1888 "--without-headers"
1889
1890 ;; Disable features not needed at this stage.
1891 "--disable-shared"
1892 "--enable-languages=c,c++"
1893
1894 ;; libstdc++ cannot be built at this stage
1895 ;; ("Link tests are not allowed after
1896 ;; GCC_NO_EXECUTABLES.").
1897 "--disable-libstdc++-v3"
1898
1899 "--disable-threads"
1900 "--disable-libmudflap"
1901 "--disable-libatomic"
1902 "--disable-libsanitizer"
1903 "--disable-libitm"
1904 "--disable-libgomp"
1905 "--disable-libmpx"
1906 "--disable-libcilkrts"
1907 "--disable-libvtv"
1908 "--disable-libssp"
1909 "--disable-libquadmath"
1910 "--disable-decimal-float")
1911 (remove (cut string-match
1912 "--(with-system-zlib|enable-languages.*)" <>)
1913 ,flags)))
1914 ((#:make-flags flags)
1915 `(let* ((libc (assoc-ref %build-inputs "libc"))
1916 (libc-native (or (assoc-ref %build-inputs "libc-native")
1917 libc)))
1918 `(,(string-append "LDFLAGS="
1919 "-Wl,-rpath=" libc-native "/lib "
1920 "-Wl,-dynamic-linker "
1921 "-Wl," libc-native ,(glibc-dynamic-linker
1922 (match (%current-system)
1923 ("x86_64-linux" "i686-linux")
1924 (_ (%current-system))))))))
1925 ((#:phases phases)
1926 `(modify-phases ,phases
1927 (add-after 'unpack 'unpack-gmp&co
1928 (lambda* (#:key inputs #:allow-other-keys)
1929 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1930 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1931 (mpc (assoc-ref %build-inputs "mpc-source")))
1932
1933 ;; To reduce the set of pre-built bootstrap inputs, build
1934 ;; GMP & co. from GCC.
1935 (for-each (lambda (source)
1936 (invoke "tar" "xvf" source))
1937 (list gmp mpfr mpc))
1938
1939 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1940 ,@(map (lambda (lib)
1941 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1942 ;; into gmp-6.0.0.
1943 `(symlink ,(string-trim-right
1944 (package-full-name lib "-")
1945 char-set:letter)
1946 ,(package-name lib)))
1947 (list gmp-6.0 mpfr mpc))
1948 #t)))
1949 ,(match (%current-system)
1950 ((or "i686-linux" "x86_64-linux")
1951 '(add-before 'configure 'fix-libcc1
77e02d94
MB
1952 (lambda* (#:key inputs #:allow-other-keys)
1953 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
1954 ;; to placate the 'validate-runpath' phase.
1955 (substitute* "libcc1/Makefile.in"
1956 (("la_LDFLAGS =")
1957 (string-append "la_LDFLAGS = -Wl,-rpath="
1958 (assoc-ref inputs "gcc") "/lib")))
1959 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
1960 (substitute* "libcc1/configure"
1961 (("g\\+\\+ -v") "true"))
1962 #t)))
99b73d0f
LC
1963 (_ '(add-before 'configure 'return-true
1964 (lambda _ #t))))
1965 (add-after 'install 'symlink-libgcc_eh
1966 (lambda* (#:key outputs #:allow-other-keys)
1967 (let ((out (assoc-ref outputs "lib")))
1968 ;; Glibc wants to link against libgcc_eh, so provide
1969 ;; it.
1970 (with-directory-excursion
1971 (string-append out "/lib/gcc/"
1972 ,(boot-triplet)
1973 "/" ,(package-version gcc))
1974 (symlink "libgcc.a" "libgcc_eh.a"))
1975 #t))))))))
bdb36958 1976
99b73d0f
LC
1977 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
1978 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
1979 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
1980 ("binutils-cross" ,binutils-boot0)
bdb36958 1981
99b73d0f
LC
1982 ;; The libstdc++ that libcc1 links against.
1983 ("libstdc++" ,libstdc++-boot0)
b810a850 1984
99b73d0f
LC
1985 ;; Call it differently so that the builder can check whether
1986 ;; the "libc" input is #f.
1987 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
1988 ,@(alist-delete "libc" (%boot0-inputs))))
9dee9e8f 1989
99b73d0f
LC
1990 ;; No need for the native-inputs to build the documentation at this stage.
1991 (native-inputs `())))
bdb36958
LC
1992
1993(define perl-boot0
99b73d0f
LC
1994 (package
1995 (inherit perl)
1996 (name "perl-boot0")
1997 (source (bootstrap-origin (package-source perl)))
1998 (inputs (%boot0-inputs))
1999 (arguments
2000 `(#:implicit-inputs? #f
2001 #:guile ,%bootstrap-guile
2002 #:validate-runpath? #f
2003
2004 ;; At the very least, this must not depend on GCC & co.
2005 #:disallowed-references ,(list %bootstrap-binutils)
2006
2007 ,@(substitute-keyword-arguments (package-arguments perl)
2008 ((#:phases phases)
2009 `(modify-phases ,phases
2010 ;; Pthread support is missing in the bootstrap compiler
2011 ;; (broken spec file), so disable it.
2012 (add-before 'configure 'disable-pthreads
2013 (lambda _
2014 (substitute* "Configure"
2015 (("^libswanted=(.*)pthread" _ before)
2016 (string-append "libswanted=" before)))
2017 #t))))
2018 ;; Do not configure with '-Dusethreads' since pthread
2019 ;; support is missing.
2020 ((#:configure-flags configure-flags)
2021 `(delete "-Dusethreads" ,configure-flags)))))))
bdb36958 2022
32f4a073 2023(define m4-boot0
99b73d0f
LC
2024 (package
2025 (inherit m4)
2026 (name "m4-boot0")
2027 (source (bootstrap-origin (package-source m4)))
2028 (inputs (%boot0-inputs))
2029 (arguments
2030 `(#:guile ,%bootstrap-guile
2031 #:implicit-inputs? #f
2032 ,@(package-arguments m4)))))
2033
d75acc29
MR
2034(define bison-boot0
2035 ;; This Bison is needed to build MiG so we need it early in the process.
12908554 2036 ;; Recent versions of Linux-Libre headers also depend on this.
99b73d0f
LC
2037 (package
2038 (inherit bison)
e5c1f5cf 2039 (name "bison-boot0")
57bc2dcf 2040 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
2041 (native-inputs `(("perl" ,perl-boot0)))
2042 (inputs (%boot0-inputs)) ;remove Flex...
2043 (arguments
2044 `(#:tests? #f ;... and thus disable tests
2045 #:implicit-inputs? #f
2046 #:guile ,%bootstrap-guile
2047
99b73d0f
LC
2048 ;; Zero timestamps in liby.a; this must be done
2049 ;; explicitly here because the bootstrap Binutils don't
2050 ;; do that (default is "cru".)
2051 #:make-flags `("ARFLAGS=crD"
2052 ,,(match (%current-system)
2053 ;; ranlib: '-D': No such file
2054 ((or "i686-linux" "x86_64-linux")
2055 "RANLIB=ranlib")
2056 (_
2057 "RANLIB=ranlib -D"))
62548232
LC
2058 "V=1")
2059
2060 ,@(package-arguments bison)))))
d75acc29
MR
2061
2062(define flex-boot0
12908554 2063 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
99b73d0f
LC
2064 (package
2065 (inherit flex)
2066 (native-inputs `(("bison" ,bison-boot0)))
57bc2dcf 2067 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
2068 (inputs (%boot0-inputs))
2069 (arguments
2070 `(#:implicit-inputs? #f
2071 #:guile ,%bootstrap-guile
2072 #:tests? #f))))
d75acc29 2073
429243a4
MB
2074(define rsync-boot0
2075 (package
2076 (inherit rsync)
2077 (native-inputs `(("perl" ,perl-boot0)))
2078 (inputs (%boot0-inputs))
2079 (arguments
2080 `(#:implicit-inputs? #f
2081 #:guile ,%bootstrap-guile))))
2082
8102cf0b
LC
2083(define linux-libre-headers-boot0
2084 (mlambda ()
2085 "Return Linux-Libre header files for the bootstrap environment."
2086 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
2087 ;; between (gnu packages linux) and this module. Additionally, memoize
2088 ;; the result to play well with further memoization and code that relies
2089 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
99b73d0f
LC
2090 (package
2091 (inherit linux-libre-headers)
2092 (arguments
2093 `(#:guile ,%bootstrap-guile
2094 #:implicit-inputs? #f
2095 ,@(package-arguments linux-libre-headers)))
2096 (native-inputs
2097 `(("perl" ,perl-boot0)
2098
2099 ;; Flex and Bison are required since version 4.16.
2100 ("flex" ,flex-boot0)
2101 ("bison" ,bison-boot0)
429243a4
MB
2102
2103 ;; Rsync is required since version 5.3.
2104 ("rsync" ,rsync-boot0)
99b73d0f 2105 ,@(%boot0-inputs))))))
bdb36958 2106
efa8fdda
LC
2107(define with-boot0
2108 (package-with-explicit-inputs %boot0-inputs
2109 %bootstrap-guile))
2110
d75acc29 2111(define gnumach-headers-boot0
efa8fdda 2112 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
d75acc29
MR
2113
2114(define mig-boot0
efa8fdda
LC
2115 (let* ((mig (package
2116 (inherit (package-with-bootstrap-guile mig))
d75acc29
MR
2117 (native-inputs `(("bison" ,bison-boot0)
2118 ("flex" ,flex-boot0)))
2119 (inputs `(("flex" ,flex-boot0)))
2120 (arguments
2121 `(#:configure-flags
2122 `(,(string-append "LDFLAGS=-Wl,-rpath="
2123 (assoc-ref %build-inputs "flex") "/lib/")))))))
efa8fdda 2124 (with-boot0 mig)))
d75acc29
MR
2125
2126(define hurd-headers-boot0
2127 (let ((hurd-headers (package (inherit hurd-headers)
2128 (native-inputs `(("mig" ,mig-boot0)))
2129 (inputs '()))))
efa8fdda 2130 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
d75acc29
MR
2131
2132(define hurd-minimal-boot0
2133 (let ((hurd-minimal (package (inherit hurd-minimal)
2134 (native-inputs `(("mig" ,mig-boot0)))
2135 (inputs '()))))
efa8fdda 2136 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
d75acc29 2137
8102cf0b
LC
2138(define hurd-core-headers-boot0
2139 (mlambda ()
2140 "Return the Hurd and Mach headers as well as initial Hurd libraries for
d75acc29 2141the bootstrap environment."
efa8fdda
LC
2142 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
2143 (arguments `(#:guile ,%bootstrap-guile
2144 ,@(package-arguments hurd-core-headers)))
2145 (inputs
2146 `(("gnumach-headers" ,gnumach-headers-boot0)
2147 ("hurd-headers" ,hurd-headers-boot0)
2148 ("hurd-minimal" ,hurd-minimal-boot0)
2149 ,@(%boot0-inputs))))))
d75acc29
MR
2150
2151(define* (kernel-headers-boot0 #:optional (system (%current-system)))
2152 (match system
2153 ("i586-gnu" (hurd-core-headers-boot0))
2154 (_ (linux-libre-headers-boot0))))
2155
bdb36958
LC
2156(define texinfo-boot0
2157 ;; Texinfo used to build libc's manual.
2158 ;; We build without ncurses because it fails to build at this stage, and
2159 ;; because we don't need the stand-alone Info reader.
a2b2070b 2160 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
99b73d0f
LC
2161 (package
2162 (inherit texinfo)
2163 (native-inputs '())
2164 (inputs `(,@(%boot0-inputs)
2165 ("perl" ,perl-boot0)))
2166 (arguments
2167 `(#:implicit-inputs? #f
2168 #:guile ,%bootstrap-guile
2169
2170 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
2171 ;; character type in locale" but we don't have a UTF-8 locale at this
2172 ;; stage, so skip them.
2173 #:tests? #f))))
bdb36958 2174
5f3f7039
MB
2175(define expat-sans-tests
2176 (package
2177 (inherit expat)
99b73d0f 2178 (inputs (%boot0-inputs))
5f3f7039
MB
2179 (arguments
2180 ;; XXX: Linking 'runtestscpp' fails with things like:
2181 ;;
2182 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
2183 ;;
2184 ;; Skip tests altogether.
99b73d0f
LC
2185 `(#:implicit-inputs? #f
2186 #:guile ,%bootstrap-guile
2187
2188 ,@(substitute-keyword-arguments (package-arguments expat)
2189 ((#:configure-flags flags ''())
2190 ;; Since we're not passing the right -Wl,-rpath flags, build the
2191 ;; static library to avoid RUNPATH validation failure.
2192 `(cons "--disable-shared" ,flags))
2193 ((#:tests? _ #f) #f))))))
5f3f7039
MB
2194
2195(define python-boot0
99b73d0f
LC
2196 (package
2197 (inherit python-minimal)
2198 ;; We cannot use Python 3.7 and later here, because they require
2199 ;; pthreads, which is missing on non-x86 platforms at this stage.
2200 ;; Python 3.6 technically supports being built without threading
2201 ;; support, but requires additional patches.
73fec9ca 2202 (version "3.5.9")
99b73d0f
LC
2203 (source (bootstrap-origin
2204 (origin
404efac4 2205 (method url-fetch)
99b73d0f
LC
2206 (uri (string-append "https://www.python.org/ftp/python/"
2207 version "/Python-" version ".tar.xz"))
99b73d0f
LC
2208 (sha256
2209 (base32
73fec9ca 2210 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
404efac4
MB
2211 (modules '((guix build utils)))
2212 (snippet
2213 '(begin
2214 ;; Delete the bundled copy of libexpat.
2215 (delete-file-recursively "Modules/expat")
2216 (substitute* "Modules/Setup.dist"
2217 ;; Link Expat instead of embedding the bundled one.
2218 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
2219 #t)))))
99b73d0f
LC
2220 (inputs
2221 `(,@(%boot0-inputs)
2222 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
2223 (native-inputs '()) ;and pkg-config
2224 (arguments
2225 `(#:implicit-inputs? #f
2226 #:guile ,%bootstrap-guile
2227
2228 ,@(substitute-keyword-arguments (package-arguments python-minimal)
2229 ;; Disable features that cannot be built at this stage.
2230 ((#:configure-flags _ ''())
2231 `(list "--without-ensurepip"
2232 "--without-threads"))
2233 ;; Clear #:make-flags, such that changes to the regular
2234 ;; Python package won't interfere with this one.
2235 ((#:make-flags _ ''()) ''())
2236 ((#:phases phases)
2237 `(modify-phases ,phases
2238 (add-before 'configure 'disable-modules
2239 (lambda _
2240 (substitute* "setup.py"
2241 ;; Disable ctypes, since it requires libffi.
2242 (("extensions\\.append\\(ctypes\\)") "")
2243 ;; Prevent the 'ossaudiodev' extension from being
2244 ;; built, since it requires Linux headers.
2245 (("'linux', ") ""))
2246 #t))
2247 (delete 'set-TZDIR)))
2248 ((#:tests? _ #f) #f))))))
5f3f7039 2249
dab669e0
LC
2250(define ld-wrapper-boot0
2251 (mlambda ()
2252 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
2253 ;; in their RUNPATH, otherwise validate-runpath will fail.
2254 (make-ld-wrapper "ld-wrapper-boot0"
2255 #:target boot-triplet
2256 #:binutils binutils-boot0
2257 #:guile %bootstrap-guile
2258 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
2259 #:guile-for-build %bootstrap-guile)))
d75acc29 2260
a2b2070b 2261(define (%boot1-inputs)
bdb36958
LC
2262 ;; 2nd stage inputs.
2263 `(("gcc" ,gcc-boot0)
f50b013f 2264 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
bdb36958 2265 ("binutils-cross" ,binutils-boot0)
a2b2070b 2266 ,@(alist-delete "binutils" (%boot0-inputs))))
bdb36958
LC
2267
2268(define glibc-final-with-bootstrap-bash
2269 ;; The final libc, "cross-built". If everything went well, the resulting
2270 ;; store path has no dependencies. Actually, the really-final libc is
2271 ;; built just below; the only difference is that this one uses the
2272 ;; bootstrap Bash.
99b73d0f
LC
2273 (package
2274 (inherit glibc)
2275 (name "glibc-intermediate")
2276 (source (bootstrap-origin (package-source glibc)))
2277 (arguments
2278 `(#:guile ,%bootstrap-guile
2279 #:implicit-inputs? #f
2280
2281 ,@(substitute-keyword-arguments (package-arguments glibc)
2282 ((#:configure-flags flags)
2283 `(append (list ,(string-append "--host=" (boot-triplet))
2284 ,(string-append "--build="
2285 (nix-system->gnu-triplet)))
2286 ,flags))
2287 ((#:phases phases)
2288 `(modify-phases ,phases
2289 (add-before 'configure 'pre-configure
2290 (lambda* (#:key inputs #:allow-other-keys)
2291 ;; Don't clobber CPATH with the bootstrap libc.
2292 (setenv "NATIVE_CPATH" (getenv "CPATH"))
2293 (unsetenv "CPATH")
2294
2295 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
2296 ,@(if (hurd-triplet? (%current-system))
2297 `((substitute* "libpthread/Makefile"
2298 (("LDLIBS-pthread.so =.*")
2299 (string-append "LDLIBS-pthread.so = "
2300 (assoc-ref %build-inputs "kernel-headers")
2301 "/lib/libihash.a\n"))))
2302 '())
2303
2304 ;; 'rpcgen' needs native libc headers to be built.
2305 (substitute* "sunrpc/Makefile"
2306 (("sunrpc-CPPFLAGS =.*" all)
2307 (string-append "CPATH = $(NATIVE_CPATH)\n"
2308 "export CPATH\n"
2309 all "\n")))
2310 #t)))))))
2311 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2312 (native-inputs
2313 `(("bison" ,bison-boot0)
2314 ("texinfo" ,texinfo-boot0)
2315 ("perl" ,perl-boot0)
2316 ("python" ,python-boot0)))
2317 (inputs
2318 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2319 ;; it in $CPATH, hence the 'pre-configure' phase above.
2320 ,@(%boot1-inputs)
2321
2322 ;; A native MiG is needed to build Glibc on Hurd.
2323 ,@(if (hurd-triplet? (%current-system))
2324 `(("mig" ,mig-boot0))
2325 '())
2326
2327 ;; A native GCC is needed to build `cross-rpcgen'.
2328 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2329
2330 ;; Here, we use the bootstrap Bash, which is not satisfactory
2331 ;; because we don't want to depend on bootstrap tools.
2332 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
bdb36958
LC
2333
2334(define (cross-gcc-wrapper gcc binutils glibc bash)
2335 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2336that makes it available under the native tool names."
c92f1c0a 2337 (package (inherit gcc)
bdb36958
LC
2338 (name (string-append (package-name gcc) "-wrapped"))
2339 (source #f)
2340 (build-system trivial-build-system)
2341 (outputs '("out"))
2342 (arguments
2343 `(#:guile ,%bootstrap-guile
2344 #:modules ((guix build utils))
2345 #:builder (begin
2346 (use-modules (guix build utils))
2347
2348 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2349 (gcc (assoc-ref %build-inputs "gcc"))
2350 (libc (assoc-ref %build-inputs "libc"))
2351 (bash (assoc-ref %build-inputs "bash"))
2352 (out (assoc-ref %outputs "out"))
2353 (bindir (string-append out "/bin"))
2354 (triplet ,(boot-triplet)))
2355 (define (wrap-program program)
2356 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2357 ;; needs to be told where to find the crt files and
2358 ;; the dynamic linker.
2359 (call-with-output-file program
2360 (lambda (p)
2361 (format p "#!~a/bin/bash
2362exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2363 bash
2364 gcc triplet program
2365 libc libc
2366 ,(glibc-dynamic-linker))))
2367
2368 (chmod program #o555))
2369
2370 (mkdir-p bindir)
2371 (with-directory-excursion bindir
2372 (for-each (lambda (tool)
2373 (symlink (string-append binutils "/bin/"
2374 triplet "-" tool)
2375 tool))
2376 '("ar" "ranlib"))
e3cfef22
MW
2377 (for-each wrap-program '("gcc" "g++")))
2378
2379 #t))))
bdb36958
LC
2380 (native-inputs
2381 `(("binutils" ,binutils)
2382 ("gcc" ,gcc)
2383 ("libc" ,glibc)
2384 ("bash" ,bash)))
2385 (inputs '())))
2386
32793c09
LC
2387(define gcc-boot0-intermediate-wrapped
2388 (mlambda ()
2389 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2390 ;; non-cross names.
2391 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2392 glibc-final-with-bootstrap-bash
2393 (car (assoc-ref (%boot1-inputs) "bash")))))
eb443459 2394
bdb36958 2395(define static-bash-for-glibc
90d891fc 2396 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
99b73d0f
LC
2397 (package
2398 (inherit static-bash)
2399 (source (bootstrap-origin (package-source static-bash)))
2400 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2401 ("libc" ,glibc-final-with-bootstrap-bash)
2402 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2403 ,@(fold alist-delete (%boot1-inputs)
2404 '("gcc" "libc"))))
2405 (arguments
2406 `(#:implicit-inputs? #f
2407 #:guile ,%bootstrap-guile
2408
2409 ,@(substitute-keyword-arguments (package-arguments static-bash)
2410 ((#:configure-flags flags '())
2411 ;; Add a '-L' flag so that the pseudo-cross-ld of
2412 ;; BINUTILS-BOOT0 can find libc.a.
2413 `(append ,flags
2414 (list (string-append "LDFLAGS=-static -L"
2415 (assoc-ref %build-inputs
2416 "libc:static")
2417 "/lib")))))))))
bdb36958 2418
6162b95d
LC
2419(define gettext-boot0
2420 ;; A minimal gettext used during bootstrap.
99b73d0f
LC
2421 (package
2422 (inherit gettext-minimal)
2423 (name "gettext-boot0")
2424 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2425 ;; simplify the dependency chain, we stick to this version here.
2426 (version "0.19.8.1")
2427 (source (origin
2428 (method url-fetch)
2429 (uri (string-append "mirror://gnu/gettext/gettext-"
2430 version ".tar.gz"))
2431 (sha256
2432 (base32
2433 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2434 (inputs (%boot1-inputs)) ;zero dependencies
2435 (arguments
2436 `(#:implicit-inputs? #f
2437 #:guile ,%bootstrap-guile
2438 #:tests? #f
2439 #:phases (modify-phases %standard-phases
2440 ;; Build only the tools.
2441 (add-after 'unpack 'chdir
2442 (lambda _
2443 (chdir "gettext-tools")
2444 #t))
2445
2446 ;; Some test programs require pthreads, which we don't have.
2447 (add-before 'configure 'no-test-programs
2448 (lambda _
2449 (substitute* "tests/Makefile.in"
2450 (("^PROGRAMS =.*$")
2451 "PROGRAMS =\n"))
2452 #t)))))))
6162b95d 2453
89223417 2454(define glibc-final
bdb36958 2455 ;; The final glibc, which embeds the statically-linked Bash built above.
7c788ed2 2456 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
99b73d0f
LC
2457 (package/inherit
2458 glibc
2459 (name "glibc")
2460 (source (bootstrap-origin (package-source glibc)))
2461 (inputs `(("static-bash" ,static-bash-for-glibc)
2462 ,@(alist-delete
2463 "static-bash"
2464 (package-inputs glibc-final-with-bootstrap-bash))))
2465
2466 ;; This time we need 'msgfmt' to install all the libc.mo files.
2467 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2468 ("gettext" ,gettext-boot0)))
2469
2470 (propagated-inputs
2471 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2472
2473 ;; The final libc only refers to itself, but the 'debug' output contains
2474 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2475 ;; if 'allowed-references' were per-output.
2476 (arguments
2477 `(#:allowed-references
2478 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2479 static-bash-for-glibc
2480 (package-outputs glibc-final-with-bootstrap-bash))
2481
2482 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
bdb36958 2483
32793c09
LC
2484(define gcc-boot0-wrapped
2485 (mlambda ()
2486 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2487 ;; non-cross names.
2488 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2489 (car (assoc-ref (%boot1-inputs) "bash")))))
bdb36958 2490
a2b2070b 2491(define (%boot2-inputs)
bdb36958
LC
2492 ;; 3rd stage inputs.
2493 `(("libc" ,glibc-final)
6dff905e 2494 ("libc:static" ,glibc-final "static")
f50b013f 2495 ("gcc" ,(gcc-boot0-wrapped))
4ae7dc7b 2496 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
bdb36958
LC
2497
2498(define binutils-final
99b73d0f
LC
2499 (package
2500 (inherit binutils)
2501 (source (bootstrap-origin (package-source binutils)))
2502 (arguments
2503 `(#:guile ,%bootstrap-guile
2504 #:implicit-inputs? #f
2505 #:allowed-references ("out" ,glibc-final)
2506 ,@(package-arguments binutils)))
2507 (inputs (%boot2-inputs))))
bdb36958
LC
2508
2509(define libstdc++
2510 ;; Intermediate libstdc++ that will allow us to build the final GCC
2511 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
99b73d0f 2512 (let ((lib (make-libstdc++ gcc)))
86d02fa8
EF
2513 (package
2514 (inherit lib)
99b73d0f 2515 (source (bootstrap-origin (package-source lib)))
86d02fa8
EF
2516 (arguments
2517 `(#:guile ,%bootstrap-guile
2518 #:implicit-inputs? #f
2519 #:allowed-references ("out")
2520
2521 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2522 #:validate-runpath? #f
2523
2524 ;; All of the package arguments from 'make-libstdc++
2525 ;; except for the configure-flags.
2526 ,@(package-arguments lib)
2527 #:configure-flags `("--disable-shared"
01e8263f 2528 "--disable-libstdcxx-dual-abi"
86d02fa8
EF
2529 "--disable-libstdcxx-threads"
2530 "--disable-libstdcxx-pch"
2531 ,(string-append "--with-gxx-include-dir="
2532 (assoc-ref %outputs "out")
2533 "/include"))))
2534 (outputs '("out"))
a2b2070b 2535 (inputs (%boot2-inputs))
86d02fa8 2536 (synopsis "GNU C++ standard library (intermediate)"))))
bdb36958 2537
98bd851e
LC
2538(define zlib-final
2539 ;; Zlib used by GCC-FINAL.
99b73d0f
LC
2540 (package
2541 (inherit zlib)
2542 (arguments
2543 `(#:guile ,%bootstrap-guile
2544 #:implicit-inputs? #f
2545 #:allowed-references ("out" ,glibc-final)
2546 ,@(package-arguments zlib)))
2547 (inputs (%boot2-inputs))))
98bd851e 2548
dab669e0
LC
2549(define ld-wrapper-boot3
2550 (mlambda ()
2551 ;; A linker wrapper that uses the bootstrap Guile.
2552 (make-ld-wrapper "ld-wrapper-boot3"
2553 #:binutils binutils-final
2554 #:guile %bootstrap-guile
2555 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2556 #:guile-for-build %bootstrap-guile)))
98bd851e 2557
89223417 2558(define gcc-final
bdb36958
LC
2559 ;; The final GCC.
2560 (package (inherit gcc-boot0)
2561 (name "gcc")
ab999c25
LC
2562
2563 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2564 ;; "debug" output contains disallowed references, notably
2565 ;; linux-libre-headers. Disable the debugging output to work around that.
2566 (outputs (delete "debug" (package-outputs gcc-boot0)))
2567
bdb36958
LC
2568 (arguments
2569 `(#:guile ,%bootstrap-guile
2570 #:implicit-inputs? #f
2571
98bd851e 2572 #:allowed-references ("out" "lib" ,zlib-final
90d891fc 2573 ,glibc-final ,static-bash-for-glibc)
bdb36958 2574
d485ebba
LC
2575 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2576 ;; reason, but it is not in their RUNPATH. This is a false
2577 ;; positive, so turn it off.
2578 #:validate-runpath? #f
2579
eb443459 2580 ,@(substitute-keyword-arguments (package-arguments gcc)
bdb36958 2581 ((#:make-flags flags)
52cfd8cb 2582 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
98bd851e
LC
2583 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2584 (map (lambda (flag)
2585 (if (string-prefix? "LDFLAGS=" flag)
2586 (string-append flag " -L"
2587 (assoc-ref %build-inputs "libstdc++")
2588 "/lib -L" zlib "/lib -Wl,-rpath="
2589 zlib "/lib")
2590 flag))
2591 ,flags)))
eb443459
JN
2592 ;; Build again GMP & co. within GCC's build process, because it's hard
2593 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2594 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
bdb36958 2595 ((#:phases phases)
eb443459
JN
2596 `(modify-phases ,phases
2597 (add-after 'unpack 'unpack-gmp&co
2598 (lambda* (#:key inputs #:allow-other-keys)
2599 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2600 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2601 (mpc (assoc-ref %build-inputs "mpc-source")))
2602
2603 ;; To reduce the set of pre-built bootstrap inputs, build
2604 ;; GMP & co. from GCC.
2605 (for-each (lambda (source)
2606 (invoke "tar" "xvf" source))
2607 (list gmp mpfr mpc))
2608
2609 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2610 ,@(map (lambda (lib)
2611 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2612 ;; into gmp-6.0.0.
2613 `(symlink ,(string-trim-right
2614 (package-full-name lib "-")
2615 char-set:letter)
2616 ,(package-name lib)))
2617 (list gmp-6.0 mpfr mpc))
2618 #t))))))))
bdb36958 2619
90d891fc
LC
2620 ;; This time we want Texinfo, so we get the manual. Add
2621 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2622 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2623 ;; scripts?).
bdb36958 2624 (native-inputs `(("texinfo" ,texinfo-boot0)
19d27131 2625 ("perl" ,perl-boot0) ;for manpages
90d891fc 2626 ("static-bash" ,static-bash-for-glibc)
bdb36958
LC
2627 ,@(package-native-inputs gcc-boot0)))
2628
8309c389 2629 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
bdb36958
LC
2630 ("mpfr-source" ,(package-source mpfr))
2631 ("mpc-source" ,(package-source mpc))
f50b013f 2632 ("ld-wrapper" ,(ld-wrapper-boot3))
bdb36958
LC
2633 ("binutils" ,binutils-final)
2634 ("libstdc++" ,libstdc++)
98bd851e 2635 ("zlib" ,zlib-final)
a2b2070b 2636 ,@(%boot2-inputs)))))
bdb36958 2637
a2b2070b 2638(define (%boot3-inputs)
bdb36958
LC
2639 ;; 4th stage inputs.
2640 `(("gcc" ,gcc-final)
f50b013f 2641 ("ld-wrapper" ,(ld-wrapper-boot3))
a2b2070b 2642 ,@(alist-delete "gcc" (%boot2-inputs))))
bdb36958
LC
2643
2644(define bash-final
2645 ;; Link with `-static-libgcc' to make sure we don't retain a reference
704243e0
LC
2646 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2647 ;; on Readline and ncurses.
99b73d0f
LC
2648 (let ((bash (static-libgcc-package bash-minimal)))
2649 (package
2650 (inherit bash)
2651 (source (bootstrap-origin (package-source bash)))
2652 (inputs (%boot3-inputs))
2653 (arguments
2654 `(#:implicit-inputs? #f
2655 #:guile ,%bootstrap-guile
2656
2657 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2658
2659 ,@(package-arguments bash))))))
bdb36958 2660
a2b2070b 2661(define (%boot4-inputs)
bdb36958
LC
2662 ;; Now use the final Bash.
2663 `(("bash" ,bash-final)
a2b2070b 2664 ,@(alist-delete "bash" (%boot3-inputs))))
bdb36958 2665
8f417ed2
LC
2666(define with-boot4
2667 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2668
bdb36958 2669(define-public guile-final
386b71d1
LC
2670 ;; This package must be public because other modules refer to it. However,
2671 ;; mark it as hidden so that 'fold-packages' ignores it.
8f417ed2
LC
2672 (with-boot4 (hidden-package
2673 (package-with-bootstrap-guile guile-2.2/fixed))))
bdb36958 2674
89223417 2675(define glibc-utf8-locales-final
87c8b92f
LC
2676 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2677 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2678 ;; with the full range of Unicode codepoints (remember
2679 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2680 ;; function.)
2681 (package
2682 (inherit glibc-utf8-locales)
58a75996
MO
2683 (native-inputs
2684 `(("glibc" ,glibc-final)
8f417ed2 2685 ("gzip" ,(with-boot4 gzip))))))
87c8b92f 2686
28cbc587
LC
2687(define-public ld-wrapper
2688 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
78dea6f1
LC
2689 (make-ld-wrapper "ld-wrapper"
2690 #:binutils binutils-final
2691 #:guile guile-final
2692 #:bash bash-final))
28cbc587 2693
a2b2070b 2694(define (%boot5-inputs)
b6ac5451
LC
2695 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2696 ;; with an older libc, which cannot load the new locale format. See
28cbc587 2697 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
b6ac5451 2698 `(("locales" ,glibc-utf8-locales-final)
a2b2070b 2699 ,@(%boot4-inputs)))
87c8b92f 2700
8f417ed2
LC
2701(define with-boot5
2702 (package-with-explicit-inputs %boot5-inputs))
2703
bdb36958
LC
2704(define gnu-make-final
2705 ;; The final GNU Make, which uses the final Guile.
8f417ed2 2706 (let ((pkg-config (package
537b2dab 2707 (inherit %pkg-config) ;the native pkg-config
8f417ed2
LC
2708 (inputs `(("guile" ,guile-final)
2709 ,@(%boot5-inputs)))
2710 (arguments
2711 `(#:implicit-inputs? #f
2712 ,@(package-arguments pkg-config))))))
2713 (package
2714 (inherit (package-with-bootstrap-guile gnu-make))
2715 (inputs `(("guile" ,guile-final)
2716 ,@(%boot5-inputs)))
2717 (native-inputs `(("pkg-config" ,pkg-config)))
2718 (arguments
2719 `(#:implicit-inputs? #f
2720 ,@(package-arguments gnu-make))))))
2721
bdb36958 2722
bdb36958
LC
2723(define coreutils-final
2724 ;; The final Coreutils. Treat them specially because some packages, such as
2725 ;; Findutils, keep a reference to the Coreutils they were built with.
8f417ed2
LC
2726 (with-boot5 (package-with-bootstrap-guile coreutils)
2727 ;; Use the final Guile, linked against the
2728 ;; final libc with working iconv, so that
2729 ;; 'substitute*' works well when touching
2730 ;; test files in Gettext.
2731 ))
bdb36958
LC
2732
2733(define grep-final
2734 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2735 ;; built before gzip.
8f417ed2 2736 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
78ca500a
LC
2737 (package/inherit grep
2738 (inputs (alist-delete "pcre" (package-inputs grep)))
2739 (native-inputs `(("perl" ,perl-boot0))))))
bdb36958 2740
a2b2070b 2741(define (%boot6-inputs)
bdb36958
LC
2742 ;; Now use the final Coreutils.
2743 `(("coreutils" ,coreutils-final)
2744 ("grep" ,grep-final)
a2b2070b 2745 ,@(%boot5-inputs)))
b0fd2bd3 2746
8f417ed2
LC
2747(define with-boot6
2748 (package-with-explicit-inputs %boot6-inputs))
2749
301a4249
LC
2750(define sed-final
2751 ;; The final sed.
8f417ed2 2752 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
301a4249
LC
2753 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2754
bdb36958
LC
2755(define-public %final-inputs
2756 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2757 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2758 ;; used for origins that have patches, thereby avoiding circular
2759 ;; dependencies.
8f417ed2 2760 (let ((finalize (compose with-boot6
099dbc4f 2761 package-with-bootstrap-guile)))
bdb36958 2762 `(,@(map (match-lambda
099dbc4f
LC
2763 ((name package)
2764 (list name (finalize package))))
bdb36958 2765 `(("tar" ,tar)
87c8b92f 2766 ("gzip" ,gzip)
bdb36958
LC
2767 ("bzip2" ,bzip2)
2768 ("xz" ,xz)
c00a9fbf 2769 ("file" ,file)
bdb36958
LC
2770 ("diffutils" ,diffutils)
2771 ("patch" ,patch)
bdb36958
LC
2772 ("findutils" ,findutils)
2773 ("gawk" ,gawk)))
301a4249 2774 ("sed" ,sed-final)
bdb36958
LC
2775 ("grep" ,grep-final)
2776 ("coreutils" ,coreutils-final)
2777 ("make" ,gnu-make-final)
2778 ("bash" ,bash-final)
2779 ("ld-wrapper" ,ld-wrapper)
2780 ("binutils" ,binutils-final)
2781 ("gcc" ,gcc-final)
b0fd2bd3 2782 ("libc" ,glibc-final)
6dff905e 2783 ("libc:static" ,glibc-final "static")
b0fd2bd3 2784 ("locales" ,glibc-utf8-locales-final))))
bdb36958
LC
2785
2786(define-public canonical-package
2787 (let ((name->package (fold (lambda (input result)
2788 (match input
6dff905e 2789 ((_ package . outputs)
bdb36958
LC
2790 (vhash-cons (package-full-name package)
2791 package result))))
2792 vlist-null
2793 `(("guile" ,guile-final)
2794 ,@%final-inputs))))
2795 (lambda (package)
2796 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2797the implicit inputs of 'gnu-build-system', return that one, otherwise return
2798PACKAGE.
2799
34d624ce 2800The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
bdb36958
LC
2801COREUTILS-FINAL vs. COREUTILS, etc."
2802 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2803 ;; libunistring, GMP, etc.
2804 (match (vhash-assoc (package-full-name package) name->package)
2805 ((_ . canon)
2806 ;; In general we want CANON, except if we're cross-compiling: CANON
2807 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2808 ;; process, with dependencies on things that cannot be
2809 ;; cross-compiled.
2810 (if (%current-target-system)
2811 package
2812 canon))
2813 (_ package)))))
2814
2815\f
2816;;;
2817;;; GCC toolchain.
2818;;;
2819
6869b663
CD
2820;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2821;; instantiated like this:
2822;;
2823;; (define-public gcc-glibc-2.27-toolchain
2824;; (make-gcc-toolchain gcc glibc-2.27))
2825
2826(define* (make-gcc-toolchain gcc
2827 #:optional
2828 (libc #f))
2829 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2830 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2831 (libc (if libc libc glibc-final)))
2832 (package
2833 (name (string-append (package-name gcc) "-toolchain"))
2834 (version (package-version gcc))
2835 (source #f)
2836 (build-system trivial-build-system)
2837 (arguments
2838 '(#:modules ((guix build union))
2839 #:builder (begin
2840 (use-modules (ice-9 match)
2841 (srfi srfi-26)
2842 (guix build union))
2843
2844 (let ((out (assoc-ref %outputs "out")))
2845
2846 (match %build-inputs
2847 (((names . directories) ...)
2848 (union-build out directories)))
2849
2850 (union-build (assoc-ref %outputs "debug")
2851 (list (assoc-ref %build-inputs
2852 "libc-debug")))
2853 (union-build (assoc-ref %outputs "static")
2854 (list (assoc-ref %build-inputs
2855 "libc-static")))
2856 #t))))
2857
2858 (native-search-paths (package-native-search-paths gcc))
2859 (search-paths (package-search-paths gcc))
2860
2861 (license (package-license gcc))
2862 (synopsis "Complete GCC tool chain for C/C++ development")
2863 (description
2864 "This package provides a complete GCC tool chain for C/C++ development to
34e8f0af
JB
2865be installed in user profiles. This includes GCC, as well as libc (headers and
2866binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
6869b663
CD
2867 (home-page "https://gcc.gnu.org/")
2868 (outputs '("out" "debug" "static"))
2869
2870 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2871 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2872 ;; before Binutils' ld in the user's profile.
2873 (inputs `(("gcc" ,gcc)
2874 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2875 ("binutils" ,binutils-final)
2876 ("libc" ,libc)
2877 ("libc-debug" ,libc "debug")
2878 ("libc-static" ,libc "static"))))))
bdb36958 2879
01e8263f
MB
2880(define-public gcc-toolchain
2881 (make-gcc-toolchain gcc-final))
2882
bdb36958 2883(define-public gcc-toolchain-4.8
b887ede1 2884 (make-gcc-toolchain gcc-4.8))
bdb36958
LC
2885
2886(define-public gcc-toolchain-4.9
b887ede1
LC
2887 (make-gcc-toolchain gcc-4.9))
2888
629f4d2e 2889(define-public gcc-toolchain-5
01e8263f 2890 (make-gcc-toolchain gcc-5))
60e2d5fe 2891
e760ec41 2892(define-public gcc-toolchain-6
b887ede1 2893 (make-gcc-toolchain gcc-6))
e760ec41 2894
d7ecab74 2895(define-public gcc-toolchain-7
01e8263f 2896 gcc-toolchain)
d7ecab74 2897
5ae27f57
LC
2898(define-public gcc-toolchain-8
2899 (make-gcc-toolchain gcc-8))
2900
bdfc3276
CD
2901(define-public gcc-toolchain-9
2902 (make-gcc-toolchain gcc-9))
2903
4ac5d4fe
KH
2904;; Provide the Fortran toolchain package only for the version of gfortran that
2905;; is used by Guix internally to build Fortran libraries, because combining
2906;; code compiled with different versions can cause problems.
2907
2908(define-public gfortran-toolchain
2909 (package (inherit (make-gcc-toolchain gfortran))
2910 (synopsis "Complete GCC tool chain for Fortran development")
2911 (description "This package provides a complete GCC tool chain for
2912Fortran development to be installed in user profiles. This includes
2913gfortran, as well as libc (headers and binaries, plus debugging symbols
2914in the @code{debug} output), and binutils.")))
2915
2916
bdb36958 2917;;; commencement.scm ends here