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