1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu packages base)
21 #:use-module ((guix licenses)
22 #:select (gpl3+ lgpl2.0+ public-domain))
23 #:use-module (gnu packages)
24 #:use-module (gnu packages acl)
25 #:use-module (gnu packages bash)
26 #:use-module (gnu packages bootstrap)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages gcc)
29 #:use-module (gnu packages gawk)
30 #:use-module (gnu packages guile)
31 #:use-module (gnu packages multiprecision)
32 #:use-module (gnu packages perl)
33 #:use-module (gnu packages linux)
34 #:use-module (guix packages)
35 #:use-module (guix download)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system trivial)
38 #:use-module (guix utils)
39 #:use-module (srfi srfi-1)
40 #:use-module (srfi srfi-26)
41 #:use-module (ice-9 match))
45 ;;; Base packages of the Guix-based GNU user-land software distribution.
55 (uri (string-append "mirror://gnu/hello/hello-" version
58 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
59 (build-system gnu-build-system)
60 (arguments '(#:configure-flags
61 `("--disable-dependency-tracking"
62 ,(string-append "--with-gawk=" ; for illustration purposes
63 (assoc-ref %build-inputs "gawk")))))
64 (inputs `(("gawk" ,gawk)))
65 (synopsis "Hello, GNU world: An example GNU package")
66 (description "Yeah...")
67 (home-page "http://www.gnu.org/software/hello/")
76 (uri (string-append "mirror://gnu/grep/grep-"
80 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
81 (build-system gnu-build-system)
82 (synopsis "Print lines matching a pattern")
84 "The grep command searches one or more input files for lines containing a
85 match to a specified pattern. By default, grep prints the matching
88 (home-page "http://www.gnu.org/software/grep/")))
96 (uri (string-append "mirror://gnu/sed/sed-" version
100 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
101 (build-system gnu-build-system)
102 (synopsis "Stream editor")
104 (if (%current-target-system)
106 `(#:phases (alist-cons-before
107 'patch-source-shebangs 'patch-test-suite
108 (lambda* (#:key inputs #:allow-other-keys)
109 (let ((bash (assoc-ref inputs "bash")))
110 (patch-makefile-SHELL "testsuite/Makefile.tests")
111 (substitute* '("testsuite/bsd.sh"
112 "testsuite/bug-regex9.c")
114 (string-append bash "/bin/bash")))))
117 "Sed (stream editor) isn't really a true text editor or text processor.
118 Instead, it is used to filter text, i.e., it takes text input and performs
119 some operation (or set of operations) on it and outputs the modified text.
120 Sed is typically used for extracting part of a file using pattern matching or
121 substituting multiple occurrences of a string within a file.")
123 (home-page "http://www.gnu.org/software/sed/")))
131 (uri (string-append "mirror://gnu/tar/tar-"
135 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
136 (build-system gnu-build-system)
137 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
139 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
140 (synopsis "Managing tar archives")
142 "The Tar program provides the ability to create tar archives, as well as
143 various other kinds of manipulation. For example, you can use Tar on
144 previously created archives to extract files, to store additional files, or
145 to update or list files which were already stored.
147 Initially, tar archives were used to store files conveniently on magnetic
148 tape. The name \"Tar\" comes from this use; it stands for tape archiver.
149 Despite the utility's name, Tar can direct its output to available devices,
150 files, or other programs (using pipes), it can even access remote devices or
151 files (as archives).")
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 "GNU Patch takes a patch file containing a difference listing produced by
176 the diff program and applies those differences to one or more original files,
177 producing patched versions.")
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 of several programs related to finding
196 differences between files.
198 Computer users often find occasion to ask how two files differ. Perhaps one
199 file is a newer version of the other file. Or maybe the two files started out
200 as identical copies but were changed by different people.
202 You can use the diff command to show differences between two files, or each
203 corresponding file in two directories. diff outputs differences between files
204 line by line in any of several formats, selectable by command line
205 options. This set of differences is often called a ‘diff’ or ‘patch’. For
206 files that are identical, diff normally produces no output; for
207 binary (non-text) files, diff normally reports only that they are different.
209 You can use the cmp command to show the offsets and line numbers where two
210 files differ. cmp can also show all the characters that differ between the
211 two files, side by side.
213 You can use the diff3 command to show differences among three files. When two
214 people have made independent changes to a common original, diff3 can report
215 the differences between the original and the two changed versions, and can
216 produce a merged file that contains both persons' changes together with
217 warnings about conflicts.
219 You can use the sdiff command to merge two files interactively.")
221 (home-page "http://www.gnu.org/software/diffutils/")))
223 (define-public findutils
229 (uri (string-append "mirror://gnu/findutils/findutils-"
233 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))))
234 (build-system gnu-build-system)
236 `(("patch/absolute-paths"
237 ,(search-patch "findutils-absolute-paths.patch"))))
239 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths"))
241 ;; Work around cross-compilation failure.
242 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
243 ,@(if (%current-target-system)
244 '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
246 (synopsis "Operating on files matching given criteria")
248 "The GNU Find Utilities are the basic directory searching utilities of
249 the GNU operating system. These programs are typically used in conjunction
250 with other programs to provide modular and powerful directory search and file
251 locating capabilities to other commands.
253 The tools supplied with this package are:
255 * find - search for files in a directory hierarchy;
256 * locate - list files in databases that match a pattern;
257 * updatedb - update a file name database;
258 * xargs - build and execute command lines from standard input.
261 (home-page "http://www.gnu.org/software/findutils/")))
263 (define-public coreutils
269 (uri (string-append "mirror://gnu/coreutils/coreutils-"
273 "064f512185iysqqcvhnhaf3bfmzrvcgs7n405qsyp99zmfyl9amd"))))
274 (build-system gnu-build-system)
275 (inputs `(("acl" ,acl) ; TODO: add SELinux
278 ;; Perl is needed to run tests; remove it from cross builds.
279 ,@(if (%current-target-system)
282 (outputs '("out" "debug"))
284 `(#:parallel-build? #f ; help2man may be called too early
285 #:phases (alist-cons-before
286 'build 'patch-shell-references
287 (lambda* (#:key inputs #:allow-other-keys)
288 (let ((bash (assoc-ref inputs "bash")))
289 (substitute* (cons "src/split.c"
290 (find-files "gnulib-tests"
293 (format #f "~a/bin/sh" bash)))
294 (substitute* (find-files "tests" "\\.sh$")
296 (format #f "#!~a/bin/bash" bash)))))
298 (synopsis "Core GNU utilities (file, text, shell)")
300 "The GNU Core Utilities are the basic file, shell and text manipulation
301 utilities of the GNU operating system. These are the core utilities which
302 are expected to exist on every operating system.")
304 (home-page "http://www.gnu.org/software/coreutils/")))
306 (define-public gnu-make
312 (uri (string-append "mirror://gnu/make/make-" version
316 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
317 (build-system gnu-build-system)
319 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
320 (outputs '("out" "debug"))
322 '(#:patches (list (assoc-ref %build-inputs "patch/impure-dirs"))
323 #:phases (alist-cons-before
324 'build 'set-default-shell
325 (lambda* (#:key inputs #:allow-other-keys)
326 ;; Change the default shell from /bin/sh.
327 (let ((bash (assoc-ref inputs "bash")))
329 (("default_shell\\[\\] =.*$")
330 (format #f "default_shell[] = \"~a/bin/bash\";\n"
333 (synopsis "Remake files automatically")
335 "Make is a tool which controls the generation of executables and other
336 non-source files of a program from the program's source files.
338 Make gets its knowledge of how to build your program from a file called the
339 makefile, which lists each of the non-source files and how to compute it from
340 other files. When you write a program, you should write a makefile for it, so
341 that it is possible to use Make to build and install the program.")
343 (home-page "http://www.gnu.org/software/make/")))
345 (define-public binutils
351 (uri (string-append "mirror://gnu/binutils/binutils-"
355 "15qhbkz3r266xaa52slh857qn3abw7rb2x2jnhpfrafpzrb4x4gy"))))
356 (build-system gnu-build-system)
358 ;; Split Binutils in several outputs, mostly to avoid collisions in
359 ;; user profiles with GCC---e.g., libiberty.a.
360 (outputs '("out" ; ar, ld, binutils.info, etc.
361 "lib")) ; libbfd.a, bfd.h, etc.
363 ;; TODO: Add dependency on zlib + those for Gold.
365 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
367 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
368 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
369 ;; on GCC when bootstrapping.
370 "LDFLAGS=-static-libgcc"
372 ;; Don't search under /usr/lib & co.
373 "--with-lib-path=/no-ld-lib-path"
375 ;; Glibc 2.17 has a "comparison of unsigned
376 ;; expression >= 0 is always true" in wchar.h.
377 "--disable-werror")))
379 (synopsis "Binary utilities: bfd gas gprof ld")
381 "The GNU Binutils are a collection of binary tools. The main ones are
382 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
383 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
385 (home-page "http://www.gnu.org/software/binutils/")))
393 (uri (string-append "mirror://gnu/glibc/glibc-"
397 "18spla703zav8dq9fw7rbzkyv9qfisxb26p7amg1x3wjh7iy3d1c"))))
398 (build-system gnu-build-system)
400 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
401 ;; users should automatically pull Linux headers as well.
402 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
404 ;; Store the locales separately (~100 MiB). Note that "out" retains a
405 ;; reference to them anyway, so there's no space savings here.
406 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
408 (outputs '("out" "locales" "debug"))
411 `(#:out-of-source? #t
412 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
414 (list "--enable-add-ons"
416 (string-append "--localedir=" (assoc-ref %outputs "locales")
419 ;; `--localedir' is not honored, so work around it.
420 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
421 (string-append "libc_cv_localedir="
422 (assoc-ref %outputs "locales")
426 (string-append "--with-headers="
427 (assoc-ref %build-inputs "linux-headers")
430 ;; The default is to assume a 2.4 Linux interface, but we'll
431 ;; always use something newer. See "kernel-features.h" in the
432 ;; GNU libc for details.
433 "--enable-kernel=2.6.30"
435 ;; Use our Bash instead of /bin/sh.
436 (string-append "BASH_SHELL="
437 (assoc-ref %build-inputs "bash")
440 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
444 #:phases (alist-cons-before
445 'configure 'pre-configure
446 (lambda* (#:key inputs outputs #:allow-other-keys)
447 (let* ((out (assoc-ref outputs "out"))
448 (bin (string-append out "/bin")))
449 ;; Use `pwd', not `/bin/pwd'.
450 (substitute* "configure"
451 (("/bin/pwd") "pwd"))
453 ;; Install the rpc data base file under `$out/etc/rpc'.
454 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
455 (substitute* "sunrpc/Makefile"
456 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
457 (string-append out "/etc/rpc" suffix "\n"))
458 (("^install-others =.*$")
459 (string-append "install-others = " out "/etc/rpc\n")))
461 (substitute* "Makeconfig"
463 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
464 ;; linking against libgcc_s is not needed with GCC
468 ;; Copy a statically-linked Bash in the output, with
469 ;; no references to other store paths.
471 (copy-file (string-append (assoc-ref inputs "static-bash")
473 (string-append bin "/bash"))
474 (remove-store-references (string-append bin "/bash"))
475 (chmod (string-append bin "/bash") #o555)
477 ;; Keep a symlink, for `patch-shebang' resolution.
478 (with-directory-excursion bin
479 (symlink "bash" "sh"))
481 ;; Have `system' use that Bash.
482 (substitute* "sysdeps/posix/system.c"
483 (("#define[[:blank:]]+SHELL_PATH.*$")
484 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
488 (substitute* "libio/iopopen.c"
490 (string-append out "/bin/bash")))))
492 'install 'install-locales
494 (zero? (system* "make" "localedata/install-locales")))
497 (inputs `(("patch/ld.so.cache"
498 ,(search-patch "glibc-no-ld-so-cache.patch"))
499 ("static-bash" ,(static-package bash-light))))
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 "011v63ppr73vhjgxv00inkn5pc7z48i8lhbapkpdq3kfczq9c76d"))))
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 inputs #:allow-other-keys)
548 (and (zero? (system* "tar" "xvf" (assoc-ref inputs "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 "1dh7nzmfxs8fps4bzcd2lz5fz24zxy2123a99avxsk34jh6bk7id"))))))
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 (zero? (system* "./build.sh")))
599 'install (lambda* (#:key outputs #:allow-other-keys)
600 (let* ((out (assoc-ref outputs "out"))
601 (bin (string-append out "/bin")))
604 (string-append bin "/make"))))
606 (inputs %bootstrap-inputs))))
608 (define diffutils-boot0
609 (package-with-bootstrap-guile
610 (let ((p (package-with-explicit-inputs diffutils
611 `(("make" ,gnu-make-boot0)
613 #:guile %bootstrap-guile)))
615 (location (source-properties->location (current-source-location)))
616 (arguments `(#:tests? #f ; the test suite needs diffutils
617 ,@(package-arguments p)))))))
619 (define findutils-boot0
620 (package-with-bootstrap-guile
621 (package-with-explicit-inputs findutils
622 `(("make" ,gnu-make-boot0)
623 ("diffutils" ,diffutils-boot0) ; for tests
625 (current-source-location)
626 #:guile %bootstrap-guile)))
629 (define %boot0-inputs
630 `(("make" ,gnu-make-boot0)
631 ("diffutils" ,diffutils-boot0)
632 ("findutils" ,findutils-boot0)
633 ,@%bootstrap-inputs))
635 (define* (nix-system->gnu-triplet
636 #:optional (system (%current-system)) (vendor "unknown"))
637 "Return an a guess of the GNU triplet corresponding to Nix system
639 (let* ((dash (string-index system #\-))
640 (arch (substring system 0 dash))
641 (os (substring system (+ 1 dash))))
644 (if (string=? os "linux")
648 (define* (boot-triplet #:optional (system (%current-system)))
649 ;; Return the triplet used to create the cross toolchain needed in the
650 ;; first bootstrapping stage.
651 (nix-system->gnu-triplet system "guix"))
653 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
654 ;; toolchain actually targets the same OS and arch, but it has the advantage
655 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
656 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
658 (define binutils-boot0
659 (package-with-bootstrap-guile
660 (package (inherit binutils)
661 (name "binutils-cross-boot0")
663 `(#:guile ,%bootstrap-guile
664 #:implicit-inputs? #f
665 ,@(substitute-keyword-arguments (package-arguments binutils)
666 ((#:configure-flags cf)
667 `(cons ,(string-append "--target=" (boot-triplet))
669 (inputs %boot0-inputs))))
672 (package-with-bootstrap-guile
673 (package (inherit gcc-4.7)
674 (name "gcc-cross-boot0")
676 `(#:guile ,%bootstrap-guile
677 #:implicit-inputs? #f
678 #:modules ((guix build gnu-build-system)
683 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
684 ((#:configure-flags flags)
685 `(append (list ,(string-append "--target=" (boot-triplet))
690 ;; Disable features not needed at this stage.
692 "--enable-languages=c"
693 "--disable-libmudflap"
696 "--disable-libquadmath"
697 "--disable-decimal-float")
698 (remove (cut string-match "--enable-languages.*" <>)
702 'unpack 'unpack-gmp&co
703 (lambda* (#:key inputs #:allow-other-keys)
704 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
705 (mpfr (assoc-ref %build-inputs "mpfr-source"))
706 (mpc (assoc-ref %build-inputs "mpc-source")))
708 ;; To reduce the set of pre-built bootstrap inputs, build
709 ;; GMP & co. from GCC.
710 (for-each (lambda (source)
711 (or (zero? (system* "tar" "xvf" source))
712 (error "failed to unpack tarball"
716 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
718 `(symlink ,(package-full-name lib)
719 ,(package-name lib)))
722 ;; MPFR headers/lib are found under $(MPFR)/src, but
723 ;; `configure' wrongfully tells MPC too look under
724 ;; $(MPFR), so fix that.
725 (substitute* "configure"
726 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
727 _ equals include middle lib)
728 (string-append "extra_mpc_mpfr_configure_flags" equals
729 "--with-mpfr-include=" include
731 "--with-mpfr-lib=" lib
733 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
734 (string-append "gmpinc='-I" a "/mpfr/src "
736 (("gmplibs='-L([^ ]+)/mpfr" _ a)
737 (string-append "gmplibs='-L" a "/mpfr/src")))))
739 'install 'symlink-libgcc_eh
740 (lambda* (#:key outputs #:allow-other-keys)
741 (let ((out (assoc-ref outputs "out")))
742 ;; Glibc wants to link against libgcc_eh, so provide
744 (with-directory-excursion
745 (string-append out "/lib/gcc/"
747 "/" ,(package-version gcc-4.7))
748 (symlink "libgcc.a" "libgcc_eh.a"))))
751 (inputs `(("gmp-source" ,(package-source gmp))
752 ("mpfr-source" ,(package-source mpfr))
753 ("mpc-source" ,(package-source mpc))
754 ("binutils-cross" ,binutils-boot0)
756 ;; Call it differently so that the builder can check whether
757 ;; the "libc" input is #f.
758 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
759 ,@(alist-delete "libc" %boot0-inputs)))
761 ;; No need for Texinfo at this stage.
762 (native-inputs (alist-delete "texinfo"
763 (package-native-inputs gcc-4.7))))))
765 (define linux-libre-headers-boot0
766 (package-with-bootstrap-guile
767 (package (inherit linux-libre-headers)
768 (arguments `(#:guile ,%bootstrap-guile
769 #:implicit-inputs? #f
770 ,@(package-arguments linux-libre-headers)))
772 (let ((perl (package-with-explicit-inputs perl
774 (current-source-location)
775 #:guile %bootstrap-guile)))
777 ,@%boot0-inputs))))))
779 (define %boot1-inputs
782 ("binutils-cross" ,binutils-boot0)
784 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
788 (define glibc-final-with-bootstrap-bash
789 ;; The final libc, "cross-built". If everything went well, the resulting
790 ;; store path has no dependencies. Actually, the really-final libc is
791 ;; built just below; the only difference is that this one uses the
793 (package-with-bootstrap-guile
794 (package (inherit glibc)
795 (name "glibc-intermediate")
797 `(#:guile ,%bootstrap-guile
798 #:implicit-inputs? #f
800 ,@(substitute-keyword-arguments (package-arguments glibc)
801 ((#:configure-flags flags)
802 `(append (list ,(string-append "--host=" (boot-triplet))
803 ,(string-append "--build="
804 (nix-system->gnu-triplet))
806 ;; Build Sun/ONC RPC support. In particular,
808 "--enable-obsolete-rpc")
810 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
812 `( ;; A native GCC is needed to build `cross-rpcgen'.
813 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
815 ;; Here, we use the bootstrap Bash, which is not satisfactory
816 ;; because we don't want to depend on bootstrap tools.
817 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
820 ,@(alist-delete "static-bash"
821 (package-inputs glibc))))))) ; patches
823 (define (cross-gcc-wrapper gcc binutils glibc bash)
824 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
825 that makes it available under the native tool names."
826 (package (inherit gcc-4.7)
827 (name (string-append (package-name gcc) "-wrapped"))
829 (build-system trivial-build-system)
831 `(#:guile ,%bootstrap-guile
832 #:modules ((guix build utils))
834 (use-modules (guix build utils))
836 (let* ((binutils (assoc-ref %build-inputs "binutils"))
837 (gcc (assoc-ref %build-inputs "gcc"))
838 (libc (assoc-ref %build-inputs "libc"))
839 (bash (assoc-ref %build-inputs "bash"))
840 (out (assoc-ref %outputs "out"))
841 (bindir (string-append out "/bin"))
842 (triplet ,(boot-triplet)))
844 (with-directory-excursion bindir
845 (for-each (lambda (tool)
846 (symlink (string-append binutils "/bin/"
851 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
852 ;; needs to be told where to find the crt files and
853 ;; the dynamic linker.
854 (call-with-output-file "gcc"
856 (format p "#!~a/bin/bash
857 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
861 ,(glibc-dynamic-linker))))
863 (chmod "gcc" #o555))))))
865 `(("binutils" ,binutils)
871 (define static-bash-for-glibc
872 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
874 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
875 glibc-final-with-bootstrap-bash
876 (car (assoc-ref %boot1-inputs "bash"))))
877 (bash (package (inherit bash-light)
879 `(#:guile ,%bootstrap-guile
880 ,@(package-arguments bash-light))))))
881 (package-with-bootstrap-guile
882 (package-with-explicit-inputs (static-package bash)
884 ("libc" ,glibc-final-with-bootstrap-bash)
885 ,@(fold alist-delete %boot1-inputs
887 (current-source-location)))))
889 (define-public glibc-final
890 ;; The final glibc, which embeds the statically-linked Bash built above.
891 (package (inherit glibc-final-with-bootstrap-bash)
893 (inputs `(("static-bash" ,static-bash-for-glibc)
896 (package-inputs glibc-final-with-bootstrap-bash))))))
898 (define gcc-boot0-wrapped
899 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
901 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
902 (car (assoc-ref %boot1-inputs "bash"))))
904 (define %boot2-inputs
906 `(("libc" ,glibc-final)
907 ("gcc" ,gcc-boot0-wrapped)
908 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
910 (define-public binutils-final
911 (package-with-bootstrap-guile
912 (package (inherit binutils)
914 `(#:guile ,%bootstrap-guile
915 #:implicit-inputs? #f
916 ,@(package-arguments binutils)))
917 (inputs %boot2-inputs))))
919 (define-public gcc-final
921 (package (inherit gcc-boot0)
924 `(#:guile ,%bootstrap-guile
925 #:implicit-inputs? #f
927 ;; Build again GMP & co. within GCC's build process, because it's hard
928 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
929 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
930 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
931 ((#:configure-flags boot-flags)
932 (let loop ((args (package-arguments gcc-4.7)))
934 ((#:configure-flags normal-flags _ ...)
939 `(alist-delete 'symlink-libgcc_eh ,phases)))))
941 (inputs `(("gmp-source" ,(package-source gmp))
942 ("mpfr-source" ,(package-source mpfr))
943 ("mpc-source" ,(package-source mpc))
944 ("binutils" ,binutils-final)
947 (define ld-wrapper-boot3
948 ;; A linker wrapper that uses the bootstrap Guile.
950 (name "ld-wrapper-boot3")
953 (build-system trivial-build-system)
954 (inputs `(("binutils" ,binutils-final)
955 ("guile" ,%bootstrap-guile)
956 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
957 ("wrapper" ,(search-path %load-path
958 "gnu/packages/ld-wrapper.scm"))))
960 `(#:guile ,%bootstrap-guile
961 #:modules ((guix build utils))
963 (use-modules (guix build utils)
964 (system base compile))
966 (let* ((out (assoc-ref %outputs "out"))
967 (bin (string-append out "/bin"))
968 (ld (string-append bin "/ld"))
969 (go (string-append bin "/ld.go")))
971 (setvbuf (current-output-port) _IOLBF)
972 (format #t "building ~s/bin/ld wrapper in ~s~%"
973 (assoc-ref %build-inputs "binutils")
977 (copy-file (assoc-ref %build-inputs "wrapper") ld)
980 (string-append (assoc-ref %build-inputs "guile")
983 (string-append (assoc-ref %build-inputs "bash")
986 (string-append (assoc-ref %build-inputs "binutils")
989 (compile-file ld #:output-file go)))))
990 (synopsis "The linker wrapper")
992 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
993 missing `-rpath' flags, and to detect any misuse of libraries outside of the
998 (define %boot3-inputs
1000 `(("gcc" ,gcc-final)
1001 ("ld-wrapper" ,ld-wrapper-boot3)
1002 ,@(alist-delete "gcc" %boot2-inputs)))
1004 (define-public bash-final
1005 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1006 ;; to the bootstrap GCC.
1007 (package-with-bootstrap-guile
1008 (package-with-explicit-inputs (static-libgcc-package bash)
1010 (current-source-location)
1011 #:guile %bootstrap-guile)))
1013 (define %boot4-inputs
1014 ;; Now use the final Bash.
1015 `(("bash" ,bash-final)
1016 ,@(alist-delete "bash" %boot3-inputs)))
1018 (define-public guile-final
1019 (package-with-bootstrap-guile
1020 (package-with-explicit-inputs guile-2.0/fixed
1022 (current-source-location)
1023 #:guile %bootstrap-guile)))
1025 (define-public ld-wrapper
1026 ;; The final `ld' wrapper, which uses the final Guile.
1027 (package (inherit ld-wrapper-boot3)
1029 (inputs `(("guile" ,guile-final)
1030 ("bash" ,bash-final)
1031 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1032 '("guile" "bash"))))))
1034 (define-public %final-inputs
1035 ;; Final derivations used as implicit inputs by `gnu-build-system'.
1036 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
1037 (current-source-location))))
1038 `(,@(map (match-lambda
1040 (list name (finalize package))))
1045 ("diffutils" ,diffutils)
1047 ("coreutils" ,coreutils)
1050 ("findutils" ,findutils)
1052 ("make" ,gnu-make)))
1053 ("bash" ,bash-final)
1054 ("ld-wrapper" ,ld-wrapper)
1055 ("binutils" ,binutils-final)
1057 ("libc" ,glibc-final))))
1059 ;;; base.scm ends here