gnu: emacs-sly: Update to 20200228.
[jackhill/guix/guix.git] / gnu / packages / make-bootstrap.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2018, 2019 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7 ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
8 ;;;
9 ;;; This file is part of GNU Guix.
10 ;;;
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
15 ;;;
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24 (define-module (gnu packages make-bootstrap)
25 #:use-module (guix utils)
26 #:use-module (guix packages)
27 #:use-module (guix memoization)
28 #:use-module ((guix licenses) #:select (gpl3+))
29 #:use-module (guix build-system trivial)
30 #:use-module (guix build-system gnu)
31 #:use-module ((gnu packages) #:select (search-patch))
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages cross-base)
34 #:use-module (gnu packages bash)
35 #:use-module (gnu packages compression)
36 #:use-module (gnu packages gawk)
37 #:use-module (gnu packages gcc)
38 #:use-module (gnu packages guile)
39 #:use-module (gnu packages bdw-gc)
40 #:use-module (gnu packages libunistring)
41 #:use-module (gnu packages linux)
42 #:use-module (gnu packages hurd)
43 #:use-module (gnu packages mes)
44 #:use-module (gnu packages multiprecision)
45 #:use-module (ice-9 match)
46 #:use-module (srfi srfi-1)
47 #:export (%bootstrap-binaries-tarball
48 %linux-libre-headers-bootstrap-tarball
49 %binutils-bootstrap-tarball
50 %glibc-bootstrap-tarball
51 %gcc-bootstrap-tarball
52 %guile-bootstrap-tarball
53 %mescc-tools-bootstrap-tarball
54 %mes-bootstrap-tarball
55 %bootstrap-tarballs
56
57 %guile-static-stripped))
58
59 ;;; Commentary:
60 ;;;
61 ;;; This module provides tools to build tarballs of the "bootstrap binaries"
62 ;;; used in (gnu packages bootstrap). These statically-linked binaries are
63 ;;; taken for granted and used as the root of the whole bootstrap procedure.
64 ;;;
65 ;;; Code:
66
67 (define glibc-for-bootstrap
68 (mlambdaq (base)
69 "Return a libc deriving from BASE whose `system' and `popen' functions looks
70 for `sh' in $PATH, and without nscd, and with static NSS modules."
71 (package
72 (inherit base)
73 (source (origin (inherit (package-source base))
74 (patches (cons (search-patch "glibc-bootstrap-system.patch")
75 (origin-patches (package-source base))))))
76 (arguments
77 (substitute-keyword-arguments (package-arguments base)
78 ((#:configure-flags flags)
79 ;; Arrange so that getaddrinfo & co. do not contact the nscd,
80 ;; and can use statically-linked NSS modules.
81 `(cons* "--disable-nscd" "--disable-build-nscd"
82 "--enable-static-nss"
83 ,flags))))
84
85 ;; Remove the 'debug' output to allow bit-reproducible builds (when the
86 ;; 'debug' output is used, ELF files end up with a .gnu_debuglink, which
87 ;; includes a CRC of the corresponding debugging symbols; those symbols
88 ;; contain store file names, so the CRC changes at every rebuild.)
89 (outputs (delete "debug" (package-outputs base))))))
90
91 (define gcc-for-bootstrap
92 (mlambdaq (glibc)
93 "Return a variant of GCC that uses the bootstrap variant of GLIBC."
94 (package
95 (inherit gcc)
96 (outputs '("out")) ;all in one so libgcc_s is easily found
97 (native-search-paths
98 ;; Set CPLUS_INCLUDE_PATH so GCC is able to find the libc
99 ;; C++ headers.
100 (cons (search-path-specification
101 (variable "CPLUS_INCLUDE_PATH")
102 (files '("include")))
103 (package-native-search-paths gcc)))
104 (inputs
105 `( ;; Distinguish the name so we can refer to it below.
106 ("bootstrap-libc" ,(glibc-for-bootstrap glibc))
107 ("libc:static" ,(glibc-for-bootstrap glibc) "static")
108 ,@(package-inputs gcc)))
109 (arguments
110 (substitute-keyword-arguments (package-arguments gcc)
111 ((#:phases phases)
112 `(modify-phases ,phases
113 (add-before 'configure 'treat-glibc-as-system-header
114 (lambda* (#:key inputs #:allow-other-keys)
115 (let ((libc (assoc-ref inputs "bootstrap-libc")))
116 ;; GCCs build processes requires that the libc
117 ;; we're building against is on the system header
118 ;; search path.
119 (for-each (lambda (var)
120 (setenv var (string-append libc "/include")))
121 '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
122 #t))))))))))
123
124 (define (package-with-relocatable-glibc p)
125 "Return a variant of P that uses the libc as defined by
126 `glibc-for-bootstrap'."
127
128 (define (cross-bootstrap-libc target)
129 (glibc-for-bootstrap
130 ;; `cross-libc' already returns a cross libc, so clear
131 ;; %CURRENT-TARGET-SYSTEM.
132 (parameterize ((%current-target-system #f))
133 (cross-libc target))))
134
135 ;; Standard inputs with the above libc and corresponding GCC.
136
137 (define (inputs)
138 (if (%current-target-system) ; is this package cross built?
139 `(("cross-libc"
140 ,(cross-bootstrap-libc (%current-target-system))))
141 '()))
142
143 (define (native-inputs)
144 (if (%current-target-system)
145 (let* ((target (%current-target-system))
146 (xgcc (cross-gcc
147 target
148 #:xbinutils (cross-binutils target)
149 #:libc (cross-bootstrap-libc target))))
150 `(("cross-gcc" ,(package
151 (inherit xgcc)
152 (search-paths
153 ;; Ensure the cross libc headers appears on the
154 ;; C++ system header search path.
155 (cons (search-path-specification
156 (variable "CROSS_CPLUS_INCLUDE_PATH")
157 (files '("include")))
158 (package-search-paths gcc)))))
159 ("cross-binutils" ,(cross-binutils target))
160 ,@(%final-inputs)))
161 `(("libc" ,(glibc-for-bootstrap glibc))
162 ("libc:static" ,(glibc-for-bootstrap glibc) "static")
163 ("gcc" ,(gcc-for-bootstrap glibc))
164 ,@(fold alist-delete (%final-inputs) '("libc" "gcc")))))
165
166 (package-with-explicit-inputs p inputs
167 (current-source-location)
168 #:native-inputs native-inputs))
169
170 (define static-bash-for-bootstrap
171 (package
172 (inherit static-bash)
173 (source (origin
174 (inherit (package-source static-bash))
175 (patches
176 (cons (search-patch "bash-reproducible-linux-pgrp-pipe.patch")
177 (origin-patches (package-source static-bash))))))))
178
179 (define %static-inputs
180 ;; Packages that are to be used as %BOOTSTRAP-INPUTS.
181 (let ((coreutils (package (inherit coreutils)
182 (arguments
183 `(#:configure-flags
184 '("--disable-nls"
185 "--disable-silent-rules"
186 "--enable-no-install-program=stdbuf,libstdbuf.so"
187 "CFLAGS=-Os -g0" ; smaller, please
188 "LDFLAGS=-static -pthread"
189
190 ;; Work around a cross-compilation bug whereby libcoreutils.a
191 ;; would provide '__mktime_internal', which conflicts with the
192 ;; one in libc.a.
193 ,@(if (%current-target-system)
194 `("gl_cv_func_working_mktime=yes")
195 '()))
196
197 #:tests? #f ; signal-related Gnulib tests fail
198 ,@(package-arguments coreutils)))
199
200 ;; Remove optional dependencies such as GMP. Keep Perl
201 ;; except if it's missing (which is the case when
202 ;; cross-compiling).
203 (inputs (match (assoc "perl" (package-inputs coreutils))
204 (#f '())
205 (x (list x))))
206
207 ;; Remove the 'debug' output (see above for the reason.)
208 (outputs '("out"))))
209 (bzip2 (package (inherit bzip2)
210 (arguments
211 (substitute-keyword-arguments (package-arguments bzip2)
212 ((#:phases phases)
213 `(modify-phases ,phases
214 (add-before 'build 'dash-static
215 (lambda _
216 (substitute* "Makefile"
217 (("^LDFLAGS[[:blank:]]*=.*$")
218 "LDFLAGS = -static"))
219 #t))))))))
220 (xz (package (inherit xz)
221 (outputs '("out"))
222 (arguments
223 `(#:strip-flags '("--strip-all")
224 #:phases (modify-phases %standard-phases
225 (add-before 'configure 'static-executable
226 (lambda _
227 ;; Ask Libtool for a static executable.
228 (substitute* "src/xz/Makefile.in"
229 (("^xz_LDADD =")
230 "xz_LDADD = -all-static"))
231 #t)))))))
232 (gawk (package (inherit gawk)
233 (source (origin (inherit (package-source gawk))
234 (patches (cons (search-patch "gawk-shell.patch")
235 (origin-patches
236 (package-source gawk))))))
237 (arguments
238 `(;; Starting from gawk 4.1.0, some of the tests for the
239 ;; plug-in mechanism just fail on static builds:
240 ;;
241 ;; ./fts.awk:1: error: can't open shared library `filefuncs' for reading (No such file or directory)
242 #:tests? #f
243
244 ,@(substitute-keyword-arguments (package-arguments gawk)
245 ((#:phases phases)
246 `(modify-phases ,phases
247 (add-before 'configure 'no-export-dynamic
248 (lambda _
249 ;; Since we use `-static', remove
250 ;; `-export-dynamic'.
251 (substitute* "configure"
252 (("-Wl,-export-dynamic") ""))
253 #t)))))))
254 (inputs (if (%current-target-system)
255 `(("bash" ,static-bash-for-bootstrap))
256 '()))))
257 (tar (package (inherit tar)
258 (arguments
259 `(;; Work around a cross-compilation bug whereby libgnu.a would provide
260 ;; '__mktime_internal', which conflicts with the one in libc.a.
261 ,@(if (%current-target-system)
262 `(#:configure-flags '("gl_cv_func_working_mktime=yes"))
263 '())
264 ,@(substitute-keyword-arguments (package-arguments tar)
265 ((#:phases phases)
266 `(modify-phases ,phases
267 (replace 'set-shell-file-name
268 (lambda _
269 ;; Do not use "/bin/sh" to run programs; see
270 ;; <http://lists.gnu.org/archive/html/guix-devel/2016-09/msg02272.html>.
271 (substitute* "src/system.c"
272 (("/bin/sh") "sh")
273 (("execv ") "execvp "))
274 #t)))))))))
275 ;; We don't want to retain a reference to /gnu/store in the bootstrap
276 ;; versions of egrep/fgrep, so we remove the custom phase added since
277 ;; grep@2.25. The effect is 'egrep' and 'fgrep' look for 'grep' in
278 ;; $PATH.
279 (grep (package
280 (inherit grep)
281 (inputs '()) ;remove PCRE, which is optional
282 (arguments
283 (substitute-keyword-arguments (package-arguments grep)
284 ((#:phases phases)
285 `(modify-phases ,phases
286 (delete 'fix-egrep-and-fgrep)))))))
287 (finalize (compose static-package
288 package-with-relocatable-glibc)))
289 `(,@(map (match-lambda
290 ((name package)
291 (list name (finalize package))))
292 `(("tar" ,tar)
293 ("gzip" ,gzip)
294 ("bzip2" ,bzip2)
295 ("xz" ,xz)
296 ("patch" ,patch)
297 ("coreutils" ,coreutils)
298 ("sed" ,sed)
299 ("grep" ,grep)
300 ("gawk" ,gawk)))
301 ("bash" ,static-bash-for-bootstrap))))
302
303 (define %static-binaries
304 (package
305 (name "static-binaries")
306 (version "0")
307 (build-system trivial-build-system)
308 (source #f)
309 (inputs %static-inputs)
310 (arguments
311 `(#:modules ((guix build utils))
312 #:builder
313 (begin
314 (use-modules (ice-9 ftw)
315 (ice-9 match)
316 (srfi srfi-1)
317 (srfi srfi-26)
318 (guix build utils))
319
320 (let ()
321 (define (directory-contents dir)
322 (map (cut string-append dir "/" <>)
323 (scandir dir (negate (cut member <> '("." ".."))))))
324
325 (define (copy-directory source destination)
326 (for-each (lambda (file)
327 (format #t "copying ~s...~%" file)
328 (copy-file file
329 (string-append destination "/"
330 (basename file))))
331 (directory-contents source)))
332
333 (let* ((out (assoc-ref %outputs "out"))
334 (bin (string-append out "/bin")))
335 (mkdir-p bin)
336
337 ;; Copy Coreutils binaries.
338 (let* ((coreutils (assoc-ref %build-inputs "coreutils"))
339 (source (string-append coreutils "/bin")))
340 (copy-directory source bin))
341
342 ;; For the other inputs, copy just one binary, which has the
343 ;; same name as the input.
344 (for-each (match-lambda
345 ((name . dir)
346 (let ((source (string-append dir "/bin/" name)))
347 (format #t "copying ~s...~%" source)
348 (copy-file source
349 (string-append bin "/" name)))))
350 (alist-delete "coreutils" %build-inputs))
351
352 ;; But of course, there are exceptions to this rule.
353 (let ((grep (assoc-ref %build-inputs "grep")))
354 (install-file (string-append grep "/bin/fgrep") bin)
355 (install-file (string-append grep "/bin/egrep") bin))
356
357 ;; Clear references to the store path.
358 (for-each remove-store-references
359 (directory-contents bin))
360
361 (with-directory-excursion bin
362 ;; Programs such as Perl's build system want these aliases.
363 (symlink "bash" "sh")
364 (symlink "gawk" "awk"))
365
366 #t)))))
367 (synopsis "Statically-linked bootstrap binaries")
368 (description
369 "Binaries used to bootstrap the distribution.")
370 (license gpl3+)
371 (home-page #f)))
372
373 (define %linux-libre-headers-stripped
374 ;; The subset of Linux-Libre-Headers that we need.
375 (package (inherit linux-libre-headers)
376 (name (string-append (package-name linux-libre-headers) "-stripped"))
377 (build-system trivial-build-system)
378 (outputs '("out"))
379 (arguments
380 `(#:modules ((guix build utils)
381 (guix build make-bootstrap))
382 #:builder
383 (begin
384 (use-modules (guix build utils)
385 (guix build make-bootstrap))
386
387 (let* ((in (assoc-ref %build-inputs "linux-libre-headers"))
388 (out (assoc-ref %outputs "out")))
389 (copy-linux-headers out in)
390 #t))))
391 (inputs `(("linux-libre-headers" ,linux-libre-headers)))))
392
393 (define %binutils-static
394 ;; Statically-linked Binutils.
395 (package (inherit binutils)
396 (name "binutils-static")
397 (arguments
398 `(#:configure-flags (cons "--disable-gold"
399 ,(match (memq #:configure-flags
400 (package-arguments binutils))
401 ((#:configure-flags flags _ ...)
402 flags)))
403 #:strip-flags '("--strip-all")
404 #:phases (modify-phases %standard-phases
405 (add-before 'configure 'all-static
406 (lambda _
407 ;; The `-all-static' libtool flag can only be passed
408 ;; after `configure', since configure tests don't use
409 ;; libtool, and only for executables built with libtool.
410 (substitute* '("binutils/Makefile.in"
411 "gas/Makefile.in"
412 "ld/Makefile.in")
413 (("^LDFLAGS =(.*)$" line)
414 (string-append line
415 "\nAM_LDFLAGS = -static -all-static\n")))
416 #t)))))))
417
418 (define %binutils-static-stripped
419 ;; The subset of Binutils that we need.
420 (package (inherit %binutils-static)
421 (name (string-append (package-name %binutils-static) "-stripped"))
422 (build-system trivial-build-system)
423 (outputs '("out"))
424 (arguments
425 `(#:modules ((guix build utils))
426 #:builder
427 (begin
428 (use-modules (guix build utils))
429
430 (setvbuf (current-output-port) _IOLBF)
431 (let* ((in (assoc-ref %build-inputs "binutils"))
432 (out (assoc-ref %outputs "out"))
433 (bin (string-append out "/bin")))
434 (mkdir-p bin)
435 (for-each (lambda (file)
436 (let ((target (string-append bin "/" file)))
437 (format #t "copying `~a'...~%" file)
438 (copy-file (string-append in "/bin/" file)
439 target)
440 (remove-store-references target)))
441 '("ar" "as" "ld" "nm" "objcopy" "objdump"
442 "ranlib" "readelf" "size" "strings" "strip"))
443 #t))))
444 (inputs `(("binutils" ,%binutils-static)))))
445
446 (define (%glibc-stripped)
447 ;; GNU libc's essential shared libraries, dynamic linker, and headers,
448 ;; with all references to store directories stripped. As a result,
449 ;; libc.so is unusable and need to be patched for proper relocation.
450 (let ((glibc (glibc-for-bootstrap glibc)))
451 (package (inherit glibc)
452 (name "glibc-stripped")
453 (build-system trivial-build-system)
454 (arguments
455 `(#:modules ((guix build utils)
456 (guix build make-bootstrap))
457 #:builder
458 (begin
459 (use-modules (guix build make-bootstrap))
460 (make-stripped-libc (assoc-ref %outputs "out")
461 (assoc-ref %build-inputs "libc")
462 (assoc-ref %build-inputs "kernel-headers")))))
463 (inputs `(("kernel-headers"
464 ,(if (or (and (%current-target-system)
465 (hurd-triplet? (%current-target-system)))
466 (string-suffix? "-hurd" (%current-system)))
467 gnumach-headers
468 linux-libre-headers))
469 ("libc" ,(let ((target (%current-target-system)))
470 (if target
471 (glibc-for-bootstrap
472 (parameterize ((%current-target-system #f))
473 (cross-libc target)))
474 glibc)))))
475 (native-inputs '())
476 (propagated-inputs '())
477
478 ;; Only one output.
479 (outputs '("out")))))
480
481 (define %gcc-static
482 ;; A statically-linked GCC, with stripped-down functionality.
483 (package-with-relocatable-glibc
484 (package (inherit gcc)
485 (name "gcc-static")
486 (outputs '("out")) ; all in one
487 (arguments
488 `(#:modules ((guix build utils)
489 (guix build gnu-build-system)
490 (srfi srfi-1)
491 (srfi srfi-26)
492 (ice-9 regex))
493 ,@(substitute-keyword-arguments (package-arguments gcc)
494 ((#:guile _) #f)
495 ((#:implicit-inputs? _) #t)
496 ((#:configure-flags flags)
497 `(append (list
498 ;; We don't need a full bootstrap here.
499 "--disable-bootstrap"
500
501 ;; Make sure '-static' is passed where it matters.
502 "--with-stage1-ldflags=-static"
503
504 ;; GCC 4.8+ requires a C++ compiler and library.
505 "--enable-languages=c,c++"
506
507 ;; Make sure gcc-nm doesn't require liblto_plugin.so.
508 "--disable-lto"
509
510 "--disable-shared"
511 "--disable-plugin"
512 "--disable-libmudflap"
513 "--disable-libatomic"
514 "--disable-libsanitizer"
515 "--disable-libitm"
516 "--disable-libgomp"
517 "--disable-libcilkrts"
518 "--disable-libvtv"
519 "--disable-libssp"
520 "--disable-libquadmath")
521 (remove (cut string-match "--(.*plugin|enable-languages)" <>)
522 ,flags)))
523 ((#:phases phases)
524 `(modify-phases ,phases
525 (add-after 'pre-configure 'remove-lgcc_s
526 (lambda _
527 ;; Remove the '-lgcc_s' added to GNU_USER_TARGET_LIB_SPEC in
528 ;; the 'pre-configure phase of our main gcc package, because
529 ;; that shared library is not present in this static gcc. See
530 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-01/msg00008.html>.
531 (substitute* (cons "gcc/config/rs6000/sysv4.h"
532 (find-files "gcc/config"
533 "^gnu-user.*\\.h$"))
534 ((" -lgcc_s}}") "}}"))
535 #t)))))))
536 (inputs
537 `(("zlib:static" ,zlib "static")
538 ,@(package-inputs gcc)))
539 (native-inputs
540 (if (%current-target-system)
541 `(;; When doing a Canadian cross, we need GMP/MPFR/MPC both
542 ;; as target inputs and as native inputs; the latter is
543 ;; needed when building build-time tools ('genconstants',
544 ;; etc.) Failing to do that leads to misdetections of
545 ;; declarations by 'gcc/configure', and eventually to
546 ;; duplicate declarations as reported in
547 ;; <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>.
548 ("gmp-native" ,gmp)
549 ("mpfr-native" ,mpfr)
550 ("mpc-native" ,mpc)
551 ,@(package-native-inputs gcc))
552 (package-native-inputs gcc))))))
553
554 (define %gcc-stripped
555 ;; The subset of GCC files needed for bootstrap.
556 (package (inherit gcc)
557 (name "gcc-stripped")
558 (build-system trivial-build-system)
559 (source #f)
560 (outputs '("out")) ;only one output
561 (arguments
562 `(#:modules ((guix build utils))
563 #:builder
564 (begin
565 (use-modules (srfi srfi-1)
566 (srfi srfi-26)
567 (guix build utils))
568
569 (setvbuf (current-output-port) _IOLBF)
570 (let* ((out (assoc-ref %outputs "out"))
571 (bindir (string-append out "/bin"))
572 (libdir (string-append out "/lib"))
573 (includedir (string-append out "/include"))
574 (libexecdir (string-append out "/libexec"))
575 (gcc (assoc-ref %build-inputs "gcc")))
576 (copy-recursively (string-append gcc "/bin") bindir)
577 (for-each remove-store-references
578 (find-files bindir ".*"))
579
580 (copy-recursively (string-append gcc "/lib") libdir)
581 (for-each remove-store-references
582 (remove (cut string-suffix? ".h" <>)
583 (find-files libdir ".*")))
584
585 (copy-recursively (string-append gcc "/libexec")
586 libexecdir)
587 (for-each remove-store-references
588 (find-files libexecdir ".*"))
589
590 ;; Starting from GCC 4.8, helper programs built natively
591 ;; (‘genchecksum’, ‘gcc-nm’, etc.) rely on C++ headers.
592 (copy-recursively (string-append gcc "/include/c++")
593 (string-append includedir "/c++"))
594
595 ;; For native builds, check whether the binaries actually work.
596 ,@(if (%current-target-system)
597 '()
598 '((for-each (lambda (prog)
599 (invoke (string-append gcc "/bin/" prog)
600 "--version"))
601 '("gcc" "g++" "cpp"))))
602
603 #t))))
604 (inputs `(("gcc" ,%gcc-static)))))
605
606 ;; Two packages: first build static, bare minimum content.
607 (define %mescc-tools-static
608 ;; A statically linked MesCC Tools.
609 (package
610 (inherit mescc-tools-0.5.2)
611 (name "mescc-tools-static")
612 (arguments
613 `(#:system "i686-linux"
614 ,@(substitute-keyword-arguments (package-arguments mescc-tools)
615 ((#:make-flags flags)
616 `(cons "CC=gcc -static" ,flags)))))))
617
618 ;; ... next remove store references.
619 (define %mescc-tools-static-stripped
620 ;; A statically linked Mescc Tools with store references removed, for
621 ;; bootstrap.
622 (package
623 (inherit %mescc-tools-static)
624 (name (string-append (package-name %mescc-tools-static) "-stripped"))
625 (build-system trivial-build-system)
626 (arguments
627 `(#:modules ((guix build utils))
628 #:builder
629 (begin
630 (use-modules (guix build utils))
631 (let* ((in (assoc-ref %build-inputs "mescc-tools"))
632 (out (assoc-ref %outputs "out"))
633 (bin (string-append out "/bin")))
634 (mkdir-p bin)
635 (for-each (lambda (file)
636 (let ((target (string-append bin "/" file)))
637 (format #t "copying `~a'...~%" file)
638 (copy-file (string-append in "/bin/" file)
639 target)
640 (remove-store-references target)))
641 '( "M1" "blood-elf" "hex2"))
642 #t))))
643 (inputs `(("mescc-tools" ,%mescc-tools-static)))))
644
645 ;; Two packages: first build static, bare minimum content.
646 (define-public %mes-minimal
647 ;; A minimal Mes without documentation.
648 (let ((triplet "i686-unknown-linux-gnu"))
649 (package
650 (inherit mes-0.19)
651 (name "mes-minimal")
652 (native-inputs
653 `(("guile" ,guile-2.2)))
654 (arguments
655 `(#:system "i686-linux"
656 #:strip-binaries? #f
657 #:configure-flags '("--mes")
658 #:phases
659 (modify-phases %standard-phases
660 (delete 'patch-shebangs)
661 (add-after 'install 'strip-install
662 (lambda _
663 (let* ((out (assoc-ref %outputs "out"))
664 (share (string-append out "/share")))
665 (delete-file-recursively (string-append out "/lib/guile"))
666 (delete-file-recursively (string-append share "/guile"))
667 (delete-file-recursively (string-append share "/mes/scaffold"))
668
669 (for-each delete-file
670 (find-files
671 (string-append share "/mes/lib")
672 "\\.(h|c)")))))))))))
673
674 ;; next remove store references.
675 (define %mes-minimal-stripped
676 ;; A minimal Mes with store references removed, for bootstrap.
677 (package
678 (inherit %mes-minimal)
679 (name (string-append (package-name %mes-minimal) "-stripped"))
680 (build-system trivial-build-system)
681 (arguments
682 `(#:modules ((guix build utils))
683 #:builder
684 (begin
685 (use-modules (guix build utils))
686 (let ((in (assoc-ref %build-inputs "mes"))
687 (out (assoc-ref %outputs "out")))
688
689 (copy-recursively in out)
690 (for-each (lambda (dir)
691 (for-each remove-store-references
692 (find-files (string-append out "/" dir)
693 ".*")))
694 '("bin" "share/mes"))
695 #t))))
696 (inputs `(("mes" ,%mes-minimal)))))
697
698 (define %guile-static
699 ;; A statically-linked Guile that is relocatable--i.e., it can search
700 ;; .scm and .go files relative to its installation directory, rather
701 ;; than in hard-coded configure-time paths.
702 (let* ((patches (cons* (search-patch "guile-relocatable.patch")
703 (search-patch "guile-2.2-default-utf8.patch")
704 (search-patch "guile-linux-syscalls.patch")
705 (origin-patches (package-source guile-2.2))))
706 (source (origin (inherit (package-source guile-2.2))
707 (patches patches)))
708 (guile (package (inherit guile-2.2)
709 (name (string-append (package-name guile-2.2) "-static"))
710 (source source)
711 (synopsis "Statically-linked and relocatable Guile")
712
713 ;; Remove the 'debug' output (see above for the reason.)
714 (outputs (delete "debug" (package-outputs guile-2.2)))
715
716 (inputs
717 `(("libunistring:static" ,libunistring "static")
718 ,@(package-inputs guile-2.2)))
719
720 (propagated-inputs
721 `(("bdw-gc" ,libgc)
722 ,@(alist-delete "bdw-gc"
723 (package-propagated-inputs guile-2.2))))
724 (arguments
725 (substitute-keyword-arguments (package-arguments guile-2.2)
726 ((#:configure-flags flags '())
727 ;; When `configure' checks for ltdl availability, it
728 ;; doesn't try to link using libtool, and thus fails
729 ;; because of a missing -ldl. Work around that.
730 ''("LDFLAGS=-ldl"))
731 ((#:phases phases '%standard-phases)
732 `(modify-phases ,phases
733
734 ;; Do not record the absolute file name of 'sh' in
735 ;; (ice-9 popen). This makes 'open-pipe' unusable in
736 ;; a build chroot ('open-pipe*' is fine) but avoids
737 ;; keeping a reference to Bash.
738 (delete 'pre-configure)
739
740 (add-before 'configure 'static-guile
741 (lambda _
742 (substitute* "libguile/Makefile.in"
743 ;; Create a statically-linked `guile'
744 ;; executable.
745 (("^guile_LDFLAGS =")
746 "guile_LDFLAGS = -all-static")
747
748 ;; Add `-ldl' *after* libguile-2.2.la.
749 (("^guile_LDADD =(.*)$" _ ldadd)
750 (string-append "guile_LDADD = "
751 (string-trim-right ldadd)
752 " -ldl\n")))))))
753 ((#:tests? _ #f)
754 ;; There are uses of `dynamic-link' in
755 ;; {foreign,coverage}.test that don't fly here.
756 #f)
757 ((#:parallel-build? _ #f)
758 ;; Work around the fact that the Guile build system is
759 ;; not deterministic when parallel-build is enabled.
760 #f))))))
761 (package-with-relocatable-glibc (static-package guile))))
762
763 (define %guile-static-stripped
764 ;; A stripped static Guile binary, for use during bootstrap.
765 (package (inherit %guile-static)
766 (name "guile-static-stripped")
767 (build-system trivial-build-system)
768 (arguments
769 ;; The end result should depend on nothing but itself.
770 `(#:allowed-references ("out")
771 #:modules ((guix build utils))
772 #:builder
773 (let ()
774 (use-modules (guix build utils))
775
776 (let* ((in (assoc-ref %build-inputs "guile"))
777 (out (assoc-ref %outputs "out"))
778 (guile1 (string-append in "/bin/guile"))
779 (guile2 (string-append out "/bin/guile")))
780 (mkdir-p (string-append out "/share/guile/2.2"))
781 (copy-recursively (string-append in "/share/guile/2.2")
782 (string-append out "/share/guile/2.2"))
783
784 (mkdir-p (string-append out "/lib/guile/2.2/ccache"))
785 (copy-recursively (string-append in "/lib/guile/2.2/ccache")
786 (string-append out "/lib/guile/2.2/ccache"))
787
788 (mkdir (string-append out "/bin"))
789 (copy-file guile1 guile2)
790
791 ;; Verify that the relocated Guile works.
792 ,@(if (%current-target-system)
793 '()
794 '((invoke guile2 "--version")))
795
796 ;; Strip store references.
797 (remove-store-references guile2)
798
799 ;; Verify that the stripped Guile works. If it aborts, it could be
800 ;; that it tries to open iconv descriptors and fails because libc's
801 ;; iconv data isn't available (see `guile-default-utf8.patch'.)
802 ,@(if (%current-target-system)
803 '()
804 '((invoke guile2 "--version")))
805
806 #t))))
807 (inputs `(("guile" ,%guile-static)))
808 (outputs '("out"))
809 (synopsis "Minimal statically-linked and relocatable Guile")))
810
811 (define (tarball-package pkg)
812 "Return a package containing a tarball of PKG."
813 (package (inherit pkg)
814 (name (string-append (package-name pkg) "-tarball"))
815 (build-system trivial-build-system)
816 (native-inputs `(("tar" ,tar)
817 ("xz" ,xz)))
818 (inputs `(("input" ,pkg)))
819 (arguments
820 (let ((name (package-name pkg))
821 (version (package-version pkg)))
822 `(#:modules ((guix build utils))
823 #:builder
824 (begin
825 (use-modules (guix build utils))
826 (let ((out (assoc-ref %outputs "out"))
827 (input (assoc-ref %build-inputs "input"))
828 (tar (assoc-ref %build-inputs "tar"))
829 (xz (assoc-ref %build-inputs "xz")))
830 (mkdir out)
831 (set-path-environment-variable "PATH" '("bin") (list tar xz))
832 (with-directory-excursion input
833 (invoke "tar" "cJvf"
834 (string-append out "/"
835 ,name "-" ,version
836 "-"
837 ,(or (%current-target-system)
838 (%current-system))
839 ".tar.xz")
840 "."
841 ;; avoid non-determinism in the archive
842 "--sort=name" "--mtime=@0"
843 "--owner=root:0" "--group=root:0")))))))))
844
845 (define %bootstrap-binaries-tarball
846 ;; A tarball with the statically-linked bootstrap binaries.
847 (tarball-package %static-binaries))
848
849 (define %linux-libre-headers-bootstrap-tarball
850 ;; A tarball with the statically-linked Linux-Libre-Headers programs.
851 (tarball-package %linux-libre-headers-stripped))
852
853 (define %binutils-bootstrap-tarball
854 ;; A tarball with the statically-linked Binutils programs.
855 (tarball-package %binutils-static-stripped))
856
857 (define (%glibc-bootstrap-tarball)
858 ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers.
859 (tarball-package (%glibc-stripped)))
860
861 (define %gcc-bootstrap-tarball
862 ;; A tarball with a dynamic-linked GCC and its headers.
863 (tarball-package %gcc-stripped))
864
865 (define %guile-bootstrap-tarball
866 ;; A tarball with the statically-linked, relocatable Guile.
867 (tarball-package %guile-static-stripped))
868
869 (define %mescc-tools-bootstrap-tarball
870 ;; A tarball with statically-linked MesCC binary seed.
871 (tarball-package %mescc-tools-static-stripped))
872
873 (define %mes-bootstrap-tarball
874 ;; A tarball with Mes binary seed.
875 (tarball-package %mes-minimal-stripped))
876
877 (define %bootstrap-tarballs
878 ;; A single derivation containing all the bootstrap tarballs, for
879 ;; convenience.
880 (package
881 (name "bootstrap-tarballs")
882 (version "0")
883 (source #f)
884 (build-system trivial-build-system)
885 (arguments
886 `(#:modules ((guix build utils))
887 #:builder
888 (let ((out (assoc-ref %outputs "out")))
889 (use-modules (guix build utils)
890 (ice-9 match)
891 (srfi srfi-26))
892
893 (setvbuf (current-output-port) _IOLBF)
894 (mkdir out)
895 (chdir out)
896 (for-each (match-lambda
897 ((name . directory)
898 (for-each (lambda (file)
899 (format #t "~a -> ~a~%" file out)
900 (symlink file (basename file)))
901 (find-files directory "\\.tar\\."))))
902 %build-inputs)
903 #t)))
904 (inputs `(("guile-tarball" ,%guile-bootstrap-tarball)
905 ,@(match (or (%current-target-system) (%current-system))
906 ((or "i686-linux" "x86_64-linux")
907 `(("bootstrap-mescc-tools" ,%mescc-tools-bootstrap-tarball)
908 ("bootstrap-mes" ,%mes-bootstrap-tarball)
909 ("bootstrap-linux-libre-headers"
910 ,%linux-libre-headers-bootstrap-tarball)))
911 (_ `(("gcc-tarball" ,%gcc-bootstrap-tarball)
912 ("binutils-tarball" ,%binutils-bootstrap-tarball)
913 ("glibc-tarball" ,(%glibc-bootstrap-tarball)))))
914 ("coreutils&co-tarball" ,%bootstrap-binaries-tarball)))
915 (synopsis "Tarballs containing all the bootstrap binaries")
916 (description synopsis)
917 (home-page #f)
918 (license gpl3+)))
919
920 ;;; make-bootstrap.scm ends here