Commit | Line | Data |
---|---|---|
bdb36958 | 1 | ;;; GNU Guix --- Functional package management for GNU |
d4aaf954 | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
bdb36958 LC |
3 | ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr> |
4 | ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org> | |
60e2d5fe | 5 | ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org> |
bdb36958 LC |
6 | ;;; |
7 | ;;; This file is part of GNU Guix. | |
8 | ;;; | |
9 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
10 | ;;; under the terms of the GNU General Public License as published by | |
11 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
12 | ;;; your option) any later version. | |
13 | ;;; | |
14 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
15 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;;; GNU General Public License for more details. | |
18 | ;;; | |
19 | ;;; You should have received a copy of the GNU General Public License | |
20 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
22 | (define-module (gnu packages commencement) | |
23 | #:use-module ((guix licenses) | |
24 | #:select (gpl3+ lgpl2.0+ public-domain)) | |
25 | #:use-module (gnu packages bootstrap) | |
26 | #:use-module (gnu packages base) | |
27 | #:use-module (gnu packages bash) | |
28 | #:use-module (gnu packages gcc) | |
2d5d63d7 | 29 | #:use-module (gnu packages m4) |
c00a9fbf | 30 | #:use-module (gnu packages file) |
bdb36958 | 31 | #:use-module (gnu packages gawk) |
2d5d63d7 | 32 | #:use-module (gnu packages bison) |
bdb36958 | 33 | #:use-module (gnu packages guile) |
6162b95d | 34 | #:use-module (gnu packages gettext) |
bdb36958 LC |
35 | #:use-module (gnu packages multiprecision) |
36 | #:use-module (gnu packages compression) | |
37 | #:use-module (gnu packages perl) | |
38 | #:use-module (gnu packages linux) | |
39 | #:use-module (gnu packages texinfo) | |
40 | #:use-module (gnu packages pkg-config) | |
41 | #:use-module (guix packages) | |
42 | #:use-module (guix download) | |
43 | #:use-module (guix build-system gnu) | |
44 | #:use-module (guix build-system trivial) | |
45 | #:use-module (guix utils) | |
46 | #:use-module (srfi srfi-1) | |
47 | #:use-module (srfi srfi-26) | |
48 | #:use-module (ice-9 vlist) | |
49 | #:use-module (ice-9 match)) | |
50 | ||
51 | ;;; Commentary: | |
52 | ;;; | |
53 | ;;; This is the commencement, this is where things start. Before the | |
54 | ;;; commencement, of course, there's the 'bootstrap' module, which provides us | |
55 | ;;; with the initial binaries. This module uses those bootstrap binaries to | |
56 | ;;; actually build up the whole tool chain that make up the implicit inputs of | |
57 | ;;; 'gnu-build-system'. | |
58 | ;;; | |
59 | ;;; To avoid circular dependencies, this module should not be imported | |
60 | ;;; directly from anywhere. | |
61 | ;;; | |
62 | ;;; Code: | |
63 | ||
64 | (define gnu-make-boot0 | |
65 | (package-with-bootstrap-guile | |
66 | (package (inherit gnu-make) | |
67 | (name "make-boot0") | |
bdb36958 LC |
68 | (arguments |
69 | `(#:guile ,%bootstrap-guile | |
70 | #:implicit-inputs? #f | |
71 | #:tests? #f ; cannot run "make check" | |
72 | ,@(substitute-keyword-arguments (package-arguments gnu-make) | |
73 | ((#:phases phases) | |
74 | `(alist-replace | |
75 | 'build (lambda _ | |
bdb36958 LC |
76 | (zero? (system* "./build.sh"))) |
77 | (alist-replace | |
78 | 'install (lambda* (#:key outputs #:allow-other-keys) | |
79 | (let* ((out (assoc-ref outputs "out")) | |
80 | (bin (string-append out "/bin"))) | |
81 | (mkdir-p bin) | |
82 | (copy-file "make" | |
83 | (string-append bin "/make")))) | |
84 | ,phases)))))) | |
85 | (native-inputs '()) ; no need for 'pkg-config' | |
86 | (inputs %bootstrap-inputs)))) | |
87 | ||
88 | (define diffutils-boot0 | |
89 | (package-with-bootstrap-guile | |
90 | (let ((p (package-with-explicit-inputs diffutils | |
91 | `(("make" ,gnu-make-boot0) | |
92 | ,@%bootstrap-inputs) | |
93 | #:guile %bootstrap-guile))) | |
94 | (package (inherit p) | |
bdb36958 LC |
95 | (arguments `(#:tests? #f ; the test suite needs diffutils |
96 | ,@(package-arguments p))))))) | |
97 | ||
98 | (define findutils-boot0 | |
99 | (package-with-bootstrap-guile | |
100 | (package-with-explicit-inputs findutils | |
101 | `(("make" ,gnu-make-boot0) | |
102 | ("diffutils" ,diffutils-boot0) ; for tests | |
103 | ,@%bootstrap-inputs) | |
104 | (current-source-location) | |
105 | #:guile %bootstrap-guile))) | |
106 | ||
c00a9fbf MW |
107 | (define file-boot0 |
108 | (package-with-bootstrap-guile | |
109 | (package-with-explicit-inputs file | |
110 | `(("make" ,gnu-make-boot0) | |
111 | ,@%bootstrap-inputs) | |
112 | (current-source-location) | |
113 | #:guile %bootstrap-guile))) | |
114 | ||
bdb36958 LC |
115 | |
116 | (define %boot0-inputs | |
117 | `(("make" ,gnu-make-boot0) | |
118 | ("diffutils" ,diffutils-boot0) | |
119 | ("findutils" ,findutils-boot0) | |
c00a9fbf | 120 | ("file" ,file-boot0) |
bdb36958 LC |
121 | ,@%bootstrap-inputs)) |
122 | ||
bdb36958 LC |
123 | (define* (boot-triplet #:optional (system (%current-system))) |
124 | ;; Return the triplet used to create the cross toolchain needed in the | |
125 | ;; first bootstrapping stage. | |
126 | (nix-system->gnu-triplet system "guix")) | |
127 | ||
128 | ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That | |
129 | ;; toolchain actually targets the same OS and arch, but it has the advantage | |
130 | ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since | |
131 | ;; GCC-BOOT0 (below) is built without any reference to the target libc. | |
132 | ||
133 | (define binutils-boot0 | |
134 | (package-with-bootstrap-guile | |
135 | (package (inherit binutils) | |
136 | (name "binutils-cross-boot0") | |
137 | (arguments | |
138 | `(#:guile ,%bootstrap-guile | |
139 | #:implicit-inputs? #f | |
f8badf15 MW |
140 | |
141 | #:modules ((guix build gnu-build-system) | |
142 | (guix build utils) | |
143 | (ice-9 ftw)) ; for 'scandir' | |
144 | #:phases (alist-cons-after | |
145 | 'install 'add-symlinks | |
146 | (lambda* (#:key outputs #:allow-other-keys) | |
147 | ;; The cross-gcc invokes 'as', 'ld', etc, without the | |
148 | ;; triplet prefix, so add symlinks. | |
149 | (let ((out (assoc-ref outputs "out")) | |
150 | (triplet-prefix (string-append ,(boot-triplet) "-"))) | |
151 | (define (has-triplet-prefix? name) | |
152 | (string-prefix? triplet-prefix name)) | |
153 | (define (remove-triplet-prefix name) | |
154 | (substring name (string-length triplet-prefix))) | |
155 | (with-directory-excursion (string-append out "/bin") | |
156 | (for-each (lambda (name) | |
157 | (symlink name (remove-triplet-prefix name))) | |
158 | (scandir "." has-triplet-prefix?))) | |
159 | #t)) | |
160 | %standard-phases) | |
161 | ||
bdb36958 LC |
162 | ,@(substitute-keyword-arguments (package-arguments binutils) |
163 | ((#:configure-flags cf) | |
164 | `(cons ,(string-append "--target=" (boot-triplet)) | |
165 | ,cf))))) | |
166 | (inputs %boot0-inputs)))) | |
167 | ||
168 | (define gcc-boot0 | |
169 | (package-with-bootstrap-guile | |
c92f1c0a | 170 | (package (inherit gcc) |
bdb36958 LC |
171 | (name "gcc-cross-boot0") |
172 | (arguments | |
173 | `(#:guile ,%bootstrap-guile | |
174 | #:implicit-inputs? #f | |
175 | #:modules ((guix build gnu-build-system) | |
176 | (guix build utils) | |
177 | (ice-9 regex) | |
178 | (srfi srfi-1) | |
179 | (srfi srfi-26)) | |
c92f1c0a | 180 | ,@(substitute-keyword-arguments (package-arguments gcc) |
bdb36958 LC |
181 | ((#:configure-flags flags) |
182 | `(append (list ,(string-append "--target=" (boot-triplet)) | |
183 | ||
184 | ;; No libc yet. | |
185 | "--without-headers" | |
186 | ||
187 | ;; Disable features not needed at this stage. | |
188 | "--disable-shared" | |
189 | "--enable-languages=c,c++" | |
190 | ||
191 | ;; libstdc++ cannot be built at this stage | |
192 | ;; ("Link tests are not allowed after | |
193 | ;; GCC_NO_EXECUTABLES."). | |
194 | "--disable-libstdc++-v3" | |
195 | ||
196 | "--disable-threads" | |
197 | "--disable-libmudflap" | |
198 | "--disable-libatomic" | |
199 | "--disable-libsanitizer" | |
200 | "--disable-libitm" | |
201 | "--disable-libgomp" | |
de4ac325 LC |
202 | "--disable-libcilkrts" |
203 | "--disable-libvtv" | |
bdb36958 LC |
204 | "--disable-libssp" |
205 | "--disable-libquadmath" | |
206 | "--disable-decimal-float") | |
207 | (remove (cut string-match "--enable-languages.*" <>) | |
208 | ,flags))) | |
209 | ((#:phases phases) | |
210 | `(alist-cons-after | |
211 | 'unpack 'unpack-gmp&co | |
212 | (lambda* (#:key inputs #:allow-other-keys) | |
213 | (let ((gmp (assoc-ref %build-inputs "gmp-source")) | |
214 | (mpfr (assoc-ref %build-inputs "mpfr-source")) | |
215 | (mpc (assoc-ref %build-inputs "mpc-source"))) | |
216 | ||
217 | ;; To reduce the set of pre-built bootstrap inputs, build | |
218 | ;; GMP & co. from GCC. | |
219 | (for-each (lambda (source) | |
220 | (or (zero? (system* "tar" "xvf" source)) | |
221 | (error "failed to unpack tarball" | |
222 | source))) | |
223 | (list gmp mpfr mpc)) | |
224 | ||
225 | ;; Create symlinks like `gmp' -> `gmp-x.y.z'. | |
226 | ,@(map (lambda (lib) | |
227 | ;; Drop trailing letters, as gmp-6.0.0a unpacks | |
228 | ;; into gmp-6.0.0. | |
229 | `(symlink ,(string-trim-right | |
230 | (package-full-name lib) | |
231 | char-set:letter) | |
232 | ,(package-name lib))) | |
233 | (list gmp mpfr mpc)))) | |
234 | (alist-cons-after | |
235 | 'install 'symlink-libgcc_eh | |
236 | (lambda* (#:key outputs #:allow-other-keys) | |
237 | (let ((out (assoc-ref outputs "lib"))) | |
238 | ;; Glibc wants to link against libgcc_eh, so provide | |
239 | ;; it. | |
240 | (with-directory-excursion | |
241 | (string-append out "/lib/gcc/" | |
242 | ,(boot-triplet) | |
c92f1c0a | 243 | "/" ,(package-version gcc)) |
bdb36958 LC |
244 | (symlink "libgcc.a" "libgcc_eh.a")))) |
245 | ,phases)))))) | |
246 | ||
247 | (inputs `(("gmp-source" ,(package-source gmp)) | |
248 | ("mpfr-source" ,(package-source mpfr)) | |
249 | ("mpc-source" ,(package-source mpc)) | |
250 | ("binutils-cross" ,binutils-boot0) | |
251 | ||
252 | ;; Call it differently so that the builder can check whether | |
253 | ;; the "libc" input is #f. | |
254 | ("libc-native" ,@(assoc-ref %boot0-inputs "libc")) | |
255 | ,@(alist-delete "libc" %boot0-inputs))) | |
256 | ||
257 | ;; No need for Texinfo at this stage. | |
258 | (native-inputs (alist-delete "texinfo" | |
c92f1c0a | 259 | (package-native-inputs gcc)))))) |
bdb36958 LC |
260 | |
261 | (define perl-boot0 | |
262 | (package-with-bootstrap-guile | |
263 | (package-with-explicit-inputs perl | |
264 | %boot0-inputs | |
265 | (current-source-location) | |
266 | #:guile %bootstrap-guile))) | |
267 | ||
268 | (define (linux-libre-headers-boot0) | |
269 | "Return Linux-Libre header files for the bootstrap environment." | |
270 | ;; Note: this is wrapped in a thunk to nicely handle circular dependencies | |
271 | ;; between (gnu packages linux) and this module. | |
272 | (package-with-bootstrap-guile | |
273 | (package (inherit linux-libre-headers) | |
274 | (arguments `(#:guile ,%bootstrap-guile | |
275 | #:implicit-inputs? #f | |
276 | ,@(package-arguments linux-libre-headers))) | |
277 | (native-inputs | |
278 | `(("perl" ,perl-boot0) | |
279 | ,@%boot0-inputs))))) | |
280 | ||
281 | (define texinfo-boot0 | |
282 | ;; Texinfo used to build libc's manual. | |
283 | ;; We build without ncurses because it fails to build at this stage, and | |
284 | ;; because we don't need the stand-alone Info reader. | |
285 | ;; Also, use %BOOT0-INPUTS to avoid building Perl once more. | |
286 | (let ((texinfo (package (inherit texinfo) | |
47ed8e04 | 287 | (native-inputs '()) |
bdb36958 LC |
288 | (inputs (alist-delete "ncurses" (package-inputs texinfo)))))) |
289 | (package-with-bootstrap-guile | |
290 | (package-with-explicit-inputs texinfo %boot0-inputs | |
291 | (current-source-location) | |
292 | #:guile %bootstrap-guile)))) | |
293 | ||
294 | (define %boot1-inputs | |
295 | ;; 2nd stage inputs. | |
296 | `(("gcc" ,gcc-boot0) | |
297 | ("binutils-cross" ,binutils-boot0) | |
f8badf15 | 298 | ,@(alist-delete "binutils" %boot0-inputs))) |
bdb36958 LC |
299 | |
300 | (define glibc-final-with-bootstrap-bash | |
301 | ;; The final libc, "cross-built". If everything went well, the resulting | |
302 | ;; store path has no dependencies. Actually, the really-final libc is | |
303 | ;; built just below; the only difference is that this one uses the | |
304 | ;; bootstrap Bash. | |
305 | (package-with-bootstrap-guile | |
306 | (package (inherit glibc) | |
307 | (name "glibc-intermediate") | |
308 | (arguments | |
309 | `(#:guile ,%bootstrap-guile | |
310 | #:implicit-inputs? #f | |
311 | ||
312 | ,@(substitute-keyword-arguments (package-arguments glibc) | |
313 | ((#:configure-flags flags) | |
314 | `(append (list ,(string-append "--host=" (boot-triplet)) | |
315 | ,(string-append "--build=" | |
316 | (nix-system->gnu-triplet)) | |
317 | ||
318 | ;; Build Sun/ONC RPC support. In particular, | |
319 | ;; install rpc/*.h. | |
320 | "--enable-obsolete-rpc") | |
321 | ,flags)) | |
322 | ((#:phases phases) | |
323 | `(alist-cons-before | |
324 | 'configure 'pre-configure | |
325 | (lambda* (#:key inputs #:allow-other-keys) | |
326 | ;; Don't clobber CPATH with the bootstrap libc. | |
327 | (setenv "NATIVE_CPATH" (getenv "CPATH")) | |
328 | (unsetenv "CPATH") | |
329 | ||
330 | ;; 'rpcgen' needs native libc headers to be built. | |
331 | (substitute* "sunrpc/Makefile" | |
332 | (("sunrpc-CPPFLAGS =.*" all) | |
333 | (string-append "CPATH = $(NATIVE_CPATH)\n" | |
334 | "export CPATH\n" | |
335 | all "\n")))) | |
336 | ,phases))))) | |
337 | (propagated-inputs `(("linux-headers" ,(linux-libre-headers-boot0)))) | |
338 | (native-inputs | |
339 | `(("texinfo" ,texinfo-boot0) | |
340 | ("perl" ,perl-boot0))) | |
341 | (inputs | |
342 | `(;; The boot inputs. That includes the bootstrap libc. We don't want | |
343 | ;; it in $CPATH, hence the 'pre-configure' phase above. | |
344 | ,@%boot1-inputs | |
345 | ||
346 | ;; A native GCC is needed to build `cross-rpcgen'. | |
347 | ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc")) | |
348 | ||
349 | ;; Here, we use the bootstrap Bash, which is not satisfactory | |
350 | ;; because we don't want to depend on bootstrap tools. | |
351 | ("static-bash" ,@(assoc-ref %boot0-inputs "bash"))))))) | |
352 | ||
353 | (define (cross-gcc-wrapper gcc binutils glibc bash) | |
354 | "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC | |
355 | that makes it available under the native tool names." | |
c92f1c0a | 356 | (package (inherit gcc) |
bdb36958 LC |
357 | (name (string-append (package-name gcc) "-wrapped")) |
358 | (source #f) | |
359 | (build-system trivial-build-system) | |
360 | (outputs '("out")) | |
361 | (arguments | |
362 | `(#:guile ,%bootstrap-guile | |
363 | #:modules ((guix build utils)) | |
364 | #:builder (begin | |
365 | (use-modules (guix build utils)) | |
366 | ||
367 | (let* ((binutils (assoc-ref %build-inputs "binutils")) | |
368 | (gcc (assoc-ref %build-inputs "gcc")) | |
369 | (libc (assoc-ref %build-inputs "libc")) | |
370 | (bash (assoc-ref %build-inputs "bash")) | |
371 | (out (assoc-ref %outputs "out")) | |
372 | (bindir (string-append out "/bin")) | |
373 | (triplet ,(boot-triplet))) | |
374 | (define (wrap-program program) | |
375 | ;; GCC-BOOT0 is a libc-less cross-compiler, so it | |
376 | ;; needs to be told where to find the crt files and | |
377 | ;; the dynamic linker. | |
378 | (call-with-output-file program | |
379 | (lambda (p) | |
380 | (format p "#!~a/bin/bash | |
381 | exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%" | |
382 | bash | |
383 | gcc triplet program | |
384 | libc libc | |
385 | ,(glibc-dynamic-linker)))) | |
386 | ||
387 | (chmod program #o555)) | |
388 | ||
389 | (mkdir-p bindir) | |
390 | (with-directory-excursion bindir | |
391 | (for-each (lambda (tool) | |
392 | (symlink (string-append binutils "/bin/" | |
393 | triplet "-" tool) | |
394 | tool)) | |
395 | '("ar" "ranlib")) | |
396 | (for-each wrap-program '("gcc" "g++"))))))) | |
397 | (native-inputs | |
398 | `(("binutils" ,binutils) | |
399 | ("gcc" ,gcc) | |
400 | ("libc" ,glibc) | |
401 | ("bash" ,bash))) | |
402 | (inputs '()))) | |
403 | ||
2d5d63d7 MW |
404 | (define bison-boot1 |
405 | ;; XXX: This Bison is needed to rebuild Bash's parser, which is modified by | |
406 | ;; its CVE patches. Remove it when it's no longer needed. | |
407 | (let* ((m4 (package-with-bootstrap-guile | |
408 | (package-with-explicit-inputs m4 %boot0-inputs | |
409 | (current-source-location) | |
410 | #:guile %bootstrap-guile))) | |
411 | (bison (package (inherit bison) | |
412 | (native-inputs `(("perl" ,perl-boot0))) | |
413 | (propagated-inputs `(("m4" ,m4))) | |
414 | (inputs '()) ;remove Flex... | |
415 | (arguments '(#:tests? #f))))) ;... and thus disable tests | |
416 | (package-with-bootstrap-guile | |
417 | (package-with-explicit-inputs bison %boot0-inputs | |
418 | (current-source-location) | |
419 | #:guile %bootstrap-guile)))) | |
420 | ||
bdb36958 | 421 | (define static-bash-for-glibc |
90d891fc | 422 | ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co. |
bdb36958 LC |
423 | (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0 |
424 | glibc-final-with-bootstrap-bash | |
425 | (car (assoc-ref %boot1-inputs "bash")))) | |
90d891fc | 426 | (bash (package (inherit static-bash) |
2d5d63d7 | 427 | (native-inputs `(("bison" ,bison-boot1))) |
bdb36958 LC |
428 | (arguments |
429 | `(#:guile ,%bootstrap-guile | |
90d891fc | 430 | ,@(package-arguments static-bash)))))) |
bdb36958 | 431 | (package-with-bootstrap-guile |
90d891fc | 432 | (package-with-explicit-inputs bash |
bdb36958 LC |
433 | `(("gcc" ,gcc) |
434 | ("libc" ,glibc-final-with-bootstrap-bash) | |
435 | ,@(fold alist-delete %boot1-inputs | |
436 | '("gcc" "libc"))) | |
d4aaf954 LC |
437 | (current-source-location) |
438 | #:guile %bootstrap-guile)))) | |
bdb36958 | 439 | |
6162b95d LC |
440 | (define gettext-boot0 |
441 | ;; A minimal gettext used during bootstrap. | |
669b8639 LC |
442 | (let ((gettext-minimal |
443 | (package (inherit gnu-gettext) | |
444 | (name "gettext-boot0") | |
445 | (inputs '()) ;zero dependencies | |
446 | (arguments | |
447 | (substitute-keyword-arguments | |
448 | `(#:tests? #f | |
449 | ,@(package-arguments gnu-gettext)) | |
450 | ((#:phases phases) | |
451 | `(modify-phases ,phases | |
452 | ;; Build only the tools. | |
453 | (add-after 'unpack 'chdir | |
454 | (lambda _ | |
455 | (chdir "gettext-tools"))) | |
456 | ||
457 | ;; Some test programs require pthreads, which we don't have. | |
458 | (add-before 'configure 'no-test-programs | |
459 | (lambda _ | |
460 | (substitute* "tests/Makefile.in" | |
461 | (("^PROGRAMS =.*$") | |
462 | "PROGRAMS =\n")) | |
463 | #t)) | |
464 | ||
465 | ;; Don't try to link against libexpat. | |
466 | (delete 'link-expat) | |
467 | (delete 'patch-tests)))))))) | |
6162b95d LC |
468 | (package-with-bootstrap-guile |
469 | (package-with-explicit-inputs gettext-minimal | |
470 | %boot1-inputs | |
471 | (current-source-location) | |
472 | #:guile %bootstrap-guile)))) | |
473 | ||
89223417 | 474 | (define glibc-final |
bdb36958 LC |
475 | ;; The final glibc, which embeds the statically-linked Bash built above. |
476 | (package (inherit glibc-final-with-bootstrap-bash) | |
477 | (name "glibc") | |
478 | (inputs `(("static-bash" ,static-bash-for-glibc) | |
479 | ,@(alist-delete | |
480 | "static-bash" | |
481 | (package-inputs glibc-final-with-bootstrap-bash)))) | |
482 | ||
6162b95d LC |
483 | ;; This time we need 'msgfmt' to install all the libc.mo files. |
484 | (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash) | |
485 | ("gettext" ,gettext-boot0))) | |
486 | ||
bdb36958 LC |
487 | ;; The final libc only refers to itself, but the 'debug' output contains |
488 | ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great | |
489 | ;; if 'allowed-references' were per-output. | |
490 | (arguments | |
491 | `(#:allowed-references | |
492 | ,(cons* `(,gcc-boot0 "lib") (linux-libre-headers-boot0) | |
90d891fc | 493 | static-bash-for-glibc |
bdb36958 LC |
494 | (package-outputs glibc-final-with-bootstrap-bash)) |
495 | ||
496 | ,@(package-arguments glibc-final-with-bootstrap-bash))))) | |
497 | ||
498 | (define gcc-boot0-wrapped | |
499 | ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the | |
500 | ;; non-cross names. | |
501 | (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final | |
502 | (car (assoc-ref %boot1-inputs "bash")))) | |
503 | ||
504 | (define %boot2-inputs | |
505 | ;; 3rd stage inputs. | |
506 | `(("libc" ,glibc-final) | |
507 | ("gcc" ,gcc-boot0-wrapped) | |
508 | ,@(fold alist-delete %boot1-inputs '("libc" "gcc")))) | |
509 | ||
510 | (define binutils-final | |
511 | (package-with-bootstrap-guile | |
512 | (package (inherit binutils) | |
513 | (arguments | |
514 | `(#:guile ,%bootstrap-guile | |
515 | #:implicit-inputs? #f | |
516 | #:allowed-references ("out" ,glibc-final) | |
517 | ,@(package-arguments binutils))) | |
518 | (inputs %boot2-inputs)))) | |
519 | ||
520 | (define libstdc++ | |
521 | ;; Intermediate libstdc++ that will allow us to build the final GCC | |
522 | ;; (remember that GCC-BOOT0 cannot build libstdc++.) | |
d0abf829 | 523 | ;; TODO: Write in terms of 'make-libstdc++'. |
bdb36958 | 524 | (package-with-bootstrap-guile |
c92f1c0a | 525 | (package (inherit gcc) |
bdb36958 LC |
526 | (name "libstdc++") |
527 | (arguments | |
528 | `(#:guile ,%bootstrap-guile | |
529 | #:implicit-inputs? #f | |
530 | ||
531 | #:out-of-source? #t | |
532 | #:phases (alist-cons-before | |
533 | 'configure 'chdir | |
534 | (lambda _ | |
535 | (chdir "libstdc++-v3")) | |
536 | %standard-phases) | |
537 | #:configure-flags `("--disable-shared" | |
538 | "--disable-libstdcxx-threads" | |
539 | "--disable-libstdcxx-pch" | |
540 | ,(string-append "--with-gxx-include-dir=" | |
541 | (assoc-ref %outputs "out") | |
542 | "/include" | |
543 | ;; "/include/c++/" | |
c92f1c0a | 544 | ;; ,(package-version gcc) |
bdb36958 LC |
545 | )))) |
546 | (outputs '("out")) | |
547 | (inputs %boot2-inputs) | |
548 | (native-inputs '()) | |
549 | (propagated-inputs '()) | |
550 | (synopsis "GNU C++ standard library (intermediate)")))) | |
551 | ||
89223417 | 552 | (define gcc-final |
bdb36958 LC |
553 | ;; The final GCC. |
554 | (package (inherit gcc-boot0) | |
555 | (name "gcc") | |
ab999c25 LC |
556 | |
557 | ;; XXX: Currently #:allowed-references applies to all the outputs but the | |
558 | ;; "debug" output contains disallowed references, notably | |
559 | ;; linux-libre-headers. Disable the debugging output to work around that. | |
560 | (outputs (delete "debug" (package-outputs gcc-boot0))) | |
561 | ||
bdb36958 LC |
562 | (arguments |
563 | `(#:guile ,%bootstrap-guile | |
564 | #:implicit-inputs? #f | |
565 | ||
90d891fc LC |
566 | #:allowed-references ("out" "lib" |
567 | ,glibc-final ,static-bash-for-glibc) | |
bdb36958 | 568 | |
d485ebba LC |
569 | ;; Things like libasan.so and libstdc++.so NEED ld.so for some |
570 | ;; reason, but it is not in their RUNPATH. This is a false | |
571 | ;; positive, so turn it off. | |
572 | #:validate-runpath? #f | |
573 | ||
bdb36958 LC |
574 | ;; Build again GMP & co. within GCC's build process, because it's hard |
575 | ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus | |
576 | ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.) | |
577 | ,@(substitute-keyword-arguments (package-arguments gcc-boot0) | |
578 | ((#:configure-flags boot-flags) | |
c92f1c0a | 579 | (let loop ((args (package-arguments gcc))) |
bdb36958 LC |
580 | (match args |
581 | ((#:configure-flags normal-flags _ ...) | |
582 | normal-flags) | |
583 | ((_ rest ...) | |
584 | (loop rest))))) | |
585 | ((#:make-flags flags) | |
586 | ;; Since $LIBRARY_PATH and $CPATH are not honored, add the | |
587 | ;; relevant flags. | |
588 | `(cons (string-append "CPPFLAGS=-I" | |
589 | (assoc-ref %build-inputs "libstdc++") | |
590 | "/include") | |
591 | (map (lambda (flag) | |
592 | (if (string-prefix? "LDFLAGS=" flag) | |
593 | (string-append flag " -L" | |
594 | (assoc-ref %build-inputs "libstdc++") | |
595 | "/lib") | |
596 | flag)) | |
597 | ,flags))) | |
598 | ((#:phases phases) | |
599 | `(alist-delete 'symlink-libgcc_eh ,phases))))) | |
600 | ||
90d891fc LC |
601 | ;; This time we want Texinfo, so we get the manual. Add |
602 | ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of | |
603 | ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these | |
604 | ;; scripts?). | |
bdb36958 | 605 | (native-inputs `(("texinfo" ,texinfo-boot0) |
90d891fc | 606 | ("static-bash" ,static-bash-for-glibc) |
bdb36958 LC |
607 | ,@(package-native-inputs gcc-boot0))) |
608 | ||
24aaf2f2 | 609 | (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp))) |
bdb36958 LC |
610 | ("mpfr-source" ,(package-source mpfr)) |
611 | ("mpc-source" ,(package-source mpc)) | |
612 | ("binutils" ,binutils-final) | |
613 | ("libstdc++" ,libstdc++) | |
614 | ,@%boot2-inputs)))) | |
615 | ||
616 | (define ld-wrapper-boot3 | |
617 | ;; A linker wrapper that uses the bootstrap Guile. | |
8fdd4101 LC |
618 | (make-ld-wrapper "ld-wrapper-boot3" |
619 | #:binutils binutils-final | |
620 | #:guile %bootstrap-guile | |
621 | #:bash (car (assoc-ref %boot2-inputs "bash")))) | |
bdb36958 LC |
622 | |
623 | (define %boot3-inputs | |
624 | ;; 4th stage inputs. | |
625 | `(("gcc" ,gcc-final) | |
626 | ("ld-wrapper" ,ld-wrapper-boot3) | |
627 | ,@(alist-delete "gcc" %boot2-inputs))) | |
628 | ||
629 | (define bash-final | |
630 | ;; Link with `-static-libgcc' to make sure we don't retain a reference | |
631 | ;; to the bootstrap GCC. | |
632 | (package-with-bootstrap-guile | |
633 | (package-with-explicit-inputs (static-libgcc-package bash) | |
634 | %boot3-inputs | |
635 | (current-source-location) | |
636 | #:guile %bootstrap-guile))) | |
637 | ||
638 | (define %boot4-inputs | |
639 | ;; Now use the final Bash. | |
640 | `(("bash" ,bash-final) | |
641 | ,@(alist-delete "bash" %boot3-inputs))) | |
642 | ||
643 | (define-public guile-final | |
644 | (package-with-bootstrap-guile | |
645 | (package-with-explicit-inputs guile-2.0/fixed | |
646 | %boot4-inputs | |
647 | (current-source-location) | |
648 | #:guile %bootstrap-guile))) | |
649 | ||
89223417 | 650 | (define glibc-utf8-locales-final |
87c8b92f LC |
651 | ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed |
652 | ;; by the build processes afterwards so their 'scm_to_locale_string' works | |
653 | ;; with the full range of Unicode codepoints (remember | |
654 | ;; 'scm_to_locale_string' is called every time a string is passed to a C | |
655 | ;; function.) | |
656 | (package | |
657 | (inherit glibc-utf8-locales) | |
658 | (inputs `(("glibc" ,glibc-final) | |
659 | ("gzip" | |
660 | ,(package-with-explicit-inputs gzip %boot4-inputs | |
661 | (current-source-location) | |
662 | #:guile %bootstrap-guile)))))) | |
663 | ||
28cbc587 LC |
664 | (define-public ld-wrapper |
665 | ;; The final 'ld' wrapper, which uses the final Guile and Binutils. | |
666 | (package (inherit ld-wrapper-boot3) | |
667 | (name "ld-wrapper") | |
668 | (inputs `(("guile" ,guile-final) | |
669 | ("bash" ,bash-final) | |
670 | ,@(fold alist-delete (package-inputs ld-wrapper-boot3) | |
671 | '("guile" "bash")))))) | |
672 | ||
87c8b92f | 673 | (define %boot5-inputs |
b6ac5451 LC |
674 | ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built |
675 | ;; with an older libc, which cannot load the new locale format. See | |
28cbc587 | 676 | ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>. |
b6ac5451 LC |
677 | `(("locales" ,glibc-utf8-locales-final) |
678 | ,@%boot4-inputs)) | |
87c8b92f | 679 | |
bdb36958 LC |
680 | (define gnu-make-final |
681 | ;; The final GNU Make, which uses the final Guile. | |
682 | (package-with-bootstrap-guile | |
683 | (package-with-explicit-inputs gnu-make | |
684 | `(("guile" ,guile-final) | |
87c8b92f | 685 | ,@%boot5-inputs) |
bdb36958 LC |
686 | (current-source-location)))) |
687 | ||
bdb36958 LC |
688 | (define coreutils-final |
689 | ;; The final Coreutils. Treat them specially because some packages, such as | |
690 | ;; Findutils, keep a reference to the Coreutils they were built with. | |
691 | (package-with-bootstrap-guile | |
692 | (package-with-explicit-inputs coreutils | |
87c8b92f | 693 | %boot5-inputs |
bdb36958 LC |
694 | (current-source-location) |
695 | ||
696 | ;; Use the final Guile, linked against the | |
697 | ;; final libc with working iconv, so that | |
698 | ;; 'substitute*' works well when touching | |
699 | ;; test files in Gettext. | |
700 | #:guile guile-final))) | |
701 | ||
702 | (define grep-final | |
703 | ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be | |
704 | ;; built before gzip. | |
705 | (package-with-bootstrap-guile | |
706 | (package-with-explicit-inputs grep | |
87c8b92f | 707 | %boot5-inputs |
bdb36958 LC |
708 | (current-source-location) |
709 | #:guile guile-final))) | |
710 | ||
87c8b92f | 711 | (define %boot6-inputs |
bdb36958 LC |
712 | ;; Now use the final Coreutils. |
713 | `(("coreutils" ,coreutils-final) | |
714 | ("grep" ,grep-final) | |
87c8b92f | 715 | ,@%boot5-inputs)) |
b0fd2bd3 | 716 | |
bdb36958 LC |
717 | (define-public %final-inputs |
718 | ;; Final derivations used as implicit inputs by 'gnu-build-system'. We | |
719 | ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are | |
720 | ;; used for origins that have patches, thereby avoiding circular | |
721 | ;; dependencies. | |
722 | (let ((finalize (compose package-with-bootstrap-guile | |
87c8b92f | 723 | (cut package-with-explicit-inputs <> %boot6-inputs |
bdb36958 LC |
724 | (current-source-location))))) |
725 | `(,@(map (match-lambda | |
726 | ((name package) | |
727 | (list name (finalize package)))) | |
728 | `(("tar" ,tar) | |
87c8b92f | 729 | ("gzip" ,gzip) |
bdb36958 LC |
730 | ("bzip2" ,bzip2) |
731 | ("xz" ,xz) | |
c00a9fbf | 732 | ("file" ,file) |
bdb36958 LC |
733 | ("diffutils" ,diffutils) |
734 | ("patch" ,patch) | |
735 | ("sed" ,sed) | |
736 | ("findutils" ,findutils) | |
737 | ("gawk" ,gawk))) | |
738 | ("grep" ,grep-final) | |
739 | ("coreutils" ,coreutils-final) | |
740 | ("make" ,gnu-make-final) | |
741 | ("bash" ,bash-final) | |
742 | ("ld-wrapper" ,ld-wrapper) | |
743 | ("binutils" ,binutils-final) | |
744 | ("gcc" ,gcc-final) | |
b0fd2bd3 LC |
745 | ("libc" ,glibc-final) |
746 | ("locales" ,glibc-utf8-locales-final)))) | |
bdb36958 LC |
747 | |
748 | (define-public canonical-package | |
749 | (let ((name->package (fold (lambda (input result) | |
750 | (match input | |
751 | ((_ package) | |
752 | (vhash-cons (package-full-name package) | |
753 | package result)))) | |
754 | vlist-null | |
755 | `(("guile" ,guile-final) | |
756 | ,@%final-inputs)))) | |
757 | (lambda (package) | |
758 | "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of | |
759 | the implicit inputs of 'gnu-build-system', return that one, otherwise return | |
760 | PACKAGE. | |
761 | ||
762 | The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.0, | |
763 | COREUTILS-FINAL vs. COREUTILS, etc." | |
764 | ;; XXX: This doesn't handle dependencies of the final inputs, such as | |
765 | ;; libunistring, GMP, etc. | |
766 | (match (vhash-assoc (package-full-name package) name->package) | |
767 | ((_ . canon) | |
768 | ;; In general we want CANON, except if we're cross-compiling: CANON | |
769 | ;; uses explicit inputs, so it is "anchored" in the bootstrapped | |
770 | ;; process, with dependencies on things that cannot be | |
771 | ;; cross-compiled. | |
772 | (if (%current-target-system) | |
773 | package | |
774 | canon)) | |
775 | (_ package))))) | |
776 | ||
777 | \f | |
778 | ;;; | |
779 | ;;; GCC toolchain. | |
780 | ;;; | |
781 | ||
782 | (define (gcc-toolchain gcc) | |
783 | "Return a complete toolchain for GCC." | |
784 | (package | |
785 | (name "gcc-toolchain") | |
786 | (version (package-version gcc)) | |
787 | (source #f) | |
788 | (build-system trivial-build-system) | |
789 | (arguments | |
790 | '(#:modules ((guix build union)) | |
791 | #:builder (begin | |
792 | (use-modules (ice-9 match) | |
6f450b87 | 793 | (srfi srfi-26) |
bdb36958 LC |
794 | (guix build union)) |
795 | ||
6f450b87 | 796 | (let ((out (assoc-ref %outputs "out"))) |
bdb36958 | 797 | |
6f450b87 LC |
798 | (match %build-inputs |
799 | (((names . directories) ...) | |
800 | (union-build out directories))) | |
801 | ||
6f450b87 LC |
802 | (union-build (assoc-ref %outputs "debug") |
803 | (list (assoc-ref %build-inputs | |
804 | "libc-debug"))))))) | |
d474d5d0 LC |
805 | |
806 | (native-search-paths (package-native-search-paths gcc)) | |
807 | (search-paths (package-search-paths gcc)) | |
808 | ||
bdb36958 LC |
809 | (license (package-license gcc)) |
810 | (synopsis "Complete GCC tool chain for C/C++ development") | |
811 | (description | |
812 | "This package provides a complete GCC tool chain for C/C++ development to | |
813 | be installed in user profiles. This includes GCC, as well as libc (headers | |
814 | and binaries, plus debugging symbols in the 'debug' output), and Binutils.") | |
815 | (home-page "http://gcc.gnu.org/") | |
816 | (outputs '("out" "debug")) | |
817 | ||
818 | ;; The main raison d'être of this "meta-package" is (1) to conveniently | |
819 | ;; install everything that we need, and (2) to make sure ld-wrapper comes | |
820 | ;; before Binutils' ld in the user's profile. | |
821 | (inputs `(("gcc" ,gcc) | |
cbbb11c8 | 822 | ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper"))) |
bdb36958 LC |
823 | ("binutils" ,binutils-final) |
824 | ("libc" ,glibc-final) | |
825 | ("libc-debug" ,glibc-final "debug"))))) | |
826 | ||
827 | (define-public gcc-toolchain-4.8 | |
828 | (gcc-toolchain gcc-final)) | |
829 | ||
830 | (define-public gcc-toolchain-4.9 | |
831 | (gcc-toolchain gcc-4.9)) | |
832 | ||
629f4d2e MW |
833 | (define-public gcc-toolchain-5 |
834 | (gcc-toolchain gcc-5)) | |
60e2d5fe | 835 | |
bdb36958 | 836 | ;;; commencement.scm ends here |