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