gnu: coreutils, sed: Update.
[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 gawk)
28 #:use-module (gnu packages guile)
29 #:use-module (gnu packages multiprecision)
30 #:use-module (gnu packages perl)
31 #:use-module (gnu packages linux)
32 #:use-module (guix packages)
33 #:use-module (guix download)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system trivial)
36 #:use-module (guix utils)
37 #:use-module (srfi srfi-1)
38 #:use-module (srfi srfi-26)
39 #:use-module (ice-9 match))
40
41 ;;; Commentary:
42 ;;;
43 ;;; Base packages of the Guix-based GNU user-land software distribution.
44 ;;;
45 ;;; Code:
46
47 (define-public hello
48 (package
49 (name "hello")
50 (version "2.8")
51 (source (origin
52 (method url-fetch)
53 (uri (string-append "mirror://gnu/hello/hello-" version
54 ".tar.gz"))
55 (sha256
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/")
66 (license gpl3+)))
67
68 (define-public grep
69 (package
70 (name "grep")
71 (version "2.14")
72 (source (origin
73 (method url-fetch)
74 (uri (string-append "mirror://gnu/grep/grep-"
75 version ".tar.xz"))
76 (sha256
77 (base32
78 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
79 (build-system gnu-build-system)
80 (synopsis "GNU implementation of the Unix grep command")
81 (description
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
84 lines.")
85 (license gpl3+)
86 (home-page "http://www.gnu.org/software/grep/")))
87
88 (define-public sed
89 (package
90 (name "sed")
91 (version "4.2.2")
92 (source (origin
93 (method url-fetch)
94 (uri (string-append "mirror://gnu/sed/sed-" version
95 ".tar.bz2"))
96 (sha256
97 (base32
98 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
99 (build-system gnu-build-system)
100 (synopsis "GNU sed, a batch stream editor")
101 (arguments
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")
109 (("/bin/sh")
110 (string-append bash "/bin/bash")))))
111 %standard-phases)))
112 (description
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.")
118 (license gpl3+)
119 (home-page "http://www.gnu.org/software/sed/")))
120
121 (define-public tar
122 (package
123 (name "tar")
124 (version "1.26")
125 (source (origin
126 (method url-fetch)
127 (uri (string-append "mirror://gnu/tar/tar-"
128 version ".tar.bz2"))
129 (sha256
130 (base32
131 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
132 (build-system gnu-build-system)
133 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
134 (arguments
135 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
136 (synopsis "GNU implementation of the `tar' archiver")
137 (description
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.
142
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).")
148 (license gpl3+)
149 (home-page "http://www.gnu.org/software/tar/")))
150
151 (define-public patch
152 (package
153 (name "patch")
154 (version "2.6.1")
155 (source (origin
156 (method url-fetch)
157 (uri (string-append "mirror://gnu/patch/patch-"
158 version ".tar.xz"))
159 (sha256
160 (base32
161 "18012gxs9wc96izskp1q7bclrwns6rdmkn4jj31c8jbyfz6l5npq"))))
162 (build-system gnu-build-system)
163 (native-inputs '()) ; FIXME: needs `ed' for the tests
164 (arguments
165 '(#:tests? #f)
166 ;; TODO: When cross-compiling, add this:
167 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
168 )
169 (synopsis "GNU Patch, a program to apply differences to files")
170 (description
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.")
174 (license gpl3+)
175 (home-page "http://savannah.gnu.org/projects/patch/")))
176
177 (define-public diffutils
178 (package
179 (name "diffutils")
180 (version "3.2")
181 (source (origin
182 (method url-fetch)
183 (uri (string-append "mirror://gnu/diffutils/diffutils-"
184 version ".tar.xz"))
185 (sha256
186 (base32
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")
193 (description
194 "GNU Diffutils is a package of several programs related to finding
195 differences between files.
196
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.
200
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.
207
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.
211
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.
217
218 You can use the sdiff command to merge two files interactively.")
219 (license gpl3+)
220 (home-page "http://www.gnu.org/software/diffutils/")))
221
222 (define-public findutils
223 (package
224 (name "findutils")
225 (version "4.4.2")
226 (source (origin
227 (method url-fetch)
228 (uri (string-append "mirror://gnu/findutils/findutils-"
229 version ".tar.gz"))
230 (sha256
231 (base32
232 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))))
233 (build-system gnu-build-system)
234 (native-inputs
235 `(("patch/absolute-paths"
236 ,(search-patch "findutils-absolute-paths.patch"))))
237 (arguments
238 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths")))
239
240 ;; TODO: Work around cross-compilation failure.
241 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
242 ;; `(#:configure-flags '("gl_cv_func_wcwidth_works=yes")
243 ;; ,@(arguments cross-system))
244 )
245 (synopsis "Basic directory searching utilities of the GNU operating
246 system")
247 (description
248 "The GNU Find Utilities are the basic directory searching utilities of
249 the GNU operating system. These programs are typically used in conjunction
250 with other programs to provide modular and powerful directory search and file
251 locating capabilities to other commands.
252
253 The tools supplied with this package are:
254
255 * find - search for files in a directory hierarchy;
256 * locate - list files in databases that match a pattern;
257 * updatedb - update a file name database;
258 * xargs - build and execute command lines from standard input.
259 ")
260 (license gpl3+)
261 (home-page "http://www.gnu.org/software/findutils/")))
262
263 (define-public coreutils
264 (package
265 (name "coreutils")
266 (version "8.21")
267 (source (origin
268 (method url-fetch)
269 (uri (string-append "mirror://gnu/coreutils/coreutils-"
270 version ".tar.xz"))
271 (sha256
272 (base32
273 "064f512185iysqqcvhnhaf3bfmzrvcgs7n405qsyp99zmfyl9amd"))))
274 (build-system gnu-build-system)
275 (inputs `(("acl" ,acl)
276 ("gmp" ,gmp)
277 ("perl" ,perl))) ; TODO: add SELinux
278 (arguments
279 `(#:parallel-build? #f ; help2man may be called too early
280 #:phases (alist-cons-before
281 'build 'patch-shell-references
282 (lambda* (#:key inputs #:allow-other-keys)
283 (let ((bash (assoc-ref inputs "bash")))
284 (substitute* (cons "src/split.c"
285 (find-files "gnulib-tests"
286 "\\.c$"))
287 (("/bin/sh")
288 (format #f "~a/bin/sh" bash)))
289 (substitute* (find-files "tests" "\\.sh$")
290 (("#!/bin/sh")
291 (format #f "#!~a/bin/bash" bash)))))
292 %standard-phases)))
293 (synopsis
294 "The basic file, shell and text manipulation utilities of the GNU
295 operating system")
296 (description
297 "The GNU Core Utilities are the basic file, shell and text manipulation
298 utilities of the GNU operating system. These are the core utilities which
299 are expected to exist on every operating system.")
300 (license gpl3+)
301 (home-page "http://www.gnu.org/software/coreutils/")))
302
303 (define-public gnu-make
304 (package
305 (name "make")
306 (version "3.82")
307 (source (origin
308 (method url-fetch)
309 (uri (string-append "mirror://gnu/make/make-" version
310 ".tar.bz2"))
311 (sha256
312 (base32
313 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
314 (build-system gnu-build-system)
315 (native-inputs
316 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
317 (arguments
318 '(#:patches (list (assoc-ref %build-inputs "patch/impure-dirs"))
319 #:phases (alist-cons-before
320 'build 'set-default-shell
321 (lambda* (#:key inputs #:allow-other-keys)
322 ;; Change the default shell from /bin/sh.
323 (let ((bash (assoc-ref inputs "bash")))
324 (substitute* "job.c"
325 (("default_shell\\[\\] =.*$")
326 (format #f "default_shell[] = \"~a/bin/bash\";\n"
327 bash)))))
328 %standard-phases)))
329 (synopsis "GNU Make, a program controlling the generation of non-source
330 files from sources")
331 (description
332 "Make is a tool which controls the generation of executables and other
333 non-source files of a program from the program's source files.
334
335 Make gets its knowledge of how to build your program from a file called the
336 makefile, which lists each of the non-source files and how to compute it from
337 other files. When you write a program, you should write a makefile for it, so
338 that it is possible to use Make to build and install the program.")
339 (license gpl3+)
340 (home-page "http://www.gnu.org/software/make/")))
341
342 (define-public binutils
343 (package
344 (name "binutils")
345 (version "2.23.1")
346 (source (origin
347 (method url-fetch)
348 (uri (string-append "mirror://gnu/binutils/binutils-"
349 version ".tar.bz2"))
350 (sha256
351 (base32
352 "06bs5v5ndb4g5qx96d52lc818gkbskd1m0sz57314v887sqfbcia"))))
353 (build-system gnu-build-system)
354
355 ;; Split Binutils in several outputs, mostly to avoid collisions in
356 ;; user profiles with GCC---e.g., libiberty.a.
357 (outputs '("out" ; ar, ld, binutils.info, etc.
358 "lib")) ; libbfd.a, bfd.h, etc.
359
360 ;; TODO: Add dependency on zlib + those for Gold.
361 (native-inputs
362 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
363 (arguments
364 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
365 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
366 ;; on GCC when bootstrapping.
367 "LDFLAGS=-static-libgcc"
368
369 ;; Don't search under /usr/lib & co.
370 "--with-lib-path=/no-ld-lib-path"
371
372 ;; Glibc 2.17 has a "comparison of unsigned
373 ;; expression >= 0 is always true" in wchar.h.
374 "--disable-werror")))
375
376 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
377 assembler, etc.)")
378 (description
379 "The GNU Binutils are a collection of binary tools. The main ones are
380 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
381 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
382 (license gpl3+)
383 (home-page "http://www.gnu.org/software/binutils/")))
384
385 (define-public gcc-4.7
386 (let ((stripped? #t)) ; TODO: make this a parameter
387 (package
388 (name "gcc")
389 (version "4.7.2")
390 (source (origin
391 (method url-fetch)
392 (uri (string-append "mirror://gnu/gcc/gcc-"
393 version "/gcc-" version ".tar.bz2"))
394 (sha256
395 (base32
396 "115h03hil99ljig8lkrq4qk426awmzh0g99wrrggxf8g07bq74la"))))
397 (build-system gnu-build-system)
398 (inputs `(("gmp" ,gmp)
399 ("mpfr" ,mpfr)
400 ("mpc" ,mpc))) ; TODO: libelf, ppl, cloog, zlib, etc.
401 (arguments
402 `(#:out-of-source? #t
403 #:strip-binaries? ,stripped?
404 #:configure-flags
405 `("--enable-plugin"
406 "--enable-languages=c,c++"
407 "--disable-multilib"
408
409 "--with-local-prefix=/no-gcc-local-prefix"
410
411 ,(let ((libc (assoc-ref %build-inputs "libc")))
412 (if libc
413 (string-append "--with-native-system-header-dir=" libc
414 "/include")
415 "--without-headers")))
416 #:make-flags
417 (let ((libc (assoc-ref %build-inputs "libc")))
418 `(,@(if libc
419 (list (string-append "LDFLAGS_FOR_TARGET="
420 "-B" libc "/lib "
421 "-Wl,-dynamic-linker "
422 "-Wl," libc
423 ,(glibc-dynamic-linker)))
424 '())
425 ,(string-append "BOOT_CFLAGS=-O2 "
426 ,(if stripped? "-g0" "-g"))))
427
428 #:tests? #f
429 #:phases
430 (alist-cons-before
431 'configure 'pre-configure
432 (lambda* (#:key inputs outputs #:allow-other-keys)
433 (let ((out (assoc-ref outputs "out"))
434 (libc (assoc-ref inputs "libc")))
435 (when libc
436 ;; The following is not performed for `--without-headers'
437 ;; cross-compiler builds.
438
439 ;; Fix the dynamic linker's file name.
440 (substitute* (find-files "gcc/config"
441 "^linux(64|-elf)?\\.h$")
442 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
443 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
444 suffix
445 (string-append libc ,(glibc-dynamic-linker)))))
446
447 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
448 ;; `crt{begin,end}.o', which come with GCC.
449 (substitute* (find-files "gcc/config"
450 "^(gnu-user(64)?|linux-elf)\\.h$")
451 (("#define LIB_SPEC (.*)$" _ suffix)
452 ;; Note that with this "lib" spec, we may still add a
453 ;; RUNPATH to GCC even when `libgcc_s' is not NEEDED.
454 ;; There's not much that can be done to avoid it, though.
455 (format #f "#define LIB_SPEC \"-L~a/lib %{!static:-rpath=~a/lib \
456 %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib}} \" ~a"
457 libc libc out out suffix))
458 (("#define STARTFILE_SPEC.*$" line)
459 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
460 #define STANDARD_STARTFILE_PREFIX_2 \"\"
461 ~a~%"
462 libc line))))
463
464 ;; Don't retain a dependency on the build-time sed.
465 (substitute* "fixincludes/fixincl.x"
466 (("static char const sed_cmd_z\\[\\] =.*;")
467 "static char const sed_cmd_z[] = \"sed\";"))))
468
469 (alist-cons-after
470 'configure 'post-configure
471 (lambda _
472 ;; Don't store configure flags, to avoid retaining references to
473 ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
474 (substitute* "Makefile"
475 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
476 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
477 (alist-replace 'install
478 (lambda* (#:key outputs #:allow-other-keys)
479 (zero?
480 (system* "make"
481 ,(if stripped?
482 "install-strip"
483 "install"))))
484 %standard-phases)))))
485
486 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
487 (synopsis "The GNU Compiler Collection")
488 (description
489 "The GNU Compiler Collection includes compiler front ends for C, C++,
490 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well as
491 libraries for these languages (libstdc++, libgcj, libgomp,...).
492
493 GCC development is a part of the GNU Project, aiming to improve the compiler
494 used in the GNU system including the GNU/Linux variant.")
495 (license gpl3+)
496 (home-page "http://gcc.gnu.org/"))))
497
498 (define-public glibc
499 (package
500 (name "glibc")
501 (version "2.17")
502 (source (origin
503 (method url-fetch)
504 (uri (string-append "mirror://gnu/glibc/glibc-"
505 version ".tar.xz"))
506 (sha256
507 (base32
508 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
509 (build-system gnu-build-system)
510
511 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
512 ;; users should automatically pull Linux headers as well.
513 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
514
515 ;; Store the locales separately (~100 MiB). Note that "out" retains a
516 ;; reference to them anyway, so there's no space savings here.
517 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
518 ;; Nixpkgs does.
519 (outputs '("out" "locales"))
520
521 (arguments
522 `(#:out-of-source? #t
523 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
524 #:configure-flags
525 (list "--enable-add-ons"
526 "--sysconfdir=/etc"
527 (string-append "--localedir=" (assoc-ref %outputs "locales")
528 "/share/locale")
529
530 ;; `--localedir' is not honored, so work around it.
531 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
532 (string-append "libc_cv_localedir="
533 (assoc-ref %outputs "locales")
534 "/share/locale")
535
536
537 (string-append "--with-headers="
538 (assoc-ref %build-inputs "linux-headers")
539 "/include")
540
541 ;; The default is to assume a 2.4 Linux interface, but we'll
542 ;; always use something newer. See "kernel-features.h" in the
543 ;; GNU libc for details.
544 "--enable-kernel=2.6.30"
545
546 ;; Use our Bash instead of /bin/sh.
547 (string-append "BASH_SHELL="
548 (assoc-ref %build-inputs "bash")
549 "/bin/bash")
550
551 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
552 "libc_cv_ssp=no")
553
554 #:tests? #f ; XXX
555 #:phases (alist-cons-before
556 'configure 'pre-configure
557 (lambda* (#:key inputs outputs #:allow-other-keys)
558 (let* ((out (assoc-ref outputs "out"))
559 (bin (string-append out "/bin")))
560 ;; Use `pwd', not `/bin/pwd'.
561 (substitute* "configure"
562 (("/bin/pwd") "pwd"))
563
564 ;; Install the rpc data base file under `$out/etc/rpc'.
565 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
566 (substitute* "sunrpc/Makefile"
567 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
568 (string-append out "/etc/rpc" suffix "\n"))
569 (("^install-others =.*$")
570 (string-append "install-others = " out "/etc/rpc\n")))
571
572 (substitute* "Makeconfig"
573 ;; According to
574 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
575 ;; linking against libgcc_s is not needed with GCC
576 ;; 4.7.1.
577 ((" -lgcc_s") ""))
578
579 ;; Copy a statically-linked Bash in the output, with
580 ;; no references to other store paths.
581 (mkdir-p bin)
582 (copy-file (string-append (assoc-ref inputs "static-bash")
583 "/bin/bash")
584 (string-append bin "/bash"))
585 (remove-store-references (string-append bin "/bash"))
586 (chmod (string-append bin "/bash") #o555)
587
588 ;; Keep a symlink, for `patch-shebang' resolution.
589 (with-directory-excursion bin
590 (symlink "bash" "sh"))
591
592 ;; Have `system' use that Bash.
593 (substitute* "sysdeps/posix/system.c"
594 (("#define[[:blank:]]+SHELL_PATH.*$")
595 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
596 out)))
597
598 ;; Same for `popen'.
599 (substitute* "libio/iopopen.c"
600 (("/bin/sh")
601 (string-append out "/bin/bash")))))
602 (alist-cons-after
603 'install 'install-locales
604 (lambda _
605 (zero? (system* "make" "localedata/install-locales")))
606 %standard-phases))))
607
608 (inputs `(("patch/ld.so.cache"
609 ,(search-patch "glibc-no-ld-so-cache.patch"))
610 ("static-bash" ,(static-package bash-light))))
611 (synopsis "The GNU C Library")
612 (description
613 "Any Unix-like operating system needs a C library: the library which
614 defines the \"system calls\" and other basic facilities such as open, malloc,
615 printf, exit...
616
617 The GNU C library is used as the C library in the GNU system and most systems
618 with the Linux kernel.")
619 (license lgpl2.0+)
620 (home-page "http://www.gnu.org/software/libc/")))
621
622 \f
623 ;;;
624 ;;; Bootstrap packages.
625 ;;;
626
627 (define gnu-make-boot0
628 (package-with-bootstrap-guile
629 (package (inherit gnu-make)
630 (name "make-boot0")
631 (location (source-properties->location (current-source-location)))
632 (arguments
633 `(#:guile ,%bootstrap-guile
634 #:implicit-inputs? #f
635 #:tests? #f ; cannot run "make check"
636 ,@(substitute-keyword-arguments (package-arguments gnu-make)
637 ((#:phases phases)
638 `(alist-replace
639 'build (lambda _
640 (zero? (system* "./build.sh")))
641 (alist-replace
642 'install (lambda* (#:key outputs #:allow-other-keys)
643 (let* ((out (assoc-ref outputs "out"))
644 (bin (string-append out "/bin")))
645 (mkdir-p bin)
646 (copy-file "make"
647 (string-append bin "/make"))))
648 ,phases))))))
649 (inputs %bootstrap-inputs))))
650
651 (define diffutils-boot0
652 (package-with-bootstrap-guile
653 (let ((p (package-with-explicit-inputs diffutils
654 `(("make" ,gnu-make-boot0)
655 ,@%bootstrap-inputs)
656 #:guile %bootstrap-guile)))
657 (package (inherit p)
658 (location (source-properties->location (current-source-location)))
659 (arguments `(#:tests? #f ; the test suite needs diffutils
660 ,@(package-arguments p)))))))
661
662 (define findutils-boot0
663 (package-with-bootstrap-guile
664 (package-with-explicit-inputs findutils
665 `(("make" ,gnu-make-boot0)
666 ("diffutils" ,diffutils-boot0) ; for tests
667 ,@%bootstrap-inputs)
668 (current-source-location)
669 #:guile %bootstrap-guile)))
670
671
672 (define %boot0-inputs
673 `(("make" ,gnu-make-boot0)
674 ("diffutils" ,diffutils-boot0)
675 ("findutils" ,findutils-boot0)
676 ,@%bootstrap-inputs))
677
678 (define* (nix-system->gnu-triplet
679 #:optional (system (%current-system)) (vendor "unknown"))
680 "Return an a guess of the GNU triplet corresponding to Nix system
681 identifier SYSTEM."
682 (let* ((dash (string-index system #\-))
683 (arch (substring system 0 dash))
684 (os (substring system (+ 1 dash))))
685 (string-append arch
686 "-" vendor "-"
687 (if (string=? os "linux")
688 "linux-gnu"
689 os))))
690
691 (define* (boot-triplet #:optional (system (%current-system)))
692 ;; Return the triplet used to create the cross toolchain needed in the
693 ;; first bootstrapping stage.
694 (nix-system->gnu-triplet system "guix"))
695
696 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
697 ;; toolchain actually targets the same OS and arch, but it has the advantage
698 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
699 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
700
701 (define binutils-boot0
702 (package-with-bootstrap-guile
703 (package (inherit binutils)
704 (name "binutils-cross-boot0")
705 (arguments
706 `(#:guile ,%bootstrap-guile
707 #:implicit-inputs? #f
708 ,@(substitute-keyword-arguments (package-arguments binutils)
709 ((#:configure-flags cf)
710 `(cons ,(string-append "--target=" (boot-triplet))
711 ,cf)))))
712 (inputs %boot0-inputs))))
713
714 (define gcc-boot0
715 (package-with-bootstrap-guile
716 (package (inherit gcc-4.7)
717 (name "gcc-cross-boot0")
718 (arguments
719 `(#:guile ,%bootstrap-guile
720 #:implicit-inputs? #f
721 #:modules ((guix build gnu-build-system)
722 (guix build utils)
723 (ice-9 regex)
724 (srfi srfi-1)
725 (srfi srfi-26))
726 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
727 ((#:configure-flags flags)
728 `(append (list ,(string-append "--target=" (boot-triplet))
729
730 ;; No libc yet.
731 "--without-headers"
732
733 ;; Disable features not needed at this stage.
734 "--disable-shared"
735 "--enable-languages=c"
736 "--disable-libmudflap"
737 "--disable-libgomp"
738 "--disable-libssp"
739 "--disable-libquadmath"
740 "--disable-decimal-float")
741 (remove (cut string-match "--enable-languages.*" <>)
742 ,flags)))
743 ((#:phases phases)
744 `(alist-cons-after
745 'unpack 'unpack-gmp&co
746 (lambda* (#:key inputs #:allow-other-keys)
747 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
748 (mpfr (assoc-ref %build-inputs "mpfr-source"))
749 (mpc (assoc-ref %build-inputs "mpc-source")))
750
751 ;; To reduce the set of pre-built bootstrap inputs, build
752 ;; GMP & co. from GCC.
753 (for-each (lambda (source)
754 (or (zero? (system* "tar" "xvf" source))
755 (error "failed to unpack tarball"
756 source)))
757 (list gmp mpfr mpc))
758
759 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
760 ,@(map (lambda (lib)
761 `(symlink ,(package-full-name lib)
762 ,(package-name lib)))
763 (list gmp mpfr mpc))
764
765 ;; MPFR headers/lib are found under $(MPFR)/src, but
766 ;; `configure' wrongfully tells MPC too look under
767 ;; $(MPFR), so fix that.
768 (substitute* "configure"
769 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
770 _ equals include middle lib)
771 (string-append "extra_mpc_mpfr_configure_flags" equals
772 "--with-mpfr-include=" include
773 "/mpfr/src" middle
774 "--with-mpfr-lib=" lib
775 "/mpfr/src"))
776 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
777 (string-append "gmpinc='-I" a "/mpfr/src "
778 "-I" b "/mpfr/src"))
779 (("gmplibs='-L([^ ]+)/mpfr" _ a)
780 (string-append "gmplibs='-L" a "/mpfr/src")))))
781 (alist-cons-after
782 'install 'symlink-libgcc_eh
783 (lambda* (#:key outputs #:allow-other-keys)
784 (let ((out (assoc-ref outputs "out")))
785 ;; Glibc wants to link against libgcc_eh, so provide
786 ;; it.
787 (with-directory-excursion
788 (string-append out "/lib/gcc/"
789 ,(boot-triplet)
790 "/" ,(package-version gcc-4.7))
791 (symlink "libgcc.a" "libgcc_eh.a"))))
792 ,phases))))))
793
794 (inputs `(("gmp-source" ,(package-source gmp))
795 ("mpfr-source" ,(package-source mpfr))
796 ("mpc-source" ,(package-source mpc))
797 ("binutils-cross" ,binutils-boot0)
798
799 ;; Call it differently so that the builder can check whether
800 ;; the "libc" input is #f.
801 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
802 ,@(alist-delete "libc" %boot0-inputs))))))
803
804 (define linux-libre-headers-boot0
805 (package-with-bootstrap-guile
806 (package (inherit linux-libre-headers)
807 (arguments `(#:guile ,%bootstrap-guile
808 #:implicit-inputs? #f
809 ,@(package-arguments linux-libre-headers)))
810 (native-inputs
811 (let ((perl (package-with-explicit-inputs perl
812 %boot0-inputs
813 (current-source-location)
814 #:guile %bootstrap-guile)))
815 `(("perl" ,perl)
816 ,@%boot0-inputs))))))
817
818 (define %boot1-inputs
819 ;; 2nd stage inputs.
820 `(("gcc" ,gcc-boot0)
821 ("binutils-cross" ,binutils-boot0)
822
823 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
824 ;; cross-`as'.
825 ,@%boot0-inputs))
826
827 (define glibc-final-with-bootstrap-bash
828 ;; The final libc, "cross-built". If everything went well, the resulting
829 ;; store path has no dependencies. Actually, the really-final libc is
830 ;; built just below; the only difference is that this one uses the
831 ;; bootstrap Bash.
832 (package-with-bootstrap-guile
833 (package (inherit glibc)
834 (name "glibc-intermediate")
835 (arguments
836 `(#:guile ,%bootstrap-guile
837 #:implicit-inputs? #f
838
839 ,@(substitute-keyword-arguments (package-arguments glibc)
840 ((#:configure-flags flags)
841 `(append (list ,(string-append "--host=" (boot-triplet))
842 ,(string-append "--build="
843 (nix-system->gnu-triplet))
844
845 ;; Build Sun/ONC RPC support. In particular,
846 ;; install rpc/*.h.
847 "--enable-obsolete-rpc")
848 ,flags)))))
849 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
850 (inputs
851 `( ;; A native GCC is needed to build `cross-rpcgen'.
852 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
853
854 ;; Here, we use the bootstrap Bash, which is not satisfactory
855 ;; because we don't want to depend on bootstrap tools.
856 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
857
858 ,@%boot1-inputs
859 ,@(alist-delete "static-bash"
860 (package-inputs glibc))))))) ; patches
861
862 (define (cross-gcc-wrapper gcc binutils glibc bash)
863 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
864 that makes it available under the native tool names."
865 (package (inherit gcc-4.7)
866 (name (string-append (package-name gcc) "-wrapped"))
867 (source #f)
868 (build-system trivial-build-system)
869 (arguments
870 `(#:guile ,%bootstrap-guile
871 #:modules ((guix build utils))
872 #:builder (begin
873 (use-modules (guix build utils))
874
875 (let* ((binutils (assoc-ref %build-inputs "binutils"))
876 (gcc (assoc-ref %build-inputs "gcc"))
877 (libc (assoc-ref %build-inputs "libc"))
878 (bash (assoc-ref %build-inputs "bash"))
879 (out (assoc-ref %outputs "out"))
880 (bindir (string-append out "/bin"))
881 (triplet ,(boot-triplet)))
882 (mkdir-p bindir)
883 (with-directory-excursion bindir
884 (for-each (lambda (tool)
885 (symlink (string-append binutils "/bin/"
886 triplet "-" tool)
887 tool))
888 '("ar" "ranlib"))
889
890 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
891 ;; needs to be told where to find the crt files and
892 ;; the dynamic linker.
893 (call-with-output-file "gcc"
894 (lambda (p)
895 (format p "#!~a/bin/bash
896 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
897 bash
898 gcc triplet
899 libc libc
900 ,(glibc-dynamic-linker))))
901
902 (chmod "gcc" #o555))))))
903 (native-inputs
904 `(("binutils" ,binutils)
905 ("gcc" ,gcc)
906 ("libc" ,glibc)
907 ("bash" ,bash)))
908 (inputs '())))
909
910 (define static-bash-for-glibc
911 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
912 ;; system(3) & co.
913 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
914 glibc-final-with-bootstrap-bash
915 (car (assoc-ref %boot1-inputs "bash"))))
916 (bash (package (inherit bash-light)
917 (arguments
918 `(#:guile ,%bootstrap-guile
919 ,@(package-arguments bash-light))))))
920 (package-with-bootstrap-guile
921 (package-with-explicit-inputs (static-package bash)
922 `(("gcc" ,gcc)
923 ("libc" ,glibc-final-with-bootstrap-bash)
924 ,@(fold alist-delete %boot1-inputs
925 '("gcc" "libc")))
926 (current-source-location)))))
927
928 (define-public glibc-final
929 ;; The final glibc, which embeds the statically-linked Bash built above.
930 (package (inherit glibc-final-with-bootstrap-bash)
931 (name "glibc")
932 (inputs `(("static-bash" ,static-bash-for-glibc)
933 ,@(alist-delete
934 "static-bash"
935 (package-inputs glibc-final-with-bootstrap-bash))))))
936
937 (define gcc-boot0-wrapped
938 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
939 ;; non-cross names.
940 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
941 (car (assoc-ref %boot1-inputs "bash"))))
942
943 (define %boot2-inputs
944 ;; 3rd stage inputs.
945 `(("libc" ,glibc-final)
946 ("gcc" ,gcc-boot0-wrapped)
947 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
948
949 (define-public binutils-final
950 (package-with-bootstrap-guile
951 (package (inherit binutils)
952 (arguments
953 `(#:guile ,%bootstrap-guile
954 #:implicit-inputs? #f
955 ,@(package-arguments binutils)))
956 (inputs %boot2-inputs))))
957
958 (define-public gcc-final
959 ;; The final GCC.
960 (package (inherit gcc-boot0)
961 (name "gcc")
962 (arguments
963 `(#:guile ,%bootstrap-guile
964 #:implicit-inputs? #f
965
966 ;; Build again GMP & co. within GCC's build process, because it's hard
967 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
968 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
969 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
970 ((#:configure-flags boot-flags)
971 (let loop ((args (package-arguments gcc-4.7)))
972 (match args
973 ((#:configure-flags normal-flags _ ...)
974 normal-flags)
975 ((_ rest ...)
976 (loop rest)))))
977 ((#:phases phases)
978 `(alist-delete 'symlink-libgcc_eh ,phases)))))
979
980 (inputs `(("gmp-source" ,(package-source gmp))
981 ("mpfr-source" ,(package-source mpfr))
982 ("mpc-source" ,(package-source mpc))
983 ("binutils" ,binutils-final)
984 ,@%boot2-inputs))))
985
986 (define ld-wrapper-boot3
987 ;; A linker wrapper that uses the bootstrap Guile.
988 (package
989 (name "ld-wrapper-boot3")
990 (version "0")
991 (source #f)
992 (build-system trivial-build-system)
993 (inputs `(("binutils" ,binutils-final)
994 ("guile" ,%bootstrap-guile)
995 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
996 ("wrapper" ,(search-path %load-path
997 "gnu/packages/ld-wrapper.scm"))))
998 (arguments
999 `(#:guile ,%bootstrap-guile
1000 #:modules ((guix build utils))
1001 #:builder (begin
1002 (use-modules (guix build utils)
1003 (system base compile))
1004
1005 (let* ((out (assoc-ref %outputs "out"))
1006 (bin (string-append out "/bin"))
1007 (ld (string-append bin "/ld"))
1008 (go (string-append bin "/ld.go")))
1009
1010 (setvbuf (current-output-port) _IOLBF)
1011 (format #t "building ~s/bin/ld wrapper in ~s~%"
1012 (assoc-ref %build-inputs "binutils")
1013 out)
1014
1015 (mkdir-p bin)
1016 (copy-file (assoc-ref %build-inputs "wrapper") ld)
1017 (substitute* ld
1018 (("@GUILE@")
1019 (string-append (assoc-ref %build-inputs "guile")
1020 "/bin/guile"))
1021 (("@BASH@")
1022 (string-append (assoc-ref %build-inputs "bash")
1023 "/bin/bash"))
1024 (("@LD@")
1025 (string-append (assoc-ref %build-inputs "binutils")
1026 "/bin/ld")))
1027 (chmod ld #o555)
1028 (compile-file ld #:output-file go)))))
1029 (synopsis "The linker wrapper")
1030 (description
1031 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1032 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1033 store.")
1034 (home-page #f)
1035 (license gpl3+)))
1036
1037 (define %boot3-inputs
1038 ;; 4th stage inputs.
1039 `(("gcc" ,gcc-final)
1040 ("ld-wrapper" ,ld-wrapper-boot3)
1041 ,@(alist-delete "gcc" %boot2-inputs)))
1042
1043 (define-public bash-final
1044 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1045 ;; to the bootstrap GCC.
1046 (package-with-bootstrap-guile
1047 (package-with-explicit-inputs (static-libgcc-package bash)
1048 %boot3-inputs
1049 (current-source-location)
1050 #:guile %bootstrap-guile)))
1051
1052 (define %boot4-inputs
1053 ;; Now use the final Bash.
1054 `(("bash" ,bash-final)
1055 ,@(alist-delete "bash" %boot3-inputs)))
1056
1057 (define-public guile-final
1058 (package-with-bootstrap-guile
1059 (package-with-explicit-inputs guile-2.0/fixed
1060 %boot4-inputs
1061 (current-source-location)
1062 #:guile %bootstrap-guile)))
1063
1064 (define-public ld-wrapper
1065 ;; The final `ld' wrapper, which uses the final Guile.
1066 (package (inherit ld-wrapper-boot3)
1067 (name "ld-wrapper")
1068 (inputs `(("guile" ,guile-final)
1069 ("bash" ,bash-final)
1070 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1071 '("guile" "bash"))))))
1072
1073 (define-public %final-inputs
1074 ;; Final derivations used as implicit inputs by `gnu-build-system'.
1075 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
1076 (current-source-location))))
1077 `(,@(map (match-lambda
1078 ((name package)
1079 (list name (finalize package))))
1080 `(("tar" ,tar)
1081 ("gzip" ,gzip)
1082 ("bzip2" ,bzip2)
1083 ("xz" ,xz)
1084 ("diffutils" ,diffutils)
1085 ("patch" ,patch)
1086 ("coreutils" ,coreutils)
1087 ("sed" ,sed)
1088 ("grep" ,grep)
1089 ("findutils" ,findutils)
1090 ("gawk" ,gawk)
1091 ("make" ,gnu-make)))
1092 ("bash" ,bash-final)
1093 ("ld-wrapper" ,ld-wrapper)
1094 ("binutils" ,binutils-final)
1095 ("gcc" ,gcc-final)
1096 ("libc" ,glibc-final))))
1097
1098 ;;; base.scm ends here