gnu: commencement: Do not graft early bootstrap packages.
[guix.git] / gnu / packages / commencement.scm
blobc5c00688e4b4633af1d0e366462c5d907cee2495
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>
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/>.
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))
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:
70 (define gnu-make-boot0
71   (package-with-bootstrap-guile
72    (package (inherit gnu-make)
73      (name "make-boot0")
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)
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")))
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)
96                                             ,@%bootstrap-inputs)
97                                           #:guile %bootstrap-guile)))
98      (package (inherit p)
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
106                                    (inherit findutils)
107                                    (name "findutils-boot0"))
108                                  `(("make" ,gnu-make-boot0)
109                                    ("diffutils" ,diffutils-boot0) ; for tests
110                                    ,@%bootstrap-inputs)
111                                  (current-source-location)
112                                  #:guile %bootstrap-guile)))
114 (define file-boot0
115   (package-with-bootstrap-guile
116    (package-with-explicit-inputs (package
117                                    (inherit file)
118                                    (name "file-boot0"))
119                                  `(("make" ,gnu-make-boot0)
120                                    ,@%bootstrap-inputs)
121                                  (current-source-location)
122                                  #:guile %bootstrap-guile)))
125 (define %boot0-inputs
126   `(("make" ,gnu-make-boot0)
127     ("diffutils" ,diffutils-boot0)
128     ("findutils" ,findutils-boot0)
129     ("file" ,file-boot0)
130     ,@%bootstrap-inputs))
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"))
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.
142 (define binutils-boot0
143   (package-with-bootstrap-guile
144    (package (inherit binutils)
145      (name "binutils-cross-boot0")
146      (arguments
147       `(#:guile ,%bootstrap-guile
148         #:implicit-inputs? #f
150         #:modules ((guix build gnu-build-system)
151                    (guix build utils)
152                    (ice-9 ftw))                    ; for 'scandir'
153         #:phases (alist-cons-after
154                   '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))
169                   %standard-phases)
171         ,@(substitute-keyword-arguments (package-arguments binutils)
172             ((#:configure-flags cf)
173              `(cons ,(string-append "--target=" (boot-triplet))
174                     ,cf)))))
175      (inputs %boot0-inputs))))
177 (define libstdc++-boot0
178   ;; GCC's libcc1 is always built as a shared library (the top-level
179   ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
180   ;; to libstdc++.so.  We cannot build libstdc++-5.3 because it relies on
181   ;; C++14 features missing in our bootstrap compiler.
182   (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc-4.9))))
183     (package
184       (inherit lib)
185       (name "libstdc++-boot0")
186       (arguments
187        `(#:guile ,%bootstrap-guile
188          #:implicit-inputs? #f
190          ;; XXX: libstdc++.so NEEDs ld.so for some reason.
191          #:validate-runpath? #f
193          ,@(package-arguments lib)))
194       (inputs %boot0-inputs)
195       (native-inputs '()))))
197 (define gcc-boot0
198   (package-with-bootstrap-guile
199    (package (inherit gcc)
200      (name "gcc-cross-boot0")
201      (arguments
202       `(#:guile ,%bootstrap-guile
203         #:implicit-inputs? #f
204         #:modules ((guix build gnu-build-system)
205                    (guix build utils)
206                    (ice-9 regex)
207                    (srfi srfi-1)
208                    (srfi srfi-26))
209         ,@(substitute-keyword-arguments (package-arguments gcc)
210             ((#:configure-flags flags)
211              `(append (list ,(string-append "--target=" (boot-triplet))
213                             ;; No libc yet.
214                             "--without-headers"
216                             ;; Disable features not needed at this stage.
217                             "--disable-shared"
218                             "--enable-languages=c,c++"
220                             ;; libstdc++ cannot be built at this stage
221                             ;; ("Link tests are not allowed after
222                             ;; GCC_NO_EXECUTABLES.").
223                             "--disable-libstdc++-v3"
225                             "--disable-threads"
226                             "--disable-libmudflap"
227                             "--disable-libatomic"
228                             "--disable-libsanitizer"
229                             "--disable-libitm"
230                             "--disable-libgomp"
231                             "--disable-libcilkrts"
232                             "--disable-libvtv"
233                             "--disable-libssp"
234                             "--disable-libquadmath"
235                             "--disable-decimal-float")
236                       (remove (cut string-match
237                                 "--(with-system-zlib|enable-languages.*)" <>)
238                               ,flags)))
239             ((#:phases phases)
240              `(alist-cons-after
241                'unpack 'unpack-gmp&co
242                (lambda* (#:key inputs #:allow-other-keys)
243                  (let ((gmp  (assoc-ref %build-inputs "gmp-source"))
244                        (mpfr (assoc-ref %build-inputs "mpfr-source"))
245                        (mpc  (assoc-ref %build-inputs "mpc-source")))
247                    ;; To reduce the set of pre-built bootstrap inputs, build
248                    ;; GMP & co. from GCC.
249                    (for-each (lambda (source)
250                                (or (zero? (system* "tar" "xvf" source))
251                                    (error "failed to unpack tarball"
252                                           source)))
253                              (list gmp mpfr mpc))
255                    ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
256                    ,@(map (lambda (lib)
257                             ;; Drop trailing letters, as gmp-6.0.0a unpacks
258                             ;; into gmp-6.0.0.
259                             `(symlink ,(string-trim-right
260                                         (package-full-name lib)
261                                         char-set:letter)
262                                       ,(package-name lib)))
263                           (list gmp-6.0 mpfr mpc))))
264                (alist-cons-after
265                 'install 'symlink-libgcc_eh
266                 (lambda* (#:key outputs #:allow-other-keys)
267                   (let ((out (assoc-ref outputs "lib")))
268                     ;; Glibc wants to link against libgcc_eh, so provide
269                     ;; it.
270                     (with-directory-excursion
271                         (string-append out "/lib/gcc/"
272                                        ,(boot-triplet)
273                                        "/" ,(package-version gcc))
274                       (symlink "libgcc.a" "libgcc_eh.a"))))
275                 ,phases))))))
277      (inputs `(("gmp-source" ,(package-source gmp-6.0))
278                ("mpfr-source" ,(package-source mpfr))
279                ("mpc-source" ,(package-source mpc))
280                ("binutils-cross" ,binutils-boot0)
282                ;; The libstdc++ that libcc1 links against.
283                ("libstdc++" ,libstdc++-boot0)
285                ;; Call it differently so that the builder can check whether
286                ;; the "libc" input is #f.
287                ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
288                ,@(alist-delete "libc" %boot0-inputs)))
290      ;; No need for Texinfo at this stage.
291      (native-inputs (alist-delete "texinfo"
292                                   (package-native-inputs gcc))))))
294 (define perl-boot0
295   (let ((perl (package
296                 (inherit perl)
297                 (name "perl-boot0")
298                 (arguments
299                  ;; At the very least, this must not depend on GCC & co.
300                  (let ((args `(#:disallowed-references
301                                ,(list %bootstrap-binutils))))
302                    (substitute-keyword-arguments (package-arguments perl)
303                      ((#:phases phases)
304                       `(modify-phases ,phases
305                          ;; Pthread support is missing in the bootstrap compiler
306                          ;; (broken spec file), so disable it.
307                          (add-before 'configure 'disable-pthreads
308                            (lambda _
309                              (substitute* "Configure"
310                                (("^libswanted=(.*)pthread" _ before)
311                                 (string-append "libswanted=" before)))))))
312                      ;; Do not configure with '-Dusethreads' since pthread
313                      ;; support is missing.
314                      ((#:configure-flags configure-flags)
315                       `(delete "-Dusethreads" ,configure-flags))))))))
316     (package-with-bootstrap-guile
317      (package-with-explicit-inputs perl
318                                    %boot0-inputs
319                                    (current-source-location)
320                                    #:guile %bootstrap-guile))))
322 (define bison-boot0
323   ;; This Bison is needed to build MiG so we need it early in the process.
324   ;; It is also needed to rebuild Bash's parser, which is modified by
325   ;; its CVE patches.  Remove it when it's no longer needed.
326   (let* ((m4    (package-with-bootstrap-guile
327                  (package-with-explicit-inputs m4 %boot0-inputs
328                                                (current-source-location)
329                                                #:guile %bootstrap-guile)))
330          (bison (package (inherit bison)
331                   (propagated-inputs `(("m4" ,m4)))
332                   (inputs '())                    ;remove Flex...
333                   (arguments
334                    '(#:tests? #f                  ;... and thus disable tests
336                      ;; Zero timestamps in liby.a; this must be done
337                      ;; explicitly here because the bootstrap Binutils don't
338                      ;; do that (default is "cru".)
339                      #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
340                                     "V=1"))))))
341     (package
342       (inherit (package-with-bootstrap-guile
343                 (package-with-explicit-inputs bison %boot0-inputs
344                                               (current-source-location)
345                                               #:guile %bootstrap-guile)))
346       (native-inputs `(("perl" ,perl-boot0))))))
348 (define flex-boot0
349   ;; This Flex is needed to build MiG.
350   (let* ((flex (package (inherit flex)
351                  (native-inputs `(("bison" ,bison-boot0)))
352                  (propagated-inputs `(("m4" ,m4)))
353                  (inputs `(("indent" ,indent)))
354                  (arguments '(#:tests? #f)))))
355     (package-with-bootstrap-guile
356      (package-with-explicit-inputs flex %boot0-inputs
357                                    (current-source-location)
358                                    #:guile %bootstrap-guile))))
360 (define (linux-libre-headers-boot0)
361   "Return Linux-Libre header files for the bootstrap environment."
362   ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
363   ;; between (gnu packages linux) and this module.
364   (package-with-bootstrap-guile
365    (package (inherit linux-libre-headers)
366      (arguments `(#:guile ,%bootstrap-guile
367                   #:implicit-inputs? #f
368                   ,@(package-arguments linux-libre-headers)))
369      (native-inputs
370       `(("perl" ,perl-boot0)
371         ,@%boot0-inputs)))))
373 (define gnumach-headers-boot0
374   (package-with-bootstrap-guile
375    (package-with-explicit-inputs gnumach-headers
376                                  %boot0-inputs
377                                  (current-source-location)
378                                  #:guile %bootstrap-guile)))
380 (define mig-boot0
381   (let* ((mig (package (inherit mig)
382                  (native-inputs `(("bison" ,bison-boot0)
383                                   ("flex" ,flex-boot0)))
384                  (inputs `(("flex" ,flex-boot0)))
385                  (arguments
386                   `(#:configure-flags
387                     `(,(string-append "LDFLAGS=-Wl,-rpath="
388                                       (assoc-ref %build-inputs "flex") "/lib/")))))))
389     (package-with-bootstrap-guile
390      (package-with-explicit-inputs mig %boot0-inputs
391                                    (current-source-location)
392                                    #:guile %bootstrap-guile))))
394 (define hurd-headers-boot0
395   (let ((hurd-headers (package (inherit hurd-headers)
396                         (native-inputs `(("mig" ,mig-boot0)))
397                         (inputs '()))))
398     (package-with-bootstrap-guile
399      (package-with-explicit-inputs hurd-headers %boot0-inputs
400                                    (current-source-location)
401                                    #:guile %bootstrap-guile))))
403 (define hurd-minimal-boot0
404   (let ((hurd-minimal (package (inherit hurd-minimal)
405                         (native-inputs `(("mig" ,mig-boot0)))
406                         (inputs '()))))
407     (package-with-bootstrap-guile
408      (package-with-explicit-inputs hurd-minimal %boot0-inputs
409                                    (current-source-location)
410                                    #:guile %bootstrap-guile))))
412 (define (hurd-core-headers-boot0)
413   "Return the Hurd and Mach headers as well as initial Hurd libraries for
414 the bootstrap environment."
415   (package-with-bootstrap-guile
416    (package (inherit hurd-core-headers)
417             (arguments `(#:guile ,%bootstrap-guile
418                                  ,@(package-arguments hurd-core-headers)))
419             (inputs
420              `(("gnumach-headers" ,gnumach-headers-boot0)
421                ("hurd-headers" ,hurd-headers-boot0)
422                ("hurd-minimal" ,hurd-minimal-boot0)
423                ,@%boot0-inputs)))))
425 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
426   (match system
427     ("i586-gnu" (hurd-core-headers-boot0))
428     (_ (linux-libre-headers-boot0))))
430 (define texinfo-boot0
431   ;; Texinfo used to build libc's manual.
432   ;; We build without ncurses because it fails to build at this stage, and
433   ;; because we don't need the stand-alone Info reader.
434   ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
435   (let ((texinfo (package (inherit texinfo)
436                    (native-inputs '())
437                    (inputs `(("perl" ,perl-boot0)))
439                    ;; Some of Texinfo 6.1's tests would fail with "Couldn't
440                    ;; set UTF-8 character type in locale" but we don't have a
441                    ;; UTF-8 locale at this stage, so skip them.
442                    (arguments '(#:tests? #f)))))
443     (package-with-bootstrap-guile
444      (package-with-explicit-inputs texinfo %boot0-inputs
445                                    (current-source-location)
446                                    #:guile %bootstrap-guile))))
448 (define ld-wrapper-boot0
449   ;; We need this so binaries on Hurd will have libmachuser and libhurduser
450   ;; in their RUNPATH, otherwise validate-runpath will fail.
451   (make-ld-wrapper "ld-wrapper-boot0"
452                    #:target boot-triplet
453                    #:binutils binutils-boot0
454                    #:guile %bootstrap-guile
455                    #:bash (car (assoc-ref %boot0-inputs "bash"))))
457 (define %boot1-inputs
458   ;; 2nd stage inputs.
459   `(("gcc" ,gcc-boot0)
460     ("ld-wrapper-cross" ,ld-wrapper-boot0)
461     ("binutils-cross" ,binutils-boot0)
462     ,@(alist-delete "binutils" %boot0-inputs)))
464 (define glibc-final-with-bootstrap-bash
465   ;; The final libc, "cross-built".  If everything went well, the resulting
466   ;; store path has no dependencies.  Actually, the really-final libc is
467   ;; built just below; the only difference is that this one uses the
468   ;; bootstrap Bash.
469   (package-with-bootstrap-guile
470    (package/inherit glibc
471      (name "glibc-intermediate")
472      (arguments
473       `(#:guile ,%bootstrap-guile
474         #:implicit-inputs? #f
476         ,@(substitute-keyword-arguments (package-arguments glibc)
477             ((#:configure-flags flags)
478              `(append (list ,(string-append "--host=" (boot-triplet))
479                             ,(string-append "--build="
480                                             (nix-system->gnu-triplet))
482                             ;; Build Sun/ONC RPC support.  In particular,
483                             ;; install rpc/*.h.
484                             "--enable-obsolete-rpc")
485                       ,flags))
486             ((#:phases phases)
487              `(alist-cons-before
488                'configure 'pre-configure
489                (lambda* (#:key inputs #:allow-other-keys)
490                  ;; Don't clobber CPATH with the bootstrap libc.
491                  (setenv "NATIVE_CPATH" (getenv "CPATH"))
492                  (unsetenv "CPATH")
494                  ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
495                  ,@(if (hurd-triplet? (%current-system))
496                        `((substitute* "libpthread/Makefile"
497                            (("LDLIBS-pthread.so =.*")
498                             (string-append "LDLIBS-pthread.so = "
499                                            (assoc-ref %build-inputs "kernel-headers")
500                                            "/lib/libihash.a\n"))))
501                        '())
503                  ;; 'rpcgen' needs native libc headers to be built.
504                  (substitute* "sunrpc/Makefile"
505                    (("sunrpc-CPPFLAGS =.*" all)
506                     (string-append "CPATH = $(NATIVE_CPATH)\n"
507                                    "export CPATH\n"
508                                    all "\n"))))
509                ,phases)))))
510      (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
511      (native-inputs
512       `(("texinfo" ,texinfo-boot0)
513         ("perl" ,perl-boot0)))
514      (inputs
515       `(;; The boot inputs.  That includes the bootstrap libc.  We don't want
516         ;; it in $CPATH, hence the 'pre-configure' phase above.
517         ,@%boot1-inputs
519         ;; A native MiG is needed to build Glibc on Hurd.
520         ,@(if (hurd-triplet? (%current-system))
521               `(("mig" ,mig-boot0))
522               '())
524         ;; A native GCC is needed to build `cross-rpcgen'.
525         ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
527         ;; Here, we use the bootstrap Bash, which is not satisfactory
528         ;; because we don't want to depend on bootstrap tools.
529         ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
531 (define (cross-gcc-wrapper gcc binutils glibc bash)
532   "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
533 that makes it available under the native tool names."
534   (package (inherit gcc)
535     (name (string-append (package-name gcc) "-wrapped"))
536     (source #f)
537     (build-system trivial-build-system)
538     (outputs '("out"))
539     (arguments
540      `(#:guile ,%bootstrap-guile
541        #:modules ((guix build utils))
542        #:builder (begin
543                    (use-modules (guix build utils))
545                    (let* ((binutils (assoc-ref %build-inputs "binutils"))
546                           (gcc      (assoc-ref %build-inputs "gcc"))
547                           (libc     (assoc-ref %build-inputs "libc"))
548                           (bash     (assoc-ref %build-inputs "bash"))
549                           (out      (assoc-ref %outputs "out"))
550                           (bindir   (string-append out "/bin"))
551                           (triplet  ,(boot-triplet)))
552                      (define (wrap-program program)
553                        ;; GCC-BOOT0 is a libc-less cross-compiler, so it
554                        ;; needs to be told where to find the crt files and
555                        ;; the dynamic linker.
556                        (call-with-output-file program
557                          (lambda (p)
558                            (format p "#!~a/bin/bash
559 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
560                                    bash
561                                    gcc triplet program
562                                    libc libc
563                                    ,(glibc-dynamic-linker))))
565                        (chmod program #o555))
567                      (mkdir-p bindir)
568                      (with-directory-excursion bindir
569                        (for-each (lambda (tool)
570                                    (symlink (string-append binutils "/bin/"
571                                                            triplet "-" tool)
572                                             tool))
573                                  '("ar" "ranlib"))
574                        (for-each wrap-program '("gcc" "g++")))))))
575     (native-inputs
576      `(("binutils" ,binutils)
577        ("gcc" ,gcc)
578        ("libc" ,glibc)
579        ("bash" ,bash)))
580     (inputs '())))
582 (define static-bash-for-glibc
583   ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
584   (let* ((gcc  (cross-gcc-wrapper gcc-boot0 binutils-boot0
585                                   glibc-final-with-bootstrap-bash
586                                   (car (assoc-ref %boot1-inputs "bash"))))
587          (bash (package (inherit static-bash)
588                  (arguments
589                   `(#:guile ,%bootstrap-guile
590                     ,@(package-arguments static-bash)))))
591          (inputs `(("gcc" ,gcc)
592                    ("libc" ,glibc-final-with-bootstrap-bash)
593                    ,@(fold alist-delete %boot1-inputs
594                            '("gcc" "libc")))))
595     (package-with-bootstrap-guile
596      (package-with-explicit-inputs bash inputs
597                                    (current-source-location)
598                                    #:guile %bootstrap-guile))))
600 (define gettext-boot0
601   ;; A minimal gettext used during bootstrap.
602   (let ((gettext-minimal
603          (package (inherit gettext-minimal)
604            (name "gettext-boot0")
605            (inputs '())                           ;zero dependencies
606            (arguments
607             (substitute-keyword-arguments
608                 `(#:tests? #f
609                   ,@(package-arguments gettext-minimal))
610               ((#:phases phases)
611                `(modify-phases ,phases
612                   ;; Build only the tools.
613                   (add-after 'unpack 'chdir
614                              (lambda _
615                                (chdir "gettext-tools")))
617                   ;; Some test programs require pthreads, which we don't have.
618                   (add-before 'configure 'no-test-programs
619                               (lambda _
620                                 (substitute* "tests/Makefile.in"
621                                   (("^PROGRAMS =.*$")
622                                    "PROGRAMS =\n"))
623                                 #t))
625                   ;; Don't try to link against libexpat.
626                   (delete 'link-expat)
627                   (delete 'patch-tests))))))))
628     (package-with-bootstrap-guile
629      (package-with-explicit-inputs gettext-minimal
630                                    %boot1-inputs
631                                    (current-source-location)
632                                    #:guile %bootstrap-guile))))
634 (define glibc-final
635   ;; The final glibc, which embeds the statically-linked Bash built above.
636   (package/inherit glibc-final-with-bootstrap-bash
637     (name "glibc")
638     (inputs `(("static-bash" ,static-bash-for-glibc)
639               ,@(alist-delete
640                  "static-bash"
641                  (package-inputs glibc-final-with-bootstrap-bash))))
643     ;; This time we need 'msgfmt' to install all the libc.mo files.
644     (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
645                      ("gettext" ,gettext-boot0)))
647     ;; The final libc only refers to itself, but the 'debug' output contains
648     ;; references to GCC-BOOT0 and to the Linux headers.  XXX: Would be great
649     ;; if 'allowed-references' were per-output.
650     (arguments
651      `(#:allowed-references
652        ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
653                static-bash-for-glibc
654                (package-outputs glibc-final-with-bootstrap-bash))
656        ,@(package-arguments glibc-final-with-bootstrap-bash)))))
658 (define gcc-boot0-wrapped
659   ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
660   ;; non-cross names.
661   (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
662                      (car (assoc-ref %boot1-inputs "bash"))))
664 (define %boot2-inputs
665   ;; 3rd stage inputs.
666   `(("libc" ,glibc-final)
667     ("gcc" ,gcc-boot0-wrapped)
668     ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
670 (define binutils-final
671   (package-with-bootstrap-guile
672    (package/inherit binutils
673      (arguments
674       `(#:guile ,%bootstrap-guile
675         #:implicit-inputs? #f
676         #:allowed-references ("out" ,glibc-final)
677         ,@(package-arguments binutils)))
678      (inputs %boot2-inputs))))
680 (define libstdc++
681   ;; Intermediate libstdc++ that will allow us to build the final GCC
682   ;; (remember that GCC-BOOT0 cannot build libstdc++.)
683   ;; TODO: Write in terms of 'make-libstdc++'.
684   (package-with-bootstrap-guile
685    (package (inherit gcc)
686      (name "libstdc++")
687      (arguments
688       `(#:guile ,%bootstrap-guile
689         #:implicit-inputs? #f
690         #:allowed-references ("out")
691         #:out-of-source? #t
692         #:phases (alist-cons-before
693                   'configure 'chdir
694                   (lambda _
695                     (chdir "libstdc++-v3"))
696                   %standard-phases)
697         #:configure-flags `("--disable-shared"
698                             "--disable-libstdcxx-threads"
699                             "--disable-libstdcxx-pch"
700                             ,(string-append "--with-gxx-include-dir="
701                                             (assoc-ref %outputs "out")
702                                             "/include"
703                                             ;; "/include/c++/"
704                                             ;; ,(package-version gcc)
705                                             ))))
706      (outputs '("out"))
707      (inputs %boot2-inputs)
708      (native-inputs '())
709      (propagated-inputs '())
710      (synopsis "GNU C++ standard library (intermediate)"))))
712 (define zlib-final
713   ;; Zlib used by GCC-FINAL.
714   (package-with-bootstrap-guile
715    (package
716      (inherit zlib)
717      (arguments
718       `(#:guile ,%bootstrap-guile
719         #:implicit-inputs? #f
720         #:allowed-references ("out" ,glibc-final)
721         ,@(package-arguments zlib)))
722      (inputs %boot2-inputs))))
724 (define ld-wrapper-boot3
725   ;; A linker wrapper that uses the bootstrap Guile.
726   (make-ld-wrapper "ld-wrapper-boot3"
727                    #:binutils binutils-final
728                    #:guile %bootstrap-guile
729                    #:bash (car (assoc-ref %boot2-inputs "bash"))))
731 (define gcc-final
732   ;; The final GCC.
733   (package (inherit gcc-boot0)
734     (name "gcc")
736     ;; XXX: Currently #:allowed-references applies to all the outputs but the
737     ;; "debug" output contains disallowed references, notably
738     ;; linux-libre-headers.  Disable the debugging output to work around that.
739     (outputs (delete "debug" (package-outputs gcc-boot0)))
741     (arguments
742      `(#:guile ,%bootstrap-guile
743        #:implicit-inputs? #f
745        #:allowed-references ("out" "lib" ,zlib-final
746                              ,glibc-final ,static-bash-for-glibc)
748        ;; Things like libasan.so and libstdc++.so NEED ld.so for some
749        ;; reason, but it is not in their RUNPATH.  This is a false
750        ;; positive, so turn it off.
751        #:validate-runpath? #f
753        ;; Build again GMP & co. within GCC's build process, because it's hard
754        ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
755        ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
756        ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
757            ((#:configure-flags boot-flags)
758             (let loop ((args (package-arguments gcc)))
759               (match args
760                 ((#:configure-flags normal-flags _ ...)
761                  normal-flags)
762                 ((_ rest ...)
763                  (loop rest)))))
764            ((#:make-flags flags)
765             ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
766             `(let ((zlib (assoc-ref %build-inputs "zlib")))
767                (map (lambda (flag)
768                       (if (string-prefix? "LDFLAGS=" flag)
769                           (string-append flag " -L"
770                                          (assoc-ref %build-inputs "libstdc++")
771                                          "/lib -L" zlib "/lib -Wl,-rpath="
772                                          zlib "/lib")
773                           flag))
774                     ,flags)))
775            ((#:phases phases)
776             `(alist-delete 'symlink-libgcc_eh ,phases)))))
778     ;; This time we want Texinfo, so we get the manual.  Add
779     ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
780     ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
781     ;; scripts?).
782     (native-inputs `(("texinfo" ,texinfo-boot0)
783                      ("static-bash" ,static-bash-for-glibc)
784                      ,@(package-native-inputs gcc-boot0)))
786     (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
787               ("mpfr-source" ,(package-source mpfr))
788               ("mpc-source" ,(package-source mpc))
789               ("ld-wrapper" ,ld-wrapper-boot3)
790               ("binutils" ,binutils-final)
791               ("libstdc++" ,libstdc++)
792               ("zlib" ,zlib-final)
793               ,@%boot2-inputs))))
795 (define %boot3-inputs
796   ;; 4th stage inputs.
797   `(("gcc" ,gcc-final)
798     ("ld-wrapper" ,ld-wrapper-boot3)
799     ,@(alist-delete "gcc" %boot2-inputs)))
801 (define bash-final
802   ;; Link with `-static-libgcc' to make sure we don't retain a reference
803   ;; to the bootstrap GCC.  Use "bash-minimal" to avoid an extra dependency
804   ;; on Readline and ncurses.
805   (let ((bash (package
806                 (inherit bash-minimal)
807                 (arguments
808                  `(#:disallowed-references
809                    ,(assoc-ref %boot3-inputs "coreutils&co")
810                    ,@(package-arguments bash-minimal))))))
811     (package-with-bootstrap-guile
812      (package-with-explicit-inputs (static-libgcc-package bash)
813                                    %boot3-inputs
814                                    (current-source-location)
815                                    #:guile %bootstrap-guile))))
817 (define %boot4-inputs
818   ;; Now use the final Bash.
819   `(("bash" ,bash-final)
820     ,@(alist-delete "bash" %boot3-inputs)))
822 (define-public guile-final
823   ;; This package must be public because other modules refer to it.  However,
824   ;; mark it as hidden so that 'fold-packages' ignores it.
825   (package-with-bootstrap-guile
826    (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
827                                  %boot4-inputs
828                                  (current-source-location)
829                                  #:guile %bootstrap-guile)))
831 (define glibc-utf8-locales-final
832   ;; Now that we have GUILE-FINAL, build the UTF-8 locales.  They are needed
833   ;; by the build processes afterwards so their 'scm_to_locale_string' works
834   ;; with the full range of Unicode codepoints (remember
835   ;; 'scm_to_locale_string' is called every time a string is passed to a C
836   ;; function.)
837   (package
838     (inherit glibc-utf8-locales)
839     (inputs `(("glibc" ,glibc-final)
840               ("gzip"
841                ,(package-with-explicit-inputs gzip %boot4-inputs
842                                               (current-source-location)
843                                               #:guile %bootstrap-guile))))))
845 (define-public ld-wrapper
846   ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
847   (make-ld-wrapper "ld-wrapper"
848                    #:binutils binutils-final
849                    #:guile guile-final
850                    #:bash bash-final))
852 (define %boot5-inputs
853   ;; Now with UTF-8 locales.  Remember that the bootstrap binaries were built
854   ;; with an older libc, which cannot load the new locale format.  See
855   ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
856   `(("locales" ,glibc-utf8-locales-final)
857     ,@%boot4-inputs))
859 (define gnu-make-final
860   ;; The final GNU Make, which uses the final Guile.
861   (package-with-bootstrap-guile
862    (package-with-explicit-inputs gnu-make
863                                  `(("guile" ,guile-final)
864                                    ,@%boot5-inputs)
865                                  (current-source-location))))
867 (define coreutils-final
868   ;; The final Coreutils.  Treat them specially because some packages, such as
869   ;; Findutils, keep a reference to the Coreutils they were built with.
870   (package-with-bootstrap-guile
871    (package-with-explicit-inputs coreutils
872                                  %boot5-inputs
873                                  (current-source-location)
875                                  ;; Use the final Guile, linked against the
876                                  ;; final libc with working iconv, so that
877                                  ;; 'substitute*' works well when touching
878                                  ;; test files in Gettext.
879                                  #:guile guile-final)))
881 (define grep-final
882   ;; The final grep.  Gzip holds a reference to it (via zgrep), so it must be
883   ;; built before gzip.
884   (package-with-bootstrap-guile
885    (package-with-explicit-inputs (package
886                                    (inherit grep)
887                                    (native-inputs `(("perl" ,perl-boot0))))
888                                  %boot5-inputs
889                                  (current-source-location)
890                                  #:guile guile-final)))
892 (define %boot6-inputs
893   ;; Now use the final Coreutils.
894   `(("coreutils" ,coreutils-final)
895     ("grep" ,grep-final)
896     ,@%boot5-inputs))
898 (define-public %final-inputs
899   ;; Final derivations used as implicit inputs by 'gnu-build-system'.  We
900   ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
901   ;; used for origins that have patches, thereby avoiding circular
902   ;; dependencies.
903   (let ((finalize (compose package-with-bootstrap-guile
904                            (cut package-with-explicit-inputs <> %boot6-inputs
905                                 (current-source-location)))))
906     `(,@(map (match-lambda
907               ((name package)
908                (list name (finalize package))))
909              `(("tar" ,tar)
910                ("gzip" ,gzip)
911                ("bzip2" ,bzip2)
912                ("xz" ,xz)
913                ("file" ,file)
914                ("diffutils" ,diffutils)
915                ("patch" ,patch)
916                ("sed" ,sed)
917                ("findutils" ,findutils)
918                ("gawk" ,gawk)))
919       ("grep" ,grep-final)
920       ("coreutils" ,coreutils-final)
921       ("make" ,gnu-make-final)
922       ("bash" ,bash-final)
923       ("ld-wrapper" ,ld-wrapper)
924       ("binutils" ,binutils-final)
925       ("gcc" ,gcc-final)
926       ("libc" ,glibc-final)
927       ("locales" ,glibc-utf8-locales-final))))
929 (define-public canonical-package
930   (let ((name->package (fold (lambda (input result)
931                                (match input
932                                  ((_ package)
933                                   (vhash-cons (package-full-name package)
934                                               package result))))
935                              vlist-null
936                              `(("guile" ,guile-final)
937                                ,@%final-inputs))))
938     (lambda (package)
939       "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
940 the implicit inputs of 'gnu-build-system', return that one, otherwise return
941 PACKAGE.
943 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
944 COREUTILS-FINAL vs. COREUTILS, etc."
945       ;; XXX: This doesn't handle dependencies of the final inputs, such as
946       ;; libunistring, GMP, etc.
947       (match (vhash-assoc (package-full-name package) name->package)
948         ((_ . canon)
949          ;; In general we want CANON, except if we're cross-compiling: CANON
950          ;; uses explicit inputs, so it is "anchored" in the bootstrapped
951          ;; process, with dependencies on things that cannot be
952          ;; cross-compiled.
953          (if (%current-target-system)
954              package
955              canon))
956         (_ package)))))
960 ;;; GCC toolchain.
963 (define (make-gcc-toolchain gcc)
964   "Return a complete toolchain for GCC."
965   (package
966     (name "gcc-toolchain")
967     (version (package-version gcc))
968     (source #f)
969     (build-system trivial-build-system)
970     (arguments
971      '(#:modules ((guix build union))
972        #:builder (begin
973                    (use-modules (ice-9 match)
974                                 (srfi srfi-26)
975                                 (guix build union))
977                    (let ((out (assoc-ref %outputs "out")))
979                      (match %build-inputs
980                        (((names . directories) ...)
981                         (union-build out directories)))
983                      (union-build (assoc-ref %outputs "debug")
984                                   (list (assoc-ref %build-inputs
985                                                    "libc-debug")))))))
987     (native-search-paths (package-native-search-paths gcc))
988     (search-paths (package-search-paths gcc))
990     (license (package-license gcc))
991     (synopsis "Complete GCC tool chain for C/C++ development")
992     (description
993      "This package provides a complete GCC tool chain for C/C++ development to
994 be installed in user profiles.  This includes GCC, as well as libc (headers
995 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
996     (home-page "https://gcc.gnu.org/")
997     (outputs '("out" "debug"))
999     ;; The main raison d'être of this "meta-package" is (1) to conveniently
1000     ;; install everything that we need, and (2) to make sure ld-wrapper comes
1001     ;; before Binutils' ld in the user's profile.
1002     (inputs `(("gcc" ,gcc)
1003               ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
1004               ("binutils" ,binutils-final)
1005               ("libc" ,glibc-final)
1006               ("libc-debug" ,glibc-final "debug")))))
1008 (define-public gcc-toolchain-4.8
1009   (make-gcc-toolchain gcc-4.8))
1011 (define-public gcc-toolchain-4.9
1012   (make-gcc-toolchain gcc-4.9))
1014 (define-public gcc-toolchain
1015   (make-gcc-toolchain gcc-final))
1017 (define-public gcc-toolchain-5
1018   gcc-toolchain)
1020 (define-public gcc-toolchain-6
1021   (make-gcc-toolchain gcc-6))
1023 (define-public gcc-toolchain-7
1024   (make-gcc-toolchain gcc-7))
1026 ;;; commencement.scm ends here