Merge branch 'staging' into core-updates
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
9 ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
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)
27 #:use-module ((guix licenses)
28 #:select (gpl3+ lgpl2.0+ public-domain))
29 #:use-module (gnu packages)
30 #:use-module (gnu packages bootstrap)
31 #:use-module (gnu packages base)
32 #:use-module (gnu packages bash)
33 #:use-module (gnu packages c)
34 #:use-module (gnu packages gcc)
35 #:use-module (gnu packages m4)
36 #:use-module (gnu packages file)
37 #:use-module (gnu packages gawk)
38 #:use-module (gnu packages bison)
39 #:use-module (gnu packages flex)
40 #:use-module (gnu packages guile)
41 #:use-module (gnu packages gettext)
42 #:use-module (gnu packages multiprecision)
43 #:use-module (gnu packages compression)
44 #:use-module (gnu packages mes)
45 #:use-module (gnu packages perl)
46 #:use-module (gnu packages python)
47 #:use-module (gnu packages linux)
48 #:use-module (gnu packages hurd)
49 #:use-module (gnu packages texinfo)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages xml)
52 #:use-module (guix packages)
53 #:use-module (guix download)
54 #:use-module (guix build-system gnu)
55 #:use-module (guix build-system trivial)
56 #:use-module (guix memoization)
57 #:use-module (guix utils)
58 #:use-module (srfi srfi-1)
59 #:use-module (srfi srfi-26)
60 #:use-module (ice-9 vlist)
61 #:use-module (ice-9 match)
62 #:use-module (ice-9 regex)
63 #:export (make-gcc-toolchain))
64
65 ;;; Commentary:
66 ;;;
67 ;;; This is the commencement, this is where things start. Before the
68 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
69 ;;; with the initial binaries. This module uses those bootstrap binaries to
70 ;;; actually build up the whole tool chain that make up the implicit inputs of
71 ;;; 'gnu-build-system'.
72 ;;;
73 ;;; To avoid circular dependencies, this module should not be imported
74 ;;; directly from anywhere.
75 ;;;
76 ;;; Below, we frequently use "inherit" to create modified packages. The
77 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
78 ;;; not want these commencement packages to inherit grafts. By definition,
79 ;;; these packages are not depended on at run time by any of the packages we
80 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
81 ;;; grafts would often lead to extra overhead for users who would end up
82 ;;; downloading those "-boot0" packages just to build package replacements
83 ;;; that are in fact not going to be used.
84 ;;;
85 ;;; Code:
86
87 (define mes-boot
88 (package
89 (inherit mes)
90 (name "mes-boot")
91 (version "0.19")
92 (source (origin
93 (method url-fetch)
94 (uri (string-append "mirror://gnu/mes/"
95 "mes-" version ".tar.gz"))
96 (sha256
97 (base32
98 "15h4yhaywdc0djpjlin2jz1kzahpqxfki0r0aav1qm9nxxmnp1l0"))))
99 (inputs '())
100 (propagated-inputs '())
101 (native-inputs
102 `(("mescc-tools" ,%bootstrap-mescc-tools)
103 ("nyacc-source" ,(bootstrap-origin
104 (package-source nyacc-0.86)))
105
106 ("coreutils" , %bootstrap-coreutils&co)
107 ("bootstrap-mes" ,%bootstrap-mes)))
108 (arguments
109 `(#:implicit-inputs? #f
110 #:guile ,%bootstrap-guile
111 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
112 #:phases
113 (modify-phases %standard-phases
114 (add-after 'unpack 'unpack-seeds
115 (lambda _
116 (let ((nyacc-source (assoc-ref %build-inputs "nyacc-source"))
117 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
118 (with-directory-excursion ".."
119 (mkdir-p "nyacc-source")
120 (invoke "tar" "--strip=1" "-C" "nyacc-source" "-xvf" nyacc-source)
121 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
122 #t)))
123 (replace 'configure
124 (lambda* (#:key outputs #:allow-other-keys)
125 (let ((out (assoc-ref %outputs "out")))
126 (setenv "GUILE" "mes")
127 (setenv "GUILE_EFFECTIVE_VERSION" "2.2")
128 (setenv "GUILE_LOAD_PATH" "nyacc")
129 (symlink (string-append "../nyacc-source/module") "nyacc")
130 (invoke "bash" "configure.sh"
131 (string-append "--prefix=" out)))))
132 (replace 'build
133 (lambda _
134 (let ((mes (assoc-ref %build-inputs "bootstrap-mes")))
135 (setenv "MES_PREFIX" (string-append mes "/share/mes"))
136 (setenv "MES_ARENA" "100000000")
137 (setenv "MES_MAX_ARENA" "100000000")
138 (setenv "MES_STACK" "10000000")
139 (invoke "sh" "bootstrap.sh"))))
140 (replace 'check
141 (lambda _
142 (setenv "DIFF" "sh scripts/diff.scm")
143 ;; fail fast tests
144 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/t")
145 ;; (invoke "sh" "-x" "build-aux/test.sh" "scaffold/tests/63-struct-cell")
146 (invoke "sh" "check.sh")))
147 (replace 'install
148 (lambda _
149 (invoke "sh" "install.sh"))))))
150 (native-search-paths
151 ;; Use the language-specific variables rather than 'CPATH' because they
152 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
153 ;; The intent is to allow headers that are in the search path to be
154 ;; treated as "system headers" (headers exempt from warnings) just like
155 ;; the typical /usr/include headers on an FHS system.
156 (list (search-path-specification
157 (variable "C_INCLUDE_PATH")
158 (files '("share/mes/include")))
159 (search-path-specification
160 (variable "LIBRARY_PATH")
161 (files '("share/mes/lib")))))))
162
163 (define tcc-boot0
164 ;; Pristine tcc cannot be built by MesCC, we are keeping a delta of 11
165 ;; patches. In a very early and rough form they were presented to the
166 ;; TinyCC developers, who at the time showed no interest in supporting the
167 ;; bootstrappable effort; we will try again later. These patches have been
168 ;; ported to 0.9.27, alas the resulting tcc is buggy. Once MesCC is more
169 ;; mature, this package should use the 0.9.27 sources (or later).
170 (let ((version "0.9.26")
171 (revision "6")
172 (commit "c004e9a34fb026bb44d211ab98bb768e79900eef"))
173 (package
174 (inherit tcc)
175 (name "tcc-boot0")
176 (version (string-append version "-" revision "." (string-take commit 7)))
177 (source (origin
178 (method url-fetch)
179 (uri (list (string-append "mirror://gnu/guix/mirror"
180 "/tinycc-" commit ".tar.gz")
181 (string-append "https://gitlab.com/janneke/tinycc"
182 "/-/archive/" commit
183 "/tinycc-" commit ".tar.gz")))
184 (sha256
185 (base32
186 "1hmzn1pq0x22ppd80hyrn5qzqq94mxd0ychzj6vrr2vnj2frjv5b"))))
187 (build-system gnu-build-system)
188 (supported-systems '("i686-linux" "x86_64-linux"))
189 (inputs '())
190 (propagated-inputs '())
191 (native-inputs
192 `(("mes" ,mes-boot)
193 ("mescc-tools" ,%bootstrap-mescc-tools)
194 ("nyacc-source" ,(bootstrap-origin
195 (package-source nyacc-0.86)))
196
197 ("coreutils" , %bootstrap-coreutils&co)
198 ("bootstrap-mes" ,%bootstrap-mes)))
199 (arguments
200 `(#:implicit-inputs? #f
201 #:guile ,%bootstrap-guile
202 #:strip-binaries? #f ; binutil's strip b0rkes MesCC/M1/hex2 binaries
203 #:phases
204 (modify-phases %standard-phases
205 (add-after 'unpack 'unpack-seeds
206 (lambda* (#:key outputs #:allow-other-keys)
207 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
208 (nyacc-source (assoc-ref %build-inputs "nyacc-source"))
209 (bootstrap-mes (assoc-ref %build-inputs "bootstrap-mes")))
210 (setenv "PATH" (string-append
211 coreutils "/bin"))
212 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
213 (with-directory-excursion ".."
214 (mkdir-p "nyacc-source")
215 (invoke "tar" "--strip=1" "-C" "nyacc-source"
216 "-xvf" nyacc-source)
217 (symlink (string-append bootstrap-mes "/share/mes/lib") "mes-seed"))
218 #t)))
219 (replace 'configure
220 (lambda* (#:key outputs #:allow-other-keys)
221 (let* ((out (assoc-ref %outputs "out"))
222 (dir (with-directory-excursion ".." (getcwd)))
223 (coreutils (assoc-ref %build-inputs "coreutils"))
224 (mes (assoc-ref %build-inputs "mes"))
225 (mescc-tools (assoc-ref %build-inputs "mescc-tools"))
226 (libc (assoc-ref %build-inputs "libc"))
227 (interpreter (if libc
228 ;; also for x86_64-linux, we are still on i686-linux
229 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
230 (string-append mes "/lib/mes-loader"))))
231 (setenv "PATH" (string-append
232 coreutils "/bin"
233 ":" mes "/bin"
234 ":" mescc-tools "/bin"))
235 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
236
237 (setenv "PREFIX" out)
238 (symlink (string-append mes "/share/mes") "mes")
239 (symlink (string-append "../nyacc-source/module") "nyacc")
240 (setenv "MES_PREFIX" "mes")
241 (setenv "MES_ARENA" "100000000")
242 (setenv "MES_MAX_ARENA" "100000000")
243 (setenv "MES_STACK" "10000000")
244 (setenv "MES" "mes")
245 (setenv "GUILE_LOAD_PATH" "nyacc")
246 (invoke "sh" "configure"
247 "--prefix=$PREFIX"
248 (string-append "--elfinterp=" interpreter)
249 "--crtprefix=."
250 "--tccdir=."))))
251 (replace 'build
252 (lambda _
253 (substitute* "bootstrap.sh"
254 (("^ cmp") "# cmp"))
255 (invoke "sh" "bootstrap.sh")))
256 (replace 'check
257 (lambda _
258 (setenv "DIFF" "diff.scm")
259 (setenv "OBJDUMP" "true")
260 ;; fail fast tests
261 ;; (invoke "sh" "test.sh" "mes/scaffold/tests/30-strlen")
262 ;; (invoke "sh" "-x" "test.sh" "mes/scaffold/tinycc/00_assignment")
263 (setenv "TCC" "./tcc")
264 (invoke "sh" "check.sh")))
265 (replace 'install
266 (lambda _
267 (invoke "sh" "install.sh"))))))
268 (native-search-paths
269 ;; Use the language-specific variables rather than 'CPATH' because they
270 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
271 ;; The intent is to allow headers that are in the search path to be
272 ;; treated as "system headers" (headers exempt from warnings) just like
273 ;; the typical /usr/include headers on an FHS system.
274 (list (search-path-specification
275 (variable "C_INCLUDE_PATH")
276 (files '("include")))
277 (search-path-specification
278 (variable "LIBRARY_PATH")
279 (files '("lib"))))))))
280
281 (define tcc-boot
282 (package
283 (inherit tcc-boot0)
284 (name "tcc-boot")
285 (version "0.9.27")
286 (source (bootstrap-origin
287 (origin
288 (inherit (package-source tcc))
289 (patches (search-patches "tcc-boot-0.9.27.patch")))))
290 (build-system gnu-build-system)
291 (inputs '())
292 (propagated-inputs '())
293 (native-inputs
294 `(("mes" ,mes-boot)
295 ("tcc" ,tcc-boot0)
296
297 ("coreutils" , %bootstrap-coreutils&co)))
298 (arguments
299 `(#:implicit-inputs? #f
300 #:guile ,%bootstrap-guile
301
302 ;; Binutils' 'strip' b0rkes MesCC/M1/hex2 binaries, tcc-boot also comes
303 ;; with MesCC/M1/hex2-built binaries.
304 #:strip-binaries? #f
305
306 #:phases
307 (modify-phases %standard-phases
308 (replace 'configure
309 (lambda* (#:key outputs #:allow-other-keys)
310 (let* ((out (assoc-ref %outputs "out"))
311 (coreutils (assoc-ref %build-inputs "coreutils"))
312 (mes (assoc-ref %build-inputs "mes"))
313 (tcc (assoc-ref %build-inputs "tcc"))
314 (libc (assoc-ref %build-inputs "libc"))
315 (interpreter (if libc
316 ;; also for x86_64-linux, we are still on i686-linux
317 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
318 (string-append mes "/lib/mes-loader"))))
319 ;; unpack
320 (setenv "PATH" (string-append
321 coreutils "/bin"
322 ":" tcc "/bin"))
323 (format (current-error-port) "PATH=~s\n" (getenv "PATH"))
324 (invoke "sh" "configure"
325 (string-append "--cc=tcc")
326 (string-append "--cpu=i386")
327 (string-append "--prefix=" out)
328 (string-append "--elfinterp=" interpreter)
329 (string-append "--crtprefix=" tcc "/lib")
330 (string-append "--sysincludepaths=" tcc "/include")
331 (string-append "--libpaths=" tcc "/lib")))))
332 (replace 'build
333 (lambda* (#:key outputs #:allow-other-keys)
334 (let* ((out (assoc-ref %outputs "out"))
335 (mes (assoc-ref %build-inputs "mes"))
336 (tcc (assoc-ref %build-inputs "tcc"))
337 (libc (assoc-ref %build-inputs "libc"))
338 (interpreter (if libc
339 ;; also for x86_64-linux, we are still on i686-linux
340 (string-append libc ,(glibc-dynamic-linker "i686-linux"))
341 (string-append mes "/lib/mes-loader"))))
342 (invoke "tcc"
343 "-vvv"
344 "-D" "BOOTSTRAP=1"
345 "-D" "ONE_SOURCE=1"
346 "-D" "TCC_TARGET_I386=1"
347 "-D" "CONFIG_TCC_STATIC=1"
348 "-D" "CONFIG_USE_LIBGCC=1"
349 "-D" (string-append "CONFIG_TCCDIR=\"" out "/lib/tcc\"")
350 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out "/lib:{B}/lib:.\"")
351 "-D" (string-append "CONFIG_TCC_CRTPREFIX=\"" out
352 "/lib:{B}/lib:.\"")
353 "-D" (string-append "CONFIG_TCC_ELFINTERP=\"" interpreter "\"")
354 "-D" (string-append "CONFIG_TCC_LIBPATHS=\"" tcc "/lib:{B}/lib:.\"")
355 "-D" (string-append "CONFIG_TCC_SYSINCLUDEPATHS=\"" tcc "/include" ":/include:{B}/include\"")
356 "-D" (string-append "TCC_LIBGCC=\"" tcc "/lib/libc.a\"")
357 "-o" "tcc"
358 "tcc.c"))))
359 (replace 'check
360 (lambda _
361 ;; FIXME: add sensible check target (without depending on make)
362 ;; ./check.sh ?
363 (= 1 (status:exit-val (system* "./tcc" "--help")))))
364 (replace 'install
365 (lambda* (#:key outputs #:allow-other-keys)
366 (let ((out (assoc-ref %outputs "out"))
367 (tcc (assoc-ref %build-inputs "tcc")))
368 (mkdir-p (string-append out "/bin"))
369 (copy-file "tcc" (string-append out "/bin/tcc"))
370 (mkdir-p (string-append out "/lib/tcc"))
371 (copy-recursively (string-append tcc "/include")
372 (string-append out "/include"))
373 (copy-recursively (string-append tcc "/lib")
374 (string-append out "/lib"))
375 (invoke "tcc" "-D" "TCC_TARGET_I386=1" "-c" "-o" "libtcc1.o" "lib/libtcc1.c")
376 (invoke "tcc" "-ar" "rc" "libtcc1.a" "libtcc1.o")
377 (copy-file "libtcc1.a" (string-append out "/lib/libtcc1.a"))
378 (delete-file (string-append out "/lib/tcc/libtcc1.a"))
379 (copy-file "libtcc1.a" (string-append out "/lib/tcc/libtcc1.a"))
380 #t))))))))
381
382 (define make-mesboot0
383 (package
384 (inherit gnu-make)
385 (name "make-mesboot0")
386 (version "3.80")
387 (source (origin
388 (method url-fetch)
389 (uri (string-append "mirror://gnu/make/make-"
390 version ".tar.gz"))
391 (sha256
392 (base32
393 "1pb7fb7fqf9wz9najm85qdma1xhxzf1rhj5gwrlzdsz2zm0hpcv4"))))
394 (supported-systems '("i686-linux" "x86_64-linux"))
395 (inputs '())
396 (propagated-inputs '())
397 (native-inputs `(("tcc" ,tcc-boot)
398
399 ("bash" ,%bootstrap-coreutils&co)
400 ("coreutils" ,%bootstrap-coreutils&co)))
401 (arguments
402 `(#:implicit-inputs? #f
403 #:tests? #f ; check depends on perl
404 #:guile ,%bootstrap-guile
405 #:configure-flags `("CC=tcc -DO_RDONLY=0"
406 "LD=tcc"
407 "--disable-nls")
408 #:phases
409 (modify-phases %standard-phases
410 (add-after 'configure 'configure-fixup
411 (lambda _
412 (substitute* "build.sh"
413 (("^REMOTE=.*") "REMOTE=stub\n")
414 (("^extras=.*") "extras=getloadavg.c\n"))
415 (substitute* "make.h"
416 (("^extern long int lseek.*" all) (string-append "// " all)))
417 #t))
418 (delete 'patch-generated-file-shebangs) ; no perl
419 (replace 'build
420 (lambda _
421 (invoke "sh" "./build.sh")))
422 (replace 'install
423 (lambda* (#:key outputs #:allow-other-keys)
424 (let* ((out (assoc-ref outputs "out"))
425 (bin (string-append out "/bin")))
426 (install-file "make" bin)
427 #t))))))))
428
429 (define diffutils-mesboot
430 (package
431 (inherit diffutils)
432 (name "diffutils-mesboot")
433 (version "2.7")
434 (source (origin
435 (method url-fetch)
436 (uri (string-append "mirror://gnu/diffutils/diffutils-"
437 version ".tar.gz"))
438 (sha256
439 (base32
440 "1mirn5i825bn5w7rh6mgn0r8aj9xqanav95dwcl1b8sn82f4iwnm"))))
441 (supported-systems '("i686-linux" "x86_64-linux"))
442 (inputs '())
443 (propagated-inputs '())
444 (native-inputs `(("mes" ,mes-boot)
445 ("tcc" ,tcc-boot)
446
447 ("bash" ,%bootstrap-coreutils&co)
448 ("coreutils" ,%bootstrap-coreutils&co)
449 ("make" ,make-mesboot0)))
450 (arguments
451 `(#:implicit-inputs? #f
452 #:guile ,%bootstrap-guile
453 #:parallel-build? #f
454 #:tests? #f ; check is naive, also checks non-built PROGRAMS
455 #:strip-binaries? #f ; no strip yet
456 #:phases
457 (modify-phases %standard-phases
458 ;; diffutils-2.7 needs more traditional configure
459 (replace 'configure
460 (lambda* (#:key outputs #:allow-other-keys)
461 (let ((out (assoc-ref outputs "out"))
462 (bash (assoc-ref %build-inputs "bash")))
463 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
464 (setenv "CC" "tcc")
465 (setenv "LD" "tcc")
466 (invoke "./configure" (string-append "--prefix=" out)))))
467 (add-before 'configure 'remove-diff3-sdiff
468 (lambda* (#:key outputs #:allow-other-keys)
469 (substitute* "Makefile.in"
470 (("PROGRAMS = .*" all) "PROGRAMS = cmp diff"))
471 #t)))))))
472
473 (define binutils-mesboot0
474 (package
475 (inherit binutils)
476 (name "binutils-mesboot0")
477 (version "2.20.1a")
478 (source (bootstrap-origin
479 (origin
480 (method url-fetch)
481 (uri (string-append "mirror://gnu/binutils/binutils-"
482 version ".tar.bz2"))
483 (patches (search-patches "binutils-boot-2.20.1a.patch"))
484 (sha256
485 (base32
486 "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi")))))
487 (inputs '())
488 (propagated-inputs '())
489 (native-inputs `(("tcc" ,tcc-boot)
490
491 ("bash" ,%bootstrap-coreutils&co)
492 ("coreutils" ,%bootstrap-coreutils&co)
493 ("diffutils" ,diffutils-mesboot)
494 ("make" ,make-mesboot0)))
495 (supported-systems '("i686-linux" "x86_64-linux"))
496 (arguments
497 `(#:implicit-inputs? #f
498 #:guile ,%bootstrap-guile
499 #:tests? #f ; runtest: command not found
500 #:parallel-build? #f
501 #:strip-binaries? #f ; no strip yet
502 #:configure-flags
503 (let ((cppflags (string-append " -D __GLIBC_MINOR__=6"
504 " -D MES_BOOTSTRAP=1"))
505 (bash (assoc-ref %build-inputs "bash")))
506 `(,(string-append "CONFIG_SHELL=" bash "/bin/sh")
507 ,(string-append "CPPFLAGS=" cppflags)
508 "AR=tcc -ar"
509 "CXX=false"
510 "RANLIB=true"
511 ,(string-append "CC=tcc" cppflags)
512 "--disable-nls"
513 "--disable-shared"
514 "--disable-werror"
515 "--build=i686-unknown-linux-gnu"
516 "--host=i686-unknown-linux-gnu"
517 "--with-sysroot=/"))))))
518
519 (define gcc-core-mesboot
520 ;; Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C
521 ;; Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C
522 ;; library, such as dir.h/struct DIR/readdir, locales, signals... Also,
523 ;; with gcc-2.95.3, binutils-boot-2.20.1a and glibc-2.2.5 we found a GNU
524 ;; toolchain triplet "that works".
525 (package
526 (inherit gcc)
527 (name "gcc-core-mesboot")
528 (version "2.95.3")
529 (source (bootstrap-origin
530 (origin
531 (method url-fetch)
532 (uri (string-append "mirror://gnu/gcc/gcc-2.95.3/gcc-core-"
533 version
534 ".tar.gz"))
535 (patches (search-patches "gcc-boot-2.95.3.patch"))
536 (sha256
537 (base32
538 "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an")))))
539 (supported-systems '("i686-linux" "x86_64-linux"))
540 (inputs '())
541 (propagated-inputs '())
542 (native-inputs `(("binutils" ,binutils-mesboot0)
543 ("tcc" ,tcc-boot)
544
545 ("bash" ,%bootstrap-coreutils&co)
546 ("coreutils" ,%bootstrap-coreutils&co)
547 ("diffutils" ,diffutils-mesboot)
548 ("make" ,make-mesboot0)))
549 (outputs '("out"))
550 (arguments
551 `(#:implicit-inputs? #f
552 #:guile ,%bootstrap-guile
553 #:tests? #f
554 #:parallel-build? #f
555 #:strip-binaries? #f
556 #:configure-flags
557 (let ((out (assoc-ref %outputs "out")))
558 `("--enable-static"
559 "--disable-shared"
560 "--disable-werror"
561 "--build=i686-unknown-linux-gnu"
562 "--host=i686-unknown-linux-gnu"
563 ,(string-append "--prefix=" out)))
564 #:make-flags (list
565 "CC=tcc -static -D __GLIBC_MINOR__=6"
566 "OLDCC=tcc -static -D __GLIBC_MINOR__=6"
567 "CC_FOR_BUILD=tcc -static -D __GLIBC_MINOR__=6"
568 "AR=ar"
569 "RANLIB=ranlib"
570 (string-append "LIBGCC2_INCLUDES=-I "
571 (assoc-ref %build-inputs "tcc")
572 "/include")
573 "LANGUAGES=c"
574 (string-append "BOOT_LDFLAGS="
575 " -B" (assoc-ref %build-inputs "tcc")
576 "/lib/"))
577 #:modules ((guix build gnu-build-system)
578 (guix build utils)
579 (srfi srfi-1))
580 #:phases
581 (modify-phases %standard-phases
582 ;; gcc-2.95.3 needs more traditional configure
583 (add-before 'configure 'setenv
584 (lambda* (#:key outputs #:allow-other-keys)
585 (let ((out (assoc-ref outputs "out"))
586 (bash (assoc-ref %build-inputs "bash"))
587 (tcc (assoc-ref %build-inputs "tcc"))
588 (cppflags " -D __GLIBC_MINOR__=6"))
589 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
590 (setenv "CPPFLAGS" cppflags)
591 (setenv "CC" (string-append "tcc" cppflags))
592 (setenv "CC_FOR_BUILD" (string-append "tcc" cppflags))
593 (setenv "CPP" (string-append "tcc -E" cppflags))
594 (with-output-to-file "config.cache"
595 (lambda _
596 (display "
597 ac_cv_c_float_format='IEEE (little-endian)'
598 ")))
599 #t)))
600 (replace 'configure
601 (lambda* (#:key configure-flags #:allow-other-keys)
602 (format (current-error-port)
603 "running ./configure ~a\n" (string-join configure-flags))
604 (apply invoke "./configure" configure-flags)))
605 (add-after 'configure 'remove-info
606 (lambda _
607 ;; no info at this stage
608 (delete-file-recursively "texinfo")
609 (invoke "touch" "gcc/cpp.info" "gcc/gcc.info")))
610 (add-after 'install 'install2
611 (lambda* (#:key outputs #:allow-other-keys)
612 (let* ((tcc (assoc-ref %build-inputs "tcc"))
613 (tcc-lib (string-append tcc "/lib/x86-mes-gcc"))
614 (out (assoc-ref outputs "out"))
615 (gcc-dir (string-append
616 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
617 (mkdir-p "tmp")
618 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
619 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
620 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
621 (copy-file (string-append tcc "/lib/libtcc1.a")
622 (string-append out "/lib/libtcc1.a"))
623 (invoke "ar" "r" (string-append gcc-dir "/libc.a")
624 (string-append tcc-lib "/libc+gnu.o")
625 (string-append tcc-lib "/libtcc1.o"))
626 (invoke "ar" "r" (string-append out "/lib/libc.a")
627 (string-append tcc-lib "/libc+gnu.o")
628 (string-append tcc-lib "/libtcc1.o"))
629 (invoke "ls" "-ltrF" gcc-dir)
630 (copy-recursively (string-append tcc "/include")
631 (string-append out "/include"))
632 #t))))))
633 (native-search-paths
634 ;; Use the language-specific variables rather than 'CPATH' because they
635 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
636 ;; The intent is to allow headers that are in the search path to be
637 ;; treated as "system headers" (headers exempt from warnings) just like
638 ;; the typical /usr/include headers on an FHS system.
639 (list (search-path-specification
640 (variable "C_INCLUDE_PATH")
641 (files '("include" "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include")))
642 (search-path-specification
643 (variable "LIBRARY_PATH")
644 (files '("lib")))))))
645
646 (define mesboot-headers
647 (package
648 (inherit mes-boot)
649 (name "mesboot-headers")
650 (supported-systems '("i686-linux" "x86_64-linux"))
651 (inputs '())
652 (propagated-inputs '())
653 (native-inputs `(("coreutils" ,%bootstrap-coreutils&co)
654 ("headers" ,%bootstrap-linux-libre-headers)))
655 (arguments
656 `(#:implicit-inputs? #f
657 #:guile ,%bootstrap-guile
658 #:tests? #f
659 #:strip-binaries? #f
660 #:phases
661 (modify-phases %standard-phases
662 (delete 'configure)
663 (delete 'build)
664 (replace 'install
665 (lambda* (#:key outputs #:allow-other-keys)
666 (let* ((out (assoc-ref outputs "out"))
667 (include (string-append out "/include"))
668 (headers (assoc-ref %build-inputs "headers" )))
669 (mkdir-p include)
670 (copy-recursively "include" out)
671 (copy-recursively headers out)
672 #t))))))
673 (native-search-paths
674 ;; Use the language-specific variables rather than 'CPATH' because they
675 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
676 ;; The intent is to allow headers that are in the search path to be
677 ;; treated as "system headers" (headers exempt from warnings) just like
678 ;; the typical /usr/include headers on an FHS system.
679 (list (search-path-specification
680 (variable "C_INCLUDE_PATH")
681 (files '("include")))))))
682
683 (define glibc-mesboot0
684 ;; GNU C Library 2.2.5 is the most recent glibc that we managed to build
685 ;; using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer
686 ;; gcc.
687 (package
688 (inherit glibc)
689 (name "glibc-mesboot0")
690 (version "2.2.5")
691 (source (bootstrap-origin
692 (origin
693 (method url-fetch)
694 (uri (string-append "mirror://gnu/glibc/glibc-"
695 version
696 ".tar.gz"))
697 (patches (search-patches "glibc-boot-2.2.5.patch"))
698 (sha256
699 (base32
700 "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q")))))
701 (supported-systems '("i686-linux" "x86_64-linux"))
702 (inputs '())
703 (propagated-inputs '())
704 (native-inputs `(("binutils" ,binutils-mesboot0)
705 ("gcc" ,gcc-core-mesboot)
706
707 ("bash" ,%bootstrap-coreutils&co)
708 ("coreutils" ,%bootstrap-coreutils&co)
709 ("diffutils" ,diffutils-mesboot)
710 ("headers" ,mesboot-headers)
711 ("make" ,make-mesboot0)))
712 (outputs '("out"))
713 (arguments
714 `(#:implicit-inputs? #f
715 #:guile ,%bootstrap-guile
716 #:tests? #f
717 #:strip-binaries? #f
718 #:parallel-build? #f ; gcc-2.95.3 ICEs on massively parallel builds
719 #:make-flags (list (string-append
720 "SHELL="
721 (assoc-ref %build-inputs "bash")
722 "/bin/sh"))
723 #:configure-flags
724 (let ((out (assoc-ref %outputs "out"))
725 (headers (assoc-ref %build-inputs "headers")))
726 (list
727 "--disable-shared"
728 "--enable-static"
729 "--disable-sanity-checks"
730 "--build=i686-unknown-linux-gnu"
731 "--host=i686-unknown-linux-gnu"
732 (string-append "--with-headers=" headers "/include")
733 "--enable-static-nss"
734 "--without-__thread"
735 "--without-cvs"
736 "--without-gd"
737 "--without-tls"
738 (string-append "--prefix=" out)))
739 #:phases
740 (modify-phases %standard-phases
741 (add-before 'configure 'setenv
742 (lambda* (#:key outputs #:allow-other-keys)
743 (let* ((out (assoc-ref outputs "out"))
744 (bash (assoc-ref %build-inputs "bash"))
745 (gcc (assoc-ref %build-inputs "gcc"))
746 (headers (assoc-ref %build-inputs "headers"))
747 (cppflags (string-append
748 ;;" -D __STDC__=1"
749 " -D MES_BOOTSTRAP=1"
750 " -D BOOTSTRAP_GLIBC=1"))
751 (cflags (string-append " -L " (getcwd))))
752 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
753 (setenv "SHELL" (getenv "CONFIG_SHELL"))
754 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
755 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
756 #t)))
757 ;; glibc-2.2.5 needs a more classic invocation of configure
758 ;; configure: warning: CONFIG_SHELL=/gnu/store/…-bash-minimal-4.4.12/bin/bash: invalid host type
759 (replace 'configure
760 (lambda* (#:key configure-flags #:allow-other-keys)
761 (format (current-error-port)
762 "running ./configure ~a\n" (string-join configure-flags))
763 (apply invoke "./configure" configure-flags))))))
764 (native-search-paths
765 ;; Use the language-specific variables rather than 'CPATH' because they
766 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
767 ;; The intent is to allow headers that are in the search path to be
768 ;; treated as "system headers" (headers exempt from warnings) just like
769 ;; the typical /usr/include headers on an FHS system.
770 (list (search-path-specification
771 (variable "C_INCLUDE_PATH")
772 (files '("include")))
773 (search-path-specification
774 (variable "CPLUS_INCLUDE_PATH")
775 (files '("include")))
776 (search-path-specification
777 (variable "LIBRARY_PATH")
778 (files '("lib")))))))
779
780 (define gcc-mesboot0
781 (package
782 (inherit gcc-core-mesboot)
783 (name "gcc-mesboot0")
784 (native-inputs `(("binutils" ,binutils-mesboot0)
785 ("gcc" ,gcc-core-mesboot)
786 ("libc" ,glibc-mesboot0)
787
788 ("bash" ,%bootstrap-coreutils&co)
789 ("coreutils" ,%bootstrap-coreutils&co)
790 ("diffutils" ,diffutils-mesboot)
791 ("kernel-headers" ,%bootstrap-linux-libre-headers)
792 ("make" ,make-mesboot0)))
793 (arguments
794 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
795 ((#:phases phases)
796 `(modify-phases ,phases
797 (replace 'setenv
798 (lambda* (#:key outputs #:allow-other-keys)
799 (let ((out (assoc-ref outputs "out"))
800 (bash (assoc-ref %build-inputs "bash"))
801 (gcc (assoc-ref %build-inputs "gcc"))
802 (glibc (assoc-ref %build-inputs "libc"))
803 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
804 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
805 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
806 (setenv "C_INCLUDE_PATH" (string-append
807 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include"
808 ":" kernel-headers "/include"
809 ":" glibc "/include"))
810 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
811 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
812 ;; FIXME: add glibc dirs to paths manually
813 (setenv "LIBRARY_PATH" (string-join
814 (list (string-append glibc "/lib")
815 (getenv "LIBRARY_PATH"))
816 ":"))
817 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
818 (with-output-to-file "config.cache"
819 (lambda _
820 (display "
821 ac_cv_c_float_format='IEEE (little-endian)'
822 ")))
823 #t)))
824 (replace 'install2
825 (lambda* (#:key outputs #:allow-other-keys)
826 (let* ((out (assoc-ref outputs "out"))
827 (gcc-dir (string-append
828 out "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3")))
829 (mkdir-p "tmp")
830 (zero? (system (string-append "set -x; cd tmp && ar x ../gcc/libgcc2.a")))
831 (zero? (system (string-append "set -x; cd tmp && ar r " gcc-dir "/libgcc.a *.o")))
832 (copy-file "gcc/libgcc2.a" (string-append out "/lib/libgcc2.a"))
833 #t)))))
834 ((#:configure-flags configure-flags)
835 `(let ((out (assoc-ref %outputs "out")))
836 `("--disable-shared"
837 "--disable-werror"
838 "--build=i686-unknown-linux-gnu"
839 "--host=i686-unknown-linux-gnu"
840 ,(string-append "--prefix=" out))))
841 ((#:make-flags make-flags)
842 `(let ((gcc (assoc-ref %build-inputs "gcc")))
843 `("RANLIB=true"
844 ,(string-append "LIBGCC2_INCLUDES=-I " gcc "/include")
845 "LANGUAGES=c")))))))
846
847 (define binutils-mesboot
848 (package
849 (inherit binutils-mesboot0)
850 (name "binutils-mesboot")
851 (native-inputs `(("binutils" ,binutils-mesboot0)
852 ("libc" ,glibc-mesboot0)
853 ("gcc" ,gcc-mesboot0)
854
855 ("bash" ,%bootstrap-coreutils&co)
856 ("coreutils" ,%bootstrap-coreutils&co)
857 ("diffutils" ,diffutils-mesboot)
858 ("kernel-headers" ,%bootstrap-linux-libre-headers)
859 ("make" ,make-mesboot0)))
860 (arguments
861 (substitute-keyword-arguments (package-arguments binutils-mesboot0)
862 ((#:configure-flags configure-flags)
863 '(list "--disable-nls"
864 "--disable-shared"
865 "--disable-werror"
866 "--build=i686-unknown-linux-gnu"
867 "--host=i686-unknown-linux-gnu"
868 "--with-sysroot=/"))))))
869
870 (define make-mesboot
871 (package
872 (inherit make-mesboot0)
873 (name "make-mesboot")
874 (version "3.82")
875 (source (origin
876 (method url-fetch)
877 (uri (string-append "mirror://gnu/make/make-"
878 version ".tar.gz"))
879 (sha256
880 (base32
881 "1rs2f9hmvy3q6zkl15jnlmnpgffm0bhw5ax0h5c7q604wqrip69x"))))
882 (native-inputs `(("binutils" ,binutils-mesboot0)
883 ("libc" ,glibc-mesboot0)
884 ("gcc" ,gcc-mesboot0)
885 ("make" ,make-mesboot0)
886
887 ("bash" ,%bootstrap-coreutils&co)
888 ("coreutils" ,%bootstrap-coreutils&co)
889 ("kernel-headers" ,%bootstrap-linux-libre-headers)))
890 (arguments
891 (substitute-keyword-arguments (package-arguments make-mesboot0)
892 ((#:configure-flags configure-flags)
893 `(let ((out (assoc-ref %outputs "out")))
894 `(,(string-append "--prefix=" out))))
895 ((#:phases phases)
896 `(modify-phases ,phases
897 (delete 'configure-fixup)
898 (add-before 'configure 'setenv
899 (lambda _
900 (setenv "LIBS" "-lc -lnss_files -lnss_dns -lresolv")
901 #t))))))))
902
903 (define gmp-boot
904 (package
905 (inherit gmp)
906 (version "4.3.2")
907 (source (origin
908 (method url-fetch)
909 (uri (string-append "mirror://gnu/gmp/gmp-" version
910 ".tar.gz"))
911 (sha256 (base32
912 "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"))))))
913
914 (define mpfr-boot
915 (package
916 (inherit mpfr)
917 (version "2.4.2")
918 (source (origin
919 (method url-fetch)
920 (uri (string-append "mirror://gnu/mpfr/mpfr-" version
921 ".tar.gz"))
922 (sha256 (base32
923 "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"))))))
924
925 (define mpc-boot
926 (package
927 (inherit mpc)
928 (version "1.0.3")
929 (source (origin
930 (method url-fetch)
931 (uri (string-append
932 "mirror://gnu/mpc/mpc-" version ".tar.gz"))
933 (sha256
934 (base32
935 "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"))))))
936
937 (define gcc-mesboot1
938 (package
939 (inherit gcc-mesboot0)
940 (name "gcc-mesboot1")
941 (version "4.7.4")
942 (source (bootstrap-origin
943 (origin (inherit (package-source gcc-4.7))
944 (patches (search-patches "gcc-boot-4.7.4.patch")))))
945 (inputs `(("gmp-source" ,(package-source gmp-boot))
946 ("mpfr-source" ,(package-source mpfr-boot))
947 ("mpc-source" ,(package-source mpc-boot))))
948 (native-inputs `(("binutils" ,binutils-mesboot)
949 ("gcc" ,gcc-mesboot0)
950 ("libc" ,glibc-mesboot0)
951
952 ("bash" ,%bootstrap-coreutils&co)
953 ("coreutils" ,%bootstrap-coreutils&co)
954 ("diffutils" ,diffutils-mesboot)
955 ("kernel-headers" ,%bootstrap-linux-libre-headers)
956 ("make" ,make-mesboot)))
957 (arguments
958 (substitute-keyword-arguments (package-arguments gcc-core-mesboot)
959 ((#:make-flags make-flags)
960 `(let* ((libc (assoc-ref %build-inputs "libc"))
961 (ldflags (string-append
962 "-B" libc "/lib "
963 "-Wl,-dynamic-linker "
964 "-Wl," libc
965 ,(glibc-dynamic-linker "i686-linux"))))
966 (list (string-append "LDFLAGS=" ldflags)
967 (string-append "LDFLAGS_FOR_TARGET=" ldflags))))
968 ((#:phases phases)
969 `(modify-phases ,phases
970 ;; c&p from commencement.scm:gcc-boot0
971 (add-after 'unpack 'unpack-gmp&co
972 (lambda* (#:key inputs #:allow-other-keys)
973 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
974 (mpfr (assoc-ref %build-inputs "mpfr-source"))
975 (mpc (assoc-ref %build-inputs "mpc-source")))
976
977 ;; To reduce the set of pre-built bootstrap inputs, build
978 ;; GMP & co. from GCC.
979 (for-each (lambda (source)
980 (or (invoke "tar" "xvf" source)
981 (error "failed to unpack tarball"
982 source)))
983 (list gmp mpfr mpc))
984
985 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
986 ,@(map (lambda (lib)
987 ;; Drop trailing letters, as gmp-6.0.0a unpacks
988 ;; into gmp-6.0.0.
989 `(symlink ,(string-trim-right
990 (package-full-name lib "-")
991 char-set:letter)
992 ,(package-name lib)))
993 (list gmp-boot mpfr-boot mpc-boot))
994 #t)))
995 (delete 'remove-info)
996 (replace 'setenv
997 (lambda* (#:key outputs #:allow-other-keys)
998 (let* ((out (assoc-ref outputs "out"))
999 (binutils (assoc-ref %build-inputs "binutils"))
1000 (bash (assoc-ref %build-inputs "bash"))
1001 (gcc (assoc-ref %build-inputs "gcc"))
1002 (glibc (assoc-ref %build-inputs "libc"))
1003 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
1004 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1005 (setenv "C_INCLUDE_PATH" (string-append
1006 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/2.95.3/include"
1007 ":" kernel-headers "/include"
1008 ":" glibc "/include"
1009 ":" (getcwd) "/mpfr/src"))
1010 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
1011 ":" gcc "/lib"))
1012 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
1013 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
1014 #t)))
1015 (delete 'install2)))
1016 ((#:configure-flags configure-flags)
1017 `(let ((out (assoc-ref %outputs "out"))
1018 (glibc (assoc-ref %build-inputs "libc")))
1019 (list (string-append "--prefix=" out)
1020 "--build=i686-unknown-linux-gnu"
1021 "--host=i686-unknown-linux-gnu"
1022
1023 (string-append "--with-native-system-header-dir=" glibc "/include")
1024 (string-append "--with-build-sysroot=" glibc "/include")
1025
1026 "--disable-bootstrap"
1027 "--disable-decimal-float"
1028 "--disable-libatomic"
1029 "--disable-libcilkrts"
1030 "--disable-libgomp"
1031 "--disable-libitm"
1032 "--disable-libmudflap"
1033 "--disable-libquadmath"
1034 "--disable-libsanitizer"
1035 "--disable-libssp"
1036 "--disable-libvtv"
1037 "--disable-lto"
1038 "--disable-lto-plugin"
1039 "--disable-multilib"
1040 "--disable-plugin"
1041 "--disable-threads"
1042 "--enable-languages=c,c++"
1043
1044 "--enable-static"
1045 ;; libstdc++.so: error: depends on 'libgcc_s.so.1', which cannot be found in RUNPATH ()
1046 "--disable-shared"
1047 "--enable-threads=single"
1048
1049 ;; No pre-compiled libstdc++ headers, to save space.
1050 "--disable-libstdcxx-pch"
1051
1052 ;; for libcpp ...
1053 "--disable-build-with-cxx")))))))
1054
1055 (define gcc-mesboot1-wrapper
1056 ;; We need this so gcc-mesboot1 can be used to create shared binaries that
1057 ;; have the correct interpreter, otherwise configuring gcc-mesboot using
1058 ;; --enable-shared will fail.
1059 (package
1060 (inherit gcc-mesboot1)
1061 (name "gcc-mesboot1-wrapper")
1062 (source #f)
1063 (inputs '())
1064 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1065 ("libc" ,glibc-mesboot)
1066 ("gcc" ,gcc-mesboot1)))
1067 (arguments
1068 `(#:implicit-inputs? #f
1069 #:guile ,%bootstrap-guile
1070 #:phases
1071 (modify-phases %standard-phases
1072 (delete 'unpack)
1073 (delete 'configure)
1074 (delete 'install)
1075 (replace 'build
1076 (lambda* (#:key outputs #:allow-other-keys)
1077 (let* ((out (assoc-ref outputs "out"))
1078 (bash (assoc-ref %build-inputs "bash"))
1079 (libc (assoc-ref %build-inputs "libc"))
1080 (gcc (assoc-ref %build-inputs "gcc"))
1081 (bin (string-append out "/bin")))
1082 (mkdir-p bin)
1083 (for-each
1084 (lambda (program)
1085 (let ((wrapper (string-append bin "/" program)))
1086 (with-output-to-file wrapper
1087 (lambda _
1088 (display (string-append "#! " bash "/bin/bash
1089 exec " gcc "/bin/" program
1090 " -Wl,--dynamic-linker"
1091 ;; also for x86_64-linux, we are still on i686-linux
1092 " -Wl," libc ,(glibc-dynamic-linker "i686-linux")
1093 " -Wl,--rpath"
1094 " -Wl," libc "/lib"
1095 " \"$@\"
1096 "))
1097 (chmod wrapper #o555)))))
1098 '(
1099 "gcc"
1100 "g++"
1101 "i686-unknown-linux-gnu-gcc"
1102 "i686-unknown-linux-gnu-g++"
1103 ))
1104 #t)))
1105 (replace 'check
1106 (lambda* (#:key outputs #:allow-other-keys)
1107 (let* ((out (assoc-ref outputs "out"))
1108 (bin (string-append out "/bin"))
1109 (program (string-append bin "/gcc")))
1110 (invoke program "--help")))))))))
1111
1112 (define glibc-headers-mesboot
1113 (package
1114 (inherit glibc-mesboot0)
1115 (name "glibc-headers-mesboot")
1116 (version "2.16.0")
1117 (source (bootstrap-origin
1118 (origin
1119 (method url-fetch)
1120 (uri (string-append "mirror://gnu/glibc/glibc-"
1121 version
1122 ".tar.gz"))
1123 (patches (search-patches "glibc-boot-2.16.0.patch"
1124 "glibc-bootstrap-system-2.16.0.patch"))
1125 (sha256
1126 (base32
1127 "0vlz4x6cgz7h54qq4528q526qlhnsjzbsvgc4iizn76cb0bfanx7")))))
1128 (native-inputs `(("binutils" ,binutils-mesboot)
1129 ("libc" ,glibc-mesboot0)
1130 ("gcc" ,gcc-mesboot1)
1131 ("headers" ,mesboot-headers)
1132
1133 ("bash" ,%bootstrap-coreutils&co)
1134 ("coreutils" ,%bootstrap-coreutils&co)
1135 ("diffutils" ,diffutils-mesboot)
1136 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1137 ("make" ,make-mesboot)))
1138
1139 (arguments
1140 (substitute-keyword-arguments (package-arguments glibc-mesboot0)
1141 ((#:configure-flags configure-flags)
1142 `(let ((out (assoc-ref %outputs "out"))
1143 (headers (assoc-ref %build-inputs "headers")))
1144 (list
1145 (string-append "--prefix=" out)
1146 "--disable-obsolete-rpc"
1147 "--host=i686-unknown-linux-gnu"
1148 (string-append "--with-headers=" headers "/include")
1149 "--enable-static-nss"
1150 "--with-pthread"
1151 "--without-cvs"
1152 "--without-gd"
1153 "--enable-add-ons=nptl")))
1154 ((#:make-flags make-flags)
1155 `(let ((bash (assoc-ref %build-inputs "bash")))
1156 (list (string-append "SHELL=" bash "/bin/sh")
1157 "install-bootstrap-headers=yes" "install-headers")))
1158 ((#:phases phases)
1159 `(modify-phases ,phases
1160 (replace 'setenv
1161 (lambda* (#:key outputs #:allow-other-keys)
1162 (let* ((out (assoc-ref outputs "out"))
1163 (headers (assoc-ref %build-inputs "headers"))
1164 (bash (assoc-ref %build-inputs "bash"))
1165 (coreutils (assoc-ref %build-inputs "coreutils"))
1166 (libc (assoc-ref %build-inputs "libc"))
1167 (gcc (assoc-ref %build-inputs "gcc"))
1168 (cppflags (string-append
1169 " -I " (getcwd) "/nptl/sysdeps/pthread/bits"
1170 " -D BOOTSTRAP_GLIBC=1"))
1171 (cflags (string-append " -L " (getcwd)
1172 " -L " libc "/lib")))
1173 (setenv "libc_cv_friendly_stddef" "yes")
1174 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1175 (setenv "SHELL" (getenv "CONFIG_SHELL"))
1176 (format (current-error-port) "CONFIG_SHELL=~s\n" (getenv "CONFIG_SHELL"))
1177
1178 (setenv "CPP" (string-append gcc "/bin/gcc -E " cppflags))
1179 (setenv "CC" (string-append gcc "/bin/gcc " cppflags cflags))
1180
1181 ;; avoid -fstack-protector
1182 (setenv "libc_cv_ssp" "false")
1183 (substitute* "configure"
1184 (("/bin/pwd") (string-append coreutils "/bin/pwd")))
1185 (setenv "C_INCLUDE_PATH" (string-append libc "/include"
1186 headers "/include"))
1187 (setenv "LIBRARY_PATH" (string-append libc "/lib"))
1188 #t)))
1189 (replace 'install
1190 (lambda* (#:key outputs make-flags #:allow-other-keys)
1191 (let ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1192 (out (assoc-ref outputs "out")))
1193 (apply invoke "make" make-flags)
1194 (copy-recursively kernel-headers out)
1195 #t)))
1196 (replace 'configure
1197 (lambda* (#:key configure-flags #:allow-other-keys)
1198 (format (current-error-port) "running ../configure ~a\n" (string-join configure-flags))
1199 (mkdir-p "build")
1200 (chdir "build")
1201 (apply invoke "../configure" configure-flags)))
1202 (add-after 'configure 'remove-sunrpc
1203 (lambda _
1204 (invoke "make" (string-append (getcwd) "/sysd-sorted" )
1205 (string-append "SHELL=" (getenv "CONFIG_SHELL")))
1206 (substitute* "sysd-sorted"
1207 ((" sunrpc") " ")
1208 ((" nis") " "))
1209 ;; 'rpcgen' needs native libc headers to be built.
1210 (substitute* "../Makefile"
1211 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1212 (substitute* "../Makeconfig"
1213 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))
1214 (substitute* "../elf/Makefile"
1215 (("^SHELL := /bin/sh") (string-append "SHELL := " (getenv "CONFIG_SHELL"))))))))))))
1216
1217 (define glibc-mesboot
1218 (package
1219 (inherit glibc-headers-mesboot)
1220 (name "glibc-mesboot")
1221 (native-inputs `(("binutils" ,binutils-mesboot)
1222 ("libc" ,glibc-mesboot0)
1223 ("headers" ,glibc-headers-mesboot)
1224 ("gcc" ,gcc-mesboot1)
1225
1226 ("bash" ,%bootstrap-coreutils&co)
1227 ("coreutils" ,%bootstrap-coreutils&co)
1228 ("diffutils" ,diffutils-mesboot)
1229 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1230 ("make" ,make-mesboot)))
1231
1232 (arguments
1233 `(#:validate-runpath? #f ; fails when using --enable-shared
1234 ,@(substitute-keyword-arguments (package-arguments glibc-headers-mesboot)
1235 ((#:make-flags make-flags)
1236 `(let ((bash (assoc-ref %build-inputs "bash")))
1237 (list (string-append "SHELL=" bash "/bin/sh"))))
1238 ((#:phases phases)
1239 `(modify-phases ,phases
1240 (replace 'install
1241 (lambda* (#:key outputs make-flags #:allow-other-keys)
1242 (let* ((kernel-headers (assoc-ref %build-inputs "kernel-headers"))
1243 (out (assoc-ref outputs "out"))
1244 (install-flags (cons "install" make-flags)))
1245 (apply invoke "make" install-flags)
1246 (copy-recursively kernel-headers out)
1247 #t))))))))
1248 (native-search-paths ;; FIXME: move to glibc-mesboot0
1249 ;; Use the language-specific variables rather than 'CPATH' because they
1250 ;; are equivalent to '-isystem' whereas 'CPATH' is equivalent to '-I'.
1251 ;; The intent is to allow headers that are in the search path to be
1252 ;; treated as "system headers" (headers exempt from warnings) just like
1253 ;; the typical /usr/include headers on an FHS system.
1254 (list (search-path-specification
1255 (variable "C_INCLUDE_PATH")
1256 (files '("include")))
1257 (search-path-specification
1258 (variable "CPLUS_INCLUDE_PATH")
1259 (files '("include")))
1260 (search-path-specification
1261 (variable "LIBRARY_PATH")
1262 (files '("lib")))))))
1263
1264 (define gcc-mesboot
1265 (package
1266 (inherit gcc-mesboot1)
1267 (name "gcc-mesboot")
1268 (version "4.9.4")
1269 (source (bootstrap-origin (package-source gcc-4.9)))
1270 (native-inputs `(("binutils" ,binutils-mesboot)
1271 ("gcc-wrapper" ,gcc-mesboot1-wrapper)
1272 ("gcc" ,gcc-mesboot1)
1273 ("libc" ,glibc-mesboot)
1274
1275 ("bash" ,%bootstrap-coreutils&co)
1276 ("coreutils" ,%bootstrap-coreutils&co)
1277 ("diffutils" ,diffutils-mesboot)
1278 ("kernel-headers" ,%bootstrap-linux-libre-headers)
1279 ("make" ,make-mesboot)))
1280 (arguments
1281 `(#:validate-runpath? #f
1282 ,@(substitute-keyword-arguments (package-arguments gcc-mesboot1)
1283 ((#:configure-flags configure-flags)
1284 `(let ((out (assoc-ref %outputs "out"))
1285 (glibc (assoc-ref %build-inputs "libc")))
1286 (list (string-append "--prefix=" out)
1287 "--build=i686-unknown-linux-gnu"
1288 "--host=i686-unknown-linux-gnu"
1289
1290 "--with-host-libstdcxx=-lsupc++"
1291
1292 (string-append "--with-native-system-header-dir=" glibc "/include")
1293 (string-append "--with-build-sysroot=" glibc "/include")
1294
1295 "--disable-bootstrap"
1296 "--disable-decimal-float"
1297 "--disable-libatomic"
1298 "--disable-libcilkrts"
1299 "--disable-libgomp"
1300 "--disable-libitm"
1301 "--disable-libmudflap"
1302 "--disable-libquadmath"
1303 "--disable-libsanitizer"
1304 "--disable-libssp"
1305 "--disable-libvtv"
1306 "--disable-lto"
1307 "--disable-lto-plugin"
1308 "--disable-multilib"
1309 "--disable-plugin"
1310 "--disable-threads"
1311 "--enable-languages=c,c++"
1312
1313 "--enable-static"
1314 "--enable-shared"
1315 "--enable-threads=single"
1316
1317 ;; No pre-compiled libstdc++ headers, to save space.
1318 "--disable-libstdcxx-pch"
1319
1320 ;; for libcpp ...
1321 "--disable-build-with-cxx")))
1322 ((#:phases phases)
1323 `(modify-phases ,phases
1324 (replace 'setenv
1325 (lambda* (#:key outputs #:allow-other-keys)
1326 (let* ((out (assoc-ref outputs "out"))
1327 (binutils (assoc-ref %build-inputs "binutils"))
1328 (bash (assoc-ref %build-inputs "bash"))
1329 (gcc (assoc-ref %build-inputs "gcc"))
1330 (glibc (assoc-ref %build-inputs "libc"))
1331 (kernel-headers (assoc-ref %build-inputs "kernel-headers")))
1332 (setenv "CONFIG_SHELL" (string-append bash "/bin/sh"))
1333 (setenv "C_INCLUDE_PATH" (string-append
1334 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.7.4/include"
1335 ":" kernel-headers "/include"
1336 ":" glibc "/include"
1337 ":" (getcwd) "/mpfr/src"))
1338 (setenv "CPLUS_INCLUDE_PATH" (string-append
1339 gcc "/lib/gcc-lib/i686-unknown-linux-gnu/4.7.4/include"
1340 ":" kernel-headers "/include"
1341 ":" glibc "/include"
1342 ":" (getcwd) "/mpfr/src"))
1343 (setenv "LIBRARY_PATH" (string-append glibc "/lib"
1344 ":" gcc "/lib"))
1345 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
1346 (format (current-error-port) "CPLUS_INCLUDE_PATH=~a\n" (getenv "CPLUS_INCLUDE_PATH"))
1347 (format (current-error-port) "LIBRARY_PATH=~a\n" (getenv "LIBRARY_PATH"))
1348 #t))))))))))
1349
1350 (define gcc-mesboot-wrapper
1351 ;; We need this so gcc-mesboot can be used to create shared binaries that
1352 ;; have the correct interpreter and runpath to libc.
1353 (package
1354 (inherit gcc-mesboot1-wrapper)
1355 (name "gcc-mesboot-wrapper")
1356 (version (package-version gcc-mesboot))
1357 (source #f)
1358 (inputs '())
1359 (native-inputs `(("bash" ,%bootstrap-coreutils&co)
1360 ("libc" ,glibc-mesboot)
1361 ("gcc" ,gcc-mesboot)))))
1362
1363 (define m4-mesboot
1364 (package
1365 (inherit m4)
1366 (name "m4-mesboot")
1367 (version "1.4")
1368 (source (origin
1369 (method url-fetch)
1370 (uri (string-append "mirror://gnu/m4/m4-"
1371 version ".tar.gz"))
1372 (sha256
1373 (base32
1374 "1f9bxj176kf3pvs350w2dfs8jgwhminywri5pyn01b11yc4yhsjw"))))
1375 (supported-systems '("i686-linux" "x86_64-linux"))
1376 (native-inputs `(("mes" ,mes-boot)
1377 ("tcc" ,tcc-boot)))
1378 (arguments
1379 `(#:phases
1380 (modify-phases %standard-phases
1381 (replace 'configure
1382 (lambda* (#:key outputs #:allow-other-keys)
1383 (let ((out (assoc-ref outputs "out")))
1384 (setenv "CONFIG_SHELL" (string-append
1385 (assoc-ref %build-inputs "bash")
1386 "/bin/sh"))
1387 (setenv "CC" "tcc -static")
1388 (setenv "CPP" "tcc -E")
1389 (invoke "./configure" (string-append "--prefix=" out))))))))))
1390
1391 (define (%bootstrap-inputs+toolchain)
1392 ;; The traditional bootstrap-inputs. For the i686-linux Reduced Binary Seed
1393 ;; the actual reduced set with bootstrapped toolchain.
1394 (match (%current-system)
1395 ((or "i686-linux" "x86_64-linux")
1396 `(("libc" ,glibc-mesboot)
1397 ("binutils" ,binutils-mesboot)
1398 ("gcc-wrapper" ,gcc-mesboot-wrapper)
1399 ("gcc" ,gcc-mesboot)
1400 ,@(fold alist-delete (%bootstrap-inputs)
1401 '("bootstrap-mescc-tools" "mes"))))
1402 (_
1403 (%bootstrap-inputs))))
1404
1405 (define gnu-make-boot0
1406 (package
1407 (inherit gnu-make)
1408 (source (bootstrap-origin (package-source gnu-make)))
1409 (name "make-boot0")
1410 (arguments
1411 `(#:guile ,%bootstrap-guile
1412 #:implicit-inputs? #f
1413 #:tests? #f ; cannot run "make check"
1414 ,@(substitute-keyword-arguments (package-arguments gnu-make)
1415 ((#:phases phases)
1416 `(modify-phases ,phases
1417 (replace 'build
1418 (lambda _
1419 (invoke "./build.sh")))
1420 (replace 'install
1421 (lambda* (#:key outputs #:allow-other-keys)
1422 (let* ((out (assoc-ref outputs "out"))
1423 (bin (string-append out "/bin")))
1424 (install-file "make" bin)
1425 #t))))))))
1426 (native-inputs '()) ; no need for 'pkg-config'
1427 (inputs (%bootstrap-inputs+toolchain))))
1428
1429 (define diffutils-boot0
1430 (package
1431 (inherit diffutils)
1432 (name "diffutils-boot0")
1433 (native-inputs `())
1434 (inputs
1435 `(("make" ,gnu-make-boot0)
1436 ,@(%bootstrap-inputs+toolchain)))
1437 (arguments
1438 `(#:tests? #f ; the test suite needs diffutils
1439 #:guile ,%bootstrap-guile
1440 #:implicit-inputs? #f
1441 ,@(package-arguments diffutils)))))
1442
1443 (define findutils-boot0
1444 (package
1445 (inherit findutils)
1446 (name "findutils-boot0")
1447 (source (bootstrap-origin (package-source findutils)))
1448 (inputs
1449 `(("make" ,gnu-make-boot0)
1450 ("diffutils" ,diffutils-boot0) ; for tests
1451 ,@(%bootstrap-inputs+toolchain)))
1452 (arguments
1453 `(#:implicit-inputs? #f
1454 #:guile ,%bootstrap-guile
1455
1456 ;; The build system assumes we have done a mistake when time_t is 32-bit
1457 ;; on a 64-bit system. Ignore that for our bootstrap toolchain.
1458 ,@(if (target-64bit?)
1459 (substitute-keyword-arguments (package-arguments findutils)
1460 ((#:configure-flags flags ''())
1461 `(cons "TIME_T_32_BIT_OK=yes"
1462 ,flags)))
1463 (package-arguments findutils))))))
1464
1465 (define file-boot0
1466 (package
1467 (inherit file)
1468 (source (bootstrap-origin (package-source file)))
1469 (name "file-boot0")
1470 (inputs
1471 `(("make" ,gnu-make-boot0)
1472 ,@(%bootstrap-inputs+toolchain)))
1473 (arguments
1474 `(#:implicit-inputs? #f
1475 #:guile ,%bootstrap-guile
1476 #:strip-binaries? #f
1477 #:validate-runpath? #f))))
1478
1479 (define (%boot0-inputs)
1480 `(("make" ,gnu-make-boot0)
1481 ("diffutils" ,diffutils-boot0)
1482 ("findutils" ,findutils-boot0)
1483 ("file" ,file-boot0)
1484 ,@(%bootstrap-inputs+toolchain)))
1485
1486 (define* (boot-triplet #:optional (system (%current-system)))
1487 ;; Return the triplet used to create the cross toolchain needed in the
1488 ;; first bootstrapping stage.
1489 (nix-system->gnu-triplet system "guix"))
1490
1491 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
1492 ;; toolchain actually targets the same OS and arch, but it has the advantage
1493 ;; of being independent of the libc and tools in
1494 ;; (%BOOTSTRAP-INPUTS+TOOLCHAIN), since GCC-BOOT0 (below) is built without any
1495 ;; reference to the target libc.
1496
1497 (define binutils-boot0
1498 (package
1499 (inherit binutils)
1500 (source (bootstrap-origin (package-source binutils)))
1501 (name "binutils-cross-boot0")
1502 (arguments
1503 `(#:guile ,%bootstrap-guile
1504 #:implicit-inputs? #f
1505
1506 #:modules ((guix build gnu-build-system)
1507 (guix build utils)
1508 (ice-9 ftw)) ; for 'scandir'
1509 #:phases (modify-phases %standard-phases
1510 (add-after 'install 'add-symlinks
1511 (lambda* (#:key outputs #:allow-other-keys)
1512 ;; The cross-gcc invokes 'as', 'ld', etc, without the
1513 ;; triplet prefix, so add symlinks.
1514 (let ((out (assoc-ref outputs "out"))
1515 (triplet-prefix (string-append ,(boot-triplet) "-")))
1516 (define (has-triplet-prefix? name)
1517 (string-prefix? triplet-prefix name))
1518 (define (remove-triplet-prefix name)
1519 (substring name (string-length triplet-prefix)))
1520 (with-directory-excursion (string-append out "/bin")
1521 (for-each (lambda (name)
1522 (symlink name (remove-triplet-prefix name)))
1523 (scandir "." has-triplet-prefix?)))
1524 #t))))
1525
1526 ,@(substitute-keyword-arguments (package-arguments binutils)
1527 ((#:configure-flags cf)
1528 `(cons ,(string-append "--target=" (boot-triplet))
1529 ,cf)))))
1530 (inputs (%boot0-inputs))))
1531
1532 (define libstdc++-boot0
1533 ;; GCC's libcc1 is always built as a shared library (the top-level
1534 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
1535 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
1536 ;; C++14 features missing in some of our bootstrap compilers.
1537 (let ((lib (make-libstdc++ gcc-4.9)))
1538 (package
1539 (inherit lib)
1540 (source (bootstrap-origin (package-source lib)))
1541 (name "libstdc++-boot0")
1542 (arguments
1543 `(#:guile ,%bootstrap-guile
1544 #:implicit-inputs? #f
1545
1546 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
1547 #:validate-runpath? #f
1548
1549 ,@(match (%current-system)
1550 ((or "i686-linux" "x86_64-linux")
1551 (substitute-keyword-arguments (package-arguments lib)
1552 ((#:phases phases)
1553 `(modify-phases ,phases
1554 (add-after 'unpack 'workaround-wrapper-bug
1555 ;; XXX: The crude gcc-cross-wrapper causes "g++ -v" to
1556 ;; fail, which in turn confuses the configure script.
1557 (lambda _
1558 (substitute* "libstdc++-v3/configure"
1559 (("g\\+\\+ -v") "true"))
1560 #t))))))
1561 (_ (package-arguments lib)))))
1562 (inputs (%boot0-inputs))
1563 (native-inputs '()))))
1564
1565 (define gcc-boot0
1566 (package
1567 (inherit gcc)
1568 (name "gcc-cross-boot0")
1569 (source (bootstrap-origin (package-source gcc)))
1570 (arguments
1571 `(#:guile ,%bootstrap-guile
1572 #:implicit-inputs? #f
1573 #:modules ((guix build gnu-build-system)
1574 (guix build utils)
1575 (ice-9 regex)
1576 (srfi srfi-1)
1577 (srfi srfi-26))
1578 ,@(substitute-keyword-arguments (package-arguments gcc)
1579 ((#:configure-flags flags)
1580 `(append (list ,(string-append "--target=" (boot-triplet))
1581
1582 ;; No libc yet.
1583 "--without-headers"
1584
1585 ;; Disable features not needed at this stage.
1586 "--disable-shared"
1587 "--enable-languages=c,c++"
1588
1589 ;; libstdc++ cannot be built at this stage
1590 ;; ("Link tests are not allowed after
1591 ;; GCC_NO_EXECUTABLES.").
1592 "--disable-libstdc++-v3"
1593
1594 "--disable-threads"
1595 "--disable-libmudflap"
1596 "--disable-libatomic"
1597 "--disable-libsanitizer"
1598 "--disable-libitm"
1599 "--disable-libgomp"
1600 "--disable-libmpx"
1601 "--disable-libcilkrts"
1602 "--disable-libvtv"
1603 "--disable-libssp"
1604 "--disable-libquadmath"
1605 "--disable-decimal-float")
1606 (remove (cut string-match
1607 "--(with-system-zlib|enable-languages.*)" <>)
1608 ,flags)))
1609 ((#:make-flags flags)
1610 `(let* ((libc (assoc-ref %build-inputs "libc"))
1611 (libc-native (or (assoc-ref %build-inputs "libc-native")
1612 libc)))
1613 `(,(string-append "LDFLAGS="
1614 "-Wl,-rpath=" libc-native "/lib "
1615 "-Wl,-dynamic-linker "
1616 "-Wl," libc-native ,(glibc-dynamic-linker
1617 (match (%current-system)
1618 ("x86_64-linux" "i686-linux")
1619 (_ (%current-system))))))))
1620 ((#:phases phases)
1621 `(modify-phases ,phases
1622 (add-after 'unpack 'unpack-gmp&co
1623 (lambda* (#:key inputs #:allow-other-keys)
1624 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
1625 (mpfr (assoc-ref %build-inputs "mpfr-source"))
1626 (mpc (assoc-ref %build-inputs "mpc-source")))
1627
1628 ;; To reduce the set of pre-built bootstrap inputs, build
1629 ;; GMP & co. from GCC.
1630 (for-each (lambda (source)
1631 (invoke "tar" "xvf" source))
1632 (list gmp mpfr mpc))
1633
1634 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
1635 ,@(map (lambda (lib)
1636 ;; Drop trailing letters, as gmp-6.0.0a unpacks
1637 ;; into gmp-6.0.0.
1638 `(symlink ,(string-trim-right
1639 (package-full-name lib "-")
1640 char-set:letter)
1641 ,(package-name lib)))
1642 (list gmp-6.0 mpfr mpc))
1643 #t)))
1644 ,(match (%current-system)
1645 ((or "i686-linux" "x86_64-linux")
1646 '(add-before 'configure 'fix-libcc1
1647 (lambda* (#:key inputs #:allow-other-keys)
1648 ;; libcc1.so NEEDs libgcc_s.so, so provide one here
1649 ;; to placate the 'validate-runpath' phase.
1650 (substitute* "libcc1/Makefile.in"
1651 (("la_LDFLAGS =")
1652 (string-append "la_LDFLAGS = -Wl,-rpath="
1653 (assoc-ref inputs "gcc") "/lib")))
1654 ;; XXX: "g++ -v" is broken (see also libstdc++ above).
1655 (substitute* "libcc1/configure"
1656 (("g\\+\\+ -v") "true"))
1657 #t)))
1658 (_ '(add-before 'configure 'return-true
1659 (lambda _ #t))))
1660 (add-after 'install 'symlink-libgcc_eh
1661 (lambda* (#:key outputs #:allow-other-keys)
1662 (let ((out (assoc-ref outputs "lib")))
1663 ;; Glibc wants to link against libgcc_eh, so provide
1664 ;; it.
1665 (with-directory-excursion
1666 (string-append out "/lib/gcc/"
1667 ,(boot-triplet)
1668 "/" ,(package-version gcc))
1669 (symlink "libgcc.a" "libgcc_eh.a"))
1670 #t))))))))
1671
1672 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
1673 ("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
1674 ("mpc-source" ,(bootstrap-origin (package-source mpc)))
1675 ("binutils-cross" ,binutils-boot0)
1676
1677 ;; The libstdc++ that libcc1 links against.
1678 ("libstdc++" ,libstdc++-boot0)
1679
1680 ;; Call it differently so that the builder can check whether
1681 ;; the "libc" input is #f.
1682 ("libc-native" ,@(assoc-ref (%boot0-inputs) "libc"))
1683 ,@(alist-delete "libc" (%boot0-inputs))))
1684
1685 ;; No need for the native-inputs to build the documentation at this stage.
1686 (native-inputs `())))
1687
1688 (define perl-boot0
1689 (package
1690 (inherit perl)
1691 (name "perl-boot0")
1692 (source (bootstrap-origin (package-source perl)))
1693 (inputs (%boot0-inputs))
1694 (arguments
1695 `(#:implicit-inputs? #f
1696 #:guile ,%bootstrap-guile
1697 #:validate-runpath? #f
1698
1699 ;; At the very least, this must not depend on GCC & co.
1700 #:disallowed-references ,(list %bootstrap-binutils)
1701
1702 ,@(substitute-keyword-arguments (package-arguments perl)
1703 ((#:phases phases)
1704 `(modify-phases ,phases
1705 ;; Pthread support is missing in the bootstrap compiler
1706 ;; (broken spec file), so disable it.
1707 (add-before 'configure 'disable-pthreads
1708 (lambda _
1709 (substitute* "Configure"
1710 (("^libswanted=(.*)pthread" _ before)
1711 (string-append "libswanted=" before)))
1712 #t))))
1713 ;; Do not configure with '-Dusethreads' since pthread
1714 ;; support is missing.
1715 ((#:configure-flags configure-flags)
1716 `(delete "-Dusethreads" ,configure-flags)))))))
1717
1718 (define m4-boot0
1719 (package
1720 (inherit m4)
1721 (name "m4-boot0")
1722 (source (bootstrap-origin (package-source m4)))
1723 (inputs (%boot0-inputs))
1724 (arguments
1725 `(#:guile ,%bootstrap-guile
1726 #:implicit-inputs? #f
1727 ,@(package-arguments m4)))))
1728
1729 (define bison-boot0
1730 ;; This Bison is needed to build MiG so we need it early in the process.
1731 ;; Recent versions of Linux-Libre headers also depend on this.
1732 (package
1733 (inherit bison)
1734 (name "bison-boot0")
1735 (propagated-inputs `(("m4" ,m4-boot0)))
1736 (native-inputs `(("perl" ,perl-boot0)))
1737 (inputs (%boot0-inputs)) ;remove Flex...
1738 (arguments
1739 `(#:tests? #f ;... and thus disable tests
1740 #:implicit-inputs? #f
1741 #:guile ,%bootstrap-guile
1742
1743 ;; Zero timestamps in liby.a; this must be done
1744 ;; explicitly here because the bootstrap Binutils don't
1745 ;; do that (default is "cru".)
1746 #:make-flags `("ARFLAGS=crD"
1747 ,,(match (%current-system)
1748 ;; ranlib: '-D': No such file
1749 ((or "i686-linux" "x86_64-linux")
1750 "RANLIB=ranlib")
1751 (_
1752 "RANLIB=ranlib -D"))
1753 "V=1")
1754
1755 ,@(package-arguments bison)))))
1756
1757 (define flex-boot0
1758 ;; This Flex is needed to build MiG as well as Linux-Libre headers.
1759 (package
1760 (inherit flex)
1761 (native-inputs `(("bison" ,bison-boot0)))
1762 (propagated-inputs `(("m4" ,m4-boot0)))
1763 (inputs (%boot0-inputs))
1764 (arguments
1765 `(#:implicit-inputs? #f
1766 #:guile ,%bootstrap-guile
1767 #:tests? #f))))
1768
1769 (define linux-libre-headers-boot0
1770 (mlambda ()
1771 "Return Linux-Libre header files for the bootstrap environment."
1772 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
1773 ;; between (gnu packages linux) and this module. Additionally, memoize
1774 ;; the result to play well with further memoization and code that relies
1775 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
1776 (package
1777 (inherit linux-libre-headers)
1778 (arguments
1779 `(#:guile ,%bootstrap-guile
1780 #:implicit-inputs? #f
1781 ,@(package-arguments linux-libre-headers)))
1782 (native-inputs
1783 `(("perl" ,perl-boot0)
1784
1785 ;; Flex and Bison are required since version 4.16.
1786 ("flex" ,flex-boot0)
1787 ("bison" ,bison-boot0)
1788 ,@(%boot0-inputs))))))
1789
1790 (define with-boot0
1791 (package-with-explicit-inputs %boot0-inputs
1792 %bootstrap-guile))
1793
1794 (define gnumach-headers-boot0
1795 (with-boot0 (package-with-bootstrap-guile gnumach-headers)))
1796
1797 (define mig-boot0
1798 (let* ((mig (package
1799 (inherit (package-with-bootstrap-guile mig))
1800 (native-inputs `(("bison" ,bison-boot0)
1801 ("flex" ,flex-boot0)))
1802 (inputs `(("flex" ,flex-boot0)))
1803 (arguments
1804 `(#:configure-flags
1805 `(,(string-append "LDFLAGS=-Wl,-rpath="
1806 (assoc-ref %build-inputs "flex") "/lib/")))))))
1807 (with-boot0 mig)))
1808
1809 (define hurd-headers-boot0
1810 (let ((hurd-headers (package (inherit hurd-headers)
1811 (native-inputs `(("mig" ,mig-boot0)))
1812 (inputs '()))))
1813 (with-boot0 (package-with-bootstrap-guile hurd-headers))))
1814
1815 (define hurd-minimal-boot0
1816 (let ((hurd-minimal (package (inherit hurd-minimal)
1817 (native-inputs `(("mig" ,mig-boot0)))
1818 (inputs '()))))
1819 (with-boot0 (package-with-bootstrap-guile hurd-minimal))))
1820
1821 (define hurd-core-headers-boot0
1822 (mlambda ()
1823 "Return the Hurd and Mach headers as well as initial Hurd libraries for
1824 the bootstrap environment."
1825 (package (inherit (package-with-bootstrap-guile hurd-core-headers))
1826 (arguments `(#:guile ,%bootstrap-guile
1827 ,@(package-arguments hurd-core-headers)))
1828 (inputs
1829 `(("gnumach-headers" ,gnumach-headers-boot0)
1830 ("hurd-headers" ,hurd-headers-boot0)
1831 ("hurd-minimal" ,hurd-minimal-boot0)
1832 ,@(%boot0-inputs))))))
1833
1834 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
1835 (match system
1836 ("i586-gnu" (hurd-core-headers-boot0))
1837 (_ (linux-libre-headers-boot0))))
1838
1839 (define texinfo-boot0
1840 ;; Texinfo used to build libc's manual.
1841 ;; We build without ncurses because it fails to build at this stage, and
1842 ;; because we don't need the stand-alone Info reader.
1843 ;; Also, use (%BOOT0-INPUTS) to avoid building Perl once more.
1844 (package
1845 (inherit texinfo)
1846 (native-inputs '())
1847 (inputs `(,@(%boot0-inputs)
1848 ("perl" ,perl-boot0)))
1849 (arguments
1850 `(#:implicit-inputs? #f
1851 #:guile ,%bootstrap-guile
1852
1853 ;; Some of Texinfo 6.1's tests would fail with "Couldn't set UTF-8
1854 ;; character type in locale" but we don't have a UTF-8 locale at this
1855 ;; stage, so skip them.
1856 #:tests? #f))))
1857
1858 (define expat-sans-tests
1859 (package
1860 (inherit expat)
1861 (inputs (%boot0-inputs))
1862 (arguments
1863 ;; XXX: Linking 'runtestscpp' fails with things like:
1864 ;;
1865 ;; ld: Dwarf Error: found dwarf version '3789', this reader only handles version 2 and 3 information.
1866 ;;
1867 ;; Skip tests altogether.
1868 `(#:implicit-inputs? #f
1869 #:guile ,%bootstrap-guile
1870
1871 ,@(substitute-keyword-arguments (package-arguments expat)
1872 ((#:configure-flags flags ''())
1873 ;; Since we're not passing the right -Wl,-rpath flags, build the
1874 ;; static library to avoid RUNPATH validation failure.
1875 `(cons "--disable-shared" ,flags))
1876 ((#:tests? _ #f) #f))))))
1877
1878 (define python-boot0
1879 (package
1880 (inherit python-minimal)
1881 ;; We cannot use Python 3.7 and later here, because they require
1882 ;; pthreads, which is missing on non-x86 platforms at this stage.
1883 ;; Python 3.6 technically supports being built without threading
1884 ;; support, but requires additional patches.
1885 (version "3.5.9")
1886 (source (bootstrap-origin
1887 (origin
1888 (method url-fetch)
1889 (uri (string-append "https://www.python.org/ftp/python/"
1890 version "/Python-" version ".tar.xz"))
1891 (sha256
1892 (base32
1893 "0jdh9pvx6m6lfz2liwvvhn7vks7qrysqgwn517fkpxb77b33fjn2"))
1894 (modules '((guix build utils)))
1895 (snippet
1896 '(begin
1897 ;; Delete the bundled copy of libexpat.
1898 (delete-file-recursively "Modules/expat")
1899 (substitute* "Modules/Setup.dist"
1900 ;; Link Expat instead of embedding the bundled one.
1901 (("^#pyexpat.*") "pyexpat pyexpat.c -lexpat\n"))
1902 #t)))))
1903 (inputs
1904 `(,@(%boot0-inputs)
1905 ("expat" ,expat-sans-tests))) ;remove OpenSSL, zlib, etc.
1906 (native-inputs '()) ;and pkg-config
1907 (arguments
1908 `(#:implicit-inputs? #f
1909 #:guile ,%bootstrap-guile
1910
1911 ,@(substitute-keyword-arguments (package-arguments python-minimal)
1912 ;; Disable features that cannot be built at this stage.
1913 ((#:configure-flags _ ''())
1914 `(list "--without-ensurepip"
1915 "--without-threads"))
1916 ;; Clear #:make-flags, such that changes to the regular
1917 ;; Python package won't interfere with this one.
1918 ((#:make-flags _ ''()) ''())
1919 ((#:phases phases)
1920 `(modify-phases ,phases
1921 (add-before 'configure 'disable-modules
1922 (lambda _
1923 (substitute* "setup.py"
1924 ;; Disable ctypes, since it requires libffi.
1925 (("extensions\\.append\\(ctypes\\)") "")
1926 ;; Prevent the 'ossaudiodev' extension from being
1927 ;; built, since it requires Linux headers.
1928 (("'linux', ") ""))
1929 #t))
1930 (delete 'set-TZDIR)))
1931 ((#:tests? _ #f) #f))))))
1932
1933 (define ld-wrapper-boot0
1934 (mlambda ()
1935 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
1936 ;; in their RUNPATH, otherwise validate-runpath will fail.
1937 (make-ld-wrapper "ld-wrapper-boot0"
1938 #:target boot-triplet
1939 #:binutils binutils-boot0
1940 #:guile %bootstrap-guile
1941 #:bash (car (assoc-ref (%boot0-inputs) "bash"))
1942 #:guile-for-build %bootstrap-guile)))
1943
1944 (define (%boot1-inputs)
1945 ;; 2nd stage inputs.
1946 `(("gcc" ,gcc-boot0)
1947 ("ld-wrapper-cross" ,(ld-wrapper-boot0))
1948 ("binutils-cross" ,binutils-boot0)
1949 ,@(alist-delete "binutils" (%boot0-inputs))))
1950
1951 (define glibc-final-with-bootstrap-bash
1952 ;; The final libc, "cross-built". If everything went well, the resulting
1953 ;; store path has no dependencies. Actually, the really-final libc is
1954 ;; built just below; the only difference is that this one uses the
1955 ;; bootstrap Bash.
1956 (package
1957 (inherit glibc)
1958 (name "glibc-intermediate")
1959 (source (bootstrap-origin (package-source glibc)))
1960 (arguments
1961 `(#:guile ,%bootstrap-guile
1962 #:implicit-inputs? #f
1963
1964 ,@(substitute-keyword-arguments (package-arguments glibc)
1965 ((#:configure-flags flags)
1966 `(append (list ,(string-append "--host=" (boot-triplet))
1967 ,(string-append "--build="
1968 (nix-system->gnu-triplet)))
1969 ,flags))
1970 ((#:phases phases)
1971 `(modify-phases ,phases
1972 (add-before 'configure 'pre-configure
1973 (lambda* (#:key inputs #:allow-other-keys)
1974 ;; Don't clobber CPATH with the bootstrap libc.
1975 (setenv "NATIVE_CPATH" (getenv "CPATH"))
1976 (unsetenv "CPATH")
1977
1978 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
1979 ,@(if (hurd-triplet? (%current-system))
1980 `((substitute* "libpthread/Makefile"
1981 (("LDLIBS-pthread.so =.*")
1982 (string-append "LDLIBS-pthread.so = "
1983 (assoc-ref %build-inputs "kernel-headers")
1984 "/lib/libihash.a\n"))))
1985 '())
1986
1987 ;; 'rpcgen' needs native libc headers to be built.
1988 (substitute* "sunrpc/Makefile"
1989 (("sunrpc-CPPFLAGS =.*" all)
1990 (string-append "CPATH = $(NATIVE_CPATH)\n"
1991 "export CPATH\n"
1992 all "\n")))
1993 #t)))))))
1994 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
1995 (native-inputs
1996 `(("bison" ,bison-boot0)
1997 ("texinfo" ,texinfo-boot0)
1998 ("perl" ,perl-boot0)
1999 ("python" ,python-boot0)))
2000 (inputs
2001 `( ;; The boot inputs. That includes the bootstrap libc. We don't want
2002 ;; it in $CPATH, hence the 'pre-configure' phase above.
2003 ,@(%boot1-inputs)
2004
2005 ;; A native MiG is needed to build Glibc on Hurd.
2006 ,@(if (hurd-triplet? (%current-system))
2007 `(("mig" ,mig-boot0))
2008 '())
2009
2010 ;; A native GCC is needed to build `cross-rpcgen'.
2011 ("native-gcc" ,@(assoc-ref (%boot0-inputs) "gcc"))
2012
2013 ;; Here, we use the bootstrap Bash, which is not satisfactory
2014 ;; because we don't want to depend on bootstrap tools.
2015 ("static-bash" ,@(assoc-ref (%boot0-inputs) "bash"))))))
2016
2017 (define (cross-gcc-wrapper gcc binutils glibc bash)
2018 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
2019 that makes it available under the native tool names."
2020 (package (inherit gcc)
2021 (name (string-append (package-name gcc) "-wrapped"))
2022 (source #f)
2023 (build-system trivial-build-system)
2024 (outputs '("out"))
2025 (arguments
2026 `(#:guile ,%bootstrap-guile
2027 #:modules ((guix build utils))
2028 #:builder (begin
2029 (use-modules (guix build utils))
2030
2031 (let* ((binutils (assoc-ref %build-inputs "binutils"))
2032 (gcc (assoc-ref %build-inputs "gcc"))
2033 (libc (assoc-ref %build-inputs "libc"))
2034 (bash (assoc-ref %build-inputs "bash"))
2035 (out (assoc-ref %outputs "out"))
2036 (bindir (string-append out "/bin"))
2037 (triplet ,(boot-triplet)))
2038 (define (wrap-program program)
2039 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
2040 ;; needs to be told where to find the crt files and
2041 ;; the dynamic linker.
2042 (call-with-output-file program
2043 (lambda (p)
2044 (format p "#!~a/bin/bash
2045 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
2046 bash
2047 gcc triplet program
2048 libc libc
2049 ,(glibc-dynamic-linker))))
2050
2051 (chmod program #o555))
2052
2053 (mkdir-p bindir)
2054 (with-directory-excursion bindir
2055 (for-each (lambda (tool)
2056 (symlink (string-append binutils "/bin/"
2057 triplet "-" tool)
2058 tool))
2059 '("ar" "ranlib"))
2060 (for-each wrap-program '("gcc" "g++")))
2061
2062 #t))))
2063 (native-inputs
2064 `(("binutils" ,binutils)
2065 ("gcc" ,gcc)
2066 ("libc" ,glibc)
2067 ("bash" ,bash)))
2068 (inputs '())))
2069
2070 (define gcc-boot0-intermediate-wrapped
2071 (mlambda ()
2072 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2073 ;; non-cross names.
2074 (cross-gcc-wrapper gcc-boot0 binutils-boot0
2075 glibc-final-with-bootstrap-bash
2076 (car (assoc-ref (%boot1-inputs) "bash")))))
2077
2078 (define static-bash-for-glibc
2079 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
2080 (package
2081 (inherit static-bash)
2082 (source (bootstrap-origin (package-source static-bash)))
2083 (inputs `(("gcc" ,(gcc-boot0-intermediate-wrapped))
2084 ("libc" ,glibc-final-with-bootstrap-bash)
2085 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
2086 ,@(fold alist-delete (%boot1-inputs)
2087 '("gcc" "libc"))))
2088 (arguments
2089 `(#:implicit-inputs? #f
2090 #:guile ,%bootstrap-guile
2091
2092 ,@(substitute-keyword-arguments (package-arguments static-bash)
2093 ((#:configure-flags flags '())
2094 ;; Add a '-L' flag so that the pseudo-cross-ld of
2095 ;; BINUTILS-BOOT0 can find libc.a.
2096 `(append ,flags
2097 (list (string-append "LDFLAGS=-static -L"
2098 (assoc-ref %build-inputs
2099 "libc:static")
2100 "/lib")))))))))
2101
2102 (define gettext-boot0
2103 ;; A minimal gettext used during bootstrap.
2104 (package
2105 (inherit gettext-minimal)
2106 (name "gettext-boot0")
2107 ;; Newer versions of GNU gettext depends on libxml2 and ncurses. To
2108 ;; simplify the dependency chain, we stick to this version here.
2109 (version "0.19.8.1")
2110 (source (origin
2111 (method url-fetch)
2112 (uri (string-append "mirror://gnu/gettext/gettext-"
2113 version ".tar.gz"))
2114 (sha256
2115 (base32
2116 "0hsw28f9q9xaggjlsdp2qmbp2rbd1mp0njzan2ld9kiqwkq2m57z"))))
2117 (inputs (%boot1-inputs)) ;zero dependencies
2118 (arguments
2119 `(#:implicit-inputs? #f
2120 #:guile ,%bootstrap-guile
2121 #:tests? #f
2122 #:phases (modify-phases %standard-phases
2123 ;; Build only the tools.
2124 (add-after 'unpack 'chdir
2125 (lambda _
2126 (chdir "gettext-tools")
2127 #t))
2128
2129 ;; Some test programs require pthreads, which we don't have.
2130 (add-before 'configure 'no-test-programs
2131 (lambda _
2132 (substitute* "tests/Makefile.in"
2133 (("^PROGRAMS =.*$")
2134 "PROGRAMS =\n"))
2135 #t)))))))
2136
2137 (define glibc-final
2138 ;; The final glibc, which embeds the statically-linked Bash built above.
2139 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
2140 (package/inherit
2141 glibc
2142 (name "glibc")
2143 (source (bootstrap-origin (package-source glibc)))
2144 (inputs `(("static-bash" ,static-bash-for-glibc)
2145 ,@(alist-delete
2146 "static-bash"
2147 (package-inputs glibc-final-with-bootstrap-bash))))
2148
2149 ;; This time we need 'msgfmt' to install all the libc.mo files.
2150 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
2151 ("gettext" ,gettext-boot0)))
2152
2153 (propagated-inputs
2154 (package-propagated-inputs glibc-final-with-bootstrap-bash))
2155
2156 ;; The final libc only refers to itself, but the 'debug' output contains
2157 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
2158 ;; if 'allowed-references' were per-output.
2159 (arguments
2160 `(#:allowed-references
2161 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
2162 static-bash-for-glibc
2163 (package-outputs glibc-final-with-bootstrap-bash))
2164
2165 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
2166
2167 (define gcc-boot0-wrapped
2168 (mlambda ()
2169 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
2170 ;; non-cross names.
2171 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
2172 (car (assoc-ref (%boot1-inputs) "bash")))))
2173
2174 (define (%boot2-inputs)
2175 ;; 3rd stage inputs.
2176 `(("libc" ,glibc-final)
2177 ("libc:static" ,glibc-final "static")
2178 ("gcc" ,(gcc-boot0-wrapped))
2179 ,@(fold alist-delete (%boot1-inputs) '("libc" "gcc" "linux-libre-headers"))))
2180
2181 (define binutils-final
2182 (package
2183 (inherit binutils)
2184 (source (bootstrap-origin (package-source binutils)))
2185 (arguments
2186 `(#:guile ,%bootstrap-guile
2187 #:implicit-inputs? #f
2188 #:allowed-references ("out" ,glibc-final)
2189 ,@(package-arguments binutils)))
2190 (inputs (%boot2-inputs))))
2191
2192 (define libstdc++
2193 ;; Intermediate libstdc++ that will allow us to build the final GCC
2194 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
2195 (let ((lib (make-libstdc++ gcc)))
2196 (package
2197 (inherit lib)
2198 (source (bootstrap-origin (package-source lib)))
2199 (arguments
2200 `(#:guile ,%bootstrap-guile
2201 #:implicit-inputs? #f
2202 #:allowed-references ("out")
2203
2204 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
2205 #:validate-runpath? #f
2206
2207 ;; All of the package arguments from 'make-libstdc++
2208 ;; except for the configure-flags.
2209 ,@(package-arguments lib)
2210 #:configure-flags `("--disable-shared"
2211 "--disable-libstdcxx-dual-abi"
2212 "--disable-libstdcxx-threads"
2213 "--disable-libstdcxx-pch"
2214 ,(string-append "--with-gxx-include-dir="
2215 (assoc-ref %outputs "out")
2216 "/include"))))
2217 (outputs '("out"))
2218 (inputs (%boot2-inputs))
2219 (synopsis "GNU C++ standard library (intermediate)"))))
2220
2221 (define zlib-final
2222 ;; Zlib used by GCC-FINAL.
2223 (package
2224 (inherit zlib)
2225 (arguments
2226 `(#:guile ,%bootstrap-guile
2227 #:implicit-inputs? #f
2228 #:allowed-references ("out" ,glibc-final)
2229 ,@(package-arguments zlib)))
2230 (inputs (%boot2-inputs))))
2231
2232 (define ld-wrapper-boot3
2233 (mlambda ()
2234 ;; A linker wrapper that uses the bootstrap Guile.
2235 (make-ld-wrapper "ld-wrapper-boot3"
2236 #:binutils binutils-final
2237 #:guile %bootstrap-guile
2238 #:bash (car (assoc-ref (%boot2-inputs) "bash"))
2239 #:guile-for-build %bootstrap-guile)))
2240
2241 (define gcc-final
2242 ;; The final GCC.
2243 (package (inherit gcc-boot0)
2244 (name "gcc")
2245
2246 ;; XXX: Currently #:allowed-references applies to all the outputs but the
2247 ;; "debug" output contains disallowed references, notably
2248 ;; linux-libre-headers. Disable the debugging output to work around that.
2249 (outputs (delete "debug" (package-outputs gcc-boot0)))
2250
2251 (arguments
2252 `(#:guile ,%bootstrap-guile
2253 #:implicit-inputs? #f
2254
2255 #:allowed-references ("out" "lib" ,zlib-final
2256 ,glibc-final ,static-bash-for-glibc)
2257
2258 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
2259 ;; reason, but it is not in their RUNPATH. This is a false
2260 ;; positive, so turn it off.
2261 #:validate-runpath? #f
2262
2263 ,@(substitute-keyword-arguments (package-arguments gcc)
2264 ((#:make-flags flags)
2265 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
2266 `(let ((zlib (assoc-ref %build-inputs "zlib")))
2267 (map (lambda (flag)
2268 (if (string-prefix? "LDFLAGS=" flag)
2269 (string-append flag " -L"
2270 (assoc-ref %build-inputs "libstdc++")
2271 "/lib -L" zlib "/lib -Wl,-rpath="
2272 zlib "/lib")
2273 flag))
2274 ,flags)))
2275 ;; Build again GMP & co. within GCC's build process, because it's hard
2276 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
2277 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
2278 ((#:phases phases)
2279 `(modify-phases ,phases
2280 (add-after 'unpack 'unpack-gmp&co
2281 (lambda* (#:key inputs #:allow-other-keys)
2282 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
2283 (mpfr (assoc-ref %build-inputs "mpfr-source"))
2284 (mpc (assoc-ref %build-inputs "mpc-source")))
2285
2286 ;; To reduce the set of pre-built bootstrap inputs, build
2287 ;; GMP & co. from GCC.
2288 (for-each (lambda (source)
2289 (invoke "tar" "xvf" source))
2290 (list gmp mpfr mpc))
2291
2292 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
2293 ,@(map (lambda (lib)
2294 ;; Drop trailing letters, as gmp-6.0.0a unpacks
2295 ;; into gmp-6.0.0.
2296 `(symlink ,(string-trim-right
2297 (package-full-name lib "-")
2298 char-set:letter)
2299 ,(package-name lib)))
2300 (list gmp-6.0 mpfr mpc))
2301 #t)))
2302 (add-before 'configure 'treat-glibc-as-system-header
2303 (lambda* (#:key inputs #:allow-other-keys)
2304 (let ((libc (assoc-ref inputs "libc")))
2305 ;; Make sure Glibc is treated as a "system header" so
2306 ;; #include_next does the right thing.
2307 (for-each (lambda (var)
2308 (setenv var (string-append libc "/include")))
2309 '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
2310 #t))))))))
2311
2312 ;; This time we want Texinfo, so we get the manual. Add
2313 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
2314 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
2315 ;; scripts?).
2316 (native-inputs `(("texinfo" ,texinfo-boot0)
2317 ("perl" ,perl-boot0) ;for manpages
2318 ("static-bash" ,static-bash-for-glibc)
2319 ,@(package-native-inputs gcc-boot0)))
2320
2321 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
2322 ("mpfr-source" ,(package-source mpfr))
2323 ("mpc-source" ,(package-source mpc))
2324 ("ld-wrapper" ,(ld-wrapper-boot3))
2325 ("binutils" ,binutils-final)
2326 ("libstdc++" ,libstdc++)
2327 ("zlib" ,zlib-final)
2328 ,@(%boot2-inputs)))))
2329
2330 (define (%boot3-inputs)
2331 ;; 4th stage inputs.
2332 `(("gcc" ,gcc-final)
2333 ("ld-wrapper" ,(ld-wrapper-boot3))
2334 ,@(alist-delete "gcc" (%boot2-inputs))))
2335
2336 (define bash-final
2337 ;; Link with `-static-libgcc' to make sure we don't retain a reference
2338 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
2339 ;; on Readline and ncurses.
2340 (let ((bash (static-libgcc-package bash-minimal)))
2341 (package
2342 (inherit bash)
2343 (source (bootstrap-origin (package-source bash)))
2344 (inputs (%boot3-inputs))
2345 (arguments
2346 `(#:implicit-inputs? #f
2347 #:guile ,%bootstrap-guile
2348
2349 #:disallowed-references ,(assoc-ref (%boot3-inputs) "coreutils&co")
2350
2351 ,@(package-arguments bash))))))
2352
2353 (define (%boot4-inputs)
2354 ;; Now use the final Bash.
2355 `(("bash" ,bash-final)
2356 ,@(alist-delete "bash" (%boot3-inputs))))
2357
2358 (define with-boot4
2359 (package-with-explicit-inputs %boot4-inputs %bootstrap-guile))
2360
2361 (define-public guile-final
2362 ;; This package must be public because other modules refer to it. However,
2363 ;; mark it as hidden so that 'fold-packages' ignores it.
2364 (with-boot4 (hidden-package
2365 (package-with-bootstrap-guile guile-2.2/fixed))))
2366
2367 (define glibc-utf8-locales-final
2368 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
2369 ;; by the build processes afterwards so their 'scm_to_locale_string' works
2370 ;; with the full range of Unicode codepoints (remember
2371 ;; 'scm_to_locale_string' is called every time a string is passed to a C
2372 ;; function.)
2373 (package
2374 (inherit glibc-utf8-locales)
2375 (native-inputs
2376 `(("glibc" ,glibc-final)
2377 ("gzip" ,(with-boot4 gzip))))))
2378
2379 (define-public ld-wrapper
2380 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
2381 (make-ld-wrapper "ld-wrapper"
2382 #:binutils binutils-final
2383 #:guile guile-final
2384 #:bash bash-final))
2385
2386 (define (%boot5-inputs)
2387 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
2388 ;; with an older libc, which cannot load the new locale format. See
2389 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
2390 `(("locales" ,glibc-utf8-locales-final)
2391 ,@(%boot4-inputs)))
2392
2393 (define with-boot5
2394 (package-with-explicit-inputs %boot5-inputs))
2395
2396 (define gnu-make-final
2397 ;; The final GNU Make, which uses the final Guile.
2398 (let ((pkg-config (package
2399 (inherit %pkg-config) ;the native pkg-config
2400 (inputs `(("guile" ,guile-final)
2401 ,@(%boot5-inputs)))
2402 (arguments
2403 `(#:implicit-inputs? #f
2404 ,@(package-arguments pkg-config))))))
2405 (package
2406 (inherit (package-with-bootstrap-guile gnu-make))
2407 (inputs `(("guile" ,guile-final)
2408 ,@(%boot5-inputs)))
2409 (native-inputs `(("pkg-config" ,pkg-config)))
2410 (arguments
2411 `(#:implicit-inputs? #f
2412 ,@(package-arguments gnu-make))))))
2413
2414
2415 (define coreutils-final
2416 ;; The final Coreutils. Treat them specially because some packages, such as
2417 ;; Findutils, keep a reference to the Coreutils they were built with.
2418 (with-boot5 (package-with-bootstrap-guile coreutils)
2419 ;; Use the final Guile, linked against the
2420 ;; final libc with working iconv, so that
2421 ;; 'substitute*' works well when touching
2422 ;; test files in Gettext.
2423 ))
2424
2425 (define grep-final
2426 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
2427 ;; built before gzip.
2428 (let ((grep (with-boot5 (package-with-bootstrap-guile grep))))
2429 (package/inherit grep
2430 (inputs (alist-delete "pcre" (package-inputs grep)))
2431 (native-inputs `(("perl" ,perl-boot0))))))
2432
2433 (define (%boot6-inputs)
2434 ;; Now use the final Coreutils.
2435 `(("coreutils" ,coreutils-final)
2436 ("grep" ,grep-final)
2437 ,@(%boot5-inputs)))
2438
2439 (define with-boot6
2440 (package-with-explicit-inputs %boot6-inputs))
2441
2442 (define sed-final
2443 ;; The final sed.
2444 (let ((sed (with-boot6 (package-with-bootstrap-guile sed))))
2445 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
2446
2447 (define-public %final-inputs
2448 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
2449 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
2450 ;; used for origins that have patches, thereby avoiding circular
2451 ;; dependencies.
2452 (let ((finalize (compose with-boot6
2453 package-with-bootstrap-guile)))
2454 `(,@(map (match-lambda
2455 ((name package)
2456 (list name (finalize package))))
2457 `(("tar" ,tar)
2458 ("gzip" ,gzip)
2459 ("bzip2" ,bzip2)
2460 ("xz" ,xz)
2461 ("file" ,file)
2462 ("diffutils" ,diffutils)
2463 ("patch" ,patch)
2464 ("findutils" ,findutils)
2465 ("gawk" ,gawk)))
2466 ("sed" ,sed-final)
2467 ("grep" ,grep-final)
2468 ("coreutils" ,coreutils-final)
2469 ("make" ,gnu-make-final)
2470 ("bash" ,bash-final)
2471 ("ld-wrapper" ,ld-wrapper)
2472 ("binutils" ,binutils-final)
2473 ("gcc" ,gcc-final)
2474 ("libc" ,glibc-final)
2475 ("libc:static" ,glibc-final "static")
2476 ("locales" ,glibc-utf8-locales-final))))
2477
2478 (define-public canonical-package
2479 (let ((name->package (fold (lambda (input result)
2480 (match input
2481 ((_ package . outputs)
2482 (vhash-cons (package-full-name package)
2483 package result))))
2484 vlist-null
2485 `(("guile" ,guile-final)
2486 ,@%final-inputs))))
2487 (lambda (package)
2488 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
2489 the implicit inputs of 'gnu-build-system', return that one, otherwise return
2490 PACKAGE.
2491
2492 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
2493 COREUTILS-FINAL vs. COREUTILS, etc."
2494 ;; XXX: This doesn't handle dependencies of the final inputs, such as
2495 ;; libunistring, GMP, etc.
2496 (match (vhash-assoc (package-full-name package) name->package)
2497 ((_ . canon)
2498 ;; In general we want CANON, except if we're cross-compiling: CANON
2499 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
2500 ;; process, with dependencies on things that cannot be
2501 ;; cross-compiled.
2502 (if (%current-target-system)
2503 package
2504 canon))
2505 (_ package)))))
2506
2507 \f
2508 ;;;
2509 ;;; GCC toolchain.
2510 ;;;
2511
2512 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
2513 ;; instantiated like this:
2514 ;;
2515 ;; (define-public gcc-glibc-2.27-toolchain
2516 ;; (make-gcc-toolchain gcc glibc-2.27))
2517
2518 (define* (make-gcc-toolchain gcc
2519 #:optional
2520 (libc #f))
2521 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
2522 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
2523 (libc (if libc libc glibc-final)))
2524 (package
2525 (name (string-append (package-name gcc) "-toolchain"))
2526 (version (package-version gcc))
2527 (source #f)
2528 (build-system trivial-build-system)
2529 (arguments
2530 '(#:modules ((guix build union))
2531 #:builder (begin
2532 (use-modules (ice-9 match)
2533 (srfi srfi-26)
2534 (guix build union))
2535
2536 (let ((out (assoc-ref %outputs "out")))
2537
2538 (match %build-inputs
2539 (((names . directories) ...)
2540 (union-build out directories)))
2541
2542 (union-build (assoc-ref %outputs "debug")
2543 (list (assoc-ref %build-inputs
2544 "libc-debug")))
2545 (union-build (assoc-ref %outputs "static")
2546 (list (assoc-ref %build-inputs
2547 "libc-static")))
2548 #t))))
2549
2550 (native-search-paths (package-native-search-paths gcc))
2551 (search-paths (package-search-paths gcc))
2552
2553 (license (package-license gcc))
2554 (synopsis "Complete GCC tool chain for C/C++ development")
2555 (description
2556 "This package provides a complete GCC tool chain for C/C++ development to
2557 be installed in user profiles. This includes GCC, as well as libc (headers and
2558 binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
2559 (home-page "https://gcc.gnu.org/")
2560 (outputs '("out" "debug" "static"))
2561
2562 ;; The main raison d'être of this "meta-package" is (1) to conveniently
2563 ;; install everything that we need, and (2) to make sure ld-wrapper comes
2564 ;; before Binutils' ld in the user's profile.
2565 (inputs `(("gcc" ,gcc)
2566 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
2567 ("binutils" ,binutils-final)
2568 ("libc" ,libc)
2569 ("libc-debug" ,libc "debug")
2570 ("libc-static" ,libc "static"))))))
2571
2572 (define-public gcc-toolchain
2573 (make-gcc-toolchain gcc-final))
2574
2575 (define-public gcc-toolchain-4.8
2576 (make-gcc-toolchain gcc-4.8))
2577
2578 (define-public gcc-toolchain-4.9
2579 (make-gcc-toolchain gcc-4.9))
2580
2581 (define-public gcc-toolchain-5
2582 (make-gcc-toolchain gcc-5))
2583
2584 (define-public gcc-toolchain-6
2585 (make-gcc-toolchain gcc-6))
2586
2587 (define-public gcc-toolchain-7
2588 gcc-toolchain)
2589
2590 (define-public gcc-toolchain-8
2591 (make-gcc-toolchain gcc-8))
2592
2593 (define-public gcc-toolchain-9
2594 (make-gcc-toolchain gcc-9))
2595
2596 ;; Provide the Fortran toolchain package only for the version of gfortran that
2597 ;; is used by Guix internally to build Fortran libraries, because combining
2598 ;; code compiled with different versions can cause problems.
2599
2600 (define-public gfortran-toolchain
2601 (package (inherit (make-gcc-toolchain gfortran))
2602 (synopsis "Complete GCC tool chain for Fortran development")
2603 (description "This package provides a complete GCC tool chain for
2604 Fortran development to be installed in user profiles. This includes
2605 gfortran, as well as libc (headers and binaries, plus debugging symbols
2606 in the @code{debug} output), and binutils.")))
2607
2608
2609 ;;; commencement.scm ends here