gnu: Python: use /nix/.../sh instead of /bin/sh in the subprocess module
[jackhill/guix/guix.git] / gnu / packages / base.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
4 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu packages base)
22 #:use-module ((guix licenses)
23 #:select (gpl3+ lgpl2.0+ public-domain))
24 #:use-module (gnu packages)
25 #:use-module (gnu packages acl)
26 #:use-module (gnu packages bash)
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages compression)
29 #:use-module (gnu packages gcc)
30 #:use-module (gnu packages gawk)
31 #:use-module (gnu packages guile)
32 #:use-module (gnu packages multiprecision)
33 #:use-module (gnu packages perl)
34 #:use-module (gnu packages linux)
35 #:use-module (gnu packages texinfo)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (guix packages)
38 #:use-module (guix download)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system trivial)
41 #:use-module (guix utils)
42 #:use-module (srfi srfi-1)
43 #:use-module (srfi srfi-26)
44 #:use-module (ice-9 match))
45
46 ;;; Commentary:
47 ;;;
48 ;;; Base packages of the Guix-based GNU user-land software distribution.
49 ;;;
50 ;;; Code:
51
52 (define-public hello
53 (package
54 (name "hello")
55 (version "2.9")
56 (source (origin
57 (method url-fetch)
58 (uri (string-append "mirror://gnu/hello/hello-" version
59 ".tar.gz"))
60 (sha256
61 (base32 "19qy37gkasc4csb1d3bdiz9snn8mir2p3aj0jgzmfv0r2hi7mfzc"))))
62 (build-system gnu-build-system)
63 (synopsis "Hello, GNU world: An example GNU package")
64 (description
65 "GNU Hello prints the message \"Hello, world!\" and then exits. It
66 serves as an example of standard GNU coding practices. As such, it supports
67 command-line arguments, multiple languages, and so on.")
68 (home-page "http://www.gnu.org/software/hello/")
69 (license gpl3+)))
70
71 (define-public grep
72 (package
73 (name "grep")
74 (version "2.18")
75 (source (origin
76 (method url-fetch)
77 (uri (string-append "mirror://gnu/grep/grep-"
78 version ".tar.xz"))
79 (sha256
80 (base32
81 "08773flbnx28ksy0y4mzd4iifysh7yysmzn8rkz9f57sfx86whz6"))))
82 (build-system gnu-build-system)
83 (synopsis "Print lines matching a pattern")
84 (description
85 "grep is a tool for finding text inside files. Text is found by
86 matching a pattern provided by the user in one or many files. The pattern
87 may be provided as a basic or extended regular expression, or as fixed
88 strings. By default, the matching text is simply printed to the screen,
89 however the output can be greatly customized to include, for example, line
90 numbers. GNU grep offers many extensions over the standard utility,
91 including, for example, recursive directory searching.")
92 (license gpl3+)
93 (home-page "http://www.gnu.org/software/grep/")))
94
95 (define-public sed
96 (package
97 (name "sed")
98 (version "4.2.2")
99 (source (origin
100 (method url-fetch)
101 (uri (string-append "mirror://gnu/sed/sed-" version
102 ".tar.bz2"))
103 (sha256
104 (base32
105 "1myvrmh99jsvk7v3d7crm0gcrq51hmmm1r2kjyyci152in1x2j7h"))))
106 (build-system gnu-build-system)
107 (synopsis "Stream editor")
108 (arguments
109 (if (%current-target-system)
110 '()
111 `(#:phases (alist-cons-before
112 'patch-source-shebangs 'patch-test-suite
113 (lambda* (#:key inputs #:allow-other-keys)
114 (let ((bash (assoc-ref inputs "bash")))
115 (patch-makefile-SHELL "testsuite/Makefile.tests")
116 (substitute* '("testsuite/bsd.sh"
117 "testsuite/bug-regex9.c")
118 (("/bin/sh")
119 (string-append bash "/bin/bash")))))
120 %standard-phases))))
121 (description
122 "Sed is a non-interactive, text stream editor. It receives a text
123 input from a file or from standard input and it then applies a series of text
124 editing commands to the stream and prints its output to standard output. It
125 is often used for substituting text patterns in a stream. The GNU
126 implementation offers several extensions over the standard utility.")
127 (license gpl3+)
128 (home-page "http://www.gnu.org/software/sed/")))
129
130 (define-public tar
131 (package
132 (name "tar")
133 (version "1.27.1")
134 (source (origin
135 (method url-fetch)
136 (uri (string-append "mirror://gnu/tar/tar-"
137 version ".tar.bz2"))
138 (sha256
139 (base32
140 "1iip0fk0wqhxb0jcwphz43r4fxkx1y7mznnhmlvr618jhp7b63wv"))))
141 (build-system gnu-build-system)
142 (synopsis "Managing tar archives")
143 (description
144 "Tar provides the ability to create tar archives, as well as the
145 ability to extract, update or list files in an existing archive. It is
146 useful for combining many files into one larger file, while maintaining
147 directory structure and file information such as permissions and
148 creation/modification dates. GNU tar offers many extensions over the
149 standard utility.")
150 (license gpl3+)
151 (home-page "http://www.gnu.org/software/tar/")))
152
153 (define-public patch
154 (package
155 (name "patch")
156 (version "2.7.1")
157 (source (origin
158 (method url-fetch)
159 (uri (string-append "mirror://gnu/patch/patch-"
160 version ".tar.xz"))
161 (sha256
162 (base32
163 "1sqckf560pzwgniy00vcpdv2c9c11s4cmhlm14yqgg8avd3bl94i"))))
164 (build-system gnu-build-system)
165 (native-inputs '()) ; FIXME: needs `ed' for the tests
166 (arguments
167 '(#:tests? #f)
168 ;; TODO: When cross-compiling, add this:
169 ;; '(#:configure-flags '("ac_cv_func_strnlen_working=yes"))
170 )
171 (synopsis "Apply differences to originals, with optional backups")
172 (description
173 "Patch is a program that applies changes to files based on differences
174 laid out as by the program \"diff\". The changes may be applied to one or more
175 files depending on the contents of the diff file. It accepts several
176 different diff formats. It may also be used to revert previously applied
177 differences.")
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 containing tools for finding the
196 differences between files. The \"diff\" command is used to show how two files
197 differ, while \"cmp\" shows the offsets and line numbers where they differ.
198 \"diff3\" allows you to compare three files. Finally, \"sdiff\" offers an
199 interactive means to merge two files.")
200 (license gpl3+)
201 (home-page "http://www.gnu.org/software/diffutils/")))
202
203 (define-public findutils
204 (package
205 (name "findutils")
206 (version "4.4.2")
207 (source (origin
208 (method url-fetch)
209 (uri (string-append "mirror://gnu/findutils/findutils-"
210 version ".tar.gz"))
211 (sha256
212 (base32
213 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))
214 (patches (list (search-patch "findutils-absolute-paths.patch")))))
215 (build-system gnu-build-system)
216 (arguments
217 ;; Work around cross-compilation failure.
218 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
219 (if (%current-target-system)
220 '(#:configure-flags '("gl_cv_func_wcwidth_works=yes"))
221 '()))
222 (synopsis "Operating on files matching given criteria")
223 (description
224 "Findutils supplies the basic file directory searching utilities of the
225 GNU system. It consists of two primary searching utilities: \"find\"
226 recursively searches for files in a directory according to given criteria and
227 \"locate\" lists files in a database that match a query. Two auxiliary tools
228 are included: \"updatedb\" updates the file name database and \"xargs\" may be
229 used to apply commands with arbitrarily long arguments.")
230 (license gpl3+)
231 (home-page "http://www.gnu.org/software/findutils/")))
232
233 (define-public coreutils
234 (package
235 (name "coreutils")
236 (version "8.22")
237 (source (origin
238 (method url-fetch)
239 (uri (string-append "mirror://gnu/coreutils/coreutils-"
240 version ".tar.xz"))
241 (sha256
242 (base32
243 "04hjzzv434fb8ak3hh3dyhdvg3hqjjwvjmjxqzk1gh2jh6cr8gjv"))
244 (patches (list (search-patch "coreutils-dummy-man.patch")
245 ;; TODO: remove this patch for >= 8.23
246 (search-patch "coreutils-skip-nohup.patch")))))
247 (build-system gnu-build-system)
248 (inputs `(("acl" ,acl) ; TODO: add SELinux
249 ("gmp" ,gmp)))
250 (native-inputs
251 ;; Perl is needed to run tests in native builds, and to run the bundled
252 ;; copy of help2man. However, don't pass it when cross-compiling since
253 ;; that would lead it to try to run programs to get their '--help' output
254 ;; for help2man.
255 (if (%current-target-system)
256 '()
257 `(("perl" ,perl))))
258 (outputs '("out" "debug"))
259 (arguments
260 `(#:parallel-build? #f ; help2man may be called too early
261 #:phases (alist-cons-before
262 'build 'patch-shell-references
263 (lambda* (#:key inputs #:allow-other-keys)
264 (let ((bash (assoc-ref inputs "bash")))
265 (substitute* (cons "src/split.c"
266 (find-files "gnulib-tests"
267 "\\.c$"))
268 (("/bin/sh")
269 (format #f "~a/bin/sh" bash)))
270 (substitute* (find-files "tests" "\\.sh$")
271 (("#!/bin/sh")
272 (format #f "#!~a/bin/bash" bash)))))
273 %standard-phases)))
274 (synopsis "Core GNU utilities (file, text, shell)")
275 (description
276 "GNU Coreutils includes all of the basic command-line tools that are
277 expected in a POSIX system. These provide the basic file, shell and text
278 manipulation functions of the GNU system. Most of these tools offer extended
279 functionality beyond that which is outlined in the POSIX standard.")
280 (license gpl3+)
281 (home-page "http://www.gnu.org/software/coreutils/")))
282
283 (define-public gnu-make
284 (package
285 (name "make")
286 (version "4.0")
287 (source (origin
288 (method url-fetch)
289 (uri (string-append "mirror://gnu/make/make-" version
290 ".tar.bz2"))
291 (sha256
292 (base32
293 "1nyvn8mknw0mf7727lprva3lisl1y0n03lvar342rrpdmz3qc1p6"))
294 (patches (list (search-patch "make-impure-dirs.patch")))))
295 (build-system gnu-build-system)
296 (native-inputs `(("pkg-config", pkg-config))) ; to detect Guile
297 (inputs `(("guile" ,guile-2.0)))
298 (outputs '("out" "debug"))
299 (arguments
300 '(#:phases (alist-cons-before
301 'build 'set-default-shell
302 (lambda* (#:key inputs #:allow-other-keys)
303 ;; Change the default shell from /bin/sh.
304 (let ((bash (assoc-ref inputs "bash")))
305 (substitute* "job.c"
306 (("default_shell\\[\\] =.*$")
307 (format #f "default_shell[] = \"~a/bin/bash\";\n"
308 bash)))))
309 %standard-phases)))
310 (synopsis "Remake files automatically")
311 (description
312 "Make is a program that is used to control the production of
313 executables or other files from their source files. The process is
314 controlled from a Makefile, in which the developer specifies how each file is
315 generated from its source. It has powerful dependency resolution and the
316 ability to determine when files have to be regenerated after their sources
317 change. GNU make offers many powerful extensions over the standard utility.")
318 (license gpl3+)
319 (home-page "http://www.gnu.org/software/make/")))
320
321 (define-public binutils
322 (package
323 (name "binutils")
324 (version "2.24")
325 (source (origin
326 (method url-fetch)
327 (uri (string-append "mirror://gnu/binutils/binutils-"
328 version ".tar.bz2"))
329 (sha256
330 (base32
331 "0ds1y7qa0xqihw4ihnsgg6bxanmb228r228ddvwzgrv4jszcbs75"))
332 (patches (list (search-patch "binutils-ld-new-dtags.patch")
333 (search-patch "binutils-loongson-workaround.patch")))))
334 (build-system gnu-build-system)
335
336 ;; TODO: Add dependency on zlib + those for Gold.
337 (arguments
338 `(#:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
339 ;; on GCC when bootstrapping.
340 "LDFLAGS=-static-libgcc"
341
342 ;; Don't search under /usr/lib & co.
343 "--with-lib-path=/no-ld-lib-path"
344
345 ;; Glibc 2.17 has a "comparison of unsigned
346 ;; expression >= 0 is always true" in wchar.h.
347 "--disable-werror"
348
349 ;; Install BFD. It ends up in a hidden directory,
350 ;; but it's here.
351 "--enable-install-libbfd"
352
353 ;; Make sure 'ar' and 'ranlib' produce archives in a
354 ;; deterministic fashion.
355 "--enable-deterministic-archives")))
356
357 (synopsis "Binary utilities: bfd gas gprof ld")
358 (description
359 "GNU Binutils is a collection of tools for working with binary files.
360 Perhaps the most notable are \"ld\", a linker, and \"as\", an assembler. Other
361 tools include programs to display binary profiling information, list the
362 strings in a binary file, and utilities for working with archives. The \"bfd\"
363 library for working with executable and object formats is also included.")
364 (license gpl3+)
365 (home-page "http://www.gnu.org/software/binutils/")))
366
367 (define-public glibc
368 (package
369 (name "glibc")
370 (version "2.19")
371 (source (origin
372 (method url-fetch)
373 (uri (string-append "mirror://gnu/glibc/glibc-"
374 version ".tar.xz"))
375 (sha256
376 (base32
377 "18m2dssd6ja5arxmdxinc90xvpqcsnqjfwmjl2as07j0i3srff9d"))
378 (snippet
379 ;; Disable 'ldconfig' and /etc/ld.so.cache. The latter is
380 ;; required on LFS distros to avoid loading the distro's libc.so
381 ;; instead of ours.
382 '(substitute* "sysdeps/unix/sysv/linux/configure"
383 (("use_ldconfig=yes")
384 "use_ldconfig=no")))
385 (modules '((guix build utils)))
386 (patches (list (search-patch "glibc-ldd-x86_64.patch")))))
387 (build-system gnu-build-system)
388
389 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
390 ;; users should automatically pull Linux headers as well.
391 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
392
393 ;; Store the locales separately (~100 MiB). Note that "out" retains a
394 ;; reference to them anyway, so there's no space savings here.
395 ;; TODO: Eventually we may want to add a $LOCALE_ARCHIVE search path like
396 ;; Nixpkgs does.
397 (outputs '("out" "locales" "debug"))
398
399 (arguments
400 `(#:out-of-source? #t
401 #:configure-flags
402 (list "--enable-add-ons"
403 "--sysconfdir=/etc"
404 (string-append "--localedir=" (assoc-ref %outputs "locales")
405 "/share/locale")
406
407 ;; `--localedir' is not honored, so work around it.
408 ;; See <http://sourceware.org/ml/libc-alpha/2013-03/msg00093.html>.
409 (string-append "libc_cv_localedir="
410 (assoc-ref %outputs "locales")
411 "/share/locale")
412
413 (string-append "--with-headers="
414 (assoc-ref %build-inputs "linux-headers")
415 "/include")
416
417 ;; The default is to assume a 2.4 Linux interface, but we'll
418 ;; always use something newer. See "kernel-features.h" in the
419 ;; GNU libc for details.
420 "--enable-kernel=2.6.30"
421
422 ;; Use our Bash instead of /bin/sh.
423 (string-append "BASH_SHELL="
424 (assoc-ref %build-inputs "bash")
425 "/bin/bash")
426
427 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
428 "libc_cv_ssp=no")
429
430 #:tests? #f ; XXX
431 #:phases (alist-cons-before
432 'configure 'pre-configure
433 (lambda* (#:key inputs outputs #:allow-other-keys)
434 (let* ((out (assoc-ref outputs "out"))
435 (bin (string-append out "/bin")))
436 ;; Use `pwd', not `/bin/pwd'.
437 (substitute* "configure"
438 (("/bin/pwd") "pwd"))
439
440 ;; Install the rpc data base file under `$out/etc/rpc'.
441 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
442 (substitute* "sunrpc/Makefile"
443 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
444 (string-append out "/etc/rpc" suffix "\n"))
445 (("^install-others =.*$")
446 (string-append "install-others = " out "/etc/rpc\n")))
447
448 (substitute* "Makeconfig"
449 ;; According to
450 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
451 ;; linking against libgcc_s is not needed with GCC
452 ;; 4.7.1.
453 ((" -lgcc_s") ""))
454
455 ;; Copy a statically-linked Bash in the output, with
456 ;; no references to other store paths.
457 (mkdir-p bin)
458 (copy-file (string-append (assoc-ref inputs "static-bash")
459 "/bin/bash")
460 (string-append bin "/bash"))
461 (remove-store-references (string-append bin "/bash"))
462 (chmod (string-append bin "/bash") #o555)
463
464 ;; Keep a symlink, for `patch-shebang' resolution.
465 (with-directory-excursion bin
466 (symlink "bash" "sh"))
467
468 ;; Have `system' use that Bash.
469 (substitute* "sysdeps/posix/system.c"
470 (("#define[[:blank:]]+SHELL_PATH.*$")
471 (format #f "#define SHELL_PATH \"~a/bin/bash\"\n"
472 out)))
473
474 ;; Same for `popen'.
475 (substitute* "libio/iopopen.c"
476 (("/bin/sh")
477 (string-append out "/bin/bash")))
478
479 ;; Make sure we don't retain a reference to the
480 ;; bootstrap Perl.
481 (substitute* "malloc/mtrace.pl"
482 (("^#!.*")
483 ;; The shebang can be omitted, because there's the
484 ;; "bilingual" eval/exec magic at the top of the file.
485 "")
486 (("exec @PERL@")
487 "exec perl"))))
488 (alist-cons-after
489 'install 'install-locales
490 (lambda _
491 (zero? (system* "make" "localedata/install-locales")))
492 %standard-phases))))
493
494 (inputs `(("static-bash" ,(static-package bash-light))))
495
496 ;; To build the manual, we need Texinfo and Perl.
497 (native-inputs `(("texinfo" ,texinfo)
498 ("perl" ,perl)))
499
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 "2014a")
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 "1cg843ajz4g16axpz56zvalwsbp1s764na2bk4fb44ayx162bzvw"))))
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 source inputs #:allow-other-keys)
548 (and (zero? (system* "tar" "xvf" 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 "1xfkqi1q8cnxqbv8azdj5pqlzhkjz6xag09f1z0s8rxi86jkpf85"))))))
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 ;; Don't attempt to build 'guile.c' since we don't
598 ;; have Guile here.
599 (substitute* "build.sh"
600 (("guile\\.\\$\\{OBJEXT\\}") ""))
601 (zero? (system* "./build.sh")))
602 (alist-replace
603 'install (lambda* (#:key outputs #:allow-other-keys)
604 (let* ((out (assoc-ref outputs "out"))
605 (bin (string-append out "/bin")))
606 (mkdir-p bin)
607 (copy-file "make"
608 (string-append bin "/make"))))
609 ,phases))))))
610 (native-inputs '()) ; no need for 'pkg-config'
611 (inputs %bootstrap-inputs))))
612
613 (define diffutils-boot0
614 (package-with-bootstrap-guile
615 (let ((p (package-with-explicit-inputs diffutils
616 `(("make" ,gnu-make-boot0)
617 ,@%bootstrap-inputs)
618 #:guile %bootstrap-guile)))
619 (package (inherit p)
620 (location (source-properties->location (current-source-location)))
621 (arguments `(#:tests? #f ; the test suite needs diffutils
622 ,@(package-arguments p)))))))
623
624 (define findutils-boot0
625 (package-with-bootstrap-guile
626 (package-with-explicit-inputs findutils
627 `(("make" ,gnu-make-boot0)
628 ("diffutils" ,diffutils-boot0) ; for tests
629 ,@%bootstrap-inputs)
630 (current-source-location)
631 #:guile %bootstrap-guile)))
632
633
634 (define %boot0-inputs
635 `(("make" ,gnu-make-boot0)
636 ("diffutils" ,diffutils-boot0)
637 ("findutils" ,findutils-boot0)
638 ,@%bootstrap-inputs))
639
640 (define* (nix-system->gnu-triplet
641 #:optional (system (%current-system)) (vendor "unknown"))
642 "Return an a guess of the GNU triplet corresponding to Nix system
643 identifier SYSTEM."
644 (let* ((dash (string-index system #\-))
645 (arch (substring system 0 dash))
646 (os (substring system (+ 1 dash))))
647 (string-append arch
648 "-" vendor "-"
649 (if (string=? os "linux")
650 "linux-gnu"
651 os))))
652
653 (define* (boot-triplet #:optional (system (%current-system)))
654 ;; Return the triplet used to create the cross toolchain needed in the
655 ;; first bootstrapping stage.
656 (nix-system->gnu-triplet system "guix"))
657
658 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
659 ;; toolchain actually targets the same OS and arch, but it has the advantage
660 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
661 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
662
663 (define binutils-boot0
664 (package-with-bootstrap-guile
665 (package (inherit binutils)
666 (name "binutils-cross-boot0")
667 (arguments
668 `(#:guile ,%bootstrap-guile
669 #:implicit-inputs? #f
670 ,@(substitute-keyword-arguments (package-arguments binutils)
671 ((#:configure-flags cf)
672 `(cons ,(string-append "--target=" (boot-triplet))
673 ,cf)))))
674 (inputs %boot0-inputs))))
675
676 (define gcc-boot0
677 (package-with-bootstrap-guile
678 (package (inherit gcc-4.8)
679 (name "gcc-cross-boot0")
680 (arguments
681 `(#:guile ,%bootstrap-guile
682 #:implicit-inputs? #f
683 #:modules ((guix build gnu-build-system)
684 (guix build utils)
685 (ice-9 regex)
686 (srfi srfi-1)
687 (srfi srfi-26))
688 ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
689 ((#:configure-flags flags)
690 `(append (list ,(string-append "--target=" (boot-triplet))
691
692 ;; No libc yet.
693 "--without-headers"
694
695 ;; Disable features not needed at this stage.
696 "--disable-shared"
697 "--enable-languages=c,c++"
698
699 ;; libstdc++ cannot be built at this stage
700 ;; ("Link tests are not allowed after
701 ;; GCC_NO_EXECUTABLES.").
702 "--disable-libstdc++-v3"
703
704 "--disable-threads"
705 "--disable-libmudflap"
706 "--disable-libatomic"
707 "--disable-libsanitizer"
708 "--disable-libitm"
709 "--disable-libgomp"
710 "--disable-libssp"
711 "--disable-libquadmath"
712 "--disable-decimal-float")
713 (remove (cut string-match "--enable-languages.*" <>)
714 ,flags)))
715 ((#:phases phases)
716 `(alist-cons-after
717 'unpack 'unpack-gmp&co
718 (lambda* (#:key inputs #:allow-other-keys)
719 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
720 (mpfr (assoc-ref %build-inputs "mpfr-source"))
721 (mpc (assoc-ref %build-inputs "mpc-source")))
722
723 ;; To reduce the set of pre-built bootstrap inputs, build
724 ;; GMP & co. from GCC.
725 (for-each (lambda (source)
726 (or (zero? (system* "tar" "xvf" source))
727 (error "failed to unpack tarball"
728 source)))
729 (list gmp mpfr mpc))
730
731 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
732 ,@(map (lambda (lib)
733 `(symlink ,(package-full-name lib)
734 ,(package-name lib)))
735 (list gmp mpfr mpc))))
736 (alist-cons-after
737 'install 'symlink-libgcc_eh
738 (lambda* (#:key outputs #:allow-other-keys)
739 (let ((out (assoc-ref outputs "out")))
740 ;; Glibc wants to link against libgcc_eh, so provide
741 ;; it.
742 (with-directory-excursion
743 (string-append out "/lib/gcc/"
744 ,(boot-triplet)
745 "/" ,(package-version gcc-4.8))
746 (symlink "libgcc.a" "libgcc_eh.a"))))
747 ,phases))))))
748
749 (inputs `(("gmp-source" ,(package-source gmp))
750 ("mpfr-source" ,(package-source mpfr))
751 ("mpc-source" ,(package-source mpc))
752 ("binutils-cross" ,binutils-boot0)
753
754 ;; Call it differently so that the builder can check whether
755 ;; the "libc" input is #f.
756 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
757 ,@(alist-delete "libc" %boot0-inputs)))
758
759 ;; No need for Texinfo at this stage.
760 (native-inputs (alist-delete "texinfo"
761 (package-native-inputs gcc-4.8))))))
762
763 (define perl-boot0
764 (package-with-bootstrap-guile
765 (package-with-explicit-inputs perl
766 %boot0-inputs
767 (current-source-location)
768 #:guile %bootstrap-guile)))
769
770 (define (linux-libre-headers-boot0)
771 "Return Linux-Libre header files for the bootstrap environment."
772 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
773 ;; between (gnu packages linux) and this module.
774 (package-with-bootstrap-guile
775 (package (inherit linux-libre-headers)
776 (arguments `(#:guile ,%bootstrap-guile
777 #:implicit-inputs? #f
778 ,@(package-arguments linux-libre-headers)))
779 (native-inputs
780 `(("perl" ,perl-boot0)
781 ,@%boot0-inputs)))))
782
783 (define texinfo-boot0
784 ;; Texinfo used to build libc's manual.
785 ;; We build without ncurses because it fails to build at this stage, and
786 ;; because we don't need the stand-alone Info reader.
787 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
788 (let ((texinfo (package (inherit texinfo)
789 (inputs (alist-delete "ncurses" (package-inputs texinfo))))))
790 (package-with-bootstrap-guile
791 (package-with-explicit-inputs texinfo %boot0-inputs
792 (current-source-location)
793 #:guile %bootstrap-guile))))
794
795 (define %boot1-inputs
796 ;; 2nd stage inputs.
797 `(("gcc" ,gcc-boot0)
798 ("binutils-cross" ,binutils-boot0)
799
800 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
801 ;; cross-`as'.
802 ,@%boot0-inputs))
803
804 (define glibc-final-with-bootstrap-bash
805 ;; The final libc, "cross-built". If everything went well, the resulting
806 ;; store path has no dependencies. Actually, the really-final libc is
807 ;; built just below; the only difference is that this one uses the
808 ;; bootstrap Bash.
809 (package-with-bootstrap-guile
810 (package (inherit glibc)
811 (name "glibc-intermediate")
812 (arguments
813 `(#:guile ,%bootstrap-guile
814 #:implicit-inputs? #f
815
816 ,@(substitute-keyword-arguments (package-arguments glibc)
817 ((#:configure-flags flags)
818 `(append (list ,(string-append "--host=" (boot-triplet))
819 ,(string-append "--build="
820 (nix-system->gnu-triplet))
821
822 ;; Build Sun/ONC RPC support. In particular,
823 ;; install rpc/*.h.
824 "--enable-obsolete-rpc")
825 ,flags)))))
826 (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0))))
827 (native-inputs
828 `(("texinfo" ,texinfo-boot0)
829 ("perl" ,perl-boot0)))
830 (inputs
831 `( ;; A native GCC is needed to build `cross-rpcgen'.
832 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
833
834 ;; Here, we use the bootstrap Bash, which is not satisfactory
835 ;; because we don't want to depend on bootstrap tools.
836 ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))
837
838 ,@%boot1-inputs
839 ,@(alist-delete "static-bash"
840 (package-inputs glibc))))))) ; patches
841
842 (define (cross-gcc-wrapper gcc binutils glibc bash)
843 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
844 that makes it available under the native tool names."
845 (package (inherit gcc-4.8)
846 (name (string-append (package-name gcc) "-wrapped"))
847 (source #f)
848 (build-system trivial-build-system)
849 (arguments
850 `(#:guile ,%bootstrap-guile
851 #:modules ((guix build utils))
852 #:builder (begin
853 (use-modules (guix build utils))
854
855 (let* ((binutils (assoc-ref %build-inputs "binutils"))
856 (gcc (assoc-ref %build-inputs "gcc"))
857 (libc (assoc-ref %build-inputs "libc"))
858 (bash (assoc-ref %build-inputs "bash"))
859 (out (assoc-ref %outputs "out"))
860 (bindir (string-append out "/bin"))
861 (triplet ,(boot-triplet)))
862 (define (wrap-program program)
863 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
864 ;; needs to be told where to find the crt files and
865 ;; the dynamic linker.
866 (call-with-output-file program
867 (lambda (p)
868 (format p "#!~a/bin/bash
869 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
870 bash
871 gcc triplet program
872 libc libc
873 ,(glibc-dynamic-linker))))
874
875 (chmod program #o555))
876
877 (mkdir-p bindir)
878 (with-directory-excursion bindir
879 (for-each (lambda (tool)
880 (symlink (string-append binutils "/bin/"
881 triplet "-" tool)
882 tool))
883 '("ar" "ranlib"))
884 (for-each wrap-program '("gcc" "g++")))))))
885 (native-inputs
886 `(("binutils" ,binutils)
887 ("gcc" ,gcc)
888 ("libc" ,glibc)
889 ("bash" ,bash)))
890 (inputs '())))
891
892 (define static-bash-for-glibc
893 ;; A statically-linked Bash to be embedded in GLIBC-FINAL, for use by
894 ;; system(3) & co.
895 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
896 glibc-final-with-bootstrap-bash
897 (car (assoc-ref %boot1-inputs "bash"))))
898 (bash (package (inherit bash-light)
899 (arguments
900 `(#:guile ,%bootstrap-guile
901 ,@(package-arguments bash-light))))))
902 (package-with-bootstrap-guile
903 (package-with-explicit-inputs (static-package bash)
904 `(("gcc" ,gcc)
905 ("libc" ,glibc-final-with-bootstrap-bash)
906 ,@(fold alist-delete %boot1-inputs
907 '("gcc" "libc")))
908 (current-source-location)))))
909
910 (define-public glibc-final
911 ;; The final glibc, which embeds the statically-linked Bash built above.
912 (package (inherit glibc-final-with-bootstrap-bash)
913 (name "glibc")
914 (inputs `(("static-bash" ,static-bash-for-glibc)
915 ,@(alist-delete
916 "static-bash"
917 (package-inputs glibc-final-with-bootstrap-bash))))))
918
919 (define gcc-boot0-wrapped
920 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
921 ;; non-cross names.
922 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
923 (car (assoc-ref %boot1-inputs "bash"))))
924
925 (define %boot2-inputs
926 ;; 3rd stage inputs.
927 `(("libc" ,glibc-final)
928 ("gcc" ,gcc-boot0-wrapped)
929 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
930
931 (define binutils-final
932 (package-with-bootstrap-guile
933 (package (inherit binutils)
934 (arguments
935 `(#:guile ,%bootstrap-guile
936 #:implicit-inputs? #f
937 ,@(package-arguments binutils)))
938 (inputs %boot2-inputs))))
939
940 (define libstdc++
941 ;; Intermediate libstdc++ that will allow us to build the final GCC
942 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
943 (package-with-bootstrap-guile
944 (package (inherit gcc-4.8)
945 (name "libstdc++")
946 (arguments
947 `(#:guile ,%bootstrap-guile
948 #:implicit-inputs? #f
949
950 #:out-of-source? #t
951 #:phases (alist-cons-before
952 'configure 'chdir
953 (lambda _
954 (chdir "libstdc++-v3"))
955 %standard-phases)
956 #:configure-flags `("--disable-shared"
957 "--disable-libstdcxx-threads"
958 "--disable-libstdcxx-pch"
959 ,(string-append "--with-gxx-include-dir="
960 (assoc-ref %outputs "out")
961 "/include"
962 ;; "/include/c++/"
963 ;; ,(package-version gcc-4.8)
964 ))))
965 (inputs %boot2-inputs)
966 (native-inputs '())
967 (propagated-inputs '())
968 (synopsis "GNU C++ standard library (intermediate)"))))
969
970 (define-public gcc-final
971 ;; The final GCC.
972 (package (inherit gcc-boot0)
973 (name "gcc")
974 (arguments
975 `(#:guile ,%bootstrap-guile
976 #:implicit-inputs? #f
977
978 ;; Build again GMP & co. within GCC's build process, because it's hard
979 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
980 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
981 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
982 ((#:configure-flags boot-flags)
983 (let loop ((args (package-arguments gcc-4.8)))
984 (match args
985 ((#:configure-flags normal-flags _ ...)
986 normal-flags)
987 ((_ rest ...)
988 (loop rest)))))
989 ((#:make-flags flags)
990 ;; Since $LIBRARY_PATH and $CPATH are not honored, add the
991 ;; relevant flags.
992 `(cons (string-append "CPPFLAGS=-I"
993 (assoc-ref %build-inputs "libstdc++")
994 "/include")
995 (map (lambda (flag)
996 (if (string-prefix? "LDFLAGS=" flag)
997 (string-append flag " -L"
998 (assoc-ref %build-inputs "libstdc++")
999 "/lib")
1000 flag))
1001 ,flags)))
1002 ((#:phases phases)
1003 `(alist-delete 'symlink-libgcc_eh ,phases)))))
1004
1005 (inputs `(("gmp-source" ,(package-source gmp))
1006 ("mpfr-source" ,(package-source mpfr))
1007 ("mpc-source" ,(package-source mpc))
1008 ("binutils" ,binutils-final)
1009 ("libstdc++" ,libstdc++)
1010 ,@%boot2-inputs))))
1011
1012 (define ld-wrapper-boot3
1013 ;; A linker wrapper that uses the bootstrap Guile.
1014 (package
1015 (name "ld-wrapper-boot3")
1016 (version "0")
1017 (source #f)
1018 (build-system trivial-build-system)
1019 (inputs `(("binutils" ,binutils-final)
1020 ("guile" ,%bootstrap-guile)
1021 ("bash" ,@(assoc-ref %boot2-inputs "bash"))
1022 ("wrapper" ,(search-path %load-path
1023 "gnu/packages/ld-wrapper.scm"))))
1024 (arguments
1025 `(#:guile ,%bootstrap-guile
1026 #:modules ((guix build utils))
1027 #:builder (begin
1028 (use-modules (guix build utils)
1029 (system base compile))
1030
1031 (let* ((out (assoc-ref %outputs "out"))
1032 (bin (string-append out "/bin"))
1033 (ld (string-append bin "/ld"))
1034 (go (string-append bin "/ld.go")))
1035
1036 (setvbuf (current-output-port) _IOLBF)
1037 (format #t "building ~s/bin/ld wrapper in ~s~%"
1038 (assoc-ref %build-inputs "binutils")
1039 out)
1040
1041 (mkdir-p bin)
1042 (copy-file (assoc-ref %build-inputs "wrapper") ld)
1043 (substitute* ld
1044 (("@GUILE@")
1045 (string-append (assoc-ref %build-inputs "guile")
1046 "/bin/guile"))
1047 (("@BASH@")
1048 (string-append (assoc-ref %build-inputs "bash")
1049 "/bin/bash"))
1050 (("@LD@")
1051 (string-append (assoc-ref %build-inputs "binutils")
1052 "/bin/ld")))
1053 (chmod ld #o555)
1054 (compile-file ld #:output-file go)))))
1055 (synopsis "The linker wrapper")
1056 (description
1057 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
1058 missing `-rpath' flags, and to detect any misuse of libraries outside of the
1059 store.")
1060 (home-page #f)
1061 (license gpl3+)))
1062
1063 (define %boot3-inputs
1064 ;; 4th stage inputs.
1065 `(("gcc" ,gcc-final)
1066 ("ld-wrapper" ,ld-wrapper-boot3)
1067 ,@(alist-delete "gcc" %boot2-inputs)))
1068
1069 (define bash-final
1070 ;; Link with `-static-libgcc' to make sure we don't retain a reference
1071 ;; to the bootstrap GCC.
1072 (package-with-bootstrap-guile
1073 (package-with-explicit-inputs (static-libgcc-package bash)
1074 %boot3-inputs
1075 (current-source-location)
1076 #:guile %bootstrap-guile)))
1077
1078 (define %boot4-inputs
1079 ;; Now use the final Bash.
1080 `(("bash" ,bash-final)
1081 ,@(alist-delete "bash" %boot3-inputs)))
1082
1083 (define-public guile-final
1084 (package-with-bootstrap-guile
1085 (package-with-explicit-inputs guile-2.0/fixed
1086 %boot4-inputs
1087 (current-source-location)
1088 #:guile %bootstrap-guile)))
1089
1090 (define gnu-make-final
1091 ;; The final GNU Make, which uses the final Guile.
1092 (package-with-bootstrap-guile
1093 (package-with-explicit-inputs gnu-make
1094 `(("guile" ,guile-final)
1095 ,@%boot4-inputs)
1096 (current-source-location))))
1097
1098 (define-public ld-wrapper
1099 ;; The final `ld' wrapper, which uses the final Guile.
1100 (package (inherit ld-wrapper-boot3)
1101 (name "ld-wrapper")
1102 (inputs `(("guile" ,guile-final)
1103 ("bash" ,bash-final)
1104 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
1105 '("guile" "bash"))))))
1106
1107 (define-public %final-inputs
1108 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
1109 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
1110 ;; used for origins that have patches, thereby avoiding circular
1111 ;; dependencies.
1112 (let ((finalize (compose package-with-bootstrap-guile
1113 (cut package-with-explicit-inputs <> %boot4-inputs
1114 (current-source-location)))))
1115 `(,@(map (match-lambda
1116 ((name package)
1117 (list name (finalize package))))
1118 `(("tar" ,tar)
1119 ("gzip" ,gzip)
1120 ("bzip2" ,bzip2)
1121 ("xz" ,xz)
1122 ("diffutils" ,diffutils)
1123 ("patch" ,patch)
1124 ("coreutils" ,coreutils)
1125 ("sed" ,sed)
1126 ("grep" ,grep)
1127 ("findutils" ,findutils)
1128 ("gawk" ,gawk)))
1129 ("make" ,gnu-make-final)
1130 ("bash" ,bash-final)
1131 ("ld-wrapper" ,ld-wrapper)
1132 ("binutils" ,binutils-final)
1133 ("gcc" ,gcc-final)
1134 ("libc" ,glibc-final))))
1135
1136 ;;; base.scm ends here