gnu: Add zita-resampler.
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
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/>.
21
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))
50
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:
63
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))))
87
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)))))))
97
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)))
106
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)))
114
115
116 (define %boot0-inputs
117 `(("make" ,gnu-make-boot0)
118 ("diffutils" ,diffutils-boot0)
119 ("findutils" ,findutils-boot0)
120 ("file" ,file-boot0)
121 ,@%bootstrap-inputs))
122
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"))
127
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.
132
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
140 ,@(substitute-keyword-arguments (package-arguments binutils)
141 ((#:configure-flags cf)
142 `(cons ,(string-append "--target=" (boot-triplet))
143 ,cf)))))
144 (inputs %boot0-inputs))))
145
146 (define gcc-boot0
147 (package-with-bootstrap-guile
148 (package (inherit gcc-4.8)
149 (name "gcc-cross-boot0")
150 (arguments
151 `(#:guile ,%bootstrap-guile
152 #:implicit-inputs? #f
153 #:modules ((guix build gnu-build-system)
154 (guix build utils)
155 (ice-9 regex)
156 (srfi srfi-1)
157 (srfi srfi-26))
158 ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
159 ((#:configure-flags flags)
160 `(append (list ,(string-append "--target=" (boot-triplet))
161
162 ;; No libc yet.
163 "--without-headers"
164
165 ;; Disable features not needed at this stage.
166 "--disable-shared"
167 "--enable-languages=c,c++"
168
169 ;; libstdc++ cannot be built at this stage
170 ;; ("Link tests are not allowed after
171 ;; GCC_NO_EXECUTABLES.").
172 "--disable-libstdc++-v3"
173
174 "--disable-threads"
175 "--disable-libmudflap"
176 "--disable-libatomic"
177 "--disable-libsanitizer"
178 "--disable-libitm"
179 "--disable-libgomp"
180 "--disable-libssp"
181 "--disable-libquadmath"
182 "--disable-decimal-float")
183 (remove (cut string-match "--enable-languages.*" <>)
184 ,flags)))
185 ((#:phases phases)
186 `(alist-cons-after
187 'unpack 'unpack-gmp&co
188 (lambda* (#:key inputs #:allow-other-keys)
189 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
190 (mpfr (assoc-ref %build-inputs "mpfr-source"))
191 (mpc (assoc-ref %build-inputs "mpc-source")))
192
193 ;; To reduce the set of pre-built bootstrap inputs, build
194 ;; GMP & co. from GCC.
195 (for-each (lambda (source)
196 (or (zero? (system* "tar" "xvf" source))
197 (error "failed to unpack tarball"
198 source)))
199 (list gmp mpfr mpc))
200
201 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
202 ,@(map (lambda (lib)
203 ;; Drop trailing letters, as gmp-6.0.0a unpacks
204 ;; into gmp-6.0.0.
205 `(symlink ,(string-trim-right
206 (package-full-name lib)
207 char-set:letter)
208 ,(package-name lib)))
209 (list gmp mpfr mpc))))
210 (alist-cons-after
211 'install 'symlink-libgcc_eh
212 (lambda* (#:key outputs #:allow-other-keys)
213 (let ((out (assoc-ref outputs "lib")))
214 ;; Glibc wants to link against libgcc_eh, so provide
215 ;; it.
216 (with-directory-excursion
217 (string-append out "/lib/gcc/"
218 ,(boot-triplet)
219 "/" ,(package-version gcc-4.8))
220 (symlink "libgcc.a" "libgcc_eh.a"))))
221 ,phases))))))
222
223 (inputs `(("gmp-source" ,(package-source gmp))
224 ("mpfr-source" ,(package-source mpfr))
225 ("mpc-source" ,(package-source mpc))
226 ("binutils-cross" ,binutils-boot0)
227
228 ;; Call it differently so that the builder can check whether
229 ;; the "libc" input is #f.
230 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
231 ,@(alist-delete "libc" %boot0-inputs)))
232
233 ;; No need for Texinfo at this stage.
234 (native-inputs (alist-delete "texinfo"
235 (package-native-inputs gcc-4.8))))))
236
237 (define perl-boot0
238 (package-with-bootstrap-guile
239 (package-with-explicit-inputs perl
240 %boot0-inputs
241 (current-source-location)
242 #:guile %bootstrap-guile)))
243
244 (define (linux-libre-headers-boot0)
245 "Return Linux-Libre header files for the bootstrap environment."
246 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
247 ;; between (gnu packages linux) and this module.
248 (package-with-bootstrap-guile
249 (package (inherit linux-libre-headers)
250 (arguments `(#:guile ,%bootstrap-guile
251 #:implicit-inputs? #f
252 ,@(package-arguments linux-libre-headers)))
253 (native-inputs
254 `(("perl" ,perl-boot0)
255 ,@%boot0-inputs)))))
256
257 (define texinfo-boot0
258 ;; Texinfo used to build libc's manual.
259 ;; We build without ncurses because it fails to build at this stage, and
260 ;; because we don't need the stand-alone Info reader.
261 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
262 (let ((texinfo (package (inherit texinfo)
263 (inputs (alist-delete "ncurses" (package-inputs texinfo))))))
264 (package-with-bootstrap-guile
265 (package-with-explicit-inputs texinfo %boot0-inputs
266 (current-source-location)
267 #:guile %bootstrap-guile))))
268
269 (define %boot1-inputs
270 ;; 2nd stage inputs.
271 `(("gcc" ,gcc-boot0)
272 ("binutils-cross" ,binutils-boot0)
273
274 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
275 ;; cross-`as'.
276 ,@%boot0-inputs))
277
278 (define glibc-final-with-bootstrap-bash
279 ;; The final libc, "cross-built". If everything went well, the resulting
280 ;; store path has no dependencies. Actually, the really-final libc is
281 ;; built just below; the only difference is that this one uses the
282 ;; bootstrap Bash.
283 (package-with-bootstrap-guile
284 (package (inherit glibc)
285 (name "glibc-intermediate")
286 (arguments
287 `(#:guile ,%bootstrap-guile
288 #:implicit-inputs? #f
289
290 ,@(substitute-keyword-arguments (package-arguments glibc)
291 ((#:configure-flags flags)
292 `(append (list ,(string-append "--host=" (boot-triplet))
293 ,(string-append "--build="
294 (nix-system->gnu-triplet))
295
296 ;; Build Sun/ONC RPC support. In particular,
297 ;; install rpc/*.h.
298 "--enable-obsolete-rpc")
299 ,flags))
300 ((#:phases phases)
301 `(alist-cons-before
302 'configure 'pre-configure
303 (lambda* (#:key inputs #:allow-other-keys)
304 ;; Don't clobber CPATH with the bootstrap libc.
305 (setenv "NATIVE_CPATH" (getenv "CPATH"))
306 (unsetenv "CPATH")
307
308 ;; 'rpcgen' needs native libc headers to be built.
309 (substitute* "sunrpc/Makefile"
310 (("sunrpc-CPPFLAGS =.*" all)
311 (string-append "CPATH = $(NATIVE_CPATH)\n"
312 "export CPATH\n"
313 all "\n"))))
314 ,phases)))))
315 (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
316 (native-inputs
317 `(("texinfo" ,texinfo-boot0)
318 ("perl" ,perl-boot0)))
319 (inputs
320 `(;; The boot inputs. That includes the bootstrap libc. We don't want
321 ;; it in $CPATH, hence the 'pre-configure' phase above.
322 ,@%boot1-inputs
323
324 ;; A native GCC is needed to build `cross-rpcgen'.
325 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
326
327 ;; Here, we use the bootstrap Bash, which is not satisfactory
328 ;; because we don't want to depend on bootstrap tools.
329 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
330
331 (define (cross-gcc-wrapper gcc binutils glibc bash)
332 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
333 that makes it available under the native tool names."
334 (package (inherit gcc-4.8)
335 (name (string-append (package-name gcc) "-wrapped"))
336 (source #f)
337 (build-system trivial-build-system)
338 (outputs '("out"))
339 (arguments
340 `(#:guile ,%bootstrap-guile
341 #:modules ((guix build utils))
342 #:builder (begin
343 (use-modules (guix build utils))
344
345 (let* ((binutils (assoc-ref %build-inputs "binutils"))
346 (gcc (assoc-ref %build-inputs "gcc"))
347 (libc (assoc-ref %build-inputs "libc"))
348 (bash (assoc-ref %build-inputs "bash"))
349 (out (assoc-ref %outputs "out"))
350 (bindir (string-append out "/bin"))
351 (triplet ,(boot-triplet)))
352 (define (wrap-program program)
353 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
354 ;; needs to be told where to find the crt files and
355 ;; the dynamic linker.
356 (call-with-output-file program
357 (lambda (p)
358 (format p "#!~a/bin/bash
359 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
360 bash
361 gcc triplet program
362 libc libc
363 ,(glibc-dynamic-linker))))
364
365 (chmod program #o555))
366
367 (mkdir-p bindir)
368 (with-directory-excursion bindir
369 (for-each (lambda (tool)
370 (symlink (string-append binutils "/bin/"
371 triplet "-" tool)
372 tool))
373 '("ar" "ranlib"))
374 (for-each wrap-program '("gcc" "g++")))))))
375 (native-inputs
376 `(("binutils" ,binutils)
377 ("gcc" ,gcc)
378 ("libc" ,glibc)
379 ("bash" ,bash)))
380 (inputs '())))
381
382 (define bison-boot1
383 ;; XXX: This Bison is needed to rebuild Bash's parser, which is modified by
384 ;; its CVE patches. Remove it when it's no longer needed.
385 (let* ((m4 (package-with-bootstrap-guile
386 (package-with-explicit-inputs m4 %boot0-inputs
387 (current-source-location)
388 #:guile %bootstrap-guile)))
389 (bison (package (inherit bison)
390 (native-inputs `(("perl" ,perl-boot0)))
391 (propagated-inputs `(("m4" ,m4)))
392 (inputs '()) ;remove Flex...
393 (arguments '(#:tests? #f))))) ;... and thus disable tests
394 (package-with-bootstrap-guile
395 (package-with-explicit-inputs bison %boot0-inputs
396 (current-source-location)
397 #:guile %bootstrap-guile))))
398
399 (define static-bash-for-glibc
400 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
401 ;; system(3) & co.
402 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
403 glibc-final-with-bootstrap-bash
404 (car (assoc-ref %boot1-inputs "bash"))))
405 (bash (package (inherit bash-light)
406 (native-inputs `(("bison" ,bison-boot1)))
407 (arguments
408 `(#:guile ,%bootstrap-guile
409 ,@(package-arguments bash-light))))))
410 (package-with-bootstrap-guile
411 (package-with-explicit-inputs (static-package bash)
412 `(("gcc" ,gcc)
413 ("libc" ,glibc-final-with-bootstrap-bash)
414 ,@(fold alist-delete %boot1-inputs
415 '("gcc" "libc")))
416 (current-source-location)))))
417
418 (define gettext-boot0
419 ;; A minimal gettext used during bootstrap.
420 (let ((gettext-minimal
421 (package (inherit gnu-gettext)
422 (name "gettext-boot0")
423 (inputs '()) ;zero dependencies
424 (arguments
425 (substitute-keyword-arguments
426 `(#:tests? #f
427 ,@(package-arguments gnu-gettext))
428 ((#:phases phases)
429 `(modify-phases ,phases
430 ;; Build only the tools.
431 (add-after 'unpack 'chdir
432 (lambda _
433 (chdir "gettext-tools")))
434
435 ;; Some test programs require pthreads, which we don't have.
436 (add-before 'configure 'no-test-programs
437 (lambda _
438 (substitute* "tests/Makefile.in"
439 (("^PROGRAMS =.*$")
440 "PROGRAMS =\n"))
441 #t))
442
443 ;; Don't try to link against libexpat.
444 (delete 'link-expat)
445 (delete 'patch-tests))))))))
446 (package-with-bootstrap-guile
447 (package-with-explicit-inputs gettext-minimal
448 %boot1-inputs
449 (current-source-location)
450 #:guile %bootstrap-guile))))
451
452 (define-public glibc-final
453 ;; The final glibc, which embeds the statically-linked Bash built above.
454 (package (inherit glibc-final-with-bootstrap-bash)
455 (name "glibc")
456 (inputs `(("static-bash" ,static-bash-for-glibc)
457 ,@(alist-delete
458 "static-bash"
459 (package-inputs glibc-final-with-bootstrap-bash))))
460
461 ;; This time we need 'msgfmt' to install all the libc.mo files.
462 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
463 ("gettext" ,gettext-boot0)))
464
465 ;; The final libc only refers to itself, but the 'debug' output contains
466 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
467 ;; if 'allowed-references' were per-output.
468 (arguments
469 `(#:allowed-references
470 ,(cons* `(,gcc-boot0 "lib") (linux-libre-headers-boot0)
471 (package-outputs glibc-final-with-bootstrap-bash))
472
473 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
474
475 (define gcc-boot0-wrapped
476 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
477 ;; non-cross names.
478 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
479 (car (assoc-ref %boot1-inputs "bash"))))
480
481 (define %boot2-inputs
482 ;; 3rd stage inputs.
483 `(("libc" ,glibc-final)
484 ("gcc" ,gcc-boot0-wrapped)
485 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
486
487 (define binutils-final
488 (package-with-bootstrap-guile
489 (package (inherit binutils)
490 (arguments
491 `(#:guile ,%bootstrap-guile
492 #:implicit-inputs? #f
493 #:allowed-references ("out" ,glibc-final)
494 ,@(package-arguments binutils)))
495 (inputs %boot2-inputs))))
496
497 (define libstdc++
498 ;; Intermediate libstdc++ that will allow us to build the final GCC
499 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
500 (package-with-bootstrap-guile
501 (package (inherit gcc-4.8)
502 (name "libstdc++")
503 (arguments
504 `(#:guile ,%bootstrap-guile
505 #:implicit-inputs? #f
506
507 #:out-of-source? #t
508 #:phases (alist-cons-before
509 'configure 'chdir
510 (lambda _
511 (chdir "libstdc++-v3"))
512 %standard-phases)
513 #:configure-flags `("--disable-shared"
514 "--disable-libstdcxx-threads"
515 "--disable-libstdcxx-pch"
516 ,(string-append "--with-gxx-include-dir="
517 (assoc-ref %outputs "out")
518 "/include"
519 ;; "/include/c++/"
520 ;; ,(package-version gcc-4.8)
521 ))))
522 (outputs '("out"))
523 (inputs %boot2-inputs)
524 (native-inputs '())
525 (propagated-inputs '())
526 (synopsis "GNU C++ standard library (intermediate)"))))
527
528 (define-public gcc-final
529 ;; The final GCC.
530 (package (inherit gcc-boot0)
531 (name "gcc")
532 (arguments
533 `(#:guile ,%bootstrap-guile
534 #:implicit-inputs? #f
535
536 #:allowed-references ("out" "lib" ,glibc-final)
537
538 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
539 ;; reason, but it is not in their RUNPATH. This is a false
540 ;; positive, so turn it off.
541 #:validate-runpath? #f
542
543 ;; Build again GMP & co. within GCC's build process, because it's hard
544 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
545 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
546 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
547 ((#:configure-flags boot-flags)
548 (let loop ((args (package-arguments gcc-4.8)))
549 (match args
550 ((#:configure-flags normal-flags _ ...)
551 normal-flags)
552 ((_ rest ...)
553 (loop rest)))))
554 ((#:make-flags flags)
555 ;; Since $LIBRARY_PATH and $CPATH are not honored, add the
556 ;; relevant flags.
557 `(cons (string-append "CPPFLAGS=-I"
558 (assoc-ref %build-inputs "libstdc++")
559 "/include")
560 (map (lambda (flag)
561 (if (string-prefix? "LDFLAGS=" flag)
562 (string-append flag " -L"
563 (assoc-ref %build-inputs "libstdc++")
564 "/lib")
565 flag))
566 ,flags)))
567 ((#:phases phases)
568 `(alist-delete 'symlink-libgcc_eh ,phases)))))
569
570 ;; This time we want Texinfo, so we get the manual.
571 (native-inputs `(("texinfo" ,texinfo-boot0)
572 ,@(package-native-inputs gcc-boot0)))
573
574 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp)))
575 ("mpfr-source" ,(package-source mpfr))
576 ("mpc-source" ,(package-source mpc))
577 ("binutils" ,binutils-final)
578 ("libstdc++" ,libstdc++)
579 ,@%boot2-inputs))))
580
581 (define ld-wrapper-boot3
582 ;; A linker wrapper that uses the bootstrap Guile.
583 (make-ld-wrapper "ld-wrapper-boot3"
584 #:binutils binutils-final
585 #:guile %bootstrap-guile
586 #:bash (car (assoc-ref %boot2-inputs "bash"))))
587
588 (define %boot3-inputs
589 ;; 4th stage inputs.
590 `(("gcc" ,gcc-final)
591 ("ld-wrapper" ,ld-wrapper-boot3)
592 ,@(alist-delete "gcc" %boot2-inputs)))
593
594 (define bash-final
595 ;; Link with `-static-libgcc' to make sure we don't retain a reference
596 ;; to the bootstrap GCC.
597 (package-with-bootstrap-guile
598 (package-with-explicit-inputs (static-libgcc-package bash)
599 %boot3-inputs
600 (current-source-location)
601 #:guile %bootstrap-guile)))
602
603 (define %boot4-inputs
604 ;; Now use the final Bash.
605 `(("bash" ,bash-final)
606 ,@(alist-delete "bash" %boot3-inputs)))
607
608 (define-public guile-final
609 (package-with-bootstrap-guile
610 (package-with-explicit-inputs guile-2.0/fixed
611 %boot4-inputs
612 (current-source-location)
613 #:guile %bootstrap-guile)))
614
615 (define-public glibc-utf8-locales-final
616 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
617 ;; by the build processes afterwards so their 'scm_to_locale_string' works
618 ;; with the full range of Unicode codepoints (remember
619 ;; 'scm_to_locale_string' is called every time a string is passed to a C
620 ;; function.)
621 (package
622 (inherit glibc-utf8-locales)
623 (inputs `(("glibc" ,glibc-final)
624 ("gzip"
625 ,(package-with-explicit-inputs gzip %boot4-inputs
626 (current-source-location)
627 #:guile %bootstrap-guile))))))
628
629 (define %boot5-inputs
630 ;; Now with UTF-8 locale.
631 `(("locales" ,glibc-utf8-locales-final)
632 ,@%boot4-inputs))
633
634 (define gnu-make-final
635 ;; The final GNU Make, which uses the final Guile.
636 (package-with-bootstrap-guile
637 (package-with-explicit-inputs gnu-make
638 `(("guile" ,guile-final)
639 ,@%boot5-inputs)
640 (current-source-location))))
641
642 (define-public ld-wrapper
643 ;; The final `ld' wrapper, which uses the final Guile.
644 (package (inherit ld-wrapper-boot3)
645 (name "ld-wrapper")
646 (inputs `(("guile" ,guile-final)
647 ("bash" ,bash-final)
648 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
649 '("guile" "bash"))))))
650
651 (define coreutils-final
652 ;; The final Coreutils. Treat them specially because some packages, such as
653 ;; Findutils, keep a reference to the Coreutils they were built with.
654 (package-with-bootstrap-guile
655 (package-with-explicit-inputs coreutils
656 %boot5-inputs
657 (current-source-location)
658
659 ;; Use the final Guile, linked against the
660 ;; final libc with working iconv, so that
661 ;; 'substitute*' works well when touching
662 ;; test files in Gettext.
663 #:guile guile-final)))
664
665 (define grep-final
666 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
667 ;; built before gzip.
668 (package-with-bootstrap-guile
669 (package-with-explicit-inputs grep
670 %boot5-inputs
671 (current-source-location)
672 #:guile guile-final)))
673
674 (define %boot6-inputs
675 ;; Now use the final Coreutils.
676 `(("coreutils" ,coreutils-final)
677 ("grep" ,grep-final)
678 ,@%boot5-inputs))
679
680 (define-public %final-inputs
681 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
682 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
683 ;; used for origins that have patches, thereby avoiding circular
684 ;; dependencies.
685 (let ((finalize (compose package-with-bootstrap-guile
686 (cut package-with-explicit-inputs <> %boot6-inputs
687 (current-source-location)))))
688 `(,@(map (match-lambda
689 ((name package)
690 (list name (finalize package))))
691 `(("tar" ,tar)
692 ("gzip" ,gzip)
693 ("bzip2" ,bzip2)
694 ("xz" ,xz)
695 ("file" ,file)
696 ("diffutils" ,diffutils)
697 ("patch" ,patch)
698 ("sed" ,sed)
699 ("findutils" ,findutils)
700 ("gawk" ,gawk)))
701 ("grep" ,grep-final)
702 ("coreutils" ,coreutils-final)
703 ("make" ,gnu-make-final)
704 ("bash" ,bash-final)
705 ("ld-wrapper" ,ld-wrapper)
706 ("binutils" ,binutils-final)
707 ("gcc" ,gcc-final)
708 ("libc" ,glibc-final)
709 ("locales" ,glibc-utf8-locales-final))))
710
711 (define-public canonical-package
712 (let ((name->package (fold (lambda (input result)
713 (match input
714 ((_ package)
715 (vhash-cons (package-full-name package)
716 package result))))
717 vlist-null
718 `(("guile" ,guile-final)
719 ,@%final-inputs))))
720 (lambda (package)
721 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
722 the implicit inputs of 'gnu-build-system', return that one, otherwise return
723 PACKAGE.
724
725 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.0,
726 COREUTILS-FINAL vs. COREUTILS, etc."
727 ;; XXX: This doesn't handle dependencies of the final inputs, such as
728 ;; libunistring, GMP, etc.
729 (match (vhash-assoc (package-full-name package) name->package)
730 ((_ . canon)
731 ;; In general we want CANON, except if we're cross-compiling: CANON
732 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
733 ;; process, with dependencies on things that cannot be
734 ;; cross-compiled.
735 (if (%current-target-system)
736 package
737 canon))
738 (_ package)))))
739
740 \f
741 ;;;
742 ;;; GCC toolchain.
743 ;;;
744
745 (define (gcc-toolchain gcc)
746 "Return a complete toolchain for GCC."
747 (package
748 (name "gcc-toolchain")
749 (version (package-version gcc))
750 (source #f)
751 (build-system trivial-build-system)
752 (arguments
753 '(#:modules ((guix build union))
754 #:builder (begin
755 (use-modules (ice-9 match)
756 (srfi srfi-26)
757 (guix build union))
758
759 (let ((out (assoc-ref %outputs "out")))
760
761 (match %build-inputs
762 (((names . directories) ...)
763 (union-build out directories)))
764
765 ;; Remove the 'sh' and 'bash' binaries that come with
766 ;; libc to avoid polluting the user's profile (these are
767 ;; statically-linked binaries with no locale support and
768 ;; so on.)
769 (for-each (lambda (file)
770 (delete-file (string-append out "/bin/" file)))
771 '("sh" "bash"))
772
773 (union-build (assoc-ref %outputs "debug")
774 (list (assoc-ref %build-inputs
775 "libc-debug")))))))
776
777 (native-search-paths (package-native-search-paths gcc))
778 (search-paths (package-search-paths gcc))
779
780 (license (package-license gcc))
781 (synopsis "Complete GCC tool chain for C/C++ development")
782 (description
783 "This package provides a complete GCC tool chain for C/C++ development to
784 be installed in user profiles. This includes GCC, as well as libc (headers
785 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
786 (home-page "http://gcc.gnu.org/")
787 (outputs '("out" "debug"))
788
789 ;; The main raison d'être of this "meta-package" is (1) to conveniently
790 ;; install everything that we need, and (2) to make sure ld-wrapper comes
791 ;; before Binutils' ld in the user's profile.
792 (inputs `(("gcc" ,gcc)
793 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
794 ("binutils" ,binutils-final)
795 ("libc" ,glibc-final)
796 ("libc-debug" ,glibc-final "debug")))))
797
798 (define-public gcc-toolchain-4.8
799 (gcc-toolchain gcc-final))
800
801 (define-public gcc-toolchain-4.9
802 (gcc-toolchain gcc-4.9))
803
804 (define-public gcc-toolchain-5.1
805 (gcc-toolchain gcc-5.1))
806
807 ;;; commencement.scm ends here