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