Revert "utils: Add 'wrap-program'."
[jackhill/guix/guix.git] / gnu / packages / bootstrap.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
4050e5d6 2;;; Copyright © 2012, 2013 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
67 (let ((orig-method (origin-method source)))
68 (origin (inherit source)
87f5d366 69 (method (cond ((eq? orig-method url-fetch)
62cab99c 70 (boot url-fetch))
18633d4f
LC
71 (else orig-method))))))
72
73(define (package-from-tarball name* source* program-to-test description*)
74 "Return a package that correspond to the extraction of SOURCE*.
75PROGRAM-TO-TEST is a program to run after extraction of SOURCE*, to
76check whether everything is alright."
77 (package
78 (name name*)
79 (version "0")
80 (source #f)
81 (build-system trivial-build-system)
82 (arguments
83 `(#:guile ,%bootstrap-guile
84 #:modules ((guix build utils))
85 #:builder
86 (let ((out (assoc-ref %outputs "out"))
87 (tar (assoc-ref %build-inputs "tar"))
88 (xz (assoc-ref %build-inputs "xz"))
89 (tarball (assoc-ref %build-inputs "tarball")))
90 (use-modules (guix build utils))
91
92 (mkdir out)
93 (copy-file tarball "binaries.tar.xz")
94 (system* xz "-d" "binaries.tar.xz")
95 (let ((builddir (getcwd)))
96 (with-directory-excursion out
97 (and (zero? (system* tar "xvf"
98 (string-append builddir "/binaries.tar")))
99 (zero? (system* (string-append "bin/" ,program-to-test)
100 "--version"))))))))
101 (inputs
dd6b9a37
LC
102 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
103 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
104 ("tarball" ,(bootstrap-origin (source* (%current-system))))))
18633d4f
LC
105 (synopsis description*)
106 (description #f)
107 (home-page #f)))
108
109(define package-with-bootstrap-guile
110 (memoize
111 (lambda (p)
112 "Return a variant of P such that all its origins are fetched with
113%BOOTSTRAP-GUILE."
114 (define rewritten-input
115 (match-lambda
116 ((name (? origin? o))
117 `(,name ,(bootstrap-origin o)))
118 ((name (? package? p) sub-drvs ...)
119 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
120 (x x)))
121
122 (package (inherit p)
123 (source (match (package-source p)
124 ((? origin? o) (bootstrap-origin o))
125 (s s)))
126 (inputs (map rewritten-input
127 (package-inputs p)))
128 (native-inputs (map rewritten-input
129 (package-native-inputs p)))
130 (propagated-inputs (map rewritten-input
131 (package-propagated-inputs p)))))))
132
21c203a5 133(define* (glibc-dynamic-linker #:optional (system (%current-system)))
18633d4f
LC
134 "Return the name of Glibc's dynamic linker for SYSTEM."
135 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
136 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
137 (else (error "dynamic linker name not known for this system"
138 system))))
139
140\f
141;;;
142;;; Bootstrap packages.
143;;;
144
145(define %bootstrap-guile
146 ;; The Guile used to run the build scripts of the initial derivations.
147 ;; It is just unpacked from a tarball containing a pre-built binary.
148 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
149 ;;
150 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
151 ;; support (for /etc/services).
152 (let ((raw (build-system
153 (name "raw")
154 (description "Raw build system with direct store access")
155 (build (lambda* (store name source inputs #:key outputs system)
156 (define (->store file)
a9ebd9ef 157 (add-to-store store file #t "sha256"
18633d4f
LC
158 (or (search-bootstrap-binary file
159 system)
160 (error "bootstrap binary not found"
161 file system))))
162
163 (let* ((tar (->store "tar"))
164 (xz (->store "xz"))
165 (mkdir (->store "mkdir"))
166 (bash (->store "bash"))
0f099552 167 (guile (->store "guile-2.0.7.tar.xz"))
18633d4f
LC
168 (builder
169 (add-text-to-store store
170 "build-bootstrap-guile.sh"
171 (format #f "
172echo \"unpacking bootstrap Guile to '$out'...\"
173~a $out
174cd $out
175~a -dc < ~a | ~a xv
176
177# Sanity check.
178$out/bin/guile --version~%"
179 mkdir xz guile tar)
180 (list mkdir xz guile tar))))
181 (derivation store name system
182 bash `(,builder) '()
183 `((,bash) (,builder)))))))))
184 (package
185 (name "guile-bootstrap")
186 (version "2.0")
187 (source #f)
188 (build-system raw)
189 (synopsis "Bootstrap Guile")
190 (description "Pre-built Guile for bootstrapping purposes.")
191 (home-page #f)
4a44e743 192 (license lgpl3+))))
18633d4f 193
04732c37 194(define %bootstrap-base-urls
18633d4f 195 ;; This is where the initial binaries come from.
04732c37
LC
196 '("http://alpha.gnu.org/gnu/guix/bootstrap"
197 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
18633d4f
LC
198
199(define %bootstrap-coreutils&co
200 (package-from-tarball "bootstrap-binaries"
201 (lambda (system)
202 (origin
87f5d366 203 (method url-fetch)
04732c37
LC
204 (uri (map (cut string-append <> "/" system
205 "/20130105/static-binaries.tar.xz")
206 %bootstrap-base-urls))
18633d4f
LC
207 (sha256
208 (match system
209 ("x86_64-linux"
210 (base32
79580eb6 211 "0md23alzy6nc5f16pric7mkagczdzr8xbh074sb3rjzrls06j1ls"))
18633d4f
LC
212 ("i686-linux"
213 (base32
79580eb6 214 "0nzj1lmm9b94g7k737cr4w1dv282w5nmhb53238ikax9r6pkc0yb"))))))
18633d4f
LC
215 "true" ; the program to test
216 "Bootstrap binaries of Coreutils, Awk, etc."))
217
218(define %bootstrap-binutils
219 (package-from-tarball "binutils-bootstrap"
220 (lambda (system)
221 (origin
87f5d366 222 (method url-fetch)
04732c37
LC
223 (uri (map (cut string-append <> "/" system
224 "/20130105/binutils-2.22.tar.xz")
225 %bootstrap-base-urls))
18633d4f
LC
226 (sha256
227 (match system
228 ("x86_64-linux"
229 (base32
79580eb6 230 "1ffmk2yy2pxvkqgzrkzp3s4jpn4qaaksyk3b5nsc5cjwfm7qkgzh"))
18633d4f
LC
231 ("i686-linux"
232 (base32
79580eb6 233 "1rafk6aq4sayvv3r3d2khn93nkyzf002xzh0xadlyci4mznr6b0a"))))))
18633d4f
LC
234 "ld" ; the program to test
235 "Bootstrap binaries of the GNU Binutils"))
236
237(define %bootstrap-glibc
238 ;; The initial libc.
239 (package
240 (name "glibc-bootstrap")
241 (version "0")
242 (source #f)
243 (build-system trivial-build-system)
244 (arguments
245 `(#:guile ,%bootstrap-guile
246 #:modules ((guix build utils))
247 #:builder
248 (let ((out (assoc-ref %outputs "out"))
249 (tar (assoc-ref %build-inputs "tar"))
250 (xz (assoc-ref %build-inputs "xz"))
251 (tarball (assoc-ref %build-inputs "tarball")))
252 (use-modules (guix build utils))
253
254 (mkdir out)
255 (copy-file tarball "binaries.tar.xz")
256 (system* xz "-d" "binaries.tar.xz")
257 (let ((builddir (getcwd)))
258 (with-directory-excursion out
259 (system* tar "xvf"
260 (string-append builddir
261 "/binaries.tar"))
262 (chmod "lib" #o755)
263
264 ;; Patch libc.so so it refers to the right path.
265 (substitute* "lib/libc.so"
266 (("/[^ ]+/lib/(libc|ld)" _ prefix)
267 (string-append out "/lib/" prefix))))))))
268 (inputs
dd6b9a37
LC
269 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
270 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
271 ("tarball" ,(bootstrap-origin
272 (origin
273 (method url-fetch)
274 (uri (map (cut string-append <> "/" (%current-system)
275 "/20130105/glibc-2.17.tar.xz")
276 %bootstrap-base-urls))
277 (sha256
278 (match (%current-system)
279 ("x86_64-linux"
280 (base32
281 "18kv1z9d8dr1j3hm9w7663kchqw9p6rsx11n1m143jgba2jz6jy3"))
282 ("i686-linux"
283 (base32
284 "08hv8i0axwnihrcgbz19x0a7s6zyv3yx38x8r29liwl8h82x9g88")))))))))
18633d4f
LC
285 (synopsis "Bootstrap binaries and headers of the GNU C Library")
286 (description #f)
287 (home-page #f)))
288
289(define %bootstrap-gcc
290 ;; The initial GCC. Uses binaries from a tarball typically built by
291 ;; %GCC-BOOTSTRAP-TARBALL.
292 (package
293 (name "gcc-bootstrap")
294 (version "0")
295 (source #f)
296 (build-system trivial-build-system)
297 (arguments
21c203a5
LC
298 `(#:guile ,%bootstrap-guile
299 #:modules ((guix build utils))
300 #:builder
301 (let ((out (assoc-ref %outputs "out"))
302 (tar (assoc-ref %build-inputs "tar"))
303 (xz (assoc-ref %build-inputs "xz"))
304 (bash (assoc-ref %build-inputs "bash"))
305 (libc (assoc-ref %build-inputs "libc"))
306 (tarball (assoc-ref %build-inputs "tarball")))
307 (use-modules (guix build utils)
308 (ice-9 popen))
18633d4f 309
21c203a5
LC
310 (mkdir out)
311 (copy-file tarball "binaries.tar.xz")
312 (system* xz "-d" "binaries.tar.xz")
313 (let ((builddir (getcwd))
314 (bindir (string-append out "/bin")))
315 (with-directory-excursion out
316 (system* tar "xvf"
317 (string-append builddir "/binaries.tar")))
18633d4f 318
21c203a5
LC
319 (with-directory-excursion bindir
320 (chmod "." #o755)
321 (rename-file "gcc" ".gcc-wrapped")
322 (call-with-output-file "gcc"
323 (lambda (p)
324 (format p "#!~a
18633d4f
LC
325exec ~a/bin/.gcc-wrapped -B~a/lib \
326 -Wl,-rpath -Wl,~a/lib \
327 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
21c203a5
LC
328 bash
329 out libc libc libc
330 ,(glibc-dynamic-linker))))
18633d4f 331
21c203a5 332 (chmod "gcc" #o555))))))
18633d4f 333 (inputs
dd6b9a37
LC
334 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
335 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
336 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
18633d4f 337 ("libc" ,%bootstrap-glibc)
dd6b9a37
LC
338 ("tarball" ,(bootstrap-origin
339 (origin
340 (method url-fetch)
341 (uri (map (cut string-append <> "/" (%current-system)
342 "/20130105/gcc-4.7.2.tar.xz")
343 %bootstrap-base-urls))
344 (sha256
345 (match (%current-system)
346 ("x86_64-linux"
347 (base32
348 "1x1p7han5crnbw906iwdifykr6grzm0w27dy9gz75j0q1b32i4px"))
349 ("i686-linux"
350 (base32
351 "06wqs0xxnpw3hn0xjb4c9cs0899p1xwkcysa2rvzhvpra0c5vsg2")))))))))
18633d4f
LC
352 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
353 (description #f)
354 (home-page #f)))
355
356(define %bootstrap-inputs
357 ;; The initial, pre-built inputs. From now on, we can start building our
358 ;; own packages.
359 `(("libc" ,%bootstrap-glibc)
360 ("gcc" ,%bootstrap-gcc)
361 ("binutils" ,%bootstrap-binutils)
9d1d434c
LC
362 ("coreutils&co" ,%bootstrap-coreutils&co)
363
364 ;; In gnu-build-system.scm, we rely on the availability of Bash.
365 ("bash" ,%bootstrap-coreutils&co)))
18633d4f
LC
366
367;;; bootstrap.scm ends here