Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
a273796c | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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> |
fe507d7a | 5 | ;;; Copyright © 2018, 2019 Mark H Weaver <mhw@netris.org> |
0481289c | 6 | ;;; Copyright © 2018, 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> |
e050aa19 | 7 | ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com> |
8ba60d7b | 8 | ;;; |
233e7676 | 9 | ;;; This file is part of GNU Guix. |
8ba60d7b | 10 | ;;; |
233e7676 | 11 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
8ba60d7b LC |
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 | ;;; | |
233e7676 | 16 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
8ba60d7b LC |
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 | |
233e7676 | 22 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
8ba60d7b | 23 | |
1ffa7090 | 24 | (define-module (gnu packages make-bootstrap) |
8ba60d7b LC |
25 | #:use-module (guix utils) |
26 | #:use-module (guix packages) | |
a273796c | 27 | #:use-module (guix memoization) |
3f35e0da | 28 | #:use-module ((guix licenses) #:select (gpl3+)) |
8ba60d7b | 29 | #:use-module (guix build-system trivial) |
4d058c67 | 30 | #:use-module (guix build-system gnu) |
59a43334 | 31 | #:use-module ((gnu packages) #:select (search-patch)) |
1ffa7090 | 32 | #:use-module (gnu packages base) |
a410a010 | 33 | #:use-module (gnu packages cross-base) |
1ffa7090 LC |
34 | #:use-module (gnu packages bash) |
35 | #:use-module (gnu packages compression) | |
36 | #:use-module (gnu packages gawk) | |
c415f145 | 37 | #:use-module (gnu packages gcc) |
1ffa7090 | 38 | #:use-module (gnu packages guile) |
e3b2cf4c | 39 | #:use-module (gnu packages bdw-gc) |
3f35e0da | 40 | #:use-module (gnu packages libunistring) |
1ffa7090 | 41 | #:use-module (gnu packages linux) |
f13f60cb | 42 | #:use-module (gnu packages hurd) |
35dcf851 | 43 | #:use-module (gnu packages mes) |
1ffa7090 | 44 | #:use-module (gnu packages multiprecision) |
8ba60d7b | 45 | #:use-module (ice-9 match) |
5d4fd267 | 46 | #:use-module (srfi srfi-1) |
8ba60d7b | 47 | #:export (%bootstrap-binaries-tarball |
990ee301 | 48 | %linux-libre-headers-bootstrap-tarball |
8ba60d7b LC |
49 | %binutils-bootstrap-tarball |
50 | %glibc-bootstrap-tarball | |
51 | %gcc-bootstrap-tarball | |
312543dc | 52 | %guile-bootstrap-tarball |
fae3c0d9 | 53 | %mescc-tools-bootstrap-tarball |
35dcf851 | 54 | %mes-bootstrap-tarball |
78214b4b LC |
55 | %bootstrap-tarballs |
56 | ||
57 | %guile-static-stripped)) | |
8ba60d7b LC |
58 | |
59 | ;;; Commentary: | |
60 | ;;; | |
3e8f16ba | 61 | ;;; This module provides tools to build tarballs of the "bootstrap binaries" |
1ffa7090 | 62 | ;;; used in (gnu packages bootstrap). These statically-linked binaries are |
8ba60d7b LC |
63 | ;;; taken for granted and used as the root of the whole bootstrap procedure. |
64 | ;;; | |
65 | ;;; Code: | |
66 | ||
a273796c LC |
67 | (define glibc-for-bootstrap |
68 | (mlambdaq (base) | |
69 | "Return a libc deriving from BASE whose `system' and `popen' functions looks | |
62751a5d | 70 | for `sh' in $PATH, and without nscd, and with static NSS modules." |
a273796c LC |
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)))))) | |
62751a5d | 90 | |
0c72a719 LC |
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 | ||
62751a5d LC |
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 | ||
929c365a LC |
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)))) | |
a410a010 LC |
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? | |
929c365a LC |
139 | `(("cross-libc" |
140 | ,(cross-bootstrap-libc (%current-target-system)))) | |
a410a010 LC |
141 | '())) |
142 | ||
143 | (define (native-inputs) | |
144 | (if (%current-target-system) | |
25a54eb0 MB |
145 | (let* ((target (%current-target-system)) |
146 | (xgcc (cross-gcc | |
147 | target | |
148 | #:xbinutils (cross-binutils target) | |
929c365a | 149 | #:libc (cross-bootstrap-libc target)))) |
25a54eb0 MB |
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))))) | |
a410a010 | 159 | ("cross-binutils" ,(cross-binutils target)) |
fb77c614 | 160 | ,@(%final-inputs))) |
a273796c LC |
161 | `(("libc" ,(glibc-for-bootstrap glibc)) |
162 | ("libc:static" ,(glibc-for-bootstrap glibc) "static") | |
0c72a719 | 163 | ("gcc" ,(gcc-for-bootstrap glibc)) |
fb77c614 | 164 | ,@(fold alist-delete (%final-inputs) '("libc" "gcc"))))) |
62751a5d LC |
165 | |
166 | (package-with-explicit-inputs p inputs | |
a410a010 LC |
167 | (current-source-location) |
168 | #:native-inputs native-inputs)) | |
5d4fd267 | 169 | |
fe507d7a MW |
170 | (define static-bash-for-bootstrap |
171 | (package | |
172 | (inherit static-bash) | |
173 | (source (origin | |
174 | (inherit (package-source static-bash)) | |
175 | (patches | |
737c83f0 | 176 | (cons (search-patch "bash-reproducible-linux-pgrp-pipe.patch") |
fe507d7a MW |
177 | (origin-patches (package-source static-bash)))))))) |
178 | ||
8ba60d7b LC |
179 | (define %static-inputs |
180 | ;; Packages that are to be used as %BOOTSTRAP-INPUTS. | |
181 | (let ((coreutils (package (inherit coreutils) | |
af5cb60f LC |
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 | |
7c836efa MB |
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 | ||
af5cb60f LC |
197 | #:tests? #f ; signal-related Gnulib tests fail |
198 | ,@(package-arguments coreutils))) | |
c2d771fd | 199 | |
af5cb60f LC |
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 '()) | |
e47185a4 LC |
205 | (x (list x)))) |
206 | ||
69f777d1 | 207 | ;; Remove the 'debug' output (see above for the reason.) |
e47185a4 | 208 | (outputs '("out")))) |
8ba60d7b LC |
209 | (bzip2 (package (inherit bzip2) |
210 | (arguments | |
211 | (substitute-keyword-arguments (package-arguments bzip2) | |
212 | ((#:phases phases) | |
edbce464 TGR |
213 | `(modify-phases ,phases |
214 | (add-before 'build 'dash-static | |
215 | (lambda _ | |
216 | (substitute* "Makefile" | |
217 | (("^LDFLAGS[[:blank:]]*=.*$") | |
218 | "LDFLAGS = -static")) | |
219 | #t)))))))) | |
8ba60d7b | 220 | (xz (package (inherit xz) |
5b2da2a6 | 221 | (outputs '("out")) |
8ba60d7b LC |
222 | (arguments |
223 | `(#:strip-flags '("--strip-all") | |
edbce464 TGR |
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))))))) | |
8ba60d7b | 232 | (gawk (package (inherit gawk) |
01eafd38 LC |
233 | (source (origin (inherit (package-source gawk)) |
234 | (patches (cons (search-patch "gawk-shell.patch") | |
235 | (origin-patches | |
236 | (package-source gawk)))))) | |
8ba60d7b | 237 | (arguments |
01eafd38 | 238 | `(;; Starting from gawk 4.1.0, some of the tests for the |
ffd20934 LC |
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 | ||
21c203a5 LC |
244 | ,@(substitute-keyword-arguments (package-arguments gawk) |
245 | ((#:phases phases) | |
edbce464 TGR |
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))))))) | |
01eafd38 | 254 | (inputs (if (%current-target-system) |
fe507d7a | 255 | `(("bash" ,static-bash-for-bootstrap)) |
01eafd38 | 256 | '())))) |
80c9164f CSLL |
257 | (tar (package (inherit tar) |
258 | (arguments | |
7c836efa MB |
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))))))))) | |
29d37e99 LC |
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))))))) | |
a410a010 LC |
287 | (finalize (compose static-package |
288 | package-with-relocatable-glibc))) | |
8ba60d7b LC |
289 | `(,@(map (match-lambda |
290 | ((name package) | |
5d4fd267 | 291 | (list name (finalize package)))) |
8ba60d7b LC |
292 | `(("tar" ,tar) |
293 | ("gzip" ,gzip) | |
294 | ("bzip2" ,bzip2) | |
295 | ("xz" ,xz) | |
296 | ("patch" ,patch) | |
297 | ("coreutils" ,coreutils) | |
298 | ("sed" ,sed) | |
29d37e99 | 299 | ("grep" ,grep) |
8ba60d7b | 300 | ("gawk" ,gawk))) |
fe507d7a | 301 | ("bash" ,static-bash-for-bootstrap)))) |
8ba60d7b LC |
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"))) | |
96c46210 LC |
354 | (install-file (string-append grep "/bin/fgrep") bin) |
355 | (install-file (string-append grep "/bin/egrep") bin)) | |
8ba60d7b LC |
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.") | |
90f2801e | 370 | (license gpl3+) |
8ba60d7b LC |
371 | (home-page #f))) |
372 | ||
990ee301 JN |
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 | ||
8ba60d7b LC |
393 | (define %binutils-static |
394 | ;; Statically-linked Binutils. | |
395 | (package (inherit binutils) | |
396 | (name "binutils-static") | |
397 | (arguments | |
57084853 LC |
398 | `(#:configure-flags (cons "--disable-gold" |
399 | ,(match (memq #:configure-flags | |
400 | (package-arguments binutils)) | |
401 | ((#:configure-flags flags _ ...) | |
402 | flags))) | |
8ba60d7b | 403 | #:strip-flags '("--strip-all") |
edbce464 TGR |
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))))))) | |
8ba60d7b LC |
417 | |
418 | (define %binutils-static-stripped | |
419 | ;; The subset of Binutils that we need. | |
420 | (package (inherit %binutils-static) | |
431f35f0 | 421 | (name (string-append (package-name %binutils-static) "-stripped")) |
8ba60d7b | 422 | (build-system trivial-build-system) |
431f35f0 | 423 | (outputs '("out")) |
8ba60d7b LC |
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 | ||
f13f60cb | 446 | (define (%glibc-stripped) |
8ba60d7b LC |
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. | |
a273796c | 450 | (let ((glibc (glibc-for-bootstrap glibc))) |
5d4fd267 LC |
451 | (package (inherit glibc) |
452 | (name "glibc-stripped") | |
453 | (build-system trivial-build-system) | |
454 | (arguments | |
f13f60cb MR |
455 | `(#:modules ((guix build utils) |
456 | (guix build make-bootstrap)) | |
5d4fd267 LC |
457 | #:builder |
458 | (begin | |
f13f60cb MR |
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))) | |
a410a010 LC |
470 | (if target |
471 | (glibc-for-bootstrap | |
472 | (parameterize ((%current-target-system #f)) | |
473 | (cross-libc target))) | |
f13f60cb | 474 | glibc))))) |
4dd1edc7 LC |
475 | (native-inputs '()) |
476 | (propagated-inputs '()) | |
867df0ee LC |
477 | |
478 | ;; Only one output. | |
479 | (outputs '("out"))))) | |
8ba60d7b LC |
480 | |
481 | (define %gcc-static | |
482 | ;; A statically-linked GCC, with stripped-down functionality. | |
62751a5d | 483 | (package-with-relocatable-glibc |
c92f1c0a | 484 | (package (inherit gcc) |
5d4fd267 | 485 | (name "gcc-static") |
84e6756c | 486 | (outputs '("out")) ; all in one |
5d4fd267 | 487 | (arguments |
21c203a5 LC |
488 | `(#:modules ((guix build utils) |
489 | (guix build gnu-build-system) | |
490 | (srfi srfi-1) | |
491 | (srfi srfi-26) | |
492 | (ice-9 regex)) | |
c92f1c0a | 493 | ,@(substitute-keyword-arguments (package-arguments gcc) |
21c203a5 LC |
494 | ((#:guile _) #f) |
495 | ((#:implicit-inputs? _) #t) | |
496 | ((#:configure-flags flags) | |
497 | `(append (list | |
288a09ca LC |
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 | ||
97b465fe LC |
504 | ;; GCC 4.8+ requires a C++ compiler and library. |
505 | "--enable-languages=c,c++" | |
506 | ||
c4873bc4 LC |
507 | ;; Make sure gcc-nm doesn't require liblto_plugin.so. |
508 | "--disable-lto" | |
509 | ||
21c203a5 LC |
510 | "--disable-shared" |
511 | "--disable-plugin" | |
21c203a5 | 512 | "--disable-libmudflap" |
953ab503 LC |
513 | "--disable-libatomic" |
514 | "--disable-libsanitizer" | |
515 | "--disable-libitm" | |
21c203a5 | 516 | "--disable-libgomp" |
8dca238b LC |
517 | "--disable-libcilkrts" |
518 | "--disable-libvtv" | |
21c203a5 | 519 | "--disable-libssp" |
70db9576 | 520 | "--disable-libquadmath") |
21c203a5 | 521 | (remove (cut string-match "--(.*plugin|enable-languages)" <>) |
270b501e MW |
522 | ,flags))) |
523 | ((#:phases phases) | |
edbce464 TGR |
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))))))) | |
3f35e0da MB |
536 | (inputs |
537 | `(("zlib:static" ,zlib "static") | |
538 | ,@(package-inputs gcc))) | |
0ece7074 LC |
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 | |
6fd52309 | 547 | ;; <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59217>. |
0ece7074 LC |
548 | ("gmp-native" ,gmp) |
549 | ("mpfr-native" ,mpfr) | |
550 | ("mpc-native" ,mpc) | |
c92f1c0a LC |
551 | ,@(package-native-inputs gcc)) |
552 | (package-native-inputs gcc)))))) | |
8ba60d7b LC |
553 | |
554 | (define %gcc-stripped | |
555 | ;; The subset of GCC files needed for bootstrap. | |
c92f1c0a | 556 | (package (inherit gcc) |
8ba60d7b LC |
557 | (name "gcc-stripped") |
558 | (build-system trivial-build-system) | |
559 | (source #f) | |
37550e67 | 560 | (outputs '("out")) ;only one output |
8ba60d7b LC |
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")) | |
55a5674f | 573 | (includedir (string-append out "/include")) |
8ba60d7b LC |
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 ".*")) | |
55a5674f LC |
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++")) | |
6e3ecad6 LC |
594 | |
595 | ;; For native builds, check whether the binaries actually work. | |
c2af3b07 MW |
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)))) | |
8ba60d7b LC |
604 | (inputs `(("gcc" ,%gcc-static))))) |
605 | ||
fb925c72 | 606 | ;; Two packages: first build static, bare minimum content. |
fae3c0d9 | 607 | (define %mescc-tools-static |
fb925c72 | 608 | ;; A statically linked MesCC Tools. |
fae3c0d9 | 609 | (package |
066cb9ba | 610 | (inherit mescc-tools-0.5.2) |
fae3c0d9 JN |
611 | (name "mescc-tools-static") |
612 | (arguments | |
da91723c JN |
613 | `(#:system "i686-linux" |
614 | ,@(substitute-keyword-arguments (package-arguments mescc-tools) | |
615 | ((#:make-flags flags) | |
616 | `(cons "CC=gcc -static" ,flags))))))) | |
fae3c0d9 | 617 | |
fb925c72 JN |
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))))) | |
ed050b1c | 644 | |
ed050b1c JN |
645 | ;; Two packages: first build static, bare minimum content. |
646 | (define-public %mes-minimal | |
647 | ;; A minimal Mes without documentation. | |
a647da36 JN |
648 | (let ((triplet "i686-unknown-linux-gnu")) |
649 | (package | |
bffd8fcd | 650 | (inherit mes-0.19) |
ed050b1c | 651 | (name "mes-minimal") |
a647da36 | 652 | (native-inputs |
da91723c | 653 | `(("guile" ,guile-2.2))) |
a647da36 | 654 | (arguments |
da91723c JN |
655 | `(#:system "i686-linux" |
656 | #:strip-binaries? #f | |
20dd94b8 | 657 | #:configure-flags '("--mes") |
a647da36 JN |
658 | #:phases |
659 | (modify-phases %standard-phases | |
ed050b1c | 660 | (delete 'patch-shebangs) |
20dd94b8 | 661 | (add-after 'install 'strip-install |
a647da36 | 662 | (lambda _ |
20dd94b8 JN |
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")) | |
ed050b1c JN |
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))))) | |
35dcf851 | 697 | |
8ba60d7b LC |
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. | |
dfb52abb | 702 | (let* ((patches (cons* (search-patch "guile-relocatable.patch") |
2acfe022 | 703 | (search-patch "guile-2.2-default-utf8.patch") |
dfb52abb | 704 | (search-patch "guile-linux-syscalls.patch") |
2acfe022 LC |
705 | (origin-patches (package-source guile-2.2)))) |
706 | (source (origin (inherit (package-source guile-2.2)) | |
dfb52abb | 707 | (patches patches))) |
2acfe022 LC |
708 | (guile (package (inherit guile-2.2) |
709 | (name (string-append (package-name guile-2.2) "-static")) | |
dfb52abb | 710 | (source source) |
75ca2f4f | 711 | (synopsis "Statically-linked and relocatable Guile") |
69f777d1 LC |
712 | |
713 | ;; Remove the 'debug' output (see above for the reason.) | |
2acfe022 | 714 | (outputs (delete "debug" (package-outputs guile-2.2))) |
69f777d1 | 715 | |
3f35e0da MB |
716 | (inputs |
717 | `(("libunistring:static" ,libunistring "static") | |
718 | ,@(package-inputs guile-2.2))) | |
719 | ||
a410a010 LC |
720 | (propagated-inputs |
721 | `(("bdw-gc" ,libgc) | |
722 | ,@(alist-delete "bdw-gc" | |
2acfe022 | 723 | (package-propagated-inputs guile-2.2)))) |
a410a010 | 724 | (arguments |
c99a64e1 LC |
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 | |
63e48300 LC |
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 | ||
c99a64e1 LC |
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. | |
9e6256ba MW |
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. | |
c99a64e1 | 760 | #f)))))) |
62751a5d | 761 | (package-with-relocatable-glibc (static-package guile)))) |
8ba60d7b LC |
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 | |
63e48300 LC |
769 | ;; The end result should depend on nothing but itself. |
770 | `(#:allowed-references ("out") | |
771 | #:modules ((guix build utils)) | |
8ba60d7b LC |
772 | #:builder |
773 | (let () | |
774 | (use-modules (guix build utils)) | |
775 | ||
3e8f16ba LC |
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"))) | |
2acfe022 LC |
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")) | |
8ba60d7b | 783 | |
2acfe022 LC |
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")) | |
8ba60d7b LC |
787 | |
788 | (mkdir (string-append out "/bin")) | |
3e8f16ba LC |
789 | (copy-file guile1 guile2) |
790 | ||
1a83e2a2 MW |
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)))) | |
3a4ebc11 | 807 | (inputs `(("guile" ,%guile-static))) |
75ca2f4f LC |
808 | (outputs '("out")) |
809 | (synopsis "Minimal statically-linked and relocatable Guile"))) | |
8ba60d7b LC |
810 | |
811 | (define (tarball-package pkg) | |
812 | "Return a package containing a tarball of PKG." | |
813 | (package (inherit pkg) | |
8ba60d7b LC |
814 | (name (string-append (package-name pkg) "-tarball")) |
815 | (build-system trivial-build-system) | |
a410a010 LC |
816 | (native-inputs `(("tar" ,tar) |
817 | ("xz" ,xz))) | |
818 | (inputs `(("input" ,pkg))) | |
8ba60d7b | 819 | (arguments |
21c203a5 LC |
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 | |
d1c86620 MW |
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"))))))))) | |
8ba60d7b LC |
844 | |
845 | (define %bootstrap-binaries-tarball | |
846 | ;; A tarball with the statically-linked bootstrap binaries. | |
847 | (tarball-package %static-binaries)) | |
848 | ||
990ee301 JN |
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 | ||
8ba60d7b LC |
853 | (define %binutils-bootstrap-tarball |
854 | ;; A tarball with the statically-linked Binutils programs. | |
855 | (tarball-package %binutils-static-stripped)) | |
856 | ||
f13f60cb | 857 | (define (%glibc-bootstrap-tarball) |
8ba60d7b | 858 | ;; A tarball with GNU libc's shared libraries, dynamic linker, and headers. |
f13f60cb | 859 | (tarball-package (%glibc-stripped))) |
8ba60d7b LC |
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 | ||
fae3c0d9 | 869 | (define %mescc-tools-bootstrap-tarball |
fb925c72 JN |
870 | ;; A tarball with statically-linked MesCC binary seed. |
871 | (tarball-package %mescc-tools-static-stripped)) | |
fae3c0d9 | 872 | |
35dcf851 | 873 | (define %mes-bootstrap-tarball |
ed050b1c | 874 | ;; A tarball with Mes binary seed. |
a647da36 | 875 | (tarball-package %mes-minimal-stripped)) |
35dcf851 | 876 | |
312543dc LC |
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) | |
f16a866f | 905 | ,@(match (or (%current-target-system) (%current-system)) |
d9ed0a46 JN |
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))) | |
d536c39e JN |
911 | (_ `(("gcc-tarball" ,%gcc-bootstrap-tarball) |
912 | ("binutils-tarball" ,%binutils-bootstrap-tarball) | |
913 | ("glibc-tarball" ,(%glibc-bootstrap-tarball))))) | |
312543dc | 914 | ("coreutils&co-tarball" ,%bootstrap-binaries-tarball))) |
7de1f103 LC |
915 | (synopsis "Tarballs containing all the bootstrap binaries") |
916 | (description synopsis) | |
312543dc LC |
917 | (home-page #f) |
918 | (license gpl3+))) | |
919 | ||
8ba60d7b | 920 | ;;; make-bootstrap.scm ends here |