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 #:use-module (gnu packages)
23 #:use-module (gnu packages acl)
24 #:use-module (gnu packages bash)
25 #:use-module (gnu packages bootstrap)
26 #:use-module (gnu packages compression)
27 #:use-module (gnu packages gawk)
28 #:use-module (gnu packages guile)
29 #:use-module (gnu packages multiprecision)
30 #:use-module (gnu packages perl)
31 #:use-module (gnu packages linux)
32 #:use-module (guix packages)
33 #:use-module (guix download)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system trivial)
36 #:use-module (guix utils)
37 #:use-module (srfi srfi-1)
38 #:use-module (srfi srfi-26)
39 #:use-module (ice-9 match))
43 ;;; Base packages of the Guix-based GNU user-land software distribution.
53 (uri (string-append "mirror://gnu/hello/hello-" version
56 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
57 (build-system gnu-build-system)
58 (arguments '(#:configure-flags
59 `("--disable-dependency-tracking"
60 ,(string-append "--with-gawk=" ; for illustration purposes
61 (assoc-ref %build-inputs "gawk")))))
62 (inputs `(("gawk" ,gawk)))
63 (synopsis "GNU Hello")
64 (description "Yeah...")
65 (home-page "http://www.gnu.org/software/hello/")
74 (uri (string-append "mirror://gnu/grep/grep-"
78 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
79 (build-system gnu-build-system)
80 (synopsis "GNU implementation of the Unix grep command")
82 "The grep command searches one or more input files for lines containing a
83 match to a specified pattern. By default, grep prints the matching
86 (home-page "http://www.gnu.org/software/grep/")))
94 (uri (string-append "mirror://gnu/sed/sed-" version
98 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
99 (build-system gnu-build-system)
100 (synopsis "GNU sed, a batch stream editor")
102 `(#:phases (alist-cons-before
103 'patch-source-shebangs 'patch-test-suite
104 (lambda* (#:key inputs #:allow-other-keys)
105 (let ((bash (assoc-ref inputs "bash")))
106 (patch-makefile-SHELL "testsuite/Makefile.tests")
107 (substitute* '("testsuite/bsd.sh"
108 "testsuite/bug-regex9.c")
110 (string-append bash "/bin/bash")))))
113 "Sed (stream editor) isn't really a true text editor or text processor.
114 Instead, it is used to filter text, i.e., it takes text input and performs
115 some operation (or set of operations) on it and outputs the modified text.
116 Sed is typically used for extracting part of a file using pattern matching or
117 substituting multiple occurrences of a string within a file.")
119 (home-page "http://www.gnu.org/software/sed/")))
127 (uri (string-append "mirror://gnu/tar/tar-"
131 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
132 (build-system gnu-build-system)
133 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
135 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
136 (synopsis "GNU implementation of the `tar' archiver")
138 "The Tar program provides the ability to create tar archives, as well as
139 various other kinds of manipulation. For example, you can use Tar on
140 previously created archives to extract files, to store additional files, or
141 to update or list files which were already stored.
143 Initially, tar archives were used to store files conveniently on magnetic
144 tape. The name \"Tar\" comes from this use; it stands for tape archiver.
145 Despite the utility's name, Tar can direct its output to available devices,
146 files, or other programs (using pipes), it can even access remote devices or
147 files (as archives).")
149 (home-page "http://www.gnu.org/software/tar/")))
157 (uri (string-append "mirror://gnu/patch/patch-"
161 "18012gxs9wc96izskp1q7bclrwns6rdmkn4jj31c8jbyfz6l5npq"))))
162 (build-system gnu-build-system)
163 (native-inputs '()) ; FIXME: needs `ed' for the tests
166 ;; TODO: When cross-compiling, add this:
167 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
169 (synopsis "GNU Patch, a program to apply differences to files")
171 "GNU Patch takes a patch file containing a difference listing produced by
172 the diff program and applies those differences to one or more original files,
173 producing patched versions.")
175 (home-page "http://savannah.gnu.org/projects/patch/")))
177 (define-public diffutils
183 (uri (string-append "mirror://gnu/diffutils/diffutils-"
187 "0jci0wv68025xd0s0rq4s5qxpx56dd9d730lka63qpzk1rfvfkxb"))))
188 (build-system gnu-build-system)
189 (inputs `(("patch/gets"
190 ,(search-patch "diffutils-gets-undeclared.patch"))))
191 (arguments `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
192 (synopsis "Programs to find differences among text files")
194 "GNU Diffutils is a package of several programs related to finding
195 differences between files.
197 Computer users often find occasion to ask how two files differ. Perhaps one
198 file is a newer version of the other file. Or maybe the two files started out
199 as identical copies but were changed by different people.
201 You can use the diff command to show differences between two files, or each
202 corresponding file in two directories. diff outputs differences between files
203 line by line in any of several formats, selectable by command line
204 options. This set of differences is often called a ‘diff’ or ‘patch’. For
205 files that are identical, diff normally produces no output; for
206 binary (non-text) files, diff normally reports only that they are different.
208 You can use the cmp command to show the offsets and line numbers where two
209 files differ. cmp can also show all the characters that differ between the
210 two files, side by side.
212 You can use the diff3 command to show differences among three files. When two
213 people have made independent changes to a common original, diff3 can report
214 the differences between the original and the two changed versions, and can
215 produce a merged file that contains both persons' changes together with
216 warnings about conflicts.
218 You can use the sdiff command to merge two files interactively.")
220 (home-page "http://www.gnu.org/software/diffutils/")))
222 (define-public findutils
228 (uri (string-append "mirror://gnu/findutils/findutils-"
232 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))))
233 (build-system gnu-build-system)
235 `(("patch/absolute-paths"
236 ,(search-patch "findutils-absolute-paths.patch"))))
238 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths")))
240 ;; TODO: Work around cross-compilation failure.
241 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
242 ;; `(#:configure-flags '("gl_cv_func_wcwidth_works=yes")
243 ;; ,@(arguments cross-system))
245 (synopsis "Basic directory searching utilities of the GNU operating
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)
277 ("perl" ,perl))) ; TODO: add SELinux
279 `(#:parallel-build? #f ; help2man may be called too early
280 #:phases (alist-cons-before
281 'build 'patch-shell-references
282 (lambda* (#:key inputs #:allow-other-keys)
283 (let ((bash (assoc-ref inputs "bash")))
284 (substitute* (cons "src/split.c"
285 (find-files "gnulib-tests"
288 (format #f "~a/bin/sh" bash)))
289 (substitute* (find-files "tests" "\\.sh$")
291 (format #f "#!~a/bin/bash" bash)))))
294 "The basic file, shell and text manipulation utilities of the GNU
297 "The GNU Core Utilities are the basic file, shell and text manipulation
298 utilities of the GNU operating system. These are the core utilities which
299 are expected to exist on every operating system.")
301 (home-page "http://www.gnu.org/software/coreutils/")))
303 (define-public gnu-make
309 (uri (string-append "mirror://gnu/make/make-" version
313 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
314 (build-system gnu-build-system)
316 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
318 '(#:patches (list (assoc-ref %build-inputs "patch/impure-dirs"))
319 #:phases (alist-cons-before
320 'build 'set-default-shell
321 (lambda* (#:key inputs #:allow-other-keys)
322 ;; Change the default shell from /bin/sh.
323 (let ((bash (assoc-ref inputs "bash")))
325 (("default_shell\\[\\] =.*$")
326 (format #f "default_shell[] = \"~a/bin/bash\";\n"
329 (synopsis "GNU Make, a program controlling the generation of non-source
332 "Make is a tool which controls the generation of executables and other
333 non-source files of a program from the program's source files.
335 Make gets its knowledge of how to build your program from a file called the
336 makefile, which lists each of the non-source files and how to compute it from
337 other files. When you write a program, you should write a makefile for it, so
338 that it is possible to use Make to build and install the program.")
340 (home-page "http://www.gnu.org/software/make/")))
342 (define-public binutils
348 (uri (string-append "mirror://gnu/binutils/binutils-"
352 "06bs5v5ndb4g5qx96d52lc818gkbskd1m0sz57314v887sqfbcia"))))
353 (build-system gnu-build-system)
355 ;; Split Binutils in several outputs, mostly to avoid collisions in
356 ;; user profiles with GCC---e.g., libiberty.a.
357 (outputs '("out" ; ar, ld, binutils.info, etc.
358 "lib")) ; libbfd.a, bfd.h, etc.
360 ;; TODO: Add dependency on zlib + those for Gold.
362 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
364 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
365 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
366 ;; on GCC when bootstrapping.
367 "LDFLAGS=-static-libgcc"
369 ;; Don't search under /usr/lib & co.
370 "--with-lib-path=/no-ld-lib-path"
372 ;; Glibc 2.17 has a "comparison of unsigned
373 ;; expression >= 0 is always true" in wchar.h.
374 "--disable-werror")))
376 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
379 "The GNU Binutils are a collection of binary tools. The main ones are
380 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
381 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
383 (home-page "http://www.gnu.org/software/binutils/")))
385 (define-public gcc-4.7
386 (let ((stripped? #t)) ; TODO: make this a parameter
392 (uri (string-append "mirror://gnu/gcc/gcc-"
393 version "/gcc-" version ".tar.bz2"))
396 "115h03hil99ljig8lkrq4qk426awmzh0g99wrrggxf8g07bq74la"))))
397 (build-system gnu-build-system)
398 (inputs `(("gmp" ,gmp)
400 ("mpc" ,mpc))) ; TODO: libelf, ppl, cloog, zlib, etc.
402 `(#:out-of-source? #t
403 #:strip-binaries? ,stripped?
406 "--enable-languages=c,c++"
409 "--with-local-prefix=/no-gcc-local-prefix"
411 ,(let ((libc (assoc-ref %build-inputs "libc")))
413 (string-append "--with-native-system-header-dir=" libc
415 "--without-headers")))
417 (let ((libc (assoc-ref %build-inputs "libc")))
419 (list (string-append "LDFLAGS_FOR_TARGET="
421 "-Wl,-dynamic-linker "
423 ,(glibc-dynamic-linker)))
425 ,(string-append "BOOT_CFLAGS=-O2 "
426 ,(if stripped? "-g0" "-g"))))
431 'configure 'pre-configure
432 (lambda* (#:key inputs outputs #:allow-other-keys)
433 (let ((out (assoc-ref outputs "out"))
434 (libc (assoc-ref inputs "libc")))
436 ;; The following is not performed for `--without-headers'
437 ;; cross-compiler builds.
439 ;; Fix the dynamic linker's file name.
440 (substitute* (find-files "gcc/config"
441 "^linux(64|-elf)?\\.h$")
442 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
443 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
445 (string-append libc ,(glibc-dynamic-linker)))))
447 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
448 ;; `crt{begin,end}.o', which come with GCC.
449 (substitute* (find-files "gcc/config"
450 "^(gnu-user(64)?|linux-elf)\\.h$")
451 (("#define LIB_SPEC (.*)$" _ suffix)
452 ;; Note that with this "lib" spec, we may still add a
453 ;; RUNPATH to GCC even when `libgcc_s' is not NEEDED.
454 ;; There's not much that can be done to avoid it, though.
455 (format #f "#define LIB_SPEC \"-L~a/lib %{!static:-rpath=~a/lib \
456 %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib}} \" ~a"
457 libc libc out out suffix))
458 (("#define STARTFILE_SPEC.*$" line)
459 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
460 #define STANDARD_STARTFILE_PREFIX_2 \"\"
464 ;; Don't retain a dependency on the build-time sed.
465 (substitute* "fixincludes/fixincl.x"
466 (("static char const sed_cmd_z\\[\\] =.*;")
467 "static char const sed_cmd_z[] = \"sed\";"))))
470 'configure 'post-configure
472 ;; Don't store configure flags, to avoid retaining references to
473 ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
474 (substitute* "Makefile"
475 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
476 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
477 (alist-replace 'install
478 (lambda* (#:key outputs #:allow-other-keys)
484 %standard-phases)))))
486 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
487 (synopsis "The GNU Compiler Collection")
489 "The GNU Compiler Collection includes compiler front ends for C, C++,
490 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well as
491 libraries for these languages (libstdc++, libgcj, libgomp,...).
493 GCC development is a part of the GNU Project, aiming to improve the compiler
494 used in the GNU system including the GNU/Linux variant.")
496 (home-page "http://gcc.gnu.org/"))))
504 (uri (string-append "mirror://gnu/glibc/glibc-"
508 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
509 (build-system gnu-build-system)
511 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
512 ;; users should automatically pull Linux headers as well.
513 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
515 ;; Store the locales separately (~100 MiB). Note that "out" retains a
516 ;; reference to them anyway, so there's no space savings here.
517 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
519 (outputs '("out" "locales"))
522 `(#:out-of-source? #t
523 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
525 (list "--enable-add-ons"
527 (string-append "--localedir=" (assoc-ref %outputs "locales")
530 ;; `--localedir' is not honored, so work around it.
531 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
532 (string-append "libc_cv_localedir="
533 (assoc-ref %outputs "locales")
537 (string-append "--with-headers="
538 (assoc-ref %build-inputs "linux-headers")
541 ;; The default is to assume a 2.4 Linux interface, but we'll
542 ;; always use something newer. See "kernel-features.h" in the
543 ;; GNU libc for details.
544 "--enable-kernel=2.6.30"
546 ;; Use our Bash instead of /bin/sh.
547 (string-append "BASH_SHELL="
548 (assoc-ref %build-inputs "bash")
551 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
555 #:phases (alist-cons-before
556 'configure 'pre-configure
557 (lambda* (#:key inputs outputs #:allow-other-keys)
558 (let* ((out (assoc-ref outputs "out"))
559 (bin (string-append out "/bin")))
560 ;; Use `pwd', not `/bin/pwd'.
561 (substitute* "configure"
562 (("/bin/pwd") "pwd"))
564 ;; Install the rpc data base file under `$out/etc/rpc'.
565 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
566 (substitute* "sunrpc/Makefile"
567 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
568 (string-append out "/etc/rpc" suffix "\n"))
569 (("^install-others =.*$")
570 (string-append "install-others = " out "/etc/rpc\n")))
572 (substitute* "Makeconfig"
574 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
575 ;; linking against libgcc_s is not needed with GCC
579 ;; Copy a statically-linked Bash in the output, with
580 ;; no references to other store paths.
582 (copy-file (string-append (assoc-ref inputs "static-bash")
584 (string-append bin "/bash"))
585 (remove-store-references (string-append bin "/bash"))
586 (chmod (string-append bin "/bash") #o555)
588 ;; Keep a symlink, for `patch-shebang' resolution.
589 (with-directory-excursion bin
590 (symlink "bash" "sh"))
592 ;; Have `system' use that Bash.
593 (substitute* "sysdeps/posix/system.c"
594 (("#define[[:blank:]]+SHELL_PATH.*$")
595 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
599 (substitute* "libio/iopopen.c"
601 (string-append out "/bin/bash")))))
603 'install 'install-locales
605 (zero? (system* "make" "localedata/install-locales")))
608 (inputs `(("patch/ld.so.cache"
609 ,(search-patch "glibc-no-ld-so-cache.patch"))
610 ("static-bash" ,(static-package bash-light))))
611 (synopsis "The GNU C Library")
613 "Any Unix-like operating system needs a C library: the library which
614 defines the \"system calls\" and other basic facilities such as open, malloc,
617 The GNU C library is used as the C library in the GNU system and most systems
618 with the Linux kernel.")
620 (home-page "http://www.gnu.org/software/libc/")))
624 ;;; Bootstrap packages.
627 (define gnu-make-boot0
628 (package-with-bootstrap-guile
629 (package (inherit gnu-make)
631 (location (source-properties->location (current-source-location)))
633 `(#:guile ,%bootstrap-guile
634 #:implicit-inputs? #f
635 #:tests? #f ; cannot run "make check"
636 ,@(substitute-keyword-arguments (package-arguments gnu-make)
640 (zero? (system* "./build.sh")))
642 'install (lambda* (#:key outputs #:allow-other-keys)
643 (let* ((out (assoc-ref outputs "out"))
644 (bin (string-append out "/bin")))
647 (string-append bin "/make"))))
649 (inputs %bootstrap-inputs))))
651 (define diffutils-boot0
652 (package-with-bootstrap-guile
653 (let ((p (package-with-explicit-inputs diffutils
654 `(("make" ,gnu-make-boot0)
656 #:guile %bootstrap-guile)))
658 (location (source-properties->location (current-source-location)))
659 (arguments `(#:tests? #f ; the test suite needs diffutils
660 ,@(package-arguments p)))))))
662 (define findutils-boot0
663 (package-with-bootstrap-guile
664 (package-with-explicit-inputs findutils
665 `(("make" ,gnu-make-boot0)
666 ("diffutils" ,diffutils-boot0) ; for tests
668 (current-source-location)
669 #:guile %bootstrap-guile)))
672 (define %boot0-inputs
673 `(("make" ,gnu-make-boot0)
674 ("diffutils" ,diffutils-boot0)
675 ("findutils" ,findutils-boot0)
676 ,@%bootstrap-inputs))
678 (define* (nix-system->gnu-triplet
679 #:optional (system (%current-system)) (vendor "unknown"))
680 "Return an a guess of the GNU triplet corresponding to Nix system
682 (let* ((dash (string-index system #\-))
683 (arch (substring system 0 dash))
684 (os (substring system (+ 1 dash))))
687 (if (string=? os "linux")
691 (define* (boot-triplet #:optional (system (%current-system)))
692 ;; Return the triplet used to create the cross toolchain needed in the
693 ;; first bootstrapping stage.
694 (nix-system->gnu-triplet system "guix"))
696 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
697 ;; toolchain actually targets the same OS and arch, but it has the advantage
698 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
699 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
701 (define binutils-boot0
702 (package-with-bootstrap-guile
703 (package (inherit binutils)
704 (name "binutils-cross-boot0")
706 `(#:guile ,%bootstrap-guile
707 #:implicit-inputs? #f
708 ,@(substitute-keyword-arguments (package-arguments binutils)
709 ((#:configure-flags cf)
710 `(cons ,(string-append "--target=" (boot-triplet))
712 (inputs %boot0-inputs))))
715 (package-with-bootstrap-guile
716 (package (inherit gcc-4.7)
717 (name "gcc-cross-boot0")
719 `(#:guile ,%bootstrap-guile
720 #:implicit-inputs? #f
721 #:modules ((guix build gnu-build-system)
726 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
727 ((#:configure-flags flags)
728 `(append (list ,(string-append "--target=" (boot-triplet))
733 ;; Disable features not needed at this stage.
735 "--enable-languages=c"
736 "--disable-libmudflap"
739 "--disable-libquadmath"
740 "--disable-decimal-float")
741 (remove (cut string-match "--enable-languages.*" <>)
745 'unpack 'unpack-gmp&co
746 (lambda* (#:key inputs #:allow-other-keys)
747 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
748 (mpfr (assoc-ref %build-inputs "mpfr-source"))
749 (mpc (assoc-ref %build-inputs "mpc-source")))
751 ;; To reduce the set of pre-built bootstrap inputs, build
752 ;; GMP & co. from GCC.
753 (for-each (lambda (source)
754 (or (zero? (system* "tar" "xvf" source))
755 (error "failed to unpack tarball"
759 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
761 `(symlink ,(package-full-name lib)
762 ,(package-name lib)))
765 ;; MPFR headers/lib are found under $(MPFR)/src, but
766 ;; `configure' wrongfully tells MPC too look under
767 ;; $(MPFR), so fix that.
768 (substitute* "configure"
769 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
770 _ equals include middle lib)
771 (string-append "extra_mpc_mpfr_configure_flags" equals
772 "--with-mpfr-include=" include
774 "--with-mpfr-lib=" lib
776 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
777 (string-append "gmpinc='-I" a "/mpfr/src "
779 (("gmplibs='-L([^ ]+)/mpfr" _ a)
780 (string-append "gmplibs='-L" a "/mpfr/src")))))
782 'install 'symlink-libgcc_eh
783 (lambda* (#:key outputs #:allow-other-keys)
784 (let ((out (assoc-ref outputs "out")))
785 ;; Glibc wants to link against libgcc_eh, so provide
787 (with-directory-excursion
788 (string-append out "/lib/gcc/"
790 "/" ,(package-version gcc-4.7))
791 (symlink "libgcc.a" "libgcc_eh.a"))))
794 (inputs `(("gmp-source" ,(package-source gmp))
795 ("mpfr-source" ,(package-source mpfr))
796 ("mpc-source" ,(package-source mpc))
797 ("binutils-cross" ,binutils-boot0)
799 ;; Call it differently so that the builder can check whether
800 ;; the "libc" input is #f.
801 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
802 ,@(alist-delete "libc" %boot0-inputs))))))
804 (define linux-libre-headers-boot0
805 (package-with-bootstrap-guile
806 (package (inherit linux-libre-headers)
807 (arguments `(#:guile ,%bootstrap-guile
808 #:implicit-inputs? #f
809 ,@(package-arguments linux-libre-headers)))
811 (let ((perl (package-with-explicit-inputs perl
813 (current-source-location)
814 #:guile %bootstrap-guile)))
816 ,@%boot0-inputs))))))
818 (define %boot1-inputs
821 ("binutils-cross" ,binutils-boot0)
823 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
827 (define glibc-final-with-bootstrap-bash
828 ;; The final libc, "cross-built". If everything went well, the resulting
829 ;; store path has no dependencies. Actually, the really-final libc is
830 ;; built just below; the only difference is that this one uses the
832 (package-with-bootstrap-guile
833 (package (inherit glibc)
834 (name "glibc-intermediate")
836 `(#:guile ,%bootstrap-guile
837 #:implicit-inputs? #f
839 ,@(substitute-keyword-arguments (package-arguments glibc)
840 ((#:configure-flags flags)
841 `(append (list ,(string-append "--host=" (boot-triplet))
842 ,(string-append "--build="
843 (nix-system->gnu-triplet))
845 ;; Build Sun/ONC RPC support. In particular,
847 "--enable-obsolete-rpc")
849 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
851 `( ;; A native GCC is needed to build `cross-rpcgen'.
852 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
854 ;; Here, we use the bootstrap Bash, which is not satisfactory
855 ;; because we don't want to depend on bootstrap tools.
856 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
859 ,@(alist-delete "static-bash"
860 (package-inputs glibc))))))) ; patches
862 (define (cross-gcc-wrapper gcc binutils glibc bash)
863 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
864 that makes it available under the native tool names."
865 (package (inherit gcc-4.7)
866 (name (string-append (package-name gcc) "-wrapped"))
868 (build-system trivial-build-system)
870 `(#:guile ,%bootstrap-guile
871 #:modules ((guix build utils))
873 (use-modules (guix build utils))
875 (let* ((binutils (assoc-ref %build-inputs "binutils"))
876 (gcc (assoc-ref %build-inputs "gcc"))
877 (libc (assoc-ref %build-inputs "libc"))
878 (bash (assoc-ref %build-inputs "bash"))
879 (out (assoc-ref %outputs "out"))
880 (bindir (string-append out "/bin"))
881 (triplet ,(boot-triplet)))
883 (with-directory-excursion bindir
884 (for-each (lambda (tool)
885 (symlink (string-append binutils "/bin/"
890 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
891 ;; needs to be told where to find the crt files and
892 ;; the dynamic linker.
893 (call-with-output-file "gcc"
895 (format p "#!~a/bin/bash
896 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
900 ,(glibc-dynamic-linker))))
902 (chmod "gcc" #o555))))))
904 `(("binutils" ,binutils)
910 (define static-bash-for-glibc
911 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
913 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
914 glibc-final-with-bootstrap-bash
915 (car (assoc-ref %boot1-inputs "bash"))))
916 (bash (package (inherit bash-light)
918 `(#:guile ,%bootstrap-guile
919 ,@(package-arguments bash-light))))))
920 (package-with-bootstrap-guile
921 (package-with-explicit-inputs (static-package bash)
923 ("libc" ,glibc-final-with-bootstrap-bash)
924 ,@(fold alist-delete %boot1-inputs
926 (current-source-location)))))
928 (define-public glibc-final
929 ;; The final glibc, which embeds the statically-linked Bash built above.
930 (package (inherit glibc-final-with-bootstrap-bash)
932 (inputs `(("static-bash" ,static-bash-for-glibc)
935 (package-inputs glibc-final-with-bootstrap-bash))))))
937 (define gcc-boot0-wrapped
938 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
940 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
941 (car (assoc-ref %boot1-inputs "bash"))))
943 (define %boot2-inputs
945 `(("libc" ,glibc-final)
946 ("gcc" ,gcc-boot0-wrapped)
947 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
949 (define-public binutils-final
950 (package-with-bootstrap-guile
951 (package (inherit binutils)
953 `(#:guile ,%bootstrap-guile
954 #:implicit-inputs? #f
955 ,@(package-arguments binutils)))
956 (inputs %boot2-inputs))))
958 (define-public gcc-final
960 (package (inherit gcc-boot0)
963 `(#:guile ,%bootstrap-guile
964 #:implicit-inputs? #f
966 ;; Build again GMP & co. within GCC's build process, because it's hard
967 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
968 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
969 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
970 ((#:configure-flags boot-flags)
971 (let loop ((args (package-arguments gcc-4.7)))
973 ((#:configure-flags normal-flags _ ...)
978 `(alist-delete 'symlink-libgcc_eh ,phases)))))
980 (inputs `(("gmp-source" ,(package-source gmp))
981 ("mpfr-source" ,(package-source mpfr))
982 ("mpc-source" ,(package-source mpc))
983 ("binutils" ,binutils-final)
986 (define ld-wrapper-boot3
987 ;; A linker wrapper that uses the bootstrap Guile.
989 (name "ld-wrapper-boot3")
992 (build-system trivial-build-system)
993 (inputs `(("binutils" ,binutils-final)
994 ("guile" ,%bootstrap-guile)
995 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
996 ("wrapper" ,(search-path %load-path
997 "gnu/packages/ld-wrapper.scm"))))
999 `(#:guile ,%bootstrap-guile
1000 #:modules ((guix build utils))
1002 (use-modules (guix build utils)
1003 (system base compile))
1005 (let* ((out (assoc-ref %outputs "out"))
1006 (bin (string-append out "/bin"))
1007 (ld (string-append bin "/ld"))
1008 (go (string-append bin "/ld.go")))
1010 (setvbuf (current-output-port) _IOLBF)
1011 (format #t "building ~s/bin/ld wrapper in ~s~%"
1012 (assoc-ref %build-inputs "binutils")
1016 (copy-file (assoc-ref %build-inputs "wrapper") ld)
1019 (string-append (assoc-ref %build-inputs "guile")
1022 (string-append (assoc-ref %build-inputs "bash")
1025 (string-append (assoc-ref %build-inputs "binutils")
1028 (compile-file ld #:output-file go)))))
1029 (synopsis "The linker wrapper")
1031 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1032 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1037 (define %boot3-inputs
1038 ;; 4th stage inputs.
1039 `(("gcc" ,gcc-final)
1040 ("ld-wrapper" ,ld-wrapper-boot3)
1041 ,@(alist-delete "gcc" %boot2-inputs)))
1043 (define-public bash-final
1044 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1045 ;; to the bootstrap GCC.
1046 (package-with-bootstrap-guile
1047 (package-with-explicit-inputs (static-libgcc-package bash)
1049 (current-source-location)
1050 #:guile %bootstrap-guile)))
1052 (define %boot4-inputs
1053 ;; Now use the final Bash.
1054 `(("bash" ,bash-final)
1055 ,@(alist-delete "bash" %boot3-inputs)))
1057 (define-public guile-final
1058 (package-with-bootstrap-guile
1059 (package-with-explicit-inputs guile-2.0/fixed
1061 (current-source-location)
1062 #:guile %bootstrap-guile)))
1064 (define-public ld-wrapper
1065 ;; The final `ld' wrapper, which uses the final Guile.
1066 (package (inherit ld-wrapper-boot3)
1068 (inputs `(("guile" ,guile-final)
1069 ("bash" ,bash-final)
1070 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1071 '("guile" "bash"))))))
1073 (define-public %final-inputs
1074 ;; Final derivations used as implicit inputs by `gnu-build-system'.
1075 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
1076 (current-source-location))))
1077 `(,@(map (match-lambda
1079 (list name (finalize package))))
1084 ("diffutils" ,diffutils)
1086 ("coreutils" ,coreutils)
1089 ("findutils" ,findutils)
1091 ("make" ,gnu-make)))
1092 ("bash" ,bash-final)
1093 ("ld-wrapper" ,ld-wrapper)
1094 ("binutils" ,binutils-final)
1096 ("libc" ,glibc-final))))
1098 ;;; base.scm ends here