Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
4050e5d6 | 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> |
18633d4f | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
18633d4f | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
18633d4f LC |
7 | ;;; under the terms of the GNU General Public License as published by |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
18633d4f LC |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
18633d4f | 18 | |
1ffa7090 | 19 | (define-module (gnu packages bootstrap) |
4a44e743 | 20 | #:use-module (guix licenses) |
59a43334 | 21 | #:use-module (gnu packages) |
18633d4f | 22 | #:use-module (guix packages) |
62cab99c | 23 | #:use-module (guix download) |
18633d4f LC |
24 | #:use-module (guix build-system) |
25 | #:use-module (guix build-system gnu) | |
26 | #:use-module (guix build-system trivial) | |
27 | #:use-module ((guix store) #:select (add-to-store add-text-to-store)) | |
28 | #:use-module ((guix derivations) #:select (derivation)) | |
29 | #:use-module (guix utils) | |
30 | #:use-module (srfi srfi-1) | |
31 | #:use-module (srfi srfi-26) | |
32 | #:use-module (ice-9 match) | |
33 | #:export (bootstrap-origin | |
34 | package-with-bootstrap-guile | |
35 | glibc-dynamic-linker | |
36 | ||
37 | %bootstrap-guile | |
38 | %bootstrap-coreutils&co | |
39 | %bootstrap-binutils | |
40 | %bootstrap-gcc | |
41 | %bootstrap-glibc | |
42 | %bootstrap-inputs)) | |
43 | ||
44 | ;;; Commentary: | |
45 | ;;; | |
46 | ;;; Pre-built packages that are used to bootstrap the | |
47 | ;;; distribution--i.e., to build all the core packages from scratch. | |
48 | ;;; | |
49 | ;;; Code: | |
50 | ||
51 | ||
52 | \f | |
53 | ;;; | |
54 | ;;; Helper procedures. | |
55 | ;;; | |
56 | ||
57 | (define (bootstrap-origin source) | |
58 | "Return a variant of SOURCE, an <origin> instance, whose method uses | |
59 | %BOOTSTRAP-GUILE to do its job." | |
60 | (define (boot fetch) | |
61 | (lambda* (store url hash-algo hash | |
62 | #:optional name #:key system) | |
63 | (fetch store url hash-algo hash | |
64 | #:guile %bootstrap-guile | |
65 | #:system system))) | |
66 | ||
5fbeb4e6 LC |
67 | (define %bootstrap-patch-inputs |
68 | ;; Packages used when an <origin> has a non-empty 'patches' field. | |
69 | `(("tar" ,%bootstrap-coreutils&co) | |
70 | ("xz" ,%bootstrap-coreutils&co) | |
71 | ("bzip2" ,%bootstrap-coreutils&co) | |
72 | ("gzip" ,%bootstrap-coreutils&co) | |
73 | ("patch" ,%bootstrap-coreutils&co))) | |
74 | ||
18633d4f LC |
75 | (let ((orig-method (origin-method source))) |
76 | (origin (inherit source) | |
87f5d366 | 77 | (method (cond ((eq? orig-method url-fetch) |
62cab99c | 78 | (boot url-fetch)) |
5fbeb4e6 LC |
79 | (else orig-method))) |
80 | (patch-guile %bootstrap-guile) | |
81 | (patch-inputs %bootstrap-patch-inputs)))) | |
18633d4f | 82 | |
dfb52abb LC |
83 | (define (package-from-tarball name source program-to-test description) |
84 | "Return a package that correspond to the extraction of SOURCE. | |
85 | PROGRAM-TO-TEST is a program to run after extraction of SOURCE, to | |
18633d4f LC |
86 | check whether everything is alright." |
87 | (package | |
dfb52abb | 88 | (name name) |
18633d4f | 89 | (version "0") |
18633d4f LC |
90 | (build-system trivial-build-system) |
91 | (arguments | |
92 | `(#:guile ,%bootstrap-guile | |
93 | #:modules ((guix build utils)) | |
94 | #:builder | |
95 | (let ((out (assoc-ref %outputs "out")) | |
96 | (tar (assoc-ref %build-inputs "tar")) | |
97 | (xz (assoc-ref %build-inputs "xz")) | |
98 | (tarball (assoc-ref %build-inputs "tarball"))) | |
99 | (use-modules (guix build utils)) | |
100 | ||
101 | (mkdir out) | |
102 | (copy-file tarball "binaries.tar.xz") | |
103 | (system* xz "-d" "binaries.tar.xz") | |
104 | (let ((builddir (getcwd))) | |
105 | (with-directory-excursion out | |
106 | (and (zero? (system* tar "xvf" | |
107 | (string-append builddir "/binaries.tar"))) | |
108 | (zero? (system* (string-append "bin/" ,program-to-test) | |
109 | "--version")))))))) | |
110 | (inputs | |
dd6b9a37 LC |
111 | `(("tar" ,(search-bootstrap-binary "tar" (%current-system))) |
112 | ("xz" ,(search-bootstrap-binary "xz" (%current-system))) | |
dfb52abb LC |
113 | ("tarball" ,(bootstrap-origin (source (%current-system)))))) |
114 | (source #f) | |
115 | (synopsis description) | |
18633d4f | 116 | (description #f) |
1fb78cb2 LC |
117 | (home-page #f) |
118 | (license #f))) | |
18633d4f LC |
119 | |
120 | (define package-with-bootstrap-guile | |
121 | (memoize | |
122 | (lambda (p) | |
123 | "Return a variant of P such that all its origins are fetched with | |
124 | %BOOTSTRAP-GUILE." | |
125 | (define rewritten-input | |
126 | (match-lambda | |
127 | ((name (? origin? o)) | |
128 | `(,name ,(bootstrap-origin o))) | |
129 | ((name (? package? p) sub-drvs ...) | |
130 | `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs)) | |
131 | (x x))) | |
132 | ||
133 | (package (inherit p) | |
134 | (source (match (package-source p) | |
135 | ((? origin? o) (bootstrap-origin o)) | |
136 | (s s))) | |
137 | (inputs (map rewritten-input | |
138 | (package-inputs p))) | |
139 | (native-inputs (map rewritten-input | |
140 | (package-native-inputs p))) | |
141 | (propagated-inputs (map rewritten-input | |
142 | (package-propagated-inputs p))))))) | |
143 | ||
e7133c76 LC |
144 | (define* (glibc-dynamic-linker |
145 | #:optional (system (or (and=> (%current-target-system) | |
146 | gnu-triplet->nix-system) | |
147 | (%current-system)))) | |
18633d4f LC |
148 | "Return the name of Glibc's dynamic linker for SYSTEM." |
149 | (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2") | |
150 | ((string=? system "i686-linux") "/lib/ld-linux.so.2") | |
827d2891 | 151 | ((string=? system "mips64el-linux") "/lib/ld.so.1") |
18633d4f LC |
152 | (else (error "dynamic linker name not known for this system" |
153 | system)))) | |
154 | ||
155 | \f | |
156 | ;;; | |
157 | ;;; Bootstrap packages. | |
158 | ;;; | |
159 | ||
160 | (define %bootstrap-guile | |
161 | ;; The Guile used to run the build scripts of the initial derivations. | |
162 | ;; It is just unpacked from a tarball containing a pre-built binary. | |
163 | ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below. | |
164 | ;; | |
165 | ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo' | |
166 | ;; support (for /etc/services). | |
167 | (let ((raw (build-system | |
168 | (name "raw") | |
169 | (description "Raw build system with direct store access") | |
a18eda27 LC |
170 | (build (lambda* (store name source inputs |
171 | #:key outputs system search-paths) | |
18633d4f | 172 | (define (->store file) |
a9ebd9ef | 173 | (add-to-store store file #t "sha256" |
18633d4f LC |
174 | (or (search-bootstrap-binary file |
175 | system) | |
176 | (error "bootstrap binary not found" | |
177 | file system)))) | |
178 | ||
179 | (let* ((tar (->store "tar")) | |
180 | (xz (->store "xz")) | |
181 | (mkdir (->store "mkdir")) | |
182 | (bash (->store "bash")) | |
06213498 | 183 | (guile (->store "guile-2.0.9.tar.xz")) |
18633d4f LC |
184 | (builder |
185 | (add-text-to-store store | |
186 | "build-bootstrap-guile.sh" | |
187 | (format #f " | |
188 | echo \"unpacking bootstrap Guile to '$out'...\" | |
189 | ~a $out | |
190 | cd $out | |
191 | ~a -dc < ~a | ~a xv | |
192 | ||
193 | # Sanity check. | |
194 | $out/bin/guile --version~%" | |
195 | mkdir xz guile tar) | |
196 | (list mkdir xz guile tar)))) | |
a987d2c0 LC |
197 | (derivation store name |
198 | bash `(,builder) | |
199 | #:system system | |
200 | #:inputs `((,bash) (,builder))))))))) | |
18633d4f LC |
201 | (package |
202 | (name "guile-bootstrap") | |
203 | (version "2.0") | |
204 | (source #f) | |
205 | (build-system raw) | |
206 | (synopsis "Bootstrap Guile") | |
207 | (description "Pre-built Guile for bootstrapping purposes.") | |
208 | (home-page #f) | |
4a44e743 | 209 | (license lgpl3+)))) |
18633d4f | 210 | |
04732c37 | 211 | (define %bootstrap-base-urls |
18633d4f | 212 | ;; This is where the initial binaries come from. |
04732c37 LC |
213 | '("http://alpha.gnu.org/gnu/guix/bootstrap" |
214 | "http://www.fdn.fr/~lcourtes/software/guix/packages")) | |
18633d4f LC |
215 | |
216 | (define %bootstrap-coreutils&co | |
217 | (package-from-tarball "bootstrap-binaries" | |
218 | (lambda (system) | |
219 | (origin | |
87f5d366 | 220 | (method url-fetch) |
04732c37 | 221 | (uri (map (cut string-append <> "/" system |
06213498 | 222 | "/20131110/static-binaries.tar.xz") |
04732c37 | 223 | %bootstrap-base-urls)) |
18633d4f LC |
224 | (sha256 |
225 | (match system | |
226 | ("x86_64-linux" | |
227 | (base32 | |
06213498 | 228 | "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4")) |
18633d4f LC |
229 | ("i686-linux" |
230 | (base32 | |
06213498 | 231 | "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak")) |
f57ff219 MW |
232 | ("mips64el-linux" |
233 | (base32 | |
06213498 | 234 | "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753")))))) |
18633d4f LC |
235 | "true" ; the program to test |
236 | "Bootstrap binaries of Coreutils, Awk, etc.")) | |
237 | ||
238 | (define %bootstrap-binutils | |
239 | (package-from-tarball "binutils-bootstrap" | |
240 | (lambda (system) | |
241 | (origin | |
87f5d366 | 242 | (method url-fetch) |
04732c37 | 243 | (uri (map (cut string-append <> "/" system |
06213498 | 244 | "/20131110/binutils-2.23.2.tar.xz") |
04732c37 | 245 | %bootstrap-base-urls)) |
18633d4f LC |
246 | (sha256 |
247 | (match system | |
248 | ("x86_64-linux" | |
249 | (base32 | |
06213498 | 250 | "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20")) |
18633d4f LC |
251 | ("i686-linux" |
252 | (base32 | |
06213498 | 253 | "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9")) |
f57ff219 MW |
254 | ("mips64el-linux" |
255 | (base32 | |
06213498 | 256 | "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7")))))) |
18633d4f LC |
257 | "ld" ; the program to test |
258 | "Bootstrap binaries of the GNU Binutils")) | |
259 | ||
260 | (define %bootstrap-glibc | |
261 | ;; The initial libc. | |
262 | (package | |
263 | (name "glibc-bootstrap") | |
264 | (version "0") | |
265 | (source #f) | |
266 | (build-system trivial-build-system) | |
267 | (arguments | |
268 | `(#:guile ,%bootstrap-guile | |
269 | #:modules ((guix build utils)) | |
270 | #:builder | |
271 | (let ((out (assoc-ref %outputs "out")) | |
272 | (tar (assoc-ref %build-inputs "tar")) | |
273 | (xz (assoc-ref %build-inputs "xz")) | |
274 | (tarball (assoc-ref %build-inputs "tarball"))) | |
275 | (use-modules (guix build utils)) | |
276 | ||
277 | (mkdir out) | |
278 | (copy-file tarball "binaries.tar.xz") | |
279 | (system* xz "-d" "binaries.tar.xz") | |
280 | (let ((builddir (getcwd))) | |
281 | (with-directory-excursion out | |
282 | (system* tar "xvf" | |
283 | (string-append builddir | |
284 | "/binaries.tar")) | |
285 | (chmod "lib" #o755) | |
286 | ||
287 | ;; Patch libc.so so it refers to the right path. | |
288 | (substitute* "lib/libc.so" | |
289 | (("/[^ ]+/lib/(libc|ld)" _ prefix) | |
290 | (string-append out "/lib/" prefix)))))))) | |
291 | (inputs | |
dd6b9a37 LC |
292 | `(("tar" ,(search-bootstrap-binary "tar" (%current-system))) |
293 | ("xz" ,(search-bootstrap-binary "xz" (%current-system))) | |
294 | ("tarball" ,(bootstrap-origin | |
295 | (origin | |
296 | (method url-fetch) | |
297 | (uri (map (cut string-append <> "/" (%current-system) | |
06213498 | 298 | "/20131110/glibc-2.18.tar.xz") |
dd6b9a37 LC |
299 | %bootstrap-base-urls)) |
300 | (sha256 | |
301 | (match (%current-system) | |
302 | ("x86_64-linux" | |
303 | (base32 | |
06213498 | 304 | "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v")) |
dd6b9a37 LC |
305 | ("i686-linux" |
306 | (base32 | |
06213498 | 307 | "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w")) |
f57ff219 MW |
308 | ("mips64el-linux" |
309 | (base32 | |
06213498 | 310 | "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg"))))))))) |
18633d4f LC |
311 | (synopsis "Bootstrap binaries and headers of the GNU C Library") |
312 | (description #f) | |
1fb78cb2 LC |
313 | (home-page #f) |
314 | (license lgpl2.1+))) | |
18633d4f LC |
315 | |
316 | (define %bootstrap-gcc | |
317 | ;; The initial GCC. Uses binaries from a tarball typically built by | |
318 | ;; %GCC-BOOTSTRAP-TARBALL. | |
319 | (package | |
320 | (name "gcc-bootstrap") | |
321 | (version "0") | |
322 | (source #f) | |
323 | (build-system trivial-build-system) | |
324 | (arguments | |
21c203a5 LC |
325 | `(#:guile ,%bootstrap-guile |
326 | #:modules ((guix build utils)) | |
327 | #:builder | |
328 | (let ((out (assoc-ref %outputs "out")) | |
329 | (tar (assoc-ref %build-inputs "tar")) | |
330 | (xz (assoc-ref %build-inputs "xz")) | |
331 | (bash (assoc-ref %build-inputs "bash")) | |
332 | (libc (assoc-ref %build-inputs "libc")) | |
333 | (tarball (assoc-ref %build-inputs "tarball"))) | |
334 | (use-modules (guix build utils) | |
335 | (ice-9 popen)) | |
18633d4f | 336 | |
21c203a5 LC |
337 | (mkdir out) |
338 | (copy-file tarball "binaries.tar.xz") | |
339 | (system* xz "-d" "binaries.tar.xz") | |
340 | (let ((builddir (getcwd)) | |
341 | (bindir (string-append out "/bin"))) | |
342 | (with-directory-excursion out | |
343 | (system* tar "xvf" | |
344 | (string-append builddir "/binaries.tar"))) | |
18633d4f | 345 | |
21c203a5 LC |
346 | (with-directory-excursion bindir |
347 | (chmod "." #o755) | |
348 | (rename-file "gcc" ".gcc-wrapped") | |
349 | (call-with-output-file "gcc" | |
350 | (lambda (p) | |
351 | (format p "#!~a | |
18633d4f LC |
352 | exec ~a/bin/.gcc-wrapped -B~a/lib \ |
353 | -Wl,-rpath -Wl,~a/lib \ | |
354 | -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%" | |
21c203a5 LC |
355 | bash |
356 | out libc libc libc | |
357 | ,(glibc-dynamic-linker)))) | |
18633d4f | 358 | |
21c203a5 | 359 | (chmod "gcc" #o555)))))) |
18633d4f | 360 | (inputs |
dd6b9a37 LC |
361 | `(("tar" ,(search-bootstrap-binary "tar" (%current-system))) |
362 | ("xz" ,(search-bootstrap-binary "xz" (%current-system))) | |
363 | ("bash" ,(search-bootstrap-binary "bash" (%current-system))) | |
18633d4f | 364 | ("libc" ,%bootstrap-glibc) |
dd6b9a37 LC |
365 | ("tarball" ,(bootstrap-origin |
366 | (origin | |
367 | (method url-fetch) | |
368 | (uri (map (cut string-append <> "/" (%current-system) | |
06213498 | 369 | "/20131110/gcc-4.8.2.tar.xz") |
dd6b9a37 LC |
370 | %bootstrap-base-urls)) |
371 | (sha256 | |
372 | (match (%current-system) | |
373 | ("x86_64-linux" | |
374 | (base32 | |
06213498 | 375 | "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls")) |
dd6b9a37 LC |
376 | ("i686-linux" |
377 | (base32 | |
06213498 | 378 | "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw")) |
f57ff219 MW |
379 | ("mips64el-linux" |
380 | (base32 | |
06213498 | 381 | "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks"))))))))) |
a18eda27 LC |
382 | (native-search-paths |
383 | (list (search-path-specification | |
384 | (variable "CPATH") | |
385 | (directories '("include"))) | |
386 | (search-path-specification | |
387 | (variable "LIBRARY_PATH") | |
388 | (directories '("lib" "lib64"))))) | |
18633d4f LC |
389 | (synopsis "Bootstrap binaries of the GNU Compiler Collection") |
390 | (description #f) | |
1fb78cb2 LC |
391 | (home-page #f) |
392 | (license gpl3+))) | |
18633d4f LC |
393 | |
394 | (define %bootstrap-inputs | |
395 | ;; The initial, pre-built inputs. From now on, we can start building our | |
396 | ;; own packages. | |
397 | `(("libc" ,%bootstrap-glibc) | |
398 | ("gcc" ,%bootstrap-gcc) | |
399 | ("binutils" ,%bootstrap-binutils) | |
9d1d434c LC |
400 | ("coreutils&co" ,%bootstrap-coreutils&co) |
401 | ||
402 | ;; In gnu-build-system.scm, we rely on the availability of Bash. | |
403 | ("bash" ,%bootstrap-coreutils&co))) | |
18633d4f LC |
404 | |
405 | ;;; bootstrap.scm ends here |