7ca7ec74c609353f68df9aba5561685978eff701
[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 #:select (gpl3+ lgpl2.0+ public-domain))
23 #:use-module (gnu packages)
24 #:use-module (gnu packages acl)
25 #:use-module (gnu packages bash)
26 #:use-module (gnu packages bootstrap)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages gcc)
29 #:use-module (gnu packages gawk)
30 #:use-module (gnu packages guile)
31 #:use-module (gnu packages multiprecision)
32 #:use-module (gnu packages perl)
33 #:use-module (gnu packages linux)
34 #:use-module (guix packages)
35 #:use-module (guix download)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system trivial)
38 #:use-module (guix utils)
39 #:use-module (srfi srfi-1)
40 #:use-module (srfi srfi-26)
41 #:use-module (ice-9 match))
42
43 ;;; Commentary:
44 ;;;
45 ;;; Base packages of the Guix-based GNU user-land software distribution.
46 ;;;
47 ;;; Code:
48
49 (define-public hello
50 (package
51 (name "hello")
52 (version "2.8")
53 (source (origin
54 (method url-fetch)
55 (uri (string-append "mirror://gnu/hello/hello-" version
56 ".tar.gz"))
57 (sha256
58 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
59 (build-system gnu-build-system)
60 (arguments '(#:configure-flags
61 `("--disable-dependency-tracking"
62 ,(string-append "--with-gawk=" ; for illustration purposes
63 (assoc-ref %build-inputs "gawk")))))
64 (inputs `(("gawk" ,gawk)))
65 (synopsis "Hello, GNU world: An example GNU package")
66 (description "Yeah...")
67 (home-page "http://www.gnu.org/software/hello/")
68 (license gpl3+)))
69
70 (define-public grep
71 (package
72 (name "grep")
73 (version "2.14")
74 (source (origin
75 (method url-fetch)
76 (uri (string-append "mirror://gnu/grep/grep-"
77 version ".tar.xz"))
78 (sha256
79 (base32
80 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
81 (build-system gnu-build-system)
82 (synopsis "Print lines matching a pattern")
83 (description
84 "The grep command searches one or more input files for lines containing a
85 match to a specified pattern. By default, grep prints the matching
86 lines.")
87 (license gpl3+)
88 (home-page "http://www.gnu.org/software/grep/")))
89
90 (define-public sed
91 (package
92 (name "sed")
93 (version "4.2.2")
94 (source (origin
95 (method url-fetch)
96 (uri (string-append "mirror://gnu/sed/sed-" version
97 ".tar.bz2"))
98 (sha256
99 (base32
100 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
101 (build-system gnu-build-system)
102 (synopsis "Stream editor")
103 (arguments
104 (if (%current-target-system)
105 '()
106 `(#:phases (alist-cons-before
107 'patch-source-shebangs 'patch-test-suite
108 (lambda* (#:key inputs #:allow-other-keys)
109 (let ((bash (assoc-ref inputs "bash")))
110 (patch-makefile-SHELL "testsuite/Makefile.tests")
111 (substitute* '("testsuite/bsd.sh"
112 "testsuite/bug-regex9.c")
113 (("/bin/sh")
114 (string-append bash "/bin/bash")))))
115 %standard-phases))))
116 (description
117 "Sed (stream editor) isn't really a true text editor or text processor.
118 Instead, it is used to filter text, i.e., it takes text input and performs
119 some operation (or set of operations) on it and outputs the modified text.
120 Sed is typically used for extracting part of a file using pattern matching or
121 substituting multiple occurrences of a string within a file.")
122 (license gpl3+)
123 (home-page "http://www.gnu.org/software/sed/")))
124
125 (define-public tar
126 (package
127 (name "tar")
128 (version "1.26")
129 (source (origin
130 (method url-fetch)
131 (uri (string-append "mirror://gnu/tar/tar-"
132 version ".tar.bz2"))
133 (sha256
134 (base32
135 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
136 (build-system gnu-build-system)
137 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
138 (arguments
139 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
140 (synopsis "Managing tar archives")
141 (description
142 "The Tar program provides the ability to create tar archives, as well as
143 various other kinds of manipulation. For example, you can use Tar on
144 previously created archives to extract files, to store additional files, or
145 to update or list files which were already stored.
146
147 Initially, tar archives were used to store files conveniently on magnetic
148 tape. The name \"Tar\" comes from this use; it stands for tape archiver.
149 Despite the utility's name, Tar can direct its output to available devices,
150 files, or other programs (using pipes), it can even access remote devices or
151 files (as archives).")
152 (license gpl3+)
153 (home-page "http://www.gnu.org/software/tar/")))
154
155 (define-public patch
156 (package
157 (name "patch")
158 (version "2.7.1")
159 (source (origin
160 (method url-fetch)
161 (uri (string-append "mirror://gnu/patch/patch-"
162 version ".tar.xz"))
163 (sha256
164 (base32
165 "1sqckf560pzwgniy00vcpdv2c9c11s4cmhlm14yqgg8avd3bl94i"))))
166 (build-system gnu-build-system)
167 (native-inputs '()) ; FIXME: needs `ed' for the tests
168 (arguments
169 '(#:tests? #f)
170 ;; TODO: When cross-compiling, add this:
171 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
172 )
173 (synopsis "Apply differences to originals, with optional backups")
174 (description
175 "GNU Patch takes a patch file containing a difference listing produced by
176 the diff program and applies those differences to one or more original files,
177 producing patched versions.")
178 (license gpl3+)
179 (home-page "http://savannah.gnu.org/projects/patch/")))
180
181 (define-public diffutils
182 (package
183 (name "diffutils")
184 (version "3.3")
185 (source (origin
186 (method url-fetch)
187 (uri (string-append "mirror://gnu/diffutils/diffutils-"
188 version ".tar.xz"))
189 (sha256
190 (base32
191 "1761vymxbp4wb5rzjvabhdkskk95pghnn67464byvzb5mfl8jpm2"))))
192 (build-system gnu-build-system)
193 (synopsis "Comparing and merging 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 ;; Work around cross-compilation failure.
242 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
243 ,@(if (%current-target-system)
244 '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
245 '())))
246 (synopsis "Operating on files matching given criteria")
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) ; TODO: add SELinux
276 ("gmp" ,gmp)
277
278 ;; Perl is needed to run tests; remove it from cross builds.
279 ,@(if (%current-target-system)
280 '()
281 `(("perl" ,perl)))))
282 (outputs '("out" "debug"))
283 (arguments
284 `(#:parallel-build? #f ; help2man may be called too early
285 #:phases (alist-cons-before
286 'build 'patch-shell-references
287 (lambda* (#:key inputs #:allow-other-keys)
288 (let ((bash (assoc-ref inputs "bash")))
289 (substitute* (cons "src/split.c"
290 (find-files "gnulib-tests"
291 "\\.c$"))
292 (("/bin/sh")
293 (format #f "~a/bin/sh" bash)))
294 (substitute* (find-files "tests" "\\.sh$")
295 (("#!/bin/sh")
296 (format #f "#!~a/bin/bash" bash)))))
297 %standard-phases)))
298 (synopsis "Core GNU utilities (file, text, shell)")
299 (description
300 "The GNU Core Utilities are the basic file, shell and text manipulation
301 utilities of the GNU operating system. These are the core utilities which
302 are expected to exist on every operating system.")
303 (license gpl3+)
304 (home-page "http://www.gnu.org/software/coreutils/")))
305
306 (define-public gnu-make
307 (package
308 (name "make")
309 (version "3.82")
310 (source (origin
311 (method url-fetch)
312 (uri (string-append "mirror://gnu/make/make-" version
313 ".tar.bz2"))
314 (sha256
315 (base32
316 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
317 (build-system gnu-build-system)
318 (native-inputs
319 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
320 (outputs '("out" "debug"))
321 (arguments
322 '(#:patches (list (assoc-ref %build-inputs "patch/impure-dirs"))
323 #:phases (alist-cons-before
324 'build 'set-default-shell
325 (lambda* (#:key inputs #:allow-other-keys)
326 ;; Change the default shell from /bin/sh.
327 (let ((bash (assoc-ref inputs "bash")))
328 (substitute* "job.c"
329 (("default_shell\\[\\] =.*$")
330 (format #f "default_shell[] = \"~a/bin/bash\";\n"
331 bash)))))
332 %standard-phases)))
333 (synopsis "Remake files automatically")
334 (description
335 "Make is a tool which controls the generation of executables and other
336 non-source files of a program from the program's source files.
337
338 Make gets its knowledge of how to build your program from a file called the
339 makefile, which lists each of the non-source files and how to compute it from
340 other files. When you write a program, you should write a makefile for it, so
341 that it is possible to use Make to build and install the program.")
342 (license gpl3+)
343 (home-page "http://www.gnu.org/software/make/")))
344
345 (define-public binutils
346 (package
347 (name "binutils")
348 (version "2.23.2")
349 (source (origin
350 (method url-fetch)
351 (uri (string-append "mirror://gnu/binutils/binutils-"
352 version ".tar.bz2"))
353 (sha256
354 (base32
355 "15qhbkz3r266xaa52slh857qn3abw7rb2x2jnhpfrafpzrb4x4gy"))))
356 (build-system gnu-build-system)
357
358 ;; Split Binutils in several outputs, mostly to avoid collisions in
359 ;; user profiles with GCC---e.g., libiberty.a.
360 (outputs '("out" ; ar, ld, binutils.info, etc.
361 "lib")) ; libbfd.a, bfd.h, etc.
362
363 ;; TODO: Add dependency on zlib + those for Gold.
364 (native-inputs
365 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
366 (arguments
367 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
368 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
369 ;; on GCC when bootstrapping.
370 "LDFLAGS=-static-libgcc"
371
372 ;; Don't search under /usr/lib & co.
373 "--with-lib-path=/no-ld-lib-path"
374
375 ;; Glibc 2.17 has a "comparison of unsigned
376 ;; expression >= 0 is always true" in wchar.h.
377 "--disable-werror")))
378
379 (synopsis "Binary utilities: bfd gas gprof ld")
380 (description
381 "The GNU Binutils are a collection of binary tools. The main ones are
382 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
383 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
384 (license gpl3+)
385 (home-page "http://www.gnu.org/software/binutils/")))
386
387 (define-public glibc
388 (package
389 (name "glibc")
390 (version "2.17")
391 (source (origin
392 (method url-fetch)
393 (uri (string-append "mirror://gnu/glibc/glibc-"
394 version ".tar.xz"))
395 (sha256
396 (base32
397 "0gmjnn4kma9vgizccw1jv979xw55a8n1nkk94gg0l3hy80vy6539"))))
398 (build-system gnu-build-system)
399
400 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
401 ;; users should automatically pull Linux headers as well.
402 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
403
404 ;; Store the locales separately (~100 MiB). Note that "out" retains a
405 ;; reference to them anyway, so there's no space savings here.
406 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
407 ;; Nixpkgs does.
408 (outputs '("out" "locales" "debug"))
409
410 (arguments
411 `(#:out-of-source? #t
412 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
413 #:configure-flags
414 (list "--enable-add-ons"
415 "--sysconfdir=/etc"
416 (string-append "--localedir=" (assoc-ref %outputs "locales")
417 "/share/locale")
418
419 ;; `--localedir' is not honored, so work around it.
420 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
421 (string-append "libc_cv_localedir="
422 (assoc-ref %outputs "locales")
423 "/share/locale")
424
425
426 (string-append "--with-headers="
427 (assoc-ref %build-inputs "linux-headers")
428 "/include")
429
430 ;; The default is to assume a 2.4 Linux interface, but we'll
431 ;; always use something newer. See "kernel-features.h" in the
432 ;; GNU libc for details.
433 "--enable-kernel=2.6.30"
434
435 ;; Use our Bash instead of /bin/sh.
436 (string-append "BASH_SHELL="
437 (assoc-ref %build-inputs "bash")
438 "/bin/bash")
439
440 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
441 "libc_cv_ssp=no")
442
443 #:tests? #f ; XXX
444 #:phases (alist-cons-before
445 'configure 'pre-configure
446 (lambda* (#:key inputs outputs #:allow-other-keys)
447 (let* ((out (assoc-ref outputs "out"))
448 (bin (string-append out "/bin")))
449 ;; Use `pwd', not `/bin/pwd'.
450 (substitute* "configure"
451 (("/bin/pwd") "pwd"))
452
453 ;; Install the rpc data base file under `$out/etc/rpc'.
454 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
455 (substitute* "sunrpc/Makefile"
456 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
457 (string-append out "/etc/rpc" suffix "\n"))
458 (("^install-others =.*$")
459 (string-append "install-others = " out "/etc/rpc\n")))
460
461 (substitute* "Makeconfig"
462 ;; According to
463 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
464 ;; linking against libgcc_s is not needed with GCC
465 ;; 4.7.1.
466 ((" -lgcc_s") ""))
467
468 ;; Copy a statically-linked Bash in the output, with
469 ;; no references to other store paths.
470 (mkdir-p bin)
471 (copy-file (string-append (assoc-ref inputs "static-bash")
472 "/bin/bash")
473 (string-append bin "/bash"))
474 (remove-store-references (string-append bin "/bash"))
475 (chmod (string-append bin "/bash") #o555)
476
477 ;; Keep a symlink, for `patch-shebang' resolution.
478 (with-directory-excursion bin
479 (symlink "bash" "sh"))
480
481 ;; Have `system' use that Bash.
482 (substitute* "sysdeps/posix/system.c"
483 (("#define[[:blank:]]+SHELL_PATH.*$")
484 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
485 out)))
486
487 ;; Same for `popen'.
488 (substitute* "libio/iopopen.c"
489 (("/bin/sh")
490 (string-append out "/bin/bash")))))
491 (alist-cons-after
492 'install 'install-locales
493 (lambda _
494 (zero? (system* "make" "localedata/install-locales")))
495 %standard-phases))))
496
497 (inputs `(("patch/ld.so.cache"
498 ,(search-patch "glibc-no-ld-so-cache.patch"))
499 ("static-bash" ,(static-package bash-light))))
500 (synopsis "The GNU C Library")
501 (description
502 "Any Unix-like operating system needs a C library: the library which
503 defines the \"system calls\" and other basic facilities such as open, malloc,
504 printf, exit...
505
506 The GNU C library is used as the C library in the GNU system and most systems
507 with the Linux kernel.")
508 (license lgpl2.0+)
509 (home-page "http://www.gnu.org/software/libc/")))
510
511 (define-public tzdata
512 (package
513 (name "tzdata")
514 (version "2013c")
515 (source (origin
516 (method url-fetch)
517 (uri (string-append
518 "http://www.iana.org/time-zones/repository/releases/tzdata"
519 version ".tar.gz"))
520 (sha256
521 (base32
522 "11swq6fg20m2dh520qcr8vb23gqhzbvqhizx8wifnmci4gmsg5z5"))))
523 (build-system gnu-build-system)
524 (arguments
525 '(#:tests? #f
526 #:make-flags (let ((out (assoc-ref %outputs "out"))
527 (tmp (getenv "TMPDIR")))
528 (list (string-append "TOPDIR=" out)
529 (string-append "TZDIR=" out "/share/zoneinfo")
530
531 ;; Discard zic, dump, and tzselect, already
532 ;; provided by glibc.
533 (string-append "ETCDIR=" tmp "/etc")
534
535 ;; Likewise for the C library routines.
536 (string-append "LIBDIR=" tmp "/lib")
537 (string-append "MANDIR=" tmp "/man")
538
539 "AWK=awk"
540 "CC=gcc"))
541 #:modules ((guix build utils)
542 (guix build gnu-build-system)
543 (srfi srfi-1))
544 #:phases
545 (alist-replace
546 'unpack
547 (lambda* (#:key inputs #:allow-other-keys)
548 (and (zero? (system* "tar" "xvf" (assoc-ref inputs "source")))
549 (zero? (system* "tar" "xvf" (assoc-ref inputs "tzcode")))))
550 (alist-cons-after
551 'install 'post-install
552 (lambda* (#:key outputs #:allow-other-keys)
553 ;; Move data in the right place.
554 (let ((out (assoc-ref outputs "out")))
555 (copy-recursively (string-append out "/share/zoneinfo-posix")
556 (string-append out "/share/zoneinfo/posix"))
557 (copy-recursively (string-append out "/share/zoneinfo-leaps")
558 (string-append out "/share/zoneinfo/right"))
559 (delete-file-recursively (string-append out "/share/zoneinfo-posix"))
560 (delete-file-recursively (string-append out "/share/zoneinfo-leaps"))))
561 (alist-delete 'configure %standard-phases)))))
562 (inputs `(("tzcode" ,(origin
563 (method url-fetch)
564 (uri (string-append
565 "http://www.iana.org/time-zones/repository/releases/tzcode"
566 version ".tar.gz"))
567 (sha256
568 (base32
569 "1w6nkdwhi6k9llshp4baac1yj43jqf3apdf6n66i0wvjj8qyjvp4"))))))
570 (home-page "http://www.iana.org/time-zones")
571 (synopsis "Database of current and historical time zones")
572 (description "The Time Zone Database (often called tz or zoneinfo)
573 contains code and data that represent the history of local time for many
574 representative locations around the globe. It is updated periodically to
575 reflect changes made by political bodies to time zone boundaries, UTC offsets,
576 and daylight-saving rules.")
577 (license public-domain)))
578
579 \f
580 ;;;
581 ;;; Bootstrap packages.
582 ;;;
583
584 (define gnu-make-boot0
585 (package-with-bootstrap-guile
586 (package (inherit gnu-make)
587 (name "make-boot0")
588 (location (source-properties->location (current-source-location)))
589 (arguments
590 `(#:guile ,%bootstrap-guile
591 #:implicit-inputs? #f
592 #:tests? #f ; cannot run "make check"
593 ,@(substitute-keyword-arguments (package-arguments gnu-make)
594 ((#:phases phases)
595 `(alist-replace
596 'build (lambda _
597 (zero? (system* "./build.sh")))
598 (alist-replace
599 'install (lambda* (#:key outputs #:allow-other-keys)
600 (let* ((out (assoc-ref outputs "out"))
601 (bin (string-append out "/bin")))
602 (mkdir-p bin)
603 (copy-file "make"
604 (string-append bin "/make"))))
605 ,phases))))))
606 (inputs %bootstrap-inputs))))
607
608 (define diffutils-boot0
609 (package-with-bootstrap-guile
610 (let ((p (package-with-explicit-inputs diffutils
611 `(("make" ,gnu-make-boot0)
612 ,@%bootstrap-inputs)
613 #:guile %bootstrap-guile)))
614 (package (inherit p)
615 (location (source-properties->location (current-source-location)))
616 (arguments `(#:tests? #f ; the test suite needs diffutils
617 ,@(package-arguments p)))))))
618
619 (define findutils-boot0
620 (package-with-bootstrap-guile
621 (package-with-explicit-inputs findutils
622 `(("make" ,gnu-make-boot0)
623 ("diffutils" ,diffutils-boot0) ; for tests
624 ,@%bootstrap-inputs)
625 (current-source-location)
626 #:guile %bootstrap-guile)))
627
628
629 (define %boot0-inputs
630 `(("make" ,gnu-make-boot0)
631 ("diffutils" ,diffutils-boot0)
632 ("findutils" ,findutils-boot0)
633 ,@%bootstrap-inputs))
634
635 (define* (nix-system->gnu-triplet
636 #:optional (system (%current-system)) (vendor "unknown"))
637 "Return an a guess of the GNU triplet corresponding to Nix system
638 identifier SYSTEM."
639 (let* ((dash (string-index system #\-))
640 (arch (substring system 0 dash))
641 (os (substring system (+ 1 dash))))
642 (string-append arch
643 "-" vendor "-"
644 (if (string=? os "linux")
645 "linux-gnu"
646 os))))
647
648 (define* (boot-triplet #:optional (system (%current-system)))
649 ;; Return the triplet used to create the cross toolchain needed in the
650 ;; first bootstrapping stage.
651 (nix-system->gnu-triplet system "guix"))
652
653 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
654 ;; toolchain actually targets the same OS and arch, but it has the advantage
655 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
656 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
657
658 (define binutils-boot0
659 (package-with-bootstrap-guile
660 (package (inherit binutils)
661 (name "binutils-cross-boot0")
662 (arguments
663 `(#:guile ,%bootstrap-guile
664 #:implicit-inputs? #f
665 ,@(substitute-keyword-arguments (package-arguments binutils)
666 ((#:configure-flags cf)
667 `(cons ,(string-append "--target=" (boot-triplet))
668 ,cf)))))
669 (inputs %boot0-inputs))))
670
671 (define gcc-boot0
672 (package-with-bootstrap-guile
673 (package (inherit gcc-4.7)
674 (name "gcc-cross-boot0")
675 (arguments
676 `(#:guile ,%bootstrap-guile
677 #:implicit-inputs? #f
678 #:modules ((guix build gnu-build-system)
679 (guix build utils)
680 (ice-9 regex)
681 (srfi srfi-1)
682 (srfi srfi-26))
683 ,@(substitute-keyword-arguments (package-arguments gcc-4.7)
684 ((#:configure-flags flags)
685 `(append (list ,(string-append "--target=" (boot-triplet))
686
687 ;; No libc yet.
688 "--without-headers"
689
690 ;; Disable features not needed at this stage.
691 "--disable-shared"
692 "--enable-languages=c"
693 "--disable-libmudflap"
694 "--disable-libgomp"
695 "--disable-libssp"
696 "--disable-libquadmath"
697 "--disable-decimal-float")
698 (remove (cut string-match "--enable-languages.*" <>)
699 ,flags)))
700 ((#:phases phases)
701 `(alist-cons-after
702 'unpack 'unpack-gmp&co
703 (lambda* (#:key inputs #:allow-other-keys)
704 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
705 (mpfr (assoc-ref %build-inputs "mpfr-source"))
706 (mpc (assoc-ref %build-inputs "mpc-source")))
707
708 ;; To reduce the set of pre-built bootstrap inputs, build
709 ;; GMP & co. from GCC.
710 (for-each (lambda (source)
711 (or (zero? (system* "tar" "xvf" source))
712 (error "failed to unpack tarball"
713 source)))
714 (list gmp mpfr mpc))
715
716 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
717 ,@(map (lambda (lib)
718 `(symlink ,(package-full-name lib)
719 ,(package-name lib)))
720 (list gmp mpfr mpc))
721
722 ;; MPFR headers/lib are found under $(MPFR)/src, but
723 ;; `configure' wrongfully tells MPC too look under
724 ;; $(MPFR), so fix that.
725 (substitute* "configure"
726 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
727 _ equals include middle lib)
728 (string-append "extra_mpc_mpfr_configure_flags" equals
729 "--with-mpfr-include=" include
730 "/mpfr/src" middle
731 "--with-mpfr-lib=" lib
732 "/mpfr/src"))
733 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
734 (string-append "gmpinc='-I" a "/mpfr/src "
735 "-I" b "/mpfr/src"))
736 (("gmplibs='-L([^ ]+)/mpfr" _ a)
737 (string-append "gmplibs='-L" a "/mpfr/src")))))
738 (alist-cons-after
739 'install 'symlink-libgcc_eh
740 (lambda* (#:key outputs #:allow-other-keys)
741 (let ((out (assoc-ref outputs "out")))
742 ;; Glibc wants to link against libgcc_eh, so provide
743 ;; it.
744 (with-directory-excursion
745 (string-append out "/lib/gcc/"
746 ,(boot-triplet)
747 "/" ,(package-version gcc-4.7))
748 (symlink "libgcc.a" "libgcc_eh.a"))))
749 ,phases))))))
750
751 (inputs `(("gmp-source" ,(package-source gmp))
752 ("mpfr-source" ,(package-source mpfr))
753 ("mpc-source" ,(package-source mpc))
754 ("binutils-cross" ,binutils-boot0)
755
756 ;; Call it differently so that the builder can check whether
757 ;; the "libc" input is #f.
758 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
759 ,@(alist-delete "libc" %boot0-inputs))))))
760
761 (define linux-libre-headers-boot0
762 (package-with-bootstrap-guile
763 (package (inherit linux-libre-headers)
764 (arguments `(#:guile ,%bootstrap-guile
765 #:implicit-inputs? #f
766 ,@(package-arguments linux-libre-headers)))
767 (native-inputs
768 (let ((perl (package-with-explicit-inputs perl
769 %boot0-inputs
770 (current-source-location)
771 #:guile %bootstrap-guile)))
772 `(("perl" ,perl)
773 ,@%boot0-inputs))))))
774
775 (define %boot1-inputs
776 ;; 2nd stage inputs.
777 `(("gcc" ,gcc-boot0)
778 ("binutils-cross" ,binutils-boot0)
779
780 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
781 ;; cross-`as'.
782 ,@%boot0-inputs))
783
784 (define glibc-final-with-bootstrap-bash
785 ;; The final libc, "cross-built". If everything went well, the resulting
786 ;; store path has no dependencies. Actually, the really-final libc is
787 ;; built just below; the only difference is that this one uses the
788 ;; bootstrap Bash.
789 (package-with-bootstrap-guile
790 (package (inherit glibc)
791 (name "glibc-intermediate")
792 (arguments
793 `(#:guile ,%bootstrap-guile
794 #:implicit-inputs? #f
795
796 ,@(substitute-keyword-arguments (package-arguments glibc)
797 ((#:configure-flags flags)
798 `(append (list ,(string-append "--host=" (boot-triplet))
799 ,(string-append "--build="
800 (nix-system->gnu-triplet))
801
802 ;; Build Sun/ONC RPC support. In particular,
803 ;; install rpc/*.h.
804 "--enable-obsolete-rpc")
805 ,flags)))))
806 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
807 (inputs
808 `( ;; A native GCC is needed to build `cross-rpcgen'.
809 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
810
811 ;; Here, we use the bootstrap Bash, which is not satisfactory
812 ;; because we don't want to depend on bootstrap tools.
813 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
814
815 ,@%boot1-inputs
816 ,@(alist-delete "static-bash"
817 (package-inputs glibc))))))) ; patches
818
819 (define (cross-gcc-wrapper gcc binutils glibc bash)
820 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
821 that makes it available under the native tool names."
822 (package (inherit gcc-4.7)
823 (name (string-append (package-name gcc) "-wrapped"))
824 (source #f)
825 (build-system trivial-build-system)
826 (arguments
827 `(#:guile ,%bootstrap-guile
828 #:modules ((guix build utils))
829 #:builder (begin
830 (use-modules (guix build utils))
831
832 (let* ((binutils (assoc-ref %build-inputs "binutils"))
833 (gcc (assoc-ref %build-inputs "gcc"))
834 (libc (assoc-ref %build-inputs "libc"))
835 (bash (assoc-ref %build-inputs "bash"))
836 (out (assoc-ref %outputs "out"))
837 (bindir (string-append out "/bin"))
838 (triplet ,(boot-triplet)))
839 (mkdir-p bindir)
840 (with-directory-excursion bindir
841 (for-each (lambda (tool)
842 (symlink (string-append binutils "/bin/"
843 triplet "-" tool)
844 tool))
845 '("ar" "ranlib"))
846
847 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
848 ;; needs to be told where to find the crt files and
849 ;; the dynamic linker.
850 (call-with-output-file "gcc"
851 (lambda (p)
852 (format p "#!~a/bin/bash
853 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
854 bash
855 gcc triplet
856 libc libc
857 ,(glibc-dynamic-linker))))
858
859 (chmod "gcc" #o555))))))
860 (native-inputs
861 `(("binutils" ,binutils)
862 ("gcc" ,gcc)
863 ("libc" ,glibc)
864 ("bash" ,bash)))
865 (inputs '())))
866
867 (define static-bash-for-glibc
868 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
869 ;; system(3) & co.
870 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
871 glibc-final-with-bootstrap-bash
872 (car (assoc-ref %boot1-inputs "bash"))))
873 (bash (package (inherit bash-light)
874 (arguments
875 `(#:guile ,%bootstrap-guile
876 ,@(package-arguments bash-light))))))
877 (package-with-bootstrap-guile
878 (package-with-explicit-inputs (static-package bash)
879 `(("gcc" ,gcc)
880 ("libc" ,glibc-final-with-bootstrap-bash)
881 ,@(fold alist-delete %boot1-inputs
882 '("gcc" "libc")))
883 (current-source-location)))))
884
885 (define-public glibc-final
886 ;; The final glibc, which embeds the statically-linked Bash built above.
887 (package (inherit glibc-final-with-bootstrap-bash)
888 (name "glibc")
889 (inputs `(("static-bash" ,static-bash-for-glibc)
890 ,@(alist-delete
891 "static-bash"
892 (package-inputs glibc-final-with-bootstrap-bash))))))
893
894 (define gcc-boot0-wrapped
895 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
896 ;; non-cross names.
897 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
898 (car (assoc-ref %boot1-inputs "bash"))))
899
900 (define %boot2-inputs
901 ;; 3rd stage inputs.
902 `(("libc" ,glibc-final)
903 ("gcc" ,gcc-boot0-wrapped)
904 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
905
906 (define-public binutils-final
907 (package-with-bootstrap-guile
908 (package (inherit binutils)
909 (arguments
910 `(#:guile ,%bootstrap-guile
911 #:implicit-inputs? #f
912 ,@(package-arguments binutils)))
913 (inputs %boot2-inputs))))
914
915 (define-public gcc-final
916 ;; The final GCC.
917 (package (inherit gcc-boot0)
918 (name "gcc")
919 (arguments
920 `(#:guile ,%bootstrap-guile
921 #:implicit-inputs? #f
922
923 ;; Build again GMP & co. within GCC's build process, because it's hard
924 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
925 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
926 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
927 ((#:configure-flags boot-flags)
928 (let loop ((args (package-arguments gcc-4.7)))
929 (match args
930 ((#:configure-flags normal-flags _ ...)
931 normal-flags)
932 ((_ rest ...)
933 (loop rest)))))
934 ((#:phases phases)
935 `(alist-delete 'symlink-libgcc_eh ,phases)))))
936
937 (inputs `(("gmp-source" ,(package-source gmp))
938 ("mpfr-source" ,(package-source mpfr))
939 ("mpc-source" ,(package-source mpc))
940 ("binutils" ,binutils-final)
941 ,@%boot2-inputs))))
942
943 (define ld-wrapper-boot3
944 ;; A linker wrapper that uses the bootstrap Guile.
945 (package
946 (name "ld-wrapper-boot3")
947 (version "0")
948 (source #f)
949 (build-system trivial-build-system)
950 (inputs `(("binutils" ,binutils-final)
951 ("guile" ,%bootstrap-guile)
952 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
953 ("wrapper" ,(search-path %load-path
954 "gnu/packages/ld-wrapper.scm"))))
955 (arguments
956 `(#:guile ,%bootstrap-guile
957 #:modules ((guix build utils))
958 #:builder (begin
959 (use-modules (guix build utils)
960 (system base compile))
961
962 (let* ((out (assoc-ref %outputs "out"))
963 (bin (string-append out "/bin"))
964 (ld (string-append bin "/ld"))
965 (go (string-append bin "/ld.go")))
966
967 (setvbuf (current-output-port) _IOLBF)
968 (format #t "building ~s/bin/ld wrapper in ~s~%"
969 (assoc-ref %build-inputs "binutils")
970 out)
971
972 (mkdir-p bin)
973 (copy-file (assoc-ref %build-inputs "wrapper") ld)
974 (substitute* ld
975 (("@GUILE@")
976 (string-append (assoc-ref %build-inputs "guile")
977 "/bin/guile"))
978 (("@BASH@")
979 (string-append (assoc-ref %build-inputs "bash")
980 "/bin/bash"))
981 (("@LD@")
982 (string-append (assoc-ref %build-inputs "binutils")
983 "/bin/ld")))
984 (chmod ld #o555)
985 (compile-file ld #:output-file go)))))
986 (synopsis "The linker wrapper")
987 (description
988 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
989 missing `-rpath' flags, and to detect any misuse of libraries outside of the
990 store.")
991 (home-page #f)
992 (license gpl3+)))
993
994 (define %boot3-inputs
995 ;; 4th stage inputs.
996 `(("gcc" ,gcc-final)
997 ("ld-wrapper" ,ld-wrapper-boot3)
998 ,@(alist-delete "gcc" %boot2-inputs)))
999
1000 (define-public bash-final
1001 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1002 ;; to the bootstrap GCC.
1003 (package-with-bootstrap-guile
1004 (package-with-explicit-inputs (static-libgcc-package bash)
1005 %boot3-inputs
1006 (current-source-location)
1007 #:guile %bootstrap-guile)))
1008
1009 (define %boot4-inputs
1010 ;; Now use the final Bash.
1011 `(("bash" ,bash-final)
1012 ,@(alist-delete "bash" %boot3-inputs)))
1013
1014 (define-public guile-final
1015 (package-with-bootstrap-guile
1016 (package-with-explicit-inputs guile-2.0/fixed
1017 %boot4-inputs
1018 (current-source-location)
1019 #:guile %bootstrap-guile)))
1020
1021 (define-public ld-wrapper
1022 ;; The final `ld' wrapper, which uses the final Guile.
1023 (package (inherit ld-wrapper-boot3)
1024 (name "ld-wrapper")
1025 (inputs `(("guile" ,guile-final)
1026 ("bash" ,bash-final)
1027 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1028 '("guile" "bash"))))))
1029
1030 (define-public %final-inputs
1031 ;; Final derivations used as implicit inputs by `gnu-build-system'.
1032 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
1033 (current-source-location))))
1034 `(,@(map (match-lambda
1035 ((name package)
1036 (list name (finalize package))))
1037 `(("tar" ,tar)
1038 ("gzip" ,gzip)
1039 ("bzip2" ,bzip2)
1040 ("xz" ,xz)
1041 ("diffutils" ,diffutils)
1042 ("patch" ,patch)
1043 ("coreutils" ,coreutils)
1044 ("sed" ,sed)
1045 ("grep" ,grep)
1046 ("findutils" ,findutils)
1047 ("gawk" ,gawk)
1048 ("make" ,gnu-make)))
1049 ("bash" ,bash-final)
1050 ("ld-wrapper" ,ld-wrapper)
1051 ("binutils" ,binutils-final)
1052 ("gcc" ,gcc-final)
1053 ("libc" ,glibc-final))))
1054
1055 ;;; base.scm ends here