1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 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 Mark H Weaver <mhw@netris.org>
7 ;;; This file is part of GNU Guix.
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.
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.
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 base)
23 #:use-module ((guix licenses)
24 #:select (gpl3+ lgpl2.0+ public-domain))
25 #:use-module (gnu packages)
26 #:use-module (gnu packages acl)
27 #:use-module (gnu packages bash)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (gnu packages compression)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages gawk)
32 #:use-module (gnu packages guile)
33 #:use-module (gnu packages multiprecision)
34 #:use-module (gnu packages perl)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages texinfo)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (guix packages)
39 #:use-module (guix download)
40 #:use-module (guix build-system gnu)
41 #:use-module (guix build-system trivial)
42 #:use-module (guix utils)
43 #:use-module (srfi srfi-1)
44 #:use-module (srfi srfi-26)
45 #:use-module (ice-9 vlist)
46 #:use-module (ice-9 match))
50 ;;; Base packages of the Guix-based GNU user-land software distribution.
60 (uri (string-append "mirror://gnu/hello/hello-" version
63 (base32 "19qy37gkasc4csb1d3bdiz9snn8mir2p3aj0jgzmfv0r2hi7mfzc"))))
64 (build-system gnu-build-system)
65 (synopsis "Hello, GNU world: An example GNU package")
67 "GNU Hello prints the message \"Hello, world!\" and then exits. It
68 serves as an example of standard GNU coding practices. As such, it supports
69 command-line arguments, multiple languages, and so on.")
70 (home-page "http://www.gnu.org/software/hello/")
79 (uri (string-append "mirror://gnu/grep/grep-"
83 "0rcs0spsxdmh6yz8y4frkqp6f5iw19mdbdl9s2v6956hq0mlbbzh"))))
84 (build-system gnu-build-system)
85 (synopsis "Print lines matching a pattern")
87 "grep is a tool for finding text inside files. Text is found by
88 matching a pattern provided by the user in one or many files. The pattern
89 may be provided as a basic or extended regular expression, or as fixed
90 strings. By default, the matching text is simply printed to the screen,
91 however the output can be greatly customized to include, for example, line
92 numbers. GNU grep offers many extensions over the standard utility,
93 including, for example, recursive directory searching.")
95 (home-page "http://www.gnu.org/software/grep/")))
103 (uri (string-append "mirror://gnu/sed/sed-" version
107 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
108 (build-system gnu-build-system)
109 (synopsis "Stream editor")
111 (if (%current-target-system)
113 `(#:phases (alist-cons-before
114 'patch-source-shebangs 'patch-test-suite
115 (lambda* (#:key inputs #:allow-other-keys)
116 (let ((bash (assoc-ref inputs "bash")))
117 (patch-makefile-SHELL "testsuite/Makefile.tests")
118 (substitute* '("testsuite/bsd.sh"
119 "testsuite/bug-regex9.c")
121 (string-append bash "/bin/bash")))))
124 "Sed is a non-interactive, text stream editor. It receives a text
125 input from a file or from standard input and it then applies a series of text
126 editing commands to the stream and prints its output to standard output. It
127 is often used for substituting text patterns in a stream. The GNU
128 implementation offers several extensions over the standard utility.")
130 (home-page "http://www.gnu.org/software/sed/")))
138 (uri (string-append "mirror://gnu/tar/tar-"
142 "1iip0fk0wqhxb0jcwphz43r4fxkx1y7mznnhmlvr618jhp7b63wv"))))
143 (build-system gnu-build-system)
144 (synopsis "Managing tar archives")
146 "Tar provides the ability to create tar archives, as well as the
147 ability to extract, update or list files in an existing archive. It is
148 useful for combining many files into one larger file, while maintaining
149 directory structure and file information such as permissions and
150 creation/modification dates. GNU tar offers many extensions over the
153 (home-page "http://www.gnu.org/software/tar/")))
161 (uri (string-append "mirror://gnu/patch/patch-"
165 "1sqckf560pzwgniy00vcpdv2c9c11s4cmhlm14yqgg8avd3bl94i"))))
166 (build-system gnu-build-system)
167 (native-inputs '()) ; FIXME: needs `ed' for the tests
170 ;; TODO: When cross-compiling, add this:
171 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
173 (synopsis "Apply differences to originals, with optional backups")
175 "Patch is a program that applies changes to files based on differences
176 laid out as by the program \"diff\". The changes may be applied to one or more
177 files depending on the contents of the diff file. It accepts several
178 different diff formats. It may also be used to revert previously applied
181 (home-page "http://savannah.gnu.org/projects/patch/")))
183 (define-public diffutils
189 (uri (string-append "mirror://gnu/diffutils/diffutils-"
193 "1761vymxbp4wb5rzjvabhdkskk95pghnn67464byvzb5mfl8jpm2"))))
194 (build-system gnu-build-system)
195 (synopsis "Comparing and merging files")
197 "GNU Diffutils is a package containing tools for finding the
198 differences between files. The \"diff\" command is used to show how two files
199 differ, while \"cmp\" shows the offsets and line numbers where they differ.
200 \"diff3\" allows you to compare three files. Finally, \"sdiff\" offers an
201 interactive means to merge two files.")
203 (home-page "http://www.gnu.org/software/diffutils/")))
205 (define-public findutils
211 (uri (string-append "mirror://gnu/findutils/findutils-"
215 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))
216 (patches (list (search-patch "findutils-absolute-paths.patch")))))
217 (build-system gnu-build-system)
219 ;; Work around cross-compilation failure.
220 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
221 (if (%current-target-system)
222 '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
224 (synopsis "Operating on files matching given criteria")
226 "Findutils supplies the basic file directory searching utilities of the
227 GNU system. It consists of two primary searching utilities: \"find\"
228 recursively searches for files in a directory according to given criteria and
229 \"locate\" lists files in a database that match a query. Two auxiliary tools
230 are included: \"updatedb\" updates the file name database and \"xargs\" may be
231 used to apply commands with arbitrarily long arguments.")
233 (home-page "http://www.gnu.org/software/findutils/")))
235 (define-public coreutils
241 (uri (string-append "mirror://gnu/coreutils/coreutils-"
245 "04hjzzv434fb8ak3hh3dyhdvg3hqjjwvjmjxqzk1gh2jh6cr8gjv"))
246 (patches (list (search-patch "coreutils-dummy-man.patch")
247 ;; TODO: remove this patch for >= 8.23
248 (search-patch "coreutils-skip-nohup.patch")))))
249 (build-system gnu-build-system)
250 (inputs `(("acl" ,acl) ; TODO: add SELinux
253 ;; Perl is needed to run tests in native builds, and to run the bundled
254 ;; copy of help2man. However, don't pass it when cross-compiling since
255 ;; that would lead it to try to run programs to get their '--help' output
257 (if (%current-target-system)
260 (outputs '("out" "debug"))
262 `(#:parallel-build? #f ; help2man may be called too early
263 #:phases (alist-cons-before
264 'build 'patch-shell-references
265 (lambda* (#:key inputs #:allow-other-keys)
266 (let ((bash (assoc-ref inputs "bash")))
267 ;; 'split' uses either $SHELL or /bin/sh. Set $SHELL so
268 ;; that tests pass, since /bin/sh isn't in the chroot.
269 (setenv "SHELL" (which "sh"))
271 (substitute* (find-files "gnulib-tests" "\\.c$")
273 (format #f "~a/bin/sh" bash)))
274 (substitute* (find-files "tests" "\\.sh$")
276 (format #f "#!~a/bin/sh" bash)))))
278 (synopsis "Core GNU utilities (file, text, shell)")
280 "GNU Coreutils includes all of the basic command-line tools that are
281 expected in a POSIX system. These provide the basic file, shell and text
282 manipulation functions of the GNU system. Most of these tools offer extended
283 functionality beyond that which is outlined in the POSIX standard.")
285 (home-page "http://www.gnu.org/software/coreutils/")))
287 (define-public gnu-make
293 (uri (string-append "mirror://gnu/make/make-" version
297 "1nyvn8mknw0mf7727lprva3lisl1y0n03lvar342rrpdmz3qc1p6"))
298 (patches (list (search-patch "make-impure-dirs.patch")))))
299 (build-system gnu-build-system)
300 (native-inputs `(("pkg-config", pkg-config))) ; to detect Guile
301 (inputs `(("guile" ,guile-2.0)))
302 (outputs '("out" "debug"))
304 '(#:phases (alist-cons-before
305 'build 'set-default-shell
306 (lambda* (#:key inputs #:allow-other-keys)
307 ;; Change the default shell from /bin/sh.
308 (let ((bash (assoc-ref inputs "bash")))
310 (("default_shell\\[\\] =.*$")
311 (format #f "default_shell[] = \"~a/bin/bash\";\n"
314 (synopsis "Remake files automatically")
316 "Make is a program that is used to control the production of
317 executables or other files from their source files. The process is
318 controlled from a Makefile, in which the developer specifies how each file is
319 generated from its source. It has powerful dependency resolution and the
320 ability to determine when files have to be regenerated after their sources
321 change. GNU make offers many powerful extensions over the standard utility.")
323 (home-page "http://www.gnu.org/software/make/")))
325 (define-public binutils
331 (uri (string-append "mirror://gnu/binutils/binutils-"
335 "0ds1y7qa0xqihw4ihnsgg6bxanmb228r228ddvwzgrv4jszcbs75"))
336 (patches (list (search-patch "binutils-ld-new-dtags.patch")
337 (search-patch "binutils-loongson-workaround.patch")))))
338 (build-system gnu-build-system)
340 ;; TODO: Add dependency on zlib + those for Gold.
342 `(#:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
343 ;; on GCC when bootstrapping.
344 "LDFLAGS=-static-libgcc"
346 ;; Don't search under /usr/lib & co.
347 "--with-lib-path=/no-ld-lib-path"
349 ;; Glibc 2.17 has a "comparison of unsigned
350 ;; expression >= 0 is always true" in wchar.h.
353 ;; Install BFD. It ends up in a hidden directory,
355 "--enable-install-libbfd"
357 ;; Make sure 'ar' and 'ranlib' produce archives in a
358 ;; deterministic fashion.
359 "--enable-deterministic-archives")))
361 (synopsis "Binary utilities: bfd gas gprof ld")
363 "GNU Binutils is a collection of tools for working with binary files.
364 Perhaps the most notable are \"ld\", a linker, and \"as\", an assembler. Other
365 tools include programs to display binary profiling information, list the
366 strings in a binary file, and utilities for working with archives. The \"bfd\"
367 library for working with executable and object formats is also included.")
369 (home-page "http://www.gnu.org/software/binutils/")))
377 (uri (string-append "mirror://gnu/glibc/glibc-"
381 "18m2dssd6ja5arxmdxinc90xvpqcsnqjfwmjl2as07j0i3srff9d"))
383 ;; Disable 'ldconfig' and /etc/ld.so.cache. The latter is
384 ;; required on LFS distros to avoid loading the distro's libc.so
386 '(substitute* "sysdeps/unix/sysv/linux/configure"
387 (("use_ldconfig=yes")
389 (modules '((guix build utils)))
390 (patches (list (search-patch "glibc-ldd-x86_64.patch")))))
391 (build-system gnu-build-system)
393 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
394 ;; users should automatically pull Linux headers as well.
395 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
397 ;; Store the locales separately (~100 MiB). Note that "out" retains a
398 ;; reference to them anyway, so there's no space savings here.
399 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
401 (outputs '("out" "locales" "debug"))
404 `(#:out-of-source? #t
406 (list "--enable-add-ons"
408 (string-append "--localedir=" (assoc-ref %outputs "locales")
411 ;; `--localedir' is not honored, so work around it.
412 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
413 (string-append "libc_cv_localedir="
414 (assoc-ref %outputs "locales")
417 (string-append "--with-headers="
418 (assoc-ref %build-inputs "linux-headers")
421 ;; The default is to assume a 2.4 Linux interface, but we'll
422 ;; always use something newer. See "kernel-features.h" in the
423 ;; GNU libc for details.
424 "--enable-kernel=2.6.30"
426 ;; Use our Bash instead of /bin/sh.
427 (string-append "BASH_SHELL="
428 (assoc-ref %build-inputs "bash")
431 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
435 #:phases (alist-cons-before
436 'configure 'pre-configure
437 (lambda* (#:key inputs outputs #:allow-other-keys)
438 (let* ((out (assoc-ref outputs "out"))
439 (bin (string-append out "/bin")))
440 ;; Use `pwd', not `/bin/pwd'.
441 (substitute* "configure"
442 (("/bin/pwd") "pwd"))
444 ;; Install the rpc data base file under `$out/etc/rpc'.
445 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
446 (substitute* "sunrpc/Makefile"
447 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
448 (string-append out "/etc/rpc" suffix "\n"))
449 (("^install-others =.*$")
450 (string-append "install-others = " out "/etc/rpc\n")))
452 (substitute* "Makeconfig"
454 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
455 ;; linking against libgcc_s is not needed with GCC
459 ;; Copy a statically-linked Bash in the output, with
460 ;; no references to other store paths.
462 (copy-file (string-append (assoc-ref inputs "static-bash")
464 (string-append bin "/bash"))
465 (remove-store-references (string-append bin "/bash"))
466 (chmod (string-append bin "/bash") #o555)
468 ;; Keep a symlink, for `patch-shebang' resolution.
469 (with-directory-excursion bin
470 (symlink "bash" "sh"))
472 ;; Have `system' use that Bash.
473 (substitute* "sysdeps/posix/system.c"
474 (("#define[[:blank:]]+SHELL_PATH.*$")
475 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
479 (substitute* "libio/iopopen.c"
481 (string-append out "/bin/bash")))
483 ;; Make sure we don't retain a reference to the
485 (substitute* "malloc/mtrace.pl"
487 ;; The shebang can be omitted, because there's the
488 ;; "bilingual" eval/exec magic at the top of the file.
493 'install 'install-locales
495 (zero? (system* "make" "localedata/install-locales")))
498 (inputs `(("static-bash" ,(static-package bash-light))))
500 ;; To build the manual, we need Texinfo and Perl.
501 (native-inputs `(("texinfo" ,texinfo)
504 (synopsis "The GNU C Library")
506 "Any Unix-like operating system needs a C library: the library which
507 defines the \"system calls\" and other basic facilities such as open, malloc,
510 The GNU C library is used as the C library in the GNU system and most systems
511 with the Linux kernel.")
513 (home-page "http://www.gnu.org/software/libc/")))
515 (define-public tzdata
522 "http://www.iana.org/time-zones/repository/releases/tzdata"
526 "1cg843ajz4g16axpz56zvalwsbp1s764na2bk4fb44ayx162bzvw"))))
527 (build-system gnu-build-system)
530 #:make-flags (let ((out (assoc-ref %outputs "out"))
531 (tmp (getenv "TMPDIR")))
532 (list (string-append "TOPDIR=" out)
533 (string-append "TZDIR=" out "/share/zoneinfo")
535 ;; Discard zic, dump, and tzselect, already
536 ;; provided by glibc.
537 (string-append "ETCDIR=" tmp "/etc")
539 ;; Likewise for the C library routines.
540 (string-append "LIBDIR=" tmp "/lib")
541 (string-append "MANDIR=" tmp "/man")
545 #:modules ((guix build utils)
546 (guix build gnu-build-system)
551 (lambda* (#:key source inputs #:allow-other-keys)
552 (and (zero? (system* "tar" "xvf" source))
553 (zero? (system* "tar" "xvf" (assoc-ref inputs "tzcode")))))
555 'install 'post-install
556 (lambda* (#:key outputs #:allow-other-keys)
557 ;; Move data in the right place.
558 (let ((out (assoc-ref outputs "out")))
559 (copy-recursively (string-append out "/share/zoneinfo-posix")
560 (string-append out "/share/zoneinfo/posix"))
561 (copy-recursively (string-append out "/share/zoneinfo-leaps")
562 (string-append out "/share/zoneinfo/right"))
563 (delete-file-recursively (string-append out "/share/zoneinfo-posix"))
564 (delete-file-recursively (string-append out "/share/zoneinfo-leaps"))))
565 (alist-delete 'configure %standard-phases)))))
566 (inputs `(("tzcode" ,(origin
569 "http://www.iana.org/time-zones/repository/releases/tzcode"
573 "1xfkqi1q8cnxqbv8azdj5pqlzhkjz6xag09f1z0s8rxi86jkpf85"))))))
574 (home-page "http://www.iana.org/time-zones")
575 (synopsis "Database of current and historical time zones")
576 (description "The Time Zone Database (often called tz or zoneinfo)
577 contains code and data that represent the history of local time for many
578 representative locations around the globe. It is updated periodically to
579 reflect changes made by political bodies to time zone boundaries, UTC offsets,
580 and daylight-saving rules.")
581 (license public-domain)))
585 ;;; Bootstrap packages.
588 (define gnu-make-boot0
589 (package-with-bootstrap-guile
590 (package (inherit gnu-make)
592 (location (source-properties->location (current-source-location)))
594 `(#:guile ,%bootstrap-guile
595 #:implicit-inputs? #f
596 #:tests? #f ; cannot run "make check"
597 ,@(substitute-keyword-arguments (package-arguments gnu-make)
601 ;; Don't attempt to build 'guile.c' since we don't
603 (substitute* "build.sh"
604 (("guile\\.\\$\\{OBJEXT\\}") ""))
605 (zero? (system* "./build.sh")))
607 'install (lambda* (#:key outputs #:allow-other-keys)
608 (let* ((out (assoc-ref outputs "out"))
609 (bin (string-append out "/bin")))
612 (string-append bin "/make"))))
614 (native-inputs '()) ; no need for 'pkg-config'
615 (inputs %bootstrap-inputs))))
617 (define diffutils-boot0
618 (package-with-bootstrap-guile
619 (let ((p (package-with-explicit-inputs diffutils
620 `(("make" ,gnu-make-boot0)
622 #:guile %bootstrap-guile)))
624 (location (source-properties->location (current-source-location)))
625 (arguments `(#:tests? #f ; the test suite needs diffutils
626 ,@(package-arguments p)))))))
628 (define findutils-boot0
629 (package-with-bootstrap-guile
630 (package-with-explicit-inputs findutils
631 `(("make" ,gnu-make-boot0)
632 ("diffutils" ,diffutils-boot0) ; for tests
634 (current-source-location)
635 #:guile %bootstrap-guile)))
638 (define %boot0-inputs
639 `(("make" ,gnu-make-boot0)
640 ("diffutils" ,diffutils-boot0)
641 ("findutils" ,findutils-boot0)
642 ,@%bootstrap-inputs))
644 (define* (nix-system->gnu-triplet
645 #:optional (system (%current-system)) (vendor "unknown"))
646 "Return an a guess of the GNU triplet corresponding to Nix system
648 (let* ((dash (string-index system #\-))
649 (arch (substring system 0 dash))
650 (os (substring system (+ 1 dash))))
653 (if (string=? os "linux")
657 (define* (boot-triplet #:optional (system (%current-system)))
658 ;; Return the triplet used to create the cross toolchain needed in the
659 ;; first bootstrapping stage.
660 (nix-system->gnu-triplet system "guix"))
662 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
663 ;; toolchain actually targets the same OS and arch, but it has the advantage
664 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
665 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
667 (define binutils-boot0
668 (package-with-bootstrap-guile
669 (package (inherit binutils)
670 (name "binutils-cross-boot0")
672 `(#:guile ,%bootstrap-guile
673 #:implicit-inputs? #f
674 ,@(substitute-keyword-arguments (package-arguments binutils)
675 ((#:configure-flags cf)
676 `(cons ,(string-append "--target=" (boot-triplet))
678 (inputs %boot0-inputs))))
681 (package-with-bootstrap-guile
682 (package (inherit gcc-4.8)
683 (name "gcc-cross-boot0")
685 `(#:guile ,%bootstrap-guile
686 #:implicit-inputs? #f
687 #:modules ((guix build gnu-build-system)
692 ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
693 ((#:configure-flags flags)
694 `(append (list ,(string-append "--target=" (boot-triplet))
699 ;; Disable features not needed at this stage.
701 "--enable-languages=c,c++"
703 ;; libstdc++ cannot be built at this stage
704 ;; ("Link tests are not allowed after
705 ;; GCC_NO_EXECUTABLES.").
706 "--disable-libstdc++-v3"
709 "--disable-libmudflap"
710 "--disable-libatomic"
711 "--disable-libsanitizer"
715 "--disable-libquadmath"
716 "--disable-decimal-float")
717 (remove (cut string-match "--enable-languages.*" <>)
721 'unpack 'unpack-gmp&co
722 (lambda* (#:key inputs #:allow-other-keys)
723 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
724 (mpfr (assoc-ref %build-inputs "mpfr-source"))
725 (mpc (assoc-ref %build-inputs "mpc-source")))
727 ;; To reduce the set of pre-built bootstrap inputs, build
728 ;; GMP & co. from GCC.
729 (for-each (lambda (source)
730 (or (zero? (system* "tar" "xvf" source))
731 (error "failed to unpack tarball"
735 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
737 ;; Drop trailing letters, as gmp-6.0.0a unpacks
739 `(symlink ,(string-trim-right
740 (package-full-name lib)
742 ,(package-name lib)))
743 (list gmp mpfr mpc))))
745 'install 'symlink-libgcc_eh
746 (lambda* (#:key outputs #:allow-other-keys)
747 (let ((out (assoc-ref outputs "lib")))
748 ;; Glibc wants to link against libgcc_eh, so provide
750 (with-directory-excursion
751 (string-append out "/lib/gcc/"
753 "/" ,(package-version gcc-4.8))
754 (symlink "libgcc.a" "libgcc_eh.a"))))
757 (inputs `(("gmp-source" ,(package-source gmp))
758 ("mpfr-source" ,(package-source mpfr))
759 ("mpc-source" ,(package-source mpc))
760 ("binutils-cross" ,binutils-boot0)
762 ;; Call it differently so that the builder can check whether
763 ;; the "libc" input is #f.
764 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
765 ,@(alist-delete "libc" %boot0-inputs)))
767 ;; No need for Texinfo at this stage.
768 (native-inputs (alist-delete "texinfo"
769 (package-native-inputs gcc-4.8))))))
772 (package-with-bootstrap-guile
773 (package-with-explicit-inputs perl
775 (current-source-location)
776 #:guile %bootstrap-guile)))
778 (define (linux-libre-headers-boot0)
779 "Return Linux-Libre header files for the bootstrap environment."
780 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
781 ;; between (gnu packages linux) and this module.
782 (package-with-bootstrap-guile
783 (package (inherit linux-libre-headers)
784 (arguments `(#:guile ,%bootstrap-guile
785 #:implicit-inputs? #f
786 ,@(package-arguments linux-libre-headers)))
788 `(("perl" ,perl-boot0)
791 (define texinfo-boot0
792 ;; Texinfo used to build libc's manual.
793 ;; We build without ncurses because it fails to build at this stage, and
794 ;; because we don't need the stand-alone Info reader.
795 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
796 (let ((texinfo (package (inherit texinfo)
797 (inputs (alist-delete "ncurses" (package-inputs texinfo))))))
798 (package-with-bootstrap-guile
799 (package-with-explicit-inputs texinfo %boot0-inputs
800 (current-source-location)
801 #:guile %bootstrap-guile))))
803 (define %boot1-inputs
806 ("binutils-cross" ,binutils-boot0)
808 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
812 (define glibc-final-with-bootstrap-bash
813 ;; The final libc, "cross-built". If everything went well, the resulting
814 ;; store path has no dependencies. Actually, the really-final libc is
815 ;; built just below; the only difference is that this one uses the
817 (package-with-bootstrap-guile
818 (package (inherit glibc)
819 (name "glibc-intermediate")
821 `(#:guile ,%bootstrap-guile
822 #:implicit-inputs? #f
824 ,@(substitute-keyword-arguments (package-arguments glibc)
825 ((#:configure-flags flags)
826 `(append (list ,(string-append "--host=" (boot-triplet))
827 ,(string-append "--build="
828 (nix-system->gnu-triplet))
830 ;; Build Sun/ONC RPC support. In particular,
832 "--enable-obsolete-rpc")
836 'configure 'pre-configure
837 (lambda* (#:key inputs #:allow-other-keys)
838 ;; Don't clobber CPATH with the bootstrap libc.
839 (setenv "NATIVE_CPATH" (getenv "CPATH"))
842 ;; 'rpcgen' needs native libc headers to be built.
843 (substitute* "sunrpc/Makefile"
844 (("sunrpc-CPPFLAGS =.*" all)
845 (string-append "CPATH = $(NATIVE_CPATH)\n"
849 (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
851 `(("texinfo" ,texinfo-boot0)
852 ("perl" ,perl-boot0)))
854 `(;; The boot inputs. That includes the bootstrap libc. We don't want
855 ;; it in $CPATH, hence the 'pre-configure' phase above.
858 ;; A native GCC is needed to build `cross-rpcgen'.
859 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
861 ;; Here, we use the bootstrap Bash, which is not satisfactory
862 ;; because we don't want to depend on bootstrap tools.
863 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
865 (define (cross-gcc-wrapper gcc binutils glibc bash)
866 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
867 that makes it available under the native tool names."
868 (package (inherit gcc-4.8)
869 (name (string-append (package-name gcc) "-wrapped"))
871 (build-system trivial-build-system)
874 `(#:guile ,%bootstrap-guile
875 #:modules ((guix build utils))
877 (use-modules (guix build utils))
879 (let* ((binutils (assoc-ref %build-inputs "binutils"))
880 (gcc (assoc-ref %build-inputs "gcc"))
881 (libc (assoc-ref %build-inputs "libc"))
882 (bash (assoc-ref %build-inputs "bash"))
883 (out (assoc-ref %outputs "out"))
884 (bindir (string-append out "/bin"))
885 (triplet ,(boot-triplet)))
886 (define (wrap-program program)
887 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
888 ;; needs to be told where to find the crt files and
889 ;; the dynamic linker.
890 (call-with-output-file program
892 (format p "#!~a/bin/bash
893 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
897 ,(glibc-dynamic-linker))))
899 (chmod program #o555))
902 (with-directory-excursion bindir
903 (for-each (lambda (tool)
904 (symlink (string-append binutils "/bin/"
908 (for-each wrap-program '("gcc" "g++")))))))
910 `(("binutils" ,binutils)
916 (define static-bash-for-glibc
917 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
919 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
920 glibc-final-with-bootstrap-bash
921 (car (assoc-ref %boot1-inputs "bash"))))
922 (bash (package (inherit bash-light)
924 `(#:guile ,%bootstrap-guile
925 ,@(package-arguments bash-light))))))
926 (package-with-bootstrap-guile
927 (package-with-explicit-inputs (static-package bash)
929 ("libc" ,glibc-final-with-bootstrap-bash)
930 ,@(fold alist-delete %boot1-inputs
932 (current-source-location)))))
934 (define-public glibc-final
935 ;; The final glibc, which embeds the statically-linked Bash built above.
936 (package (inherit glibc-final-with-bootstrap-bash)
938 (inputs `(("static-bash" ,static-bash-for-glibc)
941 (package-inputs glibc-final-with-bootstrap-bash))))
943 ;; The final libc only refers to itself, but the 'debug' output contains
944 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
945 ;; if 'allowed-references' were per-output.
947 `(#:allowed-references
948 ,(cons* `(,gcc-boot0 "lib") (linux-libre-headers-boot0)
949 (package-outputs glibc-final-with-bootstrap-bash))
951 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
953 (define gcc-boot0-wrapped
954 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
956 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
957 (car (assoc-ref %boot1-inputs "bash"))))
959 (define %boot2-inputs
961 `(("libc" ,glibc-final)
962 ("gcc" ,gcc-boot0-wrapped)
963 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
965 (define binutils-final
966 (package-with-bootstrap-guile
967 (package (inherit binutils)
969 `(#:guile ,%bootstrap-guile
970 #:implicit-inputs? #f
971 #:allowed-references ("out" ,glibc-final)
972 ,@(package-arguments binutils)))
973 (inputs %boot2-inputs))))
976 ;; Intermediate libstdc++ that will allow us to build the final GCC
977 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
978 (package-with-bootstrap-guile
979 (package (inherit gcc-4.8)
982 `(#:guile ,%bootstrap-guile
983 #:implicit-inputs? #f
986 #:phases (alist-cons-before
989 (chdir "libstdc++-v3"))
991 #:configure-flags `("--disable-shared"
992 "--disable-libstdcxx-threads"
993 "--disable-libstdcxx-pch"
994 ,(string-append "--with-gxx-include-dir="
995 (assoc-ref %outputs "out")
998 ;; ,(package-version gcc-4.8)
1001 (inputs %boot2-inputs)
1003 (propagated-inputs '())
1004 (synopsis "GNU C++ standard library (intermediate)"))))
1006 (define-public gcc-final
1008 (package (inherit gcc-boot0)
1010 (location (source-properties->location (current-source-location)))
1012 `(#:guile ,%bootstrap-guile
1013 #:implicit-inputs? #f
1015 #:allowed-references ("out" "lib" ,glibc-final)
1017 ;; Build again GMP & co. within GCC's build process, because it's hard
1018 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
1019 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
1020 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
1021 ((#:configure-flags boot-flags)
1022 (let loop ((args (package-arguments gcc-4.8)))
1024 ((#:configure-flags normal-flags _ ...)
1028 ((#:make-flags flags)
1029 ;; Since $LIBRARY_PATH and $CPATH are not honored, add the
1031 `(cons (string-append "CPPFLAGS=-I"
1032 (assoc-ref %build-inputs "libstdc++")
1035 (if (string-prefix? "LDFLAGS=" flag)
1036 (string-append flag " -L"
1037 (assoc-ref %build-inputs "libstdc++")
1042 `(alist-delete 'symlink-libgcc_eh ,phases)))))
1044 ;; This time we want Texinfo, so we get the manual.
1045 (native-inputs `(("texinfo" ,texinfo-boot0)
1046 ,@(package-native-inputs gcc-boot0)))
1048 (inputs `(("gmp-source" ,(package-source gmp))
1049 ("mpfr-source" ,(package-source mpfr))
1050 ("mpc-source" ,(package-source mpc))
1051 ("binutils" ,binutils-final)
1052 ("libstdc++" ,libstdc++)
1055 (define ld-wrapper-boot3
1056 ;; A linker wrapper that uses the bootstrap Guile.
1058 (name "ld-wrapper-boot3")
1061 (build-system trivial-build-system)
1062 (inputs `(("binutils" ,binutils-final)
1063 ("guile" ,%bootstrap-guile)
1064 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
1065 ("wrapper" ,(search-path %load-path
1066 "gnu/packages/ld-wrapper.scm"))))
1068 `(#:guile ,%bootstrap-guile
1069 #:modules ((guix build utils))
1071 (use-modules (guix build utils)
1072 (system base compile))
1074 (let* ((out (assoc-ref %outputs "out"))
1075 (bin (string-append out "/bin"))
1076 (ld (string-append bin "/ld"))
1077 (go (string-append bin "/ld.go")))
1079 (setvbuf (current-output-port) _IOLBF)
1080 (format #t "building ~s/bin/ld wrapper in ~s~%"
1081 (assoc-ref %build-inputs "binutils")
1085 (copy-file (assoc-ref %build-inputs "wrapper") ld)
1088 (string-append (assoc-ref %build-inputs "guile")
1091 (string-append (assoc-ref %build-inputs "bash")
1094 (string-append (assoc-ref %build-inputs "binutils")
1097 (compile-file ld #:output-file go)))))
1098 (synopsis "The linker wrapper")
1100 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1101 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1106 (define %boot3-inputs
1107 ;; 4th stage inputs.
1108 `(("gcc" ,gcc-final)
1109 ("ld-wrapper" ,ld-wrapper-boot3)
1110 ,@(alist-delete "gcc" %boot2-inputs)))
1113 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1114 ;; to the bootstrap GCC.
1115 (package-with-bootstrap-guile
1116 (package-with-explicit-inputs (static-libgcc-package bash)
1118 (current-source-location)
1119 #:guile %bootstrap-guile)))
1121 (define %boot4-inputs
1122 ;; Now use the final Bash.
1123 `(("bash" ,bash-final)
1124 ,@(alist-delete "bash" %boot3-inputs)))
1126 (define-public guile-final
1127 (package-with-bootstrap-guile
1128 (package-with-explicit-inputs guile-2.0/fixed
1130 (current-source-location)
1131 #:guile %bootstrap-guile)))
1133 (define gnu-make-final
1134 ;; The final GNU Make, which uses the final Guile.
1135 (package-with-bootstrap-guile
1136 (package-with-explicit-inputs gnu-make
1137 `(("guile" ,guile-final)
1139 (current-source-location))))
1141 (define-public ld-wrapper
1142 ;; The final `ld' wrapper, which uses the final Guile.
1143 (package (inherit ld-wrapper-boot3)
1145 (inputs `(("guile" ,guile-final)
1146 ("bash" ,bash-final)
1147 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1148 '("guile" "bash"))))))
1150 (define coreutils-final
1151 ;; The final Coreutils. Treat them specially because some packages, such as
1152 ;; Findutils, keep a reference to the Coreutils they were built with.
1153 (package-with-bootstrap-guile
1154 (package-with-explicit-inputs coreutils
1156 (current-source-location)
1158 ;; Use the final Guile, linked against the
1159 ;; final libc with working iconv, so that
1160 ;; 'substitute*' works well when touching
1161 ;; test files in Gettext.
1162 #:guile guile-final)))
1165 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
1166 ;; built before gzip.
1167 (package-with-bootstrap-guile
1168 (package-with-explicit-inputs grep
1170 (current-source-location)
1171 #:guile guile-final)))
1173 (define %boot5-inputs
1174 ;; Now use the final Coreutils.
1175 `(("coreutils" ,coreutils-final)
1176 ("grep" ,grep-final)
1179 (define-public %final-inputs
1180 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
1181 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
1182 ;; used for origins that have patches, thereby avoiding circular
1184 (let ((finalize (compose package-with-bootstrap-guile
1185 (cut package-with-explicit-inputs <> %boot5-inputs
1186 (current-source-location)))))
1187 `(,@(map (match-lambda
1189 (list name (finalize package))))
1194 ("diffutils" ,diffutils)
1197 ("findutils" ,findutils)
1199 ("grep" ,grep-final)
1200 ("coreutils" ,coreutils-final)
1201 ("make" ,gnu-make-final)
1202 ("bash" ,bash-final)
1203 ("ld-wrapper" ,ld-wrapper)
1204 ("binutils" ,binutils-final)
1206 ("libc" ,glibc-final))))
1208 (define-public canonical-package
1209 (let ((name->package (fold (lambda (input result)
1212 (vhash-cons (package-full-name package)
1215 `(("guile" ,guile-final)
1218 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
1219 the implicit inputs of 'gnu-build-system', return that one, otherwise return
1222 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.0,
1223 COREUTILS-FINAL vs. COREUTILS, etc."
1224 ;; XXX: This doesn't handle dependencies of the final inputs, such as
1225 ;; libunistring, GMP, etc.
1226 (match (vhash-assoc (package-full-name package) name->package)
1228 ;; In general we want CANON, except if we're cross-compiling: CANON
1229 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
1230 ;; process, with dependencies on things that cannot be
1232 (if (%current-target-system)
1242 (define (gcc-toolchain gcc)
1243 "Return a complete toolchain for GCC."
1245 (name "gcc-toolchain")
1246 (version (package-version gcc))
1248 (build-system trivial-build-system)
1250 '(#:modules ((guix build union))
1252 (use-modules (ice-9 match)
1255 (match %build-inputs
1256 (((names . directories) ...)
1257 (union-build (assoc-ref %outputs "out")
1260 (union-build (assoc-ref %outputs "debug")
1261 (list (assoc-ref %build-inputs
1263 (license (package-license gcc))
1264 (synopsis "Complete GCC tool chain for C/C++ development")
1266 "This package provides a complete GCC tool chain for C/C++ development to
1267 be installed in user profiles. This includes GCC, as well as libc (headers
1268 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
1269 (home-page "http://gcc.gnu.org/")
1270 (outputs '("out" "debug"))
1272 ;; The main raison d'être of this "meta-package" is (1) to conveniently
1273 ;; install everything that we need, and (2) to make sure ld-wrapper comes
1274 ;; before Binutils' ld in the user's profile.
1275 (inputs `(("gcc" ,gcc)
1276 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
1277 ("binutils" ,binutils-final)
1278 ("libc" ,glibc-final)
1279 ("libc-debug" ,glibc-final "debug")))))
1281 (define-public gcc-toolchain-4.8
1282 (gcc-toolchain gcc-final))
1284 (define-public gcc-toolchain-4.9
1285 (gcc-toolchain gcc-4.9))
1287 ;;; base.scm ends here