packages: patch-and-repack: Build tarballs deterministically.
[jackhill/guix/guix.git] / gnu / packages / make-bootstrap.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
b15389e1 2;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
8ba60d7b 3;;;
233e7676 4;;; This file is part of GNU Guix.
8ba60d7b 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
8ba60d7b
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
8ba60d7b
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/>.
8ba60d7b 18
1ffa7090 19(define-module (gnu packages make-bootstrap)
8ba60d7b
LC
20 #:use-module (guix utils)
21 #:use-module (guix packages)
312543dc 22 #:use-module (guix licenses)
8ba60d7b 23 #:use-module (guix build-system trivial)
4d058c67 24 #:use-module (guix build-system gnu)
59a43334 25 #:use-module ((gnu packages) #:select (search-patch))
bdb36958 26 #:use-module ((gnu packages commencement) #:select (%final-inputs))
1ffa7090 27 #:use-module (gnu packages base)
a410a010 28 #:use-module (gnu packages cross-base)
1ffa7090
LC
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages gawk)
c415f145 32 #:use-module (gnu packages gcc)
1ffa7090 33 #:use-module (gnu packages guile)
e3b2cf4c 34 #:use-module (gnu packages bdw-gc)
1ffa7090
LC
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages multiprecision)
8ba60d7b 37 #:use-module (ice-9 match)
5d4fd267 38 #:use-module (srfi srfi-1)
8ba60d7b
LC
39 #:export (%bootstrap-binaries-tarball
40 %binutils-bootstrap-tarball
41 %glibc-bootstrap-tarball
42 %gcc-bootstrap-tarball
312543dc 43 %guile-bootstrap-tarball
78214b4b
LC
44 %bootstrap-tarballs
45
46 %guile-static-stripped))
8ba60d7b
LC
47
48;;; Commentary:
49;;;
3e8f16ba 50;;; This module provides tools to build tarballs of the "bootstrap binaries"
1ffa7090 51;;; used in (gnu packages bootstrap). These statically-linked binaries are
8ba60d7b
LC
52;;; taken for granted and used as the root of the whole bootstrap procedure.
53;;;
54;;; Code:
55
a410a010 56(define* (glibc-for-bootstrap #:optional (base glibc))
62751a5d
LC
57 "Return a libc deriving from BASE whose `system' and `popen' functions looks
58for `sh' in $PATH, and without nscd, and with static NSS modules."
59 (package (inherit base)
01eafd38
LC
60 (source (origin (inherit (package-source base))
61 (patches (cons (search-patch "glibc-bootstrap-system.patch")
62 (origin-patches (package-source base))))))
5d4fd267 63 (arguments
62751a5d 64 (substitute-keyword-arguments (package-arguments base)
21c203a5 65 ((#:configure-flags flags)
a410a010
LC
66 ;; Arrange so that getaddrinfo & co. do not contact the nscd,
67 ;; and can use statically-linked NSS modules.
68 `(cons* "--disable-nscd" "--disable-build-nscd"
69 "--enable-static-nss"
69f777d1
LC
70 ,flags))))
71
72 ;; Remove the 'debug' output to allow bit-reproducible builds (when the
73 ;; 'debug' output is used, ELF files end up with a .gnu_debuglink, which
74 ;; includes a CRC of the corresponding debugging symbols; those symbols
75 ;; contain store file names, so the CRC changes at every rebuild.)
76 (outputs (delete "debug" (package-outputs base)))))
62751a5d
LC
77
78(define (package-with-relocatable-glibc p)
79 "Return a variant of P that uses the libc as defined by
80`glibc-for-bootstrap'."
81
a410a010
LC
82 (define (cross-bootstrap-libc)
83 (let ((target (%current-target-system)))
84 (glibc-for-bootstrap
85 ;; `cross-libc' already returns a cross libc, so clear
86 ;; %CURRENT-TARGET-SYSTEM.
87 (parameterize ((%current-target-system #f))
88 (cross-libc target)))))
89
90 ;; Standard inputs with the above libc and corresponding GCC.
91
92 (define (inputs)
93 (if (%current-target-system) ; is this package cross built?
94 `(("cross-libc" ,(cross-bootstrap-libc)))
95 '()))
96
97 (define (native-inputs)
98 (if (%current-target-system)
99 (let ((target (%current-target-system)))
100 `(("cross-gcc" ,(cross-gcc target
101 (cross-binutils target)
102 (cross-bootstrap-libc)))
103 ("cross-binutils" ,(cross-binutils target))
104 ,@%final-inputs))
105 `(("libc" ,(glibc-for-bootstrap))
c92f1c0a 106 ("gcc" ,(package (inherit gcc)
37550e67 107 (outputs '("out")) ; all in one so libgcc_s is easily found
a410a010
LC
108 (inputs
109 `(("libc",(glibc-for-bootstrap))
c92f1c0a 110 ,@(package-inputs gcc)))))
a410a010 111 ,@(fold alist-delete %final-inputs '("libc" "gcc")))))
62751a5d
LC
112
113 (package-with-explicit-inputs p inputs
a410a010
LC
114 (current-source-location)
115 #:native-inputs native-inputs))
5d4fd267 116
8ba60d7b 117(define %bash-static
450fb5a6 118 (static-package bash-light))
8ba60d7b
LC
119
120(define %static-inputs
121 ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
122 (let ((coreutils (package (inherit coreutils)
af5cb60f
LC
123 (arguments
124 `(#:configure-flags
125 '("--disable-nls"
126 "--disable-silent-rules"
127 "--enable-no-install-program=stdbuf,libstdbuf.so"
128 "CFLAGS=-Os -g0" ; smaller, please
129 "LDFLAGS=-static -pthread")
130 #:tests? #f ; signal-related Gnulib tests fail
131 ,@(package-arguments coreutils)))
c2d771fd 132
af5cb60f
LC
133 ;; Remove optional dependencies such as GMP. Keep Perl
134 ;; except if it's missing (which is the case when
135 ;; cross-compiling).
136 (inputs (match (assoc "perl" (package-inputs coreutils))
137 (#f '())
e47185a4
LC
138 (x (list x))))
139
69f777d1 140 ;; Remove the 'debug' output (see above for the reason.)
e47185a4 141 (outputs '("out"))))
8ba60d7b
LC
142 (bzip2 (package (inherit bzip2)
143 (arguments
144 (substitute-keyword-arguments (package-arguments bzip2)
145 ((#:phases phases)
146 `(alist-cons-before
147 'build 'dash-static
148 (lambda _
149 (substitute* "Makefile"
150 (("^LDFLAGS[[:blank:]]*=.*$")
151 "LDFLAGS = -static")))
152 ,phases))))))
153 (xz (package (inherit xz)
154 (arguments
155 `(#:strip-flags '("--strip-all")
156 #:phases (alist-cons-before
157 'configure 'static-executable
158 (lambda _
159 ;; Ask Libtool for a static executable.
160 (substitute* "src/xz/Makefile.in"
161 (("^xz_LDADD =")
162 "xz_LDADD = -all-static")))
163 %standard-phases)))))
164 (gawk (package (inherit gawk)
01eafd38
LC
165 (source (origin (inherit (package-source gawk))
166 (patches (cons (search-patch "gawk-shell.patch")
167 (origin-patches
168 (package-source gawk))))))
8ba60d7b 169 (arguments
01eafd38 170 `(;; Starting from gawk 4.1.0, some of the tests for the
ffd20934
LC
171 ;; plug-in mechanism just fail on static builds:
172 ;;
173 ;; ./fts.awk:1: error: can't open shared library `filefuncs' for reading (No such file or directory)
174 #:tests? #f
175
21c203a5
LC
176 ,@(substitute-keyword-arguments (package-arguments gawk)
177 ((#:phases phases)
178 `(alist-cons-before
179 'configure 'no-export-dynamic
180 (lambda _
181 ;; Since we use `-static', remove
182 ;; `-export-dynamic'.
183 (substitute* "configure"
86d7043c 184 (("-Wl,-export-dynamic") "")))
21c203a5 185 ,phases)))))
01eafd38
LC
186 (inputs (if (%current-target-system)
187 `(("bash" ,%bash-static))
188 '()))))
a410a010
LC
189 (finalize (compose static-package
190 package-with-relocatable-glibc)))
8ba60d7b
LC
191 `(,@(map (match-lambda
192 ((name package)
5d4fd267 193 (list name (finalize package))))
8ba60d7b
LC
194 `(("tar" ,tar)
195 ("gzip" ,gzip)
196 ("bzip2" ,bzip2)
197 ("xz" ,xz)
198 ("patch" ,patch)
199 ("coreutils" ,coreutils)
200 ("sed" ,sed)
201 ("grep" ,grep)
202 ("gawk" ,gawk)))
a410a010 203 ("bash" ,%bash-static))))
8ba60d7b
LC
204
205(define %static-binaries
206 (package
207 (name "static-binaries")
208 (version "0")
209 (build-system trivial-build-system)
210 (source #f)
211 (inputs %static-inputs)
212 (arguments
213 `(#:modules ((guix build utils))
214 #:builder
215 (begin
216 (use-modules (ice-9 ftw)
217 (ice-9 match)
218 (srfi srfi-1)
219 (srfi srfi-26)
220 (guix build utils))
221
222 (let ()
223 (define (directory-contents dir)
224 (map (cut string-append dir "/" <>)
225 (scandir dir (negate (cut member <> '("." ".."))))))
226
227 (define (copy-directory source destination)
228 (for-each (lambda (file)
229 (format #t "copying ~s...~%" file)
230 (copy-file file
231 (string-append destination "/"
232 (basename file))))
233 (directory-contents source)))
234
235 (let* ((out (assoc-ref %outputs "out"))
236 (bin (string-append out "/bin")))
237 (mkdir-p bin)
238
239 ;; Copy Coreutils binaries.
240 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
241 (source (string-append coreutils "/bin")))
242 (copy-directory source bin))
243
244 ;; For the other inputs, copy just one binary, which has the
245 ;; same name as the input.
246 (for-each (match-lambda
247 ((name . dir)
248 (let ((source (string-append dir "/bin/" name)))
249 (format #t "copying ~s...~%" source)
250 (copy-file source
251 (string-append bin "/" name)))))
252 (alist-delete "coreutils" %build-inputs))
253
254 ;; But of course, there are exceptions to this rule.
255 (let ((grep (assoc-ref %build-inputs "grep")))
256 (copy-file (string-append grep "/bin/fgrep")
257 (string-append bin "/fgrep"))
258 (copy-file (string-append grep "/bin/egrep")
259 (string-append bin "/egrep")))
260
261 ;; Clear references to the store path.
262 (for-each remove-store-references
263 (directory-contents bin))
264
265 (with-directory-excursion bin
266 ;; Programs such as Perl's build system want these aliases.
267 (symlink "bash" "sh")
268 (symlink "gawk" "awk"))
269
270 #t)))))
271 (synopsis "Statically-linked bootstrap binaries")
272 (description
273 "Binaries used to bootstrap the distribution.")
274 (license #f)
275 (home-page #f)))
276
277(define %binutils-static
278 ;; Statically-linked Binutils.
279 (package (inherit binutils)
280 (name "binutils-static")
281 (arguments
57084853
LC
282 `(#:configure-flags (cons "--disable-gold"
283 ,(match (memq #:configure-flags
284 (package-arguments binutils))
285 ((#:configure-flags flags _ ...)
286 flags)))
8ba60d7b
LC
287 #:strip-flags '("--strip-all")
288 #:phases (alist-cons-before
289 'configure 'all-static
290 (lambda _
291 ;; The `-all-static' libtool flag can only be passed
292 ;; after `configure', since configure tests don't use
293 ;; libtool, and only for executables built with libtool.
294 (substitute* '("binutils/Makefile.in"
295 "gas/Makefile.in"
296 "ld/Makefile.in")
297 (("^LDFLAGS =(.*)$" line)
298 (string-append line
299 "\nAM_LDFLAGS = -static -all-static\n"))))
300 %standard-phases)))))
301
302(define %binutils-static-stripped
303 ;; The subset of Binutils that we need.
304 (package (inherit %binutils-static)
431f35f0 305 (name (string-append (package-name %binutils-static) "-stripped"))
8ba60d7b 306 (build-system trivial-build-system)
431f35f0 307 (outputs '("out"))
8ba60d7b
LC
308 (arguments
309 `(#:modules ((guix build utils))
310 #:builder
311 (begin
312 (use-modules (guix build utils))
313
314 (setvbuf (current-output-port) _IOLBF)
315 (let* ((in (assoc-ref %build-inputs "binutils"))
316 (out (assoc-ref %outputs "out"))
317 (bin (string-append out "/bin")))
318 (mkdir-p bin)
319 (for-each (lambda (file)
320 (let ((target (string-append bin "/" file)))
321 (format #t "copying `~a'...~%" file)
322 (copy-file (string-append in "/bin/" file)
323 target)
324 (remove-store-references target)))
325 '("ar" "as" "ld" "nm" "objcopy" "objdump"
326 "ranlib" "readelf" "size" "strings" "strip"))
327 #t))))
328 (inputs `(("binutils" ,%binutils-static)))))
329
330(define %glibc-stripped
331 ;; GNU libc's essential shared libraries, dynamic linker, and headers,
332 ;; with all references to store directories stripped. As a result,
333 ;; libc.so is unusable and need to be patched for proper relocation.
62751a5d 334 (let ((glibc (glibc-for-bootstrap)))
5d4fd267
LC
335 (package (inherit glibc)
336 (name "glibc-stripped")
337 (build-system trivial-build-system)
338 (arguments
339 `(#:modules ((guix build utils))
340 #:builder
341 (begin
342 (use-modules (guix build utils))
343
344 (setvbuf (current-output-port) _IOLBF)
345 (let* ((out (assoc-ref %outputs "out"))
346 (libdir (string-append out "/lib"))
347 (incdir (string-append out "/include"))
348 (libc (assoc-ref %build-inputs "libc"))
349 (linux (assoc-ref %build-inputs "linux-headers")))
350 (mkdir-p libdir)
351 (for-each (lambda (file)
352 (let ((target (string-append libdir "/"
353 (basename file))))
354 (copy-file file target)
355 (remove-store-references target)))
356 (find-files (string-append libc "/lib")
357 "^(crt.*|ld.*|lib(c|m|dl|rt|pthread|nsl|util).*\\.so(\\..*)?|libc_nonshared\\.a)$"))
358
359 (copy-recursively (string-append libc "/include") incdir)
360
361 ;; Copy some of the Linux-Libre headers that glibc headers
362 ;; refer to.
363 (mkdir (string-append incdir "/linux"))
364 (for-each (lambda (file)
365 (copy-file (string-append linux "/include/linux/" file)
366 (string-append incdir "/linux/"
367 (basename file))))
368 '("limits.h" "errno.h" "socket.h" "kernel.h"
369 "sysctl.h" "param.h" "ioctl.h" "types.h"
370 "posix_types.h" "stddef.h"))
371
372 (copy-recursively (string-append linux "/include/asm")
373 (string-append incdir "/asm"))
374 (copy-recursively (string-append linux "/include/asm-generic")
375 (string-append incdir "/asm-generic"))
c9323eac 376
5d4fd267 377 #t))))
a410a010
LC
378 (inputs `(("libc" ,(let ((target (%current-target-system)))
379 (if target
380 (glibc-for-bootstrap
381 (parameterize ((%current-target-system #f))
382 (cross-libc target)))
383 glibc)))
867df0ee
LC
384 ("linux-headers" ,linux-libre-headers)))
385
386 ;; Only one output.
387 (outputs '("out")))))
8ba60d7b
LC
388
389(define %gcc-static
390 ;; A statically-linked GCC, with stripped-down functionality.
62751a5d 391 (package-with-relocatable-glibc
c92f1c0a 392 (package (inherit gcc)
5d4fd267 393 (name "gcc-static")
84e6756c 394 (outputs '("out")) ; all in one
5d4fd267 395 (arguments
21c203a5
LC
396 `(#:modules ((guix build utils)
397 (guix build gnu-build-system)
398 (srfi srfi-1)
399 (srfi srfi-26)
400 (ice-9 regex))
c92f1c0a 401 ,@(substitute-keyword-arguments (package-arguments gcc)
21c203a5
LC
402 ((#:guile _) #f)
403 ((#:implicit-inputs? _) #t)
404 ((#:configure-flags flags)
405 `(append (list
288a09ca
LC
406 ;; We don't need a full bootstrap here.
407 "--disable-bootstrap"
408
409 ;; Make sure '-static' is passed where it matters.
410 "--with-stage1-ldflags=-static"
411
97b465fe
LC
412 ;; GCC 4.8+ requires a C++ compiler and library.
413 "--enable-languages=c,c++"
414
c4873bc4
LC
415 ;; Make sure gcc-nm doesn't require liblto_plugin.so.
416 "--disable-lto"
417
21c203a5
LC
418 "--disable-shared"
419 "--disable-plugin"
21c203a5 420 "--disable-libmudflap"
953ab503
LC
421 "--disable-libatomic"
422 "--disable-libsanitizer"
423 "--disable-libitm"
21c203a5 424 "--disable-libgomp"
8dca238b
LC
425 "--disable-libcilkrts"
426 "--disable-libvtv"
21c203a5
LC
427 "--disable-libssp"
428 "--disable-libquadmath"
429 "--disable-decimal-float")
430 (remove (cut string-match "--(.*plugin|enable-languages)" <>)
270b501e
MW
431 ,flags)))
432 ((#:phases phases)
433 `(alist-cons-after
434 'pre-configure 'remove-lgcc_s
435 (lambda _
436 ;; Remove the '-lgcc_s' added to GNU_USER_TARGET_LIB_SPEC in
437 ;; the 'pre-configure phase of our main gcc package, because
438 ;; that shared library is not present in this static gcc. See
439 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-01/msg00008.html>.
440 (substitute* (find-files "gcc/config"
441 "^gnu-user.*\\.h$")
442 ((" -lgcc_s}}") "}}")))
443 ,phases)))))
0ece7074
LC
444 (native-inputs
445 (if (%current-target-system)
446 `(;; When doing a Canadian cross, we need GMP/MPFR/MPC both
447 ;; as target inputs and as native inputs; the latter is
448 ;; needed when building build-time tools ('genconstants',
449 ;; etc.) Failing to do that leads to misdetections of
450 ;; declarations by 'gcc/configure', and eventually to
451 ;; duplicate declarations as reported in
452 ;; <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>.
453 ("gmp-native" ,gmp)
454 ("mpfr-native" ,mpfr)
455 ("mpc-native" ,mpc)
c92f1c0a
LC
456 ,@(package-native-inputs gcc))
457 (package-native-inputs gcc))))))
8ba60d7b
LC
458
459(define %gcc-stripped
460 ;; The subset of GCC files needed for bootstrap.
c92f1c0a 461 (package (inherit gcc)
8ba60d7b
LC
462 (name "gcc-stripped")
463 (build-system trivial-build-system)
464 (source #f)
37550e67 465 (outputs '("out")) ;only one output
8ba60d7b
LC
466 (arguments
467 `(#:modules ((guix build utils))
468 #:builder
469 (begin
470 (use-modules (srfi srfi-1)
471 (srfi srfi-26)
472 (guix build utils))
473
474 (setvbuf (current-output-port) _IOLBF)
475 (let* ((out (assoc-ref %outputs "out"))
476 (bindir (string-append out "/bin"))
477 (libdir (string-append out "/lib"))
55a5674f 478 (includedir (string-append out "/include"))
8ba60d7b
LC
479 (libexecdir (string-append out "/libexec"))
480 (gcc (assoc-ref %build-inputs "gcc")))
481 (copy-recursively (string-append gcc "/bin") bindir)
482 (for-each remove-store-references
483 (find-files bindir ".*"))
484
485 (copy-recursively (string-append gcc "/lib") libdir)
486 (for-each remove-store-references
487 (remove (cut string-suffix? ".h" <>)
488 (find-files libdir ".*")))
489
490 (copy-recursively (string-append gcc "/libexec")
491 libexecdir)
492 (for-each remove-store-references
493 (find-files libexecdir ".*"))
55a5674f
LC
494
495 ;; Starting from GCC 4.8, helper programs built natively
496 ;; (‘genchecksum’, ‘gcc-nm’, etc.) rely on C++ headers.
497 (copy-recursively (string-append gcc "/include/c++")
498 (string-append includedir "/c++"))
6e3ecad6
LC
499
500 ;; For native builds, check whether the binaries actually work.
501 ,(if (%current-target-system)
502 '#t
503 '(every (lambda (prog)
504 (zero? (system* (string-append gcc "/bin/" prog)
505 "--version")))
506 '("gcc" "g++" "cpp")))))))
8ba60d7b
LC
507 (inputs `(("gcc" ,%gcc-static)))))
508
509(define %guile-static
510 ;; A statically-linked Guile that is relocatable--i.e., it can search
511 ;; .scm and .go files relative to its installation directory, rather
512 ;; than in hard-coded configure-time paths.
dfb52abb
LC
513 (let* ((patches (cons* (search-patch "guile-relocatable.patch")
514 (search-patch "guile-default-utf8.patch")
515 (search-patch "guile-linux-syscalls.patch")
516 (origin-patches (package-source guile-2.0))))
517 (source (origin (inherit (package-source guile-2.0))
518 (patches patches)))
01eafd38 519 (guile (package (inherit guile-2.0)
a410a010 520 (name (string-append (package-name guile-2.0) "-static"))
dfb52abb 521 (source source)
75ca2f4f 522 (synopsis "Statically-linked and relocatable Guile")
69f777d1
LC
523
524 ;; Remove the 'debug' output (see above for the reason.)
525 (outputs (delete "debug" (package-outputs guile-2.0)))
526
a410a010
LC
527 (propagated-inputs
528 `(("bdw-gc" ,libgc)
529 ,@(alist-delete "bdw-gc"
530 (package-propagated-inputs guile-2.0))))
531 (arguments
532 `(;; When `configure' checks for ltdl availability, it
533 ;; doesn't try to link using libtool, and thus fails
534 ;; because of a missing -ldl. Work around that.
db619089 535 #:configure-flags '("LDFLAGS=-ldl")
a410a010
LC
536
537 #:phases (alist-cons-before
538 'configure 'static-guile
539 (lambda _
540 (substitute* "libguile/Makefile.in"
541 ;; Create a statically-linked `guile'
542 ;; executable.
543 (("^guile_LDFLAGS =")
544 "guile_LDFLAGS = -all-static")
545
546 ;; Add `-ldl' *after* libguile-2.0.la.
547 (("^guile_LDADD =(.*)$" _ ldadd)
548 (string-append "guile_LDADD = "
549 (string-trim-right ldadd)
550 " -ldl\n"))))
551 %standard-phases)
552
a410a010
LC
553 ;; There are uses of `dynamic-link' in
554 ;; {foreign,coverage}.test that don't fly here.
555 #:tests? #f)))))
62751a5d 556 (package-with-relocatable-glibc (static-package guile))))
8ba60d7b
LC
557
558(define %guile-static-stripped
559 ;; A stripped static Guile binary, for use during bootstrap.
560 (package (inherit %guile-static)
561 (name "guile-static-stripped")
562 (build-system trivial-build-system)
563 (arguments
564 `(#:modules ((guix build utils))
565 #:builder
566 (let ()
567 (use-modules (guix build utils))
568
3e8f16ba
LC
569 (let* ((in (assoc-ref %build-inputs "guile"))
570 (out (assoc-ref %outputs "out"))
571 (guile1 (string-append in "/bin/guile"))
572 (guile2 (string-append out "/bin/guile")))
8ba60d7b
LC
573 (mkdir-p (string-append out "/share/guile/2.0"))
574 (copy-recursively (string-append in "/share/guile/2.0")
575 (string-append out "/share/guile/2.0"))
576
577 (mkdir-p (string-append out "/lib/guile/2.0/ccache"))
578 (copy-recursively (string-append in "/lib/guile/2.0/ccache")
579 (string-append out "/lib/guile/2.0/ccache"))
580
581 (mkdir (string-append out "/bin"))
3e8f16ba
LC
582 (copy-file guile1 guile2)
583
584 ;; Does the relocated Guile work?
585 (and ,(if (%current-target-system)
586 #t
587 '(zero? (system* guile2 "--version")))
588 (begin
589 ;; Strip store references.
590 (remove-store-references guile2)
591
592 ;; Does the stripped Guile work? If it aborts, it could be
593 ;; that it tries to open iconv descriptors and fails because
594 ;; libc's iconv data isn't available (see
595 ;; `guile-default-utf8.patch'.)
596 ,(if (%current-target-system)
597 #t
598 '(zero? (system* guile2 "--version")))))))))
3a4ebc11 599 (inputs `(("guile" ,%guile-static)))
75ca2f4f
LC
600 (outputs '("out"))
601 (synopsis "Minimal statically-linked and relocatable Guile")))
8ba60d7b
LC
602
603(define (tarball-package pkg)
604 "Return a package containing a tarball of PKG."
605 (package (inherit pkg)
8ba60d7b
LC
606 (name (string-append (package-name pkg) "-tarball"))
607 (build-system trivial-build-system)
a410a010
LC
608 (native-inputs `(("tar" ,tar)
609 ("xz" ,xz)))
610 (inputs `(("input" ,pkg)))
8ba60d7b 611 (arguments
21c203a5
LC
612 (let ((name (package-name pkg))
613 (version (package-version pkg)))
614 `(#:modules ((guix build utils))
615 #:builder
616 (begin
617 (use-modules (guix build utils))
618 (let ((out (assoc-ref %outputs "out"))
619 (input (assoc-ref %build-inputs "input"))
620 (tar (assoc-ref %build-inputs "tar"))
621 (xz (assoc-ref %build-inputs "xz")))
622 (mkdir out)
623 (set-path-environment-variable "PATH" '("bin") (list tar xz))
624 (with-directory-excursion input
625 (zero? (system* "tar" "cJvf"
626 (string-append out "/"
627 ,name "-" ,version
a410a010
LC
628 "-"
629 ,(or (%current-target-system)
630 (%current-system))
21c203a5
LC
631 ".tar.xz")
632 "."))))))))))
8ba60d7b
LC
633
634(define %bootstrap-binaries-tarball
635 ;; A tarball with the statically-linked bootstrap binaries.
636 (tarball-package %static-binaries))
637
638(define %binutils-bootstrap-tarball
639 ;; A tarball with the statically-linked Binutils programs.
640 (tarball-package %binutils-static-stripped))
641
642(define %glibc-bootstrap-tarball
643 ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
644 (tarball-package %glibc-stripped))
645
646(define %gcc-bootstrap-tarball
647 ;; A tarball with a dynamic-linked GCC and its headers.
648 (tarball-package %gcc-stripped))
649
650(define %guile-bootstrap-tarball
651 ;; A tarball with the statically-linked, relocatable Guile.
652 (tarball-package %guile-static-stripped))
653
312543dc
LC
654(define %bootstrap-tarballs
655 ;; A single derivation containing all the bootstrap tarballs, for
656 ;; convenience.
657 (package
658 (name "bootstrap-tarballs")
659 (version "0")
660 (source #f)
661 (build-system trivial-build-system)
662 (arguments
663 `(#:modules ((guix build utils))
664 #:builder
665 (let ((out (assoc-ref %outputs "out")))
666 (use-modules (guix build utils)
667 (ice-9 match)
668 (srfi srfi-26))
669
670 (setvbuf (current-output-port) _IOLBF)
671 (mkdir out)
672 (chdir out)
673 (for-each (match-lambda
674 ((name . directory)
675 (for-each (lambda (file)
676 (format #t "~a -> ~a~%" file out)
677 (symlink file (basename file)))
678 (find-files directory "\\.tar\\."))))
679 %build-inputs)
680 #t)))
681 (inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
682 ("gcc-tarball" ,%gcc-bootstrap-tarball)
683 ("binutils-tarball" ,%binutils-bootstrap-tarball)
684 ("glibc-tarball" ,%glibc-bootstrap-tarball)
685 ("coreutils&co-tarball" ,%bootstrap-binaries-tarball)))
686 (synopsis #f)
687 (description #f)
688 (home-page #f)
689 (license gpl3+)))
690
8ba60d7b 691;;; make-bootstrap.scm ends here