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 gcc)
28 #:use-module (gnu packages gawk)
29 #:use-module (gnu packages guile)
30 #:use-module (gnu packages multiprecision)
31 #:use-module (gnu packages perl)
32 #:use-module (gnu packages linux)
33 #:use-module (guix packages)
34 #:use-module (guix download)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system trivial)
37 #:use-module (guix utils)
38 #:use-module (srfi srfi-1)
39 #:use-module (srfi srfi-26)
40 #:use-module (ice-9 match))
44 ;;; Base packages of the Guix-based GNU user-land software distribution.
54 (uri (string-append "mirror://gnu/hello/hello-" version
57 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
58 (build-system gnu-build-system)
59 (arguments '(#:configure-flags
60 `("--disable-dependency-tracking"
61 ,(string-append "--with-gawk=" ; for illustration purposes
62 (assoc-ref %build-inputs "gawk")))))
63 (inputs `(("gawk" ,gawk)))
64 (synopsis "GNU Hello")
65 (description "Yeah...")
66 (home-page "http://www.gnu.org/software/hello/")
75 (uri (string-append "mirror://gnu/grep/grep-"
79 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
80 (build-system gnu-build-system)
81 (synopsis "GNU implementation of the Unix grep command")
83 "The grep command searches one or more input files for lines containing a
84 match to a specified pattern. By default, grep prints the matching
87 (home-page "http://www.gnu.org/software/grep/")))
95 (uri (string-append "mirror://gnu/sed/sed-" version
99 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
100 (build-system gnu-build-system)
101 (synopsis "GNU sed, a batch stream editor")
103 `(#:phases (alist-cons-before
104 'patch-source-shebangs 'patch-test-suite
105 (lambda* (#:key inputs #:allow-other-keys)
106 (let ((bash (assoc-ref inputs "bash")))
107 (patch-makefile-SHELL "testsuite/Makefile.tests")
108 (substitute* '("testsuite/bsd.sh"
109 "testsuite/bug-regex9.c")
111 (string-append bash "/bin/bash")))))
114 "Sed (stream editor) isn't really a true text editor or text processor.
115 Instead, it is used to filter text, i.e., it takes text input and performs
116 some operation (or set of operations) on it and outputs the modified text.
117 Sed is typically used for extracting part of a file using pattern matching or
118 substituting multiple occurrences of a string within a file.")
120 (home-page "http://www.gnu.org/software/sed/")))
128 (uri (string-append "mirror://gnu/tar/tar-"
132 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
133 (build-system gnu-build-system)
134 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
136 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
137 (synopsis "GNU implementation of the `tar' archiver")
139 "The Tar program provides the ability to create tar archives, as well as
140 various other kinds of manipulation. For example, you can use Tar on
141 previously created archives to extract files, to store additional files, or
142 to update or list files which were already stored.
144 Initially, tar archives were used to store files conveniently on magnetic
145 tape. The name \"Tar\" comes from this use; it stands for tape archiver.
146 Despite the utility's name, Tar can direct its output to available devices,
147 files, or other programs (using pipes), it can even access remote devices or
148 files (as archives).")
150 (home-page "http://www.gnu.org/software/tar/")))
158 (uri (string-append "mirror://gnu/patch/patch-"
162 "18012gxs9wc96izskp1q7bclrwns6rdmkn4jj31c8jbyfz6l5npq"))))
163 (build-system gnu-build-system)
164 (native-inputs '()) ; FIXME: needs `ed' for the tests
167 ;; TODO: When cross-compiling, add this:
168 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
170 (synopsis "GNU Patch, a program to apply differences to files")
172 "GNU Patch takes a patch file containing a difference listing produced by
173 the diff program and applies those differences to one or more original files,
174 producing patched versions.")
176 (home-page "http://savannah.gnu.org/projects/patch/")))
178 (define-public diffutils
184 (uri (string-append "mirror://gnu/diffutils/diffutils-"
188 "0jci0wv68025xd0s0rq4s5qxpx56dd9d730lka63qpzk1rfvfkxb"))))
189 (build-system gnu-build-system)
190 (inputs `(("patch/gets"
191 ,(search-patch "diffutils-gets-undeclared.patch"))))
192 (arguments `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
193 (synopsis "Programs to find differences among text 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 ;; TODO: Work around cross-compilation failure.
242 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
243 ;; `(#:configure-flags '("gl_cv_func_wcwidth_works=yes")
244 ;; ,@(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 "064f512185iysqqcvhnhaf3bfmzrvcgs7n405qsyp99zmfyl9amd"))))
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 "06bs5v5ndb4g5qx96d52lc818gkbskd1m0sz57314v887sqfbcia"))))
354 (build-system gnu-build-system)
356 ;; Split Binutils in several outputs, mostly to avoid collisions in
357 ;; user profiles with GCC---e.g., libiberty.a.
358 (outputs '("out" ; ar, ld, binutils.info, etc.
359 "lib")) ; libbfd.a, bfd.h, etc.
361 ;; TODO: Add dependency on zlib + those for Gold.
363 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
365 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
366 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
367 ;; on GCC when bootstrapping.
368 "LDFLAGS=-static-libgcc"
370 ;; Don't search under /usr/lib & co.
371 "--with-lib-path=/no-ld-lib-path"
373 ;; Glibc 2.17 has a "comparison of unsigned
374 ;; expression >= 0 is always true" in wchar.h.
375 "--disable-werror")))
377 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
380 "The GNU Binutils are a collection of binary tools. The main ones are
381 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
382 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
384 (home-page "http://www.gnu.org/software/binutils/")))
392 (uri (string-append "mirror://gnu/glibc/glibc-"
396 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
397 (build-system gnu-build-system)
399 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
400 ;; users should automatically pull Linux headers as well.
401 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
403 ;; Store the locales separately (~100 MiB). Note that "out" retains a
404 ;; reference to them anyway, so there's no space savings here.
405 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
407 (outputs '("out" "locales"))
410 `(#:out-of-source? #t
411 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
413 (list "--enable-add-ons"
415 (string-append "--localedir=" (assoc-ref %outputs "locales")
418 ;; `--localedir' is not honored, so work around it.
419 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
420 (string-append "libc_cv_localedir="
421 (assoc-ref %outputs "locales")
425 (string-append "--with-headers="
426 (assoc-ref %build-inputs "linux-headers")
429 ;; The default is to assume a 2.4 Linux interface, but we'll
430 ;; always use something newer. See "kernel-features.h" in the
431 ;; GNU libc for details.
432 "--enable-kernel=2.6.30"
434 ;; Use our Bash instead of /bin/sh.
435 (string-append "BASH_SHELL="
436 (assoc-ref %build-inputs "bash")
439 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
443 #:phases (alist-cons-before
444 'configure 'pre-configure
445 (lambda* (#:key inputs outputs #:allow-other-keys)
446 (let* ((out (assoc-ref outputs "out"))
447 (bin (string-append out "/bin")))
448 ;; Use `pwd', not `/bin/pwd'.
449 (substitute* "configure"
450 (("/bin/pwd") "pwd"))
452 ;; Install the rpc data base file under `$out/etc/rpc'.
453 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
454 (substitute* "sunrpc/Makefile"
455 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
456 (string-append out "/etc/rpc" suffix "\n"))
457 (("^install-others =.*$")
458 (string-append "install-others = " out "/etc/rpc\n")))
460 (substitute* "Makeconfig"
462 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
463 ;; linking against libgcc_s is not needed with GCC
467 ;; Copy a statically-linked Bash in the output, with
468 ;; no references to other store paths.
470 (copy-file (string-append (assoc-ref inputs "static-bash")
472 (string-append bin "/bash"))
473 (remove-store-references (string-append bin "/bash"))
474 (chmod (string-append bin "/bash") #o555)
476 ;; Keep a symlink, for `patch-shebang' resolution.
477 (with-directory-excursion bin
478 (symlink "bash" "sh"))
480 ;; Have `system' use that Bash.
481 (substitute* "sysdeps/posix/system.c"
482 (("#define[[:blank:]]+SHELL_PATH.*$")
483 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
487 (substitute* "libio/iopopen.c"
489 (string-append out "/bin/bash")))))
491 'install 'install-locales
493 (zero? (system* "make" "localedata/install-locales")))
496 (inputs `(("patch/ld.so.cache"
497 ,(search-patch "glibc-no-ld-so-cache.patch"))
498 ("static-bash" ,(static-package bash-light))))
499 (synopsis "The GNU C Library")
501 "Any Unix-like operating system needs a C library: the library which
502 defines the \"system calls\" and other basic facilities such as open, malloc,
505 The GNU C library is used as the C library in the GNU system and most systems
506 with the Linux kernel.")
508 (home-page "http://www.gnu.org/software/libc/")))
512 ;;; Bootstrap packages.
515 (define gnu-make-boot0
516 (package-with-bootstrap-guile
517 (package (inherit gnu-make)
519 (location (source-properties->location (current-source-location)))
521 `(#:guile ,%bootstrap-guile
522 #:implicit-inputs? #f
523 #:tests? #f ; cannot run "make check"
524 ,@(substitute-keyword-arguments (package-arguments gnu-make)
528 (zero? (system* "./build.sh")))
530 'install (lambda* (#:key outputs #:allow-other-keys)
531 (let* ((out (assoc-ref outputs "out"))
532 (bin (string-append out "/bin")))
535 (string-append bin "/make"))))
537 (inputs %bootstrap-inputs))))
539 (define diffutils-boot0
540 (package-with-bootstrap-guile
541 (let ((p (package-with-explicit-inputs diffutils
542 `(("make" ,gnu-make-boot0)
544 #:guile %bootstrap-guile)))
546 (location (source-properties->location (current-source-location)))
547 (arguments `(#:tests? #f ; the test suite needs diffutils
548 ,@(package-arguments p)))))))
550 (define findutils-boot0
551 (package-with-bootstrap-guile
552 (package-with-explicit-inputs findutils
553 `(("make" ,gnu-make-boot0)
554 ("diffutils" ,diffutils-boot0) ; for tests
556 (current-source-location)
557 #:guile %bootstrap-guile)))
560 (define %boot0-inputs
561 `(("make" ,gnu-make-boot0)
562 ("diffutils" ,diffutils-boot0)
563 ("findutils" ,findutils-boot0)
564 ,@%bootstrap-inputs))
566 (define* (nix-system->gnu-triplet
567 #:optional (system (%current-system)) (vendor "unknown"))
568 "Return an a guess of the GNU triplet corresponding to Nix system
570 (let* ((dash (string-index system #\-))
571 (arch (substring system 0 dash))
572 (os (substring system (+ 1 dash))))
575 (if (string=? os "linux")
579 (define* (boot-triplet #:optional (system (%current-system)))
580 ;; Return the triplet used to create the cross toolchain needed in the
581 ;; first bootstrapping stage.
582 (nix-system->gnu-triplet system "guix"))
584 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
585 ;; toolchain actually targets the same OS and arch, but it has the advantage
586 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
587 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
589 (define binutils-boot0
590 (package-with-bootstrap-guile
591 (package (inherit binutils)
592 (name "binutils-cross-boot0")
594 `(#:guile ,%bootstrap-guile
595 #:implicit-inputs? #f
596 ,@(substitute-keyword-arguments (package-arguments binutils)
597 ((#:configure-flags cf)
598 `(cons ,(string-append "--target=" (boot-triplet))
600 (inputs %boot0-inputs))))
603 (package-with-bootstrap-guile
604 (package (inherit gcc-4.7)
605 (name "gcc-cross-boot0")
607 `(#:guile ,%bootstrap-guile
608 #:implicit-inputs? #f
609 #:modules ((guix build gnu-build-system)
614 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
615 ((#:configure-flags flags)
616 `(append (list ,(string-append "--target=" (boot-triplet))
621 ;; Disable features not needed at this stage.
623 "--enable-languages=c"
624 "--disable-libmudflap"
627 "--disable-libquadmath"
628 "--disable-decimal-float")
629 (remove (cut string-match "--enable-languages.*" <>)
633 'unpack 'unpack-gmp&co
634 (lambda* (#:key inputs #:allow-other-keys)
635 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
636 (mpfr (assoc-ref %build-inputs "mpfr-source"))
637 (mpc (assoc-ref %build-inputs "mpc-source")))
639 ;; To reduce the set of pre-built bootstrap inputs, build
640 ;; GMP & co. from GCC.
641 (for-each (lambda (source)
642 (or (zero? (system* "tar" "xvf" source))
643 (error "failed to unpack tarball"
647 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
649 `(symlink ,(package-full-name lib)
650 ,(package-name lib)))
653 ;; MPFR headers/lib are found under $(MPFR)/src, but
654 ;; `configure' wrongfully tells MPC too look under
655 ;; $(MPFR), so fix that.
656 (substitute* "configure"
657 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
658 _ equals include middle lib)
659 (string-append "extra_mpc_mpfr_configure_flags" equals
660 "--with-mpfr-include=" include
662 "--with-mpfr-lib=" lib
664 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
665 (string-append "gmpinc='-I" a "/mpfr/src "
667 (("gmplibs='-L([^ ]+)/mpfr" _ a)
668 (string-append "gmplibs='-L" a "/mpfr/src")))))
670 'install 'symlink-libgcc_eh
671 (lambda* (#:key outputs #:allow-other-keys)
672 (let ((out (assoc-ref outputs "out")))
673 ;; Glibc wants to link against libgcc_eh, so provide
675 (with-directory-excursion
676 (string-append out "/lib/gcc/"
678 "/" ,(package-version gcc-4.7))
679 (symlink "libgcc.a" "libgcc_eh.a"))))
682 (inputs `(("gmp-source" ,(package-source gmp))
683 ("mpfr-source" ,(package-source mpfr))
684 ("mpc-source" ,(package-source mpc))
685 ("binutils-cross" ,binutils-boot0)
687 ;; Call it differently so that the builder can check whether
688 ;; the "libc" input is #f.
689 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
690 ,@(alist-delete "libc" %boot0-inputs))))))
692 (define linux-libre-headers-boot0
693 (package-with-bootstrap-guile
694 (package (inherit linux-libre-headers)
695 (arguments `(#:guile ,%bootstrap-guile
696 #:implicit-inputs? #f
697 ,@(package-arguments linux-libre-headers)))
699 (let ((perl (package-with-explicit-inputs perl
701 (current-source-location)
702 #:guile %bootstrap-guile)))
704 ,@%boot0-inputs))))))
706 (define %boot1-inputs
709 ("binutils-cross" ,binutils-boot0)
711 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
715 (define glibc-final-with-bootstrap-bash
716 ;; The final libc, "cross-built". If everything went well, the resulting
717 ;; store path has no dependencies. Actually, the really-final libc is
718 ;; built just below; the only difference is that this one uses the
720 (package-with-bootstrap-guile
721 (package (inherit glibc)
722 (name "glibc-intermediate")
724 `(#:guile ,%bootstrap-guile
725 #:implicit-inputs? #f
727 ,@(substitute-keyword-arguments (package-arguments glibc)
728 ((#:configure-flags flags)
729 `(append (list ,(string-append "--host=" (boot-triplet))
730 ,(string-append "--build="
731 (nix-system->gnu-triplet))
733 ;; Build Sun/ONC RPC support. In particular,
735 "--enable-obsolete-rpc")
737 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
739 `( ;; A native GCC is needed to build `cross-rpcgen'.
740 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
742 ;; Here, we use the bootstrap Bash, which is not satisfactory
743 ;; because we don't want to depend on bootstrap tools.
744 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
747 ,@(alist-delete "static-bash"
748 (package-inputs glibc))))))) ; patches
750 (define (cross-gcc-wrapper gcc binutils glibc bash)
751 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
752 that makes it available under the native tool names."
753 (package (inherit gcc-4.7)
754 (name (string-append (package-name gcc) "-wrapped"))
756 (build-system trivial-build-system)
758 `(#:guile ,%bootstrap-guile
759 #:modules ((guix build utils))
761 (use-modules (guix build utils))
763 (let* ((binutils (assoc-ref %build-inputs "binutils"))
764 (gcc (assoc-ref %build-inputs "gcc"))
765 (libc (assoc-ref %build-inputs "libc"))
766 (bash (assoc-ref %build-inputs "bash"))
767 (out (assoc-ref %outputs "out"))
768 (bindir (string-append out "/bin"))
769 (triplet ,(boot-triplet)))
771 (with-directory-excursion bindir
772 (for-each (lambda (tool)
773 (symlink (string-append binutils "/bin/"
778 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
779 ;; needs to be told where to find the crt files and
780 ;; the dynamic linker.
781 (call-with-output-file "gcc"
783 (format p "#!~a/bin/bash
784 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
788 ,(glibc-dynamic-linker))))
790 (chmod "gcc" #o555))))))
792 `(("binutils" ,binutils)
798 (define static-bash-for-glibc
799 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
801 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
802 glibc-final-with-bootstrap-bash
803 (car (assoc-ref %boot1-inputs "bash"))))
804 (bash (package (inherit bash-light)
806 `(#:guile ,%bootstrap-guile
807 ,@(package-arguments bash-light))))))
808 (package-with-bootstrap-guile
809 (package-with-explicit-inputs (static-package bash)
811 ("libc" ,glibc-final-with-bootstrap-bash)
812 ,@(fold alist-delete %boot1-inputs
814 (current-source-location)))))
816 (define-public glibc-final
817 ;; The final glibc, which embeds the statically-linked Bash built above.
818 (package (inherit glibc-final-with-bootstrap-bash)
820 (inputs `(("static-bash" ,static-bash-for-glibc)
823 (package-inputs glibc-final-with-bootstrap-bash))))))
825 (define gcc-boot0-wrapped
826 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
828 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
829 (car (assoc-ref %boot1-inputs "bash"))))
831 (define %boot2-inputs
833 `(("libc" ,glibc-final)
834 ("gcc" ,gcc-boot0-wrapped)
835 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
837 (define-public binutils-final
838 (package-with-bootstrap-guile
839 (package (inherit binutils)
841 `(#:guile ,%bootstrap-guile
842 #:implicit-inputs? #f
843 ,@(package-arguments binutils)))
844 (inputs %boot2-inputs))))
846 (define-public gcc-final
848 (package (inherit gcc-boot0)
851 `(#:guile ,%bootstrap-guile
852 #:implicit-inputs? #f
854 ;; Build again GMP & co. within GCC's build process, because it's hard
855 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
856 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
857 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
858 ((#:configure-flags boot-flags)
859 (let loop ((args (package-arguments gcc-4.7)))
861 ((#:configure-flags normal-flags _ ...)
866 `(alist-delete 'symlink-libgcc_eh ,phases)))))
868 (inputs `(("gmp-source" ,(package-source gmp))
869 ("mpfr-source" ,(package-source mpfr))
870 ("mpc-source" ,(package-source mpc))
871 ("binutils" ,binutils-final)
874 (define ld-wrapper-boot3
875 ;; A linker wrapper that uses the bootstrap Guile.
877 (name "ld-wrapper-boot3")
880 (build-system trivial-build-system)
881 (inputs `(("binutils" ,binutils-final)
882 ("guile" ,%bootstrap-guile)
883 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
884 ("wrapper" ,(search-path %load-path
885 "gnu/packages/ld-wrapper.scm"))))
887 `(#:guile ,%bootstrap-guile
888 #:modules ((guix build utils))
890 (use-modules (guix build utils)
891 (system base compile))
893 (let* ((out (assoc-ref %outputs "out"))
894 (bin (string-append out "/bin"))
895 (ld (string-append bin "/ld"))
896 (go (string-append bin "/ld.go")))
898 (setvbuf (current-output-port) _IOLBF)
899 (format #t "building ~s/bin/ld wrapper in ~s~%"
900 (assoc-ref %build-inputs "binutils")
904 (copy-file (assoc-ref %build-inputs "wrapper") ld)
907 (string-append (assoc-ref %build-inputs "guile")
910 (string-append (assoc-ref %build-inputs "bash")
913 (string-append (assoc-ref %build-inputs "binutils")
916 (compile-file ld #:output-file go)))))
917 (synopsis "The linker wrapper")
919 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
920 missing `-rpath' flags, and to detect any misuse of libraries outside of the
925 (define %boot3-inputs
928 ("ld-wrapper" ,ld-wrapper-boot3)
929 ,@(alist-delete "gcc" %boot2-inputs)))
931 (define-public bash-final
932 ;; Link with `-static-libgcc' to make sure we don't retain a reference
933 ;; to the bootstrap GCC.
934 (package-with-bootstrap-guile
935 (package-with-explicit-inputs (static-libgcc-package bash)
937 (current-source-location)
938 #:guile %bootstrap-guile)))
940 (define %boot4-inputs
941 ;; Now use the final Bash.
942 `(("bash" ,bash-final)
943 ,@(alist-delete "bash" %boot3-inputs)))
945 (define-public guile-final
946 (package-with-bootstrap-guile
947 (package-with-explicit-inputs guile-2.0/fixed
949 (current-source-location)
950 #:guile %bootstrap-guile)))
952 (define-public ld-wrapper
953 ;; The final `ld' wrapper, which uses the final Guile.
954 (package (inherit ld-wrapper-boot3)
956 (inputs `(("guile" ,guile-final)
958 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
959 '("guile" "bash"))))))
961 (define-public %final-inputs
962 ;; Final derivations used as implicit inputs by `gnu-build-system'.
963 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
964 (current-source-location))))
965 `(,@(map (match-lambda
967 (list name (finalize package))))
972 ("diffutils" ,diffutils)
974 ("coreutils" ,coreutils)
977 ("findutils" ,findutils)
981 ("ld-wrapper" ,ld-wrapper)
982 ("binutils" ,binutils-final)
984 ("libc" ,glibc-final))))
986 ;;; base.scm ends here