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