gnu: Add gom.
[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"))))
0d5a559f
LC
200 (builder
201 (add-text-to-store store
202 "build-bootstrap-guile.sh"
203 (format #f "
204echo \"unpacking bootstrap Guile to '$out'...\"
205~a $out
206cd $out
207~a -dc < ~a | ~a xv
208
209# Sanity check.
210$out/bin/guile --version~%"
211 mkdir xz guile tar)
212 (list mkdir xz guile tar))))
213 (derivation store name
214 bash `(,builder)
215 #:system system
216 #:inputs `((,bash) (,builder)))))
217
218(define* (make-raw-bag name
d3d337d2
LC
219 #:key source inputs native-inputs outputs
220 system target)
0d5a559f
LC
221 (bag
222 (name name)
d3d337d2 223 (system system)
0d5a559f
LC
224 (build-inputs inputs)
225 (build raw-build)))
226
18633d4f
LC
227(define %bootstrap-guile
228 ;; The Guile used to run the build scripts of the initial derivations.
229 ;; It is just unpacked from a tarball containing a pre-built binary.
230 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
231 ;;
232 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
233 ;; support (for /etc/services).
234 (let ((raw (build-system
0d5a559f
LC
235 (name 'raw)
236 (description "Raw build system with direct store access")
237 (lower make-raw-bag))))
18633d4f
LC
238 (package
239 (name "guile-bootstrap")
240 (version "2.0")
241 (source #f)
242 (build-system raw)
243 (synopsis "Bootstrap Guile")
244 (description "Pre-built Guile for bootstrapping purposes.")
245 (home-page #f)
4a44e743 246 (license lgpl3+))))
18633d4f 247
04732c37 248(define %bootstrap-base-urls
18633d4f 249 ;; This is where the initial binaries come from.
04732c37
LC
250 '("http://alpha.gnu.org/gnu/guix/bootstrap"
251 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
18633d4f
LC
252
253(define %bootstrap-coreutils&co
254 (package-from-tarball "bootstrap-binaries"
255 (lambda (system)
256 (origin
87f5d366 257 (method url-fetch)
04732c37 258 (uri (map (cut string-append <> "/" system
aa1e1947
MW
259 (match system
260 ("armhf-linux"
261 "/20150101/static-binaries.tar.xz")
262 (_
263 "/20131110/static-binaries.tar.xz")))
04732c37 264 %bootstrap-base-urls))
18633d4f
LC
265 (sha256
266 (match system
267 ("x86_64-linux"
268 (base32
06213498 269 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
18633d4f
LC
270 ("i686-linux"
271 (base32
06213498 272 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
aa1e1947
MW
273 ("armhf-linux"
274 (base32
275 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
f57ff219
MW
276 ("mips64el-linux"
277 (base32
06213498 278 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
84cbe39c
MW
279 "fgrep" ; the program to test
280 "Bootstrap binaries of Coreutils, Awk, etc."
281 #:snippet
282 '(let ((path (list (string-append (getcwd) "/bin"))))
283 (chmod "bin" #o755)
284 (patch-shebang "bin/egrep" path)
285 (patch-shebang "bin/fgrep" path)
286 (chmod "bin" #o555)
287 #t)))
18633d4f
LC
288
289(define %bootstrap-binutils
290 (package-from-tarball "binutils-bootstrap"
291 (lambda (system)
292 (origin
87f5d366 293 (method url-fetch)
04732c37 294 (uri (map (cut string-append <> "/" system
aa1e1947
MW
295 (match system
296 ("armhf-linux"
297 "/20150101/binutils-2.25.tar.xz")
298 (_
299 "/20131110/binutils-2.23.2.tar.xz")))
04732c37 300 %bootstrap-base-urls))
18633d4f
LC
301 (sha256
302 (match system
303 ("x86_64-linux"
304 (base32
06213498 305 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
18633d4f
LC
306 ("i686-linux"
307 (base32
06213498 308 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
aa1e1947
MW
309 ("armhf-linux"
310 (base32
311 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
f57ff219
MW
312 ("mips64el-linux"
313 (base32
06213498 314 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
18633d4f
LC
315 "ld" ; the program to test
316 "Bootstrap binaries of the GNU Binutils"))
317
318(define %bootstrap-glibc
319 ;; The initial libc.
320 (package
321 (name "glibc-bootstrap")
322 (version "0")
323 (source #f)
324 (build-system trivial-build-system)
325 (arguments
326 `(#:guile ,%bootstrap-guile
327 #:modules ((guix build utils))
328 #:builder
329 (let ((out (assoc-ref %outputs "out"))
330 (tar (assoc-ref %build-inputs "tar"))
331 (xz (assoc-ref %build-inputs "xz"))
332 (tarball (assoc-ref %build-inputs "tarball")))
333 (use-modules (guix build utils))
334
335 (mkdir out)
336 (copy-file tarball "binaries.tar.xz")
337 (system* xz "-d" "binaries.tar.xz")
338 (let ((builddir (getcwd)))
339 (with-directory-excursion out
340 (system* tar "xvf"
341 (string-append builddir
342 "/binaries.tar"))
343 (chmod "lib" #o755)
344
345 ;; Patch libc.so so it refers to the right path.
346 (substitute* "lib/libc.so"
347 (("/[^ ]+/lib/(libc|ld)" _ prefix)
348 (string-append out "/lib/" prefix))))))))
349 (inputs
dd6b9a37
LC
350 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
351 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
352 ("tarball" ,(bootstrap-origin
353 (origin
354 (method url-fetch)
355 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
356 (match (%current-system)
357 ("armhf-linux"
358 "/20150101/glibc-2.20.tar.xz")
359 (_
360 "/20131110/glibc-2.18.tar.xz")))
dd6b9a37
LC
361 %bootstrap-base-urls))
362 (sha256
363 (match (%current-system)
364 ("x86_64-linux"
365 (base32
06213498 366 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
dd6b9a37
LC
367 ("i686-linux"
368 (base32
06213498 369 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
aa1e1947
MW
370 ("armhf-linux"
371 (base32
372 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
f57ff219
MW
373 ("mips64el-linux"
374 (base32
06213498 375 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
18633d4f
LC
376 (synopsis "Bootstrap binaries and headers of the GNU C Library")
377 (description #f)
1fb78cb2
LC
378 (home-page #f)
379 (license lgpl2.1+)))
18633d4f
LC
380
381(define %bootstrap-gcc
382 ;; The initial GCC. Uses binaries from a tarball typically built by
383 ;; %GCC-BOOTSTRAP-TARBALL.
384 (package
385 (name "gcc-bootstrap")
386 (version "0")
387 (source #f)
388 (build-system trivial-build-system)
389 (arguments
21c203a5
LC
390 `(#:guile ,%bootstrap-guile
391 #:modules ((guix build utils))
392 #:builder
393 (let ((out (assoc-ref %outputs "out"))
394 (tar (assoc-ref %build-inputs "tar"))
395 (xz (assoc-ref %build-inputs "xz"))
396 (bash (assoc-ref %build-inputs "bash"))
397 (libc (assoc-ref %build-inputs "libc"))
398 (tarball (assoc-ref %build-inputs "tarball")))
399 (use-modules (guix build utils)
400 (ice-9 popen))
18633d4f 401
21c203a5
LC
402 (mkdir out)
403 (copy-file tarball "binaries.tar.xz")
404 (system* xz "-d" "binaries.tar.xz")
405 (let ((builddir (getcwd))
406 (bindir (string-append out "/bin")))
407 (with-directory-excursion out
408 (system* tar "xvf"
409 (string-append builddir "/binaries.tar")))
18633d4f 410
21c203a5
LC
411 (with-directory-excursion bindir
412 (chmod "." #o755)
413 (rename-file "gcc" ".gcc-wrapped")
414 (call-with-output-file "gcc"
415 (lambda (p)
416 (format p "#!~a
18633d4f
LC
417exec ~a/bin/.gcc-wrapped -B~a/lib \
418 -Wl,-rpath -Wl,~a/lib \
419 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
21c203a5
LC
420 bash
421 out libc libc libc
422 ,(glibc-dynamic-linker))))
18633d4f 423
21c203a5 424 (chmod "gcc" #o555))))))
18633d4f 425 (inputs
dd6b9a37
LC
426 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
427 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
428 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
18633d4f 429 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
430 ("tarball" ,(bootstrap-origin
431 (origin
432 (method url-fetch)
433 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
434 (match (%current-system)
435 ("armhf-linux"
436 "/20150101/gcc-4.8.4.tar.xz")
437 (_
438 "/20131110/gcc-4.8.2.tar.xz")))
dd6b9a37
LC
439 %bootstrap-base-urls))
440 (sha256
441 (match (%current-system)
442 ("x86_64-linux"
443 (base32
06213498 444 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
dd6b9a37
LC
445 ("i686-linux"
446 (base32
06213498 447 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
aa1e1947
MW
448 ("armhf-linux"
449 (base32
450 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
f57ff219
MW
451 ("mips64el-linux"
452 (base32
06213498 453 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
a18eda27
LC
454 (native-search-paths
455 (list (search-path-specification
456 (variable "CPATH")
af070955 457 (files '("include")))
a18eda27
LC
458 (search-path-specification
459 (variable "LIBRARY_PATH")
af070955 460 (files '("lib" "lib64")))))
18633d4f
LC
461 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
462 (description #f)
1fb78cb2
LC
463 (home-page #f)
464 (license gpl3+)))
18633d4f
LC
465
466(define %bootstrap-inputs
467 ;; The initial, pre-built inputs. From now on, we can start building our
468 ;; own packages.
469 `(("libc" ,%bootstrap-glibc)
470 ("gcc" ,%bootstrap-gcc)
471 ("binutils" ,%bootstrap-binutils)
9d1d434c
LC
472 ("coreutils&co" ,%bootstrap-coreutils&co)
473
474 ;; In gnu-build-system.scm, we rely on the availability of Bash.
475 ("bash" ,%bootstrap-coreutils&co)))
18633d4f
LC
476
477;;; bootstrap.scm ends here