1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
4 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu packages base)
22 #:use-module ((guix licenses)
23 #:select (gpl3+ lgpl2.0+ public-domain))
24 #:use-module (gnu packages)
25 #:use-module (gnu packages acl)
26 #:use-module (gnu packages bash)
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages compression)
29 #:use-module (gnu packages gcc)
30 #:use-module (gnu packages gawk)
31 #:use-module (gnu packages guile)
32 #:use-module (gnu packages multiprecision)
33 #:use-module (gnu packages perl)
34 #:use-module (gnu packages linux)
35 #:use-module (gnu packages texinfo)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (guix packages)
38 #:use-module (guix download)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system trivial)
41 #:use-module (guix utils)
42 #:use-module (srfi srfi-1)
43 #:use-module (srfi srfi-26)
44 #:use-module (ice-9 match))
48 ;;; Base packages of the Guix-based GNU user-land software distribution.
58 (uri (string-append "mirror://gnu/hello/hello-" version
61 (base32 "19qy37gkasc4csb1d3bdiz9snn8mir2p3aj0jgzmfv0r2hi7mfzc"))))
62 (build-system gnu-build-system)
63 (synopsis "Hello, GNU world: An example GNU package")
65 "GNU Hello prints the message \"Hello, world!\" and then exits. It
66 serves as an example of standard GNU coding practices. As such, it supports
67 command-line arguments, multiple languages, and so on.")
68 (home-page "http://www.gnu.org/software/hello/")
77 (uri (string-append "mirror://gnu/grep/grep-"
81 "08773flbnx28ksy0y4mzd4iifysh7yysmzn8rkz9f57sfx86whz6"))))
82 (build-system gnu-build-system)
83 (synopsis "Print lines matching a pattern")
85 "grep is a tool for finding text inside files. Text is found by
86 matching a pattern provided by the user in one or many files. The pattern
87 may be provided as a basic or extended regular expression, or as fixed
88 strings. By default, the matching text is simply printed to the screen,
89 however the output can be greatly customized to include, for example, line
90 numbers. GNU grep offers many extensions over the standard utility,
91 including, for example, recursive directory searching.")
93 (home-page "http://www.gnu.org/software/grep/")))
101 (uri (string-append "mirror://gnu/sed/sed-" version
105 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
106 (build-system gnu-build-system)
107 (synopsis "Stream editor")
109 (if (%current-target-system)
111 `(#:phases (alist-cons-before
112 'patch-source-shebangs 'patch-test-suite
113 (lambda* (#:key inputs #:allow-other-keys)
114 (let ((bash (assoc-ref inputs "bash")))
115 (patch-makefile-SHELL "testsuite/Makefile.tests")
116 (substitute* '("testsuite/bsd.sh"
117 "testsuite/bug-regex9.c")
119 (string-append bash "/bin/bash")))))
122 "Sed is a non-interactive, text stream editor. It receives a text
123 input from a file or from standard input and it then applies a series of text
124 editing commands to the stream and prints its output to standard output. It
125 is often used for substituting text patterns in a stream. The GNU
126 implementation offers several extensions over the standard utility.")
128 (home-page "http://www.gnu.org/software/sed/")))
136 (uri (string-append "mirror://gnu/tar/tar-"
140 "1iip0fk0wqhxb0jcwphz43r4fxkx1y7mznnhmlvr618jhp7b63wv"))))
141 (build-system gnu-build-system)
142 (synopsis "Managing tar archives")
144 "Tar provides the ability to create tar archives, as well as the
145 ability to extract, update or list files in an existing archive. It is
146 useful for combining many files into one larger file, while maintaining
147 directory structure and file information such as permissions and
148 creation/modification dates. GNU tar offers many extensions over the
151 (home-page "http://www.gnu.org/software/tar/")))
159 (uri (string-append "mirror://gnu/patch/patch-"
163 "1sqckf560pzwgniy00vcpdv2c9c11s4cmhlm14yqgg8avd3bl94i"))))
164 (build-system gnu-build-system)
165 (native-inputs '()) ; FIXME: needs `ed' for the tests
168 ;; TODO: When cross-compiling, add this:
169 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
171 (synopsis "Apply differences to originals, with optional backups")
173 "Patch is a program that applies changes to files based on differences
174 laid out as by the program \"diff\". The changes may be applied to one or more
175 files depending on the contents of the diff file. It accepts several
176 different diff formats. It may also be used to revert previously applied
179 (home-page "http://savannah.gnu.org/projects/patch/")))
181 (define-public diffutils
187 (uri (string-append "mirror://gnu/diffutils/diffutils-"
191 "1761vymxbp4wb5rzjvabhdkskk95pghnn67464byvzb5mfl8jpm2"))))
192 (build-system gnu-build-system)
193 (synopsis "Comparing and merging files")
195 "GNU Diffutils is a package containing tools for finding the
196 differences between files. The \"diff\" command is used to show how two files
197 differ, while \"cmp\" shows the offsets and line numbers where they differ.
198 \"diff3\" allows you to compare three files. Finally, \"sdiff\" offers an
199 interactive means to merge two files.")
201 (home-page "http://www.gnu.org/software/diffutils/")))
203 (define-public findutils
209 (uri (string-append "mirror://gnu/findutils/findutils-"
213 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))
214 (patches (list (search-patch "findutils-absolute-paths.patch")))))
215 (build-system gnu-build-system)
217 ;; Work around cross-compilation failure.
218 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
219 (if (%current-target-system)
220 '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
222 (synopsis "Operating on files matching given criteria")
224 "Findutils supplies the basic file directory searching utilities of the
225 GNU system. It consists of two primary searching utilities: \"find\"
226 recursively searches for files in a directory according to given criteria and
227 \"locate\" lists files in a database that match a query. Two auxiliary tools
228 are included: \"updatedb\" updates the file name database and \"xargs\" may be
229 used to apply commands with arbitrarily long arguments.")
231 (home-page "http://www.gnu.org/software/findutils/")))
233 (define-public coreutils
239 (uri (string-append "mirror://gnu/coreutils/coreutils-"
243 "04hjzzv434fb8ak3hh3dyhdvg3hqjjwvjmjxqzk1gh2jh6cr8gjv"))
244 (patches (list (search-patch "coreutils-dummy-man.patch")
245 ;; TODO: remove this patch for >= 8.23
246 (search-patch "coreutils-skip-nohup.patch")))))
247 (build-system gnu-build-system)
248 (inputs `(("acl" ,acl) ; TODO: add SELinux
251 ;; Perl is needed to run tests in native builds, and to run the bundled
252 ;; copy of help2man. However, don't pass it when cross-compiling since
253 ;; that would lead it to try to run programs to get their '--help' output
255 (if (%current-target-system)
258 (outputs '("out" "debug"))
260 `(#:parallel-build? #f ; help2man may be called too early
261 #:phases (alist-cons-before
262 'build 'patch-shell-references
263 (lambda* (#:key inputs #:allow-other-keys)
264 (let ((bash (assoc-ref inputs "bash")))
265 (substitute* (cons "src/split.c"
266 (find-files "gnulib-tests"
269 (format #f "~a/bin/sh" bash)))
270 (substitute* (find-files "tests" "\\.sh$")
272 (format #f "#!~a/bin/bash" bash)))))
274 (synopsis "Core GNU utilities (file, text, shell)")
276 "GNU Coreutils includes all of the basic command-line tools that are
277 expected in a POSIX system. These provide the basic file, shell and text
278 manipulation functions of the GNU system. Most of these tools offer extended
279 functionality beyond that which is outlined in the POSIX standard.")
281 (home-page "http://www.gnu.org/software/coreutils/")))
283 (define-public gnu-make
289 (uri (string-append "mirror://gnu/make/make-" version
293 "1nyvn8mknw0mf7727lprva3lisl1y0n03lvar342rrpdmz3qc1p6"))
294 (patches (list (search-patch "make-impure-dirs.patch")))))
295 (build-system gnu-build-system)
296 (native-inputs `(("pkg-config", pkg-config))) ; to detect Guile
297 (inputs `(("guile" ,guile-2.0)))
298 (outputs '("out" "debug"))
300 '(#:phases (alist-cons-before
301 'build 'set-default-shell
302 (lambda* (#:key inputs #:allow-other-keys)
303 ;; Change the default shell from /bin/sh.
304 (let ((bash (assoc-ref inputs "bash")))
306 (("default_shell\\[\\] =.*$")
307 (format #f "default_shell[] = \"~a/bin/bash\";\n"
310 (synopsis "Remake files automatically")
312 "Make is a program that is used to control the production of
313 executables or other files from their source files. The process is
314 controlled from a Makefile, in which the developer specifies how each file is
315 generated from its source. It has powerful dependency resolution and the
316 ability to determine when files have to be regenerated after their sources
317 change. GNU make offers many powerful extensions over the standard utility.")
319 (home-page "http://www.gnu.org/software/make/")))
321 (define-public binutils
327 (uri (string-append "mirror://gnu/binutils/binutils-"
331 "0ds1y7qa0xqihw4ihnsgg6bxanmb228r228ddvwzgrv4jszcbs75"))
332 (patches (list (search-patch "binutils-ld-new-dtags.patch")
333 (search-patch "binutils-loongson-workaround.patch")))))
334 (build-system gnu-build-system)
336 ;; TODO: Add dependency on zlib + those for Gold.
338 `(#:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
339 ;; on GCC when bootstrapping.
340 "LDFLAGS=-static-libgcc"
342 ;; Don't search under /usr/lib & co.
343 "--with-lib-path=/no-ld-lib-path"
345 ;; Glibc 2.17 has a "comparison of unsigned
346 ;; expression >= 0 is always true" in wchar.h.
349 ;; Install BFD. It ends up in a hidden directory,
351 "--enable-install-libbfd"
353 ;; Make sure 'ar' and 'ranlib' produce archives in a
354 ;; deterministic fashion.
355 "--enable-deterministic-archives")))
357 (synopsis "Binary utilities: bfd gas gprof ld")
359 "GNU Binutils is a collection of tools for working with binary files.
360 Perhaps the most notable are \"ld\", a linker, and \"as\", an assembler. Other
361 tools include programs to display binary profiling information, list the
362 strings in a binary file, and utilities for working with archives. The \"bfd\"
363 library for working with executable and object formats is also included.")
365 (home-page "http://www.gnu.org/software/binutils/")))
373 (uri (string-append "mirror://gnu/glibc/glibc-"
377 "18m2dssd6ja5arxmdxinc90xvpqcsnqjfwmjl2as07j0i3srff9d"))
379 ;; Disable 'ldconfig' and /etc/ld.so.cache. The latter is
380 ;; required on LFS distros to avoid loading the distro's libc.so
382 '(substitute* "sysdeps/unix/sysv/linux/configure"
383 (("use_ldconfig=yes")
385 (modules '((guix build utils)))
386 (patches (list (search-patch "glibc-ldd-x86_64.patch")))))
387 (build-system gnu-build-system)
389 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
390 ;; users should automatically pull Linux headers as well.
391 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
393 ;; Store the locales separately (~100 MiB). Note that "out" retains a
394 ;; reference to them anyway, so there's no space savings here.
395 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
397 (outputs '("out" "locales" "debug"))
400 `(#:out-of-source? #t
402 (list "--enable-add-ons"
404 (string-append "--localedir=" (assoc-ref %outputs "locales")
407 ;; `--localedir' is not honored, so work around it.
408 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
409 (string-append "libc_cv_localedir="
410 (assoc-ref %outputs "locales")
413 (string-append "--with-headers="
414 (assoc-ref %build-inputs "linux-headers")
417 ;; The default is to assume a 2.4 Linux interface, but we'll
418 ;; always use something newer. See "kernel-features.h" in the
419 ;; GNU libc for details.
420 "--enable-kernel=2.6.30"
422 ;; Use our Bash instead of /bin/sh.
423 (string-append "BASH_SHELL="
424 (assoc-ref %build-inputs "bash")
427 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
431 #:phases (alist-cons-before
432 'configure 'pre-configure
433 (lambda* (#:key inputs outputs #:allow-other-keys)
434 (let* ((out (assoc-ref outputs "out"))
435 (bin (string-append out "/bin")))
436 ;; Use `pwd', not `/bin/pwd'.
437 (substitute* "configure"
438 (("/bin/pwd") "pwd"))
440 ;; Install the rpc data base file under `$out/etc/rpc'.
441 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
442 (substitute* "sunrpc/Makefile"
443 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
444 (string-append out "/etc/rpc" suffix "\n"))
445 (("^install-others =.*$")
446 (string-append "install-others = " out "/etc/rpc\n")))
448 (substitute* "Makeconfig"
450 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
451 ;; linking against libgcc_s is not needed with GCC
455 ;; Copy a statically-linked Bash in the output, with
456 ;; no references to other store paths.
458 (copy-file (string-append (assoc-ref inputs "static-bash")
460 (string-append bin "/bash"))
461 (remove-store-references (string-append bin "/bash"))
462 (chmod (string-append bin "/bash") #o555)
464 ;; Keep a symlink, for `patch-shebang' resolution.
465 (with-directory-excursion bin
466 (symlink "bash" "sh"))
468 ;; Have `system' use that Bash.
469 (substitute* "sysdeps/posix/system.c"
470 (("#define[[:blank:]]+SHELL_PATH.*$")
471 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
475 (substitute* "libio/iopopen.c"
477 (string-append out "/bin/bash")))
479 ;; Make sure we don't retain a reference to the
481 (substitute* "malloc/mtrace.pl"
483 ;; The shebang can be omitted, because there's the
484 ;; "bilingual" eval/exec magic at the top of the file.
489 'install 'install-locales
491 (zero? (system* "make" "localedata/install-locales")))
494 (inputs `(("static-bash" ,(static-package bash-light))))
496 ;; To build the manual, we need Texinfo and Perl.
497 (native-inputs `(("texinfo" ,texinfo)
500 (synopsis "The GNU C Library")
502 "Any Unix-like operating system needs a C library: the library which
503 defines the \"system calls\" and other basic facilities such as open, malloc,
506 The GNU C library is used as the C library in the GNU system and most systems
507 with the Linux kernel.")
509 (home-page "http://www.gnu.org/software/libc/")))
511 (define-public tzdata
518 "http://www.iana.org/time-zones/repository/releases/tzdata"
522 "1cg843ajz4g16axpz56zvalwsbp1s764na2bk4fb44ayx162bzvw"))))
523 (build-system gnu-build-system)
526 #:make-flags (let ((out (assoc-ref %outputs "out"))
527 (tmp (getenv "TMPDIR")))
528 (list (string-append "TOPDIR=" out)
529 (string-append "TZDIR=" out "/share/zoneinfo")
531 ;; Discard zic, dump, and tzselect, already
532 ;; provided by glibc.
533 (string-append "ETCDIR=" tmp "/etc")
535 ;; Likewise for the C library routines.
536 (string-append "LIBDIR=" tmp "/lib")
537 (string-append "MANDIR=" tmp "/man")
541 #:modules ((guix build utils)
542 (guix build gnu-build-system)
547 (lambda* (#:key source inputs #:allow-other-keys)
548 (and (zero? (system* "tar" "xvf" source))
549 (zero? (system* "tar" "xvf" (assoc-ref inputs "tzcode")))))
551 'install 'post-install
552 (lambda* (#:key outputs #:allow-other-keys)
553 ;; Move data in the right place.
554 (let ((out (assoc-ref outputs "out")))
555 (copy-recursively (string-append out "/share/zoneinfo-posix")
556 (string-append out "/share/zoneinfo/posix"))
557 (copy-recursively (string-append out "/share/zoneinfo-leaps")
558 (string-append out "/share/zoneinfo/right"))
559 (delete-file-recursively (string-append out "/share/zoneinfo-posix"))
560 (delete-file-recursively (string-append out "/share/zoneinfo-leaps"))))
561 (alist-delete 'configure %standard-phases)))))
562 (inputs `(("tzcode" ,(origin
565 "http://www.iana.org/time-zones/repository/releases/tzcode"
569 "1xfkqi1q8cnxqbv8azdj5pqlzhkjz6xag09f1z0s8rxi86jkpf85"))))))
570 (home-page "http://www.iana.org/time-zones")
571 (synopsis "Database of current and historical time zones")
572 (description "The Time Zone Database (often called tz or zoneinfo)
573 contains code and data that represent the history of local time for many
574 representative locations around the globe. It is updated periodically to
575 reflect changes made by political bodies to time zone boundaries, UTC offsets,
576 and daylight-saving rules.")
577 (license public-domain)))
581 ;;; Bootstrap packages.
584 (define gnu-make-boot0
585 (package-with-bootstrap-guile
586 (package (inherit gnu-make)
588 (location (source-properties->location (current-source-location)))
590 `(#:guile ,%bootstrap-guile
591 #:implicit-inputs? #f
592 #:tests? #f ; cannot run "make check"
593 ,@(substitute-keyword-arguments (package-arguments gnu-make)
597 ;; Don't attempt to build 'guile.c' since we don't
599 (substitute* "build.sh"
600 (("guile\\.\\$\\{OBJEXT\\}") ""))
601 (zero? (system* "./build.sh")))
603 'install (lambda* (#:key outputs #:allow-other-keys)
604 (let* ((out (assoc-ref outputs "out"))
605 (bin (string-append out "/bin")))
608 (string-append bin "/make"))))
610 (native-inputs '()) ; no need for 'pkg-config'
611 (inputs %bootstrap-inputs))))
613 (define diffutils-boot0
614 (package-with-bootstrap-guile
615 (let ((p (package-with-explicit-inputs diffutils
616 `(("make" ,gnu-make-boot0)
618 #:guile %bootstrap-guile)))
620 (location (source-properties->location (current-source-location)))
621 (arguments `(#:tests? #f ; the test suite needs diffutils
622 ,@(package-arguments p)))))))
624 (define findutils-boot0
625 (package-with-bootstrap-guile
626 (package-with-explicit-inputs findutils
627 `(("make" ,gnu-make-boot0)
628 ("diffutils" ,diffutils-boot0) ; for tests
630 (current-source-location)
631 #:guile %bootstrap-guile)))
634 (define %boot0-inputs
635 `(("make" ,gnu-make-boot0)
636 ("diffutils" ,diffutils-boot0)
637 ("findutils" ,findutils-boot0)
638 ,@%bootstrap-inputs))
640 (define* (nix-system->gnu-triplet
641 #:optional (system (%current-system)) (vendor "unknown"))
642 "Return an a guess of the GNU triplet corresponding to Nix system
644 (let* ((dash (string-index system #\-))
645 (arch (substring system 0 dash))
646 (os (substring system (+ 1 dash))))
649 (if (string=? os "linux")
653 (define* (boot-triplet #:optional (system (%current-system)))
654 ;; Return the triplet used to create the cross toolchain needed in the
655 ;; first bootstrapping stage.
656 (nix-system->gnu-triplet system "guix"))
658 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
659 ;; toolchain actually targets the same OS and arch, but it has the advantage
660 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
661 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
663 (define binutils-boot0
664 (package-with-bootstrap-guile
665 (package (inherit binutils)
666 (name "binutils-cross-boot0")
668 `(#:guile ,%bootstrap-guile
669 #:implicit-inputs? #f
670 ,@(substitute-keyword-arguments (package-arguments binutils)
671 ((#:configure-flags cf)
672 `(cons ,(string-append "--target=" (boot-triplet))
674 (inputs %boot0-inputs))))
677 (package-with-bootstrap-guile
678 (package (inherit gcc-4.8)
679 (name "gcc-cross-boot0")
681 `(#:guile ,%bootstrap-guile
682 #:implicit-inputs? #f
683 #:modules ((guix build gnu-build-system)
688 ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
689 ((#:configure-flags flags)
690 `(append (list ,(string-append "--target=" (boot-triplet))
695 ;; Disable features not needed at this stage.
697 "--enable-languages=c,c++"
699 ;; libstdc++ cannot be built at this stage
700 ;; ("Link tests are not allowed after
701 ;; GCC_NO_EXECUTABLES.").
702 "--disable-libstdc++-v3"
705 "--disable-libmudflap"
706 "--disable-libatomic"
707 "--disable-libsanitizer"
711 "--disable-libquadmath"
712 "--disable-decimal-float")
713 (remove (cut string-match "--enable-languages.*" <>)
717 'unpack 'unpack-gmp&co
718 (lambda* (#:key inputs #:allow-other-keys)
719 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
720 (mpfr (assoc-ref %build-inputs "mpfr-source"))
721 (mpc (assoc-ref %build-inputs "mpc-source")))
723 ;; To reduce the set of pre-built bootstrap inputs, build
724 ;; GMP & co. from GCC.
725 (for-each (lambda (source)
726 (or (zero? (system* "tar" "xvf" source))
727 (error "failed to unpack tarball"
731 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
733 `(symlink ,(package-full-name lib)
734 ,(package-name lib)))
735 (list gmp mpfr mpc))))
737 'install 'symlink-libgcc_eh
738 (lambda* (#:key outputs #:allow-other-keys)
739 (let ((out (assoc-ref outputs "out")))
740 ;; Glibc wants to link against libgcc_eh, so provide
742 (with-directory-excursion
743 (string-append out "/lib/gcc/"
745 "/" ,(package-version gcc-4.8))
746 (symlink "libgcc.a" "libgcc_eh.a"))))
749 (inputs `(("gmp-source" ,(package-source gmp))
750 ("mpfr-source" ,(package-source mpfr))
751 ("mpc-source" ,(package-source mpc))
752 ("binutils-cross" ,binutils-boot0)
754 ;; Call it differently so that the builder can check whether
755 ;; the "libc" input is #f.
756 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
757 ,@(alist-delete "libc" %boot0-inputs)))
759 ;; No need for Texinfo at this stage.
760 (native-inputs (alist-delete "texinfo"
761 (package-native-inputs gcc-4.8))))))
764 (package-with-bootstrap-guile
765 (package-with-explicit-inputs perl
767 (current-source-location)
768 #:guile %bootstrap-guile)))
770 (define (linux-libre-headers-boot0)
771 "Return Linux-Libre header files for the bootstrap environment."
772 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
773 ;; between (gnu packages linux) and this module.
774 (package-with-bootstrap-guile
775 (package (inherit linux-libre-headers)
776 (arguments `(#:guile ,%bootstrap-guile
777 #:implicit-inputs? #f
778 ,@(package-arguments linux-libre-headers)))
780 `(("perl" ,perl-boot0)
783 (define texinfo-boot0
784 ;; Texinfo used to build libc's manual.
785 ;; We build without ncurses because it fails to build at this stage, and
786 ;; because we don't need the stand-alone Info reader.
787 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
788 (let ((texinfo (package (inherit texinfo)
789 (inputs (alist-delete "ncurses" (package-inputs texinfo))))))
790 (package-with-bootstrap-guile
791 (package-with-explicit-inputs texinfo %boot0-inputs
792 (current-source-location)
793 #:guile %bootstrap-guile))))
795 (define %boot1-inputs
798 ("binutils-cross" ,binutils-boot0)
800 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
804 (define glibc-final-with-bootstrap-bash
805 ;; The final libc, "cross-built". If everything went well, the resulting
806 ;; store path has no dependencies. Actually, the really-final libc is
807 ;; built just below; the only difference is that this one uses the
809 (package-with-bootstrap-guile
810 (package (inherit glibc)
811 (name "glibc-intermediate")
813 `(#:guile ,%bootstrap-guile
814 #:implicit-inputs? #f
816 ,@(substitute-keyword-arguments (package-arguments glibc)
817 ((#:configure-flags flags)
818 `(append (list ,(string-append "--host=" (boot-triplet))
819 ,(string-append "--build="
820 (nix-system->gnu-triplet))
822 ;; Build Sun/ONC RPC support. In particular,
824 "--enable-obsolete-rpc")
826 (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
828 `(("texinfo" ,texinfo-boot0)
829 ("perl" ,perl-boot0)))
831 `( ;; A native GCC is needed to build `cross-rpcgen'.
832 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
834 ;; Here, we use the bootstrap Bash, which is not satisfactory
835 ;; because we don't want to depend on bootstrap tools.
836 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
839 ,@(alist-delete "static-bash"
840 (package-inputs glibc))))))) ; patches
842 (define (cross-gcc-wrapper gcc binutils glibc bash)
843 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
844 that makes it available under the native tool names."
845 (package (inherit gcc-4.8)
846 (name (string-append (package-name gcc) "-wrapped"))
848 (build-system trivial-build-system)
850 `(#:guile ,%bootstrap-guile
851 #:modules ((guix build utils))
853 (use-modules (guix build utils))
855 (let* ((binutils (assoc-ref %build-inputs "binutils"))
856 (gcc (assoc-ref %build-inputs "gcc"))
857 (libc (assoc-ref %build-inputs "libc"))
858 (bash (assoc-ref %build-inputs "bash"))
859 (out (assoc-ref %outputs "out"))
860 (bindir (string-append out "/bin"))
861 (triplet ,(boot-triplet)))
862 (define (wrap-program program)
863 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
864 ;; needs to be told where to find the crt files and
865 ;; the dynamic linker.
866 (call-with-output-file program
868 (format p "#!~a/bin/bash
869 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
873 ,(glibc-dynamic-linker))))
875 (chmod program #o555))
878 (with-directory-excursion bindir
879 (for-each (lambda (tool)
880 (symlink (string-append binutils "/bin/"
884 (for-each wrap-program '("gcc" "g++")))))))
886 `(("binutils" ,binutils)
892 (define static-bash-for-glibc
893 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
895 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
896 glibc-final-with-bootstrap-bash
897 (car (assoc-ref %boot1-inputs "bash"))))
898 (bash (package (inherit bash-light)
900 `(#:guile ,%bootstrap-guile
901 ,@(package-arguments bash-light))))))
902 (package-with-bootstrap-guile
903 (package-with-explicit-inputs (static-package bash)
905 ("libc" ,glibc-final-with-bootstrap-bash)
906 ,@(fold alist-delete %boot1-inputs
908 (current-source-location)))))
910 (define-public glibc-final
911 ;; The final glibc, which embeds the statically-linked Bash built above.
912 (package (inherit glibc-final-with-bootstrap-bash)
914 (inputs `(("static-bash" ,static-bash-for-glibc)
917 (package-inputs glibc-final-with-bootstrap-bash))))))
919 (define gcc-boot0-wrapped
920 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
922 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
923 (car (assoc-ref %boot1-inputs "bash"))))
925 (define %boot2-inputs
927 `(("libc" ,glibc-final)
928 ("gcc" ,gcc-boot0-wrapped)
929 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
931 (define binutils-final
932 (package-with-bootstrap-guile
933 (package (inherit binutils)
935 `(#:guile ,%bootstrap-guile
936 #:implicit-inputs? #f
937 ,@(package-arguments binutils)))
938 (inputs %boot2-inputs))))
941 ;; Intermediate libstdc++ that will allow us to build the final GCC
942 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
943 (package-with-bootstrap-guile
944 (package (inherit gcc-4.8)
947 `(#:guile ,%bootstrap-guile
948 #:implicit-inputs? #f
951 #:phases (alist-cons-before
954 (chdir "libstdc++-v3"))
956 #:configure-flags `("--disable-shared"
957 "--disable-libstdcxx-threads"
958 "--disable-libstdcxx-pch"
959 ,(string-append "--with-gxx-include-dir="
960 (assoc-ref %outputs "out")
963 ;; ,(package-version gcc-4.8)
965 (inputs %boot2-inputs)
967 (propagated-inputs '())
968 (synopsis "GNU C++ standard library (intermediate)"))))
970 (define-public gcc-final
972 (package (inherit gcc-boot0)
975 `(#:guile ,%bootstrap-guile
976 #:implicit-inputs? #f
978 ;; Build again GMP & co. within GCC's build process, because it's hard
979 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
980 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
981 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
982 ((#:configure-flags boot-flags)
983 (let loop ((args (package-arguments gcc-4.8)))
985 ((#:configure-flags normal-flags _ ...)
989 ((#:make-flags flags)
990 ;; Since $LIBRARY_PATH and $CPATH are not honored, add the
992 `(cons (string-append "CPPFLAGS=-I"
993 (assoc-ref %build-inputs "libstdc++")
996 (if (string-prefix? "LDFLAGS=" flag)
997 (string-append flag " -L"
998 (assoc-ref %build-inputs "libstdc++")
1003 `(alist-delete 'symlink-libgcc_eh ,phases)))))
1005 (inputs `(("gmp-source" ,(package-source gmp))
1006 ("mpfr-source" ,(package-source mpfr))
1007 ("mpc-source" ,(package-source mpc))
1008 ("binutils" ,binutils-final)
1009 ("libstdc++" ,libstdc++)
1012 (define ld-wrapper-boot3
1013 ;; A linker wrapper that uses the bootstrap Guile.
1015 (name "ld-wrapper-boot3")
1018 (build-system trivial-build-system)
1019 (inputs `(("binutils" ,binutils-final)
1020 ("guile" ,%bootstrap-guile)
1021 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
1022 ("wrapper" ,(search-path %load-path
1023 "gnu/packages/ld-wrapper.scm"))))
1025 `(#:guile ,%bootstrap-guile
1026 #:modules ((guix build utils))
1028 (use-modules (guix build utils)
1029 (system base compile))
1031 (let* ((out (assoc-ref %outputs "out"))
1032 (bin (string-append out "/bin"))
1033 (ld (string-append bin "/ld"))
1034 (go (string-append bin "/ld.go")))
1036 (setvbuf (current-output-port) _IOLBF)
1037 (format #t "building ~s/bin/ld wrapper in ~s~%"
1038 (assoc-ref %build-inputs "binutils")
1042 (copy-file (assoc-ref %build-inputs "wrapper") ld)
1045 (string-append (assoc-ref %build-inputs "guile")
1048 (string-append (assoc-ref %build-inputs "bash")
1051 (string-append (assoc-ref %build-inputs "binutils")
1054 (compile-file ld #:output-file go)))))
1055 (synopsis "The linker wrapper")
1057 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1058 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1063 (define %boot3-inputs
1064 ;; 4th stage inputs.
1065 `(("gcc" ,gcc-final)
1066 ("ld-wrapper" ,ld-wrapper-boot3)
1067 ,@(alist-delete "gcc" %boot2-inputs)))
1070 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1071 ;; to the bootstrap GCC.
1072 (package-with-bootstrap-guile
1073 (package-with-explicit-inputs (static-libgcc-package bash)
1075 (current-source-location)
1076 #:guile %bootstrap-guile)))
1078 (define %boot4-inputs
1079 ;; Now use the final Bash.
1080 `(("bash" ,bash-final)
1081 ,@(alist-delete "bash" %boot3-inputs)))
1083 (define-public guile-final
1084 (package-with-bootstrap-guile
1085 (package-with-explicit-inputs guile-2.0/fixed
1087 (current-source-location)
1088 #:guile %bootstrap-guile)))
1090 (define gnu-make-final
1091 ;; The final GNU Make, which uses the final Guile.
1092 (package-with-bootstrap-guile
1093 (package-with-explicit-inputs gnu-make
1094 `(("guile" ,guile-final)
1096 (current-source-location))))
1098 (define-public ld-wrapper
1099 ;; The final `ld' wrapper, which uses the final Guile.
1100 (package (inherit ld-wrapper-boot3)
1102 (inputs `(("guile" ,guile-final)
1103 ("bash" ,bash-final)
1104 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1105 '("guile" "bash"))))))
1107 (define-public %final-inputs
1108 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
1109 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
1110 ;; used for origins that have patches, thereby avoiding circular
1112 (let ((finalize (compose package-with-bootstrap-guile
1113 (cut package-with-explicit-inputs <> %boot4-inputs
1114 (current-source-location)))))
1115 `(,@(map (match-lambda
1117 (list name (finalize package))))
1122 ("diffutils" ,diffutils)
1124 ("coreutils" ,coreutils)
1127 ("findutils" ,findutils)
1129 ("make" ,gnu-make-final)
1130 ("bash" ,bash-final)
1131 ("ld-wrapper" ,ld-wrapper)
1132 ("binutils" ,binutils-final)
1134 ("libc" ,glibc-final))))
1136 ;;; base.scm ends here