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