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