gnu: hidapi: Fix 'license'.
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
CommitLineData
bdb36958 1;;; GNU Guix --- Functional package management for GNU
d4aaf954 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
bdb36958
LC
3;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
60e2d5fe 5;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
bdb36958
LC
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22(define-module (gnu packages commencement)
23 #:use-module ((guix licenses)
24 #:select (gpl3+ lgpl2.0+ public-domain))
25 #:use-module (gnu packages bootstrap)
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages bash)
28 #:use-module (gnu packages gcc)
2d5d63d7 29 #:use-module (gnu packages m4)
c00a9fbf 30 #:use-module (gnu packages file)
bdb36958 31 #:use-module (gnu packages gawk)
2d5d63d7 32 #:use-module (gnu packages bison)
bdb36958 33 #:use-module (gnu packages guile)
6162b95d 34 #:use-module (gnu packages gettext)
bdb36958
LC
35 #:use-module (gnu packages multiprecision)
36 #:use-module (gnu packages compression)
37 #:use-module (gnu packages perl)
38 #:use-module (gnu packages linux)
39 #:use-module (gnu packages texinfo)
40 #:use-module (gnu packages pkg-config)
41 #:use-module (guix packages)
42 #:use-module (guix download)
43 #:use-module (guix build-system gnu)
44 #:use-module (guix build-system trivial)
45 #:use-module (guix utils)
46 #:use-module (srfi srfi-1)
47 #:use-module (srfi srfi-26)
48 #:use-module (ice-9 vlist)
49 #:use-module (ice-9 match))
50
51;;; Commentary:
52;;;
53;;; This is the commencement, this is where things start. Before the
54;;; commencement, of course, there's the 'bootstrap' module, which provides us
55;;; with the initial binaries. This module uses those bootstrap binaries to
56;;; actually build up the whole tool chain that make up the implicit inputs of
57;;; 'gnu-build-system'.
58;;;
59;;; To avoid circular dependencies, this module should not be imported
60;;; directly from anywhere.
61;;;
62;;; Code:
63
64(define gnu-make-boot0
65 (package-with-bootstrap-guile
66 (package (inherit gnu-make)
67 (name "make-boot0")
bdb36958
LC
68 (arguments
69 `(#:guile ,%bootstrap-guile
70 #:implicit-inputs? #f
71 #:tests? #f ; cannot run "make check"
72 ,@(substitute-keyword-arguments (package-arguments gnu-make)
73 ((#:phases phases)
74 `(alist-replace
75 'build (lambda _
bdb36958
LC
76 (zero? (system* "./build.sh")))
77 (alist-replace
78 'install (lambda* (#:key outputs #:allow-other-keys)
79 (let* ((out (assoc-ref outputs "out"))
80 (bin (string-append out "/bin")))
81 (mkdir-p bin)
82 (copy-file "make"
83 (string-append bin "/make"))))
84 ,phases))))))
85 (native-inputs '()) ; no need for 'pkg-config'
86 (inputs %bootstrap-inputs))))
87
88(define diffutils-boot0
89 (package-with-bootstrap-guile
90 (let ((p (package-with-explicit-inputs diffutils
91 `(("make" ,gnu-make-boot0)
92 ,@%bootstrap-inputs)
93 #:guile %bootstrap-guile)))
94 (package (inherit p)
09964b4f 95 (name "diffutils-boot0")
bdb36958
LC
96 (arguments `(#:tests? #f ; the test suite needs diffutils
97 ,@(package-arguments p)))))))
98
99(define findutils-boot0
100 (package-with-bootstrap-guile
09964b4f
LC
101 (package-with-explicit-inputs (package
102 (inherit findutils)
103 (name "findutils-boot0"))
bdb36958
LC
104 `(("make" ,gnu-make-boot0)
105 ("diffutils" ,diffutils-boot0) ; for tests
106 ,@%bootstrap-inputs)
107 (current-source-location)
108 #:guile %bootstrap-guile)))
109
c00a9fbf
MW
110(define file-boot0
111 (package-with-bootstrap-guile
09964b4f
LC
112 (package-with-explicit-inputs (package
113 (inherit file)
114 (name "file-boot0"))
c00a9fbf
MW
115 `(("make" ,gnu-make-boot0)
116 ,@%bootstrap-inputs)
117 (current-source-location)
118 #:guile %bootstrap-guile)))
119
bdb36958
LC
120
121(define %boot0-inputs
122 `(("make" ,gnu-make-boot0)
123 ("diffutils" ,diffutils-boot0)
124 ("findutils" ,findutils-boot0)
c00a9fbf 125 ("file" ,file-boot0)
bdb36958
LC
126 ,@%bootstrap-inputs))
127
bdb36958
LC
128(define* (boot-triplet #:optional (system (%current-system)))
129 ;; Return the triplet used to create the cross toolchain needed in the
130 ;; first bootstrapping stage.
131 (nix-system->gnu-triplet system "guix"))
132
133;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
134;; toolchain actually targets the same OS and arch, but it has the advantage
135;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
136;; GCC-BOOT0 (below) is built without any reference to the target libc.
137
138(define binutils-boot0
139 (package-with-bootstrap-guile
140 (package (inherit binutils)
141 (name "binutils-cross-boot0")
142 (arguments
143 `(#:guile ,%bootstrap-guile
144 #:implicit-inputs? #f
f8badf15
MW
145
146 #:modules ((guix build gnu-build-system)
147 (guix build utils)
148 (ice-9 ftw)) ; for 'scandir'
149 #:phases (alist-cons-after
150 'install 'add-symlinks
151 (lambda* (#:key outputs #:allow-other-keys)
152 ;; The cross-gcc invokes 'as', 'ld', etc, without the
153 ;; triplet prefix, so add symlinks.
154 (let ((out (assoc-ref outputs "out"))
155 (triplet-prefix (string-append ,(boot-triplet) "-")))
156 (define (has-triplet-prefix? name)
157 (string-prefix? triplet-prefix name))
158 (define (remove-triplet-prefix name)
159 (substring name (string-length triplet-prefix)))
160 (with-directory-excursion (string-append out "/bin")
161 (for-each (lambda (name)
162 (symlink name (remove-triplet-prefix name)))
163 (scandir "." has-triplet-prefix?)))
164 #t))
165 %standard-phases)
166
bdb36958
LC
167 ,@(substitute-keyword-arguments (package-arguments binutils)
168 ((#:configure-flags cf)
169 `(cons ,(string-append "--target=" (boot-triplet))
170 ,cf)))))
171 (inputs %boot0-inputs))))
172
173(define gcc-boot0
174 (package-with-bootstrap-guile
c92f1c0a 175 (package (inherit gcc)
bdb36958
LC
176 (name "gcc-cross-boot0")
177 (arguments
178 `(#:guile ,%bootstrap-guile
179 #:implicit-inputs? #f
180 #:modules ((guix build gnu-build-system)
181 (guix build utils)
182 (ice-9 regex)
183 (srfi srfi-1)
184 (srfi srfi-26))
c92f1c0a 185 ,@(substitute-keyword-arguments (package-arguments gcc)
bdb36958
LC
186 ((#:configure-flags flags)
187 `(append (list ,(string-append "--target=" (boot-triplet))
188
189 ;; No libc yet.
190 "--without-headers"
191
192 ;; Disable features not needed at this stage.
193 "--disable-shared"
194 "--enable-languages=c,c++"
195
196 ;; libstdc++ cannot be built at this stage
197 ;; ("Link tests are not allowed after
198 ;; GCC_NO_EXECUTABLES.").
199 "--disable-libstdc++-v3"
200
201 "--disable-threads"
202 "--disable-libmudflap"
203 "--disable-libatomic"
204 "--disable-libsanitizer"
205 "--disable-libitm"
206 "--disable-libgomp"
de4ac325
LC
207 "--disable-libcilkrts"
208 "--disable-libvtv"
bdb36958
LC
209 "--disable-libssp"
210 "--disable-libquadmath"
211 "--disable-decimal-float")
98bd851e
LC
212 (remove (cut string-match
213 "--(with-system-zlib|enable-languages.*)" <>)
bdb36958
LC
214 ,flags)))
215 ((#:phases phases)
216 `(alist-cons-after
217 'unpack 'unpack-gmp&co
218 (lambda* (#:key inputs #:allow-other-keys)
219 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
220 (mpfr (assoc-ref %build-inputs "mpfr-source"))
221 (mpc (assoc-ref %build-inputs "mpc-source")))
222
223 ;; To reduce the set of pre-built bootstrap inputs, build
224 ;; GMP & co. from GCC.
225 (for-each (lambda (source)
226 (or (zero? (system* "tar" "xvf" source))
227 (error "failed to unpack tarball"
228 source)))
229 (list gmp mpfr mpc))
230
231 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
232 ,@(map (lambda (lib)
233 ;; Drop trailing letters, as gmp-6.0.0a unpacks
234 ;; into gmp-6.0.0.
235 `(symlink ,(string-trim-right
236 (package-full-name lib)
237 char-set:letter)
238 ,(package-name lib)))
8309c389 239 (list gmp-6.0 mpfr mpc))))
bdb36958
LC
240 (alist-cons-after
241 'install 'symlink-libgcc_eh
242 (lambda* (#:key outputs #:allow-other-keys)
243 (let ((out (assoc-ref outputs "lib")))
244 ;; Glibc wants to link against libgcc_eh, so provide
245 ;; it.
246 (with-directory-excursion
247 (string-append out "/lib/gcc/"
248 ,(boot-triplet)
c92f1c0a 249 "/" ,(package-version gcc))
bdb36958
LC
250 (symlink "libgcc.a" "libgcc_eh.a"))))
251 ,phases))))))
252
8309c389 253 (inputs `(("gmp-source" ,(package-source gmp-6.0))
bdb36958
LC
254 ("mpfr-source" ,(package-source mpfr))
255 ("mpc-source" ,(package-source mpc))
256 ("binutils-cross" ,binutils-boot0)
257
258 ;; Call it differently so that the builder can check whether
259 ;; the "libc" input is #f.
260 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
9dee9e8f
LC
261 ,@(alist-delete "libc" %boot0-inputs)))
262
263 ;; No need for Texinfo at this stage.
264 (native-inputs (alist-delete "texinfo"
265 (package-native-inputs gcc))))))
bdb36958
LC
266
267(define perl-boot0
4de35074
LC
268 (let ((perl (package
269 (inherit perl)
09964b4f 270 (name "perl-boot0")
d8173f21 271 (replacement #f)
4de35074 272 (arguments
81cea47d
LC
273 ;; At the very least, this must not depend on GCC & co.
274 (let ((args `(#:disallowed-references
275 ,(list %bootstrap-binutils))))
276 (substitute-keyword-arguments (package-arguments perl)
277 ((#:phases phases)
278 `(modify-phases ,phases
279 ;; Pthread support is missing in the bootstrap compiler
280 ;; (broken spec file), so disable it.
281 (add-before 'configure 'disable-pthreads
282 (lambda _
283 (substitute* "Configure"
284 (("^libswanted=(.*)pthread" _ before)
285 (string-append "libswanted=" before)))))))))))))
286 (package-with-bootstrap-guile
287 (package-with-explicit-inputs perl
288 %boot0-inputs
289 (current-source-location)
290 #:guile %bootstrap-guile))))
bdb36958
LC
291
292(define (linux-libre-headers-boot0)
293 "Return Linux-Libre header files for the bootstrap environment."
294 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
295 ;; between (gnu packages linux) and this module.
296 (package-with-bootstrap-guile
297 (package (inherit linux-libre-headers)
298 (arguments `(#:guile ,%bootstrap-guile
299 #:implicit-inputs? #f
300 ,@(package-arguments linux-libre-headers)))
301 (native-inputs
302 `(("perl" ,perl-boot0)
303 ,@%boot0-inputs)))))
304
305(define texinfo-boot0
306 ;; Texinfo used to build libc's manual.
307 ;; We build without ncurses because it fails to build at this stage, and
308 ;; because we don't need the stand-alone Info reader.
309 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
310 (let ((texinfo (package (inherit texinfo)
47ed8e04 311 (native-inputs '())
5d6c4d37
LC
312 (inputs `(("perl" ,perl-boot0)))
313
314 ;; Some of Texinfo 6.1's tests would fail with "Couldn't
315 ;; set UTF-8 character type in locale" but we don't have a
316 ;; UTF-8 locale at this stage, so skip them.
317 (arguments '(#:tests? #f)))))
bdb36958
LC
318 (package-with-bootstrap-guile
319 (package-with-explicit-inputs texinfo %boot0-inputs
320 (current-source-location)
321 #:guile %bootstrap-guile))))
322
323(define %boot1-inputs
324 ;; 2nd stage inputs.
325 `(("gcc" ,gcc-boot0)
326 ("binutils-cross" ,binutils-boot0)
f8badf15 327 ,@(alist-delete "binutils" %boot0-inputs)))
bdb36958
LC
328
329(define glibc-final-with-bootstrap-bash
330 ;; The final libc, "cross-built". If everything went well, the resulting
331 ;; store path has no dependencies. Actually, the really-final libc is
332 ;; built just below; the only difference is that this one uses the
333 ;; bootstrap Bash.
334 (package-with-bootstrap-guile
335 (package (inherit glibc)
336 (name "glibc-intermediate")
337 (arguments
338 `(#:guile ,%bootstrap-guile
339 #:implicit-inputs? #f
340
341 ,@(substitute-keyword-arguments (package-arguments glibc)
342 ((#:configure-flags flags)
343 `(append (list ,(string-append "--host=" (boot-triplet))
344 ,(string-append "--build="
345 (nix-system->gnu-triplet))
346
347 ;; Build Sun/ONC RPC support. In particular,
348 ;; install rpc/*.h.
349 "--enable-obsolete-rpc")
350 ,flags))
351 ((#:phases phases)
352 `(alist-cons-before
353 'configure 'pre-configure
354 (lambda* (#:key inputs #:allow-other-keys)
355 ;; Don't clobber CPATH with the bootstrap libc.
356 (setenv "NATIVE_CPATH" (getenv "CPATH"))
357 (unsetenv "CPATH")
358
359 ;; 'rpcgen' needs native libc headers to be built.
360 (substitute* "sunrpc/Makefile"
361 (("sunrpc-CPPFLAGS =.*" all)
362 (string-append "CPATH = $(NATIVE_CPATH)\n"
363 "export CPATH\n"
364 all "\n"))))
365 ,phases)))))
55de892b 366 (propagated-inputs `(("kernel-headers" ,(linux-libre-headers-boot0))))
bdb36958
LC
367 (native-inputs
368 `(("texinfo" ,texinfo-boot0)
369 ("perl" ,perl-boot0)))
370 (inputs
371 `(;; The boot inputs. That includes the bootstrap libc. We don't want
372 ;; it in $CPATH, hence the 'pre-configure' phase above.
373 ,@%boot1-inputs
374
375 ;; A native GCC is needed to build `cross-rpcgen'.
376 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
377
378 ;; Here, we use the bootstrap Bash, which is not satisfactory
379 ;; because we don't want to depend on bootstrap tools.
380 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
381
382(define (cross-gcc-wrapper gcc binutils glibc bash)
383 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
384that makes it available under the native tool names."
c92f1c0a 385 (package (inherit gcc)
bdb36958
LC
386 (name (string-append (package-name gcc) "-wrapped"))
387 (source #f)
388 (build-system trivial-build-system)
389 (outputs '("out"))
390 (arguments
391 `(#:guile ,%bootstrap-guile
392 #:modules ((guix build utils))
393 #:builder (begin
394 (use-modules (guix build utils))
395
396 (let* ((binutils (assoc-ref %build-inputs "binutils"))
397 (gcc (assoc-ref %build-inputs "gcc"))
398 (libc (assoc-ref %build-inputs "libc"))
399 (bash (assoc-ref %build-inputs "bash"))
400 (out (assoc-ref %outputs "out"))
401 (bindir (string-append out "/bin"))
402 (triplet ,(boot-triplet)))
403 (define (wrap-program program)
404 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
405 ;; needs to be told where to find the crt files and
406 ;; the dynamic linker.
407 (call-with-output-file program
408 (lambda (p)
409 (format p "#!~a/bin/bash
410exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
411 bash
412 gcc triplet program
413 libc libc
414 ,(glibc-dynamic-linker))))
415
416 (chmod program #o555))
417
418 (mkdir-p bindir)
419 (with-directory-excursion bindir
420 (for-each (lambda (tool)
421 (symlink (string-append binutils "/bin/"
422 triplet "-" tool)
423 tool))
424 '("ar" "ranlib"))
425 (for-each wrap-program '("gcc" "g++")))))))
426 (native-inputs
427 `(("binutils" ,binutils)
428 ("gcc" ,gcc)
429 ("libc" ,glibc)
430 ("bash" ,bash)))
431 (inputs '())))
432
2d5d63d7
MW
433(define bison-boot1
434 ;; XXX: This Bison is needed to rebuild Bash's parser, which is modified by
435 ;; its CVE patches. Remove it when it's no longer needed.
436 (let* ((m4 (package-with-bootstrap-guile
437 (package-with-explicit-inputs m4 %boot0-inputs
438 (current-source-location)
439 #:guile %bootstrap-guile)))
440 (bison (package (inherit bison)
2d5d63d7
MW
441 (propagated-inputs `(("m4" ,m4)))
442 (inputs '()) ;remove Flex...
53088d00
LC
443 (arguments
444 '(#:tests? #f ;... and thus disable tests
445
446 ;; Zero timestamps in liby.a; this must be done
447 ;; explicitly here because the bootstrap Binutils don't
448 ;; do that (default is "cru".)
449 #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
450 "V=1"))))))
32243bfb
LC
451 (package
452 (inherit (package-with-bootstrap-guile
453 (package-with-explicit-inputs bison %boot0-inputs
454 (current-source-location)
455 #:guile %bootstrap-guile)))
456 (native-inputs `(("perl" ,perl-boot0))))))
2d5d63d7 457
bdb36958 458(define static-bash-for-glibc
90d891fc 459 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
bdb36958
LC
460 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
461 glibc-final-with-bootstrap-bash
462 (car (assoc-ref %boot1-inputs "bash"))))
90d891fc 463 (bash (package (inherit static-bash)
bdb36958
LC
464 (arguments
465 `(#:guile ,%bootstrap-guile
32243bfb
LC
466 ,@(package-arguments static-bash)))))
467 (inputs `(("gcc" ,gcc)
468 ("libc" ,glibc-final-with-bootstrap-bash)
469 ,@(fold alist-delete %boot1-inputs
470 '("gcc" "libc")))))
471 (package
472 (inherit (package-with-bootstrap-guile
473 (package-with-explicit-inputs bash inputs
8c986ab1
LC
474 (current-source-location)
475 #:guile %bootstrap-guile)))
32243bfb 476 (native-inputs `(("bison" ,bison-boot1))))))
bdb36958 477
6162b95d
LC
478(define gettext-boot0
479 ;; A minimal gettext used during bootstrap.
669b8639
LC
480 (let ((gettext-minimal
481 (package (inherit gnu-gettext)
482 (name "gettext-boot0")
483 (inputs '()) ;zero dependencies
484 (arguments
485 (substitute-keyword-arguments
486 `(#:tests? #f
487 ,@(package-arguments gnu-gettext))
488 ((#:phases phases)
489 `(modify-phases ,phases
490 ;; Build only the tools.
491 (add-after 'unpack 'chdir
492 (lambda _
493 (chdir "gettext-tools")))
494
495 ;; Some test programs require pthreads, which we don't have.
496 (add-before 'configure 'no-test-programs
497 (lambda _
498 (substitute* "tests/Makefile.in"
499 (("^PROGRAMS =.*$")
500 "PROGRAMS =\n"))
501 #t))
502
503 ;; Don't try to link against libexpat.
504 (delete 'link-expat)
505 (delete 'patch-tests))))))))
6162b95d
LC
506 (package-with-bootstrap-guile
507 (package-with-explicit-inputs gettext-minimal
508 %boot1-inputs
509 (current-source-location)
510 #:guile %bootstrap-guile))))
511
89223417 512(define glibc-final
bdb36958
LC
513 ;; The final glibc, which embeds the statically-linked Bash built above.
514 (package (inherit glibc-final-with-bootstrap-bash)
515 (name "glibc")
516 (inputs `(("static-bash" ,static-bash-for-glibc)
517 ,@(alist-delete
518 "static-bash"
519 (package-inputs glibc-final-with-bootstrap-bash))))
520
6162b95d
LC
521 ;; This time we need 'msgfmt' to install all the libc.mo files.
522 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
523 ("gettext" ,gettext-boot0)))
524
bdb36958
LC
525 ;; The final libc only refers to itself, but the 'debug' output contains
526 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
527 ;; if 'allowed-references' were per-output.
528 (arguments
529 `(#:allowed-references
530 ,(cons* `(,gcc-boot0 "lib") (linux-libre-headers-boot0)
90d891fc 531 static-bash-for-glibc
bdb36958
LC
532 (package-outputs glibc-final-with-bootstrap-bash))
533
534 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
535
536(define gcc-boot0-wrapped
537 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
538 ;; non-cross names.
539 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
540 (car (assoc-ref %boot1-inputs "bash"))))
541
542(define %boot2-inputs
543 ;; 3rd stage inputs.
544 `(("libc" ,glibc-final)
545 ("gcc" ,gcc-boot0-wrapped)
546 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
547
548(define binutils-final
549 (package-with-bootstrap-guile
550 (package (inherit binutils)
551 (arguments
552 `(#:guile ,%bootstrap-guile
553 #:implicit-inputs? #f
554 #:allowed-references ("out" ,glibc-final)
555 ,@(package-arguments binutils)))
556 (inputs %boot2-inputs))))
557
558(define libstdc++
559 ;; Intermediate libstdc++ that will allow us to build the final GCC
560 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
d0abf829 561 ;; TODO: Write in terms of 'make-libstdc++'.
bdb36958 562 (package-with-bootstrap-guile
c92f1c0a 563 (package (inherit gcc)
bdb36958
LC
564 (name "libstdc++")
565 (arguments
566 `(#:guile ,%bootstrap-guile
567 #:implicit-inputs? #f
557b5557 568 #:allowed-references ("out")
bdb36958
LC
569 #:out-of-source? #t
570 #:phases (alist-cons-before
571 'configure 'chdir
572 (lambda _
573 (chdir "libstdc++-v3"))
574 %standard-phases)
575 #:configure-flags `("--disable-shared"
576 "--disable-libstdcxx-threads"
577 "--disable-libstdcxx-pch"
578 ,(string-append "--with-gxx-include-dir="
579 (assoc-ref %outputs "out")
580 "/include"
581 ;; "/include/c++/"
c92f1c0a 582 ;; ,(package-version gcc)
bdb36958
LC
583 ))))
584 (outputs '("out"))
585 (inputs %boot2-inputs)
586 (native-inputs '())
587 (propagated-inputs '())
588 (synopsis "GNU C++ standard library (intermediate)"))))
589
98bd851e
LC
590(define zlib-final
591 ;; Zlib used by GCC-FINAL.
592 (package-with-bootstrap-guile
593 (package
594 (inherit zlib)
595 (arguments
596 `(#:guile ,%bootstrap-guile
597 #:implicit-inputs? #f
598 #:allowed-references ("out" ,glibc-final)
599 ,@(package-arguments zlib)))
600 (inputs %boot2-inputs))))
601
602(define ld-wrapper-boot3
603 ;; A linker wrapper that uses the bootstrap Guile.
604 (make-ld-wrapper "ld-wrapper-boot3"
605 #:binutils binutils-final
606 #:guile %bootstrap-guile
607 #:bash (car (assoc-ref %boot2-inputs "bash"))))
608
89223417 609(define gcc-final
bdb36958
LC
610 ;; The final GCC.
611 (package (inherit gcc-boot0)
612 (name "gcc")
ab999c25
LC
613
614 ;; XXX: Currently #:allowed-references applies to all the outputs but the
615 ;; "debug" output contains disallowed references, notably
616 ;; linux-libre-headers. Disable the debugging output to work around that.
617 (outputs (delete "debug" (package-outputs gcc-boot0)))
618
bdb36958
LC
619 (arguments
620 `(#:guile ,%bootstrap-guile
621 #:implicit-inputs? #f
622
98bd851e 623 #:allowed-references ("out" "lib" ,zlib-final
90d891fc 624 ,glibc-final ,static-bash-for-glibc)
bdb36958 625
d485ebba
LC
626 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
627 ;; reason, but it is not in their RUNPATH. This is a false
628 ;; positive, so turn it off.
629 #:validate-runpath? #f
630
bdb36958
LC
631 ;; Build again GMP & co. within GCC's build process, because it's hard
632 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
633 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
634 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
635 ((#:configure-flags boot-flags)
c92f1c0a 636 (let loop ((args (package-arguments gcc)))
bdb36958
LC
637 (match args
638 ((#:configure-flags normal-flags _ ...)
639 normal-flags)
640 ((_ rest ...)
641 (loop rest)))))
642 ((#:make-flags flags)
52cfd8cb 643 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
98bd851e
LC
644 `(let ((zlib (assoc-ref %build-inputs "zlib")))
645 (map (lambda (flag)
646 (if (string-prefix? "LDFLAGS=" flag)
647 (string-append flag " -L"
648 (assoc-ref %build-inputs "libstdc++")
649 "/lib -L" zlib "/lib -Wl,-rpath="
650 zlib "/lib")
651 flag))
652 ,flags)))
bdb36958
LC
653 ((#:phases phases)
654 `(alist-delete 'symlink-libgcc_eh ,phases)))))
655
90d891fc
LC
656 ;; This time we want Texinfo, so we get the manual. Add
657 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
658 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
659 ;; scripts?).
bdb36958 660 (native-inputs `(("texinfo" ,texinfo-boot0)
90d891fc 661 ("static-bash" ,static-bash-for-glibc)
bdb36958
LC
662 ,@(package-native-inputs gcc-boot0)))
663
8309c389 664 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
bdb36958
LC
665 ("mpfr-source" ,(package-source mpfr))
666 ("mpc-source" ,(package-source mpc))
98bd851e 667 ("ld-wrapper" ,ld-wrapper-boot3)
bdb36958
LC
668 ("binutils" ,binutils-final)
669 ("libstdc++" ,libstdc++)
98bd851e 670 ("zlib" ,zlib-final)
bdb36958
LC
671 ,@%boot2-inputs))))
672
bdb36958
LC
673(define %boot3-inputs
674 ;; 4th stage inputs.
675 `(("gcc" ,gcc-final)
676 ("ld-wrapper" ,ld-wrapper-boot3)
677 ,@(alist-delete "gcc" %boot2-inputs)))
678
679(define bash-final
680 ;; Link with `-static-libgcc' to make sure we don't retain a reference
681 ;; to the bootstrap GCC.
f1e0c85a
LC
682 (package
683 (inherit (package-with-bootstrap-guile
684 (package-with-explicit-inputs (static-libgcc-package bash)
685 %boot3-inputs
686 (current-source-location)
687 #:guile %bootstrap-guile)))
688 (native-inputs `(("bison" ,bison-boot1)))))
bdb36958
LC
689
690(define %boot4-inputs
691 ;; Now use the final Bash.
692 `(("bash" ,bash-final)
693 ,@(alist-delete "bash" %boot3-inputs)))
694
695(define-public guile-final
386b71d1
LC
696 ;; This package must be public because other modules refer to it. However,
697 ;; mark it as hidden so that 'fold-packages' ignores it.
bdb36958 698 (package-with-bootstrap-guile
386b71d1 699 (package-with-explicit-inputs (hidden-package guile-2.0/fixed)
bdb36958
LC
700 %boot4-inputs
701 (current-source-location)
702 #:guile %bootstrap-guile)))
703
89223417 704(define glibc-utf8-locales-final
87c8b92f
LC
705 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
706 ;; by the build processes afterwards so their 'scm_to_locale_string' works
707 ;; with the full range of Unicode codepoints (remember
708 ;; 'scm_to_locale_string' is called every time a string is passed to a C
709 ;; function.)
710 (package
711 (inherit glibc-utf8-locales)
712 (inputs `(("glibc" ,glibc-final)
713 ("gzip"
714 ,(package-with-explicit-inputs gzip %boot4-inputs
715 (current-source-location)
716 #:guile %bootstrap-guile))))))
717
28cbc587
LC
718(define-public ld-wrapper
719 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
720 (package (inherit ld-wrapper-boot3)
721 (name "ld-wrapper")
722 (inputs `(("guile" ,guile-final)
723 ("bash" ,bash-final)
724 ,@(fold alist-delete (package-inputs ld-wrapper-boot3)
725 '("guile" "bash"))))))
726
87c8b92f 727(define %boot5-inputs
b6ac5451
LC
728 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
729 ;; with an older libc, which cannot load the new locale format. See
28cbc587 730 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
b6ac5451
LC
731 `(("locales" ,glibc-utf8-locales-final)
732 ,@%boot4-inputs))
87c8b92f 733
bdb36958
LC
734(define gnu-make-final
735 ;; The final GNU Make, which uses the final Guile.
736 (package-with-bootstrap-guile
737 (package-with-explicit-inputs gnu-make
738 `(("guile" ,guile-final)
87c8b92f 739 ,@%boot5-inputs)
bdb36958
LC
740 (current-source-location))))
741
bdb36958
LC
742(define coreutils-final
743 ;; The final Coreutils. Treat them specially because some packages, such as
744 ;; Findutils, keep a reference to the Coreutils they were built with.
745 (package-with-bootstrap-guile
746 (package-with-explicit-inputs coreutils
87c8b92f 747 %boot5-inputs
bdb36958
LC
748 (current-source-location)
749
750 ;; Use the final Guile, linked against the
751 ;; final libc with working iconv, so that
752 ;; 'substitute*' works well when touching
753 ;; test files in Gettext.
754 #:guile guile-final)))
755
756(define grep-final
757 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
758 ;; built before gzip.
759 (package-with-bootstrap-guile
304e4f51
LC
760 (package-with-explicit-inputs (package
761 (inherit grep)
762 (native-inputs `(("perl" ,perl-boot0))))
87c8b92f 763 %boot5-inputs
bdb36958
LC
764 (current-source-location)
765 #:guile guile-final)))
766
87c8b92f 767(define %boot6-inputs
bdb36958
LC
768 ;; Now use the final Coreutils.
769 `(("coreutils" ,coreutils-final)
770 ("grep" ,grep-final)
87c8b92f 771 ,@%boot5-inputs))
b0fd2bd3 772
bdb36958
LC
773(define-public %final-inputs
774 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
775 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
776 ;; used for origins that have patches, thereby avoiding circular
777 ;; dependencies.
778 (let ((finalize (compose package-with-bootstrap-guile
87c8b92f 779 (cut package-with-explicit-inputs <> %boot6-inputs
bdb36958
LC
780 (current-source-location)))))
781 `(,@(map (match-lambda
782 ((name package)
783 (list name (finalize package))))
784 `(("tar" ,tar)
87c8b92f 785 ("gzip" ,gzip)
bdb36958
LC
786 ("bzip2" ,bzip2)
787 ("xz" ,xz)
c00a9fbf 788 ("file" ,file)
bdb36958
LC
789 ("diffutils" ,diffutils)
790 ("patch" ,patch)
791 ("sed" ,sed)
792 ("findutils" ,findutils)
793 ("gawk" ,gawk)))
794 ("grep" ,grep-final)
795 ("coreutils" ,coreutils-final)
796 ("make" ,gnu-make-final)
797 ("bash" ,bash-final)
798 ("ld-wrapper" ,ld-wrapper)
799 ("binutils" ,binutils-final)
800 ("gcc" ,gcc-final)
b0fd2bd3
LC
801 ("libc" ,glibc-final)
802 ("locales" ,glibc-utf8-locales-final))))
bdb36958
LC
803
804(define-public canonical-package
805 (let ((name->package (fold (lambda (input result)
806 (match input
807 ((_ package)
808 (vhash-cons (package-full-name package)
809 package result))))
810 vlist-null
811 `(("guile" ,guile-final)
812 ,@%final-inputs))))
813 (lambda (package)
814 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
815the implicit inputs of 'gnu-build-system', return that one, otherwise return
816PACKAGE.
817
818The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.0,
819COREUTILS-FINAL vs. COREUTILS, etc."
820 ;; XXX: This doesn't handle dependencies of the final inputs, such as
821 ;; libunistring, GMP, etc.
822 (match (vhash-assoc (package-full-name package) name->package)
823 ((_ . canon)
824 ;; In general we want CANON, except if we're cross-compiling: CANON
825 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
826 ;; process, with dependencies on things that cannot be
827 ;; cross-compiled.
828 (if (%current-target-system)
829 package
830 canon))
831 (_ package)))))
832
833\f
834;;;
835;;; GCC toolchain.
836;;;
837
838(define (gcc-toolchain gcc)
839 "Return a complete toolchain for GCC."
840 (package
841 (name "gcc-toolchain")
842 (version (package-version gcc))
843 (source #f)
844 (build-system trivial-build-system)
845 (arguments
846 '(#:modules ((guix build union))
847 #:builder (begin
848 (use-modules (ice-9 match)
6f450b87 849 (srfi srfi-26)
bdb36958
LC
850 (guix build union))
851
6f450b87 852 (let ((out (assoc-ref %outputs "out")))
bdb36958 853
6f450b87
LC
854 (match %build-inputs
855 (((names . directories) ...)
856 (union-build out directories)))
857
6f450b87
LC
858 (union-build (assoc-ref %outputs "debug")
859 (list (assoc-ref %build-inputs
860 "libc-debug")))))))
d474d5d0
LC
861
862 (native-search-paths (package-native-search-paths gcc))
863 (search-paths (package-search-paths gcc))
864
bdb36958
LC
865 (license (package-license gcc))
866 (synopsis "Complete GCC tool chain for C/C++ development")
867 (description
868 "This package provides a complete GCC tool chain for C/C++ development to
869be installed in user profiles. This includes GCC, as well as libc (headers
870and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
871 (home-page "http://gcc.gnu.org/")
872 (outputs '("out" "debug"))
873
874 ;; The main raison d'être of this "meta-package" is (1) to conveniently
875 ;; install everything that we need, and (2) to make sure ld-wrapper comes
876 ;; before Binutils' ld in the user's profile.
877 (inputs `(("gcc" ,gcc)
cbbb11c8 878 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
bdb36958
LC
879 ("binutils" ,binutils-final)
880 ("libc" ,glibc-final)
881 ("libc-debug" ,glibc-final "debug")))))
882
883(define-public gcc-toolchain-4.8
ce362de8 884 (gcc-toolchain gcc-4.8))
bdb36958
LC
885
886(define-public gcc-toolchain-4.9
9dee9e8f 887 (gcc-toolchain gcc-final))
bdb36958 888
629f4d2e 889(define-public gcc-toolchain-5
9dee9e8f 890 (gcc-toolchain gcc-5))
60e2d5fe 891
e760ec41
LC
892(define-public gcc-toolchain-6
893 (gcc-toolchain gcc-6))
894
bdb36958 895;;; commencement.scm ends here