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 (distro packages base)
21 #:use-module (guix licenses)
23 #:use-module (distro packages acl)
24 #:use-module (distro packages bash)
25 #:use-module (distro packages bootstrap)
26 #:use-module (distro packages compression)
27 #:use-module (distro packages gawk)
28 #:use-module (distro packages guile)
29 #:use-module (distro packages multiprecision)
30 #:use-module (distro packages perl)
31 #:use-module (distro 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 "13wlsb4sf5d5a82xjhxqmdvrrn36rmw5f0pl9qyb9zkvldnb7hra"))))
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 ((system) '(#:tests? #f))
167 ((system cross-system)
168 '(#: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"))))
240 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths"))))
241 ((system cross-system)
242 ;; Work around cross-compilation failure.
243 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
244 `(#:configure-flags '("gl_cv_func_wcwidth_works=yes")
245 ,@(arguments cross-system)))))
246 (synopsis "Basic directory searching utilities of the GNU operating
249 "The GNU Find Utilities are the basic directory searching utilities of
250 the GNU operating system. These programs are typically used in conjunction
251 with other programs to provide modular and powerful directory search and file
252 locating capabilities to other commands.
254 The tools supplied with this package are:
256 * find - search for files in a directory hierarchy;
257 * locate - list files in databases that match a pattern;
258 * updatedb - update a file name database;
259 * xargs - build and execute command lines from standard input.
262 (home-page "http://www.gnu.org/software/findutils/")))
264 (define-public coreutils
270 (uri (string-append "mirror://gnu/coreutils/coreutils-"
274 "1cly97xdy3v4nbbx631k43smqw0nnpn651kkprs0yyl2cj3pkjyv"))))
275 (build-system gnu-build-system)
276 (inputs `(("acl" ,acl)
278 ("perl" ,perl))) ; TODO: add SELinux
280 `(#:parallel-build? #f ; help2man may be called too early
281 #:phases (alist-cons-before
282 'build 'patch-shell-references
283 (lambda* (#:key inputs #:allow-other-keys)
284 (let ((bash (assoc-ref inputs "bash")))
285 (substitute* (cons "src/split.c"
286 (find-files "gnulib-tests"
289 (format #f "~a/bin/sh" bash)))
290 (substitute* (find-files "tests" "\\.sh$")
292 (format #f "#!~a/bin/bash" bash)))))
295 "The basic file, shell and text manipulation utilities of the GNU
298 "The GNU Core Utilities are the basic file, shell and text manipulation
299 utilities of the GNU operating system. These are the core utilities which
300 are expected to exist on every operating system.")
302 (home-page "http://www.gnu.org/software/coreutils/")))
304 (define-public gnu-make
310 (uri (string-append "mirror://gnu/make/make-" version
314 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
315 (build-system gnu-build-system)
317 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
319 '(#:patches (list (assoc-ref %build-inputs "patch/impure-dirs"))
320 #:phases (alist-cons-before
321 'build 'set-default-shell
322 (lambda* (#:key inputs #:allow-other-keys)
323 ;; Change the default shell from /bin/sh.
324 (let ((bash (assoc-ref inputs "bash")))
326 (("default_shell\\[\\] =.*$")
327 (format #f "default_shell[] = \"~a/bin/bash\";\n"
330 (synopsis "GNU Make, a program controlling the generation of non-source
333 "Make is a tool which controls the generation of executables and other
334 non-source files of a program from the program's source files.
336 Make gets its knowledge of how to build your program from a file called the
337 makefile, which lists each of the non-source files and how to compute it from
338 other files. When you write a program, you should write a makefile for it, so
339 that it is possible to use Make to build and install the program.")
341 (home-page "http://www.gnu.org/software/make/")))
343 (define-public binutils
349 (uri (string-append "mirror://gnu/binutils/binutils-"
353 "1a9w66v5dwvbnawshjwqcgz7km6kw6ihkzp6sswv9ycc3knzhykc"))))
354 (build-system gnu-build-system)
356 ;; TODO: Add dependency on zlib + those for Gold.
358 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
360 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
361 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
362 ;; on GCC when bootstrapping.
363 "LDFLAGS=-static-libgcc"
365 ;; Don't search under /usr/lib & co.
366 "--with-lib-path=/no-ld-lib-path")))
368 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
371 "The GNU Binutils are a collection of binary tools. The main ones are
372 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
373 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
375 (home-page "http://www.gnu.org/software/binutils/")))
377 (define-public gcc-4.7
378 (let ((stripped? #t)) ; TODO: make this a parameter
384 (uri (string-append "mirror://gnu/gcc/gcc-"
385 version "/gcc-" version ".tar.bz2"))
388 "115h03hil99ljig8lkrq4qk426awmzh0g99wrrggxf8g07bq74la"))))
389 (build-system gnu-build-system)
390 (inputs `(("gmp" ,gmp)
392 ("mpc" ,mpc))) ; TODO: libelf, ppl, cloog, zlib, etc.
395 `(#:out-of-source? #t
396 #:strip-binaries? ,stripped?
399 "--enable-languages=c,c++"
402 "--with-local-prefix=/no-gcc-local-prefix"
404 ,(let ((libc (assoc-ref %build-inputs "libc")))
406 (string-append "--with-native-system-header-dir=" libc
408 "--without-headers")))
410 (let ((libc (assoc-ref %build-inputs "libc")))
412 (list (string-append "LDFLAGS_FOR_BUILD="
414 "-Wl,-dynamic-linker "
416 ,(glibc-dynamic-linker system)))
418 ,(string-append "BOOT_CFLAGS=-O2 "
419 ,(if stripped? "-g0" "-g"))))
424 'configure 'pre-configure
425 (lambda* (#:key inputs outputs #:allow-other-keys)
426 (let ((out (assoc-ref outputs "out"))
427 (libc (assoc-ref inputs "libc")))
429 ;; The following is not performed for `--without-headers'
430 ;; cross-compiler builds.
432 ;; Fix the dynamic linker's file name.
433 (substitute* (find-files "gcc/config"
434 "^linux(64|-elf)?\\.h$")
435 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
436 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
438 (string-append libc ,(glibc-dynamic-linker system)))))
440 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
441 ;; `crt{begin,end}.o', which come with GCC.
442 (substitute* (find-files "gcc/config"
443 "^(gnu-user(64)?|linux-elf)\\.h$")
444 (("#define LIB_SPEC (.*)$" _ suffix)
445 ;; Note that with this "lib" spec, we may still add a
446 ;; RUNPATH to GCC even when `libgcc_s' is not NEEDED.
447 ;; There's not much that can be done to avoid it, though.
448 (format #f "#define LIB_SPEC \"-L~a/lib %{!static:-rpath=~a/lib \
449 %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib}} \" ~a~%"
450 libc libc out out suffix))
451 (("#define STARTFILE_SPEC.*$" line)
452 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
453 #define STANDARD_STARTFILE_PREFIX_2 \"\"
457 ;; Don't retain a dependency on the build-time sed.
458 (substitute* "fixincludes/fixincl.x"
459 (("static char const sed_cmd_z\\[\\] =.*;")
460 "static char const sed_cmd_z[] = \"sed\";"))))
463 'configure 'post-configure
465 ;; Don't store configure flags, to avoid retaining references to
466 ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
467 (substitute* "Makefile"
468 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
469 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
470 (alist-replace 'install
471 (lambda* (#:key outputs #:allow-other-keys)
477 %standard-phases))))))
479 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
480 (synopsis "The GNU Compiler Collection")
482 "The GNU Compiler Collection includes compiler front ends for C, C++,
483 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well as
484 libraries for these languages (libstdc++, libgcj, libgomp,...).
486 GCC development is a part of the GNU Project, aiming to improve the compiler
487 used in the GNU system including the GNU/Linux variant.")
489 (home-page "http://gcc.gnu.org/"))))
497 (uri (string-append "mirror://gnu/glibc/glibc-"
501 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
502 (build-system gnu-build-system)
504 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
505 ;; users should automatically pull Linux headers as well.
506 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
509 `(#:out-of-source? #t
510 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
512 (list "--enable-add-ons"
514 "--localedir=/var/run/current-system/sw/lib/locale" ; XXX
515 (string-append "--with-headers="
516 (assoc-ref %build-inputs "linux-headers")
519 ;; The default is to assume a 2.4 Linux interface, but we'll
520 ;; always use something newer. See "kernel-features.h" in the
521 ;; GNU libc for details.
522 "--enable-kernel=2.6.30"
524 ;; Use our Bash instead of /bin/sh.
525 (string-append "BASH_SHELL="
526 (assoc-ref %build-inputs "bash")
529 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
533 #:phases (alist-cons-before
534 'configure 'pre-configure
535 (lambda* (#:key inputs outputs #:allow-other-keys)
536 (let* ((out (assoc-ref outputs "out"))
537 (bin (string-append out "/bin")))
538 ;; Use `pwd', not `/bin/pwd'.
539 (substitute* "configure"
540 (("/bin/pwd") "pwd"))
542 ;; Install the rpc data base file under `$out/etc/rpc'.
543 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
544 (substitute* "sunrpc/Makefile"
545 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
546 (string-append out "/etc/rpc" suffix "\n"))
547 (("^install-others =.*$")
548 (string-append "install-others = " out "/etc/rpc\n")))
550 (substitute* "Makeconfig"
552 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
553 ;; linking against libgcc_s is not needed with GCC
557 ;; Copy a statically-linked Bash in the output, with
558 ;; no references to other store paths.
560 (copy-file (string-append (assoc-ref inputs "static-bash")
562 (string-append bin "/bash"))
563 (remove-store-references (string-append bin "/bash"))
564 (chmod (string-append bin "/bash") #o555)
566 ;; Keep a symlink, for `patch-shebang' resolution.
567 (with-directory-excursion bin
568 (symlink "bash" "sh"))
570 ;; Have `system' use that Bash.
571 (substitute* "sysdeps/posix/system.c"
572 (("#define[[:blank:]]+SHELL_PATH.*$")
573 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
577 (substitute* "libio/iopopen.c"
579 (string-append out "/bin/bash")))))
581 (inputs `(("patch/ld.so.cache"
582 ,(search-patch "glibc-no-ld-so-cache.patch"))
583 ("static-bash" ,(static-package bash-light))))
584 (synopsis "The GNU C Library")
586 "Any Unix-like operating system needs a C library: the library which
587 defines the \"system calls\" and other basic facilities such as open, malloc,
590 The GNU C library is used as the C library in the GNU system and most systems
591 with the Linux kernel.")
593 (home-page "http://www.gnu.org/software/libc/")))
597 ;;; Bootstrap packages.
600 (define gnu-make-boot0
601 (package-with-bootstrap-guile
602 (package (inherit gnu-make)
604 (location (source-properties->location (current-source-location)))
606 `(#:guile ,%bootstrap-guile
607 #:implicit-inputs? #f
608 #:tests? #f ; cannot run "make check"
609 ,@(substitute-keyword-arguments (package-arguments gnu-make)
613 (zero? (system* "./build.sh")))
615 'install (lambda* (#:key outputs #:allow-other-keys)
616 (let* ((out (assoc-ref outputs "out"))
617 (bin (string-append out "/bin")))
620 (string-append bin "/make"))))
622 (inputs %bootstrap-inputs))))
624 (define diffutils-boot0
625 (package-with-bootstrap-guile
626 (let ((p (package-with-explicit-inputs diffutils
627 `(("make" ,gnu-make-boot0)
629 #:guile %bootstrap-guile)))
631 (location (source-properties->location (current-source-location)))
632 (arguments `(#:tests? #f ; the test suite needs diffutils
633 ,@(package-arguments p)))))))
635 (define findutils-boot0
636 (package-with-bootstrap-guile
637 (package-with-explicit-inputs findutils
638 `(("make" ,gnu-make-boot0)
639 ("diffutils" ,diffutils-boot0) ; for tests
641 (current-source-location)
642 #:guile %bootstrap-guile)))
645 (define %boot0-inputs
646 `(("make" ,gnu-make-boot0)
647 ("diffutils" ,diffutils-boot0)
648 ("findutils" ,findutils-boot0)
649 ,@%bootstrap-inputs))
651 (define* (nix-system->gnu-triplet system #:optional (vendor "unknown"))
652 "Return an a guess of the GNU triplet corresponding to Nix system
654 (let* ((dash (string-index system #\-))
655 (arch (substring system 0 dash))
656 (os (substring system (+ 1 dash))))
659 (if (string=? os "linux")
664 ;; Return the triplet used to create the cross toolchain needed in the
665 ;; first bootstrapping stage.
666 (cut nix-system->gnu-triplet <> "guix"))
668 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
669 ;; toolchain actually targets the same OS and arch, but it has the advantage
670 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
671 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
673 (define binutils-boot0
674 (package-with-bootstrap-guile
675 (package (inherit binutils)
676 (name "binutils-cross-boot0")
679 `(#:guile ,%bootstrap-guile
680 #:implicit-inputs? #f
681 ,@(substitute-keyword-arguments (package-arguments binutils)
682 ((#:configure-flags cf)
683 `(list ,(string-append "--target=" (boot-triplet system))))))))
684 (inputs %boot0-inputs))))
687 (package-with-bootstrap-guile
688 (package (inherit gcc-4.7)
689 (name "gcc-cross-boot0")
692 `(#:guile ,%bootstrap-guile
693 #:implicit-inputs? #f
694 #:modules ((guix build gnu-build-system)
699 ,@(substitute-keyword-arguments ((package-arguments gcc-4.7) system)
700 ((#:configure-flags flags)
701 `(append (list ,(string-append "--target="
702 (boot-triplet system))
707 ;; Disable features not needed at this stage.
709 "--enable-languages=c"
710 "--disable-libmudflap"
713 "--disable-libquadmath"
714 "--disable-decimal-float")
715 (remove (cut string-match "--enable-languages.*" <>)
719 'unpack 'unpack-gmp&co
720 (lambda* (#:key inputs #:allow-other-keys)
721 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
722 (mpfr (assoc-ref %build-inputs "mpfr-source"))
723 (mpc (assoc-ref %build-inputs "mpc-source")))
725 ;; To reduce the set of pre-built bootstrap inputs, build
726 ;; GMP & co. from GCC.
727 (for-each (lambda (source)
728 (or (zero? (system* "tar" "xvf" source))
729 (error "failed to unpack tarball"
733 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
735 `(symlink ,(package-full-name lib)
736 ,(package-name lib)))
739 ;; MPFR headers/lib are found under $(MPFR)/src, but
740 ;; `configure' wrongfully tells MPC too look under
741 ;; $(MPFR), so fix that.
742 (substitute* "configure"
743 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
744 _ equals include middle lib)
745 (string-append "extra_mpc_mpfr_configure_flags" equals
746 "--with-mpfr-include=" include
748 "--with-mpfr-lib=" lib
750 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
751 (string-append "gmpinc='-I" a "/mpfr/src "
753 (("gmplibs='-L([^ ]+)/mpfr" _ a)
754 (string-append "gmplibs='-L" a "/mpfr/src")))))
756 'install 'symlink-libgcc_eh
757 (lambda* (#:key outputs #:allow-other-keys)
758 (let ((out (assoc-ref outputs "out")))
759 ;; Glibc wants to link against libgcc_eh, so provide
761 (with-directory-excursion
762 (string-append out "/lib/gcc/"
763 ,(boot-triplet system)
764 "/" ,(package-version gcc-4.7))
765 (symlink "libgcc.a" "libgcc_eh.a"))))
768 (inputs `(("gmp-source" ,(package-source gmp))
769 ("mpfr-source" ,(package-source mpfr))
770 ("mpc-source" ,(package-source mpc))
771 ("binutils-cross" ,binutils-boot0)
773 ;; Call it differently so that the builder can check whether
774 ;; the "libc" input is #f.
775 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
776 ,@(alist-delete "libc" %boot0-inputs))))))
778 (define linux-libre-headers-boot0
779 (package-with-bootstrap-guile
780 (package (inherit linux-libre-headers)
781 (arguments `(#:guile ,%bootstrap-guile
782 #:implicit-inputs? #f
783 ,@(package-arguments linux-libre-headers)))
785 (let ((perl (package-with-explicit-inputs perl
787 (current-source-location)
788 #:guile %bootstrap-guile)))
790 ,@%boot0-inputs))))))
792 (define %boot1-inputs
795 ("binutils-cross" ,binutils-boot0)
797 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
801 (define glibc-final-with-bootstrap-bash
802 ;; The final libc, "cross-built". If everything went well, the resulting
803 ;; store path has no dependencies. Actually, the really-final libc is
804 ;; built just below; the only difference is that this one uses the
806 (package-with-bootstrap-guile
807 (package (inherit glibc)
808 (name "glibc-intermediate")
811 `(#:guile ,%bootstrap-guile
812 #:implicit-inputs? #f
814 ,@(substitute-keyword-arguments (package-arguments glibc)
815 ((#:configure-flags flags)
816 `(append (list ,(string-append "--host=" (boot-triplet system))
817 ,(string-append "--build="
818 (nix-system->gnu-triplet system))
820 ;; Build Sun/ONC RPC support. In particular,
822 "--enable-obsolete-rpc")
824 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
826 `( ;; A native GCC is needed to build `cross-rpcgen'.
827 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
829 ;; Here, we use the bootstrap Bash, which is not satisfactory
830 ;; because we don't want to depend on bootstrap tools.
831 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
834 ,@(alist-delete "static-bash"
835 (package-inputs glibc))))))) ; patches
837 (define (cross-gcc-wrapper gcc binutils glibc bash)
838 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
839 that makes it available under the native tool names."
840 (package (inherit gcc-4.7)
841 (name (string-append (package-name gcc) "-wrapped"))
843 (build-system trivial-build-system)
846 `(#:guile ,%bootstrap-guile
847 #:modules ((guix build utils))
849 (use-modules (guix build utils))
851 (let* ((binutils (assoc-ref %build-inputs "binutils"))
852 (gcc (assoc-ref %build-inputs "gcc"))
853 (libc (assoc-ref %build-inputs "libc"))
854 (bash (assoc-ref %build-inputs "bash"))
855 (out (assoc-ref %outputs "out"))
856 (bindir (string-append out "/bin"))
857 (triplet ,(boot-triplet system)))
859 (with-directory-excursion bindir
860 (for-each (lambda (tool)
861 (symlink (string-append binutils "/bin/"
866 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
867 ;; needs to be told where to find the crt files and
868 ;; the dynamic linker.
869 (call-with-output-file "gcc"
871 (format p "#!~a/bin/bash
872 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
876 ,(glibc-dynamic-linker system))))
878 (chmod "gcc" #o555)))))))
880 `(("binutils" ,binutils)
886 (define static-bash-for-glibc
887 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
889 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
890 glibc-final-with-bootstrap-bash
891 (car (assoc-ref %boot1-inputs "bash"))))
892 (bash (package (inherit bash-light)
895 `(#:guile ,%bootstrap-guile
896 ,@(package-arguments bash-light)))))))
897 (package-with-bootstrap-guile
898 (package-with-explicit-inputs (static-package bash)
900 ("libc" ,glibc-final-with-bootstrap-bash)
901 ,@(fold alist-delete %boot1-inputs
903 (current-source-location)))))
905 (define-public glibc-final
906 ;; The final glibc, which embeds the statically-linked Bash built above.
907 (package (inherit glibc-final-with-bootstrap-bash)
909 (inputs `(("static-bash" ,static-bash-for-glibc)
912 (package-inputs glibc-final-with-bootstrap-bash))))))
914 (define gcc-boot0-wrapped
915 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
917 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
918 (car (assoc-ref %boot1-inputs "bash"))))
920 (define %boot2-inputs
922 `(("libc" ,glibc-final)
923 ("gcc" ,gcc-boot0-wrapped)
924 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
926 (define-public binutils-final
927 (package-with-bootstrap-guile
928 (package (inherit binutils)
931 `(#:guile ,%bootstrap-guile
932 #:implicit-inputs? #f
933 ,@(package-arguments binutils))))
934 (inputs %boot2-inputs))))
936 (define-public gcc-final
938 (package (inherit gcc-boot0)
942 `(#:guile ,%bootstrap-guile
943 #:implicit-inputs? #f
945 ;; Build again GMP & co. within GCC's build process, because it's hard
946 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
947 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
948 ,@(substitute-keyword-arguments ((package-arguments gcc-boot0) system)
949 ((#:configure-flags boot-flags)
950 (let loop ((args ((package-arguments gcc-4.7) system)))
952 ((#:configure-flags normal-flags _ ...)
957 `(alist-delete 'symlink-libgcc_eh ,phases))))))
959 (inputs `(("gmp-source" ,(package-source gmp))
960 ("mpfr-source" ,(package-source mpfr))
961 ("mpc-source" ,(package-source mpc))
962 ("binutils" ,binutils-final)
965 (define ld-wrapper-boot3
966 ;; A linker wrapper that uses the bootstrap Guile.
968 (name "ld-wrapper-boot3")
971 (build-system trivial-build-system)
972 (inputs `(("binutils" ,binutils-final)
973 ("guile" ,%bootstrap-guile)
974 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
975 ("wrapper" ,(search-path %load-path
976 "distro/packages/ld-wrapper.scm"))))
978 `(#:guile ,%bootstrap-guile
979 #:modules ((guix build utils))
981 (use-modules (guix build utils)
982 (system base compile))
984 (let* ((out (assoc-ref %outputs "out"))
985 (bin (string-append out "/bin"))
986 (ld (string-append bin "/ld"))
987 (go (string-append bin "/ld.go")))
989 (setvbuf (current-output-port) _IOLBF)
990 (format #t "building ~s/bin/ld wrapper in ~s~%"
991 (assoc-ref %build-inputs "binutils")
995 (copy-file (assoc-ref %build-inputs "wrapper") ld)
998 (string-append (assoc-ref %build-inputs "guile")
1001 (string-append (assoc-ref %build-inputs "bash")
1004 (string-append (assoc-ref %build-inputs "binutils")
1007 (compile-file ld #:output-file go)))))
1008 (synopsis "The linker wrapper")
1010 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1011 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1016 (define %boot3-inputs
1017 ;; 4th stage inputs.
1018 `(("gcc" ,gcc-final)
1019 ("ld-wrapper" ,ld-wrapper-boot3)
1020 ,@(alist-delete "gcc" %boot2-inputs)))
1022 (define-public bash-final
1023 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1024 ;; to the bootstrap GCC.
1025 (package-with-bootstrap-guile
1026 (package-with-explicit-inputs (static-libgcc-package bash)
1028 (current-source-location)
1029 #:guile %bootstrap-guile)))
1031 (define %boot4-inputs
1032 ;; Now use the final Bash.
1033 `(("bash" ,bash-final)
1034 ,@(alist-delete "bash" %boot3-inputs)))
1036 (define-public guile-final
1037 (package-with-bootstrap-guile
1038 (package-with-explicit-inputs guile-2.0/fixed
1040 (current-source-location)
1041 #:guile %bootstrap-guile)))
1043 (define-public ld-wrapper
1044 ;; The final `ld' wrapper, which uses the final Guile.
1045 (package (inherit ld-wrapper-boot3)
1047 (inputs `(("guile" ,guile-final)
1048 ("bash" ,bash-final)
1049 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1050 '("guile" "bash"))))))
1052 (define-public %final-inputs
1053 ;; Final derivations used as implicit inputs by `gnu-build-system'.
1054 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
1055 (current-source-location))))
1056 `(,@(map (match-lambda
1058 (list name (finalize package))))
1063 ("diffutils" ,diffutils)
1065 ("coreutils" ,coreutils)
1068 ("findutils" ,findutils)
1070 ("make" ,gnu-make)))
1071 ("bash" ,bash-final)
1072 ("ld-wrapper" ,ld-wrapper)
1073 ("binutils" ,binutils-final)
1075 ("libc" ,glibc-final))))
1077 ;;; base.scm ends here