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