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