Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / base.scm
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>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
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.
11 ;;;
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.
16 ;;;
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/>.
19
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))
41
42 ;;; Commentary:
43 ;;;
44 ;;; Base packages of the Guix-based GNU user-land software distribution.
45 ;;;
46 ;;; Code:
47
48 (define-public hello
49 (package
50 (name "hello")
51 (version "2.8")
52 (source (origin
53 (method url-fetch)
54 (uri (string-append "mirror://gnu/hello/hello-" version
55 ".tar.gz"))
56 (sha256
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/")
67 (license gpl3+)))
68
69 (define-public grep
70 (package
71 (name "grep")
72 (version "2.14")
73 (source (origin
74 (method url-fetch)
75 (uri (string-append "mirror://gnu/grep/grep-"
76 version ".tar.xz"))
77 (sha256
78 (base32
79 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
80 (build-system gnu-build-system)
81 (synopsis "GNU implementation of the Unix grep command")
82 (description
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
85 lines.")
86 (license gpl3+)
87 (home-page "http://www.gnu.org/software/grep/")))
88
89 (define-public sed
90 (package
91 (name "sed")
92 (version "4.2.2")
93 (source (origin
94 (method url-fetch)
95 (uri (string-append "mirror://gnu/sed/sed-" version
96 ".tar.bz2"))
97 (sha256
98 (base32
99 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
100 (build-system gnu-build-system)
101 (synopsis "GNU sed, a batch stream editor")
102 (arguments
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")
110 (("/bin/sh")
111 (string-append bash "/bin/bash")))))
112 %standard-phases)))
113 (description
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.")
119 (license gpl3+)
120 (home-page "http://www.gnu.org/software/sed/")))
121
122 (define-public tar
123 (package
124 (name "tar")
125 (version "1.26")
126 (source (origin
127 (method url-fetch)
128 (uri (string-append "mirror://gnu/tar/tar-"
129 version ".tar.bz2"))
130 (sha256
131 (base32
132 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
133 (build-system gnu-build-system)
134 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
135 (arguments
136 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
137 (synopsis "GNU implementation of the `tar' archiver")
138 (description
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.
143
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).")
149 (license gpl3+)
150 (home-page "http://www.gnu.org/software/tar/")))
151
152 (define-public patch
153 (package
154 (name "patch")
155 (version "2.6.1")
156 (source (origin
157 (method url-fetch)
158 (uri (string-append "mirror://gnu/patch/patch-"
159 version ".tar.xz"))
160 (sha256
161 (base32
162 "18012gxs9wc96izskp1q7bclrwns6rdmkn4jj31c8jbyfz6l5npq"))))
163 (build-system gnu-build-system)
164 (native-inputs '()) ; FIXME: needs `ed' for the tests
165 (arguments
166 '(#:tests? #f)
167 ;; TODO: When cross-compiling, add this:
168 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
169 )
170 (synopsis "GNU Patch, a program to apply differences to files")
171 (description
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.")
175 (license gpl3+)
176 (home-page "http://savannah.gnu.org/projects/patch/")))
177
178 (define-public diffutils
179 (package
180 (name "diffutils")
181 (version "3.2")
182 (source (origin
183 (method url-fetch)
184 (uri (string-append "mirror://gnu/diffutils/diffutils-"
185 version ".tar.xz"))
186 (sha256
187 (base32
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")
194 (description
195 "GNU Diffutils is a package of several programs related to finding
196 differences between files.
197
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.
201
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.
208
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.
212
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.
218
219 You can use the sdiff command to merge two files interactively.")
220 (license gpl3+)
221 (home-page "http://www.gnu.org/software/diffutils/")))
222
223 (define-public findutils
224 (package
225 (name "findutils")
226 (version "4.4.2")
227 (source (origin
228 (method url-fetch)
229 (uri (string-append "mirror://gnu/findutils/findutils-"
230 version ".tar.gz"))
231 (sha256
232 (base32
233 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))))
234 (build-system gnu-build-system)
235 (native-inputs
236 `(("patch/absolute-paths"
237 ,(search-patch "findutils-absolute-paths.patch"))))
238 (arguments
239 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths")))
240
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))
245 )
246 (synopsis "Basic directory searching utilities of the GNU operating
247 system")
248 (description
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.
253
254 The tools supplied with this package are:
255
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.
260 ")
261 (license gpl3+)
262 (home-page "http://www.gnu.org/software/findutils/")))
263
264 (define-public coreutils
265 (package
266 (name "coreutils")
267 (version "8.21")
268 (source (origin
269 (method url-fetch)
270 (uri (string-append "mirror://gnu/coreutils/coreutils-"
271 version ".tar.xz"))
272 (sha256
273 (base32
274 "064f512185iysqqcvhnhaf3bfmzrvcgs7n405qsyp99zmfyl9amd"))))
275 (build-system gnu-build-system)
276 (inputs `(("acl" ,acl)
277 ("gmp" ,gmp)
278 ("perl" ,perl))) ; TODO: add SELinux
279 (arguments
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"
287 "\\.c$"))
288 (("/bin/sh")
289 (format #f "~a/bin/sh" bash)))
290 (substitute* (find-files "tests" "\\.sh$")
291 (("#!/bin/sh")
292 (format #f "#!~a/bin/bash" bash)))))
293 %standard-phases)))
294 (synopsis
295 "The basic file, shell and text manipulation utilities of the GNU
296 operating system")
297 (description
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.")
301 (license gpl3+)
302 (home-page "http://www.gnu.org/software/coreutils/")))
303
304 (define-public gnu-make
305 (package
306 (name "make")
307 (version "3.82")
308 (source (origin
309 (method url-fetch)
310 (uri (string-append "mirror://gnu/make/make-" version
311 ".tar.bz2"))
312 (sha256
313 (base32
314 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
315 (build-system gnu-build-system)
316 (native-inputs
317 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
318 (arguments
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")))
325 (substitute* "job.c"
326 (("default_shell\\[\\] =.*$")
327 (format #f "default_shell[] = \"~a/bin/bash\";\n"
328 bash)))))
329 %standard-phases)))
330 (synopsis "GNU Make, a program controlling the generation of non-source
331 files from sources")
332 (description
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.
335
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.")
340 (license gpl3+)
341 (home-page "http://www.gnu.org/software/make/")))
342
343 (define-public binutils
344 (package
345 (name "binutils")
346 (version "2.23.1")
347 (source (origin
348 (method url-fetch)
349 (uri (string-append "mirror://gnu/binutils/binutils-"
350 version ".tar.bz2"))
351 (sha256
352 (base32
353 "06bs5v5ndb4g5qx96d52lc818gkbskd1m0sz57314v887sqfbcia"))))
354 (build-system gnu-build-system)
355
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.
360
361 ;; TODO: Add dependency on zlib + those for Gold.
362 (native-inputs
363 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
364 (arguments
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"
369
370 ;; Don't search under /usr/lib & co.
371 "--with-lib-path=/no-ld-lib-path"
372
373 ;; Glibc 2.17 has a "comparison of unsigned
374 ;; expression >= 0 is always true" in wchar.h.
375 "--disable-werror")))
376
377 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
378 assembler, etc.)")
379 (description
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.")
383 (license gpl3+)
384 (home-page "http://www.gnu.org/software/binutils/")))
385
386 (define-public glibc
387 (package
388 (name "glibc")
389 (version "2.17")
390 (source (origin
391 (method url-fetch)
392 (uri (string-append "mirror://gnu/glibc/glibc-"
393 version ".tar.xz"))
394 (sha256
395 (base32
396 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
397 (build-system gnu-build-system)
398
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)))
402
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
406 ;; Nixpkgs does.
407 (outputs '("out" "locales"))
408
409 (arguments
410 `(#:out-of-source? #t
411 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
412 #:configure-flags
413 (list "--enable-add-ons"
414 "--sysconfdir=/etc"
415 (string-append "--localedir=" (assoc-ref %outputs "locales")
416 "/share/locale")
417
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")
422 "/share/locale")
423
424
425 (string-append "--with-headers="
426 (assoc-ref %build-inputs "linux-headers")
427 "/include")
428
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"
433
434 ;; Use our Bash instead of /bin/sh.
435 (string-append "BASH_SHELL="
436 (assoc-ref %build-inputs "bash")
437 "/bin/bash")
438
439 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
440 "libc_cv_ssp=no")
441
442 #:tests? #f ; XXX
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"))
451
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")))
459
460 (substitute* "Makeconfig"
461 ;; According to
462 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
463 ;; linking against libgcc_s is not needed with GCC
464 ;; 4.7.1.
465 ((" -lgcc_s") ""))
466
467 ;; Copy a statically-linked Bash in the output, with
468 ;; no references to other store paths.
469 (mkdir-p bin)
470 (copy-file (string-append (assoc-ref inputs "static-bash")
471 "/bin/bash")
472 (string-append bin "/bash"))
473 (remove-store-references (string-append bin "/bash"))
474 (chmod (string-append bin "/bash") #o555)
475
476 ;; Keep a symlink, for `patch-shebang' resolution.
477 (with-directory-excursion bin
478 (symlink "bash" "sh"))
479
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"
484 out)))
485
486 ;; Same for `popen'.
487 (substitute* "libio/iopopen.c"
488 (("/bin/sh")
489 (string-append out "/bin/bash")))))
490 (alist-cons-after
491 'install 'install-locales
492 (lambda _
493 (zero? (system* "make" "localedata/install-locales")))
494 %standard-phases))))
495
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")
500 (description
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,
503 printf, exit...
504
505 The GNU C library is used as the C library in the GNU system and most systems
506 with the Linux kernel.")
507 (license lgpl2.0+)
508 (home-page "http://www.gnu.org/software/libc/")))
509
510 \f
511 ;;;
512 ;;; Bootstrap packages.
513 ;;;
514
515 (define gnu-make-boot0
516 (package-with-bootstrap-guile
517 (package (inherit gnu-make)
518 (name "make-boot0")
519 (location (source-properties->location (current-source-location)))
520 (arguments
521 `(#:guile ,%bootstrap-guile
522 #:implicit-inputs? #f
523 #:tests? #f ; cannot run "make check"
524 ,@(substitute-keyword-arguments (package-arguments gnu-make)
525 ((#:phases phases)
526 `(alist-replace
527 'build (lambda _
528 (zero? (system* "./build.sh")))
529 (alist-replace
530 'install (lambda* (#:key outputs #:allow-other-keys)
531 (let* ((out (assoc-ref outputs "out"))
532 (bin (string-append out "/bin")))
533 (mkdir-p bin)
534 (copy-file "make"
535 (string-append bin "/make"))))
536 ,phases))))))
537 (inputs %bootstrap-inputs))))
538
539 (define diffutils-boot0
540 (package-with-bootstrap-guile
541 (let ((p (package-with-explicit-inputs diffutils
542 `(("make" ,gnu-make-boot0)
543 ,@%bootstrap-inputs)
544 #:guile %bootstrap-guile)))
545 (package (inherit p)
546 (location (source-properties->location (current-source-location)))
547 (arguments `(#:tests? #f ; the test suite needs diffutils
548 ,@(package-arguments p)))))))
549
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
555 ,@%bootstrap-inputs)
556 (current-source-location)
557 #:guile %bootstrap-guile)))
558
559
560 (define %boot0-inputs
561 `(("make" ,gnu-make-boot0)
562 ("diffutils" ,diffutils-boot0)
563 ("findutils" ,findutils-boot0)
564 ,@%bootstrap-inputs))
565
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
569 identifier SYSTEM."
570 (let* ((dash (string-index system #\-))
571 (arch (substring system 0 dash))
572 (os (substring system (+ 1 dash))))
573 (string-append arch
574 "-" vendor "-"
575 (if (string=? os "linux")
576 "linux-gnu"
577 os))))
578
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"))
583
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.
588
589 (define binutils-boot0
590 (package-with-bootstrap-guile
591 (package (inherit binutils)
592 (name "binutils-cross-boot0")
593 (arguments
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))
599 ,cf)))))
600 (inputs %boot0-inputs))))
601
602 (define gcc-boot0
603 (package-with-bootstrap-guile
604 (package (inherit gcc-4.7)
605 (name "gcc-cross-boot0")
606 (arguments
607 `(#:guile ,%bootstrap-guile
608 #:implicit-inputs? #f
609 #:modules ((guix build gnu-build-system)
610 (guix build utils)
611 (ice-9 regex)
612 (srfi srfi-1)
613 (srfi srfi-26))
614 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
615 ((#:configure-flags flags)
616 `(append (list ,(string-append "--target=" (boot-triplet))
617
618 ;; No libc yet.
619 "--without-headers"
620
621 ;; Disable features not needed at this stage.
622 "--disable-shared"
623 "--enable-languages=c"
624 "--disable-libmudflap"
625 "--disable-libgomp"
626 "--disable-libssp"
627 "--disable-libquadmath"
628 "--disable-decimal-float")
629 (remove (cut string-match "--enable-languages.*" <>)
630 ,flags)))
631 ((#:phases phases)
632 `(alist-cons-after
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")))
638
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"
644 source)))
645 (list gmp mpfr mpc))
646
647 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
648 ,@(map (lambda (lib)
649 `(symlink ,(package-full-name lib)
650 ,(package-name lib)))
651 (list gmp mpfr mpc))
652
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
661 "/mpfr/src" middle
662 "--with-mpfr-lib=" lib
663 "/mpfr/src"))
664 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
665 (string-append "gmpinc='-I" a "/mpfr/src "
666 "-I" b "/mpfr/src"))
667 (("gmplibs='-L([^ ]+)/mpfr" _ a)
668 (string-append "gmplibs='-L" a "/mpfr/src")))))
669 (alist-cons-after
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
674 ;; it.
675 (with-directory-excursion
676 (string-append out "/lib/gcc/"
677 ,(boot-triplet)
678 "/" ,(package-version gcc-4.7))
679 (symlink "libgcc.a" "libgcc_eh.a"))))
680 ,phases))))))
681
682 (inputs `(("gmp-source" ,(package-source gmp))
683 ("mpfr-source" ,(package-source mpfr))
684 ("mpc-source" ,(package-source mpc))
685 ("binutils-cross" ,binutils-boot0)
686
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))))))
691
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)))
698 (native-inputs
699 (let ((perl (package-with-explicit-inputs perl
700 %boot0-inputs
701 (current-source-location)
702 #:guile %bootstrap-guile)))
703 `(("perl" ,perl)
704 ,@%boot0-inputs))))))
705
706 (define %boot1-inputs
707 ;; 2nd stage inputs.
708 `(("gcc" ,gcc-boot0)
709 ("binutils-cross" ,binutils-boot0)
710
711 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
712 ;; cross-`as'.
713 ,@%boot0-inputs))
714
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
719 ;; bootstrap Bash.
720 (package-with-bootstrap-guile
721 (package (inherit glibc)
722 (name "glibc-intermediate")
723 (arguments
724 `(#:guile ,%bootstrap-guile
725 #:implicit-inputs? #f
726
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))
732
733 ;; Build Sun/ONC RPC support. In particular,
734 ;; install rpc/*.h.
735 "--enable-obsolete-rpc")
736 ,flags)))))
737 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
738 (inputs
739 `( ;; A native GCC is needed to build `cross-rpcgen'.
740 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
741
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"))
745
746 ,@%boot1-inputs
747 ,@(alist-delete "static-bash"
748 (package-inputs glibc))))))) ; patches
749
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"))
755 (source #f)
756 (build-system trivial-build-system)
757 (arguments
758 `(#:guile ,%bootstrap-guile
759 #:modules ((guix build utils))
760 #:builder (begin
761 (use-modules (guix build utils))
762
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)))
770 (mkdir-p bindir)
771 (with-directory-excursion bindir
772 (for-each (lambda (tool)
773 (symlink (string-append binutils "/bin/"
774 triplet "-" tool)
775 tool))
776 '("ar" "ranlib"))
777
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"
782 (lambda (p)
783 (format p "#!~a/bin/bash
784 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
785 bash
786 gcc triplet
787 libc libc
788 ,(glibc-dynamic-linker))))
789
790 (chmod "gcc" #o555))))))
791 (native-inputs
792 `(("binutils" ,binutils)
793 ("gcc" ,gcc)
794 ("libc" ,glibc)
795 ("bash" ,bash)))
796 (inputs '())))
797
798 (define static-bash-for-glibc
799 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
800 ;; system(3) & co.
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)
805 (arguments
806 `(#:guile ,%bootstrap-guile
807 ,@(package-arguments bash-light))))))
808 (package-with-bootstrap-guile
809 (package-with-explicit-inputs (static-package bash)
810 `(("gcc" ,gcc)
811 ("libc" ,glibc-final-with-bootstrap-bash)
812 ,@(fold alist-delete %boot1-inputs
813 '("gcc" "libc")))
814 (current-source-location)))))
815
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)
819 (name "glibc")
820 (inputs `(("static-bash" ,static-bash-for-glibc)
821 ,@(alist-delete
822 "static-bash"
823 (package-inputs glibc-final-with-bootstrap-bash))))))
824
825 (define gcc-boot0-wrapped
826 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
827 ;; non-cross names.
828 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
829 (car (assoc-ref %boot1-inputs "bash"))))
830
831 (define %boot2-inputs
832 ;; 3rd stage inputs.
833 `(("libc" ,glibc-final)
834 ("gcc" ,gcc-boot0-wrapped)
835 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
836
837 (define-public binutils-final
838 (package-with-bootstrap-guile
839 (package (inherit binutils)
840 (arguments
841 `(#:guile ,%bootstrap-guile
842 #:implicit-inputs? #f
843 ,@(package-arguments binutils)))
844 (inputs %boot2-inputs))))
845
846 (define-public gcc-final
847 ;; The final GCC.
848 (package (inherit gcc-boot0)
849 (name "gcc")
850 (arguments
851 `(#:guile ,%bootstrap-guile
852 #:implicit-inputs? #f
853
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)))
860 (match args
861 ((#:configure-flags normal-flags _ ...)
862 normal-flags)
863 ((_ rest ...)
864 (loop rest)))))
865 ((#:phases phases)
866 `(alist-delete 'symlink-libgcc_eh ,phases)))))
867
868 (inputs `(("gmp-source" ,(package-source gmp))
869 ("mpfr-source" ,(package-source mpfr))
870 ("mpc-source" ,(package-source mpc))
871 ("binutils" ,binutils-final)
872 ,@%boot2-inputs))))
873
874 (define ld-wrapper-boot3
875 ;; A linker wrapper that uses the bootstrap Guile.
876 (package
877 (name "ld-wrapper-boot3")
878 (version "0")
879 (source #f)
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"))))
886 (arguments
887 `(#:guile ,%bootstrap-guile
888 #:modules ((guix build utils))
889 #:builder (begin
890 (use-modules (guix build utils)
891 (system base compile))
892
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")))
897
898 (setvbuf (current-output-port) _IOLBF)
899 (format #t "building ~s/bin/ld wrapper in ~s~%"
900 (assoc-ref %build-inputs "binutils")
901 out)
902
903 (mkdir-p bin)
904 (copy-file (assoc-ref %build-inputs "wrapper") ld)
905 (substitute* ld
906 (("@GUILE@")
907 (string-append (assoc-ref %build-inputs "guile")
908 "/bin/guile"))
909 (("@BASH@")
910 (string-append (assoc-ref %build-inputs "bash")
911 "/bin/bash"))
912 (("@LD@")
913 (string-append (assoc-ref %build-inputs "binutils")
914 "/bin/ld")))
915 (chmod ld #o555)
916 (compile-file ld #:output-file go)))))
917 (synopsis "The linker wrapper")
918 (description
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
921 store.")
922 (home-page #f)
923 (license gpl3+)))
924
925 (define %boot3-inputs
926 ;; 4th stage inputs.
927 `(("gcc" ,gcc-final)
928 ("ld-wrapper" ,ld-wrapper-boot3)
929 ,@(alist-delete "gcc" %boot2-inputs)))
930
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)
936 %boot3-inputs
937 (current-source-location)
938 #:guile %bootstrap-guile)))
939
940 (define %boot4-inputs
941 ;; Now use the final Bash.
942 `(("bash" ,bash-final)
943 ,@(alist-delete "bash" %boot3-inputs)))
944
945 (define-public guile-final
946 (package-with-bootstrap-guile
947 (package-with-explicit-inputs guile-2.0/fixed
948 %boot4-inputs
949 (current-source-location)
950 #:guile %bootstrap-guile)))
951
952 (define-public ld-wrapper
953 ;; The final `ld' wrapper, which uses the final Guile.
954 (package (inherit ld-wrapper-boot3)
955 (name "ld-wrapper")
956 (inputs `(("guile" ,guile-final)
957 ("bash" ,bash-final)
958 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
959 '("guile" "bash"))))))
960
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
966 ((name package)
967 (list name (finalize package))))
968 `(("tar" ,tar)
969 ("gzip" ,gzip)
970 ("bzip2" ,bzip2)
971 ("xz" ,xz)
972 ("diffutils" ,diffutils)
973 ("patch" ,patch)
974 ("coreutils" ,coreutils)
975 ("sed" ,sed)
976 ("grep" ,grep)
977 ("findutils" ,findutils)
978 ("gawk" ,gawk)
979 ("make" ,gnu-make)))
980 ("bash" ,bash-final)
981 ("ld-wrapper" ,ld-wrapper)
982 ("binutils" ,binutils-final)
983 ("gcc" ,gcc-final)
984 ("libc" ,glibc-final))))
985
986 ;;; base.scm ends here