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