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