gnu: commencement: Add bzip2-mesboot.
[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 676
b022827d
JN
677(define gzip-mesboot
678 ;; The initial gzip. We keep this scripted gzip build before building make
679 ;; to soften the dependency on Gash Core Utils gzip.
680 (package
681 (inherit gzip)
682 (version "1.2.4")
683 (name "gzip-mesboot")
684 (source (origin
685 (method url-fetch)
686 (uri (string-append "mirror://gnu/gzip/gzip-" version ".tar"))
687 (sha256
688 (base32
689 "1rhgk2vvmdvnn6vygf0dja92ryyng00knl0kz5srb77k2kryjb2d"))))
690 (supported-systems '("i686-linux" "x86_64-linux"))
691 (inputs '())
692 (propagated-inputs '())
693 (native-inputs `(("tcc" ,tcc-boot0)
694 ,@(%boot-gash-inputs)))
695 (arguments
696 `(#:implicit-inputs? #f
697 #:guile ,%bootstrap-guile
698 #:strip-binaries? #f ; no strip yet
699 #:phases
700 (modify-phases %standard-phases
701 (delete 'configure)
702 (add-after 'unpack 'scripted-patch
703 (lambda _
704 (substitute* "util.c"
705 (("^char [*]strlwr" all) (string-append all "_tcc_cannot_handle_dupe")))
706 #t))
707 (replace 'build
708 (lambda _
709 (let ((files '("bits" "crypt" "deflate" "getopt" "gzip"
710 "inflate" "lzw" "trees" "unlzh" "unlzw"
711 "unpack" "unzip" "util" "zip")))
712 (define (compile x)
713 (invoke "tcc" "-c" "-D NO_UTIME=1" "-D HAVE_UNISTD_H=1"
714 (string-append x ".c")))
715 (for-each compile files)
716 (apply invoke
717 (cons* "tcc" "-o" "gzip"
718 (map (lambda (x) (string-append x ".o")) files)))
719 (link "gzip" "gunzip"))))
720 (replace 'install
721 (lambda _
722 (let* ((out (assoc-ref %outputs "out"))
723 (bin (string-append out "/bin")))
724 (install-file "gzip" bin)
725 (install-file "gunzip" bin))))
726 (replace 'check
727 (lambda _
728 (invoke "./gzip" "--version")))
729 ;; no gzip yet
730 (delete 'compress-documentation))))))
731
19be1dc6
JN
732(define make-mesboot0
733 ;; The initial make
734 (package
735 (inherit gnu-make)
736 (name "make-mesboot0")
737 (version "3.80")
738 (source (origin
739 (method url-fetch)
740 (uri (string-append "mirror://gnu/make/make-" version ".tar.gz"))
741 (sha256
742 (base32
743 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
744 (supported-systems '("i686-linux" "x86_64-linux"))
745 (inputs '())
746 (propagated-inputs '())
747 (native-inputs `(("tcc" ,tcc-boot0)
748 ,@(%boot-gash-inputs)))
749 (arguments
750 `(#:implicit-inputs? #f
751 #:guile ,%bootstrap-guile
752 #:configure-flags '("CC=tcc"
753 "CPP=tcc -E"
754 "LD=tcc"
755 "--build=i686-unknown-linux-gnu"
756 "--host=i686-unknown-linux-gnu"
757 "--disable-nls")
758 #:modules ((guix build gnu-build-system)
759 (guix build utils)
760 (srfi srfi-1))
761 #:strip-binaries? #f ; no strip yet
762 #:phases
763 (modify-phases %standard-phases
764 (add-after 'unpack 'scripted-patch
765 (lambda _
766 (substitute* "build.sh.in"
767 (("@LIBOBJS@") "getloadavg.o")
768 (("@REMOTE@") "stub"))
769 #t))
770 (add-after 'configure 'configure-fixup
771 (lambda _
772 (substitute* "make.h"
773 (("^extern long int lseek.*" all) (string-append "// " all)))
774 #t))
775 (replace 'build
776 (lambda _
777 (invoke "sh" "./build.sh")))
778 (replace 'check ; proper check needs awk
779 (lambda _
780 (invoke "./make" "--version")))
781 (replace 'install
782 (lambda _
783 (let* ((out (assoc-ref %outputs "out"))
784 (bin (string-append out "/bin")))
785 (install-file "make" bin)))))))))
786
787(define (%boot-tcc0-inputs)
788 `(("make" ,make-mesboot0)
789 ("tcc" ,tcc-boot0)
790 ,@(%boot-gash-inputs)))
791
0bf34663
JN
792(define bzip2-mesboot
793 ;; The initial bzip2
794 (package
795 (inherit bzip2)
796 (name "bzip2-mesboot")
797 (version (package-version bzip2))
798 (source (bootstrap-origin (package-source bzip2)))
799 (supported-systems '("i686-linux" "x86_64-linux"))
800 (inputs '())
801 (propagated-inputs '())
802 (native-inputs (%boot-tcc0-inputs))
803 (outputs '("out"))
804 (arguments
805 `(#:implicit-inputs? #f
806 #:guile ,%bootstrap-guile
807 #:parallel-build? #f
808 #:tests? #f ; check is naive, also checks non-built PROGRAMS
809 #:strip-binaries? #f ; no strip yet
810 #:make-flags (list "CC=tcc -I ." "AR=tcc -ar" "bzip2"
811 (string-append "PREFIX="
812 (assoc-ref %outputs "out")))
813 #:phases
814 (modify-phases %standard-phases
815 (add-after 'unpack 'scripted-patch
816 (lambda _
817 (substitute* "Makefile"
818 (("\tln " all)
819 (string-append "\t#" all)))
820 (substitute* "bzip2.c"
821 (("struct utimbuf uTimBuf;" all)
822 (string-append "// " all))
823 (("uTimBuf[.]" all)
824 (string-append "// " all))
825 (("retVal = utime [(] dstName, &uTimBuf [)];" all)
826 (string-append "retVal = 0; // " all)))
827 #t))
828 (replace 'configure
829 (lambda _
830 (with-output-to-file "utime.h"
831 (lambda _ (display "
832#define fchown(filedes, owner, group) 0
833#define fchmod(filedes, mode) 0
834")))
835 #t))
836 (replace 'check
837 (lambda _
838 (invoke "./bzip2" "--help")))
839 ;; FIXME: no compressing gzip yet
840 (delete 'compress-documentation))))))
841
0b652851 842(define tcc-boot
9a45a24f
LC
843 (package
844 (inherit tcc-boot0)
845 (name "tcc-boot")
846 (version "0.9.27")
847 (source (bootstrap-origin
848 (origin
0b652851 849 (inherit (package-source tcc))
9a45a24f
LC
850 (patches (search-patches "tcc-boot-0.9.27.patch")))))
851 (build-system gnu-build-system)
852 (inputs '())
853 (propagated-inputs '())
854 (native-inputs
855 `(("mes" ,mes-boot)
856 ("tcc" ,tcc-boot0)
0b652851 857
9a45a24f
LC
858 ("coreutils" , %bootstrap-coreutils&co)))
859 (arguments
860 `(#:implicit-inputs? #f
861 #:guile ,%bootstrap-guile
862
863 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
864 ;; with MesCC/M1/hex2-built binaries.
865 #:strip-binaries? #f
866
867 #:phases
868 (modify-phases %standard-phases
869 (replace 'configure
870 (lambda* (#:key outputs #:allow-other-keys)
871 (let* ((out (assoc-ref %outputs "out"))
872 (coreutils (assoc-ref %build-inputs "coreutils"))
873 (mes (assoc-ref %build-inputs "mes"))
874 (tcc (assoc-ref %build-inputs "tcc"))
875 (libc (assoc-ref %build-inputs "libc"))
876 (interpreter (if libc
877 ;; also for x86_64-linux, we are still on i686-linux
878 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
879 (string-append mes "/lib/mes-loader"))))
880 ;; unpack
881 (setenv "PATH" (string-append
882 coreutils "/bin"
883 ":" tcc "/bin"))
884 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
885 (invoke "sh" "configure"
886 (string-append "--cc=tcc")
887 (string-append "--cpu=i386")
888 (string-append "--prefix=" out)
889 (string-append "--elfinterp=" interpreter)
890 (string-append "--crtprefix=" tcc "/lib")
891 (string-append "--sysincludepaths=" tcc "/include")
892 (string-append "--libpaths=" tcc "/lib")))))
893 (replace 'build
894 (lambda* (#:key outputs #:allow-other-keys)
895 (let* ((out (assoc-ref %outputs "out"))
896 (mes (assoc-ref %build-inputs "mes"))
897 (tcc (assoc-ref %build-inputs "tcc"))
898 (libc (assoc-ref %build-inputs "libc"))
899 (interpreter (if libc
900 ;; also for x86_64-linux, we are still on i686-linux
901 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
902 (string-append mes "/lib/mes-loader"))))
903 (invoke "tcc"
904 "-vvv"
905 "-D" "BOOTSTRAP=1"
906 "-D" "ONE_SOURCE=1"
907 "-D" "TCC_TARGET_I386=1"
908 "-D" "CONFIG_TCC_STATIC=1"
909 "-D" "CONFIG_USE_LIBGCC=1"
910 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
911 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
912 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
913 "/lib:{B}/lib:.\"")
914 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
915 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
916 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
917 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
918 "-o" "tcc"
919 "tcc.c"))))
920 (replace 'check
921 (lambda _
922 ;; FIXME: add sensible check target (without depending on make)
923 ;; ./check.sh ?
924 (= 1 (status:exit-val (system* "./tcc" "--help")))))
925 (replace 'install
926 (lambda* (#:key outputs #:allow-other-keys)
927 (let ((out (assoc-ref %outputs "out"))
928 (tcc (assoc-ref %build-inputs "tcc")))
929 (mkdir-p (string-append out "/bin"))
930 (copy-file "tcc" (string-append out "/bin/tcc"))
931 (mkdir-p (string-append out "/lib/tcc"))
932 (copy-recursively (string-append tcc "/include")
933 (string-append out "/include"))
934 (copy-recursively (string-append tcc "/lib")
935 (string-append out "/lib"))
936 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
937 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
938 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
939 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
940 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
941 #t))))))))
0b652851 942
0b652851 943(define diffutils-mesboot
9a45a24f
LC
944 (package
945 (inherit diffutils)
946 (name "diffutils-mesboot")
947 (version "2.7")
948 (source (origin
949 (method url-fetch)
950 (uri (string-append "mirror://gnu/diffutils/diffutils-"
951 version ".tar.gz"))
952 (sha256
953 (base32
954 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
955 (supported-systems '("i686-linux" "x86_64-linux"))
956 (inputs '())
957 (propagated-inputs '())
958 (native-inputs `(("mes" ,mes-boot)
959 ("tcc" ,tcc-boot)
0b652851 960
9a45a24f
LC
961 ("bash" ,%bootstrap-coreutils&co)
962 ("coreutils" ,%bootstrap-coreutils&co)
963 ("make" ,make-mesboot0)))
964 (arguments
965 `(#:implicit-inputs? #f
966 #:guile ,%bootstrap-guile
967 #:parallel-build? #f
968 #:tests? #f ; check is naive, also checks non-built PROGRAMS
969 #:strip-binaries? #f ; no strip yet
970 #:phases
971 (modify-phases %standard-phases
972 ;; diffutils-2.7 needs more traditional configure
973 (replace 'configure
974 (lambda* (#:key outputs #:allow-other-keys)
975 (let ((out (assoc-ref outputs "out"))
976 (bash (assoc-ref %build-inputs "bash")))
977 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
978 (setenv "CC" "tcc")
979 (setenv "LD" "tcc")
980 (invoke "./configure" (string-append "--prefix=" out)))))
981 (add-before 'configure 'remove-diff3-sdiff
982 (lambda* (#:key outputs #:allow-other-keys)
983 (substitute* "Makefile.in"
984 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
985 #t)))))))
0b652851
JN
986
987(define binutils-mesboot0
9a45a24f
LC
988 (package
989 (inherit binutils)
990 (name "binutils-mesboot0")
991 (version "2.20.1a")
992 (source (bootstrap-origin
993 (origin
0b652851
JN
994 (method url-fetch)
995 (uri (string-append "mirror://gnu/binutils/binutils-"
996 version ".tar.bz2"))
997 (patches (search-patches "binutils-boot-2.20.1a.patch"))
998 (sha256
999 (base32
9a45a24f
LC
1000 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
1001 (inputs '())
1002 (propagated-inputs '())
1003 (native-inputs `(("tcc" ,tcc-boot)
0b652851 1004
9a45a24f
LC
1005 ("bash" ,%bootstrap-coreutils&co)
1006 ("coreutils" ,%bootstrap-coreutils&co)
1007 ("diffutils" ,diffutils-mesboot)
1008 ("make" ,make-mesboot0)))
1009 (supported-systems '("i686-linux" "x86_64-linux"))
1010 (arguments
1011 `(#:implicit-inputs? #f
1012 #:guile ,%bootstrap-guile
1013 #:tests? #f ; runtest: command not found
1014 #:parallel-build? #f
1015 #:strip-binaries? #f ; no strip yet
1016 #:configure-flags
1017 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
1018 " -D MES_BOOTSTRAP=1"))
1019 (bash (assoc-ref %build-inputs "bash")))
1020 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
1021 ,(string-append "CPPFLAGS=" cppflags)
1022 "AR=tcc -ar"
1023 "CXX=false"
1024 "RANLIB=true"
1025 ,(string-append "CC=tcc" cppflags)
1026 "--disable-nls"
1027 "--disable-shared"
1028 "--disable-werror"
1029 "--build=i686-unknown-linux-gnu"
1030 "--host=i686-unknown-linux-gnu"
1031 "--with-sysroot=/"))))))
0b652851
JN
1032
1033(define gcc-core-mesboot
1034 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
1035 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
1036 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
1037 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
1038 ;; toolchain triplet "that works".
9a45a24f
LC
1039 (package
1040 (inherit gcc)
1041 (name "gcc-core-mesboot")
1042 (version "2.95.3")
1043 (source (bootstrap-origin
1044 (origin
0b652851
JN
1045 (method url-fetch)
1046 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
1047 version
1048 ".tar.gz"))
1049 (patches (search-patches "gcc-boot-2.95.3.patch"))
1050 (sha256
1051 (base32
9a45a24f
LC
1052 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
1053 (supported-systems '("i686-linux" "x86_64-linux"))
1054 (inputs '())
1055 (propagated-inputs '())
1056 (native-inputs `(("binutils" ,binutils-mesboot0)
1057 ("tcc" ,tcc-boot)
0b652851 1058
9a45a24f
LC
1059 ("bash" ,%bootstrap-coreutils&co)
1060 ("coreutils" ,%bootstrap-coreutils&co)
1061 ("diffutils" ,diffutils-mesboot)
1062 ("make" ,make-mesboot0)))
1063 (outputs '("out"))
1064 (arguments
1065 `(#:implicit-inputs? #f
1066 #:guile ,%bootstrap-guile
1067 #:tests? #f
1068 #:parallel-build? #f
1069 #:strip-binaries? #f
1070 #:configure-flags
1071 (let ((out (assoc-ref %outputs "out")))
1072 `("--enable-static"
1073 "--disable-shared"
1074 "--disable-werror"
1075 "--build=i686-unknown-linux-gnu"
1076 "--host=i686-unknown-linux-gnu"
1077 ,(string-append "--prefix=" out)))
1078 #:make-flags (list
1079 "CC=tcc -static -D __GLIBC_MINOR__=6"
1080 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
1081 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
1082 "AR=ar"
1083 "RANLIB=ranlib"
1084 (string-append "LIBGCC2_INCLUDES=-I "
1085 (assoc-ref %build-inputs "tcc")
1086 "/include")
1087 "LANGUAGES=c"
1088 (string-append "BOOT_LDFLAGS="
1089 " -B" (assoc-ref %build-inputs "tcc")
1090 "/lib/"))
1091 #:modules ((guix build gnu-build-system)
1092 (guix build utils)
1093 (srfi srfi-1))
1094 #:phases
1095 (modify-phases %standard-phases
1096 ;; gcc-2.95.3 needs more traditional configure
1097 (add-before 'configure 'setenv
1098 (lambda* (#:key outputs #:allow-other-keys)
1099 (let ((out (assoc-ref outputs "out"))
1100 (bash (assoc-ref %build-inputs "bash"))
1101 (tcc (assoc-ref %build-inputs "tcc"))
1102 (cppflags " -D __GLIBC_MINOR__=6"))
1103 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1104 (setenv "CPPFLAGS" cppflags)
1105 (setenv "CC" (string-append "tcc" cppflags))
1106 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
1107 (setenv "CPP" (string-append "tcc -E" cppflags))
1108 (with-output-to-file "config.cache"
1109 (lambda _
1110 (display "
0b652851 1111ac_cv_c_float_format='IEEE (little-endian)'
2b5e412b 1112")))
9a45a24f
LC
1113 #t)))
1114 (replace 'configure
1115 (lambda* (#:key configure-flags #:allow-other-keys)
1116 (format (current-error-port)
1117 "running ./configure ~a\n" (string-join configure-flags))
1118 (apply invoke "./configure" configure-flags)))
1119 (add-after 'configure 'remove-info
1120 (lambda _
1121 ;; no info at this stage
1122 (delete-file-recursively "texinfo")
1123 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
1124 (add-after 'install 'install2
1125 (lambda* (#:key outputs #:allow-other-keys)
1126 (let* ((tcc (assoc-ref %build-inputs "tcc"))
1127 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
1128 (out (assoc-ref outputs "out"))
1129 (gcc-dir (string-append
1130 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1131 (mkdir-p "tmp")
1132 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1133 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1134 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1135 (copy-file (string-append tcc "/lib/libtcc1.a")
1136 (string-append out "/lib/libtcc1.a"))
1137 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
1138 (string-append tcc-lib "/libc+gnu.o")
1139 (string-append tcc-lib "/libtcc1.o"))
1140 (invoke "ar" "r" (string-append out "/lib/libc.a")
1141 (string-append tcc-lib "/libc+gnu.o")
1142 (string-append tcc-lib "/libtcc1.o"))
1143 (invoke "ls" "-ltrF" gcc-dir)
9a45a24f
LC
1144 #t))))))
1145 (native-search-paths
9a45a24f
LC
1146 (list (search-path-specification
1147 (variable "C_INCLUDE_PATH")
558b0bbe
LC
1148 (files '("include"
1149
1150 ;; Needed to get things like GCC's <stddef.h>.
1151 "lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
9a45a24f
LC
1152 (search-path-specification
1153 (variable "LIBRARY_PATH")
1154 (files '("lib")))))))
0b652851
JN
1155
1156(define mesboot-headers
9a45a24f
LC
1157 (package
1158 (inherit mes-boot)
1159 (name "mesboot-headers")
1160 (supported-systems '("i686-linux" "x86_64-linux"))
1161 (inputs '())
1162 (propagated-inputs '())
1163 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
1164 ("headers" ,%bootstrap-linux-libre-headers)))
1165 (arguments
1166 `(#:implicit-inputs? #f
1167 #:guile ,%bootstrap-guile
1168 #:tests? #f
1169 #:strip-binaries? #f
1170 #:phases
1171 (modify-phases %standard-phases
1172 (delete 'configure)
1173 (delete 'build)
1174 (replace 'install
1175 (lambda* (#:key outputs #:allow-other-keys)
1176 (let* ((out (assoc-ref outputs "out"))
1177 (include (string-append out "/include"))
1178 (headers (assoc-ref %build-inputs "headers" )))
1179 (mkdir-p include)
1180 (copy-recursively "include" out)
1181 (copy-recursively headers out)
558b0bbe 1182 #t))))))))
0b652851
JN
1183
1184(define glibc-mesboot0
1185 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
1186 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
1187 ;; gcc.
9a45a24f
LC
1188 (package
1189 (inherit glibc)
1190 (name "glibc-mesboot0")
1191 (version "2.2.5")
1192 (source (bootstrap-origin
1193 (origin
0b652851
JN
1194 (method url-fetch)
1195 (uri (string-append "mirror://gnu/glibc/glibc-"
1196 version
1197 ".tar.gz"))
1198 (patches (search-patches "glibc-boot-2.2.5.patch"))
1199 (sha256
1200 (base32
9a45a24f
LC
1201 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
1202 (supported-systems '("i686-linux" "x86_64-linux"))
1203 (inputs '())
1204 (propagated-inputs '())
1205 (native-inputs `(("binutils" ,binutils-mesboot0)
1206 ("gcc" ,gcc-core-mesboot)
0b652851 1207
9a45a24f
LC
1208 ("bash" ,%bootstrap-coreutils&co)
1209 ("coreutils" ,%bootstrap-coreutils&co)
1210 ("diffutils" ,diffutils-mesboot)
1211 ("headers" ,mesboot-headers)
1212 ("make" ,make-mesboot0)))
1213 (outputs '("out"))
1214 (arguments
1215 `(#:implicit-inputs? #f
1216 #:guile ,%bootstrap-guile
1217 #:tests? #f
1218 #:strip-binaries? #f
1219 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
1220 #:make-flags (list (string-append
1221 "SHELL="
1222 (assoc-ref %build-inputs "bash")
1223 "/bin/sh"))
1224 #:configure-flags
1225 (let ((out (assoc-ref %outputs "out"))
1226 (headers (assoc-ref %build-inputs "headers")))
1227 (list
1228 "--disable-shared"
1229 "--enable-static"
1230 "--disable-sanity-checks"
1231 "--build=i686-unknown-linux-gnu"
1232 "--host=i686-unknown-linux-gnu"
1233 (string-append "--with-headers=" headers "/include")
1234 "--enable-static-nss"
1235 "--without-__thread"
1236 "--without-cvs"
1237 "--without-gd"
1238 "--without-tls"
1239 (string-append "--prefix=" out)))
1240 #:phases
1241 (modify-phases %standard-phases
1242 (add-before 'configure 'setenv
1243 (lambda* (#:key outputs #:allow-other-keys)
1244 (let* ((out (assoc-ref outputs "out"))
1245 (bash (assoc-ref %build-inputs "bash"))
1246 (gcc (assoc-ref %build-inputs "gcc"))
1247 (headers (assoc-ref %build-inputs "headers"))
1248 (cppflags (string-append
1249 ;;" -D __STDC__=1"
1250 " -D MES_BOOTSTRAP=1"
1251 " -D BOOTSTRAP_GLIBC=1"))
1252 (cflags (string-append " -L " (getcwd))))
1253 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1254 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1255 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1256 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1257 #t)))
1258 ;; glibc-2.2.5 needs a more classic invocation of configure
1259 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
1260 (replace 'configure
1261 (lambda* (#:key configure-flags #:allow-other-keys)
1262 (format (current-error-port)
1263 "running ./configure ~a\n" (string-join configure-flags))
558b0bbe 1264 (apply invoke "./configure" configure-flags))))))))
0b652851
JN
1265
1266(define gcc-mesboot0
9a45a24f
LC
1267 (package
1268 (inherit gcc-core-mesboot)
1269 (name "gcc-mesboot0")
1270 (native-inputs `(("binutils" ,binutils-mesboot0)
558b0bbe
LC
1271
1272 ;; Packages are given in an order that's relevant for
1273 ;; #include_next purposes.
9a45a24f 1274 ("libc" ,glibc-mesboot0)
558b0bbe
LC
1275 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1276 ("gcc" ,gcc-core-mesboot)
0b652851 1277
9a45a24f
LC
1278 ("bash" ,%bootstrap-coreutils&co)
1279 ("coreutils" ,%bootstrap-coreutils&co)
1280 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1281 ("make" ,make-mesboot0)))
1282 (arguments
1283 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1284 ((#:phases phases)
1285 `(modify-phases ,phases
1286 (replace 'setenv
558b0bbe
LC
1287 (lambda _
1288 (setenv "CONFIG_SHELL" (which "sh"))
1289 (with-output-to-file "config.cache"
1290 (lambda _
1291 (display "
0b652851
JN
1292ac_cv_c_float_format='IEEE (little-endian)'
1293")))
558b0bbe 1294 #t))
9a45a24f
LC
1295 (replace 'install2
1296 (lambda* (#:key outputs #:allow-other-keys)
1297 (let* ((out (assoc-ref outputs "out"))
1298 (gcc-dir (string-append
1299 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
1300 (mkdir-p "tmp")
1301 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
1302 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
1303 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
1304 #t)))))
1305 ((#:configure-flags configure-flags)
1306 `(let ((out (assoc-ref %outputs "out")))
1307 `("--disable-shared"
1308 "--disable-werror"
1309 "--build=i686-unknown-linux-gnu"
1310 "--host=i686-unknown-linux-gnu"
1311 ,(string-append "--prefix=" out))))
1312 ((#:make-flags make-flags)
1313 `(let ((gcc (assoc-ref %build-inputs "gcc")))
1314 `("RANLIB=true"
1315 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
1316 "LANGUAGES=c")))))))
0b652851
JN
1317
1318(define binutils-mesboot
9a45a24f
LC
1319 (package
1320 (inherit binutils-mesboot0)
1321 (name "binutils-mesboot")
1322 (native-inputs `(("binutils" ,binutils-mesboot0)
1323 ("libc" ,glibc-mesboot0)
1324 ("gcc" ,gcc-mesboot0)
0b652851 1325
9a45a24f
LC
1326 ("bash" ,%bootstrap-coreutils&co)
1327 ("coreutils" ,%bootstrap-coreutils&co)
1328 ("diffutils" ,diffutils-mesboot)
1329 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1330 ("make" ,make-mesboot0)))
1331 (arguments
1332 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
1333 ((#:configure-flags configure-flags)
1334 '(list "--disable-nls"
1335 "--disable-shared"
1336 "--disable-werror"
1337 "--build=i686-unknown-linux-gnu"
1338 "--host=i686-unknown-linux-gnu"
1339 "--with-sysroot=/"))))))
0b652851
JN
1340
1341(define make-mesboot
9a45a24f
LC
1342 (package
1343 (inherit make-mesboot0)
1344 (name "make-mesboot")
1345 (version "3.82")
1346 (source (origin
1347 (method url-fetch)
1348 (uri (string-append "mirror://gnu/make/make-"
1349 version ".tar.gz"))
1350 (sha256
1351 (base32
1352 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
1353 (native-inputs `(("binutils" ,binutils-mesboot0)
1354 ("libc" ,glibc-mesboot0)
1355 ("gcc" ,gcc-mesboot0)
1356 ("make" ,make-mesboot0)
0b652851 1357
9a45a24f
LC
1358 ("bash" ,%bootstrap-coreutils&co)
1359 ("coreutils" ,%bootstrap-coreutils&co)
1360 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
1361 (arguments
1362 (substitute-keyword-arguments (package-arguments make-mesboot0)
1363 ((#:configure-flags configure-flags)
1364 `(let ((out (assoc-ref %outputs "out")))
1365 `(,(string-append "--prefix=" out))))
1366 ((#:phases phases)
1367 `(modify-phases ,phases
1368 (delete 'configure-fixup)
1369 (add-before 'configure 'setenv
1370 (lambda _
1371 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
1372 #t))))))))
0b652851
JN
1373
1374(define gmp-boot
1375 (package
1376 (inherit gmp)
1377 (version "4.3.2")
1378 (source (origin
1379 (method url-fetch)
1380 (uri (string-append "mirror://gnu/gmp/gmp-" version
1381 ".tar.gz"))
1382 (sha256 (base32
1383 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
1384
1385(define mpfr-boot
1386 (package
1387 (inherit mpfr)
1388 (version "2.4.2")
1389 (source (origin
1390 (method url-fetch)
1391 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
1392 ".tar.gz"))
1393 (sha256 (base32
1394 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
1395
1396(define mpc-boot
1397 (package
1398 (inherit mpc)
1399 (version "1.0.3")
1400 (source (origin
1401 (method url-fetch)
1402 (uri (string-append
1403 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
1404 (sha256
1405 (base32
1406 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
1407
1408(define gcc-mesboot1
9a45a24f
LC
1409 (package
1410 (inherit gcc-mesboot0)
1411 (name "gcc-mesboot1")
a1caea07 1412 (version (package-version gcc-4.7))
9a45a24f
LC
1413 (source (bootstrap-origin
1414 (origin (inherit (package-source gcc-4.7))
1415 (patches (search-patches "gcc-boot-4.7.4.patch")))))
1416 (inputs `(("gmp-source" ,(package-source gmp-boot))
1417 ("mpfr-source" ,(package-source mpfr-boot))
1418 ("mpc-source" ,(package-source mpc-boot))))
1419 (native-inputs `(("binutils" ,binutils-mesboot)
558b0bbe 1420
9a45a24f 1421 ("libc" ,glibc-mesboot0)
558b0bbe
LC
1422 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1423 ("gcc" ,gcc-mesboot0)
0b652851 1424
9a45a24f
LC
1425 ("bash" ,%bootstrap-coreutils&co)
1426 ("coreutils" ,%bootstrap-coreutils&co)
1427 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1428 ("make" ,make-mesboot)))
1429 (arguments
1430 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
1431 ((#:make-flags make-flags)
1432 `(let* ((libc (assoc-ref %build-inputs "libc"))
1433 (ldflags (string-append
1434 "-B" libc "/lib "
1435 "-Wl,-dynamic-linker "
1436 "-Wl," libc
1437 ,(glibc-dynamic-linker "i686-linux"))))
1438 (list (string-append "LDFLAGS=" ldflags)
1439 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
1440 ((#:phases phases)
1441 `(modify-phases ,phases
1442 ;; c&p from commencement.scm:gcc-boot0
1443 (add-after 'unpack 'unpack-gmp&co
1444 (lambda* (#:key inputs #:allow-other-keys)
1445 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1446 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1447 (mpc (assoc-ref %build-inputs "mpc-source")))
0b652851 1448
9a45a24f
LC
1449 ;; To reduce the set of pre-built bootstrap inputs, build
1450 ;; GMP & co. from GCC.
1451 (for-each (lambda (source)
1452 (or (invoke "tar" "xvf" source)
1453 (error "failed to unpack tarball"
1454 source)))
1455 (list gmp mpfr mpc))
0b652851 1456
9a45a24f
LC
1457 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1458 ,@(map (lambda (lib)
1459 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1460 ;; into gmp-6.0.0.
1461 `(symlink ,(string-trim-right
1462 (package-full-name lib "-")
1463 char-set:letter)
1464 ,(package-name lib)))
1465 (list gmp-boot mpfr-boot mpc-boot))
1466 #t)))
1467 (delete 'remove-info)
1468 (replace 'setenv
558b0bbe
LC
1469 (lambda _
1470 (setenv "CONFIG_SHELL" (which "sh"))
1471
1472 ;; Allow MPFR headers to be found.
1473 (setenv "C_INCLUDE_PATH"
1474 (string-append (getcwd) "/mpfr/src:"
1475 (getenv "C_INCLUDE_PATH")))
1476
1477 ;; Set the C++ search path so that C headers can be found as
1478 ;; libstdc++ is being compiled.
1479 (setenv "CPLUS_INCLUDE_PATH" (getenv "C_INCLUDE_PATH"))
1480 #t))
9a45a24f
LC
1481 (delete 'install2)))
1482 ((#:configure-flags configure-flags)
1483 `(let ((out (assoc-ref %outputs "out"))
1484 (glibc (assoc-ref %build-inputs "libc")))
1485 (list (string-append "--prefix=" out)
1486 "--build=i686-unknown-linux-gnu"
1487 "--host=i686-unknown-linux-gnu"
0b652851 1488
9a45a24f
LC
1489 (string-append "--with-native-system-header-dir=" glibc "/include")
1490 (string-append "--with-build-sysroot=" glibc "/include")
0b652851 1491
9a45a24f
LC
1492 "--disable-bootstrap"
1493 "--disable-decimal-float"
1494 "--disable-libatomic"
1495 "--disable-libcilkrts"
1496 "--disable-libgomp"
1497 "--disable-libitm"
1498 "--disable-libmudflap"
1499 "--disable-libquadmath"
1500 "--disable-libsanitizer"
1501 "--disable-libssp"
1502 "--disable-libvtv"
1503 "--disable-lto"
1504 "--disable-lto-plugin"
1505 "--disable-multilib"
1506 "--disable-plugin"
1507 "--disable-threads"
1508 "--enable-languages=c,c++"
0b652851 1509
9a45a24f
LC
1510 "--enable-static"
1511 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1512 "--disable-shared"
1513 "--enable-threads=single"
0b652851 1514
9a45a24f
LC
1515 ;; No pre-compiled libstdc++ headers, to save space.
1516 "--disable-libstdcxx-pch"
0b652851 1517
9a45a24f
LC
1518 ;; for libcpp ...
1519 "--disable-build-with-cxx")))))))
0b652851
JN
1520
1521(define gcc-mesboot1-wrapper
1522 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1523 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1524 ;; --enable-shared will fail.
9a45a24f
LC
1525 (package
1526 (inherit gcc-mesboot1)
1527 (name "gcc-mesboot1-wrapper")
1528 (source #f)
1529 (inputs '())
1530 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1531 ("libc" ,glibc-mesboot)
1532 ("gcc" ,gcc-mesboot1)))
1533 (arguments
1534 `(#:implicit-inputs? #f
1535 #:guile ,%bootstrap-guile
1536 #:phases
1537 (modify-phases %standard-phases
1538 (delete 'unpack)
1539 (delete 'configure)
1540 (delete 'install)
1541 (replace 'build
1542 (lambda* (#:key outputs #:allow-other-keys)
1543 (let* ((out (assoc-ref outputs "out"))
1544 (bash (assoc-ref %build-inputs "bash"))
1545 (libc (assoc-ref %build-inputs "libc"))
1546 (gcc (assoc-ref %build-inputs "gcc"))
1547 (bin (string-append out "/bin")))
1548 (mkdir-p bin)
1549 (for-each
1550 (lambda (program)
1551 (let ((wrapper (string-append bin "/" program)))
1552 (with-output-to-file wrapper
1553 (lambda _
1554 (display (string-append "#! " bash "/bin/bash
0b652851
JN
1555exec " gcc "/bin/" program
1556" -Wl,--dynamic-linker"
eb443459
JN
1557;; also for x86_64-linux, we are still on i686-linux
1558" -Wl," libc ,(glibc-dynamic-linker "i686-linux")
0b652851
JN
1559" -Wl,--rpath"
1560" -Wl," libc "/lib"
1561" \"$@\"
1562"))
9a45a24f
LC
1563 (chmod wrapper #o555)))))
1564 '(
1565 "gcc"
1566 "g++"
1567 "i686-unknown-linux-gnu-gcc"
1568 "i686-unknown-linux-gnu-g++"
1569 ))
1570 #t)))
1571 (replace 'check
1572 (lambda* (#:key outputs #:allow-other-keys)
1573 (let* ((out (assoc-ref outputs "out"))
1574 (bin (string-append out "/bin"))
1575 (program (string-append bin "/gcc")))
1576 (invoke program "--help")))))))))
0b652851
JN
1577
1578(define glibc-headers-mesboot
9a45a24f
LC
1579 (package
1580 (inherit glibc-mesboot0)
1581 (name "glibc-headers-mesboot")
1582 (version "2.16.0")
1583 (source (bootstrap-origin
1584 (origin
0b652851
JN
1585 (method url-fetch)
1586 (uri (string-append "mirror://gnu/glibc/glibc-"
1587 version
1588 ".tar.gz"))
1589 (patches (search-patches "glibc-boot-2.16.0.patch"
1590 "glibc-bootstrap-system-2.16.0.patch"))
1591 (sha256
1592 (base32
9a45a24f
LC
1593 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1594 (native-inputs `(("binutils" ,binutils-mesboot)
1595 ("libc" ,glibc-mesboot0)
1596 ("gcc" ,gcc-mesboot1)
1597 ("headers" ,mesboot-headers)
0b652851 1598
9a45a24f
LC
1599 ("bash" ,%bootstrap-coreutils&co)
1600 ("coreutils" ,%bootstrap-coreutils&co)
1601 ("diffutils" ,diffutils-mesboot)
1602 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1603 ("make" ,make-mesboot)))
0b652851 1604
9a45a24f
LC
1605 (arguments
1606 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1607 ((#:configure-flags configure-flags)
1608 `(let ((out (assoc-ref %outputs "out"))
1609 (headers (assoc-ref %build-inputs "headers")))
1610 (list
1611 (string-append "--prefix=" out)
1612 "--disable-obsolete-rpc"
1613 "--host=i686-unknown-linux-gnu"
1614 (string-append "--with-headers=" headers "/include")
1615 "--enable-static-nss"
1616 "--with-pthread"
1617 "--without-cvs"
1618 "--without-gd"
1619 "--enable-add-ons=nptl")))
1620 ((#:make-flags make-flags)
1621 `(let ((bash (assoc-ref %build-inputs "bash")))
1622 (list (string-append "SHELL=" bash "/bin/sh")
1623 "install-bootstrap-headers=yes" "install-headers")))
1624 ((#:phases phases)
1625 `(modify-phases ,phases
1626 (replace 'setenv
558b0bbe
LC
1627 (lambda* (#:key inputs #:allow-other-keys)
1628 (let* ((headers (assoc-ref inputs "headers"))
1629 (libc (assoc-ref inputs "libc"))
1630 (gcc (assoc-ref inputs "gcc"))
9a45a24f
LC
1631 (cppflags (string-append
1632 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1633 " -D BOOTSTRAP_GLIBC=1"))
1634 (cflags (string-append " -L " (getcwd)
1635 " -L " libc "/lib")))
1636 (setenv "libc_cv_friendly_stddef" "yes")
558b0bbe
LC
1637 (setenv "CONFIG_SHELL" (which "sh"))
1638 (setenv "SHELL" (which "sh"))
0b652851 1639
9a45a24f
LC
1640 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1641 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
0b652851 1642
9a45a24f
LC
1643 ;; avoid -fstack-protector
1644 (setenv "libc_cv_ssp" "false")
1645 (substitute* "configure"
558b0bbe 1646 (("/bin/pwd") "pwd"))
9a45a24f
LC
1647 #t)))
1648 (replace 'install
1649 (lambda* (#:key outputs make-flags #:allow-other-keys)
1650 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1651 (out (assoc-ref outputs "out")))
1652 (apply invoke "make" make-flags)
1653 (copy-recursively kernel-headers out)
1654 #t)))
1655 (replace 'configure
1656 (lambda* (#:key configure-flags #:allow-other-keys)
1657 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1658 (mkdir-p "build")
1659 (chdir "build")
1660 (apply invoke "../configure" configure-flags)))
1661 (add-after 'configure 'remove-sunrpc
1662 (lambda _
1663 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1664 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1665 (substitute* "sysd-sorted"
1666 ((" sunrpc") " ")
1667 ((" nis") " "))
1668 ;; 'rpcgen' needs native libc headers to be built.
1669 (substitute* "../Makefile"
1670 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1671 (substitute* "../Makeconfig"
1672 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1673 (substitute* "../elf/Makefile"
1674 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
0b652851
JN
1675
1676(define glibc-mesboot
9a45a24f
LC
1677 (package
1678 (inherit glibc-headers-mesboot)
1679 (name "glibc-mesboot")
1680 (native-inputs `(("binutils" ,binutils-mesboot)
1681 ("libc" ,glibc-mesboot0)
1682 ("headers" ,glibc-headers-mesboot)
1683 ("gcc" ,gcc-mesboot1)
0b652851 1684
9a45a24f
LC
1685 ("bash" ,%bootstrap-coreutils&co)
1686 ("coreutils" ,%bootstrap-coreutils&co)
1687 ("diffutils" ,diffutils-mesboot)
1688 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1689 ("make" ,make-mesboot)))
0b652851 1690
9a45a24f
LC
1691 (arguments
1692 `(#:validate-runpath? #f ; fails when using --enable-shared
1693 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1694 ((#:make-flags make-flags)
1695 `(let ((bash (assoc-ref %build-inputs "bash")))
1696 (list (string-append "SHELL=" bash "/bin/sh"))))
1697 ((#:phases phases)
1698 `(modify-phases ,phases
1699 (replace 'install
1700 (lambda* (#:key outputs make-flags #:allow-other-keys)
1701 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1702 (out (assoc-ref outputs "out"))
1703 (install-flags (cons "install" make-flags)))
1704 (apply invoke "make" install-flags)
1705 (copy-recursively kernel-headers out)
558b0bbe 1706 #t))))))))))
0b652851
JN
1707
1708(define gcc-mesboot
9a45a24f
LC
1709 (package
1710 (inherit gcc-mesboot1)
1711 (name "gcc-mesboot")
a1caea07 1712 (version (package-version gcc-4.9))
9a45a24f
LC
1713 (source (bootstrap-origin (package-source gcc-4.9)))
1714 (native-inputs `(("binutils" ,binutils-mesboot)
558b0bbe
LC
1715
1716 ("libc" ,glibc-mesboot)
1717 ("kernel-headers" ,%bootstrap-linux-libre-headers)
9a45a24f
LC
1718 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1719 ("gcc" ,gcc-mesboot1)
0b652851 1720
9a45a24f
LC
1721 ("bash" ,%bootstrap-coreutils&co)
1722 ("coreutils" ,%bootstrap-coreutils&co)
1723 ("diffutils" ,diffutils-mesboot)
9a45a24f
LC
1724 ("make" ,make-mesboot)))
1725 (arguments
1726 `(#:validate-runpath? #f
1727 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1728 ((#:configure-flags configure-flags)
1729 `(let ((out (assoc-ref %outputs "out"))
1730 (glibc (assoc-ref %build-inputs "libc")))
1731 (list (string-append "--prefix=" out)
1732 "--build=i686-unknown-linux-gnu"
1733 "--host=i686-unknown-linux-gnu"
0b652851 1734
9a45a24f 1735 "--with-host-libstdcxx=-lsupc++"
0b652851 1736
9a45a24f
LC
1737 (string-append "--with-native-system-header-dir=" glibc "/include")
1738 (string-append "--with-build-sysroot=" glibc "/include")
0b652851 1739
9a45a24f
LC
1740 "--disable-bootstrap"
1741 "--disable-decimal-float"
1742 "--disable-libatomic"
1743 "--disable-libcilkrts"
1744 "--disable-libgomp"
1745 "--disable-libitm"
1746 "--disable-libmudflap"
1747 "--disable-libquadmath"
1748 "--disable-libsanitizer"
1749 "--disable-libssp"
1750 "--disable-libvtv"
1751 "--disable-lto"
1752 "--disable-lto-plugin"
1753 "--disable-multilib"
1754 "--disable-plugin"
1755 "--disable-threads"
1756 "--enable-languages=c,c++"
0b652851 1757
9a45a24f
LC
1758 "--enable-static"
1759 "--enable-shared"
1760 "--enable-threads=single"
0b652851 1761
9a45a24f
LC
1762 ;; No pre-compiled libstdc++ headers, to save space.
1763 "--disable-libstdcxx-pch"
0b652851 1764
9a45a24f 1765 ;; for libcpp ...
558b0bbe 1766 "--disable-build-with-cxx"))))))))
0b652851
JN
1767
1768(define gcc-mesboot-wrapper
1769 ;; We need this so gcc-mesboot can be used to create shared binaries that
1770 ;; have the correct interpreter and runpath to libc.
9a45a24f
LC
1771 (package
1772 (inherit gcc-mesboot1-wrapper)
1773 (name "gcc-mesboot-wrapper")
1774 (version (package-version gcc-mesboot))
1775 (source #f)
1776 (inputs '())
1777 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1778 ("libc" ,glibc-mesboot)
1779 ("gcc" ,gcc-mesboot)))))
0b652851
JN
1780
1781(define m4-mesboot
9a45a24f
LC
1782 (package
1783 (inherit m4)
1784 (name "m4-mesboot")
1785 (version "1.4")
1786 (source (origin
1787 (method url-fetch)
1788 (uri (string-append "mirror://gnu/m4/m4-"
1789 version ".tar.gz"))
1790 (sha256
1791 (base32
1792 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1793 (supported-systems '("i686-linux" "x86_64-linux"))
1794 (native-inputs `(("mes" ,mes-boot)
1795 ("tcc" ,tcc-boot)))
1796 (arguments
1797 `(#:phases
1798 (modify-phases %standard-phases
1799 (replace 'configure
1800 (lambda* (#:key outputs #:allow-other-keys)
1801 (let ((out (assoc-ref outputs "out")))
1802 (setenv "CONFIG_SHELL" (string-append
1803 (assoc-ref %build-inputs "bash")
1804 "/bin/sh"))
1805 (setenv "CC" "tcc -static")
1806 (setenv "CPP" "tcc -E")
1807 (invoke "./configure" (string-append "--prefix=" out))))))))))
0b652851 1808
c3629044 1809(define (%bootstrap-inputs+toolchain)
0b652851
JN
1810 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1811 ;; the actual reduced set with bootstrapped toolchain.
1380be3c
LC
1812 (match (%current-system)
1813 ((or "i686-linux" "x86_64-linux")
1814 `(("libc" ,glibc-mesboot)
1815 ("binutils" ,binutils-mesboot)
1816 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1817 ("gcc" ,gcc-mesboot)
1818 ,@(fold alist-delete (%bootstrap-inputs)
1819 '("bootstrap-mescc-tools" "mes"))))
1820 (_
1821 (%bootstrap-inputs))))
c3629044 1822
bdb36958 1823(define gnu-make-boot0
9a45a24f
LC
1824 (package
1825 (inherit gnu-make)
1826 (source (bootstrap-origin (package-source gnu-make)))
1827 (name "make-boot0")
1828 (arguments
1829 `(#:guile ,%bootstrap-guile
1830 #:implicit-inputs? #f
1831 #:tests? #f ; cannot run "make check"
1832 ,@(substitute-keyword-arguments (package-arguments gnu-make)
cdba9148
MB
1833 ((#:configure-flags flags ''())
1834 ;; The generated config.status has some problems due to the
1835 ;; bootstrap environment. Disable dependency tracking to work
1836 ;; around it.
1837 `(cons "--disable-dependency-tracking" ,flags))
9a45a24f
LC
1838 ((#:phases phases)
1839 `(modify-phases ,phases
1840 (replace 'build
1841 (lambda _
1842 (invoke "./build.sh")))
1843 (replace 'install
1844 (lambda* (#:key outputs #:allow-other-keys)
1845 (let* ((out (assoc-ref outputs "out"))
1846 (bin (string-append out "/bin")))
1847 (install-file "make" bin)
1848 #t))))))))
1849 (native-inputs '()) ; no need for 'pkg-config'
1850 (inputs (%bootstrap-inputs+toolchain))))
bdb36958
LC
1851
1852(define diffutils-boot0
99b73d0f
LC
1853 (package
1854 (inherit diffutils)
1855 (name "diffutils-boot0")
1856 (native-inputs `())
1857 (inputs
1858 `(("make" ,gnu-make-boot0)
1859 ,@(%bootstrap-inputs+toolchain)))
1860 (arguments
1861 `(#:tests? #f ; the test suite needs diffutils
1862 #:guile ,%bootstrap-guile
1863 #:implicit-inputs? #f
1864 ,@(package-arguments diffutils)))))
bdb36958
LC
1865
1866(define findutils-boot0
99b73d0f
LC
1867 (package
1868 (inherit findutils)
1869 (name "findutils-boot0")
1870 (source (bootstrap-origin (package-source findutils)))
1871 (inputs
1872 `(("make" ,gnu-make-boot0)
1873 ("diffutils" ,diffutils-boot0) ; for tests
1874 ,@(%bootstrap-inputs+toolchain)))
1875 (arguments
1876 `(#:implicit-inputs? #f
1877 #:guile ,%bootstrap-guile
717867a6
MB
1878
1879 ;; The build system assumes we have done a mistake when time_t is 32-bit
1880 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1881 ,@(if (target-64bit?)
1882 (substitute-keyword-arguments (package-arguments findutils)
1883 ((#:configure-flags flags ''())
1884 `(cons "TIME_T_32_BIT_OK=yes"
1885 ,flags)))
1886 (package-arguments findutils))))))
bdb36958 1887
c00a9fbf 1888(define file-boot0
99b73d0f
LC
1889 (package
1890 (inherit file)
1891 (source (bootstrap-origin (package-source file)))
1892 (name "file-boot0")
1893 (inputs
1894 `(("make" ,gnu-make-boot0)
1895 ,@(%bootstrap-inputs+toolchain)))
1896 (arguments
1897 `(#:implicit-inputs? #f
1898 #:guile ,%bootstrap-guile
1899 #:strip-binaries? #f
1900 #:validate-runpath? #f))))
c00a9fbf 1901
a2b2070b 1902(define (%boot0-inputs)
bdb36958
LC
1903 `(("make" ,gnu-make-boot0)
1904 ("diffutils" ,diffutils-boot0)
1905 ("findutils" ,findutils-boot0)
c00a9fbf 1906 ("file" ,file-boot0)
c3629044 1907 ,@(%bootstrap-inputs+toolchain)))
bdb36958 1908
bdb36958
LC
1909(define* (boot-triplet #:optional (system (%current-system)))
1910 ;; Return the triplet used to create the cross toolchain needed in the
1911 ;; first bootstrapping stage.
1912 (nix-system->gnu-triplet system "guix"))
1913
1914;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1915;; toolchain actually targets the same OS and arch, but it has the advantage
c3629044
JN
1916;; of being independent of the libc and tools in
1917;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1918;; reference to the target libc.
bdb36958
LC
1919
1920(define binutils-boot0
99b73d0f
LC
1921 (package
1922 (inherit binutils)
1923 (source (bootstrap-origin (package-source binutils)))
1924 (name "binutils-cross-boot0")
1925 (arguments
1926 `(#:guile ,%bootstrap-guile
1927 #:implicit-inputs? #f
1928
1929 #:modules ((guix build gnu-build-system)
1930 (guix build utils)
1931 (ice-9 ftw)) ; for 'scandir'
1932 #:phases (modify-phases %standard-phases
1933 (add-after 'install 'add-symlinks
1934 (lambda* (#:key outputs #:allow-other-keys)
1935 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1936 ;; triplet prefix, so add symlinks.
1937 (let ((out (assoc-ref outputs "out"))
1938 (triplet-prefix (string-append ,(boot-triplet) "-")))
1939 (define (has-triplet-prefix? name)
1940 (string-prefix? triplet-prefix name))
1941 (define (remove-triplet-prefix name)
1942 (substring name (string-length triplet-prefix)))
1943 (with-directory-excursion (string-append out "/bin")
1944 (for-each (lambda (name)
1945 (symlink name (remove-triplet-prefix name)))
1946 (scandir "." has-triplet-prefix?)))
1947 #t))))
1948
1949 ,@(substitute-keyword-arguments (package-arguments binutils)
1950 ((#:configure-flags cf)
1951 `(cons ,(string-append "--target=" (boot-triplet))
1952 ,cf)))))
1953 (inputs (%boot0-inputs))))
bdb36958 1954
b810a850
LC
1955(define libstdc++-boot0
1956 ;; GCC's libcc1 is always built as a shared library (the top-level
1957 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1958 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
809b0a90 1959 ;; C++14 features missing in some of our bootstrap compilers.
99b73d0f 1960 (let ((lib (make-libstdc++ gcc-4.9)))
b810a850
LC
1961 (package
1962 (inherit lib)
99b73d0f 1963 (source (bootstrap-origin (package-source lib)))
b810a850
LC
1964 (name "libstdc++-boot0")
1965 (arguments
1966 `(#:guile ,%bootstrap-guile
1967 #:implicit-inputs? #f
1968
1969 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1970 #:validate-runpath? #f
1971
d536c39e 1972 ,@(match (%current-system)
eb443459 1973 ((or "i686-linux" "x86_64-linux")
d536c39e
JN
1974 (substitute-keyword-arguments (package-arguments lib)
1975 ((#:phases phases)
1976 `(modify-phases ,phases
a6facf94
MB
1977 (add-after 'unpack 'workaround-wrapper-bug
1978 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1979 ;; fail, which in turn confuses the configure script.
1980 (lambda _
1981 (substitute* "libstdc++-v3/configure"
1982 (("g\\+\\+ -v") "true"))
1983 #t))))))
d536c39e 1984 (_ (package-arguments lib)))))
a2b2070b 1985 (inputs (%boot0-inputs))
b810a850
LC
1986 (native-inputs '()))))
1987
bdb36958 1988(define gcc-boot0
99b73d0f
LC
1989 (package
1990 (inherit gcc)
1991 (name "gcc-cross-boot0")
1992 (source (bootstrap-origin (package-source gcc)))
1993 (arguments
1994 `(#:guile ,%bootstrap-guile
1995 #:implicit-inputs? #f
1996 #:modules ((guix build gnu-build-system)
1997 (guix build utils)
1998 (ice-9 regex)
1999 (srfi srfi-1)
2000 (srfi srfi-26))
2001 ,@(substitute-keyword-arguments (package-arguments gcc)
2002 ((#:configure-flags flags)
2003 `(append (list ,(string-append "--target=" (boot-triplet))
2004
2005 ;; No libc yet.
2006 "--without-headers"
2007
2008 ;; Disable features not needed at this stage.
2009 "--disable-shared"
2010 "--enable-languages=c,c++"
2011
2012 ;; libstdc++ cannot be built at this stage
2013 ;; ("Link tests are not allowed after
2014 ;; GCC_NO_EXECUTABLES.").
2015 "--disable-libstdc++-v3"
2016
2017 "--disable-threads"
2018 "--disable-libmudflap"
2019 "--disable-libatomic"
2020 "--disable-libsanitizer"
2021 "--disable-libitm"
2022 "--disable-libgomp"
2023 "--disable-libmpx"
2024 "--disable-libcilkrts"
2025 "--disable-libvtv"
2026 "--disable-libssp"
2027 "--disable-libquadmath"
2028 "--disable-decimal-float")
2029 (remove (cut string-match
2030 "--(with-system-zlib|enable-languages.*)" <>)
2031 ,flags)))
2032 ((#:make-flags flags)
2033 `(let* ((libc (assoc-ref %build-inputs "libc"))
2034 (libc-native (or (assoc-ref %build-inputs "libc-native")
2035 libc)))
2036 `(,(string-append "LDFLAGS="
2037 "-Wl,-rpath=" libc-native "/lib "
2038 "-Wl,-dynamic-linker "
2039 "-Wl," libc-native ,(glibc-dynamic-linker
2040 (match (%current-system)
2041 ("x86_64-linux" "i686-linux")
2042 (_ (%current-system))))))))
2043 ((#:phases phases)
2044 `(modify-phases ,phases
2045 (add-after 'unpack 'unpack-gmp&co
2046 (lambda* (#:key inputs #:allow-other-keys)
2047 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2048 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2049 (mpc (assoc-ref %build-inputs "mpc-source")))
2050
2051 ;; To reduce the set of pre-built bootstrap inputs, build
2052 ;; GMP & co. from GCC.
2053 (for-each (lambda (source)
2054 (invoke "tar" "xvf" source))
2055 (list gmp mpfr mpc))
2056
2057 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2058 ,@(map (lambda (lib)
2059 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2060 ;; into gmp-6.0.0.
2061 `(symlink ,(string-trim-right
2062 (package-full-name lib "-")
2063 char-set:letter)
2064 ,(package-name lib)))
2065 (list gmp-6.0 mpfr mpc))
2066 #t)))
2067 ,(match (%current-system)
2068 ((or "i686-linux" "x86_64-linux")
2069 '(add-before 'configure 'fix-libcc1
77e02d94
MB
2070 (lambda* (#:key inputs #:allow-other-keys)
2071 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
2072 ;; to placate the 'validate-runpath' phase.
2073 (substitute* "libcc1/Makefile.in"
2074 (("la_LDFLAGS =")
2075 (string-append "la_LDFLAGS = -Wl,-rpath="
2076 (assoc-ref inputs "gcc") "/lib")))
2077 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
2078 (substitute* "libcc1/configure"
2079 (("g\\+\\+ -v") "true"))
2080 #t)))
99b73d0f
LC
2081 (_ '(add-before 'configure 'return-true
2082 (lambda _ #t))))
2083 (add-after 'install 'symlink-libgcc_eh
2084 (lambda* (#:key outputs #:allow-other-keys)
2085 (let ((out (assoc-ref outputs "lib")))
2086 ;; Glibc wants to link against libgcc_eh, so provide
2087 ;; it.
2088 (with-directory-excursion
2089 (string-append out "/lib/gcc/"
2090 ,(boot-triplet)
2091 "/" ,(package-version gcc))
2092 (symlink "libgcc.a" "libgcc_eh.a"))
2093 #t))))))))
bdb36958 2094
99b73d0f
LC
2095 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2096 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
2097 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
2098 ("binutils-cross" ,binutils-boot0)
bdb36958 2099
99b73d0f
LC
2100 ;; The libstdc++ that libcc1 links against.
2101 ("libstdc++" ,libstdc++-boot0)
b810a850 2102
99b73d0f
LC
2103 ;; Call it differently so that the builder can check whether
2104 ;; the "libc" input is #f.
2105 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
2106 ,@(alist-delete "libc" (%boot0-inputs))))
9dee9e8f 2107
99b73d0f
LC
2108 ;; No need for the native-inputs to build the documentation at this stage.
2109 (native-inputs `())))
bdb36958
LC
2110
2111(define perl-boot0
99b73d0f
LC
2112 (package
2113 (inherit perl)
2114 (name "perl-boot0")
2115 (source (bootstrap-origin (package-source perl)))
2116 (inputs (%boot0-inputs))
2117 (arguments
2118 `(#:implicit-inputs? #f
2119 #:guile ,%bootstrap-guile
2120 #:validate-runpath? #f
2121
2122 ;; At the very least, this must not depend on GCC & co.
2123 #:disallowed-references ,(list %bootstrap-binutils)
2124
2125 ,@(substitute-keyword-arguments (package-arguments perl)
2126 ((#:phases phases)
2127 `(modify-phases ,phases
2128 ;; Pthread support is missing in the bootstrap compiler
2129 ;; (broken spec file), so disable it.
2130 (add-before 'configure 'disable-pthreads
2131 (lambda _
2132 (substitute* "Configure"
2133 (("^libswanted=(.*)pthread" _ before)
2134 (string-append "libswanted=" before)))
2135 #t))))
2136 ;; Do not configure with '-Dusethreads' since pthread
2137 ;; support is missing.
2138 ((#:configure-flags configure-flags)
2139 `(delete "-Dusethreads" ,configure-flags)))))))
bdb36958 2140
32f4a073 2141(define m4-boot0
99b73d0f
LC
2142 (package
2143 (inherit m4)
2144 (name "m4-boot0")
2145 (source (bootstrap-origin (package-source m4)))
2146 (inputs (%boot0-inputs))
2147 (arguments
2148 `(#:guile ,%bootstrap-guile
2149 #:implicit-inputs? #f
2150 ,@(package-arguments m4)))))
2151
d75acc29
MR
2152(define bison-boot0
2153 ;; This Bison is needed to build MiG so we need it early in the process.
12908554 2154 ;; Recent versions of Linux-Libre headers also depend on this.
99b73d0f
LC
2155 (package
2156 (inherit bison)
e5c1f5cf 2157 (name "bison-boot0")
57bc2dcf 2158 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
2159 (native-inputs `(("perl" ,perl-boot0)))
2160 (inputs (%boot0-inputs)) ;remove Flex...
2161 (arguments
2162 `(#:tests? #f ;... and thus disable tests
2163 #:implicit-inputs? #f
2164 #:guile ,%bootstrap-guile
2165
99b73d0f
LC
2166 ;; Zero timestamps in liby.a; this must be done
2167 ;; explicitly here because the bootstrap Binutils don't
2168 ;; do that (default is "cru".)
2169 #:make-flags `("ARFLAGS=crD"
2170 ,,(match (%current-system)
2171 ;; ranlib: '-D': No such file
2172 ((or "i686-linux" "x86_64-linux")
2173 "RANLIB=ranlib")
2174 (_
2175 "RANLIB=ranlib -D"))
62548232
LC
2176 "V=1")
2177
2178 ,@(package-arguments bison)))))
d75acc29
MR
2179
2180(define flex-boot0
12908554 2181 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
99b73d0f
LC
2182 (package
2183 (inherit flex)
2184 (native-inputs `(("bison" ,bison-boot0)))
57bc2dcf 2185 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
2186 (inputs (%boot0-inputs))
2187 (arguments
2188 `(#:implicit-inputs? #f
2189 #:guile ,%bootstrap-guile
2190 #:tests? #f))))
d75acc29 2191
429243a4
MB
2192(define rsync-boot0
2193 (package
2194 (inherit rsync)
2195 (native-inputs `(("perl" ,perl-boot0)))
2196 (inputs (%boot0-inputs))
2197 (arguments
2198 `(#:implicit-inputs? #f
2199 #:guile ,%bootstrap-guile))))
2200
8102cf0b
LC
2201(define linux-libre-headers-boot0
2202 (mlambda ()
2203 "Return Linux-Libre header files for the bootstrap environment."
2204 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
2205 ;; between (gnu packages linux) and this module. Additionally, memoize
2206 ;; the result to play well with further memoization and code that relies
2207 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
99b73d0f
LC
2208 (package
2209 (inherit linux-libre-headers)
2210 (arguments
2211 `(#:guile ,%bootstrap-guile
2212 #:implicit-inputs? #f
2213 ,@(package-arguments linux-libre-headers)))
2214 (native-inputs
2215 `(("perl" ,perl-boot0)
2216
2217 ;; Flex and Bison are required since version 4.16.
2218 ("flex" ,flex-boot0)
2219 ("bison" ,bison-boot0)
429243a4
MB
2220
2221 ;; Rsync is required since version 5.3.
2222 ("rsync" ,rsync-boot0)
99b73d0f 2223 ,@(%boot0-inputs))))))
bdb36958 2224
efa8fdda
LC
2225(define with-boot0
2226 (package-with-explicit-inputs %boot0-inputs
2227 %bootstrap-guile))
2228
d75acc29 2229(define gnumach-headers-boot0
efa8fdda 2230 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
d75acc29
MR
2231
2232(define mig-boot0
efa8fdda
LC
2233 (let* ((mig (package
2234 (inherit (package-with-bootstrap-guile mig))
d75acc29
MR
2235 (native-inputs `(("bison" ,bison-boot0)
2236 ("flex" ,flex-boot0)))
2237 (inputs `(("flex" ,flex-boot0)))
2238 (arguments
2239 `(#:configure-flags
2240 `(,(string-append "LDFLAGS=-Wl,-rpath="
2241 (assoc-ref %build-inputs "flex") "/lib/")))))))
efa8fdda 2242 (with-boot0 mig)))
d75acc29
MR
2243
2244(define hurd-headers-boot0
2245 (let ((hurd-headers (package (inherit hurd-headers)
2246 (native-inputs `(("mig" ,mig-boot0)))
2247 (inputs '()))))
efa8fdda 2248 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
d75acc29
MR
2249
2250(define hurd-minimal-boot0
2251 (let ((hurd-minimal (package (inherit hurd-minimal)
2252 (native-inputs `(("mig" ,mig-boot0)))
2253 (inputs '()))))
efa8fdda 2254 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
d75acc29 2255
8102cf0b
LC
2256(define hurd-core-headers-boot0
2257 (mlambda ()
2258 "Return the Hurd and Mach headers as well as initial Hurd libraries for
d75acc29 2259the bootstrap environment."
efa8fdda
LC
2260 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
2261 (arguments `(#:guile ,%bootstrap-guile
2262 ,@(package-arguments hurd-core-headers)))
2263 (inputs
2264 `(("gnumach-headers" ,gnumach-headers-boot0)
2265 ("hurd-headers" ,hurd-headers-boot0)
2266 ("hurd-minimal" ,hurd-minimal-boot0)
2267 ,@(%boot0-inputs))))))
d75acc29
MR
2268
2269(define* (kernel-headers-boot0 #:optional (system (%current-system)))
2270 (match system
2271 ("i586-gnu" (hurd-core-headers-boot0))
2272 (_ (linux-libre-headers-boot0))))
2273
bdb36958
LC
2274(define texinfo-boot0
2275 ;; Texinfo used to build libc's manual.
2276 ;; We build without ncurses because it fails to build at this stage, and
2277 ;; because we don't need the stand-alone Info reader.
a2b2070b 2278 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
99b73d0f
LC
2279 (package
2280 (inherit texinfo)
2281 (native-inputs '())
2282 (inputs `(,@(%boot0-inputs)
2283 ("perl" ,perl-boot0)))
2284 (arguments
2285 `(#:implicit-inputs? #f
2286 #:guile ,%bootstrap-guile
2287
2288 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
2289 ;; character type in locale" but we don't have a UTF-8 locale at this
2290 ;; stage, so skip them.
2291 #:tests? #f))))
bdb36958 2292
5f3f7039
MB
2293(define expat-sans-tests
2294 (package
2295 (inherit expat)
99b73d0f 2296 (inputs (%boot0-inputs))
5f3f7039
MB
2297 (arguments
2298 ;; XXX: Linking 'runtestscpp' fails with things like:
2299 ;;
2300 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
2301 ;;
2302 ;; Skip tests altogether.
99b73d0f
LC
2303 `(#:implicit-inputs? #f
2304 #:guile ,%bootstrap-guile
2305
2306 ,@(substitute-keyword-arguments (package-arguments expat)
2307 ((#:configure-flags flags ''())
2308 ;; Since we're not passing the right -Wl,-rpath flags, build the
2309 ;; static library to avoid RUNPATH validation failure.
2310 `(cons "--disable-shared" ,flags))
2311 ((#:tests? _ #f) #f))))))
5f3f7039
MB
2312
2313(define python-boot0
99b73d0f
LC
2314 (package
2315 (inherit python-minimal)
2316 ;; We cannot use Python 3.7 and later here, because they require
2317 ;; pthreads, which is missing on non-x86 platforms at this stage.
2318 ;; Python 3.6 technically supports being built without threading
2319 ;; support, but requires additional patches.
73fec9ca 2320 (version "3.5.9")
99b73d0f
LC
2321 (source (bootstrap-origin
2322 (origin
404efac4 2323 (method url-fetch)
99b73d0f
LC
2324 (uri (string-append "https://www.python.org/ftp/python/"
2325 version "/Python-" version ".tar.xz"))
99b73d0f
LC
2326 (sha256
2327 (base32
73fec9ca 2328 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
404efac4
MB
2329 (modules '((guix build utils)))
2330 (snippet
2331 '(begin
2332 ;; Delete the bundled copy of libexpat.
2333 (delete-file-recursively "Modules/expat")
2334 (substitute* "Modules/Setup.dist"
2335 ;; Link Expat instead of embedding the bundled one.
2336 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
2337 #t)))))
99b73d0f
LC
2338 (inputs
2339 `(,@(%boot0-inputs)
2340 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
2341 (native-inputs '()) ;and pkg-config
2342 (arguments
2343 `(#:implicit-inputs? #f
2344 #:guile ,%bootstrap-guile
2345
2346 ,@(substitute-keyword-arguments (package-arguments python-minimal)
2347 ;; Disable features that cannot be built at this stage.
2348 ((#:configure-flags _ ''())
2349 `(list "--without-ensurepip"
2350 "--without-threads"))
2351 ;; Clear #:make-flags, such that changes to the regular
2352 ;; Python package won't interfere with this one.
2353 ((#:make-flags _ ''()) ''())
2354 ((#:phases phases)
2355 `(modify-phases ,phases
2356 (add-before 'configure 'disable-modules
2357 (lambda _
2358 (substitute* "setup.py"
2359 ;; Disable ctypes, since it requires libffi.
2360 (("extensions\\.append\\(ctypes\\)") "")
2361 ;; Prevent the 'ossaudiodev' extension from being
2362 ;; built, since it requires Linux headers.
2363 (("'linux', ") ""))
2364 #t))
2365 (delete 'set-TZDIR)))
2366 ((#:tests? _ #f) #f))))))
5f3f7039 2367
dab669e0
LC
2368(define ld-wrapper-boot0
2369 (mlambda ()
2370 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
2371 ;; in their RUNPATH, otherwise validate-runpath will fail.
2372 (make-ld-wrapper "ld-wrapper-boot0"
2373 #:target boot-triplet
2374 #:binutils binutils-boot0
2375 #:guile %bootstrap-guile
2376 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
2377 #:guile-for-build %bootstrap-guile)))
d75acc29 2378
a2b2070b 2379(define (%boot1-inputs)
bdb36958
LC
2380 ;; 2nd stage inputs.
2381 `(("gcc" ,gcc-boot0)
f50b013f 2382 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
bdb36958 2383 ("binutils-cross" ,binutils-boot0)
a2b2070b 2384 ,@(alist-delete "binutils" (%boot0-inputs))))
bdb36958
LC
2385
2386(define glibc-final-with-bootstrap-bash
2387 ;; The final libc, "cross-built". If everything went well, the resulting
2388 ;; store path has no dependencies. Actually, the really-final libc is
2389 ;; built just below; the only difference is that this one uses the
2390 ;; bootstrap Bash.
99b73d0f
LC
2391 (package
2392 (inherit glibc)
2393 (name "glibc-intermediate")
2394 (source (bootstrap-origin (package-source glibc)))
2395 (arguments
2396 `(#:guile ,%bootstrap-guile
2397 #:implicit-inputs? #f
2398
2399 ,@(substitute-keyword-arguments (package-arguments glibc)
2400 ((#:configure-flags flags)
2401 `(append (list ,(string-append "--host=" (boot-triplet))
2402 ,(string-append "--build="
2403 (nix-system->gnu-triplet)))
2404 ,flags))
2405 ((#:phases phases)
2406 `(modify-phases ,phases
2407 (add-before 'configure 'pre-configure
2408 (lambda* (#:key inputs #:allow-other-keys)
2409 ;; Don't clobber CPATH with the bootstrap libc.
2410 (setenv "NATIVE_CPATH" (getenv "CPATH"))
2411 (unsetenv "CPATH")
2412
2413 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
2414 ,@(if (hurd-triplet? (%current-system))
2415 `((substitute* "libpthread/Makefile"
2416 (("LDLIBS-pthread.so =.*")
2417 (string-append "LDLIBS-pthread.so = "
2418 (assoc-ref %build-inputs "kernel-headers")
2419 "/lib/libihash.a\n"))))
2420 '())
2421
2422 ;; 'rpcgen' needs native libc headers to be built.
2423 (substitute* "sunrpc/Makefile"
2424 (("sunrpc-CPPFLAGS =.*" all)
2425 (string-append "CPATH = $(NATIVE_CPATH)\n"
2426 "export CPATH\n"
2427 all "\n")))
2428 #t)))))))
2429 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
2430 (native-inputs
2431 `(("bison" ,bison-boot0)
2432 ("texinfo" ,texinfo-boot0)
2433 ("perl" ,perl-boot0)
2434 ("python" ,python-boot0)))
2435 (inputs
2436 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2437 ;; it in $CPATH, hence the 'pre-configure' phase above.
2438 ,@(%boot1-inputs)
2439
2440 ;; A native MiG is needed to build Glibc on Hurd.
2441 ,@(if (hurd-triplet? (%current-system))
2442 `(("mig" ,mig-boot0))
2443 '())
2444
2445 ;; A native GCC is needed to build `cross-rpcgen'.
2446 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2447
2448 ;; Here, we use the bootstrap Bash, which is not satisfactory
2449 ;; because we don't want to depend on bootstrap tools.
2450 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
bdb36958
LC
2451
2452(define (cross-gcc-wrapper gcc binutils glibc bash)
2453 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2454that makes it available under the native tool names."
c92f1c0a 2455 (package (inherit gcc)
bdb36958
LC
2456 (name (string-append (package-name gcc) "-wrapped"))
2457 (source #f)
2458 (build-system trivial-build-system)
2459 (outputs '("out"))
2460 (arguments
2461 `(#:guile ,%bootstrap-guile
2462 #:modules ((guix build utils))
2463 #:builder (begin
2464 (use-modules (guix build utils))
2465
2466 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2467 (gcc (assoc-ref %build-inputs "gcc"))
2468 (libc (assoc-ref %build-inputs "libc"))
2469 (bash (assoc-ref %build-inputs "bash"))
2470 (out (assoc-ref %outputs "out"))
2471 (bindir (string-append out "/bin"))
2472 (triplet ,(boot-triplet)))
2473 (define (wrap-program program)
2474 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2475 ;; needs to be told where to find the crt files and
2476 ;; the dynamic linker.
2477 (call-with-output-file program
2478 (lambda (p)
2479 (format p "#!~a/bin/bash
2480exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2481 bash
2482 gcc triplet program
2483 libc libc
2484 ,(glibc-dynamic-linker))))
2485
2486 (chmod program #o555))
2487
2488 (mkdir-p bindir)
2489 (with-directory-excursion bindir
2490 (for-each (lambda (tool)
2491 (symlink (string-append binutils "/bin/"
2492 triplet "-" tool)
2493 tool))
2494 '("ar" "ranlib"))
e3cfef22
MW
2495 (for-each wrap-program '("gcc" "g++")))
2496
2497 #t))))
bdb36958
LC
2498 (native-inputs
2499 `(("binutils" ,binutils)
2500 ("gcc" ,gcc)
2501 ("libc" ,glibc)
2502 ("bash" ,bash)))
2503 (inputs '())))
2504
32793c09
LC
2505(define gcc-boot0-intermediate-wrapped
2506 (mlambda ()
2507 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2508 ;; non-cross names.
2509 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2510 glibc-final-with-bootstrap-bash
2511 (car (assoc-ref (%boot1-inputs) "bash")))))
eb443459 2512
bdb36958 2513(define static-bash-for-glibc
90d891fc 2514 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
99b73d0f
LC
2515 (package
2516 (inherit static-bash)
2517 (source (bootstrap-origin (package-source static-bash)))
2518 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2519 ("libc" ,glibc-final-with-bootstrap-bash)
2520 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2521 ,@(fold alist-delete (%boot1-inputs)
2522 '("gcc" "libc"))))
2523 (arguments
2524 `(#:implicit-inputs? #f
2525 #:guile ,%bootstrap-guile
2526
2527 ,@(substitute-keyword-arguments (package-arguments static-bash)
2528 ((#:configure-flags flags '())
2529 ;; Add a '-L' flag so that the pseudo-cross-ld of
2530 ;; BINUTILS-BOOT0 can find libc.a.
2531 `(append ,flags
2532 (list (string-append "LDFLAGS=-static -L"
2533 (assoc-ref %build-inputs
2534 "libc:static")
2535 "/lib")))))))))
bdb36958 2536
6162b95d
LC
2537(define gettext-boot0
2538 ;; A minimal gettext used during bootstrap.
99b73d0f
LC
2539 (package
2540 (inherit gettext-minimal)
2541 (name "gettext-boot0")
2542 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2543 ;; simplify the dependency chain, we stick to this version here.
2544 (version "0.19.8.1")
2545 (source (origin
2546 (method url-fetch)
2547 (uri (string-append "mirror://gnu/gettext/gettext-"
2548 version ".tar.gz"))
2549 (sha256
2550 (base32
2551 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2552 (inputs (%boot1-inputs)) ;zero dependencies
2553 (arguments
2554 `(#:implicit-inputs? #f
2555 #:guile ,%bootstrap-guile
2556 #:tests? #f
2557 #:phases (modify-phases %standard-phases
2558 ;; Build only the tools.
2559 (add-after 'unpack 'chdir
2560 (lambda _
2561 (chdir "gettext-tools")
2562 #t))
2563
2564 ;; Some test programs require pthreads, which we don't have.
2565 (add-before 'configure 'no-test-programs
2566 (lambda _
2567 (substitute* "tests/Makefile.in"
2568 (("^PROGRAMS =.*$")
2569 "PROGRAMS =\n"))
2570 #t)))))))
6162b95d 2571
89223417 2572(define glibc-final
bdb36958 2573 ;; The final glibc, which embeds the statically-linked Bash built above.
7c788ed2 2574 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
99b73d0f
LC
2575 (package/inherit
2576 glibc
2577 (name "glibc")
2578 (source (bootstrap-origin (package-source glibc)))
2579 (inputs `(("static-bash" ,static-bash-for-glibc)
2580 ,@(alist-delete
2581 "static-bash"
2582 (package-inputs glibc-final-with-bootstrap-bash))))
2583
2584 ;; This time we need 'msgfmt' to install all the libc.mo files.
2585 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2586 ("gettext" ,gettext-boot0)))
2587
2588 (propagated-inputs
2589 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2590
2591 ;; The final libc only refers to itself, but the 'debug' output contains
2592 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2593 ;; if 'allowed-references' were per-output.
2594 (arguments
2595 `(#:allowed-references
2596 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2597 static-bash-for-glibc
2598 (package-outputs glibc-final-with-bootstrap-bash))
2599
2600 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
bdb36958 2601
32793c09
LC
2602(define gcc-boot0-wrapped
2603 (mlambda ()
2604 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2605 ;; non-cross names.
2606 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2607 (car (assoc-ref (%boot1-inputs) "bash")))))
bdb36958 2608
a2b2070b 2609(define (%boot2-inputs)
bdb36958
LC
2610 ;; 3rd stage inputs.
2611 `(("libc" ,glibc-final)
6dff905e 2612 ("libc:static" ,glibc-final "static")
f50b013f 2613 ("gcc" ,(gcc-boot0-wrapped))
4ae7dc7b 2614 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
bdb36958
LC
2615
2616(define binutils-final
99b73d0f
LC
2617 (package
2618 (inherit binutils)
2619 (source (bootstrap-origin (package-source binutils)))
2620 (arguments
2621 `(#:guile ,%bootstrap-guile
2622 #:implicit-inputs? #f
2623 #:allowed-references ("out" ,glibc-final)
2624 ,@(package-arguments binutils)))
2625 (inputs (%boot2-inputs))))
bdb36958
LC
2626
2627(define libstdc++
2628 ;; Intermediate libstdc++ that will allow us to build the final GCC
2629 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
99b73d0f 2630 (let ((lib (make-libstdc++ gcc)))
86d02fa8
EF
2631 (package
2632 (inherit lib)
99b73d0f 2633 (source (bootstrap-origin (package-source lib)))
86d02fa8
EF
2634 (arguments
2635 `(#:guile ,%bootstrap-guile
2636 #:implicit-inputs? #f
2637 #:allowed-references ("out")
2638
2639 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2640 #:validate-runpath? #f
2641
2642 ;; All of the package arguments from 'make-libstdc++
2643 ;; except for the configure-flags.
2644 ,@(package-arguments lib)
2645 #:configure-flags `("--disable-shared"
01e8263f 2646 "--disable-libstdcxx-dual-abi"
86d02fa8
EF
2647 "--disable-libstdcxx-threads"
2648 "--disable-libstdcxx-pch"
2649 ,(string-append "--with-gxx-include-dir="
2650 (assoc-ref %outputs "out")
2651 "/include"))))
2652 (outputs '("out"))
a2b2070b 2653 (inputs (%boot2-inputs))
86d02fa8 2654 (synopsis "GNU C++ standard library (intermediate)"))))
bdb36958 2655
98bd851e
LC
2656(define zlib-final
2657 ;; Zlib used by GCC-FINAL.
99b73d0f
LC
2658 (package
2659 (inherit zlib)
2660 (arguments
2661 `(#:guile ,%bootstrap-guile
2662 #:implicit-inputs? #f
2663 #:allowed-references ("out" ,glibc-final)
2664 ,@(package-arguments zlib)))
2665 (inputs (%boot2-inputs))))
98bd851e 2666
dab669e0
LC
2667(define ld-wrapper-boot3
2668 (mlambda ()
2669 ;; A linker wrapper that uses the bootstrap Guile.
2670 (make-ld-wrapper "ld-wrapper-boot3"
2671 #:binutils binutils-final
2672 #:guile %bootstrap-guile
2673 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2674 #:guile-for-build %bootstrap-guile)))
98bd851e 2675
89223417 2676(define gcc-final
bdb36958
LC
2677 ;; The final GCC.
2678 (package (inherit gcc-boot0)
2679 (name "gcc")
ab999c25
LC
2680
2681 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2682 ;; "debug" output contains disallowed references, notably
2683 ;; linux-libre-headers. Disable the debugging output to work around that.
2684 (outputs (delete "debug" (package-outputs gcc-boot0)))
2685
bdb36958
LC
2686 (arguments
2687 `(#:guile ,%bootstrap-guile
2688 #:implicit-inputs? #f
2689
98bd851e 2690 #:allowed-references ("out" "lib" ,zlib-final
90d891fc 2691 ,glibc-final ,static-bash-for-glibc)
bdb36958 2692
d485ebba
LC
2693 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2694 ;; reason, but it is not in their RUNPATH. This is a false
2695 ;; positive, so turn it off.
2696 #:validate-runpath? #f
2697
eb443459 2698 ,@(substitute-keyword-arguments (package-arguments gcc)
bdb36958 2699 ((#:make-flags flags)
52cfd8cb 2700 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
98bd851e
LC
2701 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2702 (map (lambda (flag)
2703 (if (string-prefix? "LDFLAGS=" flag)
2704 (string-append flag " -L"
2705 (assoc-ref %build-inputs "libstdc++")
2706 "/lib -L" zlib "/lib -Wl,-rpath="
2707 zlib "/lib")
2708 flag))
2709 ,flags)))
eb443459
JN
2710 ;; Build again GMP & co. within GCC's build process, because it's hard
2711 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2712 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
bdb36958 2713 ((#:phases phases)
eb443459
JN
2714 `(modify-phases ,phases
2715 (add-after 'unpack 'unpack-gmp&co
2716 (lambda* (#:key inputs #:allow-other-keys)
2717 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2718 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2719 (mpc (assoc-ref %build-inputs "mpc-source")))
2720
2721 ;; To reduce the set of pre-built bootstrap inputs, build
2722 ;; GMP & co. from GCC.
2723 (for-each (lambda (source)
2724 (invoke "tar" "xvf" source))
2725 (list gmp mpfr mpc))
2726
2727 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2728 ,@(map (lambda (lib)
2729 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2730 ;; into gmp-6.0.0.
2731 `(symlink ,(string-trim-right
2732 (package-full-name lib "-")
2733 char-set:letter)
2734 ,(package-name lib)))
2735 (list gmp-6.0 mpfr mpc))
2736 #t))))))))
bdb36958 2737
90d891fc
LC
2738 ;; This time we want Texinfo, so we get the manual. Add
2739 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2740 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2741 ;; scripts?).
bdb36958 2742 (native-inputs `(("texinfo" ,texinfo-boot0)
19d27131 2743 ("perl" ,perl-boot0) ;for manpages
90d891fc 2744 ("static-bash" ,static-bash-for-glibc)
bdb36958
LC
2745 ,@(package-native-inputs gcc-boot0)))
2746
8309c389 2747 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
bdb36958
LC
2748 ("mpfr-source" ,(package-source mpfr))
2749 ("mpc-source" ,(package-source mpc))
f50b013f 2750 ("ld-wrapper" ,(ld-wrapper-boot3))
bdb36958
LC
2751 ("binutils" ,binutils-final)
2752 ("libstdc++" ,libstdc++)
98bd851e 2753 ("zlib" ,zlib-final)
a2b2070b 2754 ,@(%boot2-inputs)))))
bdb36958 2755
a2b2070b 2756(define (%boot3-inputs)
bdb36958
LC
2757 ;; 4th stage inputs.
2758 `(("gcc" ,gcc-final)
f50b013f 2759 ("ld-wrapper" ,(ld-wrapper-boot3))
a2b2070b 2760 ,@(alist-delete "gcc" (%boot2-inputs))))
bdb36958
LC
2761
2762(define bash-final
2763 ;; Link with `-static-libgcc' to make sure we don't retain a reference
704243e0
LC
2764 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2765 ;; on Readline and ncurses.
99b73d0f
LC
2766 (let ((bash (static-libgcc-package bash-minimal)))
2767 (package
2768 (inherit bash)
2769 (source (bootstrap-origin (package-source bash)))
2770 (inputs (%boot3-inputs))
2771 (arguments
2772 `(#:implicit-inputs? #f
2773 #:guile ,%bootstrap-guile
2774
2775 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2776
2777 ,@(package-arguments bash))))))
bdb36958 2778
a2b2070b 2779(define (%boot4-inputs)
bdb36958
LC
2780 ;; Now use the final Bash.
2781 `(("bash" ,bash-final)
a2b2070b 2782 ,@(alist-delete "bash" (%boot3-inputs))))
bdb36958 2783
8f417ed2
LC
2784(define with-boot4
2785 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2786
bdb36958 2787(define-public guile-final
386b71d1
LC
2788 ;; This package must be public because other modules refer to it. However,
2789 ;; mark it as hidden so that 'fold-packages' ignores it.
8f417ed2
LC
2790 (with-boot4 (hidden-package
2791 (package-with-bootstrap-guile guile-2.2/fixed))))
bdb36958 2792
89223417 2793(define glibc-utf8-locales-final
87c8b92f
LC
2794 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2795 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2796 ;; with the full range of Unicode codepoints (remember
2797 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2798 ;; function.)
2799 (package
2800 (inherit glibc-utf8-locales)
58a75996
MO
2801 (native-inputs
2802 `(("glibc" ,glibc-final)
8f417ed2 2803 ("gzip" ,(with-boot4 gzip))))))
87c8b92f 2804
28cbc587
LC
2805(define-public ld-wrapper
2806 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
78dea6f1
LC
2807 (make-ld-wrapper "ld-wrapper"
2808 #:binutils binutils-final
2809 #:guile guile-final
2810 #:bash bash-final))
28cbc587 2811
a2b2070b 2812(define (%boot5-inputs)
b6ac5451
LC
2813 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2814 ;; with an older libc, which cannot load the new locale format. See
28cbc587 2815 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
b6ac5451 2816 `(("locales" ,glibc-utf8-locales-final)
a2b2070b 2817 ,@(%boot4-inputs)))
87c8b92f 2818
8f417ed2
LC
2819(define with-boot5
2820 (package-with-explicit-inputs %boot5-inputs))
2821
bdb36958
LC
2822(define gnu-make-final
2823 ;; The final GNU Make, which uses the final Guile.
8f417ed2 2824 (let ((pkg-config (package
537b2dab 2825 (inherit %pkg-config) ;the native pkg-config
8f417ed2
LC
2826 (inputs `(("guile" ,guile-final)
2827 ,@(%boot5-inputs)))
2828 (arguments
2829 `(#:implicit-inputs? #f
2830 ,@(package-arguments pkg-config))))))
2831 (package
2832 (inherit (package-with-bootstrap-guile gnu-make))
2833 (inputs `(("guile" ,guile-final)
2834 ,@(%boot5-inputs)))
2835 (native-inputs `(("pkg-config" ,pkg-config)))
2836 (arguments
2837 `(#:implicit-inputs? #f
2838 ,@(package-arguments gnu-make))))))
2839
bdb36958 2840
bdb36958
LC
2841(define coreutils-final
2842 ;; The final Coreutils. Treat them specially because some packages, such as
2843 ;; Findutils, keep a reference to the Coreutils they were built with.
8f417ed2
LC
2844 (with-boot5 (package-with-bootstrap-guile coreutils)
2845 ;; Use the final Guile, linked against the
2846 ;; final libc with working iconv, so that
2847 ;; 'substitute*' works well when touching
2848 ;; test files in Gettext.
2849 ))
bdb36958
LC
2850
2851(define grep-final
2852 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2853 ;; built before gzip.
8f417ed2 2854 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
78ca500a
LC
2855 (package/inherit grep
2856 (inputs (alist-delete "pcre" (package-inputs grep)))
2857 (native-inputs `(("perl" ,perl-boot0))))))
bdb36958 2858
a2b2070b 2859(define (%boot6-inputs)
bdb36958
LC
2860 ;; Now use the final Coreutils.
2861 `(("coreutils" ,coreutils-final)
2862 ("grep" ,grep-final)
a2b2070b 2863 ,@(%boot5-inputs)))
b0fd2bd3 2864
8f417ed2
LC
2865(define with-boot6
2866 (package-with-explicit-inputs %boot6-inputs))
2867
301a4249
LC
2868(define sed-final
2869 ;; The final sed.
8f417ed2 2870 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
301a4249
LC
2871 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2872
bdb36958
LC
2873(define-public %final-inputs
2874 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2875 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2876 ;; used for origins that have patches, thereby avoiding circular
2877 ;; dependencies.
8f417ed2 2878 (let ((finalize (compose with-boot6
099dbc4f 2879 package-with-bootstrap-guile)))
bdb36958 2880 `(,@(map (match-lambda
099dbc4f
LC
2881 ((name package)
2882 (list name (finalize package))))
bdb36958 2883 `(("tar" ,tar)
87c8b92f 2884 ("gzip" ,gzip)
bdb36958
LC
2885 ("bzip2" ,bzip2)
2886 ("xz" ,xz)
c00a9fbf 2887 ("file" ,file)
bdb36958
LC
2888 ("diffutils" ,diffutils)
2889 ("patch" ,patch)
bdb36958
LC
2890 ("findutils" ,findutils)
2891 ("gawk" ,gawk)))
301a4249 2892 ("sed" ,sed-final)
bdb36958
LC
2893 ("grep" ,grep-final)
2894 ("coreutils" ,coreutils-final)
2895 ("make" ,gnu-make-final)
2896 ("bash" ,bash-final)
2897 ("ld-wrapper" ,ld-wrapper)
2898 ("binutils" ,binutils-final)
2899 ("gcc" ,gcc-final)
b0fd2bd3 2900 ("libc" ,glibc-final)
6dff905e 2901 ("libc:static" ,glibc-final "static")
b0fd2bd3 2902 ("locales" ,glibc-utf8-locales-final))))
bdb36958
LC
2903
2904(define-public canonical-package
2905 (let ((name->package (fold (lambda (input result)
2906 (match input
6dff905e 2907 ((_ package . outputs)
bdb36958
LC
2908 (vhash-cons (package-full-name package)
2909 package result))))
2910 vlist-null
2911 `(("guile" ,guile-final)
2912 ,@%final-inputs))))
2913 (lambda (package)
2914 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2915the implicit inputs of 'gnu-build-system', return that one, otherwise return
2916PACKAGE.
2917
34d624ce 2918The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
bdb36958
LC
2919COREUTILS-FINAL vs. COREUTILS, etc."
2920 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2921 ;; libunistring, GMP, etc.
2922 (match (vhash-assoc (package-full-name package) name->package)
2923 ((_ . canon)
2924 ;; In general we want CANON, except if we're cross-compiling: CANON
2925 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2926 ;; process, with dependencies on things that cannot be
2927 ;; cross-compiled.
2928 (if (%current-target-system)
2929 package
2930 canon))
2931 (_ package)))))
2932
2933\f
2934;;;
2935;;; GCC toolchain.
2936;;;
2937
6869b663
CD
2938;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2939;; instantiated like this:
2940;;
2941;; (define-public gcc-glibc-2.27-toolchain
2942;; (make-gcc-toolchain gcc glibc-2.27))
2943
2944(define* (make-gcc-toolchain gcc
2945 #:optional
2946 (libc #f))
2947 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2948 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2949 (libc (if libc libc glibc-final)))
2950 (package
2951 (name (string-append (package-name gcc) "-toolchain"))
2952 (version (package-version gcc))
2953 (source #f)
2954 (build-system trivial-build-system)
2955 (arguments
2956 '(#:modules ((guix build union))
2957 #:builder (begin
2958 (use-modules (ice-9 match)
2959 (srfi srfi-26)
2960 (guix build union))
2961
2962 (let ((out (assoc-ref %outputs "out")))
2963
2964 (match %build-inputs
2965 (((names . directories) ...)
2966 (union-build out directories)))
2967
2968 (union-build (assoc-ref %outputs "debug")
2969 (list (assoc-ref %build-inputs
2970 "libc-debug")))
2971 (union-build (assoc-ref %outputs "static")
2972 (list (assoc-ref %build-inputs
2973 "libc-static")))
2974 #t))))
2975
2976 (native-search-paths (package-native-search-paths gcc))
2977 (search-paths (package-search-paths gcc))
2978
2979 (license (package-license gcc))
2980 (synopsis "Complete GCC tool chain for C/C++ development")
2981 (description
2982 "This package provides a complete GCC tool chain for C/C++ development to
34e8f0af
JB
2983be installed in user profiles. This includes GCC, as well as libc (headers and
2984binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
6869b663
CD
2985 (home-page "https://gcc.gnu.org/")
2986 (outputs '("out" "debug" "static"))
2987
2988 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2989 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2990 ;; before Binutils' ld in the user's profile.
2991 (inputs `(("gcc" ,gcc)
2992 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2993 ("binutils" ,binutils-final)
2994 ("libc" ,libc)
2995 ("libc-debug" ,libc "debug")
2996 ("libc-static" ,libc "static"))))))
bdb36958 2997
01e8263f
MB
2998(define-public gcc-toolchain
2999 (make-gcc-toolchain gcc-final))
3000
bdb36958 3001(define-public gcc-toolchain-4.8
b887ede1 3002 (make-gcc-toolchain gcc-4.8))
bdb36958
LC
3003
3004(define-public gcc-toolchain-4.9
b887ede1
LC
3005 (make-gcc-toolchain gcc-4.9))
3006
629f4d2e 3007(define-public gcc-toolchain-5
01e8263f 3008 (make-gcc-toolchain gcc-5))
60e2d5fe 3009
e760ec41 3010(define-public gcc-toolchain-6
b887ede1 3011 (make-gcc-toolchain gcc-6))
e760ec41 3012
d7ecab74 3013(define-public gcc-toolchain-7
01e8263f 3014 gcc-toolchain)
d7ecab74 3015
5ae27f57
LC
3016(define-public gcc-toolchain-8
3017 (make-gcc-toolchain gcc-8))
3018
bdfc3276
CD
3019(define-public gcc-toolchain-9
3020 (make-gcc-toolchain gcc-9))
3021
4ac5d4fe
KH
3022;; Provide the Fortran toolchain package only for the version of gfortran that
3023;; is used by Guix internally to build Fortran libraries, because combining
3024;; code compiled with different versions can cause problems.
3025
3026(define-public gfortran-toolchain
3027 (package (inherit (make-gcc-toolchain gfortran))
3028 (synopsis "Complete GCC tool chain for Fortran development")
3029 (description "This package provides a complete GCC tool chain for
3030Fortran development to be installed in user profiles. This includes
3031gfortran, as well as libc (headers and binaries, plus debugging symbols
3032in the @code{debug} output), and binutils.")))
3033
3034
bdb36958 3035;;; commencement.scm ends here