Commit | Line | Data |
---|---|---|
827d2891 | 1 | ;;; GNU Guix --- Functional package management for GNU |
2d546858 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org> |
1e5005e2 | 3 | ;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org> |
efc4eb14 | 4 | ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> |
2d558e31 | 5 | ;;; Copyright © 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com> |
273cab96 | 6 | ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr> |
b45a97ea | 7 | ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com> |
67dac6b8 | 8 | ;;; Copyright © 2019 Carl Dong <contact@carldong.me> |
827d2891 LC |
9 | ;;; |
10 | ;;; This file is part of GNU Guix. | |
11 | ;;; | |
12 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
13 | ;;; under the terms of the GNU General Public License as published by | |
14 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
15 | ;;; your option) any later version. | |
16 | ;;; | |
17 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
18 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;;; GNU General Public License for more details. | |
21 | ;;; | |
22 | ;;; You should have received a copy of the GNU General Public License | |
23 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
24 | ||
25 | (define-module (gnu packages cross-base) | |
827d2891 | 26 | #:use-module (gnu packages) |
f594028a | 27 | #:use-module (gnu packages gcc) |
827d2891 LC |
28 | #:use-module (gnu packages base) |
29 | #:use-module (gnu packages linux) | |
2d558e31 | 30 | #:use-module (gnu packages hurd) |
cba36e64 | 31 | #:use-module (gnu packages mingw) |
827d2891 LC |
32 | #:use-module (guix packages) |
33 | #:use-module (guix download) | |
34 | #:use-module (guix utils) | |
35 | #:use-module (guix build-system gnu) | |
36 | #:use-module (guix build-system trivial) | |
37 | #:use-module (srfi srfi-1) | |
38 | #:use-module (srfi srfi-26) | |
264218a4 | 39 | #:use-module (ice-9 match) |
2d558e31 | 40 | #:use-module (ice-9 regex) |
264218a4 LC |
41 | #:export (cross-binutils |
42 | cross-libc | |
cba36e64 | 43 | cross-gcc |
2ea77d48 CD |
44 | cross-newlib? |
45 | cross-kernel-headers)) | |
827d2891 | 46 | |
be99170d | 47 | (define-syntax %xgcc |
c92f1c0a LC |
48 | ;; GCC package used as the basis for cross-compilation. It doesn't have to |
49 | ;; be 'gcc' and can be a specific variant such as 'gcc-4.8'. | |
be99170d LC |
50 | ;; |
51 | ;; Note: This is a macro so that we do not refer to 'gcc' from the top | |
52 | ;; level, which would lead to circular-dependency issues. | |
53 | (identifier-syntax gcc)) | |
c92f1c0a | 54 | |
cba36e64 JN |
55 | (define %gcc-include-paths |
56 | ;; Environment variables for header search paths. | |
01e8263f MB |
57 | ;; Note: See <http://bugs.gnu.org/30756> for why not 'C_INCLUDE_PATH' & co. |
58 | '("CPATH")) | |
cba36e64 JN |
59 | |
60 | (define %gcc-cross-include-paths | |
61 | ;; Search path for target headers when cross-compiling. | |
62 | (map (cut string-append "CROSS_" <>) %gcc-include-paths)) | |
63 | ||
827d2891 LC |
64 | (define (cross p target) |
65 | (package (inherit p) | |
827d2891 LC |
66 | (name (string-append (package-name p) "-cross-" target)) |
67 | (arguments | |
68 | (substitute-keyword-arguments (package-arguments p) | |
69 | ((#:configure-flags flags) | |
70 | `(cons ,(string-append "--target=" target) | |
71 | ,flags)))))) | |
72 | ||
1306b0b0 LC |
73 | (define (package-with-patch original patch) |
74 | "Return package ORIGINAL with PATCH applied." | |
75 | (package (inherit original) | |
76 | (source (origin (inherit (package-source original)) | |
77 | (patches (list patch)))))) | |
78 | ||
47e74d6e LC |
79 | (define (cross-binutils target) |
80 | "Return a cross-Binutils for TARGET." | |
81 | (let ((binutils (package (inherit binutils) | |
82 | (arguments | |
83 | (substitute-keyword-arguments (package-arguments | |
84 | binutils) | |
85 | ((#:configure-flags flags) | |
86 | ;; Build with `--with-sysroot' so that ld honors | |
87 | ;; DT_RUNPATH entries when searching for a needed | |
88 | ;; library. This works because as a side effect | |
89 | ;; `genscripts.sh' sets `USE_LIBPATH=yes', which tells | |
90 | ;; elf32.em to use DT_RUNPATH in its search list. | |
c8fa51f2 LC |
91 | ;; See <http://sourceware.org/ml/binutils/2013-05/msg00312.html>. |
92 | ;; | |
93 | ;; In theory choosing / as the sysroot could lead ld | |
94 | ;; to pick up native libs instead of target ones. In | |
95 | ;; practice the RUNPATH of target libs only refers to | |
96 | ;; target libs, not native libs, so this is safe. | |
97 | `(cons "--with-sysroot=/" ,flags))))))) | |
1306b0b0 LC |
98 | |
99 | ;; For Xtensa, apply Qualcomm's patch. | |
100 | (cross (if (string-prefix? "xtensa-" target) | |
101 | (package-with-patch binutils | |
102 | (search-patch | |
103 | "ath9k-htc-firmware-binutils.patch")) | |
104 | binutils) | |
105 | target))) | |
827d2891 | 106 | |
7b3318e3 RW |
107 | (define (cross-gcc-arguments target xgcc libc) |
108 | "Return build system arguments for a cross-gcc for TARGET, using XGCC as the | |
109 | base compiler and using LIBC (which may be either a libc package or #f.)" | |
b4469d8c LC |
110 | ;; Set the current target system so that 'glibc-dynamic-linker' returns the |
111 | ;; right name. | |
112 | (parameterize ((%current-target-system target)) | |
2a1552c6 LC |
113 | ;; Disable stripping as this can break binaries, with object files of |
114 | ;; libgcc.a showing up as having an unknown architecture. See | |
115 | ;; <http://lists.fedoraproject.org/pipermail/arm/2010-August/000663.html> | |
116 | ;; for instance. | |
117 | (let ((args `(#:strip-binaries? #f | |
7b3318e3 | 118 | ,@(package-arguments xgcc)))) |
2a1552c6 LC |
119 | (substitute-keyword-arguments args |
120 | ((#:configure-flags flags) | |
121 | `(append (list ,(string-append "--target=" target) | |
122 | ,@(if libc | |
8fd857f5 | 123 | `( ;; Disable libcilkrts because it is not |
3009a9e4 | 124 | ;; ported to GNU/Hurd. |
871dbd6c MB |
125 | "--disable-libcilkrts" |
126 | ;; When building a cross compiler, --with-sysroot is | |
127 | ;; implicitly set to "$gcc_tooldir/sys-root". This does | |
128 | ;; not work for us, because --with-native-system-header-dir | |
129 | ;; is searched for relative to this location. Thus, we set | |
130 | ;; it to "/" so GCC is able to find the target libc headers. | |
131 | ;; This is safe because in practice GCC uses CROSS_CPATH | |
132 | ;; & co to separate target and host libraries. | |
133 | "--with-sysroot=/") | |
2a1552c6 LC |
134 | `( ;; Disable features not needed at this stage. |
135 | "--disable-shared" "--enable-static" | |
ca7ef4d4 | 136 | "--enable-languages=c,c++" |
cdb4b4b3 | 137 | |
ca7ef4d4 RW |
138 | ;; libstdc++ cannot be built at this stage |
139 | ;; ("Link tests are not allowed after | |
140 | ;; GCC_NO_EXECUTABLES."). | |
141 | "--disable-libstdc++-v3" | |
cdb4b4b3 | 142 | |
2a1552c6 LC |
143 | "--disable-threads" ;libgcc, would need libc |
144 | "--disable-libatomic" | |
145 | "--disable-libmudflap" | |
146 | "--disable-libgomp" | |
147 | "--disable-libssp" | |
148 | "--disable-libquadmath" | |
149 | "--disable-decimal-float" ;would need libc | |
8fd857f5 | 150 | "--disable-libcilkrts" |
9a745d76 MR |
151 | |
152 | ;; When target is any OS other than 'none' these | |
153 | ;; libraries will fail if there is no libc | |
154 | ;; present. See | |
155 | ;; <https://lists.gnu.org/archive/html/guix-devel/2016-02/msg01311.html> | |
156 | "--disable-libitm" | |
157 | "--disable-libvtv" | |
158 | "--disable-libsanitizer" | |
cba36e64 JN |
159 | )) |
160 | ||
161 | ;; For a newlib (non-glibc) target | |
162 | ,@(if (cross-newlib? target) | |
163 | '("--with-newlib") | |
164 | '())) | |
cdb4b4b3 | 165 | |
2a1552c6 LC |
166 | ,(if libc |
167 | flags | |
168 | `(remove (cut string-match "--enable-languages.*" <>) | |
169 | ,flags)))) | |
170 | ((#:make-flags flags) | |
171 | (if libc | |
172 | `(let ((libc (assoc-ref %build-inputs "libc"))) | |
173 | ;; FLAGS_FOR_TARGET are needed for the target libraries to receive | |
174 | ;; the -Bxxx for the startfiles. | |
175 | (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib") | |
176 | ,flags)) | |
177 | flags)) | |
178 | ((#:phases phases) | |
b45a97ea MB |
179 | `(cross-gcc-build-phases |
180 | ,target | |
181 | (modify-phases ,phases | |
182 | (add-before 'configure 'treat-glibc-as-system-header | |
183 | (lambda* (#:key inputs #:allow-other-keys) | |
184 | (let ((libc (assoc-ref inputs "libc"))) | |
185 | (when libc | |
186 | ;; For GCC6 and later, make sure Glibc is treated as a "system | |
187 | ;; header" such that #include_next does the right thing. | |
188 | (for-each (lambda (var) | |
189 | (setenv var (string-append libc "/include"))) | |
190 | '("CROSS_C_INCLUDE_PATH" "CROSS_CPLUS_INCLUDE_PATH"))) | |
191 | #t)))))))))) | |
cdb4b4b3 | 192 | |
1306b0b0 LC |
193 | (define (cross-gcc-patches target) |
194 | "Return GCC patches needed for TARGET." | |
195 | (cond ((string-prefix? "xtensa-" target) | |
196 | ;; Patch by Qualcomm needed to build the ath9k-htc firmware. | |
fc1adab1 | 197 | (search-patches "ath9k-htc-firmware-gcc.patch")) |
cba36e64 JN |
198 | ((target-mingw? target) |
199 | (search-patches "gcc-4.9.3-mingw-gthr-default.patch")) | |
1306b0b0 LC |
200 | (else '()))) |
201 | ||
cba36e64 JN |
202 | (define (cross-gcc-snippet target) |
203 | "Return GCC snippet needed for TARGET." | |
204 | (cond ((target-mingw? target) | |
6cbee49d MW |
205 | '(begin |
206 | (copy-recursively "libstdc++-v3/config/os/mingw32-w64" | |
207 | "libstdc++-v3/config/os/newlib") | |
208 | #t)) | |
cba36e64 JN |
209 | (else #f))) |
210 | ||
827d2891 | 211 | (define* (cross-gcc target |
7b3318e3 RW |
212 | #:key |
213 | (xgcc %xgcc) | |
214 | (xbinutils (cross-binutils target)) | |
215 | (libc #f)) | |
827d2891 | 216 | "Return a cross-compiler for TARGET, where TARGET is a GNU triplet. Use |
7b3318e3 RW |
217 | XGCC as the base compiler. Use XBINUTILS as the associated cross-Binutils. |
218 | If LIBC is false, then build a GCC that does not target a libc; otherwise, | |
219 | target that libc." | |
220 | (package (inherit xgcc) | |
827d2891 LC |
221 | (name (string-append "gcc-cross-" |
222 | (if libc "" "sans-libc-") | |
223 | target)) | |
7b3318e3 | 224 | (source (origin (inherit (package-source xgcc)) |
01eafd38 | 225 | (patches |
1421afa9 | 226 | (append |
7b3318e3 | 227 | (origin-patches (package-source xgcc)) |
83b0a7f4 CD |
228 | (cons (cond |
229 | ((version>=? (package-version xgcc) "8.0") (search-patch "gcc-8-cross-environment-variables.patch")) | |
230 | ((version>=? (package-version xgcc) "6.0") (search-patch "gcc-6-cross-environment-variables.patch")) | |
231 | (else (search-patch "gcc-cross-environment-variables.patch"))) | |
cba36e64 JN |
232 | (cross-gcc-patches target)))) |
233 | (modules '((guix build utils))) | |
234 | (snippet | |
235 | (cross-gcc-snippet target)))) | |
a49c57a7 LC |
236 | |
237 | ;; For simplicity, use a single output. Otherwise libgcc_s & co. are not | |
238 | ;; found by default, etc. | |
239 | (outputs '("out")) | |
240 | ||
827d2891 LC |
241 | (arguments |
242 | `(#:implicit-inputs? #f | |
3593e5d5 LC |
243 | #:imported-modules ((gnu build cross-toolchain) |
244 | ,@%gnu-build-system-modules) | |
827d2891 LC |
245 | #:modules ((guix build gnu-build-system) |
246 | (guix build utils) | |
3593e5d5 | 247 | (gnu build cross-toolchain) |
827d2891 | 248 | (srfi srfi-1) |
3593e5d5 LC |
249 | (srfi srfi-26) |
250 | (ice-9 regex)) | |
827d2891 | 251 | |
7b3318e3 | 252 | ,@(cross-gcc-arguments target xgcc libc))) |
0de71c23 LC |
253 | |
254 | (native-inputs | |
4a740d0f LC |
255 | `(("ld-wrapper-cross" ,(make-ld-wrapper |
256 | (string-append "ld-wrapper-" target) | |
5bde4503 | 257 | #:target (const target) |
4a740d0f LC |
258 | #:binutils xbinutils)) |
259 | ("binutils-cross" ,xbinutils) | |
827d2891 LC |
260 | |
261 | ;; Call it differently so that the builder can check whether the "libc" | |
262 | ;; input is #f. | |
fb77c614 | 263 | ("libc-native" ,@(assoc-ref (%final-inputs) "libc")) |
827d2891 LC |
264 | |
265 | ;; Remaining inputs. | |
7b3318e3 | 266 | ,@(let ((inputs (append (package-inputs xgcc) |
fb77c614 | 267 | (alist-delete "libc" (%final-inputs))))) |
cba36e64 JN |
268 | (cond |
269 | ((target-mingw? target) | |
270 | (if libc | |
67dac6b8 | 271 | `(("libc" ,libc) |
cba36e64 JN |
272 | ,@inputs) |
273 | `(("mingw-source" ,(package-source mingw-w64)) | |
274 | ,@inputs))) | |
275 | (libc | |
276 | `(("libc" ,libc) | |
6dff905e | 277 | ("libc:static" ,libc "static") |
cba36e64 JN |
278 | ("xkernel-headers" ;the target headers |
279 | ,@(assoc-ref (package-propagated-inputs libc) | |
280 | "kernel-headers")) | |
281 | ,@inputs)) | |
282 | (else inputs))))) | |
17bb886f | 283 | |
0de71c23 LC |
284 | (inputs '()) |
285 | ||
17bb886f | 286 | ;; Only search target inputs, not host inputs. |
cba36e64 JN |
287 | (search-paths (cons (search-path-specification |
288 | (variable "CROSS_LIBRARY_PATH") | |
289 | (files '("lib" "lib64"))) | |
290 | (map (lambda (variable) | |
291 | (search-path-specification | |
292 | (variable variable) | |
293 | (files '("include")))) | |
294 | %gcc-cross-include-paths))) | |
17bb886f | 295 | (native-search-paths '()))) |
827d2891 | 296 | |
2d558e31 MR |
297 | (define* (cross-kernel-headers target |
298 | #:optional | |
2ea77d48 | 299 | (linux-headers linux-libre-headers) |
2d558e31 MR |
300 | (xgcc (cross-gcc target)) |
301 | (xbinutils (cross-binutils target))) | |
302 | "Return headers depending on TARGET." | |
303 | ||
827d2891 | 304 | (define xlinux-headers |
2ea77d48 CD |
305 | (package (inherit linux-headers) |
306 | (name (string-append (package-name linux-headers) | |
827d2891 LC |
307 | "-cross-" target)) |
308 | (arguments | |
0d5a559f LC |
309 | (substitute-keyword-arguments |
310 | `(#:implicit-cross-inputs? #f | |
2ea77d48 | 311 | ,@(package-arguments linux-headers)) |
827d2891 LC |
312 | ((#:phases phases) |
313 | `(alist-replace | |
314 | 'build | |
315 | (lambda _ | |
316 | (setenv "ARCH" ,(system->linux-architecture target)) | |
317 | (format #t "`ARCH' set to `~a' (cross compiling)~%" (getenv "ARCH")) | |
318 | ||
1e5005e2 MW |
319 | (invoke "make" ,(system->defconfig target)) |
320 | (invoke "make" "mrproper" "headers_check")) | |
827d2891 | 321 | ,phases)))) |
0de71c23 LC |
322 | (native-inputs `(("cross-gcc" ,xgcc) |
323 | ("cross-binutils" ,xbinutils) | |
2ea77d48 | 324 | ,@(package-native-inputs linux-headers))))) |
827d2891 | 325 | |
2d558e31 MR |
326 | (define xgnumach-headers |
327 | (package (inherit gnumach-headers) | |
328 | (name (string-append (package-name gnumach-headers) | |
329 | "-cross-" target)) | |
330 | ||
331 | (native-inputs `(("cross-gcc" ,xgcc) | |
332 | ("cross-binutils" ,xbinutils) | |
333 | ,@(package-native-inputs gnumach-headers))))) | |
334 | ||
335 | (define xmig | |
336 | (package (inherit mig) | |
337 | (name (string-append "mig-cross")) | |
338 | (arguments | |
339 | `(#:modules ((guix build gnu-build-system) | |
340 | (guix build utils) | |
341 | (srfi srfi-26)) | |
273cab96 TGR |
342 | #:phases (modify-phases %standard-phases |
343 | (add-before 'configure 'set-cross-headers-path | |
344 | (lambda* (#:key inputs #:allow-other-keys) | |
345 | (let* ((mach (assoc-ref inputs "cross-gnumach-headers")) | |
346 | (cpath (string-append mach "/include"))) | |
347 | (for-each (cut setenv <> cpath) | |
348 | ',%gcc-cross-include-paths) | |
349 | #t)))) | |
2d558e31 MR |
350 | #:configure-flags (list ,(string-append "--target=" target)) |
351 | ,@(package-arguments mig))) | |
352 | ||
353 | (propagated-inputs `(("cross-gnumach-headers" ,xgnumach-headers))) | |
354 | (native-inputs `(("cross-gcc" ,xgcc) | |
355 | ("cross-binutils" ,xbinutils) | |
356 | ,@(package-native-inputs mig))))) | |
357 | ||
358 | (define xhurd-headers | |
359 | (package (inherit hurd-headers) | |
360 | (name (string-append (package-name hurd-headers) | |
361 | "-cross-" target)) | |
362 | ||
2d558e31 MR |
363 | (native-inputs `(("cross-gcc" ,xgcc) |
364 | ("cross-binutils" ,xbinutils) | |
365 | ("cross-mig" ,xmig) | |
366 | ,@(alist-delete "mig"(package-native-inputs hurd-headers)))))) | |
367 | ||
368 | (define xglibc/hurd-headers | |
369 | (package (inherit glibc/hurd-headers) | |
370 | (name (string-append (package-name glibc/hurd-headers) | |
371 | "-cross-" target)) | |
372 | ||
373 | (arguments | |
374 | (substitute-keyword-arguments | |
375 | `(#:modules ((guix build gnu-build-system) | |
376 | (guix build utils) | |
377 | (srfi srfi-26)) | |
378 | ,@(package-arguments glibc/hurd-headers)) | |
379 | ((#:phases phases) | |
273cab96 | 380 | `(modify-phases ,phases |
2d546858 | 381 | (add-after 'unpack 'set-cross-headers-path |
273cab96 TGR |
382 | (lambda* (#:key inputs #:allow-other-keys) |
383 | (let* ((mach (assoc-ref inputs "gnumach-headers")) | |
384 | (hurd (assoc-ref inputs "hurd-headers")) | |
385 | (cpath (string-append mach "/include:" | |
386 | hurd "/include"))) | |
387 | (for-each (cut setenv <> cpath) | |
388 | ',%gcc-cross-include-paths) | |
389 | #t))))))) | |
2d558e31 MR |
390 | |
391 | (propagated-inputs `(("gnumach-headers" ,xgnumach-headers) | |
392 | ("hurd-headers" ,xhurd-headers))) | |
393 | ||
394 | (native-inputs `(("cross-gcc" ,xgcc) | |
395 | ("cross-binutils" ,xbinutils) | |
396 | ("cross-mig" ,xmig) | |
397 | ,@(alist-delete "mig"(package-native-inputs glibc/hurd-headers)))))) | |
398 | ||
399 | (define xhurd-minimal | |
400 | (package (inherit hurd-minimal) | |
401 | (name (string-append (package-name hurd-minimal) | |
402 | "-cross-" target)) | |
403 | (arguments | |
404 | (substitute-keyword-arguments | |
405 | `(#:modules ((guix build gnu-build-system) | |
406 | (guix build utils) | |
407 | (srfi srfi-26)) | |
408 | ,@(package-arguments hurd-minimal)) | |
409 | ((#:phases phases) | |
273cab96 TGR |
410 | `(modify-phases ,phases |
411 | (add-before 'configure 'set-cross-headers-path | |
412 | (lambda* (#:key inputs #:allow-other-keys) | |
413 | (let* ((glibc-headers (assoc-ref inputs "cross-glibc-hurd-headers")) | |
414 | (cpath (string-append glibc-headers "/include"))) | |
415 | (for-each (cut setenv <> cpath) | |
416 | ',%gcc-cross-include-paths) | |
417 | #t))))))) | |
2d558e31 MR |
418 | |
419 | (inputs `(("cross-glibc-hurd-headers" ,xglibc/hurd-headers))) | |
420 | ||
421 | (native-inputs `(("cross-gcc" ,xgcc) | |
422 | ("cross-binutils" ,xbinutils) | |
423 | ("cross-mig" ,xmig) | |
424 | ,@(alist-delete "mig"(package-native-inputs hurd-minimal)))))) | |
425 | ||
426 | (define xhurd-core-headers | |
427 | (package (inherit hurd-core-headers) | |
428 | (name (string-append (package-name hurd-core-headers) | |
429 | "-cross-" target)) | |
430 | ||
431 | (inputs `(("gnumach-headers" ,xgnumach-headers) | |
432 | ("hurd-headers" ,xhurd-headers) | |
433 | ("hurd-minimal" ,xhurd-minimal))) | |
434 | ||
435 | (native-inputs `(("cross-gcc" ,xgcc) | |
436 | ("cross-binutils" ,xbinutils) | |
437 | ("cross-mig" ,xmig) | |
438 | ,@(package-native-inputs hurd-core-headers))))) | |
439 | ||
440 | (match target | |
441 | ((or "i586-pc-gnu" "i586-gnu") xhurd-core-headers) | |
442 | (_ xlinux-headers))) | |
443 | ||
444 | (define* (cross-libc target | |
445 | #:optional | |
102d3075 | 446 | (libc glibc) |
2d558e31 MR |
447 | (xgcc (cross-gcc target)) |
448 | (xbinutils (cross-binutils target)) | |
449 | (xheaders (cross-kernel-headers target))) | |
102d3075 CD |
450 | "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS |
451 | and the cross tool chain." | |
452 | (if (cross-newlib? target libc) | |
453 | (native-libc target libc) | |
454 | (let ((libc libc)) | |
cba36e64 JN |
455 | (package (inherit libc) |
456 | (name (string-append "glibc-cross-" target)) | |
457 | (arguments | |
458 | (substitute-keyword-arguments | |
459 | `(;; Disable stripping (see above.) | |
460 | #:strip-binaries? #f | |
461 | ||
462 | ;; This package is used as a target input, but it should not have | |
463 | ;; the usual cross-compilation inputs since that would include | |
464 | ;; itself. | |
465 | #:implicit-cross-inputs? #f | |
466 | ||
467 | ;; We need SRFI 26. | |
468 | #:modules ((guix build gnu-build-system) | |
469 | (guix build utils) | |
470 | (srfi srfi-26)) | |
471 | ||
472 | ,@(package-arguments libc)) | |
473 | ((#:configure-flags flags) | |
474 | `(cons ,(string-append "--host=" target) | |
2d546858 LC |
475 | ,(if (hurd-triplet? target) |
476 | `(cons "--disable-werror" ,flags) | |
477 | flags))) | |
cba36e64 | 478 | ((#:phases phases) |
273cab96 TGR |
479 | `(modify-phases ,phases |
480 | (add-before 'configure 'set-cross-kernel-headers-path | |
481 | (lambda* (#:key inputs #:allow-other-keys) | |
482 | (let* ((kernel (assoc-ref inputs "kernel-headers")) | |
483 | (cpath (string-append kernel "/include"))) | |
484 | (for-each (cut setenv <> cpath) | |
485 | ',%gcc-cross-include-paths) | |
486 | (setenv "CROSS_LIBRARY_PATH" | |
487 | (string-append kernel "/lib")) ; for Hurd's libihash | |
488 | #t))))))) | |
cba36e64 JN |
489 | |
490 | ;; Shadow the native "kernel-headers" because glibc's recipe expects the | |
491 | ;; "kernel-headers" input to point to the right thing. | |
492 | (propagated-inputs `(("kernel-headers" ,xheaders))) | |
493 | ||
494 | ;; FIXME: 'static-bash' should really be an input, not a native input, but | |
495 | ;; to do that will require building an intermediate cross libc. | |
496 | (inputs '()) | |
497 | ||
498 | (native-inputs `(("cross-gcc" ,xgcc) | |
499 | ("cross-binutils" ,xbinutils) | |
62596a15 | 500 | ,@(if (hurd-triplet? target) |
cba36e64 JN |
501 | `(("cross-mig" |
502 | ,@(assoc-ref (package-native-inputs xheaders) | |
ef582109 | 503 | "cross-mig"))) |
cba36e64 JN |
504 | '()) |
505 | ,@(package-inputs libc) ;FIXME: static-bash | |
506 | ,@(package-native-inputs libc))))))) | |
507 | ||
102d3075 CD |
508 | (define* (native-libc target |
509 | #:optional | |
510 | (libc glibc)) | |
cba36e64 | 511 | (if (target-mingw? target) |
67dac6b8 CD |
512 | (let ((machine (substring target 0 (string-index target #\-)))) |
513 | (make-mingw-w64 machine)) | |
102d3075 | 514 | libc)) |
cba36e64 | 515 | |
102d3075 CD |
516 | (define* (cross-newlib? target |
517 | #:optional | |
518 | (libc glibc)) | |
519 | (not (eq? (native-libc target libc) libc))) | |
827d2891 LC |
520 | |
521 | \f | |
bd2e1a8c LC |
522 | ;;; Concrete cross tool chains are instantiated like this: |
523 | ;; | |
524 | ;; (define-public xgcc-armhf | |
525 | ;; (let ((triplet "arm-linux-gnueabihf")) | |
827d2891 | 526 | ;; (cross-gcc triplet |
e0775d2a MW |
527 | ;; #:xbinutils (cross-binutils triplet) |
528 | ;; #:libc (cross-libc triplet)))) | |
bd2e1a8c LC |
529 | ;; |
530 | ;;; We don't do that here because we'd be referring to bindings from (gnu | |
531 | ;;; packages gcc) from the top level, which doesn't play well with circular | |
532 | ;;; dependencies among modules. |