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