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