| 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2020 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, 2020 Marius Bakke <mbakke@fastmail.com> |
| 8 | ;;; Copyright © 2019 Carl Dong <contact@carldong.me> |
| 9 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> |
| 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) |
| 27 | #:use-module (gnu packages) |
| 28 | #:use-module (gnu packages gcc) |
| 29 | #:use-module (gnu packages base) |
| 30 | #:use-module (gnu packages linux) |
| 31 | #:use-module (gnu packages hurd) |
| 32 | #:use-module (gnu packages mingw) |
| 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) |
| 40 | #:use-module (ice-9 match) |
| 41 | #:use-module (ice-9 regex) |
| 42 | #:export (cross-binutils |
| 43 | cross-libc |
| 44 | cross-gcc |
| 45 | cross-newlib? |
| 46 | cross-kernel-headers)) |
| 47 | |
| 48 | (define-syntax %xgcc |
| 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'. |
| 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)) |
| 55 | |
| 56 | (define %gcc-include-paths |
| 57 | ;; Environment variables for header search paths. |
| 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")) |
| 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 | |
| 68 | (define (cross p target) |
| 69 | (package (inherit p) |
| 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 | |
| 77 | (define* (cross-binutils target #:optional (binutils binutils)) |
| 78 | "Return a cross-Binutils for TARGET using BINUTILS." |
| 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. |
| 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))))))) |
| 96 | |
| 97 | ;; For Xtensa, apply Qualcomm's patch. |
| 98 | (cross (cond ((string-prefix? "xtensa-" target) |
| 99 | (package-with-patches binutils |
| 100 | (search-patches |
| 101 | "ath9k-htc-firmware-binutils.patch"))) |
| 102 | ((target-mingw? target) |
| 103 | (package-with-extra-patches |
| 104 | binutils |
| 105 | (search-patches "binutils-mingw-w64-timestamp.patch" |
| 106 | "binutils-mingw-w64-deterministic.patch"))) |
| 107 | (else binutils)) |
| 108 | target))) |
| 109 | |
| 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.)" |
| 113 | ;; Set the current target system so that 'glibc-dynamic-linker' returns the |
| 114 | ;; right name. |
| 115 | (parameterize ((%current-target-system target)) |
| 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 |
| 121 | ,@(package-arguments xgcc)))) |
| 122 | (substitute-keyword-arguments args |
| 123 | ((#:configure-flags flags) |
| 124 | `(append (list ,(string-append "--target=" target) |
| 125 | ,@(if libc |
| 126 | `( ;; Disable libcilkrts because it is not |
| 127 | ;; ported to GNU/Hurd. |
| 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=/") |
| 137 | `( ;; Disable features not needed at this stage. |
| 138 | "--disable-shared" "--enable-static" |
| 139 | "--enable-languages=c,c++" |
| 140 | |
| 141 | ;; libstdc++ cannot be built at this stage |
| 142 | ;; ("Link tests are not allowed after |
| 143 | ;; GCC_NO_EXECUTABLES."). |
| 144 | "--disable-libstdc++-v3" |
| 145 | |
| 146 | "--disable-threads" ;libgcc, would need libc |
| 147 | "--disable-libatomic" |
| 148 | "--disable-libmudflap" |
| 149 | "--disable-libgomp" |
| 150 | "--disable-libmpx" |
| 151 | "--disable-libssp" |
| 152 | "--disable-libquadmath" |
| 153 | "--disable-decimal-float" ;would need libc |
| 154 | "--disable-libcilkrts" |
| 155 | |
| 156 | ,@(if (string-prefix? "powerpc64le-" target) |
| 157 | ;; On POWER9 (little endian) glibc needs |
| 158 | ;; the 128-bit long double type. |
| 159 | '("--with-long-double-128") |
| 160 | '()) |
| 161 | |
| 162 | ;; When target is any OS other than 'none' these |
| 163 | ;; libraries will fail if there is no libc |
| 164 | ;; present. See |
| 165 | ;; <https://lists.gnu.org/archive/html/guix-devel/2016-02/msg01311.html> |
| 166 | "--disable-libitm" |
| 167 | "--disable-libvtv" |
| 168 | "--disable-libsanitizer" |
| 169 | )) |
| 170 | |
| 171 | ;; Install cross-built libraries such as libgcc_s.so in |
| 172 | ;; the "lib" output. |
| 173 | ,@(if libc |
| 174 | `((string-append "--with-toolexeclibdir=" |
| 175 | (assoc-ref %outputs "lib") |
| 176 | "/" ,target "/lib")) |
| 177 | '()) |
| 178 | ;; For a newlib (non-glibc) target |
| 179 | ,@(if (cross-newlib? target) |
| 180 | '("--with-newlib") |
| 181 | '())) |
| 182 | |
| 183 | ,(if libc |
| 184 | flags |
| 185 | `(remove (cut string-match "--enable-languages.*" <>) |
| 186 | ,flags)))) |
| 187 | ((#:make-flags flags) |
| 188 | (if libc |
| 189 | `(let ((libc (assoc-ref %build-inputs "libc"))) |
| 190 | ;; FLAGS_FOR_TARGET are needed for the target libraries to receive |
| 191 | ;; the -Bxxx for the startfiles. |
| 192 | (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib") |
| 193 | ,flags)) |
| 194 | flags)) |
| 195 | ((#:phases phases) |
| 196 | `(cross-gcc-build-phases ,target ,phases)))))) |
| 197 | |
| 198 | (define (cross-gcc-patches xgcc target) |
| 199 | "Return GCC patches needed for XGCC and TARGET." |
| 200 | (cond ((string-prefix? "xtensa-" target) |
| 201 | ;; Patch by Qualcomm needed to build the ath9k-htc firmware. |
| 202 | (search-patches "ath9k-htc-firmware-gcc.patch")) |
| 203 | ((target-mingw? target) |
| 204 | (append (search-patches "gcc-4.9.3-mingw-gthr-default.patch") |
| 205 | (if (version>=? (package-version xgcc) "7.0") |
| 206 | (search-patches "gcc-7-cross-mingw.patch") |
| 207 | '()))) |
| 208 | (else '()))) |
| 209 | |
| 210 | (define (cross-gcc-snippet target) |
| 211 | "Return GCC snippet needed for TARGET." |
| 212 | `(begin |
| 213 | ,@(if (target-mingw? target) |
| 214 | '((copy-recursively "libstdc++-v3/config/os/mingw32-w64" |
| 215 | "libstdc++-v3/config/os/newlib")) |
| 216 | '()) |
| 217 | ;; TOOLDIR_BASE_PREFIX is erroneous when using a separate "lib" |
| 218 | ;; output. Specify it correctly, otherwise GCC won't find its shared |
| 219 | ;; libraries installed in the "lib" output. See: |
| 220 | ;; https://lists.gnu.org/archive/html/bug-guix/2020-03/msg00196.html. |
| 221 | (substitute* "gcc/Makefile.in" |
| 222 | (("-DTOOLDIR_BASE_PREFIX=[^ ]*") |
| 223 | "-DTOOLDIR_BASE_PREFIX=\\\"../../../../\\\"")) |
| 224 | #t)) |
| 225 | |
| 226 | (define* (cross-gcc target |
| 227 | #:key |
| 228 | (xgcc %xgcc) |
| 229 | (xbinutils (cross-binutils target)) |
| 230 | (libc #f)) |
| 231 | "Return a cross-compiler for TARGET, where TARGET is a GNU triplet. Use |
| 232 | XGCC as the base compiler. Use XBINUTILS as the associated cross-Binutils. |
| 233 | If LIBC is false, then build a GCC that does not target a libc; otherwise, |
| 234 | target that libc." |
| 235 | (package (inherit xgcc) |
| 236 | (name (string-append "gcc-cross-" |
| 237 | (if libc "" "sans-libc-") |
| 238 | target)) |
| 239 | (source |
| 240 | (origin |
| 241 | (inherit (package-source xgcc)) |
| 242 | (patches |
| 243 | (append |
| 244 | (origin-patches (package-source xgcc)) |
| 245 | (append (cond |
| 246 | ((version>=? (package-version xgcc) "8.0") |
| 247 | (search-patches "gcc-8-cross-environment-variables.patch")) |
| 248 | ((version>=? (package-version xgcc) "6.0") |
| 249 | (search-patches "gcc-7-cross-toolexeclibdir.patch" |
| 250 | "gcc-6-cross-environment-variables.patch")) |
| 251 | (else |
| 252 | (search-patches "gcc-cross-environment-variables.patch"))) |
| 253 | (cross-gcc-patches xgcc target)))) |
| 254 | (modules '((guix build utils))) |
| 255 | (snippet |
| 256 | (cross-gcc-snippet target)))) |
| 257 | |
| 258 | (outputs '("out" "lib")) |
| 259 | |
| 260 | (arguments |
| 261 | `(#:implicit-inputs? #f |
| 262 | #:imported-modules ((gnu build cross-toolchain) |
| 263 | ,@%gnu-build-system-modules) |
| 264 | #:modules ((guix build gnu-build-system) |
| 265 | (guix build utils) |
| 266 | (gnu build cross-toolchain) |
| 267 | (srfi srfi-1) |
| 268 | (srfi srfi-26) |
| 269 | (ice-9 regex)) |
| 270 | |
| 271 | ,@(cross-gcc-arguments target xgcc libc))) |
| 272 | |
| 273 | (native-inputs |
| 274 | `(("ld-wrapper-cross" ,(make-ld-wrapper |
| 275 | (string-append "ld-wrapper-" target) |
| 276 | #:target (const target) |
| 277 | #:binutils xbinutils)) |
| 278 | ("binutils-cross" ,xbinutils) |
| 279 | |
| 280 | ,@(let ((inputs (append (package-inputs xgcc) |
| 281 | (fold alist-delete (%final-inputs) |
| 282 | '("libc" "libc:static")) |
| 283 | |
| 284 | ;; Call it differently so that the builder can |
| 285 | ;; check whether the "libc" input is #f. |
| 286 | `(("libc-native" |
| 287 | ,@(assoc-ref (%final-inputs) "libc")) |
| 288 | ("libc-native:static" |
| 289 | ,@(assoc-ref (%final-inputs) |
| 290 | "libc:static")))))) |
| 291 | (cond |
| 292 | ((target-mingw? target) |
| 293 | (if libc |
| 294 | `(,@inputs |
| 295 | ("libc" ,libc)) |
| 296 | `(,@inputs |
| 297 | ("mingw-source" ,(package-source mingw-w64))))) |
| 298 | (libc |
| 299 | `(,@inputs |
| 300 | ("libc" ,libc) |
| 301 | ("libc:static" ,libc "static") |
| 302 | ("xkernel-headers" ;the target headers |
| 303 | ,@(assoc-ref (package-propagated-inputs libc) |
| 304 | "kernel-headers")))) |
| 305 | (else inputs))))) |
| 306 | |
| 307 | (inputs '()) |
| 308 | |
| 309 | ;; Only search target inputs, not host inputs. |
| 310 | (search-paths (cons (search-path-specification |
| 311 | (variable "CROSS_LIBRARY_PATH") |
| 312 | (files '("lib" "lib64"))) |
| 313 | (map (lambda (variable) |
| 314 | (search-path-specification |
| 315 | (variable variable) |
| 316 | |
| 317 | ;; Add 'include/c++' here so that <cstdlib>'s |
| 318 | ;; "#include_next <stdlib.h>" finds GCC's |
| 319 | ;; <stdlib.h>, not libc's. |
| 320 | (files (match variable |
| 321 | ("CROSS_CPLUS_INCLUDE_PATH" |
| 322 | '("include/c++" "include")) |
| 323 | (_ |
| 324 | '("include")))))) |
| 325 | %gcc-cross-include-paths))) |
| 326 | (native-search-paths '()))) |
| 327 | |
| 328 | (define* (cross-kernel-headers target |
| 329 | #:optional |
| 330 | (linux-headers linux-libre-headers) |
| 331 | (xgcc (cross-gcc target)) |
| 332 | (xbinutils (cross-binutils target))) |
| 333 | "Return headers depending on TARGET." |
| 334 | |
| 335 | (define xlinux-headers |
| 336 | (package (inherit linux-headers) |
| 337 | (name (string-append (package-name linux-headers) |
| 338 | "-cross-" target)) |
| 339 | (arguments |
| 340 | (substitute-keyword-arguments |
| 341 | `(#:implicit-cross-inputs? #f |
| 342 | ,@(package-arguments linux-headers)) |
| 343 | ((#:phases phases) |
| 344 | `(alist-replace |
| 345 | 'build |
| 346 | (lambda _ |
| 347 | (setenv "ARCH" ,(system->linux-architecture target)) |
| 348 | (format #t "`ARCH' set to `~a' (cross compiling)~%" (getenv "ARCH")) |
| 349 | |
| 350 | (invoke "make" ,(system->defconfig target)) |
| 351 | (invoke "make" "mrproper" "headers_check")) |
| 352 | ,phases)))) |
| 353 | (native-inputs `(("cross-gcc" ,xgcc) |
| 354 | ("cross-binutils" ,xbinutils) |
| 355 | ,@(package-native-inputs linux-headers))))) |
| 356 | |
| 357 | (define xgnumach-headers |
| 358 | (package (inherit gnumach-headers) |
| 359 | (name (string-append (package-name gnumach-headers) |
| 360 | "-cross-" target)) |
| 361 | |
| 362 | (native-inputs `(("cross-gcc" ,xgcc) |
| 363 | ("cross-binutils" ,xbinutils) |
| 364 | ,@(package-native-inputs gnumach-headers))))) |
| 365 | |
| 366 | (define xmig |
| 367 | (package (inherit mig) |
| 368 | (name (string-append "mig-cross")) |
| 369 | (arguments |
| 370 | `(#:modules ((guix build gnu-build-system) |
| 371 | (guix build utils) |
| 372 | (srfi srfi-26)) |
| 373 | #:phases (modify-phases %standard-phases |
| 374 | (add-before 'configure 'set-cross-headers-path |
| 375 | (lambda* (#:key inputs #:allow-other-keys) |
| 376 | (let* ((mach (assoc-ref inputs "cross-gnumach-headers")) |
| 377 | (cpath (string-append mach "/include"))) |
| 378 | (for-each (cut setenv <> cpath) |
| 379 | ',%gcc-cross-include-paths) |
| 380 | #t)))) |
| 381 | #:configure-flags (list ,(string-append "--target=" target)) |
| 382 | #:tests? #f)) |
| 383 | |
| 384 | (propagated-inputs `(("cross-gnumach-headers" ,xgnumach-headers))) |
| 385 | (native-inputs `(("cross-gcc" ,xgcc) |
| 386 | ("cross-binutils" ,xbinutils) |
| 387 | ,@(package-native-inputs mig))))) |
| 388 | |
| 389 | (define xhurd-headers |
| 390 | (package (inherit hurd-headers) |
| 391 | (name (string-append (package-name hurd-headers) |
| 392 | "-cross-" target)) |
| 393 | |
| 394 | (native-inputs `(("cross-gcc" ,xgcc) |
| 395 | ("cross-binutils" ,xbinutils) |
| 396 | ("cross-mig" ,xmig) |
| 397 | ,@(alist-delete "mig"(package-native-inputs hurd-headers)))))) |
| 398 | |
| 399 | (define xglibc/hurd-headers |
| 400 | (package (inherit glibc/hurd-headers) |
| 401 | (name (string-append (package-name glibc/hurd-headers) |
| 402 | "-cross-" target)) |
| 403 | |
| 404 | (arguments |
| 405 | (substitute-keyword-arguments |
| 406 | `(#:modules ((guix build gnu-build-system) |
| 407 | (guix build utils) |
| 408 | (srfi srfi-26)) |
| 409 | ,@(package-arguments glibc/hurd-headers)) |
| 410 | ((#:phases phases) |
| 411 | `(modify-phases ,phases |
| 412 | (add-after 'unpack 'set-cross-headers-path |
| 413 | (lambda* (#:key inputs #:allow-other-keys) |
| 414 | (let* ((mach (assoc-ref inputs "gnumach-headers")) |
| 415 | (hurd (assoc-ref inputs "hurd-headers")) |
| 416 | (cpath (string-append mach "/include:" |
| 417 | hurd "/include"))) |
| 418 | (for-each (cut setenv <> cpath) |
| 419 | ',%gcc-cross-include-paths) |
| 420 | #t))))))) |
| 421 | |
| 422 | (propagated-inputs `(("gnumach-headers" ,xgnumach-headers) |
| 423 | ("hurd-headers" ,xhurd-headers))) |
| 424 | |
| 425 | (native-inputs `(("cross-gcc" ,xgcc) |
| 426 | ("cross-binutils" ,xbinutils) |
| 427 | ("cross-mig" ,xmig) |
| 428 | ,@(alist-delete "mig"(package-native-inputs glibc/hurd-headers)))))) |
| 429 | |
| 430 | (define xhurd-minimal |
| 431 | (package (inherit hurd-minimal) |
| 432 | (name (string-append (package-name hurd-minimal) |
| 433 | "-cross-" target)) |
| 434 | (arguments |
| 435 | (substitute-keyword-arguments |
| 436 | `(#:modules ((guix build gnu-build-system) |
| 437 | (guix build utils) |
| 438 | (srfi srfi-26)) |
| 439 | ,@(package-arguments hurd-minimal)) |
| 440 | ((#:phases phases) |
| 441 | `(modify-phases ,phases |
| 442 | (add-before 'configure 'set-cross-headers-path |
| 443 | (lambda* (#:key inputs #:allow-other-keys) |
| 444 | (let* ((glibc-headers (assoc-ref inputs "cross-glibc-hurd-headers")) |
| 445 | (cpath (string-append glibc-headers "/include"))) |
| 446 | (for-each (cut setenv <> cpath) |
| 447 | ',%gcc-cross-include-paths) |
| 448 | #t))))))) |
| 449 | |
| 450 | (inputs `(("cross-glibc-hurd-headers" ,xglibc/hurd-headers))) |
| 451 | |
| 452 | (native-inputs `(("cross-gcc" ,xgcc) |
| 453 | ("cross-binutils" ,xbinutils) |
| 454 | ("cross-mig" ,xmig) |
| 455 | ,@(alist-delete "mig"(package-native-inputs hurd-minimal)))))) |
| 456 | |
| 457 | (define xhurd-core-headers |
| 458 | (package (inherit hurd-core-headers) |
| 459 | (name (string-append (package-name hurd-core-headers) |
| 460 | "-cross-" target)) |
| 461 | |
| 462 | (inputs `(("gnumach-headers" ,xgnumach-headers) |
| 463 | ("hurd-headers" ,xhurd-headers) |
| 464 | ("hurd-minimal" ,xhurd-minimal))) |
| 465 | |
| 466 | (native-inputs `(("cross-gcc" ,xgcc) |
| 467 | ("cross-binutils" ,xbinutils) |
| 468 | ("cross-mig" ,xmig) |
| 469 | ,@(package-native-inputs hurd-core-headers))))) |
| 470 | |
| 471 | (match target |
| 472 | ((or "i586-pc-gnu" "i586-gnu") xhurd-core-headers) |
| 473 | (_ xlinux-headers))) |
| 474 | |
| 475 | (define* (cross-libc target |
| 476 | #:optional |
| 477 | (libc glibc) |
| 478 | (xgcc (cross-gcc target)) |
| 479 | (xbinutils (cross-binutils target)) |
| 480 | (xheaders (cross-kernel-headers target))) |
| 481 | "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS |
| 482 | and the cross tool chain." |
| 483 | (if (cross-newlib? target libc) |
| 484 | (native-libc target libc |
| 485 | #:xgcc xgcc |
| 486 | #:xbinutils xbinutils) |
| 487 | (package |
| 488 | (inherit libc) |
| 489 | (name (string-append "glibc-cross-" target)) |
| 490 | (arguments |
| 491 | (substitute-keyword-arguments |
| 492 | `( ;; Disable stripping (see above.) |
| 493 | #:strip-binaries? #f |
| 494 | |
| 495 | ;; This package is used as a target input, but it should not have |
| 496 | ;; the usual cross-compilation inputs since that would include |
| 497 | ;; itself. |
| 498 | #:implicit-cross-inputs? #f |
| 499 | |
| 500 | ;; We need SRFI 26. |
| 501 | #:modules ((guix build gnu-build-system) |
| 502 | (guix build utils) |
| 503 | (srfi srfi-26)) |
| 504 | |
| 505 | ,@(package-arguments libc)) |
| 506 | ((#:configure-flags flags) |
| 507 | `(cons ,(string-append "--host=" target) |
| 508 | ,(if (hurd-triplet? target) |
| 509 | `(cons "--disable-werror" ,flags) |
| 510 | flags))) |
| 511 | ((#:phases phases) |
| 512 | `(modify-phases ,phases |
| 513 | (add-before 'configure 'set-cross-kernel-headers-path |
| 514 | (lambda* (#:key inputs #:allow-other-keys) |
| 515 | (let* ((kernel (assoc-ref inputs "kernel-headers")) |
| 516 | (cpath (string-append kernel "/include"))) |
| 517 | (for-each (cut setenv <> cpath) |
| 518 | ',%gcc-cross-include-paths) |
| 519 | (setenv "CROSS_LIBRARY_PATH" |
| 520 | (string-append kernel "/lib")) ; for Hurd's libihash |
| 521 | #t))) |
| 522 | ,@(if (hurd-triplet? target) |
| 523 | '((add-after 'install 'augment-libc.so |
| 524 | (lambda* (#:key outputs #:allow-other-keys) |
| 525 | (let* ((out (assoc-ref outputs "out"))) |
| 526 | (substitute* (string-append out "/lib/libc.so") |
| 527 | (("/[^ ]+/lib/libc.so.0.3") |
| 528 | (string-append out "/lib/libc.so.0.3" |
| 529 | " libmachuser.so libhurduser.so")))) |
| 530 | #t)) |
| 531 | ;; TODO: move to glibc in the next rebuild cycle |
| 532 | (add-after 'unpack 'patch-libc/hurd |
| 533 | (lambda* (#:key inputs #:allow-other-keys) |
| 534 | (for-each |
| 535 | (lambda (name) |
| 536 | (let ((patch (assoc-ref inputs name))) |
| 537 | (invoke "patch" "-p1" "--force" "-i" patch))) |
| 538 | '("hurd-mach-print.patch" |
| 539 | "hurd-gettyent.patch"))))) |
| 540 | '()))))) |
| 541 | |
| 542 | ;; Shadow the native "kernel-headers" because glibc's recipe expects the |
| 543 | ;; "kernel-headers" input to point to the right thing. |
| 544 | (propagated-inputs `(("kernel-headers" ,xheaders))) |
| 545 | |
| 546 | ;; FIXME: 'static-bash' should really be an input, not a native input, but |
| 547 | ;; to do that will require building an intermediate cross libc. |
| 548 | (inputs (if (hurd-triplet? target) |
| 549 | `(;; TODO: move to glibc in the next rebuild cycle |
| 550 | ("hurd-mach-print.patch" |
| 551 | ,(search-patch "glibc-hurd-mach-print.patch")) |
| 552 | ("hurd-gettyent.patch" |
| 553 | ,(search-patch "glibc-hurd-gettyent.patch"))) |
| 554 | '())) |
| 555 | |
| 556 | (native-inputs `(("cross-gcc" ,xgcc) |
| 557 | ("cross-binutils" ,xbinutils) |
| 558 | ,@(if (hurd-triplet? target) |
| 559 | `(("cross-mig" |
| 560 | ,@(assoc-ref (package-native-inputs xheaders) |
| 561 | "cross-mig"))) |
| 562 | '()) |
| 563 | ,@(package-inputs libc) ;FIXME: static-bash |
| 564 | ,@(package-native-inputs libc)))))) |
| 565 | |
| 566 | (define* (native-libc target |
| 567 | #:optional |
| 568 | (libc glibc) |
| 569 | #:key |
| 570 | xgcc |
| 571 | xbinutils) |
| 572 | (if (target-mingw? target) |
| 573 | (let ((machine (substring target 0 (string-index target #\-)))) |
| 574 | (make-mingw-w64 machine |
| 575 | #:xgcc xgcc |
| 576 | #:xbinutils xbinutils)) |
| 577 | libc)) |
| 578 | |
| 579 | (define* (cross-newlib? target |
| 580 | #:optional |
| 581 | (libc glibc)) |
| 582 | (not (eq? (native-libc target libc) libc))) |
| 583 | |
| 584 | \f |
| 585 | ;;; Concrete cross tool chains are instantiated like this: |
| 586 | ;; |
| 587 | ;; (define-public xgcc-armhf |
| 588 | ;; (let ((triplet "arm-linux-gnueabihf")) |
| 589 | ;; (cross-gcc triplet |
| 590 | ;; #:xbinutils (cross-binutils triplet) |
| 591 | ;; #:libc (cross-libc triplet)))) |
| 592 | ;; |
| 593 | ;;; We don't do that here because we'd be referring to bindings from (gnu |
| 594 | ;;; packages gcc) from the top level, which doesn't play well with circular |
| 595 | ;;; dependencies among modules. |