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