gnu: thc-ipv6: Update to 3.4-0.4bb7257.
[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>
ce27857f 6;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
bdb36958
LC
7;;;
8;;; This file is part of GNU Guix.
9;;;
10;;; GNU Guix is free software; you can redistribute it and/or modify it
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
15;;; GNU Guix is distributed in the hope that it will be useful, but
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23(define-module (gnu packages commencement)
24 #:use-module ((guix licenses)
25 #:select (gpl3+ lgpl2.0+ public-domain))
b2fd8f63 26 #:use-module (gnu packages)
bdb36958
LC
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages gcc)
2d5d63d7 31 #:use-module (gnu packages m4)
d75acc29 32 #:use-module (gnu packages indent)
c00a9fbf 33 #:use-module (gnu packages file)
bdb36958 34 #:use-module (gnu packages gawk)
2d5d63d7 35 #:use-module (gnu packages bison)
d75acc29 36 #:use-module (gnu packages flex)
bdb36958 37 #:use-module (gnu packages guile)
6162b95d 38 #:use-module (gnu packages gettext)
bdb36958
LC
39 #:use-module (gnu packages multiprecision)
40 #:use-module (gnu packages compression)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages linux)
d75acc29 43 #:use-module (gnu packages hurd)
bdb36958
LC
44 #:use-module (gnu packages texinfo)
45 #:use-module (gnu packages pkg-config)
46 #:use-module (guix packages)
47 #:use-module (guix download)
48 #:use-module (guix build-system gnu)
49 #:use-module (guix build-system trivial)
50 #:use-module (guix utils)
51 #:use-module (srfi srfi-1)
52 #:use-module (srfi srfi-26)
53 #:use-module (ice-9 vlist)
d75acc29
MR
54 #:use-module (ice-9 match)
55 #:use-module (ice-9 regex))
bdb36958
LC
56
57;;; Commentary:
58;;;
59;;; This is the commencement, this is where things start. Before the
60;;; commencement, of course, there's the 'bootstrap' module, which provides us
61;;; with the initial binaries. This module uses those bootstrap binaries to
62;;; actually build up the whole tool chain that make up the implicit inputs of
63;;; 'gnu-build-system'.
64;;;
65;;; To avoid circular dependencies, this module should not be imported
66;;; directly from anywhere.
67;;;
68;;; Code:
69
70(define gnu-make-boot0
71 (package-with-bootstrap-guile
72 (package (inherit gnu-make)
73 (name "make-boot0")
bdb36958
LC
74 (arguments
75 `(#:guile ,%bootstrap-guile
76 #:implicit-inputs? #f
77 #:tests? #f ; cannot run "make check"
78 ,@(substitute-keyword-arguments (package-arguments gnu-make)
79 ((#:phases phases)
8e5e8724
LC
80 `(modify-phases ,phases
81 (replace 'build
82 (lambda _
83 (zero? (system* "./build.sh"))))
84 (replace 'install
85 (lambda* (#:key outputs #:allow-other-keys)
86 (let* ((out (assoc-ref outputs "out"))
87 (bin (string-append out "/bin")))
712b62d8 88 (install-file "make" bin)))))))))
bdb36958
LC
89 (native-inputs '()) ; no need for 'pkg-config'
90 (inputs %bootstrap-inputs))))
91
92(define diffutils-boot0
93 (package-with-bootstrap-guile
94 (let ((p (package-with-explicit-inputs diffutils
95 `(("make" ,gnu-make-boot0)
96 ,@%bootstrap-inputs)
97 #:guile %bootstrap-guile)))
98 (package (inherit p)
09964b4f 99 (name "diffutils-boot0")
bdb36958
LC
100 (arguments `(#:tests? #f ; the test suite needs diffutils
101 ,@(package-arguments p)))))))
102
103(define findutils-boot0
104 (package-with-bootstrap-guile
09964b4f
LC
105 (package-with-explicit-inputs (package
106 (inherit findutils)
107 (name "findutils-boot0"))
bdb36958
LC
108 `(("make" ,gnu-make-boot0)
109 ("diffutils" ,diffutils-boot0) ; for tests
110 ,@%bootstrap-inputs)
111 (current-source-location)
112 #:guile %bootstrap-guile)))
113
c00a9fbf
MW
114(define file-boot0
115 (package-with-bootstrap-guile
f00b85ff
LC
116 (package-with-explicit-inputs (package
117 (inherit file)
09964b4f 118 (name "file-boot0"))
c00a9fbf
MW
119 `(("make" ,gnu-make-boot0)
120 ,@%bootstrap-inputs)
121 (current-source-location)
122 #:guile %bootstrap-guile)))
123
bdb36958
LC
124
125(define %boot0-inputs
126 `(("make" ,gnu-make-boot0)
127 ("diffutils" ,diffutils-boot0)
128 ("findutils" ,findutils-boot0)
c00a9fbf 129 ("file" ,file-boot0)
bdb36958
LC
130 ,@%bootstrap-inputs))
131
bdb36958
LC
132(define* (boot-triplet #:optional (system (%current-system)))
133 ;; Return the triplet used to create the cross toolchain needed in the
134 ;; first bootstrapping stage.
135 (nix-system->gnu-triplet system "guix"))
136
137;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
138;; toolchain actually targets the same OS and arch, but it has the advantage
139;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
140;; GCC-BOOT0 (below) is built without any reference to the target libc.
141
142(define binutils-boot0
143 (package-with-bootstrap-guile
45953b1f 144 (package (inherit binutils)
bdb36958
LC
145 (name "binutils-cross-boot0")
146 (arguments
147 `(#:guile ,%bootstrap-guile
148 #:implicit-inputs? #f
f8badf15
MW
149
150 #:modules ((guix build gnu-build-system)
151 (guix build utils)
152 (ice-9 ftw)) ; for 'scandir'
ac423120
EF
153 #:phases (modify-phases %standard-phases
154 (add-after 'install 'add-symlinks
155 (lambda* (#:key outputs #:allow-other-keys)
156 ;; The cross-gcc invokes 'as', 'ld', etc, without the
157 ;; triplet prefix, so add symlinks.
158 (let ((out (assoc-ref outputs "out"))
159 (triplet-prefix (string-append ,(boot-triplet) "-")))
160 (define (has-triplet-prefix? name)
161 (string-prefix? triplet-prefix name))
162 (define (remove-triplet-prefix name)
163 (substring name (string-length triplet-prefix)))
164 (with-directory-excursion (string-append out "/bin")
165 (for-each (lambda (name)
166 (symlink name (remove-triplet-prefix name)))
167 (scandir "." has-triplet-prefix?)))
168 #t))))
f8badf15 169
bdb36958
LC
170 ,@(substitute-keyword-arguments (package-arguments binutils)
171 ((#:configure-flags cf)
172 `(cons ,(string-append "--target=" (boot-triplet))
173 ,cf)))))
174 (inputs %boot0-inputs))))
175
b810a850
LC
176(define libstdc++-boot0
177 ;; GCC's libcc1 is always built as a shared library (the top-level
178 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
179 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
180 ;; C++14 features missing in our bootstrap compiler.
181 (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc-4.9))))
182 (package
183 (inherit lib)
184 (name "libstdc++-boot0")
185 (arguments
186 `(#:guile ,%bootstrap-guile
187 #:implicit-inputs? #f
188
189 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
190 #:validate-runpath? #f
191
192 ,@(package-arguments lib)))
193 (inputs %boot0-inputs)
194 (native-inputs '()))))
195
bdb36958
LC
196(define gcc-boot0
197 (package-with-bootstrap-guile
c92f1c0a 198 (package (inherit gcc)
bdb36958
LC
199 (name "gcc-cross-boot0")
200 (arguments
201 `(#:guile ,%bootstrap-guile
202 #:implicit-inputs? #f
203 #:modules ((guix build gnu-build-system)
204 (guix build utils)
205 (ice-9 regex)
206 (srfi srfi-1)
207 (srfi srfi-26))
c92f1c0a 208 ,@(substitute-keyword-arguments (package-arguments gcc)
bdb36958
LC
209 ((#:configure-flags flags)
210 `(append (list ,(string-append "--target=" (boot-triplet))
211
212 ;; No libc yet.
213 "--without-headers"
214
215 ;; Disable features not needed at this stage.
216 "--disable-shared"
217 "--enable-languages=c,c++"
218
219 ;; libstdc++ cannot be built at this stage
220 ;; ("Link tests are not allowed after
221 ;; GCC_NO_EXECUTABLES.").
222 "--disable-libstdc++-v3"
223
224 "--disable-threads"
225 "--disable-libmudflap"
226 "--disable-libatomic"
227 "--disable-libsanitizer"
228 "--disable-libitm"
229 "--disable-libgomp"
de4ac325
LC
230 "--disable-libcilkrts"
231 "--disable-libvtv"
bdb36958
LC
232 "--disable-libssp"
233 "--disable-libquadmath"
234 "--disable-decimal-float")
98bd851e
LC
235 (remove (cut string-match
236 "--(with-system-zlib|enable-languages.*)" <>)
bdb36958
LC
237 ,flags)))
238 ((#:phases phases)
239 `(alist-cons-after
240 'unpack 'unpack-gmp&co
241 (lambda* (#:key inputs #:allow-other-keys)
242 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
243 (mpfr (assoc-ref %build-inputs "mpfr-source"))
244 (mpc (assoc-ref %build-inputs "mpc-source")))
245
246 ;; To reduce the set of pre-built bootstrap inputs, build
247 ;; GMP & co. from GCC.
248 (for-each (lambda (source)
249 (or (zero? (system* "tar" "xvf" source))
250 (error "failed to unpack tarball"
251 source)))
252 (list gmp mpfr mpc))
253
254 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
255 ,@(map (lambda (lib)
256 ;; Drop trailing letters, as gmp-6.0.0a unpacks
257 ;; into gmp-6.0.0.
258 `(symlink ,(string-trim-right
259 (package-full-name lib)
260 char-set:letter)
261 ,(package-name lib)))
8309c389 262 (list gmp-6.0 mpfr mpc))))
bdb36958
LC
263 (alist-cons-after
264 'install 'symlink-libgcc_eh
265 (lambda* (#:key outputs #:allow-other-keys)
266 (let ((out (assoc-ref outputs "lib")))
267 ;; Glibc wants to link against libgcc_eh, so provide
268 ;; it.
269 (with-directory-excursion
270 (string-append out "/lib/gcc/"
271 ,(boot-triplet)
c92f1c0a 272 "/" ,(package-version gcc))
bdb36958
LC
273 (symlink "libgcc.a" "libgcc_eh.a"))))
274 ,phases))))))
275
8309c389 276 (inputs `(("gmp-source" ,(package-source gmp-6.0))
bdb36958
LC
277 ("mpfr-source" ,(package-source mpfr))
278 ("mpc-source" ,(package-source mpc))
279 ("binutils-cross" ,binutils-boot0)
280
b810a850
LC
281 ;; The libstdc++ that libcc1 links against.
282 ("libstdc++" ,libstdc++-boot0)
283
bdb36958
LC
284 ;; Call it differently so that the builder can check whether
285 ;; the "libc" input is #f.
286 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
9dee9e8f
LC
287 ,@(alist-delete "libc" %boot0-inputs)))
288
19d27131
MC
289 ;; No need for the native-inputs to build the documentation at this stage.
290 (native-inputs `()))))
bdb36958
LC
291
292(define perl-boot0
4de35074
LC
293 (let ((perl (package
294 (inherit perl)
09964b4f 295 (name "perl-boot0")
4de35074 296 (arguments
81cea47d
LC
297 ;; At the very least, this must not depend on GCC & co.
298 (let ((args `(#:disallowed-references
299 ,(list %bootstrap-binutils))))
300 (substitute-keyword-arguments (package-arguments perl)
301 ((#:phases phases)
302 `(modify-phases ,phases
303 ;; Pthread support is missing in the bootstrap compiler
304 ;; (broken spec file), so disable it.
305 (add-before 'configure 'disable-pthreads
306 (lambda _
307 (substitute* "Configure"
308 (("^libswanted=(.*)pthread" _ before)
156c0810
BW
309 (string-append "libswanted=" before)))))))
310 ;; Do not configure with '-Dusethreads' since pthread
311 ;; support is missing.
312 ((#:configure-flags configure-flags)
313 `(delete "-Dusethreads" ,configure-flags))))))))
81cea47d
LC
314 (package-with-bootstrap-guile
315 (package-with-explicit-inputs perl
316 %boot0-inputs
317 (current-source-location)
318 #:guile %bootstrap-guile))))
bdb36958 319
d75acc29
MR
320(define bison-boot0
321 ;; This Bison is needed to build MiG so we need it early in the process.
322 ;; It is also needed to rebuild Bash's parser, which is modified by
323 ;; its CVE patches. Remove it when it's no longer needed.
324 (let* ((m4 (package-with-bootstrap-guile
325 (package-with-explicit-inputs m4 %boot0-inputs
326 (current-source-location)
327 #:guile %bootstrap-guile)))
328 (bison (package (inherit bison)
329 (propagated-inputs `(("m4" ,m4)))
330 (inputs '()) ;remove Flex...
331 (arguments
332 '(#:tests? #f ;... and thus disable tests
333
334 ;; Zero timestamps in liby.a; this must be done
335 ;; explicitly here because the bootstrap Binutils don't
336 ;; do that (default is "cru".)
337 #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
338 "V=1"))))))
339 (package
340 (inherit (package-with-bootstrap-guile
341 (package-with-explicit-inputs bison %boot0-inputs
342 (current-source-location)
343 #:guile %bootstrap-guile)))
344 (native-inputs `(("perl" ,perl-boot0))))))
345
346(define flex-boot0
347 ;; This Flex is needed to build MiG.
348 (let* ((flex (package (inherit flex)
349 (native-inputs `(("bison" ,bison-boot0)))
350 (propagated-inputs `(("m4" ,m4)))
351 (inputs `(("indent" ,indent)))
352 (arguments '(#:tests? #f)))))
353 (package-with-bootstrap-guile
354 (package-with-explicit-inputs flex %boot0-inputs
355 (current-source-location)
356 #:guile %bootstrap-guile))))
357
bdb36958
LC
358(define (linux-libre-headers-boot0)
359 "Return Linux-Libre header files for the bootstrap environment."
360 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
361 ;; between (gnu packages linux) and this module.
362 (package-with-bootstrap-guile
363 (package (inherit linux-libre-headers)
364 (arguments `(#:guile ,%bootstrap-guile
365 #:implicit-inputs? #f
366 ,@(package-arguments linux-libre-headers)))
367 (native-inputs
368 `(("perl" ,perl-boot0)
369 ,@%boot0-inputs)))))
370
d75acc29
MR
371(define gnumach-headers-boot0
372 (package-with-bootstrap-guile
373 (package-with-explicit-inputs gnumach-headers
374 %boot0-inputs
375 (current-source-location)
376 #:guile %bootstrap-guile)))
377
378(define mig-boot0
379 (let* ((mig (package (inherit mig)
380 (native-inputs `(("bison" ,bison-boot0)
381 ("flex" ,flex-boot0)))
382 (inputs `(("flex" ,flex-boot0)))
383 (arguments
384 `(#:configure-flags
385 `(,(string-append "LDFLAGS=-Wl,-rpath="
386 (assoc-ref %build-inputs "flex") "/lib/")))))))
387 (package-with-bootstrap-guile
388 (package-with-explicit-inputs mig %boot0-inputs
389 (current-source-location)
390 #:guile %bootstrap-guile))))
391
392(define hurd-headers-boot0
393 (let ((hurd-headers (package (inherit hurd-headers)
394 (native-inputs `(("mig" ,mig-boot0)))
395 (inputs '()))))
396 (package-with-bootstrap-guile
397 (package-with-explicit-inputs hurd-headers %boot0-inputs
398 (current-source-location)
399 #:guile %bootstrap-guile))))
400
401(define hurd-minimal-boot0
402 (let ((hurd-minimal (package (inherit hurd-minimal)
403 (native-inputs `(("mig" ,mig-boot0)))
404 (inputs '()))))
405 (package-with-bootstrap-guile
406 (package-with-explicit-inputs hurd-minimal %boot0-inputs
407 (current-source-location)
408 #:guile %bootstrap-guile))))
409
410(define (hurd-core-headers-boot0)
411 "Return the Hurd and Mach headers as well as initial Hurd libraries for
412the bootstrap environment."
413 (package-with-bootstrap-guile
414 (package (inherit hurd-core-headers)
415 (arguments `(#:guile ,%bootstrap-guile
416 ,@(package-arguments hurd-core-headers)))
417 (inputs
418 `(("gnumach-headers" ,gnumach-headers-boot0)
419 ("hurd-headers" ,hurd-headers-boot0)
420 ("hurd-minimal" ,hurd-minimal-boot0)
421 ,@%boot0-inputs)))))
422
423(define* (kernel-headers-boot0 #:optional (system (%current-system)))
424 (match system
425 ("i586-gnu" (hurd-core-headers-boot0))
426 (_ (linux-libre-headers-boot0))))
427
bdb36958
LC
428(define texinfo-boot0
429 ;; Texinfo used to build libc's manual.
430 ;; We build without ncurses because it fails to build at this stage, and
431 ;; because we don't need the stand-alone Info reader.
432 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
433 (let ((texinfo (package (inherit texinfo)
47ed8e04 434 (native-inputs '())
5d6c4d37
LC
435 (inputs `(("perl" ,perl-boot0)))
436
437 ;; Some of Texinfo 6.1's tests would fail with "Couldn't
438 ;; set UTF-8 character type in locale" but we don't have a
439 ;; UTF-8 locale at this stage, so skip them.
440 (arguments '(#:tests? #f)))))
bdb36958
LC
441 (package-with-bootstrap-guile
442 (package-with-explicit-inputs texinfo %boot0-inputs
443 (current-source-location)
444 #:guile %bootstrap-guile))))
445
d75acc29
MR
446(define ld-wrapper-boot0
447 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
448 ;; in their RUNPATH, otherwise validate-runpath will fail.
168c4000
LC
449 (make-ld-wrapper "ld-wrapper-boot0"
450 #:target boot-triplet
d75acc29
MR
451 #:binutils binutils-boot0
452 #:guile %bootstrap-guile
453 #:bash (car (assoc-ref %boot0-inputs "bash"))))
454
bdb36958
LC
455(define %boot1-inputs
456 ;; 2nd stage inputs.
457 `(("gcc" ,gcc-boot0)
d75acc29 458 ("ld-wrapper-cross" ,ld-wrapper-boot0)
bdb36958 459 ("binutils-cross" ,binutils-boot0)
f8badf15 460 ,@(alist-delete "binutils" %boot0-inputs)))
bdb36958
LC
461
462(define glibc-final-with-bootstrap-bash
463 ;; The final libc, "cross-built". If everything went well, the resulting
464 ;; store path has no dependencies. Actually, the really-final libc is
465 ;; built just below; the only difference is that this one uses the
466 ;; bootstrap Bash.
467 (package-with-bootstrap-guile
848f550f 468 (package (inherit glibc)
bdb36958
LC
469 (name "glibc-intermediate")
470 (arguments
471 `(#:guile ,%bootstrap-guile
472 #:implicit-inputs? #f
473
474 ,@(substitute-keyword-arguments (package-arguments glibc)
475 ((#:configure-flags flags)
476 `(append (list ,(string-append "--host=" (boot-triplet))
477 ,(string-append "--build="
478 (nix-system->gnu-triplet))
479
480 ;; Build Sun/ONC RPC support. In particular,
481 ;; install rpc/*.h.
482 "--enable-obsolete-rpc")
483 ,flags))
484 ((#:phases phases)
485 `(alist-cons-before
486 'configure 'pre-configure
487 (lambda* (#:key inputs #:allow-other-keys)
488 ;; Don't clobber CPATH with the bootstrap libc.
489 (setenv "NATIVE_CPATH" (getenv "CPATH"))
490 (unsetenv "CPATH")
491
d75acc29 492 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
62596a15 493 ,@(if (hurd-triplet? (%current-system))
d75acc29
MR
494 `((substitute* "libpthread/Makefile"
495 (("LDLIBS-pthread.so =.*")
496 (string-append "LDLIBS-pthread.so = "
497 (assoc-ref %build-inputs "kernel-headers")
498 "/lib/libihash.a\n"))))
499 '())
500
bdb36958
LC
501 ;; 'rpcgen' needs native libc headers to be built.
502 (substitute* "sunrpc/Makefile"
503 (("sunrpc-CPPFLAGS =.*" all)
504 (string-append "CPATH = $(NATIVE_CPATH)\n"
505 "export CPATH\n"
506 all "\n"))))
507 ,phases)))))
d75acc29 508 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
bdb36958
LC
509 (native-inputs
510 `(("texinfo" ,texinfo-boot0)
ff647c3d 511 ("perl" ,perl-boot0)))
bdb36958
LC
512 (inputs
513 `(;; The boot inputs. That includes the bootstrap libc. We don't want
514 ;; it in $CPATH, hence the 'pre-configure' phase above.
515 ,@%boot1-inputs
516
d75acc29 517 ;; A native MiG is needed to build Glibc on Hurd.
62596a15 518 ,@(if (hurd-triplet? (%current-system))
d75acc29
MR
519 `(("mig" ,mig-boot0))
520 '())
521
bdb36958
LC
522 ;; A native GCC is needed to build `cross-rpcgen'.
523 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
524
525 ;; Here, we use the bootstrap Bash, which is not satisfactory
526 ;; because we don't want to depend on bootstrap tools.
527 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
528
529(define (cross-gcc-wrapper gcc binutils glibc bash)
530 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
531that makes it available under the native tool names."
c92f1c0a 532 (package (inherit gcc)
bdb36958
LC
533 (name (string-append (package-name gcc) "-wrapped"))
534 (source #f)
535 (build-system trivial-build-system)
536 (outputs '("out"))
537 (arguments
538 `(#:guile ,%bootstrap-guile
539 #:modules ((guix build utils))
540 #:builder (begin
541 (use-modules (guix build utils))
542
543 (let* ((binutils (assoc-ref %build-inputs "binutils"))
544 (gcc (assoc-ref %build-inputs "gcc"))
545 (libc (assoc-ref %build-inputs "libc"))
546 (bash (assoc-ref %build-inputs "bash"))
547 (out (assoc-ref %outputs "out"))
548 (bindir (string-append out "/bin"))
549 (triplet ,(boot-triplet)))
550 (define (wrap-program program)
551 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
552 ;; needs to be told where to find the crt files and
553 ;; the dynamic linker.
554 (call-with-output-file program
555 (lambda (p)
556 (format p "#!~a/bin/bash
557exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
558 bash
559 gcc triplet program
560 libc libc
561 ,(glibc-dynamic-linker))))
562
563 (chmod program #o555))
564
565 (mkdir-p bindir)
566 (with-directory-excursion bindir
567 (for-each (lambda (tool)
568 (symlink (string-append binutils "/bin/"
569 triplet "-" tool)
570 tool))
571 '("ar" "ranlib"))
572 (for-each wrap-program '("gcc" "g++")))))))
573 (native-inputs
574 `(("binutils" ,binutils)
575 ("gcc" ,gcc)
576 ("libc" ,glibc)
577 ("bash" ,bash)))
578 (inputs '())))
579
580(define static-bash-for-glibc
90d891fc 581 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
bdb36958
LC
582 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
583 glibc-final-with-bootstrap-bash
584 (car (assoc-ref %boot1-inputs "bash"))))
6dff905e
LC
585 (bash (package
586 (inherit static-bash)
bdb36958 587 (arguments
6dff905e
LC
588 (substitute-keyword-arguments
589 (package-arguments static-bash)
590 ((#:guile _ #f)
591 '%bootstrap-guile)
592 ((#:configure-flags flags '())
593 ;; Add a '-L' flag so that the pseudo-cross-ld of
594 ;; BINUTILS-BOOT0 can find libc.a.
595 `(append ,flags
596 (list (string-append "LDFLAGS=-static -L"
597 (assoc-ref %build-inputs
598 "libc:static")
599 "/lib"))))))))
32243bfb
LC
600 (inputs `(("gcc" ,gcc)
601 ("libc" ,glibc-final-with-bootstrap-bash)
6dff905e 602 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
32243bfb
LC
603 ,@(fold alist-delete %boot1-inputs
604 '("gcc" "libc")))))
c573f5a5
LC
605 (package-with-bootstrap-guile
606 (package-with-explicit-inputs bash inputs
607 (current-source-location)
608 #:guile %bootstrap-guile))))
bdb36958 609
6162b95d
LC
610(define gettext-boot0
611 ;; A minimal gettext used during bootstrap.
669b8639 612 (let ((gettext-minimal
b94a6ca0 613 (package (inherit gettext-minimal)
669b8639
LC
614 (name "gettext-boot0")
615 (inputs '()) ;zero dependencies
616 (arguments
617 (substitute-keyword-arguments
618 `(#:tests? #f
b94a6ca0 619 ,@(package-arguments gettext-minimal))
669b8639
LC
620 ((#:phases phases)
621 `(modify-phases ,phases
622 ;; Build only the tools.
623 (add-after 'unpack 'chdir
624 (lambda _
625 (chdir "gettext-tools")))
626
627 ;; Some test programs require pthreads, which we don't have.
628 (add-before 'configure 'no-test-programs
629 (lambda _
630 (substitute* "tests/Makefile.in"
631 (("^PROGRAMS =.*$")
632 "PROGRAMS =\n"))
633 #t))
634
635 ;; Don't try to link against libexpat.
636 (delete 'link-expat)
637 (delete 'patch-tests))))))))
6162b95d
LC
638 (package-with-bootstrap-guile
639 (package-with-explicit-inputs gettext-minimal
640 %boot1-inputs
641 (current-source-location)
642 #:guile %bootstrap-guile))))
643
89223417 644(define glibc-final
bdb36958 645 ;; The final glibc, which embeds the statically-linked Bash built above.
848f550f 646 (package (inherit glibc-final-with-bootstrap-bash)
bdb36958
LC
647 (name "glibc")
648 (inputs `(("static-bash" ,static-bash-for-glibc)
649 ,@(alist-delete
650 "static-bash"
651 (package-inputs glibc-final-with-bootstrap-bash))))
652
6162b95d
LC
653 ;; This time we need 'msgfmt' to install all the libc.mo files.
654 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
655 ("gettext" ,gettext-boot0)))
656
bdb36958
LC
657 ;; The final libc only refers to itself, but the 'debug' output contains
658 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
659 ;; if 'allowed-references' were per-output.
660 (arguments
661 `(#:allowed-references
d75acc29 662 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
90d891fc 663 static-bash-for-glibc
bdb36958
LC
664 (package-outputs glibc-final-with-bootstrap-bash))
665
666 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
667
668(define gcc-boot0-wrapped
669 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
670 ;; non-cross names.
671 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
672 (car (assoc-ref %boot1-inputs "bash"))))
673
674(define %boot2-inputs
675 ;; 3rd stage inputs.
676 `(("libc" ,glibc-final)
6dff905e 677 ("libc:static" ,glibc-final "static")
bdb36958
LC
678 ("gcc" ,gcc-boot0-wrapped)
679 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
680
681(define binutils-final
682 (package-with-bootstrap-guile
45953b1f 683 (package (inherit binutils)
bdb36958
LC
684 (arguments
685 `(#:guile ,%bootstrap-guile
686 #:implicit-inputs? #f
687 #:allowed-references ("out" ,glibc-final)
688 ,@(package-arguments binutils)))
689 (inputs %boot2-inputs))))
690
691(define libstdc++
692 ;; Intermediate libstdc++ that will allow us to build the final GCC
693 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
86d02fa8
EF
694 (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc))))
695 (package
696 (inherit lib)
697 (arguments
698 `(#:guile ,%bootstrap-guile
699 #:implicit-inputs? #f
700 #:allowed-references ("out")
701
702 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
703 #:validate-runpath? #f
704
705 ;; All of the package arguments from 'make-libstdc++
706 ;; except for the configure-flags.
707 ,@(package-arguments lib)
708 #:configure-flags `("--disable-shared"
709 "--disable-libstdcxx-threads"
710 "--disable-libstdcxx-pch"
711 ,(string-append "--with-gxx-include-dir="
712 (assoc-ref %outputs "out")
713 "/include"))))
714 (outputs '("out"))
715 (inputs %boot2-inputs)
716 (synopsis "GNU C++ standard library (intermediate)"))))
bdb36958 717
98bd851e
LC
718(define zlib-final
719 ;; Zlib used by GCC-FINAL.
720 (package-with-bootstrap-guile
721 (package
722 (inherit zlib)
723 (arguments
724 `(#:guile ,%bootstrap-guile
725 #:implicit-inputs? #f
726 #:allowed-references ("out" ,glibc-final)
727 ,@(package-arguments zlib)))
728 (inputs %boot2-inputs))))
729
730(define ld-wrapper-boot3
731 ;; A linker wrapper that uses the bootstrap Guile.
732 (make-ld-wrapper "ld-wrapper-boot3"
733 #:binutils binutils-final
734 #:guile %bootstrap-guile
735 #:bash (car (assoc-ref %boot2-inputs "bash"))))
736
89223417 737(define gcc-final
bdb36958
LC
738 ;; The final GCC.
739 (package (inherit gcc-boot0)
740 (name "gcc")
ab999c25
LC
741
742 ;; XXX: Currently #:allowed-references applies to all the outputs but the
743 ;; "debug" output contains disallowed references, notably
744 ;; linux-libre-headers. Disable the debugging output to work around that.
745 (outputs (delete "debug" (package-outputs gcc-boot0)))
746
bdb36958
LC
747 (arguments
748 `(#:guile ,%bootstrap-guile
749 #:implicit-inputs? #f
750
98bd851e 751 #:allowed-references ("out" "lib" ,zlib-final
90d891fc 752 ,glibc-final ,static-bash-for-glibc)
bdb36958 753
d485ebba
LC
754 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
755 ;; reason, but it is not in their RUNPATH. This is a false
756 ;; positive, so turn it off.
757 #:validate-runpath? #f
758
bdb36958
LC
759 ;; Build again GMP & co. within GCC's build process, because it's hard
760 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
761 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
762 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
763 ((#:configure-flags boot-flags)
c92f1c0a 764 (let loop ((args (package-arguments gcc)))
bdb36958
LC
765 (match args
766 ((#:configure-flags normal-flags _ ...)
767 normal-flags)
768 ((_ rest ...)
769 (loop rest)))))
770 ((#:make-flags flags)
52cfd8cb 771 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
98bd851e
LC
772 `(let ((zlib (assoc-ref %build-inputs "zlib")))
773 (map (lambda (flag)
774 (if (string-prefix? "LDFLAGS=" flag)
775 (string-append flag " -L"
776 (assoc-ref %build-inputs "libstdc++")
777 "/lib -L" zlib "/lib -Wl,-rpath="
778 zlib "/lib")
779 flag))
780 ,flags)))
bdb36958
LC
781 ((#:phases phases)
782 `(alist-delete 'symlink-libgcc_eh ,phases)))))
783
90d891fc
LC
784 ;; This time we want Texinfo, so we get the manual. Add
785 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
786 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
787 ;; scripts?).
bdb36958 788 (native-inputs `(("texinfo" ,texinfo-boot0)
19d27131 789 ("perl" ,perl-boot0) ;for manpages
90d891fc 790 ("static-bash" ,static-bash-for-glibc)
bdb36958
LC
791 ,@(package-native-inputs gcc-boot0)))
792
8309c389 793 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
bdb36958
LC
794 ("mpfr-source" ,(package-source mpfr))
795 ("mpc-source" ,(package-source mpc))
98bd851e 796 ("ld-wrapper" ,ld-wrapper-boot3)
bdb36958
LC
797 ("binutils" ,binutils-final)
798 ("libstdc++" ,libstdc++)
98bd851e 799 ("zlib" ,zlib-final)
bdb36958
LC
800 ,@%boot2-inputs))))
801
bdb36958
LC
802(define %boot3-inputs
803 ;; 4th stage inputs.
804 `(("gcc" ,gcc-final)
805 ("ld-wrapper" ,ld-wrapper-boot3)
806 ,@(alist-delete "gcc" %boot2-inputs)))
807
808(define bash-final
809 ;; Link with `-static-libgcc' to make sure we don't retain a reference
704243e0
LC
810 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
811 ;; on Readline and ncurses.
d9b4cbc2 812 (let ((bash (package
704243e0 813 (inherit bash-minimal)
d9b4cbc2
LC
814 (arguments
815 `(#:disallowed-references
816 ,(assoc-ref %boot3-inputs "coreutils&co")
704243e0 817 ,@(package-arguments bash-minimal))))))
d9b4cbc2
LC
818 (package-with-bootstrap-guile
819 (package-with-explicit-inputs (static-libgcc-package bash)
820 %boot3-inputs
821 (current-source-location)
822 #:guile %bootstrap-guile))))
bdb36958
LC
823
824(define %boot4-inputs
825 ;; Now use the final Bash.
826 `(("bash" ,bash-final)
827 ,@(alist-delete "bash" %boot3-inputs)))
828
829(define-public guile-final
386b71d1
LC
830 ;; This package must be public because other modules refer to it. However,
831 ;; mark it as hidden so that 'fold-packages' ignores it.
bdb36958 832 (package-with-bootstrap-guile
34d624ce 833 (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
bdb36958
LC
834 %boot4-inputs
835 (current-source-location)
836 #:guile %bootstrap-guile)))
837
89223417 838(define glibc-utf8-locales-final
87c8b92f
LC
839 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
840 ;; by the build processes afterwards so their 'scm_to_locale_string' works
841 ;; with the full range of Unicode codepoints (remember
842 ;; 'scm_to_locale_string' is called every time a string is passed to a C
843 ;; function.)
844 (package
845 (inherit glibc-utf8-locales)
846 (inputs `(("glibc" ,glibc-final)
847 ("gzip"
848 ,(package-with-explicit-inputs gzip %boot4-inputs
849 (current-source-location)
850 #:guile %bootstrap-guile))))))
851
28cbc587
LC
852(define-public ld-wrapper
853 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
78dea6f1
LC
854 (make-ld-wrapper "ld-wrapper"
855 #:binutils binutils-final
856 #:guile guile-final
857 #:bash bash-final))
28cbc587 858
87c8b92f 859(define %boot5-inputs
b6ac5451
LC
860 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
861 ;; with an older libc, which cannot load the new locale format. See
28cbc587 862 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
b6ac5451
LC
863 `(("locales" ,glibc-utf8-locales-final)
864 ,@%boot4-inputs))
87c8b92f 865
bdb36958
LC
866(define gnu-make-final
867 ;; The final GNU Make, which uses the final Guile.
868 (package-with-bootstrap-guile
869 (package-with-explicit-inputs gnu-make
870 `(("guile" ,guile-final)
87c8b92f 871 ,@%boot5-inputs)
bdb36958
LC
872 (current-source-location))))
873
bdb36958
LC
874(define coreutils-final
875 ;; The final Coreutils. Treat them specially because some packages, such as
876 ;; Findutils, keep a reference to the Coreutils they were built with.
877 (package-with-bootstrap-guile
878 (package-with-explicit-inputs coreutils
87c8b92f 879 %boot5-inputs
bdb36958
LC
880 (current-source-location)
881
882 ;; Use the final Guile, linked against the
883 ;; final libc with working iconv, so that
884 ;; 'substitute*' works well when touching
885 ;; test files in Gettext.
886 #:guile guile-final)))
887
888(define grep-final
889 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
890 ;; built before gzip.
891 (package-with-bootstrap-guile
304e4f51
LC
892 (package-with-explicit-inputs (package
893 (inherit grep)
20bf5fce 894 (inputs '()) ;no PCRE support
304e4f51 895 (native-inputs `(("perl" ,perl-boot0))))
87c8b92f 896 %boot5-inputs
bdb36958
LC
897 (current-source-location)
898 #:guile guile-final)))
899
87c8b92f 900(define %boot6-inputs
bdb36958
LC
901 ;; Now use the final Coreutils.
902 `(("coreutils" ,coreutils-final)
903 ("grep" ,grep-final)
87c8b92f 904 ,@%boot5-inputs))
b0fd2bd3 905
bdb36958
LC
906(define-public %final-inputs
907 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
908 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
909 ;; used for origins that have patches, thereby avoiding circular
910 ;; dependencies.
911 (let ((finalize (compose package-with-bootstrap-guile
87c8b92f 912 (cut package-with-explicit-inputs <> %boot6-inputs
bdb36958
LC
913 (current-source-location)))))
914 `(,@(map (match-lambda
915 ((name package)
916 (list name (finalize package))))
917 `(("tar" ,tar)
87c8b92f 918 ("gzip" ,gzip)
bdb36958
LC
919 ("bzip2" ,bzip2)
920 ("xz" ,xz)
c00a9fbf 921 ("file" ,file)
bdb36958
LC
922 ("diffutils" ,diffutils)
923 ("patch" ,patch)
924 ("sed" ,sed)
925 ("findutils" ,findutils)
926 ("gawk" ,gawk)))
927 ("grep" ,grep-final)
928 ("coreutils" ,coreutils-final)
929 ("make" ,gnu-make-final)
930 ("bash" ,bash-final)
931 ("ld-wrapper" ,ld-wrapper)
932 ("binutils" ,binutils-final)
933 ("gcc" ,gcc-final)
b0fd2bd3 934 ("libc" ,glibc-final)
6dff905e 935 ("libc:static" ,glibc-final "static")
b0fd2bd3 936 ("locales" ,glibc-utf8-locales-final))))
bdb36958
LC
937
938(define-public canonical-package
939 (let ((name->package (fold (lambda (input result)
940 (match input
6dff905e 941 ((_ package . outputs)
bdb36958
LC
942 (vhash-cons (package-full-name package)
943 package result))))
944 vlist-null
945 `(("guile" ,guile-final)
946 ,@%final-inputs))))
947 (lambda (package)
948 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
949the implicit inputs of 'gnu-build-system', return that one, otherwise return
950PACKAGE.
951
34d624ce 952The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
bdb36958
LC
953COREUTILS-FINAL vs. COREUTILS, etc."
954 ;; XXX: This doesn't handle dependencies of the final inputs, such as
955 ;; libunistring, GMP, etc.
956 (match (vhash-assoc (package-full-name package) name->package)
957 ((_ . canon)
958 ;; In general we want CANON, except if we're cross-compiling: CANON
959 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
960 ;; process, with dependencies on things that cannot be
961 ;; cross-compiled.
962 (if (%current-target-system)
963 package
964 canon))
965 (_ package)))))
966
967\f
968;;;
969;;; GCC toolchain.
970;;;
971
b887ede1 972(define (make-gcc-toolchain gcc)
bdb36958
LC
973 "Return a complete toolchain for GCC."
974 (package
975 (name "gcc-toolchain")
976 (version (package-version gcc))
977 (source #f)
978 (build-system trivial-build-system)
979 (arguments
980 '(#:modules ((guix build union))
981 #:builder (begin
982 (use-modules (ice-9 match)
6f450b87 983 (srfi srfi-26)
bdb36958
LC
984 (guix build union))
985
6f450b87 986 (let ((out (assoc-ref %outputs "out")))
bdb36958 987
6f450b87
LC
988 (match %build-inputs
989 (((names . directories) ...)
990 (union-build out directories)))
991
6f450b87
LC
992 (union-build (assoc-ref %outputs "debug")
993 (list (assoc-ref %build-inputs
994 "libc-debug")))))))
d474d5d0
LC
995
996 (native-search-paths (package-native-search-paths gcc))
997 (search-paths (package-search-paths gcc))
998
bdb36958
LC
999 (license (package-license gcc))
1000 (synopsis "Complete GCC tool chain for C/C++ development")
1001 (description
1002 "This package provides a complete GCC tool chain for C/C++ development to
1003be installed in user profiles. This includes GCC, as well as libc (headers
1004and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
6fd52309 1005 (home-page "https://gcc.gnu.org/")
bdb36958
LC
1006 (outputs '("out" "debug"))
1007
1008 ;; The main raison d'être of this "meta-package" is (1) to conveniently
1009 ;; install everything that we need, and (2) to make sure ld-wrapper comes
1010 ;; before Binutils' ld in the user's profile.
1011 (inputs `(("gcc" ,gcc)
cbbb11c8 1012 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
bdb36958
LC
1013 ("binutils" ,binutils-final)
1014 ("libc" ,glibc-final)
1015 ("libc-debug" ,glibc-final "debug")))))
1016
1017(define-public gcc-toolchain-4.8
b887ede1 1018 (make-gcc-toolchain gcc-4.8))
bdb36958
LC
1019
1020(define-public gcc-toolchain-4.9
b887ede1
LC
1021 (make-gcc-toolchain gcc-4.9))
1022
1023(define-public gcc-toolchain
1024 (make-gcc-toolchain gcc-final))
bdb36958 1025
629f4d2e 1026(define-public gcc-toolchain-5
b887ede1 1027 gcc-toolchain)
60e2d5fe 1028
e760ec41 1029(define-public gcc-toolchain-6
b887ede1 1030 (make-gcc-toolchain gcc-6))
e760ec41 1031
d7ecab74 1032(define-public gcc-toolchain-7
b887ede1 1033 (make-gcc-toolchain gcc-7))
d7ecab74 1034
bdb36958 1035;;; commencement.scm ends here