build-system: Remove irrelevant special case.
[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
149 (package-propagated-inputs p)))))))
150
e7133c76
LC
151(define* (glibc-dynamic-linker
152 #:optional (system (or (and=> (%current-target-system)
153 gnu-triplet->nix-system)
154 (%current-system))))
18633d4f
LC
155 "Return the name of Glibc's dynamic linker for SYSTEM."
156 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
157 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
827d2891 158 ((string=? system "mips64el-linux") "/lib/ld.so.1")
18633d4f
LC
159 (else (error "dynamic linker name not known for this system"
160 system))))
161
162\f
163;;;
164;;; Bootstrap packages.
165;;;
166
167(define %bootstrap-guile
168 ;; The Guile used to run the build scripts of the initial derivations.
169 ;; It is just unpacked from a tarball containing a pre-built binary.
170 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
171 ;;
172 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
173 ;; support (for /etc/services).
174 (let ((raw (build-system
175 (name "raw")
176 (description "Raw build system with direct store access")
a18eda27
LC
177 (build (lambda* (store name source inputs
178 #:key outputs system search-paths)
18633d4f 179 (define (->store file)
a9ebd9ef 180 (add-to-store store file #t "sha256"
18633d4f
LC
181 (or (search-bootstrap-binary file
182 system)
183 (error "bootstrap binary not found"
184 file system))))
185
186 (let* ((tar (->store "tar"))
187 (xz (->store "xz"))
188 (mkdir (->store "mkdir"))
189 (bash (->store "bash"))
06213498 190 (guile (->store "guile-2.0.9.tar.xz"))
18633d4f
LC
191 (builder
192 (add-text-to-store store
193 "build-bootstrap-guile.sh"
194 (format #f "
195echo \"unpacking bootstrap Guile to '$out'...\"
196~a $out
197cd $out
198~a -dc < ~a | ~a xv
199
200# Sanity check.
201$out/bin/guile --version~%"
202 mkdir xz guile tar)
203 (list mkdir xz guile tar))))
a987d2c0
LC
204 (derivation store name
205 bash `(,builder)
206 #:system system
207 #:inputs `((,bash) (,builder)))))))))
18633d4f
LC
208 (package
209 (name "guile-bootstrap")
210 (version "2.0")
211 (source #f)
212 (build-system raw)
213 (synopsis "Bootstrap Guile")
214 (description "Pre-built Guile for bootstrapping purposes.")
215 (home-page #f)
4a44e743 216 (license lgpl3+))))
18633d4f 217
04732c37 218(define %bootstrap-base-urls
18633d4f 219 ;; This is where the initial binaries come from.
04732c37
LC
220 '("http://alpha.gnu.org/gnu/guix/bootstrap"
221 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
18633d4f
LC
222
223(define %bootstrap-coreutils&co
224 (package-from-tarball "bootstrap-binaries"
225 (lambda (system)
226 (origin
87f5d366 227 (method url-fetch)
04732c37 228 (uri (map (cut string-append <> "/" system
06213498 229 "/20131110/static-binaries.tar.xz")
04732c37 230 %bootstrap-base-urls))
18633d4f
LC
231 (sha256
232 (match system
233 ("x86_64-linux"
234 (base32
06213498 235 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
18633d4f
LC
236 ("i686-linux"
237 (base32
06213498 238 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
f57ff219
MW
239 ("mips64el-linux"
240 (base32
06213498 241 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
18633d4f
LC
242 "true" ; the program to test
243 "Bootstrap binaries of Coreutils, Awk, etc."))
244
245(define %bootstrap-binutils
246 (package-from-tarball "binutils-bootstrap"
247 (lambda (system)
248 (origin
87f5d366 249 (method url-fetch)
04732c37 250 (uri (map (cut string-append <> "/" system
06213498 251 "/20131110/binutils-2.23.2.tar.xz")
04732c37 252 %bootstrap-base-urls))
18633d4f
LC
253 (sha256
254 (match system
255 ("x86_64-linux"
256 (base32
06213498 257 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
18633d4f
LC
258 ("i686-linux"
259 (base32
06213498 260 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
f57ff219
MW
261 ("mips64el-linux"
262 (base32
06213498 263 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
18633d4f
LC
264 "ld" ; the program to test
265 "Bootstrap binaries of the GNU Binutils"))
266
267(define %bootstrap-glibc
268 ;; The initial libc.
269 (package
270 (name "glibc-bootstrap")
271 (version "0")
272 (source #f)
273 (build-system trivial-build-system)
274 (arguments
275 `(#:guile ,%bootstrap-guile
276 #:modules ((guix build utils))
277 #:builder
278 (let ((out (assoc-ref %outputs "out"))
279 (tar (assoc-ref %build-inputs "tar"))
280 (xz (assoc-ref %build-inputs "xz"))
281 (tarball (assoc-ref %build-inputs "tarball")))
282 (use-modules (guix build utils))
283
284 (mkdir out)
285 (copy-file tarball "binaries.tar.xz")
286 (system* xz "-d" "binaries.tar.xz")
287 (let ((builddir (getcwd)))
288 (with-directory-excursion out
289 (system* tar "xvf"
290 (string-append builddir
291 "/binaries.tar"))
292 (chmod "lib" #o755)
293
294 ;; Patch libc.so so it refers to the right path.
295 (substitute* "lib/libc.so"
296 (("/[^ ]+/lib/(libc|ld)" _ prefix)
297 (string-append out "/lib/" prefix))))))))
298 (inputs
dd6b9a37
LC
299 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
300 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
301 ("tarball" ,(bootstrap-origin
302 (origin
303 (method url-fetch)
304 (uri (map (cut string-append <> "/" (%current-system)
06213498 305 "/20131110/glibc-2.18.tar.xz")
dd6b9a37
LC
306 %bootstrap-base-urls))
307 (sha256
308 (match (%current-system)
309 ("x86_64-linux"
310 (base32
06213498 311 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
dd6b9a37
LC
312 ("i686-linux"
313 (base32
06213498 314 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
f57ff219
MW
315 ("mips64el-linux"
316 (base32
06213498 317 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
18633d4f
LC
318 (synopsis "Bootstrap binaries and headers of the GNU C Library")
319 (description #f)
1fb78cb2
LC
320 (home-page #f)
321 (license lgpl2.1+)))
18633d4f
LC
322
323(define %bootstrap-gcc
324 ;; The initial GCC. Uses binaries from a tarball typically built by
325 ;; %GCC-BOOTSTRAP-TARBALL.
326 (package
327 (name "gcc-bootstrap")
328 (version "0")
329 (source #f)
330 (build-system trivial-build-system)
331 (arguments
21c203a5
LC
332 `(#:guile ,%bootstrap-guile
333 #:modules ((guix build utils))
334 #:builder
335 (let ((out (assoc-ref %outputs "out"))
336 (tar (assoc-ref %build-inputs "tar"))
337 (xz (assoc-ref %build-inputs "xz"))
338 (bash (assoc-ref %build-inputs "bash"))
339 (libc (assoc-ref %build-inputs "libc"))
340 (tarball (assoc-ref %build-inputs "tarball")))
341 (use-modules (guix build utils)
342 (ice-9 popen))
18633d4f 343
21c203a5
LC
344 (mkdir out)
345 (copy-file tarball "binaries.tar.xz")
346 (system* xz "-d" "binaries.tar.xz")
347 (let ((builddir (getcwd))
348 (bindir (string-append out "/bin")))
349 (with-directory-excursion out
350 (system* tar "xvf"
351 (string-append builddir "/binaries.tar")))
18633d4f 352
21c203a5
LC
353 (with-directory-excursion bindir
354 (chmod "." #o755)
355 (rename-file "gcc" ".gcc-wrapped")
356 (call-with-output-file "gcc"
357 (lambda (p)
358 (format p "#!~a
18633d4f
LC
359exec ~a/bin/.gcc-wrapped -B~a/lib \
360 -Wl,-rpath -Wl,~a/lib \
361 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
21c203a5
LC
362 bash
363 out libc libc libc
364 ,(glibc-dynamic-linker))))
18633d4f 365
21c203a5 366 (chmod "gcc" #o555))))))
18633d4f 367 (inputs
dd6b9a37
LC
368 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
369 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
370 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
18633d4f 371 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
372 ("tarball" ,(bootstrap-origin
373 (origin
374 (method url-fetch)
375 (uri (map (cut string-append <> "/" (%current-system)
06213498 376 "/20131110/gcc-4.8.2.tar.xz")
dd6b9a37
LC
377 %bootstrap-base-urls))
378 (sha256
379 (match (%current-system)
380 ("x86_64-linux"
381 (base32
06213498 382 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
dd6b9a37
LC
383 ("i686-linux"
384 (base32
06213498 385 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
f57ff219
MW
386 ("mips64el-linux"
387 (base32
06213498 388 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
a18eda27
LC
389 (native-search-paths
390 (list (search-path-specification
391 (variable "CPATH")
392 (directories '("include")))
393 (search-path-specification
394 (variable "LIBRARY_PATH")
395 (directories '("lib" "lib64")))))
18633d4f
LC
396 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
397 (description #f)
1fb78cb2
LC
398 (home-page #f)
399 (license gpl3+)))
18633d4f
LC
400
401(define %bootstrap-inputs
402 ;; The initial, pre-built inputs. From now on, we can start building our
403 ;; own packages.
404 `(("libc" ,%bootstrap-glibc)
405 ("gcc" ,%bootstrap-gcc)
406 ("binutils" ,%bootstrap-binutils)
9d1d434c
LC
407 ("coreutils&co" ,%bootstrap-coreutils&co)
408
409 ;; In gnu-build-system.scm, we rely on the availability of Bash.
410 ("bash" ,%bootstrap-coreutils&co)))
18633d4f
LC
411
412;;; bootstrap.scm ends here