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