Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / distro / packages / base.scm
1 ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2 ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright (C) 2012 Nikita Karetnikov <nikita@karetnikov.org>
4 ;;;
5 ;;; This file is part of Guix.
6 ;;;
7 ;;; 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 ;;; 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 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 bash)
24 #:use-module (distro packages bootstrap)
25 #:use-module (distro packages compression)
26 #:use-module (distro packages gawk)
27 #:use-module (distro packages guile)
28 #:use-module (distro packages multiprecision)
29 #:use-module (distro packages perl)
30 #:use-module (distro packages linux)
31 #:use-module (guix packages)
32 #:use-module (guix download)
33 #:use-module (guix build-system gnu)
34 #:use-module (guix build-system trivial)
35 #:use-module (guix utils)
36 #:use-module (srfi srfi-1)
37 #:use-module (srfi srfi-26)
38 #:use-module (ice-9 match))
39
40 ;;; Commentary:
41 ;;;
42 ;;; Base packages of the Guix-based GNU user-land software distribution.
43 ;;;
44 ;;; Code:
45
46 (define-public hello
47 (package
48 (name "hello")
49 (version "2.8")
50 (source (origin
51 (method url-fetch)
52 (uri (string-append "mirror://gnu/hello/hello-" version
53 ".tar.gz"))
54 (sha256
55 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
56 (build-system gnu-build-system)
57 (arguments '(#:configure-flags
58 `("--disable-dependency-tracking"
59 ,(string-append "--with-gawk=" ; for illustration purposes
60 (assoc-ref %build-inputs "gawk")))))
61 (inputs `(("gawk" ,gawk)))
62 (synopsis "GNU Hello")
63 (description "Yeah...")
64 (home-page "http://www.gnu.org/software/hello/")
65 (license gpl3+)))
66
67 (define-public grep
68 (package
69 (name "grep")
70 (version "2.14")
71 (source (origin
72 (method url-fetch)
73 (uri (string-append "mirror://gnu/grep/grep-"
74 version ".tar.xz"))
75 (sha256
76 (base32
77 "1qbjb1l7f9blckc5pqy8jlf6482hpx4awn2acmhyf5mv9wfq03p7"))))
78 (build-system gnu-build-system)
79 (synopsis "GNU implementation of the Unix grep command")
80 (description
81 "The grep command searches one or more input files for lines containing a
82 match to a specified pattern. By default, grep prints the matching
83 lines.")
84 (license gpl3+)
85 (home-page "http://www.gnu.org/software/grep/")))
86
87 (define-public sed
88 (package
89 (name "sed")
90 (version "4.2.1")
91 (source (origin
92 (method url-fetch)
93 (uri (string-append "mirror://gnu/sed/sed-" version
94 ".tar.bz2"))
95 (sha256
96 (base32
97 "13wlsb4sf5d5a82xjhxqmdvrrn36rmw5f0pl9qyb9zkvldnb7hra"))))
98 (build-system gnu-build-system)
99 (synopsis "GNU sed, a batch stream editor")
100 (description
101 "Sed (stream editor) isn't really a true text editor or text processor.
102 Instead, it is used to filter text, i.e., it takes text input and performs
103 some operation (or set of operations) on it and outputs the modified text.
104 Sed is typically used for extracting part of a file using pattern matching or
105 substituting multiple occurrences of a string within a file.")
106 (license gpl3+)
107 (home-page "http://www.gnu.org/software/sed/")))
108
109 (define-public tar
110 (package
111 (name "tar")
112 (version "1.26")
113 (source (origin
114 (method url-fetch)
115 (uri (string-append "mirror://gnu/tar/tar-"
116 version ".tar.bz2"))
117 (sha256
118 (base32
119 "0hbdkzmchq9ycr2x1pxqdcgdbaxksh8c6ac0jf75jajhcks6jlss"))))
120 (build-system gnu-build-system)
121 (inputs `(("patch/gets" ,(search-patch "tar-gets-undeclared.patch"))))
122 (arguments
123 `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
124 (synopsis "GNU implementation of the `tar' archiver")
125 (description
126 "The Tar program provides the ability to create tar archives, as well as
127 various other kinds of manipulation. For example, you can use Tar on
128 previously created archives to extract files, to store additional files, or
129 to update or list files which were already stored.
130
131 Initially, tar archives were used to store files conveniently on magnetic
132 tape. The name \"Tar\" comes from this use; it stands for tape archiver.
133 Despite the utility's name, Tar can direct its output to available devices,
134 files, or other programs (using pipes), it can even access remote devices or
135 files (as archives).")
136 (license gpl3+)
137 (home-page "http://www.gnu.org/software/tar/")))
138
139 (define-public patch
140 (package
141 (name "patch")
142 (version "2.6.1")
143 (source (origin
144 (method url-fetch)
145 (uri (string-append "mirror://gnu/patch/patch-"
146 version ".tar.xz"))
147 (sha256
148 (base32
149 "18012gxs9wc96izskp1q7bclrwns6rdmkn4jj31c8jbyfz6l5npq"))))
150 (build-system gnu-build-system)
151 (native-inputs '()) ; FIXME: needs `ed' for the tests
152 (arguments
153 (case-lambda
154 ((system) '(#:tests? #f))
155 ((system cross-system)
156 '(#:configure-flags '("ac_cv_func_strnlen_working=yes")))))
157 (synopsis "GNU Patch, a program to apply differences to files")
158 (description
159 "GNU Patch takes a patch file containing a difference listing produced by
160 the diff program and applies those differences to one or more original files,
161 producing patched versions.")
162 (license gpl3+)
163 (home-page "http://savannah.gnu.org/projects/patch/")))
164
165 (define-public diffutils
166 (package
167 (name "diffutils")
168 (version "3.2")
169 (source (origin
170 (method url-fetch)
171 (uri (string-append "mirror://gnu/diffutils/diffutils-"
172 version ".tar.xz"))
173 (sha256
174 (base32
175 "0jci0wv68025xd0s0rq4s5qxpx56dd9d730lka63qpzk1rfvfkxb"))))
176 (build-system gnu-build-system)
177 (inputs `(("patch/gets"
178 ,(search-patch "diffutils-gets-undeclared.patch"))))
179 (arguments `(#:patches (list (assoc-ref %build-inputs "patch/gets"))))
180 (synopsis "Programs to find differences among text files")
181 (description
182 "GNU Diffutils is a package of several programs related to finding
183 differences between files.
184
185 Computer users often find occasion to ask how two files differ. Perhaps one
186 file is a newer version of the other file. Or maybe the two files started out
187 as identical copies but were changed by different people.
188
189 You can use the diff command to show differences between two files, or each
190 corresponding file in two directories. diff outputs differences between files
191 line by line in any of several formats, selectable by command line
192 options. This set of differences is often called a ‘diff’ or ‘patch’. For
193 files that are identical, diff normally produces no output; for
194 binary (non-text) files, diff normally reports only that they are different.
195
196 You can use the cmp command to show the offsets and line numbers where two
197 files differ. cmp can also show all the characters that differ between the
198 two files, side by side.
199
200 You can use the diff3 command to show differences among three files. When two
201 people have made independent changes to a common original, diff3 can report
202 the differences between the original and the two changed versions, and can
203 produce a merged file that contains both persons' changes together with
204 warnings about conflicts.
205
206 You can use the sdiff command to merge two files interactively.")
207 (license gpl3+)
208 (home-page "http://www.gnu.org/software/diffutils/")))
209
210 (define-public findutils
211 (package
212 (name "findutils")
213 (version "4.4.2")
214 (source (origin
215 (method url-fetch)
216 (uri (string-append "mirror://gnu/findutils/findutils-"
217 version ".tar.gz"))
218 (sha256
219 (base32
220 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"))))
221 (build-system gnu-build-system)
222 (native-inputs
223 `(("patch/absolute-paths"
224 ,(search-patch "findutils-absolute-paths.patch"))))
225 (arguments
226 (case-lambda
227 ((system)
228 `(#:patches (list (assoc-ref %build-inputs "patch/absolute-paths"))))
229 ((system cross-system)
230 ;; Work around cross-compilation failure.
231 ;; See <http://savannah.gnu.org/bugs/?27299#comment1>.
232 `(#:configure-flags '("gl_cv_func_wcwidth_works=yes")
233 ,@(arguments cross-system)))))
234 (synopsis "Basic directory searching utilities of the GNU operating
235 system")
236 (description
237 "The GNU Find Utilities are the basic directory searching utilities of
238 the GNU operating system. These programs are typically used in conjunction
239 with other programs to provide modular and powerful directory search and file
240 locating capabilities to other commands.
241
242 The tools supplied with this package are:
243
244 * find - search for files in a directory hierarchy;
245 * locate - list files in databases that match a pattern;
246 * updatedb - update a file name database;
247 * xargs - build and execute command lines from standard input.
248 ")
249 (license gpl3+)
250 (home-page "http://www.gnu.org/software/findutils/")))
251
252 (define-public coreutils
253 (package
254 (name "coreutils")
255 (version "8.19")
256 (source (origin
257 (method url-fetch)
258 (uri (string-append "mirror://gnu/coreutils/coreutils-"
259 version ".tar.xz"))
260 (sha256
261 (base32
262 "1rx9x3fp848w4nny7irdkcpkan9fcx24d99v5dkwgkyq7wc76f5d"))))
263 (build-system gnu-build-system)
264 (inputs `()) ; TODO: optional deps: SELinux, ACL, GMP
265 (arguments
266 '(;; Perl is missing, and some tests are failing.
267 #:tests? #f))
268 (synopsis
269 "The basic file, shell and text manipulation utilities of the GNU
270 operating system")
271 (description
272 "The GNU Core Utilities are the basic file, shell and text manipulation
273 utilities of the GNU operating system. These are the core utilities which
274 are expected to exist on every operating system.")
275 (license gpl3+)
276 (home-page "http://www.gnu.org/software/coreutils/")))
277
278 (define-public gnu-make
279 (package
280 (name "make")
281 (version "3.82")
282 (source (origin
283 (method url-fetch)
284 (uri (string-append "mirror://gnu/make/make-" version
285 ".tar.bz2"))
286 (sha256
287 (base32
288 "0ri98385hsd7li6rh4l5afcq92v8l2lgiaz85wgcfh4w2wzsghg2"))))
289 (build-system gnu-build-system)
290 (native-inputs
291 `(("patch/impure-dirs" ,(search-patch "make-impure-dirs.patch"))))
292 (arguments `(#:patches (list (assoc-ref %build-inputs
293 "patch/impure-dirs"))))
294 (synopsis "GNU Make, a program controlling the generation of non-source
295 files from sources")
296 (description
297 "Make is a tool which controls the generation of executables and other
298 non-source files of a program from the program's source files.
299
300 Make gets its knowledge of how to build your program from a file called the
301 makefile, which lists each of the non-source files and how to compute it from
302 other files. When you write a program, you should write a makefile for it, so
303 that it is possible to use Make to build and install the program.")
304 (license gpl3+)
305 (home-page "http://www.gnu.org/software/make/")))
306
307 (define-public binutils
308 (package
309 (name "binutils")
310 (version "2.22")
311 (source (origin
312 (method url-fetch)
313 (uri (string-append "mirror://gnu/binutils/binutils-"
314 version ".tar.bz2"))
315 (sha256
316 (base32
317 "1a9w66v5dwvbnawshjwqcgz7km6kw6ihkzp6sswv9ycc3knzhykc"))))
318 (build-system gnu-build-system)
319
320 ;; TODO: Add dependency on zlib + those for Gold.
321 (native-inputs
322 `(("patch/new-dtags" ,(search-patch "binutils-ld-new-dtags.patch"))))
323 (arguments
324 `(#:patches (list (assoc-ref %build-inputs "patch/new-dtags"))
325 #:configure-flags '(;; Add `-static-libgcc' to not retain a dependency
326 ;; on GCC when bootstrapping.
327 "LDFLAGS=-static-libgcc"
328
329 ;; Don't search under /usr/lib & co.
330 "--with-lib-path=/no-ld-lib-path")))
331
332 (synopsis "GNU Binutils, tools for manipulating binaries (linker,
333 assembler, etc.)")
334 (description
335 "The GNU Binutils are a collection of binary tools. The main ones are
336 `ld' (the GNU linker) and `as' (the GNU assembler). They also include the
337 BFD (Binary File Descriptor) library, `gprof', `nm', `strip', etc.")
338 (license gpl3+)
339 (home-page "http://www.gnu.org/software/binutils/")))
340
341 (define-public gcc-4.7
342 (let ((stripped? #t)) ; TODO: make this a parameter
343 (package
344 (name "gcc")
345 (version "4.7.2")
346 (source (origin
347 (method url-fetch)
348 (uri (string-append "mirror://gnu/gcc/gcc-"
349 version "/gcc-" version ".tar.bz2"))
350 (sha256
351 (base32
352 "115h03hil99ljig8lkrq4qk426awmzh0g99wrrggxf8g07bq74la"))))
353 (build-system gnu-build-system)
354 (inputs `(("gmp" ,gmp)
355 ("mpfr" ,mpfr)
356 ("mpc" ,mpc))) ; TODO: libelf, ppl, cloog, zlib, etc.
357 (arguments
358 (lambda (system)
359 `(#:out-of-source? #t
360 #:strip-binaries? ,stripped?
361 #:configure-flags
362 `("--enable-plugin"
363 "--enable-languages=c,c++"
364 "--disable-multilib"
365
366 "--with-local-prefix=/no-gcc-local-prefix"
367
368 ,(let ((libc (assoc-ref %build-inputs "libc")))
369 (if libc
370 (string-append "--with-native-system-header-dir=" libc
371 "/include")
372 "--without-headers")))
373 #:make-flags
374 (let ((libc (assoc-ref %build-inputs "libc")))
375 `(,@(if libc
376 (list (string-append "LDFLAGS_FOR_BUILD="
377 "-L" libc "/lib "
378 "-Wl,-dynamic-linker "
379 "-Wl," libc
380 ,(glibc-dynamic-linker system)))
381 '())
382 ,(string-append "BOOT_CFLAGS=-O2 "
383 ,(if stripped? "-g0" "-g"))))
384
385 #:tests? #f
386 #:phases
387 (alist-cons-before
388 'configure 'pre-configure
389 (lambda* (#:key inputs outputs #:allow-other-keys)
390 (let ((out (assoc-ref outputs "out"))
391 (libc (assoc-ref inputs "libc")))
392 (when libc
393 ;; The following is not performed for `--without-headers'
394 ;; cross-compiler builds.
395
396 ;; Fix the dynamic linker's file name.
397 (substitute* (find-files "gcc/config"
398 "^linux(64|-elf)?\\.h$")
399 (("#define GLIBC_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
400 (format #f "#define GLIBC_DYNAMIC_LINKER~a \"~a\"~%"
401 suffix
402 (string-append libc ,(glibc-dynamic-linker system)))))
403
404 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
405 ;; `crt{begin,end}.o', which come with GCC.
406 (substitute* (find-files "gcc/config"
407 "^(gnu-user(64)?|linux-elf)\\.h$")
408 (("#define LIB_SPEC (.*)$" _ suffix)
409 ;; Note that with this "lib" spec, we may still add a
410 ;; RUNPATH to GCC even when `libgcc_s' is not NEEDED.
411 ;; There's not much that can be done to avoid it, though.
412 (format #f "#define LIB_SPEC \"-L~a/lib %{!static:-rpath=~a/lib \
413 %{!static-libgcc:-rpath=~a/lib64 -rpath=~a/lib}} \" ~a~%"
414 libc libc out out suffix))
415 (("#define STARTFILE_SPEC.*$" line)
416 (format #f "#define STANDARD_STARTFILE_PREFIX_1 \"~a/lib\"
417 #define STANDARD_STARTFILE_PREFIX_2 \"\"
418 ~a~%"
419 libc line))))
420
421 ;; Don't retain a dependency on the build-time sed.
422 (substitute* "fixincludes/fixincl.x"
423 (("static char const sed_cmd_z\\[\\] =.*;")
424 "static char const sed_cmd_z[] = \"sed\";"))))
425
426 (alist-cons-after
427 'configure 'post-configure
428 (lambda _
429 ;; Don't store configure flags, to avoid retaining references to
430 ;; build-time dependencies---e.g., `--with-ppl=/nix/store/xxx'.
431 (substitute* "Makefile"
432 (("^TOPLEVEL_CONFIGURE_ARGUMENTS=(.*)$" _ rest)
433 "TOPLEVEL_CONFIGURE_ARGUMENTS=\n")))
434 (alist-replace 'install
435 (lambda* (#:key outputs #:allow-other-keys)
436 (zero?
437 (system* "make"
438 ,(if stripped?
439 "install-strip"
440 "install"))))
441 %standard-phases))))))
442
443 (properties `((gcc-libc . ,(assoc-ref inputs "libc"))))
444 (synopsis "The GNU Compiler Collection")
445 (description
446 "The GNU Compiler Collection includes compiler front ends for C, C++,
447 Objective-C, Fortran, OpenMP for C/C++/Fortran, Java, and Ada, as well as
448 libraries for these languages (libstdc++, libgcj, libgomp,...).
449
450 GCC development is a part of the GNU Project, aiming to improve the compiler
451 used in the GNU system including the GNU/Linux variant.")
452 (license gpl3+)
453 (home-page "http://gcc.gnu.org/"))))
454
455 (define-public glibc
456 (package
457 (name "glibc")
458 (version "2.16.0")
459 (source (origin
460 (method url-fetch)
461 (uri (string-append "mirror://gnu/glibc/glibc-"
462 version ".tar.xz"))
463 (sha256
464 (base32
465 "092rdm49zh6l1pqkxbcpcaawgsgzxhpf1s7wf5wi5dvc5am3dp0y"))))
466 (build-system gnu-build-system)
467
468 ;; Glibc's <limits.h> refers to <linux/limit.h>, for instance, so glibc
469 ;; users should automatically pull Linux headers as well.
470 (propagated-inputs `(("linux-headers" ,linux-libre-headers)))
471
472 (arguments
473 `(#:out-of-source? #t
474 #:patches (list (assoc-ref %build-inputs "patch/ld.so.cache"))
475 #:configure-flags
476 (list "--enable-add-ons"
477 "--sysconfdir=/etc"
478 "--localedir=/var/run/current-system/sw/lib/locale" ; XXX
479 (string-append "--with-headers="
480 (assoc-ref %build-inputs "linux-headers")
481 "/include")
482
483 ;; The default is to assume a 2.4 Linux interface, but we'll
484 ;; always use something newer. See "kernel-features.h" in the
485 ;; GNU libc for details.
486 "--enable-kernel=2.6.30"
487
488 ;; XXX: Work around "undefined reference to `__stack_chk_guard'".
489 "libc_cv_ssp=no")
490 #:tests? #f ; XXX
491 #:phases (alist-cons-before
492 'configure 'pre-configure
493 (lambda* (#:key outputs #:allow-other-keys)
494 (let ((out (assoc-ref outputs "out")))
495 ;; Use `pwd', not `/bin/pwd'.
496 (substitute* "configure"
497 (("/bin/pwd") "pwd"))
498
499 ;; Install the rpc data base file under `$out/etc/rpc'.
500 ;; FIXME: Use installFlags = [ "sysconfdir=$(out)/etc" ];
501 (substitute* "sunrpc/Makefile"
502 (("^\\$\\(inst_sysconfdir\\)/rpc(.*)$" _ suffix)
503 (string-append out "/etc/rpc" suffix "\n"))
504 (("^install-others =.*$")
505 (string-append "install-others = " out "/etc/rpc\n")))
506
507 (substitute* "Makeconfig"
508 ;; According to
509 ;; <http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html>,
510 ;; linking against libgcc_s is not needed with GCC
511 ;; 4.7.1.
512 ((" -lgcc_s") ""))))
513 %standard-phases)))
514 (inputs `(("patch/ld.so.cache"
515 ,(search-patch "glibc-no-ld-so-cache.patch"))))
516 (synopsis "The GNU C Library")
517 (description
518 "Any Unix-like operating system needs a C library: the library which
519 defines the \"system calls\" and other basic facilities such as open, malloc,
520 printf, exit...
521
522 The GNU C library is used as the C library in the GNU system and most systems
523 with the Linux kernel.")
524 (license lgpl2.0+)
525 (home-page "http://www.gnu.org/software/libc/")))
526
527 \f
528 ;;;
529 ;;; Bootstrap packages.
530 ;;;
531
532 (define gnu-make-boot0
533 (package-with-bootstrap-guile
534 (package (inherit gnu-make)
535 (name "make-boot0")
536 (location (source-properties->location (current-source-location)))
537 (arguments `(#:guile ,%bootstrap-guile
538 #:implicit-inputs? #f
539 #:tests? #f ; cannot run "make check"
540 #:phases
541 (alist-replace
542 'build (lambda _
543 (zero? (system* "./build.sh")))
544 (alist-replace
545 'install (lambda* (#:key outputs #:allow-other-keys)
546 (let* ((out (assoc-ref outputs "out"))
547 (bin (string-append out "/bin")))
548 (mkdir-p bin)
549 (copy-file "make"
550 (string-append bin "/make"))))
551 %standard-phases))))
552 (inputs %bootstrap-inputs))))
553
554 (define diffutils-boot0
555 (package-with-bootstrap-guile
556 (let ((p (package-with-explicit-inputs diffutils
557 `(("make" ,gnu-make-boot0)
558 ,@%bootstrap-inputs)
559 #:guile %bootstrap-guile)))
560 (package (inherit p)
561 (location (source-properties->location (current-source-location)))
562 (arguments `(#:tests? #f ; the test suite needs diffutils
563 ,@(package-arguments p)))))))
564
565 (define findutils-boot0
566 (package-with-bootstrap-guile
567 (package-with-explicit-inputs findutils
568 `(("make" ,gnu-make-boot0)
569 ("diffutils" ,diffutils-boot0) ; for tests
570 ,@%bootstrap-inputs)
571 (current-source-location)
572 #:guile %bootstrap-guile)))
573
574
575 (define %boot0-inputs
576 `(("make" ,gnu-make-boot0)
577 ("diffutils" ,diffutils-boot0)
578 ("findutils" ,findutils-boot0)
579 ,@%bootstrap-inputs))
580
581 (define* (nix-system->gnu-triplet system #:optional (vendor "unknown"))
582 "Return an a guess of the GNU triplet corresponding to Nix system
583 identifier SYSTEM."
584 (let* ((dash (string-index system #\-))
585 (arch (substring system 0 dash))
586 (os (substring system (+ 1 dash))))
587 (string-append arch
588 "-" vendor "-"
589 (if (string=? os "linux")
590 "linux-gnu"
591 os))))
592
593 (define boot-triplet
594 ;; Return the triplet used to create the cross toolchain needed in the
595 ;; first bootstrapping stage.
596 (cut nix-system->gnu-triplet <> "guix"))
597
598 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
599 ;; toolchain actually targets the same OS and arch, but it has the advantage
600 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
601 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
602
603 (define binutils-boot0
604 (package-with-bootstrap-guile
605 (package (inherit binutils)
606 (name "binutils-cross-boot0")
607 (arguments
608 (lambda (system)
609 `(#:guile ,%bootstrap-guile
610 #:implicit-inputs? #f
611 ,@(substitute-keyword-arguments (package-arguments binutils)
612 ((#:configure-flags cf)
613 `(list ,(string-append "--target=" (boot-triplet system))))))))
614 (inputs %boot0-inputs))))
615
616 (define gcc-boot0
617 (package-with-bootstrap-guile
618 (package (inherit gcc-4.7)
619 (name "gcc-cross-boot0")
620 (arguments
621 (lambda (system)
622 `(#:guile ,%bootstrap-guile
623 #:implicit-inputs? #f
624 #:modules ((guix build gnu-build-system)
625 (guix build utils)
626 (ice-9 regex)
627 (srfi srfi-1)
628 (srfi srfi-26))
629 ,@(substitute-keyword-arguments ((package-arguments gcc-4.7) system)
630 ((#:configure-flags flags)
631 `(append (list ,(string-append "--target="
632 (boot-triplet system))
633
634 ;; No libc yet.
635 "--without-headers"
636
637 ;; Disable features not needed at this stage.
638 "--disable-shared"
639 "--enable-languages=c"
640 "--disable-libmudflap"
641 "--disable-libgomp"
642 "--disable-libssp"
643 "--disable-libquadmath"
644 "--disable-decimal-float")
645 (remove (cut string-match "--enable-languages.*" <>)
646 ,flags)))
647 ((#:phases phases)
648 `(alist-cons-after
649 'unpack 'unpack-gmp&co
650 (lambda* (#:key inputs #:allow-other-keys)
651 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
652 (mpfr (assoc-ref %build-inputs "mpfr-source"))
653 (mpc (assoc-ref %build-inputs "mpc-source")))
654
655 ;; To reduce the set of pre-built bootstrap inputs, build
656 ;; GMP & co. from GCC.
657 (for-each (lambda (source)
658 (or (zero? (system* "tar" "xvf" source))
659 (error "failed to unpack tarball"
660 source)))
661 (list gmp mpfr mpc))
662
663 ;; Create symlinks like `gmp' -> `gmp-5.0.5'.
664 ,@(map (lambda (lib)
665 `(symlink ,(package-full-name lib)
666 ,(package-name lib)))
667 (list gmp mpfr mpc))
668
669 ;; MPFR headers/lib are found under $(MPFR)/src, but
670 ;; `configure' wrongfully tells MPC too look under
671 ;; $(MPFR), so fix that.
672 (substitute* "configure"
673 (("extra_mpc_mpfr_configure_flags(.+)--with-mpfr-include=([^/]+)/mpfr(.*)--with-mpfr-lib=([^ ]+)/mpfr"
674 _ equals include middle lib)
675 (string-append "extra_mpc_mpfr_configure_flags" equals
676 "--with-mpfr-include=" include
677 "/mpfr/src" middle
678 "--with-mpfr-lib=" lib
679 "/mpfr/src"))
680 (("gmpinc='-I([^ ]+)/mpfr -I([^ ]+)/mpfr" _ a b)
681 (string-append "gmpinc='-I" a "/mpfr/src "
682 "-I" b "/mpfr/src"))
683 (("gmplibs='-L([^ ]+)/mpfr" _ a)
684 (string-append "gmplibs='-L" a "/mpfr/src")))))
685 (alist-cons-after
686 'install 'symlink-libgcc_eh
687 (lambda* (#:key outputs #:allow-other-keys)
688 (let ((out (assoc-ref outputs "out")))
689 ;; Glibc wants to link against libgcc_eh, so provide
690 ;; it.
691 (with-directory-excursion
692 (string-append out "/lib/gcc/"
693 ,(boot-triplet system)
694 "/" ,(package-version gcc-4.7))
695 (symlink "libgcc.a" "libgcc_eh.a"))))
696 ,phases)))))))
697
698 (inputs `(("gmp-source" ,(package-source gmp))
699 ("mpfr-source" ,(package-source mpfr))
700 ("mpc-source" ,(package-source mpc))
701 ("binutils-cross" ,binutils-boot0)
702
703 ;; Call it differently so that the builder can check whether
704 ;; the "libc" input is #f.
705 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
706 ,@(alist-delete "libc" %boot0-inputs))))))
707
708 (define linux-libre-headers-boot0
709 (package-with-bootstrap-guile
710 (package (inherit linux-libre-headers)
711 (arguments `(#:guile ,%bootstrap-guile
712 #:implicit-inputs? #f
713 ,@(package-arguments linux-libre-headers)))
714 (native-inputs
715 (let ((perl (package-with-explicit-inputs perl
716 %boot0-inputs
717 (current-source-location)
718 #:guile %bootstrap-guile)))
719 `(("perl" ,perl)
720 ,@%boot0-inputs))))))
721
722 (define %boot1-inputs
723 ;; 2nd stage inputs.
724 `(("gcc" ,gcc-boot0)
725 ("binutils-cross" ,binutils-boot0)
726
727 ;; Keep "binutils" here because the cross-gcc invokes `as', not the
728 ;; cross-`as'.
729 ,@%boot0-inputs))
730
731 (define-public glibc-final
732 ;; The final libc, "cross-built". If everything went well, the resulting
733 ;; store path has no dependencies.
734 (package-with-bootstrap-guile
735 (package (inherit glibc)
736 (arguments
737 (lambda (system)
738 `(#:guile ,%bootstrap-guile
739 #:implicit-inputs? #f
740
741 ;; Leave /bin/sh as the interpreter for `ldd', `sotruss', etc. to
742 ;; avoid keeping a reference to the bootstrap Bash.
743 #:patch-shebangs? #f
744 ,@(substitute-keyword-arguments (package-arguments glibc)
745 ((#:configure-flags flags)
746 `(append (list ,(string-append "--host=" (boot-triplet system))
747 ,(string-append "--build="
748 (nix-system->gnu-triplet system))
749 "BASH_SHELL=/bin/sh"
750
751 ;; Build Sun/ONC RPC support. In particular,
752 ;; install rpc/*.h.
753 "--enable-obsolete-rpc")
754 ,flags))))))
755 (propagated-inputs `(("linux-headers" ,linux-libre-headers-boot0)))
756 (inputs `( ;; A native GCC is needed to build `cross-rpcgen'.
757 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
758 ,@%boot1-inputs
759 ,@(package-inputs glibc)))))) ; patches
760
761 (define gcc-boot0-wrapped
762 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
763 ;; non-cross names.
764 (package (inherit gcc-4.7)
765 (name (string-append (package-name gcc-boot0) "-wrapped"))
766 (source #f)
767 (build-system trivial-build-system)
768 (arguments
769 (lambda (system)
770 `(#:guile ,%bootstrap-guile
771 #:modules ((guix build utils))
772 #:builder (begin
773 (use-modules (guix build utils))
774
775 (let* ((binutils (assoc-ref %build-inputs "binutils"))
776 (gcc (assoc-ref %build-inputs "gcc"))
777 (libc (assoc-ref %build-inputs "libc"))
778 (bash (assoc-ref %build-inputs "bash"))
779 (out (assoc-ref %outputs "out"))
780 (bindir (string-append out "/bin"))
781 (triplet ,(boot-triplet system)))
782 (mkdir-p bindir)
783 (with-directory-excursion bindir
784 (for-each (lambda (tool)
785 (symlink (string-append binutils "/bin/"
786 triplet "-" tool)
787 tool))
788 '("ar" "ranlib"))
789
790 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
791 ;; needs to be told where to find the crt files and
792 ;; the dynamic linker.
793 (call-with-output-file "gcc"
794 (lambda (p)
795 (format p "#!~a/bin/bash
796 exec ~a/bin/~a-gcc -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
797 bash
798 gcc triplet
799 libc libc
800 ,(glibc-dynamic-linker system))))
801
802 (chmod "gcc" #o555)))))))
803 (native-inputs
804 `(("binutils" ,binutils-boot0)
805 ("gcc" ,gcc-boot0)
806 ("libc" ,glibc-final)
807 ,(assoc "bash" %boot1-inputs)))
808 (inputs '())))
809
810 (define %boot2-inputs
811 ;; 3rd stage inputs.
812 `(("libc" ,glibc-final)
813 ("gcc" ,gcc-boot0-wrapped)
814 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
815
816 (define-public binutils-final
817 (package-with-bootstrap-guile
818 (package (inherit binutils)
819 (arguments
820 (lambda (system)
821 `(#:guile ,%bootstrap-guile
822 #:implicit-inputs? #f
823 ,@(package-arguments binutils))))
824 (inputs %boot2-inputs))))
825
826 (define-public gcc-final
827 ;; The final GCC.
828 (package (inherit gcc-boot0)
829 (name "gcc")
830 (arguments
831 (lambda (system)
832 `(#:guile ,%bootstrap-guile
833 #:implicit-inputs? #f
834
835 ;; Build again GMP & co. within GCC's build process, because it's hard
836 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
837 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
838 ,@(substitute-keyword-arguments ((package-arguments gcc-boot0) system)
839 ((#:configure-flags boot-flags)
840 (let loop ((args ((package-arguments gcc-4.7) system)))
841 (match args
842 ((#:configure-flags normal-flags _ ...)
843 normal-flags)
844 ((_ rest ...)
845 (loop rest)))))
846 ((#:phases phases)
847 `(alist-delete 'symlink-libgcc_eh ,phases))))))
848
849 (inputs `(("gmp-source" ,(package-source gmp))
850 ("mpfr-source" ,(package-source mpfr))
851 ("mpc-source" ,(package-source mpc))
852 ("binutils" ,binutils-final)
853 ,@%boot2-inputs))))
854
855 (define ld-wrapper-boot3
856 ;; A linker wrapper that uses the bootstrap Guile.
857 (package
858 (name "ld-wrapper-boot3")
859 (version "0")
860 (source #f)
861 (build-system trivial-build-system)
862 (inputs `(("binutils" ,binutils-final)
863 ("guile" ,%bootstrap-guile)
864 ("wrapper" ,(search-path %load-path
865 "distro/packages/ld-wrapper.scm"))))
866 (arguments
867 `(#:guile ,%bootstrap-guile
868 #:modules ((guix build utils))
869 #:builder (begin
870 (use-modules (guix build utils)
871 (system base compile))
872
873 (let* ((out (assoc-ref %outputs "out"))
874 (bin (string-append out "/bin"))
875 (ld (string-append bin "/ld"))
876 (go (string-append bin "/ld.go")))
877
878 (setvbuf (current-output-port) _IOLBF)
879 (format #t "building ~s/bin/ld wrapper in ~s~%"
880 (assoc-ref %build-inputs "binutils")
881 out)
882
883 (mkdir-p bin)
884 (copy-file (assoc-ref %build-inputs "wrapper") ld)
885 (substitute* ld
886 (("@GUILE@")
887 (string-append (assoc-ref %build-inputs "guile")
888 "/bin/guile"))
889 (("@LD@")
890 (string-append (assoc-ref %build-inputs "binutils")
891 "/bin/ld")))
892 (chmod ld #o555)
893 (compile-file ld #:output-file go)))))
894 (synopsis "The linker wrapper")
895 (description
896 "The linker wrapper (or `ld-wrapper') wraps the linker to add any
897 missing `-rpath' flags, and to detect any misuse of libraries outside of the
898 store.")
899 (home-page #f)
900 (license gpl3+)))
901
902 (define %boot3-inputs
903 ;; 4th stage inputs.
904 `(("gcc" ,gcc-final)
905 ("ld-wrapper" ,ld-wrapper-boot3)
906 ,@(alist-delete "gcc" %boot2-inputs)))
907
908 (define-public bash-final
909 ;; Link with `-static-libgcc' to make sure we don't retain a reference
910 ;; to the bootstrap GCC.
911 (package-with-bootstrap-guile
912 (package-with-explicit-inputs (static-libgcc-package bash)
913 %boot3-inputs
914 (current-source-location)
915 #:guile %bootstrap-guile)))
916
917 (define %boot4-inputs
918 ;; Now use the final Bash.
919 `(("bash" ,bash-final)
920 ,@(alist-delete "bash" %boot3-inputs)))
921
922 (define-public guile-final
923 ;; FIXME: The Libtool used here, specifically its `bin/libtool' script,
924 ;; holds a dependency on the bootstrap Binutils. Use multiple outputs for
925 ;; Libtool, so that that dependency is isolated in the "bin" output.
926 (package-with-bootstrap-guile
927 (package-with-explicit-inputs guile-2.0/fixed
928 %boot4-inputs
929 (current-source-location)
930 #:guile %bootstrap-guile)))
931
932 (define-public ld-wrapper
933 ;; The final `ld' wrapper, which uses the final Guile.
934 (package (inherit ld-wrapper-boot3)
935 (name "ld-wrapper")
936 (inputs `(("guile" ,guile-final)
937 ,@(alist-delete "guile" (package-inputs ld-wrapper-boot3))))))
938
939 (define-public %final-inputs
940 ;; Final derivations used as implicit inputs by `gnu-build-system'.
941 (let ((finalize (cut package-with-explicit-inputs <> %boot4-inputs
942 (current-source-location))))
943 `(,@(map (match-lambda
944 ((name package)
945 (list name (finalize package))))
946 `(("tar" ,tar)
947 ("gzip" ,gzip)
948 ("bzip2" ,bzip2)
949 ("xz" ,xz)
950 ("diffutils" ,diffutils)
951 ("patch" ,patch)
952 ("coreutils" ,coreutils)
953 ("sed" ,sed)
954 ("grep" ,grep)
955 ("findutils" ,findutils)
956 ("gawk" ,gawk)
957 ("make" ,gnu-make)))
958 ("bash" ,bash-final)
959 ("ld-wrapper" ,ld-wrapper)
960 ("binutils" ,binutils-final)
961 ("gcc" ,gcc-final)
962 ("libc" ,glibc-final))))
963
964 ;;; base.scm ends here