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