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