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