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