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