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