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