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