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