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