gnu: clisp: Remove timestamps.
[jackhill/guix/guix.git] / gnu / packages / bootstrap.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
52c0c82f 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
2959dbe9 3;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
18633d4f 4;;;
233e7676 5;;; This file is part of GNU Guix.
18633d4f 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
18633d4f
LC
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
18633d4f
LC
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18633d4f 19
1ffa7090 20(define-module (gnu packages bootstrap)
4a44e743 21 #:use-module (guix licenses)
59a43334 22 #:use-module (gnu packages)
18633d4f 23 #:use-module (guix packages)
62cab99c 24 #:use-module (guix download)
18633d4f
LC
25 #:use-module (guix build-system)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system trivial)
28 #:use-module ((guix store) #:select (add-to-store add-text-to-store))
29 #:use-module ((guix derivations) #:select (derivation))
958dd3ce
LC
30 #:use-module ((guix utils) #:select (gnu-triplet->nix-system))
31 #:use-module (guix combinators)
18633d4f
LC
32 #:use-module (srfi srfi-1)
33 #:use-module (srfi srfi-26)
34 #:use-module (ice-9 match)
35 #:export (bootstrap-origin
36 package-with-bootstrap-guile
37 glibc-dynamic-linker
38
39 %bootstrap-guile
40 %bootstrap-coreutils&co
41 %bootstrap-binutils
42 %bootstrap-gcc
43 %bootstrap-glibc
44 %bootstrap-inputs))
45
46;;; Commentary:
47;;;
48;;; Pre-built packages that are used to bootstrap the
49;;; distribution--i.e., to build all the core packages from scratch.
50;;;
51;;; Code:
52
53
54\f
55;;;
56;;; Helper procedures.
57;;;
58
59(define (bootstrap-origin source)
60 "Return a variant of SOURCE, an <origin> instance, whose method uses
61%BOOTSTRAP-GUILE to do its job."
62 (define (boot fetch)
f220a838 63 (lambda* (url hash-algo hash
18633d4f 64 #:optional name #:key system)
52c0c82f 65 (fetch url hash-algo hash name
18633d4f
LC
66 #:guile %bootstrap-guile
67 #:system system)))
68
5fbeb4e6
LC
69 (define %bootstrap-patch-inputs
70 ;; Packages used when an <origin> has a non-empty 'patches' field.
71 `(("tar" ,%bootstrap-coreutils&co)
72 ("xz" ,%bootstrap-coreutils&co)
73 ("bzip2" ,%bootstrap-coreutils&co)
74 ("gzip" ,%bootstrap-coreutils&co)
75 ("patch" ,%bootstrap-coreutils&co)))
76
18633d4f
LC
77 (let ((orig-method (origin-method source)))
78 (origin (inherit source)
87f5d366 79 (method (cond ((eq? orig-method url-fetch)
62cab99c 80 (boot url-fetch))
5fbeb4e6
LC
81 (else orig-method)))
82 (patch-guile %bootstrap-guile)
ce517b20
LC
83 (patch-inputs %bootstrap-patch-inputs)
84
85 ;; Patches can be origins as well, so process them.
86 (patches (map (match-lambda
87 ((? origin? patch)
88 (bootstrap-origin patch))
89 (patch patch))
90 (origin-patches source))))))
18633d4f 91
2959dbe9
MW
92(define* (package-from-tarball name source program-to-test description
93 #:key snippet)
dfb52abb
LC
94 "Return a package that correspond to the extraction of SOURCE.
95PROGRAM-TO-TEST is a program to run after extraction of SOURCE, to
2959dbe9
MW
96check whether everything is alright. If SNIPPET is provided, it is
97evaluated after extracting SOURCE. SNIPPET should return true if
98successful, or false to signal an error."
18633d4f 99 (package
dfb52abb 100 (name name)
18633d4f 101 (version "0")
18633d4f
LC
102 (build-system trivial-build-system)
103 (arguments
104 `(#:guile ,%bootstrap-guile
105 #:modules ((guix build utils))
106 #:builder
107 (let ((out (assoc-ref %outputs "out"))
108 (tar (assoc-ref %build-inputs "tar"))
109 (xz (assoc-ref %build-inputs "xz"))
110 (tarball (assoc-ref %build-inputs "tarball")))
111 (use-modules (guix build utils))
112
113 (mkdir out)
114 (copy-file tarball "binaries.tar.xz")
115 (system* xz "-d" "binaries.tar.xz")
116 (let ((builddir (getcwd)))
117 (with-directory-excursion out
118 (and (zero? (system* tar "xvf"
119 (string-append builddir "/binaries.tar")))
2959dbe9 120 ,@(if snippet (list snippet) '())
18633d4f
LC
121 (zero? (system* (string-append "bin/" ,program-to-test)
122 "--version"))))))))
123 (inputs
dd6b9a37
LC
124 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
125 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
dfb52abb
LC
126 ("tarball" ,(bootstrap-origin (source (%current-system))))))
127 (source #f)
128 (synopsis description)
7de1f103 129 (description description)
1fb78cb2 130 (home-page #f)
90f2801e 131 (license gpl3+)))
18633d4f
LC
132
133(define package-with-bootstrap-guile
134 (memoize
135 (lambda (p)
136 "Return a variant of P such that all its origins are fetched with
137%BOOTSTRAP-GUILE."
138 (define rewritten-input
139 (match-lambda
140 ((name (? origin? o))
141 `(,name ,(bootstrap-origin o)))
142 ((name (? package? p) sub-drvs ...)
143 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
144 (x x)))
145
146 (package (inherit p)
147 (source (match (package-source p)
148 ((? origin? o) (bootstrap-origin o))
149 (s s)))
150 (inputs (map rewritten-input
151 (package-inputs p)))
152 (native-inputs (map rewritten-input
153 (package-native-inputs p)))
154 (propagated-inputs (map rewritten-input
05962f29
LC
155 (package-propagated-inputs p)))
156 (replacement (and=> (package-replacement p)
157 package-with-bootstrap-guile))))))
18633d4f 158
e7133c76
LC
159(define* (glibc-dynamic-linker
160 #:optional (system (or (and=> (%current-target-system)
161 gnu-triplet->nix-system)
162 (%current-system))))
18633d4f
LC
163 "Return the name of Glibc's dynamic linker for SYSTEM."
164 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
165 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
3f00ff8b 166 ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
827d2891 167 ((string=? system "mips64el-linux") "/lib/ld.so.1")
66feaa32
MB
168 ((string=? system "i586-gnu") "/lib/ld.so.1")
169 ((string=? system "i686-gnu") "/lib/ld.so.1")
19c444f4 170 ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
9d307460
LC
171
172 ;; XXX: This one is used bare-bones, without a libc, so add a case
173 ;; here just so we can keep going.
35a37efb 174 ((string=? system "arm-eabi") "no-ld.so")
9d307460 175 ((string=? system "xtensa-elf") "no-ld.so")
a5b60e3c 176 ((string=? system "avr") "no-ld.so")
3135b95f 177 ((string=? system "i686-mingw") "no-ld.so")
9d307460 178
18633d4f
LC
179 (else (error "dynamic linker name not known for this system"
180 system))))
181
182\f
183;;;
184;;; Bootstrap packages.
185;;;
186
0d5a559f
LC
187(define* (raw-build store name inputs
188 #:key outputs system search-paths
189 #:allow-other-keys)
190 (define (->store file)
191 (add-to-store store file #t "sha256"
192 (or (search-bootstrap-binary file
193 system)
194 (error "bootstrap binary not found"
195 file system))))
196
197 (let* ((tar (->store "tar"))
198 (xz (->store "xz"))
199 (mkdir (->store "mkdir"))
200 (bash (->store "bash"))
aa1e1947
MW
201 (guile (->store (match system
202 ("armhf-linux"
203 "guile-2.0.11.tar.xz")
204 (_
205 "guile-2.0.9.tar.xz"))))
5d6792f0
MW
206 ;; The following code, run by the bootstrap guile after it is
207 ;; unpacked, creates a wrapper for itself to set its load path.
208 ;; This replaces the previous non-portable method based on
209 ;; reading the /proc/self/exe symlink.
210 (make-guile-wrapper
211 '(begin
212 (use-modules (ice-9 match))
213 (match (command-line)
214 ((_ out bash)
215 (let ((bin-dir (string-append out "/bin"))
216 (guile (string-append out "/bin/guile"))
217 (guile-real (string-append out "/bin/.guile-real"))
218 ;; We must avoid using a bare dollar sign in this code,
219 ;; because it would be interpreted by the shell.
220 (dollar (string (integer->char 36))))
221 (chmod bin-dir #o755)
222 (rename-file guile guile-real)
223 (call-with-output-file guile
224 (lambda (p)
225 (format p "\
226#!~a
227export GUILE_SYSTEM_PATH=~a/share/guile/2.0
228export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
229exec -a \"~a0\" ~a \"~a@\"\n"
230 bash out out dollar guile-real dollar)))
231 (chmod guile #o555)
232 (chmod bin-dir #o555))))))
0d5a559f
LC
233 (builder
234 (add-text-to-store store
235 "build-bootstrap-guile.sh"
236 (format #f "
237echo \"unpacking bootstrap Guile to '$out'...\"
238~a $out
239cd $out
240~a -dc < ~a | ~a xv
241
5d6792f0
MW
242# Use the bootstrap guile to create its own wrapper to set the load path.
243GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
244GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
245$out/bin/guile -c ~s $out ~a
246
0d5a559f
LC
247# Sanity check.
248$out/bin/guile --version~%"
5d6792f0
MW
249 mkdir xz guile tar
250 (format #f "~s" make-guile-wrapper)
251 bash)
252 (list mkdir xz guile tar bash))))
0d5a559f
LC
253 (derivation store name
254 bash `(,builder)
255 #:system system
256 #:inputs `((,bash) (,builder)))))
257
258(define* (make-raw-bag name
d3d337d2
LC
259 #:key source inputs native-inputs outputs
260 system target)
0d5a559f
LC
261 (bag
262 (name name)
d3d337d2 263 (system system)
0d5a559f
LC
264 (build-inputs inputs)
265 (build raw-build)))
266
18633d4f
LC
267(define %bootstrap-guile
268 ;; The Guile used to run the build scripts of the initial derivations.
269 ;; It is just unpacked from a tarball containing a pre-built binary.
270 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
271 ;;
272 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
273 ;; support (for /etc/services).
274 (let ((raw (build-system
0d5a559f
LC
275 (name 'raw)
276 (description "Raw build system with direct store access")
277 (lower make-raw-bag))))
18633d4f
LC
278 (package
279 (name "guile-bootstrap")
280 (version "2.0")
281 (source #f)
282 (build-system raw)
283 (synopsis "Bootstrap Guile")
284 (description "Pre-built Guile for bootstrapping purposes.")
285 (home-page #f)
4a44e743 286 (license lgpl3+))))
18633d4f 287
04732c37 288(define %bootstrap-base-urls
18633d4f 289 ;; This is where the initial binaries come from.
d44fb7dd
LC
290 '("ftp://alpha.gnu.org/gnu/guix/bootstrap"
291 "http://alpha.gnu.org/gnu/guix/bootstrap"
04732c37 292 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
18633d4f
LC
293
294(define %bootstrap-coreutils&co
295 (package-from-tarball "bootstrap-binaries"
296 (lambda (system)
297 (origin
87f5d366 298 (method url-fetch)
04732c37 299 (uri (map (cut string-append <> "/" system
aa1e1947
MW
300 (match system
301 ("armhf-linux"
302 "/20150101/static-binaries.tar.xz")
303 (_
304 "/20131110/static-binaries.tar.xz")))
04732c37 305 %bootstrap-base-urls))
18633d4f
LC
306 (sha256
307 (match system
308 ("x86_64-linux"
309 (base32
06213498 310 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
18633d4f
LC
311 ("i686-linux"
312 (base32
06213498 313 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
aa1e1947
MW
314 ("armhf-linux"
315 (base32
316 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
f57ff219
MW
317 ("mips64el-linux"
318 (base32
06213498 319 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
84cbe39c
MW
320 "fgrep" ; the program to test
321 "Bootstrap binaries of Coreutils, Awk, etc."
322 #:snippet
323 '(let ((path (list (string-append (getcwd) "/bin"))))
324 (chmod "bin" #o755)
325 (patch-shebang "bin/egrep" path)
326 (patch-shebang "bin/fgrep" path)
327 (chmod "bin" #o555)
328 #t)))
18633d4f
LC
329
330(define %bootstrap-binutils
331 (package-from-tarball "binutils-bootstrap"
332 (lambda (system)
333 (origin
87f5d366 334 (method url-fetch)
04732c37 335 (uri (map (cut string-append <> "/" system
aa1e1947
MW
336 (match system
337 ("armhf-linux"
338 "/20150101/binutils-2.25.tar.xz")
339 (_
340 "/20131110/binutils-2.23.2.tar.xz")))
04732c37 341 %bootstrap-base-urls))
18633d4f
LC
342 (sha256
343 (match system
344 ("x86_64-linux"
345 (base32
06213498 346 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
18633d4f
LC
347 ("i686-linux"
348 (base32
06213498 349 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
aa1e1947
MW
350 ("armhf-linux"
351 (base32
352 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
f57ff219
MW
353 ("mips64el-linux"
354 (base32
06213498 355 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
18633d4f
LC
356 "ld" ; the program to test
357 "Bootstrap binaries of the GNU Binutils"))
358
359(define %bootstrap-glibc
360 ;; The initial libc.
361 (package
362 (name "glibc-bootstrap")
363 (version "0")
364 (source #f)
365 (build-system trivial-build-system)
366 (arguments
367 `(#:guile ,%bootstrap-guile
368 #:modules ((guix build utils))
369 #:builder
370 (let ((out (assoc-ref %outputs "out"))
371 (tar (assoc-ref %build-inputs "tar"))
372 (xz (assoc-ref %build-inputs "xz"))
373 (tarball (assoc-ref %build-inputs "tarball")))
374 (use-modules (guix build utils))
375
376 (mkdir out)
377 (copy-file tarball "binaries.tar.xz")
378 (system* xz "-d" "binaries.tar.xz")
379 (let ((builddir (getcwd)))
380 (with-directory-excursion out
381 (system* tar "xvf"
382 (string-append builddir
383 "/binaries.tar"))
384 (chmod "lib" #o755)
385
386 ;; Patch libc.so so it refers to the right path.
387 (substitute* "lib/libc.so"
388 (("/[^ ]+/lib/(libc|ld)" _ prefix)
389 (string-append out "/lib/" prefix))))))))
390 (inputs
dd6b9a37
LC
391 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
392 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
393 ("tarball" ,(bootstrap-origin
394 (origin
395 (method url-fetch)
396 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
397 (match (%current-system)
398 ("armhf-linux"
399 "/20150101/glibc-2.20.tar.xz")
400 (_
401 "/20131110/glibc-2.18.tar.xz")))
dd6b9a37
LC
402 %bootstrap-base-urls))
403 (sha256
404 (match (%current-system)
405 ("x86_64-linux"
406 (base32
06213498 407 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
dd6b9a37
LC
408 ("i686-linux"
409 (base32
06213498 410 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
aa1e1947
MW
411 ("armhf-linux"
412 (base32
413 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
f57ff219
MW
414 ("mips64el-linux"
415 (base32
06213498 416 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
18633d4f 417 (synopsis "Bootstrap binaries and headers of the GNU C Library")
7de1f103 418 (description synopsis)
1fb78cb2
LC
419 (home-page #f)
420 (license lgpl2.1+)))
18633d4f
LC
421
422(define %bootstrap-gcc
423 ;; The initial GCC. Uses binaries from a tarball typically built by
424 ;; %GCC-BOOTSTRAP-TARBALL.
425 (package
426 (name "gcc-bootstrap")
427 (version "0")
428 (source #f)
429 (build-system trivial-build-system)
430 (arguments
21c203a5
LC
431 `(#:guile ,%bootstrap-guile
432 #:modules ((guix build utils))
433 #:builder
434 (let ((out (assoc-ref %outputs "out"))
435 (tar (assoc-ref %build-inputs "tar"))
436 (xz (assoc-ref %build-inputs "xz"))
437 (bash (assoc-ref %build-inputs "bash"))
438 (libc (assoc-ref %build-inputs "libc"))
439 (tarball (assoc-ref %build-inputs "tarball")))
440 (use-modules (guix build utils)
441 (ice-9 popen))
18633d4f 442
21c203a5
LC
443 (mkdir out)
444 (copy-file tarball "binaries.tar.xz")
445 (system* xz "-d" "binaries.tar.xz")
446 (let ((builddir (getcwd))
447 (bindir (string-append out "/bin")))
448 (with-directory-excursion out
449 (system* tar "xvf"
450 (string-append builddir "/binaries.tar")))
18633d4f 451
21c203a5
LC
452 (with-directory-excursion bindir
453 (chmod "." #o755)
454 (rename-file "gcc" ".gcc-wrapped")
455 (call-with-output-file "gcc"
456 (lambda (p)
457 (format p "#!~a
18633d4f
LC
458exec ~a/bin/.gcc-wrapped -B~a/lib \
459 -Wl,-rpath -Wl,~a/lib \
460 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
21c203a5
LC
461 bash
462 out libc libc libc
463 ,(glibc-dynamic-linker))))
18633d4f 464
21c203a5 465 (chmod "gcc" #o555))))))
18633d4f 466 (inputs
dd6b9a37
LC
467 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
468 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
469 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
18633d4f 470 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
471 ("tarball" ,(bootstrap-origin
472 (origin
473 (method url-fetch)
474 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
475 (match (%current-system)
476 ("armhf-linux"
477 "/20150101/gcc-4.8.4.tar.xz")
478 (_
479 "/20131110/gcc-4.8.2.tar.xz")))
dd6b9a37
LC
480 %bootstrap-base-urls))
481 (sha256
482 (match (%current-system)
483 ("x86_64-linux"
484 (base32
06213498 485 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
dd6b9a37
LC
486 ("i686-linux"
487 (base32
06213498 488 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
aa1e1947
MW
489 ("armhf-linux"
490 (base32
491 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
f57ff219
MW
492 ("mips64el-linux"
493 (base32
06213498 494 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
a18eda27
LC
495 (native-search-paths
496 (list (search-path-specification
497 (variable "CPATH")
af070955 498 (files '("include")))
a18eda27
LC
499 (search-path-specification
500 (variable "LIBRARY_PATH")
af070955 501 (files '("lib" "lib64")))))
18633d4f 502 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
7de1f103 503 (description synopsis)
1fb78cb2
LC
504 (home-page #f)
505 (license gpl3+)))
18633d4f
LC
506
507(define %bootstrap-inputs
508 ;; The initial, pre-built inputs. From now on, we can start building our
509 ;; own packages.
510 `(("libc" ,%bootstrap-glibc)
511 ("gcc" ,%bootstrap-gcc)
512 ("binutils" ,%bootstrap-binutils)
9d1d434c
LC
513 ("coreutils&co" ,%bootstrap-coreutils&co)
514
515 ;; In gnu-build-system.scm, we rely on the availability of Bash.
516 ("bash" ,%bootstrap-coreutils&co)))
18633d4f
LC
517
518;;; bootstrap.scm ends here