services: avahi: Add Avahi to the system profile.
[guix.git] / gnu / packages / commencement.scm
blob73b0ce43642ba8d048c1ace75c114299d64d1a2b
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 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 Mark H Weaver <mhw@netris.org>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages commencement)
23   #:use-module ((guix licenses)
24                 #:select (gpl3+ lgpl2.0+ public-domain))
25   #:use-module (gnu packages bootstrap)
26   #:use-module (gnu packages base)
27   #:use-module (gnu packages bash)
28   #:use-module (gnu packages gcc)
29   #:use-module (gnu packages m4)
30   #:use-module (gnu packages file)
31   #:use-module (gnu packages gawk)
32   #:use-module (gnu packages bison)
33   #:use-module (gnu packages guile)
34   #:use-module (gnu packages gettext)
35   #:use-module (gnu packages multiprecision)
36   #:use-module (gnu packages compression)
37   #:use-module (gnu packages perl)
38   #:use-module (gnu packages linux)
39   #:use-module (gnu packages texinfo)
40   #:use-module (gnu packages pkg-config)
41   #:use-module (guix packages)
42   #:use-module (guix download)
43   #:use-module (guix build-system gnu)
44   #:use-module (guix build-system trivial)
45   #:use-module (guix utils)
46   #:use-module (srfi srfi-1)
47   #:use-module (srfi srfi-26)
48   #:use-module (ice-9 vlist)
49   #:use-module (ice-9 match))
51 ;;; Commentary:
52 ;;;
53 ;;; This is the commencement, this is where things start.  Before the
54 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
55 ;;; with the initial binaries.  This module uses those bootstrap binaries to
56 ;;; actually build up the whole tool chain that make up the implicit inputs of
57 ;;; 'gnu-build-system'.
58 ;;;
59 ;;; To avoid circular dependencies, this module should not be imported
60 ;;; directly from anywhere.
61 ;;;
62 ;;; Code:
64 (define gnu-make-boot0
65   (package-with-bootstrap-guile
66    (package (inherit gnu-make)
67      (name "make-boot0")
68      (arguments
69       `(#:guile ,%bootstrap-guile
70         #:implicit-inputs? #f
71         #:tests? #f                  ; cannot run "make check"
72         ,@(substitute-keyword-arguments (package-arguments gnu-make)
73             ((#:phases phases)
74              `(alist-replace
75                'build (lambda _
76                         (zero? (system* "./build.sh")))
77                (alist-replace
78                 'install (lambda* (#:key outputs #:allow-other-keys)
79                            (let* ((out (assoc-ref outputs "out"))
80                                   (bin (string-append out "/bin")))
81                              (mkdir-p bin)
82                              (copy-file "make"
83                                         (string-append bin "/make"))))
84                 ,phases))))))
85      (native-inputs '())                          ; no need for 'pkg-config'
86      (inputs %bootstrap-inputs))))
88 (define diffutils-boot0
89   (package-with-bootstrap-guile
90    (let ((p (package-with-explicit-inputs diffutils
91                                           `(("make" ,gnu-make-boot0)
92                                             ,@%bootstrap-inputs)
93                                           #:guile %bootstrap-guile)))
94      (package (inherit p)
95        (arguments `(#:tests? #f         ; the test suite needs diffutils
96                     ,@(package-arguments p)))))))
98 (define findutils-boot0
99   (package-with-bootstrap-guile
100    (package-with-explicit-inputs findutils
101                                  `(("make" ,gnu-make-boot0)
102                                    ("diffutils" ,diffutils-boot0) ; for tests
103                                    ,@%bootstrap-inputs)
104                                  (current-source-location)
105                                  #:guile %bootstrap-guile)))
107 (define file-boot0
108   (package-with-bootstrap-guile
109    (package-with-explicit-inputs file
110                                  `(("make" ,gnu-make-boot0)
111                                    ,@%bootstrap-inputs)
112                                  (current-source-location)
113                                  #:guile %bootstrap-guile)))
116 (define %boot0-inputs
117   `(("make" ,gnu-make-boot0)
118     ("diffutils" ,diffutils-boot0)
119     ("findutils" ,findutils-boot0)
120     ("file" ,file-boot0)
121     ,@%bootstrap-inputs))
123 (define* (boot-triplet #:optional (system (%current-system)))
124   ;; Return the triplet used to create the cross toolchain needed in the
125   ;; first bootstrapping stage.
126   (nix-system->gnu-triplet system "guix"))
128 ;; Following Linux From Scratch, build a cross-toolchain in stage 0.  That
129 ;; toolchain actually targets the same OS and arch, but it has the advantage
130 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
131 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
133 (define binutils-boot0
134   (package-with-bootstrap-guile
135    (package (inherit binutils)
136      (name "binutils-cross-boot0")
137      (arguments
138       `(#:guile ,%bootstrap-guile
139         #:implicit-inputs? #f
141         #:modules ((guix build gnu-build-system)
142                    (guix build utils)
143                    (ice-9 ftw))                    ; for 'scandir'
144         #:phases (alist-cons-after
145                   'install 'add-symlinks
146                   (lambda* (#:key outputs #:allow-other-keys)
147                     ;; The cross-gcc invokes 'as', 'ld', etc, without the
148                     ;; triplet prefix, so add symlinks.
149                     (let ((out (assoc-ref outputs "out"))
150                           (triplet-prefix (string-append ,(boot-triplet) "-")))
151                       (define (has-triplet-prefix? name)
152                         (string-prefix? triplet-prefix name))
153                       (define (remove-triplet-prefix name)
154                         (substring name (string-length triplet-prefix)))
155                       (with-directory-excursion (string-append out "/bin")
156                         (for-each (lambda (name)
157                                     (symlink name (remove-triplet-prefix name)))
158                                   (scandir "." has-triplet-prefix?)))
159                       #t))
160                   %standard-phases)
162         ,@(substitute-keyword-arguments (package-arguments binutils)
163             ((#:configure-flags cf)
164              `(cons ,(string-append "--target=" (boot-triplet))
165                     ,cf)))))
166      (inputs %boot0-inputs))))
168 (define gcc-boot0
169   (package-with-bootstrap-guile
170    (package (inherit gcc)
171      (name "gcc-cross-boot0")
172      (arguments
173       `(#:guile ,%bootstrap-guile
174         #:implicit-inputs? #f
175         #:modules ((guix build gnu-build-system)
176                    (guix build utils)
177                    (ice-9 regex)
178                    (srfi srfi-1)
179                    (srfi srfi-26))
180         ,@(substitute-keyword-arguments (package-arguments gcc)
181             ((#:configure-flags flags)
182              `(append (list ,(string-append "--target=" (boot-triplet))
184                             ;; No libc yet.
185                             "--without-headers"
187                             ;; Disable features not needed at this stage.
188                             "--disable-shared"
189                             "--enable-languages=c,c++"
191                             ;; libstdc++ cannot be built at this stage
192                             ;; ("Link tests are not allowed after
193                             ;; GCC_NO_EXECUTABLES.").
194                             "--disable-libstdc++-v3"
196                             "--disable-threads"
197                             "--disable-libmudflap"
198                             "--disable-libatomic"
199                             "--disable-libsanitizer"
200                             "--disable-libitm"
201                             "--disable-libgomp"
202                             "--disable-libcilkrts"
203                             "--disable-libvtv"
204                             "--disable-libssp"
205                             "--disable-libquadmath"
206                             "--disable-decimal-float")
207                       (remove (cut string-match "--enable-languages.*" <>)
208                               ,flags)))
209             ((#:phases phases)
210              `(alist-cons-after
211                'unpack 'unpack-gmp&co
212                (lambda* (#:key inputs #:allow-other-keys)
213                  (let ((gmp  (assoc-ref %build-inputs "gmp-source"))
214                        (mpfr (assoc-ref %build-inputs "mpfr-source"))
215                        (mpc  (assoc-ref %build-inputs "mpc-source")))
217                    ;; To reduce the set of pre-built bootstrap inputs, build
218                    ;; GMP & co. from GCC.
219                    (for-each (lambda (source)
220                                (or (zero? (system* "tar" "xvf" source))
221                                    (error "failed to unpack tarball"
222                                           source)))
223                              (list gmp mpfr mpc))
225                    ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
226                    ,@(map (lambda (lib)
227                             ;; Drop trailing letters, as gmp-6.0.0a unpacks
228                             ;; into gmp-6.0.0.
229                             `(symlink ,(string-trim-right
230                                         (package-full-name lib)
231                                         char-set:letter)
232                                       ,(package-name lib)))
233                           (list gmp mpfr mpc))))
234                (alist-cons-after
235                 'install 'symlink-libgcc_eh
236                 (lambda* (#:key outputs #:allow-other-keys)
237                   (let ((out (assoc-ref outputs "lib")))
238                     ;; Glibc wants to link against libgcc_eh, so provide
239                     ;; it.
240                     (with-directory-excursion
241                         (string-append out "/lib/gcc/"
242                                        ,(boot-triplet)
243                                        "/" ,(package-version gcc))
244                       (symlink "libgcc.a" "libgcc_eh.a"))))
245                 ,phases))))))
247      (inputs `(("gmp-source" ,(package-source gmp))
248                ("mpfr-source" ,(package-source mpfr))
249                ("mpc-source" ,(package-source mpc))
250                ("binutils-cross" ,binutils-boot0)
252                ;; Call it differently so that the builder can check whether
253                ;; the "libc" input is #f.
254                ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
255                ,@(alist-delete "libc" %boot0-inputs)))
257      ;; No need for Texinfo at this stage.
258      (native-inputs (alist-delete "texinfo"
259                                   (package-native-inputs gcc))))))
261 (define perl-boot0
262   (package-with-bootstrap-guile
263    (package-with-explicit-inputs perl
264                                  %boot0-inputs
265                                  (current-source-location)
266                                  #:guile %bootstrap-guile)))
268 (define (linux-libre-headers-boot0)
269   "Return Linux-Libre header files for the bootstrap environment."
270   ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
271   ;; between (gnu packages linux) and this module.
272   (package-with-bootstrap-guile
273    (package (inherit linux-libre-headers)
274      (arguments `(#:guile ,%bootstrap-guile
275                   #:implicit-inputs? #f
276                   ,@(package-arguments linux-libre-headers)))
277      (native-inputs
278       `(("perl" ,perl-boot0)
279         ,@%boot0-inputs)))))
281 (define texinfo-boot0
282   ;; Texinfo used to build libc's manual.
283   ;; We build without ncurses because it fails to build at this stage, and
284   ;; because we don't need the stand-alone Info reader.
285   ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
286   (let ((texinfo (package (inherit texinfo)
287                    (native-inputs '())
288                    (inputs (alist-delete "ncurses" (package-inputs texinfo))))))
289     (package-with-bootstrap-guile
290      (package-with-explicit-inputs texinfo %boot0-inputs
291                                    (current-source-location)
292                                    #:guile %bootstrap-guile))))
294 (define %boot1-inputs
295   ;; 2nd stage inputs.
296   `(("gcc" ,gcc-boot0)
297     ("binutils-cross" ,binutils-boot0)
298     ,@(alist-delete "binutils" %boot0-inputs)))
300 (define glibc-final-with-bootstrap-bash
301   ;; The final libc, "cross-built".  If everything went well, the resulting
302   ;; store path has no dependencies.  Actually, the really-final libc is
303   ;; built just below; the only difference is that this one uses the
304   ;; bootstrap Bash.
305   (package-with-bootstrap-guile
306    (package (inherit glibc)
307      (name "glibc-intermediate")
308      (arguments
309       `(#:guile ,%bootstrap-guile
310         #:implicit-inputs? #f
312         ,@(substitute-keyword-arguments (package-arguments glibc)
313             ((#:configure-flags flags)
314              `(append (list ,(string-append "--host=" (boot-triplet))
315                             ,(string-append "--build="
316                                             (nix-system->gnu-triplet))
318                             ;; Build Sun/ONC RPC support.  In particular,
319                             ;; install rpc/*.h.
320                             "--enable-obsolete-rpc")
321                       ,flags))
322             ((#:phases phases)
323              `(alist-cons-before
324                'configure 'pre-configure
325                (lambda* (#:key inputs #:allow-other-keys)
326                  ;; Don't clobber CPATH with the bootstrap libc.
327                  (setenv "NATIVE_CPATH" (getenv "CPATH"))
328                  (unsetenv "CPATH")
330                  ;; 'rpcgen' needs native libc headers to be built.
331                  (substitute* "sunrpc/Makefile"
332                    (("sunrpc-CPPFLAGS =.*" all)
333                     (string-append "CPATH = $(NATIVE_CPATH)\n"
334                                    "export CPATH\n"
335                                    all "\n"))))
336                ,phases)))))
337      (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
338      (native-inputs
339       `(("texinfo" ,texinfo-boot0)
340         ("perl" ,perl-boot0)))
341      (inputs
342       `(;; The boot inputs.  That includes the bootstrap libc.  We don't want
343         ;; it in $CPATH, hence the 'pre-configure' phase above.
344         ,@%boot1-inputs
346         ;; A native GCC is needed to build `cross-rpcgen'.
347         ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
349         ;; Here, we use the bootstrap Bash, which is not satisfactory
350         ;; because we don't want to depend on bootstrap tools.
351         ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
353 (define (cross-gcc-wrapper gcc binutils glibc bash)
354   "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
355 that makes it available under the native tool names."
356   (package (inherit gcc)
357     (name (string-append (package-name gcc) "-wrapped"))
358     (source #f)
359     (build-system trivial-build-system)
360     (outputs '("out"))
361     (arguments
362      `(#:guile ,%bootstrap-guile
363        #:modules ((guix build utils))
364        #:builder (begin
365                    (use-modules (guix build utils))
367                    (let* ((binutils (assoc-ref %build-inputs "binutils"))
368                           (gcc      (assoc-ref %build-inputs "gcc"))
369                           (libc     (assoc-ref %build-inputs "libc"))
370                           (bash     (assoc-ref %build-inputs "bash"))
371                           (out      (assoc-ref %outputs "out"))
372                           (bindir   (string-append out "/bin"))
373                           (triplet  ,(boot-triplet)))
374                      (define (wrap-program program)
375                        ;; GCC-BOOT0 is a libc-less cross-compiler, so it
376                        ;; needs to be told where to find the crt files and
377                        ;; the dynamic linker.
378                        (call-with-output-file program
379                          (lambda (p)
380                            (format p "#!~a/bin/bash
381 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
382                                    bash
383                                    gcc triplet program
384                                    libc libc
385                                    ,(glibc-dynamic-linker))))
387                        (chmod program #o555))
389                      (mkdir-p bindir)
390                      (with-directory-excursion bindir
391                        (for-each (lambda (tool)
392                                    (symlink (string-append binutils "/bin/"
393                                                            triplet "-" tool)
394                                             tool))
395                                  '("ar" "ranlib"))
396                        (for-each wrap-program '("gcc" "g++")))))))
397     (native-inputs
398      `(("binutils" ,binutils)
399        ("gcc" ,gcc)
400        ("libc" ,glibc)
401        ("bash" ,bash)))
402     (inputs '())))
404 (define bison-boot1
405   ;; XXX: This Bison is needed to rebuild Bash's parser, which is modified by
406   ;; its CVE patches.  Remove it when it's no longer needed.
407   (let* ((m4    (package-with-bootstrap-guile
408                  (package-with-explicit-inputs m4 %boot0-inputs
409                                                (current-source-location)
410                                                #:guile %bootstrap-guile)))
411          (bison (package (inherit bison)
412                   (native-inputs `(("perl" ,perl-boot0)))
413                   (propagated-inputs `(("m4" ,m4)))
414                   (inputs '())                    ;remove Flex...
415                   (arguments '(#:tests? #f)))))   ;... and thus disable tests
416    (package-with-bootstrap-guile
417     (package-with-explicit-inputs bison %boot0-inputs
418                                   (current-source-location)
419                                   #:guile %bootstrap-guile))))
421 (define static-bash-for-glibc
422   ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
423   (let* ((gcc  (cross-gcc-wrapper gcc-boot0 binutils-boot0
424                                   glibc-final-with-bootstrap-bash
425                                   (car (assoc-ref %boot1-inputs "bash"))))
426          (bash (package (inherit static-bash)
427                  (native-inputs `(("bison" ,bison-boot1)))
428                  (arguments
429                   `(#:guile ,%bootstrap-guile
430                     ,@(package-arguments static-bash))))))
431     (package-with-bootstrap-guile
432      (package-with-explicit-inputs bash
433                                    `(("gcc" ,gcc)
434                                      ("libc" ,glibc-final-with-bootstrap-bash)
435                                      ,@(fold alist-delete %boot1-inputs
436                                              '("gcc" "libc")))
437                                    (current-source-location)))))
439 (define gettext-boot0
440   ;; A minimal gettext used during bootstrap.
441   (let ((gettext-minimal
442          (package (inherit gnu-gettext)
443            (name "gettext-boot0")
444            (inputs '())                           ;zero dependencies
445            (arguments
446             (substitute-keyword-arguments
447                 `(#:tests? #f
448                   ,@(package-arguments gnu-gettext))
449               ((#:phases phases)
450                `(modify-phases ,phases
451                   ;; Build only the tools.
452                   (add-after 'unpack 'chdir
453                              (lambda _
454                                (chdir "gettext-tools")))
456                   ;; Some test programs require pthreads, which we don't have.
457                   (add-before 'configure 'no-test-programs
458                               (lambda _
459                                 (substitute* "tests/Makefile.in"
460                                   (("^PROGRAMS =.*$")
461                                    "PROGRAMS =\n"))
462                                 #t))
464                   ;; Don't try to link against libexpat.
465                   (delete 'link-expat)
466                   (delete 'patch-tests))))))))
467     (package-with-bootstrap-guile
468      (package-with-explicit-inputs gettext-minimal
469                                    %boot1-inputs
470                                    (current-source-location)
471                                    #:guile %bootstrap-guile))))
473 (define glibc-final
474   ;; The final glibc, which embeds the statically-linked Bash built above.
475   (package (inherit glibc-final-with-bootstrap-bash)
476     (name "glibc")
477     (inputs `(("static-bash" ,static-bash-for-glibc)
478               ,@(alist-delete
479                  "static-bash"
480                  (package-inputs glibc-final-with-bootstrap-bash))))
482     ;; This time we need 'msgfmt' to install all the libc.mo files.
483     (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
484                      ("gettext" ,gettext-boot0)))
486     ;; The final libc only refers to itself, but the 'debug' output contains
487     ;; references to GCC-BOOT0 and to the Linux headers.  XXX: Would be great
488     ;; if 'allowed-references' were per-output.
489     (arguments
490      `(#:allowed-references
491        ,(cons* `(,gcc-boot0 "lib") (linux-libre-headers-boot0)
492                static-bash-for-glibc
493                (package-outputs glibc-final-with-bootstrap-bash))
495        ,@(package-arguments glibc-final-with-bootstrap-bash)))))
497 (define gcc-boot0-wrapped
498   ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
499   ;; non-cross names.
500   (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
501                      (car (assoc-ref %boot1-inputs "bash"))))
503 (define %boot2-inputs
504   ;; 3rd stage inputs.
505   `(("libc" ,glibc-final)
506     ("gcc" ,gcc-boot0-wrapped)
507     ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
509 (define binutils-final
510   (package-with-bootstrap-guile
511    (package (inherit binutils)
512      (arguments
513       `(#:guile ,%bootstrap-guile
514         #:implicit-inputs? #f
515         #:allowed-references ("out" ,glibc-final)
516         ,@(package-arguments binutils)))
517      (inputs %boot2-inputs))))
519 (define libstdc++
520   ;; Intermediate libstdc++ that will allow us to build the final GCC
521   ;; (remember that GCC-BOOT0 cannot build libstdc++.)
522   ;; TODO: Write in terms of 'make-libstdc++'.
523   (package-with-bootstrap-guile
524    (package (inherit gcc)
525      (name "libstdc++")
526      (arguments
527       `(#:guile ,%bootstrap-guile
528         #:implicit-inputs? #f
530         #:out-of-source? #t
531         #:phases (alist-cons-before
532                   'configure 'chdir
533                   (lambda _
534                     (chdir "libstdc++-v3"))
535                   %standard-phases)
536         #:configure-flags `("--disable-shared"
537                             "--disable-libstdcxx-threads"
538                             "--disable-libstdcxx-pch"
539                             ,(string-append "--with-gxx-include-dir="
540                                             (assoc-ref %outputs "out")
541                                             "/include"
542                                             ;; "/include/c++/"
543                                             ;; ,(package-version gcc)
544                                             ))))
545      (outputs '("out"))
546      (inputs %boot2-inputs)
547      (native-inputs '())
548      (propagated-inputs '())
549      (synopsis "GNU C++ standard library (intermediate)"))))
551 (define gcc-final
552   ;; The final GCC.
553   (package (inherit gcc-boot0)
554     (name "gcc")
556     ;; XXX: Currently #:allowed-references applies to all the outputs but the
557     ;; "debug" output contains disallowed references, notably
558     ;; linux-libre-headers.  Disable the debugging output to work around that.
559     (outputs (delete "debug" (package-outputs gcc-boot0)))
561     (arguments
562      `(#:guile ,%bootstrap-guile
563        #:implicit-inputs? #f
565        #:allowed-references ("out" "lib"
566                              ,glibc-final ,static-bash-for-glibc)
568        ;; Things like libasan.so and libstdc++.so NEED ld.so for some
569        ;; reason, but it is not in their RUNPATH.  This is a false
570        ;; positive, so turn it off.
571        #:validate-runpath? #f
573        ;; Build again GMP & co. within GCC's build process, because it's hard
574        ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
575        ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
576        ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
577            ((#:configure-flags boot-flags)
578             (let loop ((args (package-arguments gcc)))
579               (match args
580                 ((#:configure-flags normal-flags _ ...)
581                  normal-flags)
582                 ((_ rest ...)
583                  (loop rest)))))
584            ((#:make-flags flags)
585             ;; Since $LIBRARY_PATH and $CPATH are not honored, add the
586             ;; relevant flags.
587             `(cons (string-append "CPPFLAGS=-I"
588                                   (assoc-ref %build-inputs "libstdc++")
589                                   "/include")
590                    (map (lambda (flag)
591                           (if (string-prefix? "LDFLAGS=" flag)
592                               (string-append flag " -L"
593                                              (assoc-ref %build-inputs "libstdc++")
594                                              "/lib")
595                               flag))
596                         ,flags)))
597            ((#:phases phases)
598             `(alist-delete 'symlink-libgcc_eh ,phases)))))
600     ;; This time we want Texinfo, so we get the manual.  Add
601     ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
602     ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
603     ;; scripts?).
604     (native-inputs `(("texinfo" ,texinfo-boot0)
605                      ("static-bash" ,static-bash-for-glibc)
606                      ,@(package-native-inputs gcc-boot0)))
608     (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp)))
609               ("mpfr-source" ,(package-source mpfr))
610               ("mpc-source" ,(package-source mpc))
611               ("binutils" ,binutils-final)
612               ("libstdc++" ,libstdc++)
613               ,@%boot2-inputs))))
615 (define ld-wrapper-boot3
616   ;; A linker wrapper that uses the bootstrap Guile.
617   (make-ld-wrapper "ld-wrapper-boot3"
618                    #:binutils binutils-final
619                    #:guile %bootstrap-guile
620                    #:bash (car (assoc-ref %boot2-inputs "bash"))))
622 (define %boot3-inputs
623   ;; 4th stage inputs.
624   `(("gcc" ,gcc-final)
625     ("ld-wrapper" ,ld-wrapper-boot3)
626     ,@(alist-delete "gcc" %boot2-inputs)))
628 (define bash-final
629   ;; Link with `-static-libgcc' to make sure we don't retain a reference
630   ;; to the bootstrap GCC.
631   (package-with-bootstrap-guile
632    (package-with-explicit-inputs (static-libgcc-package bash)
633                                  %boot3-inputs
634                                  (current-source-location)
635                                  #:guile %bootstrap-guile)))
637 (define %boot4-inputs
638   ;; Now use the final Bash.
639   `(("bash" ,bash-final)
640     ,@(alist-delete "bash" %boot3-inputs)))
642 (define-public guile-final
643   (package-with-bootstrap-guile
644    (package-with-explicit-inputs guile-2.0/fixed
645                                  %boot4-inputs
646                                  (current-source-location)
647                                  #:guile %bootstrap-guile)))
649 (define glibc-utf8-locales-final
650   ;; Now that we have GUILE-FINAL, build the UTF-8 locales.  They are needed
651   ;; by the build processes afterwards so their 'scm_to_locale_string' works
652   ;; with the full range of Unicode codepoints (remember
653   ;; 'scm_to_locale_string' is called every time a string is passed to a C
654   ;; function.)
655   (package
656     (inherit glibc-utf8-locales)
657     (inputs `(("glibc" ,glibc-final)
658               ("gzip"
659                ,(package-with-explicit-inputs gzip %boot4-inputs
660                                               (current-source-location)
661                                               #:guile %bootstrap-guile))))))
663 (define-public ld-wrapper
664   ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
665   (package (inherit ld-wrapper-boot3)
666     (name "ld-wrapper")
667     (inputs `(("guile" ,guile-final)
668               ("bash"  ,bash-final)
669               ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
670                       '("guile" "bash"))))))
672 (define %boot5-inputs
673   ;; Now with UTF-8 locales.  Remember that the bootstrap binaries were built
674   ;; with an older libc, which cannot load the new locale format.  See
675   ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
676   `(("locales" ,glibc-utf8-locales-final)
677     ,@%boot4-inputs))
679 (define gnu-make-final
680   ;; The final GNU Make, which uses the final Guile.
681   (package-with-bootstrap-guile
682    (package-with-explicit-inputs gnu-make
683                                  `(("guile" ,guile-final)
684                                    ,@%boot5-inputs)
685                                  (current-source-location))))
687 (define coreutils-final
688   ;; The final Coreutils.  Treat them specially because some packages, such as
689   ;; Findutils, keep a reference to the Coreutils they were built with.
690   (package-with-bootstrap-guile
691    (package-with-explicit-inputs coreutils
692                                  %boot5-inputs
693                                  (current-source-location)
695                                  ;; Use the final Guile, linked against the
696                                  ;; final libc with working iconv, so that
697                                  ;; 'substitute*' works well when touching
698                                  ;; test files in Gettext.
699                                  #:guile guile-final)))
701 (define grep-final
702   ;; The final grep.  Gzip holds a reference to it (via zgrep), so it must be
703   ;; built before gzip.
704   (package-with-bootstrap-guile
705    (package-with-explicit-inputs grep
706                                  %boot5-inputs
707                                  (current-source-location)
708                                  #:guile guile-final)))
710 (define %boot6-inputs
711   ;; Now use the final Coreutils.
712   `(("coreutils" ,coreutils-final)
713     ("grep" ,grep-final)
714     ,@%boot5-inputs))
716 (define-public %final-inputs
717   ;; Final derivations used as implicit inputs by 'gnu-build-system'.  We
718   ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
719   ;; used for origins that have patches, thereby avoiding circular
720   ;; dependencies.
721   (let ((finalize (compose package-with-bootstrap-guile
722                            (cut package-with-explicit-inputs <> %boot6-inputs
723                                 (current-source-location)))))
724     `(,@(map (match-lambda
725               ((name package)
726                (list name (finalize package))))
727              `(("tar" ,tar)
728                ("gzip" ,gzip)
729                ("bzip2" ,bzip2)
730                ("xz" ,xz)
731                ("file" ,file)
732                ("diffutils" ,diffutils)
733                ("patch" ,patch)
734                ("sed" ,sed)
735                ("findutils" ,findutils)
736                ("gawk" ,gawk)))
737       ("grep" ,grep-final)
738       ("coreutils" ,coreutils-final)
739       ("make" ,gnu-make-final)
740       ("bash" ,bash-final)
741       ("ld-wrapper" ,ld-wrapper)
742       ("binutils" ,binutils-final)
743       ("gcc" ,gcc-final)
744       ("libc" ,glibc-final)
745       ("locales" ,glibc-utf8-locales-final))))
747 (define-public canonical-package
748   (let ((name->package (fold (lambda (input result)
749                                (match input
750                                  ((_ package)
751                                   (vhash-cons (package-full-name package)
752                                               package result))))
753                              vlist-null
754                              `(("guile" ,guile-final)
755                                ,@%final-inputs))))
756     (lambda (package)
757       "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
758 the implicit inputs of 'gnu-build-system', return that one, otherwise return
759 PACKAGE.
761 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.0,
762 COREUTILS-FINAL vs. COREUTILS, etc."
763       ;; XXX: This doesn't handle dependencies of the final inputs, such as
764       ;; libunistring, GMP, etc.
765       (match (vhash-assoc (package-full-name package) name->package)
766         ((_ . canon)
767          ;; In general we want CANON, except if we're cross-compiling: CANON
768          ;; uses explicit inputs, so it is "anchored" in the bootstrapped
769          ;; process, with dependencies on things that cannot be
770          ;; cross-compiled.
771          (if (%current-target-system)
772              package
773              canon))
774         (_ package)))))
778 ;;; GCC toolchain.
781 (define (gcc-toolchain gcc)
782   "Return a complete toolchain for GCC."
783   (package
784     (name "gcc-toolchain")
785     (version (package-version gcc))
786     (source #f)
787     (build-system trivial-build-system)
788     (arguments
789      '(#:modules ((guix build union))
790        #:builder (begin
791                    (use-modules (ice-9 match)
792                                 (srfi srfi-26)
793                                 (guix build union))
795                    (let ((out (assoc-ref %outputs "out")))
797                      (match %build-inputs
798                        (((names . directories) ...)
799                         (union-build out directories)))
801                      (union-build (assoc-ref %outputs "debug")
802                                   (list (assoc-ref %build-inputs
803                                                    "libc-debug")))))))
805     (native-search-paths (package-native-search-paths gcc))
806     (search-paths (package-search-paths gcc))
808     (license (package-license gcc))
809     (synopsis "Complete GCC tool chain for C/C++ development")
810     (description
811      "This package provides a complete GCC tool chain for C/C++ development to
812 be installed in user profiles.  This includes GCC, as well as libc (headers
813 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
814     (home-page "http://gcc.gnu.org/")
815     (outputs '("out" "debug"))
817     ;; The main raison d'être of this "meta-package" is (1) to conveniently
818     ;; install everything that we need, and (2) to make sure ld-wrapper comes
819     ;; before Binutils' ld in the user's profile.
820     (inputs `(("gcc" ,gcc)
821               ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
822               ("binutils" ,binutils-final)
823               ("libc" ,glibc-final)
824               ("libc-debug" ,glibc-final "debug")))))
826 (define-public gcc-toolchain-4.8
827   (gcc-toolchain gcc-final))
829 (define-public gcc-toolchain-4.9
830   (gcc-toolchain gcc-4.9))
832 (define-public gcc-toolchain-5
833   (gcc-toolchain gcc-5))
835 ;;; commencement.scm ends here