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> |
308eb5c1 | 4 | ;;; Copyright © 2016, 2019 Jan (janneke) 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" | |
43124a54 | 147 | "--disable-libmpx" |
2a1552c6 LC |
148 | "--disable-libssp" |
149 | "--disable-libquadmath" | |
150 | "--disable-decimal-float" ;would need libc | |
8fd857f5 | 151 | "--disable-libcilkrts" |
9a745d76 MR |
152 | |
153 | ;; When target is any OS other than 'none' these | |
154 | ;; libraries will fail if there is no libc | |
155 | ;; present. See | |
156 | ;; <https://lists.gnu.org/archive/html/guix-devel/2016-02/msg01311.html> | |
157 | "--disable-libitm" | |
158 | "--disable-libvtv" | |
159 | "--disable-libsanitizer" | |
cba36e64 JN |
160 | )) |
161 | ||
162 | ;; For a newlib (non-glibc) target | |
163 | ,@(if (cross-newlib? target) | |
164 | '("--with-newlib") | |
165 | '())) | |
cdb4b4b3 | 166 | |
2a1552c6 LC |
167 | ,(if libc |
168 | flags | |
169 | `(remove (cut string-match "--enable-languages.*" <>) | |
170 | ,flags)))) | |
171 | ((#:make-flags flags) | |
172 | (if libc | |
173 | `(let ((libc (assoc-ref %build-inputs "libc"))) | |
174 | ;; FLAGS_FOR_TARGET are needed for the target libraries to receive | |
175 | ;; the -Bxxx for the startfiles. | |
176 | (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib") | |
177 | ,flags)) | |
178 | flags)) | |
179 | ((#:phases phases) | |
b45a97ea MB |
180 | `(cross-gcc-build-phases |
181 | ,target | |
182 | (modify-phases ,phases | |
183 | (add-before 'configure 'treat-glibc-as-system-header | |
184 | (lambda* (#:key inputs #:allow-other-keys) | |
185 | (let ((libc (assoc-ref inputs "libc"))) | |
186 | (when libc | |
187 | ;; For GCC6 and later, make sure Glibc is treated as a "system | |
188 | ;; header" such that #include_next does the right thing. | |
189 | (for-each (lambda (var) | |
190 | (setenv var (string-append libc "/include"))) | |
191 | '("CROSS_C_INCLUDE_PATH" "CROSS_CPLUS_INCLUDE_PATH"))) | |
192 | #t)))))))))) | |
cdb4b4b3 | 193 | |
308eb5c1 JN |
194 | (define (cross-gcc-patches xgcc target) |
195 | "Return GCC patches needed for XGCC and TARGET." | |
1306b0b0 LC |
196 | (cond ((string-prefix? "xtensa-" target) |
197 | ;; Patch by Qualcomm needed to build the ath9k-htc firmware. | |
fc1adab1 | 198 | (search-patches "ath9k-htc-firmware-gcc.patch")) |
cba36e64 | 199 | ((target-mingw? target) |
308eb5c1 JN |
200 | (append (search-patches "gcc-4.9.3-mingw-gthr-default.patch") |
201 | (if (version>=? (package-version xgcc) "7.0") | |
202 | (search-patches "gcc-7-cross-mingw.patch") | |
203 | '()))) | |
1306b0b0 LC |
204 | (else '()))) |
205 | ||
cba36e64 JN |
206 | (define (cross-gcc-snippet target) |
207 | "Return GCC snippet needed for TARGET." | |
208 | (cond ((target-mingw? target) | |
6cbee49d MW |
209 | '(begin |
210 | (copy-recursively "libstdc++-v3/config/os/mingw32-w64" | |
211 | "libstdc++-v3/config/os/newlib") | |
212 | #t)) | |
cba36e64 JN |
213 | (else #f))) |
214 | ||
827d2891 | 215 | (define* (cross-gcc target |
7b3318e3 RW |
216 | #:key |
217 | (xgcc %xgcc) | |
218 | (xbinutils (cross-binutils target)) | |
219 | (libc #f)) | |
827d2891 | 220 | "Return a cross-compiler for TARGET, where TARGET is a GNU triplet. Use |
7b3318e3 RW |
221 | XGCC as the base compiler. Use XBINUTILS as the associated cross-Binutils. |
222 | If LIBC is false, then build a GCC that does not target a libc; otherwise, | |
223 | target that libc." | |
224 | (package (inherit xgcc) | |
827d2891 LC |
225 | (name (string-append "gcc-cross-" |
226 | (if libc "" "sans-libc-") | |
227 | target)) | |
7b3318e3 | 228 | (source (origin (inherit (package-source xgcc)) |
01eafd38 | 229 | (patches |
1421afa9 | 230 | (append |
7b3318e3 | 231 | (origin-patches (package-source xgcc)) |
83b0a7f4 CD |
232 | (cons (cond |
233 | ((version>=? (package-version xgcc) "8.0") (search-patch "gcc-8-cross-environment-variables.patch")) | |
234 | ((version>=? (package-version xgcc) "6.0") (search-patch "gcc-6-cross-environment-variables.patch")) | |
235 | (else (search-patch "gcc-cross-environment-variables.patch"))) | |
308eb5c1 | 236 | (cross-gcc-patches xgcc target)))) |
cba36e64 JN |
237 | (modules '((guix build utils))) |
238 | (snippet | |
239 | (cross-gcc-snippet target)))) | |
a49c57a7 LC |
240 | |
241 | ;; For simplicity, use a single output. Otherwise libgcc_s & co. are not | |
242 | ;; found by default, etc. | |
243 | (outputs '("out")) | |
244 | ||
827d2891 LC |
245 | (arguments |
246 | `(#:implicit-inputs? #f | |
3593e5d5 LC |
247 | #:imported-modules ((gnu build cross-toolchain) |
248 | ,@%gnu-build-system-modules) | |
827d2891 LC |
249 | #:modules ((guix build gnu-build-system) |
250 | (guix build utils) | |
3593e5d5 | 251 | (gnu build cross-toolchain) |
827d2891 | 252 | (srfi srfi-1) |
3593e5d5 LC |
253 | (srfi srfi-26) |
254 | (ice-9 regex)) | |
827d2891 | 255 | |
7b3318e3 | 256 | ,@(cross-gcc-arguments target xgcc libc))) |
0de71c23 LC |
257 | |
258 | (native-inputs | |
4a740d0f LC |
259 | `(("ld-wrapper-cross" ,(make-ld-wrapper |
260 | (string-append "ld-wrapper-" target) | |
5bde4503 | 261 | #:target (const target) |
4a740d0f LC |
262 | #:binutils xbinutils)) |
263 | ("binutils-cross" ,xbinutils) | |
827d2891 LC |
264 | |
265 | ;; Call it differently so that the builder can check whether the "libc" | |
266 | ;; input is #f. | |
fb77c614 | 267 | ("libc-native" ,@(assoc-ref (%final-inputs) "libc")) |
827d2891 LC |
268 | |
269 | ;; Remaining inputs. | |
7b3318e3 | 270 | ,@(let ((inputs (append (package-inputs xgcc) |
fb77c614 | 271 | (alist-delete "libc" (%final-inputs))))) |
cba36e64 JN |
272 | (cond |
273 | ((target-mingw? target) | |
274 | (if libc | |
67dac6b8 | 275 | `(("libc" ,libc) |
cba36e64 JN |
276 | ,@inputs) |
277 | `(("mingw-source" ,(package-source mingw-w64)) | |
278 | ,@inputs))) | |
279 | (libc | |
280 | `(("libc" ,libc) | |
6dff905e | 281 | ("libc:static" ,libc "static") |
cba36e64 JN |
282 | ("xkernel-headers" ;the target headers |
283 | ,@(assoc-ref (package-propagated-inputs libc) | |
284 | "kernel-headers")) | |
285 | ,@inputs)) | |
286 | (else inputs))))) | |
17bb886f | 287 | |
0de71c23 LC |
288 | (inputs '()) |
289 | ||
17bb886f | 290 | ;; Only search target inputs, not host inputs. |
cba36e64 JN |
291 | (search-paths (cons (search-path-specification |
292 | (variable "CROSS_LIBRARY_PATH") | |
293 | (files '("lib" "lib64"))) | |
294 | (map (lambda (variable) | |
295 | (search-path-specification | |
296 | (variable variable) | |
297 | (files '("include")))) | |
298 | %gcc-cross-include-paths))) | |
17bb886f | 299 | (native-search-paths '()))) |
827d2891 | 300 | |
2d558e31 MR |
301 | (define* (cross-kernel-headers target |
302 | #:optional | |
2ea77d48 | 303 | (linux-headers linux-libre-headers) |
2d558e31 MR |
304 | (xgcc (cross-gcc target)) |
305 | (xbinutils (cross-binutils target))) | |
306 | "Return headers depending on TARGET." | |
307 | ||
827d2891 | 308 | (define xlinux-headers |
2ea77d48 CD |
309 | (package (inherit linux-headers) |
310 | (name (string-append (package-name linux-headers) | |
827d2891 LC |
311 | "-cross-" target)) |
312 | (arguments | |
0d5a559f LC |
313 | (substitute-keyword-arguments |
314 | `(#:implicit-cross-inputs? #f | |
2ea77d48 | 315 | ,@(package-arguments linux-headers)) |
827d2891 LC |
316 | ((#:phases phases) |
317 | `(alist-replace | |
318 | 'build | |
319 | (lambda _ | |
320 | (setenv "ARCH" ,(system->linux-architecture target)) | |
321 | (format #t "`ARCH' set to `~a' (cross compiling)~%" (getenv "ARCH")) | |
322 | ||
1e5005e2 MW |
323 | (invoke "make" ,(system->defconfig target)) |
324 | (invoke "make" "mrproper" "headers_check")) | |
827d2891 | 325 | ,phases)))) |
0de71c23 LC |
326 | (native-inputs `(("cross-gcc" ,xgcc) |
327 | ("cross-binutils" ,xbinutils) | |
2ea77d48 | 328 | ,@(package-native-inputs linux-headers))))) |
827d2891 | 329 | |
2d558e31 MR |
330 | (define xgnumach-headers |
331 | (package (inherit gnumach-headers) | |
332 | (name (string-append (package-name gnumach-headers) | |
333 | "-cross-" target)) | |
334 | ||
335 | (native-inputs `(("cross-gcc" ,xgcc) | |
336 | ("cross-binutils" ,xbinutils) | |
337 | ,@(package-native-inputs gnumach-headers))))) | |
338 | ||
339 | (define xmig | |
340 | (package (inherit mig) | |
341 | (name (string-append "mig-cross")) | |
342 | (arguments | |
343 | `(#:modules ((guix build gnu-build-system) | |
344 | (guix build utils) | |
345 | (srfi srfi-26)) | |
273cab96 TGR |
346 | #:phases (modify-phases %standard-phases |
347 | (add-before 'configure 'set-cross-headers-path | |
348 | (lambda* (#:key inputs #:allow-other-keys) | |
349 | (let* ((mach (assoc-ref inputs "cross-gnumach-headers")) | |
350 | (cpath (string-append mach "/include"))) | |
351 | (for-each (cut setenv <> cpath) | |
352 | ',%gcc-cross-include-paths) | |
353 | #t)))) | |
2d558e31 MR |
354 | #:configure-flags (list ,(string-append "--target=" target)) |
355 | ,@(package-arguments mig))) | |
356 | ||
357 | (propagated-inputs `(("cross-gnumach-headers" ,xgnumach-headers))) | |
358 | (native-inputs `(("cross-gcc" ,xgcc) | |
359 | ("cross-binutils" ,xbinutils) | |
360 | ,@(package-native-inputs mig))))) | |
361 | ||
362 | (define xhurd-headers | |
363 | (package (inherit hurd-headers) | |
364 | (name (string-append (package-name hurd-headers) | |
365 | "-cross-" target)) | |
366 | ||
2d558e31 MR |
367 | (native-inputs `(("cross-gcc" ,xgcc) |
368 | ("cross-binutils" ,xbinutils) | |
369 | ("cross-mig" ,xmig) | |
370 | ,@(alist-delete "mig"(package-native-inputs hurd-headers)))))) | |
371 | ||
372 | (define xglibc/hurd-headers | |
373 | (package (inherit glibc/hurd-headers) | |
374 | (name (string-append (package-name glibc/hurd-headers) | |
375 | "-cross-" target)) | |
376 | ||
377 | (arguments | |
378 | (substitute-keyword-arguments | |
379 | `(#:modules ((guix build gnu-build-system) | |
380 | (guix build utils) | |
381 | (srfi srfi-26)) | |
382 | ,@(package-arguments glibc/hurd-headers)) | |
383 | ((#:phases phases) | |
273cab96 | 384 | `(modify-phases ,phases |
2d546858 | 385 | (add-after 'unpack 'set-cross-headers-path |
273cab96 TGR |
386 | (lambda* (#:key inputs #:allow-other-keys) |
387 | (let* ((mach (assoc-ref inputs "gnumach-headers")) | |
388 | (hurd (assoc-ref inputs "hurd-headers")) | |
389 | (cpath (string-append mach "/include:" | |
390 | hurd "/include"))) | |
391 | (for-each (cut setenv <> cpath) | |
392 | ',%gcc-cross-include-paths) | |
393 | #t))))))) | |
2d558e31 MR |
394 | |
395 | (propagated-inputs `(("gnumach-headers" ,xgnumach-headers) | |
396 | ("hurd-headers" ,xhurd-headers))) | |
397 | ||
398 | (native-inputs `(("cross-gcc" ,xgcc) | |
399 | ("cross-binutils" ,xbinutils) | |
400 | ("cross-mig" ,xmig) | |
401 | ,@(alist-delete "mig"(package-native-inputs glibc/hurd-headers)))))) | |
402 | ||
403 | (define xhurd-minimal | |
404 | (package (inherit hurd-minimal) | |
405 | (name (string-append (package-name hurd-minimal) | |
406 | "-cross-" target)) | |
407 | (arguments | |
408 | (substitute-keyword-arguments | |
409 | `(#:modules ((guix build gnu-build-system) | |
410 | (guix build utils) | |
411 | (srfi srfi-26)) | |
412 | ,@(package-arguments hurd-minimal)) | |
413 | ((#:phases phases) | |
273cab96 TGR |
414 | `(modify-phases ,phases |
415 | (add-before 'configure 'set-cross-headers-path | |
416 | (lambda* (#:key inputs #:allow-other-keys) | |
417 | (let* ((glibc-headers (assoc-ref inputs "cross-glibc-hurd-headers")) | |
418 | (cpath (string-append glibc-headers "/include"))) | |
419 | (for-each (cut setenv <> cpath) | |
420 | ',%gcc-cross-include-paths) | |
421 | #t))))))) | |
2d558e31 MR |
422 | |
423 | (inputs `(("cross-glibc-hurd-headers" ,xglibc/hurd-headers))) | |
424 | ||
425 | (native-inputs `(("cross-gcc" ,xgcc) | |
426 | ("cross-binutils" ,xbinutils) | |
427 | ("cross-mig" ,xmig) | |
428 | ,@(alist-delete "mig"(package-native-inputs hurd-minimal)))))) | |
429 | ||
430 | (define xhurd-core-headers | |
431 | (package (inherit hurd-core-headers) | |
432 | (name (string-append (package-name hurd-core-headers) | |
433 | "-cross-" target)) | |
434 | ||
435 | (inputs `(("gnumach-headers" ,xgnumach-headers) | |
436 | ("hurd-headers" ,xhurd-headers) | |
437 | ("hurd-minimal" ,xhurd-minimal))) | |
438 | ||
439 | (native-inputs `(("cross-gcc" ,xgcc) | |
440 | ("cross-binutils" ,xbinutils) | |
441 | ("cross-mig" ,xmig) | |
442 | ,@(package-native-inputs hurd-core-headers))))) | |
443 | ||
444 | (match target | |
445 | ((or "i586-pc-gnu" "i586-gnu") xhurd-core-headers) | |
446 | (_ xlinux-headers))) | |
447 | ||
448 | (define* (cross-libc target | |
449 | #:optional | |
102d3075 | 450 | (libc glibc) |
2d558e31 MR |
451 | (xgcc (cross-gcc target)) |
452 | (xbinutils (cross-binutils target)) | |
453 | (xheaders (cross-kernel-headers target))) | |
102d3075 CD |
454 | "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS |
455 | and the cross tool chain." | |
456 | (if (cross-newlib? target libc) | |
f5d6c88d CD |
457 | (native-libc target libc |
458 | #:xgcc xgcc | |
459 | #:xbinutils xbinutils) | |
102d3075 | 460 | (let ((libc libc)) |
cba36e64 JN |
461 | (package (inherit libc) |
462 | (name (string-append "glibc-cross-" target)) | |
463 | (arguments | |
464 | (substitute-keyword-arguments | |
465 | `(;; Disable stripping (see above.) | |
466 | #:strip-binaries? #f | |
467 | ||
468 | ;; This package is used as a target input, but it should not have | |
469 | ;; the usual cross-compilation inputs since that would include | |
470 | ;; itself. | |
471 | #:implicit-cross-inputs? #f | |
472 | ||
473 | ;; We need SRFI 26. | |
474 | #:modules ((guix build gnu-build-system) | |
475 | (guix build utils) | |
476 | (srfi srfi-26)) | |
477 | ||
478 | ,@(package-arguments libc)) | |
479 | ((#:configure-flags flags) | |
480 | `(cons ,(string-append "--host=" target) | |
2d546858 LC |
481 | ,(if (hurd-triplet? target) |
482 | `(cons "--disable-werror" ,flags) | |
483 | flags))) | |
cba36e64 | 484 | ((#:phases phases) |
273cab96 TGR |
485 | `(modify-phases ,phases |
486 | (add-before 'configure 'set-cross-kernel-headers-path | |
487 | (lambda* (#:key inputs #:allow-other-keys) | |
488 | (let* ((kernel (assoc-ref inputs "kernel-headers")) | |
489 | (cpath (string-append kernel "/include"))) | |
490 | (for-each (cut setenv <> cpath) | |
491 | ',%gcc-cross-include-paths) | |
492 | (setenv "CROSS_LIBRARY_PATH" | |
493 | (string-append kernel "/lib")) ; for Hurd's libihash | |
494 | #t))))))) | |
cba36e64 JN |
495 | |
496 | ;; Shadow the native "kernel-headers" because glibc's recipe expects the | |
497 | ;; "kernel-headers" input to point to the right thing. | |
498 | (propagated-inputs `(("kernel-headers" ,xheaders))) | |
499 | ||
500 | ;; FIXME: 'static-bash' should really be an input, not a native input, but | |
501 | ;; to do that will require building an intermediate cross libc. | |
502 | (inputs '()) | |
503 | ||
504 | (native-inputs `(("cross-gcc" ,xgcc) | |
505 | ("cross-binutils" ,xbinutils) | |
62596a15 | 506 | ,@(if (hurd-triplet? target) |
cba36e64 JN |
507 | `(("cross-mig" |
508 | ,@(assoc-ref (package-native-inputs xheaders) | |
ef582109 | 509 | "cross-mig"))) |
cba36e64 JN |
510 | '()) |
511 | ,@(package-inputs libc) ;FIXME: static-bash | |
512 | ,@(package-native-inputs libc))))))) | |
513 | ||
102d3075 CD |
514 | (define* (native-libc target |
515 | #:optional | |
f5d6c88d CD |
516 | (libc glibc) |
517 | #:key | |
518 | xgcc | |
519 | xbinutils) | |
cba36e64 | 520 | (if (target-mingw? target) |
67dac6b8 | 521 | (let ((machine (substring target 0 (string-index target #\-)))) |
f5d6c88d CD |
522 | (make-mingw-w64 machine |
523 | #:xgcc xgcc | |
524 | #:xbinutils xbinutils)) | |
102d3075 | 525 | libc)) |
cba36e64 | 526 | |
102d3075 CD |
527 | (define* (cross-newlib? target |
528 | #:optional | |
529 | (libc glibc)) | |
530 | (not (eq? (native-libc target libc) libc))) | |
827d2891 LC |
531 | |
532 | \f | |
bd2e1a8c LC |
533 | ;;; Concrete cross tool chains are instantiated like this: |
534 | ;; | |
535 | ;; (define-public xgcc-armhf | |
536 | ;; (let ((triplet "arm-linux-gnueabihf")) | |
827d2891 | 537 | ;; (cross-gcc triplet |
e0775d2a MW |
538 | ;; #:xbinutils (cross-binutils triplet) |
539 | ;; #:libc (cross-libc triplet)))) | |
bd2e1a8c LC |
540 | ;; |
541 | ;;; We don't do that here because we'd be referring to bindings from (gnu | |
542 | ;;; packages gcc) from the top level, which doesn't play well with circular | |
543 | ;;; dependencies among modules. |