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