diff mbox series

[bug#66263,01/23] gnu: cross-libc: Return #f if no libc available.

Message ID 20230929091627.7820-1-jean@foundationdevices.com
State New
Headers show
Series guix: Add avr as a platform. | expand

Commit Message

Jean-Pierre De Jesus DIAZ Sept. 29, 2023, 9:16 a.m. UTC
* gnu/packages/cross-base.scm (cross-libc): Return #f if platform does
  not have a libc available.
---
 gnu/packages/cross-base.scm | 138 +++++++++++++++++++-----------------
 1 file changed, 71 insertions(+), 67 deletions(-)
diff mbox series

Patch

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 14cb365099..f55765f1b0 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -9,6 +9,7 @@ 
 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2023 Josselin Poiret <dev@jpoiret.xyz>
+;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -611,73 +612,76 @@  (define* (cross-libc* target
                       (xheaders (cross-kernel-headers target)))
   "Return LIBC cross-built for TARGET, a GNU triplet. Use XGCC and XBINUTILS
 and the cross tool chain."
-  (if (target-mingw? target)
-      (let ((machine (substring target 0 (string-index target #\-))))
-        (make-mingw-w64 machine
-                        #:xgcc xgcc
-                        #:xbinutils xbinutils))
-      (package
-        (inherit libc)
-        (name (string-append "glibc-cross-" target))
-        (arguments
-         (substitute-keyword-arguments
-             `( ;; Disable stripping (see above.)
-               #:strip-binaries? #f
-
-               ;; This package is used as a target input, but it should not have
-               ;; the usual cross-compilation inputs since that would include
-               ;; itself.
-               #:implicit-cross-inputs? #f
-
-               ;; We need SRFI 26.
-               #:modules ((guix build gnu-build-system)
-                          (guix build utils)
-                          (srfi srfi-26))
-
-               ,@(package-arguments libc))
-           ((#:configure-flags flags)
-            `(cons ,(string-append "--host=" target)
-                   ,(if (target-hurd? target)
-                        `(append (list "--disable-werror"
-                                       ,@%glibc/hurd-configure-flags)
-                                 ,flags)
-                        flags)))
-           ((#:phases phases)
-            `(modify-phases ,phases
-               (add-before 'configure 'set-cross-kernel-headers-path
-                 (lambda* (#:key inputs #:allow-other-keys)
-                   (let* ((kernel (assoc-ref inputs "kernel-headers"))
-                          (cpath (string-append kernel "/include")))
-                     (for-each (cut setenv <> cpath)
-                               ',%gcc-cross-include-paths)
-                     (setenv "CROSS_LIBRARY_PATH"
-                             (string-append kernel "/lib")) ; for Hurd's libihash
-                     #t)))
-               ,@(if (target-hurd? target)
-                     '((add-after 'install 'augment-libc.so
-                         (lambda* (#:key outputs #:allow-other-keys)
-                           (let* ((out (assoc-ref outputs "out")))
-                             (substitute* (string-append out "/lib/libc.so")
-                               (("/[^ ]+/lib/libc.so.0.3")
-                                (string-append out "/lib/libc.so.0.3"
-                                               " libmachuser.so libhurduser.so"))))
-                           #t)))
-                     '())))))
-
-        ;; Shadow the native "kernel-headers" because glibc's recipe expects the
-        ;; "kernel-headers" input to point to the right thing.
-        (propagated-inputs `(("kernel-headers" ,xheaders)))
-
-        (native-inputs `(("cross-gcc" ,xgcc)
-                         ("cross-binutils" ,xbinutils)
-                         ,@(if (target-hurd? target)
-                               `(("cross-mig"
-                                  ,(cross-mig target
-                                              #:xgcc xgcc
-                                              #:xbinutils xbinutils)))
-                               '())
-                         ,@(package-inputs libc) ;FIXME: static-bash
-                         ,@(package-native-inputs libc))))))
+  (match target
+   ((? target-mingw?)
+    (let ((machine (substring target 0 (string-index target #\-))))
+      (make-mingw-w64 machine
+                      #:xgcc xgcc
+                      #:xbinutils xbinutils)))
+   ((or (? target-linux?) (? target-hurd?))
+    (package
+      (inherit libc)
+      (name (string-append "glibc-cross-" target))
+      (arguments
+       (substitute-keyword-arguments
+           `( ;; Disable stripping (see above.)
+             #:strip-binaries? #f
+
+             ;; This package is used as a target input, but it should not have
+             ;; the usual cross-compilation inputs since that would include
+             ;; itself.
+             #:implicit-cross-inputs? #f
+
+             ;; We need SRFI 26.
+             #:modules ((guix build gnu-build-system)
+                        (guix build utils)
+                        (srfi srfi-26))
+
+             ,@(package-arguments libc))
+         ((#:configure-flags flags)
+          `(cons ,(string-append "--host=" target)
+                 ,(if (target-hurd? target)
+                      `(append (list "--disable-werror"
+                                     ,@%glibc/hurd-configure-flags)
+                               ,flags)
+                      flags)))
+         ((#:phases phases)
+          `(modify-phases ,phases
+             (add-before 'configure 'set-cross-kernel-headers-path
+               (lambda* (#:key inputs #:allow-other-keys)
+                 (let* ((kernel (assoc-ref inputs "kernel-headers"))
+                        (cpath (string-append kernel "/include")))
+                   (for-each (cut setenv <> cpath)
+                             ',%gcc-cross-include-paths)
+                   (setenv "CROSS_LIBRARY_PATH"
+                           (string-append kernel "/lib")) ; for Hurd's libihash
+                   #t)))
+             ,@(if (target-hurd? target)
+                   '((add-after 'install 'augment-libc.so
+                       (lambda* (#:key outputs #:allow-other-keys)
+                         (let* ((out (assoc-ref outputs "out")))
+                           (substitute* (string-append out "/lib/libc.so")
+                             (("/[^ ]+/lib/libc.so.0.3")
+                              (string-append out "/lib/libc.so.0.3"
+                                             " libmachuser.so libhurduser.so"))))
+                         #t)))
+                   '())))))
+
+      ;; Shadow the native "kernel-headers" because glibc's recipe expects the
+      ;; "kernel-headers" input to point to the right thing.
+      (propagated-inputs `(("kernel-headers" ,xheaders)))
+
+      (native-inputs `(("cross-gcc" ,xgcc)
+                       ("cross-binutils" ,xbinutils)
+                       ,@(if (target-hurd? target)
+                             `(("cross-mig"
+                                ,(cross-mig target
+                                            #:xgcc xgcc
+                                            #:xbinutils xbinutils)))
+                             '())
+                       ,@(package-inputs libc) ;FIXME: static-bash
+                       ,@(package-native-inputs libc)))))
+   (else #f)))
 
 
 ;;; Concrete cross tool chains are instantiated like this: