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