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