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