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