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