1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
23 (define-module (gnu packages commencement)
24 #:use-module ((guix licenses)
25 #:select (gpl3+ lgpl2.0+ public-domain))
26 #:use-module (gnu packages)
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages m4)
32 #:use-module (gnu packages indent)
33 #:use-module (gnu packages file)
34 #:use-module (gnu packages gawk)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages flex)
37 #:use-module (gnu packages guile)
38 #:use-module (gnu packages gettext)
39 #:use-module (gnu packages multiprecision)
40 #:use-module (gnu packages compression)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages linux)
43 #:use-module (gnu packages hurd)
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)
54 #:use-module (ice-9 match)
55 #:use-module (ice-9 regex))
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'.
65 ;;; To avoid circular dependencies, this module should not be imported
66 ;;; directly from anywhere.
70 (define gnu-make-boot0
71 (package-with-bootstrap-guile
72 (package (inherit gnu-make)
75 `(#:guile ,%bootstrap-guile
77 #:tests? #f ; cannot run "make check"
78 ,@(substitute-keyword-arguments (package-arguments gnu-make)
80 `(modify-phases ,phases
83 (zero? (system* "./build.sh"))))
85 (lambda* (#:key outputs #:allow-other-keys)
86 (let* ((out (assoc-ref outputs "out"))
87 (bin (string-append out "/bin")))
88 (install-file "make" bin)))))))))
89 (native-inputs '()) ; no need for 'pkg-config'
90 (inputs %bootstrap-inputs))))
92 (define diffutils-boot0
93 (package-with-bootstrap-guile
94 (let ((p (package-with-explicit-inputs diffutils
95 `(("make" ,gnu-make-boot0)
97 #:guile %bootstrap-guile)))
99 (name "diffutils-boot0")
100 (arguments `(#:tests? #f ; the test suite needs diffutils
101 ,@(package-arguments p)))))))
103 (define findutils-boot0
104 (package-with-bootstrap-guile
105 (package-with-explicit-inputs (package
107 (name "findutils-boot0"))
108 `(("make" ,gnu-make-boot0)
109 ("diffutils" ,diffutils-boot0) ; for tests
111 (current-source-location)
112 #:guile %bootstrap-guile)))
115 (package-with-bootstrap-guile
116 (package-with-explicit-inputs (package/inherit file
118 `(("make" ,gnu-make-boot0)
120 (current-source-location)
121 #:guile %bootstrap-guile)))
124 (define %boot0-inputs
125 `(("make" ,gnu-make-boot0)
126 ("diffutils" ,diffutils-boot0)
127 ("findutils" ,findutils-boot0)
129 ,@%bootstrap-inputs))
131 (define* (boot-triplet #:optional (system (%current-system)))
132 ;; Return the triplet used to create the cross toolchain needed in the
133 ;; first bootstrapping stage.
134 (nix-system->gnu-triplet system "guix"))
136 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
137 ;; toolchain actually targets the same OS and arch, but it has the advantage
138 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
139 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
141 (define binutils-boot0
142 (package-with-bootstrap-guile
143 (package/inherit binutils
144 (name "binutils-cross-boot0")
146 `(#:guile ,%bootstrap-guile
147 #:implicit-inputs? #f
149 #:modules ((guix build gnu-build-system)
151 (ice-9 ftw)) ; for 'scandir'
152 #:phases (alist-cons-after
153 'install 'add-symlinks
154 (lambda* (#:key outputs #:allow-other-keys)
155 ;; The cross-gcc invokes 'as', 'ld', etc, without the
156 ;; triplet prefix, so add symlinks.
157 (let ((out (assoc-ref outputs "out"))
158 (triplet-prefix (string-append ,(boot-triplet) "-")))
159 (define (has-triplet-prefix? name)
160 (string-prefix? triplet-prefix name))
161 (define (remove-triplet-prefix name)
162 (substring name (string-length triplet-prefix)))
163 (with-directory-excursion (string-append out "/bin")
164 (for-each (lambda (name)
165 (symlink name (remove-triplet-prefix name)))
166 (scandir "." has-triplet-prefix?)))
170 ,@(substitute-keyword-arguments (package-arguments binutils)
171 ((#:configure-flags cf)
172 `(cons ,(string-append "--target=" (boot-triplet))
174 (inputs %boot0-inputs))))
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))))
184 (name "libstdc++-boot0")
186 `(#:guile ,%bootstrap-guile
187 #:implicit-inputs? #f
189 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
190 #:validate-runpath? #f
192 ,@(package-arguments lib)))
193 (inputs %boot0-inputs)
194 (native-inputs '()))))
197 (package-with-bootstrap-guile
198 (package (inherit gcc)
199 (name "gcc-cross-boot0")
201 `(#:guile ,%bootstrap-guile
202 #:implicit-inputs? #f
203 #:modules ((guix build gnu-build-system)
208 ,@(substitute-keyword-arguments (package-arguments gcc)
209 ((#:configure-flags flags)
210 `(append (list ,(string-append "--target=" (boot-triplet))
215 ;; Disable features not needed at this stage.
217 "--enable-languages=c,c++"
219 ;; libstdc++ cannot be built at this stage
220 ;; ("Link tests are not allowed after
221 ;; GCC_NO_EXECUTABLES.").
222 "--disable-libstdc++-v3"
225 "--disable-libmudflap"
226 "--disable-libatomic"
227 "--disable-libsanitizer"
230 "--disable-libcilkrts"
233 "--disable-libquadmath"
234 "--disable-decimal-float")
235 (remove (cut string-match
236 "--(with-system-zlib|enable-languages.*)" <>)
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")))
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"
254 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
256 ;; Drop trailing letters, as gmp-6.0.0a unpacks
258 `(symlink ,(string-trim-right
259 (package-full-name lib)
261 ,(package-name lib)))
262 (list gmp-6.0 mpfr mpc))))
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
269 (with-directory-excursion
270 (string-append out "/lib/gcc/"
272 "/" ,(package-version gcc))
273 (symlink "libgcc.a" "libgcc_eh.a"))))
276 (inputs `(("gmp-source" ,(package-source gmp-6.0))
277 ("mpfr-source" ,(package-source mpfr))
278 ("mpc-source" ,(package-source mpc))
279 ("binutils-cross" ,binutils-boot0)
281 ;; The libstdc++ that libcc1 links against.
282 ("libstdc++" ,libstdc++-boot0)
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"))
287 ,@(alist-delete "libc" %boot0-inputs)))
289 ;; No need for Texinfo at this stage.
290 (native-inputs (alist-delete "texinfo"
291 (package-native-inputs gcc))))))
298 ;; At the very least, this must not depend on GCC & co.
299 (let ((args `(#:disallowed-references
300 ,(list %bootstrap-binutils))))
301 (substitute-keyword-arguments (package-arguments perl)
303 `(modify-phases ,phases
304 ;; Pthread support is missing in the bootstrap compiler
305 ;; (broken spec file), so disable it.
306 (add-before 'configure 'disable-pthreads
308 (substitute* "Configure"
309 (("^libswanted=(.*)pthread" _ before)
310 (string-append "libswanted=" before)))))))
311 ;; Do not configure with '-Dusethreads' since pthread
312 ;; support is missing.
313 ((#:configure-flags configure-flags)
314 `(delete "-Dusethreads" ,configure-flags))))))))
315 (package-with-bootstrap-guile
316 (package-with-explicit-inputs perl
318 (current-source-location)
319 #:guile %bootstrap-guile))))
322 ;; This Bison is needed to build MiG so we need it early in the process.
323 ;; It is also needed to rebuild Bash's parser, which is modified by
324 ;; its CVE patches. Remove it when it's no longer needed.
325 (let* ((m4 (package-with-bootstrap-guile
326 (package-with-explicit-inputs m4 %boot0-inputs
327 (current-source-location)
328 #:guile %bootstrap-guile)))
329 (bison (package (inherit bison)
330 (propagated-inputs `(("m4" ,m4)))
331 (inputs '()) ;remove Flex...
333 '(#:tests? #f ;... and thus disable tests
335 ;; Zero timestamps in liby.a; this must be done
336 ;; explicitly here because the bootstrap Binutils don't
337 ;; do that (default is "cru".)
338 #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
341 (inherit (package-with-bootstrap-guile
342 (package-with-explicit-inputs bison %boot0-inputs
343 (current-source-location)
344 #:guile %bootstrap-guile)))
345 (native-inputs `(("perl" ,perl-boot0))))))
348 ;; This Flex is needed to build MiG.
349 (let* ((flex (package (inherit flex)
350 (native-inputs `(("bison" ,bison-boot0)))
351 (propagated-inputs `(("m4" ,m4)))
352 (inputs `(("indent" ,indent)))
353 (arguments '(#:tests? #f)))))
354 (package-with-bootstrap-guile
355 (package-with-explicit-inputs flex %boot0-inputs
356 (current-source-location)
357 #:guile %bootstrap-guile))))
359 (define (linux-libre-headers-boot0)
360 "Return Linux-Libre header files for the bootstrap environment."
361 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
362 ;; between (gnu packages linux) and this module.
363 (package-with-bootstrap-guile
364 (package (inherit linux-libre-headers)
365 (arguments `(#:guile ,%bootstrap-guile
366 #:implicit-inputs? #f
367 ,@(package-arguments linux-libre-headers)))
369 `(("perl" ,perl-boot0)
372 (define gnumach-headers-boot0
373 (package-with-bootstrap-guile
374 (package-with-explicit-inputs gnumach-headers
376 (current-source-location)
377 #:guile %bootstrap-guile)))
380 (let* ((mig (package (inherit mig)
381 (native-inputs `(("bison" ,bison-boot0)
382 ("flex" ,flex-boot0)))
383 (inputs `(("flex" ,flex-boot0)))
386 `(,(string-append "LDFLAGS=-Wl,-rpath="
387 (assoc-ref %build-inputs "flex") "/lib/")))))))
388 (package-with-bootstrap-guile
389 (package-with-explicit-inputs mig %boot0-inputs
390 (current-source-location)
391 #:guile %bootstrap-guile))))
393 (define hurd-headers-boot0
394 (let ((hurd-headers (package (inherit hurd-headers)
395 (native-inputs `(("mig" ,mig-boot0)))
397 (package-with-bootstrap-guile
398 (package-with-explicit-inputs hurd-headers %boot0-inputs
399 (current-source-location)
400 #:guile %bootstrap-guile))))
402 (define hurd-minimal-boot0
403 (let ((hurd-minimal (package (inherit hurd-minimal)
404 (native-inputs `(("mig" ,mig-boot0)))
406 (package-with-bootstrap-guile
407 (package-with-explicit-inputs hurd-minimal %boot0-inputs
408 (current-source-location)
409 #:guile %bootstrap-guile))))
411 (define (hurd-core-headers-boot0)
412 "Return the Hurd and Mach headers as well as initial Hurd libraries for
413 the bootstrap environment."
414 (package-with-bootstrap-guile
415 (package (inherit hurd-core-headers)
416 (arguments `(#:guile ,%bootstrap-guile
417 ,@(package-arguments hurd-core-headers)))
419 `(("gnumach-headers" ,gnumach-headers-boot0)
420 ("hurd-headers" ,hurd-headers-boot0)
421 ("hurd-minimal" ,hurd-minimal-boot0)
424 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
426 ("i586-gnu" (hurd-core-headers-boot0))
427 (_ (linux-libre-headers-boot0))))
429 (define texinfo-boot0
430 ;; Texinfo used to build libc's manual.
431 ;; We build without ncurses because it fails to build at this stage, and
432 ;; because we don't need the stand-alone Info reader.
433 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
434 (let ((texinfo (package (inherit texinfo)
436 (inputs `(("perl" ,perl-boot0)))
438 ;; Some of Texinfo 6.1's tests would fail with "Couldn't
439 ;; set UTF-8 character type in locale" but we don't have a
440 ;; UTF-8 locale at this stage, so skip them.
441 (arguments '(#:tests? #f)))))
442 (package-with-bootstrap-guile
443 (package-with-explicit-inputs texinfo %boot0-inputs
444 (current-source-location)
445 #:guile %bootstrap-guile))))
447 (define ld-wrapper-boot0
448 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
449 ;; in their RUNPATH, otherwise validate-runpath will fail.
450 (make-ld-wrapper "ld-wrapper-boot0"
451 #:target boot-triplet
452 #:binutils binutils-boot0
453 #:guile %bootstrap-guile
454 #:bash (car (assoc-ref %boot0-inputs "bash"))))
456 (define %boot1-inputs
459 ("ld-wrapper-cross" ,ld-wrapper-boot0)
460 ("binutils-cross" ,binutils-boot0)
461 ,@(alist-delete "binutils" %boot0-inputs)))
463 (define glibc-final-with-bootstrap-bash
464 ;; The final libc, "cross-built". If everything went well, the resulting
465 ;; store path has no dependencies. Actually, the really-final libc is
466 ;; built just below; the only difference is that this one uses the
468 (package-with-bootstrap-guile
469 (package/inherit glibc
470 (name "glibc-intermediate")
472 `(#:guile ,%bootstrap-guile
473 #:implicit-inputs? #f
475 ,@(substitute-keyword-arguments (package-arguments glibc)
476 ((#:configure-flags flags)
477 `(append (list ,(string-append "--host=" (boot-triplet))
478 ,(string-append "--build="
479 (nix-system->gnu-triplet))
481 ;; Build Sun/ONC RPC support. In particular,
483 "--enable-obsolete-rpc")
487 'configure 'pre-configure
488 (lambda* (#:key inputs #:allow-other-keys)
489 ;; Don't clobber CPATH with the bootstrap libc.
490 (setenv "NATIVE_CPATH" (getenv "CPATH"))
493 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
494 ,@(if (hurd-triplet? (%current-system))
495 `((substitute* "libpthread/Makefile"
496 (("LDLIBS-pthread.so =.*")
497 (string-append "LDLIBS-pthread.so = "
498 (assoc-ref %build-inputs "kernel-headers")
499 "/lib/libihash.a\n"))))
502 ;; 'rpcgen' needs native libc headers to be built.
503 (substitute* "sunrpc/Makefile"
504 (("sunrpc-CPPFLAGS =.*" all)
505 (string-append "CPATH = $(NATIVE_CPATH)\n"
509 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
511 `(("texinfo" ,texinfo-boot0)
512 ("perl" ,perl-boot0)))
514 `(;; The boot inputs. That includes the bootstrap libc. We don't want
515 ;; it in $CPATH, hence the 'pre-configure' phase above.
518 ;; A native MiG is needed to build Glibc on Hurd.
519 ,@(if (hurd-triplet? (%current-system))
520 `(("mig" ,mig-boot0))
523 ;; A native GCC is needed to build `cross-rpcgen'.
524 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
526 ;; Here, we use the bootstrap Bash, which is not satisfactory
527 ;; because we don't want to depend on bootstrap tools.
528 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
530 (define (cross-gcc-wrapper gcc binutils glibc bash)
531 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
532 that makes it available under the native tool names."
533 (package (inherit gcc)
534 (name (string-append (package-name gcc) "-wrapped"))
536 (build-system trivial-build-system)
539 `(#:guile ,%bootstrap-guile
540 #:modules ((guix build utils))
542 (use-modules (guix build utils))
544 (let* ((binutils (assoc-ref %build-inputs "binutils"))
545 (gcc (assoc-ref %build-inputs "gcc"))
546 (libc (assoc-ref %build-inputs "libc"))
547 (bash (assoc-ref %build-inputs "bash"))
548 (out (assoc-ref %outputs "out"))
549 (bindir (string-append out "/bin"))
550 (triplet ,(boot-triplet)))
551 (define (wrap-program program)
552 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
553 ;; needs to be told where to find the crt files and
554 ;; the dynamic linker.
555 (call-with-output-file program
557 (format p "#!~a/bin/bash
558 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
562 ,(glibc-dynamic-linker))))
564 (chmod program #o555))
567 (with-directory-excursion bindir
568 (for-each (lambda (tool)
569 (symlink (string-append binutils "/bin/"
573 (for-each wrap-program '("gcc" "g++")))))))
575 `(("binutils" ,binutils)
581 (define static-bash-for-glibc
582 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
583 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
584 glibc-final-with-bootstrap-bash
585 (car (assoc-ref %boot1-inputs "bash"))))
586 (bash (package (inherit static-bash)
588 `(#:guile ,%bootstrap-guile
589 ,@(package-arguments static-bash)))))
590 (inputs `(("gcc" ,gcc)
591 ("libc" ,glibc-final-with-bootstrap-bash)
592 ,@(fold alist-delete %boot1-inputs
594 (package-with-bootstrap-guile
595 (package-with-explicit-inputs bash inputs
596 (current-source-location)
597 #:guile %bootstrap-guile))))
599 (define gettext-boot0
600 ;; A minimal gettext used during bootstrap.
601 (let ((gettext-minimal
602 (package (inherit gettext-minimal)
603 (name "gettext-boot0")
604 (inputs '()) ;zero dependencies
606 (substitute-keyword-arguments
608 ,@(package-arguments gettext-minimal))
610 `(modify-phases ,phases
611 ;; Build only the tools.
612 (add-after 'unpack 'chdir
614 (chdir "gettext-tools")))
616 ;; Some test programs require pthreads, which we don't have.
617 (add-before 'configure 'no-test-programs
619 (substitute* "tests/Makefile.in"
624 ;; Don't try to link against libexpat.
626 (delete 'patch-tests))))))))
627 (package-with-bootstrap-guile
628 (package-with-explicit-inputs gettext-minimal
630 (current-source-location)
631 #:guile %bootstrap-guile))))
634 ;; The final glibc, which embeds the statically-linked Bash built above.
635 (package/inherit glibc-final-with-bootstrap-bash
637 (inputs `(("static-bash" ,static-bash-for-glibc)
640 (package-inputs glibc-final-with-bootstrap-bash))))
642 ;; This time we need 'msgfmt' to install all the libc.mo files.
643 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
644 ("gettext" ,gettext-boot0)))
646 ;; The final libc only refers to itself, but the 'debug' output contains
647 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
648 ;; if 'allowed-references' were per-output.
650 `(#:allowed-references
651 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
652 static-bash-for-glibc
653 (package-outputs glibc-final-with-bootstrap-bash))
655 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
657 (define gcc-boot0-wrapped
658 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
660 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
661 (car (assoc-ref %boot1-inputs "bash"))))
663 (define %boot2-inputs
665 `(("libc" ,glibc-final)
666 ("gcc" ,gcc-boot0-wrapped)
667 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
669 (define binutils-final
670 (package-with-bootstrap-guile
671 (package/inherit binutils
673 `(#:guile ,%bootstrap-guile
674 #:implicit-inputs? #f
675 #:allowed-references ("out" ,glibc-final)
676 ,@(package-arguments binutils)))
677 (inputs %boot2-inputs))))
680 ;; Intermediate libstdc++ that will allow us to build the final GCC
681 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
682 ;; TODO: Write in terms of 'make-libstdc++'.
683 (package-with-bootstrap-guile
684 (package (inherit gcc)
687 `(#:guile ,%bootstrap-guile
688 #:implicit-inputs? #f
689 #:allowed-references ("out")
691 #:phases (alist-cons-before
694 (chdir "libstdc++-v3"))
696 #:configure-flags `("--disable-shared"
697 "--disable-libstdcxx-threads"
698 "--disable-libstdcxx-pch"
699 ,(string-append "--with-gxx-include-dir="
700 (assoc-ref %outputs "out")
703 ;; ,(package-version gcc)
706 (inputs %boot2-inputs)
708 (propagated-inputs '())
709 (synopsis "GNU C++ standard library (intermediate)"))))
712 ;; Zlib used by GCC-FINAL.
713 (package-with-bootstrap-guile
717 `(#:guile ,%bootstrap-guile
718 #:implicit-inputs? #f
719 #:allowed-references ("out" ,glibc-final)
720 ,@(package-arguments zlib)))
721 (inputs %boot2-inputs))))
723 (define ld-wrapper-boot3
724 ;; A linker wrapper that uses the bootstrap Guile.
725 (make-ld-wrapper "ld-wrapper-boot3"
726 #:binutils binutils-final
727 #:guile %bootstrap-guile
728 #:bash (car (assoc-ref %boot2-inputs "bash"))))
732 (package (inherit gcc-boot0)
735 ;; XXX: Currently #:allowed-references applies to all the outputs but the
736 ;; "debug" output contains disallowed references, notably
737 ;; linux-libre-headers. Disable the debugging output to work around that.
738 (outputs (delete "debug" (package-outputs gcc-boot0)))
741 `(#:guile ,%bootstrap-guile
742 #:implicit-inputs? #f
744 #:allowed-references ("out" "lib" ,zlib-final
745 ,glibc-final ,static-bash-for-glibc)
747 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
748 ;; reason, but it is not in their RUNPATH. This is a false
749 ;; positive, so turn it off.
750 #:validate-runpath? #f
752 ;; Build again GMP & co. within GCC's build process, because it's hard
753 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
754 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
755 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
756 ((#:configure-flags boot-flags)
757 (let loop ((args (package-arguments gcc)))
759 ((#:configure-flags normal-flags _ ...)
763 ((#:make-flags flags)
764 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
765 `(let ((zlib (assoc-ref %build-inputs "zlib")))
767 (if (string-prefix? "LDFLAGS=" flag)
768 (string-append flag " -L"
769 (assoc-ref %build-inputs "libstdc++")
770 "/lib -L" zlib "/lib -Wl,-rpath="
775 `(alist-delete 'symlink-libgcc_eh ,phases)))))
777 ;; This time we want Texinfo, so we get the manual. Add
778 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
779 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
781 (native-inputs `(("texinfo" ,texinfo-boot0)
782 ("static-bash" ,static-bash-for-glibc)
783 ,@(package-native-inputs gcc-boot0)))
785 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
786 ("mpfr-source" ,(package-source mpfr))
787 ("mpc-source" ,(package-source mpc))
788 ("ld-wrapper" ,ld-wrapper-boot3)
789 ("binutils" ,binutils-final)
790 ("libstdc++" ,libstdc++)
794 (define %boot3-inputs
797 ("ld-wrapper" ,ld-wrapper-boot3)
798 ,@(alist-delete "gcc" %boot2-inputs)))
801 ;; Link with `-static-libgcc' to make sure we don't retain a reference
802 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
803 ;; on Readline and ncurses.
805 (inherit bash-minimal)
807 `(#:disallowed-references
808 ,(assoc-ref %boot3-inputs "coreutils&co")
809 ,@(package-arguments bash-minimal))))))
810 (package-with-bootstrap-guile
811 (package-with-explicit-inputs (static-libgcc-package bash)
813 (current-source-location)
814 #:guile %bootstrap-guile))))
816 (define %boot4-inputs
817 ;; Now use the final Bash.
818 `(("bash" ,bash-final)
819 ,@(alist-delete "bash" %boot3-inputs)))
821 (define-public guile-final
822 ;; This package must be public because other modules refer to it. However,
823 ;; mark it as hidden so that 'fold-packages' ignores it.
824 (package-with-bootstrap-guile
825 (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
827 (current-source-location)
828 #:guile %bootstrap-guile)))
830 (define glibc-utf8-locales-final
831 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
832 ;; by the build processes afterwards so their 'scm_to_locale_string' works
833 ;; with the full range of Unicode codepoints (remember
834 ;; 'scm_to_locale_string' is called every time a string is passed to a C
837 (inherit glibc-utf8-locales)
838 (inputs `(("glibc" ,glibc-final)
840 ,(package-with-explicit-inputs gzip %boot4-inputs
841 (current-source-location)
842 #:guile %bootstrap-guile))))))
844 (define-public ld-wrapper
845 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
846 (make-ld-wrapper "ld-wrapper"
847 #:binutils binutils-final
851 (define %boot5-inputs
852 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
853 ;; with an older libc, which cannot load the new locale format. See
854 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
855 `(("locales" ,glibc-utf8-locales-final)
858 (define gnu-make-final
859 ;; The final GNU Make, which uses the final Guile.
860 (package-with-bootstrap-guile
861 (package-with-explicit-inputs gnu-make
862 `(("guile" ,guile-final)
864 (current-source-location))))
866 (define coreutils-final
867 ;; The final Coreutils. Treat them specially because some packages, such as
868 ;; Findutils, keep a reference to the Coreutils they were built with.
869 (package-with-bootstrap-guile
870 (package-with-explicit-inputs coreutils
872 (current-source-location)
874 ;; Use the final Guile, linked against the
875 ;; final libc with working iconv, so that
876 ;; 'substitute*' works well when touching
877 ;; test files in Gettext.
878 #:guile guile-final)))
881 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
882 ;; built before gzip.
883 (package-with-bootstrap-guile
884 (package-with-explicit-inputs (package
886 (native-inputs `(("perl" ,perl-boot0))))
888 (current-source-location)
889 #:guile guile-final)))
891 (define %boot6-inputs
892 ;; Now use the final Coreutils.
893 `(("coreutils" ,coreutils-final)
897 (define-public %final-inputs
898 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
899 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
900 ;; used for origins that have patches, thereby avoiding circular
902 (let ((finalize (compose package-with-bootstrap-guile
903 (cut package-with-explicit-inputs <> %boot6-inputs
904 (current-source-location)))))
905 `(,@(map (match-lambda
907 (list name (finalize package))))
913 ("diffutils" ,diffutils)
916 ("findutils" ,findutils)
919 ("coreutils" ,coreutils-final)
920 ("make" ,gnu-make-final)
922 ("ld-wrapper" ,ld-wrapper)
923 ("binutils" ,binutils-final)
925 ("libc" ,glibc-final)
926 ("locales" ,glibc-utf8-locales-final))))
928 (define-public canonical-package
929 (let ((name->package (fold (lambda (input result)
932 (vhash-cons (package-full-name package)
935 `(("guile" ,guile-final)
938 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
939 the implicit inputs of 'gnu-build-system', return that one, otherwise return
942 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
943 COREUTILS-FINAL vs. COREUTILS, etc."
944 ;; XXX: This doesn't handle dependencies of the final inputs, such as
945 ;; libunistring, GMP, etc.
946 (match (vhash-assoc (package-full-name package) name->package)
948 ;; In general we want CANON, except if we're cross-compiling: CANON
949 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
950 ;; process, with dependencies on things that cannot be
952 (if (%current-target-system)
962 (define (gcc-toolchain gcc)
963 "Return a complete toolchain for GCC."
965 (name "gcc-toolchain")
966 (version (package-version gcc))
968 (build-system trivial-build-system)
970 '(#:modules ((guix build union))
972 (use-modules (ice-9 match)
976 (let ((out (assoc-ref %outputs "out")))
979 (((names . directories) ...)
980 (union-build out directories)))
982 (union-build (assoc-ref %outputs "debug")
983 (list (assoc-ref %build-inputs
986 (native-search-paths (package-native-search-paths gcc))
987 (search-paths (package-search-paths gcc))
989 (license (package-license gcc))
990 (synopsis "Complete GCC tool chain for C/C++ development")
992 "This package provides a complete GCC tool chain for C/C++ development to
993 be installed in user profiles. This includes GCC, as well as libc (headers
994 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
995 (home-page "https://gcc.gnu.org/")
996 (outputs '("out" "debug"))
998 ;; The main raison d'être of this "meta-package" is (1) to conveniently
999 ;; install everything that we need, and (2) to make sure ld-wrapper comes
1000 ;; before Binutils' ld in the user's profile.
1001 (inputs `(("gcc" ,gcc)
1002 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
1003 ("binutils" ,binutils-final)
1004 ("libc" ,glibc-final)
1005 ("libc-debug" ,glibc-final "debug")))))
1007 (define-public gcc-toolchain-4.8
1008 (gcc-toolchain gcc-4.8))
1010 (define-public gcc-toolchain-4.9
1011 (gcc-toolchain gcc-4.9))
1013 (define-public gcc-toolchain-5
1014 (gcc-toolchain gcc-final))
1016 (define-public gcc-toolchain-6
1017 (gcc-toolchain gcc-6))
1019 (define-public gcc-toolchain-7
1020 (gcc-toolchain gcc-7))
1022 ;;; commencement.scm ends here