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