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