gnu: make-bootstrap: Use _IOLBF on Guile 2.0 only.
[jackhill/guix/guix.git] / gnu / packages / bootstrap.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
836a85da 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
7f1d2dd3 3;;; Copyright © 2014, 2015, 2018, 2019 Mark H Weaver <mhw@netris.org>
3b88f376 4;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
dbabfc47 5;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
67dac6b8 6;;; Copyright © 2019 Carl Dong <contact@carldong.me>
18633d4f 7;;;
233e7676 8;;; This file is part of GNU Guix.
18633d4f 9;;;
233e7676 10;;; GNU Guix is free software; you can redistribute it and/or modify it
18633d4f
LC
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
233e7676 15;;; GNU Guix is distributed in the hope that it will be useful, but
18633d4f
LC
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
233e7676 21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18633d4f 22
1ffa7090 23(define-module (gnu packages bootstrap)
4a44e743 24 #:use-module (guix licenses)
59a43334 25 #:use-module (gnu packages)
18633d4f 26 #:use-module (guix packages)
62cab99c 27 #:use-module (guix download)
18633d4f
LC
28 #:use-module (guix build-system)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix build-system trivial)
5c93d233
LC
31 #:use-module ((guix store)
32 #:select (run-with-store add-to-store add-text-to-store))
33 #:use-module ((guix derivations)
266e54e2 34 #:select (derivation derivation-input derivation->output-path))
958dd3ce 35 #:use-module ((guix utils) #:select (gnu-triplet->nix-system))
ac199505 36 #:use-module ((guix gexp) #:select (lower-object))
f9704f17 37 #:use-module (guix memoization)
836a85da 38 #:use-module (guix i18n)
18633d4f
LC
39 #:use-module (srfi srfi-1)
40 #:use-module (srfi srfi-26)
836a85da
LC
41 #:use-module (srfi srfi-34)
42 #:use-module (srfi srfi-35)
18633d4f
LC
43 #:use-module (ice-9 match)
44 #:export (bootstrap-origin
45 package-with-bootstrap-guile
46 glibc-dynamic-linker
47
1ba0b1e6 48 bootstrap-executable
3e5750af
LC
49 bootstrap-guile-origin
50
18633d4f
LC
51 %bootstrap-guile
52 %bootstrap-coreutils&co
aec77e86 53 %bootstrap-linux-libre-headers
18633d4f
LC
54 %bootstrap-binutils
55 %bootstrap-gcc
56 %bootstrap-glibc
aec77e86 57 %bootstrap-inputs
b00a95be 58 %bootstrap-mescc-tools
03d76577
LC
59 %bootstrap-mes
60
61 %bootstrap-inputs-for-tests))
18633d4f
LC
62
63;;; Commentary:
64;;;
65;;; Pre-built packages that are used to bootstrap the
66;;; distribution--i.e., to build all the core packages from scratch.
67;;;
68;;; Code:
69
70
71\f
836a85da
LC
72;;;
73;;; The bootstrap executables: 'bash', 'mkdir', 'tar', 'xz'. They allow us to
74;;; extract the very first tarball.
75;;;
76
77(define %bootstrap-executables
78 ;; List of bootstrap executables and their recursive hashes (as per 'guix
79 ;; hash -r'), taking their executable bit into account.
80 `(("aarch64-linux"
81 ("bash"
82 ,(base32 "13aqhqb8nydlwq1ah9974q0iadx1pb95v13wzzyf7vgv6nasrwzr"))
83 ("mkdir"
84 ,(base32 "1pxhdp7ldwavmm71xbh9wc197cb2nr66acjn26yjx3732cixh9ws"))
85 ("tar"
86 ,(base32 "1j51gv08sfg277yxj73xd564wjq3f8xwd6s9rbcg8v9gms47m4cx"))
87 ("xz"
88 ,(base32 "1d779rwsrasphg5g3r37qppcqy3p7ay1jb1y83w7x4i3qsc7zjy2")))
89 ("armhf-linux"
90 ("bash"
91 ,(base32 "0s6f1s26g4dsrrkl39zblvwpxmbzi6n9mgqf6vxsqz42gik6bgyn"))
92 ("mkdir"
93 ,(base32 "1r5rcp35niyxfkrdf00y2ba8ifrq9bi76cr63lwjf2l655j1i5p7"))
94 ("tar"
95 ,(base32 "0dksx5im3fv8ximz7368bsax9f26nn47ds74298flm5lnvpv9xly"))
96 ("xz"
97 ,(base32 "1cqqavghjfr0iwxqf61lrssv27wfigysgq2rs4rm1gkmn04yn1k3")))
98 ("i686-linux"
99 ("bash"
100 ,(base32 "0rjaxyzjdllfkf1abczvgaf3cdcc7mmahyvdbkjmjzhgz92pv23g"))
101 ("mkdir"
102 ,(base32 "133ybmfpkmsnysrzbngwvbysqnsmfi8is8zifs7i7n6n600h4s1w"))
103 ("tar"
104 ,(base32 "07830bx29ad5i0l1ykj0g0b1jayjdblf01sr3ww9wbnwdbzinqms"))
105 ("xz"
106 ,(base32 "0i9kxdi17bm5gxfi2xzm0y73p3ii0cqxli1sbljm6rh2fjgyn90k")))
107 ("mips64el-linux"
108 ("bash"
109 ,(base32 "1aw046dhda240k9pb9iaj5aqkm23gkvxa9j82n4k7fk87nbrixw6"))
110 ("mkdir"
111 ,(base32 "0c9j6qgyw84zxbry3ypifzll13gy8ax71w40kdk1h11jbgla3f5k"))
112 ("tar"
113 ,(base32 "06gmqdjq3rl8lr47b9fyx4ifnm5x56ymc8lyryp1ax1j2s4y5jb4"))
114 ("xz"
115 ,(base32 "09j1d69qr0hhhx4k4ih8wp00dfc9y4rp01hfg3vc15yxd0jxabh5")))))
116
fef77109
JN
117(define %bootstrap-executable-base-urls
118 ;; This is where the bootstrap executables come from.
119 '("https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/bootstrap/"
120 "http://lilypond.org/janneke/guix/"))
121
122(define (bootstrap-executable-file-name system program)
123 "Return the FILE-NAME part of url where PROGRAM can be found for SYSTEM."
124 (match system
125 ("i586-gnu" (string-append system "/20200315/" program))
126 (_ (string-append system "/" program
127 "?id=44f07d1dc6806e97c4e9ee3e6be883cc59dc666e"))))
836a85da
LC
128
129(define bootstrap-executable
130 (mlambda (program system)
131 "Return an origin for PROGRAM, a statically-linked bootstrap executable
132built for SYSTEM."
133 (let ((system (if (string=? system "x86_64-linux")
134 "i686-linux"
135 system)))
136 (match (assoc-ref (assoc-ref %bootstrap-executables system)
137 program)
138 (#f
139 (raise (condition
140 (&message
141 (message
142 (format #f (G_ "could not find bootstrap binary '~a' \
143for system '~a'")
144 program system))))))
145 ((sha256)
146 (origin
147 (method url-fetch/executable)
fef77109
JN
148 (uri (map (cute string-append <>
149 (bootstrap-executable-file-name system program))
150 %bootstrap-executable-base-urls))
836a85da
LC
151 (file-name program)
152 (sha256 sha256)))))))
153
154\f
18633d4f
LC
155;;;
156;;; Helper procedures.
157;;;
158
7e1a74da
LC
159(define bootstrap-origin
160 (mlambdaq (source)
161 "Return a variant of SOURCE, an <origin> instance, whose method uses
18633d4f 162%BOOTSTRAP-GUILE to do its job."
7e1a74da
LC
163 (define (boot fetch)
164 (lambda* (url hash-algo hash
165 #:optional name #:key system)
166 (fetch url hash-algo hash name
167 #:guile %bootstrap-guile
168 #:system system)))
169
170 (define %bootstrap-patch-inputs
171 ;; Packages used when an <origin> has a non-empty 'patches' field.
172 `(("tar" ,%bootstrap-coreutils&co)
173 ("xz" ,%bootstrap-coreutils&co)
174 ("bzip2" ,%bootstrap-coreutils&co)
175 ("gzip" ,%bootstrap-coreutils&co)
176 ("patch" ,%bootstrap-coreutils&co)))
177
178 (let ((orig-method (origin-method source)))
179 (if (or (not (null? (origin-patches source)))
180 (origin-snippet source))
181 (origin (inherit source)
182 (method (if (eq? orig-method url-fetch)
183 (boot url-fetch)
184 orig-method))
185 (patch-guile %bootstrap-guile)
186 (patch-inputs %bootstrap-patch-inputs)
187
188 ;; Patches can be origins as well, so process them.
189 (patches (map (match-lambda
190 ((? origin? patch)
191 (bootstrap-origin patch))
192 (patch patch))
193 (origin-patches source))))
194 source))))
18633d4f 195
2959dbe9
MW
196(define* (package-from-tarball name source program-to-test description
197 #:key snippet)
dfb52abb 198 "Return a package that correspond to the extraction of SOURCE.
dbabfc47
JN
199PROGRAM-TO-TEST is #f or a string: the program to run after extraction of
200SOURCE to check whether everything is alright. If SNIPPET is provided, it is
201evaluated after extracting SOURCE. SNIPPET should return true if successful,
202or false to signal an error."
18633d4f 203 (package
dfb52abb 204 (name name)
18633d4f 205 (version "0")
18633d4f
LC
206 (build-system trivial-build-system)
207 (arguments
208 `(#:guile ,%bootstrap-guile
209 #:modules ((guix build utils))
210 #:builder
668ffe1e 211 (begin
18633d4f
LC
212 (use-modules (guix build utils))
213
668ffe1e
JN
214 (let ((out (assoc-ref %outputs "out"))
215 (tar (assoc-ref %build-inputs "tar"))
216 (xz (assoc-ref %build-inputs "xz"))
217 (tarball (assoc-ref %build-inputs "tarball")))
218
219 (mkdir out)
220 (copy-file tarball "binaries.tar.xz")
221 (invoke xz "-d" "binaries.tar.xz")
222 (let ((builddir (getcwd)))
223 (with-directory-excursion out
224 (invoke tar "xvf"
225 (string-append builddir "/binaries.tar"))
226 ,@(if snippet (list snippet) '())
227 (or (not ,program-to-test)
228 (invoke (string-append "bin/" ,program-to-test)
229 "--version"))))))))
18633d4f 230 (inputs
836a85da
LC
231 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
232 ("xz" ,(bootstrap-executable "xz" (%current-system)))
dfb52abb
LC
233 ("tarball" ,(bootstrap-origin (source (%current-system))))))
234 (source #f)
235 (synopsis description)
7de1f103 236 (description description)
1fb78cb2 237 (home-page #f)
90f2801e 238 (license gpl3+)))
18633d4f
LC
239
240(define package-with-bootstrap-guile
6d7b26a3 241 (mlambdaq (p)
18633d4f
LC
242 "Return a variant of P such that all its origins are fetched with
243%BOOTSTRAP-GUILE."
244 (define rewritten-input
245 (match-lambda
55b2d921
LC
246 ((name (? origin? o))
247 `(,name ,(bootstrap-origin o)))
248 ((name (? package? p) sub-drvs ...)
249 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
250 (x x)))
18633d4f
LC
251
252 (package (inherit p)
55b2d921
LC
253 (source (match (package-source p)
254 ((? origin? o) (bootstrap-origin o))
255 (s s)))
256 (inputs (map rewritten-input
257 (package-inputs p)))
258 (native-inputs (map rewritten-input
259 (package-native-inputs p)))
260 (propagated-inputs (map rewritten-input
261 (package-propagated-inputs p)))
262 (replacement (and=> (package-replacement p)
263 package-with-bootstrap-guile)))))
18633d4f 264
e7133c76
LC
265(define* (glibc-dynamic-linker
266 #:optional (system (or (and=> (%current-target-system)
267 gnu-triplet->nix-system)
268 (%current-system))))
18633d4f 269 "Return the name of Glibc's dynamic linker for SYSTEM."
c89e2107 270 ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
18633d4f
LC
271 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
272 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
3f00ff8b 273 ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
827d2891 274 ((string=? system "mips64el-linux") "/lib/ld.so.1")
66feaa32
MB
275 ((string=? system "i586-gnu") "/lib/ld.so.1")
276 ((string=? system "i686-gnu") "/lib/ld.so.1")
19c444f4 277 ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
4a6f099e 278 ((string=? system "powerpc-linux") "/lib/ld.so.1")
c89e2107 279 ((string=? system "powerpc64le-linux") "/lib/ld64.so.2")
605fec78 280 ((string=? system "alpha-linux") "/lib/ld-linux.so.2")
b91004c2 281 ((string=? system "s390x-linux") "/lib/ld64.so.1")
7180dd67 282 ((string=? system "riscv64-linux") "/lib/ld-linux-riscv64-lp64d.so.1")
9d307460
LC
283
284 ;; XXX: This one is used bare-bones, without a libc, so add a case
285 ;; here just so we can keep going.
7f2d67c8 286 ((string=? system "arm-elf") "no-ld.so")
35a37efb 287 ((string=? system "arm-eabi") "no-ld.so")
9d307460 288 ((string=? system "xtensa-elf") "no-ld.so")
a5b60e3c 289 ((string=? system "avr") "no-ld.so")
6f5b1c91 290 ((string=? system "propeller-elf") "no-ld.so")
3135b95f 291 ((string=? system "i686-mingw") "no-ld.so")
67dac6b8 292 ((string=? system "x86_64-mingw") "no-ld.so")
7cf06d62 293 ((string=? system "vc4-elf") "no-ld.so")
9d307460 294
18633d4f
LC
295 (else (error "dynamic linker name not known for this system"
296 system))))
297
298\f
299;;;
300;;; Bootstrap packages.
301;;;
302
5c93d233
LC
303(define %bootstrap-base-urls
304 ;; This is where the initial binaries come from.
f32c3d4d
LC
305 '("https://ftp.gnu.org/gnu/guix/bootstrap"
306 "https://alpha.gnu.org/gnu/guix/bootstrap"
307 "http://ftp.gnu.org/gnu/guix/bootstrap"
5c93d233 308 "http://alpha.gnu.org/gnu/guix/bootstrap"
894fc4e9 309 "ftp://alpha.gnu.org/gnu/guix/bootstrap"
5c93d233 310 "http://www.fdn.fr/~lcourtes/software/guix/packages"
6fc09bd7
JN
311 "http://flashner.co.il/guix/bootstrap"
312 "http://lilypond.org/janneke/guix/"))
5c93d233
LC
313
314(define (bootstrap-guile-url-path system)
315 "Return the URI for FILE."
316 (string-append "/" system
317 (match system
318 ("aarch64-linux"
319 "/20170217/guile-2.0.14.tar.xz")
320 ("armhf-linux"
321 "/20150101/guile-2.0.11.tar.xz")
322 (_
323 "/20131110/guile-2.0.9.tar.xz"))))
324
325(define (bootstrap-guile-hash system)
326 "Return the SHA256 hash of the Guile bootstrap tarball for SYSTEM."
327 (match system
328 ("x86_64-linux"
329 (base32 "1w2p5zyrglzzniqgvyn1b55vprfzhgk8vzbzkkbdgl5248si0yq3"))
330 ("i686-linux"
331 (base32 "0im800m30abgh7msh331pcbjvb4n02smz5cfzf1srv0kpx3csmxp"))
332 ("mips64el-linux"
333 (base32 "0fzp93lvi0hn54acc0fpvhc7bvl0yc853k62l958cihk03q80ilr"))
334 ("armhf-linux"
335 (base32 "1mi3brl7l58aww34rawhvja84xc7l1b4hmwdmc36fp9q9mfx0lg5"))
336 ("aarch64-linux"
337 (base32 "1giy2aprjmn5fp9c4s9r125fljw4wv6ixy5739i5bffw4jgr0f9r"))))
338
3e5750af
LC
339(define (bootstrap-guile-origin system)
340 "Return an <origin> object for the Guile tarball of SYSTEM."
341 (origin
342 (method url-fetch)
343 (uri (map (cute string-append <> (bootstrap-guile-url-path system))
344 %bootstrap-base-urls))
345 (sha256 (bootstrap-guile-hash system))))
346
5c93d233
LC
347(define (download-bootstrap-guile store system)
348 "Return a derivation that downloads the bootstrap Guile tarball for SYSTEM."
349 (let* ((path (bootstrap-guile-url-path system))
350 (base (basename path))
351 (urls (map (cut string-append <> path) %bootstrap-base-urls)))
352 (run-with-store store
353 (url-fetch urls 'sha256 (bootstrap-guile-hash system)
354 #:system system))))
355
0d5a559f
LC
356(define* (raw-build store name inputs
357 #:key outputs system search-paths
358 #:allow-other-keys)
359 (define (->store file)
836a85da 360 (run-with-store store
ac199505
LC
361 (lower-object (bootstrap-executable file system)
362 system)))
0d5a559f
LC
363
364 (let* ((tar (->store "tar"))
365 (xz (->store "xz"))
366 (mkdir (->store "mkdir"))
367 (bash (->store "bash"))
5c93d233 368 (guile (download-bootstrap-guile store system))
5d6792f0
MW
369 ;; The following code, run by the bootstrap guile after it is
370 ;; unpacked, creates a wrapper for itself to set its load path.
371 ;; This replaces the previous non-portable method based on
372 ;; reading the /proc/self/exe symlink.
373 (make-guile-wrapper
374 '(begin
375 (use-modules (ice-9 match))
376 (match (command-line)
377 ((_ out bash)
378 (let ((bin-dir (string-append out "/bin"))
379 (guile (string-append out "/bin/guile"))
380 (guile-real (string-append out "/bin/.guile-real"))
381 ;; We must avoid using a bare dollar sign in this code,
382 ;; because it would be interpreted by the shell.
383 (dollar (string (integer->char 36))))
384 (chmod bin-dir #o755)
385 (rename-file guile guile-real)
386 (call-with-output-file guile
387 (lambda (p)
388 (format p "\
389#!~a
390export GUILE_SYSTEM_PATH=~a/share/guile/2.0
391export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
392exec -a \"~a0\" ~a \"~a@\"\n"
393 bash out out dollar guile-real dollar)))
394 (chmod guile #o555)
395 (chmod bin-dir #o555))))))
0d5a559f
LC
396 (builder
397 (add-text-to-store store
398 "build-bootstrap-guile.sh"
399 (format #f "
400echo \"unpacking bootstrap Guile to '$out'...\"
401~a $out
402cd $out
5c93d233 403~a -dc < $GUILE_TARBALL | ~a xv
0d5a559f 404
5d6792f0
MW
405# Use the bootstrap guile to create its own wrapper to set the load path.
406GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
407GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
408$out/bin/guile -c ~s $out ~a
409
0d5a559f
LC
410# Sanity check.
411$out/bin/guile --version~%"
836a85da
LC
412 (derivation->output-path mkdir)
413 (derivation->output-path xz)
414 (derivation->output-path tar)
5d6792f0 415 (format #f "~s" make-guile-wrapper)
836a85da 416 (derivation->output-path bash)))))
0d5a559f 417 (derivation store name
836a85da 418 (derivation->output-path bash) `(,builder)
0d5a559f 419 #:system system
64de896a
LC
420 #:inputs (map derivation-input
421 (list bash mkdir tar xz guile))
422 #:sources (list builder)
5c93d233
LC
423 #:env-vars `(("GUILE_TARBALL"
424 . ,(derivation->output-path guile))))))
0d5a559f
LC
425
426(define* (make-raw-bag name
d3d337d2
LC
427 #:key source inputs native-inputs outputs
428 system target)
0d5a559f
LC
429 (bag
430 (name name)
d3d337d2 431 (system system)
0d5a559f
LC
432 (build-inputs inputs)
433 (build raw-build)))
434
18633d4f
LC
435(define %bootstrap-guile
436 ;; The Guile used to run the build scripts of the initial derivations.
437 ;; It is just unpacked from a tarball containing a pre-built binary.
438 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
439 ;;
440 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
441 ;; support (for /etc/services).
442 (let ((raw (build-system
0d5a559f
LC
443 (name 'raw)
444 (description "Raw build system with direct store access")
445 (lower make-raw-bag))))
18633d4f
LC
446 (package
447 (name "guile-bootstrap")
448 (version "2.0")
449 (source #f)
450 (build-system raw)
451 (synopsis "Bootstrap Guile")
452 (description "Pre-built Guile for bootstrapping purposes.")
453 (home-page #f)
4a44e743 454 (license lgpl3+))))
18633d4f 455
18633d4f
LC
456(define %bootstrap-coreutils&co
457 (package-from-tarball "bootstrap-binaries"
458 (lambda (system)
459 (origin
87f5d366 460 (method url-fetch)
04732c37 461 (uri (map (cut string-append <> "/" system
aa1e1947
MW
462 (match system
463 ("armhf-linux"
464 "/20150101/static-binaries.tar.xz")
3b88f376
EF
465 ("aarch64-linux"
466 "/20170217/static-binaries.tar.xz")
aa1e1947
MW
467 (_
468 "/20131110/static-binaries.tar.xz")))
04732c37 469 %bootstrap-base-urls))
18633d4f
LC
470 (sha256
471 (match system
472 ("x86_64-linux"
473 (base32
06213498 474 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
18633d4f
LC
475 ("i686-linux"
476 (base32
06213498 477 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
aa1e1947
MW
478 ("armhf-linux"
479 (base32
480 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
3b88f376
EF
481 ("aarch64-linux"
482 (base32
483 "18dfiq6c6xhsdpbidigw6480wh0vdgsxqq3xindq4lpdgqlccpfh"))
f57ff219
MW
484 ("mips64el-linux"
485 (base32
06213498 486 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
84cbe39c
MW
487 "fgrep" ; the program to test
488 "Bootstrap binaries of Coreutils, Awk, etc."
489 #:snippet
490 '(let ((path (list (string-append (getcwd) "/bin"))))
491 (chmod "bin" #o755)
492 (patch-shebang "bin/egrep" path)
493 (patch-shebang "bin/fgrep" path)
653add37
EF
494 ;; Starting with grep@2.25 'egrep' and 'fgrep' are shell files
495 ;; that call 'grep'. If the bootstrap 'egrep' and 'fgrep'
496 ;; are not binaries then patch them to execute 'grep' via its
497 ;; absolute file name instead of searching for it in $PATH.
498 (if (not (elf-file? "bin/egrep"))
499 (substitute* '("bin/egrep" "bin/fgrep")
500 (("^exec grep") (string-append (getcwd) "/bin/grep"))))
ad1656dc 501 (chmod "bin" #o555))))
18633d4f 502
aec77e86
JN
503(define-public %bootstrap-linux-libre-headers
504 (package-from-tarball
505 "linux-libre-headers-bootstrap"
506 (lambda (system)
507 (origin
508 (method url-fetch)
da3c6a7f 509 (uri (map (cute string-append <>
7f1d2dd3 510 "/i686-linux/20190815/"
da3c6a7f
JN
511 "linux-libre-headers-stripped-4.14.67-i686-linux.tar.xz")
512 %bootstrap-base-urls))
aec77e86
JN
513 (sha256
514 (base32
da3c6a7f 515 "0sm2z9x4wk45bh6qfs94p0w1d6hsy6dqx9sw38qsqbvxwa1qzk8s"))))
aec77e86
JN
516 #f ; no program to test
517 "Bootstrap linux-libre-headers"))
518
18633d4f
LC
519(define %bootstrap-binutils
520 (package-from-tarball "binutils-bootstrap"
521 (lambda (system)
522 (origin
87f5d366 523 (method url-fetch)
04732c37 524 (uri (map (cut string-append <> "/" system
aa1e1947
MW
525 (match system
526 ("armhf-linux"
527 "/20150101/binutils-2.25.tar.xz")
3b88f376
EF
528 ("aarch64-linux"
529 "/20170217/binutils-2.27.tar.xz")
aa1e1947
MW
530 (_
531 "/20131110/binutils-2.23.2.tar.xz")))
04732c37 532 %bootstrap-base-urls))
18633d4f
LC
533 (sha256
534 (match system
535 ("x86_64-linux"
536 (base32
06213498 537 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
18633d4f
LC
538 ("i686-linux"
539 (base32
06213498 540 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
aa1e1947
MW
541 ("armhf-linux"
542 (base32
543 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
3b88f376
EF
544 ("aarch64-linux"
545 (base32
546 "111s7ilfiby033rczc71797xrmaa3qlv179wdvsaq132pd51xv3n"))
f57ff219
MW
547 ("mips64el-linux"
548 (base32
06213498 549 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
18633d4f
LC
550 "ld" ; the program to test
551 "Bootstrap binaries of the GNU Binutils"))
552
553(define %bootstrap-glibc
554 ;; The initial libc.
555 (package
556 (name "glibc-bootstrap")
557 (version "0")
558 (source #f)
559 (build-system trivial-build-system)
560 (arguments
561 `(#:guile ,%bootstrap-guile
562 #:modules ((guix build utils))
563 #:builder
668ffe1e 564 (begin
18633d4f
LC
565 (use-modules (guix build utils))
566
668ffe1e
JN
567 (let ((out (assoc-ref %outputs "out"))
568 (tar (assoc-ref %build-inputs "tar"))
569 (xz (assoc-ref %build-inputs "xz"))
570 (tarball (assoc-ref %build-inputs "tarball")))
571
572 (mkdir out)
573 (copy-file tarball "binaries.tar.xz")
574 (invoke xz "-d" "binaries.tar.xz")
575 (let ((builddir (getcwd)))
576 (with-directory-excursion out
577 (invoke tar "xvf"
578 (string-append builddir
579 "/binaries.tar"))
580 (chmod "lib" #o755)
581
582 ;; Patch libc.so so it refers to the right path.
583 (substitute* "lib/libc.so"
584 (("/[^ ]+/lib/(libc|ld)" _ prefix)
585 (string-append out "/lib/" prefix)))
586
587 #t))))))
18633d4f 588 (inputs
836a85da
LC
589 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
590 ("xz" ,(bootstrap-executable "xz" (%current-system)))
dd6b9a37
LC
591 ("tarball" ,(bootstrap-origin
592 (origin
593 (method url-fetch)
594 (uri (map (cut string-append <> "/" (%current-system)
aa1e1947
MW
595 (match (%current-system)
596 ("armhf-linux"
597 "/20150101/glibc-2.20.tar.xz")
3b88f376
EF
598 ("aarch64-linux"
599 "/20170217/glibc-2.25.tar.xz")
aa1e1947
MW
600 (_
601 "/20131110/glibc-2.18.tar.xz")))
dd6b9a37
LC
602 %bootstrap-base-urls))
603 (sha256
604 (match (%current-system)
605 ("x86_64-linux"
606 (base32
06213498 607 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
dd6b9a37
LC
608 ("i686-linux"
609 (base32
06213498 610 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
aa1e1947
MW
611 ("armhf-linux"
612 (base32
613 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
3b88f376
EF
614 ("aarch64-linux"
615 (base32
616 "07nx3x8598i2924rjnlrncg6rm61c9bmcczbbcpbx0fb742nvv5c"))
f57ff219
MW
617 ("mips64el-linux"
618 (base32
06213498 619 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
18633d4f 620 (synopsis "Bootstrap binaries and headers of the GNU C Library")
7de1f103 621 (description synopsis)
1fb78cb2
LC
622 (home-page #f)
623 (license lgpl2.1+)))
18633d4f
LC
624
625(define %bootstrap-gcc
626 ;; The initial GCC. Uses binaries from a tarball typically built by
627 ;; %GCC-BOOTSTRAP-TARBALL.
628 (package
629 (name "gcc-bootstrap")
630 (version "0")
631 (source #f)
632 (build-system trivial-build-system)
633 (arguments
21c203a5
LC
634 `(#:guile ,%bootstrap-guile
635 #:modules ((guix build utils))
636 #:builder
668ffe1e 637 (begin
21c203a5
LC
638 (use-modules (guix build utils)
639 (ice-9 popen))
18633d4f 640
668ffe1e
JN
641 (let ((out (assoc-ref %outputs "out"))
642 (tar (assoc-ref %build-inputs "tar"))
643 (xz (assoc-ref %build-inputs "xz"))
644 (bash (assoc-ref %build-inputs "bash"))
645 (libc (assoc-ref %build-inputs "libc"))
646 (tarball (assoc-ref %build-inputs "tarball")))
647
648 (mkdir out)
649 (copy-file tarball "binaries.tar.xz")
650 (invoke xz "-d" "binaries.tar.xz")
651 (let ((builddir (getcwd))
652 (bindir (string-append out "/bin")))
653 (with-directory-excursion out
654 (invoke tar "xvf"
655 (string-append builddir "/binaries.tar")))
656
657 (with-directory-excursion bindir
658 (chmod "." #o755)
659 (rename-file "gcc" ".gcc-wrapped")
660 (call-with-output-file "gcc"
661 (lambda (p)
662 (format p "#!~a
18633d4f
LC
663exec ~a/bin/.gcc-wrapped -B~a/lib \
664 -Wl,-rpath -Wl,~a/lib \
665 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
668ffe1e
JN
666 bash
667 out libc libc libc
668 ,(glibc-dynamic-linker))))
18633d4f 669
668ffe1e
JN
670 (chmod "gcc" #o555)
671 #t))))))
18633d4f 672 (inputs
836a85da
LC
673 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
674 ("xz" ,(bootstrap-executable "xz" (%current-system)))
675 ("bash" ,(bootstrap-executable "bash" (%current-system)))
18633d4f 676 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
677 ("tarball" ,(bootstrap-origin
678 (origin
668ffe1e
JN
679 (method url-fetch)
680 (uri (map (cut string-append <> "/" (%current-system)
681 (match (%current-system)
682 ("armhf-linux"
683 "/20150101/gcc-4.8.4.tar.xz")
684 ("aarch64-linux"
685 "/20170217/gcc-5.4.0.tar.xz")
686 (_
687 "/20131110/gcc-4.8.2.tar.xz")))
688 %bootstrap-base-urls))
689 (sha256
690 (match (%current-system)
691 ("x86_64-linux"
692 (base32
693 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
694 ("i686-linux"
695 (base32
696 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
697 ("armhf-linux"
698 (base32
699 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
700 ("aarch64-linux"
701 (base32
702 "1ar3vdzyqbfm0z36kmvazvfswxhcihlacl2dzdjgiq25cqnq9ih1"))
703 ("mips64el-linux"
704 (base32
705 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
a18eda27
LC
706 (native-search-paths
707 (list (search-path-specification
708 (variable "CPATH")
af070955 709 (files '("include")))
a18eda27
LC
710 (search-path-specification
711 (variable "LIBRARY_PATH")
af070955 712 (files '("lib" "lib64")))))
18633d4f 713 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
7de1f103 714 (description synopsis)
1fb78cb2
LC
715 (home-page #f)
716 (license gpl3+)))
18633d4f 717
b00a95be
JN
718(define %bootstrap-mescc-tools
719 ;; The initial MesCC tools. Uses binaries from a tarball typically built by
720 ;; %MESCC-TOOLS-BOOTSTRAP-TARBALL.
721 (package
722 (name "bootstrap-mescc-tools")
723 (version "0.5.2")
724 (source #f)
725 (build-system trivial-build-system)
726 (arguments
727 `(#:guile ,%bootstrap-guile
728 #:modules ((guix build utils))
729 #:builder
730 (begin
731 (use-modules (guix build utils)
732 (ice-9 popen))
733 (let ((out (assoc-ref %outputs "out"))
734 (tar (assoc-ref %build-inputs "tar"))
735 (xz (assoc-ref %build-inputs "xz"))
736 (tarball (assoc-ref %build-inputs "tarball")))
737
738 (mkdir out)
739 (copy-file tarball "binaries.tar.xz")
740 (invoke xz "-d" "binaries.tar.xz")
741 (let ((builddir (getcwd))
742 (bindir (string-append out "/bin")))
743 (with-directory-excursion out
744 (invoke tar "xvf"
745 (string-append builddir "/binaries.tar"))))))))
746 (inputs
836a85da
LC
747 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
748 ("xz" ,(bootstrap-executable "xz" (%current-system)))
da3c6a7f
JN
749 ("tarball"
750 ,(bootstrap-origin
751 (origin
752 (method url-fetch)
753 (uri (map
754 (cute string-append <>
7f1d2dd3
MW
755 "/i686-linux/20190815/"
756 "mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz")
da3c6a7f
JN
757 %bootstrap-base-urls))
758 (sha256
759 (base32
7f1d2dd3 760 "0c3kklgghzh4q2dbpl6asb74cimp7hp6jscdwqwmzxbapgcl6582")))))))
b00a95be
JN
761 (synopsis "Bootstrap binaries of MesCC Tools")
762 (description synopsis)
763 (home-page #f)
0b07f227 764 (supported-systems '("i686-linux" "x86_64-linux"))
b00a95be
JN
765 (license gpl3+)))
766
5f02c9b7
JN
767(define %bootstrap-mes
768 ;; The initial Mes. Uses binaries from a tarball typically built by
769 ;; %MES-BOOTSTRAP-TARBALL.
770 (package
771 (name "bootstrap-mes")
772 (version "0")
773 (source #f)
774 (build-system trivial-build-system)
775 (arguments
776 `(#:guile ,%bootstrap-guile
777 #:modules ((guix build utils))
778 #:builder
779 (begin
780 (use-modules (guix build utils)
781 (ice-9 popen))
782 (let ((out (assoc-ref %outputs "out"))
783 (tar (assoc-ref %build-inputs "tar"))
784 (xz (assoc-ref %build-inputs "xz"))
785 (tarball (assoc-ref %build-inputs "tarball")))
786
787 (mkdir out)
788 (copy-file tarball "binaries.tar.xz")
789 (invoke xz "-d" "binaries.tar.xz")
790 (let ((builddir (getcwd))
791 (bindir (string-append out "/bin")))
792 (with-directory-excursion out
793 (invoke tar "xvf"
794 (string-append builddir "/binaries.tar"))))))))
795 (inputs
836a85da
LC
796 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
797 ("xz" ,(bootstrap-executable "xz" (%current-system)))
da3c6a7f
JN
798 ("tarball"
799 ,(bootstrap-origin
800 (origin
801 (method url-fetch)
c89bbccc
JN
802 (uri (map
803 (cute string-append <>
7f1d2dd3 804 "/i686-linux/20190815/"
c89bbccc
JN
805 "mes-minimal-stripped-0.19-i686-linux.tar.xz")
806 %bootstrap-base-urls))
da3c6a7f 807 (sha256
0b07f227 808 (base32
7f1d2dd3 809 "1q4xjpx6nbn44kxnilpgl12bhpmwy2bblzwszc2ci7xkf400jcpv")))))))
0b07f227 810 (supported-systems '("i686-linux" "x86_64-linux"))
5f02c9b7
JN
811 (synopsis "Bootstrap binaries of Mes")
812 (description synopsis)
813 (home-page #f)
814 (license gpl3+)))
815
a2b2070b 816(define (%bootstrap-inputs)
18633d4f
LC
817 ;; The initial, pre-built inputs. From now on, we can start building our
818 ;; own packages.
d77860db
JN
819 (match (%current-system)
820 ((or "i686-linux" "x86_64-linux")
821 `(("linux-libre-headers" ,%bootstrap-linux-libre-headers)
822 ("bootstrap-mescc-tools" ,%bootstrap-mescc-tools)
823 ("mes" ,%bootstrap-mes)))
824 (_
825 `(("libc" ,%bootstrap-glibc)
826 ("gcc" ,%bootstrap-gcc)
827 ("binutils" ,%bootstrap-binutils)
828 ("coreutils&co" ,%bootstrap-coreutils&co)
829 ;; In gnu-build-system.scm, we rely on the availability of Bash.
830 ("bash" ,%bootstrap-coreutils&co)))))
18633d4f 831
03d76577
LC
832(define %bootstrap-inputs-for-tests
833 ;; These are bootstrap inputs that are cheap to produce (no compilation
834 ;; needed) and that are meant to be used for testing. (These are those we
835 ;; used before the Mes-based reduced bootstrap.)
836 `(("libc" ,%bootstrap-glibc)
837 ("gcc" ,%bootstrap-gcc)
838 ("binutils" ,%bootstrap-binutils)
839 ("coreutils&co" ,%bootstrap-coreutils&co)
840 ("bash" ,%bootstrap-coreutils&co)))
841
18633d4f 842;;; bootstrap.scm ends here