gnu: commencement: file: Build file without bzip2.
[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
a2b2070b 2733(define (%boot0-inputs)
bdb36958
LC
2734 `(("make" ,gnu-make-boot0)
2735 ("diffutils" ,diffutils-boot0)
2736 ("findutils" ,findutils-boot0)
c00a9fbf 2737 ("file" ,file-boot0)
c3629044 2738 ,@(%bootstrap-inputs+toolchain)))
bdb36958 2739
bdb36958
LC
2740(define* (boot-triplet #:optional (system (%current-system)))
2741 ;; Return the triplet used to create the cross toolchain needed in the
2742 ;; first bootstrapping stage.
2743 (nix-system->gnu-triplet system "guix"))
2744
2745;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
2746;; toolchain actually targets the same OS and arch, but it has the advantage
c3629044
JN
2747;; of being independent of the libc and tools in
2748;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
2749;; reference to the target libc.
bdb36958
LC
2750
2751(define binutils-boot0
99b73d0f
LC
2752 (package
2753 (inherit binutils)
2754 (source (bootstrap-origin (package-source binutils)))
2755 (name "binutils-cross-boot0")
2756 (arguments
2757 `(#:guile ,%bootstrap-guile
2758 #:implicit-inputs? #f
2759
2760 #:modules ((guix build gnu-build-system)
2761 (guix build utils)
2762 (ice-9 ftw)) ; for 'scandir'
2763 #:phases (modify-phases %standard-phases
2764 (add-after 'install 'add-symlinks
2765 (lambda* (#:key outputs #:allow-other-keys)
2766 ;; The cross-gcc invokes 'as', 'ld', etc, without the
2767 ;; triplet prefix, so add symlinks.
2768 (let ((out (assoc-ref outputs "out"))
2769 (triplet-prefix (string-append ,(boot-triplet) "-")))
2770 (define (has-triplet-prefix? name)
2771 (string-prefix? triplet-prefix name))
2772 (define (remove-triplet-prefix name)
2773 (substring name (string-length triplet-prefix)))
2774 (with-directory-excursion (string-append out "/bin")
2775 (for-each (lambda (name)
2776 (symlink name (remove-triplet-prefix name)))
2777 (scandir "." has-triplet-prefix?)))
2778 #t))))
2779
2780 ,@(substitute-keyword-arguments (package-arguments binutils)
2781 ((#:configure-flags cf)
2782 `(cons ,(string-append "--target=" (boot-triplet))
2783 ,cf)))))
2784 (inputs (%boot0-inputs))))
bdb36958 2785
b810a850
LC
2786(define libstdc++-boot0
2787 ;; GCC's libcc1 is always built as a shared library (the top-level
2788 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
2789 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
809b0a90 2790 ;; C++14 features missing in some of our bootstrap compilers.
99b73d0f 2791 (let ((lib (make-libstdc++ gcc-4.9)))
b810a850
LC
2792 (package
2793 (inherit lib)
99b73d0f 2794 (source (bootstrap-origin (package-source lib)))
b810a850
LC
2795 (name "libstdc++-boot0")
2796 (arguments
2797 `(#:guile ,%bootstrap-guile
2798 #:implicit-inputs? #f
2799
2800 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2801 #:validate-runpath? #f
2802
d536c39e 2803 ,@(match (%current-system)
eb443459 2804 ((or "i686-linux" "x86_64-linux")
d536c39e
JN
2805 (substitute-keyword-arguments (package-arguments lib)
2806 ((#:phases phases)
2807 `(modify-phases ,phases
a6facf94
MB
2808 (add-after 'unpack 'workaround-wrapper-bug
2809 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
2810 ;; fail, which in turn confuses the configure script.
2811 (lambda _
2812 (substitute* "libstdc++-v3/configure"
2813 (("g\\+\\+ -v") "true"))
2814 #t))))))
d536c39e 2815 (_ (package-arguments lib)))))
a2b2070b 2816 (inputs (%boot0-inputs))
b810a850
LC
2817 (native-inputs '()))))
2818
bdb36958 2819(define gcc-boot0
99b73d0f
LC
2820 (package
2821 (inherit gcc)
2822 (name "gcc-cross-boot0")
2823 (source (bootstrap-origin (package-source gcc)))
2824 (arguments
2825 `(#:guile ,%bootstrap-guile
2826 #:implicit-inputs? #f
2827 #:modules ((guix build gnu-build-system)
2828 (guix build utils)
2829 (ice-9 regex)
2830 (srfi srfi-1)
2831 (srfi srfi-26))
2832 ,@(substitute-keyword-arguments (package-arguments gcc)
2833 ((#:configure-flags flags)
2834 `(append (list ,(string-append "--target=" (boot-triplet))
2835
2836 ;; No libc yet.
2837 "--without-headers"
2838
2839 ;; Disable features not needed at this stage.
2840 "--disable-shared"
2841 "--enable-languages=c,c++"
2842
2843 ;; libstdc++ cannot be built at this stage
2844 ;; ("Link tests are not allowed after
2845 ;; GCC_NO_EXECUTABLES.").
2846 "--disable-libstdc++-v3"
2847
2848 "--disable-threads"
2849 "--disable-libmudflap"
2850 "--disable-libatomic"
2851 "--disable-libsanitizer"
2852 "--disable-libitm"
2853 "--disable-libgomp"
2854 "--disable-libmpx"
2855 "--disable-libcilkrts"
2856 "--disable-libvtv"
2857 "--disable-libssp"
2858 "--disable-libquadmath"
2859 "--disable-decimal-float")
2860 (remove (cut string-match
2861 "--(with-system-zlib|enable-languages.*)" <>)
2862 ,flags)))
2863 ((#:make-flags flags)
2864 `(let* ((libc (assoc-ref %build-inputs "libc"))
2865 (libc-native (or (assoc-ref %build-inputs "libc-native")
2866 libc)))
2867 `(,(string-append "LDFLAGS="
2868 "-Wl,-rpath=" libc-native "/lib "
2869 "-Wl,-dynamic-linker "
2870 "-Wl," libc-native ,(glibc-dynamic-linker
2871 (match (%current-system)
2872 ("x86_64-linux" "i686-linux")
2873 (_ (%current-system))))))))
2874 ((#:phases phases)
2875 `(modify-phases ,phases
2876 (add-after 'unpack 'unpack-gmp&co
2877 (lambda* (#:key inputs #:allow-other-keys)
2878 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2879 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2880 (mpc (assoc-ref %build-inputs "mpc-source")))
2881
2882 ;; To reduce the set of pre-built bootstrap inputs, build
2883 ;; GMP & co. from GCC.
2884 (for-each (lambda (source)
2885 (invoke "tar" "xvf" source))
2886 (list gmp mpfr mpc))
2887
2888 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2889 ,@(map (lambda (lib)
2890 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2891 ;; into gmp-6.0.0.
2892 `(symlink ,(string-trim-right
2893 (package-full-name lib "-")
2894 char-set:letter)
2895 ,(package-name lib)))
2896 (list gmp-6.0 mpfr mpc))
2897 #t)))
2898 ,(match (%current-system)
2899 ((or "i686-linux" "x86_64-linux")
2900 '(add-before 'configure 'fix-libcc1
77e02d94
MB
2901 (lambda* (#:key inputs #:allow-other-keys)
2902 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
2903 ;; to placate the 'validate-runpath' phase.
2904 (substitute* "libcc1/Makefile.in"
2905 (("la_LDFLAGS =")
2906 (string-append "la_LDFLAGS = -Wl,-rpath="
2907 (assoc-ref inputs "gcc") "/lib")))
2908 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
2909 (substitute* "libcc1/configure"
2910 (("g\\+\\+ -v") "true"))
2911 #t)))
99b73d0f
LC
2912 (_ '(add-before 'configure 'return-true
2913 (lambda _ #t))))
2914 (add-after 'install 'symlink-libgcc_eh
2915 (lambda* (#:key outputs #:allow-other-keys)
2916 (let ((out (assoc-ref outputs "lib")))
2917 ;; Glibc wants to link against libgcc_eh, so provide
2918 ;; it.
2919 (with-directory-excursion
2920 (string-append out "/lib/gcc/"
2921 ,(boot-triplet)
2922 "/" ,(package-version gcc))
2923 (symlink "libgcc.a" "libgcc_eh.a"))
2924 #t))))))))
bdb36958 2925
99b73d0f
LC
2926 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2927 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
2928 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
2929 ("binutils-cross" ,binutils-boot0)
bdb36958 2930
99b73d0f
LC
2931 ;; The libstdc++ that libcc1 links against.
2932 ("libstdc++" ,libstdc++-boot0)
b810a850 2933
99b73d0f
LC
2934 ;; Call it differently so that the builder can check whether
2935 ;; the "libc" input is #f.
2936 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
2937 ,@(alist-delete "libc" (%boot0-inputs))))
9dee9e8f 2938
99b73d0f
LC
2939 ;; No need for the native-inputs to build the documentation at this stage.
2940 (native-inputs `())))
bdb36958
LC
2941
2942(define perl-boot0
99b73d0f
LC
2943 (package
2944 (inherit perl)
2945 (name "perl-boot0")
2946 (source (bootstrap-origin (package-source perl)))
2947 (inputs (%boot0-inputs))
2948 (arguments
2949 `(#:implicit-inputs? #f
2950 #:guile ,%bootstrap-guile
2951 #:validate-runpath? #f
2952
2953 ;; At the very least, this must not depend on GCC & co.
2954 #:disallowed-references ,(list %bootstrap-binutils)
2955
2956 ,@(substitute-keyword-arguments (package-arguments perl)
2957 ((#:phases phases)
2958 `(modify-phases ,phases
2959 ;; Pthread support is missing in the bootstrap compiler
2960 ;; (broken spec file), so disable it.
2961 (add-before 'configure 'disable-pthreads
2962 (lambda _
2963 (substitute* "Configure"
2964 (("^libswanted=(.*)pthread" _ before)
2965 (string-append "libswanted=" before)))
2966 #t))))
2967 ;; Do not configure with '-Dusethreads' since pthread
2968 ;; support is missing.
2969 ((#:configure-flags configure-flags)
2970 `(delete "-Dusethreads" ,configure-flags)))))))
bdb36958 2971
32f4a073 2972(define m4-boot0
99b73d0f
LC
2973 (package
2974 (inherit m4)
2975 (name "m4-boot0")
2976 (source (bootstrap-origin (package-source m4)))
2977 (inputs (%boot0-inputs))
2978 (arguments
2979 `(#:guile ,%bootstrap-guile
2980 #:implicit-inputs? #f
2981 ,@(package-arguments m4)))))
2982
d75acc29
MR
2983(define bison-boot0
2984 ;; This Bison is needed to build MiG so we need it early in the process.
12908554 2985 ;; Recent versions of Linux-Libre headers also depend on this.
99b73d0f
LC
2986 (package
2987 (inherit bison)
e5c1f5cf 2988 (name "bison-boot0")
57bc2dcf 2989 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
2990 (native-inputs `(("perl" ,perl-boot0)))
2991 (inputs (%boot0-inputs)) ;remove Flex...
2992 (arguments
2993 `(#:tests? #f ;... and thus disable tests
2994 #:implicit-inputs? #f
2995 #:guile ,%bootstrap-guile
2996
99b73d0f
LC
2997 ;; Zero timestamps in liby.a; this must be done
2998 ;; explicitly here because the bootstrap Binutils don't
2999 ;; do that (default is "cru".)
3000 #:make-flags `("ARFLAGS=crD"
3001 ,,(match (%current-system)
3002 ;; ranlib: '-D': No such file
3003 ((or "i686-linux" "x86_64-linux")
3004 "RANLIB=ranlib")
3005 (_
3006 "RANLIB=ranlib -D"))
62548232
LC
3007 "V=1")
3008
3009 ,@(package-arguments bison)))))
d75acc29
MR
3010
3011(define flex-boot0
12908554 3012 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
99b73d0f
LC
3013 (package
3014 (inherit flex)
3015 (native-inputs `(("bison" ,bison-boot0)))
57bc2dcf 3016 (propagated-inputs `(("m4" ,m4-boot0)))
99b73d0f
LC
3017 (inputs (%boot0-inputs))
3018 (arguments
3019 `(#:implicit-inputs? #f
3020 #:guile ,%bootstrap-guile
3021 #:tests? #f))))
d75acc29 3022
429243a4
MB
3023(define rsync-boot0
3024 (package
3025 (inherit rsync)
3026 (native-inputs `(("perl" ,perl-boot0)))
3027 (inputs (%boot0-inputs))
3028 (arguments
3029 `(#:implicit-inputs? #f
3030 #:guile ,%bootstrap-guile))))
3031
8102cf0b
LC
3032(define linux-libre-headers-boot0
3033 (mlambda ()
3034 "Return Linux-Libre header files for the bootstrap environment."
3035 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
3036 ;; between (gnu packages linux) and this module. Additionally, memoize
3037 ;; the result to play well with further memoization and code that relies
3038 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
99b73d0f
LC
3039 (package
3040 (inherit linux-libre-headers)
3041 (arguments
3042 `(#:guile ,%bootstrap-guile
3043 #:implicit-inputs? #f
3044 ,@(package-arguments linux-libre-headers)))
3045 (native-inputs
3046 `(("perl" ,perl-boot0)
3047
3048 ;; Flex and Bison are required since version 4.16.
3049 ("flex" ,flex-boot0)
3050 ("bison" ,bison-boot0)
429243a4
MB
3051
3052 ;; Rsync is required since version 5.3.
3053 ("rsync" ,rsync-boot0)
99b73d0f 3054 ,@(%boot0-inputs))))))
bdb36958 3055
efa8fdda
LC
3056(define with-boot0
3057 (package-with-explicit-inputs %boot0-inputs
3058 %bootstrap-guile))
3059
d75acc29 3060(define gnumach-headers-boot0
efa8fdda 3061 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
d75acc29
MR
3062
3063(define mig-boot0
efa8fdda
LC
3064 (let* ((mig (package
3065 (inherit (package-with-bootstrap-guile mig))
d75acc29
MR
3066 (native-inputs `(("bison" ,bison-boot0)
3067 ("flex" ,flex-boot0)))
3068 (inputs `(("flex" ,flex-boot0)))
3069 (arguments
3070 `(#:configure-flags
3071 `(,(string-append "LDFLAGS=-Wl,-rpath="
3072 (assoc-ref %build-inputs "flex") "/lib/")))))))
efa8fdda 3073 (with-boot0 mig)))
d75acc29
MR
3074
3075(define hurd-headers-boot0
3076 (let ((hurd-headers (package (inherit hurd-headers)
3077 (native-inputs `(("mig" ,mig-boot0)))
3078 (inputs '()))))
efa8fdda 3079 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
d75acc29
MR
3080
3081(define hurd-minimal-boot0
3082 (let ((hurd-minimal (package (inherit hurd-minimal)
3083 (native-inputs `(("mig" ,mig-boot0)))
3084 (inputs '()))))
efa8fdda 3085 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
d75acc29 3086
8102cf0b
LC
3087(define hurd-core-headers-boot0
3088 (mlambda ()
3089 "Return the Hurd and Mach headers as well as initial Hurd libraries for
d75acc29 3090the bootstrap environment."
efa8fdda
LC
3091 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
3092 (arguments `(#:guile ,%bootstrap-guile
3093 ,@(package-arguments hurd-core-headers)))
3094 (inputs
3095 `(("gnumach-headers" ,gnumach-headers-boot0)
3096 ("hurd-headers" ,hurd-headers-boot0)
3097 ("hurd-minimal" ,hurd-minimal-boot0)
3098 ,@(%boot0-inputs))))))
d75acc29
MR
3099
3100(define* (kernel-headers-boot0 #:optional (system (%current-system)))
3101 (match system
3102 ("i586-gnu" (hurd-core-headers-boot0))
3103 (_ (linux-libre-headers-boot0))))
3104
bdb36958
LC
3105(define texinfo-boot0
3106 ;; Texinfo used to build libc's manual.
3107 ;; We build without ncurses because it fails to build at this stage, and
3108 ;; because we don't need the stand-alone Info reader.
a2b2070b 3109 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
99b73d0f
LC
3110 (package
3111 (inherit texinfo)
3112 (native-inputs '())
3113 (inputs `(,@(%boot0-inputs)
3114 ("perl" ,perl-boot0)))
3115 (arguments
3116 `(#:implicit-inputs? #f
3117 #:guile ,%bootstrap-guile
3118
3119 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
3120 ;; character type in locale" but we don't have a UTF-8 locale at this
3121 ;; stage, so skip them.
3122 #:tests? #f))))
bdb36958 3123
5f3f7039
MB
3124(define expat-sans-tests
3125 (package
3126 (inherit expat)
99b73d0f 3127 (inputs (%boot0-inputs))
5f3f7039
MB
3128 (arguments
3129 ;; XXX: Linking 'runtestscpp' fails with things like:
3130 ;;
3131 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
3132 ;;
3133 ;; Skip tests altogether.
99b73d0f
LC
3134 `(#:implicit-inputs? #f
3135 #:guile ,%bootstrap-guile
3136
3137 ,@(substitute-keyword-arguments (package-arguments expat)
3138 ((#:configure-flags flags ''())
3139 ;; Since we're not passing the right -Wl,-rpath flags, build the
3140 ;; static library to avoid RUNPATH validation failure.
3141 `(cons "--disable-shared" ,flags))
3142 ((#:tests? _ #f) #f))))))
5f3f7039
MB
3143
3144(define python-boot0
99b73d0f
LC
3145 (package
3146 (inherit python-minimal)
3147 ;; We cannot use Python 3.7 and later here, because they require
3148 ;; pthreads, which is missing on non-x86 platforms at this stage.
3149 ;; Python 3.6 technically supports being built without threading
3150 ;; support, but requires additional patches.
73fec9ca 3151 (version "3.5.9")
99b73d0f
LC
3152 (source (bootstrap-origin
3153 (origin
404efac4 3154 (method url-fetch)
99b73d0f
LC
3155 (uri (string-append "https://www.python.org/ftp/python/"
3156 version "/Python-" version ".tar.xz"))
99b73d0f
LC
3157 (sha256
3158 (base32
73fec9ca 3159 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
404efac4
MB
3160 (modules '((guix build utils)))
3161 (snippet
3162 '(begin
3163 ;; Delete the bundled copy of libexpat.
3164 (delete-file-recursively "Modules/expat")
3165 (substitute* "Modules/Setup.dist"
3166 ;; Link Expat instead of embedding the bundled one.
3167 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
3168 #t)))))
99b73d0f
LC
3169 (inputs
3170 `(,@(%boot0-inputs)
3171 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
3172 (native-inputs '()) ;and pkg-config
3173 (arguments
3174 `(#:implicit-inputs? #f
3175 #:guile ,%bootstrap-guile
3176
3177 ,@(substitute-keyword-arguments (package-arguments python-minimal)
3178 ;; Disable features that cannot be built at this stage.
3179 ((#:configure-flags _ ''())
3180 `(list "--without-ensurepip"
3181 "--without-threads"))
3182 ;; Clear #:make-flags, such that changes to the regular
3183 ;; Python package won't interfere with this one.
3184 ((#:make-flags _ ''()) ''())
3185 ((#:phases phases)
3186 `(modify-phases ,phases
3187 (add-before 'configure 'disable-modules
3188 (lambda _
3189 (substitute* "setup.py"
3190 ;; Disable ctypes, since it requires libffi.
3191 (("extensions\\.append\\(ctypes\\)") "")
3192 ;; Prevent the 'ossaudiodev' extension from being
3193 ;; built, since it requires Linux headers.
3194 (("'linux', ") ""))
3195 #t))
3196 (delete 'set-TZDIR)))
3197 ((#:tests? _ #f) #f))))))
5f3f7039 3198
dab669e0
LC
3199(define ld-wrapper-boot0
3200 (mlambda ()
3201 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
3202 ;; in their RUNPATH, otherwise validate-runpath will fail.
3203 (make-ld-wrapper "ld-wrapper-boot0"
3204 #:target boot-triplet
3205 #:binutils binutils-boot0
3206 #:guile %bootstrap-guile
3207 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
3208 #:guile-for-build %bootstrap-guile)))
d75acc29 3209
a2b2070b 3210(define (%boot1-inputs)
bdb36958
LC
3211 ;; 2nd stage inputs.
3212 `(("gcc" ,gcc-boot0)
f50b013f 3213 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
bdb36958 3214 ("binutils-cross" ,binutils-boot0)
a2b2070b 3215 ,@(alist-delete "binutils" (%boot0-inputs))))
bdb36958
LC
3216
3217(define glibc-final-with-bootstrap-bash
3218 ;; The final libc, "cross-built". If everything went well, the resulting
3219 ;; store path has no dependencies. Actually, the really-final libc is
3220 ;; built just below; the only difference is that this one uses the
3221 ;; bootstrap Bash.
99b73d0f
LC
3222 (package
3223 (inherit glibc)
3224 (name "glibc-intermediate")
3225 (source (bootstrap-origin (package-source glibc)))
3226 (arguments
3227 `(#:guile ,%bootstrap-guile
3228 #:implicit-inputs? #f
3229
3230 ,@(substitute-keyword-arguments (package-arguments glibc)
3231 ((#:configure-flags flags)
3232 `(append (list ,(string-append "--host=" (boot-triplet))
3233 ,(string-append "--build="
3234 (nix-system->gnu-triplet)))
3235 ,flags))
3236 ((#:phases phases)
3237 `(modify-phases ,phases
3238 (add-before 'configure 'pre-configure
3239 (lambda* (#:key inputs #:allow-other-keys)
3240 ;; Don't clobber CPATH with the bootstrap libc.
3241 (setenv "NATIVE_CPATH" (getenv "CPATH"))
3242 (unsetenv "CPATH")
3243
3244 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
3245 ,@(if (hurd-triplet? (%current-system))
3246 `((substitute* "libpthread/Makefile"
3247 (("LDLIBS-pthread.so =.*")
3248 (string-append "LDLIBS-pthread.so = "
3249 (assoc-ref %build-inputs "kernel-headers")
3250 "/lib/libihash.a\n"))))
3251 '())
3252
3253 ;; 'rpcgen' needs native libc headers to be built.
3254 (substitute* "sunrpc/Makefile"
3255 (("sunrpc-CPPFLAGS =.*" all)
3256 (string-append "CPATH = $(NATIVE_CPATH)\n"
3257 "export CPATH\n"
3258 all "\n")))
3259 #t)))))))
3260 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
3261 (native-inputs
3262 `(("bison" ,bison-boot0)
3263 ("texinfo" ,texinfo-boot0)
3264 ("perl" ,perl-boot0)
3265 ("python" ,python-boot0)))
3266 (inputs
3267 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
3268 ;; it in $CPATH, hence the 'pre-configure' phase above.
3269 ,@(%boot1-inputs)
3270
3271 ;; A native MiG is needed to build Glibc on Hurd.
3272 ,@(if (hurd-triplet? (%current-system))
3273 `(("mig" ,mig-boot0))
3274 '())
3275
3276 ;; A native GCC is needed to build `cross-rpcgen'.
3277 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
3278
3279 ;; Here, we use the bootstrap Bash, which is not satisfactory
3280 ;; because we don't want to depend on bootstrap tools.
3281 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
bdb36958
LC
3282
3283(define (cross-gcc-wrapper gcc binutils glibc bash)
3284 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
3285that makes it available under the native tool names."
c92f1c0a 3286 (package (inherit gcc)
bdb36958
LC
3287 (name (string-append (package-name gcc) "-wrapped"))
3288 (source #f)
3289 (build-system trivial-build-system)
3290 (outputs '("out"))
3291 (arguments
3292 `(#:guile ,%bootstrap-guile
3293 #:modules ((guix build utils))
3294 #:builder (begin
3295 (use-modules (guix build utils))
3296
3297 (let* ((binutils (assoc-ref %build-inputs "binutils"))
3298 (gcc (assoc-ref %build-inputs "gcc"))
3299 (libc (assoc-ref %build-inputs "libc"))
3300 (bash (assoc-ref %build-inputs "bash"))
3301 (out (assoc-ref %outputs "out"))
3302 (bindir (string-append out "/bin"))
3303 (triplet ,(boot-triplet)))
3304 (define (wrap-program program)
3305 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
3306 ;; needs to be told where to find the crt files and
3307 ;; the dynamic linker.
3308 (call-with-output-file program
3309 (lambda (p)
3310 (format p "#!~a/bin/bash
3311exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
3312 bash
3313 gcc triplet program
3314 libc libc
3315 ,(glibc-dynamic-linker))))
3316
3317 (chmod program #o555))
3318
3319 (mkdir-p bindir)
3320 (with-directory-excursion bindir
3321 (for-each (lambda (tool)
3322 (symlink (string-append binutils "/bin/"
3323 triplet "-" tool)
3324 tool))
3325 '("ar" "ranlib"))
e3cfef22
MW
3326 (for-each wrap-program '("gcc" "g++")))
3327
3328 #t))))
bdb36958
LC
3329 (native-inputs
3330 `(("binutils" ,binutils)
3331 ("gcc" ,gcc)
3332 ("libc" ,glibc)
3333 ("bash" ,bash)))
3334 (inputs '())))
3335
32793c09
LC
3336(define gcc-boot0-intermediate-wrapped
3337 (mlambda ()
3338 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
3339 ;; non-cross names.
3340 (cross-gcc-wrapper gcc-boot0 binutils-boot0
3341 glibc-final-with-bootstrap-bash
3342 (car (assoc-ref (%boot1-inputs) "bash")))))
eb443459 3343
bdb36958 3344(define static-bash-for-glibc
90d891fc 3345 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
99b73d0f
LC
3346 (package
3347 (inherit static-bash)
3348 (source (bootstrap-origin (package-source static-bash)))
3349 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
3350 ("libc" ,glibc-final-with-bootstrap-bash)
3351 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
3352 ,@(fold alist-delete (%boot1-inputs)
3353 '("gcc" "libc"))))
3354 (arguments
3355 `(#:implicit-inputs? #f
3356 #:guile ,%bootstrap-guile
3357
3358 ,@(substitute-keyword-arguments (package-arguments static-bash)
3359 ((#:configure-flags flags '())
3360 ;; Add a '-L' flag so that the pseudo-cross-ld of
3361 ;; BINUTILS-BOOT0 can find libc.a.
3362 `(append ,flags
3363 (list (string-append "LDFLAGS=-static -L"
3364 (assoc-ref %build-inputs
3365 "libc:static")
3366 "/lib")))))))))
bdb36958 3367
6162b95d
LC
3368(define gettext-boot0
3369 ;; A minimal gettext used during bootstrap.
99b73d0f
LC
3370 (package
3371 (inherit gettext-minimal)
3372 (name "gettext-boot0")
3373 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
3374 ;; simplify the dependency chain, we stick to this version here.
3375 (version "0.19.8.1")
3376 (source (origin
3377 (method url-fetch)
3378 (uri (string-append "mirror://gnu/gettext/gettext-"
3379 version ".tar.gz"))
3380 (sha256
3381 (base32
3382 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
3383 (inputs (%boot1-inputs)) ;zero dependencies
3384 (arguments
3385 `(#:implicit-inputs? #f
3386 #:guile ,%bootstrap-guile
3387 #:tests? #f
3388 #:phases (modify-phases %standard-phases
3389 ;; Build only the tools.
3390 (add-after 'unpack 'chdir
3391 (lambda _
3392 (chdir "gettext-tools")
3393 #t))
3394
3395 ;; Some test programs require pthreads, which we don't have.
3396 (add-before 'configure 'no-test-programs
3397 (lambda _
3398 (substitute* "tests/Makefile.in"
3399 (("^PROGRAMS =.*$")
3400 "PROGRAMS =\n"))
3401 #t)))))))
6162b95d 3402
89223417 3403(define glibc-final
bdb36958 3404 ;; The final glibc, which embeds the statically-linked Bash built above.
7c788ed2 3405 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
99b73d0f
LC
3406 (package/inherit
3407 glibc
3408 (name "glibc")
3409 (source (bootstrap-origin (package-source glibc)))
3410 (inputs `(("static-bash" ,static-bash-for-glibc)
3411 ,@(alist-delete
3412 "static-bash"
3413 (package-inputs glibc-final-with-bootstrap-bash))))
3414
3415 ;; This time we need 'msgfmt' to install all the libc.mo files.
3416 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
3417 ("gettext" ,gettext-boot0)))
3418
3419 (propagated-inputs
3420 (package-propagated-inputs glibc-final-with-bootstrap-bash))
3421
3422 ;; The final libc only refers to itself, but the 'debug' output contains
3423 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
3424 ;; if 'allowed-references' were per-output.
3425 (arguments
3426 `(#:allowed-references
3427 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
3428 static-bash-for-glibc
3429 (package-outputs glibc-final-with-bootstrap-bash))
3430
3431 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
bdb36958 3432
32793c09
LC
3433(define gcc-boot0-wrapped
3434 (mlambda ()
3435 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
3436 ;; non-cross names.
3437 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
3438 (car (assoc-ref (%boot1-inputs) "bash")))))
bdb36958 3439
a2b2070b 3440(define (%boot2-inputs)
bdb36958
LC
3441 ;; 3rd stage inputs.
3442 `(("libc" ,glibc-final)
6dff905e 3443 ("libc:static" ,glibc-final "static")
f50b013f 3444 ("gcc" ,(gcc-boot0-wrapped))
4ae7dc7b 3445 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
bdb36958
LC
3446
3447(define binutils-final
99b73d0f
LC
3448 (package
3449 (inherit binutils)
3450 (source (bootstrap-origin (package-source binutils)))
3451 (arguments
3452 `(#:guile ,%bootstrap-guile
3453 #:implicit-inputs? #f
3454 #:allowed-references ("out" ,glibc-final)
3455 ,@(package-arguments binutils)))
3456 (inputs (%boot2-inputs))))
bdb36958
LC
3457
3458(define libstdc++
3459 ;; Intermediate libstdc++ that will allow us to build the final GCC
3460 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
99b73d0f 3461 (let ((lib (make-libstdc++ gcc)))
86d02fa8
EF
3462 (package
3463 (inherit lib)
99b73d0f 3464 (source (bootstrap-origin (package-source lib)))
86d02fa8
EF
3465 (arguments
3466 `(#:guile ,%bootstrap-guile
3467 #:implicit-inputs? #f
3468 #:allowed-references ("out")
3469
3470 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
3471 #:validate-runpath? #f
3472
3473 ;; All of the package arguments from 'make-libstdc++
3474 ;; except for the configure-flags.
3475 ,@(package-arguments lib)
3476 #:configure-flags `("--disable-shared"
01e8263f 3477 "--disable-libstdcxx-dual-abi"
86d02fa8
EF
3478 "--disable-libstdcxx-threads"
3479 "--disable-libstdcxx-pch"
3480 ,(string-append "--with-gxx-include-dir="
3481 (assoc-ref %outputs "out")
3482 "/include"))))
3483 (outputs '("out"))
a2b2070b 3484 (inputs (%boot2-inputs))
86d02fa8 3485 (synopsis "GNU C++ standard library (intermediate)"))))
bdb36958 3486
98bd851e
LC
3487(define zlib-final
3488 ;; Zlib used by GCC-FINAL.
99b73d0f
LC
3489 (package
3490 (inherit zlib)
3491 (arguments
3492 `(#:guile ,%bootstrap-guile
3493 #:implicit-inputs? #f
3494 #:allowed-references ("out" ,glibc-final)
3495 ,@(package-arguments zlib)))
3496 (inputs (%boot2-inputs))))
98bd851e 3497
dab669e0
LC
3498(define ld-wrapper-boot3
3499 (mlambda ()
3500 ;; A linker wrapper that uses the bootstrap Guile.
3501 (make-ld-wrapper "ld-wrapper-boot3"
3502 #:binutils binutils-final
3503 #:guile %bootstrap-guile
3504 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
3505 #:guile-for-build %bootstrap-guile)))
98bd851e 3506
89223417 3507(define gcc-final
bdb36958
LC
3508 ;; The final GCC.
3509 (package (inherit gcc-boot0)
3510 (name "gcc")
ab999c25
LC
3511
3512 ;; XXX: Currently #:allowed-references applies to all the outputs but the
3513 ;; "debug" output contains disallowed references, notably
3514 ;; linux-libre-headers. Disable the debugging output to work around that.
3515 (outputs (delete "debug" (package-outputs gcc-boot0)))
3516
bdb36958
LC
3517 (arguments
3518 `(#:guile ,%bootstrap-guile
3519 #:implicit-inputs? #f
3520
98bd851e 3521 #:allowed-references ("out" "lib" ,zlib-final
90d891fc 3522 ,glibc-final ,static-bash-for-glibc)
bdb36958 3523
d485ebba
LC
3524 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
3525 ;; reason, but it is not in their RUNPATH. This is a false
3526 ;; positive, so turn it off.
3527 #:validate-runpath? #f
3528
eb443459 3529 ,@(substitute-keyword-arguments (package-arguments gcc)
bdb36958 3530 ((#:make-flags flags)
52cfd8cb 3531 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
98bd851e
LC
3532 `(let ((zlib (assoc-ref %build-inputs "zlib")))
3533 (map (lambda (flag)
3534 (if (string-prefix? "LDFLAGS=" flag)
3535 (string-append flag " -L"
3536 (assoc-ref %build-inputs "libstdc++")
3537 "/lib -L" zlib "/lib -Wl,-rpath="
3538 zlib "/lib")
3539 flag))
3540 ,flags)))
eb443459
JN
3541 ;; Build again GMP & co. within GCC's build process, because it's hard
3542 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
3543 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
bdb36958 3544 ((#:phases phases)
eb443459
JN
3545 `(modify-phases ,phases
3546 (add-after 'unpack 'unpack-gmp&co
3547 (lambda* (#:key inputs #:allow-other-keys)
3548 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
3549 (mpfr (assoc-ref %build-inputs "mpfr-source"))
3550 (mpc (assoc-ref %build-inputs "mpc-source")))
3551
3552 ;; To reduce the set of pre-built bootstrap inputs, build
3553 ;; GMP & co. from GCC.
3554 (for-each (lambda (source)
3555 (invoke "tar" "xvf" source))
3556 (list gmp mpfr mpc))
3557
3558 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
3559 ,@(map (lambda (lib)
3560 ;; Drop trailing letters, as gmp-6.0.0a unpacks
3561 ;; into gmp-6.0.0.
3562 `(symlink ,(string-trim-right
3563 (package-full-name lib "-")
3564 char-set:letter)
3565 ,(package-name lib)))
3566 (list gmp-6.0 mpfr mpc))
3567 #t))))))))
bdb36958 3568
90d891fc
LC
3569 ;; This time we want Texinfo, so we get the manual. Add
3570 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
3571 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
3572 ;; scripts?).
bdb36958 3573 (native-inputs `(("texinfo" ,texinfo-boot0)
19d27131 3574 ("perl" ,perl-boot0) ;for manpages
90d891fc 3575 ("static-bash" ,static-bash-for-glibc)
bdb36958
LC
3576 ,@(package-native-inputs gcc-boot0)))
3577
8309c389 3578 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
bdb36958
LC
3579 ("mpfr-source" ,(package-source mpfr))
3580 ("mpc-source" ,(package-source mpc))
f50b013f 3581 ("ld-wrapper" ,(ld-wrapper-boot3))
bdb36958
LC
3582 ("binutils" ,binutils-final)
3583 ("libstdc++" ,libstdc++)
98bd851e 3584 ("zlib" ,zlib-final)
a2b2070b 3585 ,@(%boot2-inputs)))))
bdb36958 3586
a2b2070b 3587(define (%boot3-inputs)
bdb36958
LC
3588 ;; 4th stage inputs.
3589 `(("gcc" ,gcc-final)
f50b013f 3590 ("ld-wrapper" ,(ld-wrapper-boot3))
a2b2070b 3591 ,@(alist-delete "gcc" (%boot2-inputs))))
bdb36958
LC
3592
3593(define bash-final
3594 ;; Link with `-static-libgcc' to make sure we don't retain a reference
704243e0
LC
3595 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
3596 ;; on Readline and ncurses.
99b73d0f
LC
3597 (let ((bash (static-libgcc-package bash-minimal)))
3598 (package
3599 (inherit bash)
3600 (source (bootstrap-origin (package-source bash)))
3601 (inputs (%boot3-inputs))
3602 (arguments
3603 `(#:implicit-inputs? #f
3604 #:guile ,%bootstrap-guile
3605
3606 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
3607
3608 ,@(package-arguments bash))))))
bdb36958 3609
a2b2070b 3610(define (%boot4-inputs)
bdb36958
LC
3611 ;; Now use the final Bash.
3612 `(("bash" ,bash-final)
a2b2070b 3613 ,@(alist-delete "bash" (%boot3-inputs))))
bdb36958 3614
8f417ed2
LC
3615(define with-boot4
3616 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
3617
bdb36958 3618(define-public guile-final
386b71d1
LC
3619 ;; This package must be public because other modules refer to it. However,
3620 ;; mark it as hidden so that 'fold-packages' ignores it.
8f417ed2
LC
3621 (with-boot4 (hidden-package
3622 (package-with-bootstrap-guile guile-2.2/fixed))))
bdb36958 3623
89223417 3624(define glibc-utf8-locales-final
87c8b92f
LC
3625 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
3626 ;; by the build processes afterwards so their 'scm_to_locale_string' works
3627 ;; with the full range of Unicode codepoints (remember
3628 ;; 'scm_to_locale_string' is called every time a string is passed to a C
3629 ;; function.)
3630 (package
3631 (inherit glibc-utf8-locales)
58a75996
MO
3632 (native-inputs
3633 `(("glibc" ,glibc-final)
8f417ed2 3634 ("gzip" ,(with-boot4 gzip))))))
87c8b92f 3635
28cbc587
LC
3636(define-public ld-wrapper
3637 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
78dea6f1
LC
3638 (make-ld-wrapper "ld-wrapper"
3639 #:binutils binutils-final
3640 #:guile guile-final
3641 #:bash bash-final))
28cbc587 3642
a2b2070b 3643(define (%boot5-inputs)
b6ac5451
LC
3644 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
3645 ;; with an older libc, which cannot load the new locale format. See
28cbc587 3646 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
b6ac5451 3647 `(("locales" ,glibc-utf8-locales-final)
a2b2070b 3648 ,@(%boot4-inputs)))
87c8b92f 3649
8f417ed2
LC
3650(define with-boot5
3651 (package-with-explicit-inputs %boot5-inputs))
3652
bdb36958
LC
3653(define gnu-make-final
3654 ;; The final GNU Make, which uses the final Guile.
8f417ed2 3655 (let ((pkg-config (package
537b2dab 3656 (inherit %pkg-config) ;the native pkg-config
8f417ed2
LC
3657 (inputs `(("guile" ,guile-final)
3658 ,@(%boot5-inputs)))
3659 (arguments
3660 `(#:implicit-inputs? #f
3661 ,@(package-arguments pkg-config))))))
3662 (package
3663 (inherit (package-with-bootstrap-guile gnu-make))
3664 (inputs `(("guile" ,guile-final)
3665 ,@(%boot5-inputs)))
3666 (native-inputs `(("pkg-config" ,pkg-config)))
3667 (arguments
3668 `(#:implicit-inputs? #f
3669 ,@(package-arguments gnu-make))))))
3670
bdb36958 3671
bdb36958
LC
3672(define coreutils-final
3673 ;; The final Coreutils. Treat them specially because some packages, such as
3674 ;; Findutils, keep a reference to the Coreutils they were built with.
8f417ed2
LC
3675 (with-boot5 (package-with-bootstrap-guile coreutils)
3676 ;; Use the final Guile, linked against the
3677 ;; final libc with working iconv, so that
3678 ;; 'substitute*' works well when touching
3679 ;; test files in Gettext.
3680 ))
bdb36958
LC
3681
3682(define grep-final
3683 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
3684 ;; built before gzip.
8f417ed2 3685 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
78ca500a
LC
3686 (package/inherit grep
3687 (inputs (alist-delete "pcre" (package-inputs grep)))
3688 (native-inputs `(("perl" ,perl-boot0))))))
bdb36958 3689
a2b2070b 3690(define (%boot6-inputs)
bdb36958
LC
3691 ;; Now use the final Coreutils.
3692 `(("coreutils" ,coreutils-final)
3693 ("grep" ,grep-final)
a2b2070b 3694 ,@(%boot5-inputs)))
b0fd2bd3 3695
8f417ed2
LC
3696(define with-boot6
3697 (package-with-explicit-inputs %boot6-inputs))
3698
301a4249
LC
3699(define sed-final
3700 ;; The final sed.
8f417ed2 3701 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
301a4249
LC
3702 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
3703
bdb36958
LC
3704(define-public %final-inputs
3705 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
3706 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
3707 ;; used for origins that have patches, thereby avoiding circular
3708 ;; dependencies.
8f417ed2 3709 (let ((finalize (compose with-boot6
099dbc4f 3710 package-with-bootstrap-guile)))
bdb36958 3711 `(,@(map (match-lambda
099dbc4f
LC
3712 ((name package)
3713 (list name (finalize package))))
bdb36958 3714 `(("tar" ,tar)
87c8b92f 3715 ("gzip" ,gzip)
bdb36958
LC
3716 ("bzip2" ,bzip2)
3717 ("xz" ,xz)
c00a9fbf 3718 ("file" ,file)
bdb36958
LC
3719 ("diffutils" ,diffutils)
3720 ("patch" ,patch)
bdb36958
LC
3721 ("findutils" ,findutils)
3722 ("gawk" ,gawk)))
301a4249 3723 ("sed" ,sed-final)
bdb36958
LC
3724 ("grep" ,grep-final)
3725 ("coreutils" ,coreutils-final)
3726 ("make" ,gnu-make-final)
3727 ("bash" ,bash-final)
3728 ("ld-wrapper" ,ld-wrapper)
3729 ("binutils" ,binutils-final)
3730 ("gcc" ,gcc-final)
b0fd2bd3 3731 ("libc" ,glibc-final)
6dff905e 3732 ("libc:static" ,glibc-final "static")
b0fd2bd3 3733 ("locales" ,glibc-utf8-locales-final))))
bdb36958
LC
3734
3735(define-public canonical-package
3736 (let ((name->package (fold (lambda (input result)
3737 (match input
6dff905e 3738 ((_ package . outputs)
bdb36958
LC
3739 (vhash-cons (package-full-name package)
3740 package result))))
3741 vlist-null
3742 `(("guile" ,guile-final)
3743 ,@%final-inputs))))
3744 (lambda (package)
3745 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
3746the implicit inputs of 'gnu-build-system', return that one, otherwise return
3747PACKAGE.
3748
34d624ce 3749The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
bdb36958
LC
3750COREUTILS-FINAL vs. COREUTILS, etc."
3751 ;; XXX: This doesn't handle dependencies of the final inputs, such as
3752 ;; libunistring, GMP, etc.
3753 (match (vhash-assoc (package-full-name package) name->package)
3754 ((_ . canon)
3755 ;; In general we want CANON, except if we're cross-compiling: CANON
3756 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
3757 ;; process, with dependencies on things that cannot be
3758 ;; cross-compiled.
3759 (if (%current-target-system)
3760 package
3761 canon))
3762 (_ package)))))
3763
3764\f
3765;;;
3766;;; GCC toolchain.
3767;;;
3768
6869b663
CD
3769;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
3770;; instantiated like this:
3771;;
3772;; (define-public gcc-glibc-2.27-toolchain
3773;; (make-gcc-toolchain gcc glibc-2.27))
3774
3775(define* (make-gcc-toolchain gcc
3776 #:optional
3777 (libc #f))
3778 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
3779 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
3780 (libc (if libc libc glibc-final)))
3781 (package
3782 (name (string-append (package-name gcc) "-toolchain"))
3783 (version (package-version gcc))
3784 (source #f)
3785 (build-system trivial-build-system)
3786 (arguments
3787 '(#:modules ((guix build union))
3788 #:builder (begin
3789 (use-modules (ice-9 match)
3790 (srfi srfi-26)
3791 (guix build union))
3792
3793 (let ((out (assoc-ref %outputs "out")))
3794
3795 (match %build-inputs
3796 (((names . directories) ...)
3797 (union-build out directories)))
3798
3799 (union-build (assoc-ref %outputs "debug")
3800 (list (assoc-ref %build-inputs
3801 "libc-debug")))
3802 (union-build (assoc-ref %outputs "static")
3803 (list (assoc-ref %build-inputs
3804 "libc-static")))
3805 #t))))
3806
3807 (native-search-paths (package-native-search-paths gcc))
3808 (search-paths (package-search-paths gcc))
3809
3810 (license (package-license gcc))
3811 (synopsis "Complete GCC tool chain for C/C++ development")
3812 (description
3813 "This package provides a complete GCC tool chain for C/C++ development to
34e8f0af
JB
3814be installed in user profiles. This includes GCC, as well as libc (headers and
3815binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
6869b663
CD
3816 (home-page "https://gcc.gnu.org/")
3817 (outputs '("out" "debug" "static"))
3818
3819 ;; The main raison d'être of this "meta-package" is (1) to conveniently
3820 ;; install everything that we need, and (2) to make sure ld-wrapper comes
3821 ;; before Binutils' ld in the user's profile.
3822 (inputs `(("gcc" ,gcc)
3823 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
3824 ("binutils" ,binutils-final)
3825 ("libc" ,libc)
3826 ("libc-debug" ,libc "debug")
3827 ("libc-static" ,libc "static"))))))
bdb36958 3828
01e8263f
MB
3829(define-public gcc-toolchain
3830 (make-gcc-toolchain gcc-final))
3831
bdb36958 3832(define-public gcc-toolchain-4.8
b887ede1 3833 (make-gcc-toolchain gcc-4.8))
bdb36958
LC
3834
3835(define-public gcc-toolchain-4.9
b887ede1
LC
3836 (make-gcc-toolchain gcc-4.9))
3837
629f4d2e 3838(define-public gcc-toolchain-5
01e8263f 3839 (make-gcc-toolchain gcc-5))
60e2d5fe 3840
e760ec41 3841(define-public gcc-toolchain-6
b887ede1 3842 (make-gcc-toolchain gcc-6))
e760ec41 3843
d7ecab74 3844(define-public gcc-toolchain-7
01e8263f 3845 gcc-toolchain)
d7ecab74 3846
5ae27f57
LC
3847(define-public gcc-toolchain-8
3848 (make-gcc-toolchain gcc-8))
3849
bdfc3276
CD
3850(define-public gcc-toolchain-9
3851 (make-gcc-toolchain gcc-9))
3852
4ac5d4fe
KH
3853;; Provide the Fortran toolchain package only for the version of gfortran that
3854;; is used by Guix internally to build Fortran libraries, because combining
3855;; code compiled with different versions can cause problems.
3856
3857(define-public gfortran-toolchain
3858 (package (inherit (make-gcc-toolchain gfortran))
3859 (synopsis "Complete GCC tool chain for Fortran development")
3860 (description "This package provides a complete GCC tool chain for
3861Fortran development to be installed in user profiles. This includes
3862gfortran, as well as libc (headers and binaries, plus debugging symbols
3863in the @code{debug} output), and binutils.")))
3864
3865
bdb36958 3866;;; commencement.scm ends here